]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix some undesirable frame focus changes
authorPo Lu <luangruo@yahoo.com>
Wed, 10 Aug 2022 11:30:55 +0000 (19:30 +0800)
committerPo Lu <luangruo@yahoo.com>
Wed, 10 Aug 2022 11:31:21 +0000 (19:31 +0800)
* src/xterm.c (handle_one_xevent): Only detach upon actual
device tree change.

src/xterm.c

index 41537ade15591530d83e77526e416e39b236160d..17043e078c7e5b634ca3ae94e54cf8c98cbbde68 100644 (file)
@@ -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;
            }