Subject: bug#58245: 29.0.50; other-frame is broken in EXWM

From: Po Lu <[email-masked]>
Date: Sun, 02 Oct 2022 20:31:30 +0800

Jacky Li <[email-masked]> writes:

> I am using EXWM with dual monitors. When I call (other-frame), I can see
> the modeline is activated on the other frame, but the cursor does not
> follow. Any interactive functions would be called in the original
> frame. The cursor now only follows my mouse, but I am sure that
> focus-follow-mouse is nil and mouse-autoselect-window is nil.
>
> I believe the broken commit is within the previous 24 hours. And I
> highly suspect commit 3924fbd025 is the root of the bug.

I believe this is a bug with EXWM, from reading its code:

    ((= type xcb:Atom:_NET_ACTIVE_WINDOW)
      (let ((buffer (exwm--id->buffer id))
            iconic window)
        (when (buffer-live-p buffer)
          (with-current-buffer buffer
            (when (eq exwm--frame exwm-workspace--current)
              (if exwm--floating-frame
                  (select-frame exwm--floating-frame)
                (setq iconic (exwm-layout--iconic-state-p))
                (when iconic
                  ;; State change: iconic => normal.
                  (set-window-buffer (frame-selected-window exwm--frame)
                                     (current-buffer)))
                ;; Focus transfer.
                (setq window (get-buffer-window nil t))
                (when (or iconic
                          (not (eq window (selected-window))))
                  (select-window window)))))))

Since it acts as a window manager, it must either set
`x-no-window-manager' to t, or really focus Emacs frames (which don't
have corresponding EXWM buffers) by doing the X protocol to transfer the
focus to the frame.

3924fbd025 is not buggy; EXWM enables support for _NET_ACTIVE_WINDOW,
which Emacs expects to be implemented correctly:

  Activation

  In the X world, activating a window means to give it the input
                                               ^^^^^^^^^^^^^^^^^
  focus. This may not be possible if the window is unmapped,
  ^^^^^
  because it is on a different desktop. Thus, activating a window may
  involve additional steps like moving it to the current desktop (or
  changing to the desktop the window is on), deiconifying it or raising
  it.