bug#81573: 31.0.90; sit-for sometimes does not delay as expected

Markus Triska <[email protected]> Fri, 07 Aug 2026 08:24:22 +0200 (CEST)
Newsgroups gmane.emacs.bugs
Message-ID <20260807062422.9DAEEF08652@triska-ser8>
This is an issue that we found during the discussion of #80131:

    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=80131#53

I file it here separately so that it can be discussed and addressed
separately, and is not forgotten after the other issue is closed.

To reproduce this issue, please start Emacs with:

    $ emacs -Q

and then evaluate the following form:

    (while t
      (let ((buf (get-buffer-create "sit-for-example"))
            (old-frame (selected-frame))
            (frame (make-frame `((parent-frame . ,(selected-frame))
                                 (left . 0)
                                 (minibuffer . nil)
                                 (visibility . nil)
                                 (top . 0)))))
        (set-frame-width frame 200 nil t)
        (set-frame-height frame 100 nil t)
        (set-frame-parameter frame 'visibility t)
        (discard-input)
        (unwind-protect
            (progn
              (select-frame-set-input-focus frame)
              (switch-to-buffer buf)
              (erase-buffer)
              (setq mode-line-format nil)
              (let ((chars (string-to-list "Hello!")))
                (while chars
                  (insert (pop chars))
                  (sit-for 0.1))))
          (select-frame-set-input-focus old-frame)
          (delete-frame frame))))

Unexpectedly, sit-for does not wait as expected. It works as intended
in the terminal, i.e., when I launch Emacs with "$ emacs -Q -nw".

This difference between "-nw" and GUI sessions occurs as of:

    458024a3d9e3c58d11deeb879ffc73c96840f6f0

As discussed in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=80131#71,
the following one-line change can be used to address the issue:

diff --git a/src/xterm.c b/src/xterm.c
index ac115c4ba1a..83fc583782c 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -29033,7 +29033,7 @@ x_focus_frame (struct frame *f, bool noactivate)
 	     A BadMatch error can occur if the window was obscured
 	     after the time of the last user interaction without
 	     changing the last-focus-change-time.  */
-	  x_set_input_focus (FRAME_DISPLAY_INFO (f), FRAME_OUTER_WINDOW (f),
+	  x_set_input_focus (FRAME_DISPLAY_INFO (f), FRAME_X_WINDOW (f),
 			     time);
 	}
       else

Please consider applying the change, or a different way to resolve this.

Thank you and all the best,
Markus



In GNU Emacs 31.0.90 (build 2, x86_64-pc-linux-gnu, X toolkit, Xaw
 scroll bars) of 2026-07-19 built on beelink-ser8
Repository revision: 407de5142c2631d42d53c8da470188f61e46ab22
Repository branch: HEAD
Windowing system distributor 'The X.Org Foundation', version 11.0.12101016
System Description: Debian GNU/Linux 13 (trixie)

Configured using:
 'configure --without-cairo --with-x-toolkit=lucid
 --with-xpm=ifavailable --with-gif=ifavailable --with-tiff=ifavailable
 --with-gnutls=ifavailable --with-native-compilation=no'

Configured features:
DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LIBSYSTEMD
LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS
TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XFT XIM XINERAMA
XINPUT2 XPM XRANDR LUCID ZLIB