Over a million developers have joined DZone.

Swap All Windows Between Two Workspaces In XFCE4

DZone's Guide to

Swap All Windows Between Two Workspaces In XFCE4

· ·
Free Resource

Swap all windows between two workspaces in XFCE4.
Depends: pygtk, pyxfce4
Author: Arnau Sanchez 

>>> import swap_workspaces as sw
>>> sw.swap_workspaces(1, 3)


$ swap_workspaces 1 3
import xfce4.netk
import gtk
import sys

def refresh_gui():
    """Process all GTK pending events without blocking.""" 
    while gtk.events_pending():

def get_windows_for_workspace(screen, number):
    """Get windows for a given workspace number."""    
    for window in screen.get_windows():
        workspace = window.get_workspace()
        if workspace and workspace.get_number() == number:
            yield window

def swap_workspaces(wsn1, wsn2):            
    """Swap all windows between two workspaces."""
    screen = xfce4.netk.screen_get_default()
    workspaces = screen.get_workspaces()
    assert 0 <= wsn1 < len(workspaces)
    assert 0 <= wsn2 < len(workspaces)
    windows1 = list(get_windows_for_workspace(screen, wsn1))
    windows2 = list(get_windows_for_workspace(screen, wsn2))
    for window in windows1:
    for window in windows2:
    return len(windows1), len(windows2)

def main(args):
    """Swap workspaces windows. Workspaces index 0..N-1"""
    ws1, ws2 = map(int, args)
    print swap_workspaces(ws1, ws2)
if __name__ == '__main__':


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}