-#undef I3__FILE__
-#define I3__FILE__ "ipc.c"
/*
* vim:ts=4:sw=4:expandtab
*
*
*/
#include "all.h"
+
#include "yajl_utils.h"
#include <stdint.h>
char *current_socketpath = NULL;
-TAILQ_HEAD(ipc_client_head, ipc_client) all_clients = TAILQ_HEAD_INITIALIZER(all_clients);
+TAILQ_HEAD(ipc_client_head, ipc_client)
+all_clients = TAILQ_HEAD_INITIALIZER(all_clients);
/*
* Puts the given socket file descriptor into non-blocking mode or dies if
}
/*
- * Calls shutdown() on each socket and closes it. This function to be called
+ * For shutdown events, we send the reason for the shutdown.
+ */
+static void ipc_send_shutdown_event(shutdown_reason_t reason) {
+ yajl_gen gen = ygenalloc();
+ y(map_open);
+
+ ystr("change");
+
+ if (reason == SHUTDOWN_REASON_RESTART) {
+ ystr("restart");
+ } else if (reason == SHUTDOWN_REASON_EXIT) {
+ ystr("exit");
+ }
+
+ y(map_close);
+
+ const unsigned char *payload;
+ ylength length;
+
+ y(get_buf, &payload, &length);
+ ipc_send_event("shutdown", I3_IPC_EVENT_SHUTDOWN, (const char *)payload);
+
+ y(free);
+}
+
+/*
+ * Calls shutdown() on each socket and closes it. This function is to be called
* when exiting or restarting only!
*
*/
-void ipc_shutdown(void) {
+void ipc_shutdown(shutdown_reason_t reason) {
+ ipc_send_shutdown_event(reason);
+
ipc_client *current;
while (!TAILQ_EMPTY(&all_clients)) {
current = TAILQ_FIRST(&all_clients);
ystr("focused");
y(bool, (con == focused));
+ if (con->type != CT_ROOT && con->type != CT_OUTPUT) {
+ ystr("output");
+ ystr(con_get_output(con)->name);
+ }
+
ystr("layout");
switch (con->layout) {
case L_DEFAULT:
if (match->restart_mode)
continue;
y(map_open);
- if (match->dock != -1) {
+ if (match->dock != M_DONTCHECK) {
ystr("dock");
y(integer, match->dock);
ystr("insert_where");
y(free);
}
+/*
+ * Returns a list of configured binding modes
+ *
+ */
+IPC_HANDLER(get_binding_modes) {
+ yajl_gen gen = ygenalloc();
+
+ y(array_open);
+ struct Mode *mode;
+ SLIST_FOREACH(mode, &modes, modes) {
+ ystr(mode->name);
+ }
+ y(array_close);
+
+ const unsigned char *payload;
+ ylength length;
+ y(get_buf, &payload, &length);
+
+ ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_BINDING_MODES, payload);
+ y(free);
+}
+
/*
* Callback for the YAJL parser (will be called when a string is parsed).
*
ipc_send_message(fd, strlen(reply), I3_IPC_REPLY_TYPE_SUBSCRIBE, (const uint8_t *)reply);
}
+/*
+ * Returns the raw last loaded i3 configuration file contents.
+ */
+IPC_HANDLER(get_config) {
+ yajl_gen gen = ygenalloc();
+
+ y(map_open);
+
+ ystr("config");
+ ystr(current_config);
+
+ y(map_close);
+
+ const unsigned char *payload;
+ ylength length;
+ y(get_buf, &payload, &length);
+
+ ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_CONFIG, payload);
+ y(free);
+}
+
/* The index of each callback function corresponds to the numeric
* value of the message type (see include/i3/ipc.h) */
-handler_t handlers[8] = {
+handler_t handlers[10] = {
handle_command,
handle_get_workspaces,
handle_subscribe,
handle_get_marks,
handle_get_bar_config,
handle_get_version,
+ handle_get_binding_modes,
+ handle_get_config,
};
/*