Exemple #1
0
 def xsettings_owner(self):
     try:
         with xsync:
             owner_x = X11Window.XGetSelectionOwner(self._selection)
             log("XGetSelectionOwner(%s)=%s", self._selection, owner_x)
             if owner_x == XNone:
                 return None
             return get_pywindow(self._clipboard, owner_x)
     except XError:
         log("X error while fetching owner of XSettings data; ignored")
         return None
Exemple #2
0
 def xsettings_owner(self):
     owner_x = X11Window.XGetSelectionOwner(self._selection)
     log("XGetSelectionOwner(%s)=%s", self._selection, owner_x)
     if owner_x == XNone:
         return None
     try:
         with xsync:
             return get_pywindow(self._clipboard, owner_x)
     except XError:
         log("X error while fetching owner of XSettings data; ignored")
         return None
Exemple #3
0
 def _handle_wm_hints_change(self):
     with xswallow:
         wm_hints = X11Window.getWMHints(self.xid)
     if wm_hints is None:
         return
     # GdkWindow or None
     group_leader = None
     if "window_group" in wm_hints:
         xid = wm_hints.get("window_group")
         try:
             group_leader = xid, get_pywindow(xid)
         except:
             group_leader = xid, None
     self._updateprop("group-leader", group_leader)
     self._updateprop("attention-requested", wm_hints.get("urgency", False))
     _input = wm_hints.get("input")
     metalog("wm_hints.input = %s", _input)
     #we only set this value once:
     #(input_field always starts as True, and we then set it to an int)
     if self._input_field is True and _input is not None:
         #keep the value as an int to differentiate from the start value:
         self._input_field = int(_input)
         self._update_can_focus()
Exemple #4
0
 def _handle_wm_hints_change(self):
     with xswallow:
         wm_hints = X11Window.getWMHints(self.xid)
     if wm_hints is None:
         return
     # GdkWindow or None
     group_leader = None
     if "window_group" in wm_hints:
         xid = wm_hints.get("window_group")
         try:
             group_leader = xid, get_pywindow(xid)
         except:
             group_leader = xid, None
     self._updateprop("group-leader", group_leader)
     self._updateprop("attention-requested", wm_hints.get("urgency", False))
     _input = wm_hints.get("input")
     metalog("wm_hints.input = %s", _input)
     #we only set this value once:
     #(input_field always starts as True, and we then set it to an int)
     if self._input_field is True and _input is not None:
         #keep the value as an int to differentiate from the start value:
         self._input_field = int(_input)
         self._update_can_focus()
Exemple #5
0
 "atom": (str, "ATOM", 32, lambda disp, a: struct.pack("@I", _get_xatom(a)),
          _get_atom, b""),
 "state":
 ((int, long), "WM_STATE", 32, lambda disp, c: struct.pack("=I", c),
  lambda disp, d: struct.unpack("=I", d)[0], b""),
 "u32": ((int, long), "CARDINAL", 32, lambda disp, c: struct.pack("=I", c),
         lambda disp, d: struct.unpack("=I", d)[0], b""),
 "integer":
 ((int, long), "INTEGER", 32, lambda disp, c: struct.pack("=I", c),
  lambda disp, d: struct.unpack("=I", d)[0], b""),
 "visual":
 (gdk.Visual, "VISUALID", 32,
  lambda disp, c: struct.pack("=I", get_xvisual(c)), unsupported, b""),
 "window": (gdk.Window, "WINDOW", 32,
            lambda disp, c: struct.pack("=I", get_xwindow(c)),
            lambda disp, d: get_pywindow(disp,
                                         struct.unpack("=I", d)[0]), b""),
 "strut": (NetWMStrut, "CARDINAL", 32, unsupported, NetWMStrut, None),
 "strut-partial":
 (NetWMStrut, "CARDINAL", 32, unsupported, NetWMStrut, None),
 "motif-hints": (MotifWMHints, "_MOTIF_WM_HINTS", 32, unsupported,
                 MotifWMHints, None),
 "icon": (cairo.ImageSurface, "CARDINAL", 32, unsupported, NetWMIcons,
          None),
 "xsettings-settings": (tuple, "_XSETTINGS_SETTINGS", 8, set_xsettings,
                        get_xsettings, None),
 # For uploading ad-hoc instances of the above complex structures to the
 # server, so we can test reading them out again:
 "debug-CARDINAL": (str, "CARDINAL", 32, lambda disp, c: c,
                    lambda disp, d: d, None),
 # For fetching the extra information on a MULTIPLE clipboard conversion
 # request. The exciting thing about MULTIPLE is that it's not actually
Exemple #6
0
def get_window(disp, w):
    return get_pywindow(disp, struct.unpack("=I", w)[0])
Exemple #7
0
    def acquire(self, when):
        old_owner = self._owner()
        if when is self.IF_UNOWNED and old_owner != 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
        #data is a timestamp, X11 datatype is Time which is CARD32,
        #(which is 64 bits on 64-bit systems!)
        Lsize = calcsize("@L")
        if len(ts_data)==Lsize:
            ts_num = unpack("@L", ts_data[:Lsize])[0]
        else:
            ts_num = 0      #CurrentTime
            log.warn("invalid data for 'TIMESTAMP': %s", ([hex(ord(x)) for x in ts_data]))
        # Calculate the X atom for this selection:
        selection_xatom = get_xatom(self.atom)
        # Ask X what window we used:
        self._xwindow = X11Window.XGetSelectionOwner(self.atom)

        root = self.clipboard.get_display().get_default_screen().get_root_window()
        X11Window.sendClientMessage(root.xid, root.xid, False, StructureNotifyMask,
                          "MANAGER",
                          ts_num, selection_xatom, self._xwindow)

        if old_owner != XNone and when is self.FORCE:
            # Block in a recursive mainloop until the previous owner has
            # cleared out.
            try:
                with xsync:
                    window = get_pywindow(self.clipboard, old_owner)
                    window.set_events(window.get_events() | gtk.gdk.STRUCTURE_MASK)
                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")
Exemple #8
0
 def window(self):
     if self._xwindow is None:
         return None
     return get_pywindow(self.clipboard, self._xwindow)
Exemple #9
0
    def acquire(self, when):
        old_owner = self._owner()
        if when is self.IF_UNOWNED and old_owner != 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
        #data is a timestamp, X11 datatype is Time which is CARD32,
        #(which is 64 bits on 64-bit systems!)
        Lsize = calcsize("@L")
        if len(ts_data)==Lsize:
            ts_num = unpack("@L", ts_data[:Lsize])[0]
        else:
            ts_num = 0      #CurrentTime
            log.warn("invalid data for 'TIMESTAMP': %s", ([hex(ord(x)) for x in ts_data]))
        # Calculate the X atom for this selection:
        selection_xatom = get_xatom(self.atom)
        # Ask X what window we used:
        self._xwindow = X11Window.XGetSelectionOwner(self.atom)

        root = self.clipboard.get_display().get_default_screen().get_root_window()
        X11Window.sendClientMessage(root.xid, root.xid, False, StructureNotifyMask,
                          "MANAGER",
                          ts_num, selection_xatom, self._xwindow)

        if old_owner != XNone and when is self.FORCE:
            # Block in a recursive mainloop until the previous owner has
            # cleared out.
            try:
                with xsync:
                    window = get_pywindow(self.clipboard, old_owner)
                    window.set_events(window.get_events() | gtk.gdk.STRUCTURE_MASK)
                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")
Exemple #10
0
 def window(self):
     if self._xwindow is None:
         return None
     return get_pywindow(self.clipboard, self._xwindow)
Exemple #11
0
         b""),
 "u32": ((int, long), "CARDINAL", 32,
         lambda disp, c: struct.pack("=I", c),
         lambda disp, d: struct.unpack("=I", d)[0],
         b""),
 "integer": ((int, long), "INTEGER", 32,
         lambda disp, c: struct.pack("=I", c),
         lambda disp, d: struct.unpack("=I", d)[0],
         b""),
 "visual": (gdk.Visual, "VISUALID", 32,
            lambda disp, c: struct.pack("=I", get_xvisual(c)),
            unsupported,
            b""),
 "window": (gdk.Window, "WINDOW", 32,
            lambda disp, c: struct.pack("=I", get_xwindow(c)),
            lambda disp, d: get_pywindow(disp, struct.unpack("=I", d)[0]),
            b""),
 "strut": (NetWMStrut, "CARDINAL", 32,
           unsupported, NetWMStrut, None),
 "strut-partial": (NetWMStrut, "CARDINAL", 32,
                   unsupported, NetWMStrut, None),
 "motif-hints": (MotifWMHints, "_MOTIF_WM_HINTS", 32,
           unsupported, MotifWMHints, None),
 "icon": (cairo.ImageSurface, "CARDINAL", 32,
          unsupported, NetWMIcons, None),
 "xsettings-settings": (tuple, "_XSETTINGS_SETTINGS", 8,
                        set_xsettings,
                        get_xsettings,
                        None),
 # For uploading ad-hoc instances of the above complex structures to the
 # server, so we can test reading them out again: