Difference between revisions of "Desktop notifications"

From ArchWiki
Jump to: navigation, search
m (Tips & Tricks)
(Apply style guides)
Line 5: Line 5:
 
==Installation==
 
==Installation==
  
The {{Pkg|libnotify}} package is available from the Extra repository. Install libnotify from a terminal with the following command.
+
Libnotify can be installed with the package {{Pkg|libnotify}}, available in the [[Official Repositories]].
{{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, you have to install a notification server:
In order to use libnotify in desktop environments, you have to install a notification server:
+
  
 
===GNOME===
 
===GNOME===
 
*{{Pkg|gnome-shell}} provides a notification server itself. Notifications are displayed at the bottom of the screen.
 
*{{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}}:
+
*In GNOME Fallback mode, you need to [[pacman|install]] {{Pkg|notification-daemon}}, available in the [[Official Repositories]].
:{{Cli|# pacman -S notification-daemon}}
+
 
:{{Note|notification-daemon is a required component for GNOME Fallback mode. You can't login without it.}}
 
:{{Note|notification-daemon is a required component for GNOME Fallback mode. You can't login without it.}}
  
Line 20: Line 18:
  
 
===XFCE===
 
===XFCE===
To get notifications in XFCE, you need to install {{Pkg|xfce4-notifyd}}:
+
To get notifications in XFCE, you need to [[pacman|install]] {{Pkg|xfce4-notifyd}}, available in the [[Official Repositories]].
{{Cli|# pacman -S xfce4-notifyd}}
+
{{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: {{Codeline|xfce4-notifyd-config}}.}}
+
  
 
===Unity===
 
===Unity===
Unity uses [[Notify OSD]], which is available in AUR: {{AUR|notify-osd}}.
+
Unity uses [[Notify OSD]], which is available in [[Arch User Repository]]: {{AUR|notify-osd}}.
  
 
===Other DEs===
 
===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).
+
Other [[desktop environment|desktop environments]] 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==
+
==Tips and tricks==
  
 
===Write your own notify app===
 
===Write your own notify app===
Line 39: Line 36:
 
====Bash====
 
====Bash====
 
*Dependency: {{Pkg|libnotify}}
 
*Dependency: {{Pkg|libnotify}}
{{File|hello_world.sh|<nowiki>#!/bin/bash
+
{{hc|hello_world.sh|<nowiki>#!/bin/bash
notify-send "Hello world" "This is an example notification." --icon=dialog-information</nowiki>}}
+
notify-send 'Hello world!' 'This is an example notification.' --icon=dialog-information</nowiki>}}
  
 
====C====
 
====C====
 
*Dependency: {{Pkg|libnotify}}
 
*Dependency: {{Pkg|libnotify}}
*Build with: {{Codeline|gcc -o hello_world `pkg-config --cflags --libs libnotify` hello_world.c}}
+
*Build with: {{ic|gcc -o hello_world `pkg-config --cflags --libs libnotify` hello_world.c}}
{{File|hello_world.c|<nowiki>#include <libnotify/notify.h>
+
{{hc|hello_world.c|<nowiki>#include <libnotify/notify.h>
 
void main () {
 
void main () {
notify_init ("Hello world");
+
notify_init ("Hello world!");
 
NotifyNotification * Hello = notify_notification_new ("Hello world", "This is an example notification.", "dialog-information");
 
NotifyNotification * Hello = notify_notification_new ("Hello world", "This is an example notification.", "dialog-information");
 
notify_notification_show (Hello, NULL);
 
notify_notification_show (Hello, NULL);
Line 55: Line 52:
 
====C#====
 
====C#====
 
*Dependency: {{Pkg|notify-sharp-svn}}
 
*Dependency: {{Pkg|notify-sharp-svn}}
*Build with: {{Codeline|mcs -pkg:notify-sharp hello_world.cs}}
+
*Build with: {{ic|mcs -pkg:notify-sharp hello_world.cs}}
{{File|hello_world.cs|<nowiki>using Notifications;
+
{{hc|hello_world.cs|<nowiki>using Notifications;
 
public class HelloWorld {
 
public class HelloWorld {
 
static void Main() {
 
static void Main() {
Notification Hello = new Notification();
+
var Hello = new Notification();
Hello.Summary  = "Hello world";
+
Hello.Summary  = "Hello world!";
 
Hello.Body    = "This is an example notification.";
 
Hello.Body    = "This is an example notification.";
 
Hello.IconName = "dialog-information";
 
Hello.IconName = "dialog-information";
Line 70: Line 67:
 
*Dependency: {{Pkg|libnotify}}
 
*Dependency: {{Pkg|libnotify}}
 
*Makedependency: {{Pkg|vala}}
 
*Makedependency: {{Pkg|vala}}
*Build with: {{Codeline|valac --pkg libnotify hello_world.gs}}
+
*Build with: {{ic|valac --pkg libnotify hello_world.gs}}
{{File|hello_world.gs|<nowiki>uses  
+
{{hc|hello_world.gs|<nowiki>uses  
 
Notify
 
Notify
  
 
init
 
init
 
Notify.init ("Hello world")
 
Notify.init ("Hello world")
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 ()
 
Hello.show ()
 
Notify.uninit ()</nowiki>}}
 
Notify.uninit ()</nowiki>}}
Line 82: Line 79:
 
====JavaScript (gjs)====
 
====JavaScript (gjs)====
 
*Dependencies: {{Pkg|libnotify}}, {{Pkg|gjs}}
 
*Dependencies: {{Pkg|libnotify}}, {{Pkg|gjs}}
{{File|hello_world.js|<nowiki>#!/usr/bin/gjs
+
{{hc|hello_world.js|<nowiki>#!/usr/bin/gjs
 
Notify = imports.gi.Notify;
 
Notify = imports.gi.Notify;
 
Notify.init ("Hello world");
 
Notify.init ("Hello world");
Hello=Notify.Notification.new ("Hello world","This is an example notification.","dialog-information");
+
Hello=Notify.Notification.new ("Hello world!","This is an example notification.","dialog-information");
 
Hello.show ();
 
Hello.show ();
 
Notify.uninit ();</nowiki>}}
 
Notify.uninit ();</nowiki>}}
Line 91: Line 88:
 
====JavaScript (seed)====
 
====JavaScript (seed)====
 
*Dependencies: {{Pkg|libnotify}}, {{Pkg|seed}}
 
*Dependencies: {{Pkg|libnotify}}, {{Pkg|seed}}
{{File|hello_world.js|<nowiki>#!/usr/bin/seed
+
{{hc|hello_world.js|<nowiki>#!/usr/bin/seed
 
Notify = imports.gi.Notify;
 
Notify = imports.gi.Notify;
 
Notify.init ("Hello world");
 
Notify.init ("Hello world");
Hello=new Notify.Notification ({summary: "Hello world",
+
Hello=new Notify.Notification ({summary: "Hello world!",
 
                                 body: "This is an example notification.",
 
                                 body: "This is an example notification.",
 
                                 "icon-name": "dialog-information"});
 
                                 "icon-name": "dialog-information"});
Line 102: Line 99:
 
====Perl====
 
====Perl====
 
*Dependencies: {{AUR|perl-gtk2-notify}} from AUR
 
*Dependencies: {{AUR|perl-gtk2-notify}} from AUR
{{File|hello_world.pl|<nowiki>#!/usr/bin/perl
+
{{hc|hello_world.pl|<nowiki>#!/usr/bin/perl
 
use Gtk2::Notify -init, "Hello world";
 
use Gtk2::Notify -init, "Hello world";
my $hello = Gtk2::Notify->new("Hello world", "This is an example notification.", "dialog-information");
+
my $hello = Gtk2::Notify->new("Hello world!", "This is an example notification.", "dialog-information");
 
$hello->show;</nowiki>}}
 
$hello->show;</nowiki>}}
  
 
====Python====
 
====Python====
 
*Dependencies: {{Pkg|libnotify}}, {{Pkg|python-gobject}}
 
*Dependencies: {{Pkg|libnotify}}, {{Pkg|python-gobject}}
{{File|hello_world.py|<nowiki>#!/usr/bin/python
+
{{hc|hello_world.py|<nowiki>#!/usr/bin/python
 
from gi.repository import Notify
 
from gi.repository import Notify
 
Notify.init ("Hello world")
 
Notify.init ("Hello world")
Line 118: Line 115:
 
====Python 2 (python-notify)====
 
====Python 2 (python-notify)====
 
*Dependency: {{Pkg|python-notify}}
 
*Dependency: {{Pkg|python-notify}}
{{File|hello_world.py|<nowiki>#!/usr/bin/python2
+
{{hc|hello_world.py|<nowiki>#!/usr/bin/python2
 
import pynotify
 
import pynotify
 
pynotify.init ("Hello world")
 
pynotify.init ("Hello world")
Hello=pynotify.Notification ("Hello world","This is an example notification.","dialog-information")
+
Hello=pynotify.Notification ("Hello world!","This is an example notification.","dialog-information")
 
Hello.show ()
 
Hello.show ()
 
pynotify.uninit ()</nowiki>}}
 
pynotify.uninit ()</nowiki>}}
Line 127: Line 124:
 
====Ruby====
 
====Ruby====
 
*Dependency: {{AUR|ruby-libnotify}} from AUR
 
*Dependency: {{AUR|ruby-libnotify}} from AUR
{{File|hello_world.rb|<nowiki>#!/usr/bin/ruby
+
{{hc|hello_world.rb|<nowiki>#!/usr/bin/ruby
 
require 'RNotify'
 
require 'RNotify'
 
Notify.init("Hello world")
 
Notify.init("Hello world")
Hello = Notify::Notification.new("Hello world", "This is an example notification.", "dialog-information")
+
Hello = Notify::Notification.new("Hello world!", "This is an example notification.", "dialog-information")
 
Hello.show
 
Hello.show
 
Notify.uninit</nowiki>}}
 
Notify.uninit</nowiki>}}
Line 137: Line 134:
 
*Dependency: {{Pkg|libnotify}}
 
*Dependency: {{Pkg|libnotify}}
 
*Makedependency: {{Pkg|vala}}
 
*Makedependency: {{Pkg|vala}}
*Build with: {{Codeline|valac --pkg libnotify hello_world.vala}}
+
*Build with: {{ic|valac --pkg libnotify hello_world.vala}}
{{File|hello_world.vala|<nowiki>using Notify;
+
{{hc|hello_world.vala|<nowiki>using Notify;
 
public class HelloWorld {
 
public class HelloWorld {
 
static void main () {
 
static void main () {
 
Notify.init ("Hello world");
 
Notify.init ("Hello world");
Notification 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 ();
 
Hello.show ();
 
Notify.uninit ();
 
Notify.uninit ();
Line 148: Line 145:
 
}</nowiki>}}
 
}</nowiki>}}
  
==More Resources==
+
==See also==
 
*[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://code.valaide.org/content/genie-libnotify-example Genie example]
 
*[http://code.valaide.org/content/genie-libnotify-example Genie example]
 
*[http://roscidus.com/desktop/node/336 Python example]
 
*[http://roscidus.com/desktop/node/336 Python example]

Revision as of 05:53, 4 November 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

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:

GNOME

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, available in the Official Repositories.

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

Unity

Unity uses Notify OSD, which is available in Arch User Repository: notify-osdAUR.

Other DEs

Other desktop environments could use notification-daemon (should be launched explicitly), xfce4-notifyd or notify-osdAUR (automatically launched by D-Bus on request).

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

hello_world.sh
#!/bin/bash
notify-send 'Hello world!' 'This is an example notification.' --icon=dialog-information

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);
	notify_uninit ();
}

C#

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

  • Dependency: libnotify
  • Makedependency: vala
  • Build with: valac --pkg libnotify hello_world.gs
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 ()
	Notify.uninit ()

JavaScript (gjs)

hello_world.js
#!/usr/bin/gjs
Notify = imports.gi.Notify;
Notify.init ("Hello world");
Hello=Notify.Notification.new ("Hello world!","This is an example notification.","dialog-information");
Hello.show ();
Notify.uninit ();

JavaScript (seed)

hello_world.js
#!/usr/bin/seed
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 ();
Notify.uninit ();

Perl

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

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 ()
Notify.uninit ()

Python 2 (python-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 ()
pynotify.uninit ()

Ruby

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
Notify.uninit

Vala

  • Dependency: libnotify
  • Makedependency: vala
  • Build with: valac --pkg libnotify hello_world.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 ();
		Notify.uninit ();
	}
}

See also