mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 09:51:29 +00:00
fixed split
This commit is contained in:
parent
f3a970e24e
commit
9bb2788768
|
@ -226,6 +226,7 @@ static bool cmd_set(struct sway_config *config, int argc, char **argv) {
|
||||||
list_add(config->symbols, var);
|
list_add(config->symbols, var);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
static void container_log(const swayc_t *c);
|
||||||
|
|
||||||
static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) {
|
static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) {
|
||||||
char *name = layout == L_VERT ? "splitv" :
|
char *name = layout == L_VERT ? "splitv" :
|
||||||
|
@ -235,20 +236,27 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay
|
||||||
}
|
}
|
||||||
swayc_t *focused = get_focused_container(&root_container);
|
swayc_t *focused = get_focused_container(&root_container);
|
||||||
|
|
||||||
/* Case that focus is on an empty workspace. change its layout */
|
container_log(focused);
|
||||||
if (focused->type == C_WORKSPACE) {
|
|
||||||
|
/* Case that focus is on an workspace with 0/1 children.change its layout */
|
||||||
|
if (focused->type == C_WORKSPACE && focused->children->length <= 1) {
|
||||||
|
sway_log(L_DEBUG, "changing workspace layout");
|
||||||
focused->layout = layout;
|
focused->layout = layout;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
/* Case of no siblings. change parent layout */
|
/* Case of no siblings. change parent layout */
|
||||||
if (focused->parent->children->length == 1) {
|
else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) {
|
||||||
|
sway_log(L_DEBUG, "changing container layout");
|
||||||
focused->parent->layout = layout;
|
focused->parent->layout = layout;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
/* regular case where new split container is build around focused container */
|
/* regular case where new split container is build around focused container
|
||||||
|
* or in case of workspace, container inherits its children */
|
||||||
|
else {
|
||||||
|
sway_log(L_DEBUG, "Adding new container around current focused container");
|
||||||
swayc_t *parent = new_container(focused, layout);
|
swayc_t *parent = new_container(focused, layout);
|
||||||
focus_view(focused);
|
focus_view(focused);
|
||||||
arrange_windows(parent, -1, -1);
|
arrange_windows(parent, -1, -1);
|
||||||
|
}
|
||||||
|
container_log(focused);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,9 @@ static void free_swayc(swayc_t *c) {
|
||||||
list_free(c->children);
|
list_free(c->children);
|
||||||
}
|
}
|
||||||
if (c->parent) {
|
if (c->parent) {
|
||||||
|
if (c->parent->focused == c) {
|
||||||
|
c->parent->focused = NULL;
|
||||||
|
}
|
||||||
remove_child(c->parent, c);
|
remove_child(c->parent, c);
|
||||||
}
|
}
|
||||||
free(c);
|
free(c);
|
||||||
|
@ -88,10 +91,29 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) {
|
||||||
cont->y = child->y;
|
cont->y = child->y;
|
||||||
cont->visible = child->visible;
|
cont->visible = child->visible;
|
||||||
|
|
||||||
|
/* Container inherits all of workspaces children, layout and whatnot */
|
||||||
|
if (child->type == C_WORKSPACE) {
|
||||||
|
swayc_t *workspace = child;
|
||||||
|
//reorder focus
|
||||||
|
cont->focused = workspace->focused;
|
||||||
|
workspace->focused = cont;
|
||||||
|
//Swap children
|
||||||
|
list_t *tmp_list = workspace->children;
|
||||||
|
workspace->children = cont->children;
|
||||||
|
cont->children = tmp_list;
|
||||||
|
//add container to workspace chidren
|
||||||
|
add_child(workspace, cont);
|
||||||
|
//give them proper layouts
|
||||||
|
cont->layout = workspace->layout;
|
||||||
|
workspace->layout = layout;
|
||||||
|
}
|
||||||
|
//Or is built around container
|
||||||
|
else {
|
||||||
swayc_t *parent = replace_child(child, cont);
|
swayc_t *parent = replace_child(child, cont);
|
||||||
if (parent) {
|
if (parent) {
|
||||||
add_child(cont, child);
|
add_child(cont, child);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return cont;
|
return cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,9 +174,6 @@ swayc_t *destroy_container(swayc_t *container) {
|
||||||
swayc_t *parent = container->parent;
|
swayc_t *parent = container->parent;
|
||||||
free_swayc(container);
|
free_swayc(container);
|
||||||
|
|
||||||
if (parent->focused == container) {
|
|
||||||
parent->focused = NULL;
|
|
||||||
}
|
|
||||||
container = parent;
|
container = parent;
|
||||||
}
|
}
|
||||||
return container;
|
return container;
|
||||||
|
@ -169,9 +188,6 @@ swayc_t *destroy_view(swayc_t *view) {
|
||||||
swayc_t *parent = view->parent;
|
swayc_t *parent = view->parent;
|
||||||
free_swayc(view);
|
free_swayc(view);
|
||||||
|
|
||||||
if (parent->focused == view) {
|
|
||||||
parent->focused = NULL;
|
|
||||||
}
|
|
||||||
//Destroy empty containers
|
//Destroy empty containers
|
||||||
if (parent->type == C_CONTAINER) {
|
if (parent->type == C_CONTAINER) {
|
||||||
return destroy_container(parent);
|
return destroy_container(parent);
|
||||||
|
|
Loading…
Reference in a new issue