Difference between revisions of "Desktop notifications"

From ArchWiki
Jump to: navigation, search
m
(Write your own notify app: Add Perl example)
Line 33: Line 33:
  
 
===Write your own notify app===
 
===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.
+
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====
 
====Bash====
Line 46: Line 48:
 
void main () {
 
void main () {
 
notify_init ("Hello world");
 
notify_init ("Hello world");
NotifyNotification * Hello = notify_notification_new ("Hello world", "This is an example.", "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);
 
notify_uninit ();
 
notify_uninit ();
Line 59: Line 61:
 
Notification Hello = new Notification();
 
Notification Hello = new Notification();
 
Hello.Summary  = "Hello world";
 
Hello.Summary  = "Hello world";
Hello.Body    = "This is an example.";
+
Hello.Body    = "This is an example notification.";
 
Hello.IconName = "dialog-information";
 
Hello.IconName = "dialog-information";
 
Hello.Show();
 
Hello.Show();
Line 74: Line 76:
 
init
 
init
 
Notify.init ("Hello world")
 
Notify.init ("Hello world")
var Hello=new Notification ("Hello world","This is an example.","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 83: Line 85:
 
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.","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 93: Line 95:
 
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.",
+
                                 body: "This is an example notification.",
 
                                 "icon-name": "dialog-information"});
 
                                 "icon-name": "dialog-information"});
 
Hello.show ();
 
Hello.show ();
 
Notify.uninit ();</nowiki>}}
 
Notify.uninit ();</nowiki>}}
 +
 +
====Perl====
 +
*Dependencies: {{AUR|perl-gtk2-notify}} from AUR
 +
{{File|hello_world.pl|<nowiki>#!/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;</nowiki>}}
  
 
====Python====
 
====Python====
Line 103: Line 112:
 
from gi.repository import Notify
 
from gi.repository import Notify
 
Notify.init ("Hello world")
 
Notify.init ("Hello world")
Hello=Notify.Notification.new ("Hello world","This is an example.","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 112: Line 121:
 
import pynotify
 
import pynotify
 
pynotify.init ("Hello world")
 
pynotify.init ("Hello world")
Hello=pynotify.Notification ("Hello world","This is an example.","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 124: Line 133:
 
static void main () {
 
static void main () {
 
Notify.init ("Hello world");
 
Notify.init ("Hello world");
Notification Hello = new Notification("Hello world", "This is an example.", "dialog-information");
+
Notification Hello = new Notification("Hello world", "This is an example notification.", "dialog-information");
 
Hello.show ();
 
Hello.show ();
 
Notify.uninit ();
 
Notify.uninit ();

Revision as of 19:32, 27 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

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

Template:File

C

Template:File

C#

Template:File

Genie

Template:File

JavaScript (gjs)

Template:File

JavaScript (seed)

Template:File

Perl

Template:File

Python

Template:File

Python 2 (python-notify)

Template:File

Vala

Template:File

More Resources