toggle_layout action to zoom/unzoom active window

This commit is contained in:
Kovid Goyal
2021-07-01 17:57:00 +05:30
parent 6a4668974b
commit 050c31094b
5 changed files with 27 additions and 2 deletions

View File

@@ -7,6 +7,8 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
0.21.3 [future] 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 - 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 could cause incorrect parsing if either the pending buffer capacity or the
pending timeout were exceeded (:iss:`3779`) pending timeout were exceeded (:iss:`3779`)

View File

@@ -103,7 +103,8 @@ terminal program, you can tell the kittens system to run the
``handle_result()`` function without first running the ``main()`` function. ``handle_result()`` function without first running the ``main()`` function.
For example, here is a kitten that "zooms/unzooms" the current terminal window 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` Create a file in the kitty config folder, :file:`~/.config/kitty/zoom_toggle.py`

View File

@@ -3125,6 +3125,13 @@ You can also create shortcuts to switch to specific layouts::
Similarly, to switch back to the previous layout:: Similarly, to switch back to the previous layout::
map ctrl+alt+p last_used_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
''') # }}} ''') # }}}

View File

@@ -116,7 +116,7 @@ def detach_tab_parse(func: str, rest: str) -> FuncArgsType:
return func, (rest,) 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: def simple_parse(func: str, rest: str) -> FuncArgsType:
return func, [rest] return func, [rest]

View File

@@ -258,6 +258,21 @@ class Tab: # {{{
self._set_current_layout(layout_name) self._set_current_layout(layout_name)
self.relayout() 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]: 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 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): if self.current_layout.modify_size_of_window(self.windows, window_id, increment_as_percent, is_horizontal):