make overview show only on focused monitor (fixes #2782)

This commit is contained in:
end-4
2026-01-01 09:26:43 +01:00
parent af1adef5f1
commit 575b26d572
2 changed files with 97 additions and 102 deletions
@@ -14,116 +14,111 @@ import Quickshell.Hyprland
Scope { Scope {
id: overviewScope id: overviewScope
property bool dontAutoCancelSearch: false property bool dontAutoCancelSearch: false
Variants {
id: overviewVariants PanelWindow {
model: Quickshell.screens id: root
PanelWindow { property string searchingText: ""
id: root readonly property HyprlandMonitor monitor: Hyprland.monitorFor(root.screen)
required property var modelData property bool monitorIsFocused: (Hyprland.focusedMonitor?.id == monitor?.id)
property string searchingText: "" visible: GlobalStates.overviewOpen
readonly property HyprlandMonitor monitor: Hyprland.monitorFor(root.screen)
property bool monitorIsFocused: (Hyprland.focusedMonitor?.id == monitor?.id) WlrLayershell.namespace: "quickshell:overview"
screen: modelData WlrLayershell.layer: WlrLayer.Overlay
// WlrLayershell.keyboardFocus: GlobalStates.overviewOpen ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.None
color: "transparent"
mask: Region {
item: GlobalStates.overviewOpen ? columnLayout : null
}
anchors {
top: true
bottom: true
left: true
right: true
}
HyprlandFocusGrab {
id: grab
windows: [root]
property bool canBeActive: root.monitorIsFocused
active: false
onCleared: () => {
if (!active)
GlobalStates.overviewOpen = false;
}
}
Connections {
target: GlobalStates
function onOverviewOpenChanged() {
if (!GlobalStates.overviewOpen) {
searchWidget.disableExpandAnimation();
overviewScope.dontAutoCancelSearch = false;
} else {
if (!overviewScope.dontAutoCancelSearch) {
searchWidget.cancelSearch();
}
delayedGrabTimer.start();
}
}
}
Timer {
id: delayedGrabTimer
interval: Config.options.hacks.arbitraryRaceConditionDelay
repeat: false
onTriggered: {
if (!grab.canBeActive)
return;
grab.active = GlobalStates.overviewOpen;
}
}
implicitWidth: columnLayout.implicitWidth
implicitHeight: columnLayout.implicitHeight
function setSearchingText(text) {
searchWidget.setSearchingText(text);
searchWidget.focusFirstItem();
}
Column {
id: columnLayout
visible: GlobalStates.overviewOpen visible: GlobalStates.overviewOpen
WlrLayershell.namespace: "quickshell:overview"
WlrLayershell.layer: WlrLayer.Overlay
// WlrLayershell.keyboardFocus: GlobalStates.overviewOpen ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.None
color: "transparent"
mask: Region {
item: GlobalStates.overviewOpen ? columnLayout : null
}
anchors { anchors {
top: true horizontalCenter: parent.horizontalCenter
bottom: true top: parent.top
left: true
right: true
} }
spacing: -8
HyprlandFocusGrab { Keys.onPressed: event => {
id: grab if (event.key === Qt.Key_Escape) {
windows: [root] GlobalStates.overviewOpen = false;
property bool canBeActive: root.monitorIsFocused } else if (event.key === Qt.Key_Left) {
active: false if (!root.searchingText)
onCleared: () => { Hyprland.dispatch("workspace r-1");
if (!active) } else if (event.key === Qt.Key_Right) {
GlobalStates.overviewOpen = false; if (!root.searchingText)
Hyprland.dispatch("workspace r+1");
} }
} }
Connections { SearchWidget {
target: GlobalStates id: searchWidget
function onOverviewOpenChanged() { anchors.horizontalCenter: parent.horizontalCenter
if (!GlobalStates.overviewOpen) { Synchronizer on searchingText {
searchWidget.disableExpandAnimation(); property alias source: root.searchingText
overviewScope.dontAutoCancelSearch = false;
} else {
if (!overviewScope.dontAutoCancelSearch) {
searchWidget.cancelSearch();
}
delayedGrabTimer.start();
}
} }
} }
Timer { Loader {
id: delayedGrabTimer id: overviewLoader
interval: Config.options.hacks.arbitraryRaceConditionDelay anchors.horizontalCenter: parent.horizontalCenter
repeat: false active: GlobalStates.overviewOpen && (Config?.options.overview.enable ?? true)
onTriggered: { sourceComponent: OverviewWidget {
if (!grab.canBeActive) screen: root.screen
return; visible: (root.searchingText == "")
grab.active = GlobalStates.overviewOpen;
}
}
implicitWidth: columnLayout.implicitWidth
implicitHeight: columnLayout.implicitHeight
function setSearchingText(text) {
searchWidget.setSearchingText(text);
searchWidget.focusFirstItem();
}
Column {
id: columnLayout
visible: GlobalStates.overviewOpen
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
}
spacing: -8
Keys.onPressed: event => {
if (event.key === Qt.Key_Escape) {
GlobalStates.overviewOpen = false;
} else if (event.key === Qt.Key_Left) {
if (!root.searchingText)
Hyprland.dispatch("workspace r-1");
} else if (event.key === Qt.Key_Right) {
if (!root.searchingText)
Hyprland.dispatch("workspace r+1");
}
}
SearchWidget {
id: searchWidget
anchors.horizontalCenter: parent.horizontalCenter
Synchronizer on searchingText {
property alias source: root.searchingText
}
}
Loader {
id: overviewLoader
anchors.horizontalCenter: parent.horizontalCenter
active: GlobalStates.overviewOpen && (Config?.options.overview.enable ?? true)
sourceComponent: OverviewWidget {
panelWindow: root
visible: (root.searchingText == "")
}
} }
} }
} }
@@ -13,8 +13,8 @@ import Quickshell.Hyprland
Item { Item {
id: root id: root
required property var panelWindow required property var screen
readonly property HyprlandMonitor monitor: Hyprland.monitorFor(panelWindow.screen) readonly property HyprlandMonitor monitor: Hyprland.monitorFor(screen)
readonly property var toplevels: ToplevelManager.toplevels readonly property var toplevels: ToplevelManager.toplevels
readonly property int workspacesShown: Config.options.overview.rows * Config.options.overview.columns readonly property int workspacesShown: Config.options.overview.rows * Config.options.overview.columns
readonly property int workspaceGroup: Math.floor((monitor.activeWorkspace?.id - 1) / workspacesShown) readonly property int workspaceGroup: Math.floor((monitor.activeWorkspace?.id - 1) / workspacesShown)