Linux (Ideally Mint/MATE): How Can I Avoid Moving Several Chrome Windows to Different Workspaces When Chrome Restarts

1

Chrome has a nifty feature where it saves all of your open windows. When you close Chrome (either on purpose, or because your house's electrical system is terrible and your wife tried to make tea and use the microwave at the same time) it saves every open window, and then the next time you start Chrome it restores them (or gives you an option to, depending).

That's all wonderful except for one thing: all those windows re-appear on the current workspace, NOT on the workspace they were closed from. Going with the whole point of workspaces, I like to have 1-2 Chrome windows with tabs about topic #1 on workspace #1, 1-2 with tabs on topic #2 on workspace #2, etc. But when Chrome crashes or closes and I restart it, I have to reposition all of those windows to the correct workspaces.

Has anyone found a program, or even a script, that would make it possible for Chrome (or a script that starts Chrome) to position all of those windows back to the workspace they belong on?

machineghost

Posted 2019-02-28T20:40:21.013

Reputation: 732

How would the script know what workspace the newly opened windows belong on? Save a list of all windows every few minutes, "just in case"? – Xen2050 – 2019-02-28T21:44:22.567

The solution with the least effort wins :) If there's a way for it to poll periodically "just in case" so I don't have to configure anything or even think, that of course would be awesome. But if that's not possible, a solution where I somehow configure or tell the script "I want the window with this name, or containing a tab with this URL, or whatever, to go to workspace 5", that'd still be a lot better than having to manually move that window every time Chrome restarts. – machineghost – 2019-02-28T21:55:04.033

I had another idea to send any window to a specified desktop, manually but it seems quick & easy. Edited it into my answer FYI (I don't think you get notified of answers being edited, unless it's your own answer) – Xen2050 – 2019-03-14T01:32:50.680

Answers

1

Looks like the wmctrl program (from the package of the same name) might be useful for your scripting, it's description is

Wmctrl is a command line tool to interact with an EWMH/NetWM compatible X Window Manager (examples include Enlightenment, icewm, kwin, metacity, and sawfish).

Wmctrl provides command line access to almost all the features defined in the EWMH specification. For example it can maximize windows, make them sticky, set them to be always on top. It can switch and resize desktops and perform many other useful operations.

it's got options like

  • -r <WIN> Specify a target window for an action.

  • -t <DESK> Move a window that has been specified with the -r action to the desktop <DESK>.

  • -l List the windows being managed by the window manager. One line is output for each window, with the line broken up into space separated columns. The first column always contains the window identity as a hexadecimal integer, and the second col‐ umn always contains the desktop number (a -1 is used to identify a sticky window). If the -p option is specified the next column will contain the PID for the window as a decimal integer. If the -G option is specified then four integer columns will follow: x-offset, y-offset, width and height. The next column always contains the client machine name. The remainder of the line contains the window title (possibly with multiple spaces in the title).

It appears Chrome/Chromium windows might change title depending on what tab is open... so might want these too:

  • -N name Set the name (long title) of the window specified by a -r action to name.

  • -I name Set the icon name (short title) of the window specified by a -r action to name.

  • -T name Set the both the name (long title) and icon name (short title) of the window spec‐ ified by a -r action to name. This action is like using the -N and -I actions at the same time (which would otherwise be impossible since wmctrl can execute only one action at a time).

  • -x Include WM_CLASS in the window list or interpret <WIN> as the WM_CLASS name.

    [For example, chromium.Chromium]


A quicker "manual" idea

I was looking at the AntiX (also in MX-Linux) package wingrid-antix and it has shell scripts for moving & resizing windows, they're used as keyboard shortcuts in your window manager, using wmctrl -r :ACTIVE: ... that gave me this idea:

If you made some keyboard shortcuts to send a window to a specific desktop (numbering starts at zero):

wmctrl -r :ACTIVE: -t 0

And others to send to desktops -t 1, -t 2, etc, with shortcut keys like "Ctrl+Super+1", then when a browser window is active all you have to do is press a desktop's shortcut keys and that window will get sent to another desktop.

It's not automatic, but it is push-button easy, and no worries about Chrome's weird window names.

Xen2050

Posted 2019-02-28T20:40:21.013

Reputation: 12 097