]> Dogcows Code - chaz/openbox/blobdiff - openbox/event.c
don't assert, users can bind stuff however they like. but if they do something that...
[chaz/openbox] / openbox / event.c
index 9d8c5f3c9af80e0f9ee84a48d320b32f3877828d..a2571f0e112dac34c82fca7e537b48b07d003b6b 100644 (file)
@@ -307,15 +307,26 @@ static gboolean wanted_focusevent(XEvent *e, gboolean in_client_only)
                 return FALSE;
         }
 
+        /* This means focus moved to the frame window */
+        if (detail == NotifyInferior && !in_client_only)
+            return TRUE;
+
+        /* It was on a client, was it a valid one?
+           It's possible to get a FocusIn event for a client that was managed
+           but has disappeared.
+        */
+        if (in_client_only) {
+            ObWindow *w = g_hash_table_lookup(window_map, &e->xfocus.window);
+            if (!w || !WINDOW_IS_CLIENT(w))
+                return FALSE;
+        }
+
         /* This means focus moved from the root window to a client */
         if (detail == NotifyVirtual)
             return TRUE;
         /* This means focus moved from one client to another */
         if (detail == NotifyNonlinearVirtual)
             return TRUE;
-        /* This means focus moved to the frame window */
-        if (detail == NotifyInferior && !in_client_only)
-            return TRUE;
 
         /* Otherwise.. */
         return FALSE;
@@ -356,8 +367,7 @@ static Bool event_look_for_focusin(Display *d, XEvent *e, XPointer arg)
 
 Bool event_look_for_focusin_client(Display *d, XEvent *e, XPointer arg)
 {
-    return e->type == FocusIn && wanted_focusevent(e, TRUE) &&
-        e->xfocus.window != screen_support_win;
+    return e->type == FocusIn && wanted_focusevent(e, TRUE);
 }
 
 static void print_focusevent(XEvent *e)
@@ -384,6 +394,9 @@ static void print_focusevent(XEvent *e)
     case NotifyDetailNone:  detailstr="NotifyDetailNone";  break;
     }
 
+    if (mode == NotifyGrab || mode == NotifyUngrab)
+        return;
+
     g_assert(modestr);
     g_assert(detailstr);
     ob_debug_type(OB_DEBUG_FOCUS, "Focus%s 0x%x mode=%s detail=%s\n",
@@ -470,6 +483,7 @@ static void event_process(const XEvent *ec, gpointer data)
             e->xfocus.detail == NotifyInferior)
         {
             XEvent ce;
+
             ob_debug_type(OB_DEBUG_FOCUS,
                           "Focus went to pointer root/none or to our frame "
                           "window\n");
@@ -508,7 +522,28 @@ static void event_process(const XEvent *ec, gpointer data)
                 if (!focus_left_screen)
                     focus_fallback(TRUE);
             }
-        } else if (client && client != focus_client) {
+        }
+        else if (!client)
+        {
+            XEvent ce;
+
+            ob_debug_type(OB_DEBUG_FOCUS,
+                          "Focus went to a window that is already gone\n");
+
+            /* If you send focus to a window and then it disappears, you can
+               get the FocusIn FocusOut for it, after it is unmanaged.
+            */
+            if (XCheckIfEvent(ob_display, &ce, event_look_for_focusin_client,
+                              NULL))
+            {
+                XPutBackEvent(ob_display, &ce);
+                ob_debug_type(OB_DEBUG_FOCUS,
+                              "  but another FocusIn is coming\n");
+            } else {
+                focus_fallback(TRUE);
+            }
+        }
+        else if (client != focus_client) {
             focus_left_screen = FALSE;
             frame_adjust_focus(client->frame, TRUE);
             focus_set_client(client);
@@ -561,6 +596,8 @@ static void event_process(const XEvent *ec, gpointer data)
 
         if (client && !nomove) {
             frame_adjust_focus(client->frame, FALSE);
+            if (client == focus_client)
+                focus_set_client(NULL);
             /* focus_set_client has already been called for sure */
             client_calc_layer(client);
         }
@@ -669,7 +706,7 @@ static void event_handle_root(XEvent *e)
                 screen_set_num_desktops(d);
         } else if (msgtype == prop_atoms.net_showing_desktop) {
             screen_show_desktop(e->xclient.data.l[0] != 0, NULL);
-        } else if (msgtype == prop_atoms.openbox_control) {
+        } else if (msgtype == prop_atoms.ob_control) {
             if (e->xclient.data.l[0] == 1)
                 ob_reconfigure();
             else if (e->xclient.data.l[0] == 2)
This page took 0.023734 seconds and 4 git commands to generate.