emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 0c910f689b: Avoid extra consing on monitor configuration change


From: Po Lu
Subject: master 0c910f689b: Avoid extra consing on monitor configuration change
Date: Mon, 1 Aug 2022 21:41:17 -0400 (EDT)

branch: master
commit 0c910f689b0100ec658ba7a70da23376e8eeee81
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Avoid extra consing on monitor configuration change
    
    * src/xterm.c (x_find_monitors_changed_event): New function.
    (x_monitors_changed_cb, handle_one_xevent): Look through the
    entire event queue to skip delivering monitor change events.
---
 src/xterm.c | 39 +++++++++++++++++++++++++++++++--------
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index c34fb3eb36..017e63d8b6 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -16499,6 +16499,33 @@ x_wait_for_cell_change (Lisp_Object cell, struct 
timespec timeout)
     }
 }
 
+#if defined USE_GTK || defined HAVE_XRANDR
+
+/* Find whether or not an undelivered MONITORS_CHANGED_EVENT is
+   already on the event queue.  DPYINFO is the display any such event
+   must apply to.  */
+
+static bool
+x_find_monitors_changed_event (struct x_display_info *dpyinfo)
+{
+  union buffered_input_event *event;
+
+  event = kbd_fetch_ptr;
+
+  while (event != kbd_store_ptr)
+    {
+      if (event->ie.kind == MONITORS_CHANGED_EVENT
+         && XTERMINAL (event->ie.arg) == dpyinfo->terminal)
+       return true;
+
+      event = X_NEXT_KBD_EVENT (event);
+    }
+
+  return false;
+}
+
+#endif
+
 #ifdef USE_GTK
 static void
 x_monitors_changed_cb (GdkScreen *gscr, gpointer user_data)
@@ -16516,6 +16543,9 @@ x_monitors_changed_cb (GdkScreen *gscr, gpointer 
user_data)
   if (!dpyinfo)
     return;
 
+  if (x_find_monitors_changed_event (dpyinfo))
+    return;
+
   XSETTERMINAL (terminal, dpyinfo->terminal);
 
   current_monitors
@@ -22532,7 +22562,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              || event->type == (dpyinfo->xrandr_event_base
                                 + RRNotify)))
        {
-         union buffered_input_event *ev;
          Time timestamp;
          Lisp_Object current_monitors;
          XRRScreenChangeNotifyEvent *notify;
@@ -22560,13 +22589,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
          else
            timestamp = 0;
 
-         ev = (kbd_store_ptr == kbd_buffer
-               ? kbd_buffer + KBD_BUFFER_SIZE - 1
-               : kbd_store_ptr - 1);
-
-         if (kbd_store_ptr != kbd_fetch_ptr
-             && ev->ie.kind == MONITORS_CHANGED_EVENT
-             && XTERMINAL (ev->ie.arg) == dpyinfo->terminal)
+         if (x_find_monitors_changed_event (dpyinfo))
            /* Don't store a MONITORS_CHANGED_EVENT if there is
               already an undelivered event on the queue.  */
            goto OTHER;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]