mirror of
https://github.com/swaywm/sway.git
synced 2026-04-21 06:46:22 -04:00
container: Move pending state to state struct
Pending state is currently inlined directly in the container struct, while the current state is in a state struct. A side-effect of this is that it is not immediately obvious that pending double-buffered state is accessed, nor is it obvious what state is double-buffered. Instead, use the state struct for both current and pending.
This commit is contained in:
parent
28cadf5580
commit
a047b5ee4a
33 changed files with 723 additions and 757 deletions
208
sway/tree/view.c
208
sway/tree/view.c
|
|
@ -206,7 +206,7 @@ bool view_ancestor_is_only_visible(struct sway_view *view) {
|
|||
} else {
|
||||
only_visible = true;
|
||||
}
|
||||
con = con->parent;
|
||||
con = con->pending.parent;
|
||||
}
|
||||
return only_visible;
|
||||
}
|
||||
|
|
@ -222,58 +222,58 @@ static bool view_is_only_visible(struct sway_view *view) {
|
|||
}
|
||||
}
|
||||
|
||||
con = con->parent;
|
||||
con = con->pending.parent;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool gaps_to_edge(struct sway_view *view) {
|
||||
struct side_gaps gaps = view->container->workspace->current_gaps;
|
||||
struct side_gaps gaps = view->container->pending.workspace->current_gaps;
|
||||
return gaps.top > 0 || gaps.right > 0 || gaps.bottom > 0 || gaps.left > 0;
|
||||
}
|
||||
|
||||
void view_autoconfigure(struct sway_view *view) {
|
||||
struct sway_container *con = view->container;
|
||||
struct sway_workspace *ws = con->workspace;
|
||||
struct sway_workspace *ws = con->pending.workspace;
|
||||
|
||||
if (container_is_scratchpad_hidden(con) &&
|
||||
con->fullscreen_mode != FULLSCREEN_GLOBAL) {
|
||||
con->pending.fullscreen_mode != FULLSCREEN_GLOBAL) {
|
||||
return;
|
||||
}
|
||||
struct sway_output *output = ws ? ws->output : NULL;
|
||||
|
||||
if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) {
|
||||
con->content_x = output->lx;
|
||||
con->content_y = output->ly;
|
||||
con->content_width = output->width;
|
||||
con->content_height = output->height;
|
||||
if (con->pending.fullscreen_mode == FULLSCREEN_WORKSPACE) {
|
||||
con->pending.content_x = output->lx;
|
||||
con->pending.content_y = output->ly;
|
||||
con->pending.content_width = output->width;
|
||||
con->pending.content_height = output->height;
|
||||
return;
|
||||
} else if (con->fullscreen_mode == FULLSCREEN_GLOBAL) {
|
||||
con->content_x = root->x;
|
||||
con->content_y = root->y;
|
||||
con->content_width = root->width;
|
||||
con->content_height = root->height;
|
||||
} else if (con->pending.fullscreen_mode == FULLSCREEN_GLOBAL) {
|
||||
con->pending.content_x = root->x;
|
||||
con->pending.content_y = root->y;
|
||||
con->pending.content_width = root->width;
|
||||
con->pending.content_height = root->height;
|
||||
return;
|
||||
}
|
||||
|
||||
con->border_top = con->border_bottom = true;
|
||||
con->border_left = con->border_right = true;
|
||||
con->pending.border_top = con->pending.border_bottom = true;
|
||||
con->pending.border_left = con->pending.border_right = true;
|
||||
double y_offset = 0;
|
||||
|
||||
if (!container_is_floating(con) && ws) {
|
||||
if (config->hide_edge_borders == E_BOTH
|
||||
|| config->hide_edge_borders == E_VERTICAL) {
|
||||
con->border_left = con->x != ws->x;
|
||||
int right_x = con->x + con->width;
|
||||
con->border_right = right_x != ws->x + ws->width;
|
||||
con->pending.border_left = con->pending.x != ws->x;
|
||||
int right_x = con->pending.x + con->pending.width;
|
||||
con->pending.border_right = right_x != ws->x + ws->width;
|
||||
}
|
||||
|
||||
if (config->hide_edge_borders == E_BOTH
|
||||
|| config->hide_edge_borders == E_HORIZONTAL) {
|
||||
con->border_top = con->y != ws->y;
|
||||
int bottom_y = con->y + con->height;
|
||||
con->border_bottom = bottom_y != ws->y + ws->height;
|
||||
con->pending.border_top = con->pending.y != ws->y;
|
||||
int bottom_y = con->pending.y + con->pending.height;
|
||||
con->pending.border_bottom = bottom_y != ws->y + ws->height;
|
||||
}
|
||||
|
||||
bool smart = config->hide_edge_borders_smart == ESMART_ON ||
|
||||
|
|
@ -282,10 +282,10 @@ void view_autoconfigure(struct sway_view *view) {
|
|||
if (smart) {
|
||||
bool show_border = container_is_floating_or_child(con) ||
|
||||
!view_is_only_visible(view);
|
||||
con->border_left &= show_border;
|
||||
con->border_right &= show_border;
|
||||
con->border_top &= show_border;
|
||||
con->border_bottom &= show_border;
|
||||
con->pending.border_left &= show_border;
|
||||
con->pending.border_right &= show_border;
|
||||
con->pending.border_top &= show_border;
|
||||
con->pending.border_bottom &= show_border;
|
||||
}
|
||||
|
||||
// In a tabbed or stacked container, the container's y is the top of the
|
||||
|
|
@ -298,56 +298,56 @@ void view_autoconfigure(struct sway_view *view) {
|
|||
enum sway_container_layout layout = container_parent_layout(con);
|
||||
if (layout == L_TABBED) {
|
||||
y_offset = container_titlebar_height();
|
||||
con->border_top = false;
|
||||
con->pending.border_top = false;
|
||||
} else if (layout == L_STACKED) {
|
||||
y_offset = container_titlebar_height() * siblings->length;
|
||||
con->border_top = false;
|
||||
con->pending.border_top = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double x, y, width, height;
|
||||
switch (con->border) {
|
||||
switch (con->pending.border) {
|
||||
default:
|
||||
case B_CSD:
|
||||
case B_NONE:
|
||||
x = con->x;
|
||||
y = con->y + y_offset;
|
||||
width = con->width;
|
||||
height = con->height - y_offset;
|
||||
x = con->pending.x;
|
||||
y = con->pending.y + y_offset;
|
||||
width = con->pending.width;
|
||||
height = con->pending.height - y_offset;
|
||||
break;
|
||||
case B_PIXEL:
|
||||
x = con->x + con->border_thickness * con->border_left;
|
||||
y = con->y + con->border_thickness * con->border_top + y_offset;
|
||||
width = con->width
|
||||
- con->border_thickness * con->border_left
|
||||
- con->border_thickness * con->border_right;
|
||||
height = con->height - y_offset
|
||||
- con->border_thickness * con->border_top
|
||||
- con->border_thickness * con->border_bottom;
|
||||
x = con->pending.x + con->pending.border_thickness * con->pending.border_left;
|
||||
y = con->pending.y + con->pending.border_thickness * con->pending.border_top + y_offset;
|
||||
width = con->pending.width
|
||||
- con->pending.border_thickness * con->pending.border_left
|
||||
- con->pending.border_thickness * con->pending.border_right;
|
||||
height = con->pending.height - y_offset
|
||||
- con->pending.border_thickness * con->pending.border_top
|
||||
- con->pending.border_thickness * con->pending.border_bottom;
|
||||
break;
|
||||
case B_NORMAL:
|
||||
// Height is: 1px border + 3px pad + title height + 3px pad + 1px border
|
||||
x = con->x + con->border_thickness * con->border_left;
|
||||
width = con->width
|
||||
- con->border_thickness * con->border_left
|
||||
- con->border_thickness * con->border_right;
|
||||
x = con->pending.x + con->pending.border_thickness * con->pending.border_left;
|
||||
width = con->pending.width
|
||||
- con->pending.border_thickness * con->pending.border_left
|
||||
- con->pending.border_thickness * con->pending.border_right;
|
||||
if (y_offset) {
|
||||
y = con->y + y_offset;
|
||||
height = con->height - y_offset
|
||||
- con->border_thickness * con->border_bottom;
|
||||
y = con->pending.y + y_offset;
|
||||
height = con->pending.height - y_offset
|
||||
- con->pending.border_thickness * con->pending.border_bottom;
|
||||
} else {
|
||||
y = con->y + container_titlebar_height();
|
||||
height = con->height - container_titlebar_height()
|
||||
- con->border_thickness * con->border_bottom;
|
||||
y = con->pending.y + container_titlebar_height();
|
||||
height = con->pending.height - container_titlebar_height()
|
||||
- con->pending.border_thickness * con->pending.border_bottom;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
con->content_x = x;
|
||||
con->content_y = y;
|
||||
con->content_width = width;
|
||||
con->content_height = height;
|
||||
con->pending.content_x = x;
|
||||
con->pending.content_y = y;
|
||||
con->pending.content_width = width;
|
||||
con->pending.content_height = height;
|
||||
}
|
||||
|
||||
void view_set_activated(struct sway_view *view, bool activated) {
|
||||
|
|
@ -361,7 +361,7 @@ void view_set_activated(struct sway_view *view, bool activated) {
|
|||
}
|
||||
|
||||
void view_request_activate(struct sway_view *view) {
|
||||
struct sway_workspace *ws = view->container->workspace;
|
||||
struct sway_workspace *ws = view->container->pending.workspace;
|
||||
if (!ws) { // hidden scratchpad container
|
||||
return;
|
||||
}
|
||||
|
|
@ -401,13 +401,13 @@ void view_set_csd_from_server(struct sway_view *view, bool enabled) {
|
|||
void view_update_csd_from_client(struct sway_view *view, bool enabled) {
|
||||
sway_log(SWAY_DEBUG, "View %p updated CSD to %i", view, enabled);
|
||||
struct sway_container *con = view->container;
|
||||
if (enabled && con && con->border != B_CSD) {
|
||||
con->saved_border = con->border;
|
||||
if (enabled && con && con->pending.border != B_CSD) {
|
||||
con->saved_border = con->pending.border;
|
||||
if (container_is_floating(con)) {
|
||||
con->border = B_CSD;
|
||||
con->pending.border = B_CSD;
|
||||
}
|
||||
} else if (!enabled && con && con->border == B_CSD) {
|
||||
con->border = con->saved_border;
|
||||
} else if (!enabled && con && con->pending.border == B_CSD) {
|
||||
con->pending.border = con->saved_border;
|
||||
}
|
||||
view->using_csd = enabled;
|
||||
}
|
||||
|
|
@ -577,7 +577,7 @@ static struct sway_workspace *select_workspace(struct sway_view *view) {
|
|||
if (node && node->type == N_WORKSPACE) {
|
||||
return node->sway_workspace;
|
||||
} else if (node && node->type == N_CONTAINER) {
|
||||
return node->sway_container->workspace;
|
||||
return node->sway_container->pending.workspace;
|
||||
}
|
||||
|
||||
// When there's no outputs connected, the above should match a workspace on
|
||||
|
|
@ -590,9 +590,9 @@ static bool should_focus(struct sway_view *view) {
|
|||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_container *prev_con = seat_get_focused_container(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->pending.workspace;
|
||||
|
||||
if (view->container->fullscreen_mode == FULLSCREEN_GLOBAL) {
|
||||
if (view->container->pending.fullscreen_mode == FULLSCREEN_GLOBAL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -603,9 +603,9 @@ static bool should_focus(struct sway_view *view) {
|
|||
|
||||
// If the view is the only one in the focused workspace, it'll get focus
|
||||
// regardless of any no_focus criteria.
|
||||
if (!view->container->parent && !prev_con) {
|
||||
size_t num_children = view->container->workspace->tiling->length +
|
||||
view->container->workspace->floating->length;
|
||||
if (!view->container->pending.parent && !prev_con) {
|
||||
size_t num_children = view->container->pending.workspace->tiling->length +
|
||||
view->container->pending.workspace->floating->length;
|
||||
if (num_children == 1) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -645,9 +645,9 @@ static void handle_foreign_fullscreen_request(
|
|||
|
||||
// Match fullscreen command behavior for scratchpad hidden views
|
||||
struct sway_container *container = view->container;
|
||||
if (!container->workspace) {
|
||||
while (container->parent) {
|
||||
container = container->parent;
|
||||
if (!container->pending.workspace) {
|
||||
while (container->pending.parent) {
|
||||
container = container->pending.parent;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -668,10 +668,10 @@ static void handle_foreign_fullscreen_request(
|
|||
if (event->fullscreen) {
|
||||
arrange_root();
|
||||
} else {
|
||||
if (container->parent) {
|
||||
arrange_container(container->parent);
|
||||
} else if (container->workspace) {
|
||||
arrange_workspace(container->workspace);
|
||||
if (container->pending.parent) {
|
||||
arrange_container(container->pending.parent);
|
||||
} else if (container->pending.workspace) {
|
||||
arrange_workspace(container->pending.workspace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -762,20 +762,20 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
|
|||
}
|
||||
|
||||
if (view->impl->wants_floating && view->impl->wants_floating(view)) {
|
||||
view->container->border = config->floating_border;
|
||||
view->container->border_thickness = config->floating_border_thickness;
|
||||
view->container->pending.border = config->floating_border;
|
||||
view->container->pending.border_thickness = config->floating_border_thickness;
|
||||
container_set_floating(view->container, true);
|
||||
} else {
|
||||
view->container->border = config->border;
|
||||
view->container->border_thickness = config->border_thickness;
|
||||
view->container->pending.border = config->border;
|
||||
view->container->pending.border_thickness = config->border_thickness;
|
||||
view_set_tiled(view, true);
|
||||
}
|
||||
|
||||
if (config->popup_during_fullscreen == POPUP_LEAVE &&
|
||||
container->workspace &&
|
||||
container->workspace->fullscreen &&
|
||||
container->workspace->fullscreen->view) {
|
||||
struct sway_container *fs = container->workspace->fullscreen;
|
||||
container->pending.workspace &&
|
||||
container->pending.workspace->fullscreen &&
|
||||
container->pending.workspace->fullscreen->view) {
|
||||
struct sway_container *fs = container->pending.workspace->fullscreen;
|
||||
if (view_is_transient_for(view, fs->view)) {
|
||||
container_set_fullscreen(fs, false);
|
||||
}
|
||||
|
|
@ -786,12 +786,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
|
|||
|
||||
if (fullscreen) {
|
||||
container_set_fullscreen(view->container, true);
|
||||
arrange_workspace(view->container->workspace);
|
||||
arrange_workspace(view->container->pending.workspace);
|
||||
} else {
|
||||
if (container->parent) {
|
||||
arrange_container(container->parent);
|
||||
} else if (container->workspace) {
|
||||
arrange_workspace(container->workspace);
|
||||
if (container->pending.parent) {
|
||||
arrange_container(container->pending.parent);
|
||||
} else if (container->pending.workspace) {
|
||||
arrange_workspace(container->pending.workspace);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -838,8 +838,8 @@ void view_unmap(struct sway_view *view) {
|
|||
view->foreign_toplevel = NULL;
|
||||
}
|
||||
|
||||
struct sway_container *parent = view->container->parent;
|
||||
struct sway_workspace *ws = view->container->workspace;
|
||||
struct sway_container *parent = view->container->pending.parent;
|
||||
struct sway_workspace *ws = view->container->pending.workspace;
|
||||
container_begin_destroy(view->container);
|
||||
if (parent) {
|
||||
container_reap_empty(parent);
|
||||
|
|
@ -874,8 +874,8 @@ void view_unmap(struct sway_view *view) {
|
|||
|
||||
void view_update_size(struct sway_view *view) {
|
||||
struct sway_container *con = view->container;
|
||||
con->content_width = view->geometry.width;
|
||||
con->content_height = view->geometry.height;
|
||||
con->pending.content_width = view->geometry.width;
|
||||
con->pending.content_height = view->geometry.height;
|
||||
container_set_geometry_from_content(con);
|
||||
}
|
||||
|
||||
|
|
@ -989,8 +989,8 @@ static void view_child_damage(struct sway_view_child *child, bool whole) {
|
|||
int sx, sy;
|
||||
child->impl->get_root_coords(child, &sx, &sy);
|
||||
desktop_damage_surface(child->surface,
|
||||
child->view->container->content_x + sx,
|
||||
child->view->container->content_y + sy, whole);
|
||||
child->view->container->pending.content_x + sx,
|
||||
child->view->container->pending.content_y + sy, whole);
|
||||
}
|
||||
|
||||
static void view_child_handle_surface_commit(struct wl_listener *listener,
|
||||
|
|
@ -1073,7 +1073,7 @@ void view_child_init(struct sway_view_child *child,
|
|||
wl_signal_add(&view->events.unmap, &child->view_unmap);
|
||||
child->view_unmap.notify = view_child_handle_view_unmap;
|
||||
|
||||
struct sway_workspace *workspace = child->view->container->workspace;
|
||||
struct sway_workspace *workspace = child->view->container->pending.workspace;
|
||||
if (workspace) {
|
||||
wlr_surface_send_enter(child->surface, workspace->output->wlr_output);
|
||||
}
|
||||
|
|
@ -1256,15 +1256,15 @@ bool view_is_visible(struct sway_view *view) {
|
|||
if (view->container->node.destroying) {
|
||||
return false;
|
||||
}
|
||||
struct sway_workspace *workspace = view->container->workspace;
|
||||
if (!workspace && view->container->fullscreen_mode != FULLSCREEN_GLOBAL) {
|
||||
struct sway_workspace *workspace = view->container->pending.workspace;
|
||||
if (!workspace && view->container->pending.fullscreen_mode != FULLSCREEN_GLOBAL) {
|
||||
bool fs_global_descendant = false;
|
||||
struct sway_container *parent = view->container->parent;
|
||||
struct sway_container *parent = view->container->pending.parent;
|
||||
while (parent) {
|
||||
if (parent->fullscreen_mode == FULLSCREEN_GLOBAL) {
|
||||
if (parent->pending.fullscreen_mode == FULLSCREEN_GLOBAL) {
|
||||
fs_global_descendant = true;
|
||||
}
|
||||
parent = parent->parent;
|
||||
parent = parent->pending.parent;
|
||||
}
|
||||
if (!fs_global_descendant) {
|
||||
return false;
|
||||
|
|
@ -1282,13 +1282,13 @@ bool view_is_visible(struct sway_view *view) {
|
|||
enum sway_container_layout layout = container_parent_layout(con);
|
||||
if ((layout == L_TABBED || layout == L_STACKED)
|
||||
&& !container_is_floating(con)) {
|
||||
struct sway_node *parent = con->parent ?
|
||||
&con->parent->node : &con->workspace->node;
|
||||
struct sway_node *parent = con->pending.parent ?
|
||||
&con->pending.parent->node : &con->pending.workspace->node;
|
||||
if (seat_get_active_tiling_child(seat, parent) != &con->node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
con = con->parent;
|
||||
con = con->pending.parent;
|
||||
}
|
||||
// Check view isn't hidden by another fullscreen view
|
||||
struct sway_container *fs = root->fullscreen_global ?
|
||||
|
|
@ -1322,7 +1322,7 @@ void view_set_urgent(struct sway_view *view, bool enable) {
|
|||
ipc_event_window(view->container, "urgent");
|
||||
|
||||
if (!container_is_scratchpad_hidden(view->container)) {
|
||||
workspace_detect_urgent(view->container->workspace);
|
||||
workspace_detect_urgent(view->container->pending.workspace);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue