cleanup: introduce CT_WORKSPACE as type to avoid having to check parent->type

This commit is contained in:
Michael Stapelberg 2010-05-31 00:11:11 +02:00
parent a45dc6b3ad
commit e67c712f31
4 changed files with 12 additions and 9 deletions

View File

@ -256,7 +256,7 @@ struct Match {
struct Con { struct Con {
bool mapped; 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; orientation_t orientation;
struct Con *parent; struct Con *parent;
/* parent before setting it to floating */ /* parent before setting it to floating */

View File

@ -107,7 +107,7 @@ bool con_is_leaf(Con *con) {
*/ */
bool con_accepts_window(Con *con) { bool con_accepts_window(Con *con) {
/* 1: workspaces never accept direct windows */ /* 1: workspaces never accept direct windows */
if (con->parent->type == CT_OUTPUT) if (con->type == CT_WORKSPACE)
return false; return false;
/* TODO: if this is a swallowing container, we need to check its max_clients */ /* 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 *con_get_workspace(Con *con) {
Con *result = con; Con *result = con;
while (result != NULL && result->parent->type != CT_OUTPUT) while (result != NULL && result->type != CT_WORKSPACE)
result = result->parent; result = result->parent;
assert(result != NULL); assert(result != NULL);
return result; return result;

View File

@ -71,6 +71,7 @@ void tree_init() {
/* add a workspace to this output */ /* add a workspace to this output */
ws = con_new(oc); ws = con_new(oc);
ws->type = CT_WORKSPACE;
ws->name = strdup("1"); ws->name = strdup("1");
ws->fullscreen_mode = CF_OUTPUT; ws->fullscreen_mode = CF_OUTPUT;
} }
@ -160,7 +161,7 @@ void tree_close(Con *con, bool kill_window) {
void tree_close_con() { void tree_close_con() {
assert(focused != NULL); assert(focused != NULL);
if (focused->parent->type == CT_OUTPUT) { if (focused->type == CT_WORKSPACE) {
LOG("Cannot close workspace\n"); LOG("Cannot close workspace\n");
return; return;
} }
@ -176,7 +177,7 @@ void tree_close_con() {
*/ */
void tree_split(Con *con, orientation_t orientation) { void tree_split(Con *con, orientation_t orientation) {
/* for a workspace, we just need to change orientation */ /* for a workspace, we just need to change orientation */
if (con->parent->type == CT_OUTPUT) { if (con->type == CT_WORKSPACE) {
con->orientation = orientation; con->orientation = orientation;
return; return;
} }
@ -194,7 +195,8 @@ void tree_split(Con *con, orientation_t orientation) {
void level_up() { void level_up() {
/* We can focus up to the workspace, but not any higher in the tree */ /* 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"); printf("cannot go up\n");
return; return;
} }
@ -246,7 +248,7 @@ void tree_next(char way, orientation_t orientation) {
LOG("need to go one level further up\n"); LOG("need to go one level further up\n");
/* if the current parent is an output, we are at a workspace /* if the current parent is an output, we are at a workspace
* and the orientation still does not match */ * and the orientation still does not match */
if (parent->parent->type == CT_OUTPUT) if (parent->type == CT_WORKSPACE)
return; return;
parent = parent->parent; parent = parent->parent;
} }
@ -279,14 +281,14 @@ void tree_next(char way, orientation_t orientation) {
void tree_move(char way, orientation_t orientation) { void tree_move(char way, orientation_t orientation) {
/* 1: get the first parent with the same orientation */ /* 1: get the first parent with the same orientation */
Con *parent = focused->parent; Con *parent = focused->parent;
if (parent->type == CT_OUTPUT) if (focused->type == CT_WORKSPACE)
return; return;
bool level_changed = false; bool level_changed = false;
while (parent->orientation != orientation) { while (parent->orientation != orientation) {
LOG("need to go one level further up\n"); LOG("need to go one level further up\n");
/* if the current parent is an output, we are at a workspace /* if the current parent is an output, we are at a workspace
* and the orientation still does not match */ * and the orientation still does not match */
if (parent->parent->type == CT_OUTPUT) if (parent->type == CT_WORKSPACE)
return; return;
parent = parent->parent; parent = parent->parent;
level_changed = true; level_changed = true;

View File

@ -39,6 +39,7 @@ Con *workspace_get(const char *num) {
output = con_get_output(focused); output = con_get_output(focused);
LOG("got output %p\n", output); LOG("got output %p\n", output);
workspace = con_new(output); workspace = con_new(output);
workspace->type = CT_WORKSPACE;
workspace->name = strdup(num); workspace->name = strdup(num);
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}"); ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}");