Read cornerRadius from Hyprland instead of the quickshell-menu.json toggle

This commit is contained in:
Ryan Hughes
2026-05-17 23:31:47 -04:00
parent b1e3a23088
commit 64115a9cb4
8 changed files with 77 additions and 138 deletions
@@ -8,9 +8,16 @@ import Quickshell.Io
// every panel surface and qs.Ui component should bind to so they stay
// in sync as the user toggles round/sharp corners or as themes change.
//
// `cornerRadius` is mirrored from ~/.local/state/omarchy/toggles/quickshell-menu.json.
// `omarchy style corners <round|sharp>` writes that file; we watch it and
// hot-reload the binding here so every consumer rerenders.
// `cornerRadius` mirrors Hyprland's `decoration:rounding`. Themes ship
// their own rounding via theme/hyprland.lua; the user toggle via
// `omarchy style corners <round|sharp>` flips Hyprland's flag file
// and Hyprland's auto-reload pushes the new value out. The shell picks
// up the change here by re-running `hyprctl getoption` whenever either
// of those input files changes.
//
// Single source of truth lives in Hyprland; the shell follows. That
// means a theme that ships `rounding = 10` gives us 10px panels by
// default, and the round/sharp user toggle still works on top of it.
QtObject {
id: root
@@ -29,23 +36,60 @@ QtObject {
// value PillButton was already painting before promotion.
readonly property color hotFill: Qt.rgba(Color.foreground.r, Color.foreground.g, Color.foreground.b, 0.12)
function loadStyleState(raw) {
function refresh() {
hyprctlProc.running = true
}
function applyRoundingJson(raw) {
try {
var s = JSON.parse(raw || "{}")
var n = Number(s.radius)
cornerRadius = isFinite(n) ? n : 0
var json = JSON.parse(raw || "{}")
var n = Number(json.int)
if (isFinite(n) && n >= 0) cornerRadius = n
} catch (e) {
cornerRadius = 0
// hyprctl missing / Hyprland not running — leave the previous value.
}
}
property FileView styleStateFile: FileView {
id: styleStateFile
path: Quickshell.env("HOME") + "/.local/state/omarchy/toggles/quickshell-menu.json"
property Process hyprctlProc: Process {
id: hyprctlProc
command: ["hyprctl", "-j", "getoption", "decoration:rounding"]
stdout: StdioCollector {
waitForEnd: true
onStreamFinished: root.applyRoundingJson(text)
}
}
// Re-poll Hyprland a beat after either input file changes. Hyprland's
// auto-reload runs asynchronously when its sourced .lua files change,
// so racing it with an immediate hyprctl gives the old value. 200ms is
// generous enough for Hyprland to settle without being user-visible.
property Timer refreshTimer: Timer {
id: refreshTimer
interval: 200
repeat: false
onTriggered: root.refresh()
}
// The theme name flips whenever `omarchy-theme-set` swaps the theme/
// symlink; that's when theme/hyprland.lua's `rounding` value changes.
property FileView themeNameFile: FileView {
path: Quickshell.env("HOME") + "/.config/omarchy/current/theme.name"
watchChanges: true
printErrors: false
onLoaded: root.loadStyleState(text())
onLoadFailed: root.loadStyleState("")
onFileChanged: reload()
onFileChanged: refreshTimer.restart()
}
// `omarchy style corners <round|sharp>` creates or removes this flag file.
// Hyprland reloads its config when sourced files change, then hyprctl
// reflects the new effective rounding value.
property FileView roundedCornersToggle: FileView {
path: Quickshell.env("HOME") + "/.local/state/omarchy/toggles/hypr/rounded-corners.lua"
watchChanges: true
printErrors: false
onFileChanged: refreshTimer.restart()
onLoaded: refreshTimer.restart()
onLoadFailed: refreshTimer.restart()
}
Component.onCompleted: refresh()
}