2 #define I3__FILE__ "startup.c"
18 #include <sys/types.h>
22 #define SN_API_NOT_YET_FROZEN 1
23 #include <libsn/sn-launcher.h>
35 static
void startup_timeout(EV_P_ ev_timer *w,
int revents) {
36 const char *
id = sn_launcher_context_get_startup_id(w->data);
37 DLOG(
"Timeout for startup sequence %s\n",
id);
41 if (strcmp(current->
id,
id) != 0)
49 sn_launcher_context_unref(w->data);
52 DLOG(
"Sequence already deleted, nevermind.\n");
57 sn_launcher_context_complete(w->data);
73 time_t current_time = time(NULL);
74 int active_sequences = 0;
96 return active_sequences;
107 assert(sequence != NULL);
108 DLOG(
"Deleting startup sequence %s, delete_at = %ld, current_time = %ld\n",
112 sn_launcher_context_unref(sequence->
context);
138 if (!no_startup_id) {
142 sn_launcher_context_set_name(context,
"i3");
143 sn_launcher_context_set_description(context,
"exec command in i3");
146 char *first_word =
sstrdup(command);
147 char *space = strchr(first_word,
' ');
150 sn_launcher_context_initiate(context,
"i3", first_word,
last_timestamp);
154 struct ev_timer *timeout =
scalloc(
sizeof(
struct ev_timer));
155 ev_timer_init(timeout, startup_timeout, 60.0, 0.);
159 LOG(
"startup id = %s\n", sn_launcher_context_get_startup_id(context));
165 sequence->
id =
sstrdup(sn_launcher_context_get_startup_id(context));
173 sn_launcher_context_ref(context);
176 LOG(
"executing: %s\n", command);
188 unsetenv(
"LISTEN_PID");
189 unsetenv(
"LISTEN_FDS");
193 sn_launcher_context_setup_child_process(context);
195 execl(_PATH_BSHELL, _PATH_BSHELL,
"-c", command, (
void*)NULL);
202 if (!no_startup_id) {
215 SnStartupSequence *snsequence;
217 snsequence = sn_monitor_event_get_startup_sequence(event);
220 const char *
id = sn_startup_sequence_get_id(snsequence);
223 if (strcmp(current->
id,
id) != 0)
231 DLOG(
"Got event for startup sequence that we did not initiate (ID = %s). Ignoring.\n",
id);
235 switch (sn_monitor_event_get_type(event)) {
236 case SN_MONITOR_EVENT_COMPLETED:
237 DLOG(
"startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
240 time_t current_time = time(NULL);
242 DLOG(
"Will delete startup sequence %s at timestamp %ld\n",
246 DLOG(
"No more startup sequences running, changing root window cursor to default pointer.\n");
264 xcb_get_property_reply_t *startup_id_reply,
bool ignore_mapped_leader) {
267 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
268 FREE(startup_id_reply);
269 DLOG(
"No _NET_STARTUP_ID set on window 0x%08x\n", cwindow->
id);
270 if (cwindow->
leader == XCB_NONE)
281 DLOG(
"Ignoring leader window 0x%08x\n", cwindow->
leader);
285 DLOG(
"Checking leader window 0x%08x\n", cwindow->
leader);
287 xcb_get_property_cookie_t cookie;
289 cookie = xcb_get_property(
conn,
false, cwindow->
leader,
290 A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
291 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
293 if (startup_id_reply == NULL ||
294 xcb_get_property_value_length(startup_id_reply) == 0) {
295 FREE(startup_id_reply);
296 DLOG(
"No _NET_STARTUP_ID set on the leader either\n");
302 if (asprintf(&startup_id,
"%.*s", xcb_get_property_value_length(startup_id_reply),
303 (
char*)xcb_get_property_value(startup_id_reply)) == -1) {
304 perror(
"asprintf()");
305 DLOG(
"Could not get _NET_STARTUP_ID\n");
306 free(startup_id_reply);
312 if (strcmp(current->
id, startup_id) != 0)
320 DLOG(
"WARNING: This sequence (ID %s) was not found\n", startup_id);
322 free(startup_id_reply);
327 free(startup_id_reply);
343 if (sequence == NULL)
347 time_t current_time = time(NULL);
349 DLOG(
"Deleting expired startup sequence %s\n", sequence->
id);