Weather: Made the weather effects conditional with a new setting.

This commit is contained in:
ItsLemmy
2025-11-19 08:05:33 -05:00
parent 17810d1d2f
commit 1b4cd35504
14 changed files with 89 additions and 32 deletions
@@ -1,6 +1,6 @@
import QtQuick
import QtQuick.Layouts
import QtQuick.Effects
import QtQuick.Layouts
import Quickshell
import qs.Commons
import qs.Services.Location
@@ -12,51 +12,58 @@ NBox {
property int forecastDays: 6
property bool showLocation: true
property bool showEffects: Settings.data.location.weatherShowEffects
readonly property bool weatherReady: Settings.data.location.weatherEnabled && (LocationService.data.weather !== null)
// Test mode: set to "rain" or "snow"
property string testWeatherEffect: ""
property string testEffects: ""
// Weather condition detection
readonly property int currentWeatherCode: weatherReady ? LocationService.data.weather.current_weather.weathercode : 0
readonly property bool isRaining: testWeatherEffect === "rain" || (testWeatherEffect === "" && currentWeatherCode >= 51 && currentWeatherCode <= 67)
readonly property bool isSnowing: testWeatherEffect === "snow" || (testWeatherEffect === "" && ((currentWeatherCode >= 71 && currentWeatherCode <= 77) || (currentWeatherCode >= 85 && currentWeatherCode <= 86)))
// Animated time for shaders
property real shaderTime: 0
NumberAnimation on shaderTime {
running: root.isRaining || root.isSnowing
loops: Animation.Infinite
from: 0
to: 1000
duration: 100000
}
readonly property bool isRaining: testEffects === "rain" || (testEffects === "" && currentWeatherCode >= 51 && currentWeatherCode <= 67)
readonly property bool isSnowing: testEffects === "snow" || (testEffects === "" && ((currentWeatherCode >= 71 && currentWeatherCode <= 77) || (currentWeatherCode >= 85 && currentWeatherCode <= 86)))
visible: Settings.data.location.weatherEnabled
implicitHeight: Math.max(100 * Style.uiScaleRatio, content.implicitHeight + (Style.marginXL * 2))
// Weather effect layer (rain/snow)
ShaderEffect {
id: weatherEffect
Loader {
id: weatherEffectLoader
anchors.fill: parent
// Snow fills the box, rain matches content margins
anchors.margins: root.isSnowing ? root.border.width : Style.marginXL
visible: root.isRaining || root.isSnowing
active: root.showEffects && (root.isRaining || root.isSnowing)
property var source: ShaderEffectSource {
sourceItem: content
hideSource: root.isRaining // Only hide for rain (distortion), show for snow
sourceComponent: Item {
anchors.fill: parent
// Animated time for shaders
property real shaderTime: 0
NumberAnimation on shaderTime {
loops: Animation.Infinite
from: 0
to: 1000
duration: 100000
}
ShaderEffect {
id: weatherEffect
anchors.fill: parent
// Snow fills the box, rain matches content margins
anchors.margins: root.isSnowing ? root.border.width : Style.marginXL
property var source: ShaderEffectSource {
sourceItem: content
hideSource: root.isRaining // Only hide for rain (distortion), show for snow
}
property real time: parent.shaderTime
property real itemWidth: weatherEffect.width
property real itemHeight: weatherEffect.height
property color bgColor: root.color
property real cornerRadius: root.isSnowing ? (root.radius - root.border.width) : 0
fragmentShader: root.isSnowing ? Qt.resolvedUrl(Quickshell.shellDir + "/Shaders/qsb/weather_snow.frag.qsb") : Qt.resolvedUrl(Quickshell.shellDir + "/Shaders/qsb/weather_rain.frag.qsb")
}
}
property real time: root.shaderTime
property real itemWidth: weatherEffect.width
property real itemHeight: weatherEffect.height
property color bgColor: root.color
property real cornerRadius: root.isSnowing ? (root.radius - root.border.width) : 0
fragmentShader: root.isSnowing ?
Qt.resolvedUrl(Quickshell.shellDir + "/Shaders/qsb/weather_snow.frag.qsb") :
Qt.resolvedUrl(Quickshell.shellDir + "/Shaders/qsb/weather_rain.frag.qsb")
}
ColumnLayout {