2 * vim:ts=4:sw=4:expandtab
10 #include <xcb/xproto.h>
13 * Try to get the socket path from X11 and return NULL if it doesn’t work.
15 * The memory for the socket path is dynamically allocated and has to be
16 * free()d by the caller.
19 char *socket_path_from_x11();
22 * Safe-wrapper around malloc which exits if malloc returns NULL (meaning that
23 * there is no more memory available)
26 void *smalloc(size_t size);
29 * Safe-wrapper around calloc which exits if malloc returns NULL (meaning that
30 * there is no more memory available)
33 void *scalloc(size_t size);
36 * Safe-wrapper around realloc which exits if realloc returns NULL (meaning
37 * that there is no more memory available).
40 void *srealloc(void *ptr, size_t size);
43 * Safe-wrapper around strdup which exits if malloc returns NULL (meaning that
44 * there is no more memory available)
47 char *sstrdup(const char *str);
50 * Safe-wrapper around asprintf which exits if it returns -1 (meaning that
51 * there is no more memory available)
54 int sasprintf(char **strp, const char *fmt, ...);
57 * Connects to the i3 IPC socket and returns the file descriptor for the
58 * socket. die()s if anything goes wrong.
61 int ipc_connect(const char *socket_path);
64 * Formats a message (payload) of the given size and type and sends it to i3 via
65 * the given socket file descriptor.
67 * Returns -1 when write() fails, errno will remain.
68 * Returns 0 on success.
71 int ipc_send_message(int sockfd, uint32_t message_size,
72 uint32_t message_type, const uint8_t *payload);
75 * Reads a message from the given socket file descriptor and stores its length
76 * (reply_length) as well as a pointer to its contents (reply).
78 * Returns -1 when read() fails, errno will remain.
79 * Returns -2 when the IPC protocol is violated (invalid magic, unexpected
80 * message type, EOF instead of a message). Additionally, the error will be
82 * Returns 0 on success.
85 int ipc_recv_message(int sockfd, uint32_t message_type,
86 uint32_t *reply_length, uint8_t **reply);
89 * Generates a configure_notify event and sends it to the given window
90 * Applications need this to think they’ve configured themselves correctly.
91 * The truth is, however, that we will manage them.
94 void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width);
97 * Returns the colorpixel to use for the given hex color (think of HTML). Only
98 * works for true-color (vast majority of cases) at the moment, avoiding a
101 * The hex_color has to start with #, for example #FF00FF.
103 * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
104 * This has to be done by the caller.
106 * NOTE that this function may in the future rely on a global xcb_connection_t
107 * variable called 'conn' to be present.
110 uint32_t get_colorpixel(const char *hex) __attribute__((const));
112 #if defined(__APPLE__)
116 * Returns a pointer to a new string which is a duplicate of the
117 * string, but only copies at most n characters.
120 char *strndup(const char *str, size_t n);