Aral Balkan

Mastodon icon RSS feed icon

How to disable Gtk-Message warnings in your app

A Rube-Goldberg machine: the tears of a woman peeling onions is funnelled into a pie that tips some scales that activate a blower that then lead to a number of other things (the end result is not shown in the detail).

So every elementary OS app at the moment, if you start it from Terminal, welcomes you with a variation of the following salutation:

Gtk-Message: … : Failed to load module "canberra-gtk-module"
Gtk-Message: … : Failed to load module "canberra-gtk-module"

Isn’t that friendly?

The journey begins…

I initially thought this was a long-standing issue with Flatpak (and I was a shady bitch about it too) but, thanks to a detailed write-up by Simon McVittie, we now know that it is more likely due to a configuration mismatch between the host OS (in this case elementary OS 6) and the runtime in your Flatpak.1

So just turn off those warnings in your app if they bother you so much, I hear you say.

Well, reader, it’s not that simple.

After hitting my head on a brick wall (also known as GNOME/GTK documentation) for a few hours to no avail, I opened an issue on the GTK tracker, using it like Discourse as if I’d been raised in a barn like some sort of animal.

Thanks to Emmanuele Bassi’s hints in his response, I was able to finally find a way to disable the Gtk-Message warnings.

A happy ending

All you have to do2, see, is create a custom log writer function.

Here’s an excerpt of the relevant bits from the app I’m building in case they help you too:

public class Application : Gtk.Application {
    public static string flatpak_id;
    public static bool is_running_as_flatpak;

    public Application () {

    public static int main (string[] commandline_arguments) {
        flatpak_id = Environment.get_variable ("FLATPAK_ID");
        is_running_as_flatpak = flatpak_id != null;

        if (is_running_as_flatpak) {
            Log.set_writer_func (log_writer);
        }

        return new Application ().run (commandline_arguments);
    }

    private static LogWriterOutput log_writer (LogLevelFlags log_level, [CCode (array_length_type = "gsize")] LogField[] fields) {
        return log_level == LogLevelFlags.LEVEL_MESSAGE ? LogWriterOutput.HANDLED : LogWriterOutput.UNHANDLED;
    }
}

Epilogue

Hopefully, knowing the folks at elementary OS, they’ll get to the bottom of the issue so we won’t need this workaround in the near future.

In the meanwhile, I plan on adding this to Watson – the best-practices application template for elementary OS 6 (Odin) that I’m working on, so that any apps created based on it will silence these warnings by default.

There is a lot to admire about Gtk+, really there is3, but sometimes it does feel like you have to construct a Rube Goldberg machine just to do the simplest things.

Like this? Fund us!

Small Technology Foundation is a tiny, independent not-for-profit.

We exist in part thanks to patronage by people like you. If you share our vision and want to support our work, please become a patron or donate to us today and help us continue to exist.


  1. Also, according to Simon, as apps are ported to GTK4, the problem should go away as “GTK 4 no longer supports loading arbitrary modules specified in GTK_MODULES”. ↩︎

  2. Sarcasm. ↩︎

  3. Not sarcasm. ↩︎