Launching when already on the desired workspace
I have a script that either launches a program on an explicitly named workspace, or switches to that workspace if the program is already running there as indicated by xdotool.
Suppose I launch Google Chrome; it appears on workspace 'gc'. If I quit the program, and stay on workspace 'gc', then launch the program again, i3 switches to another workspace.
I've hacked a solution as below, I'm just curious as to why i3 chooses another workspace as described. Can anyone explain please?
if [ -z "$W" ]; then
# Launch the program.
if [ $# -ge 3 ]; then
if [ "$3" == 'none' ]; then
cmd="exec ${@:4}"
else
# Changing to the previous workspace ensures that we
# launch on the target workspace, when already there.
cmd="workspace_back_and_forth; workspace $3; exec ${@:4}"
fi
i3-msg "$cmd"
fi
else
# Focus the window.
# Used 'sed' to escape any whitespace to suit 'i3-msg'.
i3-msg "[$1=$(echo $2 | sed s/\\x20/\\\\x20/g)] focus"
fi
PS Sorry, I haven't quite mastered the insertion of code snippets.
For the record: phyks posted this at https://github.com/i3/i3/issues/1224