Skip to content

Commit

Permalink
Implement basic monitor-prev/next-all commands
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
Stephan Sokolow authored and Stephan Sokolow committed Aug 21, 2017
1 parent 3818580 commit 67e0308
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions quicktile/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 67e0308

Please sign in to comment.