Tomas-M / xlunch

Graphical app launcher for X with minimal dependencies
http://xlunch.org
GNU General Public License v3.0
219 stars 35 forks source link

Add SVG icons rendering #22

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello, some applications aren't shown in the menu, example Mumble, I have realised the icons which aren't displayed are all SVG (yes, imlib2 doesn't render it, I didn't know). So I think it would be nice to add svg support through librsvg to render them.

Here is the genicons scripts I adapted if you want:

#!/bin/bash

APPS=/usr/share/applications
ICONS=/usr/share/icons/hicolor
SIZE=48

echo "Generating config file from $APPS ..." >&2

find $APPS -name "*.desktop" | while read DESKTOPFILE; do
   FDATA="$(cat $DESKTOPFILE)"
   NAME="$(echo "$FDATA" | grep -i "^Name=" | head -n 1 | cut -d "=" -f 2-)"
   EXEC="$(echo "$FDATA" | grep -i "^Exec=" | head -n 1 | cut -d "=" -f 2-)"
   ICON="$(echo "$FDATA" | grep -i "^Icon=" | head -n 1 | cut -d "=" -f 2-)"
   USETERM="$(echo "$FDATA" | grep -i "^Terminal=" | head -n 1 | cut -d "=" -f 2-)"

   if [ "$USETERM" = "true" ]; then
      EXEC="$TERM -e ""$EXEC"
   fi

   if [ "$ICON" != "" ]; then
      ICON="$(find "$ICONS" | grep $SIZE"x"$SIZE | grep $ICON"[.]png" | head -n 1)"
      if [ "$ICON" != "" -a "$EXEC" != "" -a "$NAME" != "" ]; then
         echo "$NAME;$ICON;$EXEC"
      else
        ICON="$(find "$ICONS" | grep "scalable" | grep -E $ICON"[.](png|svg)" | head -n 1)"
        if [ "$ICON" != "" -a "$EXEC" != "" -a "$NAME" != "" ]; then
           echo "$NAME;$ICON;$EXEC"
        fi
      fi
   fi
done | sort | uniq

It will add blank entries in xlunch, where you can click it but doesn't know which app is going to start, maybe you could just render the text without icon at first, and then maybe add svg support.

ghost commented 7 years ago

https://pics.unixcorn.org/GkClPU4o/RWKVkgU5.png

I'm trying to make it render a default icon to applications that have icons that wouldn't be rendered. I'll make another pull request for that if you're okay.

EDIT: some progress: https://pics.unixcorn.org/QgjaYY8u/sLDdVRKf.png about the Ghost PNG, it's a public domain image I found on Pixabay and edited a bit. I wonder if you'd prefer to set the DATA32 directly into the code or if it's okay to provide the picture ie in /etc/xlunch/ for packagers as well.

Tomas-M commented 7 years ago

Hello, thank you very much for your patches. It looks reasonable, so I'll probably merge them. I would like to test them first, but I'm not so good in this git/github thing, could you suggest how do I pull your patches from github to my local git tree? I'm lazy to copypaste the diffs one by one and I would really like to learn how to do this more easily since there may be more people offering patches in the future :) Thank you!

ghost commented 7 years ago

Hey @Tomas-M thanks. You may test directly from cloning my fork: git clone https://github.com/fwhcat/xlunch

For my tests, I made a ghost.png icon and put it in /etc/xlunch, which isn't the right path, We should move it to /usr/share/icons/applications/ I guess.

ghost commented 7 years ago

Fixed in 21fb1e41ecbd3cf2e8723511d5424982224e3c97

NB: SVG are not rendered but displayed with a ghost png icon, so that we don't add another dependency. We might rely on librsvg in the future for SVG rendering.