Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to mask StatusNotifier icons #404

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading