The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

Launching when already on the desired workspace

asked Apr 1 '14

KJ44 gravatar image

updated Apr 1 '14

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.

Comments

For the record: phyks posted this at https://github.com/i3/i3/issues/1224

Michael gravatar imageMichael (Apr 17 '14)edit

1 answer

Sort by » oldest newest most voted
0

answered Apr 12 '14

Phyks gravatar image

updated Apr 12 '14

Hi,

I'm having exactly the same problem. This is because I have set workspace_auto_back_and_forth yes in my i3 config file (and I guess you did the same).

Thanks for your hacky solution. But, I'm wondering if this is not a bug that should be fixed ? Or if a way to explicitly tell move container to workspace to not take this into account is / could be implemented ?

In fact, I'm encountering a bit different problem as I want to move an existing window with a for_window statement. I could use xdotool, but that starts to become really hacky stuff.

Thanks

Comments

Before my workaround, I somehow, sometimes, managed to create a workspace called "back and forth", this may be a clue. I think, perhaps, the problem only appears with one empty (scratchpad) workspace and one tiled workspace.

KJ44 gravatar imageKJ44 (Apr 14 '14)edit

Question Tools

Stats

Asked: Apr 1 '14

Seen: 111 times

Last updated: Apr 12 '14