]> git.eshelyaron.com Git - emacs.git/commitdiff
Stop passing CurrentTime to SetInputFocus
authorPo Lu <luangruo@yahoo.com>
Sat, 8 Oct 2022 08:38:30 +0000 (16:38 +0800)
committerPo Lu <luangruo@yahoo.com>
Sat, 8 Oct 2022 08:38:48 +0000 (16:38 +0800)
* src/xterm.c (xi_focus_handle_for_device, handle_one_xevent):
Set the last user time where required for focus to be handled
correctly.
(x_focus_frame): Do not perform actions prohibited by the ICCCM.

src/xterm.c

index cdf99f278af8f4c49b6e5f4c11c54e047c9aad31..aaf2e7988be0e3c0e24d5434c9c27f843d7d03ea 100644 (file)
@@ -12758,11 +12758,21 @@ xi_focus_handle_for_device (struct x_display_info *dpyinfo,
   switch (event->evtype)
     {
     case XI_FocusIn:
+      /* The last-focus-change time of the device changed, so update the
+        frame's user time.  */
+      x_display_set_last_user_time (dpyinfo, event->time,
+                                   event->send_event);
+
       device->focus_frame = mentioned_frame;
       device->focus_frame_time = event->time;
       break;
 
     case XI_FocusOut:
+      /* The last-focus-change time of the device changed, so update the
+        frame's user time.  */
+      x_display_set_last_user_time (dpyinfo, event->time,
+                                   event->send_event);
+
       device->focus_frame = NULL;
 
       /* So, unfortunately, the X Input Extension is implemented such
@@ -18077,6 +18087,11 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                   }
                 /* Not certain about handling scroll bars here */
 #endif
+               /* Set the provided time as the user time, which is
+                  required for SetInputFocus to work correctly after
+                  taking the input focus.  */
+               x_display_set_last_user_time (dpyinfo, event->xclient.data.l[1],
+                                             true);
                goto done;
               }
 
@@ -27021,8 +27036,22 @@ x_focus_frame (struct frame *f, bool noactivate)
 
       /* Ignore any BadMatch error this request might result in.  */
       x_ignore_errors_for_next_request (dpyinfo);
-      XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
-                     RevertToParent, CurrentTime);
+      if (NILP (Vx_no_window_manager))
+       XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
+                       /* It is invalid to use CurrentTime according to
+                          the ICCCM:
+
+                          Clients that use a SetInputFocus request must
+                          set the time field to the timestamp of the
+                          event that caused them to make the
+                          attempt. [...] Note that clients must not use
+                          CurrentTime in the time field. */
+                       RevertToParent, dpyinfo->last_user_time);
+      else
+       XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
+                       /* But when no window manager is in use, we
+                          don't care.  */
+                       RevertToParent, CurrentTime);
       x_stop_ignoring_errors (dpyinfo);
     }
 }