17 #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");
57 sn_launcher_context_complete(w->data);
73 time_t current_time = time(NULL);
74 int active_sequences = 0;
95 return active_sequences;
105 assert(sequence != NULL);
106 DLOG(
"Deleting startup sequence %s, delete_at = %lld, current_time = %lld\n",
107 sequence->
id, (
long long)sequence->
delete_at, (
long long)time(NULL));
110 sn_launcher_context_unref(sequence->
context);
134 SnLauncherContext *
context = NULL;
136 if (!no_startup_id) {
140 sn_launcher_context_set_name(
context,
"i3");
141 sn_launcher_context_set_description(
context,
"exec command in i3");
144 char *first_word =
sstrdup(command);
145 char *space = strchr(first_word,
' ');
152 struct ev_timer *timeout =
scalloc(1,
sizeof(
struct ev_timer));
153 ev_timer_init(timeout, startup_timeout, 60.0, 0.);
157 LOG(
"startup id = %s\n", sn_launcher_context_get_startup_id(
context));
171 sn_launcher_context_ref(
context);
174 LOG(
"executing: %s\n", command);
186 unsetenv(
"LISTEN_PID");
187 unsetenv(
"LISTEN_FDS");
188 signal(SIGPIPE, SIG_DFL);
192 sn_launcher_context_setup_child_process(
context);
195 execl(_PATH_BSHELL, _PATH_BSHELL,
"-c", command, NULL);
202 if (!no_startup_id) {
213 SnStartupSequence *snsequence;
215 snsequence = sn_monitor_event_get_startup_sequence(event);
218 const char *
id = sn_startup_sequence_get_id(snsequence);
221 if (strcmp(current->
id,
id) != 0)
229 DLOG(
"Got event for startup sequence that we did not initiate (ID = %s). Ignoring.\n",
id);
233 switch (sn_monitor_event_get_type(event)) {
234 case SN_MONITOR_EVENT_COMPLETED:
235 DLOG(
"startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
238 time_t current_time = time(NULL);
240 DLOG(
"Will delete startup sequence %s at timestamp %lld\n",
244 DLOG(
"No more startup sequences running, changing root window cursor to default pointer.\n");
262 if (strcmp(current->
workspace, old_name) != 0)
264 DLOG(
"Renaming workspace \"%s\" to \"%s\" in startup sequence %s.\n",
265 old_name, new_name, current->
id);
276 xcb_get_property_reply_t *startup_id_reply,
bool ignore_mapped_leader) {
279 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
280 FREE(startup_id_reply);
281 DLOG(
"No _NET_STARTUP_ID set on window 0x%08x\n", cwindow->
id);
282 if (cwindow->
leader == XCB_NONE)
293 DLOG(
"Ignoring leader window 0x%08x\n", cwindow->
leader);
297 DLOG(
"Checking leader window 0x%08x\n", cwindow->
leader);
299 xcb_get_property_cookie_t cookie;
301 cookie = xcb_get_property(
conn,
false, cwindow->
leader,
302 A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
303 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
305 if (startup_id_reply == NULL ||
306 xcb_get_property_value_length(startup_id_reply) == 0) {
307 FREE(startup_id_reply);
308 DLOG(
"No _NET_STARTUP_ID set on the leader either\n");
314 sasprintf(&startup_id,
"%.*s", xcb_get_property_value_length(startup_id_reply),
315 (
char *)xcb_get_property_value(startup_id_reply));
318 if (strcmp(current->
id, startup_id) != 0)
326 DLOG(
"WARNING: This sequence (ID %s) was not found\n", startup_id);
328 free(startup_id_reply);
333 free(startup_id_reply);
349 if (sequence == NULL)
353 time_t current_time = time(NULL);
355 DLOG(
"Deleting expired startup sequence %s\n", sequence->
id);
369 xcb_get_property_cookie_t cookie;
370 xcb_get_property_reply_t *startup_id_reply;
372 cookie = xcb_get_property(
conn,
false, win->
id, A__NET_STARTUP_ID,
373 XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
374 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
377 if (sequence != NULL) {