From a29960e7023a2375de362f59b5cb0ea9a39bbdbe Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Tue, 21 Jan 2003 20:16:20 +0000
Subject: [PATCH] Make sure to always set X focus on the top-level window, not
 on child windows.

---
 dlls/x11drv/event.c  | 3 +++
 dlls/x11drv/window.c | 7 ++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/dlls/x11drv/event.c b/dlls/x11drv/event.c
index dfae906c437..399ce347226 100644
--- a/dlls/x11drv/event.c
+++ b/dlls/x11drv/event.c
@@ -399,6 +399,7 @@ static void set_focus( HWND hwnd, Time time )
     SetForegroundWindow( hwnd );
 
     focus = GetFocus();
+    if (focus) focus = GetAncestor( focus, GA_ROOT );
     win = X11DRV_get_whole_window(focus);
 
     if (win)
@@ -451,6 +452,7 @@ static void handle_wm_protocols_message( HWND hwnd, XClientMessageEvent *event )
         else
         {
             hwnd = GetFocus();
+            if (hwnd) hwnd = GetAncestor( hwnd, GA_ROOT );
             if (!hwnd) hwnd = GetActiveWindow();
             if (!hwnd) hwnd = last_focus;
             if (hwnd && can_activate_window(hwnd)) set_focus( hwnd, event_time );
@@ -486,6 +488,7 @@ static void EVENT_FocusIn( HWND hwnd, XFocusChangeEvent *event )
     if (!can_activate_window(hwnd))
     {
         HWND hwnd = GetFocus();
+        if (hwnd) hwnd = GetAncestor( hwnd, GA_ROOT );
         if (!hwnd) hwnd = GetActiveWindow();
         if (!hwnd) hwnd = x11drv_thread_data()->last_focus;
         if (hwnd && can_activate_window(hwnd)) set_focus( hwnd, CurrentTime );
diff --git a/dlls/x11drv/window.c b/dlls/x11drv/window.c
index f80f9095092..74cf323dd2b 100644
--- a/dlls/x11drv/window.c
+++ b/dlls/x11drv/window.c
@@ -116,11 +116,12 @@ static int get_window_attributes( Display *display, WND *win, XSetWindowAttribut
     attr->colormap          = X11DRV_PALETTE_PaletteXColormap;
     attr->save_under        = ((win->clsStyle & CS_SAVEBITS) != 0);
     attr->cursor            = x11drv_thread_data()->cursor;
-    attr->event_mask        = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
+    attr->event_mask        = (ExposureMask | PointerMotionMask |
                                ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
 
     if (is_window_top_level( win ))
-        attr->event_mask |= StructureNotifyMask | FocusChangeMask | KeymapStateMask;
+        attr->event_mask |= (KeyPressMask | KeyReleaseMask | StructureNotifyMask |
+                             FocusChangeMask | KeymapStateMask);
 
     return (CWOverrideRedirect | CWSaveUnder | CWEventMask | CWColormap | CWCursor);
 }
@@ -717,7 +718,7 @@ static Window create_client_window( Display *display, WND *win )
     OffsetRect( &rect, -data->whole_rect.left, -data->whole_rect.top );
     data->client_rect = rect;
 
-    attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
+    attr.event_mask = (ExposureMask | PointerMotionMask |
                        ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
     attr.bit_gravity = (win->clsStyle & (CS_VREDRAW | CS_HREDRAW)) ?
                        ForgetGravity : NorthWestGravity;
-- 
GitLab