Files
glassMxrph/quickshell/services/HyprlandService.qml
T
mxandClaude Opus 5.5 178041edf9 Switch overview workspaces after keyboard focus is released
Closing the overview handed focus back to the previous window after the
workspace switch, pulling back to the old workspace whenever it was occupied.
Release focus first, then switch. Window clicks go to their workspace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:03:56 +01:00

125 lines
5.1 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Hyprland
import Quickshell.Io
Singleton {
id: root
readonly property var visibleWorkspaces: Hyprland.workspaces.values.filter(w => w.active).map(w => w.id)
// Hyprland IPC details by address (no 0x). Quickshell fills lastIpcObject
// only at startup, and Hyprland.refreshToplevels() can crash 0.3.1, so later
// windows lacked their initial class (dock matching), mapped/hidden state and
// floating flag. One query per burst of window events; nothing while idle.
property var clients: ({})
readonly property var windows: Hyprland.toplevels.values.map(t => {
const info = root.clients[String(t.address).replace(/^0x/, "")] || t.lastIpcObject || {};
return {
address: t.address,
handle: t.wayland,
appId: t.wayland ? t.wayland.appId : info.class || "",
initialClass: info.initialClass || "",
title: t.title,
active: t.activated,
monitor: t.monitor ? t.monitor.name : "",
workspace: t.workspace ? t.workspace.id : 0,
x: info.at ? info.at[0] : 0,
y: info.at ? info.at[1] : 0,
width: info.size ? info.size[0] : 0,
height: info.size ? info.size[1] : 0,
// Without IPC data, only a foreign-toplevel handle proves the window is mapped.
hidden: info.hidden === true || info.mapped === false || (!t.wayland && !info.address),
fullscreen: info.fullscreen === 2,
floating: info.floating === true
};
}).filter(w => !w.hidden)
// Monitors whose desktop is hidden: a tiled or fullscreen window sits on
// their active workspace. Desktop widgets pause animation and sampling there.
readonly property var coveredMonitors: windows.filter(w => visibleWorkspaces.includes(w.workspace) && (!w.floating || w.fullscreen)).map(w => w.monitor)
readonly property bool needsGeometry: ConfigService.ready && ConfigService.data.dock.enabled && ConfigService.data.dock.visibility === "intelligent"
function focusWindow(address) {
const window = windows.find(w => w.address === address);
if (!window)
return false;
if (window.handle)
window.handle.activate();
else if (/^(0x)?[0-9a-f]+$/i.test(address))
Hyprland.dispatch("hl.dsp.focus({ window = 'address:" + (address.startsWith("0x") ? address : "0x" + address) + "' })");
else
return false;
return true;
}
function closeWindow(address) {
const window = windows.find(w => w.address === address);
if (!window)
return false;
if (window.handle)
window.handle.close();
else if (/^(0x)?[0-9a-f]+$/i.test(address))
Hyprland.dispatch("hl.dsp.window.close({ window = 'address:" + (address.startsWith("0x") ? address : "0x" + address) + "' })");
else
return false;
return true;
}
function focusWorkspace(id) {
if (!Number.isInteger(id) || id < 1)
return false;
Hyprland.dispatch("hl.dsp.focus({ workspace = '" + id + "' })");
return true;
}
// Moves a window to a workspace without following it there.
function moveToWorkspace(address, id) {
if (!/^(0x)?[0-9a-f]+$/i.test(address) || !Number.isInteger(id) || id < 1)
return false;
Hyprland.dispatch("hl.dsp.window.move({ workspace = '" + id + "', follow = false, window = 'address:" + (address.startsWith("0x") ? address : "0x" + address) + "' })");
clientsDebounce.restart();
return true;
}
// Re-reads window geometry now (Hyprland emits no event for resizes).
function refresh() {
clientsDebounce.restart();
}
Process {
id: clientsQuery
command: ["hyprctl", "-j", "clients"]
stdout: StdioCollector {
onStreamFinished: {
try {
const next = {};
for (const c of JSON.parse(text))
next[String(c.address).replace(/^0x/, "")] = c;
root.clients = next;
} catch (e) {}
}
}
}
Timer {
id: clientsDebounce
interval: 150
onTriggered: {
if (clientsQuery.running)
restart();
else
clientsQuery.running = true;
}
}
// Title changes (frequent: terminals, browsers) don't affect these fields.
readonly property var clientEvents: ["openwindow", "closewindow", "movewindowv2", "changefloatingmode", "fullscreen", "togglegroup", "moveintogroup", "moveoutofgroup"]
Connections {
target: Hyprland
function onRawEvent(event) {
if (root.clientEvents.includes(event.name))
clientsDebounce.restart();
}
}
Component.onCompleted: clientsDebounce.restart()
// Native IPC, not subprocess polling. Hyprland emits no continuous resize event.
Timer {
interval: 500
repeat: true
running: root.needsGeometry
triggeredOnStart: true
onTriggered: Hyprland.refreshToplevels()
}
}