X can have two ways of authorizing clients.
One way is using cookies; then you have to set DISPLAY=:0
and XAUTHORITY=/home/yourusername/.Xauthority
.
In your case I assume it is done with xhost, otherwise setting DISPLAY would not be enough. Type xhost
to see who is authorized.
Maybe you have an ~/.Xauthority
cookie along with xhost +SI:localuser:toothrot
authorization.
You can allow root to access display :0 with DISPLAY=:0 xhost +SI:localuser:root
, but you have to do it as normal user. Using the cookie is the better way:
DISPLAY=:0 XAUTHORITY=/home/toothrot/.Xauthority notify-send hullo
To execute notify-send as user:
su toothrot -c 'DISPLAY=:0 XAUTHORITY=/home/toothrot/.Xauthority notify-send hullo'
man xauth
. But I promise you a world of pain if you try to write a udev rule that affects your X session. Don't do that, try to find a proper solution, if necessary in layers, using a dbus interface, or whatever. (What should happen if there's no X session? What if there are two or more X sessions?). – dirkt Mar 01 '17 at 17:29