From b391d0396764357edd5fde57c54af1d6c804fd16 Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Fri, 3 Oct 2025 13:13:40 +0200 Subject: [PATCH] Background: revert to old version which fixed the RAM issue Overview: only load if niri event-stream emits overview active --- Assets/Matugen/Matugen.qml | 138 +++++++++++++++--------------- Modules/Background/Background.qml | 50 ++++++----- Modules/Background/Overview.qml | 4 +- Services/CompositorService.qml | 13 +++ Services/NiriService.qml | 12 +++ 5 files changed, 126 insertions(+), 91 deletions(-) diff --git a/Assets/Matugen/Matugen.qml b/Assets/Matugen/Matugen.qml index 7732b949..ce33471e 100644 --- a/Assets/Matugen/Matugen.qml +++ b/Assets/Matugen/Matugen.qml @@ -9,76 +9,76 @@ import qs.Commons // - Assets/Matugen/templates/ // - ~/.config/matugen/ (when enableUserTemplates is true) Singleton { - id: root + id: root - // Build the base TOML using current settings - function buildConfigToml() { - var lines = []; - lines.push("[config]"); - var mode = Settings.data.colorSchemes.darkMode ? "dark" : "light"; - // Always include noctalia colors output for the shell - lines.push("[templates.noctalia]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/noctalia.json"'); - lines.push('output_path = "' + Settings.configDir + 'colors.json"'); + // Build the base TOML using current settings + function buildConfigToml() { + var lines = [] + lines.push("[config]") + var mode = Settings.data.colorSchemes.darkMode ? "dark" : "light" + // Always include noctalia colors output for the shell + lines.push("[templates.noctalia]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/noctalia.json"') + lines.push('output_path = "' + Settings.configDir + 'colors.json"') - if (Settings.data.matugen.gtk4) { - lines.push("\n[templates.gtk4]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/gtk4.css"'); - lines.push('output_path = "~/.config/gtk-4.0/gtk.css"'); - lines.push("post_hook = 'gsettings set org.gnome.desktop.interface color-scheme prefer-" + mode + "'"); - } - if (Settings.data.matugen.gtk3) { - lines.push("\n[templates.gtk3]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/gtk3.css"'); - lines.push('output_path = "~/.config/gtk-3.0/gtk.css"'); - lines.push("post_hook = 'gsettings set org.gnome.desktop.interface color-scheme prefer-" + mode + "'"); - } - if (Settings.data.matugen.qt6) { - lines.push("\n[templates.qt6]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/qtct.conf"'); - lines.push('output_path = "~/.config/qt6ct/colors/noctalia.conf"'); - } - if (Settings.data.matugen.qt5) { - lines.push("\n[templates.qt5]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/qtct.conf"'); - lines.push('output_path = "~/.config/qt5ct/colors/noctalia.conf"'); - } - if (Settings.data.matugen.kitty) { - lines.push("\n[templates.kitty]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/kitty.conf"'); - lines.push('output_path = "~/.config/kitty/themes/noctalia.conf"'); - lines.push("post_hook = 'kitty +kitten themes --reload-in=all noctalia'"); - } - if (Settings.data.matugen.ghostty) { - lines.push("\n[templates.ghostty]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/ghostty.conf"'); - lines.push('output_path = "~/.config/ghostty/themes/noctalia"'); - lines.push("post_hook = \"grep -q '^theme *= *' ~/.config/ghostty/config; and sed -i 's/^theme *= *.*/theme = noctalia/' ~/.config/ghostty/config; or echo 'theme = noctalia' >> ~/.config/ghostty/config; and pkill -SIGUSR2 ghostty\""); - } - if (Settings.data.matugen.foot) { - lines.push("\n[templates.foot]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/foot.conf"'); - lines.push('output_path = "~/.config/foot/themes/noctalia"'); - lines.push('post_hook = "sed -i /themes/d ~/.config/foot/foot.ini && echo include=~/.config/foot/themes/noctalia >> ~/.config/foot/foot.ini"'); - } - if (Settings.data.matugen.fuzzel) { - lines.push("\n[templates.fuzzel]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/fuzzel.conf"'); - lines.push('output_path = "~/.config/fuzzel/themes/noctalia"'); - lines.push('post_hook = "sed -i /themes/d ~/.config/fuzzel/fuzzel.ini && echo include=~/.config/fuzzel/themes/noctalia >> ~/.config/fuzzel/fuzzel.ini"'); - } - if (Settings.data.matugen.vesktop) { - lines.push("\n[templates.vesktop]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/vesktop.css"'); - lines.push('output_path = "~/.config/vesktop/themes/noctalia.theme.css"'); - } - if (Settings.data.matugen.pywalfox) { - lines.push("\n[templates.pywalfox]"); - lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/pywalfox.json"'); - lines.push('output_path = "~/.cache/wal/colors.json"'); - lines.push('post_hook = "pywalfox update"'); - } - - return lines.join("\n") + "\n"; + if (Settings.data.matugen.gtk4) { + lines.push("\n[templates.gtk4]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/gtk4.css"') + lines.push('output_path = "~/.config/gtk-4.0/gtk.css"') + lines.push("post_hook = 'gsettings set org.gnome.desktop.interface color-scheme prefer-" + mode + "'") } + if (Settings.data.matugen.gtk3) { + lines.push("\n[templates.gtk3]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/gtk3.css"') + lines.push('output_path = "~/.config/gtk-3.0/gtk.css"') + lines.push("post_hook = 'gsettings set org.gnome.desktop.interface color-scheme prefer-" + mode + "'") + } + if (Settings.data.matugen.qt6) { + lines.push("\n[templates.qt6]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/qtct.conf"') + lines.push('output_path = "~/.config/qt6ct/colors/noctalia.conf"') + } + if (Settings.data.matugen.qt5) { + lines.push("\n[templates.qt5]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/qtct.conf"') + lines.push('output_path = "~/.config/qt5ct/colors/noctalia.conf"') + } + if (Settings.data.matugen.kitty) { + lines.push("\n[templates.kitty]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/kitty.conf"') + lines.push('output_path = "~/.config/kitty/themes/noctalia.conf"') + lines.push("post_hook = 'kitty +kitten themes --reload-in=all noctalia'") + } + if (Settings.data.matugen.ghostty) { + lines.push("\n[templates.ghostty]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/ghostty.conf"') + lines.push('output_path = "~/.config/ghostty/themes/noctalia"') + lines.push("post_hook = \"grep -q '^theme *= *' ~/.config/ghostty/config; and sed -i 's/^theme *= *.*/theme = noctalia/' ~/.config/ghostty/config; or echo 'theme = noctalia' >> ~/.config/ghostty/config; and pkill -SIGUSR2 ghostty\"") + } + if (Settings.data.matugen.foot) { + lines.push("\n[templates.foot]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/foot.conf"') + lines.push('output_path = "~/.config/foot/themes/noctalia"') + lines.push('post_hook = "sed -i /themes/d ~/.config/foot/foot.ini && echo include=~/.config/foot/themes/noctalia >> ~/.config/foot/foot.ini"') + } + if (Settings.data.matugen.fuzzel) { + lines.push("\n[templates.fuzzel]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/fuzzel.conf"') + lines.push('output_path = "~/.config/fuzzel/themes/noctalia"') + lines.push('post_hook = "sed -i /themes/d ~/.config/fuzzel/fuzzel.ini && echo include=~/.config/fuzzel/themes/noctalia >> ~/.config/fuzzel/fuzzel.ini"') + } + if (Settings.data.matugen.vesktop) { + lines.push("\n[templates.vesktop]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/vesktop.css"') + lines.push('output_path = "~/.config/vesktop/themes/noctalia.theme.css"') + } + if (Settings.data.matugen.pywalfox) { + lines.push("\n[templates.pywalfox]") + lines.push('input_path = "' + Quickshell.shellDir + '/Assets/Matugen/templates/pywalfox.json"') + lines.push('output_path = "~/.cache/wal/colors.json"') + lines.push('post_hook = "pywalfox update"') + } + + return lines.join("\n") + "\n" + } } diff --git a/Modules/Background/Background.qml b/Modules/Background/Background.qml index f40bcd8d..fefdcc6a 100644 --- a/Modules/Background/Background.qml +++ b/Modules/Background/Background.qml @@ -13,7 +13,7 @@ Variants { required property ShellScreen modelData - active: modelData && Settings.data.wallpaper.enabled + active: Settings.isLoaded && modelData && Settings.data.wallpaper.enabled sourceComponent: PanelWindow { id: root @@ -41,10 +41,29 @@ Variants { property string futureWallpaper: "" // Fillmode default is "crop" - property real fillMode: WallpaperService.getFillModeUniform() + property real fillMode: 1.0 property vector4d fillColor: Qt.vector4d(Settings.data.wallpaper.fillColor.r, Settings.data.wallpaper.fillColor.g, Settings.data.wallpaper.fillColor.b, 1.0) - Component.onCompleted: setWallpaperInitial() + // On startup, defer assigning wallpaper until the service cache is ready + function _startWallpaperOnceReady() { + if (!modelData) { + Qt.callLater(_startWallpaperOnceReady) + return + } + + var cacheReady = WallpaperService && WallpaperService.currentWallpapers && Object.keys(WallpaperService.currentWallpapers).length > 0 + if (!cacheReady) { + // Try again on the next tick until WallpaperService.init() populates cache + Qt.callLater(_startWallpaperOnceReady) + return + } + + fillMode = WallpaperService.getFillModeUniform() + var path = WallpaperService.getWallpaper(modelData.name) + setWallpaperImmediate(path) + } + + Component.onCompleted: _startWallpaperOnceReady() Connections { target: Settings.data.wallpaper @@ -58,6 +77,7 @@ Variants { target: WallpaperService function onWallpaperChanged(screenName, path) { if (screenName === modelData.name) { + // Update wallpaper display // Set wallpaper immediately on startup futureWallpaper = path @@ -223,7 +243,9 @@ Variants { easing.type: Easing.InOutCubic onFinished: { // Swap images after transition completes - currentWallpaper.source = "" + if (currentWallpaper.source !== "") { + currentWallpaper.source = "" + } currentWallpaper.source = nextWallpaper.source nextWallpaper.source = "" transitionProgress = 0.0 @@ -233,20 +255,12 @@ Variants { } } - function setWallpaperInitial() { - // On startup, defer assigning wallpaper until the service cache is ready, retries every tick - if (!WallpaperService || !WallpaperService.isInitialized) { - Qt.callLater(setWallpaperInitial) - return - } - - setWallpaperImmediate(WallpaperService.getWallpaper(modelData.name)) - } - function setWallpaperImmediate(source) { transitionAnimation.stop() transitionProgress = 0.0 - currentWallpaper.source = "" + if (currentWallpaper.source !== "") { + currentWallpaper.source = "" + } currentWallpaper.source = source nextWallpaper.source = "" } @@ -260,12 +274,8 @@ Variants { // We are interrupting a transition transitionAnimation.stop() transitionProgress = 0 - - const newCurrentSource = nextWallpaper.source - currentWallpaper.source = "" + currentWallpaper.source = nextWallpaper.source nextWallpaper.source = "" - - currentWallpaper.source = newCurrentSource } nextWallpaper.source = source diff --git a/Modules/Background/Overview.qml b/Modules/Background/Overview.qml index b471174e..ffb7e673 100644 --- a/Modules/Background/Overview.qml +++ b/Modules/Background/Overview.qml @@ -12,7 +12,7 @@ Variants { delegate: Loader { required property ShellScreen modelData - active: CompositorService.isNiri && modelData && Settings.data.wallpaper.enabled + active: CompositorService.isNiri && CompositorService.niriOverviewActive && modelData && Settings.data.wallpaper.enabled property string wallpaper: "" @@ -37,7 +37,7 @@ Variants { } } } - + Connections { target: WallpaperService function onIsInitializedChanged() { diff --git a/Services/CompositorService.qml b/Services/CompositorService.qml index 4d30421c..32c0a42d 100644 --- a/Services/CompositorService.qml +++ b/Services/CompositorService.qml @@ -17,6 +17,9 @@ Singleton { property ListModel windows: ListModel {} property int focusedWindowIndex: -1 + // Niri-specific properties + property bool niriOverviewActive: false + // Generic events signal workspaceChanged signal activeWindowChanged @@ -102,10 +105,20 @@ Singleton { focusedWindowIndex = backend.focusedWindowIndex }) + // Niri-specific property bindings + if (isNiri && backend.overviewActiveChanged) { + backend.overviewActiveChanged.connect(() => { + niriOverviewActive = backend.overviewActive + }) + } + // Initial sync syncWorkspaces() syncWindows() focusedWindowIndex = backend.focusedWindowIndex + if (isNiri && backend.overviewActive !== undefined) { + niriOverviewActive = backend.overviewActive + } } function syncWorkspaces() { diff --git a/Services/NiriService.qml b/Services/NiriService.qml index ef525bb8..d122fdca 100644 --- a/Services/NiriService.qml +++ b/Services/NiriService.qml @@ -13,6 +13,7 @@ Item { property ListModel workspaces: ListModel {} property var windows: [] property int focusedWindowIndex: -1 + property bool overviewActive: false // Signals that match the facade interface signal workspaceChanged @@ -127,6 +128,8 @@ Item { handleWindowFocusChanged(event.WindowFocusChanged) } else if (event.WindowLayoutsChanged) { handleWindowLayoutsChanged(event.WindowLayoutsChanged) + } else if (event.OverviewOpenedOrClosed) { + handleOverviewOpenedOrClosed(event.OverviewOpenedOrClosed) } } catch (e) { Logger.error("NiriService", "Error parsing event stream:", e, data) @@ -318,6 +321,15 @@ Item { } } + function handleOverviewOpenedOrClosed(eventData) { + try { + overviewActive = eventData.is_open + Logger.log("NiriService", "Overview opened or closed:", eventData.is_open) + } catch (e) { + Logger.error("NiriService", "Error handling OverviewOpenedOrClosed:", e) + } + } + // Public functions function switchToWorkspace(workspaceId) { try {