Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to goto certain position #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions quicktile/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
39 changes: 39 additions & 0 deletions quicktile/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down