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: smarttile #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions quicktile/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,47 @@ def toggle_desktop(winman, win, state): # pylint: disable=unused-argument
target = not winman.screen.get_showing_desktop()
winman.screen.toggle_showing_desktop(target)

# pylint: disable=no-member
SMARTTILE_COMMANDS = {
'smarttile-top': [0, -1],
'smarttile-bottom': [0, 1],
'smarttile-left': [-1, 0],
'smarttile-right': [1, 0]
}
@commands.add_many(SMARTTILE_COMMANDS)
def smart_tile(winman, win, state, delta_x, delta_y): # pylint: disable=unused-argument
# type: (WindowManager, wnck.Window, Any, int,int) -> None
"""Smart window arrangement with only arrow keys. (Useful for laptops without keypad)"""
"""Move window on SmartTile grid by delta x and y:
1 2 3
4 5 6
7 8 9
5: state as it was before smart_tile started changing it
4: window fills left half of screen
2: window fills top half of screen
1: window fills top-left quarter of screen
Every time you try to move on a SmartTile out of the bounds of your screen, dimensions are cycled by cycle_dimensions.
"""
smarttiles = [
['top-left', 'top', 'top-right'],
['left', 'reset', 'right'],
['bottom-left', 'bottom', 'bottom-right']
]
columns = 3 # could be even more if there were a way to put windows in specific rows
winpos = winman.get_property('_SMARTTILE_WIN_POS', win) # position in SmartTile grid
if not winpos: # smarttile was never called on this window yet
winman.set_property('_SMARTTILE_WIN_INIT_POS', win.get_geometry(), win) # initial pos to return to
winpos = [None, None, (1, 1)]
(x, y) = winpos[2]
if 0 <= x + delta_x < columns and 0 <= y + delta_y < 3: # if not over-/underflow
x += delta_x
y += delta_y
winman.set_property('_SMARTTILE_WIN_POS', (x, y), win)
if smarttiles[y][x] == 'reset':
winman.reposition(win, gtk.gdk.Rectangle(*winman.get_property('_SMARTTILE_WIN_INIT_POS', win)[2]))
else:
commands.call(smarttiles[y][x], winman)

@commands.add('all-desktops', 'pin', 'is_pinned')
@commands.add('fullscreen', 'set_fullscreen', 'is_fullscreen', True)
@commands.add('vertical-maximize', 'maximize_vertically',
Expand Down