-
-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ui): swap layouts and stacked panes #2167
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… multiple resizes that it debounces weirdly
joshheyse
pushed a commit
to joshheyse/zellij
that referenced
this pull request
Mar 11, 2023
* relayout working with hard coded layout * work * refactor(layout): PaneLayout => TiledPaneLayout * tests passing * tests passing * tests passing * stacked panes and passing tests * tests for stacked panes * refactor(panes): stacked panes * fix: focusing into stacked panes from the left/right * fix(layouts): handle stacked layouts in the middle of the screen * fix(pane-stack): focus correctly when coming to stack from above/below * fix(stacked-panes): resize stack * fix(stacked-panes): focus with mouse * fix(stacked-panes): focus next pane * fix(layout-applier): sane focus order * fix(stacked-panes): better titles for one-liners * fix(stacked-panes): handle moving pane location in stack * fix(relayout): properly calculate display area * fix(relayout): properly calculate rounding errors * fix(stacked-panes): properly handle closing a pane near a stack * fix(swap-layouts): adjust swap layout sort order * feat(swap-layouts): ui + ux * fix(swap-layouts): include base layout * refactor(layout): remove unused method * fix(swap-layouts): respect pane contents and focus * work * fix(swap-layouts): load swap layouts from external file * fix(swap-layouts): properly truncate layout children * fix(stacked-panes): allow stacked panes to become fullscreen * fix(swap-layouts): work with multiple tabs * fix(swap-layouts): embed/eject panes properly with auto-layout * fix(stacked-panes): close last pane in stack * fix(stacked-panes): move focus for all clients in stack * fix(floating-panes): set layout damaged when moving panes * fix(relayout): move out of unfitting layout when resizing whole tab * fix(ui): background color for swap layout indicator * fix(keybinds): add switch next layout in tmux * fix(ui): swap layout indication in compact layout * fix(compact): correct swap constraint * fix(tests): tmux swap config shortcut * fix(resizes): cache resizes so as not to confuse panes (eg. vim) with multiple resizes that it debounces weirdly * feat(cli): dump swap layouts * fix(ui): stacked panes without pane frames * fix(ux): move pane forward/backwards also with floating panes * refactor(lint): remove unused stuff * refactor(tab): move swap layouts to separate file * style(fmt): rustfmt * style(fmt): rustfmt * refactor(panes): various cleanups * chore(deps): upgrade termwiz to get alt left-bracket * fix(assets): merge conflicts of binary files * style(fmt): rustfmt * style(clippy): no thank you! * chore(repo): remove garbage file
How to make |
You need to create swap layouts for your custom layout (or re-use the default ones) for this to work. Check out: https://zellij.dev/documentation/swap-layouts.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! This started out as me wanting to add the capability of applying layouts at runtime but it went a little bit off the rails.
There were a few pieces of infrastructure that needed to be laid down in order to do the above, which will happen in the next PR.
This PR however does include many exciting changes that I for one cannot wait to start using.
So what do we have here?
Swap Layouts
Swap layouts allow us to change the layout of the currently focused tab at runtime. They are built-in, but completely configurable just as the layouts are.
By default, we can rotate through these swap layouts with
Alt [
orAlt ]
(also configurable like all of our keybindings), gaining access to more layouts according to their constraints.I included 3 basic swap layouts (horizontal, vertical and stacked) for each one of our built-in layouts so the experience will be smooth out of the box with users not having to configure anything for this to "just work".
Swap layouts can also be applied (separately) to floating panes. If floating fanes are visible on screen and we switch a layout with
Alt [
orAlt ]
, the floating panes will be rearranged instead of the tiled panes. The built-in floating panes layouts are "staggered", "enlarged" and "spread".I added a piece of UI to both the status bar and the compact status bar that shows which layout we are currently in. In the status-bar it also shows the keybinding to switch the layout. It appears as soon as there is more than 1 selectable pane on screen (before that, it's not relevant).
auto_layout
Starting with this PR, panes opened with
Alt
+n
orCtrl p
+n
will be laid out according to the currently active swap_layout (if one is available). I feel this will significantly improve the experience, as they will both be laid out deterministically and be placed more comfortably on screen.When a pane is closed, the current swap_layout (if available) will reapply itself.
If a new pane is added and the current swap layout constraint does not fit (eg. the constraint is
max_panes=5
and this is pane number 6), Zellij will look for a different layout with a fitting constraint. This allows Zellij to progressively change its layout depending on how many panes are on screen.If the user performs an action that explicitly changes the layout (eg. resizing a pane or doing a horizontal/vertical split) the layout will be considered "dirty" and this behaviour will be suspended. Pressing
Alt
+[
orAlt
+]
in this case will reapply the current layout, allowing users to mess things around and then snap them back to a desired pre-set condition when they're ready.This behaviour can be disabled in the configuration by specifying
auto_layout false
.Configuration
Swap layouts can either be configured in the same file as regular layouts or in a separate
.swap.kdl
file in the same folder. (eg. if my layout is calledmy-cool-layout.kdl
, my swap layout file will be calledmy-cool-layout.swap.kdl
).Here's an example:
A
swap_tiled_layout
node can contain aname
field in its title (if present, this is the name that will be used in the UI to indicate the active layout). Its children are normal layouttab
nodes that can include all of the existing attributes of tab nodes in addition to aconstraint
node (more on these below) and achildren
node. If achildren
node is included in thetab
node, all new panes will be opened as logical children of said node.A
swap_floating_layout
is similar to aswap_tiled_layout
, only it cannot include achildren
node, and thefloating_panes
node is used as its swap unit instead of atab
node.When Zellij swaps layouts, it will progressively move through the
tab
orfloating_panes
nodes in the currently active layout, looking for the first one whose constraints match the current state of panes.Panes in swap layouts can include specific plugins or commands, but it's important to note that swap layouts will never open or close panes. Meaning if a command exists in the swap layout, Zellij will do its best effort to find a matching pane and place it in the right place, but it will not start this command. Same for plugins.
Swap layouts can also be
tab_templates
just like normal tiled or floating layouts can be. In order to save repetition when creating many similar swap layouts.Constraints
Currently there are two possible mutually exclusive constraints for layouts
max_panes
andmin_panes
. If there is demand, it is conceivable that in the future we'll add the ability for them to not be mutually exclusive, as well as add additional constraints (eg.min_screen_size
andmax_screen_size
to allow for responsive layouts).Stacked Panes
One of the swap layouts I included for all built-in layouts (default, compact and strider) is
stacked
. This swap layout includes a new Zellij capability, which is to stack panes. Stacked panes will show up as one liner panes - only rendering their title lines whether pane-frames are enabled or not - with one "flexible" pane which is the focused one. This flexible pane can be moved up or down and the stack will react accordingly.If stacked panes are command panes (meaning they were either opened with
pane command="htop"
or withzellij run -- htop
), their one-liner variety will also include theirEXIT CODE
, allowing us to easily throw a few long running tasks into a stack and visually gauge when they're done and if anything went wrong with them.Stacked panes can be configured in swap layouts as so:
Toggle pane location forwards/backwards
This PR also includes a minor fix to
move_pane
, allowing it to also work with floating panes. By default this isCtrl h
+n
and will move the currently focused pane around forwards or backwards. This PR also includes a new bindable actionMovePaneBackwards
, by defaultCtrl h
+p
to move the same pane backwards. In conjunction with the swaped layout and stacked panes features, this provides for quite a powerful experience!