]> git.sur5r.net Git - i3/i3/blob - include/ipc.h
Merge branch 'next'
[i3/i3] / include / ipc.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2011 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 <ev.h>
13 #include <stdbool.h>
14 #include <yajl/yajl_gen.h>
15 #include <yajl/yajl_parse.h>
16
17 #include "data.h"
18 #include "tree.h"
19 #include "config.h"
20
21 #include "i3/ipc.h"
22
23 extern char *current_socketpath;
24
25 typedef struct ipc_client {
26     int fd;
27
28     /* The events which this client wants to receive */
29     int num_events;
30     char **events;
31
32     TAILQ_ENTRY(ipc_client) clients;
33 } ipc_client;
34
35 /*
36  * Callback type for the different message types.
37  *
38  * message is the raw packet, as received from the UNIX domain socket. size
39  * is the remaining size of bytes for this packet.
40  *
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.
43  *
44  */
45 typedef void (*handler_t)(int, uint8_t *, int, uint32_t, uint32_t);
46
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)
52
53 /**
54  * Emulates mkdir -p (creates any missing folders)
55  *
56  */
57 bool mkdirp(const char *path);
58
59 /**
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.
64  *
65  */
66 void ipc_new_client(EV_P_ struct ev_io *w, int revents);
67
68 /**
69  * Creates the UNIX domain socket at the given path, sets it to non-blocking
70  * mode, bind()s and listen()s on it.
71  *
72  */
73 int ipc_create_socket(const char *filename);
74
75 /**
76  * Sends the specified event to all IPC clients which are currently connected
77  * and subscribed to this kind of event.
78  *
79  */
80 void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
81
82 /**
83  * Calls shutdown() on each socket and closes it. This function to be called
84  * when exiting or restarting only!
85  *
86  */
87 void ipc_shutdown(void);
88
89 void dump_node(yajl_gen gen, Con *con, bool inplace_restart);
90
91 /**
92  * Generates a json workspace event. Returns a dynamically allocated yajl
93  * generator. Free with yajl_gen_free().
94  */
95 yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old);
96
97 /**
98  * For the workspace events we send, along with the usual "change" field, also
99  * the workspace container in "current". For focus events, we send the
100  * previously focused workspace in "old".
101  */
102 void ipc_send_workspace_event(const char *change, Con *current, Con *old);
103
104 /**
105  * For the window events we send, along the usual "change" field,
106  * also the window container, in "container".
107  */
108 void ipc_send_window_event(const char *property, Con *con);
109
110 /**
111  * For the barconfig update events, we send the serialized barconfig.
112  */
113 void ipc_send_barconfig_update_event(Barconfig *barconfig);
114
115 /**
116  * For the binding events, we send the serialized binding struct.
117  */
118 void ipc_send_binding_event(const char *event_type, Binding *bind);