2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
7 * ipc.c: UNIX domain socket IPC (initialization, client handling, protocol).
16 #include <yajl/yajl_gen.h>
17 #include <yajl/yajl_parse.h>
21 #include "configuration.h"
25 extern char *current_socketpath;
27 typedef struct ipc_client {
30 /* The events which this client wants to receive */
34 /* For clients which subscribe to the tick event: whether the first tick
35 * event has been sent by i3. */
38 TAILQ_ENTRY(ipc_client)
43 * Callback type for the different message types.
45 * message is the raw packet, as received from the UNIX domain socket. size
46 * is the remaining size of bytes for this packet.
48 * message_size is the size of the message as the sender specified it.
49 * message_type is the type of the message as the sender specified it.
52 typedef void (*handler_t)(int, uint8_t *, int, uint32_t, uint32_t);
54 /* Macro to declare a callback */
55 #define IPC_HANDLER(name) \
56 static void handle_##name(int fd, uint8_t *message, \
57 int size, uint32_t message_size, \
58 uint32_t message_type)
61 * Handler for activity on the listening socket, meaning that a new client
62 * has just connected and we should accept() him. Sets up the event handler
63 * for activity on the new connection and inserts the file descriptor into
64 * the list of clients.
67 void ipc_new_client(EV_P_ struct ev_io *w, int revents);
70 * Creates the UNIX domain socket at the given path, sets it to non-blocking
71 * mode, bind()s and listen()s on it.
74 int ipc_create_socket(const char *filename);
77 * Sends the specified event to all IPC clients which are currently connected
78 * and subscribed to this kind of event.
81 void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
84 * Calls to ipc_shutdown() should provide a reason for the shutdown.
87 SHUTDOWN_REASON_RESTART,
92 * Calls shutdown() on each socket and closes it.
95 void ipc_shutdown(shutdown_reason_t reason);
97 void dump_node(yajl_gen gen, Con *con, bool inplace_restart);
100 * Generates a json workspace event. Returns a dynamically allocated yajl
101 * generator. Free with yajl_gen_free().
103 yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old);
106 * For the workspace events we send, along with the usual "change" field, also
107 * the workspace container in "current". For focus events, we send the
108 * previously focused workspace in "old".
110 void ipc_send_workspace_event(const char *change, Con *current, Con *old);
113 * For the window events we send, along the usual "change" field,
114 * also the window container, in "container".
116 void ipc_send_window_event(const char *property, Con *con);
119 * For the barconfig update events, we send the serialized barconfig.
121 void ipc_send_barconfig_update_event(Barconfig *barconfig);
124 * For the binding events, we send the serialized binding struct.
126 void ipc_send_binding_event(const char *event_type, Binding *bind);