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 (int) – Horizontal margin to apply when calculating window positions, as decimal percentage of screen width.

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

GRAVITIES: Dict[str, Gravity] = {'bottom': <Gravity.BOTTOM: (0.5, 1.0)>, 'bottom-left': <Gravity.BOTTOM_LEFT: (0.0, 1.0)>, 'bottom-right': <Gravity.BOTTOM_RIGHT: (1.0, 1.0)>, 'center': <Gravity.CENTER: (0.5, 0.5)>, 'left': <Gravity.LEFT: (0.0, 0.5)>, 'right': <Gravity.RIGHT: (1.0, 0.5)>, 'top': <Gravity.TOP: (0.5, 0.0)>, 'top-left': <Gravity.TOP_LEFT: (0.0, 0.0)>, 'top-right': <Gravity.TOP_RIGHT: (1.0, 0.0)>}

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.

check_tolerance(distance, monitor_geom, tolerance=0.1)[source]
Check whether a distance is within a tolerance value calculated as a

percentage of a monitor’s size.

Parameters
  • distance (int) – A distance in pixels.

  • monitor_geom (Rectangle) – A Rectangle representing the monitor geometry.

  • tolerance (float) – A value between 0.0 and 1.0, inclusive, which represents a percentage of the monitor size.

Note

This is not currently in use but is retained for when future plans make it necessary to design reliable “invalidate cached data if the window was repositioned/resized without QuickTile” code.

Return type

float

make_winsplit_positions(columns)[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.

Parameters

columns (int) –

resolve_fractional_geom(fract_geom, monitor_rect)[source]

Resolve proportional (eg. 0.5) and preserved (None) coordinates.

Parameters
Return type

Rectangle

Returns

A rectangle with absolute coordinates derived from monitor_rect.