Subject: bug#48413: 28.0.50; emacs does not repaint the window after switching workspaces in Xmonad

From: Platon Pronko <[email-masked]>
Date: Fri, 14 May 2021 11:32:09 +0300

This looks like Xmonad-specific regression after commit 483c5e95 by Martin Rudalics.

Steps to reproduce (under Xmonad):

1. Open a new frame (./src/emacs -Q);
2. Type something in a buffer;
3. Switch to a different workspace;
4. Switch back;
5. Observe buffer being blank and not responding to any interaction.

I bisected this problem to commit 483c5e95 (from 2021-05-05). The trouble seems to be caused by this change in xterm.c:

@@ -8232,33 +8238,36 @@ handle_one_xevent (struct x_display_info *dpyinfo,
            if (!FRAME_VISIBLE_P (f))
              {
                block_input ();
-              SET_FRAME_VISIBLE (f, 1);
-              SET_FRAME_ICONIFIED (f, false);
-              if (FRAME_X_DOUBLE_BUFFERED_P (f))
+             /* The following two are commented out to avoid that a
+                plain invisible frame gets reported as iconified.  That
+                problem occurred first for Emacs 26 and is described in
+                https://lists.gnu.org/archive/html/emacs-devel/2017-02/msg00133.html.  */
+/**          SET_FRAME_VISIBLE (f, 1); **/
+/**          SET_FRAME_ICONIFIED (f, false); **/
+
+             if (FRAME_X_DOUBLE_BUFFERED_P (f))
                  font_drop_xrender_surfaces (f);
                f->output_data.x->has_been_visible = true;
                SET_FRAME_GARBAGED (f);

Specifically the commenting of SET_FRAME_VISIBLE(f, 1) causes the problem (if I uncomment that line, buffer redisplay starts to work correctly).

Trying the same with XFCE doesn't give the error. I compared the sequences of X events received under different WMs, here's the lists (without "other", "MotionNotify" and key events, for brevity):

Xmonad:
1. When switching to different workspace:
    - FocusOut x3
    - UnmapNotify x1
    - LeaveNotify x2
    - PropertyNotify x2
2. When switching back:
    - MapNotify x1
    - VisibilityNotify x3
    - Expose x4
    - EnterNotify x2
    - FocusIn x2
    - ClientMessage x1
    - PropertyNotify x1
    - FocusIn x1

XFCE:
1. When switching to different workspace:
    - FocusOut x2
    - FocusIn x1
    - FocusOut x2
    - LeaveNotify x2
    - UnmapNotify x1
    - PropertyNotify x3
2. When switching back:
    - VisibilityNotify x3
    - Expose x4
    - EnterNotify x2
    - PropertyNotify x2
    - FocusIn x2
    - ClientMessage x1
    - PropertyNotify x2
    - FocusOut x2
    - FocusIn x1
    - FocusOut x2
    - FocusIn x2

Further inspection of SET_FRAME_VISIBLE calls shows that under Xmonad first the frame is set to invisible when UnmapNotify event happens, then after switching back the only time when it could have been set to "visible" was in second "Expose" event (but this line is commented out in commit 483c5e95, so frame thinks it's invisible and thus no redraw happens).

Under XFCE sequence is a bit less clear - frame is set to invisible after UnmapNotify event, but then it is set back to visible after second PropertyNotify event (comment near says "Gnome shell does not iconify us when C-z is pressed."). So Emacs thinks that the frame is visible even though it is on different workspace entirely.

In GNU Emacs 28.0.50 (build 19, x86_64-pc-linux-gnu, GTK+ Version 3.24.29, cairo version 1.17.4)
  of 2021-05-14 built on the-big-maker
Repository revision: 203ee33980571823147122dffb0789f92ea66b53
Repository branch: HEAD
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Arch Linux

Configured using:
  'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
  --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
  --with-sound=alsa --with-modules --without-gconf --without-gsettings
  --with-x-toolkit=gtk3 --without-xaw3d'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM HARFBUZZ JPEG JSON LCMS2
LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY PDUMPER PNG
RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM
GTK3 ZLIB

Important settings:
   value of $LC_TIME: en_SE.UTF-8
   value of $LANG: en_US.UTF-8
   locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
   tooltip-mode: t
   global-eldoc-mode: t
   eldoc-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   line-number-mode: t
   transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils thingatpt
help-mode cl-loaddefs cl-lib iso-transl tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting font-render-setting cairo move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)

Memory information:
((conses 16 53379 13368)
  (symbols 48 6717 0)
  (strings 32 18827 2036)
  (string-bytes 1 618130)
  (vectors 16 13388)
  (vector-slots 8 176246 11054)
  (floats 8 22 47)
  (intervals 56 411 4)
  (buffers 992 12))