pragma ComponentBehavior: Bound import QtQuick import QtQuick.Layouts import Quickshell import Quickshell.Io import "../../components" import "../../services" import "../../theme" // Current conditions from wttr.in, refreshed every 30 minutes. Face { id: root readonly property string location: options.location || "" readonly property bool fahrenheit: !!options.fahrenheit property var current: null property string error: "" function temperature(celsius) { return Math.round(fahrenheit ? celsius * 9 / 5 + 32 : celsius) + "°"; } // WWO weather codes used by wttr.in. function glyph(code) { if (code === 113) return "󰖙"; if (code === 116) return "󰖕"; if (code === 119 || code === 122) return "󰖐"; if ([143, 248, 260].includes(code)) return "󰖑"; if ([200, 386, 389, 392, 395].includes(code)) return "󰖓"; if ([179, 182, 185, 227, 230, 317, 320, 323, 326, 329, 332, 335, 338, 350, 362, 365, 368, 371, 374, 377].includes(code)) return "󰖘"; return "󰖗"; } Process { id: fetch command: ["python3", Quickshell.shellPath("helpers/weather.py"), root.location] stdout: StdioCollector { onStreamFinished: { try { const result = JSON.parse(text); if (result.ok) { root.current = result; root.error = ""; } else root.error = "Weather unavailable"; } catch (e) { root.error = "Weather unavailable"; } } } } Timer { interval: 30 * 60 * 1000 running: root.visible repeat: true triggeredOnStart: true onTriggered: if (!fetch.running) fetch.running = true } onLocationChanged: if (!fetch.running) fetch.running = true // The next few forecasts appear below once the face is large enough. readonly property var hourly: current && current.hourly ? current.hourly : [] readonly property bool showHourly: hourly.length > 0 && height >= 150 && width >= 260 function hourLabel(hour) { if (ConfigService.ready && !ConfigService.data.bar.clock.use24Hour) return (hour % 12 || 12) + (hour < 12 ? " AM" : " PM"); return (hour < 10 ? "0" : "") + hour + ":00"; } ColumnLayout { anchors.fill: parent anchors.margins: 14 spacing: 10 RowLayout { Layout.fillWidth: true Layout.fillHeight: true spacing: 12 GlassIcon { size: Math.min((root.showHourly ? root.height * 0.55 : root.height) - 28, 64) glyphSize: size * 0.62 glyph: root.current ? root.glyph(root.current.code) : "󰖐" fallback: "☁" color: Theme.transparent border.width: 0 } ColumnLayout { Layout.fillWidth: true spacing: 0 Text { text: root.current ? root.temperature(root.current.celsius) : "—" color: Theme.text font.pixelSize: Math.max(20, Math.min(root.height * 0.3, 44)) font.weight: Font.Light } Text { text: root.current ? root.current.description : root.error || "Loading…" color: Theme.text font.pixelSize: 12 elide: Text.ElideRight Layout.fillWidth: true } Text { visible: !!root.current && root.height > 110 text: root.current ? root.current.place + " · feels " + root.temperature(root.current.feelsCelsius) : "" color: Theme.textSecondary font.pixelSize: 10 elide: Text.ElideRight Layout.fillWidth: true } } } RowLayout { visible: root.showHourly Layout.fillWidth: true spacing: 0 Repeater { model: root.showHourly ? root.hourly : [] // Equal-width slots: a nested layout only grows when a child fills. Item { id: slot required property var modelData Layout.fillWidth: true Layout.preferredWidth: 1 implicitHeight: slotColumn.implicitHeight Column { id: slotColumn anchors.horizontalCenter: parent.horizontalCenter spacing: 2 Text { anchors.horizontalCenter: parent.horizontalCenter text: root.hourLabel(slot.modelData.hour) color: Theme.textSecondary font.pixelSize: 10 } Text { anchors.horizontalCenter: parent.horizontalCenter visible: Icons.available text: Icons.available ? root.glyph(slot.modelData.code) : "" font.family: Icons.family color: Theme.text font.pixelSize: 18 } Text { anchors.horizontalCenter: parent.horizontalCenter text: root.temperature(slot.modelData.celsius) color: Theme.text font.pixelSize: 11 font.weight: Font.DemiBold } } } } } } }