i3
ipc.h
Go to the documentation of this file.
1/*
2 * vim:ts=4:sw=4:expandtab
3 *
4 * i3 - an improved 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 <libev/ev.h>
15#include <yajl/yajl_gen.h>
16#include <yajl/yajl_parse.h>
17
18#include "data.h"
19#include "tree.h"
20#include "configuration.h"
21
22#include "i3/ipc.h"
23
24extern char *current_socketpath;
25
26typedef struct ipc_client {
27 int fd;
28
29 /* The events which this client wants to receive */
31 char **events;
32
33 /* For clients which subscribe to the tick event: whether the first tick
34 * event has been sent by i3. */
36
37 struct ev_io *read_callback;
38 struct ev_io *write_callback;
39 struct ev_timer *timeout;
40 uint8_t *buffer;
42
45
46/*
47 * Callback type for the different message types.
48 *
49 * message is the raw packet, as received from the UNIX domain socket. size
50 * is the remaining size of bytes for this packet.
51 *
52 * message_size is the size of the message as the sender specified it.
53 * message_type is the type of the message as the sender specified it.
54 *
55 */
56typedef void (*handler_t)(ipc_client *, uint8_t *, int, uint32_t, uint32_t);
57
58/* Macro to declare a callback */
59#define IPC_HANDLER(name) \
60 static void handle_##name(ipc_client *client, uint8_t *message, \
61 int size, uint32_t message_size, \
62 uint32_t message_type)
63
71void ipc_new_client(EV_P_ struct ev_io *w, int revents);
72
81ipc_client *ipc_new_client_on_fd(EV_P_ int fd);
82
88void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
89
97
105void ipc_shutdown(shutdown_reason_t reason, int exempt_fd);
106
107void dump_node(yajl_gen gen, Con *con, bool inplace_restart);
108
113yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old);
114
120void ipc_send_workspace_event(const char *change, Con *current, Con *old);
121
126void ipc_send_window_event(const char *property, Con *con);
127
132
136void ipc_send_binding_event(const char *event_type, Binding *bind, const char *modename);
137
142void ipc_set_kill_timeout(ev_tstamp new);
143
147void ipc_confirm_restart(ipc_client *client);
void ipc_set_kill_timeout(ev_tstamp new)
Set the maximum duration that we allow for a connection with an unwriteable socket.
void(* handler_t)(ipc_client *, uint8_t *, int, uint32_t, uint32_t)
Definition ipc.h:56
void dump_node(yajl_gen gen, Con *con, bool inplace_restart)
Definition ipc.c:362
void ipc_confirm_restart(ipc_client *client)
Sends a restart reply to the IPC client on the specified fd.
Definition ipc.c:1735
ipc_client * ipc_new_client_on_fd(EV_P_ int fd)
ipc_new_client_on_fd() only sets up the event handler for activity on the new connection and inserts ...
Definition ipc.c:1575
char * current_socketpath
Definition ipc.c:26
void ipc_send_binding_event(const char *event_type, Binding *bind, const char *modename)
For the binding events, we send the serialized binding struct.
Definition ipc.c:1698
shutdown_reason_t
Calls to ipc_shutdown() should provide a reason for the shutdown.
Definition ipc.h:93
@ SHUTDOWN_REASON_RESTART
Definition ipc.h:94
@ SHUTDOWN_REASON_EXIT
Definition ipc.h:95
void ipc_shutdown(shutdown_reason_t reason, int exempt_fd)
Calls shutdown() on each socket and closes it.
Definition ipc.c:192
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:1634
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:1550
void ipc_send_barconfig_update_event(Barconfig *barconfig)
For the barconfig update events, we send the serialized barconfig.
Definition ipc.c:1679
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:147
yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old)
Generates a json workspace event.
Definition ipc.c:1599
struct ipc_client ipc_client
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,...
Definition ipc.c:1650
Holds the status bar configuration (i3bar).
Holds a keybinding, consisting of a keycode combined with modifiers and the command which is executed...
Definition data.h:306
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition data.h:643
bool first_tick_sent
Definition ipc.h:35
char ** events
Definition ipc.h:31
int num_events
Definition ipc.h:30
size_t buffer_size
Definition ipc.h:41
TAILQ_ENTRY(ipc_client) clients
struct ev_io * read_callback
Definition ipc.h:37
struct ev_timer * timeout
Definition ipc.h:39
int fd
Definition ipc.h:27
uint8_t * buffer
Definition ipc.h:40
struct ev_io * write_callback
Definition ipc.h:38