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 * Opens the window we use for input/output and maps it
27 xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height) {
28 xcb_window_t win = xcb_generate_id(conn);
29 //xcb_cursor_t cursor_id = xcb_generate_id(conn);
32 /* Use the default cursor (left pointer) */
34 i3Font *cursor_font = load_font(conn, "cursor");
35 xcb_create_glyph_cursor(conn, cursor_id, cursor_font->id, cursor_font->id,
36 XCB_CURSOR_LEFT_PTR, XCB_CURSOR_LEFT_PTR + 1,
37 0, 0, 0, 65535, 65535, 65535);
44 mask |= XCB_CW_BACK_PIXEL;
47 mask |= XCB_CW_OVERRIDE_REDIRECT;
50 mask |= XCB_CW_EVENT_MASK;
51 values[2] = XCB_EVENT_MASK_EXPOSURE;
53 xcb_create_window(conn,
55 win, /* the window id */
56 root, /* parent == root */
57 50, 50, width, height, /* dimensions */
58 0, /* border = 0, we draw our own */
59 XCB_WINDOW_CLASS_INPUT_OUTPUT,
60 XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
66 xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &cursor_id);
69 /* Map the window (= make it visible) */
70 xcb_map_window(conn, win);
76 * Returns the ID of the font matching the given pattern and stores the height
77 * of the font (in pixels) in *font_height. die()s if no font matches.
80 int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height) {
81 xcb_void_cookie_t font_cookie;
82 xcb_list_fonts_with_info_cookie_t info_cookie;
84 /* Send all our requests first */
86 result = xcb_generate_id(conn);
87 font_cookie = xcb_open_font_checked(conn, result, strlen(pattern), pattern);
88 info_cookie = xcb_list_fonts_with_info(conn, 1, strlen(pattern), pattern);
90 xcb_generic_error_t *error = xcb_request_check(conn, font_cookie);
92 fprintf(stderr, "ERROR: Could not open font: %d\n", error->error_code);
96 /* Get information (height/name) for this font */
97 xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(conn, info_cookie, NULL);
99 die("Could not load font \"%s\"\n", pattern);
101 *font_height = reply->font_ascent + reply->font_descent;