i3
main.c
Go to the documentation of this file.
1/*
2 * vim:ts=4:sw=4:expandtab
3 *
4 * i3 - an improved dynamic 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
12#include <ev.h>
13#include <fcntl.h>
14#include <sys/types.h>
15#include <sys/socket.h>
16#include <sys/un.h>
17#include <sys/time.h>
18#include <sys/resource.h>
19#include <sys/mman.h>
20#include <sys/stat.h>
21#include <libgen.h>
22#include "shmlog.h"
23
24#ifdef I3_ASAN_ENABLED
25#include <sanitizer/lsan_interface.h>
26#endif
27
28#include "sd-daemon.h"
29
30/* The original value of RLIMIT_CORE when i3 was started. We need to restore
31 * this before starting any other process, since we set RLIMIT_CORE to
32 * RLIM_INFINITY for i3 debugging versions. */
34
35/* The number of file descriptors passed via socket activation. */
37
38/* We keep the xcb_prepare watcher around to be able to enable and disable it
39 * temporarily for drag_pointer(). */
40static struct ev_prepare *xcb_prepare;
41
43
44xcb_connection_t *conn;
45/* The screen (0 when you are using DISPLAY=:0) of the connection 'conn' */
47
48/* Display handle for libstartup-notification */
49SnDisplay *sndisplay;
50
51/* The last timestamp we got from X11 (timestamps are included in some events
52 * and are used for some things, like determining a unique ID in startup
53 * notification). */
54xcb_timestamp_t last_timestamp = XCB_CURRENT_TIME;
55
56xcb_screen_t *root_screen;
57xcb_window_t root;
58
59/* Color depth, visual id and colormap to use when creating windows and
60 * pixmaps. Will use 32 bit depth and an appropriate visual, if available,
61 * otherwise the root window’s default (usually 24 bit TrueColor). */
62uint8_t root_depth;
63xcb_visualtype_t *visual_type;
64xcb_colormap_t colormap;
65
66struct ev_loop *main_loop;
67
68xcb_key_symbols_t *keysyms;
69
70/* Default shmlog size if not set by user. */
71const int default_shmlog_size = 25 * 1024 * 1024;
72
73/* The list of key bindings */
74struct bindings_head *bindings;
75
76/* The list of exec-lines */
78
79/* The list of exec_always lines */
81
82/* The list of assignments */
84
85/* The list of workspace assignments (which workspace should end up on which
86 * output) */
88
89/* We hope that those are supported and set them to true */
91bool xkb_supported = true;
92bool shape_supported = true;
93
94bool force_xinerama = false;
95
96/* Define all atoms as global variables */
97#define xmacro(atom) xcb_atom_t A_##atom;
98#include "atoms.xmacro"
99#undef xmacro
100
101/*
102 * This callback is only a dummy, see xcb_prepare_cb.
103 * See also man libev(3): "ev_prepare" and "ev_check" - customise your event loop
104 *
105 */
106static void xcb_got_event(EV_P_ struct ev_io *w, int revents) {
107 /* empty, because xcb_prepare_cb are used */
108}
109
110/*
111 * Called just before the event loop sleeps. Ensures xcb’s incoming and outgoing
112 * queues are empty so that any activity will trigger another event loop
113 * iteration, and hence another xcb_prepare_cb invocation.
114 *
115 */
116static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
117 /* Process all queued (and possibly new) events before the event loop
118 sleeps. */
119 xcb_generic_event_t *event;
120
121 while ((event = xcb_poll_for_event(conn)) != NULL) {
122 if (event->response_type == 0) {
123 if (event_is_ignored(event->sequence, 0))
124 DLOG("Expected X11 Error received for sequence %x\n", event->sequence);
125 else {
126 xcb_generic_error_t *error = (xcb_generic_error_t *)event;
127 DLOG("X11 Error received (probably harmless)! sequence 0x%x, error_code = %d\n",
128 error->sequence, error->error_code);
129 }
130 free(event);
131 continue;
132 }
133
134 /* Strip off the highest bit (set if the event is generated) */
135 int type = (event->response_type & 0x7F);
136
137 handle_event(type, event);
138
139 free(event);
140 }
141
142 /* Flush all queued events to X11. */
143 xcb_flush(conn);
144}
145
146/*
147 * Enable or disable the main X11 event handling function.
148 * This is used by drag_pointer() which has its own, modal event handler, which
149 * takes precedence over the normal event handler.
150 *
151 */
152void main_set_x11_cb(bool enable) {
153 DLOG("Setting main X11 callback to enabled=%d\n", enable);
154 if (enable) {
155 ev_prepare_start(main_loop, xcb_prepare);
156 /* Trigger the watcher explicitly to handle all remaining X11 events.
157 * drag_pointer()’s event handler exits in the middle of the loop. */
158 ev_feed_event(main_loop, xcb_prepare, 0);
159 } else {
160 ev_prepare_stop(main_loop, xcb_prepare);
161 }
162}
163
164/*
165 * Exit handler which destroys the main_loop. Will trigger cleanup handlers.
166 *
167 */
168static void i3_exit(void) {
169 if (*shmlogname != '\0') {
170 fprintf(stderr, "Closing SHM log \"%s\"\n", shmlogname);
171 fflush(stderr);
172 shm_unlink(shmlogname);
173 }
175 unlink(config.ipc_socket_path);
176 xcb_disconnect(conn);
177
178/* We need ev >= 4 for the following code. Since it is not *that* important (it
179 * only makes sure that there are no i3-nagbar instances left behind) we still
180 * support old systems with libev 3. */
181#if EV_VERSION_MAJOR >= 4
182 ev_loop_destroy(main_loop);
183#endif
184
185#ifdef I3_ASAN_ENABLED
186 __lsan_do_leak_check();
187#endif
188}
189
190/*
191 * (One-shot) Handler for all signals with default action "Core", see signal(7)
192 *
193 * Unlinks the SHM log and re-raises the signal.
194 *
195 */
196static void handle_core_signal(int sig, siginfo_t *info, void *data) {
197 if (*shmlogname != '\0') {
198 shm_unlink(shmlogname);
199 }
200 raise(sig);
201}
202
203/*
204 * (One-shot) Handler for all signals with default action "Term", see signal(7)
205 *
206 * Exits the program gracefully.
207 *
208 */
209static void handle_term_signal(struct ev_loop *loop, ev_signal *signal, int revents) {
210 /* We exit gracefully here in the sense that cleanup handlers
211 * installed via atexit are invoked. */
212 exit(128 + signal->signum);
213}
214
215/*
216 * Set up handlers for all signals with default action "Term", see signal(7)
217 *
218 */
219static void setup_term_handlers(void) {
220 static struct ev_signal signal_watchers[6];
221 size_t num_watchers = sizeof(signal_watchers) / sizeof(signal_watchers[0]);
222
223 /* We have to rely on libev functionality here and should not use
224 * sigaction handlers because we need to invoke the exit handlers
225 * and cannot do so from an asynchronous signal handling context as
226 * not all code triggered during exit is signal safe (and exiting
227 * the main loop from said handler is not easily possible). libev's
228 * signal handlers does not impose such a constraint on us. */
229 ev_signal_init(&signal_watchers[0], handle_term_signal, SIGHUP);
230 ev_signal_init(&signal_watchers[1], handle_term_signal, SIGINT);
231 ev_signal_init(&signal_watchers[2], handle_term_signal, SIGALRM);
232 ev_signal_init(&signal_watchers[3], handle_term_signal, SIGTERM);
233 ev_signal_init(&signal_watchers[4], handle_term_signal, SIGUSR1);
234 ev_signal_init(&signal_watchers[5], handle_term_signal, SIGUSR1);
235 for (size_t i = 0; i < num_watchers; i++) {
236 ev_signal_start(main_loop, &signal_watchers[i]);
237 /* The signal handlers should not block ev_run from returning
238 * and so none of the signal handlers should hold a reference to
239 * the main loop. */
240 ev_unref(main_loop);
241 }
242}
243
244static int parse_restart_fd(void) {
245 const char *restart_fd = getenv("_I3_RESTART_FD");
246 if (restart_fd == NULL) {
247 return -1;
248 }
249
250 long int fd = -1;
251 if (!parse_long(restart_fd, &fd, 10)) {
252 ELOG("Malformed _I3_RESTART_FD \"%s\"\n", restart_fd);
253 return -1;
254 }
255 return fd;
256}
257
258int main(int argc, char *argv[]) {
259 /* Keep a symbol pointing to the I3_VERSION string constant so that we have
260 * it in gdb backtraces. */
261 static const char *_i3_version __attribute__((used)) = I3_VERSION;
262 char *override_configpath = NULL;
263 bool autostart = true;
264 char *layout_path = NULL;
265 bool delete_layout_path = false;
266 bool disable_randr15 = false;
267 char *fake_outputs = NULL;
268 bool disable_signalhandler = false;
269 bool only_check_config = false;
270 static struct option long_options[] = {
271 {"no-autostart", no_argument, 0, 'a'},
272 {"config", required_argument, 0, 'c'},
273 {"version", no_argument, 0, 'v'},
274 {"moreversion", no_argument, 0, 'm'},
275 {"more-version", no_argument, 0, 'm'},
276 {"more_version", no_argument, 0, 'm'},
277 {"help", no_argument, 0, 'h'},
278 {"layout", required_argument, 0, 'L'},
279 {"restart", required_argument, 0, 0},
280 {"force-xinerama", no_argument, 0, 0},
281 {"force_xinerama", no_argument, 0, 0},
282 {"disable-randr15", no_argument, 0, 0},
283 {"disable_randr15", no_argument, 0, 0},
284 {"disable-signalhandler", no_argument, 0, 0},
285 {"shmlog-size", required_argument, 0, 0},
286 {"shmlog_size", required_argument, 0, 0},
287 {"get-socketpath", no_argument, 0, 0},
288 {"get_socketpath", no_argument, 0, 0},
289 {"fake_outputs", required_argument, 0, 0},
290 {"fake-outputs", required_argument, 0, 0},
291 {"force-old-config-parser-v4.4-only", no_argument, 0, 0},
292 {0, 0, 0, 0}};
293 int option_index = 0, opt;
294
295 setlocale(LC_ALL, "");
296
297 /* Get the RLIMIT_CORE limit at startup time to restore this before
298 * starting processes. */
299 getrlimit(RLIMIT_CORE, &original_rlimit_core);
300
301 /* Disable output buffering to make redirects in .xsession actually useful for debugging */
302 if (!isatty(fileno(stdout)))
303 setbuf(stdout, NULL);
304
305 srand(time(NULL));
306
307 /* Init logging *before* initializing debug_build to guarantee early
308 * (file) logging. */
309 init_logging();
310
311 /* On release builds, disable SHM logging by default. */
312 shmlog_size = (is_debug_build() || strstr(argv[0], "i3-with-shmlog") != NULL ? default_shmlog_size : 0);
313
314 start_argv = argv;
315
316 while ((opt = getopt_long(argc, argv, "c:CvmaL:hld:V", long_options, &option_index)) != -1) {
317 switch (opt) {
318 case 'a':
319 LOG("Autostart disabled using -a\n");
320 autostart = false;
321 break;
322 case 'L':
323 FREE(layout_path);
324 layout_path = sstrdup(optarg);
325 delete_layout_path = false;
326 break;
327 case 'c':
328 FREE(override_configpath);
329 override_configpath = sstrdup(optarg);
330 break;
331 case 'C':
332 LOG("Checking configuration file only (-C)\n");
333 only_check_config = true;
334 break;
335 case 'v':
336 printf("i3 version %s © 2009 Michael Stapelberg and contributors\n", i3_version);
337 exit(EXIT_SUCCESS);
338 break;
339 case 'm':
340 printf("Binary i3 version: %s © 2009 Michael Stapelberg and contributors\n", i3_version);
342 exit(EXIT_SUCCESS);
343 break;
344 case 'V':
345 set_verbosity(true);
346 break;
347 case 'd':
348 LOG("Enabling debug logging\n");
349 set_debug_logging(true);
350 break;
351 case 'l':
352 /* DEPRECATED, ignored for the next 3 versions (3.e, 3.f, 3.g) */
353 break;
354 case 0:
355 if (strcmp(long_options[option_index].name, "force-xinerama") == 0 ||
356 strcmp(long_options[option_index].name, "force_xinerama") == 0) {
357 force_xinerama = true;
358 ELOG("Using Xinerama instead of RandR. This option should be "
359 "avoided at all cost because it does not refresh the list "
360 "of screens, so you cannot configure displays at runtime. "
361 "Please check if your driver really does not support RandR "
362 "and disable this option as soon as you can.\n");
363 break;
364 } else if (strcmp(long_options[option_index].name, "disable-randr15") == 0 ||
365 strcmp(long_options[option_index].name, "disable_randr15") == 0) {
366 disable_randr15 = true;
367 break;
368 } else if (strcmp(long_options[option_index].name, "disable-signalhandler") == 0) {
369 disable_signalhandler = true;
370 break;
371 } else if (strcmp(long_options[option_index].name, "get-socketpath") == 0 ||
372 strcmp(long_options[option_index].name, "get_socketpath") == 0) {
373 char *socket_path = root_atom_contents("I3_SOCKET_PATH", NULL, 0);
374 if (socket_path) {
375 printf("%s\n", socket_path);
376 exit(EXIT_SUCCESS);
377 }
378
379 exit(EXIT_FAILURE);
380 } else if (strcmp(long_options[option_index].name, "shmlog-size") == 0 ||
381 strcmp(long_options[option_index].name, "shmlog_size") == 0) {
382 shmlog_size = atoi(optarg);
383 /* Re-initialize logging immediately to get as many
384 * logmessages as possible into the SHM log. */
385 init_logging();
386 LOG("Limiting SHM log size to %d bytes\n", shmlog_size);
387 break;
388 } else if (strcmp(long_options[option_index].name, "restart") == 0) {
389 FREE(layout_path);
390 layout_path = sstrdup(optarg);
391 delete_layout_path = true;
392 break;
393 } else if (strcmp(long_options[option_index].name, "fake-outputs") == 0 ||
394 strcmp(long_options[option_index].name, "fake_outputs") == 0) {
395 LOG("Initializing fake outputs: %s\n", optarg);
396 fake_outputs = sstrdup(optarg);
397 break;
398 } else if (strcmp(long_options[option_index].name, "force-old-config-parser-v4.4-only") == 0) {
399 ELOG("You are passing --force-old-config-parser-v4.4-only, but that flag was removed by now.\n");
400 break;
401 }
402 /* fall-through */
403 default:
404 fprintf(stderr, "Usage: %s [-c configfile] [-d all] [-a] [-v] [-V] [-C]\n", argv[0]);
405 fprintf(stderr, "\n");
406 fprintf(stderr, "\t-a disable autostart ('exec' lines in config)\n");
407 fprintf(stderr, "\t-c <file> use the provided configfile instead\n");
408 fprintf(stderr, "\t-C validate configuration file and exit\n");
409 fprintf(stderr, "\t-d all enable debug output\n");
410 fprintf(stderr, "\t-L <file> path to the serialized layout during restarts\n");
411 fprintf(stderr, "\t-v display version and exit\n");
412 fprintf(stderr, "\t-V enable verbose mode\n");
413 fprintf(stderr, "\n");
414 fprintf(stderr, "\t--force-xinerama\n"
415 "\tUse Xinerama instead of RandR.\n"
416 "\tThis option should only be used if you are stuck with the\n"
417 "\told nVidia closed source driver (older than 302.17), which does\n"
418 "\tnot support RandR.\n");
419 fprintf(stderr, "\n");
420 fprintf(stderr, "\t--get-socketpath\n"
421 "\tRetrieve the i3 IPC socket path from X11, print it, then exit.\n");
422 fprintf(stderr, "\n");
423 fprintf(stderr, "\t--shmlog-size <limit>\n"
424 "\tLimits the size of the i3 SHM log to <limit> bytes. Setting this\n"
425 "\tto 0 disables SHM logging entirely.\n"
426 "\tThe default is %d bytes.\n",
428 fprintf(stderr, "\n");
429 fprintf(stderr, "If you pass plain text arguments, i3 will interpret them as a command\n"
430 "to send to a currently running i3 (like i3-msg). This allows you to\n"
431 "use nice and logical commands, such as:\n"
432 "\n"
433 "\ti3 border none\n"
434 "\ti3 floating toggle\n"
435 "\ti3 kill window\n"
436 "\n");
437 exit(opt == 'h' ? EXIT_SUCCESS : EXIT_FAILURE);
438 }
439 }
440
441 if (only_check_config) {
442 exit(load_configuration(override_configpath, C_VALIDATE) ? EXIT_SUCCESS : EXIT_FAILURE);
443 }
444
445 /* If the user passes more arguments, we act like i3-msg would: Just send
446 * the arguments as an IPC message to i3. This allows for nice semantic
447 * commands such as 'i3 border none'. */
448 if (optind < argc) {
449 /* We enable verbose mode so that the user knows what’s going on.
450 * This should make it easier to find mistakes when the user passes
451 * arguments by mistake. */
452 set_verbosity(true);
453
454 LOG("Additional arguments passed. Sending them as a command to i3.\n");
455 char *payload = NULL;
456 while (optind < argc) {
457 if (!payload) {
458 payload = sstrdup(argv[optind]);
459 } else {
460 char *both;
461 sasprintf(&both, "%s %s", payload, argv[optind]);
462 free(payload);
463 payload = both;
464 }
465 optind++;
466 }
467 DLOG("Command is: %s (%zd bytes)\n", payload, strlen(payload));
468 char *socket_path = root_atom_contents("I3_SOCKET_PATH", NULL, 0);
469 if (!socket_path) {
470 ELOG("Could not get i3 IPC socket path\n");
471 return 1;
472 }
473
474 int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
475 if (sockfd == -1)
476 err(EXIT_FAILURE, "Could not create socket");
477
478 struct sockaddr_un addr;
479 memset(&addr, 0, sizeof(struct sockaddr_un));
480 addr.sun_family = AF_LOCAL;
481 strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
482 FREE(socket_path);
483 if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
484 err(EXIT_FAILURE, "Could not connect to i3");
485
486 if (ipc_send_message(sockfd, strlen(payload), I3_IPC_MESSAGE_TYPE_RUN_COMMAND,
487 (uint8_t *)payload) == -1)
488 err(EXIT_FAILURE, "IPC: write()");
489 FREE(payload);
490
491 uint32_t reply_length;
492 uint32_t reply_type;
493 uint8_t *reply;
494 int ret;
495 if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
496 if (ret == -1)
497 err(EXIT_FAILURE, "IPC: read()");
498 return 1;
499 }
500 if (reply_type != I3_IPC_REPLY_TYPE_COMMAND)
501 errx(EXIT_FAILURE, "IPC: received reply of type %d but expected %d (COMMAND)", reply_type, I3_IPC_REPLY_TYPE_COMMAND);
502 printf("%.*s\n", reply_length, reply);
503 FREE(reply);
504 return 0;
505 }
506
507 /* Enable logging to handle the case when the user did not specify --shmlog-size */
508 init_logging();
509
510 /* Try to enable core dumps by default when running a debug build */
511 if (is_debug_build()) {
512 struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY};
513 setrlimit(RLIMIT_CORE, &limit);
514
515 /* The following code is helpful, but not required. We thus don’t pay
516 * much attention to error handling, non-linux or other edge cases. */
517 LOG("CORE DUMPS: You are running a development version of i3, so coredumps were automatically enabled (ulimit -c unlimited).\n");
518 size_t cwd_size = 1024;
519 char *cwd = smalloc(cwd_size);
520 char *cwd_ret;
521 while ((cwd_ret = getcwd(cwd, cwd_size)) == NULL && errno == ERANGE) {
522 cwd_size = cwd_size * 2;
523 cwd = srealloc(cwd, cwd_size);
524 }
525 if (cwd_ret != NULL)
526 LOG("CORE DUMPS: Your current working directory is \"%s\".\n", cwd);
527 int patternfd;
528 if ((patternfd = open("/proc/sys/kernel/core_pattern", O_RDONLY)) >= 0) {
529 memset(cwd, '\0', cwd_size);
530 if (read(patternfd, cwd, cwd_size) > 0)
531 /* a trailing newline is included in cwd */
532 LOG("CORE DUMPS: Your core_pattern is: %s", cwd);
533 close(patternfd);
534 }
535 free(cwd);
536 }
537
538 LOG("i3 %s starting\n", i3_version);
539
540 conn = xcb_connect(NULL, &conn_screen);
541 if (xcb_connection_has_error(conn))
542 errx(EXIT_FAILURE, "Cannot open display");
543
544 sndisplay = sn_xcb_display_new(conn, NULL, NULL);
545
546 /* Initialize the libev event loop. This needs to be done before loading
547 * the config file because the parser will install an ev_child watcher
548 * for the nagbar when config errors are found. */
549 main_loop = EV_DEFAULT;
550 if (main_loop == NULL)
551 die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
552
553 root_screen = xcb_aux_get_screen(conn, conn_screen);
554 root = root_screen->root;
555
556 /* Place requests for the atoms we need as soon as possible */
557#define xmacro(atom) \
558 xcb_intern_atom_cookie_t atom##_cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
559#include "atoms.xmacro"
560#undef xmacro
561
562 root_depth = root_screen->root_depth;
563 colormap = root_screen->default_colormap;
564 visual_type = xcb_aux_find_visual_by_attrs(root_screen, -1, 32);
565 if (visual_type != NULL) {
566 root_depth = xcb_aux_get_depth_of_visual(root_screen, visual_type->visual_id);
567 colormap = xcb_generate_id(conn);
568
569 xcb_void_cookie_t cm_cookie = xcb_create_colormap_checked(conn,
570 XCB_COLORMAP_ALLOC_NONE,
571 colormap,
572 root,
573 visual_type->visual_id);
574
575 xcb_generic_error_t *error = xcb_request_check(conn, cm_cookie);
576 if (error != NULL) {
577 ELOG("Could not create colormap. Error code: %d\n", error->error_code);
578 exit(EXIT_FAILURE);
579 }
580 } else {
582 }
583
584 init_dpi();
585
586 DLOG("root_depth = %d, visual_id = 0x%08x.\n", root_depth, visual_type->visual_id);
587 DLOG("root_screen->height_in_pixels = %d, root_screen->height_in_millimeters = %d\n",
588 root_screen->height_in_pixels, root_screen->height_in_millimeters);
589 DLOG("One logical pixel corresponds to %d physical pixels on this display.\n", logical_px(1));
590
591 xcb_get_geometry_cookie_t gcookie = xcb_get_geometry(conn, root);
592 xcb_query_pointer_cookie_t pointercookie = xcb_query_pointer(conn, root);
593
594 /* Setup NetWM atoms */
595#define xmacro(name) \
596 do { \
597 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, name##_cookie, NULL); \
598 if (!reply) { \
599 ELOG("Could not get atom " #name "\n"); \
600 exit(-1); \
601 } \
602 A_##name = reply->atom; \
603 free(reply); \
604 } while (0);
605#include "atoms.xmacro"
606#undef xmacro
607
608 load_configuration(override_configpath, C_LOAD);
609
610 if (config.ipc_socket_path == NULL) {
611 /* Fall back to a file name in /tmp/ based on the PID */
612 if ((config.ipc_socket_path = getenv("I3SOCK")) == NULL)
614 else
616 }
617
619 force_xinerama = true;
620 }
621
622 xcb_void_cookie_t cookie;
623 cookie = xcb_change_window_attributes_checked(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){ROOT_EVENT_MASK});
624 xcb_generic_error_t *error = xcb_request_check(conn, cookie);
625 if (error != NULL) {
626 ELOG("Another window manager seems to be running (X error %d)\n", error->error_code);
627#ifdef I3_ASAN_ENABLED
628 __lsan_do_leak_check();
629#endif
630 return 1;
631 }
632
633 xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(conn, gcookie, NULL);
634 if (greply == NULL) {
635 ELOG("Could not get geometry of the root window, exiting\n");
636 return 1;
637 }
638 DLOG("root geometry reply: (%d, %d) %d x %d\n", greply->x, greply->y, greply->width, greply->height);
639
641
642 /* Set a cursor for the root window (otherwise the root window will show no
643 cursor until the first client is launched). */
646 else
648
649 const xcb_query_extension_reply_t *extreply;
650 xcb_prefetch_extension_data(conn, &xcb_xkb_id);
651 xcb_prefetch_extension_data(conn, &xcb_shape_id);
652
653 extreply = xcb_get_extension_data(conn, &xcb_xkb_id);
654 xkb_supported = extreply->present;
655 if (!extreply->present) {
656 DLOG("xkb is not present on this server\n");
657 } else {
658 DLOG("initializing xcb-xkb\n");
659 xcb_xkb_use_extension(conn, XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION);
660 xcb_xkb_select_events(conn,
661 XCB_XKB_ID_USE_CORE_KBD,
662 XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_MAP_NOTIFY | XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY,
663 0,
664 XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_MAP_NOTIFY | XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY,
665 0xff,
666 0xff,
667 NULL);
668
669 /* Setting both, XCB_XKB_PER_CLIENT_FLAG_GRABS_USE_XKB_STATE and
670 * XCB_XKB_PER_CLIENT_FLAG_LOOKUP_STATE_WHEN_GRABBED, will lead to the
671 * X server sending us the full XKB state in KeyPress and KeyRelease:
672 * https://cgit.freedesktop.org/xorg/xserver/tree/xkb/xkbEvents.c?h=xorg-server-1.20.0#n927
673 *
674 * XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT enable detectable autorepeat:
675 * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Detectable_Autorepeat
676 * This affects bindings using the --release flag: instead of getting multiple KeyRelease
677 * events we get only one event when the key is physically released by the user.
678 */
679 const uint32_t mask = XCB_XKB_PER_CLIENT_FLAG_GRABS_USE_XKB_STATE |
680 XCB_XKB_PER_CLIENT_FLAG_LOOKUP_STATE_WHEN_GRABBED |
681 XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT;
682 xcb_xkb_per_client_flags_reply_t *pcf_reply;
683 /* The last three parameters are unset because they are only relevant
684 * when using a feature called “automatic reset of boolean controls”:
685 * https://www.x.org/releases/X11R7.7/doc/kbproto/xkbproto.html#Automatic_Reset_of_Boolean_Controls
686 * */
687 pcf_reply = xcb_xkb_per_client_flags_reply(
688 conn,
689 xcb_xkb_per_client_flags(
690 conn,
691 XCB_XKB_ID_USE_CORE_KBD,
692 mask,
693 mask,
694 0 /* uint32_t ctrlsToChange */,
695 0 /* uint32_t autoCtrls */,
696 0 /* uint32_t autoCtrlsValues */),
697 NULL);
698
699#define PCF_REPLY_ERROR(_value) \
700 do { \
701 if (pcf_reply == NULL || !(pcf_reply->value & (_value))) { \
702 ELOG("Could not set " #_value "\n"); \
703 } \
704 } while (0)
705
706 PCF_REPLY_ERROR(XCB_XKB_PER_CLIENT_FLAG_GRABS_USE_XKB_STATE);
707 PCF_REPLY_ERROR(XCB_XKB_PER_CLIENT_FLAG_LOOKUP_STATE_WHEN_GRABBED);
708 PCF_REPLY_ERROR(XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT);
709
710 free(pcf_reply);
711 xkb_base = extreply->first_event;
712 }
713
714 /* Check for Shape extension. We want to handle input shapes which is
715 * introduced in 1.1. */
716 extreply = xcb_get_extension_data(conn, &xcb_shape_id);
717 if (extreply->present) {
718 shape_base = extreply->first_event;
719 xcb_shape_query_version_cookie_t cookie = xcb_shape_query_version(conn);
720 xcb_shape_query_version_reply_t *version =
721 xcb_shape_query_version_reply(conn, cookie, NULL);
722 shape_supported = version && version->minor_version >= 1;
723 free(version);
724 } else {
725 shape_supported = false;
726 }
727 if (!shape_supported) {
728 DLOG("shape 1.1 is not present on this server\n");
729 }
730
732
734
736
737 keysyms = xcb_key_symbols_alloc(conn);
738
740
741 if (!load_keymap())
742 die("Could not load keymap\n");
743
746
747 bool needs_tree_init = true;
748 if (layout_path != NULL) {
749 LOG("Trying to restore the layout from \"%s\".\n", layout_path);
750 needs_tree_init = !tree_restore(layout_path, greply);
751 if (delete_layout_path) {
752 unlink(layout_path);
753 const char *dir = dirname(layout_path);
754 /* possibly fails with ENOTEMPTY if there are files (or
755 * sockets) left. */
756 rmdir(dir);
757 }
758 }
759 if (needs_tree_init)
760 tree_init(greply);
761
762 free(greply);
763
764 /* Setup fake outputs for testing */
765 if (fake_outputs == NULL && config.fake_outputs != NULL)
766 fake_outputs = config.fake_outputs;
767
768 if (fake_outputs != NULL) {
769 fake_outputs_init(fake_outputs);
770 FREE(fake_outputs);
771 config.fake_outputs = NULL;
772 } else if (force_xinerama) {
773 /* Force Xinerama (for drivers which don't support RandR yet, esp. the
774 * nVidia binary graphics driver), when specified either in the config
775 * file or on command-line */
777 } else {
778 DLOG("Checking for XRandR...\n");
779 randr_init(&randr_base, disable_randr15 || config.disable_randr15);
780 }
781
782 /* We need to force disabling outputs which have been loaded from the
783 * layout file but are no longer active. This can happen if the output has
784 * been disabled in the short time between writing the restart layout file
785 * and restarting i3. See #2326. */
786 if (layout_path != NULL && randr_base > -1) {
787 Con *con;
788 TAILQ_FOREACH(con, &(croot->nodes_head), nodes) {
789 Output *output;
790 TAILQ_FOREACH(output, &outputs, outputs) {
791 if (output->active || strcmp(con->name, output_primary_name(output)) != 0)
792 continue;
793
794 /* This will correctly correlate the output with its content
795 * container. We need to make the connection to properly
796 * disable the output. */
797 if (output->con == NULL) {
798 output_init_con(output);
799 output->changed = false;
800 }
801
802 output->to_be_disabled = true;
803 randr_disable_output(output);
804 }
805 }
806 }
807 FREE(layout_path);
808
810
811 xcb_query_pointer_reply_t *pointerreply;
812 Output *output = NULL;
813 if (!(pointerreply = xcb_query_pointer_reply(conn, pointercookie, NULL))) {
814 ELOG("Could not query pointer position, using first screen\n");
815 } else {
816 DLOG("Pointer at %d, %d\n", pointerreply->root_x, pointerreply->root_y);
817 output = get_output_containing(pointerreply->root_x, pointerreply->root_y);
818 if (!output) {
819 ELOG("ERROR: No screen at (%d, %d), starting on the first screen\n",
820 pointerreply->root_x, pointerreply->root_y);
821 }
822 }
823 if (!output) {
824 output = get_first_output();
825 }
827 free(pointerreply);
828
829 tree_render();
830
831 /* Create the UNIX domain socket for IPC */
832 int ipc_socket = ipc_create_socket(config.ipc_socket_path);
833 if (ipc_socket == -1) {
834 ELOG("Could not create the IPC socket, IPC disabled\n");
835 } else {
836 struct ev_io *ipc_io = scalloc(1, sizeof(struct ev_io));
837 ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ);
838 ev_io_start(main_loop, ipc_io);
839 }
840
841 /* Also handle the UNIX domain sockets passed via socket activation. The
842 * parameter 1 means "remove the environment variables", we don’t want to
843 * pass these to child processes. */
845 if (listen_fds < 0)
846 ELOG("socket activation: Error in sd_listen_fds\n");
847 else if (listen_fds == 0)
848 DLOG("socket activation: no sockets passed\n");
849 else {
850 int flags;
851 for (int fd = SD_LISTEN_FDS_START;
853 fd++) {
854 DLOG("socket activation: also listening on fd %d\n", fd);
855
856 /* sd_listen_fds() enables FD_CLOEXEC by default.
857 * However, we need to keep the file descriptors open for in-place
858 * restarting, therefore we explicitly disable FD_CLOEXEC. */
859 if ((flags = fcntl(fd, F_GETFD)) < 0 ||
860 fcntl(fd, F_SETFD, flags & ~FD_CLOEXEC) < 0) {
861 ELOG("Could not disable FD_CLOEXEC on fd %d\n", fd);
862 }
863
864 struct ev_io *ipc_io = scalloc(1, sizeof(struct ev_io));
865 ev_io_init(ipc_io, ipc_new_client, fd, EV_READ);
866 ev_io_start(main_loop, ipc_io);
867 }
868 }
869
870 {
871 const int restart_fd = parse_restart_fd();
872 if (restart_fd != -1) {
873 DLOG("serving restart fd %d", restart_fd);
874 ipc_client *client = ipc_new_client_on_fd(main_loop, restart_fd);
875 ipc_confirm_restart(client);
876 unsetenv("_I3_RESTART_FD");
877 }
878 }
879
880 /* Set up i3 specific atoms like I3_SOCKET_PATH and I3_CONFIG_PATH */
883
884 /* Set the ewmh desktop properties. */
886
887 struct ev_io *xcb_watcher = scalloc(1, sizeof(struct ev_io));
888 xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
889
890 ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
891 ev_io_start(main_loop, xcb_watcher);
892
893 ev_prepare_init(xcb_prepare, xcb_prepare_cb);
894 ev_prepare_start(main_loop, xcb_prepare);
895
896 xcb_flush(conn);
897
898 /* What follows is a fugly consequence of X11 protocol race conditions like
899 * the following: In an i3 in-place restart, i3 will reparent all windows
900 * to the root window, then exec() itself. In the new process, it calls
901 * manage_existing_windows. However, in case any application sent a
902 * generated UnmapNotify message to the WM (as GIMP does), this message
903 * will be handled by i3 *after* managing the window, thus i3 thinks the
904 * window just closed itself. In reality, the message was sent in the time
905 * period where i3 wasn’t running yet.
906 *
907 * To prevent this, we grab the server (disables processing of any other
908 * connections), then discard all pending events (since we didn’t do
909 * anything, there cannot be any meaningful responses), then ungrab the
910 * server. */
911 xcb_grab_server(conn);
912 {
913 xcb_aux_sync(conn);
914 xcb_generic_event_t *event;
915 while ((event = xcb_poll_for_event(conn)) != NULL) {
916 if (event->response_type == 0) {
917 free(event);
918 continue;
919 }
920
921 /* Strip off the highest bit (set if the event is generated) */
922 int type = (event->response_type & 0x7F);
923
924 /* We still need to handle MapRequests which are sent in the
925 * timespan starting from when we register as a window manager and
926 * this piece of code which drops events. */
927 if (type == XCB_MAP_REQUEST)
928 handle_event(type, event);
929
930 free(event);
931 }
933 }
934 xcb_ungrab_server(conn);
935
936 if (autostart) {
937 LOG("This is not an in-place restart, copying root window contents to a pixmap\n");
938 xcb_screen_t *root = xcb_aux_get_screen(conn, conn_screen);
939 uint16_t width = root->width_in_pixels;
940 uint16_t height = root->height_in_pixels;
941 xcb_pixmap_t pixmap = xcb_generate_id(conn);
942 xcb_gcontext_t gc = xcb_generate_id(conn);
943
944 xcb_create_pixmap(conn, root->root_depth, pixmap, root->root, width, height);
945
946 xcb_create_gc(conn, gc, root->root,
947 XCB_GC_FUNCTION | XCB_GC_PLANE_MASK | XCB_GC_FILL_STYLE | XCB_GC_SUBWINDOW_MODE,
948 (uint32_t[]){XCB_GX_COPY, ~0, XCB_FILL_STYLE_SOLID, XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS});
949
950 xcb_copy_area(conn, root->root, pixmap, gc, 0, 0, 0, 0, width, height);
951 xcb_change_window_attributes(conn, root->root, XCB_CW_BACK_PIXMAP, (uint32_t[]){pixmap});
952 xcb_flush(conn);
953 xcb_free_gc(conn, gc);
954 xcb_free_pixmap(conn, pixmap);
955 }
956
957#if defined(__OpenBSD__)
958 if (pledge("stdio rpath wpath cpath proc exec unix", NULL) == -1)
959 err(EXIT_FAILURE, "pledge");
960#endif
961
962 if (!disable_signalhandler)
964 else {
965 struct sigaction action;
966
967 action.sa_sigaction = handle_core_signal;
968 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
969 sigemptyset(&action.sa_mask);
970
971 /* Catch all signals with default action "Core", see signal(7) */
972 if (sigaction(SIGQUIT, &action, NULL) == -1 ||
973 sigaction(SIGILL, &action, NULL) == -1 ||
974 sigaction(SIGABRT, &action, NULL) == -1 ||
975 sigaction(SIGFPE, &action, NULL) == -1 ||
976 sigaction(SIGSEGV, &action, NULL) == -1)
977 ELOG("Could not setup signal handler.\n");
978 }
979
981 /* Ignore SIGPIPE to survive errors when an IPC client disconnects
982 * while we are sending them a message */
983 signal(SIGPIPE, SIG_IGN);
984
985 /* Autostarting exec-lines */
986 if (autostart) {
987 while (!TAILQ_EMPTY(&autostarts)) {
988 struct Autostart *exec = TAILQ_FIRST(&autostarts);
989
990 LOG("auto-starting %s\n", exec->command);
992
993 FREE(exec->command);
995 FREE(exec);
996 }
997 }
998
999 /* Autostarting exec_always-lines */
1000 while (!TAILQ_EMPTY(&autostarts_always)) {
1001 struct Autostart *exec_always = TAILQ_FIRST(&autostarts_always);
1002
1003 LOG("auto-starting (always!) %s\n", exec_always->command);
1004 start_application(exec_always->command, exec_always->no_startup_id);
1005
1006 FREE(exec_always->command);
1008 FREE(exec_always);
1009 }
1010
1011 /* Start i3bar processes for all configured bars */
1012 Barconfig *barconfig;
1013 TAILQ_FOREACH(barconfig, &barconfigs, configs) {
1014 char *command = NULL;
1015 sasprintf(&command, "%s %s --bar_id=%s --socket=\"%s\"",
1016 barconfig->i3bar_command ? barconfig->i3bar_command : "i3bar",
1017 barconfig->verbose ? "-V" : "",
1018 barconfig->id, current_socketpath);
1019 LOG("Starting bar process: %s\n", command);
1021 free(command);
1022 }
1023
1024 /* Make sure to destroy the event loop to invoke the cleanup callbacks
1025 * when calling exit() */
1026 atexit(i3_exit);
1027
1028 ev_loop(main_loop, 0);
1029}
int ipc_create_socket(const char *filename)
Creates the UNIX domain socket at the given path, sets it to non-blocking mode, bind()s and listen()s...
Definition: ipc.c:1515
void ipc_confirm_restart(ipc_client *client)
Sends a restart reply to the IPC client on the specified fd.
Definition: ipc.c:1692
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:1490
char * current_socketpath
Definition: ipc.c:23
void ipc_shutdown(shutdown_reason_t reason, int exempt_fd)
Calls shutdown() on each socket and closes it.
Definition: ipc.c:206
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:1465
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Definition: output.c:51
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition: output.c:16
void restore_connect(void)
Opens a separate connection to X11 for placeholder windows when restoring layouts.
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
Definition: startup.c:133
int sd_listen_fds(int unset_environment)
Definition: sd-daemon.c:47
bool load_keymap(void)
Loads the XKB keymap from the X11 server and feeds it to xkbcommon.
Definition: bindings.c:931
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:147
void translate_keysyms(void)
Translates keysymbols to keycodes for all bindings which use keysyms.
Definition: bindings.c:432
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:48
__attribute__((pure))
Definition: util.c:64
bool parse_long(const char *str, long *out, int base)
Converts a string into a long using strtol().
Definition: util.c:435
void scratchpad_fix_resolution(void)
When starting i3 initially (and after each change to the connected outputs), this function fixes the ...
Definition: scratchpad.c:247
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:109
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:449
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
Definition: x.c:1429
void display_running_version(void)
Connects to i3 to find out the currently running version.
Config config
Definition: config.c:17
bool load_configuration(const char *override_configpath, config_load_t load_type)
(Re-)loads the configuration file (sets useful defaults before).
Definition: config.c:174
struct barconfig_head barconfigs
Definition: config.c:19
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
Definition: con.c:263
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
Definition: con.c:1516
void fake_outputs_init(const char *output_spec)
Creates outputs according to the given specification.
Definition: fake_outputs.c:36
int shmlog_size
Definition: log.c:49
void init_logging(void)
Initializes logging by creating an error logfile in /tmp (or XDG_RUNTIME_DIR, see get_process_filenam...
Definition: log.c:85
void set_debug_logging(const bool _debug_logging)
Set debug logging.
Definition: log.c:214
char * shmlogname
Definition: log.c:46
void set_verbosity(bool _verbose)
Set verbosity of i3.
Definition: log.c:198
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:113
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:326
struct outputs_head outputs
Definition: randr.c:21
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:1038
Output * get_first_output(void)
Returns the first output which is active.
Definition: randr.c:72
void randr_disable_output(Output *output)
Disables the output and moves its content.
Definition: randr.c:947
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:341
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:1356
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:1308
int shape_base
Definition: handlers.c:23
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:54
int main(int argc, char *argv[])
Definition: main.c:258
const int default_shmlog_size
Definition: main.c:71
#define PCF_REPLY_ERROR(_value)
bool xkb_supported
Definition: main.c:91
static void handle_term_signal(struct ev_loop *loop, ev_signal *signal, int revents)
Definition: main.c:209
int conn_screen
Definition: main.c:46
xcb_connection_t * conn
XCB connection and root screen.
Definition: main.c:44
static void xcb_got_event(EV_P_ struct ev_io *w, int revents)
Definition: main.c:106
xcb_colormap_t colormap
Definition: main.c:64
int listen_fds
The number of file descriptors passed via socket activation.
Definition: main.c:36
bool force_xinerama
Definition: main.c:94
xcb_key_symbols_t * keysyms
Definition: main.c:68
uint8_t root_depth
Definition: main.c:62
struct autostarts_always_head autostarts_always
Definition: main.c:80
SnDisplay * sndisplay
Definition: main.c:49
static struct ev_prepare * xcb_prepare
Definition: main.c:40
xcb_window_t root
Definition: main.c:57
static void i3_exit(void)
Definition: main.c:168
struct rlimit original_rlimit_core
The original value of RLIMIT_CORE when i3 was started.
Definition: main.c:33
xcb_screen_t * root_screen
Definition: main.c:56
bool xcursor_supported
Definition: main.c:90
static void setup_term_handlers(void)
Definition: main.c:219
xcb_visualtype_t * visual_type
Definition: main.c:63
static void handle_core_signal(int sig, siginfo_t *info, void *data)
Definition: main.c:196
void main_set_x11_cb(bool enable)
Enable or disable the main X11 event handling function.
Definition: main.c:152
struct autostarts_head autostarts
Definition: main.c:77
char ** start_argv
Definition: main.c:42
bool shape_supported
Definition: main.c:92
static int parse_restart_fd(void)
Definition: main.c:244
struct ev_loop * main_loop
Definition: main.c:66
static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents)
Definition: main.c:116
struct assignments_head assignments
Definition: main.c:83
struct ws_assignments_head ws_assignments
Definition: main.c:87
struct bindings_head * bindings
Definition: main.c:74
void ewmh_setup_hints(void)
Set up the EWMH hints on the root window.
Definition: ewmh.c:305
void ewmh_update_desktop_properties(void)
Updates all the EWMH desktop properties.
Definition: ewmh.c:116
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:237
void xcb_set_root_cursor(int cursor)
Set the cursor of the root window to the given cursor id.
Definition: xcb.c:184
unsigned int xcb_numlock_mask
Definition: xcb.c:12
void xcursor_load_cursors(void)
Definition: xcursor.c:28
void xcursor_set_root_cursor(int cursor_id)
Sets the cursor of the root window to the 'pointer' cursor.
Definition: xcursor.c:57
const char * i3_version
Git commit identifier, from version.c.
Definition: version.c:13
@ SHUTDOWN_REASON_EXIT
Definition: ipc.h:104
#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
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
#define DLOG(fmt,...)
Definition: libi3.h:104
#define LOG(fmt,...)
Definition: libi3.h:94
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:99
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_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...
bool only_check_config
#define XCB_NUM_LOCK
Definition: xcb.h:29
#define ROOT_EVENT_MASK
Definition: xcb.h:49
@ XCURSOR_CURSOR_POINTER
Definition: xcursor.h:17
@ C_VALIDATE
@ C_LOAD
#define die(...)
Definition: util.h:19
#define FREE(pointer)
Definition: util.h:47
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:365
bool no_startup_id
no_startup_id flag for start_application().
Definition: data.h:370
char * command
Command, like in command mode.
Definition: data.h:367
An Output is a physical output on your graphics driver.
Definition: data.h:393
Con * con
Pointer to the Con which represents this output.
Definition: data.h:414
bool changed
Internal flags, necessary for querying RandR screens (happens in two stages)
Definition: data.h:403
bool to_be_disabled
Definition: data.h:404
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
Definition: data.h:399
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:641
nodes_head
Definition: data.h:722
char * name
Definition: data.h:687
Definition: ipc.h:27