Tighten weather popup layout and add outside-click dismiss
PopupCard now uses HyprlandFocusGrab so any popup in the shell closes when the user clicks outside it (or any other window in the listed set). Single primitive — every widget gets it for free. Weather popup rewritten: - Smaller cloud glyph beside the city name on one row, both vertically centered. - Condition string flows on its own line and wraps inside the popup. - Refresh and wttr.in pills sit side by side instead of stacked, no more dead vertical space. - contentHeight tracks the actual content height so the popup is no taller than it needs to be.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
|
import Quickshell.Hyprland
|
||||||
|
|
||||||
PopupWindow {
|
PopupWindow {
|
||||||
id: root
|
id: root
|
||||||
@@ -14,6 +15,7 @@ PopupWindow {
|
|||||||
property bool open: false
|
property bool open: false
|
||||||
|
|
||||||
readonly property var coordinatorKey: owner || root
|
readonly property var coordinatorKey: owner || root
|
||||||
|
readonly property var anchorWindow: anchorItem ? anchorItem.QsWindow.window : null
|
||||||
|
|
||||||
function closePopout() {
|
function closePopout() {
|
||||||
if (owner && "closePopout" in owner) owner.closePopout()
|
if (owner && "closePopout" in owner) owner.closePopout()
|
||||||
@@ -33,6 +35,15 @@ PopupWindow {
|
|||||||
else if (bar.activePopout === coordinatorKey) bar.releasePopout(coordinatorKey)
|
else if (bar.activePopout === coordinatorKey) bar.releasePopout(coordinatorKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Outside-click dismissal via Hyprland's focus grab. While `active`, input
|
||||||
|
// is routed only to the listed windows; clicking anywhere else clears the
|
||||||
|
// grab and we close the popup.
|
||||||
|
HyprlandFocusGrab {
|
||||||
|
active: root.open
|
||||||
|
windows: root.anchorWindow ? [root, root.anchorWindow] : [root]
|
||||||
|
onCleared: root.closePopout()
|
||||||
|
}
|
||||||
|
|
||||||
anchor {
|
anchor {
|
||||||
id: popupAnchor
|
id: popupAnchor
|
||||||
window: anchorItem ? anchorItem.QsWindow.window : null
|
window: anchorItem ? anchorItem.QsWindow.window : null
|
||||||
|
|||||||
@@ -11,13 +11,25 @@ Item {
|
|||||||
property var settings: ({})
|
property var settings: ({})
|
||||||
|
|
||||||
property bool popupOpen: false
|
property bool popupOpen: false
|
||||||
|
|
||||||
function closePopout() { popupOpen = false }
|
function closePopout() { popupOpen = false }
|
||||||
|
|
||||||
property string fullReport: ""
|
property string fullReport: ""
|
||||||
|
|
||||||
readonly property string label: bar ? bar.weatherText : ""
|
readonly property string label: bar ? bar.weatherText : ""
|
||||||
readonly property string klass: bar ? bar.weatherClass : ""
|
readonly property string klass: bar ? bar.weatherClass : ""
|
||||||
|
|
||||||
|
// Parse the wttr.in single-line report into location + condition halves so
|
||||||
|
// we can render them with different emphasis.
|
||||||
|
readonly property string reportLocation: {
|
||||||
|
var parts = String(fullReport || "").split(":")
|
||||||
|
return parts.length > 1 ? parts[0].trim() : ""
|
||||||
|
}
|
||||||
|
readonly property string reportCondition: {
|
||||||
|
var parts = String(fullReport || "").split(":")
|
||||||
|
if (parts.length > 1) return parts.slice(1).join(":").trim()
|
||||||
|
return String(fullReport || "").trim()
|
||||||
|
}
|
||||||
|
|
||||||
visible: label !== ""
|
visible: label !== ""
|
||||||
implicitWidth: button.implicitWidth
|
implicitWidth: button.implicitWidth
|
||||||
implicitHeight: button.implicitHeight
|
implicitHeight: button.implicitHeight
|
||||||
@@ -26,7 +38,6 @@ Item {
|
|||||||
if (!forecastProc.running) forecastProc.running = true
|
if (!forecastProc.running) forecastProc.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: forecastProc
|
id: forecastProc
|
||||||
command: ["bash", "-lc", "curl -fsS --max-time 5 'wttr.in/?T0&format=%l:+%C+%t+%f+wind+%w+%h+humidity' 2>/dev/null"]
|
command: ["bash", "-lc", "curl -fsS --max-time 5 'wttr.in/?T0&format=%l:+%C+%t+%f+wind+%w+%h+humidity' 2>/dev/null"]
|
||||||
@@ -60,66 +71,69 @@ Item {
|
|||||||
bar: root.bar
|
bar: root.bar
|
||||||
open: root.popupOpen
|
open: root.popupOpen
|
||||||
contentWidth: 320
|
contentWidth: 320
|
||||||
contentHeight: column.implicitHeight + 28
|
contentHeight: card.implicitHeight + 28
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
id: column
|
id: card
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
spacing: 10
|
spacing: 12
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
spacing: 12
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
spacing: 10
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
|
id: glyph
|
||||||
text: root.label || "—"
|
text: root.label || "—"
|
||||||
color: root.bar.foreground
|
color: root.bar.foreground
|
||||||
font.family: root.bar.fontFamily
|
font.family: root.bar.fontFamily
|
||||||
font.pixelSize: 28
|
font.pixelSize: 24
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: location.verticalCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Text {
|
||||||
|
id: location
|
||||||
|
text: root.reportLocation || "Weather"
|
||||||
|
color: root.bar.foreground
|
||||||
|
font.family: root.bar.fontFamily
|
||||||
|
font.pixelSize: 13
|
||||||
|
font.bold: true
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
spacing: 2
|
width: parent.width - glyph.width - parent.spacing
|
||||||
|
elide: Text.ElideRight
|
||||||
Text {
|
|
||||||
text: "Weather"
|
|
||||||
color: root.bar.foreground
|
|
||||||
font.family: root.bar.fontFamily
|
|
||||||
font.pixelSize: 12
|
|
||||||
font.bold: true
|
|
||||||
}
|
|
||||||
|
|
||||||
Text {
|
|
||||||
text: root.fullReport || "Fetching forecast…"
|
|
||||||
color: Qt.darker(root.bar.foreground, 1.2)
|
|
||||||
font.family: root.bar.fontFamily
|
|
||||||
font.pixelSize: 10
|
|
||||||
wrapMode: Text.WordWrap
|
|
||||||
width: 220
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Common.PillButton {
|
Text {
|
||||||
|
text: root.reportCondition || "Fetching forecast…"
|
||||||
|
color: Qt.darker(root.bar.foreground, 1.2)
|
||||||
|
font.family: root.bar.fontFamily
|
||||||
|
font.pixelSize: 11
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
width: parent.width
|
width: parent.width
|
||||||
iconText: ""
|
|
||||||
text: "Refresh"
|
|
||||||
foreground: root.bar.foreground
|
|
||||||
horizontalPadding: 10
|
|
||||||
verticalPadding: 6
|
|
||||||
onClicked: root.refresh()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Common.PillButton {
|
Row {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
iconText: ""
|
spacing: 8
|
||||||
text: "Open wttr.in"
|
|
||||||
foreground: root.bar.foreground
|
Common.PillButton {
|
||||||
horizontalPadding: 10
|
iconText: ""
|
||||||
verticalPadding: 6
|
text: "Refresh"
|
||||||
onClicked: { root.bar.run("xdg-open https://wttr.in"); root.popupOpen = false }
|
foreground: root.bar.foreground
|
||||||
|
horizontalPadding: 12
|
||||||
|
verticalPadding: 6
|
||||||
|
onClicked: root.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
Common.PillButton {
|
||||||
|
iconText: ""
|
||||||
|
text: "wttr.in"
|
||||||
|
foreground: root.bar.foreground
|
||||||
|
horizontalPadding: 12
|
||||||
|
verticalPadding: 6
|
||||||
|
onClicked: { root.bar.run("xdg-open https://wttr.in"); root.popupOpen = false }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user