From 99e890cc179ff6804ce6de6df0a6ad8ef0121d18 Mon Sep 17 00:00:00 2001 From: bbedward Date: Mon, 28 Jul 2025 15:31:27 -0400 Subject: [PATCH] ipc for light/dark mode --- Common/Prefs.qml | 26 ++++++++++++++++++++++++++ README.md | 4 ++++ Widgets/DankListView.qml | 21 ++++++++++----------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Common/Prefs.qml b/Common/Prefs.qml index 095eb3ad..3e77fd38 100644 --- a/Common/Prefs.qml +++ b/Common/Prefs.qml @@ -218,6 +218,9 @@ Singleton { function setLightMode(lightMode) { isLightMode = lightMode; + if (typeof Theme !== "undefined") { + Theme.isLightMode = lightMode; + } saveSettings(); } @@ -740,4 +743,27 @@ Singleton { return "SUCCESS: Wallpaper cleared" } } + + IpcHandler { + target: "theme" + + function toggle(): string { + root.setLightMode(!root.isLightMode) + return root.isLightMode ? "light" : "dark" + } + + function light(): string { + root.setLightMode(true) + return "light" + } + + function dark(): string { + root.setLightMode(false) + return "dark" + } + + function get(): string { + return root.isLightMode ? "light" : "dark" + } + } } diff --git a/README.md b/README.md index dedbcca5..ee318a82 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,10 @@ qs -c DankMaterialShell ipc call | wallpaper | get | none | Get current wallpaper path | | wallpaper | set | path (string) | Set wallpaper to image path and refresh theme | | wallpaper | clear | none | Clear current wallpaper | +| theme | get | none | Get current theme mode (light/dark) | +| theme | toggle | none | Toggle between light and dark mode | +| theme | light | none | Set theme to light mode | +| theme | dark | none | Set theme to dark mode | | notifs | clear | none | Clear all notifications | diff --git a/Widgets/DankListView.qml b/Widgets/DankListView.qml index 5c3734de..df10dbe2 100644 --- a/Widgets/DankListView.qml +++ b/Widgets/DankListView.qml @@ -7,7 +7,6 @@ import qs.Common ListView { id: listView - property int currentIndex: 0 property int itemHeight: 72 property int iconSize: 56 property bool showDescription: true @@ -23,15 +22,15 @@ ListView { // Ensure the current item is visible function ensureVisible(index) { - if (index < 0 || index >= listView.count) + if (index < 0 || index >= count) return ; var itemY = index * (itemHeight + itemSpacing); var itemBottom = itemY + itemHeight; - if (itemY < listView.contentY) - listView.contentY = itemY; - else if (itemBottom > listView.contentY + listView.height) - listView.contentY = itemBottom - listView.height; + if (itemY < contentY) + contentY = itemY; + else if (itemBottom > contentY + height) + contentY = itemBottom - height; } onCurrentIndexChanged: { @@ -50,12 +49,12 @@ ListView { WheelHandler { target: null onWheel: (ev) => { - let dy = ev.pixelDelta.y !== 0 ? ev.pixelDelta.y : (ev.angleDelta.y / 120) * listView.wheelBaseStep; + let dy = ev.pixelDelta.y !== 0 ? ev.pixelDelta.y : (ev.angleDelta.y / 120) * wheelBaseStep; if (ev.inverted) dy = -dy; - const maxY = Math.max(0, listView.contentHeight - listView.height); - listView.contentY = Math.max(0, Math.min(maxY, listView.contentY - dy * listView.wheelMultiplier)); + const maxY = Math.max(0, contentHeight - height); + contentY = Math.max(0, Math.min(maxY, contentY - dy * wheelMultiplier)); ev.accepted = true; } } @@ -69,7 +68,7 @@ ListView { } delegate: Rectangle { - width: listView.width + width: ListView.view.width height: itemHeight radius: Theme.cornerRadiusLarge color: ListView.isCurrentItem ? Theme.primaryPressed : mouseArea.containsMouse ? Theme.primaryHoverLight : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.03) @@ -152,7 +151,7 @@ ListView { z: 10 onEntered: { if (hoverUpdatesSelection && !keyboardNavigationActive) - listView.currentIndex = index; + currentIndex = index; itemHovered(index); }