Files
dotfiles/.config/quickshell/modules/WorkspacesWidget.qml
T

71 lines
2.3 KiB
QML

// modules/WorkspacesWidget.qml
// Kanji workspace labels, per-monitor, matches waybar hyprland/workspaces.
import QtQuick
import QtQuick.Layouts
import Quickshell.Hyprland
import ".."
Rectangle {
id: root
required property var screen
color: "transparent"
implicitWidth: wsRow.implicitWidth
implicitHeight: Theme.barHeight
// Filter workspaces that belong to this screen's monitor
property string monitorName: {
for (var i = 0; i < Hyprland.monitors.values.length; i++) {
var m = Hyprland.monitors.values[i]
if (m.name === screen.name) return m.name
}
return ""
}
RowLayout {
id: wsRow
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacing
Repeater {
model: {
// sort visible workspaces for this monitor
var all = Hyprland.workspaces.values
return all.filter(ws => ws.monitor && ws.monitor.name === root.monitorName)
.sort((a, b) => a.id - b.id)
}
delegate: Rectangle {
required property var modelData
property bool isActive: modelData.id === (Hyprland.focusedWorkspace?.id ?? -1)
width: 32
height: Theme.barHeight - 4
radius: Theme.radius
Layout.alignment: Qt.AlignVCenter
color: isActive
? Theme.wsActive
: (wsBtn.containsMouse ? Theme.pillHover : Theme.pill)
Behavior on color { ColorAnimation { duration: 200 } }
Text {
anchors.centerIn: parent
text: Math.min(modelData.id - 1, 10 - 1)
font { family: Theme.fontSans; pixelSize: 11 }
color: Theme.foreground
}
MouseArea {
id: wsBtn
anchors.fill: parent
hoverEnabled: true
onClicked: Hyprland.dispatch("workspace " + modelData.id)
onWheel: (w) => Hyprland.dispatch(
"workspace " + (w.angleDelta.y > 0 ? "e+1" : "e-1"))
}
}
}
}
}