Keep track of startup notifications in a TAILQ, save workspace

This commit is contained in:
Michael Stapelberg 2011-10-10 12:47:56 +01:00
parent f4f4d782bb
commit 499d89bdb0
2 changed files with 44 additions and 4 deletions

View File

@ -138,6 +138,20 @@ struct Ignore_Event {
SLIST_ENTRY(Ignore_Event) ignore_events; 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 * 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 * ^foo[0-9]$) as well as a pointer to the compiled PCRE expression and the

View File

@ -18,6 +18,9 @@
#include "all.h" #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 * Starts the given application by passing it through a shell. We use double fork
* to avoid zombie processes. As the started applications parent exits (immediately), * to avoid zombie processes. As the started applications 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)); 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); LOG("executing: %s\n", command);
if (fork() == 0) { if (fork() == 0) {
/* Child process */ /* Child process */
@ -75,14 +86,29 @@ void start_application(const char *command) {
* *
*/ */
void startup_monitor_event(SnMonitorEvent *event, void *userdata) { void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
SnStartupSequence *sequence; SnStartupSequence *snsequence;
DLOG("something happened\n"); snsequence = sn_monitor_event_get_startup_sequence(event);
sequence = 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;
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)) { switch (sn_monitor_event_get_type(event)) {
case SN_MONITOR_EVENT_COMPLETED: 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; break;
default: default:
/* ignore */ /* ignore */