mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-06 13:38:28 -04:00
powermenu: don't require key release for actions other than suspend and
hibernate
port 1.5
(cherry picked from commit 2846363f55)
This commit is contained in:
@@ -27,7 +27,7 @@ DankModal {
|
|||||||
property real holdProgress: 0
|
property real holdProgress: 0
|
||||||
property bool showHoldHint: false
|
property bool showHoldHint: false
|
||||||
property bool holdFromKeyboard: false
|
property bool holdFromKeyboard: false
|
||||||
property string pendingKeyAction: ""
|
property string committedAction: ""
|
||||||
|
|
||||||
readonly property bool needsConfirmation: SettingsData.powerActionConfirm
|
readonly property bool needsConfirmation: SettingsData.powerActionConfirm
|
||||||
readonly property int holdDurationMs: SettingsData.powerActionHoldDuration * 1000
|
readonly property int holdDurationMs: SettingsData.powerActionHoldDuration * 1000
|
||||||
@@ -39,10 +39,16 @@ DankModal {
|
|||||||
return action !== "lock" && action !== "restart";
|
return action !== "lock" && action !== "restart";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function actionWakesOnKeyRelease(action) {
|
||||||
|
return action === "suspend" || action === "hibernate";
|
||||||
|
}
|
||||||
|
|
||||||
function startHold(action, actionIndex) {
|
function startHold(action, actionIndex) {
|
||||||
|
if (committedAction !== "")
|
||||||
|
return;
|
||||||
if (!needsConfirmation || !actionNeedsConfirm(action)) {
|
if (!needsConfirmation || !actionNeedsConfirm(action)) {
|
||||||
if (holdFromKeyboard) {
|
if (holdFromKeyboard && actionWakesOnKeyRelease(action)) {
|
||||||
pendingKeyAction = action;
|
commitAction(action, actionIndex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
executeAction(action);
|
executeAction(action);
|
||||||
@@ -56,7 +62,6 @@ DankModal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cancelHold() {
|
function cancelHold() {
|
||||||
pendingKeyAction = "";
|
|
||||||
if (holdAction === "")
|
if (holdAction === "")
|
||||||
return;
|
return;
|
||||||
const wasHolding = holdProgress > 0;
|
const wasHolding = holdProgress > 0;
|
||||||
@@ -76,8 +81,8 @@ DankModal {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
holdTimer.stop();
|
holdTimer.stop();
|
||||||
if (holdFromKeyboard) {
|
if (holdFromKeyboard && actionWakesOnKeyRelease(holdAction)) {
|
||||||
pendingKeyAction = holdAction;
|
commitAction(holdAction, holdActionIndex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const action = holdAction;
|
const action = holdAction;
|
||||||
@@ -87,6 +92,25 @@ DankModal {
|
|||||||
executeAction(action);
|
executeAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function commitAction(action, actionIndex) {
|
||||||
|
holdTimer.stop();
|
||||||
|
holdAction = "";
|
||||||
|
holdActionIndex = actionIndex;
|
||||||
|
committedAction = action;
|
||||||
|
commitFallbackTimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
function executeCommittedAction() {
|
||||||
|
if (committedAction === "")
|
||||||
|
return;
|
||||||
|
commitFallbackTimer.stop();
|
||||||
|
const action = committedAction;
|
||||||
|
committedAction = "";
|
||||||
|
holdActionIndex = -1;
|
||||||
|
holdProgress = 0;
|
||||||
|
executeAction(action);
|
||||||
|
}
|
||||||
|
|
||||||
signal switchUserRequested
|
signal switchUserRequested
|
||||||
|
|
||||||
function executeAction(action) {
|
function executeAction(action) {
|
||||||
@@ -128,6 +152,12 @@ DankModal {
|
|||||||
onTriggered: root.showHoldHint = false
|
onTriggered: root.showHoldHint = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: commitFallbackTimer
|
||||||
|
interval: 5000
|
||||||
|
onTriggered: root.executeCommittedAction()
|
||||||
|
}
|
||||||
|
|
||||||
function openCentered() {
|
function openCentered() {
|
||||||
parentBounds = Qt.rect(0, 0, 0, 0);
|
parentBounds = Qt.rect(0, 0, 0, 0);
|
||||||
parentScreen = null;
|
parentScreen = null;
|
||||||
@@ -286,7 +316,8 @@ DankModal {
|
|||||||
holdProgress = 0;
|
holdProgress = 0;
|
||||||
showHoldHint = false;
|
showHoldHint = false;
|
||||||
holdFromKeyboard = false;
|
holdFromKeyboard = false;
|
||||||
pendingKeyAction = "";
|
committedAction = "";
|
||||||
|
commitFallbackTimer.stop();
|
||||||
updateVisibleActions();
|
updateVisibleActions();
|
||||||
const defaultIndex = getDefaultActionIndex();
|
const defaultIndex = getDefaultActionIndex();
|
||||||
selectedIndex = defaultIndex;
|
selectedIndex = defaultIndex;
|
||||||
@@ -309,6 +340,10 @@ DankModal {
|
|||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (committedAction !== "") {
|
||||||
|
event.accepted = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
holdFromKeyboard = true;
|
holdFromKeyboard = true;
|
||||||
if (SettingsData.powerMenuGridLayout) {
|
if (SettingsData.powerMenuGridLayout) {
|
||||||
handleGridNavigation(event, true);
|
handleGridNavigation(event, true);
|
||||||
@@ -321,6 +356,11 @@ DankModal {
|
|||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (committedAction !== "") {
|
||||||
|
event.accepted = true;
|
||||||
|
executeCommittedAction();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (SettingsData.powerMenuGridLayout) {
|
if (SettingsData.powerMenuGridLayout) {
|
||||||
handleGridNavigation(event, false);
|
handleGridNavigation(event, false);
|
||||||
} else {
|
} else {
|
||||||
@@ -331,16 +371,7 @@ DankModal {
|
|||||||
function handleListNavigation(event, isPressed) {
|
function handleListNavigation(event, isPressed) {
|
||||||
if (!isPressed) {
|
if (!isPressed) {
|
||||||
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_X || event.key === Qt.Key_L || event.key === Qt.Key_S || event.key === Qt.Key_H || event.key === Qt.Key_D || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_X || event.key === Qt.Key_L || event.key === Qt.Key_S || event.key === Qt.Key_H || event.key === Qt.Key_D || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
||||||
if (pendingKeyAction !== "") {
|
cancelHold();
|
||||||
const action = pendingKeyAction;
|
|
||||||
pendingKeyAction = "";
|
|
||||||
holdAction = "";
|
|
||||||
holdActionIndex = -1;
|
|
||||||
holdProgress = 0;
|
|
||||||
executeAction(action);
|
|
||||||
} else {
|
|
||||||
cancelHold();
|
|
||||||
}
|
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -434,16 +465,7 @@ DankModal {
|
|||||||
function handleGridNavigation(event, isPressed) {
|
function handleGridNavigation(event, isPressed) {
|
||||||
if (!isPressed) {
|
if (!isPressed) {
|
||||||
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_X || event.key === Qt.Key_L || event.key === Qt.Key_S || event.key === Qt.Key_H || event.key === Qt.Key_D || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_X || event.key === Qt.Key_L || event.key === Qt.Key_S || event.key === Qt.Key_H || event.key === Qt.Key_D || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
||||||
if (pendingKeyAction !== "") {
|
cancelHold();
|
||||||
const action = pendingKeyAction;
|
|
||||||
pendingKeyAction = "";
|
|
||||||
holdAction = "";
|
|
||||||
holdActionIndex = -1;
|
|
||||||
holdProgress = 0;
|
|
||||||
executeAction(action);
|
|
||||||
} else {
|
|
||||||
cancelHold();
|
|
||||||
}
|
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -812,6 +834,7 @@ DankModal {
|
|||||||
|
|
||||||
Row {
|
Row {
|
||||||
id: hintRow
|
id: hintRow
|
||||||
|
readonly property bool selectedNeedsHold: root.actionNeedsConfirm(root.getActionAtIndex(root.selectedIndex))
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.bottomMargin: Theme.spacingS
|
anchors.bottomMargin: Theme.spacingS
|
||||||
@@ -826,7 +849,13 @@ DankModal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DankIcon {
|
DankIcon {
|
||||||
name: root.showHoldHint ? "warning" : "touch_app"
|
name: {
|
||||||
|
if (root.showHoldHint)
|
||||||
|
return "warning";
|
||||||
|
if (!hintRow.selectedNeedsHold)
|
||||||
|
return "bolt";
|
||||||
|
return "touch_app";
|
||||||
|
}
|
||||||
size: Theme.fontSizeSmall
|
size: Theme.fontSizeSmall
|
||||||
color: root.showHoldHint ? Theme.warning : Theme.surfaceTextSecondary
|
color: root.showHoldHint ? Theme.warning : Theme.surfaceTextSecondary
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
@@ -836,8 +865,12 @@ DankModal {
|
|||||||
readonly property real totalMs: SettingsData.powerActionHoldDuration * 1000
|
readonly property real totalMs: SettingsData.powerActionHoldDuration * 1000
|
||||||
readonly property int remainingMs: Math.ceil(totalMs * (1 - root.holdProgress))
|
readonly property int remainingMs: Math.ceil(totalMs * (1 - root.holdProgress))
|
||||||
text: {
|
text: {
|
||||||
|
if (root.committedAction !== "")
|
||||||
|
return I18n.tr("Release to confirm");
|
||||||
if (root.showHoldHint)
|
if (root.showHoldHint)
|
||||||
return I18n.tr("Hold longer to confirm");
|
return I18n.tr("Hold longer to confirm");
|
||||||
|
if (!hintRow.selectedNeedsHold)
|
||||||
|
return I18n.tr("Activates immediately");
|
||||||
if (root.holdProgress > 0) {
|
if (root.holdProgress > 0) {
|
||||||
if (totalMs < 1000)
|
if (totalMs < 1000)
|
||||||
return I18n.tr("Hold to confirm (%1 ms)").arg(remainingMs);
|
return I18n.tr("Hold to confirm (%1 ms)").arg(remainingMs);
|
||||||
|
|||||||
Reference in New Issue
Block a user