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.
This commit is contained in:
parent
8d2799c251
commit
32d4dbf70f
|
@ -168,6 +168,9 @@ struct Startup_Sequence {
|
||||||
char *workspace;
|
char *workspace;
|
||||||
/** libstartup-notification context for this launch */
|
/** libstartup-notification context for this launch */
|
||||||
SnLauncherContext *context;
|
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;
|
TAILQ_ENTRY(Startup_Sequence) sequences;
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,6 +57,57 @@ static void startup_timeout(EV_P_ ev_timer *w, int revents) {
|
||||||
free(w);
|
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 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 _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
|
* 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),
|
* to avoid zombie processes. As the started application’s parent exits (immediately),
|
||||||
|
@ -182,13 +233,7 @@ void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
|
||||||
case SN_MONITOR_EVENT_COMPLETED:
|
case SN_MONITOR_EVENT_COMPLETED:
|
||||||
DLOG("startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
|
DLOG("startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
|
||||||
|
|
||||||
/* Unref the context, will be free()d */
|
if (_delete_startup_sequence(sequence) == 0) {
|
||||||
sn_launcher_context_unref(sequence->context);
|
|
||||||
|
|
||||||
/* Delete our internal sequence */
|
|
||||||
TAILQ_REMOVE(&startup_sequences, sequence, sequences);
|
|
||||||
|
|
||||||
if (TAILQ_EMPTY(&startup_sequences)) {
|
|
||||||
DLOG("No more startup sequences running, changing root window cursor to default pointer.\n");
|
DLOG("No more startup sequences running, changing root window cursor to default pointer.\n");
|
||||||
/* Change the pointer of the root window to indicate progress */
|
/* Change the pointer of the root window to indicate progress */
|
||||||
if (xcursor_supported)
|
if (xcursor_supported)
|
||||||
|
@ -250,13 +295,14 @@ char *startup_workspace_for_window(i3Window *cwindow, xcb_get_property_reply_t *
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(startup_id);
|
|
||||||
free(startup_id_reply);
|
|
||||||
|
|
||||||
if (!sequence) {
|
if (!sequence) {
|
||||||
DLOG("WARNING: This sequence (ID %s) was not found\n", startup_id);
|
DLOG("WARNING: This sequence (ID %s) was not found\n", startup_id);
|
||||||
|
free(startup_id);
|
||||||
|
free(startup_id_reply);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(startup_id);
|
||||||
|
free(startup_id_reply);
|
||||||
return sequence->workspace;
|
return sequence->workspace;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue