Example #1
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()
Example #2
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)