workspaces: auto-detect Hyprland alongside i3/Sway
Drive the switcher from Hyprland.workspaces when HYPRLAND_INSTANCE_SIGNATURE is set, else fall back to I3.workspaces. The ?: model binding only evaluates the taken branch, so the unused backend singleton is never instantiated (no stray IPC). Both workspace types share the same shape (name/active/focused/ urgent/monitor.name/activate()), so the chip renderer is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+14
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user