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
Exemple #3
0
	def generate(self, menuhandler):
		rv = []
		dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay()))	# Magic
		root = X.get_default_root_window(dpy)
		
		count, wlist = X.get_window_prop(dpy, root, "_NET_CLIENT_LIST", 1024)
		skip_taskbar = X.intern_atom(dpy, "_NET_WM_STATE_SKIP_TASKBAR", True)
		wlist = cast(wlist, POINTER(X.XID))[0:count]
		for win in wlist:
			if not skip_taskbar in X.get_wm_state(dpy, win):
				title = X.get_window_title(dpy, win)[0:self.MAX_LENGHT]
				menuitem = MenuItem(str(win), title)
				menuitem.callback = WindowListMenuGenerator.callback
				rv.append(menuitem)
		return rv
	def generate(self, menuhandler):
		rv = []
		dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay()))	# Magic
		root = X.get_default_root_window(dpy)
		
		count, wlist = X.get_window_prop(dpy, root, "_NET_CLIENT_LIST", 1024)
		skip_taskbar = X.intern_atom(dpy, "_NET_WM_STATE_SKIP_TASKBAR", True)
		wlist = cast(wlist, POINTER(X.XID))[0:count]
		for win in wlist:
			if not skip_taskbar in X.get_wm_state(dpy, win):
				title = X.get_window_title(dpy, win)[0:self.MAX_LENGHT]
				menuitem = MenuItem(str(win), title)
				menuitem.callback = WindowListMenuGenerator.callback
				rv.append(menuitem)
		return rv