import QtQuick import Quickshell import Quickshell.Wayland import Quickshell.Services.Pipewire import Quickshell.Io import "../Shared" PanelWindow { id: paletteWindow property QtObject rootState property bool enterQueued: false property var usageCounts: ({}) property string lastUsedApp: "" property var allApps: [] property bool appsLoaded: false function scoreOf(desktopName) { let count = paletteWindow.usageCounts[desktopName] || 0; let isLast = (desktopName === paletteWindow.lastUsedApp); return count * 10 + (isLast ? 10000 : 0); } function applyFilter() { let query = searchInput.text.trim().toLowerCase(); let results = query.length === 0 ? paletteWindow.allApps.slice() : paletteWindow.allApps.filter(a => a.appName.toLowerCase().includes(query)); results.sort((a, b) => { if (b.score !== a.score) return b.score - a.score; return a.appName.localeCompare(b.appName); }); results = results.slice(0, 50); appModel.clear(); for (let i = 0; i < results.length; i++) { appModel.append(results[i]); } appList.currentIndex = appModel.count > 0 ? 0 : -1; if (paletteWindow.enterQueued && appModel.count > 0) { paletteWindow.enterQueued = false; paletteWindow.launchApp(0); } } readonly property int titleBarHeight: 28 readonly property int headerHeight: 50 readonly property int footerHeight: 24 readonly property int emptyStateHeight: 40 function launchApp(index) { if (index < 0 || index >= appModel.count) return; let item = appModel.get(index); let desktopName = item.desktopName; let appPath = item.appPath; logHistoryProcess.command = ["bash", "-c", "echo '" + desktopName + "' >> ~/.cache/quickshell-app-history.txt"]; logHistoryProcess.restart(); launchProcess.command = [ "bash", "-c", "EXEC=$(awk -F= '/^Exec=/ {print $2; exit}' \"$1\" | sed 's/ %[a-zA-Z]//g'); if command -v uwsm &>/dev/null; then eval \"uwsm app -- $EXEC\"; elif command -v niri &>/dev/null; then eval \"niri msg action spawn -- $EXEC\"; else nohup eval \"$EXEC\" /dev/null 2>&1 & fi", "_", appPath ]; launchProcess.restart(); rootState.commandPaletteOpen = false; } visible: rootState.commandPaletteOpen anchors { top: true bottom: true left: true right: true } exclusiveZone: 0 color: "transparent" WlrLayershell.layer: WlrLayer.Overlay WlrLayershell.namespace: "quickshell-palette" WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive MouseArea { anchors.fill: parent onClicked: rootState.commandPaletteOpen = false } Surface { id: container // Sized appropriately for a 2560x1440 screen width: 800 height: Math.min(600, titleBarHeight + Theme.geometry.spacing + headerHeight + Theme.geometry.spacing + (appModel.count > 0 ? appList.contentHeight : emptyStateHeight) + Theme.geometry.spacing + footerHeight + Theme.geometry.padding * 2) anchors.centerIn: parent tint: Theme.colors.primary glow: true Behavior on scale { NumberAnimation { duration: Theme.animation.durationFast; easing.type: Easing.OutCubic } } Behavior on opacity { NumberAnimation { duration: Theme.animation.durationFast } } Behavior on height { NumberAnimation { duration: Theme.animation.durationFast; easing.type: Easing.OutCubic } } opacity: rootState.commandPaletteOpen ? 1 : 0 MouseArea { anchors.fill: parent } // --- App Launcher --- Column { anchors.fill: parent anchors.margins: Theme.geometry.padding spacing: Theme.geometry.spacing Item { width: parent.width height: paletteWindow.titleBarHeight Row { anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter spacing: Theme.geometry.spacing / 2 Rectangle { width: 10 height: 10 anchors.verticalCenter: parent.verticalCenter color: Theme.colors.primary border.width: Theme.geometry.borderWidth border.color: Theme.colors.crust } Text { text: "QUICKSHELL :: APP_ROFI_MODAL [WAYLAND]" color: Theme.colors.textMuted font.family: Theme.font.family font.bold: true font.pixelSize: Theme.type.caption } } Text { anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter text: "[ESC] Close" color: Theme.colors.textMuted font.family: Theme.font.family font.pixelSize: Theme.type.caption } } TextField { id: searchInput width: parent.width height: paletteWindow.headerHeight placeholder: "Search apps..." prefix: "❯" onVisibleChanged: { if (visible) focusInput(); } onTextChanged: { if (paletteWindow.appsLoaded) { paletteWindow.applyFilter(); } } onEscapePressed: { rootState.commandPaletteOpen = false; } onUpPressed: { if (appList.currentIndex > 0) { appList.currentIndex--; appList.positionViewAtIndex(appList.currentIndex, ListView.Contain); } } onDownPressed: { if (appList.currentIndex < appList.count - 1) { appList.currentIndex++; appList.positionViewAtIndex(appList.currentIndex, ListView.Contain); } } onReturnPressed: { if (appList.count > 0 && appList.currentIndex >= 0 && appList.currentIndex < appModel.count) { paletteWindow.launchApp(appList.currentIndex); } else { paletteWindow.enterQueued = true; } } } Process { id: historyProcess command: ["bash", "-c", "cat ~/.cache/quickshell-app-history.txt 2>/dev/null || true"] running: false function restart() { running = false; running = true; } stdout: StdioCollector { onStreamFinished: { let lines = this.text.split('\n').filter(l => l.trim() !== ""); let counts = {}; let lastUsed = ""; for (let i = 0; i < lines.length; i++) { let app = lines[i]; counts[app] = (counts[app] || 0) + 1; lastUsed = app; } paletteWindow.usageCounts = counts; paletteWindow.lastUsedApp = lastUsed; // Now that history is loaded, list every desktop entry once. // Filtering as the user types happens entirely in JS below // (applyFilter), so the expensive disk/symlink walk here // only ever runs a single time per palette open. listProcess.restart(); } } } Process { id: listProcess command: [ "bash", "-c", "fd -L -t f -e desktop -0 . /usr/share/applications ~/.local/share/applications /var/lib/flatpak/exports/share/applications /run/current-system/sw/share/applications ~/.nix-profile/share/applications 2>/dev/null | xargs -0 -r awk -F= 'BEGIN { OFS=\"|\" } FNR==1 { if(file!=\"\" && name!=\"\") print icon, name, file; name=\"\"; icon=\"\"; file=FILENAME } /^Name=/ && name==\"\" { name=substr($0, 6) } /^Icon=/ && icon==\"\" { icon=substr($0, 6) } END { if(file!=\"\" && name!=\"\") print icon, name, file }'" ] running: false function restart() { running = false; running = true; } stdout: StdioCollector { onStreamFinished: { let lines = this.text.split('\n').filter(l => l.trim() !== ""); let apps = []; for (let i = 0; i < lines.length; i++) { let parts = lines[i].split('|'); if (parts.length >= 3) { let desktopName = parts[2].split('/').pop(); let isLast = (desktopName === paletteWindow.lastUsedApp); apps.push({ "iconName": parts[0], "appName": parts[1], "appPath": parts[2], "desktopName": desktopName, "isLastUsed": isLast, "score": paletteWindow.scoreOf(desktopName) }); } } paletteWindow.allApps = apps; paletteWindow.appsLoaded = true; paletteWindow.applyFilter(); } } } Text { width: parent.width height: paletteWindow.emptyStateHeight visible: appModel.count === 0 verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter text: searchInput.text.length > 0 ? "No apps found for “" + searchInput.text + "”" : "No apps found" color: Theme.colors.textMuted font.family: Theme.font.family font.pixelSize: Theme.type.body } ListView { id: appList width: parent.width height: parent.height - paletteWindow.headerHeight - paletteWindow.footerHeight - Theme.geometry.spacing * 2 visible: appModel.count > 0 clip: true spacing: Theme.geometry.spacing / 2 model: ListModel { id: appModel } delegate: ListRow { id: appRow width: appList.width selected: ListView.isCurrentItem accent: model.isLastUsed ? Theme.colors.secondary : Theme.colors.primary onEntered: appList.currentIndex = index onClicked: { appList.currentIndex = index; paletteWindow.launchApp(index); } Image { id: appIcon width: 24 height: 24 source: model.iconName ? Quickshell.iconPath(model.iconName) : "" anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter fillMode: Image.PreserveAspectFit Rectangle { anchors.fill: parent color: Theme.colors.primary visible: parent.status === Image.Error || parent.status === Image.Null || model.iconName === "" Text { anchors.centerIn: parent text: model.appName.charAt(0).toUpperCase() color: Theme.colors.textOnAccent font.bold: true font.pixelSize: 12 } } } Text { text: model.appName color: appRow.selected ? Theme.colors.textOnAccent : Theme.colors.text font.family: Theme.font.family font.pixelSize: Theme.type.label anchors.left: appIcon.right anchors.leftMargin: Theme.geometry.spacing anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter elide: Text.ElideRight } } } Item { width: parent.width height: paletteWindow.footerHeight HintBar { anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter hints: [ { key: "↑↓", label: "Navigate" }, { key: "↵", label: "Launch" }, { key: "Esc", label: "Close" } ] } Row { anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter spacing: Theme.geometry.spacing / 2 Rectangle { width: 8 height: 8 anchors.verticalCenter: parent.verticalCenter color: Theme.colors.tertiary border.width: Theme.geometry.borderWidth border.color: Theme.colors.crust } Text { text: "HYPR_IPC OK" color: Theme.colors.text font.family: Theme.font.family font.bold: true font.pixelSize: Theme.type.caption } } } } Process { id: launchProcess running: false function restart() { running = false; running = true; } } Process { id: logHistoryProcess running: false function restart() { running = false; running = true; } } } onVisibleChanged: { if (visible) { container.scale = 1.0; searchInput.text = ""; paletteWindow.enterQueued = false; paletteWindow.appsLoaded = false; appModel.clear(); // Clear so it re-populates clean // Read history first, then list every desktop entry once historyProcess.restart(); } else { container.scale = 0.95; } } }