Fix Home shelf slider interactions
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import QtQuick
|
||||
|
||||
import qs.modules.quicksettings
|
||||
|
||||
ShellRoot {
|
||||
id: root
|
||||
|
||||
property int confirmedValue: 30
|
||||
property int commitCount: 0
|
||||
property int lastCommit: -1
|
||||
|
||||
HomeBrightnessSlider {
|
||||
id: slider
|
||||
width: 200
|
||||
value: root.confirmedValue
|
||||
accessibleName: "Desk lamp brightness"
|
||||
onCommitted: value => {
|
||||
root.commitCount += 1;
|
||||
root.lastCommit = value;
|
||||
}
|
||||
}
|
||||
|
||||
IpcHandler {
|
||||
target: "home-brightness-slider-test"
|
||||
|
||||
function reset(value: int): void {
|
||||
root.confirmedValue = value;
|
||||
root.commitCount = 0;
|
||||
root.lastCommit = -1;
|
||||
slider.cancelPointerInteraction();
|
||||
}
|
||||
function external(value: int): void { root.confirmedValue = value; }
|
||||
function press(position: int): void { slider.beginPointerInteraction(position); }
|
||||
function move(position: int): void { slider.movePointerInteraction(position); }
|
||||
function release(): void { slider.releasePointerInteraction(); }
|
||||
function cancel(): void { slider.cancelPointerInteraction(); }
|
||||
function wheel(delta: int): void { slider.commitWheel(delta); }
|
||||
function status(): string {
|
||||
return JSON.stringify({
|
||||
confirmedValue: root.confirmedValue,
|
||||
previewValue: slider.previewValue,
|
||||
interactionActive: slider.interactionActive,
|
||||
commitCount: root.commitCount,
|
||||
lastCommit: root.lastCommit,
|
||||
accessibleRoleIsSlider: slider.Accessible.role === Accessible.Slider,
|
||||
accessibleName: slider.Accessible.name,
|
||||
accessibleDescription: slider.Accessible.description,
|
||||
accessibleFocusable: slider.Accessible.focusable
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,10 @@ Item {
|
||||
|
||||
property int value: 0
|
||||
property int previewValue: 0
|
||||
property bool interactionActive: false
|
||||
property string accessibleName: "Brightness"
|
||||
|
||||
readonly property bool pressed: drag.pressed
|
||||
readonly property bool pressed: root.interactionActive
|
||||
|
||||
signal previewChanged(int value)
|
||||
signal committed(int value)
|
||||
@@ -20,8 +22,18 @@ Item {
|
||||
activeFocusOnTab: root.enabled
|
||||
opacity: root.enabled ? 1 : 0.42
|
||||
|
||||
Accessible.role: Accessible.Slider
|
||||
Accessible.name: root.accessibleName
|
||||
// Qt 6.11's installed Accessible attached type has no structured value or
|
||||
// range properties, so expose both in the supported live description.
|
||||
Accessible.description: root.previewValue + " percent, range 0 to 100"
|
||||
Accessible.focusable: root.enabled
|
||||
Accessible.focused: root.activeFocus
|
||||
Accessible.onIncreaseAction: root.commitStep(5)
|
||||
Accessible.onDecreaseAction: root.commitStep(-5)
|
||||
|
||||
onValueChanged: {
|
||||
if (!drag.pressed)
|
||||
if (!root.interactionActive)
|
||||
root.updatePreview(root.value, false);
|
||||
}
|
||||
|
||||
@@ -53,7 +65,7 @@ Item {
|
||||
color: Theme.warn
|
||||
|
||||
Behavior on width {
|
||||
enabled: !drag.pressed
|
||||
enabled: !root.interactionActive
|
||||
NumberAnimation {
|
||||
duration: Theme.durFast
|
||||
easing.type: Easing.OutQuad
|
||||
@@ -82,26 +94,21 @@ Item {
|
||||
anchors.fill: parent
|
||||
enabled: root.enabled
|
||||
hoverEnabled: true
|
||||
preventStealing: true
|
||||
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||
|
||||
onPressed: event => {
|
||||
root.forceActiveFocus();
|
||||
root.previewAt(event.x);
|
||||
root.beginPointerInteraction(event.x);
|
||||
event.accepted = true;
|
||||
}
|
||||
onPositionChanged: event => {
|
||||
if (pressed)
|
||||
root.previewAt(event.x);
|
||||
}
|
||||
onPositionChanged: event => root.movePointerInteraction(event.x)
|
||||
onReleased: event => {
|
||||
root.committed(root.previewValue);
|
||||
root.releasePointerInteraction();
|
||||
event.accepted = true;
|
||||
}
|
||||
onCanceled: root.updatePreview(root.value, false)
|
||||
onCanceled: root.cancelPointerInteraction()
|
||||
onWheel: event => {
|
||||
const direction = event.angleDelta.y >= 0 ? 5 : -5;
|
||||
root.commitStep(direction);
|
||||
root.commitWheel(event.angleDelta.y);
|
||||
event.accepted = true;
|
||||
}
|
||||
}
|
||||
@@ -123,6 +130,36 @@ Item {
|
||||
root.updatePreview(pointerX / Math.max(1, drag.width) * 100, true);
|
||||
}
|
||||
|
||||
function beginPointerInteraction(pointerX: real): void {
|
||||
if (!root.enabled)
|
||||
return;
|
||||
root.interactionActive = true;
|
||||
root.previewAt(pointerX);
|
||||
}
|
||||
|
||||
function movePointerInteraction(pointerX: real): void {
|
||||
if (root.interactionActive)
|
||||
root.previewAt(pointerX);
|
||||
}
|
||||
|
||||
function releasePointerInteraction(): void {
|
||||
if (!root.interactionActive)
|
||||
return;
|
||||
root.interactionActive = false;
|
||||
root.committed(root.previewValue);
|
||||
}
|
||||
|
||||
function cancelPointerInteraction(): void {
|
||||
root.interactionActive = false;
|
||||
root.updatePreview(root.value, false);
|
||||
}
|
||||
|
||||
function commitWheel(delta: int): void {
|
||||
if (delta === 0)
|
||||
return;
|
||||
root.commitStep(delta > 0 ? 5 : -5);
|
||||
}
|
||||
|
||||
function commitStep(delta: int): void {
|
||||
if (!root.enabled)
|
||||
return;
|
||||
|
||||
@@ -140,6 +140,7 @@ Rectangle {
|
||||
? root.pendingBrightness
|
||||
: root.confirmedBrightness
|
||||
enabled: root.dimmerEnabled
|
||||
accessibleName: root.entity.name + " brightness"
|
||||
onCommitted: value => root.brightnessRequested(value)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user