apgoetz / jolly

Apache License 2.0
13 stars 2 forks source link

Add support for icons #18

Closed 0323pin closed 1 year ago

0323pin commented 1 year ago

Hi,

I've been using jolly on my NetBSD system for a while now. I'm happy with the current theme support, even though, you keep an issue open related to theming.

I've been wondering how much work would be required to add support for icons?

Regards

apgoetz commented 1 year ago

Hi,

Sorry for the late reply, I have started working on icon support in the icon branch, although it is not quite ready for integration.

The implementation is split into support for 3 platforms:

I assume you are interested in the BSD implementation. This implementation leverages the Freedesktop icon specifications, and is dependent on the xdg-utils shell scripts for part of its lookup. (Jolly will default to blank gray icons with no error if xdg-utils is missing from path). Documentation has not been written yet, but there is a new config variable, config.ui.icon.theme that is used to determine which icon theme to use. If you do not set this variable to your desktop theme, Jolly will default to using hicolor (the default theme) which will not match the rest of your environment.

I have a list of topics that are still necessary before this change can be merged a new release of Jolly created:

If you have a chance, feel free to play around with the build, otherwise you are welcome to wait for the official release.

0323pin commented 1 year ago

@apgoetz Cool 😀 Thanks!

If you have a chance, feel free to play around with the build, otherwise you are welcome to wait for the official release.

I might have time to kick a build tomorrow or, Thursday. I'll will for sure give it a try.

0323pin commented 1 year ago

Hi,

I've built the package from the icon branch and added a dependency on xdg-utils. But, ...

Jolly will default to blank gray icons with no error if xdg-utils is missing from path

Exactly what I'm seeing. Would you mind pointing me to where in the code this is defined? I wonder if it could be related to the fact that we (NetBSD) install third-party apps in /usr/pkg/bin.

EDIT: I've just realized I might need to tell the compiler where to find xdg-utils. I'll see if I can find the time for testing this soon.

apgoetz commented 1 year ago

The icon logic for Jolly is split into 2 files, src/icon/mod.rs has the generic logic for all platforms, and then src/icon/linux_and_friends.rs has the implementation for freedesktop based icons.

Icon lookup on freedesktop happens in a couple of phases:

1) determine if the jolly entry is url-like -> look up the desktop entry of that url using xdg-settings shell script 2) if it is not url-like, check if jolly entry is file-like -> lookup up mime type using xdg_mime crate.

once you have the desktop-entry or mime-type, the icon is looked up using freedesktop_icon crate.

So we only actually need xdg-utils if you want to look up a URL style entry. However, file type entries depends on mime types being installed, which means there is also a dependency on the shared-mime-info package.

So far I have been developing this on a desktop machine with a working Debian install, which I have realized is masking some of the issues with the icon logic, since it already installs a lot of packages for free. I switched to running the tests in a dedicated ubuntu docker VM that starts with the minimal packages, and have identified that you also need the shared-mime-info package, as mentioned above.

Finally, the icon logic only has support for raster based icon themes, not SVG based icon themes. I have been testing using the gnome-icon-theme set, because that is what I use on my development machine. If you prefer to use a different icon theme that is only svg based, for example, Papirus theme, then icons will also not be loadable.

(something else to fix before publishing)

0323pin commented 1 year ago

Thanks for the walk through 👍

~> pkg_info | grep xdg
xdg-utils-1.1.3nb3  Tools to assist applications with various desktop integration tasks
~> pkg_info | grep shared-mime
shared-mime-info-2.2nb2 Core database of common types
~> pkg_info | grep gnome
Exception: grep exited with 1

Finally, the icon logic only has support for raster based icon themes, not SVG based icon themes

~> ls /usr/pkg/share/icons/
drwxr-xr-x pin  wheel 512 B Wed Jun  7 11:28:38 2023  Green-Maia
drwxr-xr-x root wheel 512 B Wed Jun 21 15:31:50 2023  hicolor

Green-Maia is a SVG based icon theme.

So, that's it than. It explains why I only get gray squares.

apgoetz commented 1 year ago

I updated the icon branch with support for SVG icons now. Although i am sure there are still other issues. The build script will now also check for shared-mime-info and xdg-utils, as well as that the default theme is installed. You can override which theme Jolly will use as default at compile time using the environment variable JOLLY_DEFAULT_THEME. So if you run the tests, it should still pass if you choose a different theme that is installed on your machine.

0323pin commented 1 year ago

@apgoetz I've been busy at work but, I'll have sometime for this the coming weekend, so I'll report back then.

The following check in build.rs might fail, though.

if xdg_data_dirs.is_empty() {
        xdg_data_dirs = "/usr/local/share/:/usr/share/".into()

We use /usr/pkg/... as default ${PREFIX} but, let's see.

0323pin commented 1 year ago

I've finally had the time to do a test build but,

warning: Jolly default icon theme 'gnome' does not seem to be installed. You can override the default theme via environment variable JOLLY_DEFAULT_THEME
warning: package `shared-mime-info` does not seem to be installed. Icon support may be broken

Even though I now have xdg-utils, shared-mime-info and gnome-icon-theme installed.

Here's the package Makefile:

# $NetBSD: Makefile,v 1.5 2023/06/06 12:42:53 riastradh Exp $

DISTNAME=   jolly-0.2.0
CATEGORIES= x11
MASTER_SITES=   ${MASTER_SITE_GITHUB:=apgoetz/}
GITHUB_TAG= af38644da53e0371e0830f03e548365327037272

MAINTAINER= pin@NetBSD.org
HOMEPAGE=   https://github.com/apgoetz/jolly/
COMMENT=    Small bookmarking launcher for desktop usage
LICENSE=    mit OR apache-2.0

TOOL_DEPENDS+=      cmake-[0-9]*:../../devel/cmake

.include "cargo-depends.mk"

USE_LANGUAGES+= c c++
USE_TOOLS+= pkg-config

INSTALLATION_DIRS=  bin share/examples/jolly share/icons/hicolor/scalable/apps

RUSTFLAGS+= -C link-arg=${COMPILER_RPATH_FLAG}${BUILDLINK_PREFIX.libX11}/lib
RUSTFLAGS+= -C link-arg=-L${BUILDLINK_PREFIX.libX11}/lib
RUSTFLAGS+= -C link-arg=${COMPILER_RPATH_FLAG}${BUILDLINK_PREFIX.freetype2}/lib

do-install:
    ${INSTALL_PROGRAM} ${WRKSRC}/target/release/jolly \
        ${DESTDIR}${PREFIX}/bin
    ${INSTALL_DATA} ${WRKSRC}/docs/jolly.toml \
        ${DESTDIR}${PREFIX}/share/examples/jolly
    ${INSTALL_DATA} ${WRKSRC}/icon/jolly.svg \
        ${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps

DEPENDS+=   xdg-utils-[0-9]*:../../misc/xdg-utils

.include "../../lang/rust/cargo.mk"
.include "../../x11/libX11/buildlink3.mk"
.include "../../graphics/freetype2/buildlink3.mk"
.include "../../fonts/fontconfig/buildlink3.mk"
.include "../../graphics/hicolor-icon-theme/buildlink3.mk"
.include "../../databases/shared-mime-info/buildlink3.mk"
.include "../../graphics/gnome-icon-theme/buildlink3.mk"
.include "../../mk/bsd.pkg.mk"

and here's my jolly.toml

# jolly.toml

[config.ui]
width               = 600
text_size           = 12
max_results         = 8

[config.ui.theme]
accent_color        = "#F2BDBF"
background_color    = "#2A2A2D"
text_color          = "#F28DBF"
selected_text_color = "#2A2A2D"

[config.ui.search]
text_size           = 14

[config.ui.entry]
text_size           = 12

['Spotify']
system             = 'alacritty -e spotify_player'

['RSS']
system             = 'alacritty -e tuifeed'

['Matrix']
system             = 'alacritty -e iamb'

['Firefox']
system             = 'env LD_PRELOAD=/usr/X11R7/lib/libEGL.so firefox'

['pdf-reader']
system             = 'xpdf -rv'

['Qt-theme']
system             = 'qt5ct'

['FeatherPad']
system             = 'featherpad'

['Screenshot']
system             = 'scrot -d2'

Still getting just gray-squares.

apgoetz commented 1 year ago

Thanks for providing your config, that helps to narrow down the issues.

Jolly uses the XDG Base Directory specification to try and find mime types and icons. This is done with a bunch of helper crates, but it boils down to looking for icons and mime types in the folders specified by the XDG_DATA_DIRS path. If this environment variable is not set, then Jolly (and some if its dependent crates) fall back to the default value in the spec: "/usr/local/share/:/usr/share/". Since the default NetBSD $PREFIX is /usr/pkg, this means Jolly can`t find any icons. (hence the warnings during compilation).

To fix this, you can try and make sure the environment variable $XDG_DATA_DIRS contains the /usr/pkg prefix. Setting this should prevent the warnings during compilation, but it will also need to be set when running Jolly.

Also, even if you can get the theme to work, you might not be happy with what you get. It seems like you are mostly using Jolly to launch specific applications directly via their executable. Currently, Jolly doesn't know how to look up the icon for an executable if you specify a system entry. This could be another improvement to icon handling.

In the meantime, you could try using the new icon field to specify a direct path to the icon image to use. For example:

['Firefox']
system             = 'env LD_PRELOAD=/usr/X11R7/lib/libEGL.so firefox'
icon  = '/usr/pkg/icons/hicolor/48x48/apps/firefox.png' #or wherever NetBSD stashed the firefox icon

This also requires that the specified icon be raster, not svg.

Also, you mentioned earlier that you use the Green-Maia theme in your desktop. You can specify that you want to use this icon theme by adding the following lines to your jolly.toml

[config.ui.icon]
theme = "Green-Maia"

If you are still having trouble getting the icons to load, it might help to see the output of any failed tests. Try executing via XDG_DATA_DIRS="/usr/pkg" cargo test

0323pin commented 1 year ago

Thanks! It is inline with the thought I had expressed earlier.

you can try and make sure the environment variable $XDG_DATA_DIRS contains the /usr/pkg prefix. Setting this should prevent the warnings during compilation, but it will also need to be set when running Jolly.

Yes, I can set this in my environment. But I might try to set it at build time. Something like MAKE_FLAGS+= PREFIX=${PREFIX} should pass the variable to the build environment.

Also, even if you can get the theme to work, you might not be happy with what you get. It seems like you are mostly using Jolly to launch specific applications directly via their executable.

Sorry if this is not one of your goals but, my use of jolly is kind of a replacement for rofi with the ability to extend it to specific web-sites :)

you could try using the new icon field to specify a direct path to the icon image to use.

Awesome, exactly what I needed. Thank you also for the input regarding [config.ui.icon]