summaryrefslogtreecommitdiff
path: root/launcher/components/App.qml
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-08-05 17:25:30 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-08-05 17:25:30 +0800
commitf9efa56caeeb5289d6b2314e50041a1b7055a3c8 (patch)
tree8a9e5b59f8690555ba8ad51f653db02d9483e2a7 /launcher/components/App.qml
parentf6b5ac3cfba03602fea9d8c30b13075514dbd131 (diff)
feat: add launcher support and image clipboard history utility
- Integrated a new Launcher component into the shell.qml for improved application launching. - Implemented an IPC handler to toggle the launcher visibility. - Added a new script (cliphist-img.sh) to manage image history from the clipboard. - Removed the outdated fuzzysort.js utility to streamline the codebase. - Refactored the Levenshtein distance algorithm for better performance and clarity.
Diffstat (limited to 'launcher/components/App.qml')
-rw-r--r--launcher/components/App.qml143
1 files changed, 143 insertions, 0 deletions
diff --git a/launcher/components/App.qml b/launcher/components/App.qml
new file mode 100644
index 0000000..6f0e4ce
--- /dev/null
+++ b/launcher/components/App.qml
@@ -0,0 +1,143 @@
+import Quickshell
+import Quickshell.Widgets
+import QtQuick
+import QtQuick.Layouts
+
+import qs.components
+import qs.services
+import qs.config
+
+IComponent {
+ id: root
+
+ property list<DesktopEntry> entries: inputCleaned ? AppSearch.fuzzyQuery(inputCleaned) : []
+ property int selectedIndex: -1
+
+ name: "Applications"
+
+ implicitHeight: valid ? layout.height : 0
+
+ preview: Component {
+ IconImage {
+ source: Quickshell.iconPath(answer, "image-missing")
+ implicitWidth: General.appIconSize
+ implicitHeight: General.appIconSize
+ }
+ }
+
+ property string predictiveCompletion: valid ? entries[selectedIndex].name.slice(input.length) : ""
+
+ process: function () {
+ const isValid = entries.length > 0;
+ const selected = isValid ? entries[selectedIndex] : '';
+
+ return {
+ valid: isValid,
+ priority: isValid,
+ answer: selected ? selected.icon : ""
+ };
+ }
+
+ exec: function () {
+ SelectionState.selected.modelData.execute();
+ }
+
+ up: function () {
+ if (selectedIndex <= 0)
+ return true;
+ selectedIndex--;
+ }
+ down: function () {
+ if (selectedIndex + 1 > repeater.count - 1)
+ return true;
+ selectedIndex++;
+ }
+
+ onEntriesChanged: {
+ selectedIndex = 0;
+ flickable.contentY = 0;
+ // selectedIndexChanged dont get called somehow
+ syncSelectionState();
+ }
+
+ onSelectedIndexChanged: {
+ syncSelectionState();
+ if (selectedIndex < 0 || selectedIndex >= repeater.count)
+ return;
+ Qt.callLater(() => {
+ const i = repeater.itemAt(selectedIndex), t = i.y, b = i.y + i.height, v = flickable.contentY, vb = v + flickable.height, maxY = Math.max(0, flickable.contentHeight - flickable.height);
+ const y = t < v ? t : b > vb ? b - flickable.height : v;
+ flickable.contentY = Math.max(0, Math.min(maxY, y));
+ });
+ }
+
+ function syncSelectionState() {
+ Qt.callLater(() => {
+ // fucking Qt why tf is repeater not ready when this is called
+ SelectionState.selected = repeater.itemAt(selectedIndex);
+ SelectionState.exec = root.exec;
+ });
+ }
+
+ IInnerComponent {
+ id: layout
+ fromParent: false
+ width: parent.width
+ height: Math.min(innerLayout.height + titleBar.height, Launcher.widgetHeight * 1.5)
+
+ Flickable {
+ id: flickable
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ clip: true
+ contentWidth: innerLayout.width
+ contentHeight: innerLayout.height
+
+ ColumnLayout {
+ id: innerLayout
+ spacing: 0
+
+ Repeater {
+ id: repeater
+ model: entries
+
+ Item {
+ required property DesktopEntry modelData
+ required property int index
+ Layout.margins: Launcher.innerMargin * 2
+ implicitWidth: item.width
+ implicitHeight: item.height
+
+ RowLayout {
+ id: item
+ spacing: Launcher.innerMargin * 2
+
+ IconImage {
+ source: Quickshell.iconPath(modelData.icon, "image-missing")
+ implicitWidth: General.appIconSize
+ implicitHeight: General.appIconSize
+ }
+ IText {
+ text: modelData.name
+ }
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ hoverEnabled: true
+ onPositionChanged: {
+ root.selectedIndex = index;
+ }
+ onExited: {
+ root.selectedIndex = 0;
+ }
+ onPressed: {
+ root._exec();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}