def main(filename): from xpra.gtk_common.gtk_util import get_default_root_window root = get_default_root_window() data = take_png_screenshot(root)[-1] with open(filename, "wb") as f: f.write(data) return 0
def activate_menu(self, widget): modifiers_mask = get_default_root_window().get_pointer()[-1] log("activate_menu(%s) modifiers_mask=%s", widget, modifiers_mask) if (modifiers_mask & SHIFT_MASK) ^ OSX: self.handle_click(2) else: self.handle_click(1)
def main(filename): from io import BytesIO from xpra.os_util import memoryview_to_bytes from xpra.gtk_common.gtk_util import get_default_root_window, get_root_size root = get_default_root_window() capture = setup_capture(root) capture.refresh() w, h = get_root_size() image = capture.get_image(0, 0, w, h) from PIL import Image fmt = image.get_pixel_format().replace("X", "A") pixels = memoryview_to_bytes(image.get_pixels()) log("converting %i bytes in format %s to RGBA", len(pixels), fmt) if len(fmt) == 3: target = "RGB" else: target = "RGBA" pil_image = Image.frombuffer(target, (w, h), pixels, "raw", fmt, image.get_rowstride()) if target != "RGB": pil_image = pil_image.convert("RGB") buf = BytesIO() pil_image.save(buf, "png") data = buf.getvalue() buf.close() with open(filename, "wb") as f: f.write(data) return 0
def do_clean_x11_properties(self, *properties): root = get_default_root_window() for prop in properties: try: prop_del(root, prop) except Exception as e: log("prop_del(%s, %s) %s", root, prop, e)
def _root_prop_get(prop_name, ptype="u32"): from xpra.gtk_common.gtk_util import get_default_root_window from xpra.x11.gtk_x11.prop import prop_get try: return prop_get(get_default_root_window(), prop_name, ptype) except Exception: return None
def do_unmanaged(self, wm_exiting): log("unmanaging window: %s (%s - %s)", self, self.corral_window, self.client_window) self._internal_set_property("owner", None) if self.corral_window: remove_event_receiver(self.corral_window, self) geom = None #use a new context so we will XSync right here #and detect if the window is already gone: with XSwallowContext(): geom = X11Window.getGeometry(self.xid) if geom is not None: if self.client_reparented: self.client_window.reparent(get_default_root_window(), 0, 0) self.client_window.set_events(self.client_window_saved_events) self.client_reparented = False #it is now safe to destroy the corral window: self.corral_window.destroy() self.corral_window = None # It is important to remove from our save set, even after # reparenting, because according to the X spec, windows that are # in our save set are always Mapped when we exit, *even if those # windows are no longer inferior to any of our windows!* (see # section 10. Connection Close). This causes "ghost windows", see # bug #27: if self.in_save_set: with xswallow: X11Window.XRemoveFromSaveSet(self.xid) self.in_save_set = False with xswallow: X11Window.sendConfigureNotify(self.xid) if wm_exiting: self.client_window.show_unraised() BaseWindowModel.do_unmanaged(self, wm_exiting)
def popup_menu(self, widget, button, event_time, *args): modifiers_mask = get_default_root_window().get_pointer()[-1] log("popup_menu(%s, %s, %s, %s) modifiers_mask=%s", widget, button, event_time, args, modifiers_mask) if (modifiers_mask & Gdk.ModifierType.SHIFT_MASK) ^ OSX: self.handle_click(1) else: self.handle_click(3)
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 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 claim(self): time = 0 try: with xsync: owner = X11Window.XGetSelectionOwner(self._selection) if owner==self.xid: log("claim() we already own the '%s' selection", self._selection) return setsel = X11Window.XSetSelectionOwner(self.xid, self._selection, time) owner = X11Window.XGetSelectionOwner(self._selection) self.owned = owner==self.xid log("claim_selection: set selection owner returned %s, owner=%#x, owned=%s", setsel, owner, self.owned) event_mask = StructureNotifyMask if not self.owned: log.warn("Warning: we failed to get ownership of the '%s' clipboard selection", self._selection) return #send announcement: log("claim_selection: sending message to root window") root = get_default_root_window() root_xid = root.get_xid() X11Window.sendClientMessage(root_xid, root_xid, False, event_mask, "MANAGER", time or 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 _get_xresources(): if not is_Wayland(): try: from xpra.x11.gtk_x11.prop import prop_get from xpra.gtk_common.gtk_util import get_default_root_window root = get_default_root_window() value = prop_get(root, "RESOURCE_MANAGER", "latin1", ignore_errors=True) log("RESOURCE_MANAGER=%s", value) if value is None: return None #parse the resources into a dict: values = {} options = value.split("\n") for option in options: if not option: continue parts = option.split(":\t", 1) if len(parts) != 2: log("skipped invalid option: '%s'", option) continue values[parts[0]] = parts[1] return values except Exception as e: log("_get_xresources error: %s", e) return None
def do_setup_xprops(self, *args): log("do_setup_xprops(%s)", args) ROOT_PROPS = [ "RESOURCE_MANAGER", "_NET_WORKAREA", "_NET_CURRENT_DESKTOP" ] try: self.init_x11_filter() from xpra.gtk_common.gtk_util import get_default_root_window from xpra.x11.xsettings import XSettingsWatcher from xpra.x11.xroot_props import XRootPropWatcher root = get_default_root_window() if self._xsettings_watcher is None: self._xsettings_watcher = XSettingsWatcher() self._xsettings_watcher.connect("xsettings-changed", self._handle_xsettings_changed) self._handle_xsettings_changed() if self._root_props_watcher is None: self._root_props_watcher = XRootPropWatcher(ROOT_PROPS, root) self._root_props_watcher.connect( "root-prop-changed", self._handle_root_prop_changed) #ensure we get the initial value: self._root_props_watcher.do_notify("RESOURCE_MANAGER") except ImportError as e: log("do_setup_xprops%s", args, exc_info=True) log.error( "Error: failed to load X11 properties/settings bindings:") log.error(" %s", e) log.error(" root window properties will not be propagated")
def __init__(self): self.screen_number = display_get_default().get_default_screen( ).get_number() self.root_window = get_default_root_window() self.pointer_device = XTestPointerDevice() self.last_mouse_user = None GTKServerBase.__init__(self)
def may_guess(self): log("may_guess() GUESS_GEOMETRY=%s, current guess=%s", GUESS_GEOMETRY, self.geometry_guess) if GUESS_GEOMETRY: x, y = get_default_root_window().get_pointer()[-3:-1] w, h = self.get_size() self.recalculate_geometry(x, y, w, h)
def do_unmanaged(self, wm_exiting): log("unmanaging window: %s (%s - %s)", self, self.corral_window, self.client_window) self._internal_set_property("owner", None) if self.corral_window: remove_event_receiver(self.corral_window, self) with xswallow: for prop in WindowModel.SCRUB_PROPERTIES: X11Window.XDeleteProperty(self.xid, prop) if self.client_reparented: self.client_window.reparent(get_default_root_window(), 0, 0) self.client_reparented = False self.client_window.set_events(self.client_window_saved_events) #it is now safe to destroy the corral window: self.corral_window.destroy() self.corral_window = None # It is important to remove from our save set, even after # reparenting, because according to the X spec, windows that are # in our save set are always Mapped when we exit, *even if those # windows are no longer inferior to any of our windows!* (see # section 10. Connection Close). This causes "ghost windows", see # bug #27: if self.in_save_set: with xswallow: X11Window.XRemoveFromSaveSet(self.xid) self.in_save_set = False with xswallow: X11Window.sendConfigureNotify(self.xid) if wm_exiting: self.client_window.show_unraised() BaseWindowModel.do_unmanaged(self, wm_exiting)
def create_root_transient(*args): tw = gtk.Window(WINDOW_TOPLEVEL) tw.set_size_request(200, 100) tw.connect("delete_event", lambda x, y: tw.destroy()) tw.realize() tw.get_window().set_transient_for(get_default_root_window()) tw.add(gtk.Label("Transient Root Window")) tw.show_all()
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 get_new_geometry(self): x, y = self.get_position() width, height = self.get_size() from xpra.gtk_common.gtk_util import get_default_root_window maxx, maxy = get_default_root_window().get_geometry()[2:4] new_x = (x+100) % (maxx-width) new_y = (y+100) % (maxy-height) width, height = self.get_size() return new_x, new_y, (width + 100) % (maxx-x), (height + 100) % (maxy-y)
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 create_root_transient(*_args): tw = Gtk.Window(type=Gtk.WindowType.TOPLEVEL) tw.set_size_request(200, 100) if icon: tw.set_icon(icon) tw.connect("delete_event", lambda x,y : tw.destroy()) tw.realize() tw.get_window().set_transient_for(get_default_root_window()) tw.add(Gtk.Label("Transient Root Window")) tw.show_all()
def init_window(self): root = get_default_root_window() self.window = GDKX11Window(root, width=1, height=1, title="Xpra-Clipboard", wclass=Gdk.WindowWindowClass.INPUT_ONLY) self.window.set_events(Gdk.EventMask.PROPERTY_CHANGE_MASK | self.window.get_events()) xid = self.window.get_xid() with xsync: X11Window.selectSelectionInput(xid) add_event_receiver(self.window, self)
def __init__(self): from xpra.gtk_common.gtk_util import get_default_root_window ShadowServerBase.__init__(self, get_default_root_window()) GTKServerBase.__init__(self) #for managing the systray self.tray_menu = None self.tray_menu_shown = False self.tray_widget = None self.tray = False self.tray_icon = None
def get_resource_manager(self): try: from xpra.gtk_common.gtk_util import get_default_root_window from xpra.x11.gtk_x11.prop import prop_get root = get_default_root_window() value = prop_get(root, "RESOURCE_MANAGER", "latin1", ignore_errors=True) if value is not None: return value.encode("utf-8") except: log.error("failed to get RESOURCE_MANAGER", exc_info=True) return None
def makeDynamicWindowModels(self): assert self.window_matches rwmc = self.get_root_window_model_class() root = get_default_root_window() def model_class(title, geometry): model = rwmc(root, self.capture, title, geometry) model.dynamic_property_names.append("size-hints") return model return window_matches(self.window_matches, model_class)
def __init__(self): self.root_window = get_default_root_window() self.pointer_device = XTestPointerDevice() self.touchpad_device = None self.pointer_device_map = {} self.keys_pressed = {} self.libfakeXinerama_so = None self.initial_resolution = None self.x11_filter = False self.randr_sizes_added = [] super().__init__() log("XShape=%s", X11Window.displayHasXShape())
def __init__(self): self.screen_number = display_get_default().get_default_screen( ).get_number() self.root_window = get_default_root_window() self.pointer_device = XTestPointerDevice() self.touchpad_device = None self.pointer_device_map = {} self.keys_pressed = {} self.last_mouse_user = None self.x11_filter = False GTKServerBase.__init__(self) log("XShape=%s", X11Window.displayHasXShape())
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 __init__(self): from xpra.gtk_common.gtk_util import get_default_root_window ShadowServerBase.__init__(self, get_default_root_window()) GTKServerBase.__init__(self) self.session_type = "shadow" self.pointer_position_timer = None #for managing the systray self.tray_menu = None self.tray_menu_shown = False self.tray_widget = None self.tray = False self.tray_icon = None
def __init__(self): self.screen_number = Gdk.Screen.get_default().get_number() self.root_window = get_default_root_window() self.pointer_device = XTestPointerDevice() self.touchpad_device = None self.pointer_device_map = {} self.keys_pressed = {} self.last_mouse_user = None self.libfakeXinerama_so = None self.x11_filter = False self.randr_sizes_added = [] GTKServerBase.__init__(self) log("XShape=%s", X11Window.displayHasXShape())
def _bell_signaled(self, wm, event): log("bell signaled on window %#x", event.window.get_xid()) if not self.bell: return wid = 0 if event.window != get_default_root_window( ) and event.window_model is not None: wid = self._window_to_id.get(event.window_model, 0) log("_bell_signaled(%s,%r) wid=%s", wm, event, wid) for ss in self.window_sources(): name = strtobytes(event.bell_name or "") ss.bell(wid, event.device, event.percent, event.pitch, event.duration, event.bell_class, event.bell_id, name)
def has_gtk_menu_support(): global _has_gtk_menu_support if not GTK_MENUS: _has_gtk_menu_support = False if _has_gtk_menu_support is not None: return _has_gtk_menu_support try: from xpra.gtk_common.gtk_util import get_default_root_window from xpra.x11.dbus.menu import has_gtk_menu_support root = get_default_root_window() _has_gtk_menu_support = has_gtk_menu_support(root) menulog("has_gtk_menu_support(%s)=%s", root, _has_gtk_menu_support) except Exception as e: menulog("cannot enable gtk-x11 menu support: %s", e) _has_gtk_menu_support = False return _has_gtk_menu_support
def __init__(self): ShadowServerBase.__init__(self, get_default_root_window()) X11ServerBase.__init__(self, False)
from xpra.x11.gtk_x11.prop import prop_get, prop_set from xpra.x11.bindings.window_bindings import constants, X11WindowBindings, SHAPE_KIND #@UnresolvedImport from xpra.x11.bindings.core_bindings import X11CoreBindings from xpra.gtk_common.error import xsync from xpra.x11.gtk_x11.send_wm import send_wm_workspace X11Window = X11WindowBindings() X11Core = X11CoreBindings() HAS_X11_BINDINGS = True SubstructureNotifyMask = constants["SubstructureNotifyMask"] SubstructureRedirectMask = constants["SubstructureRedirectMask"] CurrentTime = constants["CurrentTime"] try: #TODO: in theory this is not a proper check, meh - that will do root = get_default_root_window() supported = prop_get(root, "_NET_SUPPORTED", ["atom"], ignore_errors=True) CAN_SET_WORKSPACE = bool(supported) and "_NET_WM_DESKTOP" in supported except Exception as e: log.info("failed to setup workspace hooks: %s", e, exc_info=True) except ImportError: pass UNDECORATED_TRANSIENT_IS_OR = int(os.environ.get("XPRA_UNDECORATED_TRANSIENT_IS_OR", "1")) #window types we map to POPUP rather than TOPLEVEL POPUP_TYPE_HINTS = set(( #"DIALOG", #"MENU", #"TOOLBAR",
def get_root_window(self): return get_default_root_window()