From 46470e819e8a501cf705d0bca848aee36e8c6506 Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Sun, 20 Aug 2017 21:47:58 -0400 Subject: [PATCH] Implement basic monitor-prev/next-all commands Fixes #37 --- ChangeLog | 1 + quicktile/commands.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/ChangeLog b/ChangeLog index 63db29b..1038dcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ - Split QuickTile up into multiple files for easier refactoring and improvement - Fix a few latent WindowManager bugs revealed by the split-up. - Add a `ColumnCount` field to the config file +- Add `monitor-prev-all` and `monitor-next-all` commands - Add gtkexcepthook for more convenient handling of unexpected errors - Work around PyGTK's incompatibilty with tox diff --git a/quicktile/commands.py b/quicktile/commands.py index b62d758..e126df7 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -236,6 +236,40 @@ def cycle_monitors(winman, win, state, step=1): winman.reposition(win, None, new_mon_geom, keep_maximize=True) +@commands.add('monitor-prev-all', -1) +@commands.add('monitor-next-all', 1) +def cycle_monitors_all(winman, win, state, step=1): + """Cycle all windows between monitors while preserving position.""" + n_monitors = winman.gdk_screen.get_n_monitors() + curr_workspace = win.get_workspace() + + if not curr_workspace: + logging.debug("get_workspace() returned None") + return + + for window in winman.screen.get_windows(): + # Skip windows on other virtual desktops for intuitiveness + if not window.is_on_workspace(curr_workspace): + logging.debug("Skipping window on other workspace") + continue + + # Don't cycle elements of the desktop + if window.get_window_type() in [ + wnck.WINDOW_DESKTOP, wnck.WINDOW_DOCK]: # pylint: disable=E1101 + logging.debug("Skipping desktop/dock window") + continue + + gdkwin = gtk.gdk.window_foreign_new(window.get_xid()) + mon_id = winman.gdk_screen.get_monitor_at_window(gdkwin) + new_mon_id = (mon_id + step) % n_monitors + + new_mon_geom = winman.gdk_screen.get_monitor_geometry(new_mon_id) + logging.debug( + "Moving window %s to monitor 0x%d, which has geometry %s", + hex(window.get_xid()), new_mon_id, new_mon_geom) + + winman.reposition(window, None, new_mon_geom, keep_maximize=True) + # pylint: disable=no-member MOVE_TO_COMMANDS = { 'move-to-top-left': [wnck.WINDOW_GRAVITY_NORTHWEST,