From ab3fa11a4b0a5e2dc999d91d98269b3204f0aaa3 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 7 Oct 2026 18:47:14 +0200 Subject: refactor: move the workspace icon map to a shared singleton The island's clock pill shows the same desktop icon the window switcher does. One map, symlinked into both components like Theme.qml, rather than a second copy that would drift. Co-Authored-By: Claude Opus 5.5 --- desktop/Workspaces.qml | 1 + shared/Workspaces.qml | 39 +++++++++++++++++++++++++++++++++++++++ window-switcher/Windows.qml | 24 +++--------------------- window-switcher/Workspaces.qml | 1 + 4 files changed, 44 insertions(+), 21 deletions(-) create mode 120000 desktop/Workspaces.qml create mode 100644 shared/Workspaces.qml create mode 120000 window-switcher/Workspaces.qml diff --git a/desktop/Workspaces.qml b/desktop/Workspaces.qml new file mode 120000 index 0000000..712f3d6 --- /dev/null +++ b/desktop/Workspaces.qml @@ -0,0 +1 @@ +../shared/Workspaces.qml \ No newline at end of file diff --git a/shared/Workspaces.qml b/shared/Workspaces.qml new file mode 100644 index 0000000..ca4f5b0 --- /dev/null +++ b/shared/Workspaces.qml @@ -0,0 +1,39 @@ +// 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 QtQuick + +// The desktop icon for each workspace, the eight waybar drew and the window +// switcher and the island show. Names, not paths: they are resolved through +// the active icon theme, so an icon theme switch changes them everywhere. +// A named workspace, or one past eight, has none, and callers fall back to +// its number. +Singleton { + readonly property var icons: ({ + 1: "web-browser", + 2: "text-editor", + 3: "utilities-terminal", + 4: "network-server", + 5: "document-edit", + 6: "applications-graphics", + 7: "dialog-messages", + 8: "input-gaming", + }) + + function icon(name) { + const n = parseInt(String(name), 10); + if (isNaN(n)) return ""; + return icons[n] ?? ""; + } +} diff --git a/window-switcher/Windows.qml b/window-switcher/Windows.qml index ec86ee5..bfd176a 100644 --- a/window-switcher/Windows.qml +++ b/window-switcher/Windows.qml @@ -65,27 +65,9 @@ Singleton { Hyprland.dispatch(`hl.dsp.window.close({ window = "address:${addressOf(toplevel)}" })`); } - // The desktop marker on a card is the same icon waybar's bar draws for that - // workspace, so the switcher and the bar agree. waybar keeps them as CSS - // background images by workspace number (styles/modules.css); the names are - // repeated here and resolved through the active icon theme, because a - // QML-side icon has to go by name. A named workspace, or one past eight, - // has no icon and the card falls back to its number. - readonly property var workspaceIcons: ({ - 1: "web-browser", - 2: "text-editor", - 3: "utilities-terminal", - 4: "network-server", - 5: "document-edit", - 6: "applications-graphics", - 7: "dialog-messages", - 8: "input-gaming", - }) - + // The desktop marker on a card is the same icon the island and the old + // waybar bar show for that workspace; the map lives in Workspaces.qml. function workspaceIcon(workspace) { - if (!workspace) return ""; - const n = parseInt(String(workspace.name), 10); - if (isNaN(n)) return ""; - return root.workspaceIcons[n] ?? ""; + return workspace ? Workspaces.icon(workspace.name) : ""; } } diff --git a/window-switcher/Workspaces.qml b/window-switcher/Workspaces.qml new file mode 120000 index 0000000..712f3d6 --- /dev/null +++ b/window-switcher/Workspaces.qml @@ -0,0 +1 @@ +../shared/Workspaces.qml \ No newline at end of file -- cgit v1.2.3