Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions bin/omarchy-bar-text-color
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
;;
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions default/themed/shell.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ 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 = 0
radius = 0

[hyprland]
# Shared Hyprland-derived border tokens. Surface sections reference these so
Expand Down
21 changes: 21 additions & 0 deletions docs/omarchy-shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,27 @@ 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.

### 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

```toml
[bar]
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
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
```

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
Expand Down
33 changes: 32 additions & 1 deletion shell/Commons/Style.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -303,6 +304,31 @@ 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))
}

// 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()
Expand Down Expand Up @@ -350,6 +376,8 @@ QtObject {
var v = Number(root.barOverrides["notch-height"])
return (isFinite(v) && v > 0) ? Math.round(v) : 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)
readonly property int iconFont: root.barToken("icon-font", 13)
Expand Down Expand Up @@ -425,9 +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 === "icon-size" || key === "status-slot" || key === "radius") {
var b = parseInt(raw, 10)
if (isFinite(b)) barOut[key] = b
}
Expand Down
61 changes: 50 additions & 11 deletions shell/plugins/bar/Bar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down Expand Up @@ -657,6 +664,12 @@ Item {

readonly property bool vertical: position === "left" || position === "right"
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
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
Expand Down Expand Up @@ -1362,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(" ")
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
]
transparentForegroundProc.running = true
}

onRequestedTransparentChanged: scheduleTransparentForegroundRefresh()
onPositionChanged: scheduleTransparentForegroundRefresh()
onBarMarginsChanged: scheduleTransparentForegroundRefresh()
onThemeForegroundChanged: scheduleTransparentForegroundRefresh()
onThemeContrastForegroundChanged: scheduleTransparentForegroundRefresh()

Expand Down Expand Up @@ -1550,12 +1570,20 @@ 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 anchoredMargin: root.barMargins[root.position]
readonly property int parkedMargin: -(barWindow.thickness + anchoredMargin)
readonly property int edgeMargin: root.barHidden ? parkedMargin : anchoredMargin
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

// 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.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.barMargins.top : 0)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
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)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
}

anchors {
Expand Down Expand Up @@ -1585,11 +1613,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
Expand Down
70 changes: 68 additions & 2 deletions test/shell.d/bar-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,79 @@ 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 \+ anchoredMargin\)/.test(barSource),
'parking a hidden bar clears its margin as well as its whole thickness'
)
assert(
/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']) {
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`
)
}

// 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(
Expand Down
Loading