diff --git a/event.c b/event.c index 944c241c..ce208227 100644 --- a/event.c +++ b/event.c @@ -548,6 +548,32 @@ event_handle_enternotify(void *data __attribute__ ((unused)), return 0; } +/** The focus in event handler. + * \param data currently unused. + * \param connection The connection to the X server. + * \param ev The event. + */ +static int +event_handle_focusin(void *data __attribute__ ((unused)), + xcb_connection_t *connection, + xcb_focus_in_event_t *ev) +{ + /* filter focus-in events */ + if(ev->mode != XCB_NOTIFY_MODE_NORMAL + && (ev->detail == XCB_NOTIFY_DETAIL_VIRTUAL + || ev->detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL + || ev->detail == XCB_NOTIFY_DETAIL_POINTER)) + return 0; + + client_t *c; + + if((c = client_getbytitlebarwin(ev->event)) + || (c = client_getbywin(ev->event))) + client_focus(c, false); + + return 0; +} + /** The expose event handler. * \param data currently unused. * \param connection The connection to the X server. @@ -864,6 +890,7 @@ void a_xcb_set_event_handlers(void) xcb_event_set_destroy_notify_handler(&globalconf.evenths, event_handle_destroynotify, NULL); xcb_event_set_enter_notify_handler(&globalconf.evenths, event_handle_enternotify, NULL); xcb_event_set_leave_notify_handler(&globalconf.evenths, event_handle_leavenotify, NULL); + xcb_event_set_focus_in_handler(&globalconf.evenths, event_handle_focusin, NULL); xcb_event_set_motion_notify_handler(&globalconf.evenths, event_handle_motionnotify, NULL); xcb_event_set_expose_handler(&globalconf.evenths, event_handle_expose, NULL); xcb_event_set_key_press_handler(&globalconf.evenths, event_handle_key, NULL);