Linux – Notifications and notification daemon not working on window manager

arch linuxlibnotifynotifications

Notifications doesn't work on Linux standalone window managers (Openbox, Awesome WM and alike). I tried to install notification-daemon and dunst, but sending with notify-send "something" does not make any window to pop-up.

I tried to run polkit-gnome-agent and run directly notification daemons, but it does not help (while ago I solved similar problem in this way, but now it does nothing).

There is no any indications of errors unless I send trivial notification with python, then I get only vague error message:

File "/usr/lib/python3.3/site-packages/gi/types.py", line 113, in function
    return info.invoke(*args, **kwargs)
gi._glib.GError: Could not connect: Connection refused

Trivial C program outputs nothing (no error for example).

I'm using Archlinux with systemd and d-bus, I suspect it's a problem with polkit or some kind daemon not runing on window manager start, but have no idea, what could I try or how could I get more meaningfull error messages.

EDIT: I took sample code from there: https://wiki.archlinux.org/index.php/Libnotify#Python

Dbus should be runing because systemd has it as dependency. I have libnotify installed – it is package which provides notify-send. Also notification daemon should start as needed (only when notification arives), by following desktop file /usr/share/dbus-1/services/org.freedesktop.Notifications.service :

[D-BUS Service]
Name=org.freedesktop.Notifications
Exec=/usr/bin/dunst

I had even tried to run daemons directly (just execute) and tried sending notifications. If somenone knows how I could get me more info, please do not hesitate to suggest.

EDIT 2: I tried running notification daemon with sudo: sudo notification-daemon_name & (in my case sudo dunst &) and sudo notify-send something, then notification works. But when I try to do any of the previous actions as unprivileged user (which is important most programs send notification as unprivileged users), nothing shows.

notification-daemon refuses to work at all without any error or warning.

EDIT 3: Clearly it is permissions problem: I can't send notifications without root access. After clean reboot: sudo notify-send "something" works even without manually launching any daemons, however what I (and my launched programs) should do to be able send notifications without root privilegies as it is possible in Gnome or any other full desktop environments?

Best Answer

Finally I solved problem myself.

I will leave instructions what I did.

The problem consists of two parts:

  1. Dbus cannot be accessed from within windows manager
  2. Notification daemon cannot get messages from dbus

1st problem solution:

Real problem was, that my windows manager was run from lxdm, which for some reason does not merges config files from /etc/X11/xinit/xinitrc.d except for lxde session (in LXDE dbus works, in awesome wm doesn't). In this folder exists file named 30-dbus with following content:

#!/bin/bash

# launches a session dbus instance
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && type dbus-launch >/dev/null; then
  eval $(dbus-launch --sh-syntax --exit-with-session)
fi

This part of the code defines $DBUS_SESSION_BUS_ADDRESS variable which defines a dbus port to use for various applications. echo $DBUS_SESSION_BUS_ADDRESS can be used as simple sanity check to see if dbus session exists (it should return dbus session file).

Config files from this folder can be merged with simple shell script on session start(code taken from .xinitrc):

#!/bin/bash

if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

2nd problem solution:

While dbus running and is available to other programs it still needs more access for notifications to work properly, so I needed to run polkit agent, because Awesome WM does not have one. I had chosen lxpolkit, because I already had almost full lxde environment. In my case, just added to my ~/.config/awesome/rc.lua file: awful.util.spawn_with_shell("dex /etc/xdg/autostart/lxpolkit.desktop") , for some reason without this line it refused to start by default with lxdm.

I think gnome polkit agent should work fine too.

Related Question