missing ipc stuff: rebase to typesafety

master
Armin Preiml 6 years ago
parent 030b5bc024
commit 3d8c3e560b

@ -30,6 +30,20 @@ static const char *ipc_json_layout_description(enum sway_container_layout l) {
return "none";
}
static const char *ipc_json_orientation_description(enum sway_container_layout l) {
switch (l) {
case L_VERT:
return "vertical";
case L_HORIZ:
return "horizontal";
case L_TABBED:
case L_STACKED:
case L_NONE:
break;
}
return "none";
}
json_object *ipc_json_get_version() {
int major = 0, minor = 0, patch = 0;
json_object *version = json_object_new_object();
@ -57,9 +71,17 @@ static json_object *ipc_json_create_rect(struct wlr_box *box) {
return rect;
}
static json_object *ipc_json_create_empty_rect(void) {
struct wlr_box empty = {0, 0, 0, 0};
return ipc_json_create_rect(&empty);
}
static void ipc_json_describe_root(struct sway_root *root, json_object *object) {
json_object_object_add(object, "type", json_object_new_string("root"));
json_object_object_add(object, "layout", json_object_new_string("splith"));
json_object_object_add(object, "orientation",
json_object_new_string(ipc_json_orientation_description(L_HORIZ)));
}
static const char *ipc_json_get_output_transform(enum wl_output_transform transform) {
@ -124,6 +146,22 @@ static void ipc_json_describe_output(struct sway_output *output,
json_object_object_add(object, "modes", modes_array);
json_object_object_add(object, "layout", json_object_new_string("output"));
struct sway_node *parent = node_get_parent(&output->node);
struct wlr_box parent_box = {0, 0, 0, 0};
if (parent != NULL) {
node_get_box(parent, &parent_box);
}
if (parent_box.width == 0 || parent_box.height == 0) {
json_object_object_add(object, "percent", NULL);
}
else {
double percent = (output->width / parent_box.width)
* (output->height / parent_box.height);
json_object_object_add(object, "percent", json_object_new_double(percent));
}
}
json_object *ipc_json_describe_disabled_output(struct sway_output *output) {
@ -143,6 +181,8 @@ json_object *ipc_json_describe_disabled_output(struct sway_output *output) {
json_object_new_string(wlr_output->serial));
json_object_object_add(object, "modes", json_object_new_array());
json_object_object_add(object, "percent", NULL);
return object;
}
@ -162,6 +202,9 @@ static void ipc_json_describe_workspace(struct sway_workspace *workspace,
const char *layout = ipc_json_layout_description(workspace->layout);
json_object_object_add(object, "layout", json_object_new_string(layout));
const char *orientation = ipc_json_orientation_description(workspace->layout);
json_object_object_add(object, "orientation", json_object_new_string(orientation));
// Floating
json_object *floating_array = json_object_new_array();
for (int i = 0; i < workspace->floating->length; ++i) {
@ -172,35 +215,96 @@ static void ipc_json_describe_workspace(struct sway_workspace *workspace,
json_object_object_add(object, "floating_nodes", floating_array);
}
static const char *describe_container_border(enum sway_container_border border) {
switch (border) {
case B_NONE:
return "none";
case B_PIXEL:
return "pixel";
case B_NORMAL:
return "normal";
}
return "unknown";
}
static void ipc_json_describe_view(struct sway_container *c, json_object *object) {
json_object_object_add(object, "name",
c->title ? json_object_new_string(c->title) : NULL);
json_object_object_add(object, "type", json_object_new_string("con"));
const char *app_id = view_get_app_id(c->view);
json_object_object_add(object, "app_id",
app_id ? json_object_new_string(app_id) : NULL);
const char *class = view_get_class(c->view);
json_object_object_add(object, "class",
class ? json_object_new_string(class) : NULL);
json_object *marks = json_object_new_array();
list_t *view_marks = c->view->marks;
for (int i = 0; i < view_marks->length; ++i) {
json_object_array_add(marks, json_object_new_string(view_marks->items[i]));
}
if (c->view) {
const char *app_id = view_get_app_id(c->view);
json_object_object_add(object, "app_id",
app_id ? json_object_new_string(app_id) : NULL);
json_object_object_add(object, "marks", marks);
const char *class = view_get_class(c->view);
json_object_object_add(object, "class",
class ? json_object_new_string(class) : NULL);
struct wlr_box window_box = {
c->view->x - c->x,
(c->current.border == B_PIXEL) ? c->current.border_thickness : 0,
c->view->width,
c->view->height
};
json_object_object_add(object, "window_rect", ipc_json_create_rect(&window_box));
struct wlr_box deco_box = {0, 0, 0, 0};
if (c->current.border == B_NORMAL) {
deco_box.width = c->width;
deco_box.height = c->view->y - c->y;
}
json_object_object_add(object, "deco_rect", ipc_json_create_rect(&deco_box));
}
static void ipc_json_describe_container(struct sway_container *c, json_object *object) {
json_object_object_add(object, "name",
c->title ? json_object_new_string(c->title) : NULL);
json_object_object_add(object, "type", json_object_new_string("con"));
json_object_object_add(object, "layout",
json_object_new_string(ipc_json_layout_description(c->layout)));
json_object_object_add(object, "orientation",
json_object_new_string(ipc_json_orientation_description(c->layout)));
bool urgent = c->view ?
view_is_urgent(c->view) : container_has_urgent_child(c);
json_object_object_add(object, "urgent", json_object_new_boolean(urgent));
struct sway_node *parent = node_get_parent(&c->node);
struct wlr_box parent_box = {0, 0, 0, 0};
if (parent != NULL) {
node_get_box(parent, &parent_box);
}
if (parent_box.width == 0 || parent_box.height == 0) {
json_object_object_add(object, "percent", NULL);
}
else {
double percent = (c->width / parent_box.width)
* (c->height / parent_box.height);
json_object_object_add(object, "percent", json_object_new_double(percent));
}
json_object_object_add(object, "window_rect", ipc_json_create_empty_rect());
json_object_object_add(object, "deco_rect", ipc_json_create_empty_rect());
json_object_object_add(object, "border",
json_object_new_string(describe_container_border(c->current.border)));
json_object_object_add(object, "current_border_width",
json_object_new_int(c->current.border_thickness));
json_object_object_add(object, "floating_nodes", json_object_new_array());
if (c->view) {
json_object *marks = json_object_new_array();
list_t *view_marks = c->view->marks;
for (int i = 0; i < view_marks->length; ++i) {
json_object_array_add(marks, json_object_new_string(view_marks->items[i]));
}
json_object_object_add(object, "marks", marks);
ipc_json_describe_view(c, object);
}
}

Loading…
Cancel
Save