From a5403c00a5af15820165fd2729d0cd4717455c43 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sat, 12 Sep 2026 18:45:47 +0200 Subject: feat(window-switcher): the window model, filtered and sorted One place for everything that touches Hyprland, so the UI never issues a dispatch itself. That matters more than usual here because dispatch arguments are Lua on 0.56.2 and the documented-looking form is a syntax error that fails silently, and because HyprlandToplevel.address omits the 0x prefix that a dispatch needs. focusHistoryID is not a HyprlandToplevel property, only a field of the raw hyprctl object, so reading it directly returned undefined and left the sort a no-op. It is read through lastIpcObject, with a missing one sorting last rather than as most recent. Only special: workspaces are filtered, matching the rofi script this replaces. Windows elsewhere are kept whatever their visibility, since jumping to another desktop is the point of a switcher. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01SYg4wYHq5XNbiVmMeKRb1S --- window-switcher/Windows.qml | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 window-switcher/Windows.qml (limited to 'window-switcher/Windows.qml') diff --git a/window-switcher/Windows.qml b/window-switcher/Windows.qml new file mode 100644 index 0000000..040f4d4 --- /dev/null +++ b/window-switcher/Windows.qml @@ -0,0 +1,67 @@ +// Copyright (C) 2026 Danilo M. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +pragma Singleton + +import Quickshell +import Quickshell.Hyprland +import QtQuick + +// Everything that touches Hyprland lives here, so the filter, the sort and +// the dispatch syntax are in one place rather than spread across the UI. +Singleton { + id: root + + // Hyprland.toplevels reads 0 until this is called. + function refresh() { Hyprland.refreshToplevels(); } + + // Windows on a special: workspace are the scratchpad, which is reached by + // its own bind and is not something to tab to. Windows on other + // workspaces are kept whatever their visibility: jumping to another + // desktop is the point. + readonly property var windows: { + const out = []; + for (const t of Hyprland.toplevels.values) { + const ws = t.workspace; + if (!ws || String(ws.name).startsWith("special:")) continue; + out.push(t); + } + // Lowest focusHistoryID is the most recently used. HyprlandToplevel + // does not expose it as a property, only inside the raw hyprctl + // object, where a missing one sorts last rather than as 0. + out.sort((a, b) => root.focusOrder(a) - root.focusOrder(b)); + return out; + } + + function focusOrder(toplevel) { + const o = toplevel.lastIpcObject; + const n = o ? Number(o.focusHistoryID) : NaN; + return isNaN(n) ? Number.MAX_SAFE_INTEGER : n; + } + + // Dispatch arguments are evaluated as Lua on Hyprland 0.56.2, so the + // documented-looking `focuswindow address:0x...` is a syntax error that + // fails silently. This form is the one that works. + // + // HyprlandToplevel.address has no 0x prefix, while the dispatch needs one. + function addressOf(toplevel) { + const a = String(toplevel.address); + return a.startsWith("0x") ? a : "0x" + a; + } + + function focus(toplevel) { + Hyprland.dispatch(`hl.dsp.focus({ window = "address:${addressOf(toplevel)}" })`); + } + + function closeWindow(toplevel) { + Hyprland.dispatch(`hl.dsp.window.close({ window = "address:${addressOf(toplevel)}" })`); + } +} -- cgit v1.2.3