Skip to content

Commit

Permalink
[Doc] Ship rofi-thumbnails.5
Browse files Browse the repository at this point in the history
With some formatting fixes
  • Loading branch information
lbonn committed Jun 19, 2024
1 parent 90c4ea8 commit 6acf5db
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
9 changes: 7 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ generate-manpage: doc/rofi.1\
doc/rofi-dmenu.5\
doc/rofi-keys.5\
doc/rofi-script.5\
doc/rofi-theme.5
doc/rofi-theme.5 \
doc/rofi-thumbnails.5

doc/rofi.1: doc/rofi.1.markdown
pandoc --standalone --to=man --lua-filter=$(top_srcdir)/doc/man_filter.lua -f markdown-tex_math_dollars -o ./$@ ./$<
Expand All @@ -204,6 +205,8 @@ doc/rofi-script.5: doc/rofi-script.5.markdown
pandoc --standalone --to=man --lua-filter=$(top_srcdir)/doc/man_filter.lua -f markdown-tex_math_dollars -o ./$@ ./$<
doc/rofi-theme.5: doc/rofi-theme.5.markdown
pandoc --standalone --to=man --lua-filter=$(top_srcdir)/doc/man_filter.lua -f markdown-tex_math_dollars -o ./$@ ./$<
doc/rofi-thumbnails.5: doc/rofi-thumbnails.5.markdown
pandoc --standalone --to=man --lua-filter=$(top_srcdir)/doc/man_filter.lua -f markdown-tex_math_dollars -o ./$@ ./$<

endif

Expand All @@ -217,10 +220,12 @@ dist_man5_MANS=\
doc/rofi-dmenu.5\
doc/rofi-keys.5\
doc/rofi-script.5\
doc/rofi-theme.5
doc/rofi-theme.5\
doc/rofi-thumbnails.5

EXTRA_DIST += \
doc/rofi-theme.5.markdown \
doc/rofi-thumbnails.5.markdown \
doc/rofi-debugging.5.markdown \
doc/rofi-script.5.markdown \
doc/rofi-keys.5.markdown \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ new issue.
- [rofi-debugging](doc/rofi-debugging.5.markdown)
- [rofi-script](doc/rofi-script.5.markdown)
- [rofi-theme-selector](doc/rofi-theme-selector.1.markdown)
- [rofi-thumbnails](doc/rofi-thumbnails.5.markdown)
- [rofi-keys](doc/rofi-keys.5.markdown)
- [rofi-dmenu](doc/rofi-dmenu.5.markdown)

Expand Down
1 change: 1 addition & 0 deletions doc/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ man_files = [
'rofi-keys.5',
'rofi-script.5',
'rofi-theme.5',
'rofi-thumbnails.5',
]

fs = import('fs')
Expand Down
33 changes: 24 additions & 9 deletions doc/rofi-thumbnails.5.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,53 @@

## 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.
**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:

```bash
echo -en "EntryName\0icon\x1fthumbnail://path/to/file\n" | rofi -dmenu -show-icons
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 `ffmpegthumbnailer.thumbnailer`, a thumbnailer for video files using ffmpeg:

```
[Thumbnailer Entry]
TryExec=ffmpegthumbnailer
Exec=ffmpegthumbnailer -i %i -o %o -s %s -f
MimeType=video/jpeg;video/mp4;video/mpeg;video/quicktime;video/x-ms-asf;video/x-ms-wm;video/x-ms-wmv;video/x-ms-asx;video/x-ms-wmx;video/x-ms-wvx;video/x-msvideo;video/x-flv;video/x-matroska;application/mxf;video/3gp;video/3gpp;video/dv;video/divx;video/fli;video/flv;video/mp2t;video/mp4v-es;video/msvideo;video/ogg;video/vivo;video/vnd.divx;video/vnd.mpegurl;video/vnd.rn-realvideo;application/vnd.rn-realmedia;video/vnd.vivo;video/webm;video/x-anim;video/x-avi;video/x-flc;video/x-fli;video/x-flic;video/x-m4v;video/x-mpeg;video/x-mpeg2;video/x-nsv;video/x-ogm+ogg;video/x-theora+ogg
```
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.

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 ... -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.

**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
Expand All @@ -63,8 +75,11 @@ In alternative, the following apparmor profile con be placed in a file named /et
owner @{HOME}/.cache/thumbnails/** rw,
}
```
then run

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.

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

0 comments on commit 6acf5db

Please sign in to comment.