From e90d1c6d2d4962a16165b4c98a08db4d2e6af1cb Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 27 Sep 2026 21:29:01 +0000 Subject: [PATCH] Floor Apple Silicon top bars to the camera notch cutout Port the notch height stack so top bars reserve the measured camera cutout on Asahi laptops, accept a calibrated [bar] notch-height override, and migrate Apple Silicon layouts to keep center widgets off the housing. Fixes #13058 Co-authored-by: AnPod --- bin/omarchy-hw-apple-silicon | 8 ++++ migrations/1789123456.sh | 22 +++++++++ shell/Commons/Style.qml | 9 +++- shell/plugins/bar/Bar.qml | 23 ++++++++- shell/plugins/bar/BarModel.js | 52 ++++++++++++++++++++ test/shell.d/bar-notch-test.sh | 86 ++++++++++++++++++++++++++++++++++ 6 files changed, 198 insertions(+), 2 deletions(-) create mode 100755 bin/omarchy-hw-apple-silicon create mode 100755 migrations/1789123456.sh create mode 100755 test/shell.d/bar-notch-test.sh diff --git a/bin/omarchy-hw-apple-silicon b/bin/omarchy-hw-apple-silicon new file mode 100755 index 000000000000..f80276632310 --- /dev/null +++ b/bin/omarchy-hw-apple-silicon @@ -0,0 +1,8 @@ +#!/bin/bash + +# omarchy:summary=Returns true on Apple Silicon (Asahi) machines +# omarchy:hidden=true + +# The device-tree compatible string is the reliable signal on Asahi; DMI product +# names vary and some Intel Macs also say Apple. No device-tree means not Asahi. +grep -qi apple /proc/device-tree/compatible 2>/dev/null diff --git a/migrations/1789123456.sh b/migrations/1789123456.sh new file mode 100755 index 000000000000..181ed715123e --- /dev/null +++ b/migrations/1789123456.sh @@ -0,0 +1,22 @@ +# Move Apple Silicon top-bar widgets out from under the camera notch. +# +# The dynamic notch floor covers the cutout height, but center-anchored widgets +# still sit behind the camera housing. Empty the center and park those modules +# on the right so the cutout stays clear. Non-Apple machines are untouched; +# users who already cleared center keep their layout. + +omarchy-hw-apple-silicon || exit 0 + +config="$HOME/.config/omarchy/shell.json" +[[ -f $config ]] || exit 0 + +if ! jq -e '(.bar.layout.center | length) > 0' "$config" >/dev/null 2>&1; then + exit 0 +fi + +tmp=$(mktemp) +jq ' + .bar.centerAnchor = "" + | .bar.layout.right = ((.bar.layout.center // []) + (.bar.layout.right // [])) + | .bar.layout.center = [] +' "$config" >"$tmp" && mv "$tmp" "$config" diff --git a/shell/Commons/Style.qml b/shell/Commons/Style.qml index 0582356cfdae..ca1e63dc7923 100644 --- a/shell/Commons/Style.qml +++ b/shell/Commons/Style.qml @@ -342,6 +342,13 @@ QtObject { readonly property QtObject bar: QtObject { readonly property int sizeHorizontal: root.barToken("size-horizontal", 26) readonly property int sizeVertical: root.barToken("size-vertical", 28) + // Calibrated notch cutout height in logical px, for panels whose real + // cutout differs from the derived default (see BarModel.notchHeight). + // 0 means derive it. Physical alignment, so it never scales with font. + readonly property int notchHeight: { + var v = Number(root.barOverrides["notch-height"]) + return (isFinite(v) && v > 0) ? Math.round(v) : 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) @@ -416,7 +423,7 @@ QtObject { } else if (section === "bar") { if (key === "scale-with-font") { nextBarScaleWithFont = boolToken(raw, nextBarScaleWithFont) - } else if (key === "size-horizontal" || key === "size-vertical") { + } else if (key === "size-horizontal" || key === "size-vertical" || key === "notch-height") { 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 437daef07790..8181e62e4bfd 100644 --- a/shell/plugins/bar/Bar.qml +++ b/shell/plugins/bar/Bar.qml @@ -555,6 +555,16 @@ Item { readonly property bool vertical: position === "left" || position === "right" readonly property int barSize: vertical ? Style.bar.sizeVertical : Style.bar.sizeHorizontal + // Whether this machine is an Apple Silicon laptop, whose built-in panel may + // have a camera notch. Machine identity is fixed, so probe once at startup; + // the device-tree file does not exist on x86, which reads as "no" there. + property bool appleSiliconHost: false + Process { + running: true + command: ["bash", "-c", "grep -qi apple /proc/device-tree/compatible 2>/dev/null && echo yes || echo no"] + stdout: SplitParser { onRead: function(line) { root.appleSiliconHost = String(line).trim() === "yes" } } + } + function normalizePosition(value) { return BarModel.normalizePosition(value) } @@ -1261,8 +1271,19 @@ Item { right: root.position === "right" || !root.vertical } + // A top bar shorter than the camera cutout of an Apple notched panel + // leaves a sliver of every window peeking out beside the camera, so the + // cutout height is this panel's minimum sensible top-bar height. An + // intentionally taller bar still wins, and a calibrated [bar] + // notch-height in shell.toml overrides the derived value. + readonly property int notchFloor: root.appleSiliconHost && root.position === "top" + ? (Style.bar.notchHeight > 0 + ? Style.bar.notchHeight + : BarModel.notchHeight(screen.name, screen.width, screen.height, screen.devicePixelRatio)) + : 0 + implicitWidth: root.vertical ? root.barSize : 0 - implicitHeight: root.vertical ? 0 : root.barSize + implicitHeight: root.vertical ? 0 : Math.max(root.barSize, notchFloor) color: root.transparent ? "transparent" : root.background surfaceFormat.opaque: false WlrLayershell.namespace: "omarchy-bar" diff --git a/shell/plugins/bar/BarModel.js b/shell/plugins/bar/BarModel.js index 36900e5b4825..bd21b538d9b3 100644 --- a/shell/plugins/bar/BarModel.js +++ b/shell/plugins/bar/BarModel.js @@ -208,12 +208,64 @@ function nearestDropTarget(candidates, point, vertical) { return best } +// Camera-cutout depths measured on real hardware, keyed by physical panel +// size. Apple's notched panels expose more rows above the 16:10 area than +// the cutout actually covers (Apple's own menu bar extends below the notch +// too), so a measured panel gets its exact cutout and an unmeasured panel +// keeps the full strip — which errs taller, never shorter. +var measuredNotchPanels = [ + // MacBook Pro 14" (3024x1964): 64 of the 74 rows above the 16:10 area. + { width: 3024, height: 1964, cutoutRows: 64 }, + // MacBook Pro 16" (3456x2234): 64 of the 74 rows above the 16:10 area. + { width: 3456, height: 2234, cutoutRows: 64 } +] + +function measuredCutoutRows(physicalWidth, physicalHeight) { + for (var i = 0; i < measuredNotchPanels.length; i++) { + var panel = measuredNotchPanels[i] + // Logical sizes are rounded, so the reconstructed physical size can be + // a couple of pixels off at fractional scales. + if (Math.abs(physicalWidth - panel.width) <= 4 && Math.abs(physicalHeight - panel.height) <= 4) + return panel.cutoutRows + } + return 0 +} + +// Apple's notched laptop panels are a 16:10 display plus a camera strip above +// it, so whatever extends beyond the 16:10 area is the notch strip. Hyprland +// applies the display scale to both axes, so the scale cancels out and the +// strip height falls straight out of the logical screen size. +// +// Callers gate on the machine being Apple Silicon; this only guards against +// panels the formula does not describe: external monitors (not eDP), 16:10 +// or wider panels (no leftover), and taller aspect ratios (rotated or 3:2 +// panels), where the leftover is far more than a camera strip. Every notched +// Apple panel's strip is ~3.8% of its height, so 5% is a comfortable bound. +function notchHeight(screenName, logicalWidth, logicalHeight, devicePixelRatio) { + if (String(screenName || "").indexOf("eDP") !== 0) return 0 + + var width = Number(logicalWidth) + var height = Number(logicalHeight) + if (!(width > 0) || !(height > 0)) return 0 + + var strip = height - (width * 10) / 16 + if (strip <= 0 || strip > height / 20) return 0 + + var scale = Number(devicePixelRatio) + if (scale > 0) { + var cutout = measuredCutoutRows(Math.round(width * scale), Math.round(height * scale)) + if (cutout > 0) return Math.ceil(cutout / scale) + } + return Math.ceil(strip) +} + if (typeof module !== "undefined") { module.exports = { isDrawnSlot: isDrawnSlot, pickDrawnSlot: pickDrawnSlot, pickPanelSlot: pickPanelSlot, nearestDropTarget: nearestDropTarget, + notchHeight: notchHeight, normalizePosition: normalizePosition, entrySettings: entrySettings, entryId: entryId, diff --git a/test/shell.d/bar-notch-test.sh b/test/shell.d/bar-notch-test.sh new file mode 100755 index 000000000000..74b00489115b --- /dev/null +++ b/test/shell.d/bar-notch-test.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +run_node_test <<'JS' +const fs = require('fs') +const bar = requireFromRoot('shell/plugins/bar/BarModel.js') +const barSource = fs.readFileSync(root + '/shell/plugins/bar/Bar.qml', 'utf8') +const styleSource = fs.readFileSync(root + '/shell/Commons/Style.qml', 'utf8') + +assertEqual(bar.notchHeight('eDP-1', 1512, 982, 2), 32, 'MacBook Pro 14" at scale 2 uses its measured 32px cutout') +assertEqual(bar.notchHeight('eDP-1', 1890, 1227, 1.6), 40, 'MacBook Pro 14" at scale 1.6 uses its measured cutout') +assertEqual(bar.notchHeight('eDP-1', 1728, 1117, 2), 32, 'MacBook Pro 16" at scale 2 uses its measured 32px cutout') + +assertEqual(bar.notchHeight('eDP-1', 1280, 832, 2), 32, 'MacBook Air 13.6" at scale 2 falls back to its 32px strip') +assertEqual(bar.notchHeight('eDP-1', 1600, 1040, 1.6), 40, 'MacBook Air 13.6" at scale 1.6 falls back to its 40px strip') + +assertEqual(bar.notchHeight('eDP-1', 1280, 800, 2), 0, 'an exactly 16:10 panel (M1 Air) has no notch') +assertEqual(bar.notchHeight('DP-1', 1512, 982, 2), 0, 'external monitors never report a notch') +assertEqual(bar.notchHeight('eDP-1', 982, 1512, 2), 0, 'a rotated panel is not mistaken for a notch') +assertEqual(bar.notchHeight('eDP-1', 1128, 752, 2), 0, 'a 3:2 panel is not mistaken for a notch') +assertEqual(bar.notchHeight('eDP-1', 0, 0, 2), 0, 'degenerate screen sizes report no notch') +assertEqual(bar.notchHeight('', 1512, 982, 2), 0, 'a missing screen name reports no notch') +assertEqual(bar.notchHeight('eDP-1', 1512, 982, 0), 37, 'a missing scale still yields the strip fallback') + +assert( + /notchFloor: root\.appleSiliconHost && root\.position === "top"/.test(barSource), + 'bar floors only top bars on Apple Silicon machines' +) +assert( + /BarModel\.notchHeight\(screen\.name, screen\.width, screen\.height, screen\.devicePixelRatio\)/.test(barSource), + 'bar derives the floor from its own screen geometry' +) +assert( + /implicitHeight: root\.vertical \? 0 : Math\.max\(root\.barSize, notchFloor\)/.test(barSource), + 'bar height is floored at the notch, never shrunk to it' +) + +assert( + /Style\.bar\.notchHeight > 0[\s\S]{0,80}\? Style\.bar\.notchHeight/.test(barSource), + 'a calibrated notch-height overrides the derived floor' +) +assert( + /notchHeight:[\s\S]{0,240}barOverrides\["notch-height"\]/.test(styleSource) && + !/barToken\("notch-height"/.test(styleSource), + 'notch-height is read raw, not through the font-scaled bar tokens' +) +JS + +[[ -x $ROOT/bin/omarchy-hw-apple-silicon ]] || + fail "omarchy-hw-apple-silicon helper is executable" +pass "omarchy-hw-apple-silicon helper is executable" + +migration="" +for f in "$ROOT/migrations/"*.sh; do + if grep -q 'omarchy-hw-apple-silicon' "$f" && grep -q 'centerAnchor' "$f"; then + migration=$f + break + fi +done +[[ -n $migration ]] || fail "Apple Silicon notch layout migration is present" +pass "Apple Silicon notch layout migration is present" + +mig_home=$(mktemp -d) +mig_bin=$(mktemp -d) +cleanup_mig() { rm -rf "$mig_home" "$mig_bin"; } +trap cleanup_mig EXIT + +mkdir -p "$mig_home/.config/omarchy" "$mig_bin" +cat >"$mig_home/.config/omarchy/shell.json" <<'JSON' +{"bar":{"centerAnchor":"omarchy.clock","layout":{"center":[{"id":"omarchy.clock"}],"right":[{"id":"omarchy.tray"}]}}} +JSON +cat >"$mig_bin/omarchy-hw-apple-silicon" <<'SH' +#!/bin/bash +exit 0 +SH +chmod +x "$mig_bin/omarchy-hw-apple-silicon" + +HOME="$mig_home" PATH="$mig_bin:$PATH" bash "$migration" + +jq -e '.bar.centerAnchor == "" and (.bar.layout.center | length) == 0 and .bar.layout.right[0].id == "omarchy.clock"' \ + "$mig_home/.config/omarchy/shell.json" >/dev/null || + fail "notch migration clears center and moves widgets right on Apple Silicon" +pass "notch migration clears center and moves widgets right on Apple Silicon"