From: Dana Jansens Date: Tue, 18 Mar 2003 09:10:05 +0000 (+0000) Subject: focus fallback works when nothing is focused X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=20a5dd4745c935fcd19850a24b0e2fdfa0d24add;p=chaz%2Fopenbox focus fallback works when nothing is focused --- diff --git a/plugins/focus.c b/plugins/focus.c index b717f38f..a95f8d69 100644 --- a/plugins/focus.c +++ b/plugins/focus.c @@ -1,6 +1,7 @@ #include "../kernel/dispatch.h" #include "../kernel/screen.h" #include "../kernel/client.h" +#include "../kernel/focus.h" #include "../kernel/stacking.h" static GSList **focus_order = NULL; @@ -18,6 +19,11 @@ static void events(ObEvent *e, void *foo) client_focus(e->data.c.client); break; + case Event_Client_Destroy: + i = e->data.c.client->desktop; + focus_order[i] = g_slist_remove(focus_order[i], e->data.c.client); + break; + case Event_Ob_NumDesktops: new = e->data.o.num[0]; old = e->data.o.num[1]; @@ -43,11 +49,22 @@ static void events(ObEvent *e, void *foo) break; case Event_Ob_Desktop: - for (it = focus_order[e->data.o.num[0]]; it != NULL; it = it->next) + /* focus the next available target */ + new = e->data.o.num[0]; + for (it = focus_order[new]; it != NULL; it = it->next) if (client_focus(it->data)) break; break; + case Event_Client_Unfocus: + if (focus_client == NULL) { /* nothing is left with focus! */ + /* focus the next available target */ + for (it = focus_order[screen_desktop]; it != NULL; it = it->next) + if (client_focus(it->data)) + break; + } + break; + case Event_Client_Focus: /* move to the top of the list */ focus_order[e->data.c.num[1]] = @@ -65,9 +82,11 @@ void plugin_startup() { guint i; - dispatch_register(Event_Client_Mapped | Event_Ob_Desktop | - Event_Ob_NumDesktops | Event_Client_Focus | - Event_Client_Desktop, (EventHandler)events, NULL); + dispatch_register(Event_Client_Mapped | Event_Client_Destroy | + Event_Ob_Desktop | Event_Ob_NumDesktops | + Event_Client_Focus | Event_Client_Unfocus | + Event_Client_Desktop, + (EventHandler)events, NULL); focus_order = g_new(GSList*, screen_num_desktops); for (i = 0; i < screen_num_desktops; ++i)