From d37f9b7121e86e62f6033462cfafcc159f45f93b Mon Sep 17 00:00:00 2001 From: mx Date: Sat, 28 Nov 2026 01:05:11 +0100 Subject: [PATCH] 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 --- quickshell/components/HoldFill.qml | 123 +++++++++++++++++ quickshell/components/shaders/holdfill.frag | 58 ++++++++ .../components/shaders/holdfill.frag.qsb | Bin 0 -> 4711 bytes quickshell/controlcenter/CCToggle.qml | 27 +++- quickshell/controlcenter/modules/Power.qml | 128 ++++++++++-------- quickshell/dashboard/DashButton.qml | 25 +++- quickshell/dashboard/tabs/PowerTab.qml | 62 ++++----- quickshell/services/PowerService.qml | 7 +- quickshell/testing/ControlDriver.qml | 11 ++ tests/controlcenter_runtime.py | 11 +- 10 files changed, 350 insertions(+), 102 deletions(-) create mode 100644 quickshell/components/HoldFill.qml create mode 100644 quickshell/components/shaders/holdfill.frag create mode 100644 quickshell/components/shaders/holdfill.frag.qsb diff --git a/quickshell/components/HoldFill.qml b/quickshell/components/HoldFill.qml new file mode 100644 index 0000000..accaab3 --- /dev/null +++ b/quickshell/components/HoldFill.qml @@ -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 + } + } + } +} diff --git a/quickshell/components/shaders/holdfill.frag b/quickshell/components/shaders/holdfill.frag new file mode 100644 index 0000000..31082b7 --- /dev/null +++ b/quickshell/components/shaders/holdfill.frag @@ -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; +} diff --git a/quickshell/components/shaders/holdfill.frag.qsb b/quickshell/components/shaders/holdfill.frag.qsb new file mode 100644 index 0000000000000000000000000000000000000000..2a5fca3e054c5a4b5d31825265eab0025ce21496 GIT binary patch literal 4711 zcmV-t5}54(08p-Yob6l-m|Ry~KR1uvW|Po1O&@7#dYjNNlT0S_p4p^%Gzoo3LeeI- zrD>eb?#!JXGCMPwxtr{!hPIYM(F%xCEdl~U0R^Qw>rYClz1Kz~v4bTktwdwMg&;Rl($at;Tv>%XGFy z5}qOzV|9N&t0Pp9k~&6r6`}|G2jG*4zvBGlvN6D&ZVK^ z$EBpgzt`+JuqWE`i_uh?=dXH>TG)>FY&EQt<9o7DsWF~{lXFOp@nN<>PmHgI=WD2s zC#IPci}W*Ji*vd?$}#eeXj}R7D60k9-a?%VKVLvk9Ggq`g(N?W zSQlt)k&b5=H@BDIc}UwCqWNZ?&%(|9=abyIu*ug3v{wY$=Oa#T+xjT@NurN^Z9zK) zjN{C}FW3Jf`ZG(v8MIf^%;Q>SA!Fl}cLq268b!W2_~Q0vV4TYq2@usLcFf`F)Td67mPN_?_EVQqPUTkKIIAZyYuGgZT}6rJ=E@hGu^L$V6@$S8{Ns|``YonTlcSO>%W)oM;^Yf-G0CBe{oy?gS!1# zyZ=*kZykAb8_%CdQ42dJe~0mVRMhM9sx$AufHBL6{QimVkw@3I<9l4k^YC^%zrP9l zw*Omnhi`rLHn#U&*k*gHXw_Wcn0SIawQXNQmM)|Q%d!4N=w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*wXU+4h zd7kxb@vQp=&)V1FS?M2No>i&!qFBtKj0-B~u6niJoTpv$wCjx0uJ%luXI%4)Yo2k< zGp>2YbvhW=8Rc7Y&ps8Z#s97%(V<$)R*Vx>@k&k2ST@sMU#`&Z+YF7x+Ek)`JU>}@ z33<{PrlwQuBHyN8q(!cd)IG0N@A}K*Ry@>?HW_vYnxuD!}DQ9ZKGbA9FnJvWw+AWj~8y0!cQuZs2_%_2C<@oqq z=L3dQ9`Fl($<1q-Jb0#*ZLut|=z?Dvx5e%zowBc+d4hW%*niy(H|BRW>#bJ)x>{q( z$K>c?jXWQG!Ogq&?Ym)j%%s!9#=a>(U_`hj3kPn@A1pM>B_Adv0ftYaz6&TVA|z85*fgNy&whVx;L!=nvZ70RtNO8V5DfR}jVlUFksZEQ$x$;>3yS5T*g9((r1m>AW!yAl_+~X7X93~a<}GSy4*D-=fs!uf-igFenAS-oDYy@ z?`c@G_Y7#WH<&kjy@|74gO-_^aF6p&6>$e~W>1o47Vjn}Oi9gSNESi*7(|}E0DFe1 zK$HXcvnDc8LvBLdwC0r9v?u6vK0v4Qr$DFk0XjXK$e0tZStQ9NUR5rUD|)uC{jPWY zRw)tf=43W3um%J4aBVEqb;AfrBq}o##7>Z#ZUZOf*TN$F3sGE4PpoZ_iOB-5vs&3L zRtn`>y~WhALJ!SS(Ot9grpZc+_NMa2MzikM{h3CowPs{wZKXC|ohs7HezN2js`-{* ztX9Uh3A|OAEN**fFof` zVB3en0NTgGh?=V!<4X4LGTSA4_;AG3 zp-|Hkavkp#)Nekh^%zFlfBRB2pK|s~?$9B7NMOY5SDWrVK+ilE0BVtN`>#H1Xnb#V zZ$H`1{Ryhnq63fC`+QK$K3wnhJ@F$xUN@umqd#Pio&HnydT=u~uf<+x?JRrd&f8

= 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() - } - } - } - } } diff --git a/quickshell/dashboard/DashButton.qml b/quickshell/dashboard/DashButton.qml index c5b1d67..b4a0c64 100644 --- a/quickshell/dashboard/DashButton.qml +++ b/quickshell/dashboard/DashButton.qml @@ -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 } diff --git a/quickshell/dashboard/tabs/PowerTab.qml b/quickshell/dashboard/tabs/PowerTab.qml index b7ffbff..d6207e3 100644 --- a/quickshell/dashboard/tabs/PowerTab.qml +++ b/quickshell/dashboard/tabs/PowerTab.qml @@ -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() - } - } } } } diff --git a/quickshell/services/PowerService.qml b/quickshell/services/PowerService.qml index 8c9d5d5..eb59c3d 100644 --- a/quickshell/services/PowerService.qml +++ b/quickshell/services/PowerService.qml @@ -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; } diff --git a/quickshell/testing/ControlDriver.qml b/quickshell/testing/ControlDriver.qml index 1bc0866..d95aab0 100644 --- a/quickshell/testing/ControlDriver.qml +++ b/quickshell/testing/ControlDriver.qml @@ -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) diff --git a/tests/controlcenter_runtime.py b/tests/controlcenter_runtime.py index e7eab1a..b4c21d6 100644 --- a/tests/controlcenter_runtime.py +++ b/tests/controlcenter_runtime.py @@ -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') assert ipc('controlTest','slider','brightnessSlider') 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 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('controlTest','click','power-reboot');assert ipc('controlTest','click','powerConfirm') - wait(lambda:not state()['busy'],'recorded confirmation') + assert ipc('controlTest','hold','power-reboot',1200) + wait(lambda:not state()['busy'],'recorded hold confirmation') 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) 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) 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 -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.')