]> git.sur5r.net Git - i3/i3/commitdiff
Keep track of startup notifications in a TAILQ, save workspace
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 10 Oct 2011 11:47:56 +0000 (12:47 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 10 Oct 2011 14:54:17 +0000 (15:54 +0100)
include/data.h
src/startup.c

index f6052b9f81154ed98aece23cd086e1792dfb33ba..7a280b2eccfe533b97e261ad605d65448fb41823 100644 (file)
@@ -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
index dd3273551ab1ba5baadd47485811565283a62099..5fc875a3a3737bb6bf66e8d7fe96b6cdb5babc0b 100644 (file)
@@ -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 */