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;
95 return active_sequences;
105 assert(sequence != NULL);
106 DLOG(
"Deleting startup sequence %s, delete_at = %ld, current_time = %ld\n",
110 sn_launcher_context_unref(sequence->
context);
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,
' ');
148 sn_launcher_context_initiate(context,
"i3", first_word,
last_timestamp);
152 struct ev_timer *timeout =
scalloc(
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));
163 sequence->
id =
sstrdup(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);
194 execl(_PATH_BSHELL, _PATH_BSHELL,
"-c", command, (
void *)NULL);
201 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");
265 xcb_get_property_reply_t *startup_id_reply,
bool ignore_mapped_leader) {
268 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
269 FREE(startup_id_reply);
270 DLOG(
"No _NET_STARTUP_ID set on window 0x%08x\n", cwindow->
id);
271 if (cwindow->
leader == XCB_NONE)
282 DLOG(
"Ignoring leader window 0x%08x\n", cwindow->
leader);
286 DLOG(
"Checking leader window 0x%08x\n", cwindow->
leader);
288 xcb_get_property_cookie_t cookie;
290 cookie = xcb_get_property(
conn,
false, cwindow->
leader,
291 A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
292 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
294 if (startup_id_reply == NULL ||
295 xcb_get_property_value_length(startup_id_reply) == 0) {
296 FREE(startup_id_reply);
297 DLOG(
"No _NET_STARTUP_ID set on the leader either\n");
303 if (asprintf(&startup_id,
"%.*s", xcb_get_property_value_length(startup_id_reply),
304 (
char *)xcb_get_property_value(startup_id_reply)) == -1) {
305 perror(
"asprintf()");
306 DLOG(
"Could not get _NET_STARTUP_ID\n");
307 free(startup_id_reply);
313 if (strcmp(current->
id, startup_id) != 0)
321 DLOG(
"WARNING: This sequence (ID %s) was not found\n", startup_id);
323 free(startup_id_reply);
328 free(startup_id_reply);
344 if (sequence == NULL)
348 time_t current_time = time(NULL);
350 DLOG(
"Deleting expired startup sequence %s\n", sequence->
id);
#define SD_LISTEN_FDS_START
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
int listen_fds
The number of file descriptors passed via socket activation.
#define TAILQ_REMOVE(head, elm, field)
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
static struct context * context
static int _prune_startup_sequences(void)
time_t delete_at
time at which this sequence should be deleted (after it was marked as completed)
struct ev_loop * main_loop
#define TAILQ_FIRST(head)
xcb_timestamp_t last_timestamp
The last timestamp we got from X11 (timestamps are included in some events and are used for some thin...
#define TAILQ_NEXT(elm, field)
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists...
void startup_sequence_delete(struct Startup_Sequence *sequence)
Deletes a startup sequence, ignoring whether its timeout has elapsed.
struct Startup_Sequence * startup_sequence_get(i3Window *cwindow, xcb_get_property_reply_t *startup_id_reply, bool ignore_mapped_leader)
Gets the stored startup sequence for the _NET_STARTUP_ID of a given window.
void xcursor_set_root_cursor(int cursor_id)
Sets the cursor of the root window to the 'pointer' cursor.
char * startup_workspace_for_window(i3Window *cwindow, xcb_get_property_reply_t *startup_id_reply)
Checks if the given window belongs to a startup notification by checking if the _NET_STARTUP_ID prope...
A 'Con' represents everything from the X11 root window down to a single X11 window.
void xcb_set_root_cursor(int cursor)
Set the cursor of the root window to the given cursor id.
void * scalloc(size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define TAILQ_INSERT_TAIL(head, elm, field)
void startup_monitor_event(SnMonitorEvent *event, void *userdata)
Called by libstartup-notification when something happens.
#define TAILQ_HEAD_INITIALIZER(head)
static TAILQ_HEAD(startup_sequence_head, Startup_Sequence)
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
#define TAILQ_FOREACH(var, head, field)
char * id
startup ID for this sequence, generated by libstartup-notification
xcb_window_t leader
Holds the xcb_window_t (just an ID) for the leader window (logical parent for toolwindows and similar...
SnLauncherContext * context
libstartup-notification context for this launch
struct rlimit original_rlimit_core
The original value of RLIMIT_CORE when i3 was started.
char * workspace
workspace on which this startup was initiated
Stores internal information about a startup sequence, like the workspace it was initiated on...