forked from noctalia-dev/noctalia-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.qml
More file actions
175 lines (150 loc) · 4.75 KB
/
shell.qml
File metadata and controls
175 lines (150 loc) · 4.75 KB
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
import Quickshell
import Quickshell.Io
import Quickshell.Services.Pipewire
import Quickshell.Services.Notifications
import QtQuick
import QtCore
import qs.Bar
import qs.Bar.Modules
import qs.Widgets
import qs.Widgets.LockScreen
import qs.Widgets.Notification
import qs.Settings
import qs.Helpers
import "./Helpers/IdleInhibitor.qml"
import "./Helpers/IPCHandlers.qml"
Scope {
id: root
property alias appLauncherPanel: appLauncherPanel
property var notificationHistoryWin: notificationHistoryWin
property bool pendingReload: false
// Helper function to round value to nearest step
function roundToStep(value, step) {
return Math.round(value / step) * step;
}
// Volume property reflecting current audio volume in 0-100
// Will be kept in sync dynamically below
property int volume: (defaultAudioSink && defaultAudioSink.audio && !defaultAudioSink.audio.muted)
? Math.round(defaultAudioSink.audio.volume * 100)
: 0
// Function to update volume with clamping, stepping, and applying to audio sink
function updateVolume(vol) {
var clamped = Math.max(0, Math.min(100, vol));
var stepped = roundToStep(clamped, 5);
if (defaultAudioSink && defaultAudioSink.audio) {
defaultAudioSink.audio.volume = stepped / 100;
}
volume = stepped;
}
Component.onCompleted: {
Quickshell.shell = root;
}
Bar {
id: bar
shell: root
property var notificationHistoryWin: notificationHistoryWin
}
Dock {
id: dock
}
Applauncher {
id: appLauncherPanel
visible: false
}
LockScreen {
id: lockScreen
onLockedChanged: {
if (!locked && root.pendingReload) {
reloadTimer.restart();
root.pendingReload = false;
}
}
}
IdleInhibitor {
id: idleInhibitor
}
NotificationServer {
id: notificationServer
onNotification: function (notification) {
console.log("Notification received:", notification.appName);
notification.tracked = true;
if (notificationPopup.notificationsVisible) {
notificationPopup.addNotification(notification);
}
if (notificationHistoryWin) {
notificationHistoryWin.addToHistory({
id: notification.id,
appName: notification.appName || "Notification",
summary: notification.summary || "",
body: notification.body || "",
urgency: notification.urgency,
timestamp: Date.now()
});
}
}
}
NotificationPopup {
id: notificationPopup
barVisible: bar.visible
}
NotificationHistory {
id: notificationHistoryWin
}
// Reference to the default audio sink from Pipewire
property var defaultAudioSink: Pipewire.defaultAudioSink
PwObjectTracker {
objects: [Pipewire.defaultAudioSink]
}
IPCHandlers {
appLauncherPanel: appLauncherPanel
lockScreen: lockScreen
idleInhibitor: idleInhibitor
notificationPopup: notificationPopup
}
Connections {
function onReloadCompleted() {
Quickshell.inhibitReloadPopup();
}
function onReloadFailed() {
Quickshell.inhibitReloadPopup();
}
target: Quickshell
}
Timer {
id: reloadTimer
interval: 500 // ms
repeat: false
onTriggered: Quickshell.reload(true)
}
Connections {
target: Quickshell
function onScreensChanged() {
if (lockScreen.locked) {
pendingReload = true;
} else {
reloadTimer.restart();
}
}
}
// --- NEW: Keep volume property in sync with actual Pipewire audio sink volume ---
Connections {
target: defaultAudioSink ? defaultAudioSink.audio : null
function onVolumeChanged() {
if (defaultAudioSink.audio && !defaultAudioSink.audio.muted) {
volume = Math.round(defaultAudioSink.audio.volume * 100);
console.log("Volume changed externally to:", volume);
}
}
function onMutedChanged() {
if (defaultAudioSink.audio) {
if (defaultAudioSink.audio.muted) {
volume = 0;
console.log("Audio muted, volume set to 0");
} else {
volume = Math.round(defaultAudioSink.audio.volume * 100);
console.log("Audio unmuted, volume restored to:", volume);
}
}
}
}
}