i3
Macros | Functions | Variables
ipc.c File Reference
#include "all.h"
#include "yajl_utils.h"
#include <stdint.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>
#include <libgen.h>
#include <ev.h>
#include <yajl/yajl_gen.h>
#include <yajl/yajl_parse.h>
Include dependency graph for ipc.c:

Go to the source code of this file.

Macros

#define DUMP_PROPERTY(key, prop_name)
 
#define DUMP_REGEX(re_name)
 
#define YSTR_IF_SET(name)
 
#define YSTR_IF_SET(name)
 

Functions

static void set_nonblock (int sockfd)
 
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 kind of event. More...
 
static void ipc_send_shutdown_event (shutdown_reason_t reason)
 
void ipc_shutdown (shutdown_reason_t reason)
 Calls shutdown() on each socket and closes it. More...
 
 IPC_HANDLER (run_command)
 
static void dump_rect (yajl_gen gen, const char *name, Rect r)
 
static void dump_event_state_mask (yajl_gen gen, Binding *bind)
 
static void dump_binding (yajl_gen gen, Binding *bind)
 
void dump_node (yajl_gen gen, struct Con *con, bool inplace_restart)
 
static void dump_bar_bindings (yajl_gen gen, Barconfig *config)
 
static char * canonicalize_output_name (char *name)
 
static void dump_bar_config (yajl_gen gen, Barconfig *config)
 
 IPC_HANDLER (tree)
 
 IPC_HANDLER (get_workspaces)
 
 IPC_HANDLER (get_outputs)
 
 IPC_HANDLER (get_marks)
 
 IPC_HANDLER (get_version)
 
 IPC_HANDLER (get_bar_config)
 
 IPC_HANDLER (get_binding_modes)
 
static int add_subscription (void *extra, const unsigned char *s, ylength len)
 
 IPC_HANDLER (subscribe)
 
 IPC_HANDLER (get_config)
 
static void ipc_receive_message (EV_P_ struct ev_io *w, int revents)
 
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 should accept() him. More...
 
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 on it. More...
 
yajl_gen ipc_marshal_workspace_event (const char *change, Con *current, Con *old)
 Generates a json workspace event. More...
 
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 in "current". More...
 
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". More...
 
void ipc_send_barconfig_update_event (Barconfig *barconfig)
 For the barconfig update events, we send the serialized barconfig. More...
 
void ipc_send_binding_event (const char *event_type, Binding *bind)
 For the binding events, we send the serialized binding struct. More...
 

Variables

char * current_socketpath = NULL
 
 all_clients = TAILQ_HEAD_INITIALIZER(all_clients)
 
handler_t handlers [10]
 

Macro Definition Documentation

◆ DUMP_PROPERTY

#define DUMP_PROPERTY (   key,
  prop_name 
)
Value:
do { \
if (con->window->prop_name != NULL) { \
ystr(key); \
ystr(con->window->prop_name); \
} \
} while (0)

Referenced by dump_node().

◆ DUMP_REGEX

#define DUMP_REGEX (   re_name)
Value:
do { \
if (match->re_name != NULL) { \
ystr(#re_name); \
ystr(match->re_name->pattern); \
} \
} while (0)

Referenced by dump_node().

◆ YSTR_IF_SET [1/2]

#define YSTR_IF_SET (   name)
Value:
do { \
if (config->name) { \
ystr(#name); \
ystr(config->name); \
} \
} while (0)
Config config
Definition: config.c:17

Referenced by dump_bar_config().

◆ YSTR_IF_SET [2/2]

#define YSTR_IF_SET (   name)
Value:
do { \
if (config->colors.name) { \
ystr(#name); \
ystr(config->colors.name); \
} \
} while (0)
Config config
Definition: config.c:17

Function Documentation

◆ add_subscription()

static int add_subscription ( void *  extra,
const unsigned char *  s,
ylength  len 
)
static

Definition at line 1034 of file ipc.c.

References DLOG, ipc_client::events, ipc_client::num_events, scalloc(), and srealloc().

Referenced by IPC_HANDLER().

Here is the call graph for this function:

◆ canonicalize_output_name()

static char* canonicalize_output_name ( char *  name)
static

Definition at line 582 of file ipc.c.

References get_output_by_name(), and output_primary_name().

Referenced by dump_bar_config().

Here is the call graph for this function:

◆ dump_bar_bindings()

static void dump_bar_bindings ( yajl_gen  gen,
Barconfig config 
)
static

◆ dump_bar_config()

static void dump_bar_config ( yajl_gen  gen,
Barconfig config 
)
static

◆ dump_binding()

static void dump_binding ( yajl_gen  gen,
Binding bind 
)
static

Definition at line 218 of file ipc.c.

References B_KEYBOARD, Binding::command, dump_event_state_mask(), Binding::input_type, Binding::keycode, Binding::symbol, y, and ystr.

Referenced by ipc_send_binding_event().

Here is the call graph for this function:

◆ dump_event_state_mask()

static void dump_event_state_mask ( yajl_gen  gen,
Binding bind 
)
static

◆ dump_node()

void dump_node ( yajl_gen  gen,
struct Con con,
bool  inplace_restart 
)

◆ dump_rect()

static void dump_rect ( yajl_gen  gen,
const char *  name,
Rect  r 
)
static

Definition at line 142 of file ipc.c.

References Rect::height, Rect::width, Rect::x, y, Rect::y, and ystr.

Referenced by dump_node().

◆ ipc_create_socket()

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 on it.

Definition at line 1243 of file ipc.c.

References current_socketpath, DEFAULT_DIR_MODE, DLOG, FREE, mkdirp(), path_exists(), resolve_tilde(), set_nonblock(), and sstrdup().

Referenced by main().

Here is the call graph for this function:

◆ IPC_HANDLER() [1/10]

IPC_HANDLER ( run_command  )

Definition at line 116 of file ipc.c.

References command_result_free(), ipc_send_message(), LOG, CommandResult::needs_tree_render, parse_command(), scalloc(), and tree_render().

Here is the call graph for this function:

◆ IPC_HANDLER() [2/10]

IPC_HANDLER ( tree  )

Definition at line 754 of file ipc.c.

References croot, dump_node(), ipc_send_message(), y, and ygenalloc.

Here is the call graph for this function:

◆ IPC_HANDLER() [3/10]

IPC_HANDLER ( get_workspaces  )

◆ IPC_HANDLER() [4/10]

IPC_HANDLER ( get_outputs  )

◆ IPC_HANDLER() [5/10]

IPC_HANDLER ( get_marks  )

Definition at line 891 of file ipc.c.

References all_cons, ipc_send_message(), marks, Con::marks_head, mark_t::name, TAILQ_FOREACH, y, ygenalloc, and ystr.

Here is the call graph for this function:

◆ IPC_HANDLER() [6/10]

IPC_HANDLER ( get_version  )

Definition at line 917 of file ipc.c.

References current_configpath, i3_version, ipc_send_message(), y, ygenalloc, and ystr.

Here is the call graph for this function:

◆ IPC_HANDLER() [7/10]

IPC_HANDLER ( get_bar_config  )

Definition at line 951 of file ipc.c.

References barconfigs, config, dump_bar_config(), Barconfig::id, ipc_send_message(), LOG, sasprintf(), TAILQ_FOREACH, y, ygenalloc, and ystr.

Here is the call graph for this function:

◆ IPC_HANDLER() [8/10]

IPC_HANDLER ( get_binding_modes  )

Definition at line 1012 of file ipc.c.

References ipc_send_message(), modes, Mode::name, SLIST_FOREACH, y, ygenalloc, and ystr.

Here is the call graph for this function:

◆ IPC_HANDLER() [9/10]

IPC_HANDLER ( subscribe  )

Definition at line 1061 of file ipc.c.

References add_subscription(), all_clients, ELOG, ipc_client::fd, ipc_send_message(), TAILQ_FOREACH, and yalloc.

Here is the call graph for this function:

◆ IPC_HANDLER() [10/10]

IPC_HANDLER ( get_config  )

Definition at line 1107 of file ipc.c.

References current_config, ipc_send_message(), y, ygenalloc, and ystr.

Here is the call graph for this function:

◆ ipc_marshal_workspace_event()

yajl_gen ipc_marshal_workspace_event ( const char *  change,
Con current,
Con old 
)

Generates a json workspace event.

Returns a dynamically allocated yajl generator. Free with yajl_gen_free().

Definition at line 1293 of file ipc.c.

References dump_node(), y, ygenalloc, and ystr.

Referenced by _workspace_show(), con_on_remove_child(), and ipc_send_workspace_event().

Here is the call graph for this function:

◆ ipc_new_client()

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 should accept() him.

Sets up the event handler for activity on the new connection and inserts the file descriptor into the list of clients.

Definition at line 1209 of file ipc.c.

References all_clients, DLOG, ipc_receive_message(), scalloc(), set_nonblock(), and TAILQ_INSERT_TAIL.

Referenced by main().

Here is the call graph for this function:

◆ ipc_receive_message()

static void ipc_receive_message ( EV_P_ struct ev_io *  w,
int  revents 
)
static

Definition at line 1150 of file ipc.c.

References all_clients, DLOG, ipc_client::events, ipc_client::fd, FREE, handlers, ipc_recv_message(), ipc_client::num_events, TAILQ_FOREACH, and TAILQ_REMOVE.

Referenced by ipc_new_client().

Here is the call graph for this function:

◆ ipc_send_barconfig_update_event()

void ipc_send_barconfig_update_event ( Barconfig barconfig)

For the barconfig update events, we send the serialized barconfig.

Definition at line 1371 of file ipc.c.

References DLOG, dump_bar_config(), Barconfig::id, ipc_send_event(), y, and ygenalloc.

Referenced by update_barconfig().

Here is the call graph for this function:

◆ ipc_send_binding_event()

void ipc_send_binding_event ( const char *  event_type,
Binding bind 
)

For the binding events, we send the serialized binding struct.

Definition at line 1390 of file ipc.c.

References DLOG, dump_binding(), ipc_send_event(), Binding::keycode, Binding::symbol, y, ygenalloc, and ystr.

Referenced by run_binding().

Here is the call graph for this function:

◆ ipc_send_event()

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 kind of event.

Definition at line 46 of file ipc.c.

References all_clients, ipc_client::events, ipc_client::fd, ipc_send_message(), ipc_client::num_events, and TAILQ_FOREACH.

Referenced by _workspace_show(), con_on_remove_child(), handle_screen_change(), ipc_send_barconfig_update_event(), ipc_send_binding_event(), ipc_send_shutdown_event(), ipc_send_window_event(), ipc_send_workspace_event(), and switch_mode().

Here is the call graph for this function:

◆ ipc_send_shutdown_event()

static void ipc_send_shutdown_event ( shutdown_reason_t  reason)
static

Definition at line 67 of file ipc.c.

References ipc_send_event(), SHUTDOWN_REASON_EXIT, SHUTDOWN_REASON_RESTART, y, ygenalloc, and ystr.

Referenced by ipc_shutdown().

Here is the call graph for this function:

◆ ipc_send_window_event()

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 at line 1342 of file ipc.c.

References DLOG, dump_node(), Window::id, ipc_send_event(), Con::window, y, ygenalloc, and ystr.

Referenced by _con_move_to_con(), con_focus(), con_mark(), con_set_fullscreen_mode(), con_set_urgency(), con_unmark(), floating_disable(), floating_enable(), handle_windowname_change(), handle_windowname_change_legacy(), manage_window(), tree_close_internal(), tree_move(), workspace_defer_update_urgent_hint_cb(), and x_push_changes().

Here is the call graph for this function:

◆ ipc_send_workspace_event()

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 in "current".

For focus events, we send the previously focused workspace in "old".

Definition at line 1326 of file ipc.c.

References ipc_marshal_workspace_event(), ipc_send_event(), and y.

Referenced by _workspace_show(), cmd_append_layout(), cmd_reload(), cmd_rename_workspace(), move_to_output_directed(), workspace_get(), workspace_move_to_output(), and workspace_update_urgent_flag().

Here is the call graph for this function:

◆ ipc_shutdown()

void ipc_shutdown ( shutdown_reason_t  reason)

Calls shutdown() on each socket and closes it.

Definition at line 95 of file ipc.c.

References all_clients, ipc_client::events, ipc_client::fd, ipc_send_shutdown_event(), ipc_client::num_events, TAILQ_EMPTY, TAILQ_FIRST, and TAILQ_REMOVE.

Referenced by cmd_exit(), cmd_restart(), and i3_restart().

Here is the call graph for this function:

◆ set_nonblock()

static void set_nonblock ( int  sockfd)
static

Definition at line 34 of file ipc.c.

Referenced by ipc_create_socket(), and ipc_new_client().

Variable Documentation

◆ all_clients

all_clients = TAILQ_HEAD_INITIALIZER(all_clients)

Definition at line 26 of file ipc.c.

Referenced by IPC_HANDLER(), ipc_new_client(), ipc_receive_message(), ipc_send_event(), and ipc_shutdown().

◆ current_socketpath

char* current_socketpath = NULL

Definition at line 23 of file ipc.c.

Referenced by ipc_create_socket(), main(), and x_set_i3_atoms().

◆ handlers

handler_t handlers[10]
Initial value:
= {
handle_run_command,
handle_get_workspaces,
handle_subscribe,
handle_get_outputs,
handle_tree,
handle_get_marks,
handle_get_bar_config,
handle_get_version,
handle_get_binding_modes,
handle_get_config,
}

Definition at line 1127 of file ipc.c.

Referenced by ipc_receive_message().