Difference between revisions of "Desktop notifications"
Gadget3000 (talk | contribs) m (→XFCE: Fixed type) |
(Full rewrite to make this article up to date and add more examples in several programming languages) |
||
Line 1: | Line 1: | ||
[[Category:Development (English)]] | [[Category:Development (English)]] | ||
{{i18n|Libnotify}} | {{i18n|Libnotify}} | ||
− | + | '''Libnotify''' is an easy way to display desktop notifications and information in a small dialog. It's used in much open source apps like Evolution, Pidgin, etc. It has support for Gtk+ and Qt applications and is desktop independent. | |
− | Libnotify is an easy way to display desktop notifications and information in a small dialog. It's used in much | ||
==Installation== | ==Installation== | ||
− | |||
− | + | The {{Pkg|libnotify}} package is available from the Extra repository. Install libnotify from a terminal with the following command. | |
+ | {{Cli|# pacman -S libnotify}} | ||
+ | {{Note|Usually you don't have to install libnotify explicitly, since all applications that requires libnotify depends on it.}} | ||
+ | In order to use libnotify in desktop environments, you have to install a notification server: | ||
− | == | + | ===GNOME=== |
+ | *{{Pkg|gnome-shell}} provides a notification server itself. Notifications are displayed at the bottom of the screen. | ||
+ | *In GNOME Fallback mode, you need to install {{Pkg|notification-daemon}}: | ||
+ | :{{Cli|# pacman -S notification-daemon}} | ||
+ | :{{Note|notification-daemon is a required component for GNOME Fallback mode. You can't login without it.}} | ||
− | === | + | ===KDE=== |
+ | KDE uses knotify4 from {{Pkg|kdebase-runtime}} package to display notifications. If you are using KDE, this package is already installed. | ||
− | To | + | ===XFCE=== |
+ | To get notifications in XFCE, you need to install {{Pkg|xfce4-notifyd}}: | ||
+ | {{Cli|# pacman -S xfce4-notifyd}} | ||
+ | {{Tip|To configure xfce4-notifyd, run the following command in the terminal: {{Codeline|xfce4-notifyd-config}}.}} | ||
− | + | ===Unity=== | |
+ | Unity uses [[Notify OSD]], which is available in AUR: {{AUR|notify-osd}}. | ||
− | + | ===Other DEs=== | |
− | + | Other DEs could use {{Pkg|notification-daemon}} (should be launched explicitly), {{Pkg|xfce4-notifyd}} or {{AUR|notify-osd}} (automatically launched by D-Bus on request). | |
− | |||
− | + | ==Tips & Tricks== | |
+ | awn-applet-awn-notification-daemon, colibri, notify-osd, plasma-widgets-workspace, xfce4-notifyd | ||
− | === | + | ===Write your own notify app=== |
+ | You can write your own libnotify display messages easily in many programming languages through GObject-Introspection, or you can simply use bash. | ||
− | + | ====Bash==== | |
+ | *Dependency: {{Pkg|libnotify}} | ||
+ | {{File|hello_world.sh|<nowiki>#!/bin/bash | ||
+ | notify-send "Hello world" "This is an example notification." --icon=dialog-information</nowiki>}} | ||
− | + | ====C==== | |
− | + | *Dependency: {{Pkg|libnotify}} | |
+ | *Build with: {{Codeline|gcc -o hello_world `pkg-config --cflags --libs libnotify` hello_world.c}} | ||
+ | {{File|hello_world.c|<nowiki>#include <libnotify/notify.h> | ||
+ | void main () { | ||
+ | notify_init ("Hello world"); | ||
+ | NotifyNotification * Hello = notify_notification_new ("Hello world", "This is an example.", "dialog-information"); | ||
+ | notify_notification_show (Hello, NULL); | ||
+ | notify_uninit (); | ||
+ | }</nowiki>}} | ||
− | + | ====C#==== | |
− | + | *Dependency: {{Pkg|notify-sharp-svn}} | |
− | + | *Build with: {{Codeline|mcs -pkg:notify-sharp hello_world.cs}} | |
− | + | {{File|hello_world.cs|<nowiki>using Notifications; | |
− | == | + | public class HelloWorld { |
+ | static void Main() { | ||
+ | Notification Hello = new Notification(); | ||
+ | Hello.Summary = "Hello world"; | ||
+ | Hello.Body = "This is an example."; | ||
+ | Hello.IconName = "dialog-information"; | ||
+ | Hello.Show(); | ||
+ | } | ||
+ | }</nowiki>}} | ||
− | + | ====Genie==== | |
+ | *Dependency: {{Pkg|libnotify}} | ||
+ | *Makedependency: {{Pkg|vala}} | ||
+ | *Build with: {{Codeline|valac --pkg libnotify hello_world.gs}} | ||
+ | {{File|hello_world.gs|<nowiki>uses | ||
+ | Notify | ||
− | + | init | |
+ | Notify.init ("Hello world") | ||
+ | var Hello=new Notification ("Hello world","This is an example.","dialog-information") | ||
+ | Hello.show () | ||
+ | Notify.uninit ()</nowiki>}} | ||
− | + | ====JavaScript (gjs)==== | |
+ | *Dependencies: {{Pkg|libnotify}}, {{Pkg|gjs}} | ||
+ | {{File|hello_world.js|<nowiki>#!/usr/bin/gjs | ||
+ | Notify = imports.gi.Notify; | ||
+ | Notify.init ("Hello world"); | ||
+ | Hello=Notify.Notification.new ("Hello world","This is an example.","dialog-information"); | ||
+ | Hello.show (); | ||
+ | Notify.uninit ();</nowiki>}} | ||
− | + | ====JavaScript (seed)==== | |
− | + | *Dependencies: {{Pkg|libnotify}}, {{Pkg|seed}} | |
− | + | {{File|hello_world.js|<nowiki>#!/usr/bin/seed | |
− | + | Notify = imports.gi.Notify; | |
− | + | Notify.init ("Hello world"); | |
− | + | Hello=new Notify.Notification ({summary: "Hello world", | |
+ | body: "This is an example.", | ||
+ | "icon-name": "dialog-information"}); | ||
+ | Hello.show (); | ||
+ | Notify.uninit ();</nowiki>}} | ||
− | + | ====Python==== | |
− | + | *Dependencies: {{Pkg|libnotify}}, {{Pkg|python-gobject}} | |
− | + | {{File|hello_world.py|<nowiki>#!/usr/bin/python | |
− | + | from gi.repository import Notify | |
− | + | Notify.init ("Hello world") | |
− | + | Hello=Notify.Notification.new ("Hello world","This is an example.","dialog-information") | |
− | + | Hello.show () | |
− | + | Notify.uninit ()</nowiki>}} | |
− | |||
− | + | ====Python 2 (python-notify)==== | |
+ | *Dependency: {{Pkg|python-notify}} | ||
+ | {{File|hello_world.py|<nowiki>#!/usr/bin/python2 | ||
+ | import pynotify | ||
+ | pynotify.init ("Hello world") | ||
+ | Hello=pynotify.Notification ("Hello world","This is an example.","dialog-information") | ||
+ | Hello.show () | ||
+ | pynotify.uninit ()</nowiki>}} | ||
− | + | ====Vala==== | |
− | + | *Dependency: {{Pkg|libnotify}} | |
+ | *Makedependency: {{Pkg|vala}} | ||
+ | *Build with: {{Codeline|valac --pkg libnotify hello_world.vala}} | ||
+ | {{File|hello_world.vala|<nowiki>using Notify; | ||
+ | public class HelloWorld { | ||
+ | static void main () { | ||
+ | Notify.init ("Hello world"); | ||
+ | Notification Hello = new Notification("Hello world", "This is an example.", "dialog-information"); | ||
+ | Hello.show (); | ||
+ | Notify.uninit (); | ||
+ | } | ||
+ | }</nowiki>}} | ||
− | ==More Resources== | + | ==More Resources== |
− | [http:// | + | *[http://developer.gnome.org/libnotify/ Libnotify Reference Manual] |
− | [http://roscidus.com/desktop/node/336 | + | *[http://milky.manishsinha.net/2009/03/29/working-with-libnotify/ C example] |
+ | *[http://code.valaide.org/content/genie-libnotify-example Genie example] | ||
+ | *[http://roscidus.com/desktop/node/336 Python example] |
Revision as of 18:31, 25 October 2011
Libnotify is an easy way to display desktop notifications and information in a small dialog. It's used in much open source apps like Evolution, Pidgin, etc. It has support for Gtk+ and Qt applications and is desktop independent.
Contents
Installation
The libnotify package is available from the Extra repository. Install libnotify from a terminal with the following command. Template:Cli
In order to use libnotify in desktop environments, you have to install a notification server:
GNOME
- gnome-shell provides a notification server itself. Notifications are displayed at the bottom of the screen.
- In GNOME Fallback mode, you need to install notification-daemon:
- Template:Cli
- Note: notification-daemon is a required component for GNOME Fallback mode. You can't login without it.
KDE
KDE uses knotify4 from kdebase-runtime package to display notifications. If you are using KDE, this package is already installed.
XFCE
To get notifications in XFCE, you need to install xfce4-notifyd: Template:Cli
Unity
Unity uses Notify OSD, which is available in AUR: notify-osdAUR.
Other DEs
Other DEs could use notification-daemon (should be launched explicitly), xfce4-notifyd or notify-osdAUR (automatically launched by D-Bus on request).
Tips & Tricks
awn-applet-awn-notification-daemon, colibri, notify-osd, plasma-widgets-workspace, xfce4-notifyd
Write your own notify app
You can write your own libnotify display messages easily in many programming languages through GObject-Introspection, or you can simply use bash.
Bash
- Dependency: libnotify
C
- Dependency: libnotify
- Build with: Template:Codeline
C#
- Dependency: notify-sharp-svn
- Build with: Template:Codeline
Genie
- Dependency: libnotify
- Makedependency: vala
- Build with: Template:Codeline
JavaScript (gjs)
JavaScript (seed)
Python
- Dependencies: libnotify, python-gobject
Python 2 (python-notify)
- Dependency: python-notify
Vala
- Dependency: libnotify
- Makedependency: vala
- Build with: Template:Codeline