2 #define I3__FILE__ "startup.c"
18 #include <sys/types.h>
21 #define SN_API_NOT_YET_FROZEN 1
22 #include <libsn/sn-launcher.h>
34 static
void startup_timeout(EV_P_ ev_timer *w,
int revents) {
35 const char *
id = sn_launcher_context_get_startup_id(w->data);
36 DLOG(
"Timeout for startup sequence %s\n",
id);
40 if (strcmp(current->
id,
id) != 0)
48 sn_launcher_context_unref(w->data);
51 DLOG(
"Sequence already deleted, nevermind.\n");
56 sn_launcher_context_complete(w->data);
72 time_t current_time = time(NULL);
73 int active_sequences = 0;
77 DLOG(
"Will delete startup sequence %s at timestamp %ld\n",
97 DLOG(
"Deleting startup sequence %s, delete_at = %ld, current_time = %ld\n",
101 sn_launcher_context_unref(current->
context);
107 return active_sequences;
127 if (!no_startup_id) {
131 sn_launcher_context_set_name(context,
"i3");
132 sn_launcher_context_set_description(context,
"exec command in i3");
135 char *first_word =
sstrdup(command);
136 char *space = strchr(first_word,
' ');
139 sn_launcher_context_initiate(context,
"i3", first_word,
last_timestamp);
143 struct ev_timer *timeout =
scalloc(
sizeof(
struct ev_timer));
144 ev_timer_init(timeout, startup_timeout, 60.0, 0.);
148 LOG(
"startup id = %s\n", sn_launcher_context_get_startup_id(context));
154 sequence->
id =
sstrdup(sn_launcher_context_get_startup_id(context));
162 sn_launcher_context_ref(context);
165 LOG(
"executing: %s\n", command);
177 unsetenv(
"LISTEN_PID");
178 unsetenv(
"LISTEN_FDS");
182 sn_launcher_context_setup_child_process(context);
185 static const char *shell = NULL;
188 if ((shell = getenv(
"SHELL")) == NULL)
192 execl(shell, shell,
"-c", command, (
void*)NULL);
199 if (!no_startup_id) {
212 SnStartupSequence *snsequence;
214 snsequence = sn_monitor_event_get_startup_sequence(event);
217 const char *
id = sn_startup_sequence_get_id(snsequence);
220 if (strcmp(current->
id,
id) != 0)
228 DLOG(
"Got event for startup sequence that we did not initiate (ID = %s). Ignoring.\n",
id);
232 switch (sn_monitor_event_get_type(event)) {
233 case SN_MONITOR_EVENT_COMPLETED:
234 DLOG(
"startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
237 DLOG(
"No more startup sequences running, changing root window cursor to default pointer.\n");
262 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
263 FREE(startup_id_reply);
264 DLOG(
"No _NET_STARTUP_ID set on this window\n");
265 if (cwindow->
leader == XCB_NONE)
268 xcb_get_property_cookie_t cookie;
269 cookie = xcb_get_property(
conn,
false, cwindow->
leader, A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
270 DLOG(
"Checking leader window 0x%08x\n", cwindow->
leader);
271 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
273 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
274 DLOG(
"No _NET_STARTUP_ID set on the leader either\n");
275 FREE(startup_id_reply);
281 if (asprintf(&startup_id,
"%.*s", xcb_get_property_value_length(startup_id_reply),
282 (
char*)xcb_get_property_value(startup_id_reply)) == -1) {
283 perror(
"asprintf()");
284 DLOG(
"Could not get _NET_STARTUP_ID\n");
285 free(startup_id_reply);
291 if (strcmp(current->
id, startup_id) != 0)
299 DLOG(
"WARNING: This sequence (ID %s) was not found\n", startup_id);
301 free(startup_id_reply);
306 free(startup_id_reply);