From 6093d8aea17e5c0fb14959f4b1ede4931e58667c Mon Sep 17 00:00:00 2001 From: Ivan Héda Date: Mon, 12 Feb 2018 23:31:55 +0100 Subject: Code cleaning. --- move-to-next-monitor | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/move-to-next-monitor b/move-to-next-monitor index 33affce..1676cc4 100755 --- a/move-to-next-monitor +++ b/move-to-next-monitor @@ -15,12 +15,15 @@ VERTICAL_FIRST = (3, 2) display_coordinates_split = re.compile('[x+]') -def get_display_positions(): +def get_displays(horizontal_first_sorting=False): + sorting = HORIZONTAL_FIRST if horizontal_first_sorting else VERTICAL_FIRST + displays = [] for x in execute('xrandr'): split = x.split(' ') if 'connected' in split: position = [display_coordinates_split.split(t) for t in split if t != 'primary'][2] - yield [int(x) for x in position] + displays.append([int(x) for x in position]) + return sorted(displays, key=lambda x: [x[i] for i in sorting]) def get_active_window_id(): @@ -101,25 +104,15 @@ def new_window_position(window_id, displays, step=1): return xrel * nwidth + nwoffset, yrel * nheight + nhoffset -def move_to_next_monitor(window_id, displays, step=1): +def move_to_next_monitor(window_id, displays, reverse=False): state = get_window_state(window_id) unmaximize(window_id) - xnew, ynew = new_window_position(window_id, displays, step) + xnew, ynew = new_window_position(window_id, displays, step=-1 if reverse else 1) execute('xdotool windowmove %s %s %s' % (window_id, xnew, ynew)) set_window_state(window_id, state) if __name__ == '__main__': - if '--horizontal-first' in sys.argv: - sorting = HORIZONTAL_FIRST - else: - sorting = VERTICAL_FIRST - - displays = sorted(get_display_positions(), key=lambda x: [x[i] for i in sorting]) - + displays = get_displays('--horizontal-first' in sys.argv) if len(displays) > 1: - if '--reverse' in sys.argv: - step = -1 - else: - step = 1 - move_to_next_monitor(get_active_window_id(), displays, step) + move_to_next_monitor(get_active_window_id(), displays, '--reverse' in sys.argv) -- cgit