From ee77fce1cec6a99bdfa04b368affb759825c7ae5 Mon Sep 17 00:00:00 2001 From: Mariusz Ceier Date: Tue, 28 Apr 2009 10:54:10 +0200 Subject: [PATCH] Fix focus hooks calls This patch fixes focus hooks calls - for every call to focus hook, there should be call to unfocus hook. Focus related info: In this shape, awesome doesn't support multiple focused clients, that means it follows the rule "there is only a single focus", which is not true for MPX. To change this, I think it will need some magic with FocusOut events handling and changes to some structures (e.g. globalconf.screen_focus, screen_t.client_focus should be arrays) :p Now we don't need to handle FocusOut events. Signed-off-by: Mariusz Ceier Signed-off-by: Julien Danjou --- awesome.c | 1 + client.c | 18 ++++++++++++++---- event.c | 42 +++--------------------------------------- 3 files changed, 18 insertions(+), 43 deletions(-) diff --git a/awesome.c b/awesome.c index 530e756bc..5917a0067 100644 --- a/awesome.c +++ b/awesome.c @@ -498,6 +498,7 @@ main(int argc, char **argv) | XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE + | XCB_EVENT_MASK_FOCUS_CHANGE }; xcb_change_window_attributes(globalconf.connection, diff --git a/client.c b/client.c index 7fbae028f..ec1d5651c 100644 --- a/client.c +++ b/client.c @@ -187,11 +187,12 @@ client_unfocus_update(client_t *c) void client_unfocus(client_t *c) { - xcb_window_t root_win = xutil_screen_get(globalconf.connection, c->phys_screen)->root; - globalconf.screens.tab[c->phys_screen].client_focus = NULL; + xcb_window_t root_win = xutil_screen_get(globalconf.connection, c->phys_screen)->root; /* Set focus on root window, so no events leak to the current window. */ window_setfocus(root_win, true); + + client_unfocus_update(c); } /** Ban client and move it out of the viewport. @@ -239,6 +240,15 @@ client_focus_update(client_t *c) return; } + if(globalconf.screen_focus + && globalconf.screen_focus->client_focus) + { + if (globalconf.screen_focus->client_focus != c) + client_unfocus_update(globalconf.screen_focus->client_focus); + else + /* Already focused */ + return; + } /* stop hiding client */ c->ishidden = false; client_setminimized(c, false); @@ -281,8 +291,8 @@ client_focus(client_t *c) if(!client_maybevisible(c, c->screen)) return; - globalconf.screen_focus = &globalconf.screens.tab[c->phys_screen]; - globalconf.screen_focus->client_focus = c; + if (!c->nofocus) + client_focus_update(c); window_setfocus(c->win, !c->nofocus); } diff --git a/event.c b/event.c index 452107b79..7dbabe5a7 100644 --- a/event.c +++ b/event.c @@ -506,15 +506,8 @@ event_handle_focusin(void *data __attribute__ ((unused)), /* Events that we are interested in: */ switch(ev->detail) { - /* These are events that jump between windows of a toplevel client. - * - * NotifyVirtual event is handled in case where NotifyAncestor or - * NotifyInferior event is not generated on window that is managed by - * awesome ( client_* returns NULL ) - * - * Can someone explain exactly why they are needed ? + /* These are events that jump between root windows. */ - case XCB_NOTIFY_DETAIL_VIRTUAL: case XCB_NOTIFY_DETAIL_ANCESTOR: case XCB_NOTIFY_DETAIL_INFERIOR: @@ -528,37 +521,9 @@ event_handle_focusin(void *data __attribute__ ((unused)), client_focus_update(c); /* all other events are ignored */ default: - return 0; - } -} - -/** The focus out event handler. - * \param data currently unused. - * \param connection The connection to the X server. - * \param ev The event. - */ -static int -event_handle_focusout(void *data __attribute__ ((unused)), - xcb_connection_t *connection, - xcb_focus_out_event_t *ev) -{ - client_t *c; - - /* Events that we are interested in: */ - switch(ev->detail) - { - /* These are events that jump between clients. - * Virtual events ensure we always get an event on our top-level window. - */ - case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL: - case XCB_NOTIFY_DETAIL_NONLINEAR: - if((c = client_getbytitlebarwin(ev->event)) - || (c = client_getbywin(ev->event))) - client_unfocus_update(c); - /* all other events are ignored */ - default: - return 0; + break; } + return 0; } /** The expose event handler. @@ -851,7 +816,6 @@ void a_xcb_set_event_handlers(void) 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_focus_out_handler(&globalconf.evenths, event_handle_focusout, 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);