3

Problem

I'm using Sway window manager, but the same applies to i3 I guess.

On startup I want to start 2 terminal windows on the same workspace. One of them will run Neovim, and the second one will be an empty (not running any app) terminal. 2 terminals should be displayed in tabbed layout, but the empty terminal should have stacking layout set, so that when I open a new terminal from it, it'll display as a new stack entry in the second tab. Visually:

On startup

-------------------------------------------------------------------------------
|      Tab: Terminal with Neovim       |    Tab: Other terminals (active)     |
-------------------------------------------------------------------------------
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                 Terminal 1                                  |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
-------------------------------------------------------------------------------

After opening a new terminal on other terminal tabs

-------------------------------------------------------------------------------
|      Tab: Terminal with Neovim       |    Tab: Other terminals (active)     |
-------------------------------------------------------------------------------
|      Other terminals tab: Stack entry: Terminal 1                           |
-------------------------------------------------------------------------------
|      Other terminals tab: Stack entry: Terminal 2 (active)                  |
-------------------------------------------------------------------------------
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                 Terminal 2                                  |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
-------------------------------------------------------------------------------

Question

How can I configure such layout on startup in Sway/i3?

I tried adding the following to the config file, but it doesn't work. Both terminal windows are displayed, but their layouts are not set properly. I guess it happens because of exec executing asynchronously, so that when layout commands are executed, the containers are still not open.

exec swaymsg "workspace $workspace_programming; exec $term --command nvim; layout tabbed; exec $term; split vertical; layout stacking"

1 Answer 1

4

I managed to do it using that configuration:

exec \
    swaymsg "workspace $workspace_programming"; \
    swaymsg "exec $neovim"; \
    swaymsg "layout tabbed"; \
    sleep 0.3s; \
    swaymsg "exec $term"; \
    sleep 0.3s; \
    swaymsg "split vertical"; \
    swaymsg "layout stacking"

EDIT: The above worked, but only when executed after the startup (using exec_always). For some reason when executed during the startup using exec it doesn't work. Surprisingly for me it doesn't open any window at all, not even Neovim terminal. I refactored it a little bit and this version works during the startup too:

exec swaymsg "workspace $workspace_programming; exec $neovim; layout tabbed;"
exec sleep 0.3s && swaymsg "exec $term";
exec sleep 0.6s && swaymsg "workspace $workspace_programming; split vertical; layout stacking"

I don't understand what's the difference between both versions and why the first doesn't work. If somone can explaind me, I'd be glad.

I also still wonder if there is a cleaner way to do it, without having to resort to sleep.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .