tofi icon indicating copy to clipboard operation
tofi copied to clipboard

Display application icon

Open jirutka opened this issue 2 years ago • 9 comments

Could you please consider adding support for displaying the application icons?

jirutka avatar Jul 27 '22 20:07 jirutka

I knew someone would ask eventually :smile: I'll look into it, but I don't know how long it'll take. Thankfully the Icon Theme Specification provides some pseudocode showing the algorithm to use to find an icon, so maybe it won't be so bad.

philj56 avatar Jul 29 '22 07:07 philj56

Ok, so this has turned out to be much more complicated than I'd feared. There's a combination of factors:

  • The icon theme spec is really quite complex.
  • The icons apps provide are inconsistent, so I'd have to implement both SVG rendering with librsvg and scaling of PNGs to not have missing icons.
  • The real killer: there's no good way to cache the necessary icons, as these can change e.g. every time you change your tofi config or switch to a different monitor. Without caching, the lookup will be very slow every time, which goes against the nature of tofi. Even in rofi, which is generally an order of magnitude (or more) slower to startup, icon loading is delayed until after startup, causing pop-in and more complexity.

Given all that, and the fact that I never used to use them in rofi anyway, I'm gonna abandon icons for now, though I may come back to it or look at it when I've got nothing else to do.

philj56 avatar Aug 04 '22 14:08 philj56

Hello. Any news about this feature?

timsofteng avatar Oct 13 '22 19:10 timsofteng

Hi, not so far. The main problem is still as written above; I don't think there's a good way to make this quick. I do plan on having a more detailed look into this at some point, as it may not be as slow as I thought (especially SVG rendering, a random set of benchmarks suggest that resvg could be fast enough). There's other, easier improvements to make first though.

philj56 avatar Oct 13 '22 23:10 philj56

@philj56 how about lazy loading the icons? So we show the list of results first with a placeholder for icon (so it does not change width and high of the list items when they are loaded) and load the icons when there are ready.

Is that possible or are there other things that will not allow this approach?

I am new in that space so sorry if it's a dumb question.

616b2f avatar Jan 10 '23 07:01 616b2f

Not dumb at all :slightly_smiling_face:. I think if this was to be done, lazy loading would be the most likely way. Compared to the current ~2-20ms startup time for the Harfbuzz backend, loading icons will probably always be much slower (though I still haven't got round to looking at this in more detail).

The main problem with that is just complexity. For context, at an extremely simplified level, tofi's architecture is pretty much:

initialise_everything();
while (true) {
    wait_for_keypress();
    handle_keypress();
    render();
}

Everything is single-threaded, as just the time taken to spawn and join new threads makes them not really worth it at the 1-2ms level.

The dependencies are split into a few categories:

  • Drawing (Cairo)
  • Text rendering (FreeType, HarfBuzz, Pango)
  • Wayland (libwayland, xkbcommon)
  • Miscellaneous (GLib - already required by Cairo / Pango / Harfbuzz)

To add lazily-loaded icons implies a few things:

  • Logic to find and load icons (quite complicated as mentioned above, but not too bad)
  • At least some level of multi-threading (probably just a single extra thread loading & passing icons back to the main thread)
  • Dependence on an SVG library (libpng is "free", as it's already depended upon by FreeType / Cairo)

None of these are show-stoppers, but altogether it implies a fair amount of extra complexity. Combined with the fact that icons will never be as fast as the rest of tofi, they're pretty low on my priority list. I do still plan on giving them a more thorough go at some point though, as I understand the demand is fairly high (I guess it's the biggest feature that tofi's missing compared to rofi).

philj56 avatar Jan 10 '23 21:01 philj56

Maybe put the extra complexity in a seperate tool like tofi-thumbnailer. It could produce png from svg so that there is no extra dependency within tofi. It would also address the performance issue

bbusse avatar Apr 06 '23 07:04 bbusse

For icons in general one can always use font awesome or some unicode icons but then the assignment has to be done manually

bbusse avatar Apr 06 '23 07:04 bbusse

Or you could have a small plugin or patch system like dwm if plugins are too complicated. This would allow people who don't care much about performance use it. I only switched to tofi after trying every other option being not customizable at all or just too slow, tofi doesn't have both of those issues!

hamzashahid-blit avatar Jul 20 '23 12:07 hamzashahid-blit