Skip to content

Commit

Permalink
Use fallback icon in StatusNotifier widget (#4706)
Browse files Browse the repository at this point in the history
StatusNotifier widget items do not render, when a corresponding icon can not be found.
This commit allows a StatusNotifier item to fallback to some default icon in that case.
  • Loading branch information
dariogoetz committed Mar 3, 2024
1 parent 9c684ec commit 39fc0b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Qtile x.xx.x, released XXXX-XX-XX:
install this rule set.
* bugfixes
- Fix groups marked with `persist=False` not being deleted when their last window is moved to another group.
- Fallback icon in StatusNotifier widget

Qtile 0.24.0, released 2024-01-20:
!!! config breakage/changes !!!
Expand Down
Binary file added libqtile/resources/status_notifier/fallback_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 19 additions & 3 deletions libqtile/widget/statusnotifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ async def start(self):
)
return False

await self._get_local_icon()
# Trying to get the local icon (first without fallback because there might be application-provided icons)
await self._get_local_icon(fallback=False)

# If there's no XDG icon, try to use icon provided by application
if self.icon:
self.item.on_new_icon(self._update_local_icon)

else:
# Get initial application icons:
for icon in ["Icon", "Attention", "Overlay"]:
Expand All @@ -172,10 +172,16 @@ async def start(self):
logger.warning(
"Cannot find icon in current theme and no icon provided by StatusNotifierItem."
)
# No "local" icon and no application-provided icons are available.
# The "local" icon may be updated at a later time, so "_update_local_icon"
# gets registered for "on_new_icon" with the option to fall back to
# a default icon.
self.item.on_new_icon(self._update_local_icon)
await self._get_local_icon()

return True

async def _get_local_icon(self):
async def _get_local_icon(self, fallback=True):
# Default to XDG icon
# Some implementations don't provide an IconName property so we
# need to catch an error if we can't read it.
Expand All @@ -195,6 +201,13 @@ async def _get_local_icon(self):
if not self.icon:
self.icon = self._get_xdg_icon(icon_name)

if not self.icon and fallback:
# Use fallback icon libqtile/resources/status_notifier/fallback_icon.png
logger.warning("Could not find icon for '%s'. Using fallback icon.", icon_name)
root = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2])
path = os.path.join(root, "resources", "status_notifier", "fallback_icon.png")
self.icon = Img.from_path(path)

def _create_task_and_draw(self, coro):
task = create_task(coro)
task.add_done_callback(self._redraw)
Expand Down Expand Up @@ -613,6 +626,9 @@ class StatusNotifier(base._Widget):
provide its own icon. In order to use this functionality, users
are recommended to install the `pyxdg <https://pypi.org/project/pyxdg/>`__
module to support retrieving icons from the selected theme.
If the icon specified by StatusNotifierItem can not be found in
the user's current theme and no other icons are provided by the
app, a fallback icon is used.
Left-clicking an icon will trigger an activate event.
Expand Down

0 comments on commit 39fc0b7

Please sign in to comment.