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:
>>> 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 togravity
.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
andy
values, it will compute a geometry tuple which will align a windoww
wide andh
tall according togeometry
.2. If called with
x
andy
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:
- Return type:
- 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:
- 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)]}
- resolve_fractional_geom(fract_geom, monitor_rect)[source]¶
Resolve proportional (eg.
0.5
) coordinates.- Parameters:
fract_geom (
Union
[Tuple
[float
,float
,float
,float
],Rectangle
]) – An(x, y, w, h)
tuple containing monitor-relative values in the range from 0.0 to 1.0, inclusive, or aquicktile.util.Rectangle
which will be passed through without modification.monitor_rect (
Rectangle
) – Aquicktile.util.Rectangle
defining the bounding box of the monitor (or other desired region) within the desktop.
- Return type:
- 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)