diff options
author | David King <amigadave@amigadave.com> | 2013-06-24 08:21:22 +0100 |
---|---|---|
committer | David King <amigadave@amigadave.com> | 2014-09-01 11:03:25 +0100 |
commit | 147d3ecde3ec5f9153ce05208a043a802d320b3d (patch) | |
tree | cfc66bf278a5c34c6d25af96915bc8820bf80932 /daemon | |
parent | c53fd1edbcb2b4bbe664c58dc25fa7877d62d1b4 (diff) | |
download | caribou-147d3ecde3ec5f9153ce05208a043a802d320b3d.tar.gz |
daemon: Start with D-Bus activation
Install the daemon to libexecdir. Make the daemon own a name on the
session bus, and install a D-Bus service file for it. Allow the name
to be replaced by another process, so that a D-Bus activated daemon can
be replaced by a GSettings-key autostarted daemon. Handle run() being
called multiple times.
https://bugzilla.gnome.org/show_bug.cgi?id=683712
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/Makefile.am | 2 | ||||
-rw-r--r-- | daemon/daemon.vala | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 13bca11..e6432ec 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = caribou +libexec_PROGRAMS = caribou caribou_VALAFLAGS = \ --vapidir=$(top_srcdir)/vapi \ diff --git a/daemon/daemon.vala b/daemon/daemon.vala index 7192646..82b2c3f 100644 --- a/daemon/daemon.vala +++ b/daemon/daemon.vala @@ -11,13 +11,32 @@ namespace Caribou { public abstract void hide (uint32 timestamp) throws IOError; } + [DBus (name = "org.gnome.Caribou.Daemon")] class Daemon : Object { _Keyboard keyboard; Atspi.Accessible current_acc; unowned Gdk.Display display; + uint name_id; public Daemon () { display = Gdk.Display.get_default (); + name_id = Bus.own_name (BusType.SESSION, + "org.gnome.Caribou.Daemon", + BusNameOwnerFlags.ALLOW_REPLACEMENT + | BusNameOwnerFlags.REPLACE, + on_bus_acquired, null, quit); + } + + ~Daemon () { + Bus.unown_name (name_id); + } + + void on_bus_acquired (DBusConnection conn) { + try { + conn.register_object ("/org/gnome/Caribou/Daemon", this); + } catch (IOError e) { + error ("Could not register D-Bus service: %s", e.message); + } } void on_get_proxy_ready (GLib.Object? obj, GLib.AsyncResult res) { @@ -144,6 +163,13 @@ namespace Caribou { } public void run () { + if (keyboard != null) + { + // This method is available over D-Bus, so ignore the request + // to run if the daemon is already running. + return; + } + Bus.get_proxy.begin<_Keyboard> (BusType.SESSION, "org.gnome.Caribou.Keyboard", "/org/gnome/Caribou/Keyboard", |