4 * i3 - an improved dynamic tiling window manager
6 * © 2009 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
17 #include <xcb/xcb_keysyms.h>
19 #include <X11/keysym.h>
24 * Returns the mask for Mode_switch (to be used for looking up keysymbols by
28 uint32_t get_mod_mask(xcb_connection_t *conn, uint32_t keycode) {
29 xcb_key_symbols_t *symbols = xcb_key_symbols_alloc(conn);
31 xcb_get_modifier_mapping_reply_t *modmap_r;
32 xcb_keycode_t *modmap, kc;
33 xcb_keycode_t *modeswitchcodes = xcb_key_symbols_get_keycode(symbols, keycode);
34 if (modeswitchcodes == NULL)
37 modmap_r = xcb_get_modifier_mapping_reply(conn, xcb_get_modifier_mapping(conn), NULL);
38 modmap = xcb_get_modifier_mapping_keycodes(modmap_r);
40 for (int i = 0; i < 8; i++)
41 for (int j = 0; j < modmap_r->keycodes_per_modifier; j++) {
42 kc = modmap[i * modmap_r->keycodes_per_modifier + j];
43 for (xcb_keycode_t *ktest = modeswitchcodes; *ktest; ktest++) {
47 free(modeswitchcodes);
57 * Opens the window we use for input/output and maps it
60 xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height) {
61 xcb_window_t win = xcb_generate_id(conn);
62 //xcb_cursor_t cursor_id = xcb_generate_id(conn);
65 /* Use the default cursor (left pointer) */
67 i3Font *cursor_font = load_font(conn, "cursor");
68 xcb_create_glyph_cursor(conn, cursor_id, cursor_font->id, cursor_font->id,
69 XCB_CURSOR_LEFT_PTR, XCB_CURSOR_LEFT_PTR + 1,
70 0, 0, 0, 65535, 65535, 65535);
77 mask |= XCB_CW_BACK_PIXEL;
80 mask |= XCB_CW_OVERRIDE_REDIRECT;
83 mask |= XCB_CW_EVENT_MASK;
84 values[2] = XCB_EVENT_MASK_EXPOSURE;
86 xcb_create_window(conn,
88 win, /* the window id */
89 root, /* parent == root */
90 50, 50, width, height, /* dimensions */
91 0, /* border = 0, we draw our own */
92 XCB_WINDOW_CLASS_INPUT_OUTPUT,
93 XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
99 xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &cursor_id);
102 /* Map the window (= make it visible) */
103 xcb_map_window(conn, win);
109 * Returns the ID of the font matching the given pattern and stores the height
110 * of the font (in pixels) in *font_height. die()s if no font matches.
113 int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height) {
114 xcb_void_cookie_t font_cookie;
115 xcb_list_fonts_with_info_cookie_t info_cookie;
117 /* Send all our requests first */
119 result = xcb_generate_id(conn);
120 font_cookie = xcb_open_font_checked(conn, result, strlen(pattern), pattern);
121 info_cookie = xcb_list_fonts_with_info(conn, 1, strlen(pattern), pattern);
123 xcb_generic_error_t *error = xcb_request_check(conn, font_cookie);
125 fprintf(stderr, "ERROR: Could not open font: %d\n", error->error_code);
129 /* Get information (height/name) for this font */
130 xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(conn, info_cookie, NULL);
132 die("Could not load font \"%s\"\n", pattern);
134 *font_height = reply->font_ascent + reply->font_descent;