21#define SN_API_NOT_YET_FROZEN 1
22#include <libsn/sn-launcher.h>
34static 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) {
49 sn_launcher_context_unref(w->data);
52 DLOG(
"Sequence already deleted, nevermind.\n");
58 sn_launcher_context_complete(w->data);
74 time_t current_time = time(NULL);
75 int active_sequences = 0;
97 return active_sequences;
107 assert(sequence != NULL);
108 DLOG(
"Deleting startup sequence %s, delete_at = %lld, current_time = %lld\n",
109 sequence->
id, (
long long)sequence->
delete_at, (
long long)time(NULL));
112 sn_launcher_context_unref(sequence->
context);
135 SnLauncherContext *
context = NULL;
137 if (!no_startup_id) {
141 sn_launcher_context_set_name(
context,
"i3");
142 sn_launcher_context_set_description(
context,
"exec command in i3");
145 char *first_word =
sstrdup(command);
146 char *space = strchr(first_word,
' ');
154 struct ev_timer *timeout =
scalloc(1,
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));
173 sn_launcher_context_ref(
context);
176 LOG(
"executing: %s\n", command);
189 unsetenv(
"LISTEN_PID");
190 unsetenv(
"LISTEN_FDS");
191 signal(SIGPIPE, SIG_DFL);
193 if (!no_startup_id) {
194 sn_launcher_context_setup_child_process(
context);
198 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) {
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");
263 if (strcmp(current->
workspace, old_name) != 0) {
266 DLOG(
"Renaming workspace \"%s\" to \"%s\" in startup sequence %s.\n",
267 old_name, new_name, current->
id);
278 xcb_get_property_reply_t *startup_id_reply,
bool ignore_mapped_leader) {
281 if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
282 FREE(startup_id_reply);
283 DLOG(
"No _NET_STARTUP_ID set on window 0x%08x\n", cwindow->
id);
284 if (cwindow->
leader == XCB_NONE) {
296 DLOG(
"Ignoring leader window 0x%08x\n", cwindow->
leader);
300 DLOG(
"Checking leader window 0x%08x\n", cwindow->
leader);
302 xcb_get_property_cookie_t cookie;
304 cookie = xcb_get_property(
conn,
false, cwindow->
leader,
305 A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
306 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
308 if (startup_id_reply == NULL ||
309 xcb_get_property_value_length(startup_id_reply) == 0) {
310 FREE(startup_id_reply);
311 DLOG(
"No _NET_STARTUP_ID set on the leader either\n");
317 sasprintf(&startup_id,
"%.*s", xcb_get_property_value_length(startup_id_reply),
318 (
char *)xcb_get_property_value(startup_id_reply));
321 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) {
358 time_t current_time = time(NULL);
360 DLOG(
"Deleting expired startup sequence %s\n", sequence->
id);
374 xcb_get_property_cookie_t cookie;
375 xcb_get_property_reply_t *startup_id_reply;
377 cookie = xcb_get_property(
conn,
false, win->
id, A__NET_STARTUP_ID,
378 XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
379 startup_id_reply = xcb_get_property_reply(
conn, cookie, NULL);
382 if (sequence != NULL) {
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
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_by_window(i3Window *win)
Deletes the startup sequence for a window if it exists.
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...
static int _prune_startup_sequences(void)
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
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 startup_sequence_rename_workspace(const char *old_name, const char *new_name)
Renames workspaces that are mentioned in the startup sequences.
void startup_monitor_event(SnMonitorEvent *event, void *userdata)
Called by libstartup-notification when something happens.
void xcursor_set_root_cursor(int cursor_id)
Sets the cursor of the root window to the 'pointer' cursor.
char * current_socketpath
xcb_timestamp_t last_timestamp
The last timestamp we got from X11 (timestamps are included in some events and are used for some thin...
xcb_connection_t * conn
XCB connection and root screen.
int listen_fds
The number of file descriptors passed via socket activation.
struct rlimit original_rlimit_core
The original value of RLIMIT_CORE when i3 was started.
struct ev_loop * main_loop
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
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...
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_FOREACH(var, head, field)
#define TAILQ_HEAD(name, type)
#define TAILQ_INSERT_TAIL(head, elm, field)
#define TAILQ_FIRST(head)
#define TAILQ_REMOVE(head, elm, field)
#define TAILQ_NEXT(elm, field)
#define TAILQ_HEAD_INITIALIZER(head)
#define SD_LISTEN_FDS_START
Used during the config file lexing/parsing to keep the state of the lexer in order to provide useful ...
Stores internal information about a startup sequence, like the workspace it was initiated on.
char * id
startup ID for this sequence, generated by libstartup-notification
time_t delete_at
time at which this sequence should be deleted (after it was marked as completed)
char * workspace
workspace on which this startup was initiated
SnLauncherContext * context
libstartup-notification context for this launch
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
xcb_window_t leader
Holds the xcb_window_t (just an ID) for the leader window (logical parent for toolwindows and similar...
A 'Con' represents everything from the X11 root window down to a single X11 window.