From: Po Lu Date: Sat, 8 Oct 2022 08:38:30 +0000 (+0800) Subject: Stop passing CurrentTime to SetInputFocus X-Git-Tag: emacs-29.0.90~1616^2~701 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5e7e85af02c18571837c8e2669b5bf2b7b9198a3;p=emacs.git Stop passing CurrentTime to SetInputFocus * 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. --- diff --git a/src/xterm.c b/src/xterm.c index cdf99f278af..aaf2e7988be 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -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); } }