aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-03-31 23:27:18 -0400
committerDrew DeVault <sir@cmpwn.com>2019-04-13 08:48:37 -0600
commit69a1a0ff99171f15c7842bfde23ed90f09a37256 (patch)
tree6d03653b20e1c5f62200d7cc6905d768fced8d52 /sway/tree
parent913445e112b3ceca4ece731a6e57b19cab9d0c6a (diff)
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) {
if (con->fullscreen_mode == FULLSCREEN_WORKSPACE && con->workspace) {
con->workspace->fullscreen = NULL;
}
+ if (con->scratchpad && con->fullscreen_mode == FULLSCREEN_GLOBAL) {
+ container_fullscreen_disable(con);
+ }
+
wl_signal_emit(&con->node.events.destroy, &con->node);
container_end_mouse_operation(con);
@@ -128,7 +132,9 @@ void container_reap_empty(struct sway_container *con) {
container_begin_destroy(con);
con = parent;
}
- workspace_consider_destroy(ws);
+ if (ws) {
+ workspace_consider_destroy(ws);
+ }
}
struct sway_container *container_flatten(struct sway_container *container) {
@@ -954,18 +960,20 @@ static void container_fullscreen_workspace(struct sway_container *con) {
set_fullscreen_iterator(con, &enable);
container_for_each_child(con, set_fullscreen_iterator, &enable);
- con->workspace->fullscreen = con;
con->saved_x = con->x;
con->saved_y = con->y;
con->saved_width = con->width;
con->saved_height = con->height;
- struct sway_seat *seat;
- struct sway_workspace *focus_ws;
- wl_list_for_each(seat, &server.input->seats, link) {
- focus_ws = seat_get_focused_workspace(seat);
- if (focus_ws == con->workspace) {
- seat_set_focus_container(seat, con);
+ if (con->workspace) {
+ con->workspace->fullscreen = con;
+ struct sway_seat *seat;
+ struct sway_workspace *focus_ws;
+ wl_list_for_each(seat, &server.input->seats, link) {
+ focus_ws = seat_get_focused_workspace(seat);
+ if (focus_ws == con->workspace) {
+ seat_set_focus_container(seat, con);
+ }
}
}
@@ -1019,11 +1027,14 @@ void container_fullscreen_disable(struct sway_container *con) {
con->height = con->saved_height;
if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) {
- con->workspace->fullscreen = NULL;
- if (container_is_floating(con)) {
- struct sway_output *output = container_floating_find_output(con);
- if (con->workspace->output != output) {
- container_floating_move_to_center(con);
+ if (con->workspace) {
+ con->workspace->fullscreen = NULL;
+ if (container_is_floating(con)) {
+ struct sway_output *output =
+ container_floating_find_output(con);
+ if (con->workspace->output != output) {
+ container_floating_move_to_center(con);
+ }
}
}
} else {
@@ -1040,6 +1051,17 @@ void container_fullscreen_disable(struct sway_container *con) {
con->fullscreen_mode = FULLSCREEN_NONE;
container_end_mouse_operation(con);
ipc_event_window(con, "fullscreen_mode");
+
+ if (con->scratchpad) {
+ struct sway_seat *seat;
+ wl_list_for_each(seat, &server.input->seats, link) {
+ struct sway_container *focus = seat_get_focused_container(seat);
+ if (focus == con || container_has_ancestor(focus, con)) {
+ seat_set_focus(seat,
+ seat_get_focus_inactive(seat, &root->node));
+ }
+ }
+ }
}
void container_set_fullscreen(struct sway_container *con,
@@ -1056,7 +1078,7 @@ void container_set_fullscreen(struct sway_container *con,
if (root->fullscreen_global) {
container_fullscreen_disable(root->fullscreen_global);
}
- if (con->workspace->fullscreen) {
+ if (con->workspace && con->workspace->fullscreen) {
container_fullscreen_disable(con->workspace->fullscreen);
}
container_fullscreen_workspace(con);
@@ -1171,6 +1193,11 @@ void container_add_gaps(struct sway_container *c) {
c->current_gaps.bottom > 0 || c->current_gaps.left > 0) {
return;
}
+ // Fullscreen global scratchpad containers cannot have gaps
+ struct sway_workspace *ws = c->workspace;
+ if (!ws) {
+ return;
+ }
// Linear containers don't have gaps because it'd create double gaps
if (!c->view && c->layout != L_TABBED && c->layout != L_STACKED) {
return;
@@ -1199,8 +1226,6 @@ void container_add_gaps(struct sway_container *c) {
}
}
- struct sway_workspace *ws = c->workspace;
-
c->current_gaps.top = c->y == ws->y ? ws->gaps_inner : 0;
c->current_gaps.right = ws->gaps_inner;
c->current_gaps.bottom = ws->gaps_inner;
@@ -1308,6 +1333,10 @@ void container_add_child(struct sway_container *parent,
child->parent = parent;
child->workspace = parent->workspace;
container_for_each_child(child, set_workspace, NULL);
+ bool fullscreen = child->fullscreen_mode != FULLSCREEN_NONE ||
+ parent->fullscreen_mode != FULLSCREEN_NONE;
+ set_fullscreen_iterator(child, &fullscreen);
+ container_for_each_child(child, set_fullscreen_iterator, &fullscreen);
container_handle_fullscreen_reparent(child);
container_update_representation(parent);
node_set_dirty(&child->node);
@@ -1347,8 +1376,31 @@ void container_detach(struct sway_container *child) {
void container_replace(struct sway_container *container,
struct sway_container *replacement) {
+ enum sway_fullscreen_mode fullscreen = container->fullscreen_mode;
+ bool scratchpad = container->scratchpad;
+ if (fullscreen != FULLSCREEN_NONE) {
+ container_fullscreen_disable(container);
+ }
+ if (scratchpad) {
+ root_scratchpad_show(container);
+ root_scratchpad_remove_container(container);
+ }
container_add_sibling(container, replacement, 1);
container_detach(container);
+ if (scratchpad) {
+ root_scratchpad_add_container(replacement);
+ }
+ switch (fullscreen) {
+ case FULLSCREEN_WORKSPACE:
+ container_fullscreen_workspace(replacement);
+ break;
+ case FULLSCREEN_GLOBAL:
+ container_fullscreen_global(replacement);
+ break;
+ case FULLSCREEN_NONE:
+ // noop
+ break;
+ }
}
struct sway_container *container_split(struct sway_container *child,
@@ -1369,7 +1421,11 @@ struct sway_container *container_split(struct sway_container *child,
if (set_focus) {
seat_set_raw_focus(seat, &cont->node);
- seat_set_raw_focus(seat, &child->node);
+ if (cont->fullscreen_mode == FULLSCREEN_GLOBAL) {
+ seat_set_focus(seat, &child->node);
+ } else {
+ seat_set_raw_focus(seat, &child->node);
+ }
}
return cont;
@@ -1529,7 +1585,7 @@ void container_raise_floating(struct sway_container *con) {
while (floater->parent) {
floater = floater->parent;
}
- if (container_is_floating(floater)) {
+ if (container_is_floating(floater) && floater->workspace) {
list_move_to_end(floater->workspace->floating, floater);
node_set_dirty(&floater->workspace->node);
}
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) {
}
bool node_has_ancestor(struct sway_node *node, struct sway_node *ancestor) {
+ if (ancestor->type == N_ROOT && node->type == N_CONTAINER &&
+ node->sway_container->fullscreen_mode == FULLSCREEN_GLOBAL) {
+ return true;
+ }
struct sway_node *parent = node_get_parent(node);
while (parent) {
if (parent == ancestor) {
return true;
}
+ if (ancestor->type == N_ROOT && parent->type == N_CONTAINER &&
+ parent->sway_container->fullscreen_mode == FULLSCREEN_GLOBAL) {
+ return true;
+ }
parent = node_get_parent(parent);
}
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) {
struct sway_container *parent = con->parent;
struct sway_workspace *workspace = con->workspace;
+ // Clear the fullscreen mode when sending to the scratchpad
+ if (con->fullscreen_mode != FULLSCREEN_NONE) {
+ container_fullscreen_disable(con);
+ }
+
// When a tiled window is sent to scratchpad, center and resize it.
if (!container_is_floating(con)) {
container_set_floating(con, true);
@@ -143,6 +148,15 @@ void root_scratchpad_hide(struct sway_container *con) {
struct sway_node *focus = seat_get_focus_inactive(seat, &root->node);
struct sway_workspace *ws = con->workspace;
+ if (con->fullscreen_mode == FULLSCREEN_GLOBAL && !con->workspace) {
+ // If the container was made fullscreen global while in the scratchpad,
+ // it should be shown until fullscreen has been disabled
+ return;
+ }
+
+ if (con->fullscreen_mode != FULLSCREEN_NONE) {
+ container_fullscreen_disable(con);
+ }
container_detach(con);
arrange_workspace(ws);
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) {
void view_autoconfigure(struct sway_view *view) {
struct sway_container *con = view->container;
- if (container_is_scratchpad_hidden(con)) {
+ if (container_is_scratchpad_hidden(con) &&
+ con->fullscreen_mode != FULLSCREEN_GLOBAL) {
return;
}
- struct sway_output *output = con->workspace->output;
+ struct sway_output *output = con->workspace ? con->workspace->output : NULL;
if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) {
con->content_x = output->lx;
@@ -226,19 +227,21 @@ void view_autoconfigure(struct sway_view *view) {
con->border_top = con->border_bottom = true;
con->border_left = con->border_right = true;
- if (config->hide_edge_borders == E_BOTH
- || config->hide_edge_borders == E_VERTICAL
- || (smart && !other_views && no_gaps)) {
- con->border_left = con->x - con->current_gaps.left != ws->x;
- int right_x = con->x + con->width + con->current_gaps.right;
- con->border_right = right_x != ws->x + ws->width;
- }
- if (config->hide_edge_borders == E_BOTH
- || config->hide_edge_borders == E_HORIZONTAL
- || (smart && !other_views && no_gaps)) {
- con->border_top = con->y - con->current_gaps.top != ws->y;
- int bottom_y = con->y + con->height + con->current_gaps.bottom;
- con->border_bottom = bottom_y != ws->y + ws->height;
+ if (ws) {
+ if (config->hide_edge_borders == E_BOTH
+ || config->hide_edge_borders == E_VERTICAL
+ || (smart && !other_views && no_gaps)) {
+ con->border_left = con->x - con->current_gaps.left != ws->x;
+ int right_x = con->x + con->width + con->current_gaps.right;
+ con->border_right = right_x != ws->x + ws->width;
+ }
+ if (config->hide_edge_borders == E_BOTH
+ || config->hide_edge_borders == E_HORIZONTAL
+ || (smart && !other_views && no_gaps)) {
+ con->border_top = con->y - con->current_gaps.top != ws->y;
+ int bottom_y = con->y + con->height + con->current_gaps.bottom;
+ con->border_bottom = bottom_y != ws->y + ws->height;
+ }
}
double y_offset = 0;
@@ -247,7 +250,8 @@ void view_autoconfigure(struct sway_view *view) {
// title area. We have to offset the surface y by the height of the title,
// bar, and disable any top border because we'll always have the title bar.
list_t *siblings = container_get_siblings(con);
- bool show_titlebar = siblings->length > 1 || !config->hide_lone_tab;
+ bool show_titlebar = (siblings && siblings->length > 1)
+ || !config->hide_lone_tab;
if (show_titlebar && !container_is_floating(con)) {
enum sway_container_layout layout = container_parent_layout(con);
if (layout == L_TABBED) {
@@ -538,6 +542,10 @@ static bool should_focus(struct sway_view *view) {
struct sway_workspace *prev_ws = seat_get_focused_workspace(seat);
struct sway_workspace *map_ws = view->container->workspace;
+ if (view->container->fullscreen_mode == FULLSCREEN_GLOBAL) {
+ return true;
+ }
+
// Views can only take focus if they are mapped into the active workspace
if (prev_ws != map_ws) {
return false;
@@ -581,7 +589,8 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
}
struct sway_seat *seat = input_manager_current_seat();
- struct sway_node *node = seat_get_focus_inactive(seat, &ws->node);
+ struct sway_node *node = ws ? seat_get_focus_inactive(seat, &ws->node)
+ : seat_get_focus_inactive(seat, &root->node);
struct sway_container *target_sibling = node->type == N_CONTAINER ?
node->sway_container : NULL;
@@ -589,12 +598,13 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
// launch it as a tiled view in the root of the workspace instead.
if (target_sibling && container_is_floating(target_sibling)) {
target_sibling = NULL;
+ ws = seat_get_last_known_workspace(seat);
}
view->container = container_create(view);
if (target_sibling) {
container_add_sibling(target_sibling, view->container, 1);
- } else {
+ } else if (ws) {
workspace_add_tiling(ws, view->container);
}
ipc_event_window(view->container, "new");
@@ -1032,8 +1042,18 @@ bool view_is_visible(struct sway_view *view) {
return false;
}
struct sway_workspace *workspace = view->container->workspace;
- if (!workspace) {
- return false;
+ if (!workspace && view->container->fullscreen_mode != FULLSCREEN_GLOBAL) {
+ bool fs_global_descendant = false;
+ struct sway_container *parent = view->container->parent;
+ while (parent) {
+ if (parent->fullscreen_mode == FULLSCREEN_GLOBAL) {
+ fs_global_descendant = true;
+ }
+ parent = parent->parent;
+ }
+ if (!fs_global_descendant) {
+ return false;
+ }
}
// Determine if view is nested inside a floating container which is sticky
struct sway_container *floater = view->container;
@@ -1041,7 +1061,7 @@ bool view_is_visible(struct sway_view *view) {
floater = floater->parent;
}
bool is_sticky = container_is_floating(floater) && floater->is_sticky;
- if (!is_sticky && !workspace_is_visible(workspace)) {
+ if (!is_sticky && workspace && !workspace_is_visible(workspace)) {
return false;
}
// Check view isn't in a tabbed or stacked container on an inactive tab