Add support for FocusIn/FocusOut events from UI

This commit is contained in:
Maxime Coste 2015-07-15 13:56:31 +01:00
parent f8e4bb09f2
commit 10f4bb5872
3 changed files with 19 additions and 0 deletions

View File

@ -69,6 +69,10 @@ void Client::handle_available_input(EventMode mode)
{
if (*key == ctrl('c'))
killpg(getpgrp(), SIGINT);
else if (*key == Key::FocusIn)
context().hooks().run_hook("FocusIn", context().name(), context());
else if (*key == Key::FocusOut)
context().hooks().run_hook("FocusOut", context().name(), context());
else
m_input_handler.handle_key(*key);
}

View File

@ -54,6 +54,8 @@ struct Key
F10,
F11,
F12,
FocusIn,
FocusOut,
Invalid,
};

View File

@ -261,6 +261,8 @@ NCursesUI::NCursesUI()
mouseinterval(0);
// force enable report mouse position
puts("\033[?1002h");
// force enable report focus events
puts("\033[?1004h");
signal(SIGWINCH, on_term_resize);
signal(SIGINT, [](int){});
@ -272,6 +274,7 @@ NCursesUI::NCursesUI()
NCursesUI::~NCursesUI()
{
puts("\033[?1004l");
puts("\033[?1002l");
endwin();
signal(SIGWINCH, SIG_DFL);
@ -509,6 +512,16 @@ Key NCursesUI::get_key()
{
timeout(0);
const Codepoint new_c = getch();
if (new_c == '[') // potential CSI
{
const Codepoint csi_val = getch();
switch (csi_val)
{
case 'I': return Key::FocusIn;
case 'O': return Key::FocusOut;
default: break; // nothing
}
}
timeout(-1);
if (new_c != ERR)
{