startup-notifications: keep sequence around for 30s after completion

This changes the fact that Firefox would not be launched on the correct
workspace because it marked the startup sequence as completed *before*
actually mapping all of its windows.

To test this, go to workspace 3 and run this command in a terminal:
    i3-msg 'exec iceweasel; workspace 4'
That will make i3 start iceweasel (and create a proper startup
notification context for it), then immediately switch to workspace 4
(before iceweasel could possibly start).

The iceweasel window(s) should appear on workspace 3.
next
Michael Stapelberg 2012-09-05 21:00:08 +02:00
parent 8d2799c251
commit 32d4dbf70f
2 changed files with 59 additions and 10 deletions

View File

@ -168,6 +168,9 @@ struct Startup_Sequence {
char *workspace;
/** libstartup-notification context for this launch */
SnLauncherContext *context;
/** time at which this sequence should be deleted (after it was marked as
* completed) */
time_t delete_at;
TAILQ_ENTRY(Startup_Sequence) sequences;
};

View File

@ -57,6 +57,57 @@ static void startup_timeout(EV_P_ ev_timer *w, int revents) {
free(w);
}
/*
* Some applications (such as Firefox) mark a startup sequence as completede
* *before* they even map a window. Therefore, we cannot entirely delete the
* startup sequence once its marked as complete. Instead, well 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 _delete_startup_sequence(struct Startup_Sequence *sequence) {
time_t current_time = time(NULL);
int active_sequences = 0;
/* Mark the given sequence for deletion in 30 seconds. */
sequence->delete_at = current_time + 30;
DLOG("Will delete startup sequence %s at timestamp %d\n",
sequence->id, sequence->delete_at);
/* 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;
DLOG("Deleting startup sequence %s, delete_at = %d, current_time = %d\n",
current->id, current->delete_at, current_time);
/* Unref the context, will be free()d */
sn_launcher_context_unref(current->context);
/* Delete our internal sequence */
TAILQ_REMOVE(&startup_sequences, current, sequences);
}
return active_sequences;
}
/*
* 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),
@ -182,13 +233,7 @@ void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
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);
if (TAILQ_EMPTY(&startup_sequences)) {
if (_delete_startup_sequence(sequence) == 0) {
DLOG("No more startup sequences running, changing root window cursor to default pointer.\n");
/* Change the pointer of the root window to indicate progress */
if (xcursor_supported)
@ -250,13 +295,14 @@ char *startup_workspace_for_window(i3Window *cwindow, xcb_get_property_reply_t *
break;
}
free(startup_id);
free(startup_id_reply);
if (!sequence) {
DLOG("WARNING: This sequence (ID %s) was not found\n", startup_id);
free(startup_id);
free(startup_id_reply);
return NULL;
}
free(startup_id);
free(startup_id_reply);
return sequence->workspace;
}