From: Po Lu Date: Fri, 17 Jun 2022 02:57:42 +0000 (+0800) Subject: Improve window manager user time reporting mode switching X-Git-Tag: emacs-29.0.90~1447^2~1697 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a8cf6567dd61a58d0bec64fa27beb3e757ffaa51;p=emacs.git Improve window manager user time reporting mode switching * src/xterm.c (x_display_set_last_user_time): Stop periodically checking for user time window support. (x_update_frame_user_time_window): New function. (handle_one_xevent): Call it on toplevel ReparentNotify if the frame has been visible at least once. * src/xterm.h (struct x_display_info): Remove `last_user_check_time'. --- diff --git a/src/xterm.c b/src/xterm.c index 96fe75f41e2..e26cd586797 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -6915,7 +6915,6 @@ x_display_set_last_user_time (struct x_display_info *dpyinfo, Time time) { #ifndef USE_GTK struct frame *focus_frame = dpyinfo->x_focus_frame; - struct x_output *output; #endif #ifdef ENABLE_CHECKING @@ -6925,56 +6924,6 @@ x_display_set_last_user_time (struct x_display_info *dpyinfo, Time time) dpyinfo->last_user_time = time; #ifndef USE_GTK - if (focus_frame - && (dpyinfo->last_user_time - > (dpyinfo->last_user_check_time + 2000))) - { - output = FRAME_X_OUTPUT (focus_frame); - - if (!x_wm_supports (focus_frame, - dpyinfo->Xatom_net_wm_user_time_window)) - { - if (output->user_time_window == None) - output->user_time_window = FRAME_OUTER_WINDOW (focus_frame); - else if (output->user_time_window != FRAME_OUTER_WINDOW (focus_frame)) - { - XDestroyWindow (dpyinfo->display, - output->user_time_window); - XDeleteProperty (dpyinfo->display, - FRAME_OUTER_WINDOW (focus_frame), - dpyinfo->Xatom_net_wm_user_time_window); - output->user_time_window = FRAME_OUTER_WINDOW (focus_frame); - } - } - else - { - if (output->user_time_window == FRAME_OUTER_WINDOW (focus_frame) - || output->user_time_window == None) - { - XSetWindowAttributes attrs; - memset (&attrs, 0, sizeof attrs); - - output->user_time_window - = XCreateWindow (dpyinfo->display, - FRAME_X_WINDOW (focus_frame), - -1, -1, 1, 1, 0, 0, InputOnly, - CopyFromParent, 0, &attrs); - - XDeleteProperty (dpyinfo->display, - FRAME_OUTER_WINDOW (focus_frame), - dpyinfo->Xatom_net_wm_user_time); - XChangeProperty (dpyinfo->display, - FRAME_OUTER_WINDOW (focus_frame), - dpyinfo->Xatom_net_wm_user_time_window, - XA_WINDOW, 32, PropModeReplace, - (unsigned char *) &output->user_time_window, - 1); - } - } - - dpyinfo->last_user_check_time = time; - } - if (focus_frame) { while (FRAME_PARENT_FRAME (focus_frame)) @@ -6990,6 +6939,57 @@ x_display_set_last_user_time (struct x_display_info *dpyinfo, Time time) #endif } +/* Not needed on GTK because GTK handles reporting the user time + itself. */ + +#ifndef USE_GTK +static void +x_update_frame_user_time_window (struct frame *f) +{ + struct x_output *output; + struct x_display_info *dpyinfo; + XSetWindowAttributes attrs; + + output = FRAME_X_OUTPUT (f); + dpyinfo = FRAME_DISPLAY_INFO (f); + + if (!x_wm_supports (f, dpyinfo->Xatom_net_wm_user_time_window)) + { + if (output->user_time_window == None) + output->user_time_window = FRAME_OUTER_WINDOW (f); + else if (output->user_time_window != FRAME_OUTER_WINDOW (f)) + { + XDestroyWindow (dpyinfo->display, + output->user_time_window); + XDeleteProperty (dpyinfo->display, + FRAME_OUTER_WINDOW (f), + dpyinfo->Xatom_net_wm_user_time_window); + output->user_time_window = FRAME_OUTER_WINDOW (f); + } + } + else + { + if (output->user_time_window == FRAME_OUTER_WINDOW (f) + || output->user_time_window == None) + { + memset (&attrs, 0, sizeof attrs); + + output->user_time_window + = XCreateWindow (dpyinfo->display, FRAME_X_WINDOW (f), + -1, -1, 1, 1, 0, 0, InputOnly, + CopyFromParent, 0, &attrs); + + XDeleteProperty (dpyinfo->display, FRAME_OUTER_WINDOW (f), + dpyinfo->Xatom_net_wm_user_time); + XChangeProperty (dpyinfo->display, FRAME_OUTER_WINDOW (f), + dpyinfo->Xatom_net_wm_user_time_window, + XA_WINDOW, 32, PropModeReplace, + (unsigned char *) &output->user_time_window, 1); + } + } +} +#endif + void x_set_last_user_time_from_lisp (struct x_display_info *dpyinfo, Time time) @@ -16914,8 +16914,26 @@ handle_one_xevent (struct x_display_info *dpyinfo, { /* Maybe we shouldn't set this for child frames ?? */ f->output_data.x->parent_desc = event->xreparent.parent; + if (!FRAME_PARENT_FRAME (f)) - x_real_positions (f, &f->left_pos, &f->top_pos); + { + x_real_positions (f, &f->left_pos, &f->top_pos); + + /* Perhaps reparented due to a WM restart. Reset this. */ + FRAME_DISPLAY_INFO (f)->wm_type = X_WMTYPE_UNKNOWN; + FRAME_DISPLAY_INFO (f)->net_supported_window = 0; + +#ifndef USE_GTK + /* The window manager could have restarted and the new + window manager might not support user time windows, + so update what is used accordingly. + + Note that this doesn't handle changes between + non-reparenting window managers. */ + if (FRAME_X_OUTPUT (f)->has_been_visible) + x_update_frame_user_time_window (f); +#endif + } else { Window root; @@ -16928,10 +16946,6 @@ handle_one_xevent (struct x_display_info *dpyinfo, unblock_input (); } - /* Perhaps reparented due to a WM restart. Reset this. */ - FRAME_DISPLAY_INFO (f)->wm_type = X_WMTYPE_UNKNOWN; - FRAME_DISPLAY_INFO (f)->net_supported_window = 0; - x_set_frame_alpha (f); } goto OTHER; diff --git a/src/xterm.h b/src/xterm.h index 17402f962c7..3ef523d7822 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -495,9 +495,8 @@ struct x_display_info struct scroll_bar *last_mouse_scroll_bar; /* Time of last user interaction as returned in X events on this - display, and time where WM support for `_NET_WM_USER_TIME_WINDOW' - was last checked. */ - Time last_user_time, last_user_check_time; + display. */ + Time last_user_time; /* Position where the mouse was last time we reported a motion. This is a position on last_mouse_motion_frame. */