diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-08-05 17:25:30 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-08-05 17:25:30 +0800 |
| commit | f9efa56caeeb5289d6b2314e50041a1b7055a3c8 (patch) | |
| tree | 8a9e5b59f8690555ba8ad51f653db02d9483e2a7 /launcher/Launcher.qml | |
| parent | f6b5ac3cfba03602fea9d8c30b13075514dbd131 (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/Launcher.qml')
| -rw-r--r-- | launcher/Launcher.qml | 371 |
1 files changed, 371 insertions, 0 deletions
diff --git a/launcher/Launcher.qml b/launcher/Launcher.qml new file mode 100644 index 0000000..e32dae5 --- /dev/null +++ b/launcher/Launcher.qml @@ -0,0 +1,371 @@ +import Quickshell +import QtQuick +import QtQuick.Layouts + +import "components" +import qs.components +import qs.config + +// TODO: currently, we're relying on the compositor to provide the animation which ig is fine, but we should use our own in the future, however it might look weird combined with the compositors's +ILauncher { + id: launcher + name: "quickshell::launcher::launcher" + + anchors.top: true + margins.top: Launcher.topMargin + aboveWindows: true + exclusionMode: ExclusionMode.Ignore + + IRect { + id: container + property var selection: SelectionState?.selected || null + property var mappedSelection: selection?.mapToItem(null, 0, 0) + onMappedSelectionChanged: { + // SelectionState?.selected may be slow.. smh qt + // my guess is mapToItem is called when its not finished doing whatever it needs to do, + // so it doesnt get the right vars, but it doesn't update after since it already triggered it + selectionSync.running = true; + } + Timer { + id: selectionSync + running: false + repeat: false + // sync w/ IComponent y animation duration + interval: General.animationDuration / 4 + onTriggered: { + parent.mappedSelection = SelectionState?.selected?.mapToItem(null, 0, 0); + } + } + + IRect { + id: activeRect + visible: parent.mappedSelection || false + y: parent.mappedSelection?.y || 0 + x: parent.mappedSelection?.x || 0 + implicitWidth: SelectionState?.selected?.width || 0 + implicitHeight: SelectionState?.selected?.height || 0 + radius: Launcher.borderRadius + color: Qt.rgba(Colors.foreground2.r, Colors.foreground2.g, Colors.foreground2.b, Launcher.bgTransparency) + Behavior on x { + ISpringAnimation {} + } + Behavior on y { + ISpringAnimation {} + } + Behavior on implicitWidth { + ISpringAnimation {} + } + Behavior on height { + ISpringAnimation {} + } + } + color: Qt.rgba(Colors.background3.r, Colors.background3.g, Colors.background3.b, Launcher.bgTransparency) + radius: Launcher.borderRadius + + width: Math.max(root.width, Launcher.defaultWidth) + Launcher.innerMargin + height: root.height + + IRect { + id: root + property alias input: textInput.text + + height: searchBar.height + widgets.height + textInput.height / 2 // * 1.5 + width: Math.max(widgets.implicitWidth, Launcher.defaultWidth) + + anchors.centerIn: parent + + color: "transparent" + + RowLayout { + id: searchBar + anchors { + top: parent.top + left: parent.left + right: parent.right + leftMargin: Launcher.innerMargin + rightMargin: Launcher.innerMargin + // try to center it when no widgets are present + topMargin: widgets.height === Launcher.widgets.length * 5 - 5 ? parent.height / 2 - textInput.height / 2 : Launcher.innerMargin // textInput or Icon is the height of this + + Behavior on topMargin { + ISpringAnimation {} + // NumberAnimation { + // duration: General.animationDuration / 2 + // } + } + } + + spacing: Launcher.innerMargin * 2 + + Icon { + text: "" + } + + RowLayout { + spacing: 0 + TextInput { + id: textInput + Layout.fillHeight: true + Layout.fillWidth: true + Layout.maximumWidth: implicitWidth + color: Colors.foreground1 + selectionColor: Colors.background3 + text: SelectionState?.input || "" + clip: true + focus: true + renderType: Text.CurveRendering + antialiasing: true + smooth: true + font { + pixelSize: Style.font.size.large + family: Style.font.family.sans + wordSpacing: 5 + } + // move to different file if we have more textinput + cursorDelegate: IRect { + id: cursor + color: Colors.cursor + // width: 1.5 + width: 2 + height: 1 + // blinking animation + SequentialAnimation { + running: true + loops: Animation.Infinite + PauseAnimation { + duration: 500 + } + ParallelAnimation { + PropertyAnimation { + target: cursor + property: "opacity" + to: 0 + duration: General.animationDuration / 5 + } + PropertyAnimation { + target: cursor + property: "scale" + to: 0 + duration: General.animationDuration / 5 + } + } + PauseAnimation { + duration: 500 + } + ParallelAnimation { + PropertyAnimation { + target: cursor + property: "opacity" + to: 1 + duration: General.animationDuration / 5 + } + PropertyAnimation { + target: cursor + property: "scale" + to: 1 + duration: General.animationDuration / 5 + } + } + } + } + onTextChanged: { + if (SelectionState.input !== textInput.text) + SelectionState.input = textInput.text; // TODO: find ways to optimize this, like how i was using an alias + } + onCursorPositionChanged: { + SelectionState.cursorPosition = textInput.cursorPosition; + } + // onActiveFocusChanged: { + // parentLoader.active = activeFocus; + // } + onAccepted: { + SelectionState?.priorities[0]?._exec(); // TODO: kde like waiting animation for app to launch + parentLoader.active = false; + textInput.text = ""; + } + Component.onCompleted: { + selectAll(); + } + } + IRect { + opacity: SelectionState?.priorities[0]?.predictiveCompletion ? 1 : 0 + Layout.fillHeight: true + Layout.preferredWidth: text.width + radius: Launcher.predictiveCompletionRadius + color: Qt.rgba(Colors.background2.r, Colors.background2.g, Colors.background2.b, Launcher.widgetBgTransparency) + IText { + id: text + // animate: true // too jumpy + color: Colors.foreground3 + renderType: Text.CurveRendering + antialiasing: true + smooth: true + font { + pixelSize: Style.font.size.large + family: Style.font.family.sans + wordSpacing: 5 + } + text: SelectionState?.priorities[0]?.predictiveCompletion || "" + } + Behavior on Layout.preferredWidth { + ISpringAnimation {} + // NumberAnimation { + // duration: General.animationDuration / 5 + // } + } + Behavior on opacity { + NumberAnimation { + duration: General.animationDuration / 2 + easing.type: Easing.InOutQuad + } + } + } + Item { + Layout.fillWidth: true + } + Loader { + active: SelectionState?.priorities[0]?.priority || false // .priority should always be true if it's in priorities + sourceComponent: SelectionState?.priorities[0]?.preview + } + } + } + + ColumnLayout { + id: widgets + anchors { + top: searchBar.bottom + left: parent.left + right: parent.right + topMargin: Launcher.innerMargin * 1.5 // gap in between, maybe seperator FIXME + } + + Repeater { + model: Launcher.widgets + delegate: Loader { + active: true + sourceComponent: modelData + Component.onCompleted: { + SelectionState.widgets[index] = item; + // FIXME: prev predictiveCompletion still exists here + // workaround atm: just clear it or preserve the text manually + } + Connections { + target: item + function onClose() { + parentLoader.active = false; + } + } + } + } + } + } + + // not Keys.onPressed because textinput will steal it + Shortcut { + sequence: "Ctrl+H" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + if (!item) + return; + item.prev(); + } + } + + Shortcut { + sequence: "Ctrl+J" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + if (!item) + return; + item.down(); + } + } + + Shortcut { + sequence: "Ctrl+K" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + if (!item) + return; + item.up(); + } + } + + Shortcut { + sequence: "Ctrl+L" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + if (!item) + return; + item.next(); + } + } + + Shortcut { + sequence: "Escape" + context: Qt.ApplicationShortcut + onActivated: parentLoader.active = false + } + + Shortcut { + sequence: "Down" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + item?.down(); + } + } + + Shortcut { + sequence: "Up" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + item?.up(); + } + } + + Shortcut { + sequence: "PageDown" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + item?.pageDown(); + } + } + + Shortcut { + sequence: "PageUp" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + item?.pageUp(); + } + } + + Shortcut { + sequence: "Home" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + item?.home(); + } + } + + Shortcut { + sequence: "End" + context: Qt.ApplicationShortcut + onActivated: { + const item = SelectionState?.priorities[0]; + item?.end(); + } + } + } + + implicitWidth: container.width + implicitHeight: container.height +} |
