Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion bin/omarchy
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ GROUP_DESCRIPTIONS[launch]="Application launchers"
GROUP_DESCRIPTIONS[language]="Display language and system locale"
GROUP_DESCRIPTIONS[menu]="Omarchy menu commands"
GROUP_DESCRIPTIONS[migrate]="Migration runner"
GROUP_DESCRIPTIONS[monitor]="Monitor status helpers"
GROUP_DESCRIPTIONS[monitor]="Monitor status and display layouts"
GROUP_DESCRIPTIONS[network]="Network status helpers"
GROUP_DESCRIPTIONS[notification]="Notification helpers"
GROUP_DESCRIPTIONS[mise]="Mise tool wrappers"
Expand Down
4 changes: 4 additions & 0 deletions bin/omarchy-hyprland-monitor-scaling
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ normalize_scale() {
}

set_scale() {
# Serialize runtime/config changes with display Preview, Keep and recovery.
mkdir -p "$STATE_DIR" || return 1
exec 8>"$STATE_DIR/monitor-config.lock"
flock 8 || return 1
local requested_scale="$1"
local requested="${2:-$requested_scale}"
local monitor_info="$(hyprctl monitors -j | jq -e -c '.[] | select(.focused == true)')"
Expand Down
213 changes: 213 additions & 0 deletions bin/omarchy-monitor-layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#!/bin/bash

# omarchy:summary=Preview, keep, or revert display layouts
# omarchy:args=state | preview JSON | keep TOKEN | revert TOKEN

set -euo pipefail
umask 077

STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy/monitor-layout"
CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/monitors.lua"
mkdir -p "$STATE_DIR"
exec 9>"$STATE_DIR/lock"
flock 9
exec 8>"${STATE_DIR%/*}/monitor-config.lock"
flock 8

fail() { echo "$*" >&2; exit 1; }

publish_config() {
local replacement="$1" expected="$2" candidate displaced
[[ -f $CONFIG && ! -L $CONFIG ]] || return 1
sha256sum --check --status "$expected" || return 1
candidate=$(sha256sum "$replacement" | cut -d ' ' -f 1)
# Supported writers share the lock. External editors cannot be locked out:
# exchange retains the exact file displaced at publication, then checks it.
# Never discard either version when an uncooperative writer races the swap.
mv --exchange --no-copy -T "$replacement" "$CONFIG" || return 1
displaced=$(sha256sum "$replacement" | cut -d ' ' -f 1)
if [[ $displaced == "$(cut -d ' ' -f 1 "$expected")" && ! -L $replacement ]]; then
return 0
else
if [[ ! -L $CONFIG && $(sha256sum "$CONFIG" | cut -d ' ' -f 1) == "$candidate" ]]; then
mv --exchange --no-copy -T "$replacement" "$CONFIG" || return 1
fi
echo "Concurrent monitors.lua edit; retained displaced version at $replacement" >&2
return 1
fi
}

evaluate() {
local result
result=$(hyprctl eval "(function() $1 end)()")
if [[ $result != "ok" ]]; then
echo "$result" >&2
return 1
fi
}

monitor_code() {
jq -r '.displays[] | "hl.monitor({ output = \(.name | tojson), mode = \(.mode | tojson), position = \(( (.x|tostring) + "x" + (.y|tostring)) | tojson), scale = \(.scale), transform = \(.transform), disabled = false })"' "$1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Scaling changes vanish on reload

After Keep, the generated per-display rules pin each screen's scale. The scaling shortcut still saves only omarchy_monitor_scale or the catch-all rule. Its change works immediately but disappears on the next config reload or login because the saved per-display scale takes precedence.

Update the saved per-display rule when scaling a screen managed by the layout editor.

}

layout_matches() {
jq -e --argjson monitors "$(hyprctl -j monitors all)" '
all(.displays[]; . as $d |
(.mode | capture("^(?<width>[0-9]+)x(?<height>[0-9]+)@(?<rate>[0-9.]+)$")) as $mode |
any($monitors[]; .name == $d.name and .disabled != true and
.width == ($mode.width|tonumber) and .height == ($mode.height|tonumber) and
((.refreshRate - ($mode.rate|tonumber)) | fabs) < 0.15 and
.x == $d.x and .y == $d.y and .transform == $d.transform and
((.scale - $d.scale) | fabs) < 0.01))
' "$STATE_DIR/after.json" >/dev/null
}

restore() {
# Reload restores the saved monitor rules, then restore the runtime
# positions captured before the preview.
# If Keep was interrupted after publishing the new file, roll it back only
# while it still matches our candidate. Never overwrite a subsequent edit.
if [[ -f $STATE_DIR/config.changed ]]; then
if sha256sum --check --status "$STATE_DIR/candidate.sha256"; then
local replacement
replacement=$(mktemp "${CONFIG%/*}/.monitors.XXXXXX")
cp -p "$STATE_DIR/monitors.lua.backup" "$replacement"
if publish_config "$replacement" "$STATE_DIR/candidate.sha256"; then
rm -f "$replacement"
else
echo "Recovery preserved the changed monitors.lua and $replacement" >&2
fi
fi
rm -f "$STATE_DIR/config.changed"
fi
hyprctl reload >/dev/null
local monitors
monitors=$(hyprctl -j monitors all)
jq --argjson monitors "$monitors" '
.displays |= map(select(.name as $name | any($monitors[]; .name == $name)))
' "$STATE_DIR/before.json" >"$STATE_DIR/restore.json"
evaluate "$(monitor_code "$STATE_DIR/restore.json")"
rm -f "$STATE_DIR/pending.json"
}

case "${1:-}" in
state)
monitors=$(hyprctl -j monitors all)
pending=null
[[ ! -f $STATE_DIR/pending.json ]] || pending=$(cat "$STATE_DIR/pending.json")
preview=null
[[ $pending == "null" ]] || preview=$(cat "$STATE_DIR/after.json")
jq -n --argjson monitors "$monitors" --argjson pending "$pending" --argjson preview "$preview" \
'{monitors: $monitors, pending: $pending, preview: $preview}'
;;
preview)
[[ ! -f $STATE_DIR/pending.json ]] || fail "Keep or revert the current preview first"
monitors=$(hyprctl -j monitors all)
request=${2:-}
# JSON is data only. Connector names, modes and coordinates are validated
# before generating Lua.
jq -e --argjson monitors "$monitors" '
type == "object" and keys == ["displays"] and (.displays | type == "array" and length > 0) and
([.displays[].name] | length == (unique | length)) and
(.displays as $displays | all($displays[];
. as $d | [.name, .mode] | all(.[]; type == "string") ) ) and
all(.displays[]; . as $d |
(.name | test("^[A-Za-z0-9._-]+$")) and
(.mode | test("^[0-9]+x[0-9]+@[0-9]+([.][0-9]+)?$")) and
([.x, .y, .transform] | all(.[]; type == "number" and . == floor)) and
(.x >= -32768 and .x <= 32768 and .y >= -32768 and .y <= 32768) and
(.transform >= 0 and .transform <= 3) and
(.scale | type == "number" and . >= 1 and . <= 4) and
any($monitors[]; .name == $d.name and .disabled != true and
(.mirrorOf == "none" or .mirrorOf == null) and
any(.availableModes[]; sub("Hz$"; "") == $d.mode))) and
([.displays[].name] | sort) == ([$monitors[] | select(.disabled != true) | .name] | sort)
' <<<"$request" >/dev/null || fail "Invalid layout; use active displays and their supported modes"
jq -n --argjson monitors "$monitors" '{
displays: [$monitors[] | select(.disabled != true) | {
name, mode: ((.width|tostring) + "x" + (.height|tostring) + "@" + (.refreshRate|tostring)),
x, y, scale, transform
}]
}' >"$STATE_DIR/before.json"
printf '%s\n' "$request" >"$STATE_DIR/after.json"
[[ -f $CONFIG && ! -L $CONFIG ]] || fail "monitors.lua must be a regular file"
sha256sum "$CONFIG" >"$STATE_DIR/config.sha256"
token=$(cat /proc/sys/kernel/random/uuid)
expires=$(( $(date +%s) + 20 ))
jq -n --arg token "$token" --argjson expires "$expires" '{token: $token, expires: $expires}' >"$STATE_DIR/pending.json"
set -E
trap 'trap - ERR; restore' ERR
# User service survives launcher exit, shell/plugin reload and loss of the
# popup. Pass the compositor instance and XDG roots explicitly.
systemd-run --user --quiet --collect --property=Type=exec \
--setenv="HYPRLAND_INSTANCE_SIGNATURE=${HYPRLAND_INSTANCE_SIGNATURE:-}" \
--setenv="XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}" \
--setenv="XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}" \
/bin/bash -c 'sleep 20; exec "$1" revert "$2"' bash "$(readlink -f "${BASH_SOURCE[0]}")" "$token"
evaluate "$(monitor_code "$STATE_DIR/after.json")"
layout_matches || { restore; fail "The compositor could not apply the requested layout"; }
cat "$STATE_DIR/pending.json"
;;
keep | revert)
[[ -f $STATE_DIR/pending.json ]] || fail "No pending preview"
[[ ${2:-} == "$(jq -r .token "$STATE_DIR/pending.json")" ]] || fail "Stale preview token"
if [[ $1 == "revert" ]]; then
restore
else
(( $(date +%s) < $(jq -r .expires "$STATE_DIR/pending.json") )) || { restore; fail "Preview expired"; }
sha256sum --check --status "$STATE_DIR/config.sha256" || { restore; fail "monitors.lua changed during preview"; }
monitors=$(hyprctl -j monitors all)
jq -e --argjson monitors "$monitors" '
([.displays[].name] | sort) == ([$monitors[] | select(.disabled != true) | .name] | sort)
' "$STATE_DIR/after.json" >/dev/null || { restore; fail "Connected displays changed during preview"; }
layout_matches || { restore; fail "Display settings changed during preview"; }
begin_count=$(awk '/^-- BEGIN OMARCHY DISPLAY LAYOUT$/{n++} END{print n+0}' "$CONFIG")
end_count=$(awk '/^-- END OMARCHY DISPLAY LAYOUT$/{n++} END{print n+0}' "$CONFIG")
(( begin_count == end_count && begin_count <= 1 )) || { restore; fail "Invalid display layout markers"; }
awk '
/^-- BEGIN OMARCHY DISPLAY LAYOUT$/ { if (inside || ended) exit 1; inside=1 }
/^-- END OMARCHY DISPLAY LAYOUT$/ { if (!inside) exit 1; inside=0; ended=1 }
END { if (inside) exit 1 }
' "$CONFIG" || { restore; fail "Invalid display layout marker order"; }
cp -p "$CONFIG" "$STATE_DIR/monitors.lua.backup"
[[ $(sha256sum "$STATE_DIR/monitors.lua.backup" | cut -d ' ' -f 1) == "$(cut -d ' ' -f 1 "$STATE_DIR/config.sha256")" ]] || { restore; fail "monitors.lua changed while capturing the save snapshot"; }
sha256sum --check --status "$STATE_DIR/config.sha256" || { restore; fail "monitors.lua changed before saving"; }
# Own only this marked block; preserve every personal line outside it.
awk '/^-- BEGIN OMARCHY DISPLAY LAYOUT$/{skip=1; next} /^-- END OMARCHY DISPLAY LAYOUT$/{skip=0; next} !skip' \
"$STATE_DIR/monitors.lua.backup" >"$STATE_DIR/monitors.lua.new"
{
echo '-- BEGIN OMARCHY DISPLAY LAYOUT'
# Retain our generated rules for disconnected outputs. A later hotplug
# must not lose its arrangement when another display is edited.
awk '/^-- BEGIN OMARCHY DISPLAY LAYOUT$/{inside=1; next} /^-- END OMARCHY DISPLAY LAYOUT$/{inside=0} inside' "$STATE_DIR/monitors.lua.backup" |
jq -Rr --argjson active "$(jq '[.displays[].name]' "$STATE_DIR/after.json")" '
select(startswith("hl.monitor(")) | . as $line |
capture("output = \"(?<name>[A-Za-z0-9._-]+)\"") |
select(.name as $name | $active | index($name) == null) | $line'
monitor_code "$STATE_DIR/after.json"
echo '-- END OMARCHY DISPLAY LAYOUT'
} >>"$STATE_DIR/monitors.lua.new"
replacement=$(mktemp "${CONFIG%/*}/.monitors.XXXXXX")
cp -p "$STATE_DIR/monitors.lua.backup" "$replacement"
cat "$STATE_DIR/monitors.lua.new" >"$replacement"
printf '%s %s\n' "$(sha256sum "$replacement" | cut -d ' ' -f 1)" "$CONFIG" >"$STATE_DIR/candidate.sha256"
touch "$STATE_DIR/config.changed"
set -E
trap 'trap - ERR; restore' ERR
publish_config "$replacement" "$STATE_DIR/config.sha256" || { restore; fail "monitors.lua changed while saving; conflict versions were retained"; }
rm -f "$replacement"
hyprctl reload >/dev/null
errors=$(hyprctl configerrors)
if [[ -n $errors ]]; then
restore
fail "$errors"
fi
layout_matches || { restore; fail "Saved display layout did not survive reload"; }
rm -f "$STATE_DIR/pending.json" "$STATE_DIR/config.changed"
fi
;;
-h | --help)
echo 'Usage: omarchy monitor layout state | preview JSON | keep TOKEN | revert TOKEN'
;;
*) fail 'Usage: omarchy monitor layout state | preview JSON | keep TOKEN | revert TOKEN' ;;
esac
2 changes: 1 addition & 1 deletion default/hypr/apps/omarchy-shell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ hl.layer_rule({ match = { namespace = "omarchy-bar" }, no_anim = true, animation
-- animations. Overlays open as soon as their scale is ready, without a
-- compositor fade or slide. Panels keep their own QML opacity transition
-- for normal open/close, and skip it for panel handoff.
hl.layer_rule({ match = { namespace = "^(omarchy-menu|omarchy-image-selector|omarchy-emojis|omarchy-clipboard|omarchy-keyboard-panel|omarchy-osd|omarchy-reminders|omarchy-network-qr|omarchy-dock|omarchy-dock-apps)$" }, no_anim = true, animation = "none" })
hl.layer_rule({ match = { namespace = "^(omarchy-menu|omarchy-image-selector|omarchy-emojis|omarchy-clipboard|omarchy-keyboard-panel|omarchy-display-settings|omarchy-osd|omarchy-reminders|omarchy-network-qr|omarchy-dock|omarchy-dock-apps)$" }, no_anim = true, animation = "none" })

-- A boot intro hands the desktop between OWE's video layer and the shell's
-- background layer. The media fades itself, so a compositor fade on either
Expand Down
32 changes: 32 additions & 0 deletions default/i18n/en/shell.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,37 @@
"diskSpeedtest.failed": "Disk speed test failed",
"diskSpeedtest.read": "READ",
"diskSpeedtest.write": "WRITE",
"displaySettings.arrangement": "Arrangement",
"displaySettings.changeFailed": "Display change failed",
"displaySettings.close": "Close",
"displaySettings.displays": "Displays",
"displaySettings.dragHint": "Drag a display. Nearby edges snap together. Changes apply when you choose Preview.",
"displaySettings.keep": "Keep changes",
"displaySettings.keepCountdown": {
"one": "Keep these changes? Reverts in %1 second.",
"other": "Keep these changes? Reverts in %1 seconds."
},
"displaySettings.landscape": "Landscape",
"displaySettings.landscape180": "Landscape · 180°",
"displaySettings.orientation": "Orientation",
"displaySettings.placeAbove": "Above",
"displaySettings.placeBelow": "Below",
"displaySettings.placeBeside": "Place beside",
"displaySettings.placeLeft": "Left",
"displaySettings.placeRight": "Right",
"displaySettings.portrait270": "Portrait · 270°",
"displaySettings.portrait90": "Portrait · 90°",
"displaySettings.preview": "Preview",
"displaySettings.readFailed": "Could not read display state",
"displaySettings.refreshRate": "Refresh rate",
"displaySettings.refreshRateValue": "%1 Hz",
"displaySettings.reset": "Reset changes",
"displaySettings.resolution": "Resolution",
"displaySettings.revert": "Revert",
"displaySettings.selectedDisplay": "Selected display",
"displaySettings.title": "Display settings",
"displaySettings.unchanged": "Your current configuration is unchanged.",
"displaySettings.unsaved": "Unsaved changes. Preview before keeping.",
"dock.autoHide": "Auto-hide",
"dock.keepInDock": "Keep in Dock",
"dock.newWindow": "New Window",
Expand Down Expand Up @@ -316,6 +347,7 @@
"one": "%1 selected",
"other": "%1 selected"
},
"monitor.advancedSettings": "Advanced settings",
"monitor.brightness": "BRIGHTNESS",
"monitor.display": "Display",
"monitor.displayFocused": "%1 · focused",
Expand Down
40 changes: 40 additions & 0 deletions docs/display-layout-validation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"capturedOn": "2026-10-21",
"base": "quattro ce39c5e9",
"environment": {
"compositor": "Hyprland 0.56.2",
"Qt": "6.11.2",
"shell": "Full production Quickshell config from this branch",
"outputs": "Two isolated headless outputs; no physical monitor changes",
"watchdogLauncher": "The isolated session has no systemd user manager; a stand-in started the same watchdog command detached, without the caller's lock descriptors",
"notVerified": [
"disposable VM acceptance",
"physical hardware preview/Keep",
"per-monitor workspace reconciliation (the isolated compositor does not load Omarchy's Hyprland config)"
]
},
"timedRollback": {
"input": "GUI selects HEADLESS-1 beside HEADLESS-2, Below, then Preview",
"preview": [
{ "name": "HEADLESS-1", "x": 1920, "y": 1080 },
{ "name": "HEADLESS-2", "x": 1920, "y": 0 }
],
"afterExpiry": [
{ "name": "HEADLESS-1", "x": 0, "y": 0 },
{ "name": "HEADLESS-2", "x": 1920, "y": 0 }
],
"configUnchanged": true,
"images": ["images/display-layout-before.png", "images/display-layout-preview.png", "images/display-layout-reverted.png"]
},
"keep": {
"input": "GUI Below, Preview, Keep; explicit compositor reload afterward",
"afterReload": [
{ "name": "HEADLESS-1", "x": 1920, "y": 1080 },
{ "name": "HEADLESS-2", "x": 1920, "y": 0 }
],
"configErrors": "",
"workspaceRulesWritten": false,
"watchdogAfterKeep": "No pending preview",
"image": "images/display-layout-kept.png"
}
}
Binary file added docs/images/display-advanced.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/display-layout-before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/display-layout-kept.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/display-layout-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/display-layout-reverted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions manual/33-monitors.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ When you're extending, closing the lid on the laptop will automatically turn off

### Arranging multiple screens

Open the display popup in the top bar and choose the settings icon at the top right (its tooltip reads **Advanced settings**) to open the settings popup. Its tabs cover arrangement and display modes.

- **Arrangement:** drag screens; nearby edges snap together. Enter precise X/Y positions or place a screen left, right, above, or below another.
- **Displays:** select a screen, resolution, supported refresh rate, and orientation.

Choose **Preview** to try the layout. Choose **Keep changes** within 20 seconds to save it, or **Revert** to restore the previous layout. The confirmation popup stays open when the bar popup closes or a screen moves. If you close the popup or the shell restarts, an unconfirmed preview still reverts automatically. Reopening the popup during a preview restores its confirmation controls. Saved monitor rules live in a marked block at the end of `~/.config/hypr/monitors.lua`; existing personal settings remain outside that block. Layout changes and the scaling shortcut serialize their writes. An external edit detected while saving or recovering cancels the replacement. If another editor races the file exchange, any displaced version is retained as `.monitors.*` next to `monitors.lua`, and the command reports its path; inspect that file before deleting it. The editor arranges enabled, extended displays; enable screens or turn off mirroring before arranging them.

Changing resolution or orientation leaves each display's X/Y position unchanged. Adjust **Arrangement** to align the resized screens before choosing **Preview**. Saved rules for unplugged displays are retained.

Hyprland works great with multiple screens. Read more about how to lay them out in [the Hyprland monitor documentation](https://wiki.hypr.land/Configuring/Basics/Monitors/). In Omarchy, these go in `~/.config/hypr/monitors.lua` as `hl.monitor` entries — the file ships with commented examples for pinning a specific monitor to a resolution, position, and rotation.

Every monitor has workspaces 1 through 10 of its own, so `Super + 1` always means the first workspace of the monitor you're on. Behind the scenes, Hyprland still numbers workspaces across all monitors: your laptop screen (or first monitor) gets 1–10, the next monitor 11–20, and so on, and each monitor keeps its block every time you plug it in. Use those numbers if you write [workspace rules](https://wiki.hypr.land/Configuring/Basics/Workspace-Rules/) or window rules for a specific monitor, so workspace 12 is the second workspace of your second monitor. `~/.local/state/omarchy/monitor-workspaces` lists which block each monitor has.
Expand Down
Loading