emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 8c0c9398f3: Fix some undesirable frame focus changes


From: Po Lu
Subject: master 8c0c9398f3: Fix some undesirable frame focus changes
Date: Wed, 10 Aug 2022 07:31:33 -0400 (EDT)

branch: master
commit 8c0c9398f324bed79200c85ca9b0d4e95bf4a686
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Fix some undesirable frame focus changes
    
    * src/xterm.c (handle_one_xevent): Only detach upon actual
    device tree change.
---
 src/xterm.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index 41537ade15..17043e078c 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -22436,11 +22436,14 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 
          case XI_HierarchyChanged:
            {
-             XIHierarchyEvent *hev = (XIHierarchyEvent *) xi_event;
+             XIHierarchyEvent *hev;
              XIDeviceInfo *info;
              int i, ndevices, n_disabled, *disabled;
              struct xi_device_t *device;
+             bool any_changed;
 
+             any_changed = false;
+             hev = (XIHierarchyEvent *) xi_event;
              disabled = SAFE_ALLOCA (sizeof *disabled * hev->num_info);
              n_disabled = 0;
 
@@ -22450,8 +22453,17 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                    {
                      /* Handle all disabled devices now, to prevent
                         things happening out-of-order later.  */
-                     xi_disable_devices (dpyinfo, disabled, n_disabled);
-                     n_disabled = 0;
+
+                     if (ndevices)
+                       {
+                         xi_disable_devices (dpyinfo, disabled, n_disabled);
+                         n_disabled = 0;
+
+                         /* This flag really just means that disabled
+                            devices were handled early and should be
+                            used in conjunction with n_disabled.  */
+                         any_changed = true;
+                       }
 
                      x_catch_errors (dpyinfo->display);
                      info = XIQueryDevice (dpyinfo->display, 
hev->info[i].deviceid,
@@ -22502,9 +22514,12 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                 event.  */
              xi_disable_devices (dpyinfo, disabled, n_disabled);
 
-             /* Now that the device hierarchy has been changed,
-                recompute focus.  */
-             xi_handle_focus_change (dpyinfo);
+             /* If the device hierarchy has been changed, recompute
+                focus.  This might seem like a micro-optimization but
+                it actually keeps the focus from changing in some
+                cases where it would be undesierable.  */
+             if (any_changed || n_disabled)
+               xi_handle_focus_change (dpyinfo);
 
              goto XI_OTHER;
            }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]