#!/bin/sh # umbriel-float-square # Floating focused window: square, as tall as the usable height (below # Noctalia's bar) minus PAD px above and below, centered on its output. # Tiled: center its column (the old Mod+C). Extents are fractions of the # usable area, so both sides are computed from the output's usable size. set -eu PAD=4 window=$(umbriel windows --json | jq -c '[.[] | select(.active)][0] // empty') [ -n "$window" ] || exit 0 if [ "$(printf '%s' "$window" | jq -r .floating)" != true ]; then exec umbriel msg column-center fi id=$(printf '%s' "$window" | jq -r .id) output=$(printf '%s' "$window" | jq -r .output) extents=$(umbriel outputs --json | jq -r --arg o "$output" --argjson pad "$PAD" ' def frac: . * 10000 | floor / 10000; .[] | select(.name == $o) | .usable_area | (.height - 2 * $pad) as $side | "\($side) \([$side / .width, 1] | min | frac) \($side / .height | frac)"') set -- $extents side=$1 umbriel msg "window-set-secondary-extent:$3" umbriel msg "window-set-primary-extent:$2" # window-center uses the size the client has committed; centering before the # resize lands centers the old width. Wait up to 1 s for the new width. i=0 while [ $i -lt 20 ]; do w=$(umbriel windows --json | jq -r --arg id "$id" '.[] | select(.id == $id) | .w') [ $((w - side)) -ge -1 ] && [ $((w - side)) -le 1 ] && break sleep 0.05 i=$((i + 1)) done exec umbriel msg window-center