merge r5777-r5778 from trunk
authorDana Jansens <danakj@orodu.net>
Sun, 22 Apr 2007 14:11:42 +0000 (14:11 +0000)
committerDana Jansens <danakj@orodu.net>
Sun, 22 Apr 2007 14:11:42 +0000 (14:11 +0000)
openbox/action.c
openbox/client.c
openbox/event.c
openbox/grab.c
openbox/grab.h
openbox/keyboard.c
openbox/menuframe.c
openbox/moveresize.c

index 5456c80e06acccfcd1cca16f59ba9ae88ec2f19c..fc6f5a78292b2d9dffa8b1df44171079a271277d 100644 (file)
@@ -41,7 +41,7 @@ inline void client_action_start(union ActionData *data)
 {
     if (config_focus_follow)
         if (data->any.context != OB_FRAME_CONTEXT_CLIENT && !data->any.button)
-            grab_pointer(TRUE, OB_CURSOR_NONE);
+            grab_pointer(TRUE, FALSE, OB_CURSOR_NONE);
 }
 
 inline void client_action_end(union ActionData *data)
@@ -49,7 +49,7 @@ inline void client_action_end(union ActionData *data)
     if (config_focus_follow)
         if (data->any.context != OB_FRAME_CONTEXT_CLIENT) {
             if (!data->any.button) {
-                grab_pointer(FALSE, OB_CURSOR_NONE);
+                grab_pointer(FALSE, FALSE, OB_CURSOR_NONE);
             } else {
                 ObClient *c;
 
index e801ac1858d2990e37a0de577c0d67e3ec71ba05..e7af570150a7040868231c41851ef0f8fb889c54 100644 (file)
@@ -77,7 +77,6 @@ static void client_apply_startup_state(ObClient *self, gint x, gint y);
 static void client_restore_session_state(ObClient *self);
 static void client_restore_session_stacking(ObClient *self);
 static ObAppSettings *client_get_settings_state(ObClient *self);
-static void client_unfocus(ObClient *self);
 
 void client_startup(gboolean reconfig)
 {
@@ -507,8 +506,8 @@ void client_unmanage(ObClient *self)
 
     g_assert(self != NULL);
 
-    /* update the focus lists */
-    focus_order_remove(self);
+    frame_hide(self->frame);
+    XSync(ob_display, FALSE);
 
     if (focus_client == self) {
         XEvent e;
@@ -516,20 +515,8 @@ void client_unmanage(ObClient *self)
         /* focus the last focused window on the desktop, and ignore enter
            events from the unmap so it doesnt mess with the focus */
         while (XCheckTypedEvent(ob_display, EnterNotify, &e));
-        /* remove these flags so we don't end up getting focused in the
-           fallback! */
-        self->can_focus = FALSE;
-        self->focus_notify = FALSE;
-        self->modal = FALSE;
-        client_unfocus(self);
     }
 
-    /* potentially fix focusLast */
-    if (config_focus_last)
-        grab_pointer(TRUE, OB_CURSOR_NONE);
-
-    frame_hide(self->frame);
-    XFlush(ob_display);
 
     keyboard_grab_for_client(self, FALSE);
     mouse_grab_for_client(self, FALSE);
@@ -540,6 +527,9 @@ void client_unmanage(ObClient *self)
     /* we dont want events no more */
     XSelectInput(ob_display, self->window, NoEventMask);
 
+    /* update the focus lists */
+    focus_order_remove(self);
+
     client_list = g_list_remove(client_list, self);
     stacking_remove(self);
     g_hash_table_remove(window_map, &self->window);
@@ -639,9 +629,6 @@ void client_unmanage(ObClient *self)
      
     /* update the list hints */
     client_set_list();
-
-    if (config_focus_last)
-        grab_pointer(FALSE, OB_CURSOR_NONE);
 }
 
 static ObAppSettings *client_get_settings_state(ObClient *self)
@@ -3054,19 +3041,6 @@ gboolean client_focus(ObClient *self)
     return TRUE;
 }
 
-/* Used when the current client is closed or otherwise hidden, focus_last will
-   then prevent focus from going to the mouse pointer
-*/
-static void client_unfocus(ObClient *self)
-{
-    if (focus_client == self) {
-#ifdef DEBUG_FOCUS
-        ob_debug("client_unfocus for %lx\n", self->window);
-#endif
-        focus_fallback(FALSE);
-    }
-}
-
 void client_activate(ObClient *self, gboolean here, gboolean user)
 {
     guint32 last_time = focus_client ? focus_client->user_time : CurrentTime;
index 9a1e13dc831becd6c2baf1282d2033a7a32d93b7..871b158a491591210b716ff09eec73404725de67 100644 (file)
@@ -393,17 +393,13 @@ static Bool look_for_focusin(Display *d, XEvent *e, XPointer arg)
 static gboolean event_ignore(XEvent *e, ObClient *client)
 {
     switch(e->type) {
-    case EnterNotify:
-    case LeaveNotify:
-        return keyboard_interactively_grabbed();
     case FocusIn:
     case FocusOut:
-        /* I don't think this should ever happen with our event masks, but
-           if it does, we don't want it. */
-        if (client == NULL)
-            return TRUE;
-        if (!wanted_focusevent(e))
+        if (!wanted_focusevent(e)) {
+            ob_debug_type(OB_DEBUG_FOCUS, "focus event ignored\n");
             return TRUE;
+        }
+        ob_debug_type(OB_DEBUG_FOCUS, "focus event used;\n");
         break;
     }
     return FALSE;
@@ -485,6 +481,58 @@ static void event_process(const XEvent *ec, gpointer data)
     {
         /* crossing events for menu */
         event_handle_menu(e);
+    } else if (e->type == FocusIn) {
+        if (e->xfocus.detail == NotifyPointerRoot ||
+                   e->xfocus.detail == NotifyDetailNone) {
+            ob_debug_type(OB_DEBUG_FOCUS, "Focus went to root\n");
+            /* Focus has been reverted to the root window or nothing, so fall
+               back to something other than the window which just had it. */
+            focus_fallback(FALSE);
+        } else if (e->xfocus.detail == NotifyInferior) {
+            ob_debug_type(OB_DEBUG_FOCUS, "Focus went to parent\n");
+            /* Focus has been reverted to parent, which is our frame window,
+               or the root window, so fall back to something other than the
+               window which had it. */
+            focus_fallback(FALSE);
+        } else if (client && client != focus_client) {
+            focus_set_client(client);
+            frame_adjust_focus(client->frame, TRUE);
+            client_calc_layer(client);
+        }
+    } else if (e->type == FocusOut) {
+        gboolean nomove = FALSE;
+        XEvent ce;
+
+        ob_debug_type(OB_DEBUG_FOCUS, "FocusOut Event\n");
+
+        /* Look for the followup FocusIn */
+        if (!XCheckIfEvent(ob_display, &ce, look_for_focusin, NULL)) {
+            /* There is no FocusIn, this means focus went to a window that
+               is not being managed, or a window on another screen. */
+            ob_debug_type(OB_DEBUG_FOCUS, "Focus went to a black hole !\n");
+        } else if (ce.xany.window == e->xany.window) {
+            /* If focus didn't actually move anywhere, there is nothing to do*/
+            nomove = TRUE;
+        } else {
+            /* Focus did move, so process the FocusIn event */
+            ObEventData ed = { .ignored = FALSE };
+            event_process(&ce, &ed);
+            if (ed.ignored) {
+                /* The FocusIn was ignored, this means it was on a window
+                   that isn't a client. */
+                ob_debug_type(OB_DEBUG_FOCUS,
+                              "Focus went to an unmanaged window 0x%x !\n",
+                              ce.xfocus.window);
+                focus_fallback(TRUE);
+            }
+        }
+
+        if (client && !nomove) {
+            /* This client is no longer focused, so show that */
+            focus_hilite = NULL;
+            frame_adjust_focus(client->frame, FALSE);
+            client_calc_layer(client);
+        }
     } else if (group)
         event_handle_group(group, e);
     else if (client)
@@ -690,53 +738,6 @@ static void event_handle_client(ObClient *client, XEvent *e)
             }
         }
         break;
-    case FocusIn:
-        if (client != focus_client) {
-            focus_set_client(client);
-            frame_adjust_focus(client->frame, TRUE);
-            client_calc_layer(client);
-        }
-        break;
-    case FocusOut:
-        /* Look for the followup FocusIn */
-        if (!XCheckIfEvent(ob_display, &ce, look_for_focusin, NULL)) {
-            /* There is no FocusIn, this means focus went to a window that
-               is not being managed, or a window on another screen. */
-            ob_debug_type(OB_DEBUG_FOCUS, "Focus went to a black hole !\n");
-        } else if (ce.xany.window == e->xany.window) {
-            /* If focus didn't actually move anywhere, there is nothing to do*/
-            break;
-        } else if (ce.xfocus.detail == NotifyPointerRoot ||
-                 ce.xfocus.detail == NotifyDetailNone) {
-            ob_debug_type(OB_DEBUG_FOCUS, "Focus went to root\n");
-            /* Focus has been reverted to the root window or nothing, so fall
-               back to something other than the window which just had it. */
-            focus_fallback(FALSE);
-        } else if (ce.xfocus.detail == NotifyInferior) {
-            ob_debug_type(OB_DEBUG_FOCUS, "Focus went to parent\n");
-            /* Focus has been reverted to parent, which is our frame window,
-               or the root window, so fall back to something other than the
-               window which had it. */
-            focus_fallback(FALSE);
-        } else {
-            /* Focus did move, so process the FocusIn event */
-            ObEventData ed = { .ignored = FALSE };
-            event_process(&ce, &ed);
-            if (ed.ignored) {
-                /* The FocusIn was ignored, this means it was on a window
-                   that isn't a client. */
-                ob_debug_type(OB_DEBUG_FOCUS,
-                              "Focus went to an unmanaged window 0x%x !\n",
-                              ce.xfocus.window);
-                focus_fallback(TRUE);
-            }
-        }
-
-        /* This client is no longer focused, so show that */
-        focus_hilite = NULL;
-        frame_adjust_focus(client->frame, FALSE);
-        client_calc_layer(client);
-        break;
     case LeaveNotify:
         con = frame_context(client, e->xcrossing.window);
         switch (con) {
index 9b19906a340b7289a20f7a0256a38dbb8dec02e7..dfff9570e3c6dab1aa8a9e4e2590f7236fca58a9 100644 (file)
@@ -26,8 +26,7 @@
 #include <glib.h>
 #include <X11/Xlib.h>
 
-#define GRAB_PTR_MASK (ButtonPressMask | ButtonReleaseMask | \
-                       PointerMotionMask | EnterWindowMask | LeaveWindowMask)
+#define GRAB_PTR_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
 #define GRAB_KEY_MASK (KeyPressMask | KeyReleaseMask)
 
 #define MASK_LIST_SIZE 8
@@ -90,15 +89,15 @@ gboolean grab_keyboard(gboolean grab)
     return ret;
 }
 
-gboolean grab_pointer(gboolean grab, ObCursor cur)
+gboolean grab_pointer(gboolean grab, gboolean owner_events, ObCursor cur)
 {
     gboolean ret = FALSE;
 
     if (grab) {
         if (pgrabs++ == 0) {
-            ret = XGrabPointer(ob_display, screen_support_win,
-                               True, GRAB_PTR_MASK, GrabModeAsync,
-                               GrabModeAsync, None,
+            ret = XGrabPointer(ob_display, screen_support_win, owner_events,
+                               GRAB_PTR_MASK,
+                               GrabModeAsync, GrabModeAsync, None,
                                ob_cursor(cur), event_curtime) == Success;
             if (!ret)
                 --pgrabs;
@@ -115,13 +114,15 @@ gboolean grab_pointer(gboolean grab, ObCursor cur)
     return ret;
 }
 
-gboolean grab_pointer_window(gboolean grab, ObCursor cur, Window win)
+gboolean grab_pointer_window(gboolean grab, gboolean owner_events,
+                             ObCursor cur, Window win)
 {
     gboolean ret = FALSE;
 
     if (grab) {
         if (pgrabs++ == 0) {
-            ret = XGrabPointer(ob_display, win, True, GRAB_PTR_MASK,
+            ret = XGrabPointer(ob_display, win, owner_events,
+                               GRAB_PTR_MASK,
                                GrabModeAsync, GrabModeAsync, None,
                                ob_cursor(cur),
                                event_curtime) == Success;
@@ -179,8 +180,8 @@ void grab_shutdown(gboolean reconfig)
     if (reconfig) return;
 
     while (grab_keyboard(FALSE));
-    while (grab_pointer(FALSE, OB_CURSOR_NONE));
-    while (grab_pointer_window(FALSE, OB_CURSOR_NONE, None));
+    while (grab_pointer(FALSE, FALSE, OB_CURSOR_NONE));
+    while (grab_pointer_window(FALSE, FALSE, OB_CURSOR_NONE, None));
     while (grab_server(FALSE));
 }
 
index ca645cae489580f88ed9e3a3aaa0f8fe6957e4a2..9f2cf562f09353575000fc5eb8b08671666372e8 100644 (file)
@@ -28,8 +28,9 @@ void grab_startup(gboolean reconfig);
 void grab_shutdown(gboolean reconfig);
 
 gboolean grab_keyboard(gboolean grab);
-gboolean grab_pointer(gboolean grab, ObCursor cur);
-gboolean grab_pointer_window(gboolean grab, ObCursor cur, Window win);
+gboolean grab_pointer(gboolean grab, gboolean owner_events, ObCursor cur);
+gboolean grab_pointer_window(gboolean grab, gboolean owner_events,
+                             ObCursor cur, Window win);
 gint grab_server(gboolean grab);
 
 gboolean grab_on_keyboard();
index 01b54b4c10a9325d602bf87767e4ab8f3c185368..248fd1ce0dd4bdf682152a371476fe92b2e95b8e 100644 (file)
@@ -166,7 +166,7 @@ gboolean keyboard_interactive_grab(guint state, ObClient *client,
     if (!interactive_states) {
         if (!grab_keyboard(TRUE))
             return FALSE;
-        if (!grab_pointer(TRUE, OB_CURSOR_NONE)) {
+        if (!grab_pointer(TRUE, FALSE, OB_CURSOR_NONE)) {
             grab_keyboard(FALSE);
             return FALSE;
         }
@@ -195,7 +195,7 @@ void keyboard_interactive_end(ObInteractiveState *s,
 
     if (!interactive_states) {
         grab_keyboard(FALSE);
-        grab_pointer(FALSE, OB_CURSOR_NONE);
+        grab_pointer(FALSE, FALSE, OB_CURSOR_NONE);
         keyboard_reset_chains();
     }
 }
index f359c9852ee091b0c14e2793de5584fbc427b124..2e54ef88cde6dd167e8a82ad9b53948c3b951357 100644 (file)
@@ -681,10 +681,10 @@ static gboolean menu_frame_show(ObMenuFrame *self)
 
     if (menu_frame_visible == NULL) {
         /* no menus shown yet */
-        if (!grab_pointer(TRUE, OB_CURSOR_POINTER))
+        if (!grab_pointer(TRUE, TRUE, OB_CURSOR_POINTER))
             return FALSE;
         if (!grab_keyboard(TRUE)) {
-            grab_pointer(FALSE, OB_CURSOR_POINTER);
+            grab_pointer(FALSE, TRUE, OB_CURSOR_POINTER);
             return FALSE;
         }
     }
@@ -809,7 +809,7 @@ void menu_frame_hide(ObMenuFrame *self)
 
     if (menu_frame_visible == NULL) {
         /* last menu shown */
-        grab_pointer(FALSE, OB_CURSOR_NONE);
+        grab_pointer(FALSE, TRUE, OB_CURSOR_NONE);
         grab_keyboard(FALSE);
     }
 
index d078f52a389d26327dd33fa86fc5ef0e9e795f6a..6cab52262dcea9737332d42b88d523bf952a1336 100644 (file)
@@ -164,14 +164,14 @@ void moveresize_start(ObClient *c, gint x, gint y, guint b, guint32 cnr)
     else
         g_assert_not_reached();
 
-    grab_pointer(TRUE, cur);
+    grab_pointer(TRUE, FALSE, cur);
     grab_keyboard(TRUE);
 }
 
 void moveresize_end(gboolean cancel)
 {
     grab_keyboard(FALSE);
-    grab_pointer(FALSE, OB_CURSOR_NONE);
+    grab_pointer(FALSE, FALSE, OB_CURSOR_NONE);
 
     popup_hide(popup);