aboutsummaryrefslogtreecommitdiff
path: root/src/backend-dbus
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2014-04-10 03:52:50 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2014-04-10 03:52:50 +0200
commita302870b4955b0f20573fc4ddb12f4fa3aded911 (patch)
tree7186fbab94457ece04d9aaaa2d81de3440824d34 /src/backend-dbus
parentf8373fd85b5969a83aaf7de2580cb8872dc68615 (diff)
downloadayatana-indicator-session-a302870b4955b0f20573fc4ddb12f4fa3aded911.tar.gz
ayatana-indicator-session-a302870b4955b0f20573fc4ddb12f4fa3aded911.tar.bz2
ayatana-indicator-session-a302870b4955b0f20573fc4ddb12f4fa3aded911.zip
Actions: add Unity session proxy, and use to lock the screen if available
Diffstat (limited to 'src/backend-dbus')
-rw-r--r--src/backend-dbus/CMakeLists.txt6
-rw-r--r--src/backend-dbus/actions.c55
-rw-r--r--src/backend-dbus/com.canonical.Unity.Session.xml12
3 files changed, 69 insertions, 4 deletions
diff --git a/src/backend-dbus/CMakeLists.txt b/src/backend-dbus/CMakeLists.txt
index fa41534..1fb9d7c 100644
--- a/src/backend-dbus/CMakeLists.txt
+++ b/src/backend-dbus/CMakeLists.txt
@@ -14,7 +14,7 @@ add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-webcredentials
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-accounts
org.freedesktop
${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.Accounts.xml)
-
+
add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-user
org.freedesktop
${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.Accounts.User.xml)
@@ -43,6 +43,10 @@ add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-end-session-dialog
org.gnome.SessionManager
${CMAKE_CURRENT_SOURCE_DIR}/org.gnome.SessionManager.EndSessionDialog.xml)
+add_gdbus_codegen (BACKEND_GENERATED_SOURCES unity-session
+ com.canonical
+ ${CMAKE_CURRENT_SOURCE_DIR}/com.canonical.Unity.Session.xml)
+
set (SOURCES actions.c guest.c users.c backend-dbus.c utils.c)
# add warnings/coverage info on handwritten files
diff --git a/src/backend-dbus/actions.c b/src/backend-dbus/actions.c
index b1fa8ac..d99f81f 100644
--- a/src/backend-dbus/actions.c
+++ b/src/backend-dbus/actions.c
@@ -25,6 +25,7 @@
#include "dbus-webcredentials.h"
#include "gnome-screen-saver.h"
#include "gnome-session-manager.h"
+#include "unity-session.h"
#include "actions.h"
@@ -43,6 +44,7 @@ struct _IndicatorSessionActionsDbusPriv
GSettings * indicator_settings;
GnomeScreenSaver * screen_saver;
GnomeSessionManager * session_manager;
+ UnitySession * unity_session;
Login1Manager * login1_manager;
GCancellable * login1_manager_cancellable;
Login1Seat * login1_seat;
@@ -197,6 +199,23 @@ on_screensaver_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpoin
}
static void
+on_unity_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself)
+{
+ GError * err;
+ UnitySession * us;
+
+ err = NULL;
+ us = unity_session_proxy_new_for_bus_finish (res, &err);
+ if (err == NULL)
+ {
+ INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv->unity_session = us;
+
+ }
+
+ log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
+}
+
+static void
on_can_suspend_ready (GObject * o, GAsyncResult * res, gpointer gself)
{
char * str;
@@ -759,9 +778,30 @@ my_about (IndicatorSessionActions * self G_GNUC_UNUSED)
***/
static void
-lock_current_session (IndicatorSessionActions * self)
+lock_current_session (IndicatorSessionActions * self, gboolean immediate)
{
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
+ gchar * name_owner;
+
+ if (G_IS_DBUS_PROXY (p->unity_session))
+ {
+ name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (p->unity_session));
+
+ if (name_owner)
+ {
+ if (immediate)
+ {
+ unity_session_call_prompt_lock (p->unity_session, p->cancellable, NULL, NULL);
+ }
+ else
+ {
+ unity_session_call_lock (p->unity_session, p->cancellable, NULL, NULL);
+ }
+
+ g_free (name_owner);
+ return;
+ }
+ }
g_return_if_fail (p->screen_saver != NULL);
@@ -771,7 +811,7 @@ lock_current_session (IndicatorSessionActions * self)
static void
my_switch_to_screensaver (IndicatorSessionActions * self)
{
- lock_current_session (self);
+ lock_current_session (self, FALSE);
}
static void
@@ -793,7 +833,7 @@ my_switch_to_guest (IndicatorSessionActions * self)
g_return_if_fail (p->dm_seat != NULL);
- lock_current_session (self);
+ lock_current_session (self, TRUE);
display_manager_seat_call_switch_to_guest (p->dm_seat, "",
p->dm_seat_cancellable,
@@ -850,6 +890,7 @@ my_dispose (GObject * o)
g_clear_object (&p->screen_saver);
g_clear_object (&p->session_manager);
+ g_clear_object (&p->unity_session);
set_dm_seat (self, NULL);
set_login1_manager (self, NULL);
set_login1_seat (self, NULL);
@@ -952,6 +993,14 @@ indicator_session_actions_dbus_init (IndicatorSessionActionsDbus * self)
on_screensaver_proxy_ready,
self);
+ unity_session_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "com.canonical.Unity",
+ "/com/canonical/Unity/Session",
+ p->cancellable,
+ on_unity_proxy_ready,
+ self);
+
gnome_session_manager_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
"org.gnome.SessionManager",
diff --git a/src/backend-dbus/com.canonical.Unity.Session.xml b/src/backend-dbus/com.canonical.Unity.Session.xml
new file mode 100644
index 0000000..1dce43e
--- /dev/null
+++ b/src/backend-dbus/com.canonical.Unity.Session.xml
@@ -0,0 +1,12 @@
+<!DOCTYPE node PUBLIC
+"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
+ <interface name="com.canonical.Unity.Session">
+ <method name="Lock" />
+ <method name="PromptLock" />
+ <method name="RequestLogout" />
+ <method name="RequestReboot" />
+ <method name="RequestShutdown" />
+ </interface>
+</node>