From: Michael Stapelberg Date: Sun, 30 May 2010 22:11:11 +0000 (+0200) Subject: cleanup: introduce CT_WORKSPACE as type to avoid having to check parent->type X-Git-Tag: tree-pr1~211 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e67c712f31a577958a1149272a4b7ffbed3ba94e;p=i3%2Fi3 cleanup: introduce CT_WORKSPACE as type to avoid having to check parent->type --- diff --git a/include/data.h b/include/data.h index bdfcbcc3..22884aa7 100644 --- a/include/data.h +++ b/include/data.h @@ -256,7 +256,7 @@ struct Match { struct Con { bool mapped; - enum { CT_ROOT = 0, CT_OUTPUT = 1, CT_CON = 2, CT_FLOATING_CON = 3 } type; + enum { CT_ROOT = 0, CT_OUTPUT = 1, CT_CON = 2, CT_FLOATING_CON = 3, CT_WORKSPACE = 4 } type; orientation_t orientation; struct Con *parent; /* parent before setting it to floating */ diff --git a/src/con.c b/src/con.c index 36070849..efd0a82a 100644 --- a/src/con.c +++ b/src/con.c @@ -107,7 +107,7 @@ bool con_is_leaf(Con *con) { */ bool con_accepts_window(Con *con) { /* 1: workspaces never accept direct windows */ - if (con->parent->type == CT_OUTPUT) + if (con->type == CT_WORKSPACE) return false; /* TODO: if this is a swallowing container, we need to check its max_clients */ @@ -135,7 +135,7 @@ Con *con_get_output(Con *con) { */ Con *con_get_workspace(Con *con) { Con *result = con; - while (result != NULL && result->parent->type != CT_OUTPUT) + while (result != NULL && result->type != CT_WORKSPACE) result = result->parent; assert(result != NULL); return result; diff --git a/src/tree.c b/src/tree.c index d8fc9f4a..5a3a7613 100644 --- a/src/tree.c +++ b/src/tree.c @@ -71,6 +71,7 @@ void tree_init() { /* add a workspace to this output */ ws = con_new(oc); + ws->type = CT_WORKSPACE; ws->name = strdup("1"); ws->fullscreen_mode = CF_OUTPUT; } @@ -160,7 +161,7 @@ void tree_close(Con *con, bool kill_window) { void tree_close_con() { assert(focused != NULL); - if (focused->parent->type == CT_OUTPUT) { + if (focused->type == CT_WORKSPACE) { LOG("Cannot close workspace\n"); return; } @@ -176,7 +177,7 @@ void tree_close_con() { */ void tree_split(Con *con, orientation_t orientation) { /* for a workspace, we just need to change orientation */ - if (con->parent->type == CT_OUTPUT) { + if (con->type == CT_WORKSPACE) { con->orientation = orientation; return; } @@ -194,7 +195,8 @@ void tree_split(Con *con, orientation_t orientation) { void level_up() { /* We can focus up to the workspace, but not any higher in the tree */ - if (focused->parent->type != CT_CON) { + if (focused->parent->type != CT_CON && + focused->parent->type != CT_WORKSPACE) { printf("cannot go up\n"); return; } @@ -246,7 +248,7 @@ void tree_next(char way, orientation_t orientation) { LOG("need to go one level further up\n"); /* if the current parent is an output, we are at a workspace * and the orientation still does not match */ - if (parent->parent->type == CT_OUTPUT) + if (parent->type == CT_WORKSPACE) return; parent = parent->parent; } @@ -279,14 +281,14 @@ void tree_next(char way, orientation_t orientation) { void tree_move(char way, orientation_t orientation) { /* 1: get the first parent with the same orientation */ Con *parent = focused->parent; - if (parent->type == CT_OUTPUT) + if (focused->type == CT_WORKSPACE) return; bool level_changed = false; while (parent->orientation != orientation) { LOG("need to go one level further up\n"); /* if the current parent is an output, we are at a workspace * and the orientation still does not match */ - if (parent->parent->type == CT_OUTPUT) + if (parent->type == CT_WORKSPACE) return; parent = parent->parent; level_changed = true; diff --git a/src/workspace.c b/src/workspace.c index 6404cff0..457603ee 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -39,6 +39,7 @@ Con *workspace_get(const char *num) { output = con_get_output(focused); LOG("got output %p\n", output); workspace = con_new(output); + workspace->type = CT_WORKSPACE; workspace->name = strdup(num); ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}");