diff --git a/CHANGELOG b/CHANGELOG index 89f74e3..d5b5009 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +2024-12-23: [FEATURE] Add ability to mask icons in `StatusNotifier` widget 2024-12-11: [BREAKING CHANGE] `dbus-next` dependency has been replaced with `dbus-fast`. Update to latest qtile is also required. 2024-11-18: [BUGFIX] Fix square border for `AnalogueClock` 2024-11-14: [FEATURE] Enable support for vertical bars for `GroupBox2` diff --git a/qtile_extras/widget/statusnotifier.py b/qtile_extras/widget/statusnotifier.py index 315d7f3..e2668f9 100644 --- a/qtile_extras/widget/statusnotifier.py +++ b/qtile_extras/widget/statusnotifier.py @@ -23,6 +23,7 @@ import os from typing import TYPE_CHECKING +import cairocffi from libqtile.log_utils import logger from libqtile.widget.helpers.status_notifier import StatusNotifierItem, host from libqtile.widget.statusnotifier import StatusNotifier as QtileStatusNotifier @@ -77,6 +78,11 @@ class StatusNotifier(QtileStatusNotifier, DbusMenuMixin): _screenshots = [("statusnotifier.png", "Widget showing Remmina icon and context menu.")] + defaults = [ + ("mask", False, "Use icon as mask. Use 'foreground' to set icon colour."), + ("foreground", "fff", "Colour for masked icons"), + ] + def __init__(self, **config): QtileStatusNotifier.__init__(self, **config) self.add_defaults(DbusMenuMixin.defaults) @@ -109,3 +115,20 @@ def show_menu(self): if not self.selected_item: return self.selected_item.get_menu(callback=self.display_menu) + + def _draw_icon(self, icon, x, y): + ctx = self.drawer.ctx + ctx.save() + + if self.mask: + ctx.translate(x, y) + self.drawer.set_source_rgb(self.foreground) + ctx.set_operator(cairocffi.OPERATOR_SOURCE) + ctx.mask(cairocffi.SurfacePattern(icon)) + ctx.fill() + + else: + ctx.set_source_surface(icon, x, y) + ctx.paint() + + ctx.restore()