Skip to content

Spiral

Spiral(**config)

Bases: _SimpleLayoutBase

A mathematical layout.

Renders windows in a spiral form by splitting the screen based on a selected ratio. The direction of the split is changed every time in a defined order resulting in a spiral formation.

The main window can be sized with lazy.layout.grow_main() and lazy.layout.shrink_main(). All other windows are sized by lazy.layout.increase_ratio() and lazy.layout.decrease_ratio().

NB if main_pane_ratio is not set then it will also be adjusted according to ratio. However, as soon shrink_main() or grow_main() have been called once then the master pane will only change size following further calls to those methods.

Users are able to choose the location of the main (i.e. largest) pane and the direction of the rotation.

Some examples:

main_pane="left", clockwise=True

----------------------
|1        |2         |
|         |          |
|         |          |
|         |----------|
|         |5 |6 |3   |
|         |-----|    |
|         |4    |    |
----------------------

main_pane="top", clockwise=False

----------------------
|1                   |
|                    |
|                    |
|--------------------|
|2        |5    |4   |
|         |----------|
|         |3         |
----------------------

Methods:

  • add_client

    Called whenever a window is added to the group.

  • add_defaults

    Add defaults to this object, overwriting any which already exist.

  • blur

    Called whenever focus is gone from this layout.

  • clone

    Duplicate a layout.

  • command

    Return the command with the given name.

  • commands

    Returns a list of possible commands for this object.

  • configure

    Configure the layout.

  • decrease_ratio

    Decrease spiral ratio.

  • doc

    Returns the documentation for a specified command name.

  • eval

    Evaluates code in the same context as this function.

  • focus

    Called whenever the focus changes.

  • focus_first

    Called when the first client in Layout shall be focused.

  • focus_last

    Called when the last client in Layout shall be focused.

  • focus_next

    Called when the next client in Layout shall be focused.

  • focus_previous

    Called when the previous client in Layout shall be focused.

  • function

    Call a function with current object as argument.

  • get_spiral

    Calculates positions of windows in the spiral.

  • grow_main

    Grow the main window.

  • has_invalid_size

    Checks if window would have an invalid size.

  • hide

    Called when layout is being hidden.

  • increase_ratio

    Increase spiral ratio.

  • info

    Returns a dictionary of layout information.

  • items

    Build a list of contained items for the given item class.

  • remove

    Called whenever a window is removed from the group.

  • reset

    Reset ratios to values set in config.

  • select

    Return a selected object.

  • set_master_ratio

    Set the ratio for the main window.

  • set_ratio

    Set the ratio for all windows.

  • show

    Called when layout is being shown.

  • shrink_main

    Shrink the main window.

  • swap

    Swap the two given clients c1 and c2.

Attributes:

  • group (_Group) –

    Returns the group this layout is attached to.

group property

group: _Group

Returns the group this layout is attached to.

Layouts start out unattached, and are attached when the group is configured and each layout is cloned for every group.

add_client

add_client(client: Window) -> None

Called whenever a window is added to the group.

Called whether the layout is current or not. The layout should just add the window to its internal datastructures, without mapping or configuring.

add_defaults

add_defaults(defaults)

Add defaults to this object, overwriting any which already exist.

blur

blur() -> None

Called whenever focus is gone from this layout.

clone

clone(group: _Group) -> Self

Duplicate a layout.

Make a copy of this layout. This is done to provide each group with a unique instance of every layout.

Parameters:

  • group (_Group) –

    Group to attach new layout instance to.

command

command(name: str) -> Callable | None

Return the command with the given name.

Parameters:

  • name (str) –

    The name of the command to fetch.

commands

commands() -> list[str]

Returns a list of possible commands for this object.

Used by qsh for command completion and online help

configure

configure(win, screen)

Configure the layout.

This method should:

  • Configure the dimensions and borders of a window using the .place() method.
  • Call either .hide() or .unhide() on the window.

decrease_ratio

decrease_ratio()

Decrease spiral ratio.

doc

doc(name) -> str

Returns the documentation for a specified command name.

Used by qsh to provide online help.

eval

eval(code: str) -> tuple[bool, str | None]

Evaluates code in the same context as this function.

Return value is tuple (success, result), success being a boolean and result being a string representing the return value of eval, or None if exec was used instead.

focus

focus(client: Window) -> None

Called whenever the focus changes.

focus_first

focus_first() -> Window | None

Called when the first client in Layout shall be focused.

This method should:

  • Return the first client in Layout, if any.
  • Not focus the client itself, this is done by caller.

focus_last

focus_last() -> Window | None

Called when the last client in Layout shall be focused.

This method should:

  • Return the last client in Layout, if any.
  • Not focus the client itself, this is done by caller.

focus_next

focus_next(window: Window) -> Window | None

Called when the next client in Layout shall be focused.

This method should:

  • Return the next client in Layout, if any.
  • Return None if the next client would be the first client.
  • Not focus the client itself, this is done by caller.

Do not implement a full cycle here, because the Groups cycling relies on returning None here if the end of Layout is hit, such that Floating clients are included in cycle.

Parameters:

  • win (Window) –

    The currently focused client.

focus_previous

focus_previous(window: Window) -> Window | None

Called when the previous client in Layout shall be focused.

This method should:

  • Return the previous client in Layout, if any.
  • Return None if the previous client would be the last client.
  • Not focus the client itself, this is done by caller.

Do not implement a full cycle here, because the Groups cycling relies on returning None here if the end of Layout is hit, such that Floating clients are included in cycle.

Parameters:

  • win (Window) –

    The currently focused client.

function

function(function, *args, **kwargs) -> None

Call a function with current object as argument.

get_spiral

get_spiral(x, y, width, height) -> list[Rect]

Calculates positions of windows in the spiral.

Returns a list of tuples (x, y, w, h) for positioning windows.

grow_main

grow_main()

Grow the main window.

has_invalid_size

has_invalid_size(win: Rect) -> bool

Checks if window would have an invalid size.

A window that would have negative height or width (after adjusting for margins and borders) will return True.

hide

hide() -> None

Called when layout is being hidden.

increase_ratio

increase_ratio()

Increase spiral ratio.

info

info() -> dict[str, Any]

Returns a dictionary of layout information.

items

items(name: str) -> tuple[bool, list[str | int] | None]

Build a list of contained items for the given item class.

Exposing this allows qsh to navigate the command graph.

Returns a tuple (root, items) for the specified item class, where:

root: True if this class accepts a "naked" specification without an
item seletion (e.g. "layout" defaults to current layout), and False
if it does not (e.g. no default "widget").

items: a list of contained items

remove

remove(w: Window) -> Window | None

Called whenever a window is removed from the group.

Called whether the layout is current or not. The layout should just de-register the window from its data structures, without unmapping the window.

Returns the "next" window that should gain focus or None.

reset

reset()

Reset ratios to values set in config.

select

select(selectors: list[SelectorType]) -> CommandObject

Return a selected object.

Recursively finds an object specified by a list of (name, selector) items.

Raises SelectError if the object does not exist.

set_master_ratio

set_master_ratio(ratio: float)

Set the ratio for the main window.

set_ratio

set_ratio(ratio: float)

Set the ratio for all windows.

show

show(screen_rect: ScreenRect) -> None

Called when layout is being shown.

shrink_main

shrink_main()

Shrink the main window.

swap

swap(window1: Window, window2: Window) -> None

Swap the two given clients c1 and c2.