]> git.sur5r.net Git - i3/i3/blob - include/libi3.h
Move fake_configure_notify to libi3
[i3/i3] / include / libi3.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  */
4
5 #ifndef _LIBI3_H
6 #define _LIBI3_H
7
8 #include <xcb/xcb.h>
9 #include <xcb/xproto.h>
10
11 /**
12  * Try to get the socket path from X11 and return NULL if it doesn’t work.
13  *
14  * The memory for the socket path is dynamically allocated and has to be
15  * free()d by the caller.
16  *
17  */
18 char *socket_path_from_x11();
19
20 /**
21  * Safe-wrapper around malloc which exits if malloc returns NULL (meaning that
22  * there is no more memory available)
23  *
24  */
25 void *smalloc(size_t size);
26
27 /**
28  * Safe-wrapper around calloc which exits if malloc returns NULL (meaning that
29  * there is no more memory available)
30  *
31  */
32 void *scalloc(size_t size);
33
34 /**
35  * Safe-wrapper around realloc which exits if realloc returns NULL (meaning
36  * that there is no more memory available).
37  *
38  */
39 void *srealloc(void *ptr, size_t size);
40
41 /**
42  * Safe-wrapper around strdup which exits if malloc returns NULL (meaning that
43  * there is no more memory available)
44  *
45  */
46 char *sstrdup(const char *str);
47
48 /**
49  * Formats a message (payload) of the given size and type and sends it to i3 via
50  * the given socket file descriptor.
51  *
52  * Returns -1 when write() fails, errno will remain.
53  * Returns 0 on success.
54  *
55  */
56 int ipc_send_message(int sockfd, uint32_t message_size,
57                      uint32_t message_type, const uint8_t *payload);
58
59 /**
60  * Reads a message from the given socket file descriptor and stores its length
61  * (reply_length) as well as a pointer to its contents (reply).
62  *
63  * Returns -1 when read() fails, errno will remain.
64  * Returns -2 when the IPC protocol is violated (invalid magic, unexpected
65  * message type, EOF instead of a message). Additionally, the error will be
66  * printed to stderr.
67  * Returns 0 on success.
68  *
69  */
70 int ipc_recv_message(int sockfd, uint32_t message_type,
71                      uint32_t *reply_length, uint8_t **reply);
72
73 /**
74  * Generates a configure_notify event and sends it to the given window
75  * Applications need this to think they’ve configured themselves correctly.
76  * The truth is, however, that we will manage them.
77  *
78  */
79 void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width);
80
81 #endif