aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-25 20:56:23 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-26 08:27:07 +1000
commit27a20a488465468511de9b2307941ac1bc4db8bf (patch)
treec5c1aff483cb089870ffebec00869347eec29f4c /sway/tree
parentMerge pull request #2330 from progandy/set-modifier-locks (diff)
downloadsway-27a20a488465468511de9b2307941ac1bc4db8bf.tar.gz
sway-27a20a488465468511de9b2307941ac1bc4db8bf.tar.zst
sway-27a20a488465468511de9b2307941ac1bc4db8bf.zip
Allow containers to be fullscreen
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/arrange.c18
-rw-r--r--sway/tree/container.c87
-rw-r--r--sway/tree/layout.c83
-rw-r--r--sway/tree/view.c73
4 files changed, 156 insertions, 105 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 533cf71c..5452b13c 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -220,8 +220,22 @@ static void arrange_workspace(struct sway_container *workspace) {
220 container_set_dirty(workspace); 220 container_set_dirty(workspace);
221 wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, 221 wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
222 workspace->x, workspace->y); 222 workspace->x, workspace->y);
223 arrange_floating(workspace->sway_workspace->floating); 223 if (workspace->sway_workspace->fullscreen) {
224 arrange_children_of(workspace); 224 struct sway_container *fs = workspace->sway_workspace->fullscreen;
225 fs->x = workspace->parent->x;
226 fs->y = workspace->parent->y;
227 fs->width = workspace->parent->width;
228 fs->height = workspace->parent->height;
229 if (fs->type == C_VIEW) {
230 view_autoconfigure(fs->sway_view);
231 } else {
232 arrange_children_of(fs);
233 }
234 container_set_dirty(fs);
235 } else {
236 arrange_floating(workspace->sway_workspace->floating);
237 arrange_children_of(workspace);
238 }
225} 239}
226 240
227static void arrange_output(struct sway_container *output) { 241static void arrange_output(struct sway_container *output) {
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 237e1a35..6ebf2653 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -1130,3 +1130,90 @@ void container_end_mouse_operation(struct sway_container *container) {
1130 } 1130 }
1131 } 1131 }
1132} 1132}
1133
1134static void set_fullscreen_iterator(struct sway_container *con, void *data) {
1135 if (con->type != C_VIEW) {
1136 return;
1137 }
1138 if (con->sway_view->impl->set_fullscreen) {
1139 bool *enable = data;
1140 con->sway_view->impl->set_fullscreen(con->sway_view, *enable);
1141 }
1142}
1143
1144void container_set_fullscreen(struct sway_container *container, bool enable) {
1145 if (container->is_fullscreen == enable) {
1146 return;
1147 }
1148
1149 struct sway_container *workspace = container_parent(container, C_WORKSPACE);
1150 if (enable && workspace->sway_workspace->fullscreen) {
1151 container_set_fullscreen(workspace->sway_workspace->fullscreen, false);
1152 }
1153
1154 container_for_each_descendant_dfs(container,
1155 set_fullscreen_iterator, &enable);
1156
1157 container->is_fullscreen = enable;
1158
1159 if (enable) {
1160 workspace->sway_workspace->fullscreen = container;
1161 container->saved_x = container->x;
1162 container->saved_y = container->y;
1163 container->saved_width = container->width;
1164 container->saved_height = container->height;
1165
1166 struct sway_seat *seat;
1167 struct sway_container *focus, *focus_ws;
1168 wl_list_for_each(seat, &input_manager->seats, link) {
1169 focus = seat_get_focus(seat);
1170 if (focus) {
1171 focus_ws = focus;
1172 if (focus_ws->type != C_WORKSPACE) {
1173 focus_ws = container_parent(focus_ws, C_WORKSPACE);
1174 }
1175 if (focus_ws == workspace) {
1176 seat_set_focus(seat, container);
1177 }
1178 }
1179 }
1180 } else {
1181 workspace->sway_workspace->fullscreen = NULL;
1182 if (container_is_floating(container)) {
1183 container->x = container->saved_x;
1184 container->y = container->saved_y;
1185 container->width = container->saved_width;
1186 container->height = container->saved_height;
1187 } else {
1188 container->width = container->saved_width;
1189 container->height = container->saved_height;
1190 }
1191 }
1192
1193 container_end_mouse_operation(container);
1194
1195 ipc_event_window(container, "fullscreen_mode");
1196}
1197
1198bool container_is_fullscreen_or_child(struct sway_container *container) {
1199 do {
1200 if (container->is_fullscreen) {
1201 return true;
1202 }
1203 container = container->parent;
1204 } while (container && container->type != C_WORKSPACE);
1205
1206 return false;
1207}
1208
1209struct sway_container *container_wrap_children(struct sway_container *parent) {
1210 struct sway_container *middle = container_create(C_CONTAINER);
1211 middle->layout = parent->layout;
1212 while (parent->children->length) {
1213 struct sway_container *child = parent->children->items[0];
1214 container_remove_child(child);
1215 container_add_child(middle, child);
1216 }
1217 container_add_child(parent, middle);
1218 return middle;
1219}
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 2b3263f8..ab5acc16 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -66,10 +66,9 @@ static int index_child(const struct sway_container *child) {
66 66
67static void container_handle_fullscreen_reparent(struct sway_container *con, 67static void container_handle_fullscreen_reparent(struct sway_container *con,
68 struct sway_container *old_parent) { 68 struct sway_container *old_parent) {
69 if (con->type != C_VIEW || !con->sway_view->is_fullscreen) { 69 if (!con->is_fullscreen) {
70 return; 70 return;
71 } 71 }
72 struct sway_view *view = con->sway_view;
73 struct sway_container *old_workspace = old_parent; 72 struct sway_container *old_workspace = old_parent;
74 if (old_workspace && old_workspace->type != C_WORKSPACE) { 73 if (old_workspace && old_workspace->type != C_WORKSPACE) {
75 old_workspace = container_parent(old_workspace, C_WORKSPACE); 74 old_workspace = container_parent(old_workspace, C_WORKSPACE);
@@ -85,19 +84,27 @@ static void container_handle_fullscreen_reparent(struct sway_container *con,
85 84
86 // Mark the new workspace as fullscreen 85 // Mark the new workspace as fullscreen
87 if (new_workspace->sway_workspace->fullscreen) { 86 if (new_workspace->sway_workspace->fullscreen) {
88 view_set_fullscreen(new_workspace->sway_workspace->fullscreen, false); 87 container_set_fullscreen(
88 new_workspace->sway_workspace->fullscreen, false);
89 } 89 }
90 new_workspace->sway_workspace->fullscreen = view; 90 new_workspace->sway_workspace->fullscreen = con;
91 // Resize view to new output dimensions 91
92 // Resize container to new output dimensions
92 struct sway_container *output = new_workspace->parent; 93 struct sway_container *output = new_workspace->parent;
93 view->x = output->x;
94 view->y = output->y;
95 view->width = output->width;
96 view->height = output->height;
97 con->x = output->x; 94 con->x = output->x;
98 con->y = output->y; 95 con->y = output->y;
99 con->width = output->width; 96 con->width = output->width;
100 con->height = output->height; 97 con->height = output->height;
98
99 if (con->type == C_VIEW) {
100 struct sway_view *view = con->sway_view;
101 view->x = output->x;
102 view->y = output->y;
103 view->width = output->width;
104 view->height = output->height;
105 } else {
106 arrange_windows(new_workspace);
107 }
101} 108}
102 109
103void container_insert_child(struct sway_container *parent, 110void container_insert_child(struct sway_container *parent,
@@ -146,7 +153,7 @@ void container_add_child(struct sway_container *parent,
146} 153}
147 154
148struct sway_container *container_remove_child(struct sway_container *child) { 155struct sway_container *container_remove_child(struct sway_container *child) {
149 if (child->type == C_VIEW && child->sway_view->is_fullscreen) { 156 if (child->is_fullscreen) {
150 struct sway_container *workspace = container_parent(child, C_WORKSPACE); 157 struct sway_container *workspace = container_parent(child, C_WORKSPACE);
151 workspace->sway_workspace->fullscreen = NULL; 158 workspace->sway_workspace->fullscreen = NULL;
152 } 159 }
@@ -229,10 +236,10 @@ void container_move_to(struct sway_container *container,
229 if (focus_ws->type != C_WORKSPACE) { 236 if (focus_ws->type != C_WORKSPACE) {
230 focus_ws = container_parent(focus_ws, C_WORKSPACE); 237 focus_ws = container_parent(focus_ws, C_WORKSPACE);
231 } 238 }
232 seat_set_focus(seat, 239 if (focus_ws == new_workspace) {
233 new_workspace->sway_workspace->fullscreen->swayc); 240 struct sway_container *new_focus = seat_get_focus_inactive(seat,
234 if (focus_ws != new_workspace) { 241 new_workspace->sway_workspace->fullscreen);
235 seat_set_focus(seat, focus); 242 seat_set_focus(seat, new_focus);
236 } 243 }
237 } 244 }
238 } 245 }
@@ -375,10 +382,16 @@ void container_move(struct sway_container *container,
375 struct sway_container *sibling = NULL; 382 struct sway_container *sibling = NULL;
376 struct sway_container *current = container; 383 struct sway_container *current = container;
377 struct sway_container *parent = current->parent; 384 struct sway_container *parent = current->parent;
385 struct sway_container *top = &root_container;
378 386
379 // If moving a fullscreen view, only consider outputs 387 // If moving a fullscreen view, only consider outputs
380 if (container->type == C_VIEW && container->sway_view->is_fullscreen) { 388 if (container->is_fullscreen) {
381 current = container_parent(container, C_OUTPUT); 389 current = container_parent(container, C_OUTPUT);
390 } else if (container_is_fullscreen_or_child(container)) {
391 // If we've fullscreened a split container, only allow the child to move
392 // around within the fullscreen parent.
393 struct sway_container *ws = container_parent(container, C_WORKSPACE);
394 top = ws->sway_workspace->fullscreen;
382 } 395 }
383 396
384 struct sway_container *new_parent = container_flatten(parent); 397 struct sway_container *new_parent = container_flatten(parent);
@@ -388,7 +401,7 @@ void container_move(struct sway_container *container,
388 } 401 }
389 402
390 while (!sibling) { 403 while (!sibling) {
391 if (current->type == C_ROOT) { 404 if (current == top) {
392 return; 405 return;
393 } 406 }
394 407
@@ -452,8 +465,9 @@ void container_move(struct sway_container *container,
452 if ((index == parent->children->length - 1 && offs > 0) 465 if ((index == parent->children->length - 1 && offs > 0)
453 || (index == 0 && offs < 0)) { 466 || (index == 0 && offs < 0)) {
454 if (current->parent == container->parent) { 467 if (current->parent == container->parent) {
455 if (parent->layout == L_TABBED 468 if (!parent->is_fullscreen &&
456 || parent->layout == L_STACKED) { 469 (parent->layout == L_TABBED ||
470 parent->layout == L_STACKED)) {
457 move_out_of_tabs_stacks(container, current, 471 move_out_of_tabs_stacks(container, current,
458 move_dir, offs); 472 move_dir, offs);
459 return; 473 return;
@@ -474,8 +488,8 @@ void container_move(struct sway_container *container,
474 sibling = parent->children->items[index + offs]; 488 sibling = parent->children->items[index + offs];
475 wlr_log(WLR_DEBUG, "Selecting sibling id:%zd", sibling->id); 489 wlr_log(WLR_DEBUG, "Selecting sibling id:%zd", sibling->id);
476 } 490 }
477 } else if (parent->layout == L_TABBED 491 } else if (!parent->is_fullscreen && (parent->layout == L_TABBED ||
478 || parent->layout == L_STACKED) { 492 parent->layout == L_STACKED)) {
479 move_out_of_tabs_stacks(container, current, move_dir, offs); 493 move_out_of_tabs_stacks(container, current, move_dir, offs);
480 return; 494 return;
481 } else { 495 } else {
@@ -707,16 +721,16 @@ struct sway_container *container_get_in_direction(
707 return NULL; 721 return NULL;
708 } 722 }
709 723
710 if (container->type == C_VIEW && container->sway_view->is_fullscreen) { 724 if (dir == MOVE_CHILD) {
711 if (dir == MOVE_PARENT || dir == MOVE_CHILD) { 725 return seat_get_focus_inactive(seat, container);
726 }
727 if (container->is_fullscreen) {
728 if (dir == MOVE_PARENT) {
712 return NULL; 729 return NULL;
713 } 730 }
714 container = container_parent(container, C_OUTPUT); 731 container = container_parent(container, C_OUTPUT);
715 parent = container->parent; 732 parent = container->parent;
716 } else { 733 } else {
717 if (dir == MOVE_CHILD) {
718 return seat_get_focus_inactive(seat, container);
719 }
720 if (dir == MOVE_PARENT) { 734 if (dir == MOVE_PARENT) {
721 if (parent->type == C_OUTPUT) { 735 if (parent->type == C_OUTPUT) {
722 return NULL; 736 return NULL;
@@ -767,7 +781,8 @@ struct sway_container *container_get_in_direction(
767 } 781 }
768 sway_assert(next_workspace, "Next container has no workspace"); 782 sway_assert(next_workspace, "Next container has no workspace");
769 if (next_workspace->sway_workspace->fullscreen) { 783 if (next_workspace->sway_workspace->fullscreen) {
770 return next_workspace->sway_workspace->fullscreen->swayc; 784 return seat_get_focus_inactive(seat,
785 next_workspace->sway_workspace->fullscreen);
771 } 786 }
772 if (next->children && next->children->length) { 787 if (next->children && next->children->length) {
773 // TODO consider floating children as well 788 // TODO consider floating children as well
@@ -1014,13 +1029,13 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
1014 1029
1015 wlr_log(WLR_DEBUG, "Swapping containers %zu and %zu", con1->id, con2->id); 1030 wlr_log(WLR_DEBUG, "Swapping containers %zu and %zu", con1->id, con2->id);
1016 1031
1017 int fs1 = con1->type == C_VIEW && con1->sway_view->is_fullscreen; 1032 int fs1 = con1->is_fullscreen;
1018 int fs2 = con2->type == C_VIEW && con2->sway_view->is_fullscreen; 1033 int fs2 = con2->is_fullscreen;
1019 if (fs1) { 1034 if (fs1) {
1020 view_set_fullscreen(con1->sway_view, false); 1035 container_set_fullscreen(con1, false);
1021 } 1036 }
1022 if (fs2) { 1037 if (fs2) {
1023 view_set_fullscreen(con2->sway_view, false); 1038 container_set_fullscreen(con2, false);
1024 } 1039 }
1025 1040
1026 struct sway_seat *seat = input_manager_get_default_seat(input_manager); 1041 struct sway_seat *seat = input_manager_get_default_seat(input_manager);
@@ -1053,10 +1068,10 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
1053 prev_workspace_name = stored_prev_name; 1068 prev_workspace_name = stored_prev_name;
1054 } 1069 }
1055 1070
1056 if (fs1 && con2->type == C_VIEW) { 1071 if (fs1) {
1057 view_set_fullscreen(con2->sway_view, true); 1072 container_set_fullscreen(con2, true);
1058 } 1073 }
1059 if (fs2 && con1->type == C_VIEW) { 1074 if (fs2) {
1060 view_set_fullscreen(con1->sway_view, true); 1075 container_set_fullscreen(con1, true);
1061 } 1076 }
1062} 1077}
diff --git a/sway/tree/view.c b/sway/tree/view.c
index beeb8144..82c3ad4a 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -225,7 +225,7 @@ void view_autoconfigure(struct sway_view *view) {
225 225
226 struct sway_container *output = container_parent(view->swayc, C_OUTPUT); 226 struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
227 227
228 if (view->is_fullscreen) { 228 if (view->swayc->is_fullscreen) {
229 view->x = output->x; 229 view->x = output->x;
230 view->y = output->y; 230 view->y = output->y;
231 view->width = output->width; 231 view->width = output->width;
@@ -233,10 +233,6 @@ void view_autoconfigure(struct sway_view *view) {
233 return; 233 return;
234 } 234 }
235 235
236 if (container_is_floating(view->swayc)) {
237 return;
238 }
239
240 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); 236 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
241 237
242 int other_views = 0; 238 int other_views = 0;
@@ -349,68 +345,6 @@ void view_set_tiled(struct sway_view *view, bool tiled) {
349 } 345 }
350} 346}
351 347
352void view_set_fullscreen(struct sway_view *view, bool fullscreen) {
353 if (view->is_fullscreen == fullscreen) {
354 return;
355 }
356
357 struct sway_container *workspace =
358 container_parent(view->swayc, C_WORKSPACE);
359
360 if (view->impl->set_fullscreen) {
361 view->impl->set_fullscreen(view, fullscreen);
362 }
363
364 view->is_fullscreen = fullscreen;
365
366 if (fullscreen) {
367 if (workspace->sway_workspace->fullscreen) {
368 view_set_fullscreen(workspace->sway_workspace->fullscreen, false);
369 }
370 workspace->sway_workspace->fullscreen = view;
371 view->saved_x = view->x;
372 view->saved_y = view->y;
373 view->saved_width = view->width;
374 view->saved_height = view->height;
375 view->swayc->saved_x = view->swayc->x;
376 view->swayc->saved_y = view->swayc->y;
377 view->swayc->saved_width = view->swayc->width;
378 view->swayc->saved_height = view->swayc->height;
379
380 struct sway_seat *seat;
381 struct sway_container *focus, *focus_ws;
382 wl_list_for_each(seat, &input_manager->seats, link) {
383 focus = seat_get_focus(seat);
384 if (focus) {
385 focus_ws = focus;
386 if (focus && focus_ws->type != C_WORKSPACE) {
387 focus_ws = container_parent(focus_ws, C_WORKSPACE);
388 }
389 seat_set_focus(seat, view->swayc);
390 if (focus_ws != workspace) {
391 seat_set_focus(seat, focus);
392 }
393 }
394 }
395 } else {
396 workspace->sway_workspace->fullscreen = NULL;
397 if (container_is_floating(view->swayc)) {
398 view->x = view->saved_x;
399 view->y = view->saved_y;
400 view->width = view->saved_width;
401 view->height = view->saved_height;
402 container_set_geometry_from_floating_view(view->swayc);
403 } else {
404 view->swayc->width = view->swayc->saved_width;
405 view->swayc->height = view->swayc->saved_height;
406 }
407 }
408
409 container_end_mouse_operation(view->swayc);
410
411 ipc_event_window(view->swayc, "fullscreen_mode");
412}
413
414void view_close(struct sway_view *view) { 348void view_close(struct sway_view *view) {
415 if (view->impl->close) { 349 if (view->impl->close) {
416 view->impl->close(view); 350 view->impl->close(view);
@@ -680,7 +614,7 @@ void view_unmap(struct sway_view *view) {
680 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); 614 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
681 615
682 struct sway_container *parent; 616 struct sway_container *parent;
683 if (view->is_fullscreen) { 617 if (view->swayc->is_fullscreen) {
684 ws->sway_workspace->fullscreen = NULL; 618 ws->sway_workspace->fullscreen = NULL;
685 parent = container_destroy(view->swayc); 619 parent = container_destroy(view->swayc);
686 620
@@ -1133,7 +1067,8 @@ bool view_is_visible(struct sway_view *view) {
1133 container = container->parent; 1067 container = container->parent;
1134 } 1068 }
1135 // Check view isn't hidden by another fullscreen view 1069 // Check view isn't hidden by another fullscreen view
1136 if (workspace->sway_workspace->fullscreen && !view->is_fullscreen) { 1070 if (workspace->sway_workspace->fullscreen &&
1071 !container_is_fullscreen_or_child(view->swayc)) {
1137 return false; 1072 return false;
1138 } 1073 }
1139 // Check the workspace is visible 1074 // Check the workspace is visible