From f3b3af84f8f751c88e6e25a016d16965c9d9e105 Mon Sep 17 00:00:00 2001 From: matthijs Date: Mon, 10 Jan 2022 20:57:42 +0100 Subject: [PATCH] Add goto position with certain dimension commands --- quicktile/__main__.py | 9 +++++++++ quicktile/commands.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/quicktile/__main__.py b/quicktile/__main__.py index 026b006..c1cadbf 100644 --- a/quicktile/__main__.py +++ b/quicktile/__main__.py @@ -359,6 +359,15 @@ def main() -> None: commands.cycle_dimensions = commands.commands.add_many( layout.make_winsplit_positions(config.getint('general', 'ColumnCount')) )(commands.cycle_dimensions) + + goto_commands = {} + for dim_dividend in range(1, config.getint('general', 'ColumnCount')+1): + for dim_divisor in range(1, config.getint('general', 'ColumnCount')+1): + for col in range(1, dim_divisor+1): + for addition, y_col in {'': None, '-top': 'top', '-bottom': 'bottom'}.items(): + goto_commands[f'goto-{dim_dividend}/{dim_divisor}-{col}{addition}'] = (dim_dividend, dim_divisor, col, y_col) + commands.goto_position_dimension = commands.commands.add_many(goto_commands)(commands.goto_position_dimension) + commands.commands.extra_state = {'config': config} GLib.log_set_handler('Wnck', GLib.LogLevelFlags.LEVEL_WARNING, diff --git a/quicktile/commands.py b/quicktile/commands.py index 44e91d6..105fef4 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -406,6 +406,45 @@ def move_to_position(winman: WindowManager, Wnck.WindowMoveResizeMask.Y) +def goto_position_dimension(winman: WindowManager, + win: Wnck.Window, + state: Dict[str, Any], + dim_dividend: int, + dim_divisor: int, + col: int, + y_col: str): + + """Move the active window to a position on the screen with a certain dimension + This is the same as the default position command which cycles throught, but without the cycling + + :param dim_dividend: The dividend indicating the width of the screen + :param dim_divisor: The divisor indicating the wicth of the screen + :param col: The number of the column in the grid + :param y_col: None if full, bottom for lower part, top for upper part + """ + + width = dim_dividend/dim_divisor + x = (1/dim_divisor)*(col-1) + y = 0.5 if y_col == 'bottom' else 0.0 + height = 0.5 if y_col else 1 + + monitor_rect = state['monitor_geom'] + dim = resolve_fractional_geom([x, y, width, height], monitor_rect) + + result = Rectangle(*dim).from_relative(monitor_rect) + # If we're overlapping a panel, fall back to a monitor-specific + # analogue to _NET_WORKAREA to prevent overlapping any panels and + # risking the WM potentially meddling with the result of resposition() + test_result = winman.usable_region.clip_to_usable_region(result) + if test_result != result: + result = test_result + logging.debug("Result exceeds usable (non-rectangular) region of " + "desktop. (overlapped a non-fullwidth panel?) Reducing " + "to within largest usable rectangle: %s", test_result) + + winman.reposition(win, result) + + @commands.add('bordered') def toggle_decorated( winman: WindowManager,