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

Using 'image-missing' fallback if no taskbar icon is found #2677

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

sjoblomj
Copy link
Contributor

Icons are sometimes not found in the taskbar, for two reasons:

  1. The icon given in the .desktop file for that program cannot be found.
  2. Waybar is not given an app_id, so lookup is impossible.

If the user has configured Waybar to only show applications as icons, this means that the program is now essentially "hiding":

Hidden program

With this patch, when an icon cannot be found, Waybar will now load the "image-missing" icon of Gtk:

Image missing as a fallback

@@ -304,6 +315,10 @@ Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar,
with_icon_ = true;
}

if (app_id_.empty()) {
handle_app_id("unknown");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function handle_app_id(), which sets icons, will now be called twice; first here with the parameter app_id = "unknown", and then again once Wayland provides the actual app_id. In this first explicit call, the "image-missing" fallback is being set. In the second call invoked by Wayland, the icon is overwritten by the actual app image. If the program does not set an app_id correctly, this second call will not take place, and the "image-missing" fallback is being kept.

Comment on lines +193 to +194
pixbuf = DefaultGtkIconThemeWrapper::load_icon("image-missing", scaled_icon_size,
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "image-missing" icon is maybe not the prettiest, something like this maybe looks prettier. A different approach is thus to bundle in a fallback icon in resources/icons (and update resources/icons/waybar_icons.gresource.xml).

This line is then replaced by pixbuf = Gdk::Pixbuf::create_from_resource("/fr/arouillard/waybar/icons/scalable/apps/default-app-icon", scaled_icon_size, scaled_icon_size)

If bundling an icon preferred, I am happy to use this approach instead and change the PR accordingly.

@sjoblomj
Copy link
Contributor Author

Fixes #754 and fixes #921

@Alexays
Copy link
Owner

Alexays commented Nov 20, 2023

LGTM, thx!

@Alexays Alexays merged commit 061c68c into Alexays:master Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants