]> git.sur5r.net Git - i3/i3/commitdiff
startup: delete the startup sequence upon completion, make the timeout complete it
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 10 Oct 2011 14:30:07 +0000 (15:30 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 10 Oct 2011 14:54:18 +0000 (15:54 +0100)
include/data.h
src/startup.c

index ba836d550067c1e8523593e67e03b16bc3e71064..60e1ef26087aaabd91368b1045ef7dd4fee0dbc4 100644 (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;
 };
index 1a584cd49b32ac403fd909edab4afdfb765a0ca5..4b6c937dab6ad3e62ddb969bf20103a2c878236e 100644 (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 */