summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Blain <mail@servc.eu>2021-03-02 19:47:28 +0000
committerMarco Trevisan (TreviƱo) <mail@3v1n0.net>2022-04-25 22:15:50 +0200
commita396dd9af9c023315ce97605198b95c649176055 (patch)
tree9d775b8ba741139dde115bde2c503088d4cc737f
parent00a7e747746e889e70245d588f03d6297c89ec0a (diff)
downloadlibnotify-a396dd9af9c023315ce97605198b95c649176055.tar.gz
notify-send: Add option to wait until notification has been closed
If an expiration timeout is set, the notification is not waited longer than such time.
-rw-r--r--docs/notify-send.xml6
-rw-r--r--tools/notify-send.c39
2 files changed, 45 insertions, 0 deletions
diff --git a/docs/notify-send.xml b/docs/notify-send.xml
index e2c4b1d..185dbd6 100644
--- a/docs/notify-send.xml
+++ b/docs/notify-send.xml
@@ -104,6 +104,12 @@
<para>The ID of the notification to replace.</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</option>, <option>--wait</option></term>
+ <listitem>
+ <para>Wait for the notification to be closed before exiting. If the <option>expire-time</option> is set, it will be used as the maximum waiting time.</para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsection>
<refsection>
diff --git a/tools/notify-send.c b/tools/notify-send.c
index 937fb41..e8dc272 100644
--- a/tools/notify-send.c
+++ b/tools/notify-send.c
@@ -32,6 +32,7 @@
#define GETTEXT_PACKAGE NULL
static NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
+static GMainLoop *loop = NULL;
static gboolean
g_option_arg_urgency_cb (const char *option_name,
@@ -120,6 +121,22 @@ notify_notification_set_hint_variant (NotifyNotification *notification,
return TRUE;
}
+static void
+handle_closed (NotifyNotification *notify,
+ gpointer user_data)
+{
+ g_main_loop_quit (loop);
+}
+
+static gboolean
+on_wait_timeout (gpointer data)
+{
+ fprintf (stderr, "Wait timeout expired\n");
+ g_main_loop_quit (loop);
+
+ return FALSE;
+}
+
int
main (int argc, char *argv[])
{
@@ -134,6 +151,7 @@ main (int argc, char *argv[])
static gint notification_id = 0;
static gboolean do_version = FALSE;
static gboolean hint_error = FALSE, show_error = FALSE;
+ static gboolean wait = FALSE;
static glong expire_timeout = NOTIFY_EXPIRES_DEFAULT;
GOptionContext *opt_ctx;
NotifyNotification *notify;
@@ -165,6 +183,9 @@ main (int argc, char *argv[])
N_ ("Print the notification ID."), NULL},
{"replace-id", 'r', 0, G_OPTION_ARG_INT, &notification_id,
N_ ("The ID of the notification to replace."), N_("REPLACE_ID")},
+ {"wait", 'w', 0, G_OPTION_ARG_NONE, &wait,
+ N_("Wait for the notification to be closed before exiting."),
+ NULL},
{"version", 'v', 0, G_OPTION_ARG_NONE, &do_version,
N_("Version of the package."),
NULL},
@@ -273,6 +294,17 @@ main (int argc, char *argv[])
}
}
+ if (wait) {
+ g_signal_connect (G_OBJECT (notify),
+ "closed",
+ G_CALLBACK (handle_closed),
+ NULL);
+
+ if (expire_timeout > 0) {
+ g_timeout_add (expire_timeout, on_wait_timeout, NULL);
+ }
+ }
+
if (!hint_error) {
retval = notify_notification_show (notify, &error);
@@ -288,6 +320,13 @@ main (int argc, char *argv[])
g_printf ("%d\n", notification_id);
}
+ if (wait) {
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
+ g_main_loop_unref (loop);
+ loop = NULL;
+ }
+
g_object_unref (G_OBJECT (notify));
notify_uninit ();