]> git.sur5r.net Git - i3/i3/blob - include/libi3.h
add libi3/ipc_connect, use it in i3-config-wizard, i3-input, i3bar
[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 <stdarg.h>
9 #include <xcb/xcb.h>
10 #include <xcb/xproto.h>
11
12 /**
13  * Try to get the socket path from X11 and return NULL if it doesn’t work.
14  *
15  * The memory for the socket path is dynamically allocated and has to be
16  * free()d by the caller.
17  *
18  */
19 char *socket_path_from_x11();
20
21 /**
22  * Safe-wrapper around malloc which exits if malloc returns NULL (meaning that
23  * there is no more memory available)
24  *
25  */
26 void *smalloc(size_t size);
27
28 /**
29  * Safe-wrapper around calloc which exits if malloc returns NULL (meaning that
30  * there is no more memory available)
31  *
32  */
33 void *scalloc(size_t size);
34
35 /**
36  * Safe-wrapper around realloc which exits if realloc returns NULL (meaning
37  * that there is no more memory available).
38  *
39  */
40 void *srealloc(void *ptr, size_t size);
41
42 /**
43  * Safe-wrapper around strdup which exits if malloc returns NULL (meaning that
44  * there is no more memory available)
45  *
46  */
47 char *sstrdup(const char *str);
48
49 /**
50  * Safe-wrapper around asprintf which exits if it returns -1 (meaning that
51  * there is no more memory available)
52  *
53  */
54 int sasprintf(char **strp, const char *fmt, ...);
55
56 /**
57  * Connects to the i3 IPC socket and returns the file descriptor for the
58  * socket. die()s if anything goes wrong.
59  *
60  */
61 int ipc_connect(const char *socket_path);
62
63 /**
64  * Formats a message (payload) of the given size and type and sends it to i3 via
65  * the given socket file descriptor.
66  *
67  * Returns -1 when write() fails, errno will remain.
68  * Returns 0 on success.
69  *
70  */
71 int ipc_send_message(int sockfd, uint32_t message_size,
72                      uint32_t message_type, const uint8_t *payload);
73
74 /**
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).
77  *
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
81  * printed to stderr.
82  * Returns 0 on success.
83  *
84  */
85 int ipc_recv_message(int sockfd, uint32_t message_type,
86                      uint32_t *reply_length, uint8_t **reply);
87
88 /**
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.
92  *
93  */
94 void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width);
95
96 #endif