aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-03-31 23:27:18 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-04-13 08:48:37 -0600
commit69a1a0ff99171f15c7842bfde23ed90f09a37256 (patch)
tree6d03653b20e1c5f62200d7cc6905d768fced8d52 /sway/tree
parentFix potential null accesses (diff)
downloadsway-69a1a0ff99171f15c7842bfde23ed90f09a37256.tar.gz
sway-69a1a0ff99171f15c7842bfde23ed90f09a37256.tar.zst
sway-69a1a0ff99171f15c7842bfde23ed90f09a37256.zip
Fix scratchpad fullscreen behavior and crash
When setting fullscreen on a hidden scratchpad container, there was a check to see if there was an existing fullscreen container on the workspace so it could be fullscreen disabled first. Since the workspace is NULL, it would cause a SIGSEGV. This adds a NULL check to avoid the crash. This also changes the behavior of how fullscreen is handled when adding a container to the scratchpad or changing visibility of a scratchpad container to match i3's. The behavior is as follows: - When adding a container to the scratchpad or hiding a container back into the scratchpad, there is an implicit fullscreen disable - When setting fullscreen on a container that is hidden in the scratchpad, it will be fullscreen when shown (and fullscreen disabled when hidden as stated above) - When setting fullscreen global on a container that is hidden in the scratchpad, it will be shown immediately as fullscreen global. The container is not moved to a workspace and remains in the scratchpad. The container will be visible until fullscreen disabled or killed. Since the container is in the scratchpad, running `scratchpad show` or `move container to scratchpad` will have no effect This also changes `container_replace` to transfer fullscreen and scratchpad status.
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/container.c92
-rw-r--r--sway/tree/node.c8
-rw-r--r--sway/tree/root.c14
-rw-r--r--sway/tree/view.c62
4 files changed, 137 insertions, 39 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 02b4d1b0..11ed4f98 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -95,6 +95,10 @@ void container_begin_destroy(struct sway_container *con) {
95 if (con->fullscreen_mode == FULLSCREEN_WORKSPACE && con->workspace) { 95 if (con->fullscreen_mode == FULLSCREEN_WORKSPACE && con->workspace) {
96 con->workspace->fullscreen = NULL; 96 con->workspace->fullscreen = NULL;
97 } 97 }
98 if (con->scratchpad && con->fullscreen_mode == FULLSCREEN_GLOBAL) {
99 container_fullscreen_disable(con);
100 }
101
98 wl_signal_emit(&con->node.events.destroy, &con->node); 102 wl_signal_emit(&con->node.events.destroy, &con->node);
99 103
100 container_end_mouse_operation(con); 104 container_end_mouse_operation(con);
@@ -128,7 +132,9 @@ void container_reap_empty(struct sway_container *con) {
128 container_begin_destroy(con); 132 container_begin_destroy(con);
129 con = parent; 133 con = parent;
130 } 134 }
131 workspace_consider_destroy(ws); 135 if (ws) {
136 workspace_consider_destroy(ws);
137 }
132} 138}
133 139
134struct sway_container *container_flatten(struct sway_container *container) { 140struct sway_container *container_flatten(struct sway_container *container) {
@@ -954,18 +960,20 @@ static void container_fullscreen_workspace(struct sway_container *con) {
954 set_fullscreen_iterator(con, &enable); 960 set_fullscreen_iterator(con, &enable);
955 container_for_each_child(con, set_fullscreen_iterator, &enable); 961 container_for_each_child(con, set_fullscreen_iterator, &enable);
956 962
957 con->workspace->fullscreen = con;
958 con->saved_x = con->x; 963 con->saved_x = con->x;
959 con->saved_y = con->y; 964 con->saved_y = con->y;
960 con->saved_width = con->width; 965 con->saved_width = con->width;
961 con->saved_height = con->height; 966 con->saved_height = con->height;
962 967
963 struct sway_seat *seat; 968 if (con->workspace) {
964 struct sway_workspace *focus_ws; 969 con->workspace->fullscreen = con;
965 wl_list_for_each(seat, &server.input->seats, link) { 970 struct sway_seat *seat;
966 focus_ws = seat_get_focused_workspace(seat); 971 struct sway_workspace *focus_ws;
967 if (focus_ws == con->workspace) { 972 wl_list_for_each(seat, &server.input->seats, link) {
968 seat_set_focus_container(seat, con); 973 focus_ws = seat_get_focused_workspace(seat);
974 if (focus_ws == con->workspace) {
975 seat_set_focus_container(seat, con);
976 }
969 } 977 }
970 } 978 }
971 979
@@ -1019,11 +1027,14 @@ void container_fullscreen_disable(struct sway_container *con) {
1019 con->height = con->saved_height; 1027 con->height = con->saved_height;
1020 1028
1021 if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) { 1029 if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) {
1022 con->workspace->fullscreen = NULL; 1030 if (con->workspace) {
1023 if (container_is_floating(con)) { 1031 con->workspace->fullscreen = NULL;
1024 struct sway_output *output = container_floating_find_output(con); 1032 if (container_is_floating(con)) {
1025 if (con->workspace->output != output) { 1033 struct sway_output *output =
1026 container_floating_move_to_center(con); 1034 container_floating_find_output(con);
1035 if (con->workspace->output != output) {
1036 container_floating_move_to_center(con);
1037 }
1027 } 1038 }
1028 } 1039 }
1029 } else { 1040 } else {
@@ -1040,6 +1051,17 @@ void container_fullscreen_disable(struct sway_container *con) {
1040 con->fullscreen_mode = FULLSCREEN_NONE; 1051 con->fullscreen_mode = FULLSCREEN_NONE;
1041 container_end_mouse_operation(con); 1052 container_end_mouse_operation(con);
1042 ipc_event_window(con, "fullscreen_mode"); 1053 ipc_event_window(con, "fullscreen_mode");
1054
1055 if (con->scratchpad) {
1056 struct sway_seat *seat;
1057 wl_list_for_each(seat, &server.input->seats, link) {
1058 struct sway_container *focus = seat_get_focused_container(seat);
1059 if (focus == con || container_has_ancestor(focus, con)) {
1060 seat_set_focus(seat,
1061 seat_get_focus_inactive(seat, &root->node));
1062 }
1063 }
1064 }
1043} 1065}
1044 1066
1045void container_set_fullscreen(struct sway_container *con, 1067void container_set_fullscreen(struct sway_container *con,
@@ -1056,7 +1078,7 @@ void container_set_fullscreen(struct sway_container *con,
1056 if (root->fullscreen_global) { 1078 if (root->fullscreen_global) {
1057 container_fullscreen_disable(root->fullscreen_global); 1079 container_fullscreen_disable(root->fullscreen_global);
1058 } 1080 }
1059 if (con->workspace->fullscreen) { 1081 if (con->workspace && con->workspace->fullscreen) {
1060 container_fullscreen_disable(con->workspace->fullscreen); 1082 container_fullscreen_disable(con->workspace->fullscreen);
1061 } 1083 }
1062 container_fullscreen_workspace(con); 1084 container_fullscreen_workspace(con);
@@ -1171,6 +1193,11 @@ void container_add_gaps(struct sway_container *c) {
1171 c->current_gaps.bottom > 0 || c->current_gaps.left > 0) { 1193 c->current_gaps.bottom > 0 || c->current_gaps.left > 0) {
1172 return; 1194 return;
1173 } 1195 }
1196 // Fullscreen global scratchpad containers cannot have gaps
1197 struct sway_workspace *ws = c->workspace;
1198 if (!ws) {
1199 return;
1200 }
1174 // Linear containers don't have gaps because it'd create double gaps 1201 // Linear containers don't have gaps because it'd create double gaps
1175 if (!c->view && c->layout != L_TABBED && c->layout != L_STACKED) { 1202 if (!c->view && c->layout != L_TABBED && c->layout != L_STACKED) {
1176 return; 1203 return;
@@ -1199,8 +1226,6 @@ void container_add_gaps(struct sway_container *c) {
1199 } 1226 }
1200 } 1227 }
1201 1228
1202 struct sway_workspace *ws = c->workspace;
1203
1204 c->current_gaps.top = c->y == ws->y ? ws->gaps_inner : 0; 1229 c->current_gaps.top = c->y == ws->y ? ws->gaps_inner : 0;
1205 c->current_gaps.right = ws->gaps_inner; 1230 c->current_gaps.right = ws->gaps_inner;
1206 c->current_gaps.bottom = ws->gaps_inner; 1231 c->current_gaps.bottom = ws->gaps_inner;
@@ -1308,6 +1333,10 @@ void container_add_child(struct sway_container *parent,
1308 child->parent = parent; 1333 child->parent = parent;
1309 child->workspace = parent->workspace; 1334 child->workspace = parent->workspace;
1310 container_for_each_child(child, set_workspace, NULL); 1335 container_for_each_child(child, set_workspace, NULL);
1336 bool fullscreen = child->fullscreen_mode != FULLSCREEN_NONE ||
1337 parent->fullscreen_mode != FULLSCREEN_NONE;
1338 set_fullscreen_iterator(child, &fullscreen);
1339 container_for_each_child(child, set_fullscreen_iterator, &fullscreen);
1311 container_handle_fullscreen_reparent(child); 1340 container_handle_fullscreen_reparent(child);
1312 container_update_representation(parent); 1341 container_update_representation(parent);
1313 node_set_dirty(&child->node); 1342 node_set_dirty(&child->node);
@@ -1347,8 +1376,31 @@ void container_detach(struct sway_container *child) {
1347 1376
1348void container_replace(struct sway_container *container, 1377void container_replace(struct sway_container *container,
1349 struct sway_container *replacement) { 1378 struct sway_container *replacement) {
1379 enum sway_fullscreen_mode fullscreen = container->fullscreen_mode;
1380 bool scratchpad = container->scratchpad;
1381 if (fullscreen != FULLSCREEN_NONE) {
1382 container_fullscreen_disable(container);
1383 }
1384 if (scratchpad) {
1385 root_scratchpad_show(container);
1386 root_scratchpad_remove_container(container);
1387 }
1350 container_add_sibling(container, replacement, 1); 1388 container_add_sibling(container, replacement, 1);
1351 container_detach(container); 1389 container_detach(container);
1390 if (scratchpad) {
1391 root_scratchpad_add_container(replacement);
1392 }
1393 switch (fullscreen) {
1394 case FULLSCREEN_WORKSPACE:
1395 container_fullscreen_workspace(replacement);
1396 break;
1397 case FULLSCREEN_GLOBAL:
1398 container_fullscreen_global(replacement);
1399 break;
1400 case FULLSCREEN_NONE:
1401 // noop
1402 break;
1403 }
1352} 1404}
1353 1405
1354struct sway_container *container_split(struct sway_container *child, 1406struct sway_container *container_split(struct sway_container *child,
@@ -1369,7 +1421,11 @@ struct sway_container *container_split(struct sway_container *child,
1369 1421
1370 if (set_focus) { 1422 if (set_focus) {
1371 seat_set_raw_focus(seat, &cont->node); 1423 seat_set_raw_focus(seat, &cont->node);
1372 seat_set_raw_focus(seat, &child->node); 1424 if (cont->fullscreen_mode == FULLSCREEN_GLOBAL) {
1425 seat_set_focus(seat, &child->node);
1426 } else {
1427 seat_set_raw_focus(seat, &child->node);
1428 }
1373 } 1429 }
1374 1430
1375 return cont; 1431 return cont;
@@ -1529,7 +1585,7 @@ void container_raise_floating(struct sway_container *con) {
1529 while (floater->parent) { 1585 while (floater->parent) {
1530 floater = floater->parent; 1586 floater = floater->parent;
1531 } 1587 }
1532 if (container_is_floating(floater)) { 1588 if (container_is_floating(floater) && floater->workspace) {
1533 list_move_to_end(floater->workspace->floating, floater); 1589 list_move_to_end(floater->workspace->floating, floater);
1534 node_set_dirty(&floater->workspace->node); 1590 node_set_dirty(&floater->workspace->node);
1535 } 1591 }
diff --git a/sway/tree/node.c b/sway/tree/node.c
index dcab1c9b..ffa7f2cc 100644
--- a/sway/tree/node.c
+++ b/sway/tree/node.c
@@ -142,11 +142,19 @@ list_t *node_get_children(struct sway_node *node) {
142} 142}
143 143
144bool node_has_ancestor(struct sway_node *node, struct sway_node *ancestor) { 144bool node_has_ancestor(struct sway_node *node, struct sway_node *ancestor) {
145 if (ancestor->type == N_ROOT && node->type == N_CONTAINER &&
146 node->sway_container->fullscreen_mode == FULLSCREEN_GLOBAL) {
147 return true;
148 }
145 struct sway_node *parent = node_get_parent(node); 149 struct sway_node *parent = node_get_parent(node);
146 while (parent) { 150 while (parent) {
147 if (parent == ancestor) { 151 if (parent == ancestor) {
148 return true; 152 return true;
149 } 153 }
154 if (ancestor->type == N_ROOT && parent->type == N_CONTAINER &&
155 parent->sway_container->fullscreen_mode == FULLSCREEN_GLOBAL) {
156 return true;
157 }
150 parent = node_get_parent(parent); 158 parent = node_get_parent(parent);
151 } 159 }
152 return false; 160 return false;
diff --git a/sway/tree/root.c b/sway/tree/root.c
index a9d306a4..1dabc287 100644
--- a/sway/tree/root.c
+++ b/sway/tree/root.c
@@ -62,6 +62,11 @@ void root_scratchpad_add_container(struct sway_container *con) {
62 struct sway_container *parent = con->parent; 62 struct sway_container *parent = con->parent;
63 struct sway_workspace *workspace = con->workspace; 63 struct sway_workspace *workspace = con->workspace;
64 64
65 // Clear the fullscreen mode when sending to the scratchpad
66 if (con->fullscreen_mode != FULLSCREEN_NONE) {
67 container_fullscreen_disable(con);
68 }
69
65 // When a tiled window is sent to scratchpad, center and resize it. 70 // When a tiled window is sent to scratchpad, center and resize it.
66 if (!container_is_floating(con)) { 71 if (!container_is_floating(con)) {
67 container_set_floating(con, true); 72 container_set_floating(con, true);
@@ -143,6 +148,15 @@ void root_scratchpad_hide(struct sway_container *con) {
143 struct sway_node *focus = seat_get_focus_inactive(seat, &root->node); 148 struct sway_node *focus = seat_get_focus_inactive(seat, &root->node);
144 struct sway_workspace *ws = con->workspace; 149 struct sway_workspace *ws = con->workspace;
145 150
151 if (con->fullscreen_mode == FULLSCREEN_GLOBAL && !con->workspace) {
152 // If the container was made fullscreen global while in the scratchpad,
153 // it should be shown until fullscreen has been disabled
154 return;
155 }
156
157 if (con->fullscreen_mode != FULLSCREEN_NONE) {
158 container_fullscreen_disable(con);
159 }
146 container_detach(con); 160 container_detach(con);
147 arrange_workspace(ws); 161 arrange_workspace(ws);
148 if (&con->node == focus || node_has_ancestor(focus, &con->node)) { 162 if (&con->node == focus || node_has_ancestor(focus, &con->node)) {
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 2c8839f5..c241b2b3 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -197,10 +197,11 @@ static bool gaps_to_edge(struct sway_view *view) {
197 197
198void view_autoconfigure(struct sway_view *view) { 198void view_autoconfigure(struct sway_view *view) {
199 struct sway_container *con = view->container; 199 struct sway_container *con = view->container;
200 if (container_is_scratchpad_hidden(con)) { 200 if (container_is_scratchpad_hidden(con) &&
201 con->fullscreen_mode != FULLSCREEN_GLOBAL) {
201 return; 202 return;
202 } 203 }
203 struct sway_output *output = con->workspace->output; 204 struct sway_output *output = con->workspace ? con->workspace->output : NULL;
204 205
205 if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) { 206 if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) {
206 con->content_x = output->lx; 207 con->content_x = output->lx;
@@ -226,19 +227,21 @@ void view_autoconfigure(struct sway_view *view) {
226 227
227 con->border_top = con->border_bottom = true; 228 con->border_top = con->border_bottom = true;
228 con->border_left = con->border_right = true; 229 con->border_left = con->border_right = true;
229 if (config->hide_edge_borders == E_BOTH 230 if (ws) {
230 || config->hide_edge_borders == E_VERTICAL 231 if (config->hide_edge_borders == E_BOTH
231 || (smart && !other_views && no_gaps)) { 232 || config->hide_edge_borders == E_VERTICAL
232 con->border_left = con->x - con->current_gaps.left != ws->x; 233 || (smart && !other_views && no_gaps)) {
233 int right_x = con->x + con->width + con->current_gaps.right; 234 con->border_left = con->x - con->current_gaps.left != ws->x;
234 con->border_right = right_x != ws->x + ws->width; 235 int right_x = con->x + con->width + con->current_gaps.right;
235 } 236 con->border_right = right_x != ws->x + ws->width;
236 if (config->hide_edge_borders == E_BOTH 237 }
237 || config->hide_edge_borders == E_HORIZONTAL 238 if (config->hide_edge_borders == E_BOTH
238 || (smart && !other_views && no_gaps)) { 239 || config->hide_edge_borders == E_HORIZONTAL
239 con->border_top = con->y - con->current_gaps.top != ws->y; 240 || (smart && !other_views && no_gaps)) {
240 int bottom_y = con->y + con->height + con->current_gaps.bottom; 241 con->border_top = con->y - con->current_gaps.top != ws->y;
241 con->border_bottom = bottom_y != ws->y + ws->height; 242 int bottom_y = con->y + con->height + con->current_gaps.bottom;
243 con->border_bottom = bottom_y != ws->y + ws->height;
244 }
242 } 245 }
243 246
244 double y_offset = 0; 247 double y_offset = 0;
@@ -247,7 +250,8 @@ void view_autoconfigure(struct sway_view *view) {
247 // title area. We have to offset the surface y by the height of the title, 250 // title area. We have to offset the surface y by the height of the title,
248 // bar, and disable any top border because we'll always have the title bar. 251 // bar, and disable any top border because we'll always have the title bar.
249 list_t *siblings = container_get_siblings(con); 252 list_t *siblings = container_get_siblings(con);
250 bool show_titlebar = siblings->length > 1 || !config->hide_lone_tab; 253 bool show_titlebar = (siblings && siblings->length > 1)
254 || !config->hide_lone_tab;
251 if (show_titlebar && !container_is_floating(con)) { 255 if (show_titlebar && !container_is_floating(con)) {
252 enum sway_container_layout layout = container_parent_layout(con); 256 enum sway_container_layout layout = container_parent_layout(con);
253 if (layout == L_TABBED) { 257 if (layout == L_TABBED) {
@@ -538,6 +542,10 @@ static bool should_focus(struct sway_view *view) {
538 struct sway_workspace *prev_ws = seat_get_focused_workspace(seat); 542 struct sway_workspace *prev_ws = seat_get_focused_workspace(seat);
539 struct sway_workspace *map_ws = view->container->workspace; 543 struct sway_workspace *map_ws = view->container->workspace;
540 544
545 if (view->container->fullscreen_mode == FULLSCREEN_GLOBAL) {
546 return true;
547 }
548
541 // Views can only take focus if they are mapped into the active workspace 549 // Views can only take focus if they are mapped into the active workspace
542 if (prev_ws != map_ws) { 550 if (prev_ws != map_ws) {
543 return false; 551 return false;
@@ -581,7 +589,8 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
581 } 589 }
582 590
583 struct sway_seat *seat = input_manager_current_seat(); 591 struct sway_seat *seat = input_manager_current_seat();
584 struct sway_node *node = seat_get_focus_inactive(seat, &ws->node); 592 struct sway_node *node = ws ? seat_get_focus_inactive(seat, &ws->node)
593 : seat_get_focus_inactive(seat, &root->node);
585 struct sway_container *target_sibling = node->type == N_CONTAINER ? 594 struct sway_container *target_sibling = node->type == N_CONTAINER ?
586 node->sway_container : NULL; 595 node->sway_container : NULL;
587 596
@@ -589,12 +598,13 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
589 // launch it as a tiled view in the root of the workspace instead. 598 // launch it as a tiled view in the root of the workspace instead.
590 if (target_sibling && container_is_floating(target_sibling)) { 599 if (target_sibling && container_is_floating(target_sibling)) {
591 target_sibling = NULL; 600 target_sibling = NULL;
601 ws = seat_get_last_known_workspace(seat);
592 } 602 }
593 603
594 view->container = container_create(view); 604 view->container = container_create(view);
595 if (target_sibling) { 605 if (target_sibling) {
596 container_add_sibling(target_sibling, view->container, 1); 606 container_add_sibling(target_sibling, view->container, 1);
597 } else { 607 } else if (ws) {
598 workspace_add_tiling(ws, view->container); 608 workspace_add_tiling(ws, view->container);
599 } 609 }
600 ipc_event_window(view->container, "new"); 610 ipc_event_window(view->container, "new");
@@ -1032,8 +1042,18 @@ bool view_is_visible(struct sway_view *view) {
1032 return false; 1042 return false;
1033 } 1043 }
1034 struct sway_workspace *workspace = view->container->workspace; 1044 struct sway_workspace *workspace = view->container->workspace;
1035 if (!workspace) { 1045 if (!workspace && view->container->fullscreen_mode != FULLSCREEN_GLOBAL) {
1036 return false; 1046 bool fs_global_descendant = false;
1047 struct sway_container *parent = view->container->parent;
1048 while (parent) {
1049 if (parent->fullscreen_mode == FULLSCREEN_GLOBAL) {
1050 fs_global_descendant = true;
1051 }
1052 parent = parent->parent;
1053 }
1054 if (!fs_global_descendant) {
1055 return false;
1056 }
1037 } 1057 }
1038 // Determine if view is nested inside a floating container which is sticky 1058 // Determine if view is nested inside a floating container which is sticky
1039 struct sway_container *floater = view->container; 1059 struct sway_container *floater = view->container;
@@ -1041,7 +1061,7 @@ bool view_is_visible(struct sway_view *view) {
1041 floater = floater->parent; 1061 floater = floater->parent;
1042 } 1062 }
1043 bool is_sticky = container_is_floating(floater) && floater->is_sticky; 1063 bool is_sticky = container_is_floating(floater) && floater->is_sticky;
1044 if (!is_sticky && !workspace_is_visible(workspace)) { 1064 if (!is_sticky && workspace && !workspace_is_visible(workspace)) {
1045 return false; 1065 return false;
1046 } 1066 }
1047 // Check view isn't in a tabbed or stacked container on an inactive tab 1067 // Check view isn't in a tabbed or stacked container on an inactive tab