startup: delete the startup sequence upon completion, make the timeout complete it

This commit is contained in:
Michael Stapelberg 2011-10-10 15:30:07 +01:00
parent ae7dec2774
commit 2ad4fbb34a
2 changed files with 23 additions and 7 deletions

View File

@ -11,6 +11,9 @@
#ifndef _DATA_H
#define _DATA_H
#define SN_API_NOT_YET_FROZEN 1
#include <libsn/sn-launcher.h>
#include <xcb/randr.h>
#include <xcb/xcb_atom.h>
#include <stdbool.h>
@ -150,6 +153,8 @@ struct Startup_Sequence {
char *id;
/** workspace on which this startup was initiated */
char *workspace;
/** libstartup-notification context for this launch */
SnLauncherContext *context;
TAILQ_ENTRY(Startup_Sequence) sequences;
};

View File

@ -24,8 +24,8 @@ static TAILQ_HEAD(startup_sequence_head, Startup_Sequence) 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).
* The timeout will just trigger completion of the sequence, so the normal
* completion process takes place (startup_monitor_event will free it).
*
*/
static void startup_timeout(EV_P_ ev_timer *w, int revents) {
@ -41,17 +41,16 @@ static void startup_timeout(EV_P_ ev_timer *w, int revents) {
break;
}
/* Unref the context (for the timeout itself, see start_application) */
sn_launcher_context_unref(w->data);
if (!sequence) {
DLOG("Sequence already deleted, nevermind.\n");
return;
}
/* Delete our internal sequence */
TAILQ_REMOVE(&startup_sequences, sequence, sequences);
/* Complete and unref the context */
/* Complete the startup sequence, will trigger its deletion. */
sn_launcher_context_complete(w->data);
sn_launcher_context_unref(w->data);
free(w);
}
@ -95,8 +94,14 @@ void start_application(const char *command) {
struct Startup_Sequence *sequence = scalloc(sizeof(struct Startup_Sequence));
sequence->id = sstrdup(sn_launcher_context_get_startup_id(context));
sequence->workspace = sstrdup(ws->name);
sequence->context = context;
TAILQ_INSERT_TAIL(&startup_sequences, sequence, sequences);
/* Increase the refcount once (it starts with 1, so it will be 2 now) for
* the timeout. Even if the sequence gets completed, the timeout still
* needs the context (but will unref it then) */
sn_launcher_context_ref(context);
LOG("executing: %s\n", command);
if (fork() == 0) {
/* Child process */
@ -149,6 +154,12 @@ void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
switch (sn_monitor_event_get_type(event)) {
case SN_MONITOR_EVENT_COMPLETED:
DLOG("startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
/* Unref the context, will be free()d */
sn_launcher_context_unref(sequence->context);
/* Delete our internal sequence */
TAILQ_REMOVE(&startup_sequences, sequence, sequences);
break;
default:
/* ignore */