diff --git a/widgets/Workspaces.qml b/widgets/Workspaces.qml index 7e255a0..ba2ee53 100644 --- a/widgets/Workspaces.qml +++ b/widgets/Workspaces.qml @@ -2,25 +2,34 @@ import QtQuick import QtQuick.Layouts import Quickshell import Quickshell.I3 +import Quickshell.Hyprland import "../config" -// Sway/i3 workspace switcher for a single monitor. +// Workspace switcher for a single monitor. Works on both Sway/i3 and Hyprland: +// the compositor is detected once from its instance env var, and the matching +// Quickshell backend model is used. The two backends expose the same item shape +// (name / active / focused / urgent / monitor.name / activate()), so a single +// chip renderer covers both. The `?:` on `model` only evaluates the taken +// branch, so the unused backend singleton is never instantiated (no stray IPC). Row { id: root required property var screen // ShellScreen this bar lives on spacing: Theme.gap - // Name of the i3/sway output this bar is on, used to filter workspaces. + // Which compositor are we under? Hyprland always exports this signature. + readonly property bool isHyprland: !!Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE") + + // Name of the output this bar is on, used to filter workspaces. readonly property string monitorName: screen ? screen.name : "" Repeater { - model: I3.workspaces + model: root.isHyprland ? Hyprland.workspaces : I3.workspaces Rectangle { id: chip required property var modelData - // only show workspaces belonging to this monitor - // I3Workspace.monitor is an I3Monitor object, so compare its name + // only show workspaces belonging to this monitor. Both I3Workspace + // and HyprlandWorkspace expose .monitor as an object with a .name. visible: modelData.monitor && modelData.monitor.name === root.monitorName width: visible ? Math.max(height, label.implicitWidth + 16) : 0 height: Theme.barHeight - Theme.gap * 2