From b467242d69cd9ac15ecd0c079b4662fc2d73afbd Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 1 Jun 2010 22:45:18 +0200 Subject: [PATCH] Make splitting a container which was already split a noop --- include/data.h | 2 +- src/tree.c | 11 ++++++++++- src/workspace.c | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/data.h b/include/data.h index 22884aa7..def5d4b7 100644 --- a/include/data.h +++ b/include/data.h @@ -41,7 +41,7 @@ typedef struct Window i3Window; * Helper types *****************************************************************************/ typedef enum { D_LEFT, D_RIGHT, D_UP, D_DOWN } direction_t; -typedef enum { HORIZ, VERT, NO_ORIENTATION } orientation_t; +typedef enum { NO_ORIENTATION = 0, HORIZ, VERT } orientation_t; enum { BIND_NONE = 0, diff --git a/src/tree.c b/src/tree.c index 7b31ea6b..c4315e31 100644 --- a/src/tree.c +++ b/src/tree.c @@ -74,6 +74,7 @@ void tree_init() { ws->type = CT_WORKSPACE; ws->name = strdup("1"); ws->fullscreen_mode = CF_OUTPUT; + ws->orientation = HORIZ; } con_focus(ws); @@ -203,9 +204,17 @@ void tree_split(Con *con, orientation_t orientation) { con->orientation = orientation; return; } + + Con *parent = con->parent; + /* if we are in a container whose parent contains only one + * child and has the same orientation like we are trying to + * set, this operation is a no-op to not confuse the user */ + if (parent->orientation == orientation && + TAILQ_NEXT(con, nodes) == TAILQ_END(&(parent->nodes_head))) + return; + /* 2: replace it with a new Con */ Con *new = con_new(NULL); - Con *parent = con->parent; TAILQ_REPLACE(&(parent->nodes_head), con, new, nodes); TAILQ_REPLACE(&(parent->focus_head), con, new, focused); new->parent = parent; diff --git a/src/workspace.c b/src/workspace.c index 457603ee..17986baf 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -41,6 +41,7 @@ Con *workspace_get(const char *num) { workspace = con_new(output); workspace->type = CT_WORKSPACE; workspace->name = strdup(num); + workspace->orientation = HORIZ; ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}"); }