config: respect user locale for twelve hour clock & temperature (#290)

* bar: add 12h clock option

* feat: allow custom format config

* feat: 12h clock based on locale with config

* chore: cleanup

* fix: PR comments, add automatic fahrenheit

* fix: formatting

* dashboard: fix up date time

* lock: better 12h clock

---------

Co-authored-by: Soramane <61896496+soramanew@users.noreply.github.com>
This commit is contained in:
Laurens Duin 2025-07-31 12:41:56 +02:00 committed by GitHub
parent c1be0f0ccb
commit 7edcae651e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 69 additions and 55 deletions

View file

@ -221,7 +221,8 @@ All configuration options are in `~/.config/caelestia/shell.json`.
}, },
"services": { "services": {
"weatherLocation": "10,10", "weatherLocation": "10,10",
"useFahrenheit": false "useFahrenheit": false,
"useTwelveHourClock": false
}, },
"session": { "session": {
"dragThreshold": 30, "dragThreshold": 30,

View file

@ -1,6 +1,8 @@
import Quickshell.Io import Quickshell.Io
import QtQuick
JsonObject { JsonObject {
property string weatherLocation: "" // A lat,long pair or empty for autodetection, e.g. "37.8267,-122.4233" property string weatherLocation: "" // A lat,long pair or empty for autodetection, e.g. "37.8267,-122.4233"
property bool useFahrenheit: false property bool useFahrenheit: [Locale.ImperialUSSystem, Locale.ImperialSystem].includes(Qt.locale().measurementSystem)
property bool useTwelveHourClock: Qt.locale().timeFormat(Locale.ShortFormat).toLowerCase().includes("a")
} }

View file

@ -11,7 +11,7 @@ Item {
id: timeText id: timeText
anchors.centerIn: parent anchors.centerIn: parent
text: Time.format("hh:mm:ss") text: Time.format(Config.services.useTwelveHourClock ? "hh:mm:ss A" : "hh:mm:ss")
font.pointSize: Appearance.font.size.extraLarge font.pointSize: Appearance.font.size.extraLarge
font.bold: true font.bold: true
} }

View file

@ -25,7 +25,7 @@ Column {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: StyledText.AlignHCenter horizontalAlignment: StyledText.AlignHCenter
text: Time.format("hh\nmm") text: Time.format(Config.services.useTwelveHourClock ? "hh\nmm\nA" : "hh\nmm")
font.pointSize: Appearance.font.size.smaller font.pointSize: Appearance.font.size.smaller
font.family: Appearance.font.family.mono font.family: Appearance.font.family.mono
color: root.colour color: root.colour

View file

@ -2,70 +2,67 @@ import qs.widgets
import qs.services import qs.services
import qs.config import qs.config
import QtQuick import QtQuick
import QtQuick.Layouts
Item { Item {
id: root id: root
readonly property list<string> timeComponents: Time.format(Config.services.useTwelveHourClock ? "hh:mm:A" : "hh:mm").split(":")
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
implicitWidth: Config.dashboard.sizes.dateTimeWidth implicitWidth: Config.dashboard.sizes.dateTimeWidth
StyledText { ColumnLayout {
id: hours
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: parent.top anchors.verticalCenter: parent.verticalCenter
anchors.topMargin: (root.height - (hours.implicitHeight + sep.implicitHeight + sep.anchors.topMargin + mins.implicitHeight + mins.anchors.topMargin + date.implicitHeight + date.anchors.topMargin)) / 2 spacing: 0
horizontalAlignment: Text.AlignHCenter StyledText {
text: Time.format("HH") Layout.alignment: Qt.AlignHCenter
color: Colours.palette.m3secondary text: root.timeComponents[0]
font.pointSize: Appearance.font.size.extraLarge color: Colours.palette.m3secondary
font.weight: 500 font.pointSize: Appearance.font.size.extraLarge
} font.weight: 600
}
StyledText { StyledText {
id: sep Layout.topMargin: -(font.pointSize * 0.2)
Layout.alignment: Qt.AlignHCenter
text: "•••"
color: Colours.palette.m3primary
font.pointSize: Appearance.font.size.extraLarge * 0.9
}
anchors.left: parent.left StyledText {
anchors.right: parent.right Layout.alignment: Qt.AlignHCenter
anchors.top: hours.bottom text: root.timeComponents[1]
anchors.topMargin: -font.pointSize * 0.5 color: Colours.palette.m3secondary
font.pointSize: Appearance.font.size.extraLarge
font.weight: 600
}
horizontalAlignment: Text.AlignHCenter StyledText {
text: "•••" visible: Config.services.useTwelveHourClock
color: Colours.palette.m3primary Layout.topMargin: Appearance.spacing.small
font.pointSize: Appearance.font.size.extraLarge * 0.9 Layout.alignment: Qt.AlignHCenter
}
StyledText { text: root.timeComponents[2]
id: mins color: Colours.palette.m3secondary
font.pointSize: Appearance.font.size.large
font.weight: 600
}
anchors.left: parent.left StyledText {
anchors.right: parent.right Layout.topMargin: Appearance.spacing.normal
anchors.top: sep.bottom Layout.fillWidth: true
anchors.topMargin: -sep.font.pointSize * 0.45 horizontalAlignment: Text.AlignHCenter
text: Time.format("ddd, d")
horizontalAlignment: Text.AlignHCenter color: Colours.palette.m3tertiary
text: Time.format("mm") font.pointSize: Appearance.font.size.normal
color: Colours.palette.m3secondary font.weight: 500
font.pointSize: Appearance.font.size.extraLarge elide: Text.ElideRight
font.weight: 500 }
}
StyledText {
id: date
anchors.left: parent.left
anchors.right: parent.right
anchors.top: mins.bottom
anchors.topMargin: Appearance.spacing.normal
horizontalAlignment: Text.AlignHCenter
text: Time.format("ddd, d")
color: Colours.palette.m3tertiary
font.pointSize: Appearance.font.size.normal
font.weight: 500
} }
} }

View file

@ -1,6 +1,7 @@
import qs.widgets import qs.widgets
import qs.services import qs.services
import qs.config import qs.config
import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
ColumnLayout { ColumnLayout {
@ -8,13 +9,15 @@ ColumnLayout {
spacing: 0 spacing: 0
readonly property list<string> timeComponents: Time.format(Config.services.useTwelveHourClock ? "hh:mm:A" : "hh:mm").split(":")
RowLayout { RowLayout {
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
spacing: Appearance.spacing.small spacing: Appearance.spacing.small
StyledText { StyledText {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
text: Time.format("HH") text: root.timeComponents[0]
color: Colours.palette.m3secondary color: Colours.palette.m3secondary
font.pointSize: Appearance.font.size.extraLarge * 4 font.pointSize: Appearance.font.size.extraLarge * 4
font.family: Appearance.font.family.mono font.family: Appearance.font.family.mono
@ -32,12 +35,23 @@ ColumnLayout {
StyledText { StyledText {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
text: Time.format("mm") text: root.timeComponents[1]
color: Colours.palette.m3secondary color: Colours.palette.m3secondary
font.pointSize: Appearance.font.size.extraLarge * 4 font.pointSize: Appearance.font.size.extraLarge * 4
font.family: Appearance.font.family.mono font.family: Appearance.font.family.mono
font.weight: 800 font.weight: 800
} }
StyledText {
visible: Config.services.useTwelveHourClock
Layout.leftMargin: Appearance.spacing.normal
Layout.alignment: Qt.AlignVCenter
text: root.timeComponents[2]
color: Colours.palette.m3primary
font.pointSize: Appearance.font.size.extraLarge * 3
font.weight: 700
}
} }
StyledText { StyledText {