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.
This commit is contained in:
parent
00a7e74774
commit
a396dd9af9
|
@ -104,6 +104,12 @@
|
||||||
<para>The ID of the notification to replace.</para>
|
<para>The ID of the notification to replace.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</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>
|
</variablelist>
|
||||||
</refsection>
|
</refsection>
|
||||||
<refsection>
|
<refsection>
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#define GETTEXT_PACKAGE NULL
|
#define GETTEXT_PACKAGE NULL
|
||||||
|
|
||||||
static NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
|
static NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
|
||||||
|
static GMainLoop *loop = NULL;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
g_option_arg_urgency_cb (const char *option_name,
|
g_option_arg_urgency_cb (const char *option_name,
|
||||||
|
@ -120,6 +121,22 @@ notify_notification_set_hint_variant (NotifyNotification *notification,
|
||||||
return TRUE;
|
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
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -134,6 +151,7 @@ main (int argc, char *argv[])
|
||||||
static gint notification_id = 0;
|
static gint notification_id = 0;
|
||||||
static gboolean do_version = FALSE;
|
static gboolean do_version = FALSE;
|
||||||
static gboolean hint_error = FALSE, show_error = FALSE;
|
static gboolean hint_error = FALSE, show_error = FALSE;
|
||||||
|
static gboolean wait = FALSE;
|
||||||
static glong expire_timeout = NOTIFY_EXPIRES_DEFAULT;
|
static glong expire_timeout = NOTIFY_EXPIRES_DEFAULT;
|
||||||
GOptionContext *opt_ctx;
|
GOptionContext *opt_ctx;
|
||||||
NotifyNotification *notify;
|
NotifyNotification *notify;
|
||||||
|
@ -165,6 +183,9 @@ main (int argc, char *argv[])
|
||||||
N_ ("Print the notification ID."), NULL},
|
N_ ("Print the notification ID."), NULL},
|
||||||
{"replace-id", 'r', 0, G_OPTION_ARG_INT, ¬ification_id,
|
{"replace-id", 'r', 0, G_OPTION_ARG_INT, ¬ification_id,
|
||||||
N_ ("The ID of the notification to replace."), N_("REPLACE_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,
|
{"version", 'v', 0, G_OPTION_ARG_NONE, &do_version,
|
||||||
N_("Version of the package."),
|
N_("Version of the package."),
|
||||||
NULL},
|
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) {
|
if (!hint_error) {
|
||||||
retval = notify_notification_show (notify, &error);
|
retval = notify_notification_show (notify, &error);
|
||||||
|
|
||||||
|
@ -288,6 +320,13 @@ main (int argc, char *argv[])
|
||||||
g_printf ("%d\n", notification_id);
|
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));
|
g_object_unref (G_OBJECT (notify));
|
||||||
|
|
||||||
notify_uninit ();
|
notify_uninit ();
|
||||||
|
|
Loading…
Reference in New Issue