aboutsummaryrefslogtreecommitdiffstats
path: root/window-switcher
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-12 18:45:47 +0200
committerDanilo M. <danix@danix.xyz>2026-09-12 18:45:47 +0200
commita5403c00a5af15820165fd2729d0cd4717455c43 (patch)
tree772c26f438c843f3a5232511801bac5b1f1fe60f /window-switcher
parent93e2f4ebbefc13028e04f19a07e758a626194915 (diff)
downloadquickshell-a5403c00a5af15820165fd2729d0cd4717455c43.tar.gz
quickshell-a5403c00a5af15820165fd2729d0cd4717455c43.zip
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SYg4wYHq5XNbiVmMeKRb1S
Diffstat (limited to 'window-switcher')
-rw-r--r--window-switcher/Windows.qml67
1 files changed, 67 insertions, 0 deletions
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. <danix@danix.xyz>
+//
+// 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)}" })`);
+ }
+}