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>
23 extern char *current_socketpath;
25 typedef struct ipc_client {
28 /* The events which this client wants to receive */
32 TAILQ_ENTRY(ipc_client) clients;
36 * Callback type for the different message types.
38 * message is the raw packet, as received from the UNIX domain socket. size
39 * is the remaining size of bytes for this packet.
41 * message_size is the size of the message as the sender specified it.
42 * message_type is the type of the message as the sender specified it.
45 typedef void(*handler_t)(int, uint8_t*, int, uint32_t, uint32_t);
47 /* Macro to declare a callback */
48 #define IPC_HANDLER(name) \
49 static void handle_ ## name (int fd, uint8_t *message, \
50 int size, uint32_t message_size, \
51 uint32_t message_type)
54 * Emulates mkdir -p (creates any missing folders)
57 bool mkdirp(const char *path);
60 * Handler for activity on the listening socket, meaning that a new client
61 * has just connected and we should accept() him. Sets up the event handler
62 * for activity on the new connection and inserts the file descriptor into
63 * the list of clients.
66 void ipc_new_client(EV_P_ struct ev_io *w, int revents);
69 * Creates the UNIX domain socket at the given path, sets it to non-blocking
70 * mode, bind()s and listen()s on it.
73 int ipc_create_socket(const char *filename);
76 * Sends the specified event to all IPC clients which are currently connected
77 * and subscribed to this kind of event.
80 void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
83 * Calls shutdown() on each socket and closes it. This function to be called
84 * when exiting or restarting only!
87 void ipc_shutdown(void);
89 void dump_node(yajl_gen gen, Con *con, bool inplace_restart);
92 * For the workspace "focus" event we send, along the usual "change" field,
93 * also the current and previous workspace, in "current" and "old"
96 void ipc_send_workspace_focus_event(Con *current, Con *old);
99 * For the window events we send, along the usual "change" field,
100 * also the window container, in "container".
102 void ipc_send_window_event(const char *property, Con *con);
105 * For the barconfig update events, we send the serialized barconfig.
107 void ipc_send_barconfig_update_event(Barconfig *barconfig);