From f9d8a7d22b61260e18b9a5a4e055776b30e516c3 Mon Sep 17 00:00:00 2001 From: bbedward Date: Mon, 8 Dec 2025 13:45:26 -0500 Subject: [PATCH] greeter: fix weather setting fixes #921 --- quickshell/Modules/Greetd/GreeterContent.qml | 57 +++++++++++++------- quickshell/Services/WeatherService.qml | 39 +++++++------- 2 files changed, 60 insertions(+), 36 deletions(-) diff --git a/quickshell/Modules/Greetd/GreeterContent.qml b/quickshell/Modules/Greetd/GreeterContent.qml index 60eac61e..9541bb1a 100644 --- a/quickshell/Modules/Greetd/GreeterContent.qml +++ b/quickshell/Modules/Greetd/GreeterContent.qml @@ -4,6 +4,7 @@ import QtQuick.Controls import QtQuick.Effects import QtQuick.Layouts import Quickshell +import Quickshell.Hyprland import Quickshell.Io import Quickshell.Services.Greetd import Quickshell.Services.Pam @@ -35,19 +36,40 @@ Item { randomFact = Facts.getRandomFact() } + property bool weatherInitialized: false + + function initWeatherService() { + if (weatherInitialized) + return + if (!GreetdSettings.settingsLoaded) + return + if (!GreetdSettings.weatherEnabled) + return + + weatherInitialized = true + WeatherService.addRef() + WeatherService.forceRefresh() + } + + Connections { + target: GreetdSettings + function onSettingsLoadedChanged() { + if (GreetdSettings.settingsLoaded) + initWeatherService() + } + } + Component.onCompleted: { pickRandomFact() - WeatherService.addRef() + initWeatherService() if (isPrimaryScreen) { sessionListProc.running = true applyLastSuccessfulUser() } - if (CompositorService.isHyprland) { + if (CompositorService.isHyprland) updateHyprlandLayout() - hyprlandLayoutUpdateTimer.start() - } } function applyLastSuccessfulUser() { @@ -61,10 +83,8 @@ Item { } Component.onDestruction: { - WeatherService.removeRef() - if (CompositorService.isHyprland) { - hyprlandLayoutUpdateTimer.stop() - } + if (weatherInitialized) + WeatherService.removeRef() } function updateHyprlandLayout() { @@ -106,14 +126,15 @@ Item { } } - Timer { - id: hyprlandLayoutUpdateTimer - interval: 1000 - running: false - repeat: true - onTriggered: updateHyprlandLayout() - } + Connections { + target: CompositorService.isHyprland ? Hyprland : null + enabled: CompositorService.isHyprland + function onRawEvent(event) { + if (event.name === "activelayout") + updateHyprlandLayout() + } + } Connections { target: GreetdMemory @@ -750,13 +771,13 @@ Item { visible: { const keyboardVisible = (CompositorService.isNiri && NiriService.keyboardLayoutNames.length > 1) || (CompositorService.isHyprland && hyprlandLayoutCount > 1) - return keyboardVisible && WeatherService.weather.available + return keyboardVisible && GreetdSettings.weatherEnabled && WeatherService.weather.available } } Row { spacing: 6 - visible: WeatherService.weather.available + visible: GreetdSettings.weatherEnabled && WeatherService.weather.available anchors.verticalCenter: parent.verticalCenter DankIcon { @@ -780,7 +801,7 @@ Item { height: 24 color: Qt.rgba(255, 255, 255, 0.2) anchors.verticalCenter: parent.verticalCenter - visible: WeatherService.weather.available && (NetworkService.networkStatus !== "disconnected" || BluetoothService.enabled || (AudioService.sink && AudioService.sink.audio) || BatteryService.batteryAvailable) + visible: GreetdSettings.weatherEnabled && WeatherService.weather.available && (NetworkService.networkStatus !== "disconnected" || BluetoothService.enabled || (AudioService.sink && AudioService.sink.audio) || BatteryService.batteryAvailable) } Row { diff --git a/quickshell/Services/WeatherService.qml b/quickshell/Services/WeatherService.qml index 0263219e..d621b0e3 100644 --- a/quickshell/Services/WeatherService.qml +++ b/quickshell/Services/WeatherService.qml @@ -5,6 +5,7 @@ import QtQuick import Quickshell import Quickshell.Io import qs.Common +import qs.Modules.Greetd import "../Common/suncalc.js" as SunCalc Singleton { @@ -509,27 +510,29 @@ Singleton { } function updateLocation() { - if (SettingsData.useAutoLocation) { + const useAuto = SessionData.isGreeterMode ? GreetdSettings.useAutoLocation : SettingsData.useAutoLocation; + const coords = SessionData.isGreeterMode ? GreetdSettings.weatherCoordinates : SettingsData.weatherCoordinates; + const cityName = SessionData.isGreeterMode ? GreetdSettings.weatherLocation : SettingsData.weatherLocation; + + if (useAuto) { getLocationFromIP(); - } else { - const coords = SettingsData.weatherCoordinates; - if (coords) { - const parts = coords.split(","); - if (parts.length === 2) { - const lat = parseFloat(parts[0]); - const lon = parseFloat(parts[1]); - if (!isNaN(lat) && !isNaN(lon)) { - getLocationFromCoords(lat, lon); - return; - } + return; + } + + if (coords) { + const parts = coords.split(","); + if (parts.length === 2) { + const lat = parseFloat(parts[0]); + const lon = parseFloat(parts[1]); + if (!isNaN(lat) && !isNaN(lon)) { + getLocationFromCoords(lat, lon); + return; } } - - const cityName = SettingsData.weatherLocation; - if (cityName) { - getLocationFromCity(cityName); - } } + + if (cityName) + getLocationFromCity(cityName); } function getLocationFromCoords(lat, lon) { @@ -867,7 +870,7 @@ Singleton { Timer { id: updateTimer interval: nextInterval() - running: root.refCount > 0 && SettingsData.weatherEnabled + running: root.refCount > 0 && SettingsData.weatherEnabled && !SessionData.isGreeterMode repeat: true triggeredOnStart: true onTriggered: {