2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
7 * ipc.c: UNIX domain socket IPC (initialization, client handling, protocol).
14 #include <yajl/yajl_gen.h>
15 #include <yajl/yajl_parse.h>
22 extern char *current_socketpath;
24 typedef struct ipc_client {
27 /* The events which this client wants to receive */
31 TAILQ_ENTRY(ipc_client) clients;
35 * Callback type for the different message types.
37 * message is the raw packet, as received from the UNIX domain socket. size
38 * is the remaining size of bytes for this packet.
40 * message_size is the size of the message as the sender specified it.
41 * message_type is the type of the message as the sender specified it.
44 typedef void(*handler_t)(int, uint8_t*, int, uint32_t, uint32_t);
46 /* Macro to declare a callback */
47 #define IPC_HANDLER(name) \
48 static void handle_ ## name (int fd, uint8_t *message, \
49 int size, uint32_t message_size, \
50 uint32_t message_type)
53 * Handler for activity on the listening socket, meaning that a new client
54 * has just connected and we should accept() him. Sets up the event handler
55 * for activity on the new connection and inserts the file descriptor into
56 * the list of clients.
59 void ipc_new_client(EV_P_ struct ev_io *w, int revents);
62 * Creates the UNIX domain socket at the given path, sets it to non-blocking
63 * mode, bind()s and listen()s on it.
66 int ipc_create_socket(const char *filename);
69 * Sends the specified event to all IPC clients which are currently connected
70 * and subscribed to this kind of event.
73 void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
76 * Calls shutdown() on each socket and closes it. This function to be called
77 * when exiting or restarting only!
80 void ipc_shutdown(void);
82 void dump_node(yajl_gen gen, Con *con, bool inplace_restart);
85 * For the workspace "focus" event we send, along the usual "change" field,
86 * also the current and previous workspace, in "current" and "old"
89 void ipc_send_workspace_focus_event(Con *current, Con *old);
92 * For the window events we send, along the usual "change" field,
93 * also the window container, in "container".
95 void ipc_send_window_event(const char *property, Con *con);