DEV Community

Cover image for Conquering Flatpak Icons on LXDE (Pop!_OS Edition)
Ericson Willians
Ericson Willians

Posted on

Conquering Flatpak Icons on LXDE (Pop!_OS Edition)

When you’ve installed Pop!_OS but decided to ditch GDM3, switch to LXDE, and generally tinker with your system, you might find yourself icon-less in your old-school LXDE menu. Flatpak applications sometimes place .desktop files and icons in locations that certain desktop environments don’t automatically scan. Result? Ugly placeholders or missing shortcuts in the LXDE menu.

This article presents a Perl script that:

  1. Gathers Flatpak .desktop files from typical directories (~/.local/share/flatpak/exports/share/applications, /var/lib/flatpak/exports/share/applications, etc.).
  2. Copies or updates them in your local ~/.local/share/applications folder.
  3. Generates an XML menu (flatpak-apps.menu) for both LXDE and GNOME.
  4. Recursively searches for icons in the local Flatpak “abyss” (I've tried scraping them online as well but that turned out to be somewhat hellish to accomplish).
  5. Updates the local hicolor icon cache.
  6. Optionally restarts your LXDE panel (via lxpanelctl) to immediately refresh the menu.

Why This Script Is Helpful

If you’ve tried switching from a more “stock” GNOME or KDE environment to LXDE:

  • You may have discovered that the default LXDE panel menu doesn’t automatically see your Flatpak entries.
  • Even if it sees the .desktop files, it might not display the right icons (or any icons at all).
  • Tools like desktop-file-validate or manual editing can be tedious if you have dozens of Flatpak apps installed.

This script automates the entire process—finding the .desktop files, fixing icon references, copying them to the correct directory, and building an up-to-date menu you can see in LXDE.


Quick Start

You can grab the full script here in this Gist by Ericson Willians.

1. Download the Script

wget https://gist.githubusercontent.com/EricsonWillians/eadef25d6c131fdd8d564bd11ff76387/raw/flatpak_migration.pl -O flatpak_migration.pl
Enter fullscreen mode Exit fullscreen mode

(Alternatively, copy & paste from the Gist into a local file.)

2. Make It Executable

chmod +x flatpak_migration.pl
Enter fullscreen mode Exit fullscreen mode

3. Run It

./flatpak_migration.pl
Enter fullscreen mode Exit fullscreen mode

You’ll see console output showing which .desktop files are processed, icons located, and so on. If a missing icon can’t be found, you’ll see a warning. Ultimately, the script updates your menu, sets up an index.theme if needed, runs gtk-update-icon-cache, and tries to restart the LXDE panel.

Pro Tip: If you’re running a slightly different distro or a custom environment, you may need to adapt directory paths or remove references to lxpanelctl if you’re not using LXDE. For example, you might only want to generate a GNOME menu.


Troubleshooting Tips

  1. Missing Icons

    • If the script cannot find icons locally (and you uncomment the web-scraping lines), it’ll attempt a naive fetch from GitHub or a domain you specify. If those URLs 404, you’ll see warnings.
    • In many cases, the local search—especially the recursive check in ~/.local/share/flatpak/app/—is enough to find the official icons.
  2. Duplicate or Overlapping Menu Entries

    • Because the script merges .desktop files from all Flatpak exports plus your local folder, you might see duplicates if you installed an app from both the user and system Flatpak repos. Removing one or the other typically resolves this.
  3. You Already Have a .desktop File

    • The script won’t overwrite your file if it’s unchanged. It does a quick compare to decide whether to copy. If they differ, you’ll see a “processed” message. If they’re identical, it won’t copy them again.
  4. Comments in Icon= Lines

    • If you had .desktop files with inline comments on the Icon= line, that can cause malformed URLs or weird icon names. We strip inline comments automatically, but it’s good practice to keep them on a separate line.

Why We Use Perl (Instead of Bash)

  • File-Finding Logic: The script uses File::Find to search for .desktop and icon files recursively, which can be more concise and robust than iterative find calls in Bash.
  • Better String Handling: With Perl, it’s easy to parse .desktop lines, manipulate icon paths, strip out #comments, etc.
  • Portability: Although not as universal as Bash, most Linux systems come with Perl installed. If not, it’s typically trivial to install.

Potential Customizations

  • Icon Size: We currently default to copying any found icon into the 48x48/apps subdirectory of ~/.local/share/icons/hicolor. Adjust the script if you prefer a different size or want to store multiple resolutions.
  • Desktop Environments: The script aims for LXDE and GNOME, but you can add more menu directories or skip some if you only use LXDE.
  • Online Scraping: The snippet that tries to fetch icons from GitHub or other repositories is commented out by default. Uncomment and configure it if you want the script to attempt retrieving missing icons from external sources.

When All Is Done

After running ./flatpak_migration.pl:

  1. Check your LXDE menu—there should be a new “Flatpak Applications” category or at least newly recognized apps.
  2. Look for correct icons. If you see missing icons, it might mean the script didn’t locate them. Add them manually or tweak the code to fetch from the right place.
  3. Profit from a more complete, better-labeled menu in your old-school environment—no more confusion about which Flatpak is which!

Conclusion

That’s it! If you’re a Pop!_OS user who’s swapped in LXDE or just a tinkerer who wants to unify your Flatpak icons and .desktop entries, this script can save you a ton of time. It scrapes the labyrinth of Flatpak folders, merges everything into a local, standard place, and then properly rebuilds your menus.

Remember: You can always find the full code in the GitHub Gist. Feel free to customize it to your liking—maybe remove the Gnome portion if you only use LXDE, or add advanced icon scraping from your favorite repositories.

Happy hacking, and enjoy your newly minted, icon-rich LXDE menu on Pop!_OS!

Top comments (0)