Hold power actions to confirm instead of a confirm row
Logout, reboot and shut down now fill with accent liquid while held and run once full; letting go early drains it. A tap hints to hold. Replaces the Confirm/Cancel rows in the control center tile and dashboard tab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e918414d1
commit
d37f9b7121
10 files changed
+350
-102
No files matched your search
@@ -0,0 +1,123 @@
|
||||
import QtQuick
|
||||
import "../theme"
|
||||
|
||||
// Hold-to-confirm overlay: accent liquid fills the parent shape while
|
||||
// `holding` is true and emits completed() once full. Let go early and it
|
||||
// drains. The glyph (or `inkSource`) turns the accent text colour where the
|
||||
// liquid covers it, so the overlay sits on top of the button's own glyph.
|
||||
Item {
|
||||
id: root
|
||||
property bool holding: false
|
||||
property int duration: 800
|
||||
property real radius: Math.min(width, height) / 2
|
||||
property color color: Theme.accent
|
||||
property color inkColor: Theme.accentText
|
||||
// The default ink is a centred glyph matching the button's own.
|
||||
property string glyph
|
||||
property string fallback
|
||||
property int glyphSize: Math.round(Math.min(width, height) * 0.5)
|
||||
property int glyphWeight: Font.Normal
|
||||
// Any transparent item the size of this one, e.g. a row of labels.
|
||||
property Item inkSource: defaultInk
|
||||
property real progress: 0
|
||||
property real time: 0
|
||||
// Stays full for a moment after completing, in case the action fails.
|
||||
property bool latched: false
|
||||
readonly property bool active: progress > 0
|
||||
signal completed
|
||||
// Let go before full.
|
||||
signal cancelled
|
||||
|
||||
onHoldingChanged: {
|
||||
if (latched)
|
||||
return;
|
||||
if (holding) {
|
||||
drain.stop();
|
||||
rise.from = progress;
|
||||
rise.duration = Math.max(1, (1 - progress) * duration);
|
||||
rise.start();
|
||||
} else if (rise.running || progress > 0) {
|
||||
rise.stop();
|
||||
if (progress < 1)
|
||||
cancelled();
|
||||
root.empty();
|
||||
}
|
||||
}
|
||||
function empty() {
|
||||
drain.from = progress;
|
||||
drain.duration = Theme.duration * 2.2 * progress;
|
||||
drain.start();
|
||||
}
|
||||
|
||||
NumberAnimation {
|
||||
id: rise
|
||||
target: root
|
||||
property: "progress"
|
||||
to: 1
|
||||
easing.type: Easing.InOutSine
|
||||
onFinished: if (root.progress >= 1) {
|
||||
root.latched = true;
|
||||
hold.restart();
|
||||
root.completed();
|
||||
}
|
||||
}
|
||||
NumberAnimation {
|
||||
id: drain
|
||||
target: root
|
||||
property: "progress"
|
||||
to: 0
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
Timer {
|
||||
id: hold
|
||||
interval: 900
|
||||
onTriggered: {
|
||||
root.latched = false;
|
||||
if (!root.holding)
|
||||
root.empty();
|
||||
}
|
||||
}
|
||||
FrameAnimation {
|
||||
running: root.active && Theme.intensity > 0
|
||||
onTriggered: root.time += frameTime
|
||||
}
|
||||
|
||||
Text {
|
||||
id: defaultInk
|
||||
width: root.width
|
||||
height: root.height
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: Icons.available && root.glyph ? root.glyph : root.fallback
|
||||
font.family: Icons.available && root.glyph ? Icons.family : ""
|
||||
font.pixelSize: root.glyphSize
|
||||
font.weight: root.glyphWeight
|
||||
color: "white"
|
||||
}
|
||||
ShaderEffectSource {
|
||||
id: inkTexture
|
||||
sourceItem: root.inkSource
|
||||
hideSource: root.inkSource === defaultInk
|
||||
live: true
|
||||
visible: false
|
||||
}
|
||||
ShaderEffect {
|
||||
anchors.fill: parent
|
||||
visible: root.active
|
||||
property point size: Qt.point(width, height)
|
||||
property real radius: root.radius
|
||||
property real level: root.progress
|
||||
property real time: root.time
|
||||
// Sloshes more while draining than while filling.
|
||||
property real slosh: Math.max(1.2, root.height * 0.06) * Math.min(1, Theme.intensity) * (root.holding ? 1 : 1.6)
|
||||
property vector4d fill: Qt.vector4d(root.color.r * root.color.a, root.color.g * root.color.a, root.color.b * root.color.a, root.color.a)
|
||||
property vector4d ink: Qt.vector4d(root.inkColor.r * root.inkColor.a, root.inkColor.g * root.inkColor.a, root.inkColor.b * root.inkColor.a, root.inkColor.a)
|
||||
property var glyph: inkTexture
|
||||
fragmentShader: Qt.resolvedUrl("shaders/holdfill.frag.qsb")
|
||||
Behavior on slosh {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#version 440
|
||||
// Hold-to-confirm fill (HoldFill.qml): accent liquid rises inside a rounded
|
||||
// shape while a button is held, with a wavy surface, a paler back wave and a
|
||||
// lit meniscus. The glyph texture is inked in the accent text colour where the
|
||||
// liquid covers it. Output is premultiplied.
|
||||
// Rebuild holdfill.frag.qsb with scripts/build-shaders after editing.
|
||||
layout(location = 0) in vec2 qt_TexCoord0;
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 qt_Matrix;
|
||||
float qt_Opacity;
|
||||
vec2 size; // item size, px
|
||||
float radius; // corner radius, px
|
||||
float level; // 0 empty .. 1 full
|
||||
float time; // seconds, drives the waves
|
||||
float slosh; // wave amplitude, px
|
||||
vec4 fill; // premultiplied liquid colour
|
||||
vec4 ink; // premultiplied glyph colour under the liquid
|
||||
};
|
||||
|
||||
layout(binding = 1) uniform sampler2D glyph;
|
||||
|
||||
float sdBox(vec2 p, vec2 h, float r) {
|
||||
r = min(r, min(h.x, h.y));
|
||||
vec2 q = abs(p) - h + r;
|
||||
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 p = qt_TexCoord0 * size;
|
||||
float shape = clamp(0.5 - sdBox(p - size * 0.5, size * 0.5, radius), 0.0, 1.0);
|
||||
if (shape <= 0.0 || level <= 0.0) {
|
||||
fragColor = vec4(0.0);
|
||||
return;
|
||||
}
|
||||
// Waves calm down at the very bottom and top so it starts and ends flat.
|
||||
float amp = slosh * smoothstep(0.0, 0.18, level) * (1.0 - smoothstep(0.82, 1.0, level));
|
||||
float x = p.x / max(size.x, 1.0) * 6.2831853;
|
||||
float base = mix(size.y + amp * 2.0, -amp * 2.0, level);
|
||||
float front = base + amp * (sin(x * 1.3 + time * 4.2) * 0.65 + sin(x * 2.1 - time * 2.9) * 0.35);
|
||||
float back = base - amp * 0.6 + amp * sin(x * 1.1 - time * 3.4 + 1.7);
|
||||
|
||||
float aFront = clamp(p.y - front + 0.5, 0.0, 1.0);
|
||||
float aBack = clamp(p.y - back + 0.5, 0.0, 1.0) * 0.42;
|
||||
|
||||
// Deeper liquid is a touch darker; a bright band sits under the surface.
|
||||
float depth = clamp((p.y - front) / max(size.y, 1.0), 0.0, 1.0);
|
||||
vec3 col = fill.rgb * (1.0 - 0.16 * depth);
|
||||
float meniscus = exp(-max(p.y - front, 0.0) / 1.6) * aFront;
|
||||
col = mix(col, vec3(fill.a), 0.28 * meniscus);
|
||||
|
||||
vec4 c = vec4(fill.rgb, fill.a) * aBack;
|
||||
c = c * (1.0 - aFront) + vec4(col, fill.a) * aFront;
|
||||
float g = texture(glyph, qt_TexCoord0).a * aFront;
|
||||
c = c * (1.0 - g * ink.a) + ink * g;
|
||||
fragColor = c * shape * qt_Opacity;
|
||||
}
|
||||
Binary file not shown.
@@ -2,14 +2,24 @@ import QtQuick
|
||||
import "../components"
|
||||
import "../theme"
|
||||
|
||||
// Round icon toggle; filled with the accent while on.
|
||||
// Round icon toggle; filled with the accent while on. With `hold` it is a
|
||||
// hold-to-confirm button instead: liquid fills it while held and held() fires
|
||||
// once full; clicked() is not emitted.
|
||||
Item {
|
||||
id: root
|
||||
property string glyph
|
||||
property string fallback
|
||||
property bool checked: false
|
||||
property int size: 34
|
||||
property bool hold: false
|
||||
// Callers may withhold filling, e.g. until an action is pending.
|
||||
property bool armed: true
|
||||
readonly property bool holding: hold && armed && area.pressed && area.containsMouse
|
||||
readonly property bool pressed: area.pressed
|
||||
readonly property bool filled: fill.active
|
||||
signal clicked
|
||||
signal held
|
||||
signal holdCancelled
|
||||
implicitWidth: size
|
||||
implicitHeight: size
|
||||
opacity: enabled ? 1 : 0.45
|
||||
@@ -32,12 +42,25 @@ Item {
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
HoldFill {
|
||||
id: fill
|
||||
anchors.fill: parent
|
||||
visible: root.hold
|
||||
holding: root.holding
|
||||
glyph: root.glyph
|
||||
fallback: root.fallback
|
||||
glyphSize: Math.round(root.size * 0.5)
|
||||
glyphWeight: Font.DemiBold
|
||||
onCompleted: root.held()
|
||||
onCancelled: root.holdCancelled()
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
id: area
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.clicked()
|
||||
onClicked: if (!root.hold)
|
||||
root.clicked()
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import "../../services"
|
||||
import "../../theme"
|
||||
|
||||
// Session actions as round buttons, wrapped to the tile. When they do not fit
|
||||
// it becomes one power button that extends into a list. Confirmation for
|
||||
// destructive actions extends below the tile.
|
||||
// it becomes one power button that extends into a list. Destructive actions
|
||||
// are held to confirm: accent liquid fills the button, then the action runs.
|
||||
CCModule {
|
||||
id: root
|
||||
readonly property var actions: [
|
||||
@@ -56,10 +56,9 @@ CCModule {
|
||||
readonly property real buttonSize: labels || plain ? 34 : squeezed
|
||||
readonly property real buttonWidth: labels ? 52 : buttonSize
|
||||
readonly property bool fits: labels || plain || squeezed >= 24
|
||||
readonly property bool pending: PowerService.pending !== ""
|
||||
round: !fits
|
||||
hovered: menuArea.containsMouse
|
||||
extraHeight: (pending || (expanded && !fits)) && extension.item ? extension.implicitHeight + 20 : 0
|
||||
extraHeight: expanded && !fits && extension.item ? extension.implicitHeight + 20 : 0
|
||||
Component.onDestruction: PowerService.cancel()
|
||||
function allowed(id) {
|
||||
return (id === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) || (!!SystemService.state.power && !!SystemService.state.power[id] && !SystemService.acting);
|
||||
@@ -78,22 +77,41 @@ CCModule {
|
||||
ColumnLayout {
|
||||
id: action
|
||||
required property var modelData
|
||||
// A tap on a hold button says to hold it, in place of the label.
|
||||
property bool hint: false
|
||||
Layout.preferredWidth: root.buttonWidth
|
||||
spacing: 3
|
||||
Timer {
|
||||
id: hintTimer
|
||||
interval: 1600
|
||||
onTriggered: action.hint = false
|
||||
}
|
||||
CCToggle {
|
||||
objectName: "power-" + action.modelData.id
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
size: root.buttonSize
|
||||
glyph: action.modelData.glyph
|
||||
fallback: action.modelData.label.charAt(0)
|
||||
checked: PowerService.pending === action.modelData.id
|
||||
hold: PowerService.needsHold(action.modelData.id)
|
||||
armed: PowerService.pending === action.modelData.id
|
||||
enabled: root.allowed(action.modelData.id)
|
||||
onClicked: PowerService.request(action.modelData.id)
|
||||
Accessible.name: action.modelData.label
|
||||
onPressedChanged: if (hold) {
|
||||
if (pressed)
|
||||
PowerService.request(action.modelData.id);
|
||||
else if (armed)
|
||||
PowerService.cancel();
|
||||
}
|
||||
onHeld: PowerService.confirm()
|
||||
onHoldCancelled: {
|
||||
action.hint = true;
|
||||
hintTimer.restart();
|
||||
}
|
||||
Accessible.name: hold ? "Hold to " + action.modelData.label.toLowerCase() : action.modelData.label
|
||||
}
|
||||
Text {
|
||||
visible: root.labels
|
||||
text: action.modelData.label
|
||||
text: action.hint ? "Hold" : action.modelData.label
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 10
|
||||
elide: Text.ElideRight
|
||||
@@ -140,8 +158,8 @@ CCModule {
|
||||
x: 10
|
||||
y: root.baseHeight + 6
|
||||
width: root.width - 20
|
||||
active: root.pending || (root.expanded && !root.fits)
|
||||
sourceComponent: root.pending ? confirm : menu
|
||||
active: root.expanded && !root.fits
|
||||
sourceComponent: menu
|
||||
}
|
||||
Component {
|
||||
id: menu
|
||||
@@ -152,29 +170,53 @@ CCModule {
|
||||
Rectangle {
|
||||
id: item
|
||||
required property var modelData
|
||||
readonly property bool hold: PowerService.needsHold(modelData.id)
|
||||
property bool hint: false
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: 30
|
||||
radius: 8
|
||||
enabled: root.allowed(modelData.id)
|
||||
opacity: enabled ? 1 : 0.45
|
||||
color: itemArea.containsMouse ? Theme.hover : Theme.transparent
|
||||
RowLayout {
|
||||
Timer {
|
||||
id: rowHint
|
||||
interval: 1600
|
||||
onTriggered: item.hint = false
|
||||
}
|
||||
// Transparent, so it doubles as the ink mask for the fill.
|
||||
Item {
|
||||
id: rowContent
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: 8
|
||||
anchors.rightMargin: 8
|
||||
spacing: 8
|
||||
Text {
|
||||
text: Icons.available ? item.modelData.glyph : ""
|
||||
font.family: Icons.family
|
||||
font.pixelSize: 14
|
||||
color: Theme.text
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: 8
|
||||
anchors.rightMargin: 8
|
||||
spacing: 8
|
||||
Text {
|
||||
text: Icons.available ? item.modelData.glyph : ""
|
||||
font.family: Icons.family
|
||||
font.pixelSize: 14
|
||||
color: Theme.text
|
||||
}
|
||||
Text {
|
||||
text: item.hint ? "Hold to " + item.modelData.label.toLowerCase() : item.modelData.label
|
||||
color: Theme.text
|
||||
font.pixelSize: 12
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: item.modelData.label
|
||||
color: Theme.text
|
||||
font.pixelSize: 12
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
HoldFill {
|
||||
anchors.fill: parent
|
||||
visible: item.hold
|
||||
radius: item.radius
|
||||
inkSource: rowContent
|
||||
holding: item.hold && itemArea.pressed && itemArea.containsMouse && PowerService.pending === item.modelData.id
|
||||
onCompleted: PowerService.confirm()
|
||||
onCancelled: {
|
||||
item.hint = true;
|
||||
rowHint.restart();
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
@@ -183,39 +225,17 @@ CCModule {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: PowerService.request(item.modelData.id)
|
||||
onClicked: if (!item.hold)
|
||||
PowerService.request(item.modelData.id)
|
||||
onPressedChanged: if (item.hold) {
|
||||
if (pressed)
|
||||
PowerService.request(item.modelData.id);
|
||||
else if (PowerService.pending === item.modelData.id)
|
||||
PowerService.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Component {
|
||||
id: confirm
|
||||
ColumnLayout {
|
||||
spacing: 8
|
||||
Text {
|
||||
text: "Confirm " + PowerService.pending + "? Unsaved work may be lost."
|
||||
color: Theme.text
|
||||
font.pixelSize: 12
|
||||
wrapMode: Text.Wrap
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
RowLayout {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
spacing: 8
|
||||
GlassButton {
|
||||
objectName: "powerCancel"
|
||||
text: "Cancel"
|
||||
onClicked: PowerService.cancel()
|
||||
}
|
||||
GlassButton {
|
||||
objectName: "powerConfirm"
|
||||
text: "Confirm"
|
||||
accented: true
|
||||
enabled: !SystemService.acting
|
||||
onClicked: PowerService.confirm()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import QtQuick
|
||||
import "../components"
|
||||
import "../theme"
|
||||
|
||||
// Round glyph button used by the media controls and the power tab.
|
||||
@@ -12,7 +13,17 @@ Rectangle {
|
||||
property bool active: false
|
||||
property bool danger: false
|
||||
property bool interactive: true
|
||||
// Hold-to-confirm: liquid fills the button while held, held() fires once
|
||||
// full and clicked() is not emitted.
|
||||
property bool hold: false
|
||||
// Callers may withhold filling, e.g. until an action is pending.
|
||||
property bool armed: true
|
||||
readonly property bool holding: hold && armed && area.pressed && area.containsMouse
|
||||
readonly property bool pressed: area.pressed
|
||||
readonly property bool filled: fill.active
|
||||
signal clicked
|
||||
signal held
|
||||
signal holdCancelled
|
||||
implicitWidth: size
|
||||
implicitHeight: size
|
||||
radius: size / 2
|
||||
@@ -42,13 +53,25 @@ Rectangle {
|
||||
font.pixelSize: Math.round(root.size * root.glyphScale)
|
||||
color: root.accented ? Theme.accentText : root.active ? Theme.accentVivid : Theme.text
|
||||
}
|
||||
HoldFill {
|
||||
id: fill
|
||||
anchors.fill: parent
|
||||
visible: root.hold
|
||||
holding: root.holding
|
||||
glyph: root.glyph
|
||||
fallback: root.fallback
|
||||
glyphSize: Math.round(root.size * root.glyphScale)
|
||||
onCompleted: root.held()
|
||||
onCancelled: root.holdCancelled()
|
||||
}
|
||||
MouseArea {
|
||||
id: area
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
enabled: root.interactive
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.clicked()
|
||||
onClicked: if (!root.hold)
|
||||
root.clicked()
|
||||
}
|
||||
Accessible.role: Accessible.Button
|
||||
}
|
||||
@@ -4,12 +4,12 @@ import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import ".."
|
||||
import "../../components"
|
||||
import "../../core"
|
||||
import "../../services"
|
||||
import "../../theme"
|
||||
|
||||
// Lock, restart and shut down. Restart and shut down ask for confirmation.
|
||||
// Lock, restart and shut down. Restart and shut down are held to confirm:
|
||||
// accent liquid fills the button, then the action runs.
|
||||
Item {
|
||||
id: root
|
||||
property bool current: false
|
||||
@@ -106,7 +106,14 @@ Item {
|
||||
id: action
|
||||
required property var modelData
|
||||
readonly property bool armed: PowerService.pending === modelData.id
|
||||
// A tap on a hold button says to hold it, in place of the label.
|
||||
property bool hint: false
|
||||
spacing: 10
|
||||
Timer {
|
||||
id: hintTimer
|
||||
interval: 1600
|
||||
onTriggered: action.hint = false
|
||||
}
|
||||
DashButton {
|
||||
objectName: "dashPower-" + action.modelData.id
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
@@ -114,53 +121,32 @@ Item {
|
||||
glyphScale: 0.36
|
||||
glyph: action.modelData.glyph
|
||||
fallback: action.modelData.fallback
|
||||
active: action.armed
|
||||
danger: action.modelData.id !== "lock"
|
||||
hold: PowerService.needsHold(action.modelData.id)
|
||||
armed: action.armed
|
||||
interactive: root.available(action.modelData.id)
|
||||
onClicked: root.run(action.modelData.id)
|
||||
Accessible.name: action.modelData.label
|
||||
onPressedChanged: if (hold) {
|
||||
if (pressed)
|
||||
PowerService.request(action.modelData.id);
|
||||
else if (action.armed)
|
||||
PowerService.cancel();
|
||||
}
|
||||
onHeld: PowerService.confirm()
|
||||
onHoldCancelled: {
|
||||
action.hint = true;
|
||||
hintTimer.restart();
|
||||
}
|
||||
Accessible.name: hold ? "Hold to " + action.modelData.label.toLowerCase() : action.modelData.label
|
||||
}
|
||||
Text {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: action.modelData.label
|
||||
text: action.hint ? "Hold to " + action.modelData.label.toLowerCase() : action.modelData.label
|
||||
color: action.armed ? Theme.text : Theme.textSecondary
|
||||
font.pixelSize: 13
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RowLayout {
|
||||
id: confirm
|
||||
Layout.fillWidth: true
|
||||
spacing: 8
|
||||
readonly property var pending: root.actions.find(a => a.id === PowerService.pending)
|
||||
opacity: pending ? 1 : 0
|
||||
visible: opacity > 0
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: confirm.pending ? confirm.pending.label + " now? Unsaved work may be lost." : ""
|
||||
color: Theme.text
|
||||
font.pixelSize: 12
|
||||
wrapMode: Text.Wrap
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
GlassButton {
|
||||
objectName: "dashPowerCancel"
|
||||
text: "Cancel"
|
||||
onClicked: PowerService.cancel()
|
||||
}
|
||||
GlassButton {
|
||||
objectName: "dashPowerConfirm"
|
||||
text: confirm.pending ? confirm.pending.label : "Confirm"
|
||||
accented: true
|
||||
enabled: !SystemService.acting
|
||||
onClicked: PowerService.confirm()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,12 @@ import "../core"
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
// The action being held to confirm. Its button fills while this is set and
|
||||
// confirm() runs it once full; cancel() (release, Escape, closing) drains.
|
||||
property string pending: ""
|
||||
function needsHold(action) {
|
||||
return ["logout", "reboot", "shutdown"].includes(action);
|
||||
}
|
||||
function request(action) {
|
||||
// The built-in lock screen needs no external locker.
|
||||
if (action === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) {
|
||||
@@ -14,7 +19,7 @@ Singleton {
|
||||
}
|
||||
if (!SystemService.state.power || !SystemService.state.power[action] || SystemService.acting)
|
||||
return false;
|
||||
if (["logout", "reboot", "shutdown"].includes(action)) {
|
||||
if (needsHold(action)) {
|
||||
pending = action;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -178,6 +178,17 @@ Item {
|
||||
input.mouseClick(item, item.width / 2, item.height / 2);
|
||||
return true;
|
||||
}
|
||||
// Presses an item and holds it for ms before releasing.
|
||||
function hold(name: string, ms: int): bool {
|
||||
const item = root.child(name);
|
||||
if (!item || !item.enabled)
|
||||
return false;
|
||||
root.reveal(item);
|
||||
input.mousePress(item, item.width / 2, item.height / 2);
|
||||
input.wait(ms);
|
||||
input.mouseRelease(item, item.width / 2, item.height / 2);
|
||||
return true;
|
||||
}
|
||||
function slider(name: string): bool {
|
||||
const item = root.child(name);
|
||||
if (!item || !item.enabled)
|
||||
|
||||
Reference in new issue
Block a user