i3 – Implementing Layout with Autostarting Applications in i3 Window Manager

i3

This is a follow-up on a prior question on how to autostart applications on individual workspaces with the i3 window manager and what can and can't be done inside the ~/.i3/config configuration file.

First, the provided solution based on Arch Linux documentation and an update provided by op where he pushes the logic further:

exec --no-startup-id i3-msg 'workspace 1:Web; exec /usr/bin/firefox'
exec --no-startup-id i3-msg 'workspace 1; exec firefox; workspace 2; exec urxvt; workspace 1'

Also of interest is this exchange about leveraging some of that directly on the command line without duplicating:

i3-msg workspace 3; i3-msg exec firefox
i3-msg workspace 9; i3-msg exec chromium

But I have never seen a configuration which autostarts many windows/apps in each workspace according to a desired vertical or horizontal layout. My goal is to autostart this simple configuration I use:

 _____ _____     ___________     ___________
| lx  | lx  |   |        |u_|   |     |     |   proportions:
|_____|_____|   |  FF    |lx|   |spacefm    |   1- 25% each
|medit| lx  |   |        |__|   |     | vlc |   2- 75/25 x 25/50/25
|_____|_____|   |________|u_|   |_____|_____|   3- 50/50
      1               2               3

So it starts with something like this in the config file:

exec --no-startup-id i3-msg 'workspace 1; exec i3-sensible-terminal; layout toggle split; layout splitv; split vertical; exec i3-sensible-terminal; exec i3-sensible-terminal; exec i3-sensible-terminal; workspace 2; exec firefox; exec urxvt; exec i3-sensible-terminal; exec urxvt; workspace 3; exec spacefm; exec vlc'

But how in the world do you achieve the type of layout and vert/horizontal splitting you want? I'm trying, but it's not clear how you "mix" execution and layout. The syntax feels idiosyncratic to start because you're executing i3-img within i3's configuration. Do you use split h (or v) – layout split vexec layout split vfocus down(or right) in between each exec call??

For a single workspace, the configuration starts all applications either vertically or horizontally and I can't seem to influence layout – or the last split command in the chain decides whether the windows are added vertically or horizontally. i3-msg seemingly ignores parts of the command that aren't properly formatted in some cases so it's hard to debug. This is further compounded by the fact that you really need to quit X and startx again every time to verify the results as just refreshing the configuration with mod+shift+R won't cut it even if you close everything on each of the workspaces.

What is the proper way of configuring this? Does anyone have a solution which implements something like that? The documentation is pretty good but it doesn't provide that I can see a detailed example which mixes execution and layout on multiple workspaces.

Best Answer

I believe that you are looking for the new layout-saving feature that was introduced in i3 v4.8 (2014-06-15). The linked documentation seems pretty thorough.

Quoting from the documentation:

Layout saving/restoring allows you to load a JSON layout file so that you can have a base layout to start working with after powering on your computer. Dynamic use-cases also come to mind: if you frequently (but not always!) need a grid layout of terminals with ping/traceroute commands to diagnose network issues, you can easily automate opening these windows in just the right layout.

... and the release notes:

tl;dr: export1 your current layout as JSON file, load it into new i3 sessions, get placeholder windows that will be replaced by the actual apps once you start them.


1. You may require the perl-anyevent-i3 and perl-json-xs packages to use the i3-save-tree utility.

Related Question