diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-03-31 23:27:18 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-04-13 08:48:37 -0600 |
commit | 69a1a0ff99171f15c7842bfde23ed90f09a37256 (patch) | |
tree | 6d03653b20e1c5f62200d7cc6905d768fced8d52 /sway/tree/view.c | |
parent | Fix potential null accesses (diff) | |
download | sway-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/view.c')
-rw-r--r-- | sway/tree/view.c | 62 |
1 files changed, 41 insertions, 21 deletions
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 | ||
198 | void view_autoconfigure(struct sway_view *view) { | 198 | void 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 |