1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00

escape key handling

This commit is contained in:
bbedward
2025-08-05 09:15:27 -04:00
parent ef9e80bfdf
commit fccaf06baa
11 changed files with 191 additions and 19 deletions

View File

@@ -334,6 +334,13 @@ DankModal {
anchors.fill: parent
anchors.margins: Theme.spacingL
spacing: Theme.spacingL
focus: true
Keys.onPressed: function(event) {
if (event.key === Qt.Key_Escape) {
hide();
event.accepted = true;
}
}
Item {
width: parent.width

View File

@@ -185,15 +185,28 @@ PanelWindow {
FocusScope {
id: focusScope
objectName: "modalFocusScope"
anchors.fill: parent
visible: root.visible // Only active when the modal is visible
focus: root.visible
Keys.onEscapePressed: (event) => {
if (root.closeOnEscapeKey) {
root.visible = false;
event.accepted = true;
}
}
onVisibleChanged: {
if (visible) {
Qt.callLater(function() {
focusScope.forceActiveFocus();
});
}
}
}
// Expose the focusScope for external access
property alias modalFocusScope: focusScope
}

View File

@@ -15,10 +15,14 @@ DankModal {
signal closingModal()
onVisibleChanged: {
if (!visible)
if (!visible) {
if (settingsVisible) {
settingsVisible = false;
}
closingModal();
}
}
visible: settingsVisible
width: 750
height: 750
@@ -27,12 +31,6 @@ DankModal {
settingsVisible = false;
}
FocusScope {
anchors.fill: parent
focus: settingsModal.settingsVisible
Keys.onEscapePressed: settingsModal.settingsVisible = false
}
content: Component {
Column {
anchors.fill: parent

View File

@@ -194,12 +194,12 @@ DankModal {
}
Connections {
function onOpened() {
searchField.forceActiveFocus();
}
function onDialogClosed() {
searchField.clearFocus();
function onSpotlightOpenChanged() {
if (spotlightModal.spotlightOpen) {
Qt.callLater(function() {
searchField.forceActiveFocus();
});
}
}
target: spotlightModal