1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00
rofi/doc/rofi-thumbnails.5.markdown
giomatfois62 75ae2a41f0
[WIP] xdg thumbnails fetching with fallback on mimetype icons (#1939)
* implemented xdg thumbnails fetching with fallback on mimetype icons for menu entries in filebrowser mode

* included original license text

* added md5 header and source file

* implemented xdg compatible thumbnail's creation

* added -preview-cmd string option to program settings

* support custom command to create images for entries with thumbnail:// prefix

* fix custom thumbnailer command crash caused by null uri when entry is not a valid filename

* check entry_name is not NULL or empty when generating thumbnails;
use snprintf to avoid static analyzer complains

* avoid using gstrvbuilder to build thumbnailer command args

* fixed static analyzer complain about always wrong condition

* use g_spawn_check_exit_status to avoid bump to glib 2.70

* removed md5-c dependency and use glib checksum implementation

* fixed meson build after md5-c library removal

* support thumbnail generation in recursivebrowser mode

* restored check rofi_icon_fetcher_file_is_image

* create thumbnail directories if not existing

* use g_malloc0, g_strdup and g_strdup_printf

* fixed formatting with clang-format

* don't wait for jobs in execution when finalizing the icon fetcher worker threadpool

* destroy and rebuild the icon fetcher worker threadpool when the current page is changed

* added query_started boolean member to IconFetcherEntry;
check if an icon fetcher query was started on an IconFetcherEntry and submit the query again otherwise

* force icon cache lookup even if the item has a valid icon_fetch_uid (the fetching job could have been discarded before starting)

* search binaries in PATH when executing thumbnailer command

* mark icon query as not started in threadpool item free_func

* added listview page_changed_callback; rebuild icon fetcher threadpool in page_changed_callback

* [listview] Add missing code documentation param

* Create rofi-thumbnails.5.markdown

* Updated documentation with apparmor issues and workaround

* [Doc] Ship rofi-thumbnails.5

With some formatting fixes

* use a more compact thumbnailer example

---------

Co-authored-by: giomatfois62 <giomatfois62@yahoo.it>
Co-authored-by: Dave Davenport <DaveDavenport@users.noreply.github.com>
Co-authored-by: lbonn <github@lbonnans.net>
2024-06-21 18:47:38 +02:00

3.7 KiB

rofi-thumbnails(5)

NAME

rofi-thumbnails - Rofi thumbnails system

DESCRIPTION

rofi is now able to show thumbnails for all file types where an XDG compatible thumbnailer is present in the system.

This is done by default in filebrowser and recursivebrowser mode, if rofi is launched with the -show-icons argument.

In a custom user script or dmenu mode, it is possible to produce entry icons using XDG thumbnailers by adding the prefix thumbnail:// to the filename specified after \0icon\x1f, for example:

echo -en "EntryName\0icon\x1fthumbnail://path/to/file\n" | rofi -dmenu -show-icons

XDG thumbnailers

XDG thumbnailers are files with a ".thumbnailer" suffix and a structure similar to ".desktop" files for launching applications. They are placed in /usr/share/thumbnailers/ or $HOME/.local/share/thumbnailers/, and contain a list of mimetypes, for which is possible to produce the thumbnail image, and a string with the command to create said image. The example below shows the content of librsvg.thumbnailer, a thumbnailer for svg files using librsvg:

[Thumbnailer Entry]
TryExec=/usr/bin/gdk-pixbuf-thumbnailer
Exec=/usr/bin/gdk-pixbuf-thumbnailer -s %s %u %o
MimeType=image/svg+xml;image/svg+xml-compressed;

The images produced are named as the md5sum of the input files and placed, depending on their size, in the XDG thumbnails directories: $HOME/.cache/thumbnails/{normal,large,x-large,xx-large}. They are then loaded by rofi as entry icons and can also be used by file managers like Thunar, Caja or KDE Dolphin to show their thumbnails. Additionally, if a thumbnail for a file is found in the thumbnails directories (produced previously by rofi or a file manager), rofi will load it instead of calling the thumbnailer.

If a suitable thumbnailer for a given file is not found, rofi will try to use the corresponding mimetype icon from the icon theme.

Custom command to create thumbnails

It is possible to use a custom command to generate thumbnails for generic entry names, for example a script that downloads an icon given its url or selects different icons depending on the input. This can be done providing the -preview-cmd argument followed by a string with the command to execute, with the following syntax:

rofi ... -preview-cmd 'path/to/script_or_cmd "{input}" "{output}" "{size}"'

rofi will call the script or command substituting {input} with the input entry icon name (the string after \0icon\x1fthumbnail://), {output} with the output filename of the thumbnail and {size} with the requested thumbnail size. The script or command is responsible of producing a thumbnail image (if possible respecting the requested size) and saving it in the given {output} filename.

Issues with AppArmor

In Linux distributions using AppArmor (such as Ubuntu and Debian), the default rules shipped can cause issues with thumbnails generation. If that is the case, AppArmor can be disabled by issuing the following commands

sudo systemctl stop apparmor
sudo systemctl disable apparmor

In alternative, the following apparmor profile con be placed in a file named /etc/apparmor.d/usr.bin.rofi

#vim:syntax=apparmor
# AppArmor policy for rofi

#include <tunables/global>

/usr/bin/rofi {
    #include <abstractions/base>

    # TCP/UDP network access for NFS
    network inet  stream,
    network inet6 stream,
    network inet  dgram,
    network inet6 dgram,

    /usr/bin/rofi mr,

    @{HOME}/ r,
    @{HOME}/** rw,
    owner @{HOME}/.cache/thumbnails/** rw,
}

then run

apparmor_parser  -r /etc/apparmor.d/usr.bin.rofi

to reload the rule. This assumes that rofi binary is in /usr/bin, that is the case of a standard package installation.