From 16b09672c8e6fd3b9713da0b2c7250598d452d32 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 25 Sep 2021 13:30:28 +0200 Subject: [PATCH] Log FocusOut events Currently, i3 only logs FocusIn events. Thus, a debug log tells us when some window gets the focus. However, we don't know when it loses the focus. This commit remedies this by adding some log messages for this. Since I had no idea what to log, this just logs all the fields from the event plus tries to find a name for the window. Signed-off-by: Uli Schlachter Idea-in-context-of: https://github.com/i3/i3/issues/4532 --- src/handlers.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/handlers.c b/src/handlers.c index c5b09d7e5..86859ebc2 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -1058,6 +1058,76 @@ static void handle_focus_in(xcb_focus_in_event_t *event) { tree_render(); } +/* + * Log FocusOut events. + * + */ +static void handle_focus_out(xcb_focus_in_event_t *event) { + Con *con = con_by_window_id(event->event); + const char *window_name, *mode, *detail; + + if (con != NULL) { + window_name = con->name; + if (window_name == NULL) { + window_name = ""; + } + } else if (event->event == root) { + window_name = ""; + } else { + window_name = ""; + } + + switch (event->mode) { + case XCB_NOTIFY_MODE_NORMAL: + mode = "Normal"; + break; + case XCB_NOTIFY_MODE_GRAB: + mode = "Grab"; + break; + case XCB_NOTIFY_MODE_UNGRAB: + mode = "Ungrab"; + break; + case XCB_NOTIFY_MODE_WHILE_GRABBED: + mode = "WhileGrabbed"; + break; + default: + mode = ""; + break; + } + + switch (event->detail) { + case XCB_NOTIFY_DETAIL_ANCESTOR: + detail = "Ancestor"; + break; + case XCB_NOTIFY_DETAIL_VIRTUAL: + detail = "Virtual"; + break; + case XCB_NOTIFY_DETAIL_INFERIOR: + detail = "Inferior"; + break; + case XCB_NOTIFY_DETAIL_NONLINEAR: + detail = "Nonlinear"; + break; + case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL: + detail = "NonlinearVirtual"; + break; + case XCB_NOTIFY_DETAIL_POINTER: + detail = "Pointer"; + break; + case XCB_NOTIFY_DETAIL_POINTER_ROOT: + detail = "PointerRoot"; + break; + case XCB_NOTIFY_DETAIL_NONE: + detail = "NONE"; + break; + default: + detail = "unknown"; + break; + } + + DLOG("focus change out: window 0x%08x (con %p, %s) lost focus with detail=%s, mode=%s\n", event->event, con, window_name, detail, mode); +} + /* * Handles ConfigureNotify events for the root window, which are generated when * the monitor configuration changed. @@ -1434,6 +1504,10 @@ void handle_event(int type, xcb_generic_event_t *event) { handle_focus_in((xcb_focus_in_event_t *)event); break; + case XCB_FOCUS_OUT: + handle_focus_out((xcb_focus_out_event_t *)event); + break; + case XCB_PROPERTY_NOTIFY: { xcb_property_notify_event_t *e = (xcb_property_notify_event_t *)event; last_timestamp = e->time;