Skip to content

Instantly share code, notes, and snippets.

@kdevo
Last active September 25, 2024 13:00
Show Gist options
  • Save kdevo/c860af827f552c4d84511855c3b911bc to your computer and use it in GitHub Desktop.
Save kdevo/c860af827f552c4d84511855c3b911bc to your computer and use it in GitHub Desktop.
i3wm: Tricks to assign "problematic" applications to a specific workspace/layout.

i3 Window Manager Tips and Tricks

...to assign applications to a specific workspace/layout.

i3wm makes it easy to assign applications to workspaces and save and restore layouts - which is e.g. useful for auto-starting always needed software. To make these assignments, you need specific window properties so that you can tell i3 to assign [class="Your-app"] → 1 (in this example, Your-app will be assigned to workspace 1).

In many cases this just works. However, there are also many popular programs that do not initially set the correct window class or other properties on startup, which can be frustrating. This cheat sheet aims to show the problems and possible resolutions (or worse: workarounds) for more or less problematic applications.


Spotify

Snap-Package: spotify

Problem

Using assign command does not work (also stated e.g. in the official i3-docs).

Not working example: assign [class="Spotify"] 5

Resolution

Use for_window instead. It will execute on each window state change (in contrary to assign, where this only happens once).

Example: for_window [class="Spotify"] move to workspace 5


Chromium

Package: chromium-browser

Problem

The Chromium Internet Browser does not always start on the wanted workspace. You can use the class window property and assign like this: assign [class="Chromium-browser"] 1, but what if you want to setup and tile multiple Chromium instances? They all have the same class...

You cannot use the window title here since it is a) only set when the page is already loaded and b) too dependent on the website (resulting in a mismatch_

Workaround

Imagine you want to launch Google Notes and Google Calendar in split screen mode. What we need is a way to distinguish between multiple instances.

I came up with the following workaround: Launch Chromium in "app mode":

chromium-browser --app="https://calendar.google.com/"

Now check the newly launched instances by running xprop and sniping the window:

WM_WINDOW_ROLE(STRING) = "pop-up"
WM_CLASS(STRING) = "calendar.google.com", "Chromium-browser"
[...]

See line #2. The instance name is now "calendar.google.com" instead of "chromium-browser" (try it on a "normal" Chromium instance). We can use this to our advantage and adapt and use the instance name to assign the window:

assign [class="Chromium-browser" instance="calendar.google.com"] 1

If you prefer to use a layout, match the instance and the class in the relevant swallows-block:

"swallows": [{
    "class": "^Chromium\\-browser$",
    "instance": "^calendar.google.com$"
  }]

Gnome Terminal

Package: gnome-terminal

Problem

Similar to Chromium: An additional property is needed to differentiate multiple terminals.

Resolution

Start gnome-terminal with the --window-role flag to set a unique role that can be referenced (either by using assign or in your layout file). In your i3 config:

exec gnome-terminal --role "your-own-role" -- ${YOUR_COMMANDS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment