Swaync widget pour Bumblebee-status

Après plus de 10 ans sous awesome-wm, j'ai changé de gestionnaire de fenêtre en tuile pour utiliser Sway, que j'adore.

J'utilise bumblebee-status pour afficher des petits widgets pratiques dans la barre de statuts. J'utilise également sway notification center pour afficher mes notification.

J'ai écrit un petit module pour avoir un raccourci visuel vers le panneau de notification. Le voici.
"""sway notification center (swaync) widget

Add a small indicator to open the swaync-panel (left click) and
activate Do not disturb (right click).  The indicator is an empty
circle if there are no new notifications, and full if there are
notifications (numbers are too distracting).
"""

import subprocess

import core.input
import core.module
import core.widget


class Module(core.module.Module):
    def __init__(self, config, theme):
        widget = core.widget.Widget(self.full_text)
        self.number = 0
        self.dnd = False
        super().__init__(config, theme, widget)

        # Toggle on left click
        core.input.register(widget, button=core.input.LEFT_MOUSE,
                            cmd="swaync-client -t -sw")

        # Do not disturb on right click
        core.input.register(widget, button=core.input.RIGHT_MOUSE,
                            cmd="swaync-client -d -sw")

    def state(self, widget):
        # Set warning state if DND is on. 
        return self.threshold_state(int(self.dnd), 0, 1)
        
    def full_text(self, widgets):
        sp = subprocess.run(["swaync-client","-c"], capture_output=True, check=False)
        dnd = subprocess.run(["swaync-client","-D"], capture_output=True, check=False)
        
        self.dnd = dnd.stdout.decode()=="true"
        self.number = int(sp.stdout.decode())
        return "●"  if self.number else "○"

À sauvegarder dans .config/bumblebee-status/modules/swaync.py

Enjoy !