aboutsummaryrefslogtreecommitdiffstats
path: root/config/quickshell/services/MaterialThemeLoader.qml
diff options
context:
space:
mode:
authorKiran George <kirangeorge1995@gmail.com>2025-06-09 11:30:08 +0530
committerKiran George <kirangeorge1995@gmail.com>2025-06-09 11:30:08 +0530
commit952aa63147c9fb28f6ace6f0bc7ccf45ced1299a (patch)
tree306e6d86603a162c00bc5113b56baac0fe7bec7c /config/quickshell/services/MaterialThemeLoader.qml
parent4cf0d0bd5930da76e60f6770de3ee97c10ca7024 (diff)
Overview v2
Diffstat (limited to 'config/quickshell/services/MaterialThemeLoader.qml')
-rw-r--r--config/quickshell/services/MaterialThemeLoader.qml58
1 files changed, 58 insertions, 0 deletions
diff --git a/config/quickshell/services/MaterialThemeLoader.qml b/config/quickshell/services/MaterialThemeLoader.qml
new file mode 100644
index 00000000..cd4eb686
--- /dev/null
+++ b/config/quickshell/services/MaterialThemeLoader.qml
@@ -0,0 +1,58 @@
+pragma Singleton
+pragma ComponentBehavior: Bound
+
+import "root:/modules/common"
+import QtQuick
+import Quickshell
+import Quickshell.Io
+
+/**
+ * Automatically reloads generated material colors.
+ * It is necessary to run reapplyTheme() on startup because Singletons are lazily loaded.
+ */
+Singleton {
+ id: root
+ property string filePath: Directories.generatedMaterialThemePath
+
+ function reapplyTheme() {
+ themeFileView.reload()
+ }
+
+ function applyColors(fileContent) {
+ const json = JSON.parse(fileContent)
+ for (const key in json) {
+ if (json.hasOwnProperty(key)) {
+ // Convert snake_case to CamelCase
+ const camelCaseKey = key.replace(/_([a-z])/g, (g) => g[1].toUpperCase())
+ const m3Key = `m3${camelCaseKey}`
+ Appearance.m3colors[m3Key] = json[key]
+ }
+ }
+
+ Appearance.m3colors.darkmode = (Appearance.m3colors.m3background.hslLightness < 0.5)
+ }
+
+ Timer {
+ id: delayedFileRead
+ interval: ConfigOptions?.hacks?.arbitraryRaceConditionDelay ?? 100
+ repeat: false
+ running: false
+ onTriggered: {
+ root.applyColors(themeFileView.text())
+ }
+ }
+
+ FileView {
+ id: themeFileView
+ path: Qt.resolvedUrl(root.filePath)
+ watchChanges: true
+ onFileChanged: {
+ this.reload()
+ delayedFileRead.start()
+ }
+ onLoadedChanged: {
+ const fileContent = themeFileView.text()
+ root.applyColors(fileContent)
+ }
+ }
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage