mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-05 21:15:38 -05:00
notif: fix keyboard navi in popout
This commit is contained in:
@@ -1,9 +1,4 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Effects
|
|
||||||
import Quickshell
|
|
||||||
import Quickshell.Wayland
|
|
||||||
import Quickshell.Widgets
|
|
||||||
import qs.Common
|
import qs.Common
|
||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
@@ -22,8 +17,8 @@ DankPopout {
|
|||||||
listView: null
|
listView: null
|
||||||
isOpen: notificationHistoryVisible
|
isOpen: notificationHistoryVisible
|
||||||
onClose: () => {
|
onClose: () => {
|
||||||
notificationHistoryVisible = false
|
notificationHistoryVisible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
popupWidth: 400
|
popupWidth: 400
|
||||||
@@ -33,61 +28,72 @@ DankPopout {
|
|||||||
shouldBeVisible: notificationHistoryVisible
|
shouldBeVisible: notificationHistoryVisible
|
||||||
|
|
||||||
function toggle() {
|
function toggle() {
|
||||||
notificationHistoryVisible = !notificationHistoryVisible
|
notificationHistoryVisible = !notificationHistoryVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
onBackgroundClicked: {
|
onBackgroundClicked: {
|
||||||
notificationHistoryVisible = false
|
notificationHistoryVisible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onNotificationHistoryVisibleChanged: {
|
onNotificationHistoryVisibleChanged: {
|
||||||
if (notificationHistoryVisible) {
|
if (notificationHistoryVisible) {
|
||||||
open()
|
open();
|
||||||
} else {
|
} else {
|
||||||
close()
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupKeyboardNavigation() {
|
||||||
|
if (!contentLoader.item)
|
||||||
|
return;
|
||||||
|
contentLoader.item.externalKeyboardController = keyboardController;
|
||||||
|
|
||||||
|
const notificationList = findChild(contentLoader.item, "notificationList");
|
||||||
|
const notificationHeader = findChild(contentLoader.item, "notificationHeader");
|
||||||
|
|
||||||
|
if (notificationList) {
|
||||||
|
keyboardController.listView = notificationList;
|
||||||
|
notificationList.keyboardController = keyboardController;
|
||||||
|
}
|
||||||
|
if (notificationHeader) {
|
||||||
|
notificationHeader.keyboardController = keyboardController;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboardController.reset();
|
||||||
|
keyboardController.rebuildFlatNavigation();
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: contentLoader
|
||||||
|
function onLoaded() {
|
||||||
|
if (root.shouldBeVisible)
|
||||||
|
Qt.callLater(root.setupKeyboardNavigation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onShouldBeVisibleChanged: {
|
onShouldBeVisibleChanged: {
|
||||||
if (shouldBeVisible) {
|
if (shouldBeVisible) {
|
||||||
NotificationService.onOverlayOpen()
|
NotificationService.onOverlayOpen();
|
||||||
Qt.callLater(() => {
|
if (contentLoader.item)
|
||||||
if (contentLoader.item) {
|
Qt.callLater(setupKeyboardNavigation);
|
||||||
contentLoader.item.externalKeyboardController = keyboardController
|
|
||||||
|
|
||||||
const notificationList = findChild(contentLoader.item, "notificationList")
|
|
||||||
const notificationHeader = findChild(contentLoader.item, "notificationHeader")
|
|
||||||
|
|
||||||
if (notificationList) {
|
|
||||||
keyboardController.listView = notificationList
|
|
||||||
notificationList.keyboardController = keyboardController
|
|
||||||
}
|
|
||||||
if (notificationHeader) {
|
|
||||||
notificationHeader.keyboardController = keyboardController
|
|
||||||
}
|
|
||||||
|
|
||||||
keyboardController.reset()
|
|
||||||
keyboardController.rebuildFlatNavigation()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
NotificationService.onOverlayClose()
|
NotificationService.onOverlayClose();
|
||||||
keyboardController.keyboardNavigationActive = false
|
keyboardController.keyboardNavigationActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function findChild(parent, objectName) {
|
function findChild(parent, objectName) {
|
||||||
if (parent.objectName === objectName) {
|
if (parent.objectName === objectName) {
|
||||||
return parent
|
return parent;
|
||||||
}
|
}
|
||||||
for (let i = 0; i < parent.children.length; i++) {
|
for (let i = 0; i < parent.children.length; i++) {
|
||||||
const child = parent.children[i]
|
const child = parent.children[i];
|
||||||
const result = findChild(child, objectName)
|
const result = findChild(child, objectName);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
content: Component {
|
content: Component {
|
||||||
@@ -98,24 +104,24 @@ DankPopout {
|
|||||||
property real cachedHeaderHeight: 32
|
property real cachedHeaderHeight: 32
|
||||||
|
|
||||||
implicitHeight: {
|
implicitHeight: {
|
||||||
let baseHeight = Theme.spacingL * 2
|
let baseHeight = Theme.spacingL * 2;
|
||||||
baseHeight += cachedHeaderHeight
|
baseHeight += cachedHeaderHeight;
|
||||||
baseHeight += Theme.spacingM * 2
|
baseHeight += Theme.spacingM * 2;
|
||||||
|
|
||||||
const settingsHeight = notificationSettings.expanded ? notificationSettings.contentHeight : 0
|
const settingsHeight = notificationSettings.expanded ? notificationSettings.contentHeight : 0;
|
||||||
let listHeight = notificationList.listContentHeight
|
let listHeight = notificationList.listContentHeight;
|
||||||
if (NotificationService.groupedNotifications.length === 0) {
|
if (NotificationService.groupedNotifications.length === 0) {
|
||||||
listHeight = 200
|
listHeight = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxContentArea = 600
|
const maxContentArea = 600;
|
||||||
const availableListSpace = Math.max(200, maxContentArea - settingsHeight)
|
const availableListSpace = Math.max(200, maxContentArea - settingsHeight);
|
||||||
|
|
||||||
baseHeight += settingsHeight
|
baseHeight += settingsHeight;
|
||||||
baseHeight += Math.min(listHeight, availableListSpace)
|
baseHeight += Math.min(listHeight, availableListSpace);
|
||||||
|
|
||||||
const maxHeight = root.screen ? root.screen.height * 0.8 : Screen.height * 0.8
|
const maxHeight = root.screen ? root.screen.height * 0.8 : Screen.height * 0.8;
|
||||||
return Math.max(300, Math.min(baseHeight, maxHeight))
|
return Math.max(300, Math.min(baseHeight, maxHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
color: Theme.withAlpha(Theme.surfaceContainer, Theme.popupTransparency)
|
color: Theme.withAlpha(Theme.surfaceContainer, Theme.popupTransparency)
|
||||||
@@ -126,27 +132,27 @@ DankPopout {
|
|||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (root.shouldBeVisible) {
|
if (root.shouldBeVisible) {
|
||||||
forceActiveFocus()
|
forceActiveFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.onPressed: event => {
|
Keys.onPressed: event => {
|
||||||
if (event.key === Qt.Key_Escape) {
|
if (event.key === Qt.Key_Escape) {
|
||||||
root.close()
|
root.close();
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
} else if (externalKeyboardController) {
|
} else if (externalKeyboardController) {
|
||||||
externalKeyboardController.handleKey(event)
|
externalKeyboardController.handleKey(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
function onShouldBeVisibleChanged() {
|
function onShouldBeVisibleChanged() {
|
||||||
if (root.shouldBeVisible) {
|
if (root.shouldBeVisible) {
|
||||||
Qt.callLater(() => {
|
Qt.callLater(() => {
|
||||||
notificationContent.forceActiveFocus()
|
notificationContent.forceActiveFocus();
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
notificationContent.focus = false
|
notificationContent.focus = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
target: root
|
target: root
|
||||||
|
|||||||
Reference in New Issue
Block a user