diff options
author | 2015-08-15 15:06:52 -0400 | |
---|---|---|
committer | 2015-08-15 15:06:52 -0400 | |
commit | 648675c87a3360949fdccd9947e419214fdc6ff4 (patch) | |
tree | 870db1e093ea5d4eb53ec6a5d11a1bfbe46d3baf | |
parent | Merge pull request #29 from taiyu-len/master (diff) | |
parent | fixed split (diff) | |
download | sway-648675c87a3360949fdccd9947e419214fdc6ff4.tar.gz sway-648675c87a3360949fdccd9947e419214fdc6ff4.tar.zst sway-648675c87a3360949fdccd9947e419214fdc6ff4.zip |
Merge pull request #30 from taiyu-len/master
fixed split
-rw-r--r-- | sway/commands.c | 26 | ||||
-rw-r--r-- | sway/container.c | 34 |
2 files changed, 42 insertions, 18 deletions
diff --git a/sway/commands.c b/sway/commands.c index 5f378a98..6ccc92fd 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -226,6 +226,7 @@ static bool cmd_set(struct sway_config *config, int argc, char **argv) { | |||
226 | list_add(config->symbols, var); | 226 | list_add(config->symbols, var); |
227 | return true; | 227 | return true; |
228 | } | 228 | } |
229 | static void container_log(const swayc_t *c); | ||
229 | 230 | ||
230 | static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { | 231 | static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { |
231 | char *name = layout == L_VERT ? "splitv" : | 232 | char *name = layout == L_VERT ? "splitv" : |
@@ -235,20 +236,27 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay | |||
235 | } | 236 | } |
236 | swayc_t *focused = get_focused_container(&root_container); | 237 | swayc_t *focused = get_focused_container(&root_container); |
237 | 238 | ||
238 | /* Case that focus is on an empty workspace. change its layout */ | 239 | container_log(focused); |
239 | if (focused->type == C_WORKSPACE) { | 240 | |
241 | /* Case that focus is on an workspace with 0/1 children.change its layout */ | ||
242 | if (focused->type == C_WORKSPACE && focused->children->length <= 1) { | ||
243 | sway_log(L_DEBUG, "changing workspace layout"); | ||
240 | focused->layout = layout; | 244 | focused->layout = layout; |
241 | return true; | ||
242 | } | 245 | } |
243 | /* Case of no siblings. change parent layout */ | 246 | /* Case of no siblings. change parent layout */ |
244 | if (focused->parent->children->length == 1) { | 247 | else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { |
248 | sway_log(L_DEBUG, "changing container layout"); | ||
245 | focused->parent->layout = layout; | 249 | focused->parent->layout = layout; |
246 | return true; | ||
247 | } | 250 | } |
248 | /* regular case where new split container is build around focused container */ | 251 | /* regular case where new split container is build around focused container |
249 | swayc_t *parent = new_container(focused, layout); | 252 | * or in case of workspace, container inherits its children */ |
250 | focus_view(focused); | 253 | else { |
251 | arrange_windows(parent, -1, -1); | 254 | sway_log(L_DEBUG, "Adding new container around current focused container"); |
255 | swayc_t *parent = new_container(focused, layout); | ||
256 | focus_view(focused); | ||
257 | arrange_windows(parent, -1, -1); | ||
258 | } | ||
259 | container_log(focused); | ||
252 | return true; | 260 | return true; |
253 | } | 261 | } |
254 | 262 | ||
diff --git a/sway/container.c b/sway/container.c index 1c17e92f..b52ffd8c 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -26,6 +26,9 @@ static void free_swayc(swayc_t *c) { | |||
26 | list_free(c->children); | 26 | list_free(c->children); |
27 | } | 27 | } |
28 | if (c->parent) { | 28 | if (c->parent) { |
29 | if (c->parent->focused == c) { | ||
30 | c->parent->focused = NULL; | ||
31 | } | ||
29 | remove_child(c->parent, c); | 32 | remove_child(c->parent, c); |
30 | } | 33 | } |
31 | free(c); | 34 | free(c); |
@@ -88,9 +91,28 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { | |||
88 | cont->y = child->y; | 91 | cont->y = child->y; |
89 | cont->visible = child->visible; | 92 | cont->visible = child->visible; |
90 | 93 | ||
91 | swayc_t *parent = replace_child(child, cont); | 94 | /* Container inherits all of workspaces children, layout and whatnot */ |
92 | if (parent) { | 95 | if (child->type == C_WORKSPACE) { |
93 | add_child(cont, child); | 96 | swayc_t *workspace = child; |
97 | //reorder focus | ||
98 | cont->focused = workspace->focused; | ||
99 | workspace->focused = cont; | ||
100 | //Swap children | ||
101 | list_t *tmp_list = workspace->children; | ||
102 | workspace->children = cont->children; | ||
103 | cont->children = tmp_list; | ||
104 | //add container to workspace chidren | ||
105 | add_child(workspace, cont); | ||
106 | //give them proper layouts | ||
107 | cont->layout = workspace->layout; | ||
108 | workspace->layout = layout; | ||
109 | } | ||
110 | //Or is built around container | ||
111 | else { | ||
112 | swayc_t *parent = replace_child(child, cont); | ||
113 | if (parent) { | ||
114 | add_child(cont, child); | ||
115 | } | ||
94 | } | 116 | } |
95 | return cont; | 117 | return cont; |
96 | } | 118 | } |
@@ -152,9 +174,6 @@ swayc_t *destroy_container(swayc_t *container) { | |||
152 | swayc_t *parent = container->parent; | 174 | swayc_t *parent = container->parent; |
153 | free_swayc(container); | 175 | free_swayc(container); |
154 | 176 | ||
155 | if (parent->focused == container) { | ||
156 | parent->focused = NULL; | ||
157 | } | ||
158 | container = parent; | 177 | container = parent; |
159 | } | 178 | } |
160 | return container; | 179 | return container; |
@@ -169,9 +188,6 @@ swayc_t *destroy_view(swayc_t *view) { | |||
169 | swayc_t *parent = view->parent; | 188 | swayc_t *parent = view->parent; |
170 | free_swayc(view); | 189 | free_swayc(view); |
171 | 190 | ||
172 | if (parent->focused == view) { | ||
173 | parent->focused = NULL; | ||
174 | } | ||
175 | //Destroy empty containers | 191 | //Destroy empty containers |
176 | if (parent->type == C_CONTAINER) { | 192 | if (parent->type == C_CONTAINER) { |
177 | return destroy_container(parent); | 193 | return destroy_container(parent); |