Files
dotfiles/hypr/scripts/bar
Timo bed974bd4d waybar: pin the bar to the main monitor of the active profile
The previous fix listed both profiles' primaries, "output": ["eDP-1",
"DP-1"] -- but DP-1 is the laptop's second monitor too, so the laptop
would have got a bar on it as well as on eDP-1. No static list can express
"the main monitor" when the two machines share an output name.

Resolve it at launch instead. hypr/scripts/bar asks Hyprland for the
monitor at position 0x0 -- the main monitor in both profiles -- writes
{"output": "<name>"} to ~/.cache/waybar-output.jsonc, and execs waybar;
waybar/config.jsonc includes that fragment. autostart/services, the
bar_reload bind and the performance script all go through the wrapper, so
a reload re-resolves after docking. Signals still target the waybar
process, not the wrapper.

Verified all three paths on mainPC: the fragment pins the bar to DP-1
only, an empty fragment falls back to a bar on every output, and a
fragment naming a disconnected output maps nothing (the failure mode this
started from). Config parses on both profiles.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StGBghPW9Dm7z7uj2VNWHr
2026-09-04 16:55:33 +02:00

24 lines
847 B
Bash
Executable File

#!/bin/bash
# Launches waybar on the profile's main monitor.
#
# waybar can only pin a bar to an output by name, and the name differs per
# machine -- eDP-1 on the laptop, DP-1 on mainPC -- while DP-1 exists on both,
# so no static list can express "the main monitor". Resolve it from Hyprland
# instead: in both hypr/configs/profiles/*.lua the main monitor is the one at
# position 0x0. waybar/config.jsonc includes the fragment written here.
frag="${XDG_CACHE_HOME:-$HOME/.cache}/waybar-output.jsonc"
mkdir -p "$(dirname "$frag")"
out=$(hyprctl monitors -j 2>/dev/null | jq -r 'map(select(.x == 0 and .y == 0)) | .[0].name // empty')
if [ -n "$out" ]; then
printf '{ "output": "%s" }\n' "$out" > "$frag"
else
# Nothing at 0x0 (or Hyprland not up): fall back to a bar on every output.
printf '{}\n' > "$frag"
fi
exec waybar "$@"