feat: impl scheme launcher action

This commit is contained in:
2 * r + 2 * t 2025-06-17 15:55:26 +10:00
parent 2a6cc10cfa
commit 2dbec4489e
5 changed files with 227 additions and 44 deletions

View file

@ -175,7 +175,6 @@ Singleton {
required property string desc required property string desc
required property string icon required property string icon
property bool disabled property bool disabled
property string disabledReason
function onClicked(list: AppList): void { function onClicked(list: AppList): void {
} }

View file

@ -10,14 +10,16 @@ import QtQuick.Controls
ListView { ListView {
id: root id: root
required property int padding
required property TextField search required property TextField search
required property PersistentProperties visibilities required property PersistentProperties visibilities
property bool isAction: search.text.startsWith(Config.launcher.actionPrefix) property bool isAction: search.text.startsWith(Config.launcher.actionPrefix)
property bool isScheme: search.text.startsWith(`${Config.launcher.actionPrefix}scheme `)
function getModelValues() { function getModelValues() {
let text = search.text; let text = search.text;
if (isScheme)
return Schemes.fuzzyQuery(text);
if (isAction) if (isAction)
return Actions.fuzzyQuery(text); return Actions.fuzzyQuery(text);
if (text.startsWith(Config.launcher.actionPrefix)) if (text.startsWith(Config.launcher.actionPrefix))
@ -43,7 +45,13 @@ ListView {
opacity: 0.08 opacity: 0.08
} }
delegate: isAction ? actionItem : appItem delegate: {
if (isScheme)
return schemeItem;
if (isAction)
return actionItem;
return appItem;
}
ScrollBar.vertical: StyledScrollBar {} ScrollBar.vertical: StyledScrollBar {}
@ -110,44 +118,58 @@ ListView {
} }
} }
Component {
id: schemeItem
SchemeItem {
visibilities: root.visibilities
}
}
Behavior on isAction { Behavior on isAction {
SequentialAnimation { ChangeAnim {}
ParallelAnimation { }
Anim {
target: root Behavior on isScheme {
property: "opacity" ChangeAnim {}
from: 1 }
to: 0
duration: Appearance.anim.durations.small component ChangeAnim: SequentialAnimation {
easing.bezierCurve: Appearance.anim.curves.standardAccel ParallelAnimation {
} Anim {
Anim { target: root
target: root property: "opacity"
property: "scale" from: 1
from: 1 to: 0
to: 0.9 duration: Appearance.anim.durations.small
duration: Appearance.anim.durations.small easing.bezierCurve: Appearance.anim.curves.standardAccel
easing.bezierCurve: Appearance.anim.curves.standardAccel
}
} }
PropertyAction {} Anim {
ParallelAnimation { target: root
Anim { property: "scale"
target: root from: 1
property: "opacity" to: 0.9
from: 0 duration: Appearance.anim.durations.small
to: 1 easing.bezierCurve: Appearance.anim.curves.standardAccel
duration: Appearance.anim.durations.small }
easing.bezierCurve: Appearance.anim.curves.standardDecel }
} PropertyAction {}
Anim { ParallelAnimation {
target: root Anim {
property: "scale" target: root
from: 0.9 property: "opacity"
to: 1 from: 0
duration: Appearance.anim.durations.small to: 1
easing.bezierCurve: Appearance.anim.curves.standardDecel duration: Appearance.anim.durations.small
} easing.bezierCurve: Appearance.anim.curves.standardDecel
}
Anim {
target: root
property: "scale"
from: 0.9
to: 1
duration: Appearance.anim.durations.small
easing.bezierCurve: Appearance.anim.curves.standardDecel
} }
} }
} }

View file

@ -15,8 +15,8 @@ Item {
required property int padding required property int padding
required property int rounding required property int rounding
property bool showWallpapers: search.text.startsWith(`${Config.launcher.actionPrefix}wallpaper `) readonly property bool showWallpapers: search.text.startsWith(`${Config.launcher.actionPrefix}wallpaper `)
property var currentList: (showWallpapers ? wallpaperList : appList).item property var currentList
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@ -29,8 +29,9 @@ Item {
name: "apps" name: "apps"
PropertyChanges { PropertyChanges {
root.currentList: appList.item
root.implicitWidth: Config.launcher.sizes.itemWidth root.implicitWidth: Config.launcher.sizes.itemWidth
root.implicitHeight: Math.max(empty.height, appList.height) root.implicitHeight: Math.max(empty.implicitHeight, appList.implicitHeight)
appList.active: true appList.active: true
} }
@ -43,7 +44,8 @@ Item {
name: "wallpapers" name: "wallpapers"
PropertyChanges { PropertyChanges {
root.implicitWidth: Math.max(Config.launcher.sizes.itemWidth, wallpaperList.width) root.currentList: wallpaperList.item
root.implicitWidth: Math.max(Config.launcher.sizes.itemWidth, wallpaperList.implicitWidth)
root.implicitHeight: Config.launcher.sizes.wallpaperHeight root.implicitHeight: Config.launcher.sizes.wallpaperHeight
wallpaperList.active: true wallpaperList.active: true
} }
@ -96,7 +98,6 @@ Item {
anchors.right: parent.right anchors.right: parent.right
sourceComponent: AppList { sourceComponent: AppList {
padding: root.padding
search: root.search search: root.search
visibilities: root.visibilities visibilities: root.visibilities
} }

View file

@ -0,0 +1,94 @@
import "root:/widgets"
import "root:/services"
import "root:/config"
import Quickshell
import Quickshell.Widgets
import QtQuick
Item {
id: root
required property var modelData
required property PersistentProperties visibilities
implicitHeight: Config.launcher.sizes.itemHeight
anchors.left: parent?.left
anchors.right: parent?.right
StateLayer {
radius: Appearance.rounding.full
function onClicked(): void {
Apps.launch(root.modelData);
root.visibilities.launcher = false;
}
}
Item {
anchors.fill: parent
anchors.leftMargin: Appearance.padding.larger
anchors.rightMargin: Appearance.padding.larger
anchors.margins: Appearance.padding.smaller
StyledRect {
id: preview
anchors.verticalCenter: parent.verticalCenter
border.width: 1
border.color: Qt.alpha(`#${root.modelData?.colours?.outline}`, 0.5)
color: `#${root.modelData?.colours?.surface}`
radius: Appearance.rounding.full
implicitWidth: parent.height * 0.8
implicitHeight: parent.height * 0.8
Item {
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
implicitWidth: parent.implicitWidth / 2
clip: true
StyledRect {
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
implicitWidth: preview.implicitWidth
color: `#${root.modelData?.colours?.primary}`
radius: Appearance.rounding.full
}
}
}
Column {
anchors.left: preview.right
anchors.leftMargin: Appearance.spacing.normal
anchors.verticalCenter: parent.verticalCenter
width: parent.width - preview.width
spacing: 0
StyledText {
id: name
text: root.modelData?.name ?? ""
font.pointSize: Appearance.font.size.normal
}
StyledText {
id: comment
text: root.modelData?.flavour ?? ""
font.pointSize: Appearance.font.size.small
color: Colours.palette.m3outline
elide: Text.ElideRight
width: parent.width - Appearance.rounding.normal * 2
}
}
}
}

View file

@ -0,0 +1,67 @@
pragma Singleton
import "root:/utils/scripts/fuzzysort.js" as Fuzzy
import "root:/config"
import Quickshell
import Quickshell.Io
import QtQuick
Singleton {
id: root
readonly property list<var> preppedActions: schemes.instances.map(s => ({
name: Fuzzy.prepare(s.name),
flavour: Fuzzy.prepare(s.flavour),
scheme: s
}))
function fuzzyQuery(search: string): var {
return Fuzzy.go(search.slice(`${Config.launcher.actionPrefix}scheme `.length), preppedActions, {
all: true,
keys: ["name", "flavour"],
scoreFn: r => r[0].score > 0 ? r[0].score * 0.9 + r[1].score * 0.1 : 0
}).map(r => r.obj.scheme);
}
Variants {
id: schemes
Scheme {}
}
Process {
id: getSchemes
running: true
command: ["caelestia", "scheme", "list"]
stdout: StdioCollector {
onStreamFinished: {
const schemeData = JSON.parse(text);
const list = Object.entries(schemeData).map(([name, f]) => Object.entries(f).map(([flavour, colours]) => ({
name,
flavour,
colours
})));
const flat = [];
for (const s of list)
for (const f of s)
flat.push(f);
schemes.model = flat;
}
}
}
component Scheme: QtObject {
required property var modelData
readonly property string name: modelData.name
readonly property string flavour: modelData.flavour
readonly property var colours: modelData.colours
function onClicked(list: AppList): void {
Quickshell.execDetached(["caelestia", "scheme", "set", "-n", name, "-f", flavour]);
list.visibilities.launcher = false;
}
}
}