2 * vim:ts=4:sw=4:expandtab
10 #include <xcb/xproto.h>
11 #include <xcb/xcb_keysyms.h>
14 * Try to get the socket path from X11 and return NULL if it doesn’t work.
16 * The memory for the socket path is dynamically allocated and has to be
17 * free()d by the caller.
20 char *socket_path_from_x11();
23 * Safe-wrapper around malloc which exits if malloc returns NULL (meaning that
24 * there is no more memory available)
27 void *smalloc(size_t size);
30 * Safe-wrapper around calloc which exits if malloc returns NULL (meaning that
31 * there is no more memory available)
34 void *scalloc(size_t size);
37 * Safe-wrapper around realloc which exits if realloc returns NULL (meaning
38 * that there is no more memory available).
41 void *srealloc(void *ptr, size_t size);
44 * Safe-wrapper around strdup which exits if malloc returns NULL (meaning that
45 * there is no more memory available)
48 char *sstrdup(const char *str);
51 * Safe-wrapper around asprintf which exits if it returns -1 (meaning that
52 * there is no more memory available)
55 int sasprintf(char **strp, const char *fmt, ...);
58 * Connects to the i3 IPC socket and returns the file descriptor for the
59 * socket. die()s if anything goes wrong.
62 int ipc_connect(const char *socket_path);
65 * Formats a message (payload) of the given size and type and sends it to i3 via
66 * the given socket file descriptor.
68 * Returns -1 when write() fails, errno will remain.
69 * Returns 0 on success.
72 int ipc_send_message(int sockfd, uint32_t message_size,
73 uint32_t message_type, const uint8_t *payload);
76 * Reads a message from the given socket file descriptor and stores its length
77 * (reply_length) as well as a pointer to its contents (reply).
79 * Returns -1 when read() fails, errno will remain.
80 * Returns -2 when the IPC protocol is violated (invalid magic, unexpected
81 * message type, EOF instead of a message). Additionally, the error will be
83 * Returns 0 on success.
86 int ipc_recv_message(int sockfd, uint32_t message_type,
87 uint32_t *reply_length, uint8_t **reply);
90 * Generates a configure_notify event and sends it to the given window
91 * Applications need this to think they’ve configured themselves correctly.
92 * The truth is, however, that we will manage them.
95 void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width);
98 * Returns the colorpixel to use for the given hex color (think of HTML). Only
99 * works for true-color (vast majority of cases) at the moment, avoiding a
102 * The hex_color has to start with #, for example #FF00FF.
104 * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
105 * This has to be done by the caller.
107 * NOTE that this function may in the future rely on a global xcb_connection_t
108 * variable called 'conn' to be present.
111 uint32_t get_colorpixel(const char *hex) __attribute__((const));
113 #if defined(__APPLE__)
117 * Returns a pointer to a new string which is a duplicate of the
118 * string, but only copies at most n characters.
121 char *strndup(const char *str, size_t n);
126 * All-in-one function which returns the modifier mask (XCB_MOD_MASK_*) for the
127 * given keysymbol, for example for XCB_NUM_LOCK (usually configured to mod2).
129 * This function initiates one round-trip. Use get_mod_mask_for() directly if
130 * you already have the modifier mapping and key symbols.
133 uint32_t aio_get_mod_mask_for(uint32_t keysym, xcb_key_symbols_t *symbols);
136 * Returns the modifier mask (XCB_MOD_MASK_*) for the given keysymbol, for
137 * example for XCB_NUM_LOCK (usually configured to mod2).
139 * This function does not initiate any round-trips.
142 uint32_t get_mod_mask_for(uint32_t keysym,
143 xcb_key_symbols_t *symbols,
144 xcb_get_modifier_mapping_reply_t *modmap_reply);