mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-06 13:38:28 -04:00
fix(PowerMenu): defer keyboard hold actions to key release
- Fixes #2489
This commit is contained in:
@@ -26,6 +26,8 @@ DankModal {
|
|||||||
property int holdActionIndex: -1
|
property int holdActionIndex: -1
|
||||||
property real holdProgress: 0
|
property real holdProgress: 0
|
||||||
property bool showHoldHint: false
|
property bool showHoldHint: false
|
||||||
|
property bool holdFromKeyboard: false
|
||||||
|
property string pendingKeyAction: ""
|
||||||
|
|
||||||
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,6 +41,10 @@ DankModal {
|
|||||||
|
|
||||||
function startHold(action, actionIndex) {
|
function startHold(action, actionIndex) {
|
||||||
if (!needsConfirmation || !actionNeedsConfirm(action)) {
|
if (!needsConfirmation || !actionNeedsConfirm(action)) {
|
||||||
|
if (holdFromKeyboard) {
|
||||||
|
pendingKeyAction = action;
|
||||||
|
return;
|
||||||
|
}
|
||||||
executeAction(action);
|
executeAction(action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -50,6 +56,7 @@ DankModal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cancelHold() {
|
function cancelHold() {
|
||||||
|
pendingKeyAction = "";
|
||||||
if (holdAction === "")
|
if (holdAction === "")
|
||||||
return;
|
return;
|
||||||
const wasHolding = holdProgress > 0;
|
const wasHolding = holdProgress > 0;
|
||||||
@@ -68,8 +75,12 @@ DankModal {
|
|||||||
cancelHold();
|
cancelHold();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const action = holdAction;
|
|
||||||
holdTimer.stop();
|
holdTimer.stop();
|
||||||
|
if (holdFromKeyboard) {
|
||||||
|
pendingKeyAction = holdAction;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const action = holdAction;
|
||||||
holdAction = "";
|
holdAction = "";
|
||||||
holdActionIndex = -1;
|
holdActionIndex = -1;
|
||||||
holdProgress = 0;
|
holdProgress = 0;
|
||||||
@@ -274,6 +285,8 @@ DankModal {
|
|||||||
holdActionIndex = -1;
|
holdActionIndex = -1;
|
||||||
holdProgress = 0;
|
holdProgress = 0;
|
||||||
showHoldHint = false;
|
showHoldHint = false;
|
||||||
|
holdFromKeyboard = false;
|
||||||
|
pendingKeyAction = "";
|
||||||
updateVisibleActions();
|
updateVisibleActions();
|
||||||
const defaultIndex = getDefaultActionIndex();
|
const defaultIndex = getDefaultActionIndex();
|
||||||
selectedIndex = defaultIndex;
|
selectedIndex = defaultIndex;
|
||||||
@@ -296,6 +309,7 @@ DankModal {
|
|||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
holdFromKeyboard = true;
|
||||||
if (SettingsData.powerMenuGridLayout) {
|
if (SettingsData.powerMenuGridLayout) {
|
||||||
handleGridNavigation(event, true);
|
handleGridNavigation(event, true);
|
||||||
} else {
|
} else {
|
||||||
@@ -317,7 +331,16 @@ 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))) {
|
||||||
cancelHold();
|
if (pendingKeyAction !== "") {
|
||||||
|
const action = pendingKeyAction;
|
||||||
|
pendingKeyAction = "";
|
||||||
|
holdAction = "";
|
||||||
|
holdActionIndex = -1;
|
||||||
|
holdProgress = 0;
|
||||||
|
executeAction(action);
|
||||||
|
} else {
|
||||||
|
cancelHold();
|
||||||
|
}
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -411,7 +434,16 @@ 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))) {
|
||||||
cancelHold();
|
if (pendingKeyAction !== "") {
|
||||||
|
const action = pendingKeyAction;
|
||||||
|
pendingKeyAction = "";
|
||||||
|
holdAction = "";
|
||||||
|
holdActionIndex = -1;
|
||||||
|
holdProgress = 0;
|
||||||
|
executeAction(action);
|
||||||
|
} else {
|
||||||
|
cancelHold();
|
||||||
|
}
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -645,6 +677,7 @@ DankModal {
|
|||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onPressed: {
|
onPressed: {
|
||||||
|
root.holdFromKeyboard = false;
|
||||||
root.selectedRow = Math.floor(index / root.gridColumns);
|
root.selectedRow = Math.floor(index / root.gridColumns);
|
||||||
root.selectedCol = index % root.gridColumns;
|
root.selectedCol = index % root.gridColumns;
|
||||||
root.selectedIndex = index;
|
root.selectedIndex = index;
|
||||||
@@ -792,6 +825,7 @@ DankModal {
|
|||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onPressed: {
|
onPressed: {
|
||||||
|
root.holdFromKeyboard = false;
|
||||||
root.selectedIndex = index;
|
root.selectedIndex = index;
|
||||||
root.startHold(modelData, index);
|
root.startHold(modelData, index);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user