Difference between revisions of "Desktop notifications"
m (small typo much->many in program description) |
m (Add a link to an article on a python example) |
||
(20 intermediate revisions by 10 users not shown) | |||
Line 1: | Line 1: | ||
− | [[Category:Development | + | [[Category:Development]] |
− | + | [[es:Libnotify]] | |
− | + | [[ru:Libnotify]] | |
{{Article summary start|Summary}} | {{Article summary start|Summary}} | ||
− | {{Article summary text|This article discusses how to install | + | {{Article summary text|This article discusses how to install, configure and use libnotify for application development.}} |
{{Article summary heading|Related}} | {{Article summary heading|Related}} | ||
{{Article summary wiki|GTK+}} | {{Article summary wiki|GTK+}} | ||
Line 9: | Line 9: | ||
{{Article summary end}} | {{Article summary end}} | ||
− | '''Libnotify''' is an easy way to display desktop notifications and information in a small dialog. It | + | '''Libnotify''' is an easy way to display desktop notifications and information in a small dialog. It implements the [http://developer.gnome.org/notification-spec/ Desktop Notifications Specification] and it is already used by many open source apps like [[Evolution]], [[Pidgin]], etc. It has support for [[GTK+]] and [[Qt]] applications and is desktop independent. |
==Installation== | ==Installation== | ||
− | Libnotify can be installed with the package {{Pkg|libnotify}}, available in the [[ | + | Libnotify can be installed with the package {{Pkg|libnotify}}, available in the [[official repositories]]. |
In order to use libnotify, you have to install a notification server: | In order to use libnotify, you have to install a notification server: | ||
− | === | + | ===Builtin servers=== |
− | [[GNOME]] and [[KDE]] use their own implementations to display notifications, and you can't replace them. Their notification servers are started automatically on login to receive notifications from applications via DBus. | + | [[Cinnamon]], [[GNOME]] Shell and [[KDE]] use their own implementations to display notifications, and you can't replace them. Their notification servers are started automatically on login to receive notifications from applications via DBus. |
− | *{{Pkg| | + | * {{Pkg|cinnamon}} provides a notification server itself. Notifications are displayed at the top right corner of the screen. |
− | * | + | * {{Pkg|gnome-shell}} provides a notification server itself. Notifications are displayed at the bottom of the screen. |
− | *KDE uses knotify4 from package {{Pkg|kdebase-runtime}} to display notifications. Notifications are displayed at the bottom right corner of the screen. | + | * KDE uses '''knotify4''' from package {{Pkg|kdebase-runtime}} to display notifications. Notifications are displayed at the bottom right corner of the screen. |
− | ===Other | + | ===Other servers=== |
In other desktop environments, the notification server is launched on the first call via DBus. You can choose one of the following implementations: | In other desktop environments, the notification server is launched on the first call via DBus. You can choose one of the following implementations: | ||
− | *{{Pkg|xfce4-notifyd}} is a notification server for [[Xfce]], available in the | + | * {{pkg|notification-daemon}} is the notification server used by GNOME in Fallback Mode. Notifications are displayed at the top right corner of the screen. |
+ | :{{Note|notification-daemon doesn't have a DBus service file, so you have to [[autostart]] it. (Already done in GNOME Fallback Mode.) To start the daemon manually, execute the following command: {{ic|/usr/lib/notification-daemon-1.0/notification-daemon}}.}} | ||
+ | * {{Pkg|xfce4-notifyd}} is a notification server for [[Xfce]], available in the official repositories. | ||
:{{Tip|To configure xfce4-notifyd, run the following command in the terminal: {{ic|xfce4-notifyd-config}}.}} | :{{Tip|To configure xfce4-notifyd, run the following command in the terminal: {{ic|xfce4-notifyd-config}}.}} | ||
− | *{{ | + | * {{pkg|dunst}} is a minimalistic notification daemon for Linux designed to fit nicely into minimalistic windowmanagers like [[dwm]]. |
− | *{{ | + | * {{Pkg|notify-osd}} is a notification server for [[Unity]], available in the official repositories. |
+ | * {{Pkg|awn-extras-applets}} contains a notification-daemon applet for the [[Avant Window Navigator]], available in the official repositories. | ||
+ | * {{AUR|statnot}} is a small, lightweight notification daemon that can output notifications to the root window's title, stdout or FIFO pipes, making it integrate very well with tiling window managers. It's available in the [[Arch User Repository]] or as a [https://github.com/halhen/statnot git repo]. | ||
+ | * {{AUR|twmn}} is a notification system for tiling window managers. It's available in the [[Arch User Repository]] or as a [https://github.com/sboli/twmn git repo]. | ||
==Tips and tricks== | ==Tips and tricks== | ||
Line 43: | Line 48: | ||
====Boo==== | ====Boo==== | ||
− | *Dependency: {{ | + | *Dependency: {{Pkg|notify-sharp}} ({{Pkg|boo}}) |
*Makedependency: {{Pkg|boo}} | *Makedependency: {{Pkg|boo}} | ||
*Build with: {{ic|booc hello_world.boo}} | *Build with: {{ic|booc hello_world.boo}} | ||
Line 76: | Line 81: | ||
====C#==== | ====C#==== | ||
− | *Dependency: {{ | + | *Dependency: {{Pkg|notify-sharp}} |
*Build with: {{ic|mcs -pkg:notify-sharp hello_world.cs}} | *Build with: {{ic|mcs -pkg:notify-sharp hello_world.cs}} | ||
*Run with: {{ic|mono hello_world.exe}} | *Run with: {{ic|mono hello_world.exe}} | ||
Line 101: | Line 106: | ||
var Hello=new Notification ("Hello world!","This is an example notification.","dialog-information") | var Hello=new Notification ("Hello world!","This is an example notification.","dialog-information") | ||
Hello.show ()</nowiki>}} | Hello.show ()</nowiki>}} | ||
− | |||
− | |||
− | |||
====Java==== | ====Java==== | ||
Line 163: | Line 165: | ||
Or you can use the old, static python-notify bindings: | Or you can use the old, static python-notify bindings: | ||
− | *Dependency: {{Pkg| | + | *Dependency: {{Pkg|python2-notify}} |
{{hc|hello_world.py|<nowiki>#!/usr/bin/python2 | {{hc|hello_world.py|<nowiki>#!/usr/bin/python2 | ||
import pynotify | import pynotify | ||
Line 201: | Line 203: | ||
====Visual Basic .NET==== | ====Visual Basic .NET==== | ||
− | *Dependency: {{ | + | *Dependency: {{Pkg|notify-sharp}} |
*Makedependency: {{Pkg|mono-basic}} | *Makedependency: {{Pkg|mono-basic}} | ||
*Build with: {{ic|vbnc -r:/usr/lib/mono/notify-sharp/notify-sharp.dll hello_world.vb}} | *Build with: {{ic|vbnc -r:/usr/lib/mono/notify-sharp/notify-sharp.dll hello_world.vb}} | ||
Line 220: | Line 222: | ||
*[http://developer.gnome.org/libnotify/ Libnotify Reference Manual] | *[http://developer.gnome.org/libnotify/ Libnotify Reference Manual] | ||
*[http://milky.manishsinha.net/2009/03/29/working-with-libnotify/ C example] | *[http://milky.manishsinha.net/2009/03/29/working-with-libnotify/ C example] | ||
− | *[http:// | + | *[http://hashbang.fr/tutoriel-notify.html Python example] (french article) |
− |
Revision as of 08:17, 19 April 2013
Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end
Libnotify is an easy way to display desktop notifications and information in a small dialog. It implements the Desktop Notifications Specification and it is already used by many open source apps like Evolution, Pidgin, etc. It has support for GTK+ and Qt applications and is desktop independent.
Contents
Installation
Libnotify can be installed with the package libnotify, available in the official repositories.
In order to use libnotify, you have to install a notification server:
Builtin servers
Cinnamon, GNOME Shell and KDE use their own implementations to display notifications, and you can't replace them. Their notification servers are started automatically on login to receive notifications from applications via DBus.
- cinnamon provides a notification server itself. Notifications are displayed at the top right corner of the screen.
- gnome-shell provides a notification server itself. Notifications are displayed at the bottom of the screen.
- KDE uses knotify4 from package kdebase-runtime to display notifications. Notifications are displayed at the bottom right corner of the screen.
Other servers
In other desktop environments, the notification server is launched on the first call via DBus. You can choose one of the following implementations:
- notification-daemon is the notification server used by GNOME in Fallback Mode. Notifications are displayed at the top right corner of the screen.
- Note: notification-daemon doesn't have a DBus service file, so you have to autostart it. (Already done in GNOME Fallback Mode.) To start the daemon manually, execute the following command:
/usr/lib/notification-daemon-1.0/notification-daemon
.
- xfce4-notifyd is a notification server for Xfce, available in the official repositories.
- Tip: To configure xfce4-notifyd, run the following command in the terminal:
xfce4-notifyd-config
.
- dunst is a minimalistic notification daemon for Linux designed to fit nicely into minimalistic windowmanagers like dwm.
- notify-osd is a notification server for Unity, available in the official repositories.
- awn-extras-applets contains a notification-daemon applet for the Avant Window Navigator, available in the official repositories.
- statnotAUR is a small, lightweight notification daemon that can output notifications to the root window's title, stdout or FIFO pipes, making it integrate very well with tiling window managers. It's available in the Arch User Repository or as a git repo.
- twmnAUR is a notification system for tiling window managers. It's available in the Arch User Repository or as a git repo.
Tips and tricks
Write your own notify app
You can write your own libnotify display messages easily in many programming languages through GObject-Introspection or bindings, or you can simply use bash.
The following examples display simple a "Hello world" notification.
Bash
- Dependency: libnotify
hello_world.sh
#!/bin/bash notify-send 'Hello world!' 'This is an example notification.' --icon=dialog-information
Boo
- Dependency: notify-sharp (boo)
- Makedependency: boo
- Build with:
booc hello_world.boo
- Run with:
mono hello_world.exe
(orbooi hello_world.boo
)
hello_world.boo
import Notifications from "notify-sharp" Hello = Notification() Hello.Summary = "Hello world!" Hello.Body = "This is an example notification." Hello.IconName = "dialog-information" Hello.Show()
C
- Dependency: libnotify
- Build with:
gcc -o hello_world `pkg-config --cflags --libs libnotify` hello_world.c
hello_world.c
#include <libnotify/notify.h> void main () { notify_init ("Hello world!"); NotifyNotification * Hello = notify_notification_new ("Hello world", "This is an example notification.", "dialog-information"); notify_notification_show (Hello, NULL); }
C++
- Dependency: libnotifymmAUR from AUR
- Build with:
g++ -o hello_world `pkg-config --cflags --libs libnotifymm-1.0` hello_world.cc
hello_world.cc
#include <libnotifymm.h> int main(int argc, char *argv[]) { Notify::init("Hello world!"); Notify::Notification Hello("Hello world", "This is an example notification.", "dialog-information"); Hello.show(); }
C#
- Dependency: notify-sharp
- Build with:
mcs -pkg:notify-sharp hello_world.cs
- Run with:
mono hello_world.exe
hello_world.cs
using Notifications; public class HelloWorld { static void Main() { var Hello = new Notification(); Hello.Summary = "Hello world!"; Hello.Body = "This is an example notification."; Hello.IconName = "dialog-information"; Hello.Show(); } }
Genie
hello_world.gs
uses Notify init Notify.init ("Hello world") var Hello=new Notification ("Hello world!","This is an example notification.","dialog-information") Hello.show ()
Java
- Dependency: java-gnomeAUR from AUR
- Makedependency: java-environment
- Build with:
mkdir HelloWorld && javac -classpath /usr/share/java/gtk.jar -d HelloWorld HelloWorld.java
- Run with:
java -classpath /usr/share/java/gtk.jar:HelloWorld HelloWorld
HelloWorld.java
import org.gnome.gtk.Gtk; import org.gnome.notify.Notify; import org.gnome.notify.Notification; public class HelloWorld { public static void main(String[] args) { Gtk.init(args); Notify.init("Hello world"); Notification Hello = new Notification("Hello world!", "This is an example notification.", "dialog-information"); Hello.show(); } }
JavaScript
hello_world.js
#!/usr/bin/gjs Notify = imports.gi.Notify; Notify.init ("Hello world"); Hello=new Notify.Notification ({summary: "Hello world!", body: "This is an example notification.", "icon-name": "dialog-information"}); Hello.show ();
Perl
- Dependencies: libnotify, perl-glib-object-introspectionAUR from AUR
hello_world.pl
#!/usr/bin/perl use Glib::Object::Introspection; Glib::Object::Introspection->setup ( basename => 'Notify', version => '0.7', package => 'Notify'); Notify->init; my $hello = Notify::Notification->new("Hello world!", "This is an example notification.", "dialog-information"); $hello->show;
Or you can use the old, static perl-gtk2-notify bindings:
- Dependency: perl-gtk2-notifyAUR from AUR
hello_world.pl
#!/usr/bin/perl use Gtk2::Notify -init, "Hello world"; my $hello = Gtk2::Notify->new("Hello world!", "This is an example notification.", "dialog-information"); $hello->show;
Python
- Dependencies: libnotify, python-gobject
hello_world.py
#!/usr/bin/python from gi.repository import Notify Notify.init ("Hello world") Hello=Notify.Notification.new ("Hello world","This is an example notification.","dialog-information") Hello.show ()
Or you can use the old, static python-notify bindings:
- Dependency: python2-notify
hello_world.py
#!/usr/bin/python2 import pynotify pynotify.init ("Hello world") Hello=pynotify.Notification ("Hello world!","This is an example notification.","dialog-information") Hello.show ()
Ruby
- Dependencies: libnotify, ruby-gir-ffiAUR from AUR
hello_world.rb
#!/usr/bin/ruby require 'gir_ffi' GirFFI.setup :Notify Notify.init("Hello world") Hello = Notify::Notification.new("Hello world!", "This is an example notification.", "dialog-information") Hello.show
Or you can use the old, static ruby-libnotify bindings:
- Dependency: ruby-libnotifyAUR from AUR
hello_world.rb
#!/usr/bin/ruby require 'RNotify' Notify.init("Hello world") Hello = Notify::Notification.new("Hello world!", "This is an example notification.", "dialog-information") Hello.show
Vala
hello_world.vala
using Notify; public class HelloWorld { static void main () { Notify.init ("Hello world"); var Hello = new Notification("Hello world!", "This is an example notification.", "dialog-information"); Hello.show (); } }
Visual Basic .NET
- Dependency: notify-sharp
- Makedependency: mono-basic
- Build with:
vbnc -r:/usr/lib/mono/notify-sharp/notify-sharp.dll hello_world.vb
- Run with:
mono hello_world.exe
hello_world.vb
Imports Notifications Public Class Hello Public Shared Sub Main Dim Hello As New Notification Hello.Summary = "Hello world!" Hello.Body = "This is an example notification." Hello.IconName = "dialog-information" Hello.Show End Sub End Class
See also
- Libnotify Reference Manual
- C example
- Python example (french article)