Unable to show notifications


Im on Ubuntu 20.10, i have a small test application.
Whatever i do it does not show a notification in Gnome.

Other applications work fine, notify-send works fine.

Are there any requirements for an application to issue a notification?

Sample App

import sys
import gi
import cairo

gi.require_version("Gtk", "3.0")
from gi.repository import GLib, Gio, Gtk

class Application(Gtk.Application):
    def __init__(self, *args, **kwargs):
        self.window = None
        self.connect('activate', self._activate)

    def _activate(self, _application):
        if not self.window:
            self.window = AppWindow(self, "Main Window")


class AppWindow(Gtk.ApplicationWindow):
    def __init__(self, application, title):
        super().__init__(application=application, title=title)

        button = Gtk.Button(label='button')
        button.connect('clicked', self._send)


    def _send(self, *args):
        notification = Gio.Notification()
        print('send notification')
        self.get_application().send_notification('notif', notification)

if __name__ == "__main__":
    app = Application()

An org.example.mytestapp.desktop file in a location where it is picked up by gnome-shell (/usr/share/applications, /usr/local/share/applications, $HOME/.local/share/applications, …).

I assume you’re using GNOME Shell.

Yes, you need an installed desktop file with the same name as your application id—so, in this case, you need an org.example.mytestapp.desktop file.

The GNotification API will use the org.gtk.Notification D-Bus interface when running under GNOME; this interface requires a desktop file for your application, to allow the shell to match the notification to the application that sent it, and to allow the notification to re-launch the application if the application instance goes away before the user has acknowledged the notification.

When running outside of GNOME, GNotification will use the old org.freedesktop.Notification D-Bus interface, which does not have these capabilities.

Likely because they either use the old org.freedesktop.Notification interface directly, or because they have a desktop file.

notify-send uses the old org.freedesktop.Notification D-Bus interface.

Thanks for the quick answer

Follow up question

Notifications work now, if i query org.freedesktop.Notifications for capablilities it reports “body-markup”.
its not possible to query org.gtk.Notifications.

if i add markup to my notifications like


it does not work, the text is not shown bold and the tags are still in the notification

and Ideas whats wrong here?

That’s because it (and by extension GNotification) doesn’t have the concept of “body-markup”.

Ok that clears up why it does not work


mentions that it is a MUST that implementations support GetCapabilities(), so are you saying this is not implemented in org.gtk.Notifications?

Is there a list what features of the spec it supports?

org.gtk.Notifications and org.freedesktop.Notifications are two different D-Bus interfaces that provide desktop notification functionality. The former is not an implementation of the latter or vice-versa.

No, because it does not implement that spec.

The org.gtk.Notification interface is documented on the wiki.

It is not the same API as org.freedesktop.Notification.

Is there a simple way to find out what notification backend GLib is using when my application is running?
I looked a bit at the GLib code, but i found no other way than to reimplement the same logic GLib uses.

No. Under GNOME, you’ll always use org.gtk.Notification, though; so if you detect that you’re running under GNOME, you can use that information.

In general, we strongly recommend against using markup in the notification body. You simply don’t know how it’ll be rendered on the other side.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.