From 6ad9c0b17e5f0ca3356f9f62375916848a1a491a Mon Sep 17 00:00:00 2001 From: mx Date: Thu, 26 Nov 2026 00:49:19 +0100 Subject: [PATCH] Close panels on a click outside them Panels relied on Hyprland sending every click to a layer with exclusive keyboard focus; it does not, so clicking another window or monitor left the Control Center, Dashboard, notch, Overview, Settings, wallpaper picker, launcher and plugin panels open. A shared OutsideClick holds a Hyprland focus grab while a panel is open and closes it when the grab is cleared. The bars count as inside, so a bar button still toggles its panel. The old catchers stay as a fallback. Co-Authored-By: Claude Opus 5.5 --- quickshell/compat/noctalia/Host/PanelHost.qml | 5 +++ .../compat/omarchy/Ui/GlassPopupBase.qml | 9 +++- quickshell/components/OutsideClick.qml | 45 +++++++++++++++++++ quickshell/controlcenter/ControlCenter.qml | 12 +++-- quickshell/dashboard/Dashboard.qml | 7 ++- quickshell/launcher/Launcher.qml | 6 +++ quickshell/notch/Notch.qml | 7 ++- quickshell/overview/Overview.qml | 7 ++- quickshell/settings/Settings.qml | 12 +++-- quickshell/wallpaper/WallpaperPicker.qml | 7 ++- 10 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 quickshell/components/OutsideClick.qml diff --git a/quickshell/compat/noctalia/Host/PanelHost.qml b/quickshell/compat/noctalia/Host/PanelHost.qml index acf5906..2744768 100644 --- a/quickshell/compat/noctalia/Host/PanelHost.qml +++ b/quickshell/compat/noctalia/Host/PanelHost.qml @@ -60,6 +60,11 @@ PanelWindow { WlrLayershell.layer: WlrLayer.Overlay WlrLayershell.keyboardFocus: open ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None + C.OutsideClick { + window: root + active: root.open + onOutside: root.api.closePanel(null) + } MouseArea { x: -20000 y: -20000 diff --git a/quickshell/compat/omarchy/Ui/GlassPopupBase.qml b/quickshell/compat/omarchy/Ui/GlassPopupBase.qml index 7e03212..345b5e6 100644 --- a/quickshell/compat/omarchy/Ui/GlassPopupBase.qml +++ b/quickshell/compat/omarchy/Ui/GlassPopupBase.qml @@ -134,8 +134,13 @@ PanelWindow { } } - // Keyboard mode: Hyprland routes every click to the exclusive layer, so - // outside clicks arrive here with out-of-bounds coordinates (see ControlCenter). + C.OutsideClick { + window: root + active: root.open && root.mode === "keyboard" + extraWindows: root.anchorWindow ? [root.anchorWindow] : [] + onOutside: root.close() + } + // Keyboard mode: fallback outside-click catcher (see ControlCenter). MouseArea { x: -20000 y: -20000 diff --git a/quickshell/components/OutsideClick.qml b/quickshell/components/OutsideClick.qml new file mode 100644 index 0000000..6fddbc3 --- /dev/null +++ b/quickshell/components/OutsideClick.qml @@ -0,0 +1,45 @@ +import QtQuick +import Quickshell +import Quickshell.Hyprland +import "../services" + +// Closes an overlay when you click anywhere outside it. Hyprland does not +// route clicks outside a layer to it, even with exclusive keyboard focus, so +// a focus grab does it: clicking another window, the desktop or another +// monitor clears the grab. The bars count as inside, so the bar button that +// opened a panel still toggles it instead of reopening it. +// +// The grab starts once the overlay holds the keyboard; started together with +// the focus change, Hyprland clears it at once. +Item { + id: root + required property var window + property bool active: false + // More windows that count as inside (e.g. the bar a popup hangs from). + property var extraWindows: [] + signal outside + + property bool grabbing: false + function sync() { + grabbing = false; + if (active) + start.restart(); + else + start.stop(); + } + onActiveChanged: sync() + Component.onCompleted: sync() + Timer { + id: start + interval: 150 + onTriggered: root.grabbing = root.active + } + HyprlandFocusGrab { + windows: [root.window].concat(TrayService.barWindows, root.extraWindows).filter((w, i, all) => !!w && all.indexOf(w) === i) + active: root.grabbing + onCleared: if (root.grabbing) { + root.grabbing = false; + root.outside(); + } + } +} diff --git a/quickshell/controlcenter/ControlCenter.qml b/quickshell/controlcenter/ControlCenter.qml index 2b330bb..bd4c47c 100644 --- a/quickshell/controlcenter/ControlCenter.qml +++ b/quickshell/controlcenter/ControlCenter.qml @@ -245,10 +245,14 @@ PanelWindow { } } - // Hyprland routes every pointer event to a layer with exclusive keyboard - // focus, so clicks outside the panel arrive here with out-of-bounds - // coordinates. Qt Quick still delivers them to items extending past the - // window, so this catcher (behind the panel) dismisses on outside clicks. + OutsideClick { + window: root + active: ShellState.controlCenterOpen + onOutside: ShellState.controlCenterOpen = false + } + // Fallback for compositors that route every click to a layer with + // exclusive keyboard focus (out-of-bounds coordinates reach items that + // extend past the window); OutsideClick above covers Hyprland. MouseArea { objectName: "controlCenterOutside" x: -20000 diff --git a/quickshell/dashboard/Dashboard.qml b/quickshell/dashboard/Dashboard.qml index d7270a3..65ae4b6 100644 --- a/quickshell/dashboard/Dashboard.qml +++ b/quickshell/dashboard/Dashboard.qml @@ -66,7 +66,12 @@ PanelWindow { onOptionsChanged: if (options && !options.enabled) ShellState.dashboardOpen = false - // Exclusive focus routes outside clicks here (see ControlCenter). + OutsideClick { + window: root + active: ShellState.dashboardOpen + onOutside: ShellState.dashboardOpen = false + } + // Fallback outside-click catcher (see ControlCenter). MouseArea { objectName: "dashboardOutside" x: -20000 diff --git a/quickshell/launcher/Launcher.qml b/quickshell/launcher/Launcher.qml index 1581841..70b28fd 100644 --- a/quickshell/launcher/Launcher.qml +++ b/quickshell/launcher/Launcher.qml @@ -48,6 +48,12 @@ PanelWindow { anchors.fill: parent onClicked: ShellState.launcherOpen = false } + // The window covers its screen; this catches clicks on other monitors. + OutsideClick { + window: root + active: root.open + onOutside: ShellState.launcherOpen = false + } // Mode pills beside the search bar (macOS Spotlight style): each toggles // its launcher mode; the active one is filled. Row { diff --git a/quickshell/notch/Notch.qml b/quickshell/notch/Notch.qml index e60cad7..1a87f60 100644 --- a/quickshell/notch/Notch.qml +++ b/quickshell/notch/Notch.qml @@ -158,7 +158,12 @@ PanelWindow { } } - // Exclusive focus routes outside clicks here (see ControlCenter). + OutsideClick { + window: root + active: ShellState.notchOpen && !PluginService.activePopout + onOutside: ShellState.notchOpen = false + } + // Fallback outside-click catcher (see ControlCenter). MouseArea { objectName: "notchOutside" x: -20000 diff --git a/quickshell/overview/Overview.qml b/quickshell/overview/Overview.qml index e71bcfd..f871ffc 100644 --- a/quickshell/overview/Overview.qml +++ b/quickshell/overview/Overview.qml @@ -122,7 +122,12 @@ PanelWindow { } } - // Exclusive focus routes outside clicks here (see ControlCenter). + OutsideClick { + window: root + active: ShellState.overviewOpen + onOutside: ShellState.overviewOpen = false + } + // Fallback outside-click catcher (see ControlCenter). MouseArea { x: -20000 y: -20000 diff --git a/quickshell/settings/Settings.qml b/quickshell/settings/Settings.qml index c34edf4..debbd84 100644 --- a/quickshell/settings/Settings.qml +++ b/quickshell/settings/Settings.qml @@ -118,10 +118,14 @@ PanelWindow { onTriggered: ShellState.settingsHighlight = "" } - // Hyprland routes every pointer event to a layer with exclusive keyboard - // focus, so clicks outside the panel arrive here with out-of-bounds - // coordinates. Qt Quick still delivers them to items extending past the - // window, so this catcher (behind the panel) dismisses on outside clicks. + OutsideClick { + window: root + active: ShellState.settingsOpen + onOutside: ShellState.settingsOpen = false + } + // Fallback for compositors that route every click to a layer with + // exclusive keyboard focus (out-of-bounds coordinates reach items that + // extend past the window); OutsideClick above covers Hyprland. MouseArea { objectName: "settingsOutside" x: -20000 diff --git a/quickshell/wallpaper/WallpaperPicker.qml b/quickshell/wallpaper/WallpaperPicker.qml index edfb174..7bc0329 100644 --- a/quickshell/wallpaper/WallpaperPicker.qml +++ b/quickshell/wallpaper/WallpaperPicker.qml @@ -106,7 +106,12 @@ PanelWindow { } } } - // Exclusive focus routes outside clicks here (see ControlCenter). + OutsideClick { + window: root + active: ShellState.wallpaperPickerOpen + onOutside: ShellState.wallpaperPickerOpen = false + } + // Fallback outside-click catcher (see ControlCenter). MouseArea {x:-20000;y:-20000;width:40000;height:40000;onPressed:ShellState.wallpaperPickerOpen=false} BarDrawer { id:surface