blob: c59c2f1fe723323e1e9ada66397dfc1fc850ac6a (
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
|
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import QtQuick
import QtQuick.Controls
import "../.."
// A switch plus an optional minutes field. The switch is the auto-lock state:
// on means the screen locks on idle as usual. Turning it off asserts the idle
// inhibitor, which is the only thing that stops hypridle. A number in the field
// makes that disable temporary and it re-enables itself; an empty field makes
// it permanent. The singleton owns the state and the timer, so the effect
// outlives this row, which dies with the drawer page.
Item {
id: row
// A tick so the row repaints when a timed disable expires on its own.
property double now: Date.now()
Timer {
interval: 1000
running: true
repeat: true
onTriggered: row.now = Date.now()
}
readonly property bool lockOn: !Status.nolock
readonly property bool timed: Status.nolockUntil > row.now
implicitHeight: Math.max(texts.implicitHeight, controls.implicitHeight) + 16
function hhmm(ts) {
const d = new Date(ts);
return ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2);
}
function apply(lockOn) {
if (lockOn) {
Status.setMode("nolock", false);
} else {
const n = parseInt(minutes.text, 10);
Status.disableLockFor(isNaN(n) || n < 1 ? 0 : n);
}
}
Column {
id: texts
anchors {
left: parent.left
right: controls.left
rightMargin: 12
verticalCenter: parent.verticalCenter
}
spacing: 2
Text {
text: "Screen lock"
font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true }
color: Theme.text
}
Text {
width: parent.width
wrapMode: Text.WordWrap
text: row.lockOn ? "The screen locks automatically when the session is idle."
: row.timed ? "Auto-lock is off until " + row.hhmm(Status.nolockUntil) + "."
: "Auto-lock stays off until you turn it back on."
font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
color: Theme.subtext
}
}
Row {
id: controls
anchors { right: parent.right; verticalCenter: parent.verticalCenter }
spacing: 8
TextField {
id: minutes
width: 48
height: 28
placeholderText: "min"
horizontalAlignment: TextInput.AlignHCenter
color: Theme.text
font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
background: Rectangle {
radius: 6
color: Qt.alpha(Theme.surface, 0.9)
border.width: 1
border.color: Qt.alpha(Theme.text, 0.15)
}
validator: IntValidator { bottom: 1; top: 1440 }
}
Switch {
id: sw
checked: row.lockOn
onToggled: row.apply(!row.lockOn)
}
}
// The shared Switch's click handler writes `checked` directly, which drops
// the declarative binding above. Resync on any state change so the timer,
// statusctl or presentation mode moves the switch back into agreement.
onLockOnChanged: sw.checked = row.lockOn
}
|