2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
6 * © 2009-2011 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
10 * startup.c: Startup notification code
13 #include <sys/types.h>
16 #define SN_API_NOT_YET_FROZEN 1
17 #include <libsn/sn-launcher.h>
22 * Starts the given application by passing it through a shell. We use double fork
23 * to avoid zombie processes. As the started application’s parent exits (immediately),
24 * the application is reparented to init (process-id 1), which correctly handles
25 * childs, so we don’t have to do it :-).
27 * The shell is determined by looking for the SHELL environment variable. If it
28 * does not exist, /bin/sh is used.
31 void start_application(const char *command) {
32 /* Create a startup notification context to monitor the progress of this
34 SnLauncherContext *context;
35 context = sn_launcher_context_new(sndisplay, conn_screen);
36 sn_launcher_context_set_name(context, "i3");
37 sn_launcher_context_set_description(context, "exec command in i3");
38 /* Chop off everything starting from the first space (if there are any
39 * spaces in the command), since we don’t want the parameters. */
40 char *first_word = sstrdup(command);
41 char *space = strchr(first_word, ' ');
44 sn_launcher_context_initiate(context, "i3", first_word, last_timestamp);
47 LOG("startup id = %s\n", sn_launcher_context_get_startup_id(context));
49 LOG("executing: %s\n", command);
54 /* Setup the environment variable(s) */
55 sn_launcher_context_setup_child_process(context);
57 /* Stores the path of the shell */
58 static const char *shell = NULL;
61 if ((shell = getenv("SHELL")) == NULL)
64 /* This is the child */
65 execl(shell, shell, "-c", command, (void*)NULL);
74 * Called by libstartup-notification when something happens
77 void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
78 SnStartupSequence *sequence;
80 DLOG("something happened\n");
81 sequence = sn_monitor_event_get_startup_sequence(event);
83 switch (sn_monitor_event_get_type(event)) {
84 case SN_MONITOR_EVENT_COMPLETED:
85 DLOG("startup sequence %s completed\n", sn_startup_sequence_get_id(sequence));