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");
56 sn_launcher_context_complete(w->data);
72 time_t current_time = time(NULL);
73 int active_sequences = 0;
94 return active_sequences;
104 assert(sequence != NULL);
105 DLOG(
"Deleting startup sequence %s, delete_at = %lld, current_time = %lld\n",
106 sequence->
id, (
long long)sequence->
delete_at, (
long long)time(NULL));
109 sn_launcher_context_unref(sequence->
context);
133 SnLauncherContext *
context = NULL;
135 if (!no_startup_id) {
139 sn_launcher_context_set_name(context,
"i3");
140 sn_launcher_context_set_description(context,
"exec command in i3");
143 char *first_word =
sstrdup(command);
144 char *space = strchr(first_word,
' ');
147 sn_launcher_context_initiate(context,
"i3", first_word,
last_timestamp);
151 struct ev_timer *timeout =
scalloc(1,
sizeof(
struct ev_timer));
152 ev_timer_init(timeout, startup_timeout, 60.0, 0.);
156 LOG(
"startup id = %s\n", sn_launcher_context_get_startup_id(context));
162 sequence->
id =
sstrdup(sn_launcher_context_get_startup_id(context));
170 sn_launcher_context_ref(context);
173 LOG(
"executing: %s\n", command);
185 unsetenv(
"LISTEN_PID");
186 unsetenv(
"LISTEN_FDS");
187 signal(SIGPIPE, SIG_DFL);
191 sn_launcher_context_setup_child_process(context);
193 execl(_PATH_BSHELL, _PATH_BSHELL,
"-c", command, (
void *)NULL);
200 if (!no_startup_id) {
214 SnStartupSequence *snsequence;
216 snsequence = sn_monitor_event_get_startup_sequence(event);
219 const char *
id = sn_startup_sequence_get_id(snsequence);
222 if (strcmp(current->
id,
id) != 0)
230 DLOG(
"Got event for startup sequence that we did not initiate (ID = %s). Ignoring.\n",
id);
234 switch (sn_monitor_event_get_type(event)) {
235 case SN_MONITOR_EVENT_COMPLETED:
236 DLOG(
"startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
239 time_t current_time = time(NULL);
241 DLOG(
"Will delete startup sequence %s at timestamp %lld\n",
245 DLOG(
"No more startup sequences running, changing root window cursor to default pointer.\n");
266 if (strcmp(current->
workspace, old_name) != 0)
268 DLOG(
"Renaming workspace \"%s\" to \"%s\" in startup sequence %s.\n",
269 old_name, new_name, current->
id);
280 xcb_get_property_reply_t *startup_id_reply,
bool ignore_mapped_leader) {
283 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
284 FREE(startup_id_reply);
285 DLOG(
"No _NET_STARTUP_ID set on window 0x%08x\n", cwindow->
id);
286 if (cwindow->
leader == XCB_NONE)
297 DLOG(
"Ignoring leader window 0x%08x\n", cwindow->
leader);
301 DLOG(
"Checking leader window 0x%08x\n", cwindow->
leader);
303 xcb_get_property_cookie_t cookie;
305 cookie = xcb_get_property(
conn,
false, cwindow->
leader,
306 A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
307 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
309 if (startup_id_reply == NULL ||
310 xcb_get_property_value_length(startup_id_reply) == 0) {
311 FREE(startup_id_reply);
312 DLOG(
"No _NET_STARTUP_ID set on the leader either\n");
318 sasprintf(&startup_id,
"%.*s", xcb_get_property_value_length(startup_id_reply),
319 (
char *)xcb_get_property_value(startup_id_reply));
322 if (strcmp(current->
id, startup_id) != 0)
330 DLOG(
"WARNING: This sequence (ID %s) was not found\n", startup_id);
332 free(startup_id_reply);
337 free(startup_id_reply);
353 if (sequence == NULL)
357 time_t current_time = time(NULL);
359 DLOG(
"Deleting expired startup sequence %s\n", sequence->
id);
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
#define TAILQ_HEAD_INITIALIZER(head)
char * id
startup ID for this sequence, generated by libstartup-notification
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
A 'Con' represents everything from the X11 root window down to a single X11 window.
xcb_connection_t * conn
XCB connection and root screen.
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.
#define TAILQ_INSERT_TAIL(head, elm, field)
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
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
void startup_monitor_event(SnMonitorEvent *event, void *userdata)
Called by libstartup-notification when something happens.
#define SD_LISTEN_FDS_START
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 xcb_set_root_cursor(int cursor)
Set the cursor of the root window to the given cursor id.
struct rlimit original_rlimit_core
The original value of RLIMIT_CORE when i3 was started.
static int _prune_startup_sequences(void)
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
#define TAILQ_FOREACH(var, head, field)
#define TAILQ_FIRST(head)
void xcursor_set_root_cursor(int cursor_id)
Sets the cursor of the root window to the 'pointer' cursor.
static TAILQ_HEAD(startup_sequence_head, Startup_Sequence)
time_t delete_at
time at which this sequence should be deleted (after it was marked as completed)
#define TAILQ_REMOVE(head, elm, field)
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...
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
void startup_sequence_rename_workspace(const char *old_name, const char *new_name)
Renames workspaces that are mentioned in the startup sequences.
void startup_sequence_delete(struct Startup_Sequence *sequence)
Deletes a startup sequence, ignoring whether its timeout has elapsed.
#define TAILQ_NEXT(elm, field)
Used during the config file lexing/parsing to keep the state of the lexer in order to provide useful ...
struct ev_loop * main_loop
xcb_timestamp_t last_timestamp
The last timestamp we got from X11 (timestamps are included in some events and are used for some thin...
Stores internal information about a startup sequence, like the workspace it was initiated on...
static struct context * context
char * workspace
workspace on which this startup was initiated
int listen_fds
The number of file descriptors passed via socket activation.