ch11ng / exwm

Emacs X Window Manager
2.86k stars 137 forks source link

Blank cursor when switching between X and Emacs window #924

Closed ipvych closed 9 months ago

ipvych commented 10 months ago

Trying out EXWM and when switching between windows point inside Emacs becomes blank. It sometimes resets on it's own after some activity or it just gets stuck with call to redraw-display fixing it. I can reproduce this without any installed packages with example config.

This issue is present in both master and ELPA build of exwm Output of emacs-version: GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw3d scroll bars) Output of Xorg -version:

X.Org X Server 1.21.1.8
X Protocol Version 11, Revision 0
Current Operating System: Linux nixos 6.4.7-zen1 #1-NixOS ZEN SMP PREEMPT_DYNAMIC Tue Jan  1 00:00:00 UTC 1980 x86_64
Kernel command line: <omitted>

Current version of pixman: 0.42.2
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.

Here is the log where I switch between qutebrowser and scratch windows starting from focused scratch buffer where I marked cases where focus changed correctly by inserting --------------- marks - http://0x0.st/Hfp9.log (github does not allow uploading full log, if the paste expires please notify me and I will reupload it)

ipvych commented 10 months ago

Adding delay after switching window like so

(defun ipv-exwm-other-window ()
  "Call `other-window' interactively with workaround for EXWM to not lose focus."
  (interactive)
  (if (not exwm-window-type)
      (call-interactively #'other-window)
    (call-interactively #'other-window)
    (sleep-for 0.02)))

seems to be a working workaround for this.

medranocalvo commented 10 months ago

I could not reproduce with a minimal config:

(push "/path/to/xelb" load-path)
(push "/path/to/exwm" load-path)
(require 'exwm)
(exwm-input-set-key (kbd "s-o") 'other-window)
(exwm-init)
;; C-x 3
;; M-x async-shell-command RET xterm RET
;; s-o
;; s-o ...

Could you try the above? The issue might lie in the example config, which I did not test.

ipvych commented 10 months ago

Reproduced it with your config.

My ~/.xinitrc

exec emacs -Q -l ~/test.el

Where ~/test.el is

(push "<homedir>/.config/emacs/elpa/xelb/" load-path)
(push "<homedir>/.config/emacs/elpa/exwm/" load-path)
(require 'exwm)
(exwm-input-set-key (kbd "s-o") 'other-window)
(exwm-init)

Tried starting in separate tty with my current WM running, in tty1 without any other wm running both as command in .zprofile and just by running either startx or exec startx. I have second monitor and tried without it as well, could reproduce it in all cases.

tazjin commented 10 months ago

I can reproduce this, too, with my normal config and a minimal one. In my case, switching to a different workspace on the same monitor and back fixes it (which is similar to my workaround for the bug where Chromium doesn't get input focus).

medranocalvo commented 10 months ago

Hm.

Please post the output of (emacs-build-description) (remove sensitive information if any). I'm building without X toolkit, will try to match your build.

Please use git bisect to try to find out which commit introduces the issue.

Thank you both.

ipvych commented 10 months ago

Output of (emacs-build-description)

In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version
1.16.0, Xaw3d scroll bars)
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: NixOS 23.11 (Tapir)

Configured using:
 'configure --prefix=/nix/store/81g0rphgaisjz1kf6mfdlqv9m69kjfkf-emacs-29.1
 --disable-build-details --with-modules --with-x-toolkit=lucid --with-xft
 --with-cairo --with-native-compilation --with-tree-sitter --with-xinput2'

I am trying EXWM for first time and I had this issue from beginning so can't help with bisect. Only thing that might be helpful is that this issue is present in both ELPA version and master branch.

tazjin commented 10 months ago

and for me it's:

In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
version 1.16.0, Xaw3d scroll bars)
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: NixOS 23.11 (Tapir)

Configured using:
 'configure
 --prefix=/nix/store/crk4w3rpf8mwmf2f031s934za4rz2dva-emacs-29.1
 --disable-build-details --with-modules --with-x-toolkit=lucid
 --with-xft --with-cairo --with-native-compilation --with-tree-sitter
 --with-xinput2'

Note that if you have Nix installed you can get my exact Emacs (including EXWM config) by running nix-build -E '(import (builtins.fetchGit "https://cl.tvl.fyi/depot.git") {}).users.tazjin.emacs' (though it might take a while).

medranocalvo commented 10 months ago

Still could not reproduce under macOS. I'll try to set up a Linux machine.

@ipvych, that's regrettable. Thank you for taking the time to report the issue.

[... time passes ...]

Set up an Ubuntu 22 machine. Performed the following steps:

 sudo apt update
 sudo apt upgrade
 sudo reboot
 sudo apt install xfce4
 sudo apt install build-essential 
 sudo apt autoremove 
 git clone https://git.savannah.gnu.org/git/emacs.git
 cd emacs/
 git checkout emacs-29.1
 ./autogen.sh 
 sudo apt install autotools-dev libtree-sitter
 sudo apt build-dep emacs
 sudoedit /etc/apt/sources.list
 sudo apt update 
 sudo apt build-dep emacs
 gcc --version
 sudo apt install libgccjit-11-dev 
 sudo apt install libtree-sitter-dev 
 ./autogen.sh 
 ./configure --prefix=$PWD/rel --with-modules --with-x-toolkit=lucid --with-xft --with-cairo --with-native-compilation --with-tree-sitter --with-xinput2
 make -j8
 make install
 man startx
 echo '$HOME/emacs/rel/bin/emacs' >~/.xinitrc
 startx

Note that the .xinitrc contains a call to bare Emacs, no EXWM (plan was to install EXWM from GNU ELPA). Emacs' cursor appears hollow, as you describe. Remember: no EXWM.

Rebuilt --without-xinput2: the cursor is now back to normal.

Seems an Emacs issue. Reminds me of #899... Tried setting x-no-window-manager with a --with-xinput2 build:

$HOME/emacs/rel/bin/emacs --eval '(setq x-no-window-manager t)'

No dice.

Noticed that opening and closing a menu bar menu (e.g. "File") changes the cursor to full.

Summary:

Please, report this to Emacs (post a link to the bug tracker in this ticket).

As for EXWM, you can work-around this by building Emacs --without-xinput2.

ipvych commented 10 months ago

What building with or without xinput changes is whether emacs cursor is blank or not on startup when cursor is hovering over emacs window, it does not resolve issue with cursor becoming blank when switching windows in EXWM.

What is working for me is setting x-no-window-manager to t. It does not change whether cursor get focus on startup with plain Emacs, but in EXWM it fixes the issue with losing focus when switching windows. Thanks, I did not know that variable existed! Maybe it should be documented in the wiki?

I also tried Emacs 28 and it both has no issues with plain emacs cursor focus on startup (which I think is expected since it does not use xinput) and EXWM also works just fine without even setting x-no-window-manager, maybe latter should be reported as issue since I would expect emacs 29 build without xinput to work the same as emacs 28 without having to set this variable so something might have broken there.

medranocalvo commented 10 months ago

Thank you for reporting back. That is an EXWM bug, tracked in #890 and #889, https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58245 and https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58438. (I wrote the wrong ticket number in my comment above).

What building with or without xinput changes is whether emacs cursor is blank or not on startup when cursor is hovering over emacs window [...]

Kindly ask to report this to Emacs, although the issue will probably go away once we fix EXWM.

I also tried Emacs 28 and it both has no issues with plain emacs cursor focus on startup (which I think is expected since it does not use xinput) and EXWM also works just fine without even setting x-no-window-manager, maybe latter should be reported as issue since I would expect emacs 29 build without xinput to work the same as emacs 28 without having to set this variable so something might have broken there.

The conclusion is wrong, let me quickly explain: EXWM relied on contra-standard behaviour in Emacs 28. Emacs 29 fixed it and it's now our turn to comply with the spec. Having to tell Emacs that EXWM is x-no-window-manager is embarrassing ;-). Details on debbugs.

ipvych commented 10 months ago

Thanks for explaining this. If there is a need to test fix in EXWM for this issue feel free to ping me in PR and I will test it at least to check that issue reported here is not present. For focus issue with plain emacs and xinput Emacs bug ticket is https://debbugs.gnu.org/cgi/bugreport.cgi?bug=65919.

ipvych commented 10 months ago

FYI issue in Emacs is fixed in master branch. Feel free to close this one as duplicate of #889.

medranocalvo commented 9 months ago

@ipvych, thank you very much for reporting this to Emacs. I'll try to work on #889 as time permits.

Duplicate of #889.