- #define REQUEST_ATOM(name) atom_cookies[name] = xcb_intern_atom(conn, 0, strlen(#name), #name);
-
- REQUEST_ATOM(_NET_SUPPORTED);
- REQUEST_ATOM(_NET_WM_STATE_FULLSCREEN);
- REQUEST_ATOM(_NET_SUPPORTING_WM_CHECK);
- REQUEST_ATOM(_NET_WM_NAME);
- REQUEST_ATOM(_NET_WM_STATE);
- REQUEST_ATOM(_NET_WM_WINDOW_TYPE);
- REQUEST_ATOM(_NET_WM_DESKTOP);
- REQUEST_ATOM(_NET_WM_WINDOW_TYPE_DOCK);
- REQUEST_ATOM(_NET_WM_WINDOW_TYPE_DIALOG);
- REQUEST_ATOM(_NET_WM_WINDOW_TYPE_UTILITY);
- REQUEST_ATOM(_NET_WM_WINDOW_TYPE_TOOLBAR);
- REQUEST_ATOM(_NET_WM_WINDOW_TYPE_SPLASH);
- REQUEST_ATOM(_NET_WM_STRUT_PARTIAL);
- REQUEST_ATOM(WM_PROTOCOLS);
- REQUEST_ATOM(WM_DELETE_WINDOW);
- REQUEST_ATOM(UTF8_STRING);
- REQUEST_ATOM(WM_STATE);
- REQUEST_ATOM(WM_CLIENT_LEADER);
- REQUEST_ATOM(_NET_CURRENT_DESKTOP);
- REQUEST_ATOM(_NET_ACTIVE_WINDOW);
- REQUEST_ATOM(_NET_WORKAREA);
-
- memset(&evenths, 0, sizeof(xcb_event_handlers_t));
- memset(&prophs, 0, sizeof(xcb_property_handlers_t));
-
- xcb_event_handlers_init(conn, &evenths);
- xcb_property_handlers_init(&prophs, &evenths);
- xcb_event_set_key_press_handler(&evenths, handle_key_press, NULL);
-
- xcb_event_set_button_press_handler(&evenths, handle_button_press, NULL);
-
- xcb_event_set_map_request_handler(&evenths, handle_map_request, NULL);
-
- xcb_event_set_unmap_notify_handler(&evenths, handle_unmap_notify_event, NULL);
- xcb_event_set_destroy_notify_handler(&evenths, handle_destroy_notify_event, NULL);
-
- xcb_event_set_expose_handler(&evenths, handle_expose_event, NULL);
-
- /* Enter window = user moved his mouse over the window */
- xcb_event_set_enter_notify_handler(&evenths, handle_enter_notify, NULL);
-
- /* Client message are sent to the root window. The only interesting client message
- for us is _NET_WM_STATE, we honour _NET_WM_STATE_FULLSCREEN */
- xcb_event_set_client_message_handler(&evenths, handle_client_message, NULL);
-
- /* Configure request = window tried to change size on its own */
- xcb_event_set_configure_request_handler(&evenths, handle_configure_request, NULL);
+ #define xmacro(atom) \
+ xcb_intern_atom_cookie_t atom ## _cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
+ #include "atoms.xmacro"
+ #undef xmacro
+
+ /* Initialize the Xlib connection */
+ xlibdpy = xkbdpy = XOpenDisplay(NULL);
+
+ /* Try to load the X cursors and initialize the XKB extension */
+ if (xlibdpy == NULL) {
+ ELOG("ERROR: XOpenDisplay() failed, disabling libXcursor/XKB support\n");
+ xcursor_supported = false;
+ xkb_supported = false;
+ } else if (fcntl(ConnectionNumber(xlibdpy), F_SETFD, FD_CLOEXEC) == -1) {
+ ELOG("Could not set FD_CLOEXEC on xkbdpy\n");
+ return 1;
+ } else {
+ xcursor_load_cursors();
+ /*init_xkb();*/
+ }
+
+ if (xkb_supported) {
+ int errBase,
+ major = XkbMajorVersion,
+ minor = XkbMinorVersion;
+
+ if (fcntl(ConnectionNumber(xkbdpy), F_SETFD, FD_CLOEXEC) == -1) {
+ fprintf(stderr, "Could not set FD_CLOEXEC on xkbdpy\n");
+ return 1;
+ }
+
+ int i1;
+ if (!XkbQueryExtension(xkbdpy,&i1,&xkb_event_base,&errBase,&major,&minor)) {
+ fprintf(stderr, "XKB not supported by X-server\n");
+ return 1;
+ }
+ /* end of ugliness */
+
+ if (!XkbSelectEvents(xkbdpy, XkbUseCoreKbd,
+ XkbMapNotifyMask | XkbStateNotifyMask,
+ XkbMapNotifyMask | XkbStateNotifyMask)) {
+ fprintf(stderr, "Could not set XKB event mask\n");
+ return 1;
+ }
+ }