]> Dogcows Code - chaz/openbox/blobdiff - openbox/focus.c
debug print in focus.c
[chaz/openbox] / openbox / focus.c
index 42241224534e35fc07f021b0c4f86d4d0d1705c3..0f399be73e02a21e2817df2ec8fe4ea570a21b17 100644 (file)
@@ -94,20 +94,24 @@ void focus_set_client(ObClient *client)
     }
 }
 
-static ObClient* focus_fallback_target(gboolean allow_refocus)
+static ObClient* focus_fallback_target(gboolean allow_refocus, ObClient *old,
+                                       gboolean send_focus)
 {
     GList *it;
     ObClient *c;
-    ObClient *old = focus_client;
 
     ob_debug_type(OB_DEBUG_FOCUS, "trying pointer stuff\n");
     if (config_focus_follow && !config_focus_last)
         if ((c = client_under_pointer()) &&
             (allow_refocus || c != old) &&
-            (client_normal(c) &&
-             client_focus(c)))
+            client_normal(c) &&
+            /* if we're sending focus then try to */
+            ((send_focus && client_focus(c)) ||
+             /* if not just see if we could try, or it's already focused */
+             (!send_focus && (c == old || client_can_focus(c)))))
         {
-            ob_debug_type(OB_DEBUG_FOCUS, "found in pointer stuff\n");
+            ob_debug_type(OB_DEBUG_FOCUS, "found in pointer stuff (%d)\n",
+                          send_focus);
             return c;
         }
 
@@ -115,9 +119,11 @@ static ObClient* focus_fallback_target(gboolean allow_refocus)
     if (allow_refocus && old &&
         old->desktop == DESKTOP_ALL &&
         client_normal(old) &&
-        client_focus(old))
+        /* this one is only for when not sending focus, to keep it there */
+        !send_focus)
     {
-        ob_debug_type(OB_DEBUG_FOCUS, "found in omnipresentness\n");
+        ob_debug_type(OB_DEBUG_FOCUS, "found in omnipresentness (%d)\n",
+                      send_focus);
         return old;
     }
 
@@ -135,9 +141,14 @@ static ObClient* focus_fallback_target(gboolean allow_refocus)
         if (c->desktop == screen_desktop &&
             client_normal(c) &&
             (allow_refocus || c != old) &&
-            client_focus(c))
+            /* if we're sending focus then try to */
+            ((send_focus && client_focus(c)) ||
+             /* if not just see if we could try, or it's already focused */
+             (!send_focus && (c == old || client_can_focus(c)))))
         {
-            ob_debug_type(OB_DEBUG_FOCUS, "found in focus order\n");
+            ob_debug_type(OB_DEBUG_FOCUS, "found in focus order (%d) 0x%x "
+                          "from 0x%x\n",
+                          send_focus, c, old);
             return c;
         }
     }
@@ -154,9 +165,13 @@ static ObClient* focus_fallback_target(gboolean allow_refocus)
         */
         if (c->type == OB_CLIENT_TYPE_DESKTOP &&
             (allow_refocus || c != old) &&
-            client_focus(c))
+            /* if we're sending focus then try to */
+            ((send_focus && client_focus(c)) ||
+             /* if not just see if we could try, or it's already focused */
+             (!send_focus && (c == old || client_can_focus(c)))))
         {
-            ob_debug_type(OB_DEBUG_FOCUS, "found a desktop window\n");
+            ob_debug_type(OB_DEBUG_FOCUS, "found a desktop window (%d)\n",
+                          send_focus);
             return c;
         }
     }
@@ -167,13 +182,17 @@ static ObClient* focus_fallback_target(gboolean allow_refocus)
 ObClient* focus_fallback(gboolean allow_refocus)
 {
     ObClient *new;
+    ObClient *old = focus_client;
+
+    new = focus_fallback_target(allow_refocus, old, FALSE);
+    if (new == old) return;
 
     /* unfocus any focused clients.. they can be focused by Pointer events
        and such, and then when we try focus them, we won't get a FocusIn
        event at all for them. */
     focus_nothing();
 
-    new = focus_fallback_target(allow_refocus);
+    new = focus_fallback_target(allow_refocus, old, TRUE);
 
     return new;
 }
@@ -186,12 +205,8 @@ void focus_nothing()
         screen_install_colormap(NULL, TRUE);
     }
 
-    /* Don't set focus_client to NULL here. It will be set to NULL when the
-       FocusOut event comes. Otherwise, if we focus nothing and then focus the
-       same window again, The focus code says nothing changed, but focus_client
-       ends up being NULL anyways.
-    focus_client = NULL;
-    */
+    /* nothing is focused, update the colormap and _the root property_ */
+    focus_set_client(NULL);
 
     /* if there is a grab going on, then we need to cancel it. if we move
        focus during the grab, applications will get NotifyWhileGrabbed events
This page took 0.022189 seconds and 4 git commands to generate.