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;
95 return active_sequences;
106 assert(sequence != NULL);
107 DLOG(
"Deleting startup sequence %s, delete_at = %ld, current_time = %ld\n",
111 sn_launcher_context_unref(sequence->
context);
137 if (!no_startup_id) {
141 sn_launcher_context_set_name(context,
"i3");
142 sn_launcher_context_set_description(context,
"exec command in i3");
145 char *first_word =
sstrdup(command);
146 char *space = strchr(first_word,
' ');
149 sn_launcher_context_initiate(context,
"i3", first_word,
last_timestamp);
153 struct ev_timer *timeout =
scalloc(
sizeof(
struct ev_timer));
154 ev_timer_init(timeout, startup_timeout, 60.0, 0.);
158 LOG(
"startup id = %s\n", sn_launcher_context_get_startup_id(context));
164 sequence->
id =
sstrdup(sn_launcher_context_get_startup_id(context));
172 sn_launcher_context_ref(context);
175 LOG(
"executing: %s\n", command);
187 unsetenv(
"LISTEN_PID");
188 unsetenv(
"LISTEN_FDS");
192 sn_launcher_context_setup_child_process(context);
195 static const char *shell = NULL;
198 if ((shell = getenv(
"SHELL")) == NULL)
202 execl(shell, shell,
"-c", command, (
void*)NULL);
209 if (!no_startup_id) {
222 SnStartupSequence *snsequence;
224 snsequence = sn_monitor_event_get_startup_sequence(event);
227 const char *
id = sn_startup_sequence_get_id(snsequence);
230 if (strcmp(current->
id,
id) != 0)
238 DLOG(
"Got event for startup sequence that we did not initiate (ID = %s). Ignoring.\n",
id);
242 switch (sn_monitor_event_get_type(event)) {
243 case SN_MONITOR_EVENT_COMPLETED:
244 DLOG(
"startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
247 time_t current_time = time(NULL);
249 DLOG(
"Will delete startup sequence %s at timestamp %ld\n",
253 DLOG(
"No more startup sequences running, changing root window cursor to default pointer.\n");
271 xcb_get_property_reply_t *startup_id_reply,
bool ignore_mapped_leader) {
274 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
275 FREE(startup_id_reply);
276 DLOG(
"No _NET_STARTUP_ID set on window 0x%08x\n", cwindow->
id);
277 if (cwindow->
leader == XCB_NONE)
288 DLOG(
"Ignoring leader window 0x%08x\n", cwindow->
leader);
292 DLOG(
"Checking leader window 0x%08x\n", cwindow->
leader);
294 xcb_get_property_cookie_t cookie;
296 cookie = xcb_get_property(
conn,
false, cwindow->
leader,
297 A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
298 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
300 if (startup_id_reply == NULL ||
301 xcb_get_property_value_length(startup_id_reply) == 0) {
302 FREE(startup_id_reply);
303 DLOG(
"No _NET_STARTUP_ID set on the leader either\n");
309 if (asprintf(&startup_id,
"%.*s", xcb_get_property_value_length(startup_id_reply),
310 (
char*)xcb_get_property_value(startup_id_reply)) == -1) {
311 perror(
"asprintf()");
312 DLOG(
"Could not get _NET_STARTUP_ID\n");
313 free(startup_id_reply);
319 if (strcmp(current->
id, startup_id) != 0)
327 DLOG(
"WARNING: This sequence (ID %s) was not found\n", startup_id);
329 free(startup_id_reply);
334 free(startup_id_reply);
350 if (sequence == NULL)
354 time_t current_time = time(NULL);
356 DLOG(
"Deleting expired startup sequence %s\n", sequence->
id);