aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2022-08-02 09:41:02 +0800
committerPo Lu2022-08-02 09:41:02 +0800
commit0c910f689b0100ec658ba7a70da23376e8eeee81 (patch)
treee8950959b75ea60bce51462a204ea8bdeff1a4f5
parentbc7dc792dfe514fc66f8e330a4a95ece66560fa4 (diff)
downloademacs-0c910f689b0100ec658ba7a70da23376e8eeee81.tar.gz
emacs-0c910f689b0100ec658ba7a70da23376e8eeee81.zip
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.
-rw-r--r--src/xterm.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/xterm.c b/src/xterm.c
index c34fb3eb362..017e63d8b6b 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -16499,6 +16499,33 @@ x_wait_for_cell_change (Lisp_Object cell, struct timespec timeout)
16499 } 16499 }
16500} 16500}
16501 16501
16502#if defined USE_GTK || defined HAVE_XRANDR
16503
16504/* Find whether or not an undelivered MONITORS_CHANGED_EVENT is
16505 already on the event queue. DPYINFO is the display any such event
16506 must apply to. */
16507
16508static bool
16509x_find_monitors_changed_event (struct x_display_info *dpyinfo)
16510{
16511 union buffered_input_event *event;
16512
16513 event = kbd_fetch_ptr;
16514
16515 while (event != kbd_store_ptr)
16516 {
16517 if (event->ie.kind == MONITORS_CHANGED_EVENT
16518 && XTERMINAL (event->ie.arg) == dpyinfo->terminal)
16519 return true;
16520
16521 event = X_NEXT_KBD_EVENT (event);
16522 }
16523
16524 return false;
16525}
16526
16527#endif
16528
16502#ifdef USE_GTK 16529#ifdef USE_GTK
16503static void 16530static void
16504x_monitors_changed_cb (GdkScreen *gscr, gpointer user_data) 16531x_monitors_changed_cb (GdkScreen *gscr, gpointer user_data)
@@ -16516,6 +16543,9 @@ x_monitors_changed_cb (GdkScreen *gscr, gpointer user_data)
16516 if (!dpyinfo) 16543 if (!dpyinfo)
16517 return; 16544 return;
16518 16545
16546 if (x_find_monitors_changed_event (dpyinfo))
16547 return;
16548
16519 XSETTERMINAL (terminal, dpyinfo->terminal); 16549 XSETTERMINAL (terminal, dpyinfo->terminal);
16520 16550
16521 current_monitors 16551 current_monitors
@@ -22532,7 +22562,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
22532 || event->type == (dpyinfo->xrandr_event_base 22562 || event->type == (dpyinfo->xrandr_event_base
22533 + RRNotify))) 22563 + RRNotify)))
22534 { 22564 {
22535 union buffered_input_event *ev;
22536 Time timestamp; 22565 Time timestamp;
22537 Lisp_Object current_monitors; 22566 Lisp_Object current_monitors;
22538 XRRScreenChangeNotifyEvent *notify; 22567 XRRScreenChangeNotifyEvent *notify;
@@ -22560,13 +22589,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
22560 else 22589 else
22561 timestamp = 0; 22590 timestamp = 0;
22562 22591
22563 ev = (kbd_store_ptr == kbd_buffer 22592 if (x_find_monitors_changed_event (dpyinfo))
22564 ? kbd_buffer + KBD_BUFFER_SIZE - 1
22565 : kbd_store_ptr - 1);
22566
22567 if (kbd_store_ptr != kbd_fetch_ptr
22568 && ev->ie.kind == MONITORS_CHANGED_EVENT
22569 && XTERMINAL (ev->ie.arg) == dpyinfo->terminal)
22570 /* Don't store a MONITORS_CHANGED_EVENT if there is 22593 /* Don't store a MONITORS_CHANGED_EVENT if there is
22571 already an undelivered event on the queue. */ 22594 already an undelivered event on the queue. */
22572 goto OTHER; 22595 goto OTHER;