diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-14 16:59:38 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-14 16:59:38 -0400 |
commit | 5a8f464bc199f94a0a2ee848d249fe9d57b539c6 (patch) | |
tree | 91b25c94711e87e08b94bc8de30984bc403470ab /sway/commands.c | |
parent | 3a3c50135fabc6a23f7b130effef9b642e54bf3c (diff) | |
parent | 80ae2a7774457609cbcef0bd3dc6e1a651d9b5a2 (diff) |
Merge pull request #27 from taiyu-len/master
rewrote and grouped swayc related functions together.
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/sway/commands.c b/sway/commands.c index cae35237..5f378a98 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -228,33 +228,25 @@ static bool cmd_set(struct sway_config *config, int argc, char **argv) { } static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { - char *name = layout == L_VERT ? "splitv": - layout == L_HORIZ ? "splith":"split"; + char *name = layout == L_VERT ? "splitv" : + layout == L_HORIZ ? "splith" : "split"; if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) { return false; } swayc_t *focused = get_focused_container(&root_container); + + /* Case that focus is on an empty workspace. change its layout */ if (focused->type == C_WORKSPACE) { - sway_log(L_DEBUG, "Dont split workspaces"); - if (focused->children->length == 0) { - focused->layout = layout; - } + focused->layout = layout; + return true; + } + /* Case of no siblings. change parent layout */ + if (focused->parent->children->length == 1) { + focused->parent->layout = layout; return true; } - swayc_t *parent = focused->parent; - sway_log(L_DEBUG, "Splitting %p vertically with %p", parent, focused); - int index = remove_container_from_parent(parent, focused); - swayc_t *new_container = create_container(parent, -1); - new_container->layout = layout; - new_container->weight = focused->weight; - new_container->width = focused->width; - new_container->height = focused->height; - new_container->x = focused->x; - new_container->y = focused->y; - focused->weight = 1; - focused->parent = new_container; - list_insert(parent->children, index, new_container); - list_add(new_container->children, focused); + /* regular case where new split container is build around focused container */ + swayc_t *parent = new_container(focused, layout); focus_view(focused); arrange_windows(parent, -1, -1); return true; @@ -302,8 +294,7 @@ static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { swayc_t *workspace = workspace_find_by_name(argv[0]); if (!workspace) { workspace = workspace_create(argv[0]); - } else sway_log(L_DEBUG, "workspace exists, all ok"); - + } workspace_switch(workspace); return true; } |