Beispiel #1
0
    def do_get_property_contents_handle(self, name):
        if self._window is None:
            #shortcut out
            return None
        if self._contents_handle is None:
            log("refreshing named pixmap")
            assert self._listening_to is None

            def set_pixmap():
                # The tricky part here is that the pixmap returned by
                # NameWindowPixmap gets invalidated every time the window's
                # viewable state changes.  ("viewable" here is the X term that
                # means "mapped, and all ancestors are also mapped".)  But
                # there is no X event that will tell you when a window's
                # viewability changes!  Instead we have to find all ancestors,
                # and watch all of them for unmap and reparent events.  But
                # what about races?  I hear you cry.  By doing things in the
                # exact order:
                #   1) select for StructureNotify
                #   2) QueryTree to get parent
                #   3) repeat 1 & 2 up to the root
                #   4) call NameWindowPixmap
                # we are safe.  (I think.)
                listening = []
                e = None
                try:
                    win = get_parent(self._window)
                    while win is not None and win.get_parent() is not None:
                        # We have to use a lowlevel function to manipulate the
                        # event selection here, because SubstructureRedirectMask
                        # does not roundtrip through the GDK event mask
                        # functions.  So if we used them, here, we would clobber
                        # corral window selection masks, and those don't deserve
                        # clobbering.  They are our friends!  X is driving me
                        # slowly mad.
                        X11Window.addXSelectInput(
                            get_xwindow(win), constants["StructureNotifyMask"])
                        add_event_receiver(win, self, max_receivers=-1)
                        listening.append(win)
                        win = get_parent(win)
                    handle = XImage.get_xcomposite_pixmap(
                        get_xwindow(self._window))
                except Exception, e:
                    try:
                        self._cleanup_listening(listening)
                    except:
                        pass
                    raise
                if handle is None:
                    log("failed to name a window pixmap for %s: %s",
                        get_xwindow(self._window), e)
                    self._cleanup_listening(listening)
                else:
                    self._contents_handle = handle
                    # Don't save the listening set until after
                    # NameWindowPixmap has succeeded, to maintain our
                    # invariant:
                    self._listening_to = listening

            trap.swallow_synced(set_pixmap)
Beispiel #2
0
    def x11_init(self):
        X11ServerBase.x11_init(self)
        init_x11_filter()

        self._has_focus = 0
        # Do this before creating the Wm object, to avoid clobbering its
        # selecting SubstructureRedirect.
        root = gtk.gdk.get_default_root_window()
        root.set_events(root.get_events() | gtk.gdk.SUBSTRUCTURE_MASK)
        root.property_change(gtk.gdk.atom_intern("XPRA_SERVER", False),
                            gtk.gdk.atom_intern("STRING", False),
                            8,
                            gtk.gdk.PROP_MODE_REPLACE,
                            xpra.__version__)
        add_event_receiver(root, self)

        ### Create the WM object
        self._wm = Wm(self.clobber)
        self._wm.connect("new-window", self._new_window_signaled)
        self._wm.connect("bell", self._bell_signaled)
        self._wm.connect("quit", lambda _: self.quit(True))

        self.default_cursor_data = None
        self.last_cursor_serial = None
        self.send_cursor_pending = False
        self.cursor_data = None
        self.cursor_sizes = None
        def get_default_cursor():
            self.default_cursor_data = X11Keyboard.get_cursor_image()
            log("get_default_cursor=%s", self.default_cursor_data)
        trap.swallow_synced(get_default_cursor)
        self._wm.enableCursors(True)
Beispiel #3
0
    def reset_x_focus(self):
        focuslog("reset_x_focus: widget with focus: %s", self.get_focus())

        def do_reset_x_focus():
            self._take_focus()
            root_set("_NET_ACTIVE_WINDOW", "u32", XNone)

        trap.swallow_synced(do_reset_x_focus)
Beispiel #4
0
    def reset_x_focus(self):
        focuslog("reset_x_focus: widget with focus: %s", self.get_focus())

        def do_reset_x_focus():
            self._take_focus()
            root_set("_NET_ACTIVE_WINDOW", "u32", XNone)

        trap.swallow_synced(do_reset_x_focus)
Beispiel #5
0
 def _process_mouse_common(self, proto, wid, pointer, modifiers):
     ss = self._server_sources.get(proto)
     if ss is None:
         return
     pos = gtk.gdk.get_default_root_window().get_pointer()[:2]
     if pos == pointer:
         return
     trap.swallow_synced(self._move_pointer, wid, pointer)
     ss.make_keymask_match(modifiers)
Beispiel #6
0
 def _process_mouse_common(self, proto, wid, pointer, modifiers):
     ss = self._server_sources.get(proto)
     if ss is None:
         return
     pos = gtk.gdk.get_default_root_window().get_pointer()[:2]
     if pos==pointer:
         return
     trap.swallow_synced(self._move_pointer, wid, pointer)
     ss.make_keymask_match(modifiers)
Beispiel #7
0
 def do_get_property_contents_handle(self, name):
     if self._window is None:
         #shortcut out
         return  None
     if self._contents_handle is None:
         log("refreshing named pixmap")
         assert self._listening_to is None
         def set_pixmap():
             # The tricky part here is that the pixmap returned by
             # NameWindowPixmap gets invalidated every time the window's
             # viewable state changes.  ("viewable" here is the X term that
             # means "mapped, and all ancestors are also mapped".)  But
             # there is no X event that will tell you when a window's
             # viewability changes!  Instead we have to find all ancestors,
             # and watch all of them for unmap and reparent events.  But
             # what about races?  I hear you cry.  By doing things in the
             # exact order:
             #   1) select for StructureNotify
             #   2) QueryTree to get parent
             #   3) repeat 1 & 2 up to the root
             #   4) call NameWindowPixmap
             # we are safe.  (I think.)
             listening = []
             e = None
             try:
                 win = get_parent(self._window)
                 while win is not None and win.get_parent() is not None:
                     # We have to use a lowlevel function to manipulate the
                     # event selection here, because SubstructureRedirectMask
                     # does not roundtrip through the GDK event mask
                     # functions.  So if we used them, here, we would clobber
                     # corral window selection masks, and those don't deserve
                     # clobbering.  They are our friends!  X is driving me
                     # slowly mad.
                     X11Window.addXSelectInput(get_xwindow(win), constants["StructureNotifyMask"])
                     add_event_receiver(win, self, max_receivers=-1)
                     listening.append(win)
                     win = get_parent(win)
                 handle = XImage.get_xcomposite_pixmap(get_xwindow(self._window))
             except Exception, e:
                 try:
                     self._cleanup_listening(listening)
                 except:
                     pass
                 raise
             if handle is None:
                 log("failed to name a window pixmap for %s: %s", get_xwindow(self._window), e)
                 self._cleanup_listening(listening)
             else:
                 self._contents_handle = handle
                 # Don't save the listening set until after
                 # NameWindowPixmap has succeeded, to maintain our
                 # invariant:
                 self._listening_to = listening
         trap.swallow_synced(set_pixmap)
Beispiel #8
0
 def _update_window_list(self, *args):
     # Ignore errors because not all the windows may still exist; if so,
     # then it's okay to leave the lists out of date for a moment, because
     # in a moment we'll get a signal telling us about the window that
     # doesn't exist anymore, will remove it from the list, and then call
     # _update_window_list again.
     trap.swallow_synced(self.root_set, "_NET_CLIENT_LIST", ["window"],
                         self._windows_in_order)
     # This is a lie, but we don't maintain a stacking order, so...
     trap.swallow_synced(self.root_set, "_NET_CLIENT_LIST_STACKING",
                         ["window"], self._windows_in_order)
Beispiel #9
0
 def _update_window_list(self, *args):
     # Ignore errors because not all the windows may still exist; if so,
     # then it's okay to leave the lists out of date for a moment, because
     # in a moment we'll get a signal telling us about the window that
     # doesn't exist anymore, will remove it from the list, and then call
     # _update_window_list again.
     trap.swallow_synced(self.root_set, "_NET_CLIENT_LIST",
                  ["window"], self._windows_in_order)
     # This is a lie, but we don't maintain a stacking order, so...
     trap.swallow_synced(self.root_set, "_NET_CLIENT_LIST_STACKING",
                  ["window"], self._windows_in_order)
Beispiel #10
0
 def do_child_configure_request_event(self, event):
     # The point of this method is to handle configure requests on
     # withdrawn windows.  We simply allow them to move/resize any way they
     # want.  This is harmless because the window isn't visible anyway (and
     # apps can create unmapped windows with whatever coordinates they want
     # anyway, no harm in letting them move existing ones around), and it
     # means that when the window actually gets mapped, we have more
     # accurate info on what the app is actually requesting.
     log("do_child_configure_request_event(%s)", event)
     if event.window in self._windows:
         return
     log("Reconfigure on withdrawn window")
     trap.swallow_synced(X11Window.configureAndNotify,
                         get_xwindow(event.window), event.x, event.y,
                         event.width, event.height, event.value_mask)
Beispiel #11
0
 def do_child_configure_request_event(self, event):
     # The point of this method is to handle configure requests on
     # withdrawn windows.  We simply allow them to move/resize any way they
     # want.  This is harmless because the window isn't visible anyway (and
     # apps can create unmapped windows with whatever coordinates they want
     # anyway, no harm in letting them move existing ones around), and it
     # means that when the window actually gets mapped, we have more
     # accurate info on what the app is actually requesting.
     log("do_child_configure_request_event(%s)", event)
     if event.window in self._windows:
         return
     log("Reconfigure on withdrawn window")
     trap.swallow_synced(X11Window.configureAndNotify,
                  event.window.xid, event.x, event.y,
                  event.width, event.height,
                  event.value_mask)
Beispiel #12
0
 def cleanup(self):
     debug("Tray.cleanup()")
     root = gtk.gdk.get_default_root_window()
     owner = X11Window.XGetSelectionOwner(SELECTION)
     if owner==get_xwindow(self.tray_window):
         X11Window.XSetSelectionOwner(get_xwindow(root), SELECTION)
     else:
         log.warn("Tray.cleanup() we were no longer the selection owner")
     remove_event_receiver(self.tray_window, self)
     def undock(window):
         debug("undocking %s", window)
         X11Window.Withdraw(get_xwindow(window))
         X11Window.Reparent(get_xwindow(window), get_xwindow(root), 0, 0)
         X11Window.MapRaised(get_xwindow(window))
     for window, tray_window in self.tray_windows.items():
         trap.swallow_synced(undock, window)
         tray_window.destroy()
     self.tray_window.destroy()
     self.tray_window = None
     log("Tray.cleanup() done")
Beispiel #13
0
    def cleanup(self):
        debug("Tray.cleanup()")
        root = gtk.gdk.get_default_root_window()
        owner = X11Window.XGetSelectionOwner(SELECTION)
        if owner == get_xwindow(self.tray_window):
            X11Window.XSetSelectionOwner(get_xwindow(root), SELECTION)
        else:
            log.warn("Tray.cleanup() we were no longer the selection owner")
        remove_event_receiver(self.tray_window, self)

        def undock(window):
            debug("undocking %s", window)
            X11Window.Withdraw(get_xwindow(window))
            X11Window.Reparent(get_xwindow(window), get_xwindow(root), 0, 0)
            X11Window.MapRaised(get_xwindow(window))

        for window, tray_window in self.tray_windows.items():
            trap.swallow_synced(undock, window)
            tray_window.destroy()
        self.tray_window.destroy()
        self.tray_window = None
        log("Tray.cleanup() done")
Beispiel #14
0
 def destroy(self):
     if self._window is None:
         log.warn("composite window %s already destroyed!", self)
         return
     #clear the reference to the window early:
     win = self._window
     xwin = get_xwindow(self._window)
     #Note: invalidate_pixmap()/_cleanup_listening() use self._window, but won't care if it's None
     self._window = None
     remove_event_receiver(win, self)
     self.invalidate_pixmap()
     if not self._already_composited:
         trap.swallow_synced(X11Window.XCompositeUnredirectWindow, xwin)
     if self._damage_handle:
         trap.swallow_synced(X11Window.XDamageDestroy, self._damage_handle)
         self._damage_handle = None
     if self._shm_handle:
         self._shm_handle.cleanup()
         self._shm_handle = None
     #note: this should be redundant since we cleared the
     #reference to self._window and shortcut out in do_get_property_contents_handle
     #but it's cheap anyway
     self.invalidate_pixmap()
Beispiel #15
0
 def destroy(self):
     if self._window is None:
         log.warn("composite window %s already destroyed!", self)
         return
     #clear the reference to the window early:
     win = self._window
     xwin = get_xwindow(self._window)
     #Note: invalidate_pixmap()/_cleanup_listening() use self._window, but won't care if it's None
     self._window = None
     remove_event_receiver(win, self)
     self.invalidate_pixmap()
     if not self._already_composited:
         trap.swallow_synced(X11Window.XCompositeUnredirectWindow, xwin)
     if self._damage_handle:
         trap.swallow_synced(X11Window.XDamageDestroy, self._damage_handle)
         self._damage_handle = None
     if self._shm_handle:
         self._shm_handle.cleanup()
         self._shm_handle = None
     #note: this should be redundant since we cleared the
     #reference to self._window and shortcut out in do_get_property_contents_handle
     #but it's cheap anyway
     self.invalidate_pixmap()
Beispiel #16
0
 def reset_x_focus(self):
     log("widget with focus: %s", self.get_focus())
     def do_reset_x_focus():
         self._take_focus()
         root_set("_NET_ACTIVE_WINDOW", "u32", constants["XNone"])
     trap.swallow_synced(do_reset_x_focus)
Beispiel #17
0
 def acknowledge_changes(self):
     if self._damage_handle is not None and self._window is not None:
         #"Synchronously modifies the regions..." so unsynced?
         if not trap.swallow_synced(X11Window.XDamageSubtract, self._damage_handle):
             self.invalidate_pixmap()
Beispiel #18
0
 def acknowledge_changes(self):
     if self._damage_handle is not None and self._window is not None:
         #"Synchronously modifies the regions..." so unsynced?
         if not trap.swallow_synced(X11Window.XDamageSubtract, self._damage_handle):
             self.invalidate_pixmap()