From 10f4bb5872092370012a365c6b3bf8a459e8af88 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 15 Jul 2015 13:56:31 +0100 Subject: [PATCH] Add support for FocusIn/FocusOut events from UI --- src/client.cc | 4 ++++ src/keys.hh | 2 ++ src/ncurses_ui.cc | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/client.cc b/src/client.cc index e7a8085d..9abff701 100644 --- a/src/client.cc +++ b/src/client.cc @@ -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); } diff --git a/src/keys.hh b/src/keys.hh index 7cb957df..d9865f77 100644 --- a/src/keys.hh +++ b/src/keys.hh @@ -54,6 +54,8 @@ struct Key F10, F11, F12, + FocusIn, + FocusOut, Invalid, }; diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 1fc1f0d4..b9ad3a52 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -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) {