ch11ng / exwm

Emacs X Window Manager
2.85k stars 136 forks source link

`select-frame-by-name` does not work with focus-follows-mouse #470

Open medranocalvo opened 6 years ago

medranocalvo commented 6 years ago

Switching to another frame using select-frame-by-name does not work when focus-follows-mouse is enabled (mouse-autoselect-window and focus-follows-mouse).

I believe this has something to do with #456: select-frame-by-name invokes select-frame-set-input-focus (code below), which uses set-mouse-position. In that issue, you mentioned that The implementation was problematic. referring to set-mouse-position. What do you meant by that?

(defun select-frame-set-input-focus (frame &optional norecord)
  "Select FRAME, raise it, and set input focus, if possible.
If `mouse-autoselect-window' is non-nil, also move mouse pointer
to FRAME's selected window.  Otherwise, if `focus-follows-mouse'
is non-nil, move mouse cursor to FRAME.

Optional argument NORECORD means to neither change the order of
recently selected windows nor the buffer list."
  (select-frame frame norecord)
  (raise-frame frame)
  ;; Ensure, if possible, that FRAME gets input focus.
  (when (memq (window-system frame) '(x w32 ns))
    (x-focus-frame frame))
  ;; Move mouse cursor if necessary.
  (cond
   (mouse-autoselect-window
    (let ((edges (window-inside-edges (frame-selected-window frame))))
      ;; Move mouse cursor into FRAME's selected window to avoid that
      ;; Emacs mouse-autoselects another window.
      (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
   (focus-follows-mouse
    ;; Move mouse cursor into FRAME to avoid that another frame gets
    ;; selected by the window manager.
    (set-mouse-position frame (1- (frame-width frame)) 0))))
ch11ng commented 6 years ago

Duh. After a second check it seems set-mouse-position acts exactly like a raw X request.

select-frame-set-input-focus is actually different has it calls x-focus-frame which alters the input focus.

medranocalvo commented 6 years ago

Duh. After a second check it seems set-mouse-position acts exactly like a raw X request.

Would it make sense to revert to set-mouse-position then?

select-frame-set-input-focus is actually different has it calls x-focus-frame which alters the input focus.

But should alter it to the newly selected frame... I wonder wether this is related to me using XQuartz and focus-follows-mouse. Have you tried whether it works on your environment?

ch11ng commented 6 years ago

Duh. After a second check it seems set-mouse-position acts exactly like a raw X request.

Would it make sense to revert to set-mouse-position then?

Let's stick with the current solution. Emacs's builtin one might get changed over time.

select-frame-set-input-focus is actually different has it calls x-focus-frame which alters the input focus.

But should alter it to the newly selected frame... I wonder wether this is related to me using XQuartz and focus-follows-mouse. Have you tried whether it works on your environment?

We seldom set input focus to a frame with a window displaying an exwm-mode buffer selected. If that should happen, we would be working on a read-only buffer (and see the annoying "Buffer is read-only" message on every typing). Perhaps there is a race condition here. I can confirm select-frame-by-name seems working for me regardless of whether mouse-autoselect-window or focus-follows-mouse is enabled.

medranocalvo commented 6 years ago

Hmm... I'll investigate. It might have to do with XQuartz. It will take some time.