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 2014-04-01 16:14:09 +0000

KJ44 gravatar image

updated 2014-04-01 16:16:06 +0000

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.

edit retag flag offensive close merge delete

Comments

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

Michael gravatar imageMichael ( 2014-04-17 12:47:19 +0000 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-04-12 13:50:27 +0000

Phyks gravatar image

updated 2014-04-12 13:57:34 +0000

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

edit flag offensive delete link more

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 ( 2014-04-14 19:29:31 +0000 )edit

Question Tools

Stats

Asked: 2014-04-01 16:14:09 +0000

Seen: 111 times

Last updated: Apr 12 '14