From: Michael Stapelberg Date: Mon, 10 Oct 2011 12:50:03 +0000 (+0100) Subject: Implement timeouts for startup notifications X-Git-Tag: 4.1~104^2~5 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=997a539a8a09158dd4a9c87738cd9937a471042d;p=i3%2Fi3 Implement timeouts for startup notifications --- diff --git a/src/startup.c b/src/startup.c index dca7b999..1a584cd4 100644 --- a/src/startup.c +++ b/src/startup.c @@ -21,6 +21,40 @@ static TAILQ_HEAD(startup_sequence_head, Startup_Sequence) startup_sequences = TAILQ_HEAD_INITIALIZER(startup_sequences); +/* + * After 60 seconds, a timeout will be triggered for each startup sequence. + * + * The internal startup sequence will be deleted, the libstartup-notification + * context will be completed and unref'd (therefore free'd aswell). + * + */ +static void startup_timeout(EV_P_ ev_timer *w, int revents) { + const char *id = sn_launcher_context_get_startup_id(w->data); + DLOG("Timeout for startup sequence %s\n", id); + + struct Startup_Sequence *current, *sequence = NULL; + TAILQ_FOREACH(current, &startup_sequences, sequences) { + if (strcmp(current->id, id) != 0) + continue; + + sequence = current; + break; + } + + if (!sequence) { + DLOG("Sequence already deleted, nevermind.\n"); + return; + } + + /* Delete our internal sequence */ + TAILQ_REMOVE(&startup_sequences, sequence, sequences); + + /* Complete and unref the context */ + sn_launcher_context_complete(w->data); + sn_launcher_context_unref(w->data); + free(w); +} + /* * Starts the given application by passing it through a shell. We use double fork * to avoid zombie processes. As the started application’s parent exits (immediately), @@ -47,6 +81,12 @@ void start_application(const char *command) { sn_launcher_context_initiate(context, "i3", first_word, last_timestamp); free(first_word); + /* Trigger a timeout after 60 seconds */ + struct ev_timer *timeout = scalloc(sizeof(struct ev_timer)); + ev_timer_init(timeout, startup_timeout, 60.0, 0.); + timeout->data = context; + ev_timer_start(main_loop, timeout); + LOG("startup id = %s\n", sn_launcher_context_get_startup_id(context)); /* Save the ID and current workspace in our internal list of startup