Example #1
0
def get_x11_property(atom_name):
    from xpra.os_util import OSX, POSIX
    if not POSIX or OSX:
        return ""
    display = os.environ.get("DISPLAY")
    if not display:
        return ""
    try:
        from xpra.x11.bindings.posix_display_source import X11DisplayContext  #@UnresolvedImport
        with X11DisplayContext(display) as dc:
            from xpra.x11.bindings.window_bindings import X11WindowBindings
            X11Window = X11WindowBindings()
            root = X11Window.getDefaultRootWindow()
            log("getDefaultRootWindow()=%#x", root)
            try:
                prop = X11Window.XGetWindowProperty(root, atom_name, "STRING")
            except Exception as e:
                log("cannot get X11 property '%s': %s", atom_name, e)
                return ""
            log("XGetWindowProperty(..)=%s", prop)
            if prop:
                from xpra.x11.prop_conv import prop_decode
                v = prop_decode(dc.display, "latin1", prop)
                log("get_x11_property(%s)=%s", atom_name, v)
                return v
            return ""
    except Exception:
        log.error("Error: cannot get X11 property '%s'",
                  atom_name,
                  exc_info=True)
        log.error(" for python %s", sys.version_info)
        log.error(" xpra command=%s", sys.argv)
    return ""
Example #2
0
def prop_get(target, key, etype, ignore_errors=False, raise_xerrors=False):
    if isinstance(etype, (list, tuple)):
        scalar_type = etype[0]

        def etypestr():
            return "array of %s" % scalar_type
    else:
        scalar_type = etype

        def etypestr():
            return "%s" % etype

    atom = PROP_TYPES[scalar_type][1]
    try:
        buffer_size = PROP_SIZES.get(scalar_type, 64 * 1024)
        with XSyncContext():
            data = X11WindowBindings().XGetWindowProperty(
                target.get_xid(), key, atom, etype, buffer_size)
        if data is None:
            if not ignore_errors:
                log("Missing property %s (%s)", key, etype)
            return None
    except XError:
        log("prop_get%s", (target, key, etype, ignore_errors, raise_xerrors),
            exc_info=True)
        if raise_xerrors:
            raise
        log.info("Missing window %s or wrong property type %s (%s)", target,
                 key, etypestr())
        return None
    except PropertyError as e:
        log("prop_get%s", (target, key, etype, ignore_errors, raise_xerrors),
            exc_info=True)
        if not ignore_errors:
            log.info("Missing property or wrong property type %s (%s)", key,
                     etypestr())
            log.info(" %s", e)
        return None
    try:
        with XSyncContext():
            return prop_decode(target, etype, data)
    except:
        if ignore_errors:
            log("prop_get%s",
                (target, key, etype, ignore_errors, raise_xerrors),
                exc_info=True)
            return None
        log.warn("Error parsing property '%s' (%s)", key, etypestr())
        log.warn(" this may be a misbehaving application, or bug in Xpra")
        try:
            log.warn(" data length=%i", len(data))
        except TypeError:
            pass
        log.warn(" data: %r", repr_ellipsized(str(data)), exc_info=True)
        raise
Example #3
0
def do_prop_decode(key, etype, data, ignore_errors=False):
    try:
        with XSyncContext():
            return prop_decode(etype, data)
    except:
        if ignore_errors:
            log("prop_get%s", (key, etype, ignore_errors), exc_info=True)
            return None
        log.warn("Error parsing property '%s' (%s)", key, _etypestr(etype))
        log.warn(" this may be a misbehaving application, or bug in Xpra")
        try:
            log.warn(" data length=%i", len(data))
        except TypeError:
            pass
        log.warn(" data: %r", repr_ellipsized(str(data)), exc_info=True)
        raise
Example #4
0
def prop_get(target, key, etype, ignore_errors=False, raise_xerrors=False):
    if isinstance(etype, list):
        scalar_type = etype[0]
    else:
        scalar_type = etype
    (_, atom, _, _, _, _) = PROP_TYPES[scalar_type]
    try:
        with XSyncContext():
            data = X11Window.XGetWindowProperty(get_xwindow(target), key, atom,
                                                etype)
        if data is None:
            if not ignore_errors:
                log("Missing property %s (%s)", key, etype)
            return None
    except XError:
        log("prop_get%s", (target, key, etype, ignore_errors, raise_xerrors),
            exc_info=True)
        if raise_xerrors:
            raise
        log.info("Missing window %s or wrong property type %s (%s)", target,
                 key, etype)
        return None
    except PropertyError:
        log("prop_get%s", (target, key, etype, ignore_errors, raise_xerrors),
            exc_info=True)
        if not ignore_errors:
            log.info("Missing property or wrong property type %s (%s)", key,
                     etype)
        return None
    try:
        with XSyncContext():
            return prop_decode(target, etype, data)
    except:
        if ignore_errors:
            log("prop_get%s",
                (target, key, etype, ignore_errors, raise_xerrors),
                exc_info=True)
            return None
        log.warn("Error parsing property %s (type %s); this may be a" +
                 " misbehaving application, or bug in Xpra\n" +
                 "  Data: %r[...?]",
                 key,
                 etype,
                 data[:160],
                 exc_info=True)
        raise
def get_x11_property(atom_name):
    from xpra.os_util import OSX, POSIX
    if not POSIX or OSX:
        return b""
    display = os.environ.get("DISPLAY")
    if not display:
        return b""
    try:
        from xpra.gtk_common.error import xswallow
        from xpra.x11.bindings.posix_display_source import X11DisplayContext  #@UnresolvedImport
        from xpra.x11.bindings.window_bindings import X11WindowBindingsInstance
    except ImportError as e:
        log("get_x11_property(%s)", atom_name, exc_info=True)
        log.error("Error: unable to query X11 property '%s':", atom_name)
        log.error(" %s", e)
        return b""
    try:
        with X11DisplayContext(display) as dc:
            with xswallow:
                X11Window = X11WindowBindingsInstance()
                root = X11Window.getDefaultRootWindow()
                log("getDefaultRootWindow()=%#x", root)
                try:
                    prop = X11Window.XGetWindowProperty(
                        root, atom_name, "STRING")
                except Exception as e:
                    log("cannot get X11 property '%s': %s", atom_name, e)
                    return b""
                log("XGetWindowProperty(..)=%s", prop)
                if prop:
                    from xpra.os_util import strtobytes
                    from xpra.x11.prop_conv import prop_decode
                    v = prop_decode(dc.display, "latin1", prop)
                    log("get_x11_property(%s)=%s", atom_name, v)
                    return strtobytes(v)
                return b""
    except Exception:
        log.error("Error: cannot get X11 property '%s'",
                  atom_name,
                  exc_info=True)
        log.error(" for python 3")
        log.error(" xpra command=%s", sys.argv)
    return b""