aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-06-17 10:57:42 +0800
committerPo Lu2022-06-17 10:57:42 +0800
commita8cf6567dd61a58d0bec64fa27beb3e757ffaa51 (patch)
treed442daade5b80d8e576fbf416463abe79c1ca08c /src
parent61a312ba0cae10e8e19b7424540751a71d0170b1 (diff)
downloademacs-a8cf6567dd61a58d0bec64fa27beb3e757ffaa51.tar.gz
emacs-a8cf6567dd61a58d0bec64fa27beb3e757ffaa51.zip
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'.
Diffstat (limited to 'src')
-rw-r--r--src/xterm.c126
-rw-r--r--src/xterm.h5
2 files changed, 72 insertions, 59 deletions
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)
6915{ 6915{
6916#ifndef USE_GTK 6916#ifndef USE_GTK
6917 struct frame *focus_frame = dpyinfo->x_focus_frame; 6917 struct frame *focus_frame = dpyinfo->x_focus_frame;
6918 struct x_output *output;
6919#endif 6918#endif
6920 6919
6921#ifdef ENABLE_CHECKING 6920#ifdef ENABLE_CHECKING
@@ -6925,56 +6924,6 @@ x_display_set_last_user_time (struct x_display_info *dpyinfo, Time time)
6925 dpyinfo->last_user_time = time; 6924 dpyinfo->last_user_time = time;
6926 6925
6927#ifndef USE_GTK 6926#ifndef USE_GTK
6928 if (focus_frame
6929 && (dpyinfo->last_user_time
6930 > (dpyinfo->last_user_check_time + 2000)))
6931 {
6932 output = FRAME_X_OUTPUT (focus_frame);
6933
6934 if (!x_wm_supports (focus_frame,
6935 dpyinfo->Xatom_net_wm_user_time_window))
6936 {
6937 if (output->user_time_window == None)
6938 output->user_time_window = FRAME_OUTER_WINDOW (focus_frame);
6939 else if (output->user_time_window != FRAME_OUTER_WINDOW (focus_frame))
6940 {
6941 XDestroyWindow (dpyinfo->display,
6942 output->user_time_window);
6943 XDeleteProperty (dpyinfo->display,
6944 FRAME_OUTER_WINDOW (focus_frame),
6945 dpyinfo->Xatom_net_wm_user_time_window);
6946 output->user_time_window = FRAME_OUTER_WINDOW (focus_frame);
6947 }
6948 }
6949 else
6950 {
6951 if (output->user_time_window == FRAME_OUTER_WINDOW (focus_frame)
6952 || output->user_time_window == None)
6953 {
6954 XSetWindowAttributes attrs;
6955 memset (&attrs, 0, sizeof attrs);
6956
6957 output->user_time_window
6958 = XCreateWindow (dpyinfo->display,
6959 FRAME_X_WINDOW (focus_frame),
6960 -1, -1, 1, 1, 0, 0, InputOnly,
6961 CopyFromParent, 0, &attrs);
6962
6963 XDeleteProperty (dpyinfo->display,
6964 FRAME_OUTER_WINDOW (focus_frame),
6965 dpyinfo->Xatom_net_wm_user_time);
6966 XChangeProperty (dpyinfo->display,
6967 FRAME_OUTER_WINDOW (focus_frame),
6968 dpyinfo->Xatom_net_wm_user_time_window,
6969 XA_WINDOW, 32, PropModeReplace,
6970 (unsigned char *) &output->user_time_window,
6971 1);
6972 }
6973 }
6974
6975 dpyinfo->last_user_check_time = time;
6976 }
6977
6978 if (focus_frame) 6927 if (focus_frame)
6979 { 6928 {
6980 while (FRAME_PARENT_FRAME (focus_frame)) 6929 while (FRAME_PARENT_FRAME (focus_frame))
@@ -6990,6 +6939,57 @@ x_display_set_last_user_time (struct x_display_info *dpyinfo, Time time)
6990#endif 6939#endif
6991} 6940}
6992 6941
6942/* Not needed on GTK because GTK handles reporting the user time
6943 itself. */
6944
6945#ifndef USE_GTK
6946static void
6947x_update_frame_user_time_window (struct frame *f)
6948{
6949 struct x_output *output;
6950 struct x_display_info *dpyinfo;
6951 XSetWindowAttributes attrs;
6952
6953 output = FRAME_X_OUTPUT (f);
6954 dpyinfo = FRAME_DISPLAY_INFO (f);
6955
6956 if (!x_wm_supports (f, dpyinfo->Xatom_net_wm_user_time_window))
6957 {
6958 if (output->user_time_window == None)
6959 output->user_time_window = FRAME_OUTER_WINDOW (f);
6960 else if (output->user_time_window != FRAME_OUTER_WINDOW (f))
6961 {
6962 XDestroyWindow (dpyinfo->display,
6963 output->user_time_window);
6964 XDeleteProperty (dpyinfo->display,
6965 FRAME_OUTER_WINDOW (f),
6966 dpyinfo->Xatom_net_wm_user_time_window);
6967 output->user_time_window = FRAME_OUTER_WINDOW (f);
6968 }
6969 }
6970 else
6971 {
6972 if (output->user_time_window == FRAME_OUTER_WINDOW (f)
6973 || output->user_time_window == None)
6974 {
6975 memset (&attrs, 0, sizeof attrs);
6976
6977 output->user_time_window
6978 = XCreateWindow (dpyinfo->display, FRAME_X_WINDOW (f),
6979 -1, -1, 1, 1, 0, 0, InputOnly,
6980 CopyFromParent, 0, &attrs);
6981
6982 XDeleteProperty (dpyinfo->display, FRAME_OUTER_WINDOW (f),
6983 dpyinfo->Xatom_net_wm_user_time);
6984 XChangeProperty (dpyinfo->display, FRAME_OUTER_WINDOW (f),
6985 dpyinfo->Xatom_net_wm_user_time_window,
6986 XA_WINDOW, 32, PropModeReplace,
6987 (unsigned char *) &output->user_time_window, 1);
6988 }
6989 }
6990}
6991#endif
6992
6993void 6993void
6994x_set_last_user_time_from_lisp (struct x_display_info *dpyinfo, 6994x_set_last_user_time_from_lisp (struct x_display_info *dpyinfo,
6995 Time time) 6995 Time time)
@@ -16914,8 +16914,26 @@ handle_one_xevent (struct x_display_info *dpyinfo,
16914 { 16914 {
16915 /* Maybe we shouldn't set this for child frames ?? */ 16915 /* Maybe we shouldn't set this for child frames ?? */
16916 f->output_data.x->parent_desc = event->xreparent.parent; 16916 f->output_data.x->parent_desc = event->xreparent.parent;
16917
16917 if (!FRAME_PARENT_FRAME (f)) 16918 if (!FRAME_PARENT_FRAME (f))
16918 x_real_positions (f, &f->left_pos, &f->top_pos); 16919 {
16920 x_real_positions (f, &f->left_pos, &f->top_pos);
16921
16922 /* Perhaps reparented due to a WM restart. Reset this. */
16923 FRAME_DISPLAY_INFO (f)->wm_type = X_WMTYPE_UNKNOWN;
16924 FRAME_DISPLAY_INFO (f)->net_supported_window = 0;
16925
16926#ifndef USE_GTK
16927 /* The window manager could have restarted and the new
16928 window manager might not support user time windows,
16929 so update what is used accordingly.
16930
16931 Note that this doesn't handle changes between
16932 non-reparenting window managers. */
16933 if (FRAME_X_OUTPUT (f)->has_been_visible)
16934 x_update_frame_user_time_window (f);
16935#endif
16936 }
16919 else 16937 else
16920 { 16938 {
16921 Window root; 16939 Window root;
@@ -16928,10 +16946,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
16928 unblock_input (); 16946 unblock_input ();
16929 } 16947 }
16930 16948
16931 /* Perhaps reparented due to a WM restart. Reset this. */
16932 FRAME_DISPLAY_INFO (f)->wm_type = X_WMTYPE_UNKNOWN;
16933 FRAME_DISPLAY_INFO (f)->net_supported_window = 0;
16934
16935 x_set_frame_alpha (f); 16949 x_set_frame_alpha (f);
16936 } 16950 }
16937 goto OTHER; 16951 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
495 struct scroll_bar *last_mouse_scroll_bar; 495 struct scroll_bar *last_mouse_scroll_bar;
496 496
497 /* Time of last user interaction as returned in X events on this 497 /* Time of last user interaction as returned in X events on this
498 display, and time where WM support for `_NET_WM_USER_TIME_WINDOW' 498 display. */
499 was last checked. */ 499 Time last_user_time;
500 Time last_user_time, last_user_check_time;
501 500
502 /* Position where the mouse was last time we reported a motion. 501 /* Position where the mouse was last time we reported a motion.
503 This is a position on last_mouse_motion_frame. */ 502 This is a position on last_mouse_motion_frame. */