Skip to content

Add HID driver to filter BTN_0 (FN key) events on Surface devices - #1870

Merged
qzed merged 2 commits into
linux-surface:masterfrom
ciarancoffey:fn-key-btn0-fix
Dec 31, 2025
Merged

qzed merged 2 commits into
linux-surface:masterfrom
ciarancoffey:fn-key-btn0-fix

Conversation

@ciarancoffey

Copy link
Copy Markdown
Contributor

Summary

Fixes #1851 - FN key causing focus to get stuck in KWin Wayland

The Surface Aggregator Module firmware incorrectly reports the FN key as BTN_0 (button 256) through runtime HID events. This button can get stuck in pressed state, flooding the input system (~29 events per second), which breaks focus tracking in KWin Wayland compositor.

Solution

This PR adds kernel patches for 6.16 and 6.17 that create a HID driver (hid-surface.c) to filter BTN_0 events using the event callback. This prevents BTN_0 from reaching the input subsystem while allowing all other keyboard/touchpad functionality to work normally.

Testing Results

Hardware: Surface Laptop 4 AMD (Ryzen 5)
OS: Arch Linux
Desktop: KDE Plasma 6.4.5 Wayland

Tested on Kernel 6.16.9-arch1-1-surface

  • ✅ FN+Volume works correctly
  • ✅ FN+Brightness works correctly
  • ✅ Focus tracking works normally
  • ✅ No stuck mouse clicks
  • ✅ All touchpad gestures work
  • ✅ BTN_0 events successfully filtered

Tested on Kernel 6.17.1-arch1-1-surface

  • ✅ Bug confirmed present before fix
  • ✅ Fix works correctly after applying patch
  • ✅ All FN key functionality working
  • ✅ Focus tracking restored

Technical Details

Key insight: BTN_0 is NOT in the HID descriptor - it's generated dynamically at runtime from HID reports. This is why the fix required using the event callback rather than input_mapping.

Why it affects KWin Wayland specifically: X11 and GNOME Wayland handle stuck button events more gracefully. KWin Wayland's focus tracking is more sensitive to input flooding.

Compatibility & Testing Request

⚠️ Important: This has only been tested on Surface Laptop 4 AMD. It is unclear whether this issue affects Intel variants of Surface devices, or if the fix might have unintended effects on Intel models.

Confirmed working:

  • Surface Laptop 4 AMD (Ryzen 5)

Needs testing:

Please test if you have an Intel-based Surface device! We need to verify:

  1. Whether the bug exists on Intel variants
  2. Whether the fix works safely on Intel variants
  3. Whether there are any side effects

Patch Details

The patch adds 3 files totaling 99 lines per kernel version:

  • drivers/hid/hid-surface.c (new, 90 lines)
  • drivers/hid/Kconfig (modified, +8 lines)
  • drivers/hid/Makefile (modified, +1 line)

Patches included for:

  • patches/6.16/0016-hid-surface-fn-key.patch
  • patches/6.17/0016-hid-surface-fn-key.patch

Fixes: #1851

Fixes linux-surface#1851 - FN key causing focus to get stuck in KWin Wayland

The Surface Aggregator Module firmware incorrectly reports the FN key
as BTN_0 (button 256). This can get stuck in pressed state, flooding
the input system and breaking focus tracking in compositors.

This patch adds a new HID driver (hid-surface.c) that filters BTN_0
events while allowing all other keyboard/touchpad functionality to
work normally.

Tested on Surface Laptop 4 AMD with KDE Plasma Wayland.
The fix also applies to kernel 6.17.1 - tested and confirmed bug exists
there too.
@qzed

qzed commented Dec 31, 2025

Copy link
Copy Markdown
Member

Added to our kernel repo in linux-surface/kernel@7dcd050.

@qzed qzed left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@qzed
qzed merged commit c14cd4e into linux-surface:master Dec 31, 2025
@qzed qzed mentioned this pull request Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SL4A FN keys not working

2 participants