예제 #1
0
파일: wm.py 프로젝트: svn2github/Xpra
def wm_check(display):
    #there should only be one screen... but let's check all of them
    for i in range(display.get_n_screens()):
        screen = display.get_screen(i)
        root = screen.get_root_window()
        wm_prop = "WM_S%s" % i
        cwm_prop = "_NEW_WM_CM_S%s" % i
        wm_so = myGetSelectionOwner(display, wm_prop)
        cwm_so = myGetSelectionOwner(display, cwm_prop)
        log("ewmh selection owner for %s: %s", wm_prop, wm_so)
        log("compositing window manager %s: %s", cwm_prop, cwm_so)

        try:
            ewmh_wm = prop_get(root, "_NET_SUPPORTING_WM_CHECK", "window", ignore_errors=True, raise_xerrors=False)
        except:
            #errors here generally indicate that the window is gone
            #which is fine: it means the previous window manager is no longer active
            continue
        log("_NET_SUPPORTING_WM_CHECK for screen %s: %s", i, ewmh_wm)
        if ewmh_wm:
            try:
                name = prop_get(ewmh_wm, "_NET_WM_NAME", "utf8", ignore_errors=False, raise_xerrors=False)
            except:
                name = None
            log.warn("Warning: found an existing window manager on screen %s using window id %s: %s", i, hex(get_xwindow(ewmh_wm)), name or "unknown")
            if (wm_so is None or wm_so==0) and (cwm_so is None or cwm_so==0):
                log.error("it does not own the selection '%s' or '%s' so we cannot take over and make it exit", wm_prop, cwm_prop)
                log.error("please stop %s so you can run xpra on this display", name or "the existing window manager")
                return False
    return True
예제 #2
0
 def _owner(self):
     owner_x = myGetSelectionOwner(self._clipboard, "_XSETTINGS_S0")
     if owner_x == const["XNone"]:
         return None
     try:
         return trap.call(get_pywindow, self._clipboard, owner_x)
     except XError:
         log("X error while fetching owner of XSettings data; ignored")
         return None
예제 #3
0
 def _owner(self):
     owner_x = myGetSelectionOwner(self._clipboard, self._selection)
     if owner_x == const["XNone"]:
         return None
     try:
         return trap.call_synced(get_pywindow, self._clipboard, owner_x)
     except XError:
         log("X error while fetching owner of XSettings data; ignored")
         return None
예제 #4
0
def wm_check(display):
    #there should only be one screen... but let's check all of them
    for i in range(display.get_n_screens()):
        screen = display.get_screen(i)
        root = screen.get_root_window()
        wm_prop = "WM_S%s" % i
        cwm_prop = "_NEW_WM_CM_S%s" % i
        wm_so = myGetSelectionOwner(display, wm_prop)
        cwm_so = myGetSelectionOwner(display, cwm_prop)
        log("ewmh selection owner for %s: %s", wm_prop, wm_so)
        log("compositing window manager %s: %s", cwm_prop, cwm_so)

        try:
            ewmh_wm = prop_get(root,
                               "_NET_SUPPORTING_WM_CHECK",
                               "window",
                               ignore_errors=True,
                               raise_xerrors=False)
        except:
            #errors here generally indicate that the window is gone
            #which is fine: it means the previous window manager is no longer active
            continue
        log("_NET_SUPPORTING_WM_CHECK for screen %s: %s", i, ewmh_wm)
        if ewmh_wm:
            try:
                name = prop_get(ewmh_wm,
                                "_NET_WM_NAME",
                                "utf8",
                                ignore_errors=False,
                                raise_xerrors=False)
            except:
                name = None
            log.warn(
                "Warning: found an existing window manager on screen %s using window id %s: %s",
                i, hex(get_xwindow(ewmh_wm)), name or "unknown")
            if (wm_so is None or wm_so == 0) and (cwm_so is None
                                                  or cwm_so == 0):
                log.error(
                    "it does not own the selection '%s' or '%s' so we cannot take over and make it exit",
                    wm_prop, cwm_prop)
                log.error("please stop %s so you can run xpra on this display",
                          name or "the existing window manager")
                return False
    return True
예제 #5
0
    def acquire(self, when):
        old_owner = self._owner()
        if when is self.IF_UNOWNED and old_owner != const["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
        ts_num = unpack("@i", ts_data[:4])[0]
        # Calculate the X atom for this selection:
        selection_xatom = get_xatom(self.atom)
        # Ask X what window we used:
        self._xwindow = myGetSelectionOwner(self.clipboard, self.atom)

        root = self.clipboard.get_display().get_default_screen().get_root_window()
        sendClientMessage(root, root, False, const["StructureNotifyMask"],
                          "MANAGER",
                          ts_num, selection_xatom, self._xwindow, 0, 0)

        if old_owner != const["XNone"] and when is self.FORCE:
            # Block in a recursive mainloop until the previous owner has
            # cleared out.
            def getwin():
                window = get_pywindow(self.clipboard, old_owner)
                window.set_events(window.get_events() | gtk.gdk.STRUCTURE_MASK)
                return window
            try:
                window = trap.call_synced(getwin)
                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")
예제 #6
0
 def setup_tray_window(self):
     display = gtk.gdk.display_get_default()
     root = gtk.gdk.get_default_root_window()
     screen = root.get_screen()
     if TRANSPARENCY:
         colormap, visual = screen.get_rgba_colormap(
         ), screen.get_rgba_visual()
     if colormap is None or visual is None:
         log.warn("setup tray: using rgb visual fallback")
         colormap, visual = screen.get_rgb_colormap(
         ), screen.get_rgb_visual()
     assert colormap is not None and visual is not None, "failed to obtain visual or colormap"
     owner = myGetSelectionOwner(root, SELECTION)
     log("setup tray: current selection owner=%s", owner)
     if owner != const["XNone"]:
         raise Exception("%s already owned by %s" % (SELECTION, owner))
     self.tray_window = gtk.gdk.Window(root,
                                       width=1,
                                       height=1,
                                       window_type=gtk.gdk.WINDOW_TOPLEVEL,
                                       event_mask=0,
                                       wclass=gtk.gdk.INPUT_OUTPUT,
                                       title="Xpra-SystemTray",
                                       visual=visual,
                                       colormap=colormap)
     set_tray_visual(self.tray_window, visual)
     set_tray_orientation(self.tray_window, TRAY_ORIENTATION_HORZ)
     log("setup tray: tray window %s", get_xwindow(self.tray_window))
     display.request_selection_notification(SELECTION)
     setsel = mySetSelectionOwner(root, self.tray_window, SELECTION)
     log("setup tray: set selection owner returned %s", setsel)
     event_mask = const["StructureNotifyMask"]
     sendClientMessage(root, root, False, event_mask, "MANAGER",
                       const["CurrentTime"], SELECTION,
                       get_xwindow(self.tray_window), 0, 0)
     owner = myGetSelectionOwner(root, SELECTION)
     #FIXME: cleanup if we fail!
     assert owner == get_xwindow(
         self.tray_window
     ), "we failed to get ownership of the tray selection"
     add_event_receiver(self.tray_window, self)
     log("setup tray: done")
예제 #7
0
파일: tray.py 프로젝트: svn2github/Xpra
 def setup_tray_window(self):
     display = gtk.gdk.display_get_default()
     root = gtk.gdk.get_default_root_window()
     screen = root.get_screen()
     if TRANSPARENCY:
         colormap, visual = screen.get_rgba_colormap(), screen.get_rgba_visual()
     if colormap is None or visual is None:
         log.warn("setup tray: using rgb visual fallback")
         colormap, visual = screen.get_rgb_colormap(), screen.get_rgb_visual()
     assert colormap is not None and visual is not None, "failed to obtain visual or colormap"
     owner = myGetSelectionOwner(root, SELECTION)
     log("setup tray: current selection owner=%s", owner)
     if owner!=const["XNone"]:
         raise Exception("%s already owned by %s" % (SELECTION, owner))
     self.tray_window = gtk.gdk.Window(root, width=1, height=1,
                                        window_type=gtk.gdk.WINDOW_TOPLEVEL,
                                        event_mask = 0,
                                        wclass=gtk.gdk.INPUT_OUTPUT,
                                        title="Xpra-SystemTray",
                                        visual=visual,
                                        colormap=colormap)
     set_tray_visual(self.tray_window, visual)
     set_tray_orientation(self.tray_window, TRAY_ORIENTATION_HORZ)
     log("setup tray: tray window %s", get_xwindow(self.tray_window))
     display.request_selection_notification(SELECTION)
     setsel = mySetSelectionOwner(root, self.tray_window, SELECTION)
     log("setup tray: set selection owner returned %s", setsel)
     event_mask = const["StructureNotifyMask"]
     sendClientMessage(root, root, False, event_mask, "MANAGER",
                       const["CurrentTime"], SELECTION,
                       get_xwindow(self.tray_window), 0, 0)
     owner = myGetSelectionOwner(root, SELECTION)
     #FIXME: cleanup if we fail!
     assert owner==get_xwindow(self.tray_window), "we failed to get ownership of the tray selection"
     add_event_receiver(self.tray_window, self)
     log("setup tray: done")
예제 #8
0
파일: tray.py 프로젝트: rudresh2319/Xpra
 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")
예제 #9
0
 def _owner(self):
     return myGetSelectionOwner(self.clipboard, self.atom)
예제 #10
0
 def _owner(self):
     return myGetSelectionOwner(self.clipboard, self.atom)