working carousel

This commit is contained in:
ari committed 2026-09-11 14:43:36 -04:00
1 parent 7d58533539
commit eb0dc429da
7 files changed
+109 -66

No files matched your search

-9
View File
@@ -1,9 +0,0 @@
import QtQuick
import Quickshell.Io
JsonObject {
property string name
property string image
property bool isIcon: false
property list<string> exec
}
+24 -22
View File
@@ -6,10 +6,10 @@ Rectangle {
id: root
required property var theme
required property App app
required property var app
required property bool selected
signal activated()
signal activated
width: theme.cardWidth
height: theme.cardHeight
@@ -20,26 +20,28 @@ Rectangle {
clip: true
ColumnLayout {
spacing: 10
width: root.theme.cardWidth
height: root.theme.cardHeight
anchors.fill: parent
anchors.margins: root.theme.cardPadding
Image {
fillMode: Image.PreserveAspectFit
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
Layout.fillHeight: true
source: root.app.isIcon ? Quickshell.iconPath(root.app.image) : root.app.image
}
Text {
id: label
elide: Text.ElideRight
color: root.theme.textColor
text: root.app.name
font.pixelSize: root.theme.fontSize
Layout.alignment: Qt.AlignHCenter
}
spacing: 10
width: root.theme.cardWidth
height: root.theme.cardHeight
anchors.fill: parent
anchors.margins: root.theme.cardPadding
Image {
fillMode: Image.PreserveAspectFit
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
Layout.fillHeight: true
source: root.app.isIcon ? Quickshell.iconPath(root.app.image) : root.app.image
sourceSize.width: root.app.isIcon ? root.app.dims[0] : undefined
sourceSize.height: root.app.isIcon ? root.app.dims[1] : undefined
}
Text {
id: label
elide: Text.ElideRight
color: root.theme.textColor
text: root.app.name
font.pixelSize: root.theme.fontSize
Layout.alignment: Qt.AlignHCenter
}
}
MouseArea {
+52
View File
@@ -0,0 +1,52 @@
import QtQuick
import Quickshell.Io
import Quickshell
Item {
id: root
readonly property string appConfigPath: Quickshell.env("SKYG_APP_CAROUSEL")
property list<var> appConfig: []
FileView {
id: configFile
path: root.appConfigPath
watchChanges: true
onFileChanged: configFile.reload()
onLoaded: {
let parsed = JSON.parse(configFile.text());
if (!Array.isArray(parsed)) {
throw new Error(`Invalid app config: expected a JSON array, got ${typeof parsed}`);
}
for (const elm of parsed) {
if (!(typeof elm.name == 'string')) {
throw new Error(`Invalid app config: expected name to be a string, got ${typeof elm.name}`);
}
if (!(typeof elm.image == 'string')) {
throw new Error(`Invalid app config: expected image to be a string, got ${typeof elm.image}`);
}
if (elm.isIcon !== undefined && typeof elm.isIcon !== 'boolean') {
throw new Error(`Invalid app config: expected isIcon to be a boolean, got ${typeof elm.isIcon}`);
}
if (elm.dims !== undefined) {
if (!elm.isIcon) {
throw new Error(`Invalid app config: dims is only allowed when isIcon is true`);
}
if (!Array.isArray(elm.dims) || elm.dims.length !== 2 || !elm.dims.every(n => Number.isInteger(n))) {
throw new Error(`Invalid app config: expected dims to be a tuple of 2 ints`);
}
} else {
elm.dims = [100, 100];
}
if (!Array.isArray(elm.exec) || elm.exec.length === 0) {
throw new Error(`Invalid app config: expected exec to be a non-empty array, got ${typeof elm.exec}`);
}
if (!elm.exec.every(arg => typeof arg === 'string')) {
throw new Error(`Invalid app config: expected all exec entries to be strings`);
}
}
console.log("Loaded Config", configFile.__data);
root.appConfig = parsed;
}
}
}
-7
View File
@@ -1,7 +0,0 @@
pragma Singleton
import QtQuick
import Quickshell
QtObject {
readonly property string appConfigPath: Quickshell.env("SKYG_APP_CAROUSEL")
}
+30 -13
View File
@@ -7,9 +7,9 @@ PanelWindow {
id: root
required property bool shellOpen
required property list<App> apps
required property list<var> apps
signal requestClose()
signal requestClose
visible: root.shellOpen
@@ -34,19 +34,26 @@ PanelWindow {
readonly property int centerIndex: root.selectedIndex
function clampSelection() {
if (root.apps.length === 0) return;
if (root.selectedIndex >= root.apps.length) root.selectedIndex = root.apps.length - 1;
if (root.selectedIndex < 0) root.selectedIndex = 0;
if (root.apps.length === 0)
return;
if (root.selectedIndex >= root.apps.length)
root.selectedIndex = root.apps.length - 1;
if (root.selectedIndex < 0)
root.selectedIndex = 0;
}
function moveSelection(delta) {
if (root.apps.length === 0) return;
if (root.apps.length === 0)
return;
root.selectedIndex = (root.selectedIndex + delta + root.apps.length) % root.apps.length;
}
function activateSelection() {
const app = root.apps[root.selectedIndex];
if (!app) { root.requestClose(); return; }
if (!app) {
root.requestClose();
return;
}
Quickshell.execDetached(app.exec);
root.requestClose();
}
@@ -62,7 +69,8 @@ PanelWindow {
windows: [root]
active: root.visible
onCleared: {
if (root.visible) root.requestClose();
if (root.visible)
root.requestClose();
}
}
@@ -117,8 +125,10 @@ PanelWindow {
const ang = event.angleDelta;
const dx = px.x !== 0 ? px.x : ang.x;
swipeHandler.accX += dx;
if (swipeHandler.accX <= -root.theme.swipeThreshold) swipeHandler.step(1);
else if (swipeHandler.accX >= root.theme.swipeThreshold) swipeHandler.step(-1);
if (swipeHandler.accX <= -root.theme.swipeThreshold)
swipeHandler.step(1);
else if (swipeHandler.accX >= root.theme.swipeThreshold)
swipeHandler.step(-1);
}
}
@@ -143,13 +153,20 @@ PanelWindow {
scale: 1 - Math.min(Math.abs(index - root.centerIndex) * root.theme.carouselScaleStep, root.theme.carouselMaxScaleReduction)
Behavior on anchors.horizontalCenterOffset {
NumberAnimation { duration: root.theme.carouselDuration; easing.type: Easing.OutCubic }
NumberAnimation {
duration: root.theme.carouselDuration
easing.type: Easing.OutCubic
}
}
Behavior on opacity {
NumberAnimation { duration: root.theme.carouselDuration }
NumberAnimation {
duration: root.theme.carouselDuration
}
}
Behavior on scale {
NumberAnimation { duration: root.theme.carouselDuration }
NumberAnimation {
duration: root.theme.carouselDuration
}
}
onActivated: {
+1 -2
View File
@@ -1,5 +1,4 @@
singleton Config 1.0 Config.qml
App 1.0 App.qml
AppConfig 1.0 AppConfig.qml
AppButton 1.0 AppButton.qml
LauncherWindow 1.0 LauncherWindow.qml
Theme 1.0 Theme.qml
+2 -13
View File
@@ -6,18 +6,7 @@ ShellRoot {
id: shell
property bool launcherOpen: true
property var appConfig: []
FileView {
id: configFile
path: Config.appConfigPath
watchChanges: true
onFileChanged: reload()
onLoaded: {
shell.appConfig = JSON.parse(configFile.text());
console.log("here", configFile.__data);
}
}
property AppConfig config: AppConfig {}
IpcHandler {
target: "launcher"
@@ -36,6 +25,6 @@ ShellRoot {
LauncherWindow {
shellOpen: shell.launcherOpen
onRequestClose: shell.launcherOpen = false
apps: shell.appConfig
apps: shell.config.appConfig
}
}