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

Adds some snap helpers to split windows to the left in various ways #1465

Open
wants to merge 15 commits into
base: main
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
2 changes: 2 additions & 0 deletions core/windows_and_tabs/window_management.talon
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ snap last [screen]: user.move_window_previous_screen()
snap screen <number>: user.move_window_to_screen(number)
snap <user.running_applications> <user.window_snap_position>:
user.snap_app(running_applications, window_snap_position)
snap <user.window_split_position> <user.running_applications> <user.running_applications>+:
user.snap_layout(window_split_position, running_applications_list)
snap <user.running_applications> [screen] <number>:
user.move_app_to_screen(running_applications, number)
55 changes: 54 additions & 1 deletion core/windows_and_tabs/window_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# platforms

import logging
from typing import Optional
from typing import Dict, Optional

from talon import Context, Module, actions, settings, ui

Expand All @@ -17,6 +17,10 @@
"window_snap_positions",
"Predefined window positions for the current window. See `RelativeScreenPos`.",
)
mod.list(
"window_split_positions",
"Predefined window positions when splitting the screen between three applications.",
)
mod.setting(
"window_snap_screen",
type=str,
Expand Down Expand Up @@ -272,14 +276,47 @@ def __init__(self, left, top, right, bottom):
"fullscreen": RelativeScreenPos(0, 0, 1, 1),
}

_split_positions = {
"split": {
2: [_snap_positions["left"], _snap_positions["right"]],
3: [
_snap_positions["left third"],
_snap_positions["center third"],
_snap_positions["right third"],
],
},
"clock": {
2: [_snap_positions["left"], _snap_positions["right"]],
3: [
_snap_positions["left"],
_snap_positions["top right"],
_snap_positions["bottom right"],
],
},
"counterclock": {
2: [_snap_positions["left"], _snap_positions["right"]],
3: [
_snap_positions["right"],
_snap_positions["top left"],
_snap_positions["bottom left"],
],
},
}


@mod.capture(rule="{user.window_snap_positions}")
def window_snap_position(m) -> RelativeScreenPos:
return _snap_positions[m.window_snap_positions]


@mod.capture(rule="{user.window_split_positions}")
def window_split_position(m) -> Dict[int, list[RelativeScreenPos]]:
return _split_positions[m.window_split_positions]


ctx = Context()
ctx.lists["user.window_snap_positions"] = _snap_positions.keys()
ctx.lists["user.window_split_positions"] = _split_positions.keys()


@mod.action_class
Expand Down Expand Up @@ -310,6 +347,22 @@ def snap_app(app_name: str, position: RelativeScreenPos):
_bring_forward(window)
_snap_window_helper(window, position)

def snap_layout(
positions_by_count: Dict[int, list[RelativeScreenPos]],
apps: list[str],
):
"""Split the screen between multiple applications."""
try:
positions = positions_by_count[len(apps)]
except KeyError:
raise NotImplementedError(
f"There is no such layout yet defined for {len(apps)} items"
)
for index, app in enumerate(apps):
window = _get_app_window(app)
_snap_window_helper(window, positions[index])
window.focus()

def move_app_to_screen(app_name: str, screen_number: int):
"""Move a specific application to another screen."""
window = _get_app_window(app_name)
Expand Down