feat: impl scheme launcher action
This commit is contained in:
parent
2a6cc10cfa
commit
2dbec4489e
5 changed files with 227 additions and 44 deletions
|
|
@ -175,7 +175,6 @@ Singleton {
|
|||
required property string desc
|
||||
required property string icon
|
||||
property bool disabled
|
||||
property string disabledReason
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,16 @@ import QtQuick.Controls
|
|||
ListView {
|
||||
id: root
|
||||
|
||||
required property int padding
|
||||
required property TextField search
|
||||
required property PersistentProperties visibilities
|
||||
|
||||
property bool isAction: search.text.startsWith(Config.launcher.actionPrefix)
|
||||
property bool isScheme: search.text.startsWith(`${Config.launcher.actionPrefix}scheme `)
|
||||
|
||||
function getModelValues() {
|
||||
let text = search.text;
|
||||
if (isScheme)
|
||||
return Schemes.fuzzyQuery(text);
|
||||
if (isAction)
|
||||
return Actions.fuzzyQuery(text);
|
||||
if (text.startsWith(Config.launcher.actionPrefix))
|
||||
|
|
@ -43,7 +45,13 @@ ListView {
|
|||
opacity: 0.08
|
||||
}
|
||||
|
||||
delegate: isAction ? actionItem : appItem
|
||||
delegate: {
|
||||
if (isScheme)
|
||||
return schemeItem;
|
||||
if (isAction)
|
||||
return actionItem;
|
||||
return appItem;
|
||||
}
|
||||
|
||||
ScrollBar.vertical: StyledScrollBar {}
|
||||
|
||||
|
|
@ -110,44 +118,58 @@ ListView {
|
|||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: schemeItem
|
||||
|
||||
SchemeItem {
|
||||
visibilities: root.visibilities
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on isAction {
|
||||
SequentialAnimation {
|
||||
ParallelAnimation {
|
||||
Anim {
|
||||
target: root
|
||||
property: "opacity"
|
||||
from: 1
|
||||
to: 0
|
||||
duration: Appearance.anim.durations.small
|
||||
easing.bezierCurve: Appearance.anim.curves.standardAccel
|
||||
}
|
||||
Anim {
|
||||
target: root
|
||||
property: "scale"
|
||||
from: 1
|
||||
to: 0.9
|
||||
duration: Appearance.anim.durations.small
|
||||
easing.bezierCurve: Appearance.anim.curves.standardAccel
|
||||
}
|
||||
ChangeAnim {}
|
||||
}
|
||||
|
||||
Behavior on isScheme {
|
||||
ChangeAnim {}
|
||||
}
|
||||
|
||||
component ChangeAnim: SequentialAnimation {
|
||||
ParallelAnimation {
|
||||
Anim {
|
||||
target: root
|
||||
property: "opacity"
|
||||
from: 1
|
||||
to: 0
|
||||
duration: Appearance.anim.durations.small
|
||||
easing.bezierCurve: Appearance.anim.curves.standardAccel
|
||||
}
|
||||
PropertyAction {}
|
||||
ParallelAnimation {
|
||||
Anim {
|
||||
target: root
|
||||
property: "opacity"
|
||||
from: 0
|
||||
to: 1
|
||||
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
|
||||
}
|
||||
Anim {
|
||||
target: root
|
||||
property: "scale"
|
||||
from: 1
|
||||
to: 0.9
|
||||
duration: Appearance.anim.durations.small
|
||||
easing.bezierCurve: Appearance.anim.curves.standardAccel
|
||||
}
|
||||
}
|
||||
PropertyAction {}
|
||||
ParallelAnimation {
|
||||
Anim {
|
||||
target: root
|
||||
property: "opacity"
|
||||
from: 0
|
||||
to: 1
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ Item {
|
|||
required property int padding
|
||||
required property int rounding
|
||||
|
||||
property bool showWallpapers: search.text.startsWith(`${Config.launcher.actionPrefix}wallpaper `)
|
||||
property var currentList: (showWallpapers ? wallpaperList : appList).item
|
||||
readonly property bool showWallpapers: search.text.startsWith(`${Config.launcher.actionPrefix}wallpaper `)
|
||||
property var currentList
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: parent.bottom
|
||||
|
|
@ -29,8 +29,9 @@ Item {
|
|||
name: "apps"
|
||||
|
||||
PropertyChanges {
|
||||
root.currentList: appList.item
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +44,8 @@ Item {
|
|||
name: "wallpapers"
|
||||
|
||||
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
|
||||
wallpaperList.active: true
|
||||
}
|
||||
|
|
@ -96,7 +98,6 @@ Item {
|
|||
anchors.right: parent.right
|
||||
|
||||
sourceComponent: AppList {
|
||||
padding: root.padding
|
||||
search: root.search
|
||||
visibilities: root.visibilities
|
||||
}
|
||||
|
|
|
|||
94
modules/launcher/SchemeItem.qml
Normal file
94
modules/launcher/SchemeItem.qml
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
67
modules/launcher/Schemes.qml
Normal file
67
modules/launcher/Schemes.qml
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue