From ae8b1b8fd476b8c6240c1337c0c51763d4879ac9 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sun, 22 May 2022 17:15:10 +0800 Subject: [PATCH] Implement `display-monitors-changed-functions' on MS Windows * src/w32term.c (w32_read_socket): Handle WM_DISPLAYCHANGE by sending monitor change events. --- src/w32term.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/w32term.c b/src/w32term.c index da7ac379723..373c5b5f786 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -5912,6 +5912,29 @@ w32_read_socket (struct terminal *terminal, (short) HIWORD (msg.msg.lParam))); } + /* According to the MS documentation, this message is sent + to each window whenever a monitor is added, removed, or + has its resolution change. Detect duplicate events when + there are multiple frames by ensuring only one event is + put in the keyboard buffer at any given time. */ + { + union buffered_input_event *ev; + + 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) + /* Don't store a MONITORS_CHANGED_EVENT if there is + already an undelivered event on the queue. */ + break; + + inev.kind = MONITORS_CHANGED_EVENT; + XSETTERMINAL (inev.arg, dpyinfo->terminal); + } + check_visibility = 1; break; -- 2.39.2