From 4e6427a77aa3bcf4a410ac879aedaed438eb4bef Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <fourdan.olivier@wanadoo.fr>
Date: Mon, 22 Mar 2004 22:27:58 +0000
Subject: [PATCH] Add a "pending_focus" variable that helps with
 XSetInputFocus() transitions

(Old svn revision: 11661)
---
 src/client.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/client.c b/src/client.c
index d1f551677..580ab2a4a 100644
--- a/src/client.c
+++ b/src/client.c
@@ -102,11 +102,12 @@ Client *clients = NULL;
 unsigned int client_count = 0;
 unsigned long client_serial = 0;
 
-static GList *windows       = NULL;
-static GList *windows_stack = NULL;
-static Client *client_focus = NULL;
-static Client *last_raise   = NULL;
-static Client *last_ungrab  = NULL;
+static GList *windows        = NULL;
+static GList *windows_stack  = NULL;
+static Client *client_focus  = NULL;
+static Client *pending_focus = NULL;
+static Client *last_raise    = NULL;
+static Client *last_ungrab   = NULL;
 
 /* Forward decl */
 static void clientUpdateFullscreenState (Client * c);
@@ -3812,6 +3813,7 @@ clientPassFocus (Client * c)
 {
     GList *list_of_windows = NULL;
     Client *new_focus = NULL;
+    Client *current_focus = client_focus;
     Client *top_most = NULL;
     Client *c2;
     Window dr, window;
@@ -3821,7 +3823,12 @@ clientPassFocus (Client * c)
 
     TRACE ("entering clientPassFocus");
 
-    if ((c || client_focus) && (c != client_focus))
+    if (pending_focus)
+    {
+        current_focus = pending_focus;
+    }
+
+    if ((c || current_focus) && (c != current_focus))
     {
         return;
     }
@@ -3872,7 +3879,7 @@ clientPassFocus (Client * c)
     {
         new_focus = top_most;
     }
-    clientSetFocus (new_focus, FOCUS_IGNORE_MODAL);
+    clientSetFocus (new_focus, FOCUS_IGNORE_MODAL | FOCUS_FORCE);
     if (new_focus == top_most)
     {
         clientPassGrabButton1 (new_focus);
@@ -4807,6 +4814,7 @@ clientUpdateFocus (Client * c, unsigned short flags)
 
     TRACE ("entering clientUpdateFocus");
 
+    pending_focus = NULL;
     if ((c) && !clientAcceptFocus (c))
     {
         TRACE ("SKIP_FOCUS set for client \"%s\" (0x%lx)", c->name, c->window);
@@ -4903,6 +4911,7 @@ clientSetFocus (Client * c, unsigned short flags)
         }
         if (FLAG_TEST (c->wm_flags, WM_FLAG_INPUT))
         {
+            pending_focus = c;
             XSetInputFocus (dpy, c->window, RevertToNone, CurrentTime);
             XFlush (dpy);
         }
-- 
GitLab