+/*
+ * Some applications (such as Firefox) mark a startup sequence as completed
+ * *before* they even map a window. Therefore, we cannot entirely delete the
+ * startup sequence once it’s marked as complete. Instead, we’ll mark it for
+ * deletion in 30 seconds and use that chance to delete old sequences.
+ *
+ * This function returns the number of active (!) startup notifications, that
+ * is, those which are not marked for deletion yet. This is used for changing
+ * the root window cursor.
+ *
+ */
+static int _prune_startup_sequences(void) {
+ time_t current_time = time(NULL);
+ int active_sequences = 0;
+
+ /* Traverse the list and delete everything which was marked for deletion 30
+ * seconds ago or earlier. */
+ struct Startup_Sequence *current, *next;
+ for (next = TAILQ_FIRST(&startup_sequences);
+ next != TAILQ_END(&startup_sequences);) {
+ current = next;
+ next = TAILQ_NEXT(next, sequences);
+
+ if (current->delete_at == 0) {
+ active_sequences++;
+ continue;
+ }
+
+ if (current_time <= current->delete_at)
+ continue;
+
+ startup_sequence_delete(current);
+ }
+
+ return active_sequences;
+}
+
+/**
+ * Deletes a startup sequence, ignoring whether its timeout has elapsed.
+ * Useful when e.g. a window is moved between workspaces and its children
+ * shouldn't spawn on the original workspace.
+ *
+ */
+void startup_sequence_delete(struct Startup_Sequence *sequence) {
+ assert(sequence != NULL);
+ DLOG("Deleting startup sequence %s, delete_at = %lld, current_time = %lld\n",
+ sequence->id, (long long)sequence->delete_at, (long long)time(NULL));
+
+ /* Unref the context, will be free()d */
+ sn_launcher_context_unref(sequence->context);
+
+ /* Delete our internal sequence */
+ TAILQ_REMOVE(&startup_sequences, sequence, sequences);
+
+ free(sequence->id);
+ free(sequence->workspace);
+ FREE(sequence);
+}
+