Add a dontStop option in <focus> to make alt-tab not stop when a new window opens.
authorMikael Magnusson <mikachu@comhem.se>
Sat, 26 Jan 2008 08:09:47 +0000 (09:09 +0100)
committerMikael Magnusson <mikachu@comhem.se>
Sat, 8 Mar 2008 16:21:36 +0000 (17:21 +0100)
Currently focus gets a bit messed up when a window closes because I
don't feel like tracking it down right now.

Also causes crashes when windows close and whatnot. Although i think
this was fixed recently by dana.

openbox/client.c
openbox/config.c
openbox/config.h
openbox/event.c
openbox/focus.c
openbox/focus_cycle.c
openbox/focus_cycle.h

index 55402cc65667fe4dd607a719a95bb6553b8c4165..da456bc12beb0fb254cc30fe6b940c28d0ffc9cc 100644 (file)
@@ -31,6 +31,7 @@
 #include "grab.h"
 #include "prompt.h"
 #include "focus.h"
+#include "focus_cycle.h"
 #include "stacking.h"
 #include "openbox.h"
 #include "hooks.h"
@@ -281,7 +282,8 @@ void client_manage(Window window, ObPrompt *prompt)
          client_search_focus_tree_full(self)) &&
         /* this checks for focus=false for the window */
         (!settings || settings->focus != 0) &&
-        focus_valid_target(self, FALSE, FALSE, TRUE, FALSE, FALSE))
+        focus_valid_target(self, FALSE, FALSE, TRUE, FALSE, FALSE) &&
+        (!focus_cycle_target || !config_focus_dontstop))
     {
         activate = TRUE;
     }
index cc86ce7cfa748fbc0da12148485a25ce2f396d05..91b2c6136e57c17af187cc8c8db8b8afdf592ebe 100644 (file)
@@ -35,6 +35,7 @@ guint    config_focus_delay;
 gboolean config_focus_raise;
 gboolean config_focus_last;
 gboolean config_focus_under_mouse;
+gboolean config_focus_dontstop;
 
 ObPlacePolicy  config_place_policy;
 gboolean       config_place_center;
@@ -536,6 +537,8 @@ static void parse_focus(xmlNodePtr node, gpointer d)
         config_focus_last = obt_parse_node_bool(n);
     if ((n = obt_parse_find_node(node, "underMouse")))
         config_focus_under_mouse = obt_parse_node_bool(n);
+    if ((n = obt_parse_find_node(node, "dontStop")))
+        config_focus_dontstop = obt_parse_node_bool(n);
 }
 
 static void parse_placement(xmlNodePtr node, gpointer d)
@@ -944,6 +947,7 @@ void config_startup(ObtParseInst *i)
     config_focus_raise = FALSE;
     config_focus_last = TRUE;
     config_focus_under_mouse = FALSE;
+    config_focus_dontstop = FALSE;
 
     obt_parse_register(i, "focus", parse_focus, NULL);
 
index cc5fa89af75d0902878aee76352509a83efb1b62..ca312735846abe7cdc470713121e7c1ed7671071 100644 (file)
@@ -73,6 +73,8 @@ extern gboolean config_focus_last;
 /*! Try keep focus on the window under the mouse when the mouse is not moving
  */
 extern gboolean config_focus_under_mouse;
+/*! Rather than cancelling alt-tab when a client (dis)appears, don't focus anything */
+extern gboolean config_focus_dontstop;
 
 /*! The algorithm to use for placing new windows */
 extern ObPlacePolicy config_place_policy;
index e6a5719c98b7bb24551b02f2fb92c3b20c53c58d..e604e7cbd04e78bb57391da4b6bf23af9388e0c5 100644 (file)
@@ -591,10 +591,12 @@ static void event_process(const XEvent *ec, gpointer data)
         }
         else if (client != focus_client) {
             focus_left_screen = FALSE;
-            frame_adjust_focus(client->frame, TRUE);
-            focus_set_client(client);
-            client_calc_layer(client);
-            client_bring_helper_windows(client);
+            if (!focus_cycle_target || !config_focus_dontstop) {
+                frame_adjust_focus(client->frame, TRUE);
+                focus_set_client(client);
+                client_calc_layer(client);
+                client_bring_helper_windows(client);
+            }
         }
     } else if (e->type == FocusOut) {
         XEvent ce;
index baf88e8134bcc8227c8706cdbae849184781da7e..413886d03c87b3efbf10fd764760f6e9cceb840b 100644 (file)
 ObClient *focus_client = NULL;
 GList *focus_order = NULL;
 
+static gboolean stop_or_cancel_cycle(ObClient *c)
+{
+    /* in the middle of cycling..? kill it.
+     * or stop focusing */
+    if (config_focus_dontstop)
+        return focus_interruptable(c);
+    else {
+        focus_cycle_stop(c);
+        return FALSE;
+    }
+}
+
 void focus_startup(gboolean reconfig)
 {
     if (reconfig) return;
@@ -81,13 +93,17 @@ void focus_set_client(ObClient *client)
     if (focus_client == client)
         return;
 
+    /* in the middle of cycling..? kill it. */
+    if (stop_or_cancel_cycle(focus_client) ||
+        stop_or_cancel_cycle(client))
+    {
+        return;
+    }
+
     /* uninstall the old colormap, and install the new one */
     screen_install_colormap(focus_client, FALSE);
     screen_install_colormap(client, TRUE);
 
-    /* in the middle of cycling..? kill it. */
-    focus_cycle_stop(focus_client);
-    focus_cycle_stop(client);
 
     old = focus_client;
     focus_client = client;
@@ -223,16 +239,14 @@ void focus_order_add_new(ObClient *c)
             focus_order = g_list_insert(focus_order, c, 1);
     }
 
-    /* in the middle of cycling..? kill it. */
-    focus_cycle_stop(c);
+    stop_or_cancel_cycle(c);
 }
 
 void focus_order_remove(ObClient *c)
 {
     focus_order = g_list_remove(focus_order, c);
 
-    /* in the middle of cycling..? kill it. */
-    focus_cycle_stop(c);
+    stop_or_cancel_cycle(c);
 }
 
 void focus_order_to_top(ObClient *c)
index 063de6447bfa3b5f44d9483a752e1ac768764888..14c6537478b7d218ff0fdb23f8af9d1cf254c6c3 100644 (file)
@@ -50,17 +50,21 @@ void focus_cycle_shutdown(gboolean reconfig)
     if (reconfig) return;
 }
 
-void focus_cycle_stop(ObClient *ifclient)
+gboolean focus_interruptable(ObClient *ifclient)
 {
     /* stop focus cycling if the given client is a valid focus target,
        and so the cycling is being disrupted */
-    if (focus_cycle_target && ifclient &&
-        focus_valid_target(ifclient, TRUE,
-                           focus_cycle_iconic_windows,
-                           focus_cycle_all_desktops,
-                           focus_cycle_dock_windows,
-                           focus_cycle_desktop_windows))
-    {
+    return focus_cycle_target && ifclient &&
+           focus_valid_target(ifclient, TRUE,
+                              focus_cycle_iconic_windows,
+                              focus_cycle_all_desktops,
+                              focus_cycle_dock_windows,
+                              focus_cycle_desktop_windows);
+}
+
+void focus_cycle_stop(ObClient *ifclient)
+{
+    if (focus_interruptable(ifclient)) {
         focus_cycle(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,TRUE);
         focus_directional_cycle(0, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
     }
index c31abc81f47abe8165030342703c28e95604e2d2..e19060382227083e0f9856d08e5089e3d5593f27 100644 (file)
@@ -48,6 +48,7 @@ struct _ObClient* focus_directional_cycle(ObDirection dir,
                                           gboolean dialog,
                                           gboolean done, gboolean cancel);
 
+gboolean focus_interruptable(struct _ObClient *ifclient);
 void focus_cycle_stop(struct _ObClient *ifclient);
 
 #endif