#!/bin/bash # toggle reading/focus mode on the current workspace WIDTH=1000 # desired window width in pixels ws=$(i3-msg -t get_tree | jq -c 'first(.. | objects | select(.type=="workspace" and any(.. | objects; .focused == true)))') # Gap per side = (workspace width - desired width) / 2, minus any inner gap ws_width=$(echo "$ws" | jq '.rect.width') inner_gap=$(echo "$ws" | jq '.gaps.inner // 0') gap=$(( (ws_width - WIDTH) / 2 - inner_gap )) [ "$gap" -lt 0 ] && gap=0 on="layout tabbed; gaps horizontal current set $gap; bar mode hide" off="layout splith; gaps horizontal current set 0; bar mode dock" count=$(echo "$ws" | jq '.nodes | length') inner=$(echo "$ws" | jq '.nodes[0].nodes | length') if [ "$count" -eq 1 ] && [ "$inner" -gt 0 ]; then layout=$(echo "$ws" | jq -r '.nodes[0].layout') child=$(echo "$ws" | jq '.nodes[0].nodes[0].id') if [ "$layout" = "tabbed" ]; then i3-msg "[con_id=$child] $off" else i3-msg "[con_id=$child] $on" fi else child=$(echo "$ws" | jq '.nodes[0].id') i3-msg "[con_id=$child] $on" fi