]> Dogcows Code - chaz/openbox/blobdiff - openbox/event.c
fixes from commit 0ce14a727968736e57fb3fabba3794b46903875f
[chaz/openbox] / openbox / event.c
index e3214a7a1bd768a9b8d0abe01d0d41fa58ee1be5..cc3ea68fe261a2cb6b7d1d5413de604f2db2357a 100644 (file)
@@ -74,6 +74,7 @@ typedef struct
 {
     ObClient *client;
     Time time;
+    gulong serial;
 } ObFocusDelayData;
 
 typedef struct
@@ -91,6 +92,7 @@ static void event_handle_dockapp(ObDockApp *app, XEvent *e);
 static void event_handle_client(ObClient *c, XEvent *e);
 static void event_handle_user_input(ObClient *client, XEvent *e);
 static gboolean is_enter_focus_event_ignored(XEvent *e);
+static void event_ignore_enter_range(gulong start, gulong end);
 
 static void focus_delay_dest(gpointer data);
 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2);
@@ -99,6 +101,8 @@ static void focus_delay_client_dest(ObClient *client, gpointer data);
 
 Time event_curtime = CurrentTime;
 Time event_last_user_time = CurrentTime;
+/*! The serial of the current X event */
+gulong event_curserial;
 
 static gboolean focus_left_screen = FALSE;
 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
@@ -479,6 +483,7 @@ static void event_process(const XEvent *ec, gpointer data)
     }
 
     event_set_curtime(e);
+    event_curserial = e->xany.serial;
     event_hack_mods(e);
     if (event_ignore(e, client)) {
         if (ed)
@@ -689,16 +694,55 @@ static void event_process(const XEvent *ec, gpointer data)
     }
 #endif
 
-    if (e->type == ButtonPress || e->type == ButtonRelease ||
-        e->type == MotionNotify || e->type == KeyPress ||
-        e->type == KeyRelease)
-    {
-        event_handle_user_input(client, e);
+    if (e->type == ButtonPress || e->type == ButtonRelease) {
+        /* If the button press was on some non-root window, or was physically
+           on the root window, the process it */
+        if (window != RootWindow(ob_display, ob_screen) ||
+            e->xbutton.subwindow == None)
+        {
+            event_handle_user_input(client, e);
+        }
+        /* Otherwise only process it if it was physically on an openbox
+           internal window */
+        else {
+            Window target, parent, root, *children;
+            unsigned int nchildren;
+            ObWindow *w;
+
+            /* Find the top level ancestor of the subwindow, besides the
+               root */
+            target = e->xbutton.subwindow;
+            ob_debug("subwindow 0x%x\n", target);
+            while (XQueryTree(ob_display, target, &root, &parent, &children,
+                              &nchildren) != 0)
+            {
+                XFree(children);
+                if (parent == root) {
+                    ob_debug("parent is root\n");
+                    break;
+                }
+                target = parent;
+            }
+            ob_debug("toplevel 0x%x\n", target);
+
+            w = g_hash_table_lookup(window_map, &target);
+            ob_debug("w 0x%x\n", w);
+                
+            if ((w = g_hash_table_lookup(window_map, &target)) &&
+                WINDOW_IS_INTERNAL(w))
+            {
+                event_handle_user_input(client, e);
+            }
+        }
     }
+    else if (e->type == KeyPress || e->type == KeyRelease ||
+             e->type == MotionNotify)
+        event_handle_user_input(client, e);
 
     /* if something happens and it's not from an XEvent, then we don't know
        the time */
     event_curtime = CurrentTime;
+    event_curserial = 0;
 }
 
 static void event_handle_root(XEvent *e)
@@ -773,6 +817,7 @@ void event_enter_client(ObClient *client)
             data = g_new(ObFocusDelayData, 1);
             data->client = client;
             data->time = event_curtime;
+            data->serial = event_curserial;
 
             ob_main_loop_timeout_add(ob_main_loop,
                                      config_focus_delay * 1000,
@@ -782,6 +827,7 @@ void event_enter_client(ObClient *client)
             ObFocusDelayData data;
             data.client = client;
             data.time = event_curtime;
+            data.serial = event_curserial;
             focus_delay_func(&data);
         }
     }
@@ -1010,18 +1056,23 @@ static void event_handle_client(ObClient *client, XEvent *e)
                 is_enter_focus_event_ignored(e))
             {
                 ob_debug_type(OB_DEBUG_FOCUS,
-                              "%sNotify mode %d detail %d on %lx IGNORED\n",
+                              "%sNotify mode %d detail %d serial %lu on %lx "
+                              "IGNORED\n",
                               (e->type == EnterNotify ? "Enter" : "Leave"),
                               e->xcrossing.mode,
-                              e->xcrossing.detail, client?client->window:0);
+                              e->xcrossing.detail,
+                              e->xcrossing.serial,
+                              client?client->window:0);
             }
             else {
                 ob_debug_type(OB_DEBUG_FOCUS,
-                              "%sNotify mode %d detail %d on %lx, "
+                              "%sNotify mode %d detail %d serial %lu on %lx, "
                               "focusing window\n",
                               (e->type == EnterNotify ? "Enter" : "Leave"),
                               e->xcrossing.mode,
-                              e->xcrossing.detail, (client?client->window:0));
+                              e->xcrossing.detail,
+                              e->xcrossing.serial,
+                              (client?client->window:0));
                 if (config_focus_follow)
                     event_enter_client(client);
             }
@@ -1864,10 +1915,9 @@ static gboolean focus_delay_func(gpointer data)
     if (menu_frame_visible || moveresize_in_progress) return FALSE;
 
     event_curtime = d->time;
-    if (focus_client != d->client) {
-        if (client_focus(d->client) && config_focus_raise)
-            stacking_raise(CLIENT_AS_WINDOW(d->client));
-    }
+    event_curserial = d->serial;
+    if (client_focus(d->client) && config_focus_raise)
+        stacking_raise(CLIENT_AS_WINDOW(d->client));
     event_curtime = old;
     return FALSE; /* no repeat */
 }
@@ -1878,10 +1928,10 @@ static void focus_delay_client_dest(ObClient *client, gpointer data)
                                      client, FALSE);
 }
 
-void event_halt_focus_delay(void)
+void event_halt_focus_delay()
 {
-    /* ignore all enter events up till now */
-    event_end_ignore_all_enters(1);
+    /* ignore all enter events up till the event which caused this to occur */
+    if (event_curserial) event_ignore_enter_range(1, event_curserial);
     ob_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
 }
 
@@ -1891,22 +1941,31 @@ gulong event_start_ignore_all_enters(void)
     return LastKnownRequestProcessed(ob_display);
 }
 
-void event_end_ignore_all_enters(gulong start)
+static void event_ignore_enter_range(gulong start, gulong end)
 {
     ObSerialRange *r;
 
     g_assert(start != 0);
-    XSync(ob_display, FALSE);
+    g_assert(end != 0);
 
     r = g_new(ObSerialRange, 1);
     r->start = start;
-    r->end = LastKnownRequestProcessed(ob_display);
+    r->end = end;
     ignore_serials = g_slist_prepend(ignore_serials, r);
 
+    ob_debug_type(OB_DEBUG_FOCUS, "ignoring enters from %lu until %lu\n",
+                  r->start, r->end);
+
     /* increment the serial so we don't ignore events we weren't meant to */
     XSync(ob_display, FALSE);
 }
 
+void event_end_ignore_all_enters(gulong start)
+{
+    XSync(ob_display, FALSE);
+    event_ignore_enter_range(start, LastKnownRequestProcessed(ob_display));
+}
+
 static gboolean is_enter_focus_event_ignored(XEvent *e)
 {
     GSList *it, *next;
This page took 0.024245 seconds and 4 git commands to generate.