Difference between revisions of "Desktop notifications"

From ArchWiki
Jump to: navigation, search
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 opensource apps like Evolution, Pidgin, etc. It has support for Gtk+ and Qt applications and is desktop independent.
+
  
 
==Installation==
 
==Installation==
The libnotify package is available from the Extra repository. Install libnotify from a terminal with the following command.
 
  
pacman -S libnotify
+
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:
  
==Configuration==
+
===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.}}
  
===Gnome===
+
===KDE===
 +
KDE uses knotify4 from {{Pkg|kdebase-runtime}} package to display notifications. If you are using KDE, this package is already installed.
  
To configure libnotify in Gnome install the packages notification-daemon and gconf-editor available in the Extra repository.To install the packages from the terminal:
+
===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}}.}}
  
pacman -S notification-daemon gconf-editor
+
===Unity===
 +
Unity uses [[Notify OSD]], which is available in AUR: {{AUR|notify-osd}}.
  
Open gconf-editor from the terminal with the following:
+
===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).
gconf-editor
+
  
From gconf-editor, select "/apps/notification-daemon/" from the sidebar which will allow libnotify to be configured.
+
==Tips & Tricks==
 +
awn-applet-awn-notification-daemon, colibri, notify-osd, plasma-widgets-workspace, xfce4-notifyd
  
===XFCE===
+
===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.
  
To configure libnotify in XFCE, you need the packages xfce4-notifyd and xfconf available in the Extra repository.To install the packages from the terminal:
+
====Bash====
 +
*Dependency: {{Pkg|libnotify}}
 +
{{File|hello_world.sh|<nowiki>#!/bin/bash
 +
notify-send "Hello world" "This is an example notification." --icon=dialog-information</nowiki>}}
  
pacman -S xfce4-notifyd
+
====C====
pacman -S xfconf
+
*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>}}
  
To configure libnotify, run the following command in the terminal:
+
====C#====
 
+
*Dependency: {{Pkg|notify-sharp-svn}}
xfce4-notifyd-config
+
*Build with: {{Codeline|mcs -pkg:notify-sharp hello_world.cs}}
 
+
{{File|hello_world.cs|<nowiki>using Notifications;
==Tips & Tricks==
+
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>}}
  
You can write your own libnotify display messages easily in Python or other languages. Here is a simple Python example.
+
====Genie====
 +
*Dependency: {{Pkg|libnotify}}
 +
*Makedependency: {{Pkg|vala}}
 +
*Build with: {{Codeline|valac --pkg libnotify hello_world.gs}}
 +
{{File|hello_world.gs|<nowiki>uses
 +
Notify
  
Note you will need to install the Python bindings for libnotify
+
init
 +
Notify.init ("Hello world")
 +
var Hello=new Notification ("Hello world","This is an example.","dialog-information")
 +
Hello.show ()
 +
Notify.uninit ()</nowiki>}}
  
pacman -S python-notify  #(communitiy)
+
====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>}}
  
Hello world example
+
====JavaScript (seed)====
+
*Dependencies: {{Pkg|libnotify}}, {{Pkg|seed}}
#!/usr/bin/env python
+
{{File|hello_world.js|<nowiki>#!/usr/bin/seed
import subprocess
+
Notify = imports.gi.Notify;
info = "Hello world "
+
Notify.init ("Hello world");
subprocess.call(('notify-send',info))
+
Hello=new Notify.Notification ({summary: "Hello world",
 +
                                body: "This is an example.",
 +
                                "icon-name": "dialog-information"});
 +
Hello.show ();
 +
Notify.uninit ();</nowiki>}}
  
#!/usr/bin/python
+
====Python====
import subprocess
+
*Dependencies: {{Pkg|libnotify}}, {{Pkg|python-gobject}}
import commands   
+
{{File|hello_world.py|<nowiki>#!/usr/bin/python
#KERNEL VERSION
+
from gi.repository import Notify
uname = commands.getoutput('uname -r')
+
Notify.init ("Hello world")
head = "All the info about your system:"
+
Hello=Notify.Notification.new ("Hello world","This is an example.","dialog-information")
msg = "Your kernel version: "+ uname +"\n"      
+
Hello.show ()
# print message
+
Notify.uninit ()</nowiki>}}
subprocess.call(['notify-send', head, msg])
+
  
Or you can just use bash
+
====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>}}
  
# send a notification saying hello world
+
====Vala====
notify-send "hello world"
+
*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://www.florijan.net/2009/05/22/howto-using-python-to-display-notifications-using-libnotify/ Libnotify python example]
+
*[http://developer.gnome.org/libnotify/ Libnotify Reference Manual]
[http://roscidus.com/desktop/node/336 another libnotify example]
+
*[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

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

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.

Installation

The libnotify package is available from the Extra repository. Install libnotify from a terminal with the following command. Template:Cli

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

  • 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

Tip: To configure xfce4-notifyd, run the following command in the terminal: Template:Codeline.

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

Template:File

C

Template:File

C#

Template:File

Genie

Template:File

JavaScript (gjs)

Template:File

JavaScript (seed)

Template:File

Python

Template:File

Python 2 (python-notify)

Template:File

Vala

Template:File

More Resources