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 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-11-26 00:49:19 +01:00
1 parent 476ad75ba4
commit 6ad9c0b17e
10 files changed
+103 -14

No files matched your search

@@ -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
@@ -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
+45
View File
@@ -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();
}
}
}
+8 -4
View File
@@ -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
+6 -1
View File
@@ -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
+6
View File
@@ -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 {
+6 -1
View File
@@ -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
+6 -1
View File
@@ -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
+8 -4
View File
@@ -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
+6 -1
View File
@@ -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