From e8de7a4605edb22391ee02ead1e478dc2afe300a Mon Sep 17 00:00:00 2001 From: Mariusz Ceier Date: Thu, 23 Apr 2009 18:05:30 +0200 Subject: [PATCH] Focus stealing prevention - should fix FS#497 We should prevent focus stealing, in case when there are e.g. 2 clients on separate tags, first client has focus, and we receive FocusIn event for second (invisible) client. This patch adds prevention in the focus update handler. It sets focus on previously focused client, when FocusIn event destination is invisible(untagged) client. This should fix FS#497. Signed-off-by: Mariusz Ceier Signed-off-by: Julien Danjou --- client.c | 11 +++++++++++ screen.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/client.c b/client.c index cefd5dab..5b00a8e1 100644 --- a/client.c +++ b/client.c @@ -217,6 +217,9 @@ client_ban(client_t *c) if(client_hasstrut(c)) wibox_update_positions(); + if(globalconf.screens.tab[c->phys_screen].prev_client_focus == c) + globalconf.screens.tab[c->phys_screen].prev_client_focus = NULL; + /* Wait until the last moment to take away the focus from the window. */ if(globalconf.screens.tab[c->phys_screen].client_focus == c) client_unfocus(c); @@ -230,7 +233,11 @@ void client_focus_update(client_t *c) { if(!client_maybevisible(c, c->screen)) + { + /* Focus previously focused client */ + client_focus(globalconf.screen_focus->prev_client_focus); return; + } /* stop hiding client */ c->ishidden = false; @@ -240,6 +247,7 @@ client_focus_update(client_t *c) client_unban(c); globalconf.screen_focus = &globalconf.screens.tab[c->phys_screen]; + globalconf.screen_focus->prev_client_focus = c; globalconf.screen_focus->client_focus = c; /* Some layouts use focused client differently, so call them back. @@ -1224,6 +1232,9 @@ client_unmanage(client_t *c) tc->transient_for = NULL; } + if(globalconf.screens.tab[c->phys_screen].prev_client_focus == c) + globalconf.screens.tab[c->phys_screen].prev_client_focus = NULL; + if(globalconf.screens.tab[c->phys_screen].client_focus == c) client_unfocus(c); diff --git a/screen.h b/screen.h index 8e6ebef1..7a68fd9e 100644 --- a/screen.h +++ b/screen.h @@ -43,6 +43,8 @@ struct a_screen /** Systray window parent */ xcb_window_t parent; } systray; + /** Previously focused client */ + client_t *prev_client_focus; /** Focused client */ client_t *client_focus; /** The monitor of startup notifications */