Ported over some message types from -next.

This commit is contained in:
Fernando Tarlá Cardoso Lemos 2010-11-20 19:30:53 -02:00 committed by Michael Stapelberg
parent dab83ba413
commit 5d830e7a27
2 changed files with 100 additions and 80 deletions

View File

@ -27,7 +27,16 @@
#define I3_IPC_MESSAGE_TYPE_COMMAND 0 #define I3_IPC_MESSAGE_TYPE_COMMAND 0
/** Requests the current workspaces from i3 */ /** Requests the current workspaces from i3 */
#define I3_IPC_MESSAGE_TYPE_GET_TREE 1 #define I3_IPC_MESSAGE_TYPE_GET_WORKSPACES 1
/** Subscribe to the specified events */
#define I3_IPC_MESSAGE_TYPE_SUBSCRIBE 2
/** Requests the current outputs from i3 */
#define I3_IPC_MESSAGE_TYPE_GET_OUTPUTS 3
/** Requests the tree layout from i3 */
#define I3_IPC_MESSAGE_TYPE_GET_TREE 4
/* /*
@ -39,7 +48,17 @@
#define I3_IPC_REPLY_TYPE_COMMAND 0 #define I3_IPC_REPLY_TYPE_COMMAND 0
/** Workspaces reply type */ /** Workspaces reply type */
#define I3_IPC_REPLY_TYPE_TREE 1 #define I3_IPC_REPLY_TYPE_WORKSPACES 1
/** Subscription reply type */
#define I3_IPC_REPLY_TYPE_SUBSCRIBE 2
/** Outputs reply type */
#define I3_IPC_REPLY_TYPE_OUTPUTS 3
/** Tree reply type */
#define I3_IPC_REPLY_TYPE_TREE 4
/* /*
* Events from i3 to clients. Events have the first bit set high. * Events from i3 to clients. Events have the first bit set high.

View File

@ -239,7 +239,6 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
} }
IPC_HANDLER(tree) { IPC_HANDLER(tree) {
printf("tree\n");
yajl_gen gen = yajl_gen_alloc(NULL, NULL); yajl_gen gen = yajl_gen_alloc(NULL, NULL);
dump_node(gen, croot, false); dump_node(gen, croot, false);
@ -252,38 +251,35 @@ IPC_HANDLER(tree) {
} }
#if 0
/* /*
* Formats the reply message for a GET_WORKSPACES request and sends it to the * Formats the reply message for a GET_WORKSPACES request and sends it to the
* client * client
* *
*/ */
IPC_HANDLER(get_workspaces) { IPC_HANDLER(get_workspaces) {
Workspace *ws;
Client *last_focused = SLIST_FIRST(&(c_ws->focus_stack));
if (last_focused == SLIST_END(&(c_ws->focus_stack)))
last_focused = NULL;
yajl_gen gen = yajl_gen_alloc(NULL, NULL); yajl_gen gen = yajl_gen_alloc(NULL, NULL);
y(array_open); y(array_open);
TAILQ_FOREACH(ws, workspaces, workspaces) { Con *focused_ws = con_get_workspace(focused);
if (ws->output == NULL)
continue;
Con *output;
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
Con *ws;
TAILQ_FOREACH(ws, &(output->nodes_head), nodes) {
assert(ws->type == CT_WORKSPACE);
y(map_open); y(map_open);
ystr("num"); ystr("num");
y(integer, ws->num + 1); y(integer, con_num_children(ws));
ystr("name"); ystr("name");
ystr(ws->utf8_name); ystr(ws->name);
ystr("visible"); ystr("visible");
y(bool, ws->output->current_workspace == ws); y(bool, workspace_is_visible(ws));
ystr("focused"); ystr("focused");
y(bool, c_ws == ws); y(bool, ws == focused_ws);
ystr("rect"); ystr("rect");
y(map_open); y(map_open);
@ -298,13 +294,14 @@ IPC_HANDLER(get_workspaces) {
y(map_close); y(map_close);
ystr("output"); ystr("output");
ystr(ws->output->name); ystr(output->name);
ystr("urgent"); ystr("urgent");
y(bool, ws->urgent); y(bool, ws->urgent);
y(map_close); y(map_close);
} }
}
y(array_close); y(array_close);
@ -322,11 +319,10 @@ IPC_HANDLER(get_workspaces) {
* *
*/ */
IPC_HANDLER(get_outputs) { IPC_HANDLER(get_outputs) {
Output *output;
yajl_gen gen = yajl_gen_alloc(NULL, NULL); yajl_gen gen = yajl_gen_alloc(NULL, NULL);
y(array_open); y(array_open);
Output *output;
TAILQ_FOREACH(output, &outputs, outputs) { TAILQ_FOREACH(output, &outputs, outputs) {
y(map_open); y(map_open);
@ -348,10 +344,13 @@ IPC_HANDLER(get_outputs) {
y(integer, output->rect.height); y(integer, output->rect.height);
y(map_close); y(map_close);
/*
* XXX
* No idea how to handle this, where should we get this data from?
* I think we might need to keep a reference to the CT_OUTPUT Con in Output
*/
ystr("current_workspace"); ystr("current_workspace");
if (output->current_workspace == NULL)
y(null); y(null);
else y(integer, output->current_workspace->num + 1);
y(map_close); y(map_close);
} }
@ -441,12 +440,14 @@ IPC_HANDLER(subscribe) {
ipc_send_message(fd, (const unsigned char*)reply, ipc_send_message(fd, (const unsigned char*)reply,
I3_IPC_REPLY_TYPE_SUBSCRIBE, strlen(reply)); I3_IPC_REPLY_TYPE_SUBSCRIBE, strlen(reply));
} }
#endif
/* The index of each callback function corresponds to the numeric /* The index of each callback function corresponds to the numeric
* value of the message type (see include/i3/ipc.h) */ * value of the message type (see include/i3/ipc.h) */
handler_t handlers[2] = { handler_t handlers[5] = {
handle_command, handle_command,
handle_get_workspaces,
handle_subscribe,
handle_get_outputs,
handle_tree handle_tree
}; };