Repository navigation
Expand file tree
/
Copy pathPanel.qml
More file actions
1188 lines (1075 loc) · 46.3 KB
/
Copy pathPanel.qml
File metadata and controls
1188 lines (1075 loc) · 46.3 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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import QtQuick
import QtQuick.Controls
import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Commons as Commons
import qs.Ui
import "Model.js" as Model
// Bar widget: icon + remaining-time in the bar, and a popup menu to schedule
// a power action. The full-screen overlay lives in Overlay.qml (same plugin).
Panel {
id: root
moduleName: "honor.shutdown-timer"
ipcTarget: "honor.shutdown-timer"
manageIpc: false
// The bar host sizes a widget slot from its implicit size only: without
// these the widget occupies zero pixels and never shows up on the bar.
// Idle takes exactly one icon slot (27 px), like every other bar icon; the
// extra gutter exists only while the countdown label is on screen, so the
// widget never sits in a wider slot than its neighbours for no reason.
implicitWidth: vertical
? button.implicitWidth
: button.implicitWidth + (timeLabel.visible ? timeLabel.implicitWidth + Style.space(2) + Style.space(4) : 0)
implicitHeight: vertical
? button.implicitHeight + (verticalTime.visible ? verticalTime.implicitHeight : 0)
: button.implicitHeight
// ---------- theme ----------
readonly property bool vertical: bar ? bar.vertical : false
readonly property string fontFamily: bar ? bar.fontFamily : Style.font.family
readonly property color foreground: bar ? bar.barForeground : Commons.Color.foreground
// The surface the bar icon is painted on; the state badge cuts itself out
// of the mark in this colour (black on a light theme looked like dirt).
readonly property color barBackground: bar ? bar.background : Commons.Color.bar.background
readonly property color urgent: bar ? bar.urgent : Commons.Color.urgent
// The bar API has no `accent` in this shell build (`bar.accent` is
// undefined), so a fallback on it lands on `foreground` and the ≤5 min
// "warning" step of the ladder becomes invisible. Fall back to the theme
// accent instead.
readonly property color accent: (bar && bar.accent) ? bar.accent : Commons.Color.accent
// Popup surface + text, contrast-checked (TZ 12). A theme may pair a warm
// red with a warm light surface and land just under 4.5:1; readableOn()
// nudges the text toward black/white in that case and returns it unchanged
// otherwise, so urgent text stays red on every theme.
readonly property color popupSurface: Commons.Color.popups.background
readonly property color popupText: Model.readableOn(String(Commons.Color.popups.text), String(popupSurface), 4.5)
readonly property color popupUrgent: Model.readableOn(String(urgent), String(popupSurface), 4.5)
readonly property color popupAccent: Model.readableOn(String(accent), String(popupSurface), 4.5)
// ---------- localization ----------
readonly property string language: timerService.language
function tr(key, args) { return Model.t(key, language, args) }
// ---------- glyphs (Nerd Font escapes) ----------
readonly property string glyphPower: "\uf011" // nf-fa-power_off
readonly property string glyphReboot: "\uf021" // nf-fa-refresh
readonly property string glyphSuspend: "\uf0a1" // nf-fa-moon
readonly property string glyphBolt: "\uf0e7" // nf-fa-bolt
readonly property string glyphCancel: "\uf00d" // nf-fa-close
readonly property string glyphClock: "\uf017" // nf-fa-clock_o
readonly property string glyphPause: "\uf04c" // nf-fa-pause
readonly property string glyphPlay: "\uf04b" // nf-fa-play
readonly property string glyphPlus: "\uf067" // nf-fa-plus
readonly property string glyphCheck: "\uf00c" // nf-fa-check
function glyphForAction(action) {
if (action === "reboot") return glyphReboot
if (action === "suspend") return glyphSuspend
if (action === "hibernate") return glyphSuspend
return glyphPower
}
// Bar colour ladder per TZ 6.2: normal → accent in the last 5 minutes →
// urgent in the last minute and during the overlay countdown. A scheduled
// firing counts as urgent from the start — it was not asked for just now.
readonly property color barColor: {
if (!timerService.ok) return urgent
if (timerService.status === "COUNTDOWN" || timerService.status === "COUNTDOWN_SCHED") return urgent
if (timerService.status === "ACTIVE" && timerService.timeLeft <= 60) return urgent
if (timerService.status === "ACTIVE" && timerService.timeLeft <= 300) return accent
if (timerService.status === "PAUSED") return foreground
return foreground
}
// Vertical bar: "MM:SS" is split at the colon so the slot stays narrow.
readonly property var verticalLines: {
if (!vertical) return []
var txt = barText
if (txt === "") return []
return String(txt).split(":")
}
readonly property string barText: {
if (timerService.status === "IDLE") {
// a pending schedule shows a dot instead of a figure
return root.scheduleDot
}
root.tick // force re-eval on tick
return Model.formatTime(timerService.timeLeft)
}
// "•" marks "schedules exist" while idle (TZ 9.5)
readonly property string scheduleDot: timerService.scheduleCount > 0 ? "•" : ""
// How much of the timer is left, 0…1, or -1 when nothing runs. The bar
// mark closes its ring with this: no extra element, one parameter.
readonly property real remainingFraction: {
if (timerService.status === "IDLE") return -1
var total = Number(timerService.targetTime) - Number(timerService.startTime)
if (!(total > 0)) return -1
return Math.max(0, Math.min(1, Number(timerService.timeLeft) / total))
}
readonly property bool barDimmed: false
// Set for a moment after a wheel gesture on the bar icon, so the number the
// gesture produced is visible without opening the popup.
property string wheelHint: ""
Timer {
id: wheelHintTimer
interval: 1600
repeat: false
onTriggered: root.wheelHint = ""
}
readonly property string barTooltip: {
if (!timerService.ok) return tr("error.daemon")
if (root.wheelHint !== "") return root.wheelHint
if (timerService.status === "IDLE") return tr("tooltip.idle")
if (timerService.status === "PAUSED") return Model.actionLabel(timerService.action, language) + " — " + tr("btn.pause").toLowerCase() + " · " + Model.formatTime(timerService.timeLeft) + " · " + tr("tooltip.cancelHint")
if (timerService.status === "ACTIVE") return Model.actionLabel(timerService.action, language) + " " + tr("time.in") + " " + Model.formatTime(timerService.timeLeft) + " · " + tr("tooltip.cancelHint")
return tr("tooltip.countdown", Model.formatTime(timerService.timeLeft))
}
// ---------- menu state ----------
property string selectedAction: String(timerService.defaultAction)
property bool timeModeAbsolute: false
property string absoluteTime: ""
property int customMinutes: 30
// Presets come from the setting (TZ 9.8), not a literal in the panel.
readonly property var quickPresets: timerService.presetList
property string selectedQuick: ""
// Digits typed on the popup, cleared when the panel closes.
property string typedMinutes: ""
// ---------- repeat / schedule state ----------
property string repeatMode: "once" // once | daily | weekdays | weekends
property var scheduleRows: [] // [{id, at, days, action}]
// "" | "repeat" | "more" | "history" — the rare settings open in place
// instead of sitting between the user and the launch key.
property string trayOpen: ""
// Cancel asks once before it fires: the button is a decision, the hold on
// the bar icon and Esc in the overlay stay one-action escapes.
property bool confirmOpen: false
function askCancel() {
if (timerService.status === "IDLE") { root.close(); return }
root.confirmOpen = true
}
function doCancel() {
root.confirmOpen = false
timerService.cancel()
root.close()
}
// True while the dial is being dragged: the hero then shows the value
// under the finger instead of the running remainder.
property bool scrubbing: false
readonly property string targetClock: {
var t = Number(timerService.targetTime)
if (timerService.status === "IDLE" || !(t > 0)) t = Math.floor(Date.now() / 1000) + Math.round(root.customMinutes) * 60
return Qt.formatDateTime(new Date(t * 1000), "HH:mm")
}
readonly property int heroBaseMinutes: Math.max(1, Math.round(timerService.timeLeft / 60))
readonly property int heroTotalMinutes: {
var t = Number(timerService.targetTime) - Number(timerService.startTime)
return t > 0 ? Math.max(1, Math.round(t / 60)) : 1440
}
// 0 at the start of the timer, 1 at the deadline: drives the colour of the
// ring, the way a HUD shifts from calm to alarm.
readonly property real urgency: {
if (timerService.status === "IDLE") return 0
var f = root.remainingFraction
if (f < 0) return 0
return Math.max(0, Math.min(1, 1 - f))
}
function mixColor(a, b, t) {
var k = Math.max(0, Math.min(1, t))
return Qt.rgba(a.r + (b.r - a.r) * k, a.g + (b.g - a.g) * k,
a.b + (b.b - a.b) * k, a.a + (b.a - a.a) * k)
}
// The ring is calm accent at the start and urgent at the deadline, with the
// whole ramp in between instead of two hard states.
readonly property color dialTint: mixColor(root.popupAccent, root.popupUrgent, root.urgency)
// What the dial is full of: the dragged value while scrubbing, the whole
// proposed time in IDLE, the real remainder while a timer runs.
readonly property real heroFraction: {
if (root.scrubbing) {
var span = timerService.status === "IDLE" ? 1440 : root.heroTotalMinutes
return Math.max(0, Math.min(1, root.customMinutes / Math.max(1, span)))
}
if (timerService.status === "IDLE") return 1
var f = root.remainingFraction
return f < 0 ? 1 : f
}
// The one figure on the dial. In IDLE it is the time that would be set,
// not a sentence: the number is the object, the caption explains it.
readonly property string heroText: {
if (root.scrubbing || timerService.status === "IDLE")
return Model.formatTime(Math.max(1, Math.round(root.customMinutes)) * 60)
return Model.formatTime(timerService.timeLeft)
}
readonly property string heroCaption: {
if (root.scrubbing && timerService.status !== "IDLE") {
var d = root.customMinutes - root.heroBaseMinutes
return root.tr("hero.delta", (d >= 0 ? "+" : "") + String(d))
}
if (timerService.status === "IDLE") return root.tr("state.none")
if (timerService.status === "PAUSED") return root.tr("state.paused", Model.actionLabel(timerService.action, language))
if (timerService.status === "COUNTDOWN" || timerService.status === "COUNTDOWN_SCHED")
return root.tr("state.countdown", Model.actionLabel(timerService.action, language))
return root.tr("state.active", Model.actionLabel(timerService.action, language))
}
// A snooze past the limit is refused by the daemon without an error on the
// wire; the panel notices the deadline did not move and says so, instead of
// looking like nothing was pressed.
property bool snoozeRefused: false
property real snoozeBefore: 0
Timer {
id: snoozeCheck
interval: 600
repeat: false
onTriggered: {
if (Number(timerService.targetTime) <= root.snoozeBefore) {
root.snoozeRefused = true
snoozeRefusedTimer.restart()
}
}
}
Timer {
id: snoozeRefusedTimer
interval: 2600
repeat: false
onTriggered: root.snoozeRefused = false
}
function snoozeNow() {
root.snoozeBefore = Number(timerService.targetTime)
timerService.snooze(timerService.snoozeMins)
snoozeCheck.restart()
}
// One line under the dial: what the ring does, or how to get out.
readonly property string heroHint: {
if (root.snoozeRefused) return root.tr("hero.snoozeRefused")
if (timerService.status === "IDLE") return root.tr("state.noneHint")
return root.tr("hero.scrub")
}
// ---------- keyboard cursor (TZ 12: everything reachable by keyboard) ----------
// Same model as the stock panels: arrow keys walk a section cursor, Enter
// activates, and the mouse never has to be touched. The cursor stays off
// until the first arrow press so plain Enter keeps its old meaning
// ("launch the timer") for mouse users.
property bool cursorActive: false
property string focusSection: "action"
property int focusIndex: 0
readonly property var actionOptions: ["poweroff", "reboot", "suspend", "hibernate"]
readonly property var repeatOptions: ["once", "daily", "weekdays", "weekends"]
// Sections in visual order, visibility-aware.
function cursorSections() {
var out = []
if (timerService.status !== "IDLE") out.push("hero")
out.push("action")
out.push("dial")
out.push("tray")
if (trayOpen === "repeat") {
out.push("repeat", "addschedule")
if (scheduleRows.length > 0) out.push("schedules")
}
if (trayOpen === "more") out.push("advanced")
out.push("launch")
return out
}
function sectionCount(section) {
if (section === "advanced") return 5
if (section === "schedules") return scheduleRows.length
if (section === "hero") return 3
if (section === "tray") return 3
return 1
}
function ensureCursor() {
var list = cursorSections()
if (list.indexOf(focusSection) < 0) { focusSection = "action"; focusIndex = 0; return }
var max = sectionCount(focusSection) - 1
if (focusIndex > max) focusIndex = Math.max(0, max)
if (focusIndex < 0) focusIndex = 0
}
function cycleIn(list, value, dx) {
var i = list.indexOf(value)
if (i < 0) i = 0
i = (i + dx + list.length) % list.length
return list[i]
}
function moveCursor(dx, dy) {
cursorActive = true
ensureCursor()
var list = cursorSections()
if (dy !== 0) {
var at = list.indexOf(focusSection)
at = Math.max(0, Math.min(list.length - 1, at + dy))
focusSection = list[at]
focusIndex = Math.min(focusIndex, Math.max(0, sectionCount(focusSection) - 1))
} else if (dx !== 0) {
if (focusSection === "hero" || focusSection === "advanced" ||
focusSection === "schedules" || focusSection === "tray") {
focusIndex = Math.max(0, Math.min(sectionCount(focusSection) - 1, focusIndex + dx))
} else if (focusSection === "dial") {
// Left/right on the dial is a slider: one minute per step, five with
// the same modifier the wheel uses.
customMinutes = Math.max(1, Math.min(1440, Math.round(customMinutes) + dx * 5))
} else if (focusSection === "action") {
selectedAction = cycleIn(actionOptions, selectedAction, dx)
} else if (focusSection === "repeat") {
repeatMode = cycleIn(repeatOptions, repeatMode, dx)
}
}
scrollCursorIntoView()
}
function activateCursor() {
ensureCursor()
if (focusSection === "hero") {
if (focusIndex === 0) timerService.status === "PAUSED" ? timerService.resume() : timerService.pause()
else if (focusIndex === 1) root.snoozeNow()
else root.askCancel()
} else if (focusSection === "dial") {
root.startTimer()
} else if (focusSection === "tray") {
var keys = ["repeat", "more", "history"]
var key = keys[focusIndex]
if (key) trayOpen = (trayOpen === key ? "" : key)
} else if (focusSection === "addschedule") {
addSchedule()
} else if (focusSection === "schedules") {
var row = scheduleRows[focusIndex]
if (row) { timerService.scheduleRemove(row.id); Qt.callLater(function() { root.loadSchedules() }) }
} else if (focusSection === "advanced") {
if (focusIndex === 4) {
timerService.setOverride(timerService.overrideCommand === "" ? "echo" : "off")
} else {
var keys = ["batteryGuard", "quiet", "waitForInhibitors", "ambientFade"]
var ons = [timerService.batteryGuard, timerService.quiet, timerService.waitForInhibitors, timerService.ambientFade]
if (keys[focusIndex]) toggleSetting(keys[focusIndex], !ons[focusIndex])
}
} else if (focusSection === "launch") {
startTimer()
} else if (focusSection === "reset") {
resetTimer()
}
}
function scrollItemIntoView(item) {
if (!panelFlick || !item) return
Qt.callLater(function() {
var margin = Style.space(6)
var point = item.mapToItem(panelFlick.contentItem, 0, 0)
var top = point.y
var bottom = top + item.height
var viewTop = panelFlick.contentY
var viewBottom = viewTop + panelFlick.height
var maxY = Math.max(0, panelFlick.contentHeight - panelFlick.height)
if (top <= panelFlick.height * 0.1 + viewTop) panelFlick.contentY = Math.max(0, top - margin)
else if (bottom >= viewBottom - margin) panelFlick.contentY = Math.min(maxY, bottom + margin - panelFlick.height)
})
}
function scrollCursorIntoView() {
var item = null
if (focusSection === "hero" || focusSection === "launch" || focusSection === "reset") item = launchButton
else if (focusSection === "presets") item = presetGrid
else if (focusSection === "action") item = actionDropdown
else if (focusSection === "mode") item = modeGroup
else if (focusSection === "minutes") item = minutesSlider
else if (focusSection === "repeat") item = repeatGroup
else if (focusSection === "addschedule") item = addScheduleButton
else if (focusSection === "schedules") item = schedulesColumn
else if (focusSection === "advanced") item = advancedColumn
scrollItemIntoView(item)
}
// repeat mode → the day spec the daemon stores ("-", daily, 1..5, 6,7)
function daysForRepeat() {
if (repeatMode === "daily") return "1,2,3,4,5,6,7"
if (repeatMode === "weekdays") return "1,2,3,4,5"
if (repeatMode === "weekends") return "6,7"
// `once` is one occurrence: the daemon removes the row after it fires.
// Mapping it to today's weekday silently repeated it every week.
return "once"
}
function addSchedule() {
var hhmm = timeModeAbsolute && absoluteTime.trim() !== "" ? absoluteTime.trim() : minutesToHhmm(customMinutes)
if (!/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/.test(hhmm)) hhmm = minutesToHhmm(customMinutes)
timerService.scheduleAdd(hhmm, daysForRepeat(), selectedAction)
Qt.callLater(function() { root.loadSchedules() })
}
function minutesToHhmm(mins) {
var d = new Date(Date.now() + Math.round(mins) * 60000)
var h = d.getHours(), m = d.getMinutes()
return (h < 10 ? "0" : "") + h + ":" + (m < 10 ? "0" : "") + m
}
function daysLabel(spec) {
if (spec === "1,2,3,4,5,6,7") return tr("repeat.daily")
if (spec === "1,2,3,4,5") return tr("repeat.weekdays")
if (spec === "6,7") return tr("repeat.weekends")
var out = []
var parts = String(spec).split(",")
for (var i = 0; i < parts.length; i++) {
var k = "week." + parts[i]
var lbl = Model.t(k, language, [])
if (lbl !== k) out.push(lbl)
}
return out.join(" ")
}
function loadSchedules() {
schedulesProc.command = ["bash", timerService.controlPath, "schedule", "list"]
schedulesProc.running = true
}
function loadHistory() {
historyProc.command = ["bash", timerService.controlPath, "history"]
historyProc.running = true
}
Process {
id: schedulesProc
running: false
stdout: StdioCollector { id: schedulesOut; waitForEnd: true }
onExited: {
var rows = []
var lines = String(schedulesOut.text || "").split("\n")
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim()
if (line === "" || line.indexOf("#") !== 0) continue
// "#<id> at HH:MM <days label> <action label> (last: ...)"
var m = line.match(/^#(\S+)\s+at\s+(\S+)\s+(.*)$/)
if (!m) m = line.match(/^#(\S+)\s+[\u0432]\s+(\S+)\s+(.*)$/);
if (m) rows.push({ id: m[1], at: m[2], rest: m[3] })
}
root.scheduleRows = rows
}
}
Process {
id: historyProc
running: false
stdout: StdioCollector { id: historyOut; waitForEnd: true }
onExited: {
root.historyRows = String(historyOut.text || "").trim().split("\n").slice(0, 5)
}
}
property var historyRows: []
// TZ 9.1: a bad time is an inline urgent line under the field, not a toast.
readonly property bool absTimeValid: absoluteTime.trim() === "" || /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/.test(absoluteTime.trim())
readonly property string absTimeError: timeModeAbsolute && !absTimeValid ? tr("error.badTime") : ""
// Прокрутка считает от того, что виджет выставил последним, пока это «наше».
// timeLeft приходит из демона раз в refreshIntervalSec, поэтому у быстрых
// щелчков цель в виджете ещё старая — их держит короткое окно (интервал
// опроса плюс запас). Щелчок после опроса держит совпадение цели: демон
// показывает ровно ту, что создал наш щелчок. Это два разных доказательства
// одного и того же, поэтому они соединены ИЛИ: окно само по себе теряло
// накопленное значение через 1.5 с (40 -> -15 давало 20 вместо 25), а одна
// сверка цели ломала второй быстрый щелчок (35 -> 35).
property int wheelBase: -1
property double wheelBaseAt: 0
// Цель, которую создал наш же щелчок: если демон показывает другую, таймер
// переставили из другого места, и свежая база больше не наша.
property double wheelTarget: 0
function wheelAdjust(delta) {
var running = timerService.status === "ACTIVE" || timerService.status === "PAUSED"
if (timerService.status !== "IDLE" && !running) return
var now = Date.now()
var fresh = root.wheelBase > 0
&& (Math.abs(Number(timerService.targetTime) - root.wheelTarget) <= 2
|| (now - root.wheelBaseAt) < (timerService.refreshIntervalSec * 1000 + 500))
var base = running
? (fresh ? root.wheelBase : Math.max(1, Math.round(timerService.timeLeft / 60)))
: Math.round(customMinutes)
var next = Math.max(1, Math.min(1440, base + delta))
if (running) timerService.setTimer(next, timerService.action || selectedAction)
customMinutes = next
root.wheelBase = next
root.wheelBaseAt = now
root.wheelTarget = Math.round(now / 1000) + next * 60
root.wheelHint = root.tr("wheel.pending", String(next))
wheelHintTimer.restart()
}
function quickSet(mins) {
timerService.setTimer(mins, selectedAction)
close()
}
function startTimer() {
var mins = Math.round(customMinutes)
if (!mins || mins < 1) mins = 1
if (mins > 1440) mins = 1440
timerService.setTimer(mins, selectedAction)
close()
}
function cancelTimer() {
timerService.cancel()
}
function resetTimer() {
timerService.reset()
}
// Write a boolean setting back to shell.json through the shell CLI. The
// widget's own `settings` object is read-only, and the CLI is the supported
// write path — it also re-renders the widget, so the new value applies live.
function toggleSetting(key, value) {
Quickshell.execDetached(["bash", "-c",
"omarchy bar set " + root.moduleName + " " + key + " " + (value ? "true" : "false")])
}
// ---------- service ----------
Service {
id: timerService
settings: root.settings
notifyInstance: true
}
// Summon the fullscreen overlay when a countdown begins.
Connections {
target: timerService
function onStatusChanged() {
if (timerService.status === "COUNTDOWN") {
Quickshell.execDetached(["omarchy-shell", "-q", "honor.shutdown-timer:overlay", "show"])
}
}
}
// Tick every second so the remaining time re-renders between daemon polls
property int tick: 0
Timer {
id: tickTimer
interval: 1000
repeat: true
running: root.opened || (timerService.loaded && timerService.status !== "IDLE")
triggeredOnStart: true
onTriggered: { root.tick++ }
}
readonly property string omarchyPath: Quickshell.env("OMARCHY_PATH") || "/usr/share/omarchy"
// ---------- IPC handler ----------
IpcHandler {
target: root.ipcTarget
function open(): string { root.open(); return "ok" }
function close(): string { root.close(); return "ok" }
function toggle(): string { root.toggle(); return "ok" }
function refresh(): string { timerService.refresh(); return "ok" }
function status(): string {
if (!timerService.loaded) return "loading"
return timerService.status + " " + (timerService.action || "none") + " " + String(timerService.timeLeft)
}
function set(payloadJson: string): string {
var p = ({}); try { p = JSON.parse(payloadJson || "{}") } catch(e) {}
if (p.minutes !== undefined) timerService.setTimer(p.minutes, p.action || "")
else if (p.seconds !== undefined) timerService.setTimerSeconds(p.seconds, p.action || "")
else if (p.hours !== undefined) timerService.setTimer(p.hours * 60, p.action || "")
else if (p.absolute !== undefined) timerService.setTimerAbsolute(p.absolute, p.action || "")
return "ok"
}
function cancel(): string { timerService.cancel(); return "ok" }
function snooze(mins: string): string { timerService.snooze(parseInt(mins || "5", 10)); return "ok" }
function pause(): string { timerService.pause(); return "ok" }
function resume(): string { timerService.resume(); return "ok" }
function reset(): string { timerService.reset(); return "ok" }
function scheduleAdd(payloadJson: string): string {
var p = ({}); try { p = JSON.parse(payloadJson || "{}") } catch(e) {}
if (p.at) timerService.scheduleAdd(p.at, p.days || "1,2,3,4,5,6,7", p.action || "")
return "ok"
}
function scheduleRemove(id: string): string { timerService.scheduleRemove(id); return "ok" }
function show(): string { root.open(); return "ok" }
function hide(): string { root.close(); return "ok" }
// Walk the popup tree and report every visible child that pokes out of its
// parent. This is the "icons must not spill over the frame" rule as a
// test: a screenshot only shows the states someone thought to capture,
// this catches the ones nobody looks at.
function debugOverflow(): string {
var out = []
function nameOf(item, index) {
if (item.id) return String(item.id)
var s = String(item)
var m = s.match(/^([A-Za-z_][A-Za-z0-9_]*)/)
return (m ? m[1] : "item") + "#" + index
}
// Bounds of `item` mapped into `column`, which is what the eye actually
// sees: an icon scaled inside a 24-unit box can have children that stick
// out of that box on paper while staying well inside the popup column.
function boundsIn(item, target) {
var p = item.mapToItem(target, 0, 0)
return { x: p.x, y: p.y, w: item.width * (item.scale || 1), h: item.height * (item.scale || 1) }
}
var frame = { w: popupContent.width, h: popupContent.implicitHeight }
function walk(item, path) {
var kids = item.children
for (var i = 0; i < kids.length; i++) {
var c = kids[i]
var label = path + "/" + nameOf(c, i)
if (c.visible && c.width > 0 && c.height > 0) {
var b = boundsIn(c, popupContent)
// 4 px of slack: a key's halo is painted 3 px outside its box,
// which is glow, not layout.
var overRight = b.x + b.w > frame.w + 4
var overLeft = b.x < -4
var overBottom = b.y + b.h > frame.h + 4
var overTop = b.y < -4
if (overRight || overLeft || overBottom || overTop) {
out.push({
path: label,
at: Math.round(b.x) + "," + Math.round(b.y),
size: Math.round(b.w) + "x" + Math.round(b.h),
frame: Math.round(frame.w) + "x" + Math.round(frame.h),
sides: (overLeft ? "L" : "") + (overRight ? "R" : "") +
(overTop ? "T" : "") + (overBottom ? "B" : "")
})
}
}
walk(c, label)
}
}
walk(popupContent, "popupContent")
return JSON.stringify({ count: out.length, items: out.slice(0, 15) })
}
// Layout probe: every number a future bug report would need, and the two
// overflow checks the eye does on a screenshot. Text can only be trusted
// once these come back clean.
// Keyboard-cursor state, so a wtype-driven test can assert navigation
// without relying on pixels.
// The dial's angle math, so the scrub gesture can be proven from a script
// without a pointer: feed it a point in the ring's coordinates.
function debugBoxes(mm: string, ss: string): string {
popupContent.debugBoxes(mm, ss)
return JSON.stringify({ status: timerService.status, left: timerService.timeLeft })
}
// Opens a tray section so the layout check can walk it.
function debugTray(key: string): string {
root.open()
root.trayOpen = key
return JSON.stringify({ tray: root.trayOpen })
}
// Writes the given webhook URL through the real settings writer, which is
// what a hostile value has to survive: quotes, a newline, a heredoc
// terminator. The payload travels on stdin, so the command leaks nothing.
function debugSetWebhook(url: string): string {
timerService.writeSettings({ webhookUrl: url })
return JSON.stringify({ ok: true, bytes: String(url).length })
}
function debugDrag(fromDeg: string, toDeg: string, fine: string): string {
var m = popupContent.debugDrag(fromDeg, toDeg, fine)
return JSON.stringify({ minutes: m })
}
function debugWheelCount(): string {
return JSON.stringify({ events: popupContent.wheelEvents, source: popupContent.wheelSource, minutes: Math.round(root.customMinutes) })
}
function debugGeom(): string {
return JSON.stringify(popupContent.geom())
}
function debugFieldFocus(): string {
popupContent.focusExact()
return JSON.stringify({ focused: true })
}
// Where the keystrokes actually went: the exact-input boxes are read-only
// to Qt, so their text and focus have to be observable from a script.
function debugTexts(): string {
return popupContent.debugTexts()
}
// Exact input, provable from a script: the same parser the field uses.
function debugExact(text: string): string {
popupContent.submitExact(text)
return JSON.stringify({ status: timerService.status, left: timerService.timeLeft })
}
// The confirm sheet, provable from a script.
function debugConfirm(): string {
root.askCancel()
return JSON.stringify({ open: root.confirmOpen, status: timerService.status })
}
function debugConfirmAnswer(answer: string): string {
if (String(answer) === "yes") root.doCancel()
else root.confirmOpen = false
return JSON.stringify({ open: root.confirmOpen, status: timerService.status })
}
// Hold-to-cancel, provable from a script: start the hold, wait, end it.
function debugHoldStart(): string {
if (timerService.status === "IDLE") return JSON.stringify({ started: false, reason: "idle" })
root.holding = true
holdFill.restart()
holdTimer.restart()
return JSON.stringify({ started: true, status: timerService.status })
}
function debugHoldEnd(): string {
var fired = holdTimer.fired
holdTimer.stop(); holdFill.stop()
root.holding = false; root.holdProgress = 0
if (fired) timerService.cancel()
return JSON.stringify({ fired: fired, status: timerService.status })
}
// The wheel gesture, provable from a script: same code path the handler
// calls, without a pointer.
function debugWheel(step: string): string {
root.wheelAdjust(parseInt(step || "5", 10))
return JSON.stringify({ minutes: root.customMinutes, status: timerService.status,
hint: root.wheelHint })
}
function debugDial(point: string): string {
var parts = String(point || "").split(",")
var x = Number(parts[0] || 0)
var y = Number(parts[1] || 0)
try {
var m = popupContent.minutesAt(x, y)
// w/h — размер самого диска: скрипт считает точку от центра, а не от
// угаданного числа (попап бывает разной ширины).
var d = popupContent.dialItem
return JSON.stringify({
minutes: m, max: popupContent.scrubMax(), x: x, y: y,
size: Math.round(popupContent.width),
w: Math.round(d.width), h: Math.round(d.height)
})
} catch (e) {
return JSON.stringify({ error: String(e) })
}
}
function debugCursor(): string {
return JSON.stringify({
cursorActive: root.cursorActive,
focusSection: root.focusSection,
focusIndex: root.focusIndex,
sections: root.cursorSections(),
selectedAction: root.selectedAction,
customMinutes: root.customMinutes,
timeModeAbsolute: root.timeModeAbsolute,
repeatMode: root.repeatMode,
overrideCommand: timerService.overrideCommand
})
}
function debugLayout(): string {
return JSON.stringify({
language: root.language,
bar: {
implicitWidth: Math.round(root.implicitWidth),
implicitHeight: Math.round(root.implicitHeight),
button: Math.round(button.implicitWidth) + "x" + Math.round(button.implicitHeight),
icon: popupContent.aperturePixels,
labelVisible: timeLabel.visible,
labelWidth: Math.round(timeLabel.implicitWidth),
barColor: String(root.barColor),
urgentColor: String(root.urgent),
accentColor: String(root.accent)
},
popup: {
open: root.opened,
width: Math.round(panel.width),
height: Math.round(panel.height),
contentWidth: Math.round(panel.contentWidth),
contentHeight: Math.round(panel.contentHeight),
columnHeight: Math.round(popupContent.implicitHeight),
scrolls: popupContent.implicitHeight > panelFlick.height
},
hero: {
height: Math.round(popupContent.heroItem.height),
iconWidth: popupContent.aperturePixels,
labelsX: Math.round(popupContent.labelsItem.x),
labelsWidth: Math.round(popupContent.labelsItem.width),
buttonsX: Math.round(popupContent.buttonsItem.x),
buttonsWidth: Math.round(popupContent.buttonsItem.width),
iconClearsLabels: popupContent.labelsItem.x >= popupContent.aperturePixels,
labelsClearButtons: !popupContent.buttonsItem.visible
|| (popupContent.labelsItem.x + popupContent.labelsItem.width) <= popupContent.buttonsItem.x
}
})
}
}
// ---------- bar button ----------
// Icon and remaining time are separate items: the vector mark never has to
// be redrawn per state, and the label can collapse to nothing in IDLE so the
// widget takes a single icon slot when idle.
readonly property string iconVariant: {
if (timerService.status === "COUNTDOWN" || timerService.status === "COUNTDOWN_SCHED") return "countdown"
if (timerService.status === "PAUSED") return "paused"
if (timerService.status === "ACTIVE") return "active"
return "idle"
}
BarIconButton {
id: button
anchors.left: vertical ? undefined : parent.left
anchors.horizontalCenter: vertical ? parent.horizontalCenter : undefined
anchors.top: vertical ? parent.top : undefined
anchors.verticalCenter: vertical ? undefined : parent.verticalCenter
bar: root.bar
text: "timer"
foreground: root.barColor
active: root.barColor === root.urgent
dimmed: root.barDimmed
tooltipText: root.barTooltip
iconComponent: Component {
TimerIcon {
anchors.centerIn: parent
// Match the neighbours by painted ink, not by box size. The stock
// Nerd Font glyphs beside this one paint 11–12 px of ink inside the
// 16 px icon canvas; this mark paints ~0.8 × iconSize, so 15 px lands
// on the same optical size instead of overpowering the bar. (Measured
// on the live bar at scale 1.25: 24 px → 18 px of ink, 20 px → 16,
// 16 px → 12.8, 15 px → 12.)
iconSize: Style.bar.iconCanvas
reducedMotion: timerService.reducedMotion
color: root.barColor
cutout: root.barBackground
variant: root.iconVariant
fraction: root.remainingFraction
holdProgress: root.holdProgress
}
}
// A wheel over the icon sets the time without opening the popup: ±5
// minutes, ±15 with Shift. In IDLE it stages the value; while a timer
// runs it moves the deadline. No other bar widget in Omarchy does this.
WheelHandler {
target: button
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
onWheel: function(event) {
var step = (event.modifiers & Qt.ShiftModifier) ? 15 : 5
root.wheelAdjust(event.angleDelta.y > 0 ? step : -step)
}
}
}
// Press and hold the icon for half a second to cancel, without opening the
// popup: the ring fills while the hold lasts, so the gesture is visible
// before it fires. A short click still opens the menu; right-click opens it
// too (the old right-click-cancel was invisible and conflicted with the
// hold).
property real holdProgress: 0
property bool holding: false
MouseArea {
id: barPress
anchors.fill: button
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
cursorShape: Qt.PointingHandCursor
onPressed: function(mouse) {
if (mouse.button !== Qt.LeftButton) return
if (timerService.status === "IDLE") return
root.holding = true
holdFill.restart()
holdTimer.restart()
}
// A click is handled by onClicked, the same path the right button already
// used: opening the panel from onReleased left the press unclaimed by the
// popup manager, so the left button silently did nothing.
property bool holdConsumed: false
onReleased: function(mouse) {
if (mouse.button !== Qt.LeftButton) return
var fired = holdTimer.fired
holdTimer.stop()
holdFill.stop()
root.holding = false
root.holdProgress = 0
holdConsumed = fired
if (fired) timerService.cancel()
}
onCanceled: {
holdTimer.stop(); holdFill.stop(); root.holding = false; root.holdProgress = 0
holdConsumed = false
}
onClicked: function(mouse) {
if (holdConsumed) { holdConsumed = false; return }
root.toggle()
}
}
Timer {
id: holdTimer
interval: 500
repeat: false
property bool fired: false
onRunningChanged: if (running) fired = false
onTriggered: fired = true
}
NumberAnimation {
id: holdFill
target: root
property: "holdProgress"
from: 0
to: 1
duration: 500
easing.type: Easing.Linear
}
// Remaining time, monospaced so the digits do not jitter as they change.
Text {
id: timeLabel
anchors.left: button.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: Style.space(2)
visible: !root.vertical && root.barText !== ""
text: root.barText
textFormat: Text.PlainText
color: root.barColor
font.family: "monospace"
// 11 px, not the shell caption (10): TZ sets a floor and the bar is the
// one place the user reads without leaning in.
font.pixelSize: Style.font.bodySmall
renderType: Text.NativeRendering
}
// Vertical bar: the same reading, one line per colon-separated chunk.
Column {
id: verticalTime
anchors.top: button.bottom
anchors.horizontalCenter: parent.horizontalCenter
visible: root.vertical && root.verticalLines.length > 0
Repeater {
model: root.verticalLines
delegate: Text {
required property string modelData
width: button.width
textFormat: Text.PlainText
text: modelData
horizontalAlignment: Text.AlignHCenter
color: root.barColor
font.family: "monospace"
font.pixelSize: Style.font.bodySmall
renderType: Text.NativeRendering
}
}
}