From 78183cdb274f0baa75b59b0f9fc6ec7a2eb996fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=E1=BB=B3nh=20Thi=E1=BB=87n=20L=E1=BB=99c?= Date: Sat, 31 Oct 2026 07:51:11 +0700 Subject: [PATCH] fix(osd): handle touchpad hardware keys (#4045) Port 2.0 (cherry picked from commit 0a84c14a1993db932bf60363fa1c748c4bb1cc65) --- core/internal/config/embedded/niri-binds.kdl | 6 ++++++ quickshell/Services/NiriService.qml | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/internal/config/embedded/niri-binds.kdl b/core/internal/config/embedded/niri-binds.kdl index 6b3d5ac0f..4d4410f8f 100644 --- a/core/internal/config/embedded/niri-binds.kdl +++ b/core/internal/config/embedded/niri-binds.kdl @@ -94,6 +94,12 @@ binds { XF86TouchpadToggle allow-when-locked=true repeat=false { spawn "niri" "msg" "action" "toggle-touchpad"; } + XF86TouchpadOn allow-when-locked=true repeat=false { + spawn "dms" "ipc" "call" "niri" "showTouchpadOsd" "true"; + } + XF86TouchpadOff allow-when-locked=true repeat=false { + spawn "dms" "ipc" "call" "niri" "showTouchpadOsd" "false"; + } // === Window Management === Mod+Q repeat=false { close-window; } diff --git a/quickshell/Services/NiriService.qml b/quickshell/Services/NiriService.qml index d727761d0..66e7650c7 100644 --- a/quickshell/Services/NiriService.qml +++ b/quickshell/Services/NiriService.qml @@ -462,15 +462,19 @@ Singleton { } } - function handleTouchpadToggled(data) { - // Each subscription starts with a snapshot; only later changes show the OSD. - const showOsd = _touchpadStateInitialized && touchpadEnabled !== data.on; - touchpadEnabled = data.on; + function updateTouchpadState(enabled, forceOsd) { + const showOsd = forceOsd || (_touchpadStateInitialized && touchpadEnabled !== enabled); + touchpadEnabled = enabled; _touchpadStateInitialized = true; if (showOsd) touchpadToggled(); } + function handleTouchpadToggled(data) { + // Each subscription starts with a snapshot; only later changes show the OSD. + updateTouchpadState(data.on, false); + } + function handleWorkspacesChanged(data) { const newWorkspaces = {}; @@ -1923,6 +1927,14 @@ window-rule { } IpcHandler { + function showTouchpadOsd(enabled: bool): string { + if (!CompositorService.isNiri) + return "NIRI_NOT_AVAILABLE"; + + root.updateTouchpadState(enabled, true); + return "TOUCHPAD_OSD_SHOWN"; + } + function screenshot(): string { if (!CompositorService.isNiri) { return "NIRI_NOT_AVAILABLE";