[Xfce4-commits] r24052 - xfwm4/trunk/src

Olivier Fourdan olivier at xfce.org
Wed Dec 6 22:39:15 CET 2006


Author: olivier
Date: 2006-12-06 21:39:15 +0000 (Wed, 06 Dec 2006)
New Revision: 24052

Modified:
   xfwm4/trunk/src/events.c
   xfwm4/trunk/src/focus.c
   xfwm4/trunk/src/focus.h
Log:
Improve focus stealing prevention.

Modified: xfwm4/trunk/src/events.c
===================================================================
--- xfwm4/trunk/src/events.c	2006-12-06 20:10:25 UTC (rev 24051)
+++ xfwm4/trunk/src/events.c	2006-12-06 21:39:15 UTC (rev 24052)
@@ -1614,7 +1614,7 @@
 handleFocusIn (DisplayInfo *display_info, XFocusChangeEvent * ev)
 {
     ScreenInfo *screen_info;
-    Client *c, *last_raised;
+    Client *c, *user_focus;
 
     /* See http://rfc-ref.org/RFC-TEXTS/1013/chapter12.html for details */
 
@@ -1656,8 +1656,6 @@
         /* Not for us */
         return;
     }
-    
-    last_raised = NULL;
 
     if ((ev->window == screen_info->xroot)
         && ((ev->detail == NotifyDetailNone) 
@@ -1680,23 +1678,42 @@
     }
 
     c = myDisplayGetClientFromWindow (display_info, ev->window, ANY);
+    user_focus = clientGetUserFocus ();
+
     TRACE ("FocusIn on window (0x%lx)", ev->window);
     if (c)
     {
         TRACE ("focus set to \"%s\" (0x%lx)", c->name, c->window);
 
         screen_info = c->screen_info;
-        clientUpdateFocus (screen_info, c, FOCUS_SORT);
-#if 0
-        last_raised = clientGetLastRaise (screen_info);
 
-        if ((screen_info->params->click_to_focus) &&
-            (screen_info->params->raise_on_click) &&
-            (last_raised != NULL) && (c != last_raised))
+        if ((user_focus != c) && (user_focus != NULL))
         {
-            clientRaise (c, None);
+            /* 
+               Focus stealing prevention:
+               Some apps tend to focus the window directly. 
+               - If focus stealing prevention is enabled, we revert the 
+                 user set focus to the window that we think has focus and 
+                 then set the demand attention flag.
+               - Otherwise, we update the focus as requested and we raise 
+                 the window so the user can see it.
+             */
+            if (screen_info->params->prevent_focus_stealing)
+            {
+                FLAG_SET (c->flags, CLIENT_FLAG_DEMANDS_ATTENTION);
+                clientSetNetState (c);
+                clientSetFocus (user_focus->screen_info, user_focus, getXServerTime (display_info), NO_FOCUS_FLAG);
+            }
+            else
+            {
+                clientUpdateFocus (screen_info, c, FOCUS_SORT);
+                reset_timeout (screen_info);
+                clientRaise (c, None);
+            }
+            return;
         }
-#endif
+
+        clientUpdateFocus (screen_info, c, FOCUS_SORT);
         if (screen_info->params->raise_on_focus)
         {
             reset_timeout (screen_info);

Modified: xfwm4/trunk/src/focus.c
===================================================================
--- xfwm4/trunk/src/focus.c	2006-12-06 20:10:25 UTC (rev 24051)
+++ xfwm4/trunk/src/focus.c	2006-12-06 21:39:15 UTC (rev 24052)
@@ -58,6 +58,7 @@
 
 static Client *client_focus  = NULL;
 static Client *pending_focus = NULL;
+static Client *user_focus    = NULL;
 static Client *last_ungrab   = NULL;
 
 static ClientPair
@@ -447,6 +448,7 @@
     client_focus = c;
     if (c)
     {
+        user_focus = c;
         clientInstallColormaps (c);
         if (flags & FOCUS_SORT)
         {
@@ -500,6 +502,7 @@
     if ((c) && FLAG_TEST (c->xfwm_flags, XFWM_FLAG_VISIBLE))
     {
         TRACE ("setting focus to client \"%s\" (0x%lx)", c->name, c->window);
+        user_focus = c;
         if (FLAG_TEST(c->flags, CLIENT_FLAG_DEMANDS_ATTENTION))
         {
             FLAG_UNSET (c->flags, CLIENT_FLAG_DEMANDS_ATTENTION);
@@ -598,6 +601,12 @@
 }
 
 Client *
+clientGetFocusPending (void)
+{
+    return (pending_focus);
+}
+
+Client *
 clientGetFocusOrPending (void)
 {
     if (client_focus)
@@ -607,6 +616,12 @@
     return (pending_focus);
 }
 
+Client *
+clientGetUserFocus (void)
+{
+    return (user_focus);
+}
+
 void
 clientClearFocus (Client *c)
 {
@@ -618,6 +633,10 @@
     {
         pending_focus = NULL;
     }
+    if ((c == NULL) || (c == user_focus))
+    {
+        user_focus = NULL;
+    }
 }
 
 void

Modified: xfwm4/trunk/src/focus.h
===================================================================
--- xfwm4/trunk/src/focus.h	2006-12-06 20:10:25 UTC (rev 24051)
+++ xfwm4/trunk/src/focus.h	2006-12-06 21:39:15 UTC (rev 24052)
@@ -62,7 +62,9 @@
                                                                  unsigned short);
 void                     clientInitFocusFlag                    (Client *);
 Client                  *clientGetFocus                         (void);
+Client                  *clientGetFocusPending                  (void);
 Client                  *clientGetFocusOrPending                (void);
+Client                  *clientGetUserFocus                     (void);
 void                     clientClearFocus                       (Client *);
 void                     clientGrabMouseButton                  (Client *);
 void                     clientUngrabMouseButton                (Client *);



More information about the Xfce4-commits mailing list