diff options
author | Colomban Wendling <[email protected]> | 2023-08-09 15:43:46 +0200 |
---|---|---|
committer | raveit65 <[email protected]> | 2023-08-10 00:13:05 +0200 |
commit | 37e33b5fdd3c52c131045b4bebcacb9283f9883f (patch) | |
tree | b90fbffa2825e1c093de012ecd6633b56670760d | |
parent | 2e9c40a456922ca78c7ba80b0c46837b5b3c972e (diff) | |
download | mate-notification-daemon-37e33b5fdd3c52c131045b4bebcacb9283f9883f.tar.bz2 mate-notification-daemon-37e33b5fdd3c52c131045b4bebcacb9283f9883f.tar.xz |
Only exit on idle when explicitly requested
This allows to run as a regular session service that does not exit, but
also as a well-behaved D-Bus-activated service. Make the default
behavior not to exit, but when activated through D-Bus.
-rw-r--r-- | data/org.freedesktop.mate.Notifications.service.in | 2 | ||||
-rw-r--r-- | src/daemon/daemon.c | 21 | ||||
-rw-r--r-- | src/daemon/daemon.h | 3 | ||||
-rw-r--r-- | src/daemon/mnd-daemon.c | 9 |
4 files changed, 30 insertions, 5 deletions
diff --git a/data/org.freedesktop.mate.Notifications.service.in b/data/org.freedesktop.mate.Notifications.service.in index 4ce7697..a59aec4 100644 --- a/data/org.freedesktop.mate.Notifications.service.in +++ b/data/org.freedesktop.mate.Notifications.service.in @@ -1,4 +1,4 @@ [D-BUS Service] Name=org.freedesktop.Notifications -Exec=@LIBEXECDIR@/mate-notification-daemon +Exec=@LIBEXECDIR@/mate-notification-daemon --idle-exit AssumedAppArmorLabel=unconfined diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 71426f3..a9b63f5 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -66,6 +66,7 @@ enum { PROP_0, PROP_REPLACE, + PROP_IDLE_EXIT, LAST_PROP }; @@ -119,6 +120,7 @@ struct _NotifyDaemon { NotifyDaemonNotifications *skeleton; guint bus_name_id; gboolean replace; + gboolean idle_exit; NotifyStackLocation stack_location; NotifyScreen* screen; @@ -220,6 +222,9 @@ static void notify_daemon_set_property (GObject *object, case PROP_REPLACE: daemon->replace = g_value_get_boolean (value); break; + case PROP_IDLE_EXIT: + daemon->idle_exit = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -237,6 +242,12 @@ static void notify_daemon_class_init(NotifyDaemonClass* daemon_class) g_param_spec_boolean ("replace", "replace", "replace", FALSE, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + properties[PROP_IDLE_EXIT] = + g_param_spec_boolean ("idle-exit", "idle-exit", + "Whether to exit when idle", FALSE, + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_WRITABLE | + G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, LAST_PROP, properties); } @@ -263,6 +274,9 @@ static void add_exit_timeout(NotifyDaemon* daemon) { g_assert (daemon != NULL); + if (! daemon->idle_exit) + return; + if (daemon->exit_timeout_source > 0) return; @@ -1691,7 +1705,10 @@ static gboolean notify_daemon_get_server_information (NotifyDaemonNotifications return TRUE; } -NotifyDaemon* notify_daemon_new (gboolean replace) +NotifyDaemon* notify_daemon_new (gboolean replace, gboolean idle_exit) { - return g_object_new (NOTIFY_TYPE_DAEMON, "replace", replace, NULL); + return g_object_new (NOTIFY_TYPE_DAEMON, + "replace", replace, + "idle-exit", idle_exit, + NULL); } diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h index 494fdab..4c32e12 100644 --- a/src/daemon/daemon.h +++ b/src/daemon/daemon.h @@ -51,7 +51,8 @@ typedef enum { G_BEGIN_DECLS -NotifyDaemon* notify_daemon_new (gboolean replace); +NotifyDaemon* notify_daemon_new (gboolean replace, + gboolean idle_exit); GQuark notify_daemon_error_quark(void); diff --git a/src/daemon/mnd-daemon.c b/src/daemon/mnd-daemon.c index 38a5589..59921c7 100644 --- a/src/daemon/mnd-daemon.c +++ b/src/daemon/mnd-daemon.c @@ -31,6 +31,7 @@ static gboolean debug = FALSE; static gboolean replace = FALSE; +static gboolean idle_exit = FALSE; static GOptionEntry entries[] = { @@ -47,6 +48,12 @@ static GOptionEntry entries[] = NULL }, { + "idle-exit", 'i', G_OPTION_FLAG_NONE, + G_OPTION_ARG_NONE, &idle_exit, + "Auto-exit when idle, useful if run through D-Bus activation", + NULL + }, + { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; @@ -95,7 +102,7 @@ int main (int argc, char *argv[]) if (!parse_arguments (&argc, &argv)) return EXIT_FAILURE; - daemon = notify_daemon_new (replace); + daemon = notify_daemon_new (replace, idle_exit); gtk_main(); |