From b7f9c3c1ae6879affefd01d2792e59ed2bd8714c Mon Sep 17 00:00:00 2001 From: Espen Kristensen Date: Sat, 29 Aug 2026 18:52:34 +0200 Subject: [PATCH 1/8] Add support for detached bar with margin and radius properties --- default/themed/shell.toml.tpl | 6 ++++++ docs/omarchy-shell.md | 12 ++++++++++++ shell/Commons/Style.qml | 19 ++++++++++++++++++- shell/plugins/bar/Bar.qml | 32 ++++++++++++++++++++++++++------ test/shell.d/bar-test.sh | 15 +++++++++++++-- 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/default/themed/shell.toml.tpl b/default/themed/shell.toml.tpl index fda55cec8c3b..104d0a045913 100644 --- a/default/themed/shell.toml.tpl +++ b/default/themed/shell.toml.tpl @@ -15,6 +15,12 @@ active = "{{ red }}" scale-with-font = true size-horizontal = 26 size-vertical = 28 +# Detach the bar from the screen. margin is the gap left on every edge the bar +# touches, reserved along with the bar so windows still tile clear of it, and +# radius rounds the bar's corners. Both are 0 by default — flush against the +# edge, square corners — and both follow scale-with-font. +margin = 0 +radius = 0 [hyprland] # Shared Hyprland-derived border tokens. Surface sections reference these so diff --git a/docs/omarchy-shell.md b/docs/omarchy-shell.md index d08afa81f1f1..af2a646d0e28 100644 --- a/docs/omarchy-shell.md +++ b/docs/omarchy-shell.md @@ -413,6 +413,18 @@ A panel matches a screen whose connector name starts with `connector` and whose Until Hyprland reports a screen's mode, a top bar there waits to appear if a description names the screen's connector, unless the logical size times Qt's whole-number scale already matches a panel. It then appears at its floor rather than growing once windows are laid out, and never guesses a floor for a panel nothing describes. After two seconds without a mode it appears without a floor. Notifications clear the bar as thick as it is on their screen. A plugin's `shell.bar` gives the same through `barSizeFor(screenName)` and the `barSizes` map (screen name to thickness); its `barSize` stays the configured size, which the widgets are drawn at. +### Detached bar + +`[bar] margin` and `radius` lift the bar off its screen edge. `margin` is the gap left on every edge the bar touches — the one it is anchored to and the two it spans — and `radius` rounds the corners of the bar surface: + +```toml +[bar] +margin = 10 # gap between the bar and the screen edges; 0 = flush +radius = 12 # corner rounding of the bar surface; 0 = square +``` + +Both default to `0`, a bar sitting flush against its edge with square corners, and both follow `scale-with-font` like the sizes above. The gap is reserved along with the bar itself, so maximized and tiled windows stop clear of it instead of sliding underneath. Auto-hide still parks the bar fully off screen, clearing the margin as well as the bar. + ## Custom bar modules If a full plugin is overkill, declare a one-off module inline in diff --git a/shell/Commons/Style.qml b/shell/Commons/Style.qml index a40269722160..118f7448fe4d 100644 --- a/shell/Commons/Style.qml +++ b/shell/Commons/Style.qml @@ -303,6 +303,17 @@ QtObject { return Math.max(1, Math.round(base)) } + // Bar tokens whose resting value is zero: a bar flush against its edge with + // square corners. barToken() floors at 1 and reads 0 as "unset", so margin + // and radius need a reader that keeps a deliberate 0. + function barInsetToken(key, fallback) { + var v = barOverrides[key] + var n = Number(v) + var base = (isFinite(n) && n >= 0) ? n : fallback + if (barScaleWithFont) base *= fontScale + return Math.max(0, Math.round(base)) + } + function boolToken(value, fallback) { if (value === undefined || value === null) return fallback var s = String(value).replace(/^\s+|\s+$/g, "").toLowerCase() @@ -350,6 +361,11 @@ QtObject { var v = Number(root.barOverrides["notch-height"]) return (isFinite(v) && v > 0) ? Math.round(v) : 0 } + // Gap between the bar and the screen edges it would otherwise sit flush + // against, and the corner rounding of the bar surface. Both default to 0, + // which is the flush, square bar. + readonly property int margin: root.barInsetToken("margin", 0) + readonly property int radius: root.barInsetToken("radius", 0) readonly property int iconSlot: root.barToken("icon-slot", 27) readonly property int iconCanvas: root.barToken("icon-canvas", 16) readonly property int iconFont: root.barToken("icon-font", 13) @@ -427,7 +443,8 @@ QtObject { nextBarScaleWithFont = boolToken(raw, nextBarScaleWithFont) } else if (key === "size-horizontal" || key === "size-vertical" || key === "notch-height" || key === "icon-slot" || key === "icon-canvas" || key === "icon-font" - || key === "icon-size" || key === "status-slot") { + || key === "icon-size" || key === "status-slot" + || key === "margin" || key === "radius") { var b = parseInt(raw, 10) if (isFinite(b)) barOut[key] = b } diff --git a/shell/plugins/bar/Bar.qml b/shell/plugins/bar/Bar.qml index 2831ab535a63..44cc035160d2 100644 --- a/shell/plugins/bar/Bar.qml +++ b/shell/plugins/bar/Bar.qml @@ -657,6 +657,11 @@ Item { readonly property bool vertical: position === "left" || position === "right" readonly property int barSize: vertical ? Style.bar.sizeVertical : Style.bar.sizeHorizontal + // A detached bar floats barMargin away from every screen edge it touches and + // rounds its corners by barRadius. Both are 0 by default, which anchors the + // bar flush against its edge with square corners. + readonly property int barMargin: Style.bar.margin + readonly property int barRadius: Style.bar.radius // Display cutouts (a camera notch) the platform's own package describes in // the fixed platform root, which no environment variable moves. Most machines @@ -1550,12 +1555,16 @@ Item { } // Parked by its full thickness, which a notch floor may make more than - // barSize, so no strip of it stays on screen. + // barSize, plus its margin, so neither the bar nor the gap leaves a strip + // of it on screen. + readonly property int parkedMargin: -(barWindow.thickness + root.barMargin) + readonly property int edgeMargin: root.barHidden ? parkedMargin : root.barMargin + margins { - top: root.barHidden && root.position === "top" ? -barWindow.thickness : 0 - bottom: root.barHidden && root.position === "bottom" ? -barWindow.thickness : 0 - left: root.barHidden && root.position === "left" ? -barWindow.thickness : 0 - right: root.barHidden && root.position === "right" ? -barWindow.thickness : 0 + top: root.position === "top" ? edgeMargin : (root.vertical ? root.barMargin : 0) + bottom: root.position === "bottom" ? edgeMargin : (root.vertical ? root.barMargin : 0) + left: root.position === "left" ? edgeMargin : (root.vertical ? 0 : root.barMargin) + right: root.position === "right" ? edgeMargin : (root.vertical ? 0 : root.barMargin) } anchors { @@ -1585,11 +1594,22 @@ Item { implicitWidth: root.vertical ? thickness : 0 implicitHeight: root.vertical ? 0 : thickness - color: root.transparent ? "transparent" : (root.glassy ? root.glassBackground : root.background) + // The surface itself stays transparent so the rounded background below can + // paint the corners; a window color would square them off again. + color: "transparent" surfaceFormat.opaque: false WlrLayershell.namespace: "omarchy-bar" WlrLayershell.layer: WlrLayer.Top + // Declared before the loader so it paints behind the widgets. Carries the + // bar's background instead of the window, which is what lets barRadius + // round the corners. + Rectangle { + anchors.fill: parent + color: root.transparent ? "transparent" : (root.glassy ? root.glassBackground : root.background) + radius: root.barRadius + } + Loader { anchors.fill: parent sourceComponent: root.vertical ? verticalBar : horizontalBar diff --git a/test/shell.d/bar-test.sh b/test/shell.d/bar-test.sh index de20b56e097c..6994298ffcbc 100644 --- a/test/shell.d/bar-test.sh +++ b/test/shell.d/bar-test.sh @@ -79,10 +79,21 @@ assert( /exclusionMode: root\.barHidden \? ExclusionMode\.Ignore : ExclusionMode\.Auto/.test(barSource), 'a hidden bar reserves no space for itself' ) +// A detached bar sits barMargin off its edge, so parking has to clear the gap +// as well as the bar's whole thickness or the margin leaves a sliver of it on +// screen. +assert( + /readonly property int parkedMargin: -\(barWindow\.thickness \+ root\.barMargin\)/.test(barSource), + 'parking a hidden bar clears its margin as well as its whole thickness' +) +assert( + /readonly property int edgeMargin: root\.barHidden \? parkedMargin : root\.barMargin/.test(barSource), + 'the anchored edge parks when hidden and carries the margin when shown' +) for (const edge of ['top', 'bottom', 'left', 'right']) { assert( - new RegExp(`${edge}: root\\.barHidden && root\\.position === "${edge}" \\? -barWindow\\.thickness : 0`).test(barSource), - `a hidden bar parks past the ${edge} edge by its whole thickness` + new RegExp(`${edge}: root\\.position === "${edge}" \\? edgeMargin :`).test(barSource), + `a hidden bar parks past the ${edge} edge` ) } From a571fe0463ce8900eeb0439eae5584e5b73c12a0 Mon Sep 17 00:00:00 2001 From: Marc-Anthony Girard Date: Tue, 1 Sep 2026 22:02:18 -0400 Subject: [PATCH 2/8] Make the detached bar correct per edge and while transparent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bar is usually set further off the edges it spans than off the one it hangs from — sketchybar and waybar both inset 8 at the sides and 4 at the top — which a single margin cannot express. Read the gap through Geometry.parseWidthSpec, the width spec the border widths already take, so margin accepts N, "Y X", "T X B" or "T R B L" with no new vocabulary. A scalar still means every edge. Two things are only reachable once the bar is detached: windowScreenPoint() mapped drag points from the screen corner, leaving the drop marker and the drag ghost a margin away from the cursor and handing nearestScreenEdge() a skewed point. A detached bar's origin is the gap itself on the axes it spans, and the far edge less its own size and gap on the one it is anchored to. omarchy-bar-text-color crops the wallpaper at the screen edge to choose a legible transparent-mode foreground, a strip a detached bar no longer covers. It takes an --inset now, applied to all four crops. At margin 0 the mapping returns identical coordinates and the crops are byte-identical, so a flush bar is untouched. --- bin/omarchy-bar-text-color | 36 ++++++++++++++---- default/themed/shell.toml.tpl | 6 +-- docs/omarchy-shell.md | 13 ++++++- shell/Commons/Style.qml | 26 ++++++++++--- shell/plugins/bar/Bar.qml | 49 ++++++++++++++++-------- test/shell.d/bar-test.sh | 59 ++++++++++++++++++++++++++++- test/shell.d/bar-text-color-test.sh | 31 +++++++++++++++ 7 files changed, 183 insertions(+), 37 deletions(-) diff --git a/bin/omarchy-bar-text-color b/bin/omarchy-bar-text-color index 35cd0eadd2a9..eed3dbee0ae1 100755 --- a/bin/omarchy-bar-text-color +++ b/bin/omarchy-bar-text-color @@ -11,6 +11,10 @@ text_color=${3:-} background_color=${4:-} background_path="" screen_size="" +inset_top=0 +inset_right=0 +inset_bottom=0 +inset_left=0 shift 4 2>/dev/null || true while (($# > 0)); do @@ -23,6 +27,10 @@ while (($# > 0)); do screen_size=${2:-} shift 2 ;; + --inset) + read -r inset_top inset_right inset_bottom inset_left <<<"${2:-}" + shift 2 + ;; *) shift ;; @@ -72,6 +80,9 @@ valid_hex "$text_color" || fallback valid_hex "$background_color" || fallback [[ $position =~ ^(top|bottom|left|right)$ ]] || fallback [[ $bar_size =~ ^[0-9]+$ ]] || fallback +for inset in "$inset_top" "$inset_right" "$inset_bottom" "$inset_left"; do + [[ $inset =~ ^[0-9]+$ ]] || fallback +done omarchy-cmd-present magick || fallback if [[ -z $background_path ]]; then @@ -90,22 +101,31 @@ screen_width=${BASH_REMATCH[1]} screen_height=${BASH_REMATCH[2]} ((screen_width > 0 && screen_height > 0 && bar_size > 0)) || fallback +# A detached bar is inset on every edge it touches, so the strip it actually +# covers starts that far in on the axes it spans and that far short of the far +# edge it is anchored to. At all-zero insets this is the flush bar's strip. case "$position" in top) - crop="${screen_width}x${bar_size}+0+0" + crop_width=$((screen_width - inset_left - inset_right)) + ((crop_width > 0)) || fallback + crop="${crop_width}x${bar_size}+${inset_left}+${inset_top}" ;; bottom) - crop_y=$((screen_height - bar_size)) - ((crop_y >= 0)) || fallback - crop="${screen_width}x${bar_size}+0+${crop_y}" + crop_width=$((screen_width - inset_left - inset_right)) + crop_y=$((screen_height - bar_size - inset_bottom)) + ((crop_width > 0 && crop_y >= 0)) || fallback + crop="${crop_width}x${bar_size}+${inset_left}+${crop_y}" ;; left) - crop="${bar_size}x${screen_height}+0+0" + crop_height=$((screen_height - inset_top - inset_bottom)) + ((crop_height > 0)) || fallback + crop="${bar_size}x${crop_height}+${inset_left}+${inset_top}" ;; right) - crop_x=$((screen_width - bar_size)) - ((crop_x >= 0)) || fallback - crop="${bar_size}x${screen_height}+${crop_x}+0" + crop_height=$((screen_height - inset_top - inset_bottom)) + crop_x=$((screen_width - bar_size - inset_right)) + ((crop_height > 0 && crop_x >= 0)) || fallback + crop="${bar_size}x${crop_height}+${crop_x}+${inset_top}" ;; esac diff --git a/default/themed/shell.toml.tpl b/default/themed/shell.toml.tpl index 104d0a045913..40db388d2aab 100644 --- a/default/themed/shell.toml.tpl +++ b/default/themed/shell.toml.tpl @@ -15,10 +15,8 @@ active = "{{ red }}" scale-with-font = true size-horizontal = 26 size-vertical = 28 -# Detach the bar from the screen. margin is the gap left on every edge the bar -# touches, reserved along with the bar so windows still tile clear of it, and -# radius rounds the bar's corners. Both are 0 by default — flush against the -# edge, square corners — and both follow scale-with-font. +# Gap between the bar and the edge. Takes one CSS-style scalar/list: +# N, "Y X", "T X B", or "T R B L". margin = 0 radius = 0 diff --git a/docs/omarchy-shell.md b/docs/omarchy-shell.md index af2a646d0e28..547670d7476f 100644 --- a/docs/omarchy-shell.md +++ b/docs/omarchy-shell.md @@ -413,9 +413,11 @@ A panel matches a screen whose connector name starts with `connector` and whose Until Hyprland reports a screen's mode, a top bar there waits to appear if a description names the screen's connector, unless the logical size times Qt's whole-number scale already matches a panel. It then appears at its floor rather than growing once windows are laid out, and never guesses a floor for a panel nothing describes. After two seconds without a mode it appears without a floor. Notifications clear the bar as thick as it is on their screen. A plugin's `shell.bar` gives the same through `barSizeFor(screenName)` and the `barSizes` map (screen name to thickness); its `barSize` stays the configured size, which the widgets are drawn at. -### Detached bar +### Floating bar -`[bar] margin` and `radius` lift the bar off its screen edge. `margin` is the gap left on every edge the bar touches — the one it is anchored to and the two it spans — and `radius` rounds the corners of the bar surface: +`[bar] margin` lift the bar off its screen edge. `margin` is the gap between the bar and every edge the bar touches — the one it is anchored to and the two it spans + +[bar] `radius` rounds the corners of the bar surface ```toml [bar] @@ -423,6 +425,13 @@ margin = 10 # gap between the bar and the screen edges; 0 = flush radius = 12 # corner rounding of the bar surface; 0 = square ``` +`margin` accepts the same CSS-style list as the border widths — `N`, `"Y X"`, `"T X B"`, or `"T R B L"` — so the gap can differ per edge. A bar set further off the sides than off the edge it hangs from: + +```toml +[bar] +margin = "4 8" # 4 from the anchored edge, 8 at the two it spans +``` + Both default to `0`, a bar sitting flush against its edge with square corners, and both follow `scale-with-font` like the sizes above. The gap is reserved along with the bar itself, so maximized and tiled windows stop clear of it instead of sliding underneath. Auto-hide still parks the bar fully off screen, clearing the margin as well as the bar. ## Custom bar modules diff --git a/shell/Commons/Style.qml b/shell/Commons/Style.qml index 118f7448fe4d..59444c7a53c7 100644 --- a/shell/Commons/Style.qml +++ b/shell/Commons/Style.qml @@ -4,6 +4,7 @@ import qs.Commons as Commons import Quickshell import Quickshell.Hyprland import Quickshell.Io +import "BorderGeometry.js" as Geometry // Shared structural style tokens for the shell. Color is the palette // singleton; Style holds everything else themes can influence — corner @@ -314,6 +315,20 @@ QtObject { return Math.max(0, Math.round(base)) } + // margin takes the same CSS-style list as the border widths — N, "Y X", + // "T X B", or "T R B L" — because a bar is usually set further off the edges + // it spans than off the one it hangs from. + function barMarginToken() { + var widths = Geometry.parseWidthSpec(barOverrides["margin"], 0) + var scale = barScaleWithFont ? fontScale : 1 + return { + top: Math.max(0, Math.round(widths.top * scale)), + right: Math.max(0, Math.round(widths.right * scale)), + bottom: Math.max(0, Math.round(widths.bottom * scale)), + left: Math.max(0, Math.round(widths.left * scale)) + } + } + function boolToken(value, fallback) { if (value === undefined || value === null) return fallback var s = String(value).replace(/^\s+|\s+$/g, "").toLowerCase() @@ -361,10 +376,7 @@ QtObject { var v = Number(root.barOverrides["notch-height"]) return (isFinite(v) && v > 0) ? Math.round(v) : 0 } - // Gap between the bar and the screen edges it would otherwise sit flush - // against, and the corner rounding of the bar surface. Both default to 0, - // which is the flush, square bar. - readonly property int margin: root.barInsetToken("margin", 0) + readonly property var margins: root.barMarginToken() readonly property int radius: root.barInsetToken("radius", 0) readonly property int iconSlot: root.barToken("icon-slot", 27) readonly property int iconCanvas: root.barToken("icon-canvas", 16) @@ -441,10 +453,12 @@ QtObject { } else if (section === "bar") { if (key === "scale-with-font") { nextBarScaleWithFont = boolToken(raw, nextBarScaleWithFont) + } else if (key === "margin") { + // Kept verbatim: the width spec is a list as often as a number. + barOut[key] = raw } else if (key === "size-horizontal" || key === "size-vertical" || key === "notch-height" || key === "icon-slot" || key === "icon-canvas" || key === "icon-font" - || key === "icon-size" || key === "status-slot" - || key === "margin" || key === "radius") { + || key === "icon-size" || key === "status-slot" || key === "radius") { var b = parseInt(raw, 10) if (isFinite(b)) barOut[key] = b } diff --git a/shell/plugins/bar/Bar.qml b/shell/plugins/bar/Bar.qml index 44cc035160d2..664b3d00b31a 100644 --- a/shell/plugins/bar/Bar.qml +++ b/shell/plugins/bar/Bar.qml @@ -559,10 +559,17 @@ Item { var y = scenePoint ? scenePoint.y : 0 if (!window || !window.screen) return { x: x, y: y } - if (root.position === "bottom") - y += Math.max(0, window.screen.height - window.height) - else if (root.position === "right") - x += Math.max(0, window.screen.width - window.width) + // A detached bar sits inside every edge it touches, so its origin is the + // gap itself on the axes it spans, and the far edge less its own size and + // gap on the one it is anchored to. At margin 0 this is the flush bar's + // plain screen-corner offset. + var margins = root.barMargins + x += root.position === "right" + ? Math.max(0, window.screen.width - window.width - margins.right) + : margins.left + y += root.position === "bottom" + ? Math.max(0, window.screen.height - window.height - margins.bottom) + : margins.top return { x: x, y: y } } @@ -657,10 +664,11 @@ Item { readonly property bool vertical: position === "left" || position === "right" readonly property int barSize: vertical ? Style.bar.sizeVertical : Style.bar.sizeHorizontal - // A detached bar floats barMargin away from every screen edge it touches and - // rounds its corners by barRadius. Both are 0 by default, which anchors the - // bar flush against its edge with square corners. - readonly property int barMargin: Style.bar.margin + // A detached bar floats barMargins away from every screen edge it touches + // and rounds its corners by barRadius. Every side is 0 by default, which + // anchors the bar flush against its edge with square corners. The keys are + // the position names, so barMargins[position] is the anchored edge's gap. + readonly property var barMargins: Style.bar.margins readonly property int barRadius: Style.bar.radius // Display cutouts (a camera notch) the platform's own package describes in @@ -1367,13 +1375,20 @@ Item { root.position, String(root.barSize), colorHex(root.themeForeground), - colorHex(root.themeContrastForeground) + colorHex(root.themeContrastForeground), + // A detached bar no longer covers the strip at the screen edge, so the + // sample has to move in with it or the contrast is picked against pixels + // the bar does not sit on. + "--inset", + [root.barMargins.top, root.barMargins.right, + root.barMargins.bottom, root.barMargins.left].join(" ") ] transparentForegroundProc.running = true } onRequestedTransparentChanged: scheduleTransparentForegroundRefresh() onPositionChanged: scheduleTransparentForegroundRefresh() + onBarMarginsChanged: scheduleTransparentForegroundRefresh() onThemeForegroundChanged: scheduleTransparentForegroundRefresh() onThemeContrastForegroundChanged: scheduleTransparentForegroundRefresh() @@ -1557,14 +1572,18 @@ Item { // Parked by its full thickness, which a notch floor may make more than // barSize, plus its margin, so neither the bar nor the gap leaves a strip // of it on screen. - readonly property int parkedMargin: -(barWindow.thickness + root.barMargin) - readonly property int edgeMargin: root.barHidden ? parkedMargin : root.barMargin + readonly property int anchoredMargin: root.barMargins[root.position] + readonly property int parkedMargin: -(barWindow.thickness + anchoredMargin) + readonly property int edgeMargin: root.barHidden ? parkedMargin : anchoredMargin + // Only the edges the bar actually touches take a gap: the one it is + // anchored to, and the two it spans. The remaining side is the bar's own + // far face, which no margin applies to. margins { - top: root.position === "top" ? edgeMargin : (root.vertical ? root.barMargin : 0) - bottom: root.position === "bottom" ? edgeMargin : (root.vertical ? root.barMargin : 0) - left: root.position === "left" ? edgeMargin : (root.vertical ? 0 : root.barMargin) - right: root.position === "right" ? edgeMargin : (root.vertical ? 0 : root.barMargin) + top: root.position === "top" ? edgeMargin : (root.vertical ? root.barMargins.top : 0) + bottom: root.position === "bottom" ? edgeMargin : (root.vertical ? root.barMargins.bottom : 0) + left: root.position === "left" ? edgeMargin : (root.vertical ? 0 : root.barMargins.left) + right: root.position === "right" ? edgeMargin : (root.vertical ? 0 : root.barMargins.right) } anchors { diff --git a/test/shell.d/bar-test.sh b/test/shell.d/bar-test.sh index 6994298ffcbc..00e85098177b 100644 --- a/test/shell.d/bar-test.sh +++ b/test/shell.d/bar-test.sh @@ -83,11 +83,11 @@ assert( // as well as the bar's whole thickness or the margin leaves a sliver of it on // screen. assert( - /readonly property int parkedMargin: -\(barWindow\.thickness \+ root\.barMargin\)/.test(barSource), + /readonly property int parkedMargin: -\(barWindow\.thickness \+ anchoredMargin\)/.test(barSource), 'parking a hidden bar clears its margin as well as its whole thickness' ) assert( - /readonly property int edgeMargin: root\.barHidden \? parkedMargin : root\.barMargin/.test(barSource), + /readonly property int edgeMargin: root\.barHidden \? parkedMargin : anchoredMargin/.test(barSource), 'the anchored edge parks when hidden and carries the margin when shown' ) for (const edge of ['top', 'bottom', 'left', 'right']) { @@ -97,6 +97,61 @@ for (const edge of ['top', 'bottom', 'left', 'right']) { ) } +// The gap is a width spec, not a scalar, so a bar can sit further off the edges +// it spans than off the one it hangs from. The anchored edge reads out of the +// same object by position name. +const styleSource = fs.readFileSync(root + '/shell/Commons/Style.qml', 'utf8') +assert( + /Geometry\.parseWidthSpec\(barOverrides\["margin"\], 0\)/.test(styleSource), + 'the bar margin is parsed as a per-edge width spec' +) +assert( + /barOut\[key\] = raw/.test(styleSource), + 'the bar margin reaches the parser unparsed, so a list survives' +) +assert( + /readonly property int anchoredMargin: root\.barMargins\[root\.position\]/.test(barSource), + 'the anchored edge takes its own side of the margin' +) +// The drag overlays are full-screen, so a bar-local point becomes a screen point +// by adding the bar window's origin. A detached bar's origin is the gap itself on the +// axes it spans, and the far edge less its own size and gap on the one it is +// anchored to; without that the drop marker and the drag ghost sit a margin away +// from the cursor. +const windowScreenPoint = barSource.slice( + barSource.indexOf('function windowScreenPoint'), + barSource.indexOf('function barDragScreenPoint') +) +assert( + /var margins = root\.barMargins/.test(windowScreenPoint), + 'mapping a bar point to the screen accounts for a detached bar' +) +assert( + /window\.screen\.height - window\.height - margins\.bottom/.test(windowScreenPoint), + 'a detached bottom bar maps from its own top edge, not the screen edge' +) +assert( + /window\.screen\.width - window\.width - margins\.right/.test(windowScreenPoint), + 'a detached right bar maps from its own left edge, not the screen edge' +) + +// omarchy-bar-text-color samples the wallpaper under the bar to pick a legible +// transparent-mode foreground. It crops from the screen edge unless told +// otherwise, so a detached bar has to hand it the gap or the contrast is +// decided against pixels the bar does not cover. +const transparentForeground = barSource.slice( + barSource.indexOf('function refreshTransparentForeground'), + barSource.indexOf('onRequestedTransparentChanged') +) +assert( + /"--inset",\s*\n\s*\[root\.barMargins\.top/.test(transparentForeground), + 'transparent bar text samples the strip a detached bar covers' +) +assert( + /onBarMarginsChanged: scheduleTransparentForegroundRefresh\(\)/.test(barSource), + 'changing the bar margin re-samples the transparent bar text color' +) + const moduleSlot = barSource.slice(barSource.indexOf('component ModuleSlot'), barSource.indexOf('component CustomCommandModule')) const dragSpacer = barSource.slice(barSource.indexOf('component DragSpacer'), barSource.indexOf('component CenterGestureArea')) assert( diff --git a/test/shell.d/bar-text-color-test.sh b/test/shell.d/bar-text-color-test.sh index d22a289c0438..f50c734d9336 100755 --- a/test/shell.d/bar-text-color-test.sh +++ b/test/shell.d/bar-text-color-test.sh @@ -14,9 +14,12 @@ export PATH="$ROOT/bin:$PATH" light_top="$TMPDIR/light-top.png" dark_top="$TMPDIR/dark-top.png" +dark_band="$TMPDIR/dark-band.png" magick -size 100x100 xc:'#202020' -fill '#f5f5f5' -draw 'rectangle 0,0 99,19' "$light_top" magick -size 100x100 xc:'#f5f5f5' -fill '#202020' -draw 'rectangle 0,0 99,19' "$dark_top" +# Light everywhere but the band a bottom bar covers once it is inset by 20. +magick -size 100x100 xc:'#f5f5f5' -fill '#202020' -draw 'rectangle 0,60 99,79' "$dark_band" result=$(HOME="$TMPDIR" omarchy-bar-text-color top 20 '#ffffff' '#101010' --background "$light_top" --screen 100x100) [[ $result == "#101010" ]] || fail "transparent bar text switches to background color on light wallpaper" "expected #101010, got $result" @@ -41,3 +44,31 @@ ffmpeg -y -f lavfi -i "testsrc=size=640x360:rate=10:duration=2" \ result=$(HOME="$TMPDIR" omarchy-bar-text-color top 40 '#ffffff' '#101010' --background "$light_top_video" --screen 640x360) [[ $result == "#101010" ]] || fail "transparent bar text samples one frame of a video wallpaper" "expected #101010, got $result" pass "transparent bar text samples one frame of a video wallpaper" + +# A detached bar covers a strip the screen edge does not. Same wallpaper, same +# bar size: only the offset moves the sample off the light top band and onto the +# dark one below it, which has to flip the answer. +result=$(HOME="$TMPDIR" omarchy-bar-text-color top 20 '#ffffff' '#101010' --background "$light_top" --screen 100x100 --inset "20 0 0 0") +[[ $result == "#ffffff" ]] || fail "a detached top bar samples the strip it covers" "expected #ffffff, got $result" +pass "a detached top bar samples the strip it covers" + +result=$(HOME="$TMPDIR" omarchy-bar-text-color bottom 20 '#ffffff' '#101010' --background "$dark_band" --screen 100x100) +[[ $result == "#101010" ]] || fail "a flush bottom bar samples the screen edge" "expected #101010, got $result" +pass "a flush bottom bar samples the screen edge" + +result=$(HOME="$TMPDIR" omarchy-bar-text-color bottom 20 '#ffffff' '#101010' --background "$dark_band" --screen 100x100 --inset "0 0 20 0") +[[ $result == "#ffffff" ]] || fail "a detached bottom bar samples back from its own edge" "expected #ffffff, got $result" +pass "a detached bottom bar samples back from its own edge" + +# The gap on the axis the bar spans moves the sample sideways, which is the half +# of a per-edge inset the vertical cases above cannot show. +split="$TMPDIR/split.png" +magick -size 100x100 xc:'#f5f5f5' -fill '#202020' -draw 'rectangle 0,0 49,99' "$split" + +result=$(HOME="$TMPDIR" omarchy-bar-text-color top 20 '#ffffff' '#101010' --background "$split" --screen 100x100 --inset "0 0 0 50") +[[ $result == "#101010" ]] || fail "a bar inset from the left samples past the dark half" "expected #101010, got $result" +pass "a bar inset from the left samples past the dark half" + +result=$(HOME="$TMPDIR" omarchy-bar-text-color top 20 '#ffffff' '#101010' --background "$split" --screen 100x100 --inset "0 50 0 0") +[[ $result == "#ffffff" ]] || fail "a bar inset from the right stops before the light half" "expected #ffffff, got $result" +pass "a bar inset from the right stops before the light half" From a6a9d9b8a63ba9dede0fac97ed37d71fe140e482 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 19:59:41 +0000 Subject: [PATCH 3/8] Place bar popouts and toasts from a detached bar's outer face A detached bar sits its margin off the screen edge, but the panels opened from it, the clicks they forward back to the bar, and notification toasts still placed themselves as if it were flush: with a 10px margin a top bar's panels overlapped it and opened a margin left of their icon, and toasts covered it. Panels now place themselves from the bar window's origin and outer face (PanelGeometry.js), popup cards leave room for the edge margin, and toasts clear it. Widgets get the margins as bar.barMargins and plugins that place their own windows as shell.bar.barMargins, both as copies. Taken from Cristian Fleischer's floating bar work in #13138, without its floating switch. Co-authored-by: Cristian Fleischer <1486327+cristian-fleischer@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QJ9xdGDgAWUqbEooHGuMBS --- docs/omarchy-shell.md | 4 +- shell/Commons/PanelGeometry.js | 48 ++++++++++ shell/Ui/KeyboardPanel.qml | 83 +++++++---------- shell/Ui/PluginBarApi.qml | 3 + shell/Ui/PopupCard.qml | 7 +- shell/plugins/bar/Bar.qml | 4 + shell/plugins/bar/README.md | 1 + .../notifications/NotificationLogic.js | 7 +- shell/services/PluginBarStateApi.qml | 4 + shell/shell.qml | 13 +++ test/shell.d/bar-test.sh | 93 +++++++++++++++++++ 11 files changed, 214 insertions(+), 53 deletions(-) create mode 100644 shell/Commons/PanelGeometry.js diff --git a/docs/omarchy-shell.md b/docs/omarchy-shell.md index 547670d7476f..784d85e0c5b9 100644 --- a/docs/omarchy-shell.md +++ b/docs/omarchy-shell.md @@ -432,7 +432,7 @@ radius = 12 # corner rounding of the bar surface; 0 = square margin = "4 8" # 4 from the anchored edge, 8 at the two it spans ``` -Both default to `0`, a bar sitting flush against its edge with square corners, and both follow `scale-with-font` like the sizes above. The gap is reserved along with the bar itself, so maximized and tiled windows stop clear of it instead of sliding underneath. Auto-hide still parks the bar fully off screen, clearing the margin as well as the bar. +Both default to `0`, a bar sitting flush against its edge with square corners, and both follow `scale-with-font` like the sizes above. The gap is reserved along with the bar itself, so maximized and tiled windows stop clear of it instead of sliding underneath. Auto-hide still parks the bar fully off screen, clearing the margin as well as the bar. Panels opened from the bar and notifications place themselves from the bar's outer face, so they follow it. Widgets read the gap as `bar.barMargins`, and plugins that position their own windows as `shell.bar.barMargins`, both an object with `top`, `right`, `bottom` and `left`. ## Custom bar modules @@ -455,7 +455,7 @@ For a custom QML widget: Then `~/.config/omarchy/bar/modules/gpu.qml` (or set `source` to point elsewhere). The module is an `Item` and receives `bar`, `moduleName`, `settings` properties. `bar` exposes `foreground` / `background` / -`urgent` / `fontFamily` / `position` / `vertical` / `barSize`, plus +`urgent` / `fontFamily` / `position` / `vertical` / `barSize` / `barMargins`, plus `run(cmd)`, `showTooltip(t, s)` / `hideTooltip(t)`, `requestPopout(o)` / `releasePopout(o)`. To shell-quote arguments for `run`, use `Util.shellQuote(v)` from `qs.Commons`. diff --git a/shell/Commons/PanelGeometry.js b/shell/Commons/PanelGeometry.js new file mode 100644 index 000000000000..b247704250a9 --- /dev/null +++ b/shell/Commons/PanelGeometry.js @@ -0,0 +1,48 @@ +.pragma library + +// Placement of popouts opened from the bar. A floating bar sits `margins` off +// the screen edges it touches, so its window does not start at the screen's +// corner and its outer face is not at barSize from the edge. + +// Top-left of the bar window on its screen. +function barOrigin(position, margins, barW, barH, screenW, screenH) { + var m = margins || {} + return { + x: position === "right" ? screenW - (m.right || 0) - barW : (m.left || 0), + y: position === "bottom" ? screenH - (m.bottom || 0) - barH : (m.top || 0) + } +} + +// Top-left of a popout card on screen: `gap` off the bar's outer face, +// centred on its anchor (or on the bar with centerOnBar), and kept `margin` +// inside the screen. `anchor` is in screen coordinates. +// p: { position, centerOnBar, origin, barW, barH, anchor: { x, y, w, h }, +// width, height, gap, margin, screenW, screenH } +function cardOrigin(p) { + var o = p.origin + var position = p.position === "bottom" || p.position === "left" || p.position === "right" ? p.position : "top" + var horizontal = position === "top" || position === "bottom" + var x = 0, y = 0 + if (horizontal) { + x = p.centerOnBar ? o.x + p.barW / 2 - p.width / 2 : p.anchor.x + p.anchor.w / 2 - p.width / 2 + y = position === "bottom" ? o.y - p.height - p.gap : o.y + p.barH + p.gap + } else { + x = position === "left" ? o.x + p.barW + p.gap : o.x - p.width - p.gap + y = p.centerOnBar ? o.y + p.barH / 2 - p.height / 2 : p.anchor.y + p.anchor.h / 2 - p.height / 2 + } + x = Math.max(p.margin, Math.min(x, p.screenW - p.width - p.margin)) + y = Math.max(p.margin, Math.min(y, p.screenH - p.height - p.margin)) + return { x: Math.round(x), y: Math.round(y) } +} + +// Room for a card along one screen axis. Across a bar on that axis the card +// loses the bar, its edge margin and `awayReserve`; otherwise `crossReserve`. +function availableLength(screenLength, facesBar, barReach, awayReserve, crossReserve) { + return Math.max(120, screenLength - (facesBar ? barReach + awayReserve : crossReserve)) +} + +// Depth from the anchored screen edge that counts as the bar for forwarding +// clicks while a popout is open: the bar, its edge margin and the gap. +function barStripSize(barSize, thickness, edgeMargin, gap) { + return Math.max(barSize, thickness) + (edgeMargin || 0) + gap +} diff --git a/shell/Ui/KeyboardPanel.qml b/shell/Ui/KeyboardPanel.qml index ddf922964ce6..a12cc3cab93e 100644 --- a/shell/Ui/KeyboardPanel.qml +++ b/shell/Ui/KeyboardPanel.qml @@ -3,6 +3,7 @@ import Quickshell import Quickshell.Wayland import qs.Commons import qs.Commons as Commons +import "../Commons/PanelGeometry.js" as PanelGeometry // Layer-shell popup attached to a bar widget icon, designed for // click-driven AND keyboard-driven panels (e.g. SUPER+CTRL+W summon). @@ -28,8 +29,9 @@ import qs.Commons as Commons // axis (away-from-bar) because mapToItem on the anchor returns // bar-content-relative coords with internal layout offsets baked in // (e.g. ~13px from the bar's vertical centering of its widget row). The -// parallel axis (along-the-bar) uses the anchor's content x/y since the -// bar spans full screen on that axis. +// parallel axis (along-the-bar) uses the anchor's content x/y, shifted by +// the bar window's origin on screen: a floating bar sits `barMargins` off +// the screen edges. // // Outside-click dismissal: an overlay MouseArea catches clicks, with the // QsWindow.mask subtracting the bar strip so clicks on the bar still @@ -142,7 +144,7 @@ PanelWindow { readonly property real _barStripSize: { if (!bar) return 0 var actual = (root.barPos === "top" || root.barPos === "bottom") ? root.barH : root.barW - return Math.max(bar.barSize, actual) + root.gap + return PanelGeometry.barStripSize(bar.barSize, actual, root.barEdgeMargin, root.gap) } mask: Region { width: root.screenW @@ -159,25 +161,26 @@ PanelWindow { b: anchorItem } - // Anchor item's position within the bar's content surface. For a - // full-width top bar, the content x maps directly to screen x; the y - // returned here has the bar's internal padding baked in (e.g. ~13px - // from vertical centering of the widget row), which is why `cardOrigin` - // below uses `barH` for the perpendicular axis instead of this y. + // Anchor item's position on screen: its position in the bar window plus + // the window's origin (barX, barY). The coordinate across the bar has the + // bar's internal padding baked in (e.g. ~13px from vertical centering of + // the widget row), which is why `cardOrigin` places the card from the bar + // window's edge on that axis instead. readonly property point anchorScreenPos: { anchorWatcher.transform // reactive dependency if (!anchorItem || !anchorWindow) return Qt.point(0, 0) - return anchorItem.mapToItem(anchorWindow.contentItem, 0, 0) + var p = anchorItem.mapToItem(anchorWindow.contentItem, 0, 0) + return Qt.point(p.x + barX, p.y + barY) } readonly property real anchorW: anchorItem ? anchorItem.width : 0 readonly property real anchorH: anchorItem ? anchorItem.height : 0 readonly property real screenW: screen ? screen.width : 0 readonly property real screenH: screen ? screen.height : 0 readonly property real availableCardWidth: screenW > 0 - ? Math.max(120, screenW - ((barPos === "left" || barPos === "right") ? barW + gap + margin : margin * 2)) + ? PanelGeometry.availableLength(screenW, barPos === "left" || barPos === "right", barW + barEdgeMargin, gap + margin, margin * 2) : 0 readonly property real availableCardHeight: screenH > 0 - ? Math.max(120, screenH - ((barPos === "top" || barPos === "bottom") ? barH + gap + margin : margin * 2)) + ? PanelGeometry.availableLength(screenH, barPos === "top" || barPos === "bottom", barH + barEdgeMargin, gap + margin, margin * 2) : 0 readonly property real verticalContentInset: padding * 2 + Border.top(borderSpec) + Border.bottom(borderSpec) @@ -201,44 +204,30 @@ PanelWindow { return Math.round(Math.min(desired, maxHeight)) } - // Desired top-left of the card in screen coordinates. For the - // perpendicular axis (away-from-bar) we anchor to the bar window's edge - // directly — not the anchor item's y/x — because mapToItem(barContent) - // returns coordinates in the bar's content space, which can be offset - // from the bar surface's screen-anchored corner by internal layout - // (centering wrappers, padding). The bar's surface IS aligned to its - // anchored screen edge, so using `barW`/`barH` gives the right edge - // regardless of how the bar's internal widgets are positioned. For the - // parallel axis (along the bar) the anchor item's reported position is - // still consistent with the bar content origin, so it's accurate for - // centering the card under the icon. + // Desired top-left of the card in screen coordinates. Away from the bar + // the card is placed from the bar window's outer edge, not the anchor + // item's y/x, because the item's position carries internal layout offsets + // (centering wrappers, padding). Along the bar the anchor item's position + // is accurate, so the card centres under the icon. readonly property real barW: anchorWindow ? anchorWindow.width : screenW readonly property real barH: anchorWindow ? anchorWindow.height : 0 + // A floating bar sits barMargins off the screen edges it touches, so its + // window starts at (barX, barY) on screen. Both are 0 for a flush top or + // left bar. + readonly property var barMargins: bar && bar.barMargins ? bar.barMargins : ({ top: 0, right: 0, bottom: 0, left: 0 }) + readonly property real barEdgeMargin: barMargins[barPos] || 0 + readonly property var barOrigin: PanelGeometry.barOrigin(barPos, barMargins, barW, barH, screenW, screenH) + readonly property real barX: barOrigin.x + readonly property real barY: barOrigin.y readonly property point cardOrigin: { if (!anchorItem || !bar) return Qt.point(margin, margin) - var x = 0, y = 0 - if (centerOnBar && (barPos === "top" || barPos === "bottom")) { - x = screenW / 2 - contentWidth / 2 - y = barPos === "bottom" ? screenH - barH - contentHeight - gap : barH + gap - } else if (centerOnBar) { - x = barPos === "left" ? barW + gap : screenW - barW - contentWidth - gap - y = screenH / 2 - contentHeight / 2 - } else if (barPos === "bottom") { - x = anchorScreenPos.x + anchorW / 2 - contentWidth / 2 - y = screenH - barH - contentHeight - gap - } else if (barPos === "left") { - x = barW + gap - y = anchorScreenPos.y + anchorH / 2 - contentHeight / 2 - } else if (barPos === "right") { - x = screenW - barW - contentWidth - gap - y = anchorScreenPos.y + anchorH / 2 - contentHeight / 2 - } else { // "top" (default) - x = anchorScreenPos.x + anchorW / 2 - contentWidth / 2 - y = barH + gap - } - x = Math.max(margin, Math.min(x, screenW - contentWidth - margin)) - y = Math.max(margin, Math.min(y, screenH - contentHeight - margin)) - return Qt.point(Math.round(x), Math.round(y)) + var p = PanelGeometry.cardOrigin({ + position: barPos, centerOnBar: centerOnBar, origin: barOrigin, barW: barW, barH: barH, + anchor: { x: anchorScreenPos.x, y: anchorScreenPos.y, w: anchorW, h: anchorH }, + width: contentWidth, height: contentHeight, gap: gap, margin: margin, + screenW: screenW, screenH: screenH + }) + return Qt.point(p.x, p.y) } @@ -318,9 +307,7 @@ PanelWindow { } function barPoint(px, py) { - if (root.barPos === "bottom") return Qt.point(px, py - (root.screenH - root.barH)) - if (root.barPos === "right") return Qt.point(px - (root.screenW - root.barW), py) - return Qt.point(px, py) + return Qt.point(px - root.barX, py - root.barY) } function pressTargetAt(px, py) { diff --git a/shell/Ui/PluginBarApi.qml b/shell/Ui/PluginBarApi.qml index 5f55e6cd8e8f..8bd5cd19fe62 100644 --- a/shell/Ui/PluginBarApi.qml +++ b/shell/Ui/PluginBarApi.qml @@ -19,6 +19,9 @@ QtObject { property string position: "top" property bool vertical: false property int barSize: 0 + // Gap between a detached bar and the screen edges it touches, all 0 for a + // flush bar. A copy, so a widget can't change the bar's own. + property var barMargins: ({ top: 0, right: 0, bottom: 0, left: 0 }) property bool transparent: false property bool foregroundAnimationEnabled: true property bool centerSectionRevealHeld: false diff --git a/shell/Ui/PopupCard.qml b/shell/Ui/PopupCard.qml index ad3a514e6e8a..fcaa15dcdeef 100644 --- a/shell/Ui/PopupCard.qml +++ b/shell/Ui/PopupCard.qml @@ -3,6 +3,7 @@ import Quickshell import Quickshell.Hyprland import qs.Commons import qs.Commons as Commons +import "../Commons/PanelGeometry.js" as PanelGeometry PopupWindow { id: root @@ -30,11 +31,13 @@ PopupWindow { readonly property real screenH: popupScreen ? popupScreen.height : 0 readonly property real barW: anchorWindow ? anchorWindow.width : 0 readonly property real barH: anchorWindow ? anchorWindow.height : 0 + // A floating bar sits its edge margin off the screen edge. + readonly property real barEdgeMargin: bar && bar.barMargins ? (bar.barMargins[bar.position] || 0) : 0 readonly property real availableCardWidth: screenW > 0 - ? Math.max(120, screenW - ((bar && (bar.position === "left" || bar.position === "right")) ? barW : 0) - root.margin * 2) + ? PanelGeometry.availableLength(screenW, !!bar && (bar.position === "left" || bar.position === "right"), barW + barEdgeMargin, root.margin * 2, root.margin * 2) : 0 readonly property real availableCardHeight: screenH > 0 - ? Math.max(120, screenH - ((bar && (bar.position === "top" || bar.position === "bottom")) ? barH : 0) - root.margin * 2) + ? PanelGeometry.availableLength(screenH, !!bar && (bar.position === "top" || bar.position === "bottom"), barH + barEdgeMargin, root.margin * 2, root.margin * 2) : 0 readonly property real verticalContentInset: padding * 2 + Border.top(borderSpec) + Border.bottom(borderSpec) diff --git a/shell/plugins/bar/Bar.qml b/shell/plugins/bar/Bar.qml index 664b3d00b31a..c8eed90a36d3 100644 --- a/shell/plugins/bar/Bar.qml +++ b/shell/plugins/bar/Bar.qml @@ -191,6 +191,10 @@ Item { api.position = Qt.binding(function() { return root.position }) api.vertical = Qt.binding(function() { return root.vertical }) api.barSize = Qt.binding(function() { return root.barSize }) + api.barMargins = Qt.binding(function() { + var m = root.barMargins + return { top: m.top, right: m.right, bottom: m.bottom, left: m.left } + }) api.transparent = Qt.binding(function() { return root.transparent }) api.foregroundAnimationEnabled = Qt.binding(function() { return root.foregroundAnimationEnabled }) api.centerSectionRevealHeld = Qt.binding(function() { return root.centerSectionRevealHeld }) diff --git a/shell/plugins/bar/README.md b/shell/plugins/bar/README.md index 939990c793cf..2155cde6d0e0 100644 --- a/shell/plugins/bar/README.md +++ b/shell/plugins/bar/README.md @@ -174,6 +174,7 @@ Widgets receive `bar` (the shell root), `moduleName` (string), and `settings` (o - `bar.position` — `"top" | "bottom" | "left" | "right"` - `bar.vertical` — boolean shortcut - `bar.barSize` — 26 horizontal / 28 vertical +- `bar.barMargins` — `{ top, right, bottom, left }` gap between a detached bar and the screen edges it touches; all 0 for a flush bar - `bar.run(command)` — fire-and-forget bash exec (quote arguments with `Util.shellQuote` from `qs.Commons`) - `bar.showTooltip(target, text)` / `bar.hideTooltip(target)` — shared tooltip popup - `bar.requestPopout(owner)` / `bar.releasePopout(owner)` — one-popup-at-a-time coordinator diff --git a/shell/plugins/notifications/NotificationLogic.js b/shell/plugins/notifications/NotificationLogic.js index 6ba2b6ab45a9..cd5073f0dc3d 100644 --- a/shell/plugins/notifications/NotificationLogic.js +++ b/shell/plugins/notifications/NotificationLogic.js @@ -416,13 +416,18 @@ function popupExpired(entry, duration, now) { // thickness on that screen (a notch floor can make a top bar thicker than its // configured size on one screen), plus the gap. A bar without per-screen // sizes counts its configured size; a hidden or missing one, the default size. +// A floating bar sits its edge margin (barMargins) off the screen edge, so +// that is cleared too. function barClearance(bar, screenName, defaultBarSize, gapsOut) { var size = Number(defaultBarSize) + var margin = 0 if (bar && !bar.barHidden) { size = Number(typeof bar.barSizeFor === "function" ? bar.barSizeFor(screenName) : bar.barSize) size = isFinite(size) ? Math.max(0, size) : 0 + margin = bar.barMargins ? Number(bar.barMargins[String(bar.position || "top")]) : 0 + if (!isFinite(margin) || margin < 0) margin = 0 } - return size + Number(gapsOut) + return size + margin + Number(gapsOut) } function popupPlacement(barPosition, barClearance, gapsOut) { diff --git a/shell/services/PluginBarStateApi.qml b/shell/services/PluginBarStateApi.qml index 82b227180279..85ff6ace4e1d 100644 --- a/shell/services/PluginBarStateApi.qml +++ b/shell/services/PluginBarStateApi.qml @@ -10,6 +10,10 @@ QtObject { // screen; barSizes holds each screen's thickness by screen name. property int barSize: 0 property var barSizes: ({}) + // Gap between a detached bar and the screen edges it touches, all 0 for a + // flush bar: the bar's outer face is its thickness plus + // barMargins[position] from its edge. + property var barMargins: ({ top: 0, right: 0, bottom: 0, left: 0 }) property string fontFamily: "" property string position: "top" diff --git a/shell/shell.qml b/shell/shell.qml index 78e38d0d9dab..45f845fe842d 100644 --- a/shell/shell.qml +++ b/shell/shell.qml @@ -454,6 +454,18 @@ ShellRoot { return copy } + // A bar plugin's edge margins as plain numbers, all 0 for a bar that has + // none, so a plugin holds a copy rather than the bar's own object. + function detachedBarMargins(margins) { + var m = Util.isPlainObject(margins) ? margins : ({}) + return { + top: Math.max(0, Number(m.top) || 0), + right: Math.max(0, Number(m.right) || 0), + bottom: Math.max(0, Number(m.bottom) || 0), + left: Math.max(0, Number(m.left) || 0) + } + } + function pluginBarStateFor(cacheKey, pluginId) { if (_pluginBarStateApis[cacheKey]) return _pluginBarStateApis[cacheKey] var api = pluginBarStateApiComponent.createObject(null, { ownerPluginId: pluginId }) @@ -461,6 +473,7 @@ ShellRoot { api.barHidden = Qt.binding(function() { return shell.bar ? shell.bar.barHidden === true : false }) api.barSize = Qt.binding(function() { return shell.bar ? Math.max(0, shell.bar.barSize || 0) : 0 }) api.barSizes = Qt.binding(function() { return shell.bar ? shell.detachedBarSizes(shell.bar.screenBarSizes) : ({}) }) + api.barMargins = Qt.binding(function() { return shell.detachedBarMargins(shell.bar ? shell.bar.barMargins : null) }) api.fontFamily = Qt.binding(function() { return shell.bar ? String(shell.bar.fontFamily || "") : "" }) api.position = Qt.binding(function() { return shell.bar ? String(shell.bar.position || "top") : "top" }) var next = ({}) diff --git a/test/shell.d/bar-test.sh b/test/shell.d/bar-test.sh index 00e85098177b..dc581d171efc 100644 --- a/test/shell.d/bar-test.sh +++ b/test/shell.d/bar-test.sh @@ -152,6 +152,99 @@ assert( 'changing the bar margin re-samples the transparent bar text color' ) +// Popouts and toasts place themselves from the bar's outer face, which a +// detached bar moves off the screen edge. The arithmetic runs by value; the +// QML is checked only for feeding it the bar's margins. +{ + const vm = require('vm') + const panelGeometry = vm.createContext({}) + vm.runInContext(fs.readFileSync(root + '/shell/Commons/PanelGeometry.js', 'utf8').replace(/^\.pragma library\n/, ''), panelGeometry) + const flush = { top: 0, right: 0, bottom: 0, left: 0 } + const detached = { top: 6, right: 12, bottom: 12, left: 12 } + const origin = (position, margins, w, h) => JSON.parse(JSON.stringify(panelGeometry.barOrigin(position, margins, w, h, 2000, 1250))) + assertDeepEqual(origin('top', flush, 2000, 26), { x: 0, y: 0 }, 'a flush top bar starts at the screen corner') + assertDeepEqual(origin('top', detached, 1976, 26), { x: 12, y: 6 }, 'a detached top bar starts at its margins') + assertDeepEqual(origin('bottom', { top: 12, right: 12, bottom: 6, left: 12 }, 1976, 26), { x: 12, y: 1218 }, 'a detached bottom bar ends its margin above the screen edge') + assertDeepEqual(origin('right', { top: 12, right: 6, bottom: 12, left: 12 }, 28, 1226), { x: 1966, y: 12 }, 'a detached right bar ends its margin left of the screen edge') + + const card = (position, margins, barW, barH, anchor, centerOnBar) => { + const o = panelGeometry.barOrigin(position, margins, barW, barH, 2000, 1250) + return JSON.parse(JSON.stringify(panelGeometry.cardOrigin({ + position, centerOnBar: !!centerOnBar, origin: o, barW, barH, anchor, + width: 300, height: 200, gap: 6, margin: 6, screenW: 2000, screenH: 1250 + }))) + } + // An icon at x 988..1012 on screen: 976 inside a bar that starts at x 12. + const icon = { x: 988, y: 1, w: 24, h: 24 } + assertDeepEqual(card('top', flush, 2000, 26, icon), { x: 850, y: 32 }, 'a flush top bar opens its card gap below the bar, centred on the icon') + assertDeepEqual(card('top', detached, 1976, 26, icon), { x: 850, y: 38 }, 'a detached top bar opens its card gap below its outer face, centred on the icon') + assertDeepEqual(card('top', { top: 6, right: 30, bottom: 12, left: 10 }, 1960, 26, icon, true), { x: 840, y: 38 }, 'a centred card follows the bar, not the screen, with uneven margins') + assertDeepEqual(card('bottom', { top: 12, right: 12, bottom: 6, left: 12 }, 1976, 26, icon), { x: 850, y: 1012 }, 'a detached bottom bar opens its card gap above its outer face') + assertDeepEqual(card('left', { top: 12, right: 12, bottom: 12, left: 6 }, 28, 1226, { x: 8, y: 600, w: 20, h: 20 }), { x: 40, y: 510 }, 'a detached left bar opens its card gap right of its outer face') + assertDeepEqual(card('right', { top: 12, right: 6, bottom: 12, left: 12 }, 28, 1226, { x: 1970, y: 600, w: 20, h: 20 }), { x: 1660, y: 510 }, 'a detached right bar opens its card gap left of its outer face') + assertDeepEqual(card('top', detached, 1976, 26, { x: 1980, y: 1, w: 24, h: 24 }), { x: 1694, y: 38 }, 'a card near the screen end stays inside the screen margin') + assertDeepEqual(card('left', { top: 30, right: 12, bottom: 10, left: 6 }, 28, 1210, { x: 8, y: 600, w: 20, h: 20 }, true), { x: 40, y: 535 }, 'a centred card on a side bar follows the bar, not the screen') + // Room for a card: across the bar it loses the bar, its edge margin and + // the reserve; along the bar only the reserve. + assertEqual(panelGeometry.availableLength(1250, true, 26 + 6, 12, 12), 1206, 'a card below a detached bar loses the bar and its margin') + assertEqual(panelGeometry.availableLength(1250, true, 26, 12, 12), 1212, 'a card below a flush bar loses the bar') + assertEqual(panelGeometry.availableLength(2000, false, 26 + 6, 12, 12), 1988, 'a card along the bar loses only the reserve') + assertEqual(panelGeometry.availableLength(100, true, 26, 12, 12), 120, 'a card keeps at least 120 px') + assertEqual(panelGeometry.barStripSize(26, 26, 6, 6), 38, 'clicks up to the gap below a detached bar count as the bar') + assertEqual(panelGeometry.barStripSize(26, 26, 0, 6), 32, 'a flush bar strip is the bar and the gap') + + const panelSource = fs.readFileSync(root + '/shell/Ui/KeyboardPanel.qml', 'utf8') + assert( + /readonly property var barMargins: bar && bar\.barMargins \? bar\.barMargins :/.test(panelSource) && + /readonly property real barEdgeMargin: barMargins\[barPos\]/.test(panelSource) && + /readonly property var barOrigin: PanelGeometry\.barOrigin\(barPos, barMargins, barW, barH, screenW, screenH\)/.test(panelSource) && + /readonly property real barX: barOrigin\.x/.test(panelSource) && /readonly property real barY: barOrigin\.y/.test(panelSource) && + /return Qt\.point\(p\.x \+ barX, p\.y \+ barY\)/.test(panelSource) && + /PanelGeometry\.cardOrigin\(\{[\s\S]*?origin: barOrigin[\s\S]*?anchor: \{ x: anchorScreenPos\.x, y: anchorScreenPos\.y/.test(panelSource) && + /PanelGeometry\.barStripSize\(bar\.barSize, actual, root\.barEdgeMargin, root\.gap\)/.test(panelSource) && + /PanelGeometry\.availableLength\(screenW, barPos === "left" \|\| barPos === "right", barW \+ barEdgeMargin, gap \+ margin, margin \* 2\)/.test(panelSource) && + /PanelGeometry\.availableLength\(screenH, barPos === "top" \|\| barPos === "bottom", barH \+ barEdgeMargin, gap \+ margin, margin \* 2\)/.test(panelSource) && + /return Qt\.point\(px - root\.barX, py - root\.barY\)/.test(panelSource), + 'bar popouts place and forward through the bar window origin and margins' + ) + + // Tray menus, the media popup and the bar options size themselves the same way. + const popupSource = fs.readFileSync(root + '/shell/Ui/PopupCard.qml', 'utf8') + assert( + /readonly property real barEdgeMargin: bar && bar\.barMargins \? \(bar\.barMargins\[bar\.position\] \|\| 0\) : 0/.test(popupSource) && + /PanelGeometry\.availableLength\(screenW, !!bar && \(bar\.position === "left" \|\| bar\.position === "right"\), barW \+ barEdgeMargin, root\.margin \* 2, root\.margin \* 2\)/.test(popupSource) && + /PanelGeometry\.availableLength\(screenH, !!bar && \(bar\.position === "top" \|\| bar\.position === "bottom"\), barH \+ barEdgeMargin, root\.margin \* 2, root\.margin \* 2\)/.test(popupSource), + 'popup cards leave room for a detached bar\'s edge margin' + ) + + const notificationLogic = requireFromRoot('shell/plugins/notifications/NotificationLogic.js') + const flushBar = { barSize: 26, position: 'top', barMargins: flush } + const detachedBar = { barSize: 26, position: 'top', barMargins: detached } + const rightBar = { barSize: 28, position: 'right', barMargins: { top: 12, right: 6, bottom: 12, left: 12 } } + const notchBar = { barSize: 26, position: 'top', barMargins: detached, barSizeFor: () => 40 } + assertEqual(notificationLogic.barClearance(null, 'eDP-1', 26, 6), 32, 'toasts clear a missing bar by the default size and the gap') + assertEqual(notificationLogic.barClearance(Object.assign({}, detachedBar, { barHidden: true }), 'eDP-1', 26, 6), 32, 'toasts clear a hidden bar by the default size and the gap') + assertEqual(notificationLogic.barClearance(flushBar, 'eDP-1', 26, 6), 32, 'toasts clear a flush bar by its size and the gap') + assertEqual(notificationLogic.barClearance(detachedBar, 'eDP-1', 26, 6), 38, 'toasts clear a detached top bar\'s edge margin') + assertEqual(notificationLogic.barClearance(rightBar, 'eDP-1', 26, 6), 40, 'toasts clear a detached right bar\'s edge margin') + assertEqual(notificationLogic.barClearance(notchBar, 'eDP-1', 26, 6), 52, 'toasts clear a detached bar a notch has made thicker, margin included') + + // Widgets and plugins that place their own windows get the margins too, as + // copies, so none of them can change the bar's own. + const pluginApiSource = fs.readFileSync(root + '/shell/Ui/PluginBarApi.qml', 'utf8') + const stateApiSource = fs.readFileSync(root + '/shell/services/PluginBarStateApi.qml', 'utf8') + assert( + /property var barMargins:/.test(pluginApiSource) && + /api\.barMargins = Qt\.binding\(function\(\) \{\s*var m = root\.barMargins\s*return \{ top: m\.top, right: m\.right, bottom: m\.bottom, left: m\.left \}/.test(barSource), + 'bar widgets get a copy of the margins as bar.barMargins' + ) + assert( + /property var barMargins:/.test(stateApiSource) && + /api\.barMargins = Qt\.binding\(function\(\) \{ return shell\.detachedBarMargins\(shell\.bar \? shell\.bar\.barMargins : null\) \}\)/.test(shellSource), + 'plugins positioning their own windows get a copy of the margins as shell.bar.barMargins' + ) +} + const moduleSlot = barSource.slice(barSource.indexOf('component ModuleSlot'), barSource.indexOf('component CustomCommandModule')) const dragSpacer = barSource.slice(barSource.indexOf('component DragSpacer'), barSource.indexOf('component CenterGestureArea')) assert( From c5d50b5d868d993105788b261fdf9e3dc7c8ab7e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 19:59:41 +0000 Subject: [PATCH 4/8] Correct the per-edge bar margin example "4 8" is 4 top and bottom and 8 left and right, which is 4 from the anchored edge only for a top or bottom bar; on a side bar the 8 is. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QJ9xdGDgAWUqbEooHGuMBS --- docs/omarchy-shell.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/omarchy-shell.md b/docs/omarchy-shell.md index 784d85e0c5b9..350202d0120f 100644 --- a/docs/omarchy-shell.md +++ b/docs/omarchy-shell.md @@ -425,11 +425,11 @@ margin = 10 # gap between the bar and the screen edges; 0 = flush radius = 12 # corner rounding of the bar surface; 0 = square ``` -`margin` accepts the same CSS-style list as the border widths — `N`, `"Y X"`, `"T X B"`, or `"T R B L"` — so the gap can differ per edge. A bar set further off the sides than off the edge it hangs from: +`margin` accepts the same CSS-style list as the border widths — `N`, `"Y X"`, `"T X B"`, or `"T R B L"` — so the gap can differ per edge. A top bar set further off the sides than off the edge it hangs from: ```toml [bar] -margin = "4 8" # 4 from the anchored edge, 8 at the two it spans +margin = "4 8" # 4 top and bottom, 8 left and right: a top bar sits 4 below the edge and 8 in from each side ``` Both default to `0`, a bar sitting flush against its edge with square corners, and both follow `scale-with-font` like the sizes above. The gap is reserved along with the bar itself, so maximized and tiled windows stop clear of it instead of sliding underneath. Auto-hide still parks the bar fully off screen, clearing the margin as well as the bar. Panels opened from the bar and notifications place themselves from the bar's outer face, so they follow it. Widgets read the gap as `bar.barMargins`, and plugins that position their own windows as `shell.bar.barMargins`, both an object with `top`, `right`, `bottom` and `left`. From ba081bf64ebc8493f1bc63adbc61d1eb4323d5e6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 20:25:55 +0000 Subject: [PATCH 5/8] Sample the transparent bar's text color in logical pixels The bar's size and its new insets are logical pixels, but the screen was measured in hyprctl's physical mode, so on a scaled display the sample moved off the strip a detached bar covers. Measure the screen in logical pixels too, and fall back when a top or left inset pushes the strip off the screen instead of sampling what is left of it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QJ9xdGDgAWUqbEooHGuMBS --- bin/omarchy-bar-text-color | 9 ++++++--- test/shell.d/bar-text-color-test.sh | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bin/omarchy-bar-text-color b/bin/omarchy-bar-text-color index eed3dbee0ae1..397d659d9097 100755 --- a/bin/omarchy-bar-text-color +++ b/bin/omarchy-bar-text-color @@ -90,9 +90,12 @@ if [[ -z $background_path ]]; then fi [[ -f $background_path ]] || fallback +# The bar's size and insets are logical pixels and hyprctl reports the physical +# mode, so the screen is measured in logical pixels too: the wallpaper is +# scaled to cover it either way, and every crop below lands where the bar is. if [[ -z $screen_size ]]; then if omarchy-cmd-present hyprctl && omarchy-cmd-present jq; then - screen_size=$(hyprctl monitors -j 2>/dev/null | jq -r '.[0] | "\(.width)x\(.height)"' 2>/dev/null || true) + screen_size=$(hyprctl monitors -j 2>/dev/null | jq -r '.[0] | (.scale // 1) as $scale | "\(.width / $scale | round)x\(.height / $scale | round)"' 2>/dev/null || true) fi fi [[ $screen_size =~ ^([0-9]+)x([0-9]+)$ ]] || fallback @@ -107,7 +110,7 @@ screen_height=${BASH_REMATCH[2]} case "$position" in top) crop_width=$((screen_width - inset_left - inset_right)) - ((crop_width > 0)) || fallback + ((crop_width > 0 && inset_top + bar_size <= screen_height)) || fallback crop="${crop_width}x${bar_size}+${inset_left}+${inset_top}" ;; bottom) @@ -118,7 +121,7 @@ bottom) ;; left) crop_height=$((screen_height - inset_top - inset_bottom)) - ((crop_height > 0)) || fallback + ((crop_height > 0 && inset_left + bar_size <= screen_width)) || fallback crop="${bar_size}x${crop_height}+${inset_left}+${inset_top}" ;; right) diff --git a/test/shell.d/bar-text-color-test.sh b/test/shell.d/bar-text-color-test.sh index f50c734d9336..a8d9b68ad71e 100755 --- a/test/shell.d/bar-text-color-test.sh +++ b/test/shell.d/bar-text-color-test.sh @@ -6,6 +6,7 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" require_command magick require_command ffmpeg +require_command jq TMPDIR=$(mktemp -d) trap 'rm -rf "$TMPDIR"' EXIT @@ -72,3 +73,25 @@ pass "a bar inset from the left samples past the dark half" result=$(HOME="$TMPDIR" omarchy-bar-text-color top 20 '#ffffff' '#101010' --background "$split" --screen 100x100 --inset "0 50 0 0") [[ $result == "#ffffff" ]] || fail "a bar inset from the right stops before the light half" "expected #ffffff, got $result" pass "a bar inset from the right stops before the light half" + +# The bar's size and insets are logical pixels, while hyprctl reports the +# physical mode. On a 2x screen the strip a bar inset by 20 covers is the dark +# band at rows 60-79 of the logical 100x100 screen. Measured in physical pixels +# instead, the same numbers would sample light rows above it. +fake_bin="$TMPDIR/fake-bin" +mkdir -p "$fake_bin" +cat >"$fake_bin/hyprctl" <<'STUB' +#!/bin/bash +[[ $* == "monitors -j" ]] && printf '%s\n' '[{"width":200,"height":200,"scale":2}]' +STUB +chmod +x "$fake_bin/hyprctl" + +result=$(HOME="$TMPDIR" PATH="$fake_bin:$PATH" omarchy-bar-text-color bottom 20 '#ffffff' '#101010' --background "$dark_band" --inset "0 0 20 0") +[[ $result == "#ffffff" ]] || fail "a detached bar on a scaled screen samples the strip it covers" "expected #ffffff, got $result" +pass "a detached bar on a scaled screen samples the strip it covers" + +# A margin that pushes the strip off the screen falls back instead of sampling +# whatever is left of it. +result=$(HOME="$TMPDIR" omarchy-bar-text-color top 20 '#ffffff' '#101010' --background "$dark_top" --screen 100x100 --inset "90 0 0 0") +[[ $result == "#ffffff" ]] || fail "a top bar inset past the screen falls back to the text color" "expected #ffffff, got $result" +pass "a top bar inset past the screen falls back to the text color" From 054dd1a27ef517e38a0c1d56eb1754ffb18f1bcd Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 20:26:23 +0000 Subject: [PATCH 6/8] Let a detached top bar's margin count toward clearing the notch A top margin moves the bar down past part or all of a camera cutout, but the bar still took the whole cutout as its floor and still moved its center sections beside the right one. The cutout now reaches into the bar only as far as it extends past the margin: the floor shrinks by the margin, and a margin that clears the cutout leaves a plain bar with its center in the middle. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QJ9xdGDgAWUqbEooHGuMBS --- shell/plugins/bar/Bar.qml | 14 ++++++++++++-- shell/plugins/bar/BarModel.js | 8 ++++++++ test/shell.d/bar-notch-test.sh | 20 +++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/shell/plugins/bar/Bar.qml b/shell/plugins/bar/Bar.qml index c8eed90a36d3..20079572f7ed 100644 --- a/shell/plugins/bar/Bar.qml +++ b/shell/plugins/bar/Bar.qml @@ -718,12 +718,20 @@ Item { } // How thick the bar is on a screen. A top bar shorter than a panel's camera + // How far a panel's camera cutout reaches into the top bar on a screen. A + // detached bar sits its top margin below the edge, so the cutout reaches + // that much less into it, and not at all once the margin clears it. + function notchReachFor(screen) { + if (root.vertical || !screen) return 0 + return BarModel.notchReach(BarModel.notchFloor(root.displayCutouts, root.position, screen.name, screen.width, screen.height, screen.devicePixelRatio, root.panelModeFor(screen), Style.bar.notchHeight), root.barMargins.top) + } + // cutout leaves a sliver of every window peeking out beside the camera, so // the cutout is this panel's minimum sensible top-bar height. An // intentionally taller bar still wins. function thicknessFor(screen) { if (root.vertical || !screen) return root.barSize - return Math.max(root.barSize, BarModel.notchFloor(root.displayCutouts, root.position, screen.name, screen.width, screen.height, screen.devicePixelRatio, root.panelModeFor(screen), Style.bar.notchHeight)) + return Math.max(root.barSize, root.notchReachFor(screen)) } // Each screen's bar thickness, by screen name: barSize, or more where a notch @@ -1599,7 +1607,9 @@ Item { readonly property var panelMode: root.panelModeFor(screen) - readonly property bool centerBesideRight: BarModel.centerBesideRight(root.displayCutouts, root.position, screen.name, screen.width, screen.height, screen.devicePixelRatio, panelMode) + // Only while the cutout still reaches into the bar: a top margin that + // clears it leaves the center section in the middle. + readonly property bool centerBesideRight: BarModel.centerBesideRight(root.displayCutouts, root.position, screen.name, screen.width, screen.height, screen.devicePixelRatio, panelMode) && root.notchReachFor(screen) > 0 readonly property bool cutoutPending: BarModel.cutoutPending(root.displayCutouts, root.position, screen.name, screen.width, screen.height, screen.devicePixelRatio, panelMode) property bool cutoutWaitOver: false diff --git a/shell/plugins/bar/BarModel.js b/shell/plugins/bar/BarModel.js index d86e05d2e151..4334cf4a2e43 100644 --- a/shell/plugins/bar/BarModel.js +++ b/shell/plugins/bar/BarModel.js @@ -606,6 +606,13 @@ function cutoutPending(cutouts, position, screenName, logicalWidth, logicalHeigh return described && !(cutoutTop(cutouts, screenName, logicalWidth, logicalHeight, devicePixelRatio, mode) > 0) } +// How far a cutout reaches into a top bar that sits `margin` below the screen +// edge: the floor less the margin, and nothing once the margin clears it. +function notchReach(floor, margin) { + var reach = Number(floor) - Math.max(0, Number(margin) || 0) + return reach > 0 ? reach : 0 +} + // The bar's thickness on the screen with this name, from the sizes a bar // publishes by screen name, or `fallback` (its configured size) for a screen // it has none for. @@ -623,6 +630,7 @@ if (typeof module !== "undefined") { cutoutTop: cutoutTop, isDrawnSlot: isDrawnSlot, notchFloor: notchFloor, + notchReach: notchReach, parseCutouts: parseCutouts, pickDrawnSlot: pickDrawnSlot, pickPanelSlot: pickPanelSlot, diff --git a/test/shell.d/bar-notch-test.sh b/test/shell.d/bar-notch-test.sh index 4bd7d3ac5848..41f01c8053f7 100644 --- a/test/shell.d/bar-notch-test.sh +++ b/test/shell.d/bar-notch-test.sh @@ -105,11 +105,25 @@ assert( 'bar takes its screen\'s physical mode from Hyprland' ) assert( - /function thicknessFor\(screen\) \{\s*if \(root\.vertical \|\| !screen\) return root\.barSize\s*return Math\.max\(root\.barSize, BarModel\.notchFloor\(/.test(barSource) && + /function thicknessFor\(screen\) \{\s*if \(root\.vertical \|\| !screen\) return root\.barSize\s*return Math\.max\(root\.barSize, root\.notchReachFor\(screen\)\)/.test(barSource) && /readonly property int thickness: root\.thicknessFor\(screen\)/.test(barSource) && /implicitHeight: root\.vertical \? 0 : thickness/.test(barSource), 'bar height is floored at the cutout, never shrunk to it' ) + +// A detached top bar sits its top margin below the edge, so the cutout reaches +// only the rest of the floor into it, and nothing once the margin clears it. +assertEqual(bar.notchReach(32, 0), 32, 'a flush top bar meets the whole cutout') +assertEqual(bar.notchReach(32, 10), 22, 'a top margin shortens how far the cutout reaches into the bar') +assertEqual(bar.notchReach(32, 32), 0, 'a top margin as tall as the cutout clears it') +assertEqual(bar.notchReach(32, 40), 0, 'a top margin past the cutout clears it') +assertEqual(bar.notchReach(0, 10), 0, 'a screen without a cutout has nothing to reach') +assertEqual(bar.notchReach(32, -4), 32, 'a negative margin counts as none') +assertEqual(bar.notchReach(32, 'x'), 32, 'an unreadable margin counts as none') +assert( + /function notchReachFor\(screen\) \{\s*if \(root\.vertical \|\| !screen\) return 0\s*return BarModel\.notchReach\(BarModel\.notchFloor\([^\n]*\), root\.barMargins\.top\)/.test(barSource), + 'the floor a top bar takes is what the cutout reaches past its top margin' +) // A hidden bar parks by that same thickness (bar-test.sh), so a floored top // bar leaves no strip of itself on screen. @@ -136,6 +150,10 @@ assert( /centerBesideRight: BarModel\.centerBesideRight\(root\.displayCutouts, root\.position, screen\.name, screen\.width, screen\.height, screen\.devicePixelRatio, panelMode\)/.test(barSource), 'each bar surface decides the move from its own screen' ) +assert( + /centerBesideRight: BarModel\.centerBesideRight\([^\n]*\) && root\.notchReachFor\(screen\) > 0/.test(barSource), + 'a top bar whose margin clears the cutout keeps the center section in the middle' +) assert( /CenterModules \{\s*anchors\.fill: parent\s*window: barWindow\s*pool: horizontalPool\s*drawn: !barWindow\.centerBesideRight\s*\}/.test(barSource), 'a moved center section draws nothing in the middle of the bar' From b4d7678da863f4fe00030d4c2131a0eed86e5689 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 20:26:42 +0000 Subject: [PATCH 7/8] Keep a detached bar's margins to the edges it touches The bar handed out the margin width spec as written, so a top bar with "4 8" told widgets and plugins it had a 4px gap below it, and a flush bar could report a margin. barMargins now holds only the anchored edge and the two it spans, as numbers, and panel placement reads them as numbers whatever bar supplied them. Moving the bar previews it where it will land, off the candidate edge by that edge's margins and rounded like the bar. A hidden bar parks by its thickness alone, which already puts it off screen whatever its gap. The shell.toml parsing and the per-edge margins are tested by value. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QJ9xdGDgAWUqbEooHGuMBS --- shell/Commons/PanelGeometry.js | 5 +- shell/plugins/bar/Bar.qml | 28 +++++----- shell/plugins/bar/BarModel.js | 20 +++++++ test/shell.d/bar-test.sh | 96 +++++++++++++++++++++++++++++++--- 4 files changed, 129 insertions(+), 20 deletions(-) diff --git a/shell/Commons/PanelGeometry.js b/shell/Commons/PanelGeometry.js index b247704250a9..8ac60e8005f7 100644 --- a/shell/Commons/PanelGeometry.js +++ b/shell/Commons/PanelGeometry.js @@ -7,9 +7,10 @@ // Top-left of the bar window on its screen. function barOrigin(position, margins, barW, barH, screenW, screenH) { var m = margins || {} + var side = function(name) { return Number(m[name]) || 0 } return { - x: position === "right" ? screenW - (m.right || 0) - barW : (m.left || 0), - y: position === "bottom" ? screenH - (m.bottom || 0) - barH : (m.top || 0) + x: position === "right" ? screenW - side("right") - barW : side("left"), + y: position === "bottom" ? screenH - side("bottom") - barH : side("top") } } diff --git a/shell/plugins/bar/Bar.qml b/shell/plugins/bar/Bar.qml index 20079572f7ed..eb2ab192fd3b 100644 --- a/shell/plugins/bar/Bar.qml +++ b/shell/plugins/bar/Bar.qml @@ -670,9 +670,10 @@ Item { readonly property int barSize: vertical ? Style.bar.sizeVertical : Style.bar.sizeHorizontal // A detached bar floats barMargins away from every screen edge it touches // and rounds its corners by barRadius. Every side is 0 by default, which - // anchors the bar flush against its edge with square corners. The keys are - // the position names, so barMargins[position] is the anchored edge's gap. - readonly property var barMargins: Style.bar.margins + // anchors the bar flush against its edge with square corners, and the far + // face is always 0. The keys are the position names, so + // barMargins[position] is the anchored edge's gap. + readonly property var barMargins: BarModel.edgeMargins(Style.bar.margins, position) readonly property int barRadius: Style.bar.radius // Display cutouts (a camera notch) the platform's own package describes in @@ -717,7 +718,6 @@ Item { }) : null } - // How thick the bar is on a screen. A top bar shorter than a panel's camera // How far a panel's camera cutout reaches into the top bar on a screen. A // detached bar sits its top margin below the edge, so the cutout reaches // that much less into it, and not at all once the margin clears it. @@ -726,6 +726,7 @@ Item { return BarModel.notchReach(BarModel.notchFloor(root.displayCutouts, root.position, screen.name, screen.width, screen.height, screen.devicePixelRatio, root.panelModeFor(screen), Style.bar.notchHeight), root.barMargins.top) } + // How thick the bar is on a screen. A top bar shorter than a panel's camera // cutout leaves a sliver of every window peeking out beside the camera, so // the cutout is this panel's minimum sensible top-bar height. An // intentionally taller bar still wins. @@ -1582,10 +1583,10 @@ Item { } // Parked by its full thickness, which a notch floor may make more than - // barSize, plus its margin, so neither the bar nor the gap leaves a strip - // of it on screen. + // barSize, so no strip of it stays on screen. The parked margin replaces + // the anchored edge's gap rather than adding to it. readonly property int anchoredMargin: root.barMargins[root.position] - readonly property int parkedMargin: -(barWindow.thickness + anchoredMargin) + readonly property int parkedMargin: -barWindow.thickness readonly property int edgeMargin: root.barHidden ? parkedMargin : anchoredMargin // Only the edges the bar actually touches take a gap: the one it is @@ -1891,11 +1892,14 @@ Item { required property string modelData readonly property bool edgeVertical: modelData === "left" || modelData === "right" readonly property int edgeSize: edgeVertical ? Style.bar.sizeVertical : Style.bar.sizeHorizontal - - x: modelData === "right" ? parent.width - edgeSize : 0 - y: modelData === "bottom" ? parent.height - edgeSize : 0 - width: edgeVertical ? edgeSize : parent.width - height: edgeVertical ? parent.height : edgeSize + // Where a detached bar would land on this edge, rounded as it would be. + readonly property var edgeMargins: BarModel.edgeMargins(Style.bar.margins, modelData) + + x: modelData === "right" ? parent.width - edgeSize - edgeMargins.right : edgeMargins.left + y: modelData === "bottom" ? parent.height - edgeSize - edgeMargins.bottom : edgeMargins.top + width: edgeVertical ? edgeSize : parent.width - edgeMargins.left - edgeMargins.right + height: edgeVertical ? parent.height - edgeMargins.top - edgeMargins.bottom : edgeSize + radius: Style.bar.radius color: root.transparent ? "transparent" : root.background borderSpec: Border.flat(root.barForeground, 1) visible: opacity > 0 diff --git a/shell/plugins/bar/BarModel.js b/shell/plugins/bar/BarModel.js index 4334cf4a2e43..40dbdc05b88a 100644 --- a/shell/plugins/bar/BarModel.js +++ b/shell/plugins/bar/BarModel.js @@ -613,6 +613,25 @@ function notchReach(floor, margin) { return reach > 0 ? reach : 0 } +// The gaps a detached bar at `position` keeps from the screen edges, from the +// [bar] margin width spec: the edge it is anchored to and the two it spans. +// Its far face is not against an edge, so that side is 0. +function edgeMargins(margins, position) { + var m = margins || {} + var edge = normalizePosition(position) + // A side is dropped for a bar anchored opposite it, and read as a number. + var side = function(name, opposite) { + var value = Number(m[name]) + return edge === opposite || !(value > 0) ? 0 : value + } + return { + top: side("top", "bottom"), + right: side("right", "left"), + bottom: side("bottom", "top"), + left: side("left", "right") + } +} + // The bar's thickness on the screen with this name, from the sizes a bar // publishes by screen name, or `fallback` (its configured size) for a screen // it has none for. @@ -628,6 +647,7 @@ if (typeof module !== "undefined") { centerBesideRight: centerBesideRight, cutoutPending: cutoutPending, cutoutTop: cutoutTop, + edgeMargins: edgeMargins, isDrawnSlot: isDrawnSlot, notchFloor: notchFloor, notchReach: notchReach, diff --git a/test/shell.d/bar-test.sh b/test/shell.d/bar-test.sh index dc581d171efc..e56847cd2343 100644 --- a/test/shell.d/bar-test.sh +++ b/test/shell.d/bar-test.sh @@ -79,12 +79,12 @@ assert( /exclusionMode: root\.barHidden \? ExclusionMode\.Ignore : ExclusionMode\.Auto/.test(barSource), 'a hidden bar reserves no space for itself' ) -// A detached bar sits barMargin off its edge, so parking has to clear the gap -// as well as the bar's whole thickness or the margin leaves a sliver of it on -// screen. +// A detached bar sits barMargins[position] off its edge. Hidden, that edge's +// margin is replaced by minus the bar's whole thickness, which parks it fully +// off screen whatever the gap was. assert( - /readonly property int parkedMargin: -\(barWindow\.thickness \+ anchoredMargin\)/.test(barSource), - 'parking a hidden bar clears its margin as well as its whole thickness' + /readonly property int parkedMargin: -barWindow\.thickness\n/.test(barSource), + 'parking a hidden bar moves it its whole thickness past the edge' ) assert( /readonly property int edgeMargin: root\.barHidden \? parkedMargin : anchoredMargin/.test(barSource), @@ -96,6 +96,14 @@ for (const edge of ['top', 'bottom', 'left', 'right']) { `a hidden bar parks past the ${edge} edge` ) } +// The two edges a bar spans take their own gaps; its far face takes none. +assert( + /top: root\.position === "top" \? edgeMargin : \(root\.vertical \? root\.barMargins\.top : 0\)/.test(barSource) && + /bottom: root\.position === "bottom" \? edgeMargin : \(root\.vertical \? root\.barMargins\.bottom : 0\)/.test(barSource) && + /left: root\.position === "left" \? edgeMargin : \(root\.vertical \? 0 : root\.barMargins\.left\)/.test(barSource) && + /right: root\.position === "right" \? edgeMargin : \(root\.vertical \? 0 : root\.barMargins\.right\)/.test(barSource), + 'a detached bar keeps its gap at both ends and none on its far face' +) // The gap is a width spec, not a scalar, so a bar can sit further off the edges // it spans than off the one it hangs from. The anchored edge reads out of the @@ -113,6 +121,79 @@ assert( /readonly property int anchoredMargin: root\.barMargins\[root\.position\]/.test(barSource), 'the anchored edge takes its own side of the margin' ) + +// shell.toml to the bar's margins, by value: the parser keeps the list as +// written, the token reads it per edge and scales it with the font as the +// sizes do, and the bar keeps only the sides that face a screen edge. +{ + const vm = require('vm') + const qmlFunction = name => { + const start = styleSource.indexOf(`function ${name}(`) + let depth = 0 + for (let i = styleSource.indexOf('{', start); start >= 0 && i < styleSource.length; i++) { + if (styleSource[i] === '{') depth++ + else if (styleSource[i] === '}' && --depth === 0) return styleSource.slice(start, i + 1) + } + throw new Error(`Style.qml has no function ${name}`) + } + const geometry = vm.createContext({}) + vm.runInContext(fs.readFileSync(root + '/shell/Commons/BorderGeometry.js', 'utf8').replace(/^\.pragma library\n/, ''), geometry) + const style = vm.createContext({ Geometry: geometry }) + vm.runInContext(['barToken', 'barInsetToken', 'barMarginToken', 'boolToken', 'applyShellValues'].map(qmlFunction).join('\n') + + '\nvar fontScale = 1, barScaleWithFont = true, barOverrides = {}', style) + const margins = values => { + style.applyShellValues(values) + return JSON.parse(JSON.stringify(style.barMarginToken())) + } + const radius = values => { + style.applyShellValues(values) + return style.barInsetToken('radius', 0) + } + + assertDeepEqual(margins({}), { top: 0, right: 0, bottom: 0, left: 0 }, 'a bar without a margin is flush') + assertDeepEqual(margins({ 'bar.margin': '10' }), { top: 10, right: 10, bottom: 10, left: 10 }, 'a single margin applies to every edge') + assertDeepEqual(margins({ 'bar.margin': '4 8' }), { top: 4, right: 8, bottom: 4, left: 8 }, 'a two-value margin is vertical then horizontal') + assertDeepEqual(margins({ 'bar.margin': '1 2 3' }), { top: 1, right: 2, bottom: 3, left: 2 }, 'a three-value margin is top, sides, bottom') + assertDeepEqual(margins({ 'bar.margin': '1 2 3 4' }), { top: 1, right: 2, bottom: 3, left: 4 }, 'a four-value margin is top, right, bottom, left') + assertDeepEqual(margins({ 'bar.margin': '-4' }), { top: 0, right: 0, bottom: 0, left: 0 }, 'a negative margin reads as flush') + assertDeepEqual(margins({ 'bar.margin': 'wide' }), { top: 0, right: 0, bottom: 0, left: 0 }, 'an unreadable margin reads as flush') + assertEqual(style.barOverrides.margin, 'wide', 'the margin reaches the token as it was written') + assertEqual(radius({ 'bar.radius': '9' }), 9, 'the radius reaches the bar') + assertEqual(radius({ 'bar.radius': '0' }), 0, 'a radius of 0 stays square') + assertEqual(radius({}), 0, 'a bar without a radius is square') + + style.fontScale = 1.5 + assertDeepEqual(margins({ 'bar.margin': '10' }), { top: 15, right: 15, bottom: 15, left: 15 }, 'the margin scales with the font') + assertEqual(radius({ 'bar.radius': '12' }), 18, 'the radius scales with the font') + assertDeepEqual(margins({ 'bar.scale-with-font': 'false', 'bar.margin': '10' }), { top: 10, right: 10, bottom: 10, left: 10 }, 'scale-with-font = false keeps the margin in pixels') + assertEqual(radius({ 'bar.scale-with-font': 'false', 'bar.radius': '12' }), 12, 'scale-with-font = false keeps the radius in pixels') + + const spec = { top: 4, right: 8, bottom: 4, left: 8 } + const edge = position => JSON.parse(JSON.stringify(bar.edgeMargins(spec, position))) + assertDeepEqual(edge('top'), { top: 4, right: 8, bottom: 0, left: 8 }, 'a top bar has no gap below it') + assertDeepEqual(edge('bottom'), { top: 0, right: 8, bottom: 4, left: 8 }, 'a bottom bar has no gap above it') + assertDeepEqual(edge('left'), { top: 4, right: 0, bottom: 4, left: 8 }, 'a left bar has no gap right of it') + assertDeepEqual(edge('right'), { top: 4, right: 8, bottom: 4, left: 0 }, 'a right bar has no gap left of it') + assertDeepEqual(JSON.parse(JSON.stringify(bar.edgeMargins({ top: '6', right: 'x', left: -2 }, 'top'))), { top: 6, right: 0, bottom: 0, left: 0 }, 'edge margins are numbers and never negative') + assertDeepEqual(JSON.parse(JSON.stringify(bar.edgeMargins(null, 'top'))), { top: 0, right: 0, bottom: 0, left: 0 }, 'no margins are a flush bar') + assert( + /readonly property var barMargins: BarModel\.edgeMargins\(Style\.bar\.margins, position\)/.test(barSource), + 'the bar keeps only the margins that face a screen edge' + ) +} + +// Moving the bar previews it where it would land: off the candidate edge by +// that edge's margins and rounded as the bar is. +const moveGhost = barSource.slice(barSource.indexOf('component BarMoveGhostPanel')) +assert( + /readonly property var edgeMargins: BarModel\.edgeMargins\(Style\.bar\.margins, modelData\)/.test(moveGhost) && + /x: modelData === "right" \? parent\.width - edgeSize - edgeMargins\.right : edgeMargins\.left/.test(moveGhost) && + /y: modelData === "bottom" \? parent\.height - edgeSize - edgeMargins\.bottom : edgeMargins\.top/.test(moveGhost) && + /width: edgeVertical \? edgeSize : parent\.width - edgeMargins\.left - edgeMargins\.right/.test(moveGhost) && + /height: edgeVertical \? parent\.height - edgeMargins\.top - edgeMargins\.bottom : edgeSize/.test(moveGhost) && + /radius: Style\.bar\.radius/.test(moveGhost), + 'the move preview shows a detached bar where it will land' +) // The drag overlays are full-screen, so a bar-local point becomes a screen point // by adding the bar window's origin. A detached bar's origin is the gap itself on the // axes it spans, and the far edge less its own size and gap on the one it is @@ -192,6 +273,9 @@ assert( assertEqual(panelGeometry.availableLength(100, true, 26, 12, 12), 120, 'a card keeps at least 120 px') assertEqual(panelGeometry.barStripSize(26, 26, 6, 6), 38, 'clicks up to the gap below a detached bar count as the bar') assertEqual(panelGeometry.barStripSize(26, 26, 0, 6), 32, 'a flush bar strip is the bar and the gap') + // A replacement bar plugin hands over its own margins, which may be strings. + assertDeepEqual(origin('top', { top: '6', left: '12' }, 1976, 26), { x: 12, y: 6 }, 'bar margins are read as numbers') + assertDeepEqual(origin('top', { top: 'x' }, 2000, 26), { x: 0, y: 0 }, 'an unreadable bar margin counts as none') const panelSource = fs.readFileSync(root + '/shell/Ui/KeyboardPanel.qml', 'utf8') assert( @@ -208,7 +292,7 @@ assert( 'bar popouts place and forward through the bar window origin and margins' ) - // Tray menus, the media popup and the bar options size themselves the same way. + // Tray menus and the media popup size themselves the same way. const popupSource = fs.readFileSync(root + '/shell/Ui/PopupCard.qml', 'utf8') assert( /readonly property real barEdgeMargin: bar && bar\.barMargins \? \(bar\.barMargins\[bar\.position\] \|\| 0\) : 0/.test(popupSource) && From f3c6112eb1b5f9c87b0bb9de902e3b895c29e8a8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 20:26:43 +0000 Subject: [PATCH 8/8] Document floating the bar for users The manual's bar chapter shows where to set the margin and radius, and the reference and theme template say how they read, scale and interact with hiding and a camera cutout. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QJ9xdGDgAWUqbEooHGuMBS --- default/themed/shell.toml.tpl | 5 +++-- docs/omarchy-shell.md | 6 ++---- manual/05-the-top-bar.md | 12 ++++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/default/themed/shell.toml.tpl b/default/themed/shell.toml.tpl index 40db388d2aab..6a73291f3539 100644 --- a/default/themed/shell.toml.tpl +++ b/default/themed/shell.toml.tpl @@ -15,8 +15,9 @@ active = "{{ red }}" scale-with-font = true size-horizontal = 26 size-vertical = 28 -# Gap between the bar and the edge. Takes one CSS-style scalar/list: -# N, "Y X", "T X B", or "T R B L". +# margin is the gap between the bar and the screen edges it touches, as one +# CSS-style width: N, "Y X", "T X B", or "T R B L". radius rounds the bar's +# corners. 0 is flush and square, and both follow scale-with-font. margin = 0 radius = 0 diff --git a/docs/omarchy-shell.md b/docs/omarchy-shell.md index 350202d0120f..82cc61eb4388 100644 --- a/docs/omarchy-shell.md +++ b/docs/omarchy-shell.md @@ -415,9 +415,7 @@ Until Hyprland reports a screen's mode, a top bar there waits to appear if a des ### Floating bar -`[bar] margin` lift the bar off its screen edge. `margin` is the gap between the bar and every edge the bar touches — the one it is anchored to and the two it spans - -[bar] `radius` rounds the corners of the bar surface +`[bar] margin` lifts the bar off its screen edge: it is the gap between the bar and every edge the bar touches, the one it is anchored to and the two it spans. `[bar] radius` rounds the corners of the bar surface. A theme sets them in its own `shell.toml`, and `~/.config/omarchy/shell.toml` overrides it and survives theme switches. ```toml [bar] @@ -432,7 +430,7 @@ radius = 12 # corner rounding of the bar surface; 0 = square margin = "4 8" # 4 top and bottom, 8 left and right: a top bar sits 4 below the edge and 8 in from each side ``` -Both default to `0`, a bar sitting flush against its edge with square corners, and both follow `scale-with-font` like the sizes above. The gap is reserved along with the bar itself, so maximized and tiled windows stop clear of it instead of sliding underneath. Auto-hide still parks the bar fully off screen, clearing the margin as well as the bar. Panels opened from the bar and notifications place themselves from the bar's outer face, so they follow it. Widgets read the gap as `bar.barMargins`, and plugins that position their own windows as `shell.bar.barMargins`, both an object with `top`, `right`, `bottom` and `left`. +Both default to `0`, a bar sitting flush against its edge with square corners, and both follow `scale-with-font` like the sizes above. The gap is reserved along with the bar itself, so maximized and tiled windows stop clear of it instead of sliding underneath. Hiding the bar still parks it fully off screen. On a panel with a camera cutout, a top margin counts toward clearing it: the bar is floored only at what the cutout reaches past the margin, and a margin that clears the cutout leaves the center sections in the middle. Panels opened from the bar and notifications place themselves from the bar's outer face, so they follow it. Widgets read the gap as `bar.barMargins`, and plugins that position their own windows as `shell.bar.barMargins`, both an object with `top`, `right`, `bottom` and `left`. ## Custom bar modules diff --git a/manual/05-the-top-bar.md b/manual/05-the-top-bar.md index 875d839017cd..98281df1110b 100644 --- a/manual/05-the-top-bar.md +++ b/manual/05-the-top-bar.md @@ -107,6 +107,18 @@ omarchy plugin enable omarchy.media --section centerEnd omarchy plugin disable omarchy.weather ``` +## Floating the bar + +To lift the bar off the screen edge, give it a margin in `~/.config/omarchy/shell.toml`, and a radius to round its corners: + +```toml +[bar] +margin = 8 +radius = 10 +``` + +The margin is the gap the bar keeps from every screen edge it touches. It can differ per edge the way CSS margins do: `margin = "4 8"` keeps a top bar 4 pixels below the screen edge and 8 in from each side. Both default to `0`, a bar flush against its edge with square corners, and both grow with the font size. Windows, panels and notifications stay clear of the bar and its gap. The file is yours, so it survives theme switches, and the bar picks up changes as soon as you save. + ## Hiding the bar `Super + Shift + Space` toggles the bar off and back on without killing the shell — panels and hotkeys keep working, you just get the pixels back. It's also in the menu under **Trigger → Appearance → Menu Bar → Hide Bar**.