]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid extra consing on monitor configuration change
authorPo Lu <luangruo@yahoo.com>
Tue, 2 Aug 2022 01:41:02 +0000 (09:41 +0800)
committerPo Lu <luangruo@yahoo.com>
Tue, 2 Aug 2022 01:41:02 +0000 (09:41 +0800)
* 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

index c34fb3eb362c0210c37fa37d93b71b6747c29425..017e63d8b6b429d5b392ee5bd484c4bc2c87dd36 100644 (file)
@@ -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;