Skip to content

Conversation

@goferito
Copy link

Summary

Fixes multikey keybinds (binds / s flag) becoming unresponsive after using the mouse scroll wheel, until a mouse click is performed. Workarounds use ydotool to generate click events when pressing mod-keys, but this generates click events in undesirable places.

Fixes #8699

This bug was introduced in #5966 (multikey keybinds feature, May 2024) and has affected users for over a year.

Root Cause

Scroll wheel events pass through handleKeybinds() with keysym=0 and pressed=true. Since scroll events have no "release" phase, this 0 gets inserted into m_mkKeys and never removed, corrupting the keysym tracking state and breaking all subsequent multikey bind matching.

Fix

Skip keysym tracking when key.keysym == 0, as these events don't correspond to actual keys and shouldn't affect the pressed-keysym state.

Testing

  1. Configure a multikey bind: binds = Alt_R, K, exec, kitty
  2. Verify it works
  3. Scroll the mouse wheel
  4. Verify the bind still works (previously it would fail until a click)

@github-actions
Copy link

Hello and thank you for making a PR to Hyprland!

Please check the PR Guidelines and make sure your PR follows them.
It will make the entire review process faster. :)

If your code can be tested, please always add tests. See more here.

beep boop, I'm just a bot. A real human will review your PR soon.

@goferito
Copy link
Author

If someone reads this PR before it gets merged and wants to apply the patch in Arch:

  1. Create build directory and get PKGBUILD:
mkdir -p /tmp/hyprland-build && cd /tmp/hyprland-build
curl -sL "https://gitlab.archlinux.org/archlinux/packaging/packages/hyprland/-/raw/main/PKGBUILD" -o PKGBUILD
  1. Create patch file fix-binds-scroll.patch:
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -646,16 +646,20 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP
   bool            found = false;
   SDispatchResult res;

-    if (pressed) {
-        if (keycodeToModifier(key.keycode))
-            m_mkMods.insert(key.keysym);
-        else
-            m_mkKeys.insert(key.keysym);
-    } else {
-        if (keycodeToModifier(key.keycode))
-            m_mkMods.erase(key.keysym);
-        else
-            m_mkKeys.erase(key.keysym);
+    if (key.keysym != 0) {
+        if (pressed) {
+            if (keycodeToModifier(key.keycode))
+                m_mkMods.insert(key.keysym);
+            else
+                m_mkKeys.insert(key.keysym);
+        } else {
+            if (keycodeToModifier(key.keycode))
+                m_mkMods.erase(key.keysym);
+            else
+                m_mkKeys.erase(key.keysym);
+        }
   }
   for (auto& k : m_keybinds) {
  1. Edit PKGBUILD - add to source and sha256sums:
    source=("$_archive.tar.gz::$url/releases/download/v$pkgver/source-v$pkgver.tar.gz" "fix-binds-scroll.patch")
    sha256sums=('57b4db99896cad8388482b945b119b206fd7ea94638793b550210be08274d7dd' 'SKIP')

  2. Edit PKGBUILD - Add to prepare():
    patch -p1 < "$srcdir/fix-binds-scroll.patch"

  3. Build and install:
    makepkg -si

Tested on Hyprland 0.52.2 - my Alt_R binds now work after scrolling!

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, can you write a test for this please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keybinds with 's' flag does not work after scrolling with mouse until a mouse click

2 participants