def switch(self, i, target): # we have to be on workspace 0 or else it's confusing to user if xlib.get_current_desktop(self.display) != 0: # TODO maybe switch to workspace 0? it might be confusing too #xlib.set_current_desktop(self.display, 0) return self.update() if i>0 and len(self.screens) != 2: # unsupported return elif i>0 and self.screens[0].x == self.screens[1].x: # same offset return # save focus win = xlib.get_active_window(self.display) try: if xlib.get_desktop(self.display, win) == 0: # this rules out 0xffffffff self.focus[i][self.loaded[i]] = win except error.BadWindow: pass if target == self.loaded[i]: if self.history[i] != None: # swap back to previous workspace target = self.history[i] self.history[i] = self.loaded[i] else: # nowhere to switch, it's already loaded return else: # just update history self.history[i] = self.loaded[i] # save active workspace for win in self.workspaces[0]: if win.d == i: xlib.set_desktop(self.display, win.id, self.loaded[i]) # load target workspace for win in self.workspaces[target]: if win.d == i: xlib.set_desktop(self.display, win.id, 0) self.loaded[i] = target self.display.sync() self.save() # load focus win = self.focus[i][target] if win: # we have to wait for the windows to be moved sleep(0.01) xlib.set_active_window(self.display, win) self.display.sync()
def switch(self, i, target): # we have to be on workspace 0 or else it's confusing to user if xlib.get_current_desktop(self.display) != 0: xlib.set_current_desktop(self.display, 0) self.update() # are we trying to switch non-existing screen? if i >= len(self.screens): return # TODO should work for more displays, i can't test it # TODO even with mirrored if get_screens leaves them out if i>0: # screens are sorted by x, this will return if there is mirrored for j in xrange(1, len(self.screens)): if self.screens[j-1].x == self.screens[j].x: # same offset return if self.loaded[i] == None: # nothing is loaded pass else: # save focus win = xlib.get_active_window(self.display) try: if xlib.get_desktop(self.display, win) == 0: # this rules out 0xffffffff self.focus[0][self.loaded[i]] = win except error.BadWindow: pass if target == self.loaded[i]: if self.history[i] != None: # swap back to previous workspace target = self.history[i] self.history[i] = self.loaded[i] else: # nowhere to switch, it's already loaded return else: # just update history # if we still have initial value, ignore if self.loaded[i] != 0: self.history[i] = self.loaded[i] try: # already loaded elsewhere (it can't be us) where = self.loaded.index(target) # don't do just swap(), swap arbitrary display numbers self.swap_displays(i, 0, where, 0) self.loaded[where] = self.loaded[i] self.loaded[i] = target return except ValueError: # continue pass # save (we use whole workspace on display 0 for storing windows) for win in self.workspaces[0]: if win.d == i: xlib.set_desktop(self.display, win.id, self.loaded[i]) # move window, we changed displays if win.d != 0: relx = win.x - self.screens[i].x rely = win.y - self.screens[i].y x = self.screens[0].x + relx - (2*win.xrel) y = self.screens[0].y + rely - (2*win.yrel) xlib.moveresize(self.display, win.id, x, y) # load workspace for win in self.workspaces[target]: # we are using screen 0, ignore windows outside if win.d == 0: xlib.set_desktop(self.display, win.id, 0) # move window, we changed displays if win.d != i: relx = win.x - self.screens[0].x rely = win.y - self.screens[0].y x = self.screens[i].x + relx - (2*win.xrel) y = self.screens[i].y + rely - (2*win.yrel) xlib.moveresize(self.display, win.id, x, y) self.loaded[i] = target self.display.sync() self.save() # load focus win = self.focus[i][target] if win: # we have to wait for the windows to be moved sleep(0.01) xlib.set_active_window(self.display, win) self.display.sync() # sometimes it fails, again sleep(0.2) xlib.set_active_window(self.display, win) self.display.sync()
def update_workspaces(self): self.workspaces = AutoList(AutoList) # normally should be 0 (always active workspace) self.current = xlib.get_current_desktop(self.display)