diff options
author | Ivan Héda <ivan.heda@gmail.com> | 2018-02-12 23:31:55 +0100 |
---|---|---|
committer | Ivan Héda <ivan.heda@gmail.com> | 2018-02-12 23:31:55 +0100 |
commit | 6093d8aea17e5c0fb14959f4b1ede4931e58667c (patch) | |
tree | de7a4fb4ebad9c267bfdf70a7eab2100d48efe5a | |
parent | Rewritten to python. Displays are arranged into list (diff) | |
download | move-to-next-monitor-6093d8aea17e5c0fb14959f4b1ede4931e58667c.tar.gz move-to-next-monitor-6093d8aea17e5c0fb14959f4b1ede4931e58667c.tar.bz2 move-to-next-monitor-6093d8aea17e5c0fb14959f4b1ede4931e58667c.zip |
Code cleaning.
-rwxr-xr-x | move-to-next-monitor | 25 |
1 files 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) |