summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2012-11-22 08:41:47 -0800
committerStefano Karapetsas <[email protected]>2012-11-22 08:41:47 -0800
commit433b548ea199a66afbb5fc874bfdaa31695c1e3c (patch)
tree061e2ccdef2078e433d53ef3e1fb14f51766f830 /src
parent237f70ff586bffba55aaefb2af1128d7f321cb30 (diff)
parent30eed18125a03a0bede7f5e560f8f031db70dcbe (diff)
downloadmate-power-manager-433b548ea199a66afbb5fc874bfdaa31695c1e3c.tar.bz2
mate-power-manager-433b548ea199a66afbb5fc874bfdaa31695c1e3c.tar.xz
Merge pull request #37 from Firstyear/systemd-inhibit
Systemd inhibit support for MPM
Diffstat (limited to 'src')
-rw-r--r--src/gpm-manager.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index 9ee8781..c6f4d79 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -100,6 +100,8 @@ struct GpmManagerPrivate
NotifyNotification *notification_warning_low;
NotifyNotification *notification_discharging;
NotifyNotification *notification_fully_charged;
+ gint32 systemd_inhibit;
+ GDBusProxy *systemd_inhibit_proxy;
};
typedef enum {
@@ -1840,6 +1842,76 @@ gpm_manager_control_resume_cb (GpmControl *control, GpmControlAction action, Gpm
g_timeout_add_seconds (1, gpm_manager_reset_just_resumed_cb, manager);
}
+#ifdef WITH_SYSTEMD_INHIBIT
+/**
+ * gpm_main_system_inhibit:
+ **/
+static gint32
+gpm_manager_systemd_inhibit (GDBusProxy *proxy) {
+ /* Return a fd to the to the inhibitor, that we can close on exit. */
+ //GDBusProxy *proxy;
+ GError *error = NULL;
+ gint32 r = -1;
+ gint32 fd = -1;
+ GVariant *res;
+ GUnixFDList *fd_list = NULL;
+ //proxy == NULL;
+ /* Should we define these elsewhere? */
+ const char* arg_what = "handle-power-key:handle-suspend-key:handle-lid-switch";
+ const char* arg_who = g_get_user_name ();
+ const char* arg_why = "Mate power manager handles these events";
+ const char* arg_mode = "block";
+
+ egg_debug ("Inhibiting systemd sleep");
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ NULL,
+ &error );
+ //append all our arguments
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", error->message);
+ g_error_free (error);
+ return -1;
+ }
+ res = g_dbus_proxy_call_with_unix_fd_list_sync (proxy, "Inhibit",
+ g_variant_new( "(ssss)",
+ arg_what,
+ arg_who,
+ arg_why,
+ arg_mode
+ ),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &fd_list,
+ NULL,
+ &error
+ );
+ if (error == NULL && res != NULL) {
+ g_variant_get(res, "(h)", &r);
+ egg_debug ("Inhibiting systemd sleep res = %i", r);
+ fd = g_unix_fd_list_get (fd_list, r, &error);
+ if (fd == -1) {
+ egg_debug("Failed to get systemd inhibitor");
+ return r;
+ }
+ egg_debug ("System inhibitor fd is %d", fd);
+ g_object_unref (fd_list);
+ g_variant_unref (res);
+ } else if (error != NULL || res == NULL) {
+ egg_error ("Error in dbus - %s", error->message);
+ g_error_free (error);
+ return -EIO;
+ }
+ egg_debug ("Inhibiting systemd sleep - success");
+ return r;
+}
+#endif
+
/**
* gpm_manager_init:
* @manager: This class instance
@@ -1857,6 +1929,11 @@ gpm_manager_init (GpmManager *manager)
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
g_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+#ifdef WITH_SYSTEMD_INHIBIT
+ /* We want to inhibit the systemd suspend options, and take care of them ourselves */
+ manager->priv->systemd_inhibit = gpm_manager_systemd_inhibit (manager->priv->systemd_inhibit_proxy);
+#endif
+
/* init to unthrottled */
manager->priv->screensaver_ac_throttle_id = 0;
manager->priv->screensaver_dpms_throttle_id = 0;
@@ -2014,6 +2091,17 @@ gpm_manager_finalize (GObject *object)
g_object_unref (manager->priv->client);
g_object_unref (manager->priv->status_icon);
+#ifdef WITH_SYSTEMD_INHIBIT
+ /* Let systemd take over again ... */
+ if (manager->priv->systemd_inhibit > 0) {
+ close(manager->priv->systemd_inhibit);
+ }
+ if (manager->priv->systemd_inhibit_proxy != NULL) {
+ g_object_unref (manager->priv->systemd_inhibit_proxy);
+ }
+ //g_object_unref (manager->priv->systemd_inhibit);
+#endif
+
G_OBJECT_CLASS (gpm_manager_parent_class)->finalize (object);
}