343 lines
14 KiB
QML
343 lines
14 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
import Quickshell.Services.Pipewire
|
|
import Quickshell.Io
|
|
import "../Shared"
|
|
|
|
PanelWindow {
|
|
id: paletteWindow
|
|
property QtObject rootState
|
|
property var usageCounts: ({})
|
|
property string lastUsedApp: ""
|
|
|
|
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
|
|
rootState.commandPaletteOsdMode = false
|
|
}
|
|
}
|
|
|
|
Rectangle {
|
|
id: container
|
|
// Sized appropriately for a 2560x1440 screen
|
|
width: 800
|
|
height: Math.min(600, (appList.count > 0 ? appList.contentHeight : 0) + 50 + Theme.geometry.padding * 2 + Theme.geometry.spacing)
|
|
anchors.centerIn: parent
|
|
radius: Theme.geometry.radius
|
|
color: Theme.colors.background
|
|
border.color: Theme.colors.border
|
|
border.width: 1
|
|
|
|
Behavior on scale { SpringAnimation { spring: 3; damping: 0.2 } }
|
|
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
|
|
|
|
Rectangle {
|
|
width: parent.width
|
|
height: 50
|
|
color: Theme.colors.surface
|
|
radius: Theme.geometry.radius
|
|
|
|
TextInput {
|
|
id: searchInput
|
|
anchors.fill: parent
|
|
anchors.margins: Theme.geometry.padding
|
|
verticalAlignment: TextInput.AlignVCenter
|
|
font.family: Theme.font.family
|
|
font.pixelSize: 18
|
|
color: Theme.colors.text
|
|
clip: true
|
|
|
|
Text {
|
|
text: "Search apps..."
|
|
color: Theme.colors.textMuted
|
|
font.family: Theme.font.family
|
|
font.pixelSize: 18
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
visible: searchInput.text.length === 0
|
|
}
|
|
|
|
onVisibleChanged: {
|
|
if (visible) forceActiveFocus();
|
|
}
|
|
|
|
onTextChanged: {
|
|
searchTimer.restart();
|
|
}
|
|
|
|
Keys.onEscapePressed: (event) => {
|
|
rootState.commandPaletteOpen = false;
|
|
event.accepted = true;
|
|
}
|
|
|
|
Keys.onUpPressed: (event) => {
|
|
if (appList.currentIndex > 0) {
|
|
appList.currentIndex--;
|
|
appList.positionViewAtIndex(appList.currentIndex, ListView.Contain);
|
|
}
|
|
event.accepted = true;
|
|
}
|
|
|
|
Keys.onDownPressed: (event) => {
|
|
if (appList.currentIndex < appList.count - 1) {
|
|
appList.currentIndex++;
|
|
appList.positionViewAtIndex(appList.currentIndex, ListView.Contain);
|
|
}
|
|
event.accepted = true;
|
|
}
|
|
|
|
Keys.onReturnPressed: (event) => {
|
|
if (appList.currentIndex >= 0 && appList.currentIndex < appModel.count) {
|
|
let item = appModel.get(appList.currentIndex);
|
|
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 >/dev/null 2>&1 & fi",
|
|
"_", appPath
|
|
];
|
|
launchProcess.restart();
|
|
rootState.commandPaletteOpen = false;
|
|
}
|
|
event.accepted = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
Timer {
|
|
id: searchTimer
|
|
interval: 200
|
|
onTriggered: searchProcess.restart()
|
|
}
|
|
|
|
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, run the search
|
|
searchProcess.restart();
|
|
}
|
|
}
|
|
}
|
|
|
|
Process {
|
|
id: searchProcess
|
|
command: [
|
|
"bash",
|
|
"-c",
|
|
"fd -L -t f -e desktop . /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 -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 }' | { [ -z \"$1\" ] && cat || rg -i \"$1\"; } | head -n 20",
|
|
"_",
|
|
searchInput.text
|
|
]
|
|
running: false
|
|
function restart() {
|
|
running = false;
|
|
running = true;
|
|
}
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
let lines = this.text.split('\n').filter(l => l.trim() !== "");
|
|
let results = [];
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
let parts = lines[i].split('|');
|
|
if (parts.length >= 3) {
|
|
let desktopName = parts[2].split('/').pop();
|
|
|
|
// Calculate frecency score
|
|
let count = paletteWindow.usageCounts[desktopName] || 0;
|
|
let isLast = (desktopName === paletteWindow.lastUsedApp);
|
|
// Give a massive boost to the absolute last used app, then weight by total usage
|
|
let score = count * 10 + (isLast ? 10000 : 0);
|
|
|
|
results.push({
|
|
"iconName": parts[0],
|
|
"appName": parts[1],
|
|
"appPath": parts[2],
|
|
"desktopName": desktopName,
|
|
"score": score
|
|
});
|
|
}
|
|
}
|
|
|
|
// Sort by score (descending), then alphabetically
|
|
results.sort((a, b) => {
|
|
if (b.score !== a.score) return b.score - a.score;
|
|
return a.appName.localeCompare(b.appName);
|
|
});
|
|
|
|
appModel.clear();
|
|
for (let i = 0; i < results.length; i++) {
|
|
appModel.append(results[i]);
|
|
}
|
|
|
|
appList.currentIndex = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
ListView {
|
|
id: appList
|
|
width: parent.width
|
|
height: parent.height - 50 - Theme.geometry.spacing
|
|
clip: true
|
|
spacing: Theme.geometry.spacing
|
|
|
|
model: ListModel { id: appModel }
|
|
|
|
delegate: Rectangle {
|
|
width: appList.width
|
|
height: 36
|
|
color: ListView.isCurrentItem ? Theme.colors.surfaceHover : "transparent"
|
|
radius: Theme.geometry.radius
|
|
|
|
Item {
|
|
anchors.fill: parent
|
|
anchors.leftMargin: Theme.geometry.padding
|
|
anchors.rightMargin: Theme.geometry.padding
|
|
|
|
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
|
|
radius: 12
|
|
visible: parent.status === Image.Error || parent.status === Image.Null || model.iconName === ""
|
|
|
|
Text {
|
|
anchors.centerIn: parent
|
|
text: model.appName.charAt(0).toUpperCase()
|
|
color: Theme.colors.background
|
|
font.bold: true
|
|
font.pixelSize: 12
|
|
}
|
|
}
|
|
}
|
|
|
|
Text {
|
|
text: model.appName
|
|
color: Theme.colors.text
|
|
font.family: Theme.font.family
|
|
font.pixelSize: 14
|
|
anchors.left: appIcon.right
|
|
anchors.leftMargin: Theme.geometry.spacing
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
hoverEnabled: true
|
|
onEntered: appList.currentIndex = index
|
|
onClicked: {
|
|
appList.currentIndex = index;
|
|
let desktopName = model.desktopName;
|
|
let appPath = model.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 >/dev/null 2>&1 & fi",
|
|
"_", appPath
|
|
];
|
|
launchProcess.restart();
|
|
rootState.commandPaletteOpen = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = "";
|
|
appModel.clear(); // Clear so it re-populates clean
|
|
|
|
// Read history first, then search
|
|
historyProcess.restart();
|
|
} else {
|
|
container.scale = 0.95;
|
|
}
|
|
}
|
|
}
|