diff options
Diffstat (limited to 'mate-session')
-rw-r--r-- | mate-session/Makefile.am | 2 | ||||
-rw-r--r-- | mate-session/gsm-app.c | 13 | ||||
-rw-r--r-- | mate-session/gsm-app.h | 2 | ||||
-rw-r--r-- | mate-session/gsm-autostart-app.c | 23 | ||||
-rw-r--r-- | mate-session/gsm-autostart-app.h | 1 | ||||
-rw-r--r-- | mate-session/gsm-logout-dialog.c | 25 | ||||
-rw-r--r-- | mate-session/gsm-manager.c | 89 |
7 files changed, 129 insertions, 26 deletions
diff --git a/mate-session/Makefile.am b/mate-session/Makefile.am index 2c73d63..9485fec 100644 --- a/mate-session/Makefile.am +++ b/mate-session/Makefile.am @@ -7,6 +7,7 @@ noinst_PROGRAMS = \ AM_CPPFLAGS = \ $(MATE_SESSION_CFLAGS) \ $(SYSTEMD_CFLAGS) \ + $(UPOWER_CFLAGS) \ $(DISABLE_DEPRECATED_CFLAGS) AM_CFLAGS = $(WARN_CFLAGS) @@ -78,6 +79,7 @@ mate_session_LDADD = \ $(XEXT_LIBS) \ $(MATE_SESSION_LIBS) \ $(SYSTEMD_LIBS) \ + $(UPOWER_LIBS) \ $(EXECINFO_LIBS) libgsmutil_la_SOURCES = \ diff --git a/mate-session/gsm-app.c b/mate-session/gsm-app.c index cae685c..9b3ea39 100644 --- a/mate-session/gsm-app.c +++ b/mate-session/gsm-app.c @@ -246,6 +246,7 @@ gsm_app_class_init (GsmAppClass *klass) klass->impl_get_autorestart = NULL; klass->impl_provides = NULL; klass->impl_is_running = NULL; + klass->impl_peek_autostart_delay = NULL; g_object_class_install_property (object_class, PROP_PHASE, @@ -442,6 +443,18 @@ gsm_app_registered (GsmApp *app) g_signal_emit (app, signals[REGISTERED], 0); } +int +gsm_app_peek_autostart_delay (GsmApp *app) +{ + g_return_val_if_fail (GSM_IS_APP (app), FALSE); + + if (GSM_APP_GET_CLASS (app)->impl_peek_autostart_delay) { + return GSM_APP_GET_CLASS (app)->impl_peek_autostart_delay (app); + } else { + return 0; + } +} + void gsm_app_exited (GsmApp *app) { diff --git a/mate-session/gsm-app.h b/mate-session/gsm-app.h index a50c8db..a1adaa3 100644 --- a/mate-session/gsm-app.h +++ b/mate-session/gsm-app.h @@ -67,6 +67,7 @@ struct _GsmAppClass GError **error); gboolean (*impl_stop) (GsmApp *app, GError **error); + int (*impl_peek_autostart_delay) (GsmApp *app); gboolean (*impl_provides) (GsmApp *app, const char *service); gboolean (*impl_has_autostart_condition) (GsmApp *app, @@ -117,6 +118,7 @@ gboolean gsm_app_provides (GsmApp *app, gboolean gsm_app_has_autostart_condition (GsmApp *app, const char *condition); void gsm_app_registered (GsmApp *app); +int gsm_app_peek_autostart_delay (GsmApp *app); /* exported to bus */ gboolean gsm_app_get_app_id (GsmApp *app, diff --git a/mate-session/gsm-autostart-app.c b/mate-session/gsm-autostart-app.c index f19f6b6..04cc8e6 100644 --- a/mate-session/gsm-autostart-app.c +++ b/mate-session/gsm-autostart-app.c @@ -65,6 +65,7 @@ struct _GsmAutostartAppPrivate { char *condition_string; gboolean condition; gboolean autorestart; + int autostart_delay; GFileMonitor *condition_monitor; GSettings *condition_settings; @@ -101,6 +102,7 @@ gsm_autostart_app_init (GsmAutostartApp *app) app->priv->pid = -1; app->priv->condition_monitor = NULL; app->priv->condition = FALSE; + app->priv->autostart_delay = -1; } static gboolean @@ -482,6 +484,18 @@ load_desktop_file (GsmAutostartApp *app) NULL); setup_condition_monitor (app); + if (phase == GSM_MANAGER_PHASE_APPLICATION) { + /* Only accept an autostart delay for the application phase */ + app->priv->autostart_delay = egg_desktop_file_get_integer (app->priv->desktop_file, + GSM_AUTOSTART_APP_DELAY_KEY, + NULL); + if (app->priv->autostart_delay < 0) { + g_warning ("Invalid autostart delay of %d for %s", app->priv->autostart_delay, + gsm_app_peek_id (GSM_APP (app))); + app->priv->autostart_delay = -1; + } + } + g_object_set (app, "phase", phase, "startup-id", startup_id, @@ -1108,6 +1122,14 @@ gsm_autostart_app_get_app_id (GsmApp *app) } } +static int +gsm_autostart_app_peek_autostart_delay (GsmApp *app) +{ + GsmAutostartApp *aapp = GSM_AUTOSTART_APP (app); + + return aapp->priv->autostart_delay; +} + static GObject * gsm_autostart_app_constructor (GType type, guint n_construct_properties, @@ -1148,6 +1170,7 @@ gsm_autostart_app_class_init (GsmAutostartAppClass *klass) app_class->impl_has_autostart_condition = gsm_autostart_app_has_autostart_condition; app_class->impl_get_app_id = gsm_autostart_app_get_app_id; app_class->impl_get_autorestart = gsm_autostart_app_get_autorestart; + app_class->impl_peek_autostart_delay = gsm_autostart_app_peek_autostart_delay; g_object_class_install_property (object_class, PROP_DESKTOP_FILENAME, diff --git a/mate-session/gsm-autostart-app.h b/mate-session/gsm-autostart-app.h index 0502aa3..4c45338 100644 --- a/mate-session/gsm-autostart-app.h +++ b/mate-session/gsm-autostart-app.h @@ -70,6 +70,7 @@ GsmApp *gsm_autostart_app_new (const char *desktop_file); #define GSM_AUTOSTART_APP_DBUS_PATH_KEY "X-MATE-DBus-Path" #define GSM_AUTOSTART_APP_DBUS_ARGS_KEY "X-MATE-DBus-Start-Arguments" #define GSM_AUTOSTART_APP_DISCARD_KEY "X-MATE-Autostart-discard-exec" +#define GSM_AUTOSTART_APP_DELAY_KEY "X-MATE-Autostart-Delay" #ifdef __cplusplus } diff --git a/mate-session/gsm-logout-dialog.c b/mate-session/gsm-logout-dialog.c index 1a79875..323f123 100644 --- a/mate-session/gsm-logout-dialog.c +++ b/mate-session/gsm-logout-dialog.c @@ -27,7 +27,9 @@ #include <glib/gi18n.h> #include <gtk/gtk.h> +#ifdef HAVE_UPOWER #include <upower.h> +#endif #include "gsm-logout-dialog.h" #ifdef HAVE_SYSTEMD @@ -52,8 +54,9 @@ typedef enum { struct _GsmLogoutDialogPrivate { GsmDialogLogoutType type; - +#ifdef HAVE_UPOWER UpClient *up_client; +#endif #ifdef HAVE_SYSTEMD GsmSystemd *systemd; #endif @@ -147,9 +150,9 @@ gsm_logout_dialog_init (GsmLogoutDialog *logout_dialog) gtk_window_set_skip_taskbar_hint (GTK_WINDOW (logout_dialog), TRUE); gtk_window_set_keep_above (GTK_WINDOW (logout_dialog), TRUE); gtk_window_stick (GTK_WINDOW (logout_dialog)); - +#ifdef HAVE_UPOWER logout_dialog->priv->up_client = up_client_new (); - +#endif #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) logout_dialog->priv->systemd = gsm_get_systemd (); @@ -176,12 +179,12 @@ gsm_logout_dialog_destroy (GsmLogoutDialog *logout_dialog, g_source_remove (logout_dialog->priv->timeout_id); logout_dialog->priv->timeout_id = 0; } - +#ifdef HAVE_UPOWER if (logout_dialog->priv->up_client) { g_object_unref (logout_dialog->priv->up_client); logout_dialog->priv->up_client = NULL; } - +#endif #ifdef HAVE_SYSTEMD if (logout_dialog->priv->systemd) { g_object_unref (logout_dialog->priv->systemd); @@ -201,13 +204,17 @@ static gboolean gsm_logout_supports_system_suspend (GsmLogoutDialog *logout_dialog) { gboolean ret; + ret = FALSE; #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) ret = gsm_systemd_can_suspend (logout_dialog->priv->systemd); +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) else #endif +#ifdef HAVE_UPOWER ret = up_client_get_can_suspend (logout_dialog->priv->up_client); - +#endif return ret; } @@ -215,13 +222,17 @@ static gboolean gsm_logout_supports_system_hibernate (GsmLogoutDialog *logout_dialog) { gboolean ret; + ret = FALSE; #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) ret = gsm_systemd_can_hibernate (logout_dialog->priv->systemd); +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) else #endif +#ifdef HAVE_UPOWER ret = up_client_get_can_hibernate (logout_dialog->priv->up_client); - +#endif return ret; } diff --git a/mate-session/gsm-manager.c b/mate-session/gsm-manager.c index b4986ac..eda565b 100644 --- a/mate-session/gsm-manager.c +++ b/mate-session/gsm-manager.c @@ -38,7 +38,9 @@ #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> +#ifdef HAVE_UPOWER #include <upower.h> +#endif #include <gtk/gtk.h> /* for logout dialog */ #include <gio/gio.h> /* for gsettings */ @@ -144,9 +146,10 @@ struct GsmManagerPrivate DBusGProxy *bus_proxy; DBusGConnection *connection; - +#ifdef HAVE_UPOWER /* Interface with other parts of the system */ UpClient *up_client; +#endif }; enum { @@ -335,13 +338,16 @@ app_condition_changed (GsmApp *app, } else { g_debug ("GsmManager: stopping app %s", gsm_app_peek_id (app)); - /* If we don't have a client then we should try to kill the app */ + /* If we don't have a client then we should try to kill the app, + * if it is running */ error = NULL; - res = gsm_app_stop (app, &error); - if (error != NULL) { - g_warning ("Not able to stop app from its condition: %s", - error->message); - g_error_free (error); + if (gsm_app_is_running (app)) { + res = gsm_app_stop (app, &error); + if (error != NULL) { + g_warning ("Not able to stop app from its condition: %s", + error->message); + g_error_free (error); + } } } } @@ -622,12 +628,37 @@ on_phase_timeout (GsmManager *manager) } static gboolean +_autostart_delay_timeout (GsmApp *app) +{ + GError *error = NULL; + gboolean res; + + if (!gsm_app_peek_is_disabled (app) + && !gsm_app_peek_is_conditionally_disabled (app)) { + res = gsm_app_start (app, &error); + if (!res) { + if (error != NULL) { + g_warning ("Could not launch application '%s': %s", + gsm_app_peek_app_id (app), + error->message); + g_error_free (error); + } + } + } + + g_object_unref (app); + + return FALSE; +} + +static gboolean _start_app (const char *id, GsmApp *app, GsmManager *manager) { GError *error; gboolean res; + int delay; if (gsm_app_peek_phase (app) != manager->priv->phase) { goto out; @@ -646,6 +677,15 @@ _start_app (const char *id, goto out; } + delay = gsm_app_peek_autostart_delay (app); + if (delay > 0) { + g_timeout_add_seconds (delay, + (GSourceFunc)_autostart_delay_timeout, + g_object_ref (app)); + g_debug ("GsmManager: %s is scheduled to start in %d seconds", id, delay); + goto out; + } + error = NULL; res = gsm_app_start (app, &error); if (!res) { @@ -1105,10 +1145,11 @@ manager_perhaps_lock (GsmManager *manager) static void manager_attempt_hibernate (GsmManager *manager) { +#ifdef HAVE_UPOWER gboolean can_hibernate; GError *error; gboolean ret; - +#endif #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) { @@ -1121,8 +1162,11 @@ manager_attempt_hibernate (GsmManager *manager) gsm_systemd_attempt_hibernate (systemd); } +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) else { #endif +#ifdef HAVE_UPOWER can_hibernate = up_client_get_can_hibernate (manager->priv->up_client); if (can_hibernate) { @@ -1137,7 +1181,8 @@ manager_attempt_hibernate (GsmManager *manager) g_error_free (error); } } -#ifdef HAVE_SYSTEMD +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) } #endif } @@ -1145,10 +1190,11 @@ manager_attempt_hibernate (GsmManager *manager) static void manager_attempt_suspend (GsmManager *manager) { +#ifdef HAVE_UPOWER gboolean can_suspend; GError *error; gboolean ret; - +#endif #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) { @@ -1161,8 +1207,11 @@ manager_attempt_suspend (GsmManager *manager) gsm_systemd_attempt_suspend (systemd); } +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) else { #endif +#ifdef HAVE_UPOWER can_suspend = up_client_get_can_suspend (manager->priv->up_client); if (can_suspend) { @@ -1177,7 +1226,8 @@ manager_attempt_suspend (GsmManager *manager) g_error_free (error); } } -#ifdef HAVE_SYSTEMD +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) } #endif } @@ -1484,11 +1534,12 @@ _debug_app_for_phase (const char *id, return FALSE; } - g_debug ("GsmManager:\tID: %s\tapp-id:%s\tis-disabled:%d\tis-conditionally-disabled:%d", + g_debug ("GsmManager:\tID: %s\tapp-id:%s\tis-disabled:%d\tis-conditionally-disabled:%d\tis-delayed:%d", gsm_app_peek_id (app), gsm_app_peek_app_id (app), gsm_app_peek_is_disabled (app), - gsm_app_peek_is_conditionally_disabled (app)); + gsm_app_peek_is_conditionally_disabled (app), + (gsm_app_peek_autostart_delay (app) > 0)); return FALSE; } @@ -2349,12 +2400,12 @@ gsm_manager_dispose (GObject *object) g_object_unref (manager->priv->settings_screensaver); manager->priv->settings_screensaver = NULL; } - +#ifdef HAVE_UPOWER if (manager->priv->up_client != NULL) { g_object_unref (manager->priv->up_client); manager->priv->up_client = NULL; } - +#endif G_OBJECT_CLASS (gsm_manager_parent_class)->dispose (object); } @@ -2561,9 +2612,9 @@ gsm_manager_init (GsmManager *manager) "status-changed", G_CALLBACK (on_presence_status_changed), manager); - +#ifdef HAVE_UPOWER manager->priv->up_client = up_client_new (); - +#endif g_signal_connect (manager->priv->settings_session, "changed", G_CALLBACK (on_gsettings_key_changed), @@ -3232,12 +3283,12 @@ gsm_manager_can_shutdown (GsmManager *manager, #endif gboolean can_suspend; gboolean can_hibernate; - +#ifdef HAVE_UPOWER g_object_get (manager->priv->up_client, "can-suspend", &can_suspend, "can-hibernate", &can_hibernate, NULL); - +#endif g_debug ("GsmManager: CanShutdown called"); g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE); |