ublue-os / bazzite

Bazzite is a cloud native image built upon Fedora Atomic Desktops that brings the best of Linux gaming to all of your devices - including your favorite handheld.
https://bazzite.gg
Apache License 2.0
4.05k stars 247 forks source link

[Game Mode] Steam Overlay hotkey collision with games #1720

Closed AkazaRenn closed 1 month ago

AkazaRenn commented 1 month ago

Describe the bug

Hitting ctrl + 1 and ctrl + 2 in game opens the the Steam Overlay, while there are some other functions to be done by the game.

Use the classic Counter-Strike for example, ctrl is for crouching, 1 and 2 switch to the major and alternative weapons respectively. They are supposed to be working in combinations, but now they will bring up Steam Overlay and QAM instead.

Steam OS doesn't have this issue. Bazzite OS Deck image on Desktop Mode doesn't have this issue.

What did you expect to happen?

Same as Steam OS, disable the aforementioned hotkeys while in game

Output of rpm-ostree status

No response

Hardware

No response

Extra information or context

No response

parkerlreed commented 1 month ago

This is enabled for the gamescope session as a convenience for keyboard users to get back to Steam/exit game.

The reason it only happens here is it's explicitly patched in to either the Steam client or gamescope I don't recall.

There should be a way to reverse the patch.

parkerlreed commented 1 month ago

Looks like you'd need to rebuild gamescope with this patch reverted. https://github.com/ublue-os/bazzite/blob/main/spec_files/gamescope/v2-0001-always-send-ctrl-1-2-to-steam-s-wayland-session.patch

Likely easier to just use desktop mode for playing those specific games.

AkazaRenn commented 1 month ago

This is enabled for the gamescope session as a convenience for keyboard users to get back to Steam/exit game.

The reason it only happens here is it's explicitly patched in to either the Steam client or gamescope I don't recall.

There should be a way to reverse the patch.

Is there a way to get shift + tab to work instead? ctrl + 1 is too disruptive... I wish I don't have to keep switching between modes.

Not sure if we change the file you mentioned to detect shift + tab instead, it will just start working or not.

Another solution is to use menu + 1/2 to replace ctrl + 1/2 since this key has nothing to do in Game Mode.

AkazaRenn commented 1 month ago

Use shift + tab instead

diff --git a/src/wlserver.cpp b/src/wlserver.cpp
index 9c82a76..1179d57 100644
--- a/src/wlserver.cpp
+++ b/src/wlserver.cpp
@@ -312,8 +312,7 @@ static void wlserver_handle_key(struct wl_listener *listener, void *data)
        keysym == XKB_KEY_XF86PowerOff;

    // Check for steam keys (ctrl + 1/2)
-   bool is_steamshortcut = (keyboard->wlr->modifiers.depressed & WLR_MODIFIER_CTRL) && (keysym == XKB_KEY_1 ||
-                                                                                        keysym == XKB_KEY_2);
+   bool is_steamshortcut = (keyboard->wlr->modifiers.depressed & WLR_MODIFIER_SHIFT) && (keysym == XKB_KEY_TAB);

    if ( ( event->state == WL_KEYBOARD_KEY_STATE_PRESSED || event->state == WL_KEYBOARD_KEY_STATE_RELEASED ) && (forbidden_key || is_steamshortcut) )
    {

Pro: default Steam settings, should work in most cases Cons: Steam settings can be changed, but we disable the option in game mode so that could be unlikely to happen. Also we'll miss the ability for QAM in one click, but there will be ways once the overlay is up.

Use super

diff --git a/src/wlserver.cpp b/src/wlserver.cpp
index 9c82a76..eb81643 100644
--- a/src/wlserver.cpp
+++ b/src/wlserver.cpp
@@ -312,7 +312,7 @@ static void wlserver_handle_key(struct wl_listener *listener, void *data)
        keysym == XKB_KEY_XF86PowerOff;

    // Check for steam keys (ctrl + 1/2)
-   bool is_steamshortcut = (keyboard->wlr->modifiers.depressed & WLR_MODIFIER_CTRL) && (keysym == XKB_KEY_1 ||
+   bool is_steamshortcut = (keyboard->wlr->modifiers.depressed & WLR_MODIFIER_LOGO) && (keysym == XKB_KEY_1 ||
                                                                                         keysym == XKB_KEY_2);

    if ( ( event->state == WL_KEYBOARD_KEY_STATE_PRESSED || event->state == WL_KEYBOARD_KEY_STATE_RELEASED ) && (forbidden_key || is_steamshortcut) )
@@ -326,7 +326,10 @@ static void wlserver_handle_key(struct wl_listener *listener, void *data)
            wlr_seat_set_keyboard( wlserver.wlr.seat, keyboard->wlr );
            // Send modifiers to steam for it to work
            if (is_steamshortcut)
+           {
+               keyboard->wlr->modifiers.depressed = keyboard->wlr->modifiers.depressed & (~WLR_MODIFIER_LOGO) | WLR_MODIFIER_CTRL;
                wlr_seat_keyboard_notify_modifiers(wlserver.wlr.seat, &keyboard->wlr->modifiers);
+           }
            wlr_seat_keyboard_notify_key( wlserver.wlr.seat, event->time_msec, event->keycode, event->state );
            wlserver_keyboardfocus( old_kb_surf, false );
            return;

Pro: both overlay and QAM are supported Con: only works in Bazzite game mode not anywhere else, can cause consistency issue

I prefer the first one, didn't test either of them though...

AkazaRenn commented 1 month ago

With the merge of https://github.com/ublue-os/bazzite/pull/1724, anyone facing this issue can add GS_ENABLE_CTRL_12=0 to /etc/environment or any file inside /etc/environment.d/ to disable it and use super + 1/2 instead.