Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor hiding in Wayland #3334

Closed
hgaiser opened this issue Mar 23, 2023 · 38 comments
Closed

Cursor hiding in Wayland #3334

hgaiser opened this issue Mar 23, 2023 · 38 comments
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. Wayland

Comments

@hgaiser
Copy link

hgaiser commented Mar 23, 2023

What Operating System(s) are you seeing this problem on?

Linux Wayland

Which Wayland compositor or X11 Window manager(s) are you using?

Gnome

WezTerm version

wezterm 20230320-124340-559cb7b0

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

No, and I'll explain why below

Describe the bug

Moving the cursor after clicking in Wezterm and typing doesn't make it reappear.

To Reproduce

  1. Click with the mouse inside the Wezterm window.
  2. Press Shift or some other key, the cursor should be hidden.
  3. Move the cursor, it doesn't reappear until it leaves the window.

Configuration

no config

Expected Behavior

I expect the cursor to reappear after moving it.

Logs

No response

Anything else?

Related PR: #2977

Screencast.from.2023-03-23.10-59-43.webm
@hgaiser hgaiser added the bug Something isn't working label Mar 23, 2023
@wez wez added the Wayland label Mar 23, 2023
@Arjun31415
Copy link

Arjun31415 commented Mar 23, 2023

Facing the same issue, but i don't need to open neovim. As soon as i start typing the cursor disappears - as per the feature- but then does not reappear unless it is moved outside the terminal window

With forced Xwayland -
env -u WAYLAND_DISPLAY wezterm
it works fine

@VarLad
Copy link

VarLad commented Mar 23, 2023

Hard to reproduce on my side, but can confirm that this often happens with me as well (on Wayland)

@bagel897
Copy link

Can confirm

@jmbaur
Copy link
Contributor

jmbaur commented Mar 23, 2023

I cannot reproduce this with a few different wayland compositors (sway and river), but I have not tried out gnome/mutter am seeing this issue on mutter for any terminal application that supports mouse input (vim, emacs, etc.). The issue does not reproduce for me on mutter when the terminal application is not using mouse input.

@hgaiser hgaiser changed the title Cursor hiding in Wayland + Neovim Cursor hiding in Wayland Mar 27, 2023
@hgaiser
Copy link
Author

hgaiser commented Mar 27, 2023

Facing the same issue, but i don't need to open neovim. As soon as i start typing the cursor disappears - as per the feature- but then does not reappear unless it is moved outside the terminal window

With forced Xwayland - env -u WAYLAND_DISPLAY wezterm it works fine

You're right, I thought it was to do with neovim, but it happens without neovim too. I changed the description to remove the neovim part. Thanks!

@hgaiser
Copy link
Author

hgaiser commented Mar 27, 2023

I tried to find the issue, seems it has to do with this line.

Changing that function resolves the issue (effectively removing the use of self.inner.serial) :

    pub fn set_cursor(&self, name: Option<&str>, serial: Option<u32>) {
        if let Some(name) = name {
            if let Err(err) = self.auto_pointer.set_cursor(name, serial) {
                log::error!("Unable to set cursor to {}: {:#}", name, err);
            }
        } else {
            (*self.auto_pointer).set_cursor(0, None, 0, 0);
        }
    }

It seems that clicking the Wezterm window changes the value of self.inner.serial, which means that the next call to set_cursor, to show the pointer again, has no effect.

I only have a rough idea of what I'm doing and I wouldn't be surprised if my proposal is wrong. I mainly hope this helps @wez (or maybe @jmbaur ?) to more easily find the issue and propose a correct fix. Otherwise, if my proposal happens to be correct, I'd be happy to submit a PR.

@chrysos349
Copy link

I have a similar bug on Wayland Gnome on the latest version of wezterm without a config.

The cursor disappears when I hover over the terminal window. I can highlight things, but the cursor stays hidden. HOWEVER, when I open another app, this buggy behavior disappears, and the cursors stays visible. Weird, huh?

See the GIF below demonstrating this bug.

wez

P.S. Of course, this bug disappears if I set enable_wayland = false in my config, or unset the environment variable WAYLAND_DISPLAY as suggested by @Arjun31415.

@hgaiser I tried your proposal. Unfortunately, it didn't help in my case.

@jalil-salame
Copy link
Contributor

I can reproduce this issue on NixOS unstable running Sway, by setting the GTK/X11 cursor/cursor theme it fixed itself.

That might cause issues reproducing it: try using a fresh install of a distro with few defaults (Arch/NixOS minimal).

@Arjun31415
Copy link

I can reproduce this issue on NixOS unstable running Sway, by setting the GTK/X11 cursor/cursor theme it fixed itself.

That might cause issues reproducing it: try using a fresh install of a distro with few defaults (Arch/NixOS minimal).

I keep getting this error -

20:17:40.859  ERROR  window::os::wayland::pointer > Unable to set cursor to arrow: cursor not found
20:17:40.859  ERROR  window::os::wayland::pointer > Unable to set cursor to arrow: cursor not found

further, previously i was using a catpuccin cursor theme and now i changed my cursor theme to Adwaita, yet and it does not resolve itself.

If it might help, I am using Hyprland

@feathecutie
Copy link

feathecutie commented Apr 16, 2023

This issue also happened to me in conjunction with various error messages mentioning cursor not found. Setting the cursor theme, either via the environment variable XCURSOR_THEME or via the lua config option xcursor_theme, resolved both the cursor hiding issue and the error messages.

EDIT: I am also on NixOS btw.

The following are just some thoughs and research about possibly fixing this issue on wezterm's side without requiring user action, feel free to disregard:

Since it seems like this bug mainly stems from either no cursor theme being set or the cursor theme being set to a theme that is not currently installed, it might be beneficial for wezterm to query the icon theme via other sources instead of just the config option and the environment variable (as is currently the case?).
The Arch wiki mentions different mechanisms that platforms configure the cursor theme with, but none of these seem cross-platform enough to be useful for all window managers and desktop environments.
On Gnome, the cursor theme could e.g. be queried using gsettings/dconf or Gtk.Settings:gtk-cursor-theme-name, but this would not necessarily resolve anything on WMs like Sway or Hyprland.

@Arjun31415
Copy link

Arjun31415 commented Apr 16, 2023

My Xcursor theme env variable is set though.

echo $XCURSOR_THEME
Catppuccin-Mocha-Green

It does not work with Adwaita also.

However when i do this it works instead

env XCURSOR_THEME=Adwaita wezterm

@wez
Copy link
Owner

wez commented Apr 16, 2023

FWIW, I use this when I run under wayland/gnome:

~/.config/wezterm/wayland_gnome.lua:

local wezterm = require 'wezterm'
local mod = {}

local function gsettings(key)
  return wezterm.run_child_process({"gsettings", "get", "org.gnome.desktop.interface", key})
end

function mod.apply_to_config(config)
  if wezterm.target_triple ~= "x86_64-unknown-linux-gnu" then
    -- skip if not running on linux
    return
  end
  local success, stdout, stderr = gsettings("cursor-theme")
  if success then
    config.xcursor_theme = stdout:gsub("'(.+)'\n", "%1")
  end

  local success, stdout, stderr = gsettings("cursor-size")
  if success then
    config.xcursor_size = tonumber(stdout)
  end

  config.enable_wayland = true

  if config.enable_wayland and os.getenv("WAYLAND_DISPLAY") then
    local success, stdout, stderr = gsettings("text-scaling-factor")
    if success then
      config.font_size = (config.font_size or 10.0) * tonumber(stdout)
    end
  end

end

return mod

then in my main config file I pull it in like this: (See: Making your own lua modules)

local wezterm = require 'wezterm'
local config = {}
if wezterm.config_builder then
   config = wezterm.config_builder()
end

local wayland_gnome = require 'wayland_gnome'
wayland_gnome.apply_to_config(config)

return config

This obviously assumes gnome, and thus isn't suitable for non-gnome compatible environments.

@Arjun31415
Copy link

Arjun31415 commented Apr 19, 2023

Ok, I think i know how to fix my issue. Few cursor themes (read catppuccin) does not have xterm.png or whatever image format ref. Whereas Adwaita has ( see there is a xterm.png file present). Instead, catppuccin has a default.svg

Now in here it is being set to xterm by default

MouseCursor::Text => "xterm",

So there are two possibilities,

  1. I can take it up with catppuccin repo to include a xterm image file which could be a softlink to the default one
  2. The other is fixing it here, because i use kitty too which does not have this issue with the catppuccin cursor

wez added a commit that referenced this issue Apr 19, 2023
This allows for potentially listing multiple candidate cursor names,
like we do for x11, but doesn't add any.

Attempt to load default if our desired cursor is not found.

refs: #3334
@wez
Copy link
Owner

wez commented Apr 19, 2023

If the issue is really that your chosen theme doesn't have a full set of icons, then 048e8dd should help with that.

That should show up in nightly builds within the hour.

@lnicola
Copy link

lnicola commented Apr 19, 2023

I'm seeing what's reported in the original comment -- the mouse cursor disappears when I press shift, at least in htop. I don't think this is related to the cursor theme. I'm on Adwaita FWIW.

@wez
Copy link
Owner

wez commented Apr 19, 2023

The mouse cursor is supposed to hide when you press a key. It should reappear when you move the mouse; that's the behavior that I see on all the systems that I use.

@hgaiser
Copy link
Author

hgaiser commented Apr 19, 2023

The mouse cursor is supposed to hide when you press a key. It should reappear when you move the mouse; that's the behavior that I see on all the systems that I use.

Is there anything I can do to help debug this issue? As per my comment #3334 (comment), changing that code helps for me, while without it the cursor does not reappear when I move the mouse.

I'm using that for 3 weeks now and I am happy with how it works, though I have no clue if it is correct or not.

@wez
Copy link
Owner

wez commented Apr 19, 2023

@hgaiser Oh, I missed that. Wayland is a bit picky about the serial, so I would have expected the opposite behavior to be true!

We can try taking out the serial in the nightly and see what people say about it.

@hgaiser
Copy link
Author

hgaiser commented Apr 19, 2023

Would you like a PR for that change?

@wez
Copy link
Owner

wez commented Apr 19, 2023

Can you paste the diff here?

@hgaiser
Copy link
Author

hgaiser commented Apr 19, 2023

Absolutely:

diff --git a/window/src/os/wayland/pointer.rs b/window/src/os/wayland/pointer.rs
index 5dc2f0f4..72024f72 100644
--- a/window/src/os/wayland/pointer.rs
+++ b/window/src/os/wayland/pointer.rs
@@ -341,11 +341,8 @@ impl PointerDispatcher {
     }

     pub fn set_cursor(&self, name: Option<&str>, serial: Option<u32>) {
-        let inner = self.inner.lock().unwrap();
-        let serial = serial.unwrap_or(inner.serial);
-
         if let Some(name) = name {
-            if let Err(err) = self.auto_pointer.set_cursor(name, Some(serial)) {
+            if let Err(err) = self.auto_pointer.set_cursor(name, serial) {
                 log::error!("Unable to set cursor to {}: {:#}", name, err);
             }
         } else {

wez added a commit that referenced this issue Apr 19, 2023
Don't fallback to some other serial.

In a new version of SCTK, it looks like the serial we pass should
be the serial from the time we entered the surface, rather than
the latest serial that we have.

In practice, this commit uses None for the serial which seems to
have better results, but may come back to haunt us until we upgrade
to the latest SCTK.

refs: #3334 (comment)
@wez
Copy link
Owner

wez commented Apr 19, 2023

Thanks; I've applied the equivalent of that to main in e204f8b

@hgaiser
Copy link
Author

hgaiser commented Apr 19, 2023

Great, thanks 👍 . Hope it solves other peoples problems too.

@Arjun31415
Copy link

Ok this works for me with Adwaita, sadly not with catppuccin, maybe that is a different issue. Will recheck.

@chrysos349
Copy link

Neither of the commits above (048e8dd and e204f8b) fixed the issue for me.

I still had these errors:

ERROR  window::os::wayland::pointer > set_cursor: Unable to set cursor to arrow: cursor not found, Unable to set cursor to 'default': cursor not found
ERROR  window::os::wayland::frame   > Unable to set cursor to left_ptr: cursor not found

What fixed my problem of the invisible cursor was #3334 (comment). Thanks, @feathecutie!

either via the environment variable XCURSOR_THEME or via the lua config option xcursor_theme, resolved both the cursor hiding issue and the error messages.

@lnicola
Copy link

lnicola commented Apr 20, 2023

Thanks, this is fixed for me.

The mouse cursor is supposed to hide when you press a key. It should reappear when you move the mouse

This is less nice than in other terminal emulators. It disappears on Ctrl-Shift in WezTerm, but not in GNOME Terminal. The latter also doesn't hide the curson on Ctrl-Shift-C or Ctrl-Shift-V. I can file a new issue, if you're open to tweaking this.

@wez
Copy link
Owner

wez commented Apr 20, 2023

@lnicola please file a separate issue for that

@wez
Copy link
Owner

wez commented Apr 20, 2023

@chrysos349 what did you set the theme to?

@chrysos349
Copy link

@wez I have Yaru and Adwaita installed. Either of them solved the issue.

@wez
Copy link
Owner

wez commented Apr 20, 2023

@chrysos349 the way that wezterm (and other software) works is that if you don't specify a theme, default is assumed. Most systems have a symlink or similar that makes default point to whatever the main theme is on the system. It sounds like that might be missing from your system.

@chrysos349
Copy link

@wez I did a little digging. I compared both of my systems (voidlinux and archlinux). I had the issue with the cursor on voidlinux. It turns out there was no default directory in /usr/share/icons/. I created the directory default, and then the file index.theme with this contents:

[Icon Theme]
Inherits=Adwaita

The issue is solved! There is no need to export the environment variable XCURSOR_THEME or set a xcursor_theme lua config option anymore.
Thanks for pointing me in the right direction!

wez added a commit that referenced this issue Apr 20, 2023
@wez wez added the fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. label Apr 20, 2023
@Arjun31415
Copy link

Arjun31415 commented Apr 21, 2023

Ok this works for me with Adwaita, sadly not with catppuccin, maybe that is a different issue. Will recheck.

I have figured out the problem and the solution.
So, I have set the XCURSOR_THEME using gsettings -

echo $XCURSOR_THEME
Catppuccin-Mocha-Maroon

This works in all other GUI applications including browser, kitty, etc.
Now, I tried the same by setting config.xcursor_theme in wezterm config, but to no avail.

The issue is that in /usr/share/icons the folder is saved as Catppuccin-Mocha-Maroon-Cursors.
I changed my config to reflect that

local wezterm = require("wezterm")
return {
-- other setttings
    xcursor_theme="Catppuccin-Mocha-Maroon-Cursors"

}

and now it works !
I'm not sure what the exact issue is and why it is unable to detect the cursor theme even though the index file gives the correct name -

[Icon Theme]
Name=Catppuccin-Mocha-Maroon
Comment=based on Volantes Cursors

UPD: Just checked with XWayland without the xcursor_theme key in config and it works perfectly, including cursor hiding during typing and then reappearing during mouse movement with the correct cursor shape

@wez
Copy link
Owner

wez commented Apr 21, 2023

I suspect that may be an issue in the upstream https://github.com/smithay/client-toolkit that is used to manage themed cursors when running under Wayland. Under X11, wezterm uses its own logic.

@Arjun31415
Copy link

I see, then this issue can be closed, because mine is no longer related to it. Thank you for your help and quick responses

@snaggen
Copy link

snaggen commented May 16, 2023

Just tested this with the latest nightly: 20230515-073311-76406e84
It still doesn't fix the mouse pointer issue described in #2995 , where the mouse pointer stays hidden when split panes is used.

EDIT: Seems that the issue that is still here is not split pane related, but maximized window related (I just combine these). Also, it only happens when you just have maximized the window, and still have not given focus to any other window. If you give focus to another window and come back, then mouse hiding starts to work as expected.

To reproduce that case you just do:

  1. Open a wezterm window.
  2. Maximize the window (I use gnome, so I grab the windowbar and drag it to the top to maximize it). Make sure you keep the focus inside wezterm.
  3. Type in the window so the mouse is hidden.
  4. Move the mouse to make it visible. Now it should be visible but it is not.

And even if this seems like a corner case, it is highly visible if you are using maximized windows in your workflow, since you tend to maximize the window and then right away start typing.

So, this issue is not fully fixed in nightly, and should probably not have the "fixed-in-nightly" label.

@wez
Copy link
Owner

wez commented May 16, 2023

@snaggen please open a separate issue!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2023
@wez
Copy link
Owner

wez commented Jan 4, 2024

For those landing here from search engines: see #1742 (comment) for a way to explicitly apply GNOME's settings to your wezterm mouse cursor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. Wayland
Projects
None yet
Development

No branches or pull requests