diff --git a/docs/changelog.rst b/docs/changelog.rst index c9a5764ff..0cc79e734 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,8 @@ To update |kitty|, :doc:`follow the instructions `. 0.21.3 [future] ---------------------- +- Add a new :ref:`action-toggle_layout` action to easily zoom/unzoom a window + - Fix a bug in the implementation of the synchronized updates escape code that could cause incorrect parsing if either the pending buffer capacity or the pending timeout were exceeded (:iss:`3779`) diff --git a/docs/kittens/custom.rst b/docs/kittens/custom.rst index 9c2758d98..2fa2b209a 100644 --- a/docs/kittens/custom.rst +++ b/docs/kittens/custom.rst @@ -103,7 +103,8 @@ terminal program, you can tell the kittens system to run the ``handle_result()`` function without first running the ``main()`` function. For example, here is a kitten that "zooms/unzooms" the current terminal window -by switching to the stack layout or back to the previous layout. +by switching to the stack layout or back to the previous layout. This is +equivalent to the builtin :ref:`action-toggle_layout` action. Create a file in the kitty config folder, :file:`~/.config/kitty/zoom_toggle.py` diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 8dfbbed5a..472969aad 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -3125,6 +3125,13 @@ You can also create shortcuts to switch to specific layouts:: Similarly, to switch back to the previous layout:: map ctrl+alt+p last_used_layout + +There is also a toggle layout function that switches +to the named layout or back to the previous layout if +in the named layout. Useful to temporarily "zoom" the +active window by switching to the stack layout:: + + map ctrl+alt+z toggle_layout stack ''') # }}} diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 5f20390d1..1dd67ecec 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -116,7 +116,7 @@ def detach_tab_parse(func: str, rest: str) -> FuncArgsType: return func, (rest,) -@func_with_args('set_background_opacity', 'goto_layout', 'kitty_shell') +@func_with_args('set_background_opacity', 'goto_layout', 'toggle_layout', 'kitty_shell') def simple_parse(func: str, rest: str) -> FuncArgsType: return func, [rest] diff --git a/kitty/tabs.py b/kitty/tabs.py index a992af4bb..0026bcd70 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -258,6 +258,21 @@ class Tab: # {{{ self._set_current_layout(layout_name) self.relayout() + def toggle_layout(self, layout_name: str) -> None: + ''' + @ac:lay: Toggle the named layout + + Switches to the named layout if another layout is current, otherwise + switches to the last used layout. Useful to "zoom" a window temporarily + by switching to the stack layout. For example:: + + map f1 toggle_layout stack + ''' + if self._current_layout_name == layout_name: + self.last_used_layout() + else: + self.goto_layout(layout_name) + def resize_window_by(self, window_id: int, increment: float, is_horizontal: bool) -> Optional[str]: increment_as_percent = self.current_layout.bias_increment_for_cell(is_horizontal) * increment if self.current_layout.modify_size_of_window(self.windows, window_id, increment_as_percent, is_horizontal):