Skip to content

Commit

Permalink
Add ability to mask StatusNotifier icons
Browse files Browse the repository at this point in the history
Allows users to use icons as a mask and paint with a custom colour.
  • Loading branch information
elParaguayo committed Dec 23, 2024
1 parent 08a9de2 commit ec39183
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
23 changes: 23 additions & 0 deletions qtile_extras/widget/statusnotifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit ec39183

Please sign in to comment.