def get_image(self, x, y, width, height, logger=None): try: start = time.time() with xsync: if USE_XSHM: log("X11 shadow get_image, xshm=%s", self.xshm) if self.xshm is None: self.xshm = XImage.get_XShmWrapper( get_xwindow(self.window)) self.xshm.setup() if self.xshm: image = self.xshm.get_image(get_xwindow(self.window), x, y, width, height) #discard to ensure we will call XShmGetImage next time around self.xshm.discard() return image #fallback to gtk capture: return GTKRootWindowModel.get_image(self, x, y, width, height, logger) except Exception as e: log.warn("Warning: failed to capture root window pixels:") log.warn(" %s", e) #cleanup and hope for the best! self.cleanup() finally: end = time.time() log("X11 shadow captured %s pixels at %i MPixels/s using %s", width * height, (width * height / (end - start)) // 1024 // 1024, ["GTK", "XSHM"][USE_XSHM])
def do_xpra_client_message_event(self, event): # FIXME # Need to listen for: # _NET_ACTIVE_WINDOW # _NET_CURRENT_DESKTOP # _NET_WM_PING responses # and maybe: # _NET_RESTACK_WINDOW # _NET_WM_STATE log("do_xpra_client_message_event(%s)", event) if event.message_type == "_NET_SHOWING_DESKTOP": show = bool(event.data[0]) self.emit("show-desktop", show) elif event.message_type == "_NET_REQUEST_FRAME_EXTENTS" and FRAME_EXTENTS: #if we're here, that means the window model does not exist #(or it would have processed the event) #so this must be a an unmapped window frame = (0, 0, 0, 0) with xswallow: if not X11Window.is_override_redirect(get_xwindow( event.window)): #use the global default: frame = prop_get(self._root, "DEFAULT_NET_FRAME_EXTENTS", ["u32"], ignore_errors=True) if not frame: #fallback: frame = (0, 0, 0, 0) framelog( "_NET_REQUEST_FRAME_EXTENTS: setting _NET_FRAME_EXTENTS=%s on %#x", frame, get_xwindow(event.window)) prop_set(event.window, "_NET_FRAME_EXTENTS", ["u32"], frame)
def do_dock_tray(self, xid): root = get_default_root_window() window = x11_foreign_new(root.get_display(), xid) if window is None: log.warn("could not find gdk window for tray window %#x", xid) return log("dock_tray: root=%s, window=%s", root, window) w, h = window.get_geometry()[2:4] log("dock_tray: geometry=%s", (w, h)) if w == 0 and h == 0: log("dock_tray: invalid tray geometry, ignoring this request") return event_mask = STRUCTURE_MASK | EXPOSURE_MASK | PROPERTY_CHANGE_MASK window.set_events(event_mask=event_mask) add_event_receiver(window, self) w = max(1, min(MAX_TRAY_SIZE, w)) h = max(1, min(MAX_TRAY_SIZE, h)) title = prop_get(window, "_NET_WM_NAME", "utf8", ignore_errors=True) if title is None: title = prop_get(window, "WM_NAME", "latin1", ignore_errors=True) if title is None: title = "" xid = get_xwindow(root) log("dock_tray(%#x) gdk window=%#x, geometry=%s, title=%s", xid, xid, window.get_geometry(), title) kwargs = {} if not is_gtk3(): colormap = window.get_colormap() if colormap: kwargs["colormap"] = colormap visual = window.get_visual() if visual: kwargs["visual"] = visual tray_window = GDKWindow(root, width=w, height=h, event_mask=event_mask, title=title, x=-200, y=-200, override_redirect=True, **kwargs) log("dock_tray(%#x) setting tray properties", xid) set_tray_window(tray_window, window) tray_window.show() self.tray_windows[window] = tray_window self.window_trays[tray_window] = window log("dock_tray(%#x) resizing and reparenting", xid) window.resize(w, h) xwin = get_xwindow(window) xtray = get_xwindow(tray_window) X11Window.Withdraw(xwin) X11Window.Reparent(xwin, xtray, 0, 0) X11Window.MapRaised(xwin) log("dock_tray(%#x) new tray container window %#x", xid, xtray) tray_window.invalidate_rect(gdk.Rectangle(width=w, height=h), True) X11Window.send_xembed_message(xwin, XEMBED_EMBEDDED_NOTIFY, 0, xtray, XEMBED_VERSION)
def setup_tray_window(self): display = display_get_default() root = get_default_root_window() screen = root.get_screen() owner = X11Window.XGetSelectionOwner(SELECTION) log("setup tray: current selection owner=%#x", owner) if owner != XNone: raise Exception("%s already owned by %s" % (SELECTION, owner)) kwargs = {} visual = screen.get_system_visual() if TRANSPARENCY: visual = screen.get_rgba_visual() if visual is None: log.warn("setup tray: using rgb visual fallback") visual = screen.get_rgb_visual() #only GTK2 uses colormap: if not is_gtk3(): if TRANSPARENCY: colormap = screen.get_rgba_colormap() else: colormap = screen.get_rgb_colormap() kwargs["colormap"] = colormap assert visual is not None, "failed to obtain visual" self.tray_window = GDKWindow(root, width=1, height=1, title="Xpra-SystemTray", visual=visual, **kwargs) xtray = get_xwindow(self.tray_window) set_tray_visual(self.tray_window, visual) set_tray_orientation(self.tray_window, TRAY_ORIENTATION_HORZ) log("setup tray: tray window %#x", xtray) if is_gtk3(): display.request_selection_notification( gdk.Atom.intern(SELECTION, False)) else: display.request_selection_notification(SELECTION) try: with xsync: setsel = X11Window.XSetSelectionOwner(xtray, SELECTION) log("setup tray: set selection owner returned %s, owner=%#x", setsel, X11Window.XGetSelectionOwner(SELECTION)) event_mask = StructureNotifyMask log("setup tray: sending client message") xid = get_xwindow(root) X11Window.sendClientMessage(xid, xid, False, event_mask, "MANAGER", CurrentTime, SELECTION, xtray) owner = X11Window.XGetSelectionOwner(SELECTION) assert owner == xtray, "we failed to get ownership of the tray selection" add_event_receiver(self.tray_window, self) log("setup tray: done") except Exception: log("setup_tray failure", exc_info=True) self.cleanup() raise
def close(*args): from xpra.x11.gtk2 import gdk_display_source assert gdk_display_source from xpra.gtk_common.gtk_util import get_xwindow from xpra.x11.bindings.window_bindings import constants, X11WindowBindings #@UnresolvedImport X11Window = X11WindowBindings() root = window.get_window().get_screen().get_root_window() root_xid = get_xwindow(root) xwin = get_xwindow(window.get_window()) SubstructureNotifyMask = constants["SubstructureNotifyMask"] SubstructureRedirectMask = constants["SubstructureRedirectMask"] event_mask = SubstructureNotifyMask | SubstructureRedirectMask now = gtk.gdk.x11_get_server_time(window.get_window()) X11Window.sendClientMessage(root_xid, xwin, False, event_mask, "_NET_CLOSE_WINDOW", now, 1)
def send_maximized_wm_state(mode): from xpra.x11.gtk2 import gdk_display_source assert gdk_display_source from xpra.x11.bindings.window_bindings import constants, X11WindowBindings #@UnresolvedImport X11Window = X11WindowBindings() root = window.get_window().get_screen().get_root_window() root_xid = get_xwindow(root) xwin = get_xwindow(window.get_window()) SubstructureNotifyMask = constants["SubstructureNotifyMask"] SubstructureRedirectMask = constants["SubstructureRedirectMask"] event_mask = SubstructureNotifyMask | SubstructureRedirectMask X11Window.sendClientMessage(root_xid, xwin, False, event_mask, "_NET_WM_STATE", mode, "_NET_WM_STATE_MAXIMIZED_VERT", "_NET_WM_STATE_MAXIMIZED_HORZ", 0, 0)
def moveresize_X11(self, *args): new_x, new_y, new_width, new_height = self.get_new_geometry() from xpra.x11.gtk2 import gdk_display_source assert gdk_display_source from xpra.gtk_common.gtk_util import get_xwindow from xpra.x11.bindings.window_bindings import constants, X11WindowBindings #@UnresolvedImport X11Window = X11WindowBindings() root = self.get_window().get_screen().get_root_window() root_xid = get_xwindow(root) xwin = get_xwindow(self.get_window()) SubstructureNotifyMask = constants["SubstructureNotifyMask"] SubstructureRedirectMask = constants["SubstructureRedirectMask"] event_mask = SubstructureNotifyMask | SubstructureRedirectMask X11Window.sendClientMessage(root_xid, xwin, False, event_mask, "_NET_MOVERESIZE_WINDOW", 1+2**8+2**9+2**10+2**11, new_x, new_y, new_width, new_height)
def set_selection_response(self, requestor, target, prop, dtype, dformat, data, time=0): log("set_selection_response(%s, %s, %s, %s, %s, %r, %i)", requestor, target, prop, dtype, dformat, repr_ellipsized(bytestostr(data)), time) #answer the selection request: try: with xsync: xid = get_xwindow(requestor) if data is not None: X11Window.XChangeProperty(xid, prop, dtype, dformat, data) else: #maybe even delete the property? #X11Window.XDeleteProperty(xid, prop) prop = None X11Window.sendSelectionNotify(xid, self._selection, target, prop, time) except XError as e: log("failed to set selection", exc_info=True) log.warn("Warning: failed to set selection for target '%s'", target) log.warn(" on requestor %s", self.get_wininfo(xid)) log.warn(" property '%s'", prop) log.warn(" %s", e)
def claim(self, time=0): try: with xsync: setsel = X11Window.XSetSelectionOwner(self.xid, self._selection, time) log( "claim_selection: set selection owner returned %s, owner=%#x", setsel, X11Window.XGetSelectionOwner(self._selection)) event_mask = StructureNotifyMask log("claim_selection: sending message to root window") owner = X11Window.XGetSelectionOwner(self._selection) self.owned = owner == self.xid if not self.owned: log.warn( "we failed to get ownership of the '%s' selection", self._selection) else: #send announcement: root = get_default_root_window() root_xid = get_xwindow(root) X11Window.sendClientMessage(root_xid, root_xid, False, event_mask, "MANAGER", CurrentTime, self._selection, self.xid) log("claim_selection: done, owned=%s", self.owned) except Exception: log("failed to claim selection '%s'", self._selection, exc_info=True) raise
def send_wm_delete_window(target): xid = get_xwindow(target) log("sending WM_DELETE_WINDOW to %#x", xid) X11Window.sendClientMessage(xid, xid, False, 0, "WM_PROTOCOLS", "WM_DELETE_WINDOW", CurrentTime)
def cleanup(self): log("SystemTray.cleanup()") root = get_default_root_window() def undock(window): log("undocking %s", window) wxid = get_xwindow(window) rxid = get_xwindow(root) X11Window.Unmap(wxid) X11Window.Reparent(wxid, rxid, 0, 0) with xswallow: owner = X11Window.XGetSelectionOwner(SELECTION) if owner==get_xwindow(self.tray_window): X11Window.XSetSelectionOwner(0, SELECTION) log("SystemTray.cleanup() reset %s selection owner to %#x", SELECTION, X11Window.XGetSelectionOwner(SELECTION)) else: log.warn("Warning: we were no longer the tray selection owner") remove_event_receiver(self.tray_window, self) tray_windows = self.tray_windows self.tray_windows = {} for window, tray_window in tray_windows.items(): with xswallow: undock(window) tray_window.destroy() self.tray_window.destroy() self.tray_window = None log("SystemTray.cleanup() done")
def do_xpra_client_message_event(self, event): if event.message_type == "_GTK_LOAD_ICONTHEMES": #ignore this crap return log.info("clipboard window %#x received an X11 message", get_xwindow(event.window)) log.info(" %s", event)
def _manage_client(self, gdkwindow): if not gdkwindow: return if gdkwindow in self._windows: #already managed return try: with xsync: log("_manage_client(%s)", gdkwindow) desktop_geometry = self.root_get("_NET_DESKTOP_GEOMETRY", ["u32"], True, False) win = WindowModel(self._root, gdkwindow, desktop_geometry, self.size_constraints) except Exception as e: if LOG_MANAGE_FAILURES or not isinstance(e, Unmanageable): l = log.warn else: l = log l("Warning: failed to manage client window %#x:", get_xwindow(gdkwindow)) l(" %s", e) l("", exc_info=True) with xswallow: l(" window name: %s", window_name(gdkwindow)) l(" window info: %s", window_info(gdkwindow)) else: win.managed_connect("unmanaged", self._handle_client_unmanaged) self._windows[gdkwindow] = win self._windows_in_order.append(gdkwindow) self.notify("windows") self._update_window_list() self.emit("new-window", win)
def prop_get(target, key, etype, ignore_errors=False, raise_xerrors=False): if isinstance(etype, list): scalar_type = etype[0] else: scalar_type = etype (_, atom, _, _, _, _) = _prop_types[scalar_type] try: with xsync: data = X11Window.XGetWindowProperty(get_xwindow(target), key, atom, etype) if data is None: if not ignore_errors: log("Missing property %s (%s)", key, etype) return None except XError: if raise_xerrors: raise log.info("Missing window %s or wrong property type %s (%s)", target, key, etype, exc_info=True) return None except PropertyError: if not ignore_errors: log.info("Missing property or wrong property type %s (%s)", key, etype, exc_info=True) return None try: return _prop_decode(target, etype, data) except: if not ignore_errors: log.warn("Error parsing property %s (type %s); this may be a" + " misbehaving application, or bug in Xpra\n" + " Data: %r[...?]", key, etype, data[:160], exc_info=True) raise
def main(): window = gtk.Window(WINDOW_TOPLEVEL) window.set_size_request(400, 100) window.connect("delete_event", gtk.main_quit) da = gtk.DrawingArea() window.add(da) window.show_all() #self.selectX11FocusChange(self) def focus_in(_window, event): print("focus-in-event") def focus_out(_window, event): print("focus-out-event") def has_toplevel_focus(_window, event): print("has-toplevel-event") window.connect("focus-in-event", focus_in) window.connect("focus-out-event", focus_out) window.connect("notify::has-toplevel-focus", has_toplevel_focus) #x11 focus events: gdk_win = window.get_window() xid = get_xwindow(gdk_win) init_gdk_display_source() os.environ["XPRA_X11_DEBUG_EVENTS"] = "FocusIn,FocusOut" init_x11_filter() with xlog: X11WindowBindings().selectFocusChange(xid) gtk.main() return 0
def x11_bell(): global device_bell if device_bell is None: #try to load it: from xpra.x11.bindings.keyboard_bindings import X11KeyboardBindings #@UnresolvedImport device_bell = X11KeyboardBindings().device_bell device_bell(get_xwindow(window), device, bell_class, bell_id, percent, bell_name)
def setup(self): super(WindowModel, self).setup() ox, oy, ow, oh = self.client_window.get_geometry()[:4] # We enable PROPERTY_CHANGE_MASK so that we can call # x11_get_server_time on this window. # clamp this window to the desktop size: x, y = self._clamp_to_desktop(ox, oy, ow, oh) self.corral_window = GDKWindow(self.parking_window, x=x, y=y, width=ow, height=oh, window_type=GDKWINDOW_CHILD, event_mask=PROPERTY_CHANGE_MASK, title="CorralWindow-%#x" % self.xid) cxid = get_xwindow(self.corral_window) log("setup() corral_window=%#x", cxid) prop_set(self.corral_window, "_NET_WM_NAME", "utf8", u"Xpra-CorralWindow-%#x" % self.xid) X11Window.substructureRedirect(cxid) add_event_receiver(self.corral_window, self) # The child might already be mapped, in case we inherited it from # a previous window manager. If so, we unmap it now, and save the # serial number of the request -- this way, when we get an # UnmapNotify later, we'll know that it's just from us unmapping # the window, not from the client withdrawing the window. if X11Window.is_mapped(self.xid): log("hiding inherited window") self.last_unmap_serial = X11Window.Unmap(self.xid) log("setup() adding to save set") X11Window.XAddToSaveSet(self.xid) self.in_save_set = True log("setup() reparenting") X11Window.Reparent(self.xid, cxid, 0, 0) self.client_reparented = True geomlog("setup() geometry") geom = X11Window.geometry_with_border(self.xid) if geom is None: raise Unmanageable("window %#x disappeared already" % self.xid) w, h = geom[2:4] hints = self.get_property("size-hints") geomlog("setup() hints=%s size=%ix%i", hints, w, h) nw, nh = self.calc_constrained_size(w, h, hints) self._updateprop("geometry", (x, y, nw, nh)) geomlog("setup() resizing windows to %sx%s", nw, nh) #don't trigger a resize unless we have to: if ow != nw or oh != nh: self.corral_window.resize(nw, nh) if w != nw or h != nh: self.client_window.resize(nw, nh) self.client_window.show_unraised() #this is here to trigger X11 errors if any are pending #or if the window is deleted already: self.client_window.get_geometry()
def setup(self): WindowDamageHandler.setup(self) screen = self.client_window.get_screen() screen.connect("size-changed", self._screen_size_changed) self.update_size_hints(screen) self._depth = X11Window.get_depth(get_xwindow(self.client_window)) self._managed = True self._setup_done = True
def do_xpra_client_message_event(self, event): message_type = event.message_type if message_type == "_GTK_LOAD_ICONTHEMES": log("ignored clipboard client message: %s", message_type) return log.info("clipboard X11 window %#x received a client message", get_xwindow(self.window)) log.info(" %s", event)
def request_frame_extents(self, window): from xpra.x11.gtk_x11.send_wm import send_wm_request_frame_extents from xpra.gtk_common.error import xsync root = self.get_root_window() with xsync: win = window.get_window() framelog("request_frame_extents(%s) xid=%#x", window, get_xwindow(win)) send_wm_request_frame_extents(root, win)
def __init__(self): self.window = gtk.Window() self.window.connect("destroy", self.destroy) self.window.set_default_size(640, 300) self.window.set_border_width(20) self.window.set_title("Clipboard Test Tool") vbox = gtk.VBox(False, 0) vbox.set_spacing(15) self.log = deque(maxlen=25) for x in range(25): self.log.append("") self.events = gtk.Label() fixed = pango.FontDescription('monospace 9') self.events.modify_font(fixed) #how many clipboards to show: self.clipboards = CLIPBOARDS tb = TableBuilder() table = tb.get_table() labels = [label("Selection")] labels += [ label("Value"), label("Clear"), label("Targets"), label("Actions") ] tb.add_row(*labels) for selection in self.clipboards: cs = ClipboardInstance(selection, self.add_event) get_actions = gtk.HBox() for x in (cs.get_get_targets_btn, cs.get_target_btn, cs.get_string_btn): get_actions.pack_start(x) tb.add_row(label(selection), cs.value_label, cs.clear_label_btn, cs.get_targets, get_actions) set_actions = gtk.HBox() for x in (cs.set_target_btn, cs.set_string_btn): set_actions.pack_start(x) tb.add_row(None, cs.value_entry, cs.clear_entry_btn, cs.set_targets, set_actions) vbox.pack_start(table) vbox.add(self.events) self.window.add(vbox) self.window.show_all() icon = get_icon("clipboard.png") if icon: self.window.set_icon(icon) try: self.add_event( "ALL", "window=%s, xid=%#x" % (self.window, get_xwindow(self.window.get_window()))) except Exception: self.add_event("ALL", "window=%s" % self.window)
def send_wm_take_focus(target, timestamp): xid = get_xwindow(target) log("sending WM_TAKE_FOCUS: %#x, X11 timestamp=%r", xid, timestamp) if timestamp < 0: timestamp = CurrentTime #better than nothing... elif timestamp > 0xFFFFFFFF: raise OverflowError("invalid time: %#x" % timestamp) X11Window.sendClientMessage(xid, xid, False, 0, "WM_PROTOCOLS", "WM_TAKE_FOCUS", timestamp)
def _set_pixmap(self): # 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: screen = self.client_window.get_screen() if not screen: log("cannot set pixmap on client window - maybe deleted?") return root = screen.get_root_window() gdkworld = None world = get_world_window() if world: gdkworld = world.get_window() win = get_parent(self.client_window) while win not in (None, root, gdkworld) 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. xid = get_xwindow(win) X11Window.addXSelectInput(xid, StructureNotifyMask) add_event_receiver(win, self, max_receivers=-1) listening.append(win) win = get_parent(win) handle = XImage.get_xcomposite_pixmap(self.xid) except Exception as e: try: self._cleanup_listening(listening) except Exception: pass raise if handle is None: log("failed to name a window pixmap for %#x: %s", self.xid, 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
def __init__(self, client_window, use_xshm=USE_XSHM): self.client_window = client_window self.xid = get_xwindow(client_window) log("WindowDamageHandler.__init__(%#x, %s)", self.xid, use_xshm) self._use_xshm = use_xshm self._damage_handle = None self._xshm_handle = None self._contents_handle = None self._border_width = 0
def initiate(x_root, y_root, direction, button, source_indication): print("initiate%s" % str( (x_root, y_root, direction, button, source_indication))) from xpra.x11.gtk2 import gdk_display_source assert gdk_display_source from xpra.x11.bindings.core_bindings import X11CoreBindings #@UnresolvedImport from xpra.x11.bindings.window_bindings import constants, X11WindowBindings #@UnresolvedImport event_mask = constants["SubstructureNotifyMask"] | constants[ "SubstructureRedirectMask"] from xpra.gtk_common.gtk_util import get_xwindow root_xid = get_xwindow(root) xwin = get_xwindow(window.get_window()) X11Core = X11CoreBindings() X11Core.UngrabPointer() X11Window = X11WindowBindings() X11Window.sendClientMessage(root_xid, xwin, False, event_mask, "_NET_WM_MOVERESIZE", x_root, y_root, direction, button, source_indication)
def send_wm_take_focus(target, timestamp): xid = get_xwindow(target) log("sending WM_TAKE_FOCUS: %#x, X11 timestamp=%r", xid, timestamp) if timestamp<0: timestamp = CurrentTime #better than nothing... elif timestamp>0xFFFFFFFF: raise OverflowError("invalid time: %#x" % timestamp) X11Window.sendClientMessage(xid, xid, False, 0, "WM_PROTOCOLS", "WM_TAKE_FOCUS", timestamp)
def __init__(self, client_window): super(CoreX11WindowModel, self).__init__() self.xid = get_xwindow(client_window) log("new window %#x", self.xid) self.client_window = client_window self.client_window_saved_events = self.client_window.get_events() self._composite = None self._damage_forward_handle = None self._setup_done = False self._kill_count = 0 self._internal_set_property("client-window", client_window)
def do_selection_notify_event(self, event): owned = self.owned self.owned = event.owner and get_xwindow(event.owner) == self.xid log( "do_selection_notify_event(%s) owned=%s, was %s, enabled=%s, can-send=%s", event, self.owned, owned, self._enabled, self._can_send) if not self._enabled: return if self.owned or not self._can_send: return self.schedule_emit_token()
def get_x11_window_value(filter_object, window): xid = get_xwindow(window) #log("get_x11_window_value(%s, %s) xid=%#x", filter_object, window, xid) with xsync: x11type = window_bindings.GetWindowPropertyType( xid, filter_object.property_name) ptype = get_python_type(x11type) #log("%s: %s (%s)", filter_object.property_name, x11type, ptype) assert ptype, "type '%s' is not handled!" % x11type v = prop_get(window, filter_object.property_name, ptype) log("%s=%s", filter_object.property_name, v) return v
def init_window(self): root = get_default_root_window() self.window = GDKWindow(root, width=1, height=1, title="Xpra-Clipboard", wclass=CLASS_INPUT_ONLY) self.window.set_events(PROPERTY_CHANGE_MASK | self.window.get_events()) xid = get_xwindow(self.window) with xsync: X11Window.selectSelectionInput(xid) add_event_receiver(self.window, self)
def make_proxy(self, selection): xid = get_xwindow(self.window) proxy = ClipboardProxy(xid, selection) proxy.set_want_targets(self._want_targets) proxy.set_direction(self.can_send, self.can_receive) proxy.connect("send-clipboard-token", self._send_clipboard_token_handler) proxy.connect("send-clipboard-request", self._send_clipboard_request_handler) with xsync: X11Window.selectXFSelectionInput(xid, selection) return proxy
def setup_frame_request_windows(self): #query the window manager to get the frame size: from xpra.gtk_common.error import xsync from xpra.x11.gtk_x11.send_wm import send_wm_request_frame_extents self.frame_request_window = gtk.Window(WINDOW_TOPLEVEL) self.frame_request_window.set_title("Xpra-FRAME_EXTENTS") root = self.get_root_window() self.frame_request_window.realize() with xsync: win = self.frame_request_window.get_window() framelog("setup_frame_request_windows() window=%#x", get_xwindow(win)) send_wm_request_frame_extents(root, win)
def _bell_signaled(self, wm, event): log("bell signaled on window %#x", get_xwindow(event.window)) if not self.bell: return wid = 0 if event.window!=gdk.get_default_root_window() and event.window_model is not None: try: wid = self._window_to_id[event.window_model] except: pass log("_bell_signaled(%s,%r) wid=%s", wm, event, wid) for ss in self._server_sources.values(): ss.bell(wid, event.device, event.percent, event.pitch, event.duration, event.bell_class, event.bell_id, event.bell_name or "")
def get_image(self, x, y, width, height, logger=None): try: start = time.time() with xsync: if USE_XSHM: log("X11 shadow get_image, xshm=%s", self.xshm) if self.xshm is None: self.xshm = XImage.get_XShmWrapper(get_xwindow(self.window)) self.xshm.setup() if self.xshm: image = self.xshm.get_image(get_xwindow(self.window), x, y, width, height) #discard to ensure we will call XShmGetImage next time around self.xshm.discard() return image #fallback to gtk capture: return GTKRootWindowModel.get_image(self, x, y, width, height, logger) except Exception as e: log.warn("Warning: failed to capture root window pixels:") log.warn(" %s", e) #cleanup and hope for the best! self.cleanup() finally: end = time.time() log("X11 shadow captured %s pixels at %i MPixels/s using %s", width*height, (width*height/(end-start))//1024//1024, ["GTK", "XSHM"][USE_XSHM])
def send_wm_request_frame_extents(root, win): event_mask = SubstructureNotifyMask | SubstructureRedirectMask X11Window.sendClientMessage(get_xwindow(root), get_xwindow(win), False, event_mask, "_NET_REQUEST_FRAME_EXTENTS", 0, CurrentTime)
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
def __repr__(self): return "GTKX11RootWindowModel(%#x)" % get_xwindow(self.window)
def prop_set(target, key, etype, value): with xsync: X11Window.XChangeProperty(get_xwindow(target), key, _prop_encode(target, etype, value))
def prop_del(target, key): with xsync: X11Window.XDeleteProperty(get_xwindow(target), key)
def request_frame_extents(*args): with xsync: log("request_frame_extents() window=%#x", get_xwindow(win)) send_wm_request_frame_extents(root, win)
def send_wm_workspace(root, win, workspace=0): event_mask = SubstructureNotifyMask | SubstructureRedirectMask X11Window.sendClientMessage(get_xwindow(root), get_xwindow(win), False, event_mask, "_NET_WM_DESKTOP", workspace, CurrentTime)