Ejemplo n.º 1
0
 def test_get_xatom_pyatom(self):
     d2 = self.clone_display()
     asdf1 = l.get_xatom("ASDF")
     asdf2 = l.get_xatom("ASDF")
     ghjk1 = l.get_xatom("GHJK")
     ghjk2 = l.get_xatom("GHJK")
     assert asdf1 == asdf2
     assert ghjk1 == ghjk2
     assert l.get_pyatom(self.display, asdf2) == "ASDF"
     assert l.get_pyatom(d2, ghjk1) == "GHJK"
Ejemplo n.º 2
0
 def do_wimpiggy_client_message_event(self, event):
     if (event.window is self._root
         and event.message_type == "MANAGER"
         and event.data[1] == get_xatom(self._selection)):
         log("XSettings manager changed")
         self._add_watch()
         self.emit("xsettings-changed")
Ejemplo n.º 3
0
 def do_wimpiggy_client_message_event(self, event):
     if (event.window is self._root
         and event.message_type == "MANAGER"
         and event.data[1] == get_xatom(event.window, "_XSETTINGS_S0")):
         log("XSettings manager changed")
         self._add_watch()
         self.emit("xsettings-changed")
Ejemplo n.º 4
0
    def acquire(self, when):
        old_owner = self._owner()
        if when is self.IF_UNOWNED and old_owner != const["XNone"]:
            raise AlreadyOwned

        self.clipboard.set_with_data([("VERSION", 0, 0)],
                                     self._get,
                                     self._clear,
                                     None)

        # Having acquired the selection, we have to announce our existence
        # (ICCCM 2.8, still).  The details here probably don't matter too
        # much; I've never heard of an app that cares about these messages,
        # and metacity actually gets the format wrong in several ways (no
        # MANAGER or owner_window atoms).  But might as well get it as right
        # as possible.

        # To announce our existence, we need:
        #   -- the timestamp we arrived at
        #   -- the manager selection atom
        #   -- the window that registered the selection
        # Of course, because Gtk is doing so much magic for us, we have to do
        # some weird tricks to get at these.

        # Ask ourselves when we acquired the selection:
        ts_data = self.clipboard.wait_for_contents("TIMESTAMP").data
        ts_num = unpack("@i", ts_data[:4])[0]
        # Calculate the X atom for this selection:
        selection_xatom = get_xatom(self.atom)
        # Ask X what window we used:
        self._xwindow = myGetSelectionOwner(self.clipboard, self.atom)

        root = self.clipboard.get_display().get_default_screen().get_root_window()
        sendClientMessage(root, root, False, const["StructureNotifyMask"],
                          "MANAGER",
                          ts_num, selection_xatom, self._xwindow, 0, 0)

        if old_owner != const["XNone"] and when is self.FORCE:
            # Block in a recursive mainloop until the previous owner has
            # cleared out.
            def getwin():
                window = get_pywindow(self.clipboard, old_owner)
                window.set_events(window.get_events() | gtk.gdk.STRUCTURE_MASK)
                return window
            try:
                window = trap.call_synced(getwin)
                log("got window")
            except XError:
                log("Previous owner is already gone, not blocking")
            else:
                log("Waiting for previous owner to exit...")
                add_event_receiver(window, self)
                gtk.main()
                log("...they did.")
        window = get_pywindow(self.clipboard, self._xwindow)
        window.set_title("Xpra-ManagerSelection")
Ejemplo n.º 5
0
    def test_send_wm_take_focus_large_time(self):
        self.evs = []
        win = self.window()
        l.add_event_receiver(win, self)
        gtk.gdk.flush()

        send_wm.send_wm_take_focus(win, 0xff000000)
        gtk.main()
        assert len(self.evs) == 1
        event = self.evs[0]
        assert event is not None
        assert event.window is win
        assert event.message_type == "WM_PROTOCOLS"
        assert event.format == 32
        assert event.data == (l.get_xatom("WM_TAKE_FOCUS"), 0xff000000, 0, 0, 0)
Ejemplo n.º 6
0
 def _munge_wire_selection_to_raw(self, encoding, type, format, data):
     if encoding == "bytes":
         return data
     elif encoding == "atoms":
         d = gtk.gdk.display_get_default()
         ints = [get_xatom(d, a) for a in data]
         return struct.pack("@" + "L" * len(ints), *ints)
     elif encoding == "integers":
         if format == 32:
             format_char = "L"
         elif format == 16:
             format_char = "H"
         elif format == 8:
             format_char = "B"
         else:
             assert False
         return struct.pack("@" + format_char * len(data), *data)
     else:
         assert False
Ejemplo n.º 7
0
 def _munge_wire_selection_to_raw(self, encoding, type, format, data):
     if encoding == "bytes":
         return data
     elif encoding == "atoms":
         d = gtk.gdk.display_get_default()
         ints = [get_xatom(d, a) for a in data]
         return struct.pack("@" + "L" * len(ints), *ints)
     elif encoding == "integers":
         if format == 32:
             format_char = "L"
         elif format == 16:
             format_char = "H"
         elif format == 8:
             format_char = "B"
         else:
             assert False
         return struct.pack("@" + format_char * len(data), *data)
     else:
         assert False
Ejemplo n.º 8
0
_prop_types = {
    # Python type, X type Atom, format, serializer, deserializer, list
    # terminator
    "utf8": (unicode, "UTF8_STRING", 8,
             lambda disp, u: u.encode("UTF-8"),
             lambda disp, d: d.decode("UTF-8"),
             "\0"),
    # In theory, there should be something clever about COMPOUND_TEXT here.  I
    # am not sufficiently clever to deal with COMPOUNT_TEXT.  Even knowing
    # that Xutf8TextPropertyToTextList exists.
    "latin1": (unicode, "STRING", 8,
               lambda disp, u: u.encode("latin1"),
               lambda disp, d: d.decode("latin1"),
               "\0"),
    "atom": (str, "ATOM", 32,
             lambda disp, a: struct.pack("=I", get_xatom(a)),
              _get_atom,
             ""),
    "u32": ((int, long), "CARDINAL", 32,
            lambda disp, c: struct.pack("=I", c),
            lambda disp, d: struct.unpack("=I", d)[0],
            ""),
    "window": (gtk.gdk.Window, "WINDOW", 32,
               lambda disp, c: struct.pack("=I", get_xwindow(c)),
               lambda disp, d: get_pywindow(disp, struct.unpack("=I", d)[0]),
               ""),
    "wm-size-hints": (WMSizeHints, "WM_SIZE_HINTS", 32,
                      unsupported,
                      WMSizeHints,
                      None),
    "wm-hints": (WMHints, "WM_HINTS", 32,
Ejemplo n.º 9
0
def _get_atom(disp, d):
    return str(get_pyatom(disp, struct.unpack("@I", d)[0]))


_prop_types = {
    # Python type, X type Atom, format, serializer, deserializer, list
    # terminator
    "utf8": (unicode, "UTF8_STRING", 8, lambda disp, u: u.encode("UTF-8"),
             lambda disp, d: d.decode("UTF-8"), "\0"),
    # In theory, there should be something clever about COMPOUND_TEXT here.  I
    # am not sufficiently clever to deal with COMPOUNT_TEXT.  Even knowing
    # that Xutf8TextPropertyToTextList exists.
    "latin1": (unicode, "STRING", 8, lambda disp, u: u.encode("latin1"),
               lambda disp, d: d.decode("latin1"), "\0"),
    "atom": (str, "ATOM", 32, lambda disp, a: struct.pack("@I", get_xatom(a)),
             _get_atom, ""),
    "u32": ((int, long), "CARDINAL", 32, lambda disp, c: struct.pack("@I", c),
            lambda disp, d: struct.unpack("@I", d)[0], ""),
    "window": (gtk.gdk.Window, "WINDOW", 32,
               lambda disp, c: struct.pack("@I", get_xwindow(c)),
               lambda disp, d: get_pywindow(disp,
                                            struct.unpack("@I", d)[0]), ""),
    "wm-size-hints":
    (WMSizeHints, "WM_SIZE_HINTS", 32, unsupported, WMSizeHints, None),
    "wm-hints": (WMHints, "WM_HINTS", 32, unsupported, WMHints, None),
    "strut": (NetWMStrut, "CARDINAL", 32, unsupported, NetWMStrut, None),
    "strut-partial":
    (NetWMStrut, "CARDINAL", 32, unsupported, NetWMStrut, None),
    "icon":
    (cairo.ImageSurface, "CARDINAL", 32, unsupported, NetWMIcons, None),
Ejemplo n.º 10
0
 def _munge_wire_selection_to_raw(self, encoding, type, format, data):
     if encoding == "atoms":
         d = gtk.gdk.display_get_default()
         ints = [get_xatom(d, a) for a in data]
         return struct.pack("@" + "L" * len(ints), *ints)
     return ClipboardProtocolHelperBase._munge_wire_selection_to_raw(self, encoding, type, format, data)
Ejemplo n.º 11
0
 def _munge_wire_selection_to_raw(self, encoding, datatype, format, data):
     if encoding == "atoms":
         ints = [get_xatom(a) for a in data]
         log.debug("wire to raw: atoms(%s)=%s", data, ints)
         return struct.pack("=" + "L" * len(ints), *ints)
     return ClipboardProtocolHelperBase._munge_wire_selection_to_raw(self, encoding, datatype, format, data)
Ejemplo n.º 12
0
_prop_types = {
    # Python type, X type Atom, format, serializer, deserializer, list
    # terminator
    "utf8": (unicode, "UTF8_STRING", 8,
             lambda disp, u: u.encode("UTF-8"),
             lambda disp, d: d.decode("UTF-8"),
             "\0"),
    # In theory, there should be something clever about COMPOUND_TEXT here.  I
    # am not sufficiently clever to deal with COMPOUNT_TEXT.  Even knowing
    # that Xutf8TextPropertyToTextList exists.
    "latin1": (unicode, "STRING", 8,
               lambda disp, u: u.encode("latin1"),
               lambda disp, d: d.decode("latin1"),
               "\0"),
    "atom": (str, "ATOM", 32,
             lambda disp, a: struct.pack("@I", get_xatom(disp, a)),
              _get_atom,
             ""),
    "u32": ((int, long), "CARDINAL", 32,
            lambda disp, c: struct.pack("@I", c),
            lambda disp, d: struct.unpack("@I", d)[0],
            ""),
    "window": (gtk.gdk.Window, "WINDOW", 32,
               lambda disp, c: struct.pack("@I", get_xwindow(c)),
               lambda disp, d: get_pywindow(disp, struct.unpack("@I", d)[0]),
               ""),
    "wm-size-hints": (WMSizeHints, "WM_SIZE_HINTS", 32,
                      unsupported,
                      WMSizeHints,
                      None),
    "wm-hints": (WMHints, "WM_HINTS", 32,
Ejemplo n.º 13
0
_prop_types = {
    # Python type, X type Atom, formatbits, serializer, deserializer, list
    # terminator
    "utf8": (unicode, "UTF8_STRING", 8,
             lambda disp, u: u.encode("UTF-8"),
             lambda disp, d: d.decode("UTF-8"),
             "\0"),
    # In theory, there should be something clever about COMPOUND_TEXT here.  I
    # am not sufficiently clever to deal with COMPOUNT_TEXT.  Even knowing
    # that Xutf8TextPropertyToTextList exists.
    "latin1": (unicode, "STRING", 8,
               lambda disp, u: u.encode("latin1"),
               lambda disp, d: d.decode("latin1"),
               "\0"),
    "atom": (str, "ATOM", 32,
             lambda disp, a: struct.pack("@I", get_xatom(a)),
              _get_atom,
             ""),
    "u32": ((int, long), "CARDINAL", 32,
            lambda disp, c: struct.pack("=I", c),
            lambda disp, d: struct.unpack("=I", d)[0],
            ""),
    "visual": (gtk.gdk.Visual, "XA_VISUALID", 32,
               lambda disp, c: struct.pack("=I", get_xvisual(c)),
               unsupported,
               ""),
    "window": (gtk.gdk.Window, "WINDOW", 32,
               lambda disp, c: struct.pack("=I", get_xwindow(c)),
               lambda disp, d: get_pywindow(disp, struct.unpack("=I", d)[0]),
               ""),
    "wm-size-hints": (WMSizeHints, "WM_SIZE_HINTS", 32,