def get_current_window(self): """ Gets last active window that was not part of SC-Controller. Uses _NET_CLIENT_LIST_STACKING property of root window, value provided by window manager. If that fail (because of no or not ICCM compilant WM), simply returns root window. """ root = X.get_default_root_window(self._xdisplay) NET_WM_WINDOW_TYPE_NORMAL = X.intern_atom( self._xdisplay, "_NET_WM_WINDOW_TYPE_NORMAL", False) my_windows = [ x.get_xid() for x in Gdk.Screen.get_default().get_toplevel_windows() ] nitems, prop = X.get_window_prop(self._xdisplay, root, "_NET_CLIENT_LIST_STACKING", max_size=0x8000) if nitems > 0: for i in reversed(xrange(0, nitems)): window = cast(prop, POINTER(X.XID))[i] if window in my_windows: # skip over my own windows continue if not X.is_window_visible(self._xdisplay, window): # skip minimized and invisible windows continue tp = X.get_window_prop(self._xdisplay, window, "_NET_WM_WINDOW_TYPE")[-1] if tp is not None: tpval = cast(tp, POINTER(X.Atom)).contents.value X.free(tp) if tpval != NET_WM_WINDOW_TYPE_NORMAL: # skip over non-normal windows continue X.free(prop) return window if prop is not None: X.free(prop) # Failed to get property or there is not any usable window return root
def get_current_window(self): """ Gets last active window that was not part of SC-Controller. Uses _NET_CLIENT_LIST_STACKING property of root window, value provided by window manager. If that fail (because of no or not ICCM compilant WM), simply returns root window. """ root = X.get_default_root_window(self._xdisplay) NET_WM_WINDOW_TYPE_NORMAL = X.intern_atom(self._xdisplay, "_NET_WM_WINDOW_TYPE_NORMAL" , False) my_windows = [ x.get_xid() for x in Gdk.Screen.get_default().get_toplevel_windows() ] nitems, prop = X.get_window_prop(self._xdisplay, root, "_NET_CLIENT_LIST_STACKING", max_size=0x8000) if nitems > 0: for i in reversed(xrange(0, nitems)): window = cast(prop, POINTER(X.XID))[i] if window in my_windows: # skip over my own windows continue if not X.is_window_visible(self._xdisplay, window): # skip minimized and invisible windows continue tp = X.get_window_prop(self._xdisplay, window, "_NET_WM_WINDOW_TYPE")[-1] if tp is not None: tpval = cast(tp, POINTER(X.Atom)).contents.value X.free(tp) if tpval != NET_WM_WINDOW_TYPE_NORMAL: # skip over non-normal windows continue X.free(prop) return window if prop is not None: X.free(prop) # Failed to get property or there is not any usable window return root