From: Michael Stapelberg Date: Mon, 10 Oct 2011 11:47:56 +0000 (+0100) Subject: Keep track of startup notifications in a TAILQ, save workspace X-Git-Tag: 4.1~104^2~9 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=499d89bdb061f2f2f22316124f835fd79055a864;p=i3%2Fi3 Keep track of startup notifications in a TAILQ, save workspace --- diff --git a/include/data.h b/include/data.h index f6052b9f..7a280b2e 100644 --- a/include/data.h +++ b/include/data.h @@ -138,6 +138,20 @@ struct Ignore_Event { SLIST_ENTRY(Ignore_Event) ignore_events; }; +/** + * Stores internal information about a startup sequence, like the workspace it + * was initiated on. + * + */ +struct Startup_Sequence { + /** startup ID for this sequence, generated by libstartup-notification */ + char *id; + /** workspace on which this startup was initiated */ + char *workspace; + + TAILQ_ENTRY(Startup_Sequence) sequences; +}; + /** * Regular expression wrapper. It contains the pattern itself as a string (like * ^foo[0-9]$) as well as a pointer to the compiled PCRE expression and the diff --git a/src/startup.c b/src/startup.c index dd327355..5fc875a3 100644 --- a/src/startup.c +++ b/src/startup.c @@ -18,6 +18,9 @@ #include "all.h" +static TAILQ_HEAD(startup_sequence_head, Startup_Sequence) startup_sequences = + TAILQ_HEAD_INITIALIZER(startup_sequences); + /* * 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), @@ -46,6 +49,14 @@ void start_application(const char *command) { LOG("startup id = %s\n", sn_launcher_context_get_startup_id(context)); + /* Save the ID and current workspace in our internal list of startup + * sequences */ + Con *ws = con_get_workspace(focused); + struct Startup_Sequence *sequence = scalloc(sizeof(struct Startup_Sequence)); + sequence->id = sstrdup(sn_launcher_context_get_startup_id(context)); + sequence->workspace = sstrdup(ws->name); + TAILQ_INSERT_TAIL(&startup_sequences, sequence, sequences); + LOG("executing: %s\n", command); if (fork() == 0) { /* Child process */ @@ -75,14 +86,29 @@ void start_application(const char *command) { * */ void startup_monitor_event(SnMonitorEvent *event, void *userdata) { - SnStartupSequence *sequence; + SnStartupSequence *snsequence; + + snsequence = sn_monitor_event_get_startup_sequence(event); + + /* Get the corresponding internal startup sequence */ + const char *id = sn_startup_sequence_get_id(snsequence); + struct Startup_Sequence *current, *sequence = NULL; + TAILQ_FOREACH(current, &startup_sequences, sequences) { + if (strcmp(current->id, id) != 0) + continue; - DLOG("something happened\n"); - sequence = sn_monitor_event_get_startup_sequence(event); + sequence = current; + break; + } + + if (!sequence) { + DLOG("Got event for startup sequence that we did not initiate (ID = %s). Ignoring.\n", id); + return; + } switch (sn_monitor_event_get_type(event)) { case SN_MONITOR_EVENT_COMPLETED: - DLOG("startup sequence %s completed\n", sn_startup_sequence_get_id(sequence)); + DLOG("startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence)); break; default: /* ignore */