1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-28 07:22:50 -05:00

dankdash: add wallpaper selector + IPC targets

This commit is contained in:
bbedward
2025-10-21 23:15:10 -04:00
parent 967b7d05de
commit 1e72733e81
8 changed files with 812 additions and 19 deletions

View File

@@ -2,7 +2,7 @@ import QtQuick
import qs.Common
import qs.Widgets
Item {
FocusScope {
id: tabBar
property alias model: tabRepeater.model
@@ -11,12 +11,101 @@ Item {
property int tabHeight: 56
property bool showIcons: true
property bool equalWidthTabs: true
property bool enableArrowNavigation: true
property Item nextFocusTarget: null
property Item previousFocusTarget: null
signal tabClicked(int index)
signal actionTriggered(int index)
focus: false
activeFocusOnTab: true
height: tabHeight
KeyNavigation.tab: nextFocusTarget
KeyNavigation.down: nextFocusTarget
KeyNavigation.backtab: previousFocusTarget
KeyNavigation.up: previousFocusTarget
Keys.onPressed: (event) => {
if (!tabBar.activeFocus || tabRepeater.count === 0)
return
function findSelectableIndex(startIndex, step) {
let idx = startIndex
for (let i = 0; i < tabRepeater.count; i++) {
idx = (idx + step + tabRepeater.count) % tabRepeater.count
const item = tabRepeater.itemAt(idx)
if (item && !item.isAction)
return idx
}
return -1
}
const goToIndex = (nextIndex) => {
if (nextIndex >= 0 && nextIndex !== tabBar.currentIndex) {
tabBar.currentIndex = nextIndex
tabBar.tabClicked(nextIndex)
}
}
const resolveTarget = (item) => {
if (!item)
return null
if (item.focusTarget)
return resolveTarget(item.focusTarget)
return item
}
const focusItem = (item) => {
const target = resolveTarget(item)
if (!target)
return false
if (target.requestFocus) {
Qt.callLater(() => target.requestFocus())
return true
}
if (target.forceActiveFocus) {
Qt.callLater(() => target.forceActiveFocus())
return true
}
return false
}
if (event.key === Qt.Key_Right && tabBar.enableArrowNavigation) {
const baseIndex = (tabBar.currentIndex >= 0 && tabBar.currentIndex < tabRepeater.count) ? tabBar.currentIndex : -1
const nextIndex = findSelectableIndex(baseIndex, 1)
if (nextIndex >= 0) {
goToIndex(nextIndex)
event.accepted = true
}
} else if (event.key === Qt.Key_Left && tabBar.enableArrowNavigation) {
const baseIndex = (tabBar.currentIndex >= 0 && tabBar.currentIndex < tabRepeater.count) ? tabBar.currentIndex : 0
const nextIndex = findSelectableIndex(baseIndex, -1)
if (nextIndex >= 0) {
goToIndex(nextIndex)
event.accepted = true
}
} else if (event.key === Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)) {
if (focusItem(tabBar.previousFocusTarget)) {
event.accepted = true
}
} else if (event.key === Qt.Key_Tab || event.key === Qt.Key_Down) {
if (focusItem(tabBar.nextFocusTarget)) {
event.accepted = true
}
} else if (event.key === Qt.Key_Up) {
if (focusItem(tabBar.previousFocusTarget)) {
event.accepted = true
}
}
}
Row {
id: tabRow
anchors.fill: parent
@@ -77,7 +166,6 @@ Item {
if (tabItem.isAction) {
tabBar.actionTriggered(index)
} else {
tabBar.currentIndex = index
tabBar.tabClicked(index)
}
}