def _xwininfo(identifier, action):
    if identifier is None:
        args = "-root"
    else:
        args = "-id " + identifier

    s = _readfrom(_get_x11_vars() + "xwininfo %s -%s" % (args, action), shell=1)

    # Return a mapping of keys to values for the "stats" action.

    if action == "stats":
        d = {}
        for line in s.split("\n"):
            fields = line.split(":")
            if len(fields) < 2:
                continue
            key, value = fields[0].strip(), ":".join(fields[1:]).strip()
            d[key] = value

        return d

    # Otherwise, return the raw output.

    else:
        return s
Beispiel #2
0
def _xwininfo(identifier, action):
    if identifier is None:
        args = "-root"
    else:
        args = "-id " + identifier

    s = _readfrom(_get_x11_vars() + "xwininfo %s -%s" % (args, action),
                  shell=1)

    # Return a mapping of keys to values for the "stats" action.

    if action == "stats":
        d = {}
        for line in s.split("\n"):
            fields = line.split(":")
            if len(fields) < 2:
                continue
            key, value = fields[0].strip(), ":".join(fields[1:]).strip()
            d[key] = value

        return d

    # Otherwise, return the raw output.

    else:
        return s
Beispiel #3
0
    def position(self):

        "Return a tuple containing the upper left co-ordinates of this window."

        s = _readfrom(_get_x11_vars() + "xwininfo -id %s -stats" % self.identifier, shell=1)
        d = _xwininfo(s)
        return _get_int_properties(d, ["Absolute upper-left X", "Absolute upper-left Y"])
Beispiel #4
0
    def size(self):

        "Return a tuple containing the width and height of this window."

        s = _readfrom(_get_x11_vars() + "xwininfo -id %s -stats" % self.identifier, shell=1)
        d = _xwininfo(s)
        return _get_int_properties(d, ["Width", "Height"])
Beispiel #5
0
    def size(self):

        "Return a tuple containing the width and height of this window."

        s = _readfrom(_get_x11_vars() +
                      "xwininfo -id %s -stats" % self.identifier,
                      shell=1)
        d = _xwininfo(s)
        return _get_int_properties(d, ["Width", "Height"])
Beispiel #6
0
    def position(self):

        "Return a tuple containing the upper left co-ordinates of this window."

        s = _readfrom(_get_x11_vars() +
                      "xwininfo -id %s -stats" % self.identifier,
                      shell=1)
        d = _xwininfo(s)
        return _get_int_properties(
            d, ["Absolute upper-left X", "Absolute upper-left Y"])
Beispiel #7
0
    def children(self):

        "Return a list of windows which are children of this window."

        s = _readfrom(_get_x11_vars() + "xwininfo -id %s -children" % self.identifier, shell=1)
        handles = []
        adding = 0
        for line in s.split("\n"):
            if not adding and line.endswith("children:"):
                adding = 1
            elif adding and line:
                handles.append(line.strip().split()[0])
        return [Window(handle) for handle in handles]
Beispiel #8
0
    def children(self):

        "Return a list of windows which are children of this window."

        s = _readfrom(_get_x11_vars() +
                      "xwininfo -id %s -children" % self.identifier,
                      shell=1)
        handles = []
        adding = 0
        for line in s.split("\n"):
            if not adding and line.endswith("children:"):
                adding = 1
            elif adding and line:
                handles.append(line.strip().split()[0])
        return [Window(handle) for handle in handles]
Beispiel #9
0
def _xwininfo(identifier, action):
    if identifier is None:
        args = "-root"
    else:
        args = "-id " + identifier
    s = _readfrom(_get_x11_vars() + "xwininfo %s -%s" % (args, action), shell=1)
    if action == "stats":
        d = {}
        for line in s.split("\n"):
            fields = line.split(":")
            if len(fields) < 2:
                continue
            key, value = fields[0].strip(), ":".join(fields[1:]).strip()
            d[key] = value
        return d
    else:
        return s
Beispiel #10
0
    def name(self):

        "Return the name of the window."

        s = _readfrom(_get_x11_vars() + "xwininfo -id %s -stats" % self.identifier, shell=1)
        for line in s.split("\n"):
            if line.startswith("xwininfo:"):

                # Format is 'xwininfo: Window id: <handle> "<name>"

                fields = line.split(":")
                handle_and_name = fields[2].strip()
                fields2 = handle_and_name.split(" ")

                # Get the "<name>" part, stripping off the quotes.

                return " ".join(fields2[1:]).strip('"')

        return None
Beispiel #11
0
    def name(self):

        "Return the name of the window."

        s = _readfrom(_get_x11_vars() +
                      "xwininfo -id %s -stats" % self.identifier,
                      shell=1)
        for line in s.split("\n"):
            if line.startswith("xwininfo:"):

                # Format is 'xwininfo: Window id: <handle> "<name>"

                fields = line.split(":")
                handle_and_name = fields[2].strip()
                fields2 = handle_and_name.split(" ")

                # Get the "<name>" part, stripping off the quotes.

                return " ".join(fields2[1:]).strip('"')

        return None
Beispiel #12
0
def list(desktop=None):
    """
    Return a list of windows for the current desktop. If the optional 'desktop'
    parameter is specified then attempt to use that particular desktop
    environment's mechanisms to look for windows.
    """

    # NOTE: The desktop parameter is currently ignored and X11 is tested for
    # NOTE: directly.

    if _is_x11():
        s = _readfrom(_get_x11_vars() + "xlsclients -a -l", shell=1)
        prefix = "Window "
        prefix_end = len(prefix)
        handles = []

        for line in s.split("\n"):
            if line.startswith(prefix):
                handles.append(line[prefix_end:-1])  # NOTE: Assume ":" at end.
    else:
        raise OSError, "Desktop '%s' not supported" % use_desktop(desktop)

    return [Window(handle) for handle in handles]
Beispiel #13
0
def list(desktop=None):

    """
    Return a list of windows for the current desktop. If the optional 'desktop'
    parameter is specified then attempt to use that particular desktop
    environment's mechanisms to look for windows.
    """

    # NOTE: The desktop parameter is currently ignored and X11 is tested for
    # NOTE: directly.

    if _is_x11():
        s = _readfrom(_get_x11_vars() + "xlsclients -a -l", shell=1)
        prefix = "Window "
        prefix_end = len(prefix)
        handles = []

        for line in s.split("\n"):
            if line.startswith(prefix):
                handles.append(line[prefix_end:-1]) # NOTE: Assume ":" at end.
    else:
        raise OSError, "Desktop '%s' not supported" % use_desktop(desktop)

    return [Window(handle) for handle in handles]