warpdotdev / Warp

Warp is a modern, Rust-based terminal with AI built in so you and your team can build great software, faster.
https://warp.dev
Other
20.31k stars 338 forks source link

Global hotkey not supported on Wayland #4800

Open FredHaa opened 2 months ago

FredHaa commented 2 months ago

Discord username (optional)

No response

Describe the bug

After newest update Global hotkey no longer works with Wayland. It worked somewhat before (The hotkey only worked when some windows were in focus like Slack and VSCode, not Firefox and Nautilus).

To reproduce

Go to setting -> features -> keys Global hotkey feature greyed out.

Expected behavior

No response

Screenshots

Screenshot from 2024-04-21 18-33-40

Operating system

Linux

Operating system and version

Archlinux

Shell Version

zsh 5.9

Current Warp version

v0.2024.04.16.08.02.stable_00

Regression

Yes, this bug started recently or with an X Warp version

Recent working Warp date

No response

Additional context

No response

Does this block you from using Warp daily?

No

Is this a Warp specific issue? (i.e. does it happen in Terminal, iTerm, Kitty, etc.)

Yes, this I confirmed this only happens in Warp, not other terminals.

Warp Internal (ignore): linear-label:b9d78064-c89e-4973-b153-5178a31ee54e

None

acarl005 commented 2 months ago

Hi @FredHaa. Unfortunately, the Wayland protocol simply doesn't have the functionality to support this feature. Although xdg-desktop-portal does have global hotkeys, Wayland will not allow, for example, an application to bring its window to the front. Currently, the closest thing Wayland allows is for a window to "ask" for activation, which won't actually show the window in most desktop environments. As such, if Warp acts as a Wayland client, it cannot support this feature anymore.

When Warp acts as an X11 client (through Xwayland), this feature becomes kind of possible due to the backwards compatilibity. As you've noticed, it is finnicky, since we can only capture global hotkeys when another X11 client is focused, such as Chrome or other Chromium-based apps. If you want to get back the old behavior, we'll soon release an option you can toggle, "Use X11 for window management," in the settings.

Screenshot from 2024-04-22 15-45-03

There are 2 alternatives as well:

  1. Configure a hotkey with your window manager. This is highly dependent on your desktop environment. But, there should be a way to bind a keystroke to show Warp.
  2. Switch your desktop session to use X11 instead of Wayland. In this case, Warp's own global hotkey should work perfectly. However, it comes with the drawback that you have to go back to X11 which we don't necessarily recommend. It would come with other limitations w.r.t. scaling, frame rates, and any other baggage with X11.
FredHaa commented 2 months ago

Sounds good with the option to run with XWayland.

Even better would be to fix the problem similar to how Guake does it. I.e. implementing a command warp-toggle which would trivialize setting up the window manager hotkey as you suggest as the first alternative.

FredHaa commented 2 months ago

For reference, Guake uses DBus to show/hide window:

def toggle_guake_by_dbus():
    import dbus  # pylint: disable=import-outside-toplevel

    try:
        bus = dbus.SessionBus()
        remote_object = bus.get_object("org.guake3.RemoteControl", "/org/guake3/RemoteControl")
        print("Sending 'toggle' message to Guake3")
        remote_object.show_hide()
    except dbus.DBusException:
        pass
acarl005 commented 2 months ago

Ah thanks for the pointer. I'll dig into the Guake method and see what Warp can do herel.