From e994b394cf707078ba443549faeaad1e0a125fed Mon Sep 17 00:00:00 2001 From: pogobanane Date: Tue, 3 Jul 2018 18:50:27 +0200 Subject: [PATCH 1/2] add smart window tiling --- quicktile/commands.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/quicktile/commands.py b/quicktile/commands.py index 1b8163c..c7ee3f1 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -355,6 +355,43 @@ 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 + 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) + 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', From b6d55963ef0680548d878607fdb6a30abb29960e Mon Sep 17 00:00:00 2001 From: pogobanane Date: Tue, 3 Jul 2018 19:48:23 +0200 Subject: [PATCH 2/2] save previous win-pos for reset --- quicktile/commands.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/quicktile/commands.py b/quicktile/commands.py index c7ee3f1..7194173 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -384,13 +384,17 @@ def smart_tile(winman, win, state, delta_x, delta_y): # pylint: disable=unused-a 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) - commands.call(smarttiles[y][x], winman) + 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)