mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-02 03:28:28 -04:00
greeter: migrated dms-greeter to github/AvengeMedia/dank-greeter
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
DankActionButton {
|
||||
id: customButtonKeyboard
|
||||
circular: false
|
||||
property string text: ""
|
||||
width: 40
|
||||
height: 40
|
||||
property bool isShift: false
|
||||
color: Theme.surface
|
||||
|
||||
property bool isIcon: text === "keyboard_hide" || text === "Backspace" || text === "Enter"
|
||||
|
||||
DankIcon {
|
||||
anchors.centerIn: parent
|
||||
name: {
|
||||
if (parent.text === "keyboard_hide")
|
||||
return "keyboard_hide";
|
||||
if (parent.text === "Backspace")
|
||||
return "backspace";
|
||||
if (parent.text === "Enter")
|
||||
return "keyboard_return";
|
||||
return "";
|
||||
}
|
||||
size: 20
|
||||
color: Theme.surfaceText
|
||||
visible: parent.isIcon
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: contentItem
|
||||
anchors.centerIn: parent
|
||||
text: parent.text
|
||||
color: Theme.surfaceText
|
||||
font.pixelSize: Theme.fontSizeXLarge
|
||||
font.weight: Font.Normal
|
||||
visible: !parent.isIcon
|
||||
}
|
||||
}
|
||||
@@ -1,369 +0,0 @@
|
||||
import QtQuick
|
||||
import qs.Common
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
property Item target
|
||||
height: 60 * 5
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
color: Theme.surfaceContainerHigh
|
||||
|
||||
signal dismissed
|
||||
|
||||
property double rowSpacing: 0.01 * width // horizontal spacing between keyboard
|
||||
property double columnSpacing: 0.02 * height // vertical spacing between keyboard
|
||||
property bool shift: false //Boolean for the shift state
|
||||
property bool symbols: false //Boolean for the symbol state
|
||||
property double columns: 10 // Number of column
|
||||
property double rows: 4 // Number of row
|
||||
|
||||
property string strShift: '\u2191'
|
||||
property string strBackspace: "Backspace"
|
||||
property string strEnter: "Enter"
|
||||
property string strClose: "keyboard_hide"
|
||||
|
||||
property var modelKeyboard: {
|
||||
"row_1": [
|
||||
{
|
||||
"text": 'q',
|
||||
"symbol": '1',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'w',
|
||||
"symbol": '2',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'e',
|
||||
"symbol": '3',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'r',
|
||||
"symbol": '4',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 't',
|
||||
"symbol": '5',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'y',
|
||||
"symbol": '6',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'u',
|
||||
"symbol": '7',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'i',
|
||||
"symbol": '8',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'o',
|
||||
"symbol": '9',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'p',
|
||||
"symbol": '0',
|
||||
"width": 1
|
||||
}
|
||||
],
|
||||
"row_2": [
|
||||
{
|
||||
"text": 'a',
|
||||
"symbol": '-',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 's',
|
||||
"symbol": '/',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'd',
|
||||
"symbol": ':',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'f',
|
||||
"symbol": ';',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'g',
|
||||
"symbol": '(',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'h',
|
||||
"symbol": ')',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'j',
|
||||
"symbol": '€',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'k',
|
||||
"symbol": '&',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'l',
|
||||
"symbol": '@',
|
||||
"width": 1
|
||||
}
|
||||
],
|
||||
"row_3": [
|
||||
{
|
||||
"text": strShift,
|
||||
"symbol": strShift,
|
||||
"width": 1.5
|
||||
},
|
||||
{
|
||||
"text": 'z',
|
||||
"symbol": '.',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'x',
|
||||
"symbol": ',',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'c',
|
||||
"symbol": '?',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'v',
|
||||
"symbol": '!',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'b',
|
||||
"symbol": "'",
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'n',
|
||||
"symbol": "%",
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": 'm',
|
||||
"symbol": '"',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": strBackspace,
|
||||
"symbol": strBackspace,
|
||||
"width": 1.5
|
||||
}
|
||||
],
|
||||
"row_4": [
|
||||
{
|
||||
"text": strClose,
|
||||
"symbol": strClose,
|
||||
"width": 1.5
|
||||
},
|
||||
{
|
||||
"text": "123",
|
||||
"symbol": 'ABC',
|
||||
"width": 1.5
|
||||
},
|
||||
{
|
||||
"text": ' ',
|
||||
"symbol": ' ',
|
||||
"width": 4.5
|
||||
},
|
||||
{
|
||||
"text": '.',
|
||||
"symbol": '.',
|
||||
"width": 1
|
||||
},
|
||||
{
|
||||
"text": strEnter,
|
||||
"symbol": strEnter,
|
||||
"width": 1.5
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
//Here is the corresponding table between the ascii and the key event
|
||||
property var tableKeyEvent: {
|
||||
"_0": Qt.Key_0,
|
||||
"_1": Qt.Key_1,
|
||||
"_2": Qt.Key_2,
|
||||
"_3": Qt.Key_3,
|
||||
"_4": Qt.Key_4,
|
||||
"_5": Qt.Key_5,
|
||||
"_6": Qt.Key_6,
|
||||
"_7": Qt.Key_7,
|
||||
"_8": Qt.Key_8,
|
||||
"_9": Qt.Key_9,
|
||||
"_a": Qt.Key_A,
|
||||
"_b": Qt.Key_B,
|
||||
"_c": Qt.Key_C,
|
||||
"_d": Qt.Key_D,
|
||||
"_e": Qt.Key_E,
|
||||
"_f": Qt.Key_F,
|
||||
"_g": Qt.Key_G,
|
||||
"_h": Qt.Key_H,
|
||||
"_i": Qt.Key_I,
|
||||
"_j": Qt.Key_J,
|
||||
"_k": Qt.Key_K,
|
||||
"_l": Qt.Key_L,
|
||||
"_m": Qt.Key_M,
|
||||
"_n": Qt.Key_N,
|
||||
"_o": Qt.Key_O,
|
||||
"_p": Qt.Key_P,
|
||||
"_q": Qt.Key_Q,
|
||||
"_r": Qt.Key_R,
|
||||
"_s": Qt.Key_S,
|
||||
"_t": Qt.Key_T,
|
||||
"_u": Qt.Key_U,
|
||||
"_v": Qt.Key_V,
|
||||
"_w": Qt.Key_W,
|
||||
"_x": Qt.Key_X,
|
||||
"_y": Qt.Key_Y,
|
||||
"_z": Qt.Key_Z,
|
||||
"_←": Qt.Key_Backspace,
|
||||
"_return": Qt.Key_Return,
|
||||
"_ ": Qt.Key_Space,
|
||||
"_-": Qt.Key_Minus,
|
||||
"_/": Qt.Key_Slash,
|
||||
"_:": Qt.Key_Colon,
|
||||
"_;": Qt.Key_Semicolon,
|
||||
"_(": Qt.Key_BracketLeft,
|
||||
"_)": Qt.Key_BracketRight,
|
||||
"_€": parseInt("20ac", 16) // I didn't find the appropriate Qt event so I used the hex format
|
||||
,
|
||||
"_&": Qt.Key_Ampersand,
|
||||
"_@": Qt.Key_At,
|
||||
'_"': Qt.Key_QuoteDbl,
|
||||
"_.": Qt.Key_Period,
|
||||
"_,": Qt.Key_Comma,
|
||||
"_?": Qt.Key_Question,
|
||||
"_!": Qt.Key_Exclam,
|
||||
"_'": Qt.Key_Apostrophe,
|
||||
"_%": Qt.Key_Percent,
|
||||
"_*": Qt.Key_Asterisk
|
||||
}
|
||||
|
||||
Item {
|
||||
id: keyboard_container
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 5
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 5
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 5
|
||||
|
||||
//One column which contains 5 rows
|
||||
Column {
|
||||
spacing: columnSpacing
|
||||
|
||||
Row {
|
||||
id: row_1
|
||||
spacing: rowSpacing
|
||||
Repeater {
|
||||
model: modelKeyboard["row_1"]
|
||||
delegate: CustomButtonKeyboard {
|
||||
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase() : modelData.text
|
||||
width: modelData.width * keyboard_container.width / columns - rowSpacing
|
||||
height: keyboard_container.height / rows - columnSpacing
|
||||
|
||||
onClicked: root.clicked(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
Row {
|
||||
id: row_2
|
||||
spacing: rowSpacing
|
||||
Repeater {
|
||||
model: modelKeyboard["row_2"]
|
||||
delegate: CustomButtonKeyboard {
|
||||
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase() : modelData.text
|
||||
width: modelData.width * keyboard_container.width / columns - rowSpacing
|
||||
height: keyboard_container.height / rows - columnSpacing
|
||||
|
||||
onClicked: root.clicked(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
Row {
|
||||
id: row_3
|
||||
spacing: rowSpacing
|
||||
Repeater {
|
||||
model: modelKeyboard["row_3"]
|
||||
delegate: CustomButtonKeyboard {
|
||||
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase() : modelData.text
|
||||
width: modelData.width * keyboard_container.width / columns - rowSpacing
|
||||
height: keyboard_container.height / rows - columnSpacing
|
||||
isShift: shift && text === strShift
|
||||
|
||||
onClicked: root.clicked(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
Row {
|
||||
id: row_4
|
||||
spacing: rowSpacing
|
||||
Repeater {
|
||||
model: modelKeyboard["row_4"]
|
||||
delegate: CustomButtonKeyboard {
|
||||
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase() : modelData.text
|
||||
width: modelData.width * keyboard_container.width / columns - rowSpacing
|
||||
height: keyboard_container.height / rows - columnSpacing
|
||||
|
||||
onClicked: root.clicked(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
signal clicked(string text)
|
||||
|
||||
Connections {
|
||||
target: root
|
||||
function onClicked(text) {
|
||||
if (!keyboard_controller.target)
|
||||
return;
|
||||
if (text === strShift) {
|
||||
root.shift = !root.shift;
|
||||
} else if (text === '123') {
|
||||
root.symbols = true;
|
||||
} else if (text === 'ABC') {
|
||||
root.symbols = false;
|
||||
} else if (text === strEnter) {
|
||||
if (keyboard_controller.target.accepted) {
|
||||
keyboard_controller.target.accepted();
|
||||
}
|
||||
} else if (text === strClose) {
|
||||
root.dismissed();
|
||||
} else {
|
||||
if (text === strBackspace) {
|
||||
keyboard_controller.target.backspace();
|
||||
} else {
|
||||
var charToInsert = root.symbols ? text : (root.shift ? text.toUpperCase() : text);
|
||||
keyboard_controller.target.insertText(charToInsert);
|
||||
}
|
||||
|
||||
if (root.shift && text !== strShift)
|
||||
root.shift = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import qs.Services
|
||||
|
||||
Item {
|
||||
id: keyboard_controller
|
||||
readonly property var log: Log.scoped("KeyboardController")
|
||||
|
||||
// reference on the TextInput
|
||||
property Item target
|
||||
//Booléan on the state of the keyboard
|
||||
property bool isKeyboardActive: false
|
||||
|
||||
property var rootObject
|
||||
|
||||
function show() {
|
||||
if (!isKeyboardActive && keyboard === null) {
|
||||
keyboard = keyboardComponent.createObject(keyboard_controller.rootObject);
|
||||
keyboard.target = keyboard_controller.target;
|
||||
keyboard.dismissed.connect(hide);
|
||||
isKeyboardActive = true;
|
||||
} else
|
||||
log.debug("The keyboard is already shown");
|
||||
}
|
||||
|
||||
function hide() {
|
||||
if (isKeyboardActive && keyboard !== null) {
|
||||
keyboard.destroy();
|
||||
isKeyboardActive = false;
|
||||
} else
|
||||
log.debug("The keyboard is already hidden");
|
||||
}
|
||||
|
||||
// private
|
||||
property Item keyboard: null
|
||||
Component {
|
||||
id: keyboardComponent
|
||||
Keyboard {}
|
||||
}
|
||||
}
|
||||
@@ -1,827 +0,0 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import Quickshell.Widgets
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
|
||||
property bool isVisible: false
|
||||
property bool showLogout: true
|
||||
property int selectedIndex: 0
|
||||
property int selectedRow: 0
|
||||
property int selectedCol: 0
|
||||
property var visibleActions: []
|
||||
property int gridColumns: 3
|
||||
property int gridRows: 2
|
||||
property bool useGridLayout: false
|
||||
|
||||
property string holdAction: ""
|
||||
property int holdActionIndex: -1
|
||||
property real holdProgress: 0
|
||||
property bool showHoldHint: false
|
||||
|
||||
property var powerActionConfirmOverride: undefined
|
||||
property var powerActionHoldDurationOverride: undefined
|
||||
property var powerMenuActionsOverride: undefined
|
||||
property var powerMenuDefaultActionOverride: undefined
|
||||
property var powerMenuGridLayoutOverride: undefined
|
||||
property var requiredActions: []
|
||||
|
||||
readonly property bool needsConfirmation: powerActionConfirmOverride !== undefined ? powerActionConfirmOverride : SettingsData.powerActionConfirm
|
||||
readonly property int holdDurationMs: (powerActionHoldDurationOverride !== undefined ? powerActionHoldDurationOverride : SettingsData.powerActionHoldDuration) * 1000
|
||||
|
||||
signal closed
|
||||
|
||||
signal switchUserRequested
|
||||
|
||||
function updateVisibleActions() {
|
||||
const allActions = powerMenuActionsOverride !== undefined ? powerMenuActionsOverride : ((typeof SettingsData !== "undefined" && SettingsData.powerMenuActions) ? SettingsData.powerMenuActions : ["logout", "suspend", "hibernate", "reboot", "poweroff"]);
|
||||
const hibernateSupported = (typeof SessionService !== "undefined" && SessionService.hibernateSupported) || false;
|
||||
let filtered = allActions.filter(action => {
|
||||
if (action === "hibernate" && !hibernateSupported)
|
||||
return false;
|
||||
if (action === "lock")
|
||||
return false;
|
||||
if (action === "restart")
|
||||
return false;
|
||||
if (action === "logout" && !showLogout)
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
for (const action of requiredActions) {
|
||||
if (!filtered.includes(action))
|
||||
filtered.push(action);
|
||||
}
|
||||
|
||||
visibleActions = filtered;
|
||||
|
||||
useGridLayout = powerMenuGridLayoutOverride !== undefined ? powerMenuGridLayoutOverride : ((typeof SettingsData !== "undefined" && SettingsData.powerMenuGridLayout !== undefined) ? SettingsData.powerMenuGridLayout : false);
|
||||
if (!useGridLayout)
|
||||
return;
|
||||
const count = visibleActions.length;
|
||||
if (count === 0) {
|
||||
gridColumns = 1;
|
||||
gridRows = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (count <= 3) {
|
||||
gridColumns = 1;
|
||||
gridRows = count;
|
||||
return;
|
||||
}
|
||||
|
||||
if (count === 4) {
|
||||
gridColumns = 2;
|
||||
gridRows = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
gridColumns = 3;
|
||||
gridRows = Math.ceil(count / 3);
|
||||
}
|
||||
|
||||
function getDefaultActionIndex() {
|
||||
const defaultAction = powerMenuDefaultActionOverride !== undefined ? powerMenuDefaultActionOverride : ((typeof SettingsData !== "undefined" && SettingsData.powerMenuDefaultAction) ? SettingsData.powerMenuDefaultAction : "suspend");
|
||||
const index = visibleActions.indexOf(defaultAction);
|
||||
return index >= 0 ? index : 0;
|
||||
}
|
||||
|
||||
function getActionAtIndex(index) {
|
||||
if (index < 0 || index >= visibleActions.length)
|
||||
return "";
|
||||
return visibleActions[index];
|
||||
}
|
||||
|
||||
function getActionData(action) {
|
||||
switch (action) {
|
||||
case "reboot":
|
||||
return {
|
||||
"icon": "restart_alt",
|
||||
"label": I18n.tr("Reboot"),
|
||||
"key": "R"
|
||||
};
|
||||
case "logout":
|
||||
return {
|
||||
"icon": "logout",
|
||||
"label": I18n.tr("Log Out"),
|
||||
"key": "X"
|
||||
};
|
||||
case "poweroff":
|
||||
return {
|
||||
"icon": "power_settings_new",
|
||||
"label": I18n.tr("Power Off"),
|
||||
"key": "P"
|
||||
};
|
||||
case "suspend":
|
||||
return {
|
||||
"icon": "bedtime",
|
||||
"label": I18n.tr("Suspend"),
|
||||
"key": "S"
|
||||
};
|
||||
case "hibernate":
|
||||
return {
|
||||
"icon": "ac_unit",
|
||||
"label": I18n.tr("Hibernate"),
|
||||
"key": "H"
|
||||
};
|
||||
case "switchuser":
|
||||
return {
|
||||
"icon": "switch_account",
|
||||
"label": I18n.tr("Switch User"),
|
||||
"key": "U"
|
||||
};
|
||||
default:
|
||||
return {
|
||||
"icon": "help",
|
||||
"label": action,
|
||||
"key": "?"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function actionNeedsConfirm(action) {
|
||||
return action !== "lock" && action !== "restart";
|
||||
}
|
||||
|
||||
function startHold(action, actionIndex) {
|
||||
if (!needsConfirmation || !actionNeedsConfirm(action)) {
|
||||
executeAction(action);
|
||||
return;
|
||||
}
|
||||
holdAction = action;
|
||||
holdActionIndex = actionIndex;
|
||||
holdProgress = 0;
|
||||
showHoldHint = false;
|
||||
holdTimer.start();
|
||||
}
|
||||
|
||||
function cancelHold() {
|
||||
if (holdAction === "")
|
||||
return;
|
||||
const wasHolding = holdProgress > 0;
|
||||
holdTimer.stop();
|
||||
if (wasHolding && holdProgress < 1) {
|
||||
showHoldHint = true;
|
||||
hintTimer.restart();
|
||||
}
|
||||
holdAction = "";
|
||||
holdActionIndex = -1;
|
||||
holdProgress = 0;
|
||||
}
|
||||
|
||||
function completeHold() {
|
||||
if (holdProgress < 1) {
|
||||
cancelHold();
|
||||
return;
|
||||
}
|
||||
const action = holdAction;
|
||||
holdTimer.stop();
|
||||
holdAction = "";
|
||||
holdActionIndex = -1;
|
||||
holdProgress = 0;
|
||||
executeAction(action);
|
||||
}
|
||||
|
||||
function executeAction(action) {
|
||||
if (!action)
|
||||
return;
|
||||
if (action === "switchuser") {
|
||||
hide();
|
||||
switchUserRequested();
|
||||
return;
|
||||
}
|
||||
if (typeof SessionService === "undefined")
|
||||
return;
|
||||
hide();
|
||||
switch (action) {
|
||||
case "logout":
|
||||
SessionService.logout();
|
||||
break;
|
||||
case "suspend":
|
||||
SessionService.suspend();
|
||||
break;
|
||||
case "hibernate":
|
||||
SessionService.hibernate();
|
||||
break;
|
||||
case "reboot":
|
||||
SessionService.reboot();
|
||||
break;
|
||||
case "poweroff":
|
||||
SessionService.poweroff();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function selectOption(action, actionIndex) {
|
||||
startHold(action, actionIndex !== undefined ? actionIndex : -1);
|
||||
}
|
||||
|
||||
function show() {
|
||||
holdAction = "";
|
||||
holdActionIndex = -1;
|
||||
holdProgress = 0;
|
||||
showHoldHint = false;
|
||||
updateVisibleActions();
|
||||
const defaultIndex = getDefaultActionIndex();
|
||||
if (useGridLayout) {
|
||||
selectedRow = Math.floor(defaultIndex / gridColumns);
|
||||
selectedCol = defaultIndex % gridColumns;
|
||||
selectedIndex = defaultIndex;
|
||||
} else {
|
||||
selectedIndex = defaultIndex;
|
||||
}
|
||||
isVisible = true;
|
||||
Qt.callLater(() => powerMenuFocusScope.forceActiveFocus());
|
||||
}
|
||||
|
||||
function hide() {
|
||||
cancelHold();
|
||||
isVisible = false;
|
||||
closed();
|
||||
}
|
||||
|
||||
function handleListNavigation(event, 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_S || event.key === Qt.Key_H || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
||||
cancelHold();
|
||||
event.accepted = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.key) {
|
||||
case Qt.Key_Up:
|
||||
case Qt.Key_Backtab:
|
||||
selectedIndex = (selectedIndex - 1 + visibleActions.length) % visibleActions.length;
|
||||
event.accepted = true;
|
||||
break;
|
||||
case Qt.Key_Down:
|
||||
case Qt.Key_Tab:
|
||||
selectedIndex = (selectedIndex + 1) % visibleActions.length;
|
||||
event.accepted = true;
|
||||
break;
|
||||
case Qt.Key_Return:
|
||||
case Qt.Key_Enter:
|
||||
startHold(getActionAtIndex(selectedIndex), selectedIndex);
|
||||
event.accepted = true;
|
||||
break;
|
||||
case Qt.Key_N:
|
||||
if (event.modifiers & Qt.ControlModifier) {
|
||||
selectedIndex = (selectedIndex + 1) % visibleActions.length;
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_P:
|
||||
if (!(event.modifiers & Qt.ControlModifier)) {
|
||||
if (visibleActions.includes("poweroff")) {
|
||||
const idx = visibleActions.indexOf("poweroff");
|
||||
startHold("poweroff", idx);
|
||||
event.accepted = true;
|
||||
}
|
||||
} else {
|
||||
selectedIndex = (selectedIndex - 1 + visibleActions.length) % visibleActions.length;
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_J:
|
||||
if (event.modifiers & Qt.ControlModifier) {
|
||||
selectedIndex = (selectedIndex + 1) % visibleActions.length;
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_K:
|
||||
if (event.modifiers & Qt.ControlModifier) {
|
||||
selectedIndex = (selectedIndex - 1 + visibleActions.length) % visibleActions.length;
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_R:
|
||||
if (visibleActions.includes("reboot")) {
|
||||
startHold("reboot", visibleActions.indexOf("reboot"));
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_X:
|
||||
if (visibleActions.includes("logout")) {
|
||||
startHold("logout", visibleActions.indexOf("logout"));
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_S:
|
||||
if (visibleActions.includes("suspend")) {
|
||||
startHold("suspend", visibleActions.indexOf("suspend"));
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_H:
|
||||
if (visibleActions.includes("hibernate")) {
|
||||
startHold("hibernate", visibleActions.indexOf("hibernate"));
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function handleGridNavigation(event, 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_S || event.key === Qt.Key_H || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
||||
cancelHold();
|
||||
event.accepted = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.key) {
|
||||
case Qt.Key_Left:
|
||||
selectedCol = (selectedCol - 1 + gridColumns) % gridColumns;
|
||||
selectedIndex = selectedRow * gridColumns + selectedCol;
|
||||
event.accepted = true;
|
||||
break;
|
||||
case Qt.Key_Right:
|
||||
selectedCol = (selectedCol + 1) % gridColumns;
|
||||
selectedIndex = selectedRow * gridColumns + selectedCol;
|
||||
event.accepted = true;
|
||||
break;
|
||||
case Qt.Key_Up:
|
||||
case Qt.Key_Backtab:
|
||||
selectedRow = (selectedRow - 1 + gridRows) % gridRows;
|
||||
selectedIndex = selectedRow * gridColumns + selectedCol;
|
||||
event.accepted = true;
|
||||
break;
|
||||
case Qt.Key_Down:
|
||||
case Qt.Key_Tab:
|
||||
selectedRow = (selectedRow + 1) % gridRows;
|
||||
selectedIndex = selectedRow * gridColumns + selectedCol;
|
||||
event.accepted = true;
|
||||
break;
|
||||
case Qt.Key_Return:
|
||||
case Qt.Key_Enter:
|
||||
startHold(getActionAtIndex(selectedIndex), selectedIndex);
|
||||
event.accepted = true;
|
||||
break;
|
||||
case Qt.Key_N:
|
||||
if (event.modifiers & Qt.ControlModifier) {
|
||||
selectedCol = (selectedCol + 1) % gridColumns;
|
||||
selectedIndex = selectedRow * gridColumns + selectedCol;
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_P:
|
||||
if (!(event.modifiers & Qt.ControlModifier)) {
|
||||
if (visibleActions.includes("poweroff")) {
|
||||
const idx = visibleActions.indexOf("poweroff");
|
||||
startHold("poweroff", idx);
|
||||
event.accepted = true;
|
||||
}
|
||||
} else {
|
||||
selectedCol = (selectedCol - 1 + gridColumns) % gridColumns;
|
||||
selectedIndex = selectedRow * gridColumns + selectedCol;
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_J:
|
||||
if (event.modifiers & Qt.ControlModifier) {
|
||||
selectedRow = (selectedRow + 1) % gridRows;
|
||||
selectedIndex = selectedRow * gridColumns + selectedCol;
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_K:
|
||||
if (event.modifiers & Qt.ControlModifier) {
|
||||
selectedRow = (selectedRow - 1 + gridRows) % gridRows;
|
||||
selectedIndex = selectedRow * gridColumns + selectedCol;
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_R:
|
||||
if (visibleActions.includes("reboot")) {
|
||||
startHold("reboot", visibleActions.indexOf("reboot"));
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_X:
|
||||
if (visibleActions.includes("logout")) {
|
||||
startHold("logout", visibleActions.indexOf("logout"));
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_S:
|
||||
if (visibleActions.includes("suspend")) {
|
||||
startHold("suspend", visibleActions.indexOf("suspend"));
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
case Qt.Key_H:
|
||||
if (visibleActions.includes("hibernate")) {
|
||||
startHold("hibernate", visibleActions.indexOf("hibernate"));
|
||||
event.accepted = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
anchors.fill: parent
|
||||
color: Qt.rgba(0, 0, 0, 0.5)
|
||||
visible: isVisible
|
||||
z: 1000
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: root.hide()
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: holdTimer
|
||||
interval: 16
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
root.holdProgress = Math.min(1, root.holdProgress + (interval / root.holdDurationMs));
|
||||
if (root.holdProgress >= 1) {
|
||||
stop();
|
||||
root.completeHold();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: hintTimer
|
||||
interval: 2000
|
||||
onTriggered: root.showHoldHint = false
|
||||
}
|
||||
|
||||
FocusScope {
|
||||
id: powerMenuFocusScope
|
||||
anchors.fill: parent
|
||||
focus: root.isVisible
|
||||
|
||||
onVisibleChanged: {
|
||||
if (visible)
|
||||
Qt.callLater(() => forceActiveFocus());
|
||||
}
|
||||
|
||||
Keys.onEscapePressed: root.hide()
|
||||
Keys.onPressed: event => {
|
||||
if (event.isAutoRepeat) {
|
||||
event.accepted = true;
|
||||
return;
|
||||
}
|
||||
if (useGridLayout) {
|
||||
handleGridNavigation(event, true);
|
||||
} else {
|
||||
handleListNavigation(event, true);
|
||||
}
|
||||
}
|
||||
Keys.onReleased: event => {
|
||||
if (event.isAutoRepeat) {
|
||||
event.accepted = true;
|
||||
return;
|
||||
}
|
||||
if (useGridLayout) {
|
||||
handleGridNavigation(event, false);
|
||||
} else {
|
||||
handleListNavigation(event, false);
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.centerIn: parent
|
||||
width: useGridLayout ? Math.min(550, gridColumns * 180 + Theme.spacingS * (gridColumns - 1) + Theme.spacingL * 2) : 320
|
||||
height: contentItem.implicitHeight + Theme.spacingL * 2
|
||||
radius: Theme.cornerRadius
|
||||
color: Theme.surfaceContainer
|
||||
border.color: Theme.outlineMedium
|
||||
border.width: 1
|
||||
|
||||
Item {
|
||||
id: contentItem
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingL
|
||||
implicitHeight: headerRow.height + Theme.spacingM + (useGridLayout ? buttonGrid.implicitHeight : buttonColumn.implicitHeight) + (root.needsConfirmation ? hintRow.height + Theme.spacingM : 0)
|
||||
|
||||
Row {
|
||||
id: headerRow
|
||||
width: parent.width
|
||||
height: 30
|
||||
|
||||
StyledText {
|
||||
text: I18n.tr("Power Options")
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
color: Theme.surfaceText
|
||||
font.weight: Font.Medium
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
Item {
|
||||
width: parent.width - 150
|
||||
height: 1
|
||||
}
|
||||
|
||||
DankActionButton {
|
||||
iconName: "close"
|
||||
iconSize: Theme.iconSize - 4
|
||||
iconColor: Theme.surfaceText
|
||||
onClicked: root.hide()
|
||||
}
|
||||
}
|
||||
|
||||
Grid {
|
||||
id: buttonGrid
|
||||
visible: useGridLayout
|
||||
anchors.top: headerRow.bottom
|
||||
anchors.topMargin: Theme.spacingM
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
columns: root.gridColumns
|
||||
columnSpacing: Theme.spacingS
|
||||
rowSpacing: Theme.spacingS
|
||||
width: parent.width
|
||||
|
||||
Repeater {
|
||||
model: root.visibleActions
|
||||
|
||||
Rectangle {
|
||||
id: gridButtonRect
|
||||
required property int index
|
||||
required property string modelData
|
||||
|
||||
readonly property var actionData: root.getActionData(modelData)
|
||||
readonly property bool isSelected: root.selectedIndex === index
|
||||
readonly property bool showWarning: modelData === "reboot" || modelData === "poweroff"
|
||||
readonly property bool isHolding: root.holdActionIndex === index && root.holdProgress > 0
|
||||
|
||||
width: (contentItem.width - Theme.spacingS * (root.gridColumns - 1)) / root.gridColumns
|
||||
height: 100
|
||||
radius: Theme.cornerRadius
|
||||
color: {
|
||||
if (isSelected)
|
||||
return Theme.primaryHover;
|
||||
if (mouseArea.containsMouse)
|
||||
return Theme.primaryHoverLight;
|
||||
return Theme.surfaceHover;
|
||||
}
|
||||
border.color: isSelected ? Theme.primary : Theme.withAlpha(Theme.primary, 0)
|
||||
border.width: isSelected ? 2 : 0
|
||||
|
||||
ClippingRectangle {
|
||||
anchors.fill: parent
|
||||
radius: parent.radius
|
||||
color: "transparent"
|
||||
visible: gridButtonRect.isHolding
|
||||
|
||||
Rectangle {
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
width: parent.width * root.holdProgress
|
||||
color: {
|
||||
if (gridButtonRect.modelData === "poweroff")
|
||||
return Theme.errorSelected;
|
||||
if (gridButtonRect.modelData === "reboot")
|
||||
return Theme.withAlpha(Theme.warning, 0.3);
|
||||
return Theme.primarySelected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: Theme.spacingS
|
||||
|
||||
DankIcon {
|
||||
name: gridButtonRect.actionData.icon
|
||||
size: Theme.iconSize + 8
|
||||
color: {
|
||||
if (gridButtonRect.showWarning && (mouseArea.containsMouse || gridButtonRect.isHolding)) {
|
||||
return gridButtonRect.modelData === "poweroff" ? Theme.error : Theme.warning;
|
||||
}
|
||||
return Theme.surfaceText;
|
||||
}
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: gridButtonRect.actionData.label
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: {
|
||||
if (gridButtonRect.showWarning && (mouseArea.containsMouse || gridButtonRect.isHolding)) {
|
||||
return gridButtonRect.modelData === "poweroff" ? Theme.error : Theme.warning;
|
||||
}
|
||||
return Theme.surfaceText;
|
||||
}
|
||||
font.weight: Font.Medium
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: 20
|
||||
height: 16
|
||||
radius: 4
|
||||
color: Theme.onSurface_12
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
StyledText {
|
||||
text: gridButtonRect.actionData.key
|
||||
font.pixelSize: Theme.fontSizeSmall - 1
|
||||
color: Theme.surfaceTextSecondary
|
||||
font.weight: Font.Medium
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onPressed: {
|
||||
root.selectedRow = Math.floor(index / root.gridColumns);
|
||||
root.selectedCol = index % root.gridColumns;
|
||||
root.selectedIndex = index;
|
||||
root.startHold(modelData, index);
|
||||
}
|
||||
onReleased: root.cancelHold()
|
||||
onCanceled: root.cancelHold()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: buttonColumn
|
||||
visible: !useGridLayout
|
||||
anchors.top: headerRow.bottom
|
||||
anchors.topMargin: Theme.spacingM
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
spacing: Theme.spacingS
|
||||
|
||||
Repeater {
|
||||
model: root.visibleActions
|
||||
|
||||
Rectangle {
|
||||
id: listButtonRect
|
||||
required property int index
|
||||
required property string modelData
|
||||
|
||||
readonly property var actionData: root.getActionData(modelData)
|
||||
readonly property bool isSelected: root.selectedIndex === index
|
||||
readonly property bool showWarning: modelData === "reboot" || modelData === "poweroff"
|
||||
readonly property bool isHolding: root.holdActionIndex === index && root.holdProgress > 0
|
||||
|
||||
width: parent.width
|
||||
height: 50
|
||||
radius: Theme.cornerRadius
|
||||
color: {
|
||||
if (isSelected)
|
||||
return Theme.primaryHover;
|
||||
if (listMouseArea.containsMouse)
|
||||
return Theme.primaryHoverLight;
|
||||
return Theme.surfaceHover;
|
||||
}
|
||||
border.color: isSelected ? Theme.primary : Theme.withAlpha(Theme.primary, 0)
|
||||
border.width: isSelected ? 2 : 0
|
||||
|
||||
ClippingRectangle {
|
||||
anchors.fill: parent
|
||||
radius: parent.radius
|
||||
color: "transparent"
|
||||
visible: listButtonRect.isHolding
|
||||
|
||||
Rectangle {
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
width: parent.width * root.holdProgress
|
||||
color: {
|
||||
if (listButtonRect.modelData === "poweroff")
|
||||
return Theme.errorSelected;
|
||||
if (listButtonRect.modelData === "reboot")
|
||||
return Theme.withAlpha(Theme.warning, 0.3);
|
||||
return Theme.primarySelected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.leftMargin: Theme.spacingM
|
||||
anchors.rightMargin: Theme.spacingM
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: Theme.spacingM
|
||||
|
||||
DankIcon {
|
||||
name: listButtonRect.actionData.icon
|
||||
size: Theme.iconSize + 4
|
||||
color: {
|
||||
if (listButtonRect.showWarning && (listMouseArea.containsMouse || listButtonRect.isHolding)) {
|
||||
return listButtonRect.modelData === "poweroff" ? Theme.error : Theme.warning;
|
||||
}
|
||||
return Theme.surfaceText;
|
||||
}
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: listButtonRect.actionData.label
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: {
|
||||
if (listButtonRect.showWarning && (listMouseArea.containsMouse || listButtonRect.isHolding)) {
|
||||
return listButtonRect.modelData === "poweroff" ? Theme.error : Theme.warning;
|
||||
}
|
||||
return Theme.surfaceText;
|
||||
}
|
||||
font.weight: Font.Medium
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: 28
|
||||
height: 20
|
||||
radius: 4
|
||||
color: Theme.onSurface_12
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Theme.spacingM
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
StyledText {
|
||||
text: listButtonRect.actionData.key
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceTextSecondary
|
||||
font.weight: Font.Medium
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: listMouseArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onPressed: {
|
||||
root.selectedIndex = index;
|
||||
root.startHold(modelData, index);
|
||||
}
|
||||
onReleased: root.cancelHold()
|
||||
onCanceled: root.cancelHold()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: hintRow
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: Theme.spacingS
|
||||
spacing: Theme.spacingXS
|
||||
visible: root.needsConfirmation
|
||||
opacity: root.showHoldHint ? 1 : 0.5
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: 150
|
||||
}
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
name: root.showHoldHint ? "warning" : "touch_app"
|
||||
size: Theme.fontSizeSmall
|
||||
color: root.showHoldHint ? Theme.warning : Theme.surfaceTextSecondary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
StyledText {
|
||||
readonly property real totalMs: root.holdDurationMs
|
||||
readonly property int remainingMs: Math.ceil(totalMs * (1 - root.holdProgress))
|
||||
readonly property real durationSec: root.holdDurationMs / 1000
|
||||
text: {
|
||||
if (root.showHoldHint)
|
||||
return I18n.tr("Hold longer to confirm");
|
||||
if (root.holdProgress > 0) {
|
||||
if (totalMs < 1000)
|
||||
return I18n.tr("Hold to confirm (%1 ms)").arg(remainingMs);
|
||||
return I18n.tr("Hold to confirm (%1s)").arg(Math.ceil(remainingMs / 1000));
|
||||
}
|
||||
if (totalMs < 1000)
|
||||
return I18n.tr("Hold to confirm (%1 ms)").arg(totalMs);
|
||||
return I18n.tr("Hold to confirm (%1s)").arg(durationSec);
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: root.showHoldHint ? Theme.warning : Theme.surfaceTextSecondary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: updateVisibleActions()
|
||||
}
|
||||
@@ -12,7 +12,8 @@ import qs.Common
|
||||
import qs.Modals
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
import "../../Common/LayoutCodes.js" as LayoutCodes
|
||||
import qs.DankCommon.Session
|
||||
import "../../DankCommon/Common/LayoutCodes.js" as LayoutCodes
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
Reference in New Issue
Block a user