JonnyHaystack / i3-resurrect

Simple solution to saving and restoring i3 workspaces
GNU General Public License v3.0
379 stars 19 forks source link

Restore programs with multiple windows to the correct workspaces #106

Closed ScottG489 closed 3 years ago

ScottG489 commented 3 years ago

Is your feature request related to a problem? Please describe.

When I save and restore my browser (Chrome) it doesn't open the windows on the correct workspaces. Instead it seems to open them on roughly the right ones but also sometimes on random other workspaces.

Also, because I have Chrome set to restore all windows upon opening, i3-resurrect also creates a bunch of new empty Chrome windows since it detects there were multiple windows before and tries to open the same program (Chrome) multiple times.

Describe the solution you'd like

An easier way, or ability at all, to restore all windows that a program opens upon starting to the proper workspaces.

Describe alternatives you've considered

Perhaps this is already possible since it seems like a very common use case, but I wasn't able to determine how to do this from the README.

I saw some mention in the README of the situation where "You have multiple windows for a single instance of an application", but the solution assumes there's a "main window" which there isn't for a browser (or for other applications I have this problem with such as my IDE).

Also perhaps I'm saving and/or restoring my workspaces incorrectly. Currently to save and restore everything I'm running the following:

# Save
for workspace in $(wmctrl -d | awk '{print $9}'); do
  i3-resurrect save -w "$workspace"
done
#Restore
for workspace in {1..9}; do
  i3-resurrect restore -w "$workspace"
done

I've also tried saving with --swallow=class,instance,title, but this didn't seem to work either.

Thanks for the great project and let me know if something like this is already possible!

ScottG489 commented 3 years ago

After a little more testing I noticed that it does seem like the windows that are supposed to be swallowed are being restored to the right workspaces. Just for whatever reason a few of them aren't being swallowed correctly.

For instance, I have 6 windows spread evenly across 3 workspaces, 1/2/3. Windows are correctly restored on 1 and 2 but the windows that were on 3 wind up on 2 and there are two placeholder windows that I believe should have been swallowed on 3 since they have titles corresponding with the windows that should be there, but were instead put on 3.

Perhaps the problem of all the extra Chrome windows being created like I mentioned above is causing issues? Or perhaps it's some kind of race condition where only a few of them are being replaced correctly upon Chrome opening?

JonnyHaystack commented 3 years ago

For my browser I generally restore layout only on all the workspaces that had browser windows, and then I restore the programs only in the first workspace that had a browser window. Then they should all get swallowed to the other workspaces. Then I go and restore programs to the rest of the workspaces. You could maybe modify your script to do restore the layouts automatically, and then you could restore the programs one workspace at a time. I don't think restoring everything at once is very reliable and is prone to race conditions and other unexpected events, so I don't recommend it unless you're restoring layouts only.

ScottG489 commented 3 years ago

Hey thanks for your help!

Played around with it a bit more and I got it working. There was still a small problem, but using --swallow=class,instance,title fixed that.

JonnyHaystack commented 3 years ago

Ah yeah, that is necessary to actually match the window titles. You can also set window swallow criteria in your i3-resurrect config if you want to have different criteria for different programs.