justbuchanan / i3scripts

My scripts for enhancing i3wm
Other
162 stars 45 forks source link

Crashes when assigning workspaces to specific outputs #14

Closed benbc7 closed 5 years ago

benbc7 commented 5 years ago

When you assign a workspace to a specific output the script renames that workspace with a different number and crashes i3. On top of that, I had google chrome assigned to a specific workspace, and when I launched chrome, i3 put it on the new workspace on the assigned output, then the script renamed that workspace and i3 froze completely.

I have fixed this issue by commenting out the lines that add the gap in numbers for multiple monitors, and setting the new workspace name with the old workspace number instead of n


def rename_workspaces(i3):
    ws_infos = i3.get_workspaces()
    prev_output = None
    n = 1
    for ws_index, workspace in enumerate(i3.get_tree().workspaces()):
        ws_info = ws_infos[ws_index]

        name_parts = parse_workspace_name(workspace.name)
        new_icons = ' '.join([icon_for_window(w) for w in workspace.leaves()])

        # As we enumerate, leave one gap in workspace numbers between each monitor.
        # This leaves a space to insert a new one later.
        #if ws_info.output != prev_output and prev_output != None:
        #    n += 1
        prev_output = ws_info.output

        # renumber workspace
        #new_num = n
        n += 1

        new_name = construct_workspace_name(
            NameParts(
                num=name_parts.num, shortname=name_parts.shortname, icons=new_icons))
        if workspace.name == new_name:
            continue
        i3.command(
            'rename workspace "%s" to "%s"' % (workspace.name, new_name))
sjclayton commented 5 years ago

Thanks for this!!!

i3 and Polybar went crazy with my setup when I first tried to get this working, it freaked me out for a minute watching all my workspaces / windows jump all over the place.

justbuchanan commented 5 years ago

Sorry for taking so long to reply to this, it completely slipped past me.

I can look into adding a command-line flag to the script to make re-numbering optional, which should fix this.

To help me understand the problem better, does this issue only arise when you have i3 configured to assign certain apps to certain workspaces? What does that section of your i3 config look like?

benbc7 commented 5 years ago

The reason this happened was because I have multiple monitors and like to have workspaces assigned to each. I had 1-5 assigned to one monitor, and the other had 6-10. I also had chrome assigned to workspace 6. When I would launch chrome, it would launch on workspace 6, and then the script would rename that workspace to a different number after adding the gap for multiple monitors. Sometimes this made chrome jump all around to different workspaces and monitors, sometimes i3 just crashed entirely. By removing the gap between monitors it fixed the issue. You can check out a fixed version of your script, as well as my i3 and polybar config files on my dotfiles repo https://github.com/benbc7/dotfiles

justbuchanan commented 5 years ago

This should be fixed in https://github.com/justbuchanan/i3scripts/pull/17.