From: Po Lu Date: Sun, 22 May 2022 09:15:10 +0000 (+0800) Subject: Implement `display-monitors-changed-functions' on MS Windows X-Git-Tag: emacs-29.0.90~1910^2~527 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ae8b1b8fd476b8c6240c1337c0c51763d4879ac9;p=emacs.git Implement `display-monitors-changed-functions' on MS Windows * src/w32term.c (w32_read_socket): Handle WM_DISPLAYCHANGE by sending monitor change events. --- 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;