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.
This commit is contained in:
Brian Ashworth 2019-03-31 23:27:18 -04:00 committed by Drew DeVault
parent 913445e112
commit 69a1a0ff99
14 changed files with 220 additions and 57 deletions

View file

@ -143,6 +143,11 @@ struct sway_node *seat_get_focus(struct sway_seat *seat);
struct sway_workspace *seat_get_focused_workspace(struct sway_seat *seat); struct sway_workspace *seat_get_focused_workspace(struct sway_seat *seat);
// If a scratchpad container is fullscreen global, this can be used to try to
// determine the last focused workspace. Otherwise, this should yield the same
// results as seat_get_focused_workspace.
struct sway_workspace *seat_get_last_known_workspace(struct sway_seat *seat);
struct sway_container *seat_get_focused_container(struct sway_seat *seat); struct sway_container *seat_get_focused_container(struct sway_seat *seat);
/** /**

View file

@ -32,6 +32,11 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
seat_set_focus_container(config->handler_context.seat, container); seat_set_focus_container(config->handler_context.seat, container);
} }
if (container_is_scratchpad_hidden(container)) {
return cmd_results_new(CMD_INVALID,
"Can't change floating on hidden scratchpad container");
}
// If the container is in a floating split container, // If the container is in a floating split container,
// operate on the split container instead of the child. // operate on the split container instead of the child.
if (container_is_floating_or_child(container)) { if (container_is_floating_or_child(container)) {

View file

@ -182,6 +182,10 @@ static struct sway_node *node_get_in_direction_floating(
double closest_distance = DBL_MAX; double closest_distance = DBL_MAX;
struct sway_container *closest_con = NULL; struct sway_container *closest_con = NULL;
if (!con->workspace) {
return NULL;
}
for (int i = 0; i < con->workspace->floating->length; i++) { for (int i = 0; i < con->workspace->floating->length; i++) {
struct sway_container *floater = con->workspace->floating->items[i]; struct sway_container *floater = con->workspace->floating->items[i];
if (floater == con) { if (floater == con) {

View file

@ -26,6 +26,13 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {
"Can't fullscreen an empty workspace"); "Can't fullscreen an empty workspace");
} }
// If in the scratchpad, operate on the highest container
if (container && !container->workspace) {
while (container->parent) {
container = container->parent;
}
}
bool is_fullscreen = container && bool is_fullscreen = container &&
container->fullscreen_mode != FULLSCREEN_NONE; container->fullscreen_mode != FULLSCREEN_NONE;
bool global = false; bool global = false;

View file

@ -147,8 +147,12 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
workspace->layout = new_layout; workspace->layout = new_layout;
workspace_update_representation(workspace); workspace_update_representation(workspace);
} }
if (root->fullscreen_global) {
arrange_root();
} else {
arrange_workspace(workspace); arrange_workspace(workspace);
} }
}
return cmd_results_new(CMD_SUCCESS, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -395,6 +395,11 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
container = workspace_wrap_children(workspace); container = workspace_wrap_children(workspace);
} }
if (container->fullscreen_mode == FULLSCREEN_GLOBAL) {
return cmd_results_new(CMD_FAILURE,
"Can't move fullscreen global container");
}
bool no_auto_back_and_forth = false; bool no_auto_back_and_forth = false;
while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) { while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) {
no_auto_back_and_forth = true; no_auto_back_and_forth = true;
@ -646,6 +651,10 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) {
} }
struct sway_workspace *workspace = config->handler_context.workspace; struct sway_workspace *workspace = config->handler_context.workspace;
if (!workspace) {
return cmd_results_new(CMD_FAILURE, "No workspace to move");
}
struct sway_output *old_output = workspace->output; struct sway_output *old_output = workspace->output;
int center_x = workspace->width / 2 + workspace->x, int center_x = workspace->width / 2 + workspace->x,
center_y = workspace->height / 2 + workspace->y; center_y = workspace->height / 2 + workspace->y;

View file

@ -13,7 +13,8 @@ static struct cmd_results *do_split(int layout) {
struct sway_container *con = config->handler_context.container; struct sway_container *con = config->handler_context.container;
struct sway_workspace *ws = config->handler_context.workspace; struct sway_workspace *ws = config->handler_context.workspace;
if (con) { if (con) {
if (container_is_scratchpad_hidden(con)) { if (container_is_scratchpad_hidden(con) &&
con->fullscreen_mode != FULLSCREEN_GLOBAL) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE,
"Cannot split a hidden scratchpad container"); "Cannot split a hidden scratchpad container");
} }

View file

@ -251,14 +251,11 @@ static void output_for_each_surface(struct sway_output *output,
}; };
struct sway_workspace *workspace = output_get_active_workspace(output); struct sway_workspace *workspace = output_get_active_workspace(output);
struct sway_container *fullscreen_con = root->fullscreen_global;
if (!fullscreen_con) {
if (!workspace) { if (!workspace) {
return; return;
} }
struct sway_container *fullscreen_con = root->fullscreen_global;
if (fullscreen_con && container_is_scratchpad_hidden(fullscreen_con)) {
fullscreen_con = NULL;
}
if (!fullscreen_con) {
fullscreen_con = workspace->current.fullscreen; fullscreen_con = workspace->current.fullscreen;
} }
if (fullscreen_con) { if (fullscreen_con) {

View file

@ -997,9 +997,6 @@ void output_render(struct sway_output *output, struct timespec *when,
} }
struct sway_container *fullscreen_con = root->fullscreen_global; struct sway_container *fullscreen_con = root->fullscreen_global;
if (fullscreen_con && container_is_scratchpad_hidden(fullscreen_con)) {
fullscreen_con = NULL;
}
if (!fullscreen_con) { if (!fullscreen_con) {
fullscreen_con = workspace->current.fullscreen; fullscreen_con = workspace->current.fullscreen;
} }

View file

@ -172,14 +172,14 @@ static void handle_seat_node_destroy(struct wl_listener *listener, void *data) {
seat_node_destroy(seat_node); seat_node_destroy(seat_node);
if (!parent) { if (!parent && !needs_new_focus) {
// Destroying a container that is no longer in the tree // Destroying a container that is no longer in the tree
return; return;
} }
// Find new focus_inactive (ie. sibling, or workspace if no siblings left) // Find new focus_inactive (ie. sibling, or workspace if no siblings left)
struct sway_node *next_focus = NULL; struct sway_node *next_focus = NULL;
while (next_focus == NULL) { while (next_focus == NULL && parent != NULL) {
struct sway_container *con = struct sway_container *con =
seat_get_focus_inactive_view(seat, parent); seat_get_focus_inactive_view(seat, parent);
next_focus = con ? &con->node : NULL; next_focus = con ? &con->node : NULL;
@ -192,6 +192,16 @@ static void handle_seat_node_destroy(struct wl_listener *listener, void *data) {
parent = node_get_parent(parent); parent = node_get_parent(parent);
} }
if (!next_focus) {
struct sway_workspace *ws = seat_get_last_known_workspace(seat);
if (!ws) {
return;
}
struct sway_container *con =
seat_get_focus_inactive_view(seat, &ws->node);
next_focus = con ? &(con->node) : &(ws->node);
}
if (next_focus->type == N_WORKSPACE && if (next_focus->type == N_WORKSPACE &&
!workspace_is_visible(next_focus->sway_workspace)) { !workspace_is_visible(next_focus->sway_workspace)) {
// Do not change focus to a non-visible workspace // Do not change focus to a non-visible workspace
@ -199,6 +209,10 @@ static void handle_seat_node_destroy(struct wl_listener *listener, void *data) {
} }
if (needs_new_focus) { if (needs_new_focus) {
// Make sure the workspace IPC event gets sent
if (node->type == N_CONTAINER && node->sway_container->scratchpad) {
seat_set_focus(seat, NULL);
}
// The structure change might have caused it to move up to the top of // The structure change might have caused it to move up to the top of
// the focus stack without sending focus notifications to the view // the focus stack without sending focus notifications to the view
seat_send_focus(next_focus, seat); seat_send_focus(next_focus, seat);
@ -207,7 +221,7 @@ static void handle_seat_node_destroy(struct wl_listener *listener, void *data) {
// Setting focus_inactive // Setting focus_inactive
focus = seat_get_focus_inactive(seat, &root->node); focus = seat_get_focus_inactive(seat, &root->node);
seat_set_raw_focus(seat, next_focus); seat_set_raw_focus(seat, next_focus);
if (focus->type == N_CONTAINER) { if (focus->type == N_CONTAINER && focus->sway_container->workspace) {
seat_set_raw_focus(seat, &focus->sway_container->workspace->node); seat_set_raw_focus(seat, &focus->sway_container->workspace->node);
} }
seat_set_raw_focus(seat, focus); seat_set_raw_focus(seat, focus);
@ -795,7 +809,13 @@ void seat_set_raw_focus(struct sway_seat *seat, struct sway_node *node) {
wl_list_remove(&seat_node->link); wl_list_remove(&seat_node->link);
wl_list_insert(&seat->focus_stack, &seat_node->link); wl_list_insert(&seat->focus_stack, &seat_node->link);
node_set_dirty(node); node_set_dirty(node);
node_set_dirty(node_get_parent(node));
// If focusing a scratchpad container that is fullscreen global, parent
// will be NULL
struct sway_node *parent = node_get_parent(node);
if (parent) {
node_set_dirty(parent);
}
} }
void seat_set_focus(struct sway_seat *seat, struct sway_node *node) { void seat_set_focus(struct sway_seat *seat, struct sway_node *node) {
@ -850,7 +870,8 @@ void seat_set_focus(struct sway_seat *seat, struct sway_node *node) {
} }
} }
struct sway_output *new_output = new_workspace->output; struct sway_output *new_output =
new_workspace ? new_workspace->output : NULL;
if (last_workspace != new_workspace && new_output) { if (last_workspace != new_workspace && new_output) {
node_set_dirty(&new_output->node); node_set_dirty(&new_output->node);
@ -894,7 +915,8 @@ void seat_set_focus(struct sway_seat *seat, struct sway_node *node) {
} }
// Move sticky containers to new workspace // Move sticky containers to new workspace
if (new_output_last_ws && new_workspace != new_output_last_ws) { if (new_workspace && new_output_last_ws
&& new_workspace != new_output_last_ws) {
for (int i = 0; i < new_output_last_ws->floating->length; ++i) { for (int i = 0; i < new_output_last_ws->floating->length; ++i) {
struct sway_container *floater = struct sway_container *floater =
new_output_last_ws->floating->items[i]; new_output_last_ws->floating->items[i];
@ -940,7 +962,7 @@ void seat_set_focus(struct sway_seat *seat, struct sway_node *node) {
seat->has_focus = true; seat->has_focus = true;
if (config->smart_gaps) { if (config->smart_gaps && new_workspace) {
// When smart gaps is on, gaps may change when the focus changes so // When smart gaps is on, gaps may change when the focus changes so
// the workspace needs to be arranged // the workspace needs to be arranged
arrange_workspace(new_workspace); arrange_workspace(new_workspace);
@ -1134,6 +1156,20 @@ struct sway_workspace *seat_get_focused_workspace(struct sway_seat *seat) {
return NULL; // output doesn't have a workspace yet return NULL; // output doesn't have a workspace yet
} }
struct sway_workspace *seat_get_last_known_workspace(struct sway_seat *seat) {
struct sway_seat_node *current;
wl_list_for_each(current, &seat->focus_stack, link) {
struct sway_node *node = current->node;
if (node->type == N_CONTAINER &&
node->sway_container->workspace) {
return node->sway_container->workspace;
} else if (node->type == N_WORKSPACE) {
return node->sway_workspace;
}
}
return NULL;
}
struct sway_container *seat_get_focused_container(struct sway_seat *seat) { struct sway_container *seat_get_focused_container(struct sway_seat *seat) {
struct sway_node *focus = seat_get_focus(seat); struct sway_node *focus = seat_get_focus(seat);
if (focus && focus->type == N_CONTAINER) { if (focus && focus->type == N_CONTAINER) {

View file

@ -95,6 +95,10 @@ void container_begin_destroy(struct sway_container *con) {
if (con->fullscreen_mode == FULLSCREEN_WORKSPACE && con->workspace) { if (con->fullscreen_mode == FULLSCREEN_WORKSPACE && con->workspace) {
con->workspace->fullscreen = NULL; 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); wl_signal_emit(&con->node.events.destroy, &con->node);
container_end_mouse_operation(con); container_end_mouse_operation(con);
@ -128,7 +132,9 @@ void container_reap_empty(struct sway_container *con) {
container_begin_destroy(con); container_begin_destroy(con);
con = parent; con = parent;
} }
if (ws) {
workspace_consider_destroy(ws); workspace_consider_destroy(ws);
}
} }
struct sway_container *container_flatten(struct sway_container *container) { struct sway_container *container_flatten(struct sway_container *container) {
@ -954,12 +960,13 @@ static void container_fullscreen_workspace(struct sway_container *con) {
set_fullscreen_iterator(con, &enable); set_fullscreen_iterator(con, &enable);
container_for_each_child(con, set_fullscreen_iterator, &enable); container_for_each_child(con, set_fullscreen_iterator, &enable);
con->workspace->fullscreen = con;
con->saved_x = con->x; con->saved_x = con->x;
con->saved_y = con->y; con->saved_y = con->y;
con->saved_width = con->width; con->saved_width = con->width;
con->saved_height = con->height; con->saved_height = con->height;
if (con->workspace) {
con->workspace->fullscreen = con;
struct sway_seat *seat; struct sway_seat *seat;
struct sway_workspace *focus_ws; struct sway_workspace *focus_ws;
wl_list_for_each(seat, &server.input->seats, link) { wl_list_for_each(seat, &server.input->seats, link) {
@ -968,6 +975,7 @@ static void container_fullscreen_workspace(struct sway_container *con) {
seat_set_focus_container(seat, con); seat_set_focus_container(seat, con);
} }
} }
}
con->fullscreen_mode = FULLSCREEN_WORKSPACE; con->fullscreen_mode = FULLSCREEN_WORKSPACE;
container_end_mouse_operation(con); container_end_mouse_operation(con);
@ -1019,13 +1027,16 @@ void container_fullscreen_disable(struct sway_container *con) {
con->height = con->saved_height; con->height = con->saved_height;
if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) { if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) {
if (con->workspace) {
con->workspace->fullscreen = NULL; con->workspace->fullscreen = NULL;
if (container_is_floating(con)) { if (container_is_floating(con)) {
struct sway_output *output = container_floating_find_output(con); struct sway_output *output =
container_floating_find_output(con);
if (con->workspace->output != output) { if (con->workspace->output != output) {
container_floating_move_to_center(con); container_floating_move_to_center(con);
} }
} }
}
} else { } else {
root->fullscreen_global = NULL; root->fullscreen_global = NULL;
} }
@ -1040,6 +1051,17 @@ void container_fullscreen_disable(struct sway_container *con) {
con->fullscreen_mode = FULLSCREEN_NONE; con->fullscreen_mode = FULLSCREEN_NONE;
container_end_mouse_operation(con); container_end_mouse_operation(con);
ipc_event_window(con, "fullscreen_mode"); 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, void container_set_fullscreen(struct sway_container *con,
@ -1056,7 +1078,7 @@ void container_set_fullscreen(struct sway_container *con,
if (root->fullscreen_global) { if (root->fullscreen_global) {
container_fullscreen_disable(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_disable(con->workspace->fullscreen);
} }
container_fullscreen_workspace(con); 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) { c->current_gaps.bottom > 0 || c->current_gaps.left > 0) {
return; 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 // Linear containers don't have gaps because it'd create double gaps
if (!c->view && c->layout != L_TABBED && c->layout != L_STACKED) { if (!c->view && c->layout != L_TABBED && c->layout != L_STACKED) {
return; 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.top = c->y == ws->y ? ws->gaps_inner : 0;
c->current_gaps.right = ws->gaps_inner; c->current_gaps.right = ws->gaps_inner;
c->current_gaps.bottom = 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->parent = parent;
child->workspace = parent->workspace; child->workspace = parent->workspace;
container_for_each_child(child, set_workspace, NULL); 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_handle_fullscreen_reparent(child);
container_update_representation(parent); container_update_representation(parent);
node_set_dirty(&child->node); node_set_dirty(&child->node);
@ -1347,8 +1376,31 @@ void container_detach(struct sway_container *child) {
void container_replace(struct sway_container *container, void container_replace(struct sway_container *container,
struct sway_container *replacement) { 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_add_sibling(container, replacement, 1);
container_detach(container); 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, struct sway_container *container_split(struct sway_container *child,
@ -1369,8 +1421,12 @@ struct sway_container *container_split(struct sway_container *child,
if (set_focus) { if (set_focus) {
seat_set_raw_focus(seat, &cont->node); seat_set_raw_focus(seat, &cont->node);
if (cont->fullscreen_mode == FULLSCREEN_GLOBAL) {
seat_set_focus(seat, &child->node);
} else {
seat_set_raw_focus(seat, &child->node); seat_set_raw_focus(seat, &child->node);
} }
}
return cont; return cont;
} }
@ -1529,7 +1585,7 @@ void container_raise_floating(struct sway_container *con) {
while (floater->parent) { while (floater->parent) {
floater = 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); list_move_to_end(floater->workspace->floating, floater);
node_set_dirty(&floater->workspace->node); node_set_dirty(&floater->workspace->node);
} }

View file

@ -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) { 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); struct sway_node *parent = node_get_parent(node);
while (parent) { while (parent) {
if (parent == ancestor) { if (parent == ancestor) {
return true; 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); parent = node_get_parent(parent);
} }
return false; return false;

View file

@ -62,6 +62,11 @@ void root_scratchpad_add_container(struct sway_container *con) {
struct sway_container *parent = con->parent; struct sway_container *parent = con->parent;
struct sway_workspace *workspace = con->workspace; 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. // When a tiled window is sent to scratchpad, center and resize it.
if (!container_is_floating(con)) { if (!container_is_floating(con)) {
container_set_floating(con, true); 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_node *focus = seat_get_focus_inactive(seat, &root->node);
struct sway_workspace *ws = con->workspace; 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); container_detach(con);
arrange_workspace(ws); arrange_workspace(ws);
if (&con->node == focus || node_has_ancestor(focus, &con->node)) { if (&con->node == focus || node_has_ancestor(focus, &con->node)) {

View file

@ -197,10 +197,11 @@ static bool gaps_to_edge(struct sway_view *view) {
void view_autoconfigure(struct sway_view *view) { void view_autoconfigure(struct sway_view *view) {
struct sway_container *con = view->container; struct sway_container *con = view->container;
if (container_is_scratchpad_hidden(con)) { if (container_is_scratchpad_hidden(con) &&
con->fullscreen_mode != FULLSCREEN_GLOBAL) {
return; return;
} }
struct sway_output *output = con->workspace->output; struct sway_output *output = con->workspace ? con->workspace->output : NULL;
if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) { if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) {
con->content_x = output->lx; con->content_x = output->lx;
@ -226,6 +227,7 @@ void view_autoconfigure(struct sway_view *view) {
con->border_top = con->border_bottom = true; con->border_top = con->border_bottom = true;
con->border_left = con->border_right = true; con->border_left = con->border_right = true;
if (ws) {
if (config->hide_edge_borders == E_BOTH if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_VERTICAL || config->hide_edge_borders == E_VERTICAL
|| (smart && !other_views && no_gaps)) { || (smart && !other_views && no_gaps)) {
@ -240,6 +242,7 @@ void view_autoconfigure(struct sway_view *view) {
int bottom_y = con->y + con->height + con->current_gaps.bottom; int bottom_y = con->y + con->height + con->current_gaps.bottom;
con->border_bottom = bottom_y != ws->y + ws->height; con->border_bottom = bottom_y != ws->y + ws->height;
} }
}
double y_offset = 0; 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, // 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. // bar, and disable any top border because we'll always have the title bar.
list_t *siblings = container_get_siblings(con); 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)) { if (show_titlebar && !container_is_floating(con)) {
enum sway_container_layout layout = container_parent_layout(con); enum sway_container_layout layout = container_parent_layout(con);
if (layout == L_TABBED) { 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 *prev_ws = seat_get_focused_workspace(seat);
struct sway_workspace *map_ws = view->container->workspace; 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 // Views can only take focus if they are mapped into the active workspace
if (prev_ws != map_ws) { if (prev_ws != map_ws) {
return false; 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_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 ? struct sway_container *target_sibling = node->type == N_CONTAINER ?
node->sway_container : NULL; 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. // launch it as a tiled view in the root of the workspace instead.
if (target_sibling && container_is_floating(target_sibling)) { if (target_sibling && container_is_floating(target_sibling)) {
target_sibling = NULL; target_sibling = NULL;
ws = seat_get_last_known_workspace(seat);
} }
view->container = container_create(view); view->container = container_create(view);
if (target_sibling) { if (target_sibling) {
container_add_sibling(target_sibling, view->container, 1); container_add_sibling(target_sibling, view->container, 1);
} else { } else if (ws) {
workspace_add_tiling(ws, view->container); workspace_add_tiling(ws, view->container);
} }
ipc_event_window(view->container, "new"); ipc_event_window(view->container, "new");
@ -1032,16 +1042,26 @@ bool view_is_visible(struct sway_view *view) {
return false; return false;
} }
struct sway_workspace *workspace = view->container->workspace; struct sway_workspace *workspace = view->container->workspace;
if (!workspace) { 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; return false;
} }
}
// Determine if view is nested inside a floating container which is sticky // Determine if view is nested inside a floating container which is sticky
struct sway_container *floater = view->container; struct sway_container *floater = view->container;
while (floater->parent) { while (floater->parent) {
floater = floater->parent; floater = floater->parent;
} }
bool is_sticky = container_is_floating(floater) && floater->is_sticky; 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; return false;
} }
// Check view isn't in a tabbed or stacked container on an inactive tab // Check view isn't in a tabbed or stacked container on an inactive tab