How to Hack gtk3-nocsd Into Flatpak Applications

WARNING: Use at your own risk. This is NOT a supported configuration and you’ll want to turn this off and re-test before reporting any bugs. (i.e. Report bugs gtk3-nocsd fixes, not ones it causes.)

OK, so you’ve got a desktop that’s using gtk3-nocsd and a GTK app that renders fine outside Flatpak, but does something unacceptably CSD-ish inside Flatpak. (For me, among other things, it’s non-GNOME GTK-using applications like Deluge displaying big black borders on things like context menus when KWin’s compositing is disabled.)

TIP: If it’s only the shadows on the context menus you don’t like, then it’s easier and more reliable to toss decoration, decoration:backdrop { box-shadow: none; } into your ~/.config/gtk-3.0/gtk.css.

The Flatpak developers don’t appear to see this as an issue, and not all applications have a good Qt-based counterpart, so what’s a stubborn “It’s my ****ing computer” person supposed to do?

…what about taking advantage of how Flatpak applications were already probably printing this to the terminal every time you launched them?

ERROR: object '' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

Here’s how you shoe-horn your gtk3-nocsd into Flatpak without rebuilding the Flatpak Runtime or the application package:

  1. Create a folder that Flatpak isn’t going to overlay, like /gtk3-nocsd and make sure it’s got the same 0755 root:root permissions as anything else nobody but root should be able to muck in.
  2. sudo cp -p /usr/lib/x86_64-linux-gnu/ /gtk3-nocsd (substitute whatever path your host distro uses for the original, non-symlinked library file and note the -p to preserve the permissions and ownership. You need the sticky bit to pass certain safety checks.)
  3. Go into Flatseal or use flatpak override and grant your application filesystem access to /gtk3-nocsd:ro, then add an environment variable override to LD_PRELOAD=/gtk3-nocsd/

Congratulations. For better or for worse, you should now have your Flatpak’d application loading gtk3-nocsd like an un-Flatpak’d application. It seems to have solved the “big black borders on context menus with compositing disabled” issue in Deluge-GTK for me… but I make no guarantees that it’ll work for you.

You can check if it’s getting loaded by:

  1. flatpak enter <app ID> sh
  2. ps ax to get the PID of the process (probably 2 in my experience)
  3. grep nocsd /proc/<PID>/maps

In theory, you could do this in Flatseal’s “All Applications” tab, but why tempt fate. Do as I did. Apply it selectively to just the applications that exhibit problems.

I doubt the Flatpak devs will ever enable‘s secure execution mode, since it disables LD_LIBRARY_PATH, which is used in some launcher scripts to make some applications find their libraries under /app rather than /usr/lib (I had to use it to get a custom build of SDL_mixer to find libmodplug at runtime even though it found it without issue at compile time) but, if so, the next step would be to try injecting into /var/lib/flatpak/runtime/org.freedesktop.Platform/x86_64/<VERSION>/active/files/lib/ so it’ll show up in the list of standard paths‘s secure mode is whitelisted to.

CC BY-SA 4.0 How to Hack gtk3-nocsd Into Flatpak Applications by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This entry was posted in Geek Stuff. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution under the same terms as the associated post.

All comments are moderated. If your comment is generic enough to apply to any post, it will be assumed to be spam. Borderline comments will have their URL field erased before being approved.