Skip to content

Instantly share code, notes, and snippets.

@nmschulte
Created December 12, 2019 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmschulte/ab206ea9bd32f3eb599cf1552ef27ecc to your computer and use it in GitHub Desktop.
Save nmschulte/ab206ea9bd32f3eb599cf1552ef27ecc to your computer and use it in GitHub Desktop.
constrain process windows to an i3 workspace
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment