diff --git a/.config/quickshell/ii/modules/common/models/FolderListModelWithHistory.qml b/.config/quickshell/ii/modules/common/models/FolderListModelWithHistory.qml new file mode 100644 index 00000000..2aeb3e71 --- /dev/null +++ b/.config/quickshell/ii/modules/common/models/FolderListModelWithHistory.qml @@ -0,0 +1,53 @@ +import QtQuick +import Qt.labs.folderlistmodel + +FolderListModel { + id: root + property list folderHistory: [] + property int currentFolderHistoryIndex: -1 + property bool historyNavigationLock: false + + function lockNextNavigation() { + historyNavigationLock = true; + } + + function pushToHistory(path) { + if (folderHistory[currentFolderHistoryIndex] === path) + return; + folderHistory = folderHistory.slice(0, currentFolderHistoryIndex + 1); + folderHistory.push(path); + currentFolderHistoryIndex = folderHistory.length - 1; + } + + function navigateUp() { + root.folder = root.parentFolder; + } + + function navigateBack() { + if (currentFolderHistoryIndex === 0) + return; + currentFolderHistoryIndex--; + lockNextNavigation(); + root.folder = folderHistory[currentFolderHistoryIndex]; + } + + function navigateForward() { + if (currentFolderHistoryIndex >= folderHistory.length - 1) return; + currentFolderHistoryIndex++; + lockNextNavigation(); + root.folder = folderHistory[currentFolderHistoryIndex]; + } + + onFolderChanged: { + if (historyNavigationLock) { + historyNavigationLock = false; + return; + } + pushToHistory(folder); + } + + Component.onCompleted: { + root.folderHistory = [root.folder] + root.currentFolderHistoryIndex = 0 + } +} diff --git a/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml b/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml index 56e7dab7..6e2d2ff9 100644 --- a/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml +++ b/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml @@ -10,7 +10,7 @@ import Qt5Compat.GraphicalEffects import Quickshell import Quickshell.Io -Item { +MouseArea { id: root property int columns: 4 property real previewCellAspectRatio: 4 / 3 @@ -40,6 +40,15 @@ Item { } } + acceptedButtons: Qt.BackButton | Qt.ForwardButton + onPressed: event => { + if (event.button === Qt.BackButton) { + Wallpapers.navigateBack(); + } else if (event.button === Qt.ForwardButton) { + Wallpapers.navigateForward(); + } + } + Keys.onPressed: event => { if (event.key === Qt.Key_Escape) { GlobalStates.wallpaperSelectorOpen = false; @@ -47,7 +56,13 @@ Item { } else if ((event.modifiers & Qt.ControlModifier) && event.key === Qt.Key_V) { // Intercept Ctrl+V to handle "paste to go to" in pickers root.handleFilePasting(event); } else if (event.modifiers & Qt.AltModifier && event.key === Qt.Key_Up) { - Wallpapers.setDirectory(FileUtils.parentDirectory(Wallpapers.directory)); + Wallpapers.navigateUp(); + event.accepted = true; + } else if (event.modifiers & Qt.AltModifier && event.key === Qt.Key_Left) { + Wallpapers.navigateBack(); + event.accepted = true; + } else if (event.modifiers & Qt.AltModifier && event.key === Qt.Key_Right) { + Wallpapers.navigateForward(); event.accepted = true; } else if (event.key === Qt.Key_Left) { grid.moveSelection(-1); @@ -160,7 +175,7 @@ Item { } onClicked: Wallpapers.setDirectory(quickDirButton.modelData.path) enabled: modelData.icon.length > 0 - toggled: Wallpapers.directory === FileUtils.trimFileProtocol(modelData.path) + toggled: Wallpapers.directory === Qt.resolvedUrl(modelData.path) colBackgroundToggled: Appearance.colors.colSecondaryContainer colBackgroundToggledHover: Appearance.colors.colSecondaryContainerHover colRippleToggled: Appearance.colors.colSecondaryContainerActive diff --git a/.config/quickshell/ii/services/Wallpapers.qml b/.config/quickshell/ii/services/Wallpapers.qml index 019bd877..4afffa1f 100644 --- a/.config/quickshell/ii/services/Wallpapers.qml +++ b/.config/quickshell/ii/services/Wallpapers.qml @@ -1,4 +1,5 @@ import qs.modules.common +import qs.modules.common.models import qs.modules.common.functions import QtQuick import Qt.labs.folderlistmodel @@ -16,8 +17,9 @@ Singleton { property string thumbgenScriptPath: `${FileUtils.trimFileProtocol(Directories.scriptPath)}/thumbnails/thumbgen.py` property string generateThumbnailsMagicScriptPath: `${FileUtils.trimFileProtocol(Directories.scriptPath)}/thumbnails/generate-thumbnails-magick.sh` - property string directory: FileUtils.trimFileProtocol(`${Directories.pictures}/Wallpapers`) + property alias directory: folderModel.folder readonly property string effectiveDirectory: FileUtils.trimFileProtocol(folderModel.folder.toString()) + property url defaultFolder: Qt.resolvedUrl(`${Directories.pictures}/Wallpapers`) property alias folderModel: folderModel // Expose for direct binding when needed property string searchQuery: "" readonly property list extensions: [ // TODO: add videos @@ -88,11 +90,11 @@ Singleton { } stdout: StdioCollector { onStreamFinished: { + root.directory = Qt.resolvedUrl(validateDirProc.nicePath) const result = text.trim() if (result === "dir") { - root.directory = validateDirProc.nicePath } else if (result === "file") { - root.directory = FileUtils.parentDirectory(validateDirProc.nicePath) + root.directory = Qt.resolvedUrl(FileUtils.parentDirectory(validateDirProc.nicePath)) } else { // Ignore } @@ -102,11 +104,20 @@ Singleton { function setDirectory(path) { validateDirProc.setDirectoryIfValid(path) } + function navigateUp() { + folderModel.navigateUp() + } + function navigateBack() { + folderModel.navigateBack() + } + function navigateForward() { + folderModel.navigateForward() + } // Folder model - FolderListModel { + FolderListModelWithHistory { id: folderModel - folder: Qt.resolvedUrl(root.directory) + folder: Qt.resolvedUrl(root.defaultFolder) caseSensitive: false nameFilters: root.extensions.map(ext => `*${searchQuery.split(" ").filter(s => s.length > 0).map(s => `*${s}*`)}*.${ext}`) showDirs: true