Exemple #1
0
    def create_desktops(self, screen):
        # TODO: every screen has the same desktops?
        desktops = []
        for idx, (name, info) in enumerate(self.config):
            desktop = Desktop(self, screen, name, idx, info)
            desktops.append(desktop)
        self.attach_data_to(screen, ScreenData(screen, desktops))

        screen.root.change_property('_NET_NUMBER_OF_DESKTOPS', 'CARDINAL',
                32, [len(desktops)])

        # We don't support large desktops here.
        # But that could be added by a plugin.
        root_geom = screen.get_geometry()
        screen.root.change_property('_NET_DESKTOP_GEOMETRY',
                'CARDINAL', 32,
                [root_geom.width, root_geom.height])
        screen.root.change_property('_NET_DESKTOP_VIEWPORT',
                'CARDINAL', 32, [0, 0])
        screen.root.change_property('_NET_DESKTOP_NAMES',
                'UTF8_STRING', 8,
                List.from_stringlist(
                    (desktop.name for desktop in desktops)
                )
        )
Exemple #2
0
 def update_net_wm_state(self):
     """
         ensure that the window's `_NET_WM_STATE` property contains
         the same atoms as *self.state*.
     """
     self.window.change_property('_NET_WM_STATE', 'ATOM', 32,
             List.from_atoms(self.state)
     )
     self.conn.flush()
Exemple #3
0
    def __init__(self, app, screen, config):
        self.app = app
        self.conn = app.conn
        self.screen = screen
        self.config = self.default_config.copy()
        if config:
            self.config.update(config)

        self.massage_config()

        visualtype = screen.get_root_visual_type()
        self.win = xproto.Window.create_toplevel_on_screen(
            self.conn,
            screen,
            y=self.config["height"],
            width=self.config["width"],
            height=self.config["height"],
            back_pixel=screen.white_pixel,
            event_mask=(
                0
                | xproto.EventMask.Exposure
                | xproto.EventMask.ButtonPress
                | xproto.EventMask.PointerMotion
                | xproto.EventMask.KeyPress
                | xproto.EventMask.PropertyChange
                | xproto.EventMask.StructureNotify
            ),
        )

        self.win.ewmh_set_window_name("yahiko-statusbar")
        self.win.change_property("WM_CLASS", "STRING", 8, List.from_string("yahiko-statusbar"))

        self.win.change_property("_NET_WM_DESKTOP", "CARDINAL", 32, [0xFFFFFFFFL])

        self.win.change_property(
            "_NET_WM_WINDOW_TYPE", "ATOM", 32, List.from_atoms([self.conn.atoms["_NET_WM_WINDOW_TYPE_DOCK"]])
        )
        self.win.change_property(
            "_NET_WM_STATE",
            "ATOM",
            32,
            List.from_atoms(
                [
                    self.conn.atoms["_NET_WM_STATE_SKIP_PAGER"],
                    self.conn.atoms["_NET_WM_STATE_SKIP_TASKBAR"],
                    self.conn.atoms["_NET_WM_STATE_STICKY"],
                ]
            ),
        )
        self.win.change_property("_NET_WM_STRUT", "CARDINAL", 32, [0, 0, 0, self.config["height"]])
        self.win.map()
        root_geom = self.screen.root.get_geometry().reply()
        self.win.configure(x=self.config["x"] - (self.config["width"] / 2), y=root_geom.height - self.config["height"])

        @self.win.event
        def on_key_press(event):
            if event.detail == 9:
                self.app.stop()

        self.ui = ui.TopLevelContainer(self.win, visualtype, style=self.config["style"], layouter=ui.HorizontalLayouter)

        self.slots = []

        for slot in self.config["slots"]:
            slot_cls = slot["class"]
            slot_name = slot["name"]
            slot_args = slot.get("args", ())
            slot_kwargs = slot.get("kwargs", {})
            style = slot.get("style")
            s = slot_cls(self, slot_name, *slot_args, **slot_kwargs)
            if style:
                s.get_window().style.update(style)
            self.add_slot(s)
Exemple #4
0
def ewmh_set_window_name(window, name):
    if type(name) is not unicode:
        name = unicode(name, 'utf8', 'replace')
    window.change_property('WM_NAME', 'STRING', 8, List.from_string(name.encode('latin-1', 'replace')))
    window.change_property('_NET_WM_NAME', 'UTF8_STRING', 8, List.from_string(name.encode('utf8', 'replace')))