aboutsummaryrefslogtreecommitdiff
path: root/modules/system/quickshell/ControlCenter.qml
blob: 25aae5e5b5f6046bcda3c05c735d3b4511bd1595 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Networking
import Quickshell.Bluetooth
import Quickshell.Services.Pipewire
import Quickshell.Services.Mpris

Item {
    id: root
    width: childrenRect.width
    height: parent.height

    BrightnessService { id: brightnessService }

    MouseArea {
        anchors.fill: parent
        onClicked: GlobalState.toggle("ControlCenter")
    }

    // Indicator in bar
    Row {
        anchors.verticalCenter: parent.verticalCenter
        spacing: 4
        Image {
            width: 20; height: 20
            source: Quickshell.iconPath("emblem-system-symbolic")
            sourceSize: Qt.size(width, height)
            smooth: true
            mipmap: true
        }
    }

    PopupWindow {
        id: popup
        visible: GlobalState.activePopup === "ControlCenter"
        grabFocus: true
        implicitWidth: card.width
        implicitHeight: card.height

        anchor {
            window: barWindow
            item: root
            edges: Edges.Bottom
            gravity: Edges.Bottom
            margins.top: Theme.popupGap
        }

        color: "transparent"

        onVisibleChanged: {
            if (visible) anchor.updateAnchor()
        }

        PopupCard {
            id: card
            width: 320
            margins: 16

            // TOP SECTION: Connectivity & Quick Actions
            RowLayout {
                Layout.fillWidth: true
                spacing: 12

                ConnectivityBox {
                    Layout.fillWidth: true
                }

                ColumnLayout {
                    spacing: 12
                    ControlTile {
                        label: "Do Not Disturb"
                        icon: "notifications"
                    }
                    ControlTile {
                        icon: "network-wireless"
                    }
                }
            }

            // MIDDLE SECTION: Sliders
            SliderBox {
                label: "Display"
                icon: "display-brightness"
                value: brightnessService.brightness
                onMoved: val => brightnessService.setBrightness(val)
            }

            SliderBox {
                label: "Sound"
                icon: "audio-volume-high"
                value: Pipewire.defaultAudioSink?.audio?.volume ?? 0
                onMoved: val => {
                    const sink = Pipewire.defaultAudioSink
                    if (sink?.audio) {
                        sink.audio.muted = false
                        sink.audio.volume = val
                    }
                }
            }

            // NOW PLAYING BOX
            Squircle {
                Layout.fillWidth: true
                height: 64
                cornerRadius: 16
                fillColor: hoverArea.containsMouse ? Theme.surfaceHover : Theme.surface
                visible: (Mpris.players?.values?.length ?? 0) > 0

                MouseArea {
                    id: hoverArea
                    anchors.fill: parent
                    hoverEnabled: true
                    acceptedButtons: Qt.NoButton
                }

                MediaCard {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.right: parent.right
                    anchors.leftMargin: 12
                    anchors.rightMargin: 12
                    
                    isExpanded: false

                    readonly property var activePlayer: {
                        const ps = Mpris.players?.values || []
                        for (const p of ps) if (p.playbackState === MprisPlaybackState.Playing) return p
                        return ps[0]
                    }

                    player: activePlayer
                    
                    onClicked: Qt.callLater(() => GlobalState.open("Media"))
                }
            }
        }
    }
}