]> git.sur5r.net Git - i3/i3/blob - include/ipc.h
7ffbf7a831f9de3418f9d4ddad304beee5cbff22
[i3/i3] / include / ipc.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * ipc.c: UNIX domain socket IPC (initialization, client handling, protocol).
8  *
9  */
10 #pragma once
11
12 #include <config.h>
13
14 #include <ev.h>
15 #include <stdbool.h>
16 #include <yajl/yajl_gen.h>
17 #include <yajl/yajl_parse.h>
18
19 #include "data.h"
20 #include "tree.h"
21 #include "configuration.h"
22
23 #include "i3/ipc.h"
24
25 extern char *current_socketpath;
26
27 typedef struct ipc_client {
28     int fd;
29
30     /* The events which this client wants to receive */
31     int num_events;
32     char **events;
33
34     TAILQ_ENTRY(ipc_client)
35     clients;
36 } ipc_client;
37
38 /*
39  * Callback type for the different message types.
40  *
41  * message is the raw packet, as received from the UNIX domain socket. size
42  * is the remaining size of bytes for this packet.
43  *
44  * message_size is the size of the message as the sender specified it.
45  * message_type is the type of the message as the sender specified it.
46  *
47  */
48 typedef void (*handler_t)(int, uint8_t *, int, uint32_t, uint32_t);
49
50 /* Macro to declare a callback */
51 #define IPC_HANDLER(name)                                      \
52     static void handle_##name(int fd, uint8_t *message,        \
53                               int size, uint32_t message_size, \
54                               uint32_t message_type)
55
56 /**
57  * Handler for activity on the listening socket, meaning that a new client
58  * has just connected and we should accept() him. Sets up the event handler
59  * for activity on the new connection and inserts the file descriptor into
60  * the list of clients.
61  *
62  */
63 void ipc_new_client(EV_P_ struct ev_io *w, int revents);
64
65 /**
66  * Creates the UNIX domain socket at the given path, sets it to non-blocking
67  * mode, bind()s and listen()s on it.
68  *
69  */
70 int ipc_create_socket(const char *filename);
71
72 /**
73  * Sends the specified event to all IPC clients which are currently connected
74  * and subscribed to this kind of event.
75  *
76  */
77 void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
78
79 /**
80  * Calls to ipc_shutdown() should provide a reason for the shutdown.
81  */
82 typedef enum {
83     SHUTDOWN_REASON_RESTART,
84     SHUTDOWN_REASON_EXIT
85 } shutdown_reason_t;
86
87 /**
88  * Calls shutdown() on each socket and closes it.
89  *
90  */
91 void ipc_shutdown(shutdown_reason_t reason);
92
93 void dump_node(yajl_gen gen, Con *con, bool inplace_restart);
94
95 /**
96  * Generates a json workspace event. Returns a dynamically allocated yajl
97  * generator. Free with yajl_gen_free().
98  */
99 yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old);
100
101 /**
102  * For the workspace events we send, along with the usual "change" field, also
103  * the workspace container in "current". For focus events, we send the
104  * previously focused workspace in "old".
105  */
106 void ipc_send_workspace_event(const char *change, Con *current, Con *old);
107
108 /**
109  * For the window events we send, along the usual "change" field,
110  * also the window container, in "container".
111  */
112 void ipc_send_window_event(const char *property, Con *con);
113
114 /**
115  * For the barconfig update events, we send the serialized barconfig.
116  */
117 void ipc_send_barconfig_update_event(Barconfig *barconfig);
118
119 /**
120  * For the binding events, we send the serialized binding struct.
121  */
122 void ipc_send_binding_event(const char *event_type, Binding *bind);