From d69ec48728b180a47cc98b45b776131424f89ea2 Mon Sep 17 00:00:00 2001 From: lucy Date: Thu, 10 Sep 2026 21:37:33 +0200 Subject: [PATCH] add theme switcher --- Colors.js | 32 ++++++------ modules/Services/State.qml | 29 +++++++++++ modules/applets/ThemeSwitcher.qml | 82 +++++++++++++++++++++++-------- modules/bar/ColorPickerButton.qml | 16 ++++-- modules/overlays/Top.qml | 13 ----- settings/Config.qml | 5 ++ settings/settings.ini | 12 ----- settings/settings.json | 1 + shell.qml | 6 +-- 9 files changed, 127 insertions(+), 69 deletions(-) create mode 100644 modules/Services/State.qml delete mode 100644 settings/settings.ini diff --git a/Colors.js b/Colors.js index 944fd03..8a5de26 100644 --- a/Colors.js +++ b/Colors.js @@ -1,18 +1,18 @@ const colors = { - base00: "#1f2430", - base01: "#242936", - base02: "#323844", - base03: "#4a5059", - base04: "#707a8c", - base05: "#cccac2", - base06: "#d9d7ce", - base07: "#f3f4f5", - base08: "#f28779", - base09: "#ffad66", - base0A: "#ffd173", - base0B: "#d5ff80", - base0C: "#95e6cb", - base0D: "#73d0ff", - base0E: "#d4bfff", - base0F: "#f27983", + base00: "#000000", + base01: "#121212", + base02: "#222222", + base03: "#333333", + base04: "#999999", + base05: "#c1c1c1", + base06: "#999999", + base07: "#c1c1c1", + base08: "#5f8787", + base09: "#aaaaaa", + base0A: "#5f81a5", + base0B: "#d0dfee", + base0C: "#aaaaaa", + base0D: "#888888", + base0E: "#999999", + base0F: "#444444", } diff --git a/modules/Services/State.qml b/modules/Services/State.qml new file mode 100644 index 0000000..8113be0 --- /dev/null +++ b/modules/Services/State.qml @@ -0,0 +1,29 @@ +pragma Singleton + +import Quickshell +import Quickshell.Io +import QtQuick + + +Singleton { + id: root + property alias s: stateAdapter + property alias v: state + FileView { + id: state + path: Qt.resolvedUrl(Quickshell.shellDir + "/settings/state.json") + watchChanges: true + onLoadFailed: { + writeAdapter() + } + onAdapterUpdated: writeAdapter() + onFileChanged: reload() + adapter: JsonAdapter { + id: stateAdapter + property bool themeSwitcherVisible: false + } + + } + Component.onCompleted: console.log("say gex") + +} diff --git a/modules/applets/ThemeSwitcher.qml b/modules/applets/ThemeSwitcher.qml index 886a864..4ddb2e1 100644 --- a/modules/applets/ThemeSwitcher.qml +++ b/modules/applets/ThemeSwitcher.qml @@ -9,14 +9,14 @@ import qs import qs.settings import qs.widgets -Rectangle { - id: root - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.AllButtons - } - clip: true +FloatingWindow { + id: child + implicitWidth: 800 + implicitHeight: 600 + visible: Config.cfg.themeSwitcherVisible color: Colors.base00 + title: "qs-themepicker" + onClosed: Config.cfg.themeSwitcherVisible = false Process { id: getSchemes property list schemes @@ -28,20 +28,62 @@ Rectangle { } } } - ListView { - id: schemeList - orientation: ListView.Horizontal - anchors.fill: root - model: getSchemes.schemes - delegate: Rectangle { - id: container - required property string modelData - color: Colors.base01 - height: 30 - implicitWidth: schemeName.width + 16 + Rectangle { + anchors.fill: child.contentItem + anchors.centerIn: child.contentItem + anchors.margins: 10 + radius: Config.cfg.appearance.rounding / 1.5 + color: Colors.base01 + clip: true + RowLayout { + id: contentLayout + anchors.fill: parent + ListView { + id: schemeList + spacing: 5 + Layout.fillHeight: true + model: getSchemes.schemes + implicitWidth: 300 + delegate: Rectangle { + id: container + required property string modelData + color: Colors.base02 + height: 30 + radius: Config.cfg.appearance.rounding + implicitWidth: 300 + StyledText { + id: schemeName + anchors.centerIn: parent + text: container.modelData + } + MouseArea { + id: schemeSetter + anchors.fill: container + acceptedButtons: Qt.LeftButton + cursorShape: Qt.PointingHandCursor + onClicked: { + setTheme.themeName = modelData; + setTheme.running = true; + } + Process { + id: setTheme + property string themeName + command: ["tinty", "apply", themeName] + } + } + } + } StyledText { - id: schemeName - text: container.modelData + id: currentScheme + text: "" + Process { + id: getCurrentScheme + command: ["tinty", "current"] + running: true + stdout: StdioCollector { + onStreamFinished: currentScheme.text = text + } + } } } } diff --git a/modules/bar/ColorPickerButton.qml b/modules/bar/ColorPickerButton.qml index 99a111a..504a007 100644 --- a/modules/bar/ColorPickerButton.qml +++ b/modules/bar/ColorPickerButton.qml @@ -3,19 +3,25 @@ import qs.widgets import QtQuick import Quickshell import qs.modules.Services +import qs.modules.applets +import qs.settings BarComponent { implicitWidth: text.width required property ShellScreen barScreen StyledText { id: text + anchors.centerIn: parent text: "temp!!!" } MouseArea { - id: clickHandler - acceptedButtons: Qt.LeftButton - cursorShape: Qt.PointingHandCursor - anchors.fill: parent - onClicked: { WidgetTracker.toggle("colorschemes", parent.barScreen) } + id: clickHandler + acceptedButtons: Qt.LeftButton + cursorShape: Qt.PointingHandCursor + anchors.fill: parent + onClicked: { + Config.cfg.themeSwitcherVisible = true + } } + ThemeSwitcher {} } diff --git a/modules/overlays/Top.qml b/modules/overlays/Top.qml index fa0dee0..2514fa7 100644 --- a/modules/overlays/Top.qml +++ b/modules/overlays/Top.qml @@ -114,19 +114,6 @@ Variants { } } } - ThemeSwitcher { - z: 1 - id: colorschemes - property bool shown: WidgetTracker.current === "colorschemes" && root.shown - visible: shown - focus: shown - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - anchors.topMargin: Config.cfg.bar.floating ? Config.cfg.bar.height + 20 : Config.cfg.bar.height + 10 - anchors.margins: 20 - implicitHeight: 60 - } MouseArea { id: dismisser z: 0 diff --git a/settings/Config.qml b/settings/Config.qml index 2ce9e61..19bf913 100644 --- a/settings/Config.qml +++ b/settings/Config.qml @@ -18,12 +18,17 @@ Singleton { onFileChanged: { this.reload(); } + onAdapterUpdated: { + writeAdapter(); + reload(); + } onLoadFailed: error => { if (error === FileViewError.FileNotFound) writeAdapter(); } adapter: JsonAdapter { id: cfg + property bool themeSwitcherVisible: false property JsonObject appearance: JsonObject { property string font: "Iosevka" property int fontSize: 14 diff --git a/settings/settings.ini b/settings/settings.ini deleted file mode 100644 index a93161e..0000000 --- a/settings/settings.ini +++ /dev/null @@ -1,12 +0,0 @@ -[General] -barHeight=30 -floating=false -font=Iosevka -fontSize=14 -iconSize=16 -opacity=1 -primaryMon=eDP-1 -rounding=16 -showCorners=true -wallDir=/home/lucy/.walls/ -wallpaper=/home/lucy/.walls/walkingcastle.png diff --git a/settings/settings.json b/settings/settings.json index ecb7f03..144f624 100644 --- a/settings/settings.json +++ b/settings/settings.json @@ -10,6 +10,7 @@ "height": 34, "opacity": 1 }, + "themeSwitcherVisible": false, "wallpaper": { "wallDir": "/home/lucy/.walls/", "wallpaper": "/home/lucy/.walls/Kita.png" diff --git a/shell.qml b/shell.qml index 2c4fd0c..abe1463 100644 --- a/shell.qml +++ b/shell.qml @@ -9,8 +9,8 @@ import qs.settings import qs.modules.ipc ShellRoot { - Bottom {} - Top {} - Bar {} Ipc {} + Bottom {} + Bar {} + Top {} }