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 "../components"
|
||||||
import "../theme"
|
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 {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
property string glyph
|
property string glyph
|
||||||
property string fallback
|
property string fallback
|
||||||
property bool checked: false
|
property bool checked: false
|
||||||
property int size: 34
|
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 clicked
|
||||||
|
signal held
|
||||||
|
signal holdCancelled
|
||||||
implicitWidth: size
|
implicitWidth: size
|
||||||
implicitHeight: size
|
implicitHeight: size
|
||||||
opacity: enabled ? 1 : 0.45
|
opacity: enabled ? 1 : 0.45
|
||||||
@@ -32,12 +42,25 @@ Item {
|
|||||||
easing.type: Easing.OutCubic
|
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 {
|
MouseArea {
|
||||||
id: area
|
id: area
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: root.clicked()
|
onClicked: if (!root.hold)
|
||||||
|
root.clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,8 @@ import "../../services"
|
|||||||
import "../../theme"
|
import "../../theme"
|
||||||
|
|
||||||
// Session actions as round buttons, wrapped to the tile. When they do not fit
|
// 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
|
// it becomes one power button that extends into a list. Destructive actions
|
||||||
// destructive actions extends below the tile.
|
// are held to confirm: accent liquid fills the button, then the action runs.
|
||||||
CCModule {
|
CCModule {
|
||||||
id: root
|
id: root
|
||||||
readonly property var actions: [
|
readonly property var actions: [
|
||||||
@@ -56,10 +56,9 @@ CCModule {
|
|||||||
readonly property real buttonSize: labels || plain ? 34 : squeezed
|
readonly property real buttonSize: labels || plain ? 34 : squeezed
|
||||||
readonly property real buttonWidth: labels ? 52 : buttonSize
|
readonly property real buttonWidth: labels ? 52 : buttonSize
|
||||||
readonly property bool fits: labels || plain || squeezed >= 24
|
readonly property bool fits: labels || plain || squeezed >= 24
|
||||||
readonly property bool pending: PowerService.pending !== ""
|
|
||||||
round: !fits
|
round: !fits
|
||||||
hovered: menuArea.containsMouse
|
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()
|
Component.onDestruction: PowerService.cancel()
|
||||||
function allowed(id) {
|
function allowed(id) {
|
||||||
return (id === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) || (!!SystemService.state.power && !!SystemService.state.power[id] && !SystemService.acting);
|
return (id === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) || (!!SystemService.state.power && !!SystemService.state.power[id] && !SystemService.acting);
|
||||||
@@ -78,22 +77,41 @@ CCModule {
|
|||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: action
|
id: action
|
||||||
required property var modelData
|
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
|
Layout.preferredWidth: root.buttonWidth
|
||||||
spacing: 3
|
spacing: 3
|
||||||
|
Timer {
|
||||||
|
id: hintTimer
|
||||||
|
interval: 1600
|
||||||
|
onTriggered: action.hint = false
|
||||||
|
}
|
||||||
CCToggle {
|
CCToggle {
|
||||||
objectName: "power-" + action.modelData.id
|
objectName: "power-" + action.modelData.id
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
size: root.buttonSize
|
size: root.buttonSize
|
||||||
glyph: action.modelData.glyph
|
glyph: action.modelData.glyph
|
||||||
fallback: action.modelData.label.charAt(0)
|
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)
|
enabled: root.allowed(action.modelData.id)
|
||||||
onClicked: PowerService.request(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 {
|
Text {
|
||||||
visible: root.labels
|
visible: root.labels
|
||||||
text: action.modelData.label
|
text: action.hint ? "Hold" : action.modelData.label
|
||||||
color: Theme.textSecondary
|
color: Theme.textSecondary
|
||||||
font.pixelSize: 10
|
font.pixelSize: 10
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
@@ -140,8 +158,8 @@ CCModule {
|
|||||||
x: 10
|
x: 10
|
||||||
y: root.baseHeight + 6
|
y: root.baseHeight + 6
|
||||||
width: root.width - 20
|
width: root.width - 20
|
||||||
active: root.pending || (root.expanded && !root.fits)
|
active: root.expanded && !root.fits
|
||||||
sourceComponent: root.pending ? confirm : menu
|
sourceComponent: menu
|
||||||
}
|
}
|
||||||
Component {
|
Component {
|
||||||
id: menu
|
id: menu
|
||||||
@@ -152,29 +170,53 @@ CCModule {
|
|||||||
Rectangle {
|
Rectangle {
|
||||||
id: item
|
id: item
|
||||||
required property var modelData
|
required property var modelData
|
||||||
|
readonly property bool hold: PowerService.needsHold(modelData.id)
|
||||||
|
property bool hint: false
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
implicitHeight: 30
|
implicitHeight: 30
|
||||||
radius: 8
|
radius: 8
|
||||||
enabled: root.allowed(modelData.id)
|
enabled: root.allowed(modelData.id)
|
||||||
opacity: enabled ? 1 : 0.45
|
opacity: enabled ? 1 : 0.45
|
||||||
color: itemArea.containsMouse ? Theme.hover : Theme.transparent
|
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.fill: parent
|
||||||
anchors.leftMargin: 8
|
RowLayout {
|
||||||
anchors.rightMargin: 8
|
anchors.fill: parent
|
||||||
spacing: 8
|
anchors.leftMargin: 8
|
||||||
Text {
|
anchors.rightMargin: 8
|
||||||
text: Icons.available ? item.modelData.glyph : ""
|
spacing: 8
|
||||||
font.family: Icons.family
|
Text {
|
||||||
font.pixelSize: 14
|
text: Icons.available ? item.modelData.glyph : ""
|
||||||
color: Theme.text
|
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
|
HoldFill {
|
||||||
color: Theme.text
|
anchors.fill: parent
|
||||||
font.pixelSize: 12
|
visible: item.hold
|
||||||
elide: Text.ElideRight
|
radius: item.radius
|
||||||
Layout.fillWidth: true
|
inkSource: rowContent
|
||||||
|
holding: item.hold && itemArea.pressed && itemArea.containsMouse && PowerService.pending === item.modelData.id
|
||||||
|
onCompleted: PowerService.confirm()
|
||||||
|
onCancelled: {
|
||||||
|
item.hint = true;
|
||||||
|
rowHint.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MouseArea {
|
MouseArea {
|
||||||
@@ -183,39 +225,17 @@ CCModule {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
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 QtQuick
|
||||||
|
import "../components"
|
||||||
import "../theme"
|
import "../theme"
|
||||||
|
|
||||||
// Round glyph button used by the media controls and the power tab.
|
// Round glyph button used by the media controls and the power tab.
|
||||||
@@ -12,7 +13,17 @@ Rectangle {
|
|||||||
property bool active: false
|
property bool active: false
|
||||||
property bool danger: false
|
property bool danger: false
|
||||||
property bool interactive: true
|
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 clicked
|
||||||
|
signal held
|
||||||
|
signal holdCancelled
|
||||||
implicitWidth: size
|
implicitWidth: size
|
||||||
implicitHeight: size
|
implicitHeight: size
|
||||||
radius: size / 2
|
radius: size / 2
|
||||||
@@ -42,13 +53,25 @@ Rectangle {
|
|||||||
font.pixelSize: Math.round(root.size * root.glyphScale)
|
font.pixelSize: Math.round(root.size * root.glyphScale)
|
||||||
color: root.accented ? Theme.accentText : root.active ? Theme.accentVivid : Theme.text
|
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 {
|
MouseArea {
|
||||||
id: area
|
id: area
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
enabled: root.interactive
|
enabled: root.interactive
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: root.clicked()
|
onClicked: if (!root.hold)
|
||||||
|
root.clicked()
|
||||||
}
|
}
|
||||||
Accessible.role: Accessible.Button
|
Accessible.role: Accessible.Button
|
||||||
}
|
}
|
||||||
@@ -4,12 +4,12 @@ import QtQuick.Layouts
|
|||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
import ".."
|
import ".."
|
||||||
import "../../components"
|
|
||||||
import "../../core"
|
import "../../core"
|
||||||
import "../../services"
|
import "../../services"
|
||||||
import "../../theme"
|
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 {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
property bool current: false
|
property bool current: false
|
||||||
@@ -106,7 +106,14 @@ Item {
|
|||||||
id: action
|
id: action
|
||||||
required property var modelData
|
required property var modelData
|
||||||
readonly property bool armed: PowerService.pending === modelData.id
|
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
|
spacing: 10
|
||||||
|
Timer {
|
||||||
|
id: hintTimer
|
||||||
|
interval: 1600
|
||||||
|
onTriggered: action.hint = false
|
||||||
|
}
|
||||||
DashButton {
|
DashButton {
|
||||||
objectName: "dashPower-" + action.modelData.id
|
objectName: "dashPower-" + action.modelData.id
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
@@ -114,53 +121,32 @@ Item {
|
|||||||
glyphScale: 0.36
|
glyphScale: 0.36
|
||||||
glyph: action.modelData.glyph
|
glyph: action.modelData.glyph
|
||||||
fallback: action.modelData.fallback
|
fallback: action.modelData.fallback
|
||||||
active: action.armed
|
hold: PowerService.needsHold(action.modelData.id)
|
||||||
danger: action.modelData.id !== "lock"
|
armed: action.armed
|
||||||
interactive: root.available(action.modelData.id)
|
interactive: root.available(action.modelData.id)
|
||||||
onClicked: root.run(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 {
|
Text {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
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
|
color: action.armed ? Theme.text : Theme.textSecondary
|
||||||
font.pixelSize: 13
|
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 {
|
Singleton {
|
||||||
id: root
|
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: ""
|
property string pending: ""
|
||||||
|
function needsHold(action) {
|
||||||
|
return ["logout", "reboot", "shutdown"].includes(action);
|
||||||
|
}
|
||||||
function request(action) {
|
function request(action) {
|
||||||
// The built-in lock screen needs no external locker.
|
// The built-in lock screen needs no external locker.
|
||||||
if (action === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) {
|
if (action === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) {
|
||||||
@@ -14,7 +19,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
if (!SystemService.state.power || !SystemService.state.power[action] || SystemService.acting)
|
if (!SystemService.state.power || !SystemService.state.power[action] || SystemService.acting)
|
||||||
return false;
|
return false;
|
||||||
if (["logout", "reboot", "shutdown"].includes(action)) {
|
if (needsHold(action)) {
|
||||||
pending = action;
|
pending = action;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,6 +178,17 @@ Item {
|
|||||||
input.mouseClick(item, item.width / 2, item.height / 2);
|
input.mouseClick(item, item.width / 2, item.height / 2);
|
||||||
return true;
|
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 {
|
function slider(name: string): bool {
|
||||||
const item = root.child(name);
|
const item = root.child(name);
|
||||||
if (!item || !item.enabled)
|
if (!item || !item.enabled)
|
||||||
|
|||||||
@@ -80,13 +80,12 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
|
|||||||
wait(lambda:not state()['busy'] and not state()['error'] and not state()['state']['dnd']['enabled'],'provider recovery')
|
wait(lambda:not state()['busy'] and not state()['error'] and not state()['state']['dnd']['enabled'],'provider recovery')
|
||||||
assert ipc('controlTest','slider','brightnessSlider')
|
assert ipc('controlTest','slider','brightnessSlider')
|
||||||
wait(lambda:not state()['busy'] and state()['state']['brightness']['value']>60,'brightness readback')
|
wait(lambda:not state()['busy'] and state()['state']['brightness']['value']>60,'brightness readback')
|
||||||
assert ipc('controlTest','click','power-reboot');assert state()['power']=='reboot'
|
assert ipc('controlTest','click','power-reboot');assert state()['power']==''
|
||||||
|
assert ipc('controlTest','hold','power-shutdown',250);assert state()['power']==''
|
||||||
assert not any(json.loads(line)['action']=='power' for line in events.read_text().splitlines())
|
assert not any(json.loads(line)['action']=='power' for line in events.read_text().splitlines())
|
||||||
assert ipc('controlTest','click','powerCancel');assert state()['power']==''
|
|
||||||
assert ipc('controlTest','click','power-shutdown');ipc('controlTest','pressEscape');wait(lambda:state()['power']=='','Escape cancels pending power')
|
|
||||||
assert ipc('controlcenter','status')['opened']
|
assert ipc('controlcenter','status')['opened']
|
||||||
assert ipc('controlTest','click','power-reboot');assert ipc('controlTest','click','powerConfirm')
|
assert ipc('controlTest','hold','power-reboot',1200)
|
||||||
wait(lambda:not state()['busy'],'recorded confirmation')
|
wait(lambda:not state()['busy'],'recorded hold confirmation')
|
||||||
actions=[json.loads(line) for line in events.read_text().splitlines()]
|
actions=[json.loads(line) for line in events.read_text().splitlines()]
|
||||||
power=[a for a in actions if a['action']=='power'];assert len(power)==1 and power[0]['value']=='reboot' and power[0]['confirmed'] is True,str(actions)
|
power=[a for a in actions if a['action']=='power'];assert len(power)==1 and power[0]['value']=='reboot' and power[0]['confirmed'] is True,str(actions)
|
||||||
ipc('controlcenter','close');time.sleep(.3);ipc('controlcenter','open');time.sleep(.35)
|
ipc('controlcenter','close');time.sleep(.3);ipc('controlcenter','open');time.sleep(.35)
|
||||||
@@ -167,4 +166,4 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
|
|||||||
shell.terminate();shell.wait(timeout=5)
|
shell.terminate();shell.wait(timeout=5)
|
||||||
if original:subprocess.run(['hyprctl','dispatch','focusmonitor',original],capture_output=True)
|
if original:subprocess.run(['hyprctl','dispatch','focusmonitor',original],capture_output=True)
|
||||||
text=log.read_text();assert 'WARN' not in text and 'ERROR' not in text,text
|
text=log.read_text();assert 'WARN' not in text and 'ERROR' not in text,text
|
||||||
print('PASS: native read-only discovery, active-monitor placement, system pill, recording audio/per-app volume/Caffeine/Game Mode/network/Bluetooth/display/DND actions, free grid edit mode (place, push down, air gaps, resize, remove, add, plugin tiles, reset), power confirmation/cancel, outside/Escape/exclusivity, settings, clean logs.')
|
print('PASS: native read-only discovery, active-monitor placement, system pill, recording audio/per-app volume/Caffeine/Game Mode/network/Bluetooth/display/DND actions, free grid edit mode (place, push down, air gaps, resize, remove, add, plugin tiles, reset), power hold-to-confirm/early release, outside/Escape/exclusivity, settings, clean logs.')
|
||||||
Reference in new issue
Block a user