-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNightModeControlWidget.qml
More file actions
373 lines (350 loc) · 14.5 KB
/
Copy pathNightModeControlWidget.qml
File metadata and controls
373 lines (350 loc) · 14.5 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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
import QtQuick
import Quickshell.Io
import qs.Common
import qs.Services
import qs.Widgets
import qs.Modules.Plugins
PluginComponent {
id: root
// Configuration (pluginData)
readonly property int stepK: pluginData.stepK ?? 500
readonly property int minK: pluginData.minK ?? 2500
readonly property int maxK: pluginData.maxK ?? 6000
readonly property string pillFormat: pluginData.pillFormat ?? "tempOnly" // "tempOnly" | "labelTemp" | "iconOnly"
readonly property bool hideWhenInactive: pluginData.hideWhenInactive === true
readonly property var presetTempsK: {
const v = pluginData.presetTempsK;
return Array.isArray(v) && v.length > 0 ? v : [3000, 3500, 4000, 4500, 5000, 5500, 6000];
}
readonly property bool debugLog: pluginData.debugLog === true
// Live state (mirrored from DisplayService / SessionData)
readonly property bool gammaAvailable: DisplayService.gammaControlAvailable
readonly property bool automationAvailable: DisplayService.automationAvailable
readonly property bool nmEnabled: DisplayService.nightModeEnabled
readonly property int currentK: DisplayService.gammaCurrentTemp
readonly property int targetNightK: SessionData.nightModeTemperature
readonly property int targetDayK: SessionData.nightModeHighTemperature
readonly property bool autoEnabled: SessionData.nightModeAutoEnabled
readonly property string autoMode: SessionData.nightModeAutoMode || "time"
readonly property bool isDay: DisplayService.gammaIsDay
readonly property string sunriseTime: DisplayService.gammaSunriseTime
readonly property string sunsetTime: DisplayService.gammaSunsetTime
readonly property string nextTransition: DisplayService.gammaNextTransition
// Pill visibility
readonly property bool pillVisible: !hideWhenInactive || nmEnabled
onPillVisibleChanged: setVisibilityOverride(pillVisible)
Component.onCompleted: setVisibilityOverride(pillVisible)
// Helpers
function _round500(k) { return Math.round(k / 500) * 500; }
function _clampK(k) { return Math.max(minK, Math.min(maxK, _round500(k))); }
function bumpTargetTemp(delta) {
const next = _clampK(targetNightK + delta);
if (next === targetNightK) return;
setTargetTemp(next);
}
function setTargetTemp(k) {
const next = _clampK(k);
if (debugLog) console.info("nightModeControl: setTargetTemp " + next);
SessionData.setNightModeTemperature(next);
if (SessionData.nightModeHighTemperature < next)
SessionData.setNightModeHighTemperature(next);
}
function setDayTemp(k) {
const next = Math.max(targetNightK, Math.min(6500, _round500(k)));
if (debugLog) console.info("nightModeControl: setDayTemp " + next);
SessionData.setNightModeHighTemperature(next);
}
function toggleNightMode() {
if (debugLog) console.info("nightModeControl: toggle");
DisplayService.toggleNightMode();
}
function setAutoEnabled(on) {
if (debugLog) console.info("nightModeControl: autoEnabled=" + on);
SessionData.setNightModeAutoEnabled(on);
}
function setAutoMode(mode) {
if (debugLog) console.info("nightModeControl: autoMode=" + mode);
SessionData.setNightModeAutoMode(mode);
}
function _pillTemp() {
if (!gammaAvailable) return "-";
const k = (nmEnabled && currentK > 0) ? currentK : targetNightK;
return k + "K";
}
function _pillIcon() {
if (!gammaAvailable) return "block";
if (!nmEnabled) return "wb_sunny";
return autoEnabled ? "auto_mode" : "nights_stay";
}
function _pillText() {
switch (pillFormat) {
case "iconOnly": return "";
case "labelTemp": return (nmEnabled ? "Night " : "Day ") + _pillTemp();
case "tempOnly":
default: return _pillTemp();
}
}
// Bar pill
pillRightClickAction: () => root.toggleNightMode()
horizontalBarPill: Component {
Item {
implicitWidth: hRow.implicitWidth
implicitHeight: hRow.implicitHeight
Row {
id: hRow
spacing: Theme.spacingXS
DankIcon {
name: root._pillIcon()
size: root.iconSize
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
visible: root._pillText().length > 0
text: root._pillText()
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
}
WheelHandler {
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
onWheel: function (event) {
if (!root.gammaAvailable) return;
if (event.angleDelta.y > 0) root.bumpTargetTemp(+root.stepK);
else if (event.angleDelta.y < 0) root.bumpTargetTemp(-root.stepK);
}
}
}
}
verticalBarPill: Component {
Item {
implicitWidth: vCol.implicitWidth
implicitHeight: vCol.implicitHeight
Column {
id: vCol
spacing: Theme.spacingXS
DankIcon {
name: root._pillIcon()
size: root.iconSize
color: Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
visible: root._pillText().length > 0
text: root._pillText()
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
}
WheelHandler {
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
onWheel: function (event) {
if (!root.gammaAvailable) return;
if (event.angleDelta.y > 0) root.bumpTargetTemp(+root.stepK);
else if (event.angleDelta.y < 0) root.bumpTargetTemp(-root.stepK);
}
}
}
}
// Shared detail body (popout + CC detail)
Component {
id: nightDetailBody
Column {
width: parent ? parent.width : 360
spacing: Theme.spacingM
// Status line
Column {
width: parent.width
spacing: 2
StyledText {
text: root.gammaAvailable
? (root.nmEnabled ? "Active" : "Inactive")
+ " · Current: " + (root.currentK > 0 ? root.currentK + "K" : "-")
+ " · Target: " + root.targetNightK + "K"
: "Gamma control not available (DMS reports no gamma capability)"
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: Theme.surfaceText
wrapMode: Text.WordWrap
width: parent.width
}
StyledText {
visible: root.autoEnabled && root.gammaAvailable
text: "Period: " + (root.isDay ? "day" : "night")
+ (root.sunriseTime ? " · Sunrise: " + root.sunriseTime : "")
+ (root.sunsetTime ? " · Sunset: " + root.sunsetTime : "")
+ (root.nextTransition ? " · Next: " + root.nextTransition : "")
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
wrapMode: Text.WordWrap
width: parent.width
}
}
// Toggle row
Row {
width: parent.width
spacing: Theme.spacingS
DankButton {
text: root.nmEnabled ? "Turn off night mode" : "Turn on night mode"
iconName: root.nmEnabled ? "wb_sunny" : "nights_stay"
buttonHeight: 32
horizontalPadding: Theme.spacingM
enabled: root.gammaAvailable
onClicked: root.toggleNightMode()
}
}
// Target night temp slider
Column {
width: parent.width
spacing: Theme.spacingXS
StyledText {
text: root.autoEnabled ? "Night temperature" : "Target temperature"
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: Theme.surfaceText
}
DankSlider {
width: parent.width
minimum: root.minK
maximum: root.maxK
value: root.targetNightK
unit: "K"
leftIcon: "nights_stay"
onSliderValueChanged: v => root.setTargetTemp(v)
}
}
// Day temp slider - only meaningful when automation is on
Column {
width: parent.width
spacing: Theme.spacingXS
visible: root.autoEnabled
StyledText {
text: "Day temperature"
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: Theme.surfaceText
}
DankSlider {
width: parent.width
minimum: root.targetNightK
maximum: 6500
value: root.targetDayK
unit: "K"
leftIcon: "wb_sunny"
onSliderValueChanged: v => root.setDayTemp(v)
}
}
// Quick presets (rounded to 500K, persisted via setTargetTemp)
Column {
width: parent.width
spacing: Theme.spacingXS
StyledText {
text: "Quick presets"
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: Theme.surfaceText
}
DankFilterChips {
width: parent.width
model: root.presetTempsK.map(k => parseInt(k) + "K")
currentIndex: root.presetTempsK.map(k => parseInt(k)).indexOf(root.targetNightK)
showCheck: false
onSelectionChanged: index => root.setTargetTemp(root.presetTempsK[index])
}
}
// Automation
Column {
width: parent.width
spacing: Theme.spacingXS
visible: root.automationAvailable
StyledText {
text: "Automation"
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
color: Theme.surfaceText
}
Row {
spacing: Theme.spacingS
DankButton {
text: root.autoEnabled ? "Auto on" : "Auto off"
iconName: root.autoEnabled ? "autorenew" : "schedule"
buttonHeight: 30
horizontalPadding: Theme.spacingM
onClicked: root.setAutoEnabled(!root.autoEnabled)
}
}
DankButtonGroup {
width: parent.width
visible: root.autoEnabled
model: ["time", "location"]
currentIndex: root.autoMode === "location" ? 1 : 0
checkEnabled: false
onSelectionChanged: (index, selected) => {
if (!selected) return;
root.setAutoMode(index === 1 ? "location" : "time");
}
}
StyledText {
visible: root.autoEnabled
text: root.autoMode === "time"
? "Schedule editable in DMS Settings -> Display -> Gamma."
: "Uses configured latitude/longitude (or IP location)."
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
wrapMode: Text.WordWrap
width: parent.width
}
}
}
}
// Popout (left-click pill)
// Need Plenty of vertical room here - Column expands naturally inside PopoutComponent.
popoutWidth: 380
popoutHeight: 620
popoutContent: Component {
PopoutComponent {
headerText: "Night Mode"
+ (root.gammaAvailable && root.currentK > 0 ? " · " + root.currentK + "K" : "")
showCloseButton: true
Loader {
width: parent.width
sourceComponent: nightDetailBody
}
}
}
// Control Center entry
ccWidgetIcon: "nights_stay"
ccWidgetPrimaryText: "Night Mode"
ccWidgetSecondaryText: {
if (!gammaAvailable) return "Unavailable";
if (!nmEnabled) return "Off · target " + targetNightK + "K";
const cur = currentK > 0 ? currentK + "K" : targetNightK + "K";
return cur + (autoEnabled ? " · auto " + autoMode : "");
}
ccWidgetIsActive: nmEnabled
ccWidgetIsToggle: true
ccDetailHeight: 480
onCcWidgetToggled: root.toggleNightMode()
// CC clamps detail height to whatever the tile can give us - wrap the body in a DankFlickable so it scrolls instead of clipping the bottom (presets/ automation/footer) when content is taller than the available space.
ccDetailContent: Component {
Rectangle {
radius: Theme.cornerRadius
color: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
DankFlickable {
id: ccFlick
anchors.fill: parent
anchors.margins: Theme.spacingM
contentWidth: width
contentHeight: bodyLoader.implicitHeight
clip: true
Loader {
id: bodyLoader
width: ccFlick.width
sourceComponent: nightDetailBody
}
}
}
}
}