diff --git a/bin/omarchy-hyprland-monitor-scale b/bin/omarchy-hyprland-monitor-scale deleted file mode 100755 index 1d9d5aae..00000000 --- a/bin/omarchy-hyprland-monitor-scale +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -# omarchy:summary=Print the monitor scale of the internal monitor or first other monitor - -hyprctl monitors -j | jq -r '([.[] | select(.name | contains("eDP"))][0] // .[0]).scale // empty | tonumber | if . == floor then floor else . end' diff --git a/bin/omarchy-hyprland-monitor-scaling b/bin/omarchy-hyprland-monitor-scaling new file mode 100755 index 00000000..004a2743 --- /dev/null +++ b/bin/omarchy-hyprland-monitor-scaling @@ -0,0 +1,87 @@ +#!/bin/bash + +# omarchy:summary=Show, set, or adjust focused Hyprland monitor scaling +# omarchy:args=[up|down|1|1.25|1.6|2|3|4] +# omarchy:examples=omarchy hyprland monitor scaling | omarchy hyprland monitor scaling 1.6 | omarchy hyprland monitor scaling up | omarchy hyprland monitor scaling down + +SCALES=(1 1.25 1.6 2 3 4) + +usage() { + echo "Usage: omarchy-hyprland-monitor-scaling [up|down|1|1.25|1.6|2|3|4]" +} + +focused_monitor_scale() { + hyprctl monitors -j | jq -er '.[] | select(.focused == true) | .scale' +} + +set_scale() { + local new_scale="$1" + local monitor_info="$(hyprctl monitors -j | jq -e -c '.[] | select(.focused == true)')" + local active_monitor="$(echo "$monitor_info" | jq -r '.name')" + local width="$(echo "$monitor_info" | jq -r '.width')" + local height="$(echo "$monitor_info" | jq -r '.height')" + local refresh_rate="$(echo "$monitor_info" | jq -r '.refreshRate')" + local monitor_lua="$HOME/.config/hypr/monitors.lua" + + hyprctl eval "hl.monitor({ output = \"$active_monitor\", mode = \"${width}x${height}@${refresh_rate}\", position = \"auto\", scale = $new_scale })" >/dev/null + + # Persist to monitors.lua if the user still has Omarchy's generic catch-all + # defaults, so the scale survives reboots. + if [[ -f $monitor_lua ]] && grep -q '^local omarchy_monitor_scale = ' "$monitor_lua"; then + sed -i -E \ + -e "s|^local omarchy_monitor_scale = .*|local omarchy_monitor_scale = ${new_scale}|" \ + -e "s|^local omarchy_gdk_scale = .*|local omarchy_gdk_scale = ${new_scale}|" \ + "$monitor_lua" + elif [[ -f $monitor_lua ]] && grep -Eq '^hl\.monitor\(\{ output = "", mode = "preferred", position = "auto", scale = ("auto"|[0-9.]+) \}\)' "$monitor_lua"; then + sed -i -E \ + -e "s|^(hl\.monitor\(\{ output = \"\", mode = \"preferred\", position = \"auto\", scale = )([^ ]+)( \}\))|\\1${new_scale}\\3|" \ + -e 's|^hl\.env\("GDK_SCALE", ".*"\)|hl.env("GDK_SCALE", "'"$new_scale"'")|' \ + "$monitor_lua" + fi +} + +scale_from_current() { + local direction="${1:-}" + + # Find the preset closest to the current scale (Hyprland may snap fractional + # scales to nearby values, so we can't match exactly). + awk -v direction="$direction" -v list="${SCALES[*]}" ' + NR == 1 { scale = $0; found = 1 } + END { + if (!found) exit 1 + + n = split(list, scales, " ") + best = 1; best_diff = 1e9 + for (i = 1; i <= n; i++) { + diff = scale - scales[i]; if (diff < 0) diff = -diff + if (diff < best_diff) { best_diff = diff; best = i } + } + + if (direction == "next" && best < n) best++ + else if (direction == "previous" && best > 1) best-- + + print scales[best] + }' +} + +case "${1:-}" in +"") + focused_monitor_scale | scale_from_current + ;; +-h | --help) + usage + ;; +up) + set_scale "$(focused_monitor_scale | scale_from_current next)" + ;; +down) + set_scale "$(focused_monitor_scale | scale_from_current previous)" + ;; +1 | 1.25 | 1.6 | 2 | 3 | 4) + set_scale "$1" + ;; +*) + usage >&2 + exit 1 + ;; +esac diff --git a/bin/omarchy-hyprland-monitor-scaling-cycle b/bin/omarchy-hyprland-monitor-scaling-cycle deleted file mode 100755 index ce66c564..00000000 --- a/bin/omarchy-hyprland-monitor-scaling-cycle +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# omarchy:summary=Cycle focused Hyprland monitor scaling through 1x, 1.25x, 1.6x, 2x, 3x, and 4x -# omarchy:args=[--reverse] -# omarchy:examples=omarchy-hyprland-monitor-scaling-cycle | omarchy-hyprland-monitor-scaling-cycle --reverse - -CURRENT_SCALE=$(hyprctl monitors -j | jq -r '.[] | select(.focused == true) | .scale') - -SCALES=(1 1.25 1.6 2 3 4) - -# Find the index of the scale closest to the current one (Hyprland may -# snap fractional scales to nearby values, so we can't match exactly). -CURRENT_IDX=$(awk -v s="$CURRENT_SCALE" -v list="${SCALES[*]}" 'BEGIN { - n = split(list, arr, " ") - best = 0; best_diff = 1e9 - for (i = 1; i <= n; i++) { - d = s - arr[i]; if (d < 0) d = -d - if (d < best_diff) { best_diff = d; best = i - 1 } - } - print best -}') - -if [[ $1 == "--reverse" ]]; then - NEW_IDX=$(( (CURRENT_IDX - 1 + ${#SCALES[@]}) % ${#SCALES[@]} )) -else - NEW_IDX=$(( (CURRENT_IDX + 1) % ${#SCALES[@]} )) -fi - -exec omarchy-hyprland-monitor-scaling-set "${SCALES[$NEW_IDX]}" diff --git a/bin/omarchy-hyprland-monitor-scaling-get b/bin/omarchy-hyprland-monitor-scaling-get deleted file mode 100755 index f3ccb655..00000000 --- a/bin/omarchy-hyprland-monitor-scaling-get +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# omarchy:summary=Get focused Hyprland monitor scaling -# omarchy:examples=omarchy-hyprland-monitor-scaling-get - -hyprctl monitors -j | jq -r '.[] | select(.focused == true) | .scale' diff --git a/bin/omarchy-hyprland-monitor-scaling-set b/bin/omarchy-hyprland-monitor-scaling-set deleted file mode 100755 index 056326f6..00000000 --- a/bin/omarchy-hyprland-monitor-scaling-set +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# omarchy:summary=Set focused Hyprland monitor scaling to a specific value -# omarchy:args=<1|1.25|1.6|2|3|4> -# omarchy:examples=omarchy-hyprland-monitor-scaling-set 1.6 | omarchy-hyprland-monitor-scaling-set 2 - -NEW_SCALE="$1" - -case "$NEW_SCALE" in - 1) NEW_GDK_SCALE=1 ;; - 1.25) NEW_GDK_SCALE=1.25 ;; - 1.6) NEW_GDK_SCALE=1.75 ;; - 2) NEW_GDK_SCALE=2 ;; - 3) NEW_GDK_SCALE=3 ;; - 4) NEW_GDK_SCALE=4 ;; - *) - echo "Usage: omarchy-hyprland-monitor-scaling-set <1|1.25|1.6|2|3|4>" >&2 - exit 1 - ;; -esac - -MONITOR_INFO=$(hyprctl monitors -j | jq -r '.[] | select(.focused == true)') -ACTIVE_MONITOR=$(echo "$MONITOR_INFO" | jq -r '.name') -WIDTH=$(echo "$MONITOR_INFO" | jq -r '.width') -HEIGHT=$(echo "$MONITOR_INFO" | jq -r '.height') -REFRESH_RATE=$(echo "$MONITOR_INFO" | jq -r '.refreshRate') - -hyprctl eval "hl.monitor({ output = \"$ACTIVE_MONITOR\", mode = \"${WIDTH}x${HEIGHT}@${REFRESH_RATE}\", position = \"auto\", scale = $NEW_SCALE })" >/dev/null - -# Persist to monitors.lua if the user still has Omarchy's generic catch-all -# defaults, so the scale survives reboots. -MONITOR_LUA="$HOME/.config/hypr/monitors.lua" -if [[ -f $MONITOR_LUA ]] && grep -q '^local omarchy_monitor_scale = ' "$MONITOR_LUA"; then - sed -i -E \ - -e "s|^local omarchy_monitor_scale = .*|local omarchy_monitor_scale = ${NEW_SCALE}|" \ - -e "s|^local omarchy_gdk_scale = .*|local omarchy_gdk_scale = ${NEW_GDK_SCALE}|" \ - "$MONITOR_LUA" -elif [[ -f $MONITOR_LUA ]] && grep -Eq '^hl\.monitor\(\{ output = "", mode = "preferred", position = "auto", scale = ("auto"|[0-9.]+) \}\)' "$MONITOR_LUA"; then - sed -i -E \ - -e "s|^(hl\.monitor\(\{ output = \"\", mode = \"preferred\", position = \"auto\", scale = )([^ ]+)( \}\))|\\1${NEW_SCALE}\\3|" \ - -e 's|^hl\.env\("GDK_SCALE", ".*"\)|hl.env("GDK_SCALE", "'"$NEW_GDK_SCALE"'")|' \ - "$MONITOR_LUA" -fi diff --git a/default/hypr/bindings/tiling-v2.lua b/default/hypr/bindings/tiling-v2.lua index 04022b2e..058780a1 100644 --- a/default/hypr/bindings/tiling-v2.lua +++ b/default/hypr/bindings/tiling-v2.lua @@ -89,5 +89,5 @@ for index = 1, 5 do o.bind("SUPER + ALT + code:" .. tostring(index + 9), "Switch to group window " .. index, hl.dsp.group.active({ index = index })) end -o.bind("SUPER + code:61", "Cycle monitor scaling", "omarchy-hyprland-monitor-scaling-cycle") -o.bind("SUPER + ALT + code:61", "Cycle monitor scaling backwards", "omarchy-hyprland-monitor-scaling-cycle --reverse") +o.bind("SUPER + code:61", "Monitor scaling up", "omarchy-hyprland-monitor-scaling up") +o.bind("SUPER + ALT + code:61", "Monitor scaling down", "omarchy-hyprland-monitor-scaling down") diff --git a/default/omarchy/omarchy-menu.jsonc b/default/omarchy/omarchy-menu.jsonc index afda36b9..925dbc3c 100644 --- a/default/omarchy/omarchy-menu.jsonc +++ b/default/omarchy/omarchy-menu.jsonc @@ -82,7 +82,6 @@ "trigger.toggle.workspace-layout": {"icon":"󱂬","label":"Workspace Layout","action":"omarchy-hyprland-workspace-layout-toggle"}, "trigger.toggle.window-gaps": {"icon":"","label":"Window Gaps","action":"omarchy-hyprland-window-gaps-toggle"}, "trigger.toggle.one-window-ratio": {"icon":"","label":"1-Window Ratio","keywords":"square","action":"omarchy-hyprland-window-single-square-aspect-toggle"}, - "trigger.toggle.monitor-scaling": {"icon":"󰍹","label":"Monitor Scaling","keywords":"display","action":"omarchy-hyprland-monitor-scaling-cycle"}, "trigger.toggle.direct-boot": {"icon":"","label":"Direct Boot","action":"omarchy-launch-floating-terminal-with-presentation omarchy-config-direct-boot"}, "trigger.toggle.passwordless-sudo": {"icon":"󰟵","label":"Passwordless Sudo","action":"omarchy-launch-floating-terminal-with-presentation omarchy-sudo-passwordless"}, diff --git a/default/quickshell/omarchy-shell/plugins/bar/widgets/monitorPanel.qml b/default/quickshell/omarchy-shell/plugins/bar/widgets/monitorPanel.qml index 11998158..9d84a399 100644 --- a/default/quickshell/omarchy-shell/plugins/bar/widgets/monitorPanel.qml +++ b/default/quickshell/omarchy-shell/plugins/bar/widgets/monitorPanel.qml @@ -111,7 +111,7 @@ Item { } function setScale(scale) { - actionProc.command = ["bash", "-lc", "omarchy-hyprland-monitor-scaling-set " + scale] + actionProc.command = ["bash", "-lc", "omarchy-hyprland-monitor-scaling " + scale] if (!actionProc.running) actionProc.running = true } @@ -129,7 +129,7 @@ Item { Process { id: stateProc - command: ["bash", "-lc", "omarchy-brightness-display 2>/dev/null || true; monitors_json=$(hyprctl monitors all -j); printf '%s\\n' \"$monitors_json\" | jq -r 'def internal: test(\"^(eDP|LVDS|DSI)-\"); ([.[] | select(.name | internal)][0].name // \"\"), ([.[] | select((.name | internal) | not)][0].name // \"\"), ([.[] | select((.name | internal) and .disabled != true)][0].name // \"\"), ([.[] | select((.name | internal) and .mirrorOf != \"none\")][0].mirrorOf // \"\")'; omarchy-hyprland-monitor-focused 2>/dev/null || echo; omarchy-hyprland-monitor-scaling-get 2>/dev/null || echo; printf '%s\\n' \"$monitors_json\" | jq -c '[.[] | {name, enabled:(.disabled != true), focused:(.focused == true)}]'"] + command: ["bash", "-lc", "omarchy-brightness-display 2>/dev/null || true; monitors_json=$(hyprctl monitors all -j); printf '%s\\n' \"$monitors_json\" | jq -r 'def internal: test(\"^(eDP|LVDS|DSI)-\"); ([.[] | select(.name | internal)][0].name // \"\"), ([.[] | select((.name | internal) | not)][0].name // \"\"), ([.[] | select((.name | internal) and .disabled != true)][0].name // \"\"), ([.[] | select((.name | internal) and .mirrorOf != \"none\")][0].mirrorOf // \"\")'; omarchy-hyprland-monitor-focused 2>/dev/null || echo; omarchy-hyprland-monitor-scaling 2>/dev/null || echo; printf '%s\\n' \"$monitors_json\" | jq -c '[.[] | {name, enabled:(.disabled != true), focused:(.focused == true)}]'"] stdout: StdioCollector { waitForEnd: true onStreamFinished: { diff --git a/install/first-run/gdk-scale.sh b/install/first-run/gdk-scale.sh index 6cc23577..ba39e92a 100644 --- a/install/first-run/gdk-scale.sh +++ b/install/first-run/gdk-scale.sh @@ -1,3 +1,3 @@ # Set the default GDK_SCALE from what the monitor is currently reporting -sed -i -E "s|^([[:space:]]*env[[:space:]]*=[[:space:]]*GDK_SCALE,).*|\\1$(omarchy-hyprland-monitor-scale)|" ~/.config/hypr/monitors.conf +sed -i -E "s|^([[:space:]]*env[[:space:]]*=[[:space:]]*GDK_SCALE,).*|\\1$(omarchy-hyprland-monitor-scaling)|" ~/.config/hypr/monitors.conf