I'm looking for a solution to keep all windows of a process on a given workspace for use with i3 (i3wm).
I was thinking to use the
i3-msg binary to issue
assign [...] workspace ... commands to constrain the windows of a process/process-tree to a workspace (by name or number).
This is what I've come up with so far: https://gist.github.com/nmschulte/ab206ea9bd32f3eb599cf1552ef27ecc
#!/usr/bin/env sh ## constrain process windows to an i3 workspace; requires jq ## usage: i3-proc-to-ws.sh command if [ -z "$JQ" ]; then JQ=jq fi if [ -z "$I3_PROC_TO_WS" ]; then I3_PROC_TO_WS=$(i3-msg -t get_workspaces | $JQ '. | select(.focused) | .num') fi $@ & PID=$! # get window properties for wid in $(xwininfo -tree -root -int | sed 's/\(xwininfo:\| \)*\([0-9]*\) [^c].*/\2/'); do wpid=$(xprop -id $wid _NET_WM_PID | sed 's/_NET_WM_PID.* = \([0-9]\+\)/\1/') echo $PID $wpid constraint=$(xprop -id $wid WM_CLASS | sed 's/WM_CLASS.* = "\(.*\)", "\(.*\)"/class="^\2$" instance="^\1$"/') echo $constraint if [ "$PID" -eq "$wpid" ]; then #constraint=$(xprop -id $wid WM_CLASS | sed 's/WM_CLASS.* = "\(.*\)", "\(.*\)"/class="^\2$" instance="^\1$"/') echo i3-msg -t command assign [$constraint] $I3_PROC_TO_WS fi done wait $PID
references with potential alternative solutions: