quickshell-config/modules/bar/components/Workspaces.qml

110 lines
2.9 KiB
QML
Raw Normal View History

2025-06-24 07:46:51 +02:00
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Io
import QtQuick.Layouts
import "../../../services/niri"
import "../../../config"
Rectangle {
id: root
required property ShellScreen screen
property var workspaces: Niri.workspaces
2025-06-24 15:51:34 +02:00
property var wsCount: Niri.workspaces.length
2025-06-24 07:46:51 +02:00
property var activeWorkspace: Niri.activeWorkspace
property var activeWorkspaceIndex: Niri.activeWorkspaceIndex
property int wsItemHeight: 15
2025-06-24 15:51:34 +02:00
signal workspaceAdded(workspace: var)
function onWorkspaceAdded(workspace: var) {
root.workspaces.push(workspace);
2025-06-24 07:46:51 +02:00
}
2025-06-24 15:51:34 +02:00
// property bool _: log()
// function log() {
// console.log(workspaces.values);
// return true;
// }
2025-06-24 07:46:51 +02:00
// Works
height: 300
// Gives warning
// height: workspaces.length * root.wsItemHeight
implicitWidth: list.implicitWidth
color: "transparent"
border.color: Config.catppuccin.rosewater
border.width: 0
radius: 7
Layout.fillWidth: true
ListView {
id: list
model: root.workspaces
implicitHeight: contentHeight
implicitWidth: contentItem.childrenRect.width
anchors.horizontalCenter: parent.horizontalCenter
// anchors.fill: parent
delegate: Item {
id: wsItem
// Name of the workspace
property string name: "VOID"
// ID of the workspace
required property string id
required property string output
property bool isActive: (id - 1 == root.activeWorkspaceIndex)
property real animActive: isActive ? 1 : 0.65
Behavior on animActive {
NumberAnimation {
duration: 150
}
}
// property bool isCorrectScreen: log()
// function log() {
// console.log("Screen name: " + root.screen.name);
// console.log(wsItem.output);
// console.log(wsItem.id);
// let isCorrect = root.screen.name == wsItem.output;
// console.log("isCorrect: ", isCorrect);
// return root.screen.name == wsItem.output;
// }
implicitHeight: root.wsItemHeight
implicitWidth: 50
anchors {
right: parent.right
left: parent.left
}
Rectangle {
anchors.centerIn: parent
height: wsItem.height - 5
width: parent.width * wsItem.animActive
radius: height / 2
border.color: Config.catppuccin.mantle
border.width: 0
color: Config.catppuccin.blue
}
}
}
2025-06-24 15:51:34 +02:00
Component.onCompleted: {
Niri.workspaces.forEach(workspace => {
root.workspaceAdded(workspace);
});
}
2025-06-24 07:46:51 +02:00
}