diff --git a/.config/quickshell/ii/modules/common/functions/StringUtils.qml b/.config/quickshell/ii/modules/common/functions/StringUtils.qml index 92de50c5c..ea5e42df9 100644 --- a/.config/quickshell/ii/modules/common/functions/StringUtils.qml +++ b/.config/quickshell/ii/modules/common/functions/StringUtils.qml @@ -217,4 +217,8 @@ Singleton { return str; return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); } + + function cleanCliphistEntry(str: string): string { + return str.replace(/^\d+\t/, ""); + } } diff --git a/.config/quickshell/ii/modules/overview/SearchWidget.qml b/.config/quickshell/ii/modules/overview/SearchWidget.qml index 09ae87718..fe45f9702 100644 --- a/.config/quickshell/ii/modules/overview/SearchWidget.qml +++ b/.config/quickshell/ii/modules/overview/SearchWidget.qml @@ -296,7 +296,7 @@ Item { // Wrapper return Cliphist.fuzzyQuery(searchString).map(entry => { return { cliphistRawString: entry, - name: entry.replace(/^\s*\S+\s+/, ""), + name: StringUtils.cleanCliphistEntry(entry), clickActionName: "", type: `#${entry.match(/^\s*(\S+)/)?.[1] || ""}`, execute: () => { diff --git a/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml b/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml index 45a08e5c8..82bf7d438 100644 --- a/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml +++ b/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml @@ -29,10 +29,23 @@ Item { } } + function handleFilePasting(event) { + const currentClipboardEntry = Cliphist.entries[0] + if (/^\d+\tfile:\/\/\S+/.test(currentClipboardEntry)) { + const url = StringUtils.cleanCliphistEntry(currentClipboardEntry); + Wallpapers.setDirectory(FileUtils.trimFileProtocol(decodeURIComponent(url))); + event.accepted = true; + } else { + event.accepted = false; // No image, let text pasting proceed + } + } + Keys.onPressed: event => { if (event.key === Qt.Key_Escape) { GlobalStates.wallpaperSelectorOpen = false; event.accepted = true; + } 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)); event.accepted = true; @@ -316,15 +329,21 @@ Item { } Keys.onPressed: event => { - if (text.length !== 0) { + if ((event.modifiers & Qt.ControlModifier) && event.key === Qt.Key_V) { // Intercept Ctrl+V to handle "paste to go to" in pickers + root.handleFilePasting(event); + return; + } + else if (text.length !== 0) { // No filtering, just navigate grid if (event.key === Qt.Key_Down) { grid.moveSelection(grid.columns); event.accepted = true; + return; } if (event.key === Qt.Key_Up) { grid.moveSelection(-grid.columns); event.accepted = true; + return; } } event.accepted = false; diff --git a/.config/quickshell/ii/services/Wallpapers.qml b/.config/quickshell/ii/services/Wallpapers.qml index ebd7c27e5..f5c243234 100644 --- a/.config/quickshell/ii/services/Wallpapers.qml +++ b/.config/quickshell/ii/services/Wallpapers.qml @@ -76,11 +76,21 @@ Singleton { function setDirectoryIfValid(path) { validateDirProc.nicePath = FileUtils.trimFileProtocol(path).replace(/\/+$/, "") if (/^\/*$/.test(validateDirProc.nicePath)) validateDirProc.nicePath = "/"; - validateDirProc.exec(["test", "-d", nicePath]) + validateDirProc.exec([ + "bash", "-c", + `if [ -d "${validateDirProc.nicePath}" ]; then echo dir; elif [ -f "${validateDirProc.nicePath}" ]; then echo file; else echo invalid; fi` + ]) } - onExited: (exitCode, exitStatus) => { - if (exitCode === 0) { - root.directory = validateDirProc.nicePath + stdout: StdioCollector { + onStreamFinished: { + const result = text.trim() + if (result === "dir") { + root.directory = validateDirProc.nicePath + } else if (result === "file") { + root.directory = FileUtils.parentDirectory(validateDirProc.nicePath) + } else { + // Ignore + } } } }