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 * xcb.c: Helper functions for easier usage of XCB 8 * 9 */ 10 #pragma once 11 12 #include <config.h> 13 14 #include "data.h" 15 #include "xcursor.h" 16 17 #define _NET_WM_STATE_REMOVE 0 18 #define _NET_WM_STATE_ADD 1 19 #define _NET_WM_STATE_TOGGLE 2 20 21 /* from X11/keysymdef.h */ 22 #define XCB_NUM_LOCK 0xff7f 23 24 /* The event masks are defined here because we don’t only set them once but we 25 need to set slight variations of them (without XCB_EVENT_MASK_ENTER_WINDOW 26 while rendering the layout) */ 27 /** The XCB_CW_EVENT_MASK for the child (= real window) */ 28 #define CHILD_EVENT_MASK (XCB_EVENT_MASK_PROPERTY_CHANGE | \ 29 XCB_EVENT_MASK_STRUCTURE_NOTIFY | \ 30 XCB_EVENT_MASK_FOCUS_CHANGE) 31 32 /** The XCB_CW_EVENT_MASK for its frame */ 33 #define FRAME_EVENT_MASK (XCB_EVENT_MASK_BUTTON_PRESS | /* …mouse is pressed/released */ \ 34 XCB_EVENT_MASK_BUTTON_RELEASE | \ 35 XCB_EVENT_MASK_POINTER_MOTION | /* …mouse is moved */ \ 36 XCB_EVENT_MASK_EXPOSURE | /* …our window needs to be redrawn */ \ 37 XCB_EVENT_MASK_STRUCTURE_NOTIFY | /* …the frame gets destroyed */ \ 38 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | /* …the application tries to resize itself */ \ 39 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | /* …subwindows get notifies */ \ 40 XCB_EVENT_MASK_ENTER_WINDOW) /* …user moves cursor inside our window */ 41 42 #define ROOT_EVENT_MASK (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | \ 43 XCB_EVENT_MASK_BUTTON_PRESS | \ 44 XCB_EVENT_MASK_STRUCTURE_NOTIFY | /* when the user adds a screen (e.g. video \ 45 * projector), the root window gets a \ 46 * ConfigureNotify */ \ 47 XCB_EVENT_MASK_POINTER_MOTION | \ 48 XCB_EVENT_MASK_PROPERTY_CHANGE | \ 49 XCB_EVENT_MASK_FOCUS_CHANGE | \ 50 XCB_EVENT_MASK_ENTER_WINDOW) 51 52 #include "i3-atoms_rest.xmacro.h" 53 #include "i3-atoms_NET_SUPPORTED.xmacro.h" 54 55 #define xmacro(atom) extern xcb_atom_t A_##atom; 56 I3_NET_SUPPORTED_ATOMS_XMACRO 57 I3_REST_ATOMS_XMACRO 58 #undef xmacro 59 60 extern unsigned int xcb_numlock_mask; 61 62 /** 63 * Convenience wrapper around xcb_create_window which takes care of depth, 64 * generating an ID and checking for errors. 65 * 66 */ 67 xcb_window_t create_window(xcb_connection_t *conn, Rect r, uint16_t depth, xcb_visualid_t visual, 68 uint16_t window_class, enum xcursor_cursor_t cursor, bool map, uint32_t mask, uint32_t *values); 69 70 /** 71 * Generates a configure_notify_event with absolute coordinates (relative to 72 * the X root window, not to the client’s frame) for the given client. 73 * 74 */ 75 void fake_absolute_configure_notify(Con *con); 76 77 /** 78 * Sends the WM_TAKE_FOCUS ClientMessage to the given window 79 * 80 */ 81 void send_take_focus(xcb_window_t window, xcb_timestamp_t timestamp); 82 83 /** 84 * Configures the given window to have the size/position specified by given rect 85 * 86 */ 87 void xcb_set_window_rect(xcb_connection_t *conn, xcb_window_t window, Rect r); 88 89 /** 90 * Returns the first supported _NET_WM_WINDOW_TYPE atom. 91 * 92 */ 93 xcb_atom_t xcb_get_preferred_window_type(xcb_get_property_reply_t *reply); 94 95 /** 96 * Returns true if the given reply contains the given data. 97 * 98 */ 99 bool xcb_reply_contains_atom(xcb_get_property_reply_t *prop, xcb_atom_t atom); 100 101 /** 102 * Get depth of visual specified by visualid 103 * 104 */ 105 uint16_t get_visual_depth(xcb_visualid_t visual_id); 106 107 /** 108 * Get visual type specified by visualid 109 * 110 */ 111 xcb_visualtype_t *get_visualtype_by_id(xcb_visualid_t visual_id); 112 113 /** 114 * Get visualid with specified depth 115 * 116 */ 117 xcb_visualid_t get_visualid_by_depth(uint16_t depth); 118 119 /** 120 * Add an atom to a list of atoms the given property defines. 121 * This is useful, for example, for manipulating _NET_WM_STATE. 122 * 123 */ 124 void xcb_add_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t property, xcb_atom_t atom); 125 126 /** 127 * Remove an atom from a list of atoms the given property defines without 128 * removing any other potentially set atoms. This is useful, for example, for 129 * manipulating _NET_WM_STATE. 130 * 131 */ 132 void xcb_remove_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t property, xcb_atom_t atom); 133 134 /** 135 * Grab the specified buttons on a window when managing it. 136 * 137 */ 138 void xcb_grab_buttons(xcb_connection_t *conn, xcb_window_t window, int *buttons); 139