Layout Calculations (layout.py)

Layout calculation code

class GravityLayout(margin_x=0, margin_y=0)[source]

Helper for translating top-left relative dimensions to other corners.

Used to generate quicktile.commands.cycle_dimensions() presets.

Expects to operate on decimal percentage values. (0 ≤ x ≤ 1)

Parameters:
  • margin_x (float) – Horizontal margin to apply when calculating window positions, as decimal percentage of screen width.

  • margin_y (float) – Vertical margin to apply when calculating window positions, as decimal percentage of screen height.

>>> layout = GravityLayout()
>>> layout(0.5, 0.5)
(0.0, 0.0, 0.5, 0.5)
>>> layout(0.5, 0.5, 'bottom-right')
(0.5, 0.5, 0.5, 0.5)
>>> layout(0.5, 0.5, 'center')
(0.25, 0.25, 0.5, 0.5)
>>> layout(0.5, 0.5, x=0.2, y=0.2)
(0.2, 0.2, 0.5, 0.5)

>>> layout(0.5, 0.5, 'center', x=0.25, y=0.25)
(0.0, 0.0, 0.5, 0.5)

>>> layout = GravityLayout(0.01, 0.02)
>>> layout(0.5, 0.5)
(0.01, 0.02, 0.48, 0.46)
>>> layout(0.5, 0.5, 'bottom-right')
(0.51, 0.52, 0.48, 0.46)
>>> layout(0.5, 0.5, 'center')
(0.26, 0.27, 0.48, 0.46)
>>> layout(0.5, 0.5, x=0.2, y=0.2)
(0.21, 0.22, 0.48, 0.46)

>>> layout(0.5, 0.5, 'center', x=0.25, y=0.25)
(0.01, 0.02, 0.48, 0.46)
GRAVITIES: Dict[str, Gravity] = {'bottom': Gravity.BOTTOM, 'bottom-left': Gravity.BOTTOM_LEFT, 'bottom-right': Gravity.BOTTOM_RIGHT, 'center': Gravity.CENTER, 'left': Gravity.LEFT, 'right': Gravity.RIGHT, 'top': Gravity.TOP, 'top-left': Gravity.TOP_LEFT, 'top-right': Gravity.TOP_RIGHT}

A mapping of possible window alignments relative to the monitor/desktop as a mapping from formerly manually specified command names to values the quicktile.util.Gravity enum can take on.

__call__(width, height, gravity='top-left', x=None, y=None)[source]

Return a relative (x, y, w, h) tuple relative to gravity.

This function takes and returns percentages, represented as decimals in the range 0 x 1, which can be multiplied by width and height values in actual units to produce actual window geometry.

It can be used in two ways:

1. If called without x and y values, it will compute a geometry tuple which will align a window w wide and h tall according to geometry.

2. If called with x and y values, it will translate a geometry tuple which is relative to the top-left corner so that it is instead relative to another corner.

Parameters:
  • width (float) – Desired width as a decimal-form percentage

  • height (float) – Desired height as a decimal-form percentage

  • gravity (str) – Desired window alignment from GRAVITIES

  • x (Optional[float]) – Desired horizontal position if not the same as gravity

  • y (Optional[float]) – Desired vertical position if not the same as gravity

Return type:

Tuple[float, float, float, float]

Returns:

(x, y, w, h) with all values represented as decimal-form percentages.

make_winsplit_positions(columns, margin_x=0, margin_y=0)[source]

Generate the classic WinSplit Revolution tiling presets

Params columns:

The number of columns that each tiling preset should be built around.

Return type:

Dict[str, List[Tuple[float, float, float, float]]]

Returns:

A dict of presets ready to feed into quicktile.commands.CommandRegistry.add_many().

See ColumnCount in the configuration section of the manual for further details.

>>> from pprint import pprint
>>> pprint(make_winsplit_positions(2))
{'bottom': [(0.0, 0.5, 1.0, 0.5), (0.25, 0.5, 0.5, 0.5)],
'bottom-left': [(0.0, 0.5, 0.5, 0.5), (0.0, 0.5, 0.5, 0.5)],
'bottom-right': [(0.5, 0.5, 0.5, 0.5), (0.5, 0.5, 0.5, 0.5)],
'center': [(0.0, 0.0, 1.0, 1), (0.25, 0.0, 0.5, 1)],
'left': [(0.0, 0.0, 0.5, 1), (0.0, 0.0, 0.5, 1)],
'right': [(0.5, 0.0, 0.5, 1), (0.5, 0.0, 0.5, 1)],
'top': [(0.0, 0.0, 1.0, 0.5), (0.25, 0.0, 0.5, 0.5)],
'top-left': [(0.0, 0.0, 0.5, 0.5), (0.0, 0.0, 0.5, 0.5)],
'top-right': [(0.5, 0.0, 0.5, 0.5), (0.5, 0.0, 0.5, 0.5)]}
Parameters:
resolve_fractional_geom(fract_geom, monitor_rect)[source]

Resolve proportional (eg. 0.5) coordinates.

Parameters:
Return type:

Rectangle

Returns:

A rectangle with absolute coordinates derived from monitor_rect.

>>> resolve_fractional_geom(Rectangle(0, 1, 2, 3),
...                         Rectangle(1280, 0, 1280, 1024))
Rectangle(x=0, y=1, width=2, height=3)
>>> resolve_fractional_geom((0.5, 0.5, 0.5, 0.5),
...                         Rectangle(0, 0, 1280, 1024))
Rectangle(x=640, y=512, width=640, height=512)
>>> resolve_fractional_geom((0.5, 0.5, 0.5, 0.5),
...                         Rectangle(400, 500, 1280, 1024))
Rectangle(x=640, y=512, width=640, height=512)