def x11_init(self, clobber): X11ServerBase.x11_init(self, clobber) 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("Xpra", clobber) self._wm.connect("new-window", self._new_window_signaled) self._wm.connect("window-resized", self._window_resized_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 def get_default_cursor(): self.default_cursor_data = get_cursor_image() log("get_default_cursor=%s", self.default_cursor_data) trap.swallow_synced(get_default_cursor) self._wm.enableCursors(True)
def reset_x_focus(self): focus = self.get_focus() log("widget with focus: %s", focus) if isinstance(focus, wimpiggy.window.WindowView): # FIXME: ugly: focus.model.give_client_focus() trap.swallow_synced(root_set, "_NET_ACTIVE_WINDOW", "window", focus.model.get_property("client-window")) else: self._take_focus() trap.swallow_synced(root_set, "_NET_ACTIVE_WINDOW", "u32", const["XNone"])
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. addXSelectInput(win, const["StructureNotifyMask"]) add_event_receiver(win, self, max_receivers=-1) listening.append(win) win = get_parent(win) handle = xcomposite_name_window_pixmap(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)
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)
def _process_mouse_common(self, proto, wid, pointer, modifiers): ss = self._server_sources.get(proto) if ss is None: return #gone already! ss.make_keymask_match(modifiers) window = self._id_to_window.get(wid) if not window: log("_process_mouse_common() invalid window id: %s", wid) return def raise_and_move(): self._desktop_manager.raise_window(window) self._move_pointer(pointer) trap.swallow_synced(raise_and_move)
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(configureAndNotify, event.window, event.x, event.y, event.width, event.height, event.value_mask)
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 #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(xcomposite_unredirect_window, win) if self._damage_handle: trap.swallow_synced(xdamage_stop, win, self._damage_handle) self._damage_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()
def cleanup(self): log("Tray.cleanup()") root = gtk.gdk.get_default_root_window() owner = myGetSelectionOwner(root, SELECTION) if owner==get_xwindow(self.tray_window): mySetSelectionOwner(root, const["XNone"], SELECTION) else: log.warn("Tray.cleanup() we were no longer the selection owner") remove_event_receiver(self.tray_window, self) def undock(window): log("undocking %s", window) withdraw(window) reparent(window, root, 0, 0) map_raised(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")
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(xdamage_acknowledge, self._window, self._damage_handle): self.invalidate_pixmap()