Exemple #1
0
    def test_notification(self):
        m = ManagerSelection(self.display, "WM_S0")
        d2 = self.clone_display()
        root2 = d2.get_default_screen().get_root_window()
        root2.set_events(gtk.gdk.STRUCTURE_MASK)
        wimpiggy.lowlevel.add_event_receiver(root2, self)
        d2.flush()
        self.event = None

        assert not m.owned()
        assert self.event is None
        m.acquire(m.IF_UNOWNED)
        gtk.main()
        assert self.event is not None
        assert self.event.window is root2
        assert self.event.message_type == "MANAGER"
        assert self.event.format == 32
        # FIXME: is there any sensible way to check data[0] (timestamp) and
        # data[2] (window id)?
        # 0 = timestamp
        # FIXME: how to check this?
        # 1 = manager atom
        assert self.event.data[1] == wimpiggy.lowlevel.get_xatom("WM_S0")
        # 2 = window belonging to manager.  We just check that it really is a
        # window.
        assert wimpiggy.lowlevel.get_pywindow(root2,
                                              self.event.data[2]) is not None
        assert wimpiggy.lowlevel.myGetSelectionOwner(
            root2, "WM_S0") == self.event.data[2]
        # 3, 4 = 0
        assert self.event.data[3] == 0
        assert self.event.data[4] == 0
Exemple #2
0
    def test_notification(self):
        m = ManagerSelection(self.display, "WM_S0")
        root1 = self.display.get_default_screen().get_root_window()
        d2 = self.clone_display()
        root2 = d2.get_default_screen().get_root_window()
        root2.set_events(gtk.gdk.STRUCTURE_MASK)
        wimpiggy.lowlevel.add_event_receiver(root2, self)
        d2.flush()
        self.event = None

        assert not m.owned()
        assert self.event is None
        m.acquire(m.IF_UNOWNED)
        gtk.main()
        assert self.event is not None
        assert self.event.window is root2
        assert self.event.message_type == "MANAGER"
        assert self.event.format == 32
        # FIXME: is there any sensible way to check data[0] (timestamp) and
        # data[2] (window id)?
        # 0 = timestamp
        # FIXME: how to check this?
        # 1 = manager atom
        assert self.event.data[1] == wimpiggy.lowlevel.get_xatom(root2, "WM_S0")
        # 2 = window belonging to manager.  We just check that it really is a
        # window.
        assert wimpiggy.lowlevel.get_pywindow(root2, self.event.data[2]) is not None
        assert wimpiggy.lowlevel.myGetSelectionOwner(root2, "WM_S0") == self.event.data[2]
        # 3, 4 = 0
        assert self.event.data[3] == 0
        assert self.event.data[4] == 0
Exemple #3
0
 def __init__(self, settings_blob):
     self._selection = ManagerSelection(gtk.gdk.display_get_default(),
                                        "_XSETTINGS_S0")
     # Technically I suppose ICCCM says we should use FORCE, but it's not
     # like a window manager where you have to wait for the old wm to clean
     # things up before you can do anything... as soon as the selection is
     # gone, the settings are gone. (Also, if we're stealing from
     # ourselves, we probably don't clean up the window properly.)
     self._selection.acquire(self._selection.FORCE_AND_RETURN)
     self._window = self._selection.window()
     self._set_blob_in_place(settings_blob)
Exemple #4
0
    def test_conversion(self):
        m = ManagerSelection(self.display, "WM_S0")
        m.acquire(m.IF_UNOWNED)

        d2 = self.clone_display()
        clipboard = gtk.Clipboard(d2, "WM_S0")
        targets = sorted(clipboard.wait_for_targets())
        assert targets == ["MULTIPLE", "TARGETS", "TIMESTAMP", "VERSION"]
        v_data = clipboard.wait_for_contents("VERSION").data
        assert len(v_data) == 8
        assert struct.unpack("@ii", v_data) == (2, 0)
Exemple #5
0
    def test_conversion(self):
        m = ManagerSelection(self.display, "WM_S0")
        m.acquire(m.IF_UNOWNED)

        d2 = self.clone_display()
        clipboard = gtk.Clipboard(d2, "WM_S0")
        targets = sorted(clipboard.wait_for_targets())
        assert targets == ["MULTIPLE", "TARGETS", "TIMESTAMP", "VERSION"]
        v_data = clipboard.wait_for_contents("VERSION").data
        assert len(v_data) == 8
        assert struct.unpack("@ii", v_data) == (2, 0)
Exemple #6
0
class XSettingsManager(object):
    def __init__(self, settings_blob):
        self._selection = ManagerSelection(gtk.gdk.display_get_default(), "_XSETTINGS_S0")
        # Technically I suppose ICCCM says we should use FORCE, but it's not
        # like a window manager where you have to wait for the old wm to clean
        # things up before you can do anything... as soon as the selection is
        # gone, the settings are gone. (Also, if we're stealing from
        # ourselves, we probably don't clean up the window properly.)
        self._selection.acquire(self._selection.FORCE_AND_RETURN)
        self._window = self._selection.window()
        self._set_blob_in_place(settings_blob)

    # This is factored out as a separate function to make it easier to test
    # XSettingsWatcher:
    def _set_blob_in_place(self, settings_blob):
        prop_set(self._window, "_XSETTINGS_SETTINGS", "xsettings-settings", settings_blob)
Exemple #7
0
class XSettingsManager(object):
    def __init__(self, settings_blob):
        self._selection = ManagerSelection(gtk.gdk.display_get_default(),
                                           "_XSETTINGS_S0")
        # Technically I suppose ICCCM says we should use FORCE, but it's not
        # like a window manager where you have to wait for the old wm to clean
        # things up before you can do anything... as soon as the selection is
        # gone, the settings are gone. (Also, if we're stealing from
        # ourselves, we probably don't clean up the window properly.)
        self._selection.acquire(self._selection.FORCE_AND_RETURN)
        self._window = self._selection.window()
        self._set_blob_in_place(settings_blob)

    # This is factored out as a separate function to make it easier to test
    # XSettingsWatcher:
    def _set_blob_in_place(self, settings_blob):
        prop_set(self._window, "_XSETTINGS_SETTINGS", "xsettings-settings",
                 settings_blob)
Exemple #8
0
 def __init__(self, settings_blob):
     self._selection = ManagerSelection(gtk.gdk.display_get_default(), "_XSETTINGS_S0")
     # Technically I suppose ICCCM says we should use FORCE, but it's not
     # like a window manager where you have to wait for the old wm to clean
     # things up before you can do anything... as soon as the selection is
     # gone, the settings are gone. (Also, if we're stealing from
     # ourselves, we probably don't clean up the window properly.)
     self._selection.acquire(self._selection.FORCE_AND_RETURN)
     self._window = self._selection.window()
     self._set_blob_in_place(settings_blob)
Exemple #9
0
class XSettingsManager(object):
    def __init__(self, settings_blob, screen_number=0):
        selection = "_XSETTINGS_S%s" % screen_number
        self._manager = ManagerSelection(gtk.gdk.display_get_default(), selection)
        # Technically I suppose ICCCM says we should use FORCE, but it's not
        # like a window manager where you have to wait for the old wm to clean
        # things up before you can do anything... as soon as the selection is
        # gone, the settings are gone. (Also, if we're stealing from
        # ourselves, we probably don't clean up the window properly.)
        self._manager.acquire(self._manager.FORCE_AND_RETURN)
        self._window = self._manager.window()
        self._set_blob_in_place(settings_blob)

    # This is factored out as a separate function to make it easier to test
    # XSettingsWatcher:
    def _set_blob_in_place(self, settings_blob):
        if type(settings_blob)!=tuple:
            log.warn("discarding xsettings because of incompatible format: %s", type(settings_blob))
            return
        prop_set(self._window, XSETTINGS, XSETTINGS_TYPE, settings_blob)
Exemple #10
0
class XSettingsManager(object):
    def __init__(self, settings_blob, screen_number=0):
        selection = "_XSETTINGS_S%s" % screen_number
        self._manager = ManagerSelection(gtk.gdk.display_get_default(),
                                         selection)
        # Technically I suppose ICCCM says we should use FORCE, but it's not
        # like a window manager where you have to wait for the old wm to clean
        # things up before you can do anything... as soon as the selection is
        # gone, the settings are gone. (Also, if we're stealing from
        # ourselves, we probably don't clean up the window properly.)
        self._manager.acquire(self._manager.FORCE_AND_RETURN)
        self._window = self._manager.window()
        self._set_blob_in_place(settings_blob)

    # This is factored out as a separate function to make it easier to test
    # XSettingsWatcher:
    def _set_blob_in_place(self, settings_blob):
        if type(settings_blob) != tuple:
            log.warn("discarding xsettings because of incompatible format: %s",
                     type(settings_blob))
            return
        prop_set(self._window, XSETTINGS, XSETTINGS_TYPE, settings_blob)
Exemple #11
0
    def test_acquisition_stealing(self):
        d1 = self.clone_display()
        d2 = self.clone_display()
        
        m1 = ManagerSelection(d1, "WM_S0")
        m2 = ManagerSelection(d2, "WM_S0")

        selection_lost_fired = {m1: False, m2: False}
        def cb(manager):
            selection_lost_fired[manager] = True
        m1.connect("selection-lost", cb)
        m2.connect("selection-lost", cb)

        assert not m1.owned()
        assert not m2.owned()
        m1.acquire(m1.IF_UNOWNED)
        assert m1.owned()
        assert m2.owned()

        assert_raises(AlreadyOwned, m2.acquire, m2.IF_UNOWNED)

        assert not selection_lost_fired[m1]
        assert not selection_lost_fired[m2]
        m2.acquire(m2.FORCE_AND_RETURN)
        assert selection_lost_fired[m1]
        assert not selection_lost_fired[m2]
Exemple #12
0
    def test_acquisition_stealing(self):
        d1 = self.clone_display()
        d2 = self.clone_display()

        m1 = ManagerSelection(d1, "WM_S0")
        m2 = ManagerSelection(d2, "WM_S0")

        selection_lost_fired = {m1: False, m2: False}

        def cb(manager):
            selection_lost_fired[manager] = True

        m1.connect("selection-lost", cb)
        m2.connect("selection-lost", cb)

        assert not m1.owned()
        assert not m2.owned()
        m1.acquire(m1.IF_UNOWNED)
        assert m1.owned()
        assert m2.owned()

        assert_raises(AlreadyOwned, m2.acquire, m2.IF_UNOWNED)

        assert not selection_lost_fired[m1]
        assert not selection_lost_fired[m2]
        m2.acquire(m2.FORCE_AND_RETURN)
        assert selection_lost_fired[m1]
        assert not selection_lost_fired[m2]