16 #include <sys/types.h>
19 #define SN_API_NOT_YET_FROZEN 1
20 #include <libsn/sn-launcher.h>
32 static
void startup_timeout(EV_P_ ev_timer *w,
int revents) {
33 const char *
id = sn_launcher_context_get_startup_id(w->data);
34 DLOG(
"Timeout for startup sequence %s\n",
id);
38 if (strcmp(current->
id,
id) != 0)
46 sn_launcher_context_unref(w->data);
49 DLOG(
"Sequence already deleted, nevermind.\n");
54 sn_launcher_context_complete(w->data);
78 sn_launcher_context_set_name(context,
"i3");
79 sn_launcher_context_set_description(context,
"exec command in i3");
82 char *first_word =
sstrdup(command);
83 char *space = strchr(first_word,
' ');
86 sn_launcher_context_initiate(context,
"i3", first_word,
last_timestamp);
90 struct ev_timer *timeout =
scalloc(
sizeof(
struct ev_timer));
91 ev_timer_init(timeout, startup_timeout, 60.0, 0.);
95 LOG(
"startup id = %s\n", sn_launcher_context_get_startup_id(context));
101 sequence->
id =
sstrdup(sn_launcher_context_get_startup_id(context));
109 sn_launcher_context_ref(context);
112 LOG(
"executing: %s\n", command);
124 unsetenv(
"LISTEN_PID");
125 unsetenv(
"LISTEN_FDS");
129 sn_launcher_context_setup_child_process(context);
132 static const char *shell = NULL;
135 if ((shell = getenv(
"SHELL")) == NULL)
139 execl(shell, shell,
"-c", command, (
void*)NULL);
146 if (!no_startup_id) {
159 SnStartupSequence *snsequence;
161 snsequence = sn_monitor_event_get_startup_sequence(event);
164 const char *
id = sn_startup_sequence_get_id(snsequence);
167 if (strcmp(current->
id,
id) != 0)
175 DLOG(
"Got event for startup sequence that we did not initiate (ID = %s). Ignoring.\n",
id);
179 switch (sn_monitor_event_get_type(event)) {
180 case SN_MONITOR_EVENT_COMPLETED:
181 DLOG(
"startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
184 sn_launcher_context_unref(sequence->
context);
190 DLOG(
"No more startup sequences running, changing root window cursor to default pointer.\n");
215 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
216 FREE(startup_id_reply);
217 DLOG(
"No _NET_STARTUP_ID set on this window\n");
218 if (cwindow->
leader == XCB_NONE)
221 xcb_get_property_cookie_t cookie;
222 cookie = xcb_get_property(
conn,
false, cwindow->
leader, A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
223 DLOG(
"Checking leader window 0x%08x\n", cwindow->
leader);
224 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
226 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
227 DLOG(
"No _NET_STARTUP_ID set on the leader either\n");
228 FREE(startup_id_reply);
234 if (asprintf(&startup_id,
"%.*s", xcb_get_property_value_length(startup_id_reply),
235 (
char*)xcb_get_property_value(startup_id_reply)) == -1) {
236 perror(
"asprintf()");
237 DLOG(
"Could not get _NET_STARTUP_ID\n");
238 free(startup_id_reply);
244 if (strcmp(current->
id, startup_id) != 0)
252 free(startup_id_reply);
255 DLOG(
"WARNING: This sequence (ID %s) was not found\n", startup_id);