Esempio n. 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 ""
Esempio n. 2
0
 def test_unicode(self):
     display = self.find_free_display()
     xvfb = self.start_Xvfb(display)
     from xpra.x11.bindings.posix_display_source import X11DisplayContext    #@UnresolvedImport
     with X11DisplayContext(display):
         from xpra.x11.bindings.keyboard_bindings import X11KeyboardBindings        #@UnresolvedImport
         keyboard_bindings = X11KeyboardBindings()
         for x in ("2030", "0005", "0010", "220F", "2039", "2211", "2248", "FB01", "F8FF", "203A", "FB02", "02C6", "02DA", "02DC", "2206", "2044", "25CA"):
             #hex form:
             hk = keyboard_bindings.parse_keysym("0x"+x)
             #osx U+ form:
             uk = keyboard_bindings.parse_keysym("U+"+x)
             log("keysym(U+%s)=%#x, keysym(0x%s)=%#x", x, uk, x, hk)
             assert hk and uk
             assert uk == hk, "failed to get unicode keysym %s" % x
     xvfb.terminate()
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""
Esempio n. 4
0
    def test_display(self):
        from xpra.x11.gtk3.gdk_display_util import verify_gdk_display
        with OSEnvContext():
            os.environ["GDK_BACKEND"] = "x11"
            os.environ.pop("DISPLAY", None)
            for d in (None, ""):
                try:
                    verify_gdk_display(d)
                except Exception:
                    pass
                else:
                    raise Exception("%s is not a valid display" % d)

            display = self.find_free_display()
            xvfb = self.start_Xvfb(display)
            os.environ["DISPLAY"] = display
            from xpra.x11.bindings.posix_display_source import X11DisplayContext  #@UnresolvedImport
            with X11DisplayContext(display):
                verify_gdk_display(display)
            xvfb.terminate()