i3
ipc.h
Go to the documentation of this file.
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 */
32  char **events;
33 
34  /* For clients which subscribe to the tick event: whether the first tick
35  * event has been sent by i3. */
37 
38  struct ev_io *callback;
39  struct ev_timer *timeout;
40  uint8_t *buffer;
41  size_t buffer_size;
42 
45 } ipc_client;
46 
47 /*
48  * Callback type for the different message types.
49  *
50  * message is the raw packet, as received from the UNIX domain socket. size
51  * is the remaining size of bytes for this packet.
52  *
53  * message_size is the size of the message as the sender specified it.
54  * message_type is the type of the message as the sender specified it.
55  *
56  */
57 typedef void (*handler_t)(int, uint8_t *, int, uint32_t, uint32_t);
58 
59 /* Macro to declare a callback */
60 #define IPC_HANDLER(name) \
61  static void handle_##name(int fd, uint8_t *message, \
62  int size, uint32_t message_size, \
63  uint32_t message_type)
64 
72 void ipc_new_client(EV_P_ struct ev_io *w, int revents);
73 
79 int ipc_create_socket(const char *filename);
80 
86 void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
87 
91 typedef enum {
95 
100 void ipc_shutdown(shutdown_reason_t reason);
101 
102 void dump_node(yajl_gen gen, Con *con, bool inplace_restart);
103 
108 yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old);
109 
115 void ipc_send_workspace_event(const char *change, Con *current, Con *old);
116 
121 void ipc_send_window_event(const char *property, Con *con);
122 
127 
131 void ipc_send_binding_event(const char *event_type, Binding *bind);
132 
137 void ipc_set_kill_timeout(ev_tstamp new);
void ipc_send_event(const char *event, uint32_t message_type, const char *payload)
Sends the specified event to all IPC clients which are currently connected and subscribed to this kin...
Definition: ipc.c:148
yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old)
Generates a json workspace event.
Definition: ipc.c:1538
void(* handler_t)(int, uint8_t *, int, uint32_t, uint32_t)
Definition: ipc.h:57
void ipc_send_binding_event(const char *event_type, Binding *bind)
For the binding events, we send the serialized binding struct.
Definition: ipc.c:1635
void ipc_new_client(EV_P_ struct ev_io *w, int revents)
Handler for activity on the listening socket, meaning that a new client has just connected and we sho...
Definition: ipc.c:1448
void ipc_send_barconfig_update_event(Barconfig *barconfig)
For the barconfig update events, we send the serialized barconfig.
Definition: ipc.c:1616
Holds a keybinding, consisting of a keycode combined with modifiers and the command which is executed...
Definition: data.h:299
struct ev_io * callback
Definition: ipc.h:38
void ipc_shutdown(shutdown_reason_t reason)
Calls shutdown() on each socket and closes it.
Definition: ipc.c:201
Definition: ipc.h:27
uint8_t * buffer
Definition: ipc.h:40
clients
Definition: ipc.h:44
#define TAILQ_ENTRY(type)
Definition: queue.h:327
void dump_node(yajl_gen gen, Con *con, bool inplace_restart)
Definition: ipc.c:347
struct ev_timer * timeout
Definition: ipc.h:39
int fd
Definition: ipc.h:28
int ipc_create_socket(const char *filename)
Creates the UNIX domain socket at the given path, sets it to non-blocking mode, bind()s and listen()s...
Definition: ipc.c:1488
shutdown_reason_t
Calls to ipc_shutdown() should provide a reason for the shutdown.
Definition: ipc.h:91
Holds the status bar configuration (i3bar).
A &#39;Con&#39; represents everything from the X11 root window down to a single X11 window.
Definition: data.h:630
bool first_tick_sent
Definition: ipc.h:36
size_t buffer_size
Definition: ipc.h:41
void ipc_send_workspace_event(const char *change, Con *current, Con *old)
For the workspace events we send, along with the usual "change" field, also the workspace container i...
Definition: ipc.c:1571
char ** events
Definition: ipc.h:32
void ipc_set_kill_timeout(ev_tstamp new)
Set the maximum duration that we allow for a connection with an unwriteable socket.
Definition: ipc.c:86
void ipc_send_window_event(const char *property, Con *con)
For the window events we send, along the usual "change" field, also the window container, in "container".
Definition: ipc.c:1587
int num_events
Definition: ipc.h:31
char * current_socketpath
Definition: ipc.c:23