summaryrefslogtreecommitdiff
path: root/bar/Workspace.qml
blob: ccfcd57596eec35af8d5141fefe3f8f8c24848c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import QtQuick.Layouts
import QtQuick
import Quickshell
import Quickshell.Hyprland
import Quickshell.Wayland
import qs.config
import qs.components

Item {
    id: root

    // required property ShellScreen screen // multi monitor
    property var ws: Hyprland.workspaces

    // readonly property HyprlandMonitor monitor: Hyprland.monitorFor(screen) // multi monitor
    // dont work no more for some reason

    function getWorkspaceStats(index) {
        const w = ws.values.find(i => i.id === index + 1);
        return {
            isOccupied: w?.toplevels?.values?.length,
            isActive: w?.active,
            isUrgent: w?.urgent
        };
    }

    implicitWidth: layout.implicitWidth

    RowLayout {
        id: layout
        implicitWidth: childrenRect.width
        anchors.verticalCenter: parent.verticalCenter

        spacing: Bar.workspaceSpacing

        Repeater {
            model: Bar.workspaces

            Rectangle {
                id: workspaceRect
                property var st: getWorkspaceStats(index)

                implicitWidth: !st.isActive ? Bar.workspaceIconSize : Bar.workspaceActiveIconSize
                implicitHeight: Bar.workspaceIconSize - Bar.workspaceHorizontalSpacing
                radius: Bar.workspaceRounding
                Icon {
                    anchors.centerIn: parent
                    text: !st.isUrgent ? Icons.ws[index + 1] : Icons.ws['urgent'] // TODO: urgent = red
                    font.pixelSize: Bar.workspaceIconSize / 2
                    color: Colors.foreground // TODO make IText w/ ts default color
                    opacity: !st.isOccupied ? 0 : 1 // less contrast
                    // opacity: isActive(index) ? Bar.workspaceActiveOpacity : isOccupied(index) ? Bar.workspaceOpacity : Bar.workspaceEmptyOpacity
                }

                color: st.isOccupied ? Colors.alt : Colors.foreground
                opacity: st.isActive && st.isOccupied ? Bar.workspaceActiveOpacity : st.isOccupied ? Bar.workspaceOpacity : Bar.workspaceEmptyOpacity
            }
        }
    }
}