]> git.sur5r.net Git - i3/i3/blob - src/mainx.c
Bugfix: Initialize variable 'root' earlier
[i3/i3] / src / mainx.c
1 /*
2  * vim:ts=8:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  *
6  * © 2009-2010 Michael Stapelberg and contributors
7  *
8  * See file LICENSE for license information.
9  *
10  */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <sys/types.h>
15 #include <unistd.h>
16 #include <stdbool.h>
17 #include <assert.h>
18 #include <limits.h>
19 #include <locale.h>
20 #include <fcntl.h>
21 #include <getopt.h>
22
23 #include <X11/XKBlib.h>
24 #include <X11/extensions/XKB.h>
25
26 #include <xcb/xcb.h>
27 #include <xcb/xcb_atom.h>
28 #include <xcb/xcb_aux.h>
29 #include <xcb/xcb_event.h>
30 #include <xcb/xcb_property.h>
31 #include <xcb/xcb_keysyms.h>
32 #include <xcb/xcb_icccm.h>
33
34 #include <ev.h>
35
36 #include "config.h"
37 #include "data.h"
38 #include "debug.h"
39 #include "handlers.h"
40 #include "click.h"
41 #include "i3.h"
42 #include "layout.h"
43 #include "queue.h"
44 #include "table.h"
45 #include "util.h"
46 #include "xcb.h"
47 #include "randr.h"
48 #include "xinerama.h"
49 #include "manage.h"
50 #include "ipc.h"
51 #include "log.h"
52 #include "sighandler.h"
53
54 static int xkb_event_base;
55
56 int xkb_current_group;
57
58 xcb_connection_t *global_conn;
59
60 /* This is the path to i3, copied from argv[0] when starting up */
61 char **start_argv;
62
63 /* This is our connection to X11 for use with XKB */
64 Display *xkbdpy;
65
66 xcb_key_symbols_t *keysyms;
67
68 /* The list of key bindings */
69 struct bindings_head *bindings;
70
71 /* The list of exec-lines */
72 struct autostarts_head autostarts = TAILQ_HEAD_INITIALIZER(autostarts);
73
74 /* The list of assignments */
75 struct assignments_head assignments = TAILQ_HEAD_INITIALIZER(assignments);
76
77 /* This is a list of Stack_Windows, global, for easier/faster access on expose events */
78 struct stack_wins_head stack_wins = SLIST_HEAD_INITIALIZER(stack_wins);
79
80 /* The event handlers need to be global because they are accessed by our custom event handler
81    in handle_button_press(), needed for graphical resizing */
82 xcb_event_handlers_t evenths;
83 xcb_atom_t atoms[NUM_ATOMS];
84
85 xcb_window_t root;
86 int num_screens = 0;
87
88 /* The depth of the root screen (used e.g. for creating new pixmaps later) */
89 uint8_t root_depth;
90
91 /* We hope that XKB is supported and set this to false */
92 bool xkb_supported = true;
93
94 /*
95  * This callback is only a dummy, see xcb_prepare_cb and xcb_check_cb.
96  * See also man libev(3): "ev_prepare" and "ev_check" - customise your event loop
97  *
98  */
99 static void xcb_got_event(EV_P_ struct ev_io *w, int revents) {
100         /* empty, because xcb_prepare_cb and xcb_check_cb are used */
101 }
102
103 /*
104  * Flush before blocking (and waiting for new events)
105  *
106  */
107 static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
108         xcb_flush(evenths.c);
109 }
110
111 /*
112  * Instead of polling the X connection socket we leave this to
113  * xcb_poll_for_event() which knows better than we can ever know.
114  *
115  */
116 static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
117         xcb_generic_event_t *event;
118
119         while ((event = xcb_poll_for_event(evenths.c)) != NULL) {
120                 xcb_event_handle(&evenths, event);
121                 free(event);
122         }
123 }
124
125 /*
126  * When using xmodmap to change the keyboard mapping, this event
127  * is only sent via XKB. Therefore, we need this special handler.
128  *
129  */
130 static void xkb_got_event(EV_P_ struct ev_io *w, int revents) {
131         DLOG("Handling XKB event\n");
132         XkbEvent ev;
133
134         /* When using xmodmap, every change (!) gets an own event.
135          * Therefore, we just read all events and only handle the
136          * mapping_notify once. */
137         bool mapping_changed = false;
138         while (XPending(xkbdpy)) {
139                 XNextEvent(xkbdpy, (XEvent*)&ev);
140                 /* While we should never receive a non-XKB event,
141                  * better do sanity checking */
142                 if (ev.type != xkb_event_base)
143                         continue;
144
145                 if (ev.any.xkb_type == XkbMapNotify) {
146                         mapping_changed = true;
147                         continue;
148                 }
149
150                 if (ev.any.xkb_type != XkbStateNotify) {
151                         ELOG("Unknown XKB event received (type %d)\n", ev.any.xkb_type);
152                         continue;
153                 }
154
155                 /* See The XKB Extension: Library Specification, section 14.1 */
156                 /* We check if the current group (each group contains
157                  * two levels) has been changed. Mode_switch activates
158                  * group XkbGroup2Index */
159                 if (xkb_current_group == ev.state.group)
160                         continue;
161
162                 xkb_current_group = ev.state.group;
163
164                 if (ev.state.group == XkbGroup2Index) {
165                         DLOG("Mode_switch enabled\n");
166                         grab_all_keys(global_conn, true);
167                 }
168
169                 if (ev.state.group == XkbGroup1Index) {
170                         DLOG("Mode_switch disabled\n");
171                         ungrab_all_keys(global_conn);
172                         grab_all_keys(global_conn, false);
173                 }
174         }
175
176         if (!mapping_changed)
177                 return;
178
179         DLOG("Keyboard mapping changed, updating keybindings\n");
180         xcb_key_symbols_free(keysyms);
181         keysyms = xcb_key_symbols_alloc(global_conn);
182
183         xcb_get_numlock_mask(global_conn);
184
185         ungrab_all_keys(global_conn);
186         DLOG("Re-grabbing...\n");
187         translate_keysyms();
188         grab_all_keys(global_conn, (xkb_current_group == XkbGroup2Index));
189         DLOG("Done\n");
190 }
191
192
193 int main(int argc, char *argv[], char *env[]) {
194         int i, screens, opt;
195         char *override_configpath = NULL;
196         bool autostart = true;
197         bool only_check_config = false;
198         bool force_xinerama = false;
199         xcb_connection_t *conn;
200         xcb_property_handlers_t prophs;
201         xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS];
202         static struct option long_options[] = {
203                 {"no-autostart", no_argument, 0, 'a'},
204                 {"config", required_argument, 0, 'c'},
205                 {"version", no_argument, 0, 'v'},
206                 {"help", no_argument, 0, 'h'},
207                 {"force-xinerama", no_argument, 0, 0},
208                 {0, 0, 0, 0}
209         };
210         int option_index = 0;
211
212         setlocale(LC_ALL, "");
213
214         /* Disable output buffering to make redirects in .xsession actually useful for debugging */
215         if (!isatty(fileno(stdout)))
216                 setbuf(stdout, NULL);
217
218         start_argv = argv;
219
220         while ((opt = getopt_long(argc, argv, "c:Cvahld:V", long_options, &option_index)) != -1) {
221                 switch (opt) {
222                         case 'a':
223                                 LOG("Autostart disabled using -a\n");
224                                 autostart = false;
225                                 break;
226                         case 'c':
227                                 override_configpath = sstrdup(optarg);
228                                 break;
229                         case 'C':
230                                 LOG("Checking configuration file only (-C)\n");
231                                 only_check_config = true;
232                                 break;
233                         case 'v':
234                                 printf("i3 version " I3_VERSION " © 2009-2010 Michael Stapelberg and contributors\n");
235                                 exit(EXIT_SUCCESS);
236                         case 'V':
237                                 set_verbosity(true);
238                                 break;
239                         case 'd':
240                                 LOG("Enabling debug loglevel %s\n", optarg);
241                                 add_loglevel(optarg);
242                                 break;
243                         case 'l':
244                                 /* DEPRECATED, ignored for the next 3 versions (3.e, 3.f, 3.g) */
245                                 break;
246                         case 0:
247                                 if (strcmp(long_options[option_index].name, "force-xinerama") == 0) {
248                                         force_xinerama = true;
249                                         ELOG("Using Xinerama instead of RandR. This option should be "
250                                              "avoided at all cost because it does not refresh the list "
251                                              "of screens, so you cannot configure displays at runtime. "
252                                              "Please check if your driver really does not support RandR "
253                                              "and disable this option as soon as you can.\n");
254                                         break;
255                                 }
256                                 /* fall-through */
257                         default:
258                                 fprintf(stderr, "Usage: %s [-c configfile] [-d loglevel] [-a] [-v] [-V] [-C]\n", argv[0]);
259                                 fprintf(stderr, "\n");
260                                 fprintf(stderr, "-a: disable autostart\n");
261                                 fprintf(stderr, "-v: display version and exit\n");
262                                 fprintf(stderr, "-V: enable verbose mode\n");
263                                 fprintf(stderr, "-d <loglevel>: enable debug loglevel <loglevel>\n");
264                                 fprintf(stderr, "-c <configfile>: use the provided configfile instead\n");
265                                 fprintf(stderr, "-C: check configuration file and exit\n");
266                                 fprintf(stderr, "--force-xinerama: Use Xinerama instead of RandR. This "
267                                                 "option should only be used if you are stuck with the "
268                                                 "nvidia closed source driver which does not support RandR.\n");
269                                 exit(EXIT_FAILURE);
270                 }
271         }
272
273         LOG("i3 version " I3_VERSION " starting\n");
274
275         /* Initialize the table data structures for each workspace */
276         init_table();
277
278         memset(&evenths, 0, sizeof(xcb_event_handlers_t));
279         memset(&prophs, 0, sizeof(xcb_property_handlers_t));
280
281         conn = global_conn = xcb_connect(NULL, &screens);
282
283         if (xcb_connection_has_error(conn))
284                 die("Cannot open display\n");
285
286         /* Get the root window */
287         xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screens);
288         root = root_screen->root;
289         root_depth = root_screen->root_depth;
290
291         load_configuration(conn, override_configpath, false);
292         if (only_check_config) {
293                 LOG("Done checking configuration file. Exiting.\n");
294                 exit(0);
295         }
296
297         /* Create the initial container on the first workspace. This used to
298          * be part of init_table, but since it possibly requires an X
299          * connection and a loaded configuration (default mode for new
300          * containers may be stacking, which requires a new window to be
301          * created), it had to be delayed. */
302         expand_table_cols(TAILQ_FIRST(workspaces));
303         expand_table_rows(TAILQ_FIRST(workspaces));
304
305         /* Place requests for the atoms we need as soon as possible */
306         #define REQUEST_ATOM(name) atom_cookies[name] = xcb_intern_atom(conn, 0, strlen(#name), #name);
307
308         REQUEST_ATOM(_NET_SUPPORTED);
309         REQUEST_ATOM(_NET_WM_STATE_FULLSCREEN);
310         REQUEST_ATOM(_NET_SUPPORTING_WM_CHECK);
311         REQUEST_ATOM(_NET_WM_NAME);
312         REQUEST_ATOM(_NET_WM_STATE);
313         REQUEST_ATOM(_NET_WM_WINDOW_TYPE);
314         REQUEST_ATOM(_NET_WM_DESKTOP);
315         REQUEST_ATOM(_NET_WM_WINDOW_TYPE_DOCK);
316         REQUEST_ATOM(_NET_WM_WINDOW_TYPE_DIALOG);
317         REQUEST_ATOM(_NET_WM_WINDOW_TYPE_UTILITY);
318         REQUEST_ATOM(_NET_WM_WINDOW_TYPE_TOOLBAR);
319         REQUEST_ATOM(_NET_WM_WINDOW_TYPE_SPLASH);
320         REQUEST_ATOM(_NET_WM_STRUT_PARTIAL);
321         REQUEST_ATOM(WM_PROTOCOLS);
322         REQUEST_ATOM(WM_DELETE_WINDOW);
323         REQUEST_ATOM(UTF8_STRING);
324         REQUEST_ATOM(WM_STATE);
325         REQUEST_ATOM(WM_CLIENT_LEADER);
326         REQUEST_ATOM(_NET_CURRENT_DESKTOP);
327         REQUEST_ATOM(_NET_ACTIVE_WINDOW);
328         REQUEST_ATOM(_NET_WORKAREA);
329
330         /* TODO: this has to be more beautiful somewhen */
331         int major, minor, error;
332
333         major = XkbMajorVersion;
334         minor = XkbMinorVersion;
335
336         int errBase;
337
338         if ((xkbdpy = XkbOpenDisplay(getenv("DISPLAY"), &xkb_event_base, &errBase, &major, &minor, &error)) == NULL) {
339                 ELOG("ERROR: XkbOpenDisplay() failed, disabling XKB support\n");
340                 xkb_supported = false;
341         }
342
343         if (xkb_supported) {
344                 if (fcntl(ConnectionNumber(xkbdpy), F_SETFD, FD_CLOEXEC) == -1) {
345                         fprintf(stderr, "Could not set FD_CLOEXEC on xkbdpy\n");
346                         return 1;
347                 }
348
349                 int i1;
350                 if (!XkbQueryExtension(xkbdpy,&i1,&xkb_event_base,&errBase,&major,&minor)) {
351                         fprintf(stderr, "XKB not supported by X-server\n");
352                         return 1;
353                 }
354                 /* end of ugliness */
355
356                 if (!XkbSelectEvents(xkbdpy, XkbUseCoreKbd,
357                                      XkbMapNotifyMask | XkbStateNotifyMask,
358                                      XkbMapNotifyMask | XkbStateNotifyMask)) {
359                         fprintf(stderr, "Could not set XKB event mask\n");
360                         return 1;
361                 }
362         }
363
364         /* Initialize event loop using libev */
365         struct ev_loop *loop = ev_loop_new(0);
366         if (loop == NULL)
367                 die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
368
369         struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io));
370         struct ev_io *xkb = scalloc(sizeof(struct ev_io));
371         struct ev_check *xcb_check = scalloc(sizeof(struct ev_check));
372         struct ev_prepare *xcb_prepare = scalloc(sizeof(struct ev_prepare));
373
374         ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
375         ev_io_start(loop, xcb_watcher);
376
377         if (xkb_supported) {
378                 ev_io_init(xkb, xkb_got_event, ConnectionNumber(xkbdpy), EV_READ);
379                 ev_io_start(loop, xkb);
380
381                 /* Flush the buffer so that libev can properly get new events */
382                 XFlush(xkbdpy);
383         }
384
385         ev_check_init(xcb_check, xcb_check_cb);
386         ev_check_start(loop, xcb_check);
387
388         ev_prepare_init(xcb_prepare, xcb_prepare_cb);
389         ev_prepare_start(loop, xcb_prepare);
390
391         /* Grab the server to delay any events until we enter the eventloop */
392         xcb_grab_server(conn);
393
394         xcb_event_handlers_init(conn, &evenths);
395
396         /* DEBUG: Trap all events and print them */
397         for (i = 2; i < 128; ++i)
398                 xcb_event_set_handler(&evenths, i, handle_event, 0);
399
400         for (i = 0; i < 256; ++i)
401                 xcb_event_set_error_handler(&evenths, i, (xcb_generic_error_handler_t)handle_event, 0);
402
403         /* Expose = an Application should redraw itself, in this case it’s our titlebars. */
404         xcb_event_set_expose_handler(&evenths, handle_expose_event, NULL);
405
406         /* Key presses are pretty obvious, I think */
407         xcb_event_set_key_press_handler(&evenths, handle_key_press, NULL);
408
409         /* Enter window = user moved his mouse over the window */
410         xcb_event_set_enter_notify_handler(&evenths, handle_enter_notify, NULL);
411
412         /* Button press = user pushed a mouse button over one of our windows */
413         xcb_event_set_button_press_handler(&evenths, handle_button_press, NULL);
414
415         /* Map notify = there is a new window */
416         xcb_event_set_map_request_handler(&evenths, handle_map_request, &prophs);
417
418         /* Unmap notify = window disappeared. When sent from a client, we don’t manage
419            it any longer. Usually, the client destroys the window shortly afterwards. */
420         xcb_event_set_unmap_notify_handler(&evenths, handle_unmap_notify_event, NULL);
421
422         /* Destroy notify is handled the same as unmap notify */
423         xcb_event_set_destroy_notify_handler(&evenths, handle_destroy_notify_event, NULL);
424
425         /* Configure notify = window’s configuration (geometry, stacking, …). We only need
426            it to set up ignore the following enter_notify events */
427         xcb_event_set_configure_notify_handler(&evenths, handle_configure_event, NULL);
428
429         /* Configure request = window tried to change size on its own */
430         xcb_event_set_configure_request_handler(&evenths, handle_configure_request, NULL);
431
432         /* Motion notify = user moved his cursor (over the root window and may
433          * cross virtual screen boundaries doing that) */
434         xcb_event_set_motion_notify_handler(&evenths, handle_motion_notify, NULL);
435
436         /* Mapping notify = keyboard mapping changed (Xmodmap), re-grab bindings */
437         xcb_event_set_mapping_notify_handler(&evenths, handle_mapping_notify, NULL);
438
439         /* Client message are sent to the root window. The only interesting client message
440            for us is _NET_WM_STATE, we honour _NET_WM_STATE_FULLSCREEN */
441         xcb_event_set_client_message_handler(&evenths, handle_client_message, NULL);
442
443         /* Initialize the property handlers */
444         xcb_property_handlers_init(&prophs, &evenths);
445
446         /* Watch size hints (to obey correct aspect ratio) */
447         xcb_property_set_handler(&prophs, WM_NORMAL_HINTS, UINT_MAX, handle_normal_hints, NULL);
448
449         /* set event mask */
450         uint32_t mask = XCB_CW_EVENT_MASK;
451         uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
452                               XCB_EVENT_MASK_STRUCTURE_NOTIFY |         /* when the user adds a screen (e.g. video
453                                                                            projector), the root window gets a
454                                                                            ConfigureNotify */
455                               XCB_EVENT_MASK_POINTER_MOTION |
456                               XCB_EVENT_MASK_PROPERTY_CHANGE |
457                               XCB_EVENT_MASK_ENTER_WINDOW };
458         xcb_void_cookie_t cookie;
459         cookie = xcb_change_window_attributes_checked(conn, root, mask, values);
460         check_error(conn, cookie, "Another window manager seems to be running");
461
462         /* Setup NetWM atoms */
463         #define GET_ATOM(name) { \
464                 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, atom_cookies[name], NULL); \
465                 if (!reply) { \
466                         ELOG("Could not get atom " #name "\n"); \
467                         exit(-1); \
468                 } \
469                 atoms[name] = reply->atom; \
470                 free(reply); \
471         }
472
473         GET_ATOM(_NET_SUPPORTED);
474         GET_ATOM(_NET_WM_STATE_FULLSCREEN);
475         GET_ATOM(_NET_SUPPORTING_WM_CHECK);
476         GET_ATOM(_NET_WM_NAME);
477         GET_ATOM(_NET_WM_STATE);
478         GET_ATOM(_NET_WM_WINDOW_TYPE);
479         GET_ATOM(_NET_WM_DESKTOP);
480         GET_ATOM(_NET_WM_WINDOW_TYPE_DOCK);
481         GET_ATOM(_NET_WM_WINDOW_TYPE_DIALOG);
482         GET_ATOM(_NET_WM_WINDOW_TYPE_UTILITY);
483         GET_ATOM(_NET_WM_WINDOW_TYPE_TOOLBAR);
484         GET_ATOM(_NET_WM_WINDOW_TYPE_SPLASH);
485         GET_ATOM(_NET_WM_STRUT_PARTIAL);
486         GET_ATOM(WM_PROTOCOLS);
487         GET_ATOM(WM_DELETE_WINDOW);
488         GET_ATOM(UTF8_STRING);
489         GET_ATOM(WM_STATE);
490         GET_ATOM(WM_CLIENT_LEADER);
491         GET_ATOM(_NET_CURRENT_DESKTOP);
492         GET_ATOM(_NET_ACTIVE_WINDOW);
493         GET_ATOM(_NET_WORKAREA);
494
495         xcb_property_set_handler(&prophs, atoms[_NET_WM_WINDOW_TYPE], UINT_MAX, handle_window_type, NULL);
496         /* TODO: In order to comply with EWMH, we have to watch _NET_WM_STRUT_PARTIAL */
497
498         /* Watch _NET_WM_NAME (= title of the window in UTF-8) property */
499         xcb_property_set_handler(&prophs, atoms[_NET_WM_NAME], 128, handle_windowname_change, NULL);
500
501         /* Watch WM_TRANSIENT_FOR property (to which client this popup window belongs) */
502         xcb_property_set_handler(&prophs, WM_TRANSIENT_FOR, UINT_MAX, handle_transient_for, NULL);
503
504         /* Watch WM_NAME (= title of the window in compound text) property for legacy applications */
505         xcb_watch_wm_name(&prophs, 128, handle_windowname_change_legacy, NULL);
506
507         /* Watch WM_CLASS (= class of the window) */
508         xcb_property_set_handler(&prophs, WM_CLASS, 128, handle_windowclass_change, NULL);
509
510         /* Watch WM_CLIENT_LEADER (= logical parent window for toolbars etc.) */
511         xcb_property_set_handler(&prophs, atoms[WM_CLIENT_LEADER], UINT_MAX, handle_clientleader_change, NULL);
512
513         /* Watch WM_HINTS (contains the urgent property) */
514         xcb_property_set_handler(&prophs, WM_HINTS, UINT_MAX, handle_hints, NULL);
515
516         /* Set up the atoms we support */
517         check_error(conn, xcb_change_property_checked(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_SUPPORTED],
518                        ATOM, 32, 16, atoms), "Could not set _NET_SUPPORTED");
519         /* Set up the window manager’s name */
520         xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_SUPPORTING_WM_CHECK], WINDOW, 32, 1, &root);
521         xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_WM_NAME], atoms[UTF8_STRING], 8, strlen("i3"), "i3");
522
523         keysyms = xcb_key_symbols_alloc(conn);
524
525         xcb_get_numlock_mask(conn);
526
527         translate_keysyms();
528         grab_all_keys(conn, false);
529
530         int randr_base;
531         if (force_xinerama) {
532                 initialize_xinerama(conn);
533         } else {
534                 DLOG("Checking for XRandR...\n");
535                 initialize_randr(conn, &randr_base);
536
537                 xcb_event_set_handler(&evenths,
538                                       randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY,
539                                       handle_screen_change,
540                                       NULL);
541         }
542
543         xcb_flush(conn);
544
545         /* Get pointer position to see on which screen we’re starting */
546         xcb_query_pointer_reply_t *reply;
547         if ((reply = xcb_query_pointer_reply(conn, xcb_query_pointer(conn, root), NULL)) == NULL) {
548                 ELOG("Could not get pointer position\n");
549                 return 1;
550         }
551
552         Output *screen = get_output_containing(reply->root_x, reply->root_y);
553         if (screen == NULL) {
554                 ELOG("ERROR: No screen at %d x %d, starting on the first screen\n",
555                     reply->root_x, reply->root_y);
556                 screen = get_first_output();
557         }
558
559         DLOG("Starting on %p\n", screen->current_workspace);
560         c_ws = screen->current_workspace;
561
562         manage_existing_windows(conn, &prophs, root);
563
564         /* Create the UNIX domain socket for IPC */
565         if (config.ipc_socket_path != NULL) {
566                 int ipc_socket = ipc_create_socket(config.ipc_socket_path);
567                 if (ipc_socket == -1) {
568                         ELOG("Could not create the IPC socket, IPC disabled\n");
569                 } else {
570                         struct ev_io *ipc_io = scalloc(sizeof(struct ev_io));
571                         ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ);
572                         ev_io_start(loop, ipc_io);
573                 }
574         }
575
576         /* Handle the events which arrived until now */
577         xcb_check_cb(NULL, NULL, 0);
578
579         setup_signal_handler();
580
581         /* Ignore SIGPIPE to survive errors when an IPC client disconnects
582          * while we are sending him a message */
583         signal(SIGPIPE, SIG_IGN);
584
585         /* Ungrab the server to receive events and enter libev’s eventloop */
586         xcb_ungrab_server(conn);
587
588         /* Autostarting exec-lines */
589         struct Autostart *exec;
590         if (autostart) {
591                 TAILQ_FOREACH(exec, &autostarts, autostarts) {
592                         LOG("auto-starting %s\n", exec->command);
593                         start_application(exec->command);
594                 }
595         }
596
597         ev_loop(loop, 0);
598
599         /* not reached */
600         return 0;
601 }