Question

i'm trying to develop a python application that allow to move windows between gnome workspace. I' m using wnck to interact with windows, but i'd like to know how can i move a window from a workspace to another. Anyone can suggests me a way?

I tried with following code

screen = wnck.screen_get_default()
window_list = screen.get_windows()
titlePattern = re.compile('.*Downloads.*')
    if len(window_list) == 0:
        print "No Windows Found"
    for win in window_list:
        if(titlePattern.match(win.get_name())):
            win.move_to_workspace(screen.get_workspace(2))

but screen.get_workspace(2) return 'None', while it works (but it doesn't move the window!) if i use screen.get_workspace(0) as move_to_workspace parameter.

Can i solve my problem?

Thank you in advance to all.

Was it helpful?

Solution

Your window manager simply doesn't have workspace 2 when you call screen.get_workspace(2).

Your code should work for all workspaces that actually exist. In GNOME 3 that means all workspaces that already have windows plus one empty workspace. This means that screen.get_workspace(screen.get_workspace_count() - 1) should give you the "empty" workspace, if that was what you were looking for. Note that there's no spec that says the last workspace is empy, it's just what gnome-shell currently happens to do.

You can also ask the window manager to increase the number of workspaces on the screen, but it is under no obligation to do so: the GNOME 3 window manager will not do it.

Oh, and one thing to remember about Wnck:

At its creation, a WnckScreen object will not have fetched information from the X server. If queried immediately after its creation (via wnck_screen_get_windows() or wnck_screen_get_workspaces(), for example), the WnckScreen object will look like there are no workspaces nor windows on the screen. This information is fetched in the main event loop with an idle source, to avoid an expensive synchronous operation on startup. If no main event loop is used, or if the information is needed as soon as possible after the creation of the object, wnck_screen_force_update() can be used to explicitly fetch the information.

I don't think this is your problem (as you have a list of windows already), but I'm just double-checking as it's a nasty pitfall.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top