diff --git a/hypr/configs/apps.lua b/hypr/configs/apps.lua index 985cf82..31058bc 100644 --- a/hypr/configs/apps.lua +++ b/hypr/configs/apps.lua @@ -1,6 +1,9 @@ -- Was: configs/default_apps.conf -local bar = "waybar" +-- The bar is launched through a wrapper that pins it to this machine's main +-- monitor (see hypr/scripts/bar); signals still go to the waybar process. +local bar = os.getenv("HOME") .. "/.config/hypr/scripts/bar" +local bar_proc = "waybar" local notifications = "swaync-client" local terminal = "kitty" @@ -8,8 +11,8 @@ return { launcher = "rofi -show drun", bar = bar, - bar_toggle = "killall -SIGUSR1 " .. bar, - bar_reload = "killall " .. bar .. "; " .. bar, + bar_toggle = "killall -SIGUSR1 " .. bar_proc, + bar_reload = "killall " .. bar_proc .. "; " .. bar, notifications = notifications, notifications_read = notifications .. " -C", diff --git a/hypr/scripts/autostart/services b/hypr/scripts/autostart/services index 5407e6a..262a088 100755 --- a/hypr/scripts/autostart/services +++ b/hypr/scripts/autostart/services @@ -9,8 +9,8 @@ awww-daemon --format xrgb & # Pyprland Daemon pypr --debug /tmp/pypr.log & -# Bar -waybar & +# Bar (wrapper pins it to the main monitor of the active profile) +"$HOME"/.config/hypr/scripts/bar & # Notification Daemon swaync & diff --git a/hypr/scripts/bar b/hypr/scripts/bar new file mode 100755 index 0000000..6e1791a --- /dev/null +++ b/hypr/scripts/bar @@ -0,0 +1,23 @@ +#!/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 "$@" diff --git a/hypr/scripts/performance b/hypr/scripts/performance index 1818835..5fce841 100755 --- a/hypr/scripts/performance +++ b/hypr/scripts/performance @@ -17,7 +17,7 @@ if [ "$HYPRGAMEMODE" = true ]; then fi killall waybar -waybar > /dev/null 2>&1 & +"$HOME"/.config/hypr/scripts/bar > /dev/null 2>&1 & # Hyprland performance if [ "$HYPRGAMEMODE" = true ]; then diff --git a/waybar/config.jsonc b/waybar/config.jsonc index d59df89..a740476 100644 --- a/waybar/config.jsonc +++ b/waybar/config.jsonc @@ -1,12 +1,13 @@ [ { - "include": "~/.config/waybar/bars/main.jsonc", + "include": [ + "~/.config/waybar/bars/main.jsonc", + // "output", resolved per machine by hypr/scripts/bar -- see the comment + // there. Missing file just means a bar on every monitor. + "~/.cache/waybar-output.jsonc", + ], "height": 50, "layer": "top", - // Primary output of each machine profile (see hypr/configs/profiles): - // eDP-1 on the laptop, DP-1 on the PC. Waybar skips names that are - // not connected, so one list works on both. - "output": ["eDP-1", "DP-1"], "mode": "dock", "exclusive": true, "passtrough": false,