From 0e7f628c4aa1b58a7863e8fcff0ed2709a06d30f Mon Sep 17 00:00:00 2001 From: bbedward Date: Tue, 20 Jan 2026 21:55:05 -0500 Subject: [PATCH] launcher v2: improve danksearch context switching behavior --- .../Modals/DankLauncherV2/Controller.qml | 32 +++++++++++++++- .../Modals/DankLauncherV2/LauncherContent.qml | 5 ++- .../Modals/DankLauncherV2/ResultsList.qml | 37 ++++++++----------- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/quickshell/Modals/DankLauncherV2/Controller.qml b/quickshell/Modals/DankLauncherV2/Controller.qml index a7ca8a04..e3cb44d3 100644 --- a/quickshell/Modals/DankLauncherV2/Controller.qml +++ b/quickshell/Modals/DankLauncherV2/Controller.qml @@ -11,6 +11,9 @@ Item { property string searchQuery: "" property string searchMode: "all" + property string previousSearchMode: "all" + property bool autoSwitchedToFiles: false + property bool isFileSearching: false property var sections: [] property var flatModel: [] property int selectedFlatIndex: 0 @@ -198,9 +201,15 @@ Item { } } - function setMode(mode) { + function setMode(mode, isAutoSwitch) { if (searchMode === mode) return; + if (isAutoSwitch) { + previousSearchMode = searchMode; + autoSwitchedToFiles = true; + } else { + autoSwitchedToFiles = false; + } searchMode = mode; modeChanged(mode); performSearch(); @@ -209,6 +218,15 @@ Item { } } + function restorePreviousMode() { + if (!autoSwitchedToFiles) + return; + autoSwitchedToFiles = false; + searchMode = previousSearchMode; + modeChanged(previousSearchMode); + performSearch(); + } + function cycleMode() { var modes = ["all", "apps", "files", "plugins"]; var currentIndex = modes.indexOf(searchMode); @@ -219,6 +237,9 @@ Item { function reset() { searchQuery = ""; searchMode = "all"; + previousSearchMode = "all"; + autoSwitchedToFiles = false; + isFileSearching = false; sections = []; flatModel = []; selectedFlatIndex = 0; @@ -307,6 +328,8 @@ Item { clearActivePluginViewPreference(); if (searchMode === "files") { + var fileQuery = searchQuery.startsWith("/") ? searchQuery.substring(1).trim() : searchQuery.trim(); + isFileSearching = fileQuery.length >= 2 && DSearchService.dsearchAvailable; sections = []; flatModel = []; selectedFlatIndex = 0; @@ -482,8 +505,12 @@ Item { return; } - if (fileQuery.length < 2) + if (fileQuery.length < 2) { + isFileSearching = false; return; + } + + isFileSearching = true; var params = { limit: 20, fuzzy: true, @@ -492,6 +519,7 @@ Item { }; DSearchService.search(fileQuery, params, function (response) { + isFileSearching = false; if (response.error) return; var fileItems = []; diff --git a/quickshell/Modals/DankLauncherV2/LauncherContent.qml b/quickshell/Modals/DankLauncherV2/LauncherContent.qml index 1ef16ffb..5aab244c 100644 --- a/quickshell/Modals/DankLauncherV2/LauncherContent.qml +++ b/quickshell/Modals/DankLauncherV2/LauncherContent.qml @@ -247,7 +247,7 @@ FocusScope { return; case Qt.Key_Slash: if (event.modifiers === Qt.NoModifier && searchField.text.length === 0) { - controller.setMode("files"); + controller.setMode("files", true); return; } event.accepted = false; @@ -446,6 +446,9 @@ FocusScope { onTextChanged: { controller.setSearchQuery(text); + if (text.length === 0) { + controller.restorePreviousMode(); + } if (actionPanel.expanded) { actionPanel.hide(); } diff --git a/quickshell/Modals/DankLauncherV2/ResultsList.qml b/quickshell/Modals/DankLauncherV2/ResultsList.qml index 0f5a1201..72cc0be4 100644 --- a/quickshell/Modals/DankLauncherV2/ResultsList.qml +++ b/quickshell/Modals/DankLauncherV2/ResultsList.qml @@ -421,7 +421,7 @@ Item { Item { anchors.centerIn: parent - visible: !root.controller?.sections || root.controller.sections.length === 0 + visible: (!root.controller?.sections || root.controller.sections.length === 0) && !root.controller?.isFileSearching width: emptyColumn.implicitWidth height: emptyColumn.implicitHeight @@ -437,15 +437,16 @@ Item { function getEmptyIcon() { var mode = root.controller?.searchMode ?? "all"; - if (mode === "files") + switch (mode) { + case "files": return "folder_open"; - if (mode === "plugins") + case "plugins": return "extension"; - if (mode === "apps") + case "apps": return "apps"; - if (root.controller?.searchQuery?.length > 0) - return "search_off"; - return "search"; + default: + return root.controller?.searchQuery?.length > 0 ? "search_off" : "search"; + } } } @@ -460,7 +461,8 @@ Item { var mode = root.controller?.searchMode ?? "all"; var hasQuery = root.controller?.searchQuery?.length > 0; - if (mode === "files") { + switch (mode) { + case "files": if (!DSearchService.dsearchAvailable) return I18n.tr("File search requires dsearch\nInstall from github.com/morelazers/dsearch"); if (!hasQuery) @@ -468,20 +470,13 @@ Item { if (root.controller.searchQuery.length < 2) return I18n.tr("Type at least 2 characters"); return I18n.tr("No files found"); + case "plugins": + return hasQuery ? I18n.tr("No plugin results") : I18n.tr("Browse or search plugins"); + case "apps": + return hasQuery ? I18n.tr("No apps found") : I18n.tr("Type to search apps"); + default: + return hasQuery ? I18n.tr("No results found") : I18n.tr("Type to search"); } - if (mode === "plugins") { - if (!hasQuery) - return I18n.tr("Browse or search plugins"); - return I18n.tr("No plugin results"); - } - if (mode === "apps") { - if (!hasQuery) - return I18n.tr("Type to search apps"); - return I18n.tr("No apps found"); - } - if (hasQuery) - return I18n.tr("No results found"); - return I18n.tr("Type to search"); } } }