i3
main.c
Go to the documentation of this file.
1/*
2 * vim:ts=4:sw=4:expandtab
3 *
4 * i3 - an improved tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6 *
7 * main.c: Initialization, main loop
8 *
9 */
10#include "all.h"
11#include "shmlog.h"
12
13#include <libev/ev.h>
14#include <fcntl.h>
15#include <getopt.h>
16#include <libgen.h>
17#include <locale.h>
18#include <signal.h>
19#include <sys/mman.h>
20#include <sys/resource.h>
21#include <sys/socket.h>
22#include <sys/stat.h>
23#include <sys/time.h>
24#include <sys/types.h>
25#include <sys/un.h>
26#include <unistd.h>
27#include <xcb/xcb_atom.h>
28#include <xcb/xinerama.h>
29#include <xcb/bigreq.h>
30
31#ifdef I3_ASAN_ENABLED
32#include <sanitizer/lsan_interface.h>
33#endif
34
35#include "sd-daemon.h"
36
39
40/* The original value of RLIMIT_CORE when i3 was started. We need to restore
41 * this before starting any other process, since we set RLIMIT_CORE to
42 * RLIM_INFINITY for i3 debugging versions. */
44
45/* The number of file descriptors passed via socket activation. */
47
48/* We keep the xcb_prepare watcher around to be able to enable and disable it
49 * temporarily for drag_pointer(). */
50static struct ev_prepare *xcb_prepare;
51
53
54xcb_connection_t *conn;
55/* The screen (0 when you are using DISPLAY=:0) of the connection 'conn' */
57
58/* Display handle for libstartup-notification */
59SnDisplay *sndisplay;
60
61/* The last timestamp we got from X11 (timestamps are included in some events
62 * and are used for some things, like determining a unique ID in startup
63 * notification). */
64xcb_timestamp_t last_timestamp = XCB_CURRENT_TIME;
65
66xcb_screen_t *root_screen;
67xcb_window_t root;
68
70xcb_atom_t wm_sn;
71
72/* Color depth, visual id and colormap to use when creating windows and
73 * pixmaps. Will use 32 bit depth and an appropriate visual, if available,
74 * otherwise the root window’s default (usually 24 bit TrueColor). */
75uint8_t root_depth;
76xcb_visualtype_t *visual_type;
77xcb_colormap_t colormap;
78
79struct ev_loop *main_loop;
80
81xcb_key_symbols_t *keysyms;
82
83/* Default shmlog size if not set by user. */
84const int default_shmlog_size = 25 * 1024 * 1024;
85
86/* The list of key bindings */
87struct bindings_head *bindings;
88const char *current_binding_mode = NULL;
89
90/* The list of exec-lines */
92
93/* The list of exec_always lines */
95
96/* The list of assignments */
98
99/* The list of workspace assignments (which workspace should end up on which
100 * output) */
102
103/* We hope that those are supported and set them to true */
104bool xkb_supported = true;
105bool shape_supported = true;
106
107bool force_xinerama = false;
108
109/* Define all atoms as global variables */
110#define xmacro(atom) xcb_atom_t A_##atom;
113#undef xmacro
114
115/*
116 * This callback is only a dummy, see xcb_prepare_cb.
117 * See also man libev(3): "ev_prepare" and "ev_check" - customise your event loop
118 *
119 */
120static void xcb_got_event(EV_P_ struct ev_io *w, int revents) {
121 /* empty, because xcb_prepare_cb are used */
122}
123
124/*
125 * Called just before the event loop sleeps. Ensures xcb’s incoming and outgoing
126 * queues are empty so that any activity will trigger another event loop
127 * iteration, and hence another xcb_prepare_cb invocation.
128 *
129 */
130static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
131 /* Process all queued (and possibly new) events before the event loop
132 sleeps. */
133 xcb_generic_event_t *event;
134
135 while ((event = xcb_poll_for_event(conn)) != NULL) {
136 if (event->response_type == 0) {
137 if (event_is_ignored(event->sequence, 0)) {
138 DLOG("Expected X11 Error received for sequence %x\n", event->sequence);
139 } else {
140 xcb_generic_error_t *error = (xcb_generic_error_t *)event;
141 DLOG("X11 Error received (probably harmless)! sequence 0x%x, error_code = %d\n",
142 error->sequence, error->error_code);
143 }
144 free(event);
145 continue;
146 }
147
148 /* Strip off the highest bit (set if the event is generated) */
149 int type = (event->response_type & 0x7F);
150
151 handle_event(type, event);
152
153 free(event);
154 }
155
156 /* Flush all queued events to X11. */
157 xcb_flush(conn);
158}
159
160/*
161 * Enable or disable the main X11 event handling function.
162 * This is used by drag_pointer() which has its own, modal event handler, which
163 * takes precedence over the normal event handler.
164 *
165 */
166void main_set_x11_cb(bool enable) {
167 DLOG("Setting main X11 callback to enabled=%d\n", enable);
168 if (enable) {
169 ev_prepare_start(main_loop, xcb_prepare);
170 /* Trigger the watcher explicitly to handle all remaining X11 events.
171 * drag_pointer()’s event handler exits in the middle of the loop. */
172 ev_feed_event(main_loop, xcb_prepare, 0);
173 } else {
174 ev_prepare_stop(main_loop, xcb_prepare);
175 }
176}
177
178/*
179 * Exit handler which destroys the main_loop. Will trigger cleanup handlers.
180 *
181 */
182static void i3_exit(void) {
183 if (*shmlogname != '\0') {
184 fprintf(stderr, "Closing SHM log \"%s\"\n", shmlogname);
185 fflush(stderr);
186 shm_unlink(shmlogname);
187 }
189 unlink(config.ipc_socket_path);
190 if (current_log_stream_socket_path != NULL) {
192 }
193 xcb_disconnect(conn);
194
195 /* If a nagbar is active, kill it */
198
199/* We need ev >= 4 for the following code. Since it is not *that* important (it
200 * only makes sure that there are no i3-nagbar instances left behind) we still
201 * support old systems with libev 3. */
202#if EV_VERSION_MAJOR >= 4
203 ev_loop_destroy(main_loop);
204#endif
205
206#ifdef I3_ASAN_ENABLED
207 __lsan_do_leak_check();
208#endif
209}
210
211/*
212 * (One-shot) Handler for all signals with default action "Core", see signal(7)
213 *
214 * Unlinks the SHM log and re-raises the signal.
215 *
216 */
217static void handle_core_signal(int sig, siginfo_t *info, void *data) {
218 if (*shmlogname != '\0') {
219 shm_unlink(shmlogname);
220 }
221 raise(sig);
222}
223
224/*
225 * (One-shot) Handler for all signals with default action "Term", see signal(7)
226 *
227 * Exits the program gracefully.
228 *
229 */
230static void handle_term_signal(struct ev_loop *loop, ev_signal *signal, int revents) {
231 /* We exit gracefully here in the sense that cleanup handlers
232 * installed via atexit are invoked. */
233 exit(128 + signal->signum);
234}
235
236/*
237 * Set up handlers for all signals with default action "Term", see signal(7)
238 *
239 */
240static void setup_term_handlers(void) {
241 static struct ev_signal signal_watchers[6];
242 const size_t num_watchers = sizeof(signal_watchers) / sizeof(signal_watchers[0]);
243
244 /* We have to rely on libev functionality here and should not use
245 * sigaction handlers because we need to invoke the exit handlers
246 * and cannot do so from an asynchronous signal handling context as
247 * not all code triggered during exit is signal safe (and exiting
248 * the main loop from said handler is not easily possible). libev's
249 * signal handlers does not impose such a constraint on us. */
250 ev_signal_init(&signal_watchers[0], handle_term_signal, SIGHUP);
251 ev_signal_init(&signal_watchers[1], handle_term_signal, SIGINT);
252 ev_signal_init(&signal_watchers[2], handle_term_signal, SIGALRM);
253 ev_signal_init(&signal_watchers[3], handle_term_signal, SIGTERM);
254 ev_signal_init(&signal_watchers[4], handle_term_signal, SIGUSR1);
255 ev_signal_init(&signal_watchers[5], handle_term_signal, SIGUSR2);
256 for (size_t i = 0; i < num_watchers; i++) {
257 ev_signal_start(main_loop, &signal_watchers[i]);
258 /* The signal handlers should not block ev_run from returning
259 * and so none of the signal handlers should hold a reference to
260 * the main loop. */
261 ev_unref(main_loop);
262 }
263}
264
265static int parse_restart_fd(void) {
266 const char *restart_fd = getenv("_I3_RESTART_FD");
267 if (restart_fd == NULL) {
268 return -1;
269 }
270
271 long int fd = -1;
272 if (!parse_long(restart_fd, &fd, 10)) {
273 ELOG("Malformed _I3_RESTART_FD \"%s\"\n", restart_fd);
274 return -1;
275 }
276 return fd;
277}
278
279int main(int argc, char *argv[]) {
280 /* Keep a symbol pointing to the I3_VERSION string constant so that we have
281 * it in gdb backtraces. */
282 static const char *_i3_version __attribute__((used)) = I3_VERSION;
283 char *override_configpath = NULL;
284 bool autostart = true;
285 char *layout_path = NULL;
286 bool delete_layout_path = false;
287 bool disable_randr15 = false;
288 char *fake_outputs = NULL;
289 bool disable_signalhandler = false;
290 bool only_check_config = false;
291 bool replace_wm = false;
292 static struct option long_options[] = {
293 {"no-autostart", no_argument, 0, 'a'},
294 {"config", required_argument, 0, 'c'},
295 {"version", no_argument, 0, 'v'},
296 {"moreversion", no_argument, 0, 'm'},
297 {"more-version", no_argument, 0, 'm'},
298 {"more_version", no_argument, 0, 'm'},
299 {"help", no_argument, 0, 'h'},
300 {"layout", required_argument, 0, 'L'},
301 {"restart", required_argument, 0, 0},
302 {"force-xinerama", no_argument, 0, 0},
303 {"force_xinerama", no_argument, 0, 0},
304 {"disable-randr15", no_argument, 0, 0},
305 {"disable_randr15", no_argument, 0, 0},
306 {"disable-signalhandler", no_argument, 0, 0},
307 {"shmlog-size", required_argument, 0, 0},
308 {"shmlog_size", required_argument, 0, 0},
309 {"get-socketpath", no_argument, 0, 0},
310 {"get_socketpath", no_argument, 0, 0},
311 {"fake_outputs", required_argument, 0, 0},
312 {"fake-outputs", required_argument, 0, 0},
313 {"force-old-config-parser-v4.4-only", no_argument, 0, 0},
314 {"replace", no_argument, 0, 'r'},
315 {0, 0, 0, 0}};
316 int option_index = 0, opt;
317
318 setlocale(LC_ALL, "");
319
320 /* Get the RLIMIT_CORE limit at startup time to restore this before
321 * starting processes. */
322 getrlimit(RLIMIT_CORE, &original_rlimit_core);
323
324 /* Disable output buffering to make redirects in .xsession actually useful for debugging */
325 if (!isatty(fileno(stdout))) {
326 setbuf(stdout, NULL);
327 }
328
329 srand(time(NULL));
330
331 /* Init logging *before* initializing debug_build to guarantee early
332 * (file) logging. */
333 init_logging();
334
335 /* On release builds, disable SHM logging by default. */
336 shmlog_size = (is_debug_build() || strstr(argv[0], "i3-with-shmlog") != NULL ? default_shmlog_size : 0);
337
338 start_argv = argv;
339
340 while ((opt = getopt_long(argc, argv, "c:CvmaL:hld:Vr", long_options, &option_index)) != -1) {
341 switch (opt) {
342 case 'a':
343 LOG("Autostart disabled using -a\n");
344 autostart = false;
345 break;
346 case 'L':
347 FREE(layout_path);
348 layout_path = sstrdup(optarg);
349 delete_layout_path = false;
350 break;
351 case 'c':
352 FREE(override_configpath);
353 override_configpath = sstrdup(optarg);
354 break;
355 case 'C':
356 LOG("Checking configuration file only (-C)\n");
357 only_check_config = true;
358 break;
359 case 'v':
360 printf("i3 version %s © 2009 Michael Stapelberg and contributors\n", i3_version);
361 exit(EXIT_SUCCESS);
362 break;
363 case 'm':
364 printf("Binary i3 version: %s © 2009 Michael Stapelberg and contributors\n", i3_version);
366 exit(EXIT_SUCCESS);
367 break;
368 case 'V':
369 set_verbosity(true);
370 break;
371 case 'd':
372 LOG("Enabling debug logging\n");
373 set_debug_logging(true);
374 break;
375 case 'l':
376 /* DEPRECATED, ignored for the next 3 versions (3.e, 3.f, 3.g) */
377 break;
378 case 'r':
379 replace_wm = true;
380 break;
381 case 0:
382 if (strcmp(long_options[option_index].name, "force-xinerama") == 0 ||
383 strcmp(long_options[option_index].name, "force_xinerama") == 0) {
384 force_xinerama = true;
385 ELOG("Using Xinerama instead of RandR. This option should be "
386 "avoided at all cost because it does not refresh the list "
387 "of screens, so you cannot configure displays at runtime. "
388 "Please check if your driver really does not support RandR "
389 "and disable this option as soon as you can.\n");
390 break;
391 } else if (strcmp(long_options[option_index].name, "disable-randr15") == 0 ||
392 strcmp(long_options[option_index].name, "disable_randr15") == 0) {
393 disable_randr15 = true;
394 break;
395 } else if (strcmp(long_options[option_index].name, "disable-signalhandler") == 0) {
396 disable_signalhandler = true;
397 break;
398 } else if (strcmp(long_options[option_index].name, "get-socketpath") == 0 ||
399 strcmp(long_options[option_index].name, "get_socketpath") == 0) {
400 char *socket_path = root_atom_contents("I3_SOCKET_PATH", NULL, 0);
401 if (socket_path) {
402 printf("%s\n", socket_path);
403 /* With -O2 (i.e. the buildtype=debugoptimized meson
404 * option, which we set by default), gcc 9.2.1 optimizes
405 * away socket_path at this point, resulting in a Leak
406 * Sanitizer report. An explicit free helps: */
407 free(socket_path);
408 exit(EXIT_SUCCESS);
409 }
410
411 exit(EXIT_FAILURE);
412 } else if (strcmp(long_options[option_index].name, "shmlog-size") == 0 ||
413 strcmp(long_options[option_index].name, "shmlog_size") == 0) {
414 shmlog_size = atoi(optarg);
415 /* Re-initialize logging immediately to get as many
416 * logmessages as possible into the SHM log. */
417 init_logging();
418 LOG("Limiting SHM log size to %d bytes\n", shmlog_size);
419 break;
420 } else if (strcmp(long_options[option_index].name, "restart") == 0) {
421 FREE(layout_path);
422 layout_path = sstrdup(optarg);
423 delete_layout_path = true;
424 break;
425 } else if (strcmp(long_options[option_index].name, "fake-outputs") == 0 ||
426 strcmp(long_options[option_index].name, "fake_outputs") == 0) {
427 LOG("Initializing fake outputs: %s\n", optarg);
428 fake_outputs = sstrdup(optarg);
429 break;
430 } else if (strcmp(long_options[option_index].name, "force-old-config-parser-v4.4-only") == 0) {
431 ELOG("You are passing --force-old-config-parser-v4.4-only, but that flag was removed by now.\n");
432 break;
433 }
434 /* fall-through */
435 default:
436 fprintf(stderr, "Usage: %s [-c configfile] [-d all] [-a] [-v] [-V] [-C]\n", argv[0]);
437 fprintf(stderr, "\n");
438 fprintf(stderr, "\t-a disable autostart ('exec' lines in config)\n");
439 fprintf(stderr, "\t-c <file> use the provided configfile instead\n");
440 fprintf(stderr, "\t-C validate configuration file and exit\n");
441 fprintf(stderr, "\t-d all enable debug output\n");
442 fprintf(stderr, "\t-L <file> path to the serialized layout during restarts\n");
443 fprintf(stderr, "\t-v display version and exit\n");
444 fprintf(stderr, "\t-V enable verbose mode\n");
445 fprintf(stderr, "\n");
446 fprintf(stderr, "\t--force-xinerama\n"
447 "\tUse Xinerama instead of RandR.\n"
448 "\tThis option should only be used if you are stuck with the\n"
449 "\told nVidia closed source driver (older than 302.17), which does\n"
450 "\tnot support RandR.\n");
451 fprintf(stderr, "\n");
452 fprintf(stderr, "\t--get-socketpath\n"
453 "\tRetrieve the i3 IPC socket path from X11, print it, then exit.\n");
454 fprintf(stderr, "\n");
455 fprintf(stderr, "\t--shmlog-size <limit>\n"
456 "\tLimits the size of the i3 SHM log to <limit> bytes. Setting this\n"
457 "\tto 0 disables SHM logging entirely.\n"
458 "\tThe default is %d bytes.\n",
460 fprintf(stderr, "\n");
461 fprintf(stderr, "\t--replace\n"
462 "\tReplace an existing window manager.\n");
463 fprintf(stderr, "\n");
464 fprintf(stderr, "If you pass plain text arguments, i3 will interpret them as a command\n"
465 "to send to a currently running i3 (like i3-msg). This allows you to\n"
466 "use nice and logical commands, such as:\n"
467 "\n"
468 "\ti3 border none\n"
469 "\ti3 floating toggle\n"
470 "\ti3 kill window\n"
471 "\n");
472 exit(opt == 'h' ? EXIT_SUCCESS : EXIT_FAILURE);
473 }
474 }
475
476 if (only_check_config) {
477 exit(load_configuration(override_configpath, C_VALIDATE) ? EXIT_SUCCESS : EXIT_FAILURE);
478 }
479
480 /* If the user passes more arguments, we act like i3-msg would: Just send
481 * the arguments as an IPC message to i3. This allows for nice semantic
482 * commands such as 'i3 border none'. */
483 if (optind < argc) {
484 /* We enable verbose mode so that the user knows what’s going on.
485 * This should make it easier to find mistakes when the user passes
486 * arguments by mistake. */
487 set_verbosity(true);
488
489 LOG("Additional arguments passed. Sending them as a command to i3.\n");
490 char *payload = NULL;
491 while (optind < argc) {
492 if (!payload) {
493 payload = sstrdup(argv[optind]);
494 } else {
495 char *both;
496 sasprintf(&both, "%s %s", payload, argv[optind]);
497 free(payload);
498 payload = both;
499 }
500 optind++;
501 }
502 DLOG("Command is: %s (%zd bytes)\n", payload, strlen(payload));
503 char *socket_path = root_atom_contents("I3_SOCKET_PATH", NULL, 0);
504 if (!socket_path) {
505 ELOG("Could not get i3 IPC socket path\n");
506 return 1;
507 }
508
509 int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
510 if (sockfd == -1) {
511 err(EXIT_FAILURE, "Could not create socket");
512 }
513
514 struct sockaddr_un addr;
515 memset(&addr, 0, sizeof(struct sockaddr_un));
516 addr.sun_family = AF_LOCAL;
517 strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
518 FREE(socket_path);
519 if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
520 err(EXIT_FAILURE, "Could not connect to i3");
521 }
522
523 if (ipc_send_message(sockfd, strlen(payload), I3_IPC_MESSAGE_TYPE_RUN_COMMAND,
524 (uint8_t *)payload) == -1) {
525 err(EXIT_FAILURE, "IPC: write()");
526 }
527 FREE(payload);
528
529 uint32_t reply_length;
530 uint32_t reply_type;
531 uint8_t *reply;
532 int ret;
533 if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
534 if (ret == -1) {
535 err(EXIT_FAILURE, "IPC: read()");
536 }
537 return 1;
538 }
539 if (reply_type != I3_IPC_REPLY_TYPE_COMMAND) {
540 errx(EXIT_FAILURE, "IPC: received reply of type %d but expected %d (COMMAND)", reply_type, I3_IPC_REPLY_TYPE_COMMAND);
541 }
542 printf("%.*s\n", reply_length, reply);
543 FREE(reply);
544 return 0;
545 }
546
547 /* Enable logging to handle the case when the user did not specify --shmlog-size */
548 init_logging();
549
550 /* Try to enable core dumps by default when running a debug build */
551 if (is_debug_build()) {
552 struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY};
553 setrlimit(RLIMIT_CORE, &limit);
554
555 /* The following code is helpful, but not required. We thus don’t pay
556 * much attention to error handling, non-linux or other edge cases. */
557 LOG("CORE DUMPS: You are running a development version of i3, so coredumps were automatically enabled (ulimit -c unlimited).\n");
558 size_t cwd_size = 1024;
559 char *cwd = smalloc(cwd_size);
560 char *cwd_ret;
561 while ((cwd_ret = getcwd(cwd, cwd_size)) == NULL && errno == ERANGE) {
562 cwd_size = cwd_size * 2;
563 cwd = srealloc(cwd, cwd_size);
564 }
565 if (cwd_ret != NULL) {
566 LOG("CORE DUMPS: Your current working directory is \"%s\".\n", cwd);
567 }
568 int patternfd;
569 if ((patternfd = open("/proc/sys/kernel/core_pattern", O_RDONLY)) >= 0) {
570 memset(cwd, '\0', cwd_size);
571 if (read(patternfd, cwd, cwd_size) > 0) {
572 /* a trailing newline is included in cwd */
573 LOG("CORE DUMPS: Your core_pattern is: %s", cwd);
574 }
575 close(patternfd);
576 }
577 free(cwd);
578 }
579
580 LOG("i3 %s starting\n", i3_version);
581
582 conn = xcb_connect(NULL, &conn_screen);
583 if (xcb_connection_has_error(conn)) {
584 errx(EXIT_FAILURE, "Cannot open display");
585 }
586
587 sndisplay = sn_xcb_display_new(conn, NULL, NULL);
588
589 /* Initialize the libev event loop. This needs to be done before loading
590 * the config file because the parser will install an ev_child watcher
591 * for the nagbar when config errors are found.
592 *
593 * Main loop must be ev's default loop because (at the moment of writing)
594 * only the default loop can handle ev_child events and reap zombies
595 * (the start_application routine relies on that too). */
596 main_loop = EV_DEFAULT;
597 if (main_loop == NULL) {
598 die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
599 }
600
601 root_screen = xcb_aux_get_screen(conn, conn_screen);
602 root = root_screen->root;
603
604 /* Prefetch X11 extensions that we are interested in. */
605 xcb_prefetch_extension_data(conn, &xcb_xkb_id);
606 xcb_prefetch_extension_data(conn, &xcb_shape_id);
607 /* BIG-REQUESTS is used by libxcb internally. */
608 xcb_prefetch_extension_data(conn, &xcb_big_requests_id);
609 if (force_xinerama) {
610 xcb_prefetch_extension_data(conn, &xcb_xinerama_id);
611 } else {
612 xcb_prefetch_extension_data(conn, &xcb_randr_id);
613 }
614
615 /* Prepare for us to get a current timestamp as recommended by ICCCM */
616 xcb_change_window_attributes(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_PROPERTY_CHANGE});
617 xcb_change_property(conn, XCB_PROP_MODE_APPEND, root, XCB_ATOM_SUPERSCRIPT_X, XCB_ATOM_CARDINAL, 32, 0, "");
618
619 /* Place requests for the atoms we need as soon as possible */
620#define xmacro(atom) \
621 xcb_intern_atom_cookie_t atom##_cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
624#undef xmacro
625
626 root_depth = root_screen->root_depth;
627 colormap = root_screen->default_colormap;
628 visual_type = xcb_aux_find_visual_by_attrs(root_screen, -1, 32);
629 if (visual_type != NULL) {
630 root_depth = xcb_aux_get_depth_of_visual(root_screen, visual_type->visual_id);
631 colormap = xcb_generate_id(conn);
632
633 xcb_void_cookie_t cm_cookie = xcb_create_colormap_checked(conn,
634 XCB_COLORMAP_ALLOC_NONE,
635 colormap,
636 root,
637 visual_type->visual_id);
638
639 xcb_generic_error_t *error = xcb_request_check(conn, cm_cookie);
640 if (error != NULL) {
641 ELOG("Could not create colormap. Error code: %d\n", error->error_code);
642 exit(EXIT_FAILURE);
643 }
644 } else {
646 }
647
648 xcb_prefetch_maximum_request_length(conn);
649
650 init_dpi();
651
652 DLOG("root_depth = %d, visual_id = 0x%08x.\n", root_depth, visual_type->visual_id);
653 DLOG("root_screen->height_in_pixels = %d, root_screen->height_in_millimeters = %d\n",
654 root_screen->height_in_pixels, root_screen->height_in_millimeters);
655 DLOG("One logical pixel corresponds to %d physical pixels on this display.\n", logical_px(1));
656
657 xcb_get_geometry_cookie_t gcookie = xcb_get_geometry(conn, root);
658 xcb_query_pointer_cookie_t pointercookie = xcb_query_pointer(conn, root);
659
660 /* Get the PropertyNotify event we caused above */
661 xcb_flush(conn);
662 {
663 xcb_generic_event_t *event;
664 DLOG("waiting for PropertyNotify event\n");
665 while ((event = xcb_wait_for_event(conn)) != NULL) {
666 if (event->response_type == XCB_PROPERTY_NOTIFY) {
667 last_timestamp = ((xcb_property_notify_event_t *)event)->time;
668 free(event);
669 break;
670 }
671 free(event);
672 }
673 DLOG("got timestamp %d\n", last_timestamp);
674 }
675
676 /* Setup NetWM atoms */
677#define xmacro(name) \
678 do { \
679 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, name##_cookie, NULL); \
680 if (!reply) { \
681 ELOG("Could not get atom " #name "\n"); \
682 exit(-1); \
683 } \
684 A_##name = reply->atom; \
685 free(reply); \
686 } while (0);
689#undef xmacro
690
691 load_configuration(override_configpath, C_LOAD);
692
693 if (config.ipc_socket_path == NULL) {
694 /* Fall back to a file name in /tmp/ based on the PID */
695 if ((config.ipc_socket_path = getenv("I3SOCK")) == NULL) {
697 } else {
699 }
700 }
701 /* Create the UNIX domain socket for IPC */
703 if (ipc_socket == -1) {
704 die("Could not create the IPC socket: %s", config.ipc_socket_path);
705 }
706
708 force_xinerama = true;
709 }
710
711 /* Acquire the WM_Sn selection. */
712 {
713 /* Get the WM_Sn atom */
714 char *atom_name = xcb_atom_name_by_screen("WM", conn_screen);
715 wm_sn_selection_owner = xcb_generate_id(conn);
716
717 if (atom_name == NULL) {
718 ELOG("xcb_atom_name_by_screen(\"WM\", %d) failed, exiting\n", conn_screen);
719 return 1;
720 }
721
722 xcb_intern_atom_reply_t *atom_reply;
723 atom_reply = xcb_intern_atom_reply(conn,
724 xcb_intern_atom_unchecked(conn,
725 0,
726 strlen(atom_name),
727 atom_name),
728 NULL);
729 free(atom_name);
730 if (atom_reply == NULL) {
731 ELOG("Failed to intern the WM_Sn atom, exiting\n");
732 return 1;
733 }
734 wm_sn = atom_reply->atom;
735 free(atom_reply);
736
737 /* Check if the selection is already owned */
738 xcb_get_selection_owner_reply_t *selection_reply =
739 xcb_get_selection_owner_reply(conn,
740 xcb_get_selection_owner(conn, wm_sn),
741 NULL);
742 if (selection_reply && selection_reply->owner != XCB_NONE && !replace_wm) {
743 ELOG("Another window manager is already running (WM_Sn is owned)");
744 return 1;
745 }
746
747 /* Become the selection owner */
748 xcb_create_window(conn,
749 root_screen->root_depth,
750 wm_sn_selection_owner, /* window id */
751 root_screen->root, /* parent */
752 -1, -1, 1, 1, /* geometry */
753 0, /* border width */
754 XCB_WINDOW_CLASS_INPUT_OUTPUT,
755 root_screen->root_visual,
756 0, NULL);
757 xcb_change_property(conn,
758 XCB_PROP_MODE_REPLACE,
760 XCB_ATOM_WM_CLASS,
761 XCB_ATOM_STRING,
762 8,
763 (strlen("i3-WM_Sn") + 1) * 2,
764 "i3-WM_Sn\0i3-WM_Sn\0");
765
766 xcb_set_selection_owner(conn, wm_sn_selection_owner, wm_sn, last_timestamp);
767
768 if (selection_reply && selection_reply->owner != XCB_NONE) {
769 unsigned int usleep_time = 100000; /* 0.1 seconds */
770 int check_rounds = 150; /* Wait for a maximum of 15 seconds */
771 xcb_get_geometry_reply_t *geom_reply = NULL;
772
773 DLOG("waiting for old WM_Sn selection owner to exit");
774 do {
775 free(geom_reply);
776 usleep(usleep_time);
777 if (check_rounds-- == 0) {
778 ELOG("The old window manager is not exiting");
779 return 1;
780 }
781 geom_reply = xcb_get_geometry_reply(conn,
782 xcb_get_geometry(conn, selection_reply->owner),
783 NULL);
784 } while (geom_reply != NULL);
785 }
786 free(selection_reply);
787
788 /* Announce that we are the new owner */
789 /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
790 * In order to properly initialize these bytes, we allocate 32 bytes even
791 * though we only need less for an xcb_client_message_event_t */
792 union {
793 xcb_client_message_event_t message;
794 char storage[32];
795 } event;
796 memset(&event, 0, sizeof(event));
797 event.message.response_type = XCB_CLIENT_MESSAGE;
798 event.message.window = root_screen->root;
799 event.message.format = 32;
800 event.message.type = A_MANAGER;
801 event.message.data.data32[0] = last_timestamp;
802 event.message.data.data32[1] = wm_sn;
803 event.message.data.data32[2] = wm_sn_selection_owner;
804
805 xcb_send_event(conn, 0, root_screen->root, XCB_EVENT_MASK_STRUCTURE_NOTIFY, event.storage);
806 }
807
808 xcb_void_cookie_t cookie;
809 cookie = xcb_change_window_attributes_checked(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){ROOT_EVENT_MASK});
810 xcb_generic_error_t *error = xcb_request_check(conn, cookie);
811 if (error != NULL) {
812 ELOG("Another window manager seems to be running (X error %d)\n", error->error_code);
813#ifdef I3_ASAN_ENABLED
814 __lsan_do_leak_check();
815#endif
816 return 1;
817 }
818
819 xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(conn, gcookie, NULL);
820 if (greply == NULL) {
821 ELOG("Could not get geometry of the root window, exiting\n");
822 return 1;
823 }
824 DLOG("root geometry reply: (%d, %d) %d x %d\n", greply->x, greply->y, greply->width, greply->height);
825
827
828 /* Set a cursor for the root window (otherwise the root window will show no
829 cursor until the first client is launched). */
831
832 const xcb_query_extension_reply_t *extreply;
833 extreply = xcb_get_extension_data(conn, &xcb_xkb_id);
834 xkb_supported = extreply->present;
835 if (!extreply->present) {
836 DLOG("xkb is not present on this server\n");
837 } else {
838 DLOG("initializing xcb-xkb\n");
839 xcb_xkb_use_extension(conn, XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION);
840 xcb_xkb_select_events(conn,
841 XCB_XKB_ID_USE_CORE_KBD,
842 XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_MAP_NOTIFY | XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY,
843 0,
844 XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_MAP_NOTIFY | XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY,
845 0xff,
846 0xff,
847 NULL);
848
849 /* Setting both, XCB_XKB_PER_CLIENT_FLAG_GRABS_USE_XKB_STATE and
850 * XCB_XKB_PER_CLIENT_FLAG_LOOKUP_STATE_WHEN_GRABBED, will lead to the
851 * X server sending us the full XKB state in KeyPress and KeyRelease:
852 * https://cgit.freedesktop.org/xorg/xserver/tree/xkb/xkbEvents.c?h=xorg-server-1.20.0#n927
853 *
854 * XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT enable detectable autorepeat:
855 * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Detectable_Autorepeat
856 * This affects bindings using the --release flag: instead of getting multiple KeyRelease
857 * events we get only one event when the key is physically released by the user.
858 */
859 const uint32_t mask = XCB_XKB_PER_CLIENT_FLAG_GRABS_USE_XKB_STATE |
860 XCB_XKB_PER_CLIENT_FLAG_LOOKUP_STATE_WHEN_GRABBED |
861 XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT;
862 xcb_xkb_per_client_flags_reply_t *pcf_reply;
863 /* The last three parameters are unset because they are only relevant
864 * when using a feature called “automatic reset of boolean controls”:
865 * https://www.x.org/releases/X11R7.7/doc/kbproto/xkbproto.html#Automatic_Reset_of_Boolean_Controls
866 * */
867 pcf_reply = xcb_xkb_per_client_flags_reply(
868 conn,
869 xcb_xkb_per_client_flags(
870 conn,
871 XCB_XKB_ID_USE_CORE_KBD,
872 mask,
873 mask,
874 0 /* uint32_t ctrlsToChange */,
875 0 /* uint32_t autoCtrls */,
876 0 /* uint32_t autoCtrlsValues */),
877 NULL);
878
879#define PCF_REPLY_ERROR(_value) \
880 do { \
881 if (pcf_reply == NULL || !(pcf_reply->value & (_value))) { \
882 ELOG("Could not set " #_value "\n"); \
883 } \
884 } while (0)
885
886 PCF_REPLY_ERROR(XCB_XKB_PER_CLIENT_FLAG_GRABS_USE_XKB_STATE);
887 PCF_REPLY_ERROR(XCB_XKB_PER_CLIENT_FLAG_LOOKUP_STATE_WHEN_GRABBED);
888 PCF_REPLY_ERROR(XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT);
889
890 free(pcf_reply);
891 xkb_base = extreply->first_event;
892 }
893
894 /* Check for Shape extension. We want to handle input shapes which is
895 * introduced in 1.1. */
896 extreply = xcb_get_extension_data(conn, &xcb_shape_id);
897 if (extreply->present) {
898 shape_base = extreply->first_event;
899 xcb_shape_query_version_cookie_t cookie = xcb_shape_query_version(conn);
900 xcb_shape_query_version_reply_t *version =
901 xcb_shape_query_version_reply(conn, cookie, NULL);
902 shape_supported = version && version->minor_version >= 1;
903 free(version);
904 } else {
905 shape_supported = false;
906 }
907 if (!shape_supported) {
908 DLOG("shape 1.1 is not present on this server\n");
909 }
910
912
914
916
917 keysyms = xcb_key_symbols_alloc(conn);
918
920
921 if (!load_keymap()) {
922 die("Could not load keymap\n");
923 }
924
927
928 bool needs_tree_init = true;
929 if (layout_path != NULL) {
930 LOG("Trying to restore the layout from \"%s\".\n", layout_path);
931 needs_tree_init = !tree_restore(layout_path, greply);
932 if (delete_layout_path) {
933 unlink(layout_path);
934 const char *dir = dirname(layout_path);
935 /* possibly fails with ENOTEMPTY if there are files (or
936 * sockets) left. */
937 rmdir(dir);
938 }
939 }
940 if (needs_tree_init) {
941 tree_init(greply);
942 }
943
944 free(greply);
945
946 /* Setup fake outputs for testing */
947 if (fake_outputs == NULL && config.fake_outputs != NULL) {
948 fake_outputs = config.fake_outputs;
949 }
950
951 if (fake_outputs != NULL) {
952 fake_outputs_init(fake_outputs);
953 FREE(fake_outputs);
954 config.fake_outputs = NULL;
955 } else if (force_xinerama) {
956 /* Force Xinerama (for drivers which don't support RandR yet, esp. the
957 * nVidia binary graphics driver), when specified either in the config
958 * file or on command-line */
960 } else {
961 DLOG("Checking for XRandR...\n");
962 randr_init(&randr_base, disable_randr15 || config.disable_randr15);
963 }
964
965 /* We need to force disabling outputs which have been loaded from the
966 * layout file but are no longer active. This can happen if the output has
967 * been disabled in the short time between writing the restart layout file
968 * and restarting i3. See #2326. */
969 if (layout_path != NULL && randr_base > -1) {
970 Con *con;
971 TAILQ_FOREACH (con, &(croot->nodes_head), nodes) {
972 Output *output;
973 TAILQ_FOREACH (output, &outputs, outputs) {
974 if (output->active || strcmp(con->name, output_primary_name(output)) != 0) {
975 continue;
976 }
977
978 /* This will correctly correlate the output with its content
979 * container. We need to make the connection to properly
980 * disable the output. */
981 if (output->con == NULL) {
982 output_init_con(output);
983 output->changed = false;
984 }
985
986 output->to_be_disabled = true;
987 randr_disable_output(output);
988 }
989 }
990 }
991 FREE(layout_path);
992
994
995 xcb_query_pointer_reply_t *pointerreply;
996 Output *output = NULL;
997 if (!(pointerreply = xcb_query_pointer_reply(conn, pointercookie, NULL))) {
998 ELOG("Could not query pointer position, using first screen\n");
999 } else {
1000 DLOG("Pointer at %d, %d\n", pointerreply->root_x, pointerreply->root_y);
1001 output = get_output_containing(pointerreply->root_x, pointerreply->root_y);
1002 if (!output) {
1003 ELOG("ERROR: No screen at (%d, %d), starting on the first screen\n",
1004 pointerreply->root_x, pointerreply->root_y);
1005 }
1006 }
1007 if (!output) {
1008 output = get_first_output();
1009 }
1011 free(pointerreply);
1012
1013 tree_render();
1014
1015 /* Listen to the IPC socket for clients */
1016 struct ev_io *ipc_io = scalloc(1, sizeof(struct ev_io));
1017 ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ);
1018 ev_io_start(main_loop, ipc_io);
1019
1020 /* Chose a file name in /tmp/ based on the PID */
1021 char *log_stream_socket_path = get_process_filename("log-stream-socket");
1022 int log_socket = create_socket(log_stream_socket_path, &current_log_stream_socket_path);
1023 free(log_stream_socket_path);
1024 struct ev_io *log_io = NULL;
1025 if (log_socket == -1) {
1026 ELOG("Could not create the log socket, i3-dump-log -f will not work\n");
1027 } else {
1028 log_io = scalloc(1, sizeof(struct ev_io));
1029 ev_io_init(log_io, log_new_client, log_socket, EV_READ);
1030 ev_io_start(main_loop, log_io);
1031 }
1032
1033 /* Also handle the UNIX domain sockets passed via socket
1034 * activation. The parameter 0 means "do not remove the
1035 * environment variables", we need to be able to reexec. */
1036 struct ev_io *socket_ipc_io = NULL;
1038 if (listen_fds < 0) {
1039 ELOG("socket activation: Error in sd_listen_fds\n");
1040 } else if (listen_fds == 0) {
1041 DLOG("socket activation: no sockets passed\n");
1042 } else {
1043 int flags;
1044 for (int fd = SD_LISTEN_FDS_START;
1046 fd++) {
1047 DLOG("socket activation: also listening on fd %d\n", fd);
1048
1049 /* sd_listen_fds() enables FD_CLOEXEC by default.
1050 * However, we need to keep the file descriptors open for in-place
1051 * restarting, therefore we explicitly disable FD_CLOEXEC. */
1052 if ((flags = fcntl(fd, F_GETFD)) < 0 ||
1053 fcntl(fd, F_SETFD, flags & ~FD_CLOEXEC) < 0) {
1054 ELOG("Could not disable FD_CLOEXEC on fd %d\n", fd);
1055 }
1056
1057 socket_ipc_io = scalloc(1, sizeof(struct ev_io));
1058 ev_io_init(socket_ipc_io, ipc_new_client, fd, EV_READ);
1059 ev_io_start(main_loop, socket_ipc_io);
1060 }
1061 }
1062
1063 {
1064 const int restart_fd = parse_restart_fd();
1065 if (restart_fd != -1) {
1066 DLOG("serving restart fd %d", restart_fd);
1067 ipc_client *client = ipc_new_client_on_fd(main_loop, restart_fd);
1068 ipc_confirm_restart(client);
1069 unsetenv("_I3_RESTART_FD");
1070 }
1071 }
1072
1073 /* Set up i3 specific atoms like I3_SOCKET_PATH and I3_CONFIG_PATH */
1076
1077 /* Set the ewmh desktop properties. */
1079
1080 struct ev_io *xcb_watcher = scalloc(1, sizeof(struct ev_io));
1081 xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
1082
1083 ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
1084 ev_io_start(main_loop, xcb_watcher);
1085
1086 ev_prepare_init(xcb_prepare, xcb_prepare_cb);
1087 ev_prepare_start(main_loop, xcb_prepare);
1088
1089 xcb_flush(conn);
1090
1091 /* What follows is a fugly consequence of X11 protocol race conditions like
1092 * the following: In an i3 in-place restart, i3 will reparent all windows
1093 * to the root window, then exec() itself. In the new process, it calls
1094 * manage_existing_windows. However, in case any application sent a
1095 * generated UnmapNotify message to the WM (as GIMP does), this message
1096 * will be handled by i3 *after* managing the window, thus i3 thinks the
1097 * window just closed itself. In reality, the message was sent in the time
1098 * period where i3 wasn’t running yet.
1099 *
1100 * To prevent this, we grab the server (disables processing of any other
1101 * connections), then discard all pending events (since we didn’t do
1102 * anything, there cannot be any meaningful responses), then ungrab the
1103 * server. */
1104 xcb_grab_server(conn);
1105 {
1106 xcb_aux_sync(conn);
1107 xcb_generic_event_t *event;
1108 while ((event = xcb_poll_for_event(conn)) != NULL) {
1109 if (event->response_type == 0) {
1110 free(event);
1111 continue;
1112 }
1113
1114 /* Strip off the highest bit (set if the event is generated) */
1115 int type = (event->response_type & 0x7F);
1116
1117 /* We still need to handle MapRequests which are sent in the
1118 * timespan starting from when we register as a window manager and
1119 * this piece of code which drops events. */
1120 if (type == XCB_MAP_REQUEST) {
1121 handle_event(type, event);
1122 }
1123
1124 free(event);
1125 }
1127 }
1128 xcb_ungrab_server(conn);
1129
1130 if (autostart) {
1131 /* When the root's window background is set to NONE, that might mean
1132 * that old content stays visible when a window is closed. That has
1133 * unpleasant effect of "my terminal (does not seem to) close!".
1134 *
1135 * There does not seem to be an easy way to query for this problem, so
1136 * we test for it: Open & close a window and check if the background is
1137 * redrawn or the window contents stay visible.
1138 */
1139 LOG("This is not an in-place restart, checking if a wallpaper is set.\n");
1140
1141 xcb_screen_t *root = xcb_aux_get_screen(conn, conn_screen);
1142 if (is_background_set(conn, root)) {
1143 LOG("A wallpaper is set, so no screenshot is necessary.\n");
1144 } else {
1145 LOG("No wallpaper set, copying root window contents to a pixmap\n");
1147 }
1148 }
1149
1150 if (!disable_signalhandler) {
1152 } else {
1153 struct sigaction action;
1154
1155 action.sa_sigaction = handle_core_signal;
1156 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
1157 sigemptyset(&action.sa_mask);
1158
1159 /* Catch all signals with default action "Core", see signal(7) */
1160 if (sigaction(SIGQUIT, &action, NULL) == -1 ||
1161 sigaction(SIGILL, &action, NULL) == -1 ||
1162 sigaction(SIGABRT, &action, NULL) == -1 ||
1163 sigaction(SIGFPE, &action, NULL) == -1 ||
1164 sigaction(SIGSEGV, &action, NULL) == -1) {
1165 ELOG("Could not setup signal handler.\n");
1166 }
1167 }
1168
1170 /* Ignore SIGPIPE to survive errors when an IPC client disconnects
1171 * while we are sending them a message */
1172 signal(SIGPIPE, SIG_IGN);
1173
1174 /* Autostarting exec-lines */
1175 if (autostart) {
1176 while (!TAILQ_EMPTY(&autostarts)) {
1177 struct Autostart *exec = TAILQ_FIRST(&autostarts);
1178
1179 LOG("auto-starting %s\n", exec->command);
1181
1182 FREE(exec->command);
1184 FREE(exec);
1185 }
1186 }
1187
1188 /* Autostarting exec_always-lines */
1189 while (!TAILQ_EMPTY(&autostarts_always)) {
1190 struct Autostart *exec_always = TAILQ_FIRST(&autostarts_always);
1191
1192 LOG("auto-starting (always!) %s\n", exec_always->command);
1193 start_application(exec_always->command, exec_always->no_startup_id);
1194
1195 FREE(exec_always->command);
1197 FREE(exec_always);
1198 }
1199
1200 /* Start i3bar processes for all configured bars */
1201 Barconfig *barconfig;
1202 TAILQ_FOREACH (barconfig, &barconfigs, configs) {
1203 char *command = NULL;
1204 sasprintf(&command, "%s %s --bar_id=%s --socket=\"%s\"",
1205 barconfig->i3bar_command ? barconfig->i3bar_command : "exec i3bar",
1206 barconfig->verbose ? "-V" : "",
1207 barconfig->id, current_socketpath);
1208 LOG("Starting bar process: %s\n", command);
1210 free(command);
1211 }
1212
1213 /* Make sure to destroy the event loop to invoke the cleanup callbacks
1214 * when calling exit() */
1215 atexit(i3_exit);
1216
1217 /* There might be children who died before we initialized the event loop,
1218 * e.g., when restarting i3 (see #5756).
1219 * To not carry zombie children around, raise the signal to invite libev to
1220 * reap them.
1221 *
1222 * Note that there is no race condition between raising the signal below and
1223 * entering the event loop later: the signal is just to notify libev that
1224 * zombies might already be there. Actuall reaping will take place in the
1225 * event loop anyway. */
1226 (void)raise(SIGCHLD);
1227
1228 sd_notify(1, "READY=1");
1229 ev_loop(main_loop, 0);
1230
1231 /* Free these heap allocations just to satisfy LeakSanitizer. */
1232 FREE(ipc_io);
1233 FREE(socket_ipc_io);
1234 FREE(log_io);
1235 FREE(xcb_watcher);
1236}
bool load_keymap(void)
Loads the XKB keymap from the X11 server and feeds it to xkbcommon.
Definition bindings.c:983
void grab_all_keys(xcb_connection_t *conn)
Grab the bound keys (tell X to send us keypress events for those keycodes)
Definition bindings.c:155
pid_t command_error_nagbar_pid
Definition bindings.c:19
void translate_keysyms(void)
Translates keysymbols to keycodes for all bindings which use keysyms.
Definition bindings.c:449
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
Definition con.c:292
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
Definition con.c:1698
Config config
Definition config.c:19
bool load_configuration(const char *override_configpath, config_load_t load_type)
(Re-)loads the configuration file (sets useful defaults before).
Definition config.c:169
struct barconfig_head barconfigs
Definition config.c:21
pid_t config_error_nagbar_pid
void display_running_version(void)
Connects to i3 to find out the currently running version.
void ewmh_setup_hints(void)
Set up the EWMH hints on the root window.
Definition ewmh.c:309
void ewmh_update_desktop_properties(void)
Updates all the EWMH desktop properties.
Definition ewmh.c:118
void ewmh_update_workarea(void)
i3 currently does not support _NET_WORKAREA, because it does not correspond to i3’s concept of worksp...
Definition ewmh.c:241
void fake_outputs_init(const char *output_spec)
Creates outputs according to the given specification.
int randr_base
Definition handlers.c:20
void handle_event(int type, xcb_generic_event_t *event)
Takes an xcb_generic_event_t and calls the appropriate handler, based on the event type.
Definition handlers.c:1431
bool event_is_ignored(const int sequence, const int response_type)
Checks if the given sequence is ignored and returns true if so.
Definition handlers.c:52
int xkb_base
Definition handlers.c:21
void property_handlers_init(void)
Sets the appropriate atoms for the property handlers after the atoms were received from X11.
Definition handlers.c:1366
int shape_base
Definition handlers.c:23
void manage_existing_windows(xcb_window_t root)
Go through all existing windows (if the window manager is restarted) and manage them.
Definition manage.c:44
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Definition output.c:53
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition output.c:16
Output * get_output_containing(unsigned int x, unsigned int y)
Returns the active (!) output which contains the coordinates x, y or NULL if there is no output which...
Definition randr.c:122
void output_init_con(Output *output)
Initializes a CT_OUTPUT Con (searches existing ones from inplace restart before) to use for the given...
Definition randr.c:346
struct outputs_head outputs
Definition randr.c:22
void randr_init(int *event_base, const bool disable_randr15)
We have just established a connection to the X server and need the initial XRandR information to setu...
Definition randr.c:1099
Output * get_first_output(void)
Returns the first output which is active.
Definition randr.c:80
void randr_disable_output(Output *output)
Disables the output and moves its content.
Definition randr.c:1071
void restore_connect(void)
Opens a separate connection to X11 for placeholder windows when restoring layouts.
void scratchpad_fix_resolution(void)
When starting i3 initially (and after each change to the connected outputs), this function fixes the ...
Definition scratchpad.c:249
int sd_notify(int unset_environment, const char *state)
Definition sd-daemon.c:353
int sd_listen_fds(int unset_environment)
Definition sd-daemon.c:47
void setup_signal_handler(void)
Configured a signal handler to gracefully handle crashes and allow the user to generate a backtrace a...
Definition sighandler.c:335
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
Definition startup.c:134
bool tree_restore(const char *path, xcb_get_geometry_reply_t *geometry)
Loads tree from ~/.i3/_restart.json (used for in-place restarts).
Definition tree.c:66
struct Con * croot
Definition tree.c:12
void tree_init(xcb_get_geometry_reply_t *geometry)
Initializes the tree by creating the root node, adding all RandR outputs to the tree (that means rand...
Definition tree.c:130
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
Definition tree.c:455
__attribute__((pure))
Definition util.c:67
void kill_nagbar(pid_t nagbar_pid, bool wait_for_it)
Kills the i3-nagbar process, if nagbar_pid != -1.
Definition util.c:394
bool parse_long(const char *str, long *out, int base)
Converts a string into a long using strtol().
Definition util.c:419
const char * i3_version
Git commit identifier, from version.c.
Definition version.c:13
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
Definition x.c:1527
unsigned int xcb_numlock_mask
Definition xcb.c:12
void xcursor_load_cursors(void)
Definition xcursor.c:22
void xcursor_set_root_cursor(int cursor_id)
Sets the cursor of the root window to the 'pointer' cursor.
Definition xcursor.c:49
void xinerama_init(void)
We have just established a connection to the X server and need the initial Xinerama information to se...
Definition xinerama.c:112
void ipc_confirm_restart(ipc_client *client)
Sends a restart reply to the IPC client on the specified fd.
Definition ipc.c:1735
ipc_client * ipc_new_client_on_fd(EV_P_ int fd)
ipc_new_client_on_fd() only sets up the event handler for activity on the new connection and inserts ...
Definition ipc.c:1575
char * current_socketpath
Definition ipc.c:26
void ipc_shutdown(shutdown_reason_t reason, int exempt_fd)
Calls shutdown() on each socket and closes it.
Definition ipc.c:192
void ipc_new_client(EV_P_ struct ev_io *w, int revents)
Handler for activity on the listening socket, meaning that a new client has just connected and we sho...
Definition ipc.c:1550
int shmlog_size
Definition log.c:47
void log_new_client(EV_P_ struct ev_io *w, int revents)
Definition log.c:399
void init_logging(void)
Initializes logging by creating an error logfile in /tmp (or XDG_RUNTIME_DIR, see get_process_filenam...
Definition log.c:95
void set_debug_logging(const bool _debug_logging)
Set debug logging.
Definition log.c:221
char * current_log_stream_socket_path
Definition log.c:390
char * shmlogname
Definition log.c:44
void set_verbosity(bool _verbose)
Set verbosity of i3.
Definition log.c:205
xcb_timestamp_t last_timestamp
The last timestamp we got from X11 (timestamps are included in some events and are used for some thin...
Definition main.c:64
xcb_atom_t wm_sn
Definition main.c:70
int main(int argc, char *argv[])
Definition main.c:279
const int default_shmlog_size
Definition main.c:84
#define PCF_REPLY_ERROR(_value)
bool xkb_supported
Definition main.c:104
static void handle_term_signal(struct ev_loop *loop, ev_signal *signal, int revents)
Definition main.c:230
int conn_screen
Definition main.c:56
xcb_connection_t * conn
XCB connection and root screen.
Definition main.c:54
xcb_colormap_t colormap
Definition main.c:77
int listen_fds
The number of file descriptors passed via socket activation.
Definition main.c:46
bool force_xinerama
Definition main.c:107
xcb_key_symbols_t * keysyms
Definition main.c:81
uint8_t root_depth
Definition main.c:75
xcb_window_t wm_sn_selection_owner
Definition main.c:69
struct autostarts_always_head autostarts_always
Definition main.c:94
I3_NET_SUPPORTED_ATOMS_XMACRO static I3_REST_ATOMS_XMACRO void xcb_got_event(EV_P_ struct ev_io *w, int revents)
Definition main.c:120
SnDisplay * sndisplay
Definition main.c:59
static struct ev_prepare * xcb_prepare
Definition main.c:50
xcb_window_t root
Definition main.c:67
static void i3_exit(void)
Definition main.c:182
struct rlimit original_rlimit_core
The original value of RLIMIT_CORE when i3 was started.
Definition main.c:43
xcb_screen_t * root_screen
Definition main.c:66
const char * current_binding_mode
Definition main.c:88
static void setup_term_handlers(void)
Definition main.c:240
xcb_visualtype_t * visual_type
Definition main.c:76
static void handle_core_signal(int sig, siginfo_t *info, void *data)
Definition main.c:217
void main_set_x11_cb(bool enable)
Enable or disable the main X11 event handling function.
Definition main.c:166
struct autostarts_head autostarts
Definition main.c:91
char ** start_argv
Definition main.c:52
bool shape_supported
Definition main.c:105
static int parse_restart_fd(void)
Definition main.c:265
struct ev_loop * main_loop
Definition main.c:79
static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents)
Definition main.c:130
struct assignments_head assignments
Definition main.c:97
struct ws_assignments_head ws_assignments
Definition main.c:101
struct bindings_head * bindings
Definition main.c:87
@ C_VALIDATE
@ C_LOAD
#define I3_NET_SUPPORTED_ATOMS_XMACRO
#define I3_REST_ATOMS_XMACRO
bool only_check_config
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
#define DLOG(fmt,...)
Definition libi3.h:105
#define LOG(fmt,...)
Definition libi3.h:95
void set_screenshot_as_wallpaper(xcb_connection_t *conn, xcb_screen_t *screen)
Grab a screenshot of the screen's root window and set it as the wallpaper.
int create_socket(const char *filename, char **out_socketpath)
Creates the UNIX domain socket at the given path, sets it to non-blocking mode, bind()s and listen()s...
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define ELOG(fmt,...)
Definition libi3.h:100
int ipc_recv_message(int sockfd, uint32_t *message_type, uint32_t *reply_length, uint8_t **reply)
Reads a message from the given socket file descriptor and stores its length (reply_length) as well as...
uint32_t aio_get_mod_mask_for(uint32_t keysym, xcb_key_symbols_t *symbols)
All-in-one function which returns the modifier mask (XCB_MOD_MASK_*) for the given keysymbol,...
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...
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
char * root_atom_contents(const char *atomname, xcb_connection_t *provided_conn, int screen)
Try to get the contents of the given atom (for example I3_SOCKET_PATH) from the X11 root window and r...
char * get_process_filename(const char *prefix)
Returns the name of a temporary file with the specified prefix.
int ipc_send_message(int sockfd, const uint32_t message_size, const uint32_t message_type, const uint8_t *payload)
Formats a message (payload) of the given size and type and sends it to i3 via the given socket file d...
bool is_background_set(xcb_connection_t *conn, xcb_screen_t *screen)
Test whether the screen's root window has a background set.
bool is_debug_build(void) __attribute__((const))
Returns true if this version of i3 is a debug build (anything which is not a release version),...
void init_dpi(void)
Initialize the DPI setting.
xcb_visualtype_t * get_visualtype(xcb_screen_t *screen)
Returns the visual type associated with the given screen.
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:347
#define TAILQ_FIRST(head)
Definition queue.h:336
#define TAILQ_REMOVE(head, elm, field)
Definition queue.h:402
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:324
#define TAILQ_EMPTY(head)
Definition queue.h:344
#define SD_LISTEN_FDS_START
Definition sd-daemon.h:102
#define die(...)
Definition util.h:19
#define FREE(pointer)
Definition util.h:47
#define XCB_NUM_LOCK
Definition xcb.h:22
#define ROOT_EVENT_MASK
Definition xcb.h:42
@ XCURSOR_CURSOR_POINTER
Definition xcursor.h:17
@ SHUTDOWN_REASON_EXIT
Definition ipc.h:95
char * fake_outputs
Overwrites output detection (for testing), see src/fake_outputs.c.
char * ipc_socket_path
bool disable_randr15
Don’t use RandR 1.5 for querying outputs.
bool force_xinerama
By default, use the RandR API for multi-monitor setups.
Holds the status bar configuration (i3bar).
char * i3bar_command
Command that should be run to execute i3bar, give a full path if i3bar is not in your $PATH.
char * id
Automatically generated ID for this bar config.
bool verbose
Enable verbose mode? Useful for debugging purposes.
Holds a command specified by either an:
Definition data.h:369
bool no_startup_id
no_startup_id flag for start_application().
Definition data.h:374
char * command
Command, like in command mode.
Definition data.h:371
An Output is a physical output on your graphics driver.
Definition data.h:391
Con * con
Pointer to the Con which represents this output.
Definition data.h:411
bool changed
Internal flags, necessary for querying RandR screens (happens in two stages)
Definition data.h:401
bool to_be_disabled
Definition data.h:402
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
Definition data.h:397
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition data.h:643
char * name
Definition data.h:692