aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2026-10-13 17:23:31 +1100
committerYuchen Pei <id@ypei.org>2026-10-13 17:23:31 +1100
commitd1ab29768fb1d21e7733f7f3f5ab1960bf99de42 (patch)
tree90209b55112254d52ca30b2528386ee8fea3d8bd
parentde8560903a5268056125976344f5da003553b9dd (diff)
[i3] Add focus mode
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--misc/.config/i3/config3
-rwxr-xr-xmisc/.config/i3/focus.sh33
2 files changed, 36 insertions, 0 deletions
diff --git a/misc/.config/i3/config b/misc/.config/i3/config
index 803dcd1..38ab273 100644
--- a/misc/.config/i3/config
+++ b/misc/.config/i3/config
@@ -207,7 +207,10 @@ bindsym $mod+Shift+m focus parent; fullscreen; focus child
bindsym $mod+equal exec dunstctl history-pop
bindsym $mod+minus exec dunstctl close
+bindsym $mod+F1 exec --no-startup-id ~/.config/i3/focus.sh
+
# startup
+exec --no-startup-id xsetroot -solid "#000000"
exec ibus-daemon
exec redshift-gtk
exec --no-startup-id i3-msg 'workspace $ws1; exec urxvt'
diff --git a/misc/.config/i3/focus.sh b/misc/.config/i3/focus.sh
new file mode 100755
index 0000000..6dd7d46
--- /dev/null
+++ b/misc/.config/i3/focus.sh
@@ -0,0 +1,33 @@
+#!/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