「デスクトップ通知」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
imported>Agent0
(Updated international links)
 
(1版 をインポートしました)
(相違点なし)

2015年1月11日 (日) 13:38時点における版

関連記事

デスクトップ通知は、非同期に特定のイベントをユーザーに通知する小さくて控えめなポップアップダイアログです。

Libnotify

Libnotify は GTK+Qt アプリケーションのサポートを提供する Desktop Notifications Specification の実装で特定のデスクトップに依存していません: EvolutionPidgin など多数のオープンソースアプリによって使用されています。Libnotify は公式リポジトリにある libnotify パッケージでインストールすることが可能です。

libnotify を使うには、通知サーバーをインストールする必要があります。

通知サーバー

ビルトイン

以下のデスクトップ環境では通知を表示するためにそれぞれ独自の実装を使っており、置き換えることができません。通知サーバーはログイン時に自動で起動し DBus によってアプリケーションからの通知を受け取ります。

  • Avant Window Navigator には awn-extras-appletsAUR による通知デーモンアプレットがあります。
  • Cinnamon は通知サーバーを備えており、通知は画面の右上に表示されます。
  • Enlightenment は Notification モジュールを通して通知サーバーを提供しています。通知は画面の右上に表示されます。
  • GNOME は通知サーバーを備えており、通知は画面の下に表示されます。
  • KDEkdebase-runtime パッケージに入っている knotify4 を使って通知を表示します。通知は画面の右下に表示されます。

スタンドアロン

他のデスクトップ環境では、DBus で初めて呼ばれた時に通知サーバーが起動します。以下の実装からどれか一つを選ぶことが可能です:

  • dunstdwm などの最小主義のウィンドウマネージャによく似合うように作られた最小主義の通知デーモンです。
  • notification-daemonGNOME Flashback が使っている通知デーモンです。デフォルトでは D-Bus サービスファイルを持っていません。GNOME Flashback 以外から使うには、以下のファイルを作成してください:
/usr/share/dbus-1/services/org.gnome.Notifications.service
[D-BUS Service]
Name=org.freedesktop.Notifications
Exec=/usr/lib/notification-daemon-1.0/notification-daemon
  • mate-notification-daemonMATE の通知サーバーで、公式リポジトリからインストールできます。
  • notify-osdUnity の通知サーバーで、公式リポジトリからインストールできます。
  • statnotAUR は小さくて軽量な通知デーモンで、ルートウィンドウのタイトルや標準出力、FIFO パイプに通知を出力することができ、タイル型ウィンドウマネージャと上手く統合されます。Arch User Repository または git リポジトリから利用できます。
  • twmn-gitAUR はタイル型ウィンドウマネージャのための通知システムです。Arch User Repository または git リポジトリから利用できます。
  • xfce4-notifydXfce の通知サーバーで、公式リポジトリからインストールできます。
ヒント: xfce4-notifyd を設定するには、ターミナルから次のコマンドを実行してください: xfce4-notifyd-config

プログラミングでの使い方

GObject-Introspection やバインディングを通して多くのプログラミング言語を使ったり、または bash を利用して簡単に libnotify でメッセージを表示することができます。

以下の例ではシンプルな "Hello world" の通知が表示されます。

Bash

hello_world.sh
#!/bin/bash
notify-send 'Hello world!' 'This is an example notification.' --icon=dialog-information
ヒント: 利用可能なアイコンはここから参照できます。

Boo

  • 依存パッケージ: notify-sharp-3 (boo)
  • ビルドするのに必要なパッケージ: boo
  • ビルド: booc hello_world.boo
  • 実行: mono hello_world.exe (または booi 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

  • 依存パッケージ: libnotify
  • ビルド: 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);
	g_object_unref(G_OBJECT(Hello));
	notify_uninit();
}

C++

  • 依存パッケージ: AUR の libnotifymmAUR
  • ビルド: 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#

  • 依存パッケージ: notify-sharp-3
  • ビルド: mcs -pkg:notify-sharp-3.0 hello_world.cs
  • 実行: 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();
	}
}

Cobra

  • 依存パッケージ: notify-sharp-3
  • ビルドするのに必要なパッケージ: AUR の cobraAUR
  • ビルド: cobra -c hello_world
  • 実行: mono hello_world.exe
hello_world.cs
@args -pkg:notify-sharp-3.0
use Notifications
class HelloWorld
    def main
        hello = Notification()
        hello.summary  = "Hello world!"
        hello.body     = "This is an example notification."
        hello.iconName = "dialog-information"
        hello.show

F#

  • 依存パッケージ: notify-sharp-3
  • ビルドするのに必要なパッケージ: AUR の fsharpAUR
  • ビルド: fsharpc -r:notify-sharp.dll -I:/usr/lib/mono/notify-sharp-3.0/ -I:/usr/lib/mono/gtk-sharp-3.0/ hello_world.fs
  • 実行: mono hello_world.exe
hello_world.fs
open Notifications
let Hello = new Notification()
Hello.Summary  <- "Hello world!"
Hello.Body     <- "This is an example notification."
Hello.IconName <- "dialog-information"
Hello.Show()

Genie

  • 依存パッケージ: libnotify
  • ビルドするのに必要なパッケージ: vala
  • ビルド: 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 ()

Groovy

  • 依存パッケージ: groovy, AUR の java-gnomeAUR
  • ビルド: groovyc -cp /usr/share/java/gtk.jar HelloWorld.groovy && jar cfe HelloWorld.jar HelloWorld HelloWorld.class
  • 実行: java -cp /usr/share/groovy/embeddable/groovy-all.jar:/usr/share/java/gtk.jar:HelloWorld.jar HelloWorld (または groovy -cp /usr/share/java/gtk.jar HelloWorld.groovy)
HelloWorld.groovy
import org.gnome.gtk.*
import org.gnome.notify.*

Gtk.init()
Notify.init("Hello world")
def Hello = new Notification("Hello world!", "This is an example notification.", "dialog-information")
Hello.show()

Java

  • 依存パッケージ: AUR の java-gnomeAUR
  • ビルドするのに必要なパッケージ: java-environment
  • ビルド: javac -cp /usr/share/java/gtk.jar HelloWorld.java && jar cfe HelloWorld.jar HelloWorld HelloWorld.class
  • 実行: java -cp /usr/share/java/gtk.jar:HelloWorld.jar 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
#!/usr/bin/gjs
const Notify = imports.gi.Notify;
Notify.init ("Hello world");
var Hello=new Notify.Notification ({summary: "Hello world!",
                                    body: "This is an example notification.",
                                    "icon-name": "dialog-information"});
Hello.show ();

Lua

hello_world.lua
#!/usr/bin/lua
lgi = require 'lgi'
Notify = lgi.require('Notify')
Notify.init("Hello world")
Hello=Notify.Notification.new("Hello world","This is an example notification.","dialog-information")
Hello:show()</nowiki>

Perl

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;

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 ()

Ruby

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

Scala

  • 依存パッケージ: AUR の java-gnomeAUR (と scala)
  • ビルドするのに必要なパッケージ: scala
  • ビルド: scalac -cp /usr/share/java/gtk.jar -d HelloWorld.jar HelloWorld.scala
  • 実行: java -cp /usr/share/java/gtk.jar:HelloWorld.jar HelloWorld (または scala -cp /usr/share/java/gtk.jar HelloWorld.scala)
HelloWorld.scala
import org.gnome.gtk._
import org.gnome.notify._

object HelloWorld {
  def main(args: Array[String]) {
    Gtk.init(args)
    Notify.init("Hello world")
    var Hello = new Notification("Hello world!", "This is an example notification.", "dialog-information")
    Hello.show()
  }
}

Vala

  • 依存パッケージ: libnotify
  • ビルドするのに必要なパッケージ: vala
  • ビルド: 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 ();
	}
}

Visual Basic .NET

  • 依存パッケージ: notify-sharp-3
  • ビルドするのに必要なパッケージ: mono-basic
  • ビルド: vbnc -r:/usr/lib/mono/notify-sharp-3.0/notify-sharp.dll hello_world.vb
  • 実行: 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

参照