diff --git a/bin/omarchy-swap-monitors b/bin/omarchy-swap-monitors new file mode 100755 index 0000000000..fb8a1f21de --- /dev/null +++ b/bin/omarchy-swap-monitors @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# Rotate workspaces across all monitors in Hyprland/Omarchy + +readonly APP_NAME="Omarchy" + +dispatch() { + local output + if ! output=$(hyprctl dispatch "$@" 2>&1); then + notify-send "$APP_NAME" "hyprctl dispatch failed: $output" + exit 1 + fi + + if [[ "$output" != "ok" ]]; then + notify-send "$APP_NAME" "$output" + exit 1 + fi +} + +get_active_workspace() { + hyprctl monitors -j | jq -r ".[] | select(.name==\"$1\") | .activeWorkspace.id" +} + +mapfile -t MONITORS < <(hyprctl monitors -j | jq -r '.[].name') + +if (( ${#MONITORS[@]} < 2 )); then + notify-send "$APP_NAME" "Only one monitor detected — nothing to rotate." + exit 0 +fi + +ORIGINAL_MONITOR=$(hyprctl monitors -j | jq -r '.[] | select(.focused == true) | .name') + +if [[ -z "$ORIGINAL_MONITOR" || "$ORIGINAL_MONITOR" == "null" ]]; then + notify-send "$APP_NAME" "Could not detect the focused monitor." + exit 1 +fi + +# Validate that every monitor has an active workspace before rotating. +for mon in "${MONITORS[@]}"; do + ws=$(get_active_workspace "$mon") + if [[ -z "$ws" || "$ws" == "null" ]]; then + notify-send "$APP_NAME" "Could not detect workspace on $mon." + exit 1 + fi +done + +# Swap neighbouring monitors from right-to-left to rotate without creating temps. +for (( i=${#MONITORS[@]}-1; i>=1; i-- )); do + dispatch swapactiveworkspaces "${MONITORS[$((i-1))]}" "${MONITORS[$i]}" +done + +# Ensure focus returns to the monitor the user was on. +dispatch focusmonitor "$ORIGINAL_MONITOR" + +notify-send "$APP_NAME" "Rotated workspaces across ${#MONITORS[@]} monitors." diff --git a/default/hypr/bindings/utilities.conf b/default/hypr/bindings/utilities.conf index c8b3efdbd5..c6ae00627e 100644 --- a/default/hypr/bindings/utilities.conf +++ b/default/hypr/bindings/utilities.conf @@ -24,6 +24,9 @@ bindd = SUPER CTRL, I, Toggle locking on idle, exec, omarchy-toggle-idle # Toggle nightlight bindd = SUPER CTRL, N, Toggle nightlight, exec, omarchy-toggle-nightlight +# Swap between monitors +bindd = SUPER CTRL, M, Swap monitors, exec, omarchy-swap-monitors + # Control Apple Display brightness bindd = CTRL, F1, Apple Display brightness down, exec, omarchy-cmd-apple-display-brightness -5000 bindd = CTRL, F2, Apple Display brightness up, exec, omarchy-cmd-apple-display-brightness +5000