i3
Macros | Functions | Variables
ipc.c File Reference
#include "all.h"
#include "yajl_utils.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 I3__FILE__   "ipc.c"
 
#define DUMP_PROPERTY(key, prop_name)
 
#define DUMP_REGEX(re_name)
 
#define YSTR_IF_SET(name)
 
#define YSTR_IF_SET(name)
 

Functions

 TAILQ_HEAD (ipc_client_head, ipc_client)
 
static bool mkdirp (const char *path)
 
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...
 
void ipc_shutdown (void)
 Calls shutdown() on each socket and closes it. More...
 
 IPC_HANDLER (command)
 
static void dump_rect (yajl_gen gen, const char *name, Rect r)
 
void dump_node (yajl_gen gen, struct Con *con, bool inplace_restart)
 
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)
 
static int add_subscription (void *extra, const unsigned char *s, ylength len)
 
 IPC_HANDLER (subscribe)
 
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...
 
void ipc_send_workspace_focus_event (Con *current, Con *old)
 For the workspace "focus" event we send, along the usual "change" field, also the current and previous workspace, in "current" and "old" respectively. 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...
 

Variables

char * current_socketpath = NULL
 
handler_t handlers [8]
 

Macro Definition Documentation

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

Referenced by dump_node().

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

Referenced by dump_node().

#define I3__FILE__   "ipc.c"

Definition at line 2 of file ipc.c.

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

Referenced by dump_bar_config().

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

Function Documentation

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

Definition at line 822 of file ipc.c.

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

Referenced by IPC_HANDLER().

Here is the call graph for this function:

static void dump_bar_config ( yajl_gen  gen,
Barconfig config 
)
static
void dump_node ( yajl_gen  gen,
struct Con con,
bool  inplace_restart 
)
static void dump_rect ( yajl_gen  gen,
const char *  name,
Rect  r 
)
static

Definition at line 140 of file ipc.c.

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

Referenced by dump_node().

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 1007 of file ipc.c.

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

Referenced by main().

Here is the call graph for this function:

IPC_HANDLER ( command  )

Definition at line 114 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 ( tree  )

Definition at line 568 of file ipc.c.

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

Here is the call graph for this function:

IPC_HANDLER ( get_workspaces  )
IPC_HANDLER ( get_outputs  )
IPC_HANDLER ( get_marks  )

Definition at line 708 of file ipc.c.

References all_cons, ipc_send_message(), Con::mark, TAILQ_FOREACH, y, ygenalloc, and ystr.

Here is the call graph for this function:

IPC_HANDLER ( get_version  )

Definition at line 731 of file ipc.c.

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

Here is the call graph for this function:

IPC_HANDLER ( get_bar_config  )

Definition at line 762 of file ipc.c.

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

Here is the call graph for this function:

IPC_HANDLER ( subscribe  )

Definition at line 849 of file ipc.c.

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

Here is the call graph for this function:

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 973 of file ipc.c.

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

Referenced by main().

Here is the call graph for this function:

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

Definition at line 915 of file ipc.c.

References 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:

void ipc_send_barconfig_update_event ( Barconfig barconfig)

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

Definition at line 1120 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:

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 75 of file ipc.c.

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

Referenced by _workspace_show(), cmd_move_workspace_to_output(), cmd_reload(), cmd_rename_workspace(), con_on_remove_child(), handle_screen_change(), ipc_send_barconfig_update_event(), ipc_send_window_event(), ipc_send_workspace_focus_event(), switch_mode(), workspace_get(), and workspace_update_urgent_flag().

Here is the call graph for this function:

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 1091 of file ipc.c.

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

Referenced by con_toggle_fullscreen(), handle_windowname_change(), handle_windowname_change_legacy(), manage_window(), and x_push_changes().

Here is the call graph for this function:

void ipc_send_workspace_focus_event ( Con current,
Con old 
)

For the workspace "focus" event we send, along the usual "change" field, also the current and previous workspace, in "current" and "old" respectively.

Definition at line 1058 of file ipc.c.

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

Referenced by _workspace_show(), and move_to_output_directed().

Here is the call graph for this function:

void ipc_shutdown ( void  )

Calls shutdown() on each socket and closes it.

This function to be called when exiting or restarting only!

Definition at line 98 of file ipc.c.

References ipc_client::fd, TAILQ_EMPTY, TAILQ_FIRST, and TAILQ_REMOVE.

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

static bool mkdirp ( const char *  path)
static

Definition at line 44 of file ipc.c.

References ELOG, FREE, and sstrdup().

Referenced by ipc_create_socket().

Here is the call graph for this function:

TAILQ_HEAD ( ipc_client_head  ,
ipc_client   
)

Definition at line 25 of file ipc.c.

Variable Documentation

char* current_socketpath = NULL

Definition at line 23 of file ipc.c.

Referenced by ipc_create_socket(), and x_set_i3_atoms().

handler_t handlers[8]
Initial value:
= {
handle_command,
handle_get_workspaces,
handle_subscribe,
handle_get_outputs,
handle_tree,
handle_get_marks,
handle_get_bar_config,
handle_get_version,
}

Definition at line 894 of file ipc.c.

Referenced by ipc_receive_message().