I was looking into the realm of desktop notifications in Linux. How do I show custom notifications on my desktop? Will the same code work on my PinePhone?
Yes! Thanks to standardization, D-Bus, libnotify etc. this can be done. You need a server which shows the notifications and a client which submits the notifications. Naturally, ArchLinux Wiki has a great entry on this: Desktop notifications. It even provides example client source code for various languages.
Some desktop environments provide their own server built-in, some do not. Luckily there are a bunch of standalone solutions available. Plus you can customize these to your liking.
I’m running SwayWM on my desktop, so I needed to install a standalone server. Dunst is a nice and minimalistic solution, though currently just for X11 (e.g. dwm). Finally, I chose mako – a Wayland-native daemon built for Sway. Fun sidenote: mako started as a “Gah! This is too hard to port” response to this Dunst issue to support Wayland.
On the PinePhone this was simple – Phosh already provides a notifications server. It shows notifications in the top pull-down panel, just like in other phone UIs.
Running e.g. this Python code from the ArchLinux wiki is all you need!
from gi.repository import Notify
Hello = Notify.Notification.new("Hello world", "This is an example notification.", "dialog-information")
Sharing the same tools, code and APIs between a desktop and a phone is just awesome.