From 38a03a4485e943582dc60d89a68b9977904e48d9 Mon Sep 17 00:00:00 2001 From: bbedward Date: Tue, 30 Jun 2026 23:27:25 -0400 Subject: [PATCH] hyprland: general focus fixes related to #2561 --- core/internal/config/embedded/hyprland.lua | 1 + quickshell/Common/KeyboardFocus.qml | 10 ++++++++++ quickshell/Modals/Common/DankModal.qml | 3 +++ quickshell/Modules/DankBar/Widgets/SystemTrayBar.qml | 6 ++++++ quickshell/Widgets/DankPopout.qml | 5 ++++- quickshell/Widgets/DankPopoutConnected.qml | 2 +- quickshell/Widgets/DankPopoutStandalone.qml | 2 +- 7 files changed, 26 insertions(+), 3 deletions(-) diff --git a/core/internal/config/embedded/hyprland.lua b/core/internal/config/embedded/hyprland.lua index 9427f4bf0..ea6cc058e 100644 --- a/core/internal/config/embedded/hyprland.lua +++ b/core/internal/config/embedded/hyprland.lua @@ -13,6 +13,7 @@ hl.config({ input = { kb_layout = "us", numlock_by_default = true, + follow_mouse = 0, touchpad = { tap_to_click = true, natural_scroll = true, diff --git a/quickshell/Common/KeyboardFocus.qml b/quickshell/Common/KeyboardFocus.qml index f7a521414..0c52606b9 100644 --- a/quickshell/Common/KeyboardFocus.qml +++ b/quickshell/Common/KeyboardFocus.qml @@ -25,6 +25,16 @@ Singleton { return CompositorService.useHyprlandFocusGrab && keyboardFocus(active, customFocus) === WlrKeyboardFocus.OnDemand; } + function captureActiveToplevel() { + return ToplevelManager.activeToplevel; + } + + function restoreToplevel(toplevel) { + if (toplevel) + Qt.callLater(() => toplevel.activate()); + return null; + } + property list barWindows: [] function registerBarWindow(window) { diff --git a/quickshell/Modals/Common/DankModal.qml b/quickshell/Modals/Common/DankModal.qml index 820bb2499..0dec4eae8 100644 --- a/quickshell/Modals/Common/DankModal.qml +++ b/quickshell/Modals/Common/DankModal.qml @@ -58,6 +58,9 @@ Item { HyprlandFocusGrab { windows: root.contentWindow ? [root.contentWindow] : [] active: KeyboardFocus.wantsGrab(root.shouldHaveFocus, root.customKeyboardFocus) + + property var restoreToplevel: null + onActiveChanged: restoreToplevel = active ? KeyboardFocus.captureActiveToplevel() : KeyboardFocus.restoreToplevel(restoreToplevel) } readonly property var contentWindow: impl.item ? impl.item.contentWindow : null readonly property var effectiveScreen: impl.item ? impl.item.effectiveScreen : null diff --git a/quickshell/Modules/DankBar/Widgets/SystemTrayBar.qml b/quickshell/Modules/DankBar/Widgets/SystemTrayBar.qml index c6345bcb2..e62c22db3 100644 --- a/quickshell/Modules/DankBar/Widgets/SystemTrayBar.qml +++ b/quickshell/Modules/DankBar/Widgets/SystemTrayBar.qml @@ -1051,6 +1051,9 @@ BasePill { HyprlandFocusGrab { windows: [overflowMenu].concat(KeyboardFocus.barWindows) active: root.useOverflowPopup && KeyboardFocus.wantsGrab(root.menuOpen, null) + + property var restoreToplevel: null + onActiveChanged: restoreToplevel = active ? KeyboardFocus.captureActiveToplevel() : KeyboardFocus.restoreToplevel(restoreToplevel) } Connections { @@ -1595,6 +1598,9 @@ BasePill { HyprlandFocusGrab { windows: [menuWindow].concat(KeyboardFocus.barWindows) active: KeyboardFocus.wantsGrab(menuRoot.showMenu, null) + + property var restoreToplevel: null + onActiveChanged: restoreToplevel = active ? KeyboardFocus.captureActiveToplevel() : KeyboardFocus.restoreToplevel(restoreToplevel) } anchors { diff --git a/quickshell/Widgets/DankPopout.qml b/quickshell/Widgets/DankPopout.qml index 7ffbc1bca..92793414e 100644 --- a/quickshell/Widgets/DankPopout.qml +++ b/quickshell/Widgets/DankPopout.qml @@ -65,7 +65,10 @@ Item { list.push(root.backgroundWindow); return list.concat(KeyboardFocus.barWindows); } - active: KeyboardFocus.wantsGrab(root.shouldBeVisible || root.isClosing, root.customKeyboardFocus) + active: KeyboardFocus.wantsGrab(root.shouldBeVisible, root.customKeyboardFocus) + + property var restoreToplevel: null + onActiveChanged: restoreToplevel = active ? KeyboardFocus.captureActiveToplevel() : KeyboardFocus.restoreToplevel(restoreToplevel) } Loader { diff --git a/quickshell/Widgets/DankPopoutConnected.qml b/quickshell/Widgets/DankPopoutConnected.qml index 48211ea59..50626e188 100644 --- a/quickshell/Widgets/DankPopoutConnected.qml +++ b/quickshell/Widgets/DankPopoutConnected.qml @@ -965,7 +965,7 @@ Item { WlrLayershell.namespace: root.layerNamespace WlrLayershell.layer: root.effectivePopoutLayer WlrLayershell.exclusiveZone: -1 - WlrLayershell.keyboardFocus: KeyboardFocus.keyboardFocus(shouldBeVisible || (isClosing && CompositorService.useHyprlandFocusGrab), customKeyboardFocus) + WlrLayershell.keyboardFocus: KeyboardFocus.keyboardFocus(shouldBeVisible, customKeyboardFocus) readonly property bool _fullHeight: root.fullHeightSurface anchors { diff --git a/quickshell/Widgets/DankPopoutStandalone.qml b/quickshell/Widgets/DankPopoutStandalone.qml index 180b6b411..1f6aec4e5 100644 --- a/quickshell/Widgets/DankPopoutStandalone.qml +++ b/quickshell/Widgets/DankPopoutStandalone.qml @@ -636,7 +636,7 @@ Item { WlrLayershell.namespace: root.layerNamespace WlrLayershell.layer: root.effectivePopoutLayer WlrLayershell.exclusiveZone: -1 - WlrLayershell.keyboardFocus: KeyboardFocus.keyboardFocus(shouldBeVisible || (isClosing && CompositorService.useHyprlandFocusGrab), customKeyboardFocus) + WlrLayershell.keyboardFocus: KeyboardFocus.keyboardFocus(shouldBeVisible, customKeyboardFocus) anchors { left: true