summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/DankMaterialShell/quickshell/Modules/DankBar/Widgets/PrivacyIndicator.qml
blob: a09aa55fbc98b5514e5a1ca87d01b933ad8e5bc4 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import QtQuick
import qs.Common
import qs.Modules.Plugins
import qs.Services
import qs.Widgets

BasePill {
    id: root

    section: "right"

    property bool showMicIcon: SettingsData.privacyShowMicIcon
    property bool showCameraIcon: SettingsData.privacyShowCameraIcon
    property bool showScreenSharingIcon: SettingsData.privacyShowScreenShareIcon

    readonly property bool hasActivePrivacy: showMicIcon || showCameraIcon || showScreenSharingIcon || PrivacyService.anyPrivacyActive
    readonly property int activeCount: (showMicIcon ? 1 : PrivacyService.microphoneActive) + (showCameraIcon ? 1 : PrivacyService.cameraActive) + (showScreenSharingIcon ? 1 : PrivacyService.screensharingActive)
    readonly property real contentWidth: hasActivePrivacy ? (activeCount * 18 + (activeCount - 1) * Theme.spacingXS) : 0
    readonly property real contentHeight: hasActivePrivacy ? (activeCount * 18 + (activeCount - 1) * Theme.spacingXS) : 0

    opacity: hasActivePrivacy ? 1 : 0

    states: [
        State {
            name: "hidden_horizontal"
            when: !hasActivePrivacy && !isVerticalOrientation
            PropertyChanges {
                target: root
                width: 0
            }
        },
        State {
            name: "hidden_vertical"
            when: !hasActivePrivacy && isVerticalOrientation
            PropertyChanges {
                target: root
                height: 0
            }
        }
    ]

    transitions: [
        Transition {
            NumberAnimation {
                properties: "width,height"
                duration: Theme.shortDuration
                easing.type: Theme.standardEasing
            }
        }
    ]

    Behavior on opacity {
        NumberAnimation {
            duration: Theme.shortDuration
            easing.type: Theme.standardEasing
        }
    }

    content: Component {
        Item {
            implicitWidth: root.hasActivePrivacy ? root.contentWidth : 0
            implicitHeight: root.hasActivePrivacy ? root.contentHeight : 0

            Column {
                anchors.centerIn: parent
                spacing: Theme.spacingXS
                visible: root.isVerticalOrientation && root.hasActivePrivacy

                Item {
                    width: 18
                    height: 18
                    visible: root.showMicIcon || PrivacyService.microphoneActive
                    anchors.horizontalCenter: parent.horizontalCenter

                    DankIcon {
                        name: {
                            const sourceAudio = AudioService.source?.audio;
                            const muted = !sourceAudio || sourceAudio.muted || sourceAudio.volume === 0.0;
                            if (muted)
                                return "mic_off";
                            return "mic";
                        }
                        size: Theme.iconSizeSmall
                        color: PrivacyService.microphoneActive ? Theme.error : Theme.surfaceText
                        filled: PrivacyService.microphoneActive
                        anchors.centerIn: parent
                    }
                }

                Item {
                    width: 18
                    height: 18
                    visible: root.showCameraIcon || PrivacyService.cameraActive
                    anchors.horizontalCenter: parent.horizontalCenter

                    DankIcon {
                        name: "camera_video"
                        size: Theme.iconSizeSmall
                        color: PrivacyService.cameraActive ? Theme.error : Theme.surfaceText
                        filled: PrivacyService.cameraActive
                        anchors.centerIn: parent
                    }

                    Rectangle {
                        width: 6
                        height: 6
                        radius: 3
                        color: Theme.error
                        anchors.right: parent.right
                        anchors.top: parent.top
                        anchors.rightMargin: -2
                        anchors.topMargin: -1
                        visible: PrivacyService.cameraActive
                    }
                }

                Item {
                    width: 18
                    height: 18
                    visible: root.showScreenSharingIcon || PrivacyService.screensharingActive
                    anchors.horizontalCenter: parent.horizontalCenter

                    DankIcon {
                        name: "screen_share"
                        size: Theme.iconSizeSmall
                        color: PrivacyService.screensharingActive ? Theme.warning : Theme.surfaceText
                        filled: PrivacyService.screensharingActive
                        anchors.centerIn: parent
                    }
                }
            }

            Row {
                anchors.centerIn: parent
                spacing: Theme.spacingXS
                visible: !root.isVerticalOrientation && root.hasActivePrivacy

                Item {
                    width: 18
                    height: 18
                    visible: root.showMicIcon || PrivacyService.microphoneActive
                    anchors.verticalCenter: parent.verticalCenter

                    DankIcon {
                        name: {
                            const sourceAudio = AudioService.source?.audio;
                            const muted = !sourceAudio || sourceAudio.muted || sourceAudio.volume === 0.0;
                            if (muted)
                                return "mic_off";
                            return "mic";
                        }
                        size: Theme.iconSizeSmall
                        color: PrivacyService.microphoneActive ? Theme.error : Theme.surfaceText
                        filled: PrivacyService.microphoneActive
                        anchors.centerIn: parent
                    }
                }

                Item {
                    width: 18
                    height: 18
                    visible: root.showCameraIcon || PrivacyService.cameraActive
                    anchors.verticalCenter: parent.verticalCenter

                    DankIcon {
                        name: "camera_video"
                        size: Theme.iconSizeSmall
                        color: PrivacyService.cameraActive ? Theme.error : Theme.surfaceText
                        filled: PrivacyService.cameraActive
                        anchors.centerIn: parent
                    }

                    Rectangle {
                        width: 6
                        height: 6
                        radius: 3
                        color: Theme.error
                        anchors.right: parent.right
                        anchors.top: parent.top
                        anchors.rightMargin: -2
                        anchors.topMargin: -1
                        visible: PrivacyService.cameraActive
                    }
                }

                Item {
                    width: 18
                    height: 18
                    visible: root.showScreenSharingIcon || PrivacyService.screensharingActive
                    anchors.verticalCenter: parent.verticalCenter

                    DankIcon {
                        name: "screen_share"
                        size: Theme.iconSizeSmall
                        color: PrivacyService.screensharingActive ? Theme.warning : Theme.surfaceText
                        filled: PrivacyService.screensharingActive
                        anchors.centerIn: parent
                    }
                }
            }
        }
    }

    Rectangle {
        id: tooltip
        width: tooltipText.contentWidth + Theme.spacingM * 2
        height: tooltipText.contentHeight + Theme.spacingS * 2
        radius: Theme.cornerRadius
        color: Theme.withAlpha(Theme.surfaceContainer, Theme.popupTransparency)
        border.color: Theme.outlineMedium
        border.width: 1
        visible: false
        opacity: root.isMouseHovered && hasActivePrivacy ? 1 : 0
        z: 100
        x: (parent.width - width) / 2
        y: -height - Theme.spacingXS

        StyledText {
            id: tooltipText
            anchors.centerIn: parent
            text: PrivacyService.getPrivacySummary()
            font.pixelSize: Theme.barTextSize(barThickness, barConfig?.fontScale, barConfig?.maximizeWidgetText)
            color: Theme.widgetTextColor
        }

        Rectangle {
            width: 8
            height: 8
            color: parent.color
            border.color: parent.border.color
            border.width: parent.border.width
            rotation: 45
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.bottom
            anchors.topMargin: -4
        }

        Behavior on opacity {
            enabled: hasActivePrivacy && root.visible

            NumberAnimation {
                duration: Theme.shortDuration
                easing.type: Theme.standardEasing
            }
        }
    }
}