]> Dogcows Code - chaz/openbox/commitdiff
focus fallback works when nothing is focused
authorDana Jansens <danakj@orodu.net>
Tue, 18 Mar 2003 09:10:05 +0000 (09:10 +0000)
committerDana Jansens <danakj@orodu.net>
Tue, 18 Mar 2003 09:10:05 +0000 (09:10 +0000)
plugins/focus.c

index b717f38fd4916aa7fd507c2c80db0ade26d497fc..a95f8d69a1603702dc15e2b5b9941ee098ff455a 100644 (file)
@@ -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)
This page took 0.025205 seconds and 4 git commands to generate.