Merge pull request #3040 from RyanDwyer/border-props-to-container

Move view border properties to container struct
This commit is contained in:
Drew DeVault 2018-11-01 01:03:41 +01:00 committed by GitHub
commit 480b03b734
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 98 additions and 98 deletions

View file

@ -53,16 +53,16 @@ struct sway_container_state {
struct sway_container *focused_inactive_child; struct sway_container *focused_inactive_child;
bool focused; bool focused;
// View properties
double view_x, view_y;
double view_width, view_height;
enum sway_container_border border; enum sway_container_border border;
int border_thickness; int border_thickness;
bool border_top; bool border_top;
bool border_bottom; bool border_bottom;
bool border_left; bool border_left;
bool border_right; bool border_right;
// View properties
double view_x, view_y;
double view_width, view_height;
}; };
struct sway_container { struct sway_container {
@ -91,6 +91,18 @@ struct sway_container {
bool is_fullscreen; bool is_fullscreen;
enum sway_container_border border;
// Used when the view changes to CSD unexpectedly. This will be a non-B_CSD
// border which we use to restore when the view returns to SSD.
enum sway_container_border saved_border;
int border_thickness;
bool border_top;
bool border_bottom;
bool border_left;
bool border_right;
// The gaps currently applied to the container. // The gaps currently applied to the container.
double current_gaps; double current_gaps;

View file

@ -80,24 +80,8 @@ struct sway_view {
char *title_format; char *title_format;
// Our border types are B_NONE, B_PIXEL, B_NORMAL and B_CSD. We normally
// just assign this to the border property and ignore the other two.
// However, when a view using CSD is tiled, we want to render our own
// borders as well. So in this case the border property becomes one of the
// first three, and using_csd is true.
// Lastly, views can change their decoration mode at any time. When an SSD
// view becomes CSD without our approval, we save the SSD border type so it
// can be restored if/when the view returns from CSD to SSD.
enum sway_container_border border;
enum sway_container_border saved_border;
bool using_csd; bool using_csd;
int border_thickness;
bool border_top;
bool border_bottom;
bool border_left;
bool border_right;
struct timespec urgent; struct timespec urgent;
bool allow_request_urgent; bool allow_request_urgent;
struct wl_event_source *urgent_timer; struct wl_event_source *urgent_timer;

View file

@ -12,37 +12,41 @@
// in use (we set using_csd instead and render a sway border). // in use (we set using_csd instead and render a sway border).
// - view->saved_border should be the last applied border when switching to CSD. // - view->saved_border should be the last applied border when switching to CSD.
// - view->using_csd should always reflect whether CSD is applied or not. // - view->using_csd should always reflect whether CSD is applied or not.
static void set_border(struct sway_view *view, static void set_border(struct sway_container *con,
enum sway_container_border new_border) { enum sway_container_border new_border) {
if (view->using_csd && new_border != B_CSD) { if (con->view) {
view_set_csd_from_server(view, false); if (con->view->using_csd && new_border != B_CSD) {
} else if (!view->using_csd && new_border == B_CSD) { view_set_csd_from_server(con->view, false);
view_set_csd_from_server(view, true); } else if (!con->view->using_csd && new_border == B_CSD) {
view->saved_border = view->border; view_set_csd_from_server(con->view, true);
con->saved_border = con->border;
} }
if (new_border != B_CSD || container_is_floating(view->container)) {
view->border = new_border;
} }
view->using_csd = new_border == B_CSD; if (new_border != B_CSD || container_is_floating(con)) {
con->border = new_border;
}
if (con->view) {
con->view->using_csd = new_border == B_CSD;
}
} }
static void border_toggle(struct sway_view *view) { static void border_toggle(struct sway_container *con) {
if (view->using_csd) { if (con->view && con->view->using_csd) {
set_border(view, B_NONE); set_border(con, B_NONE);
return; return;
} }
switch (view->border) { switch (con->border) {
case B_NONE: case B_NONE:
set_border(view, B_PIXEL); set_border(con, B_PIXEL);
break; break;
case B_PIXEL: case B_PIXEL:
set_border(view, B_NORMAL); set_border(con, B_NORMAL);
break; break;
case B_NORMAL: case B_NORMAL:
if (view->xdg_decoration) { if (con->view && con->view->xdg_decoration) {
set_border(view, B_CSD); set_border(con, B_CSD);
} else { } else {
set_border(view, B_NONE); set_border(con, B_NONE);
} }
break; break;
case B_CSD: case B_CSD:
@ -66,33 +70,33 @@ struct cmd_results *cmd_border(int argc, char **argv) {
struct sway_view *view = container->view; struct sway_view *view = container->view;
if (strcmp(argv[0], "none") == 0) { if (strcmp(argv[0], "none") == 0) {
set_border(view, B_NONE); set_border(container, B_NONE);
} else if (strcmp(argv[0], "normal") == 0) { } else if (strcmp(argv[0], "normal") == 0) {
set_border(view, B_NORMAL); set_border(container, B_NORMAL);
} else if (strcmp(argv[0], "pixel") == 0) { } else if (strcmp(argv[0], "pixel") == 0) {
set_border(view, B_PIXEL); set_border(container, B_PIXEL);
} else if (strcmp(argv[0], "csd") == 0) { } else if (strcmp(argv[0], "csd") == 0) {
if (!view->xdg_decoration) { if (!view || !view->xdg_decoration) {
return cmd_results_new(CMD_INVALID, "border", return cmd_results_new(CMD_INVALID, "border",
"This window doesn't support client side decorations"); "This window doesn't support client side decorations");
} }
set_border(view, B_CSD); set_border(container, B_CSD);
} else if (strcmp(argv[0], "toggle") == 0) { } else if (strcmp(argv[0], "toggle") == 0) {
border_toggle(view); border_toggle(container);
} else { } else {
return cmd_results_new(CMD_INVALID, "border", return cmd_results_new(CMD_INVALID, "border",
"Expected 'border <none|normal|pixel|csd|toggle>' " "Expected 'border <none|normal|pixel|csd|toggle>' "
"or 'border pixel <px>'"); "or 'border pixel <px>'");
} }
if (argc == 2) { if (argc == 2) {
view->border_thickness = atoi(argv[1]); container->border_thickness = atoi(argv[1]);
} }
if (container_is_floating(view->container)) { if (container_is_floating(container)) {
container_set_geometry_from_floating_view(view->container); container_set_geometry_from_floating_view(container);
} }
arrange_container(view->container); arrange_container(container);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -137,6 +137,12 @@ static void copy_container_state(struct sway_container *container,
state->is_fullscreen = container->is_fullscreen; state->is_fullscreen = container->is_fullscreen;
state->parent = container->parent; state->parent = container->parent;
state->workspace = container->workspace; state->workspace = container->workspace;
state->border = container->border;
state->border_thickness = container->border_thickness;
state->border_top = container->border_top;
state->border_left = container->border_left;
state->border_right = container->border_right;
state->border_bottom = container->border_bottom;
if (container->view) { if (container->view) {
struct sway_view *view = container->view; struct sway_view *view = container->view;
@ -144,12 +150,6 @@ static void copy_container_state(struct sway_container *container,
state->view_y = view->y; state->view_y = view->y;
state->view_width = view->width; state->view_width = view->width;
state->view_height = view->height; state->view_height = view->height;
state->border = view->border;
state->border_thickness = view->border_thickness;
state->border_top = view->border_top;
state->border_left = view->border_left;
state->border_right = view->border_right;
state->border_bottom = view->border_bottom;
} else { } else {
state->children = create_list(); state->children = create_list();
list_cat(state->children, container->children); list_cat(state->children, container->children);

View file

@ -187,23 +187,22 @@ static enum wlr_edges find_edge(struct sway_container *cont,
if (!cont->view) { if (!cont->view) {
return WLR_EDGE_NONE; return WLR_EDGE_NONE;
} }
struct sway_view *view = cont->view; if (cont->border == B_NONE || !cont->border_thickness ||
if (view->border == B_NONE || !view->border_thickness || cont->border == B_CSD) {
view->border == B_CSD) {
return WLR_EDGE_NONE; return WLR_EDGE_NONE;
} }
enum wlr_edges edge = 0; enum wlr_edges edge = 0;
if (cursor->cursor->x < cont->x + view->border_thickness) { if (cursor->cursor->x < cont->x + cont->border_thickness) {
edge |= WLR_EDGE_LEFT; edge |= WLR_EDGE_LEFT;
} }
if (cursor->cursor->y < cont->y + view->border_thickness) { if (cursor->cursor->y < cont->y + cont->border_thickness) {
edge |= WLR_EDGE_TOP; edge |= WLR_EDGE_TOP;
} }
if (cursor->cursor->x >= cont->x + cont->width - view->border_thickness) { if (cursor->cursor->x >= cont->x + cont->width - cont->border_thickness) {
edge |= WLR_EDGE_RIGHT; edge |= WLR_EDGE_RIGHT;
} }
if (cursor->cursor->y >= cont->y + cont->height - view->border_thickness) { if (cursor->cursor->y >= cont->y + cont->height - cont->border_thickness) {
edge |= WLR_EDGE_BOTTOM; edge |= WLR_EDGE_BOTTOM;
} }

View file

@ -639,8 +639,8 @@ void container_init_floating(struct sway_container *con) {
view->y = ws->y + (ws->height - view->height) / 2; view->y = ws->y + (ws->height - view->height) / 2;
// If the view's border is B_NONE then these properties are ignored. // If the view's border is B_NONE then these properties are ignored.
view->border_top = view->border_bottom = true; con->border_top = con->border_bottom = true;
view->border_left = view->border_right = true; con->border_left = con->border_right = true;
container_set_geometry_from_floating_view(con); container_set_geometry_from_floating_view(con);
} }
@ -662,7 +662,7 @@ void container_set_floating(struct sway_container *container, bool enable) {
if (container->view) { if (container->view) {
view_set_tiled(container->view, false); view_set_tiled(container->view, false);
if (container->view->using_csd) { if (container->view->using_csd) {
container->view->border = B_CSD; container->border = B_CSD;
} }
} }
if (old_parent) { if (old_parent) {
@ -688,7 +688,7 @@ void container_set_floating(struct sway_container *container, bool enable) {
if (container->view) { if (container->view) {
view_set_tiled(container->view, true); view_set_tiled(container->view, true);
if (container->view->using_csd) { if (container->view->using_csd) {
container->view->border = container->view->saved_border; container->border = container->saved_border;
} }
} }
container->is_sticky = false; container->is_sticky = false;
@ -710,9 +710,9 @@ void container_set_geometry_from_floating_view(struct sway_container *con) {
size_t border_width = 0; size_t border_width = 0;
size_t top = 0; size_t top = 0;
if (view->border != B_CSD) { if (con->border != B_CSD) {
border_width = view->border_thickness * (view->border != B_NONE); border_width = con->border_thickness * (con->border != B_NONE);
top = view->border == B_NORMAL ? top = con->border == B_NORMAL ?
container_titlebar_height() : border_width; container_titlebar_height() : border_width;
} }

View file

@ -225,21 +225,21 @@ void view_autoconfigure(struct sway_view *view) {
bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS
|| !gaps_to_edge(view); || !gaps_to_edge(view);
view->border_top = view->border_bottom = true; con->border_top = con->border_bottom = true;
view->border_left = view->border_right = true; con->border_left = con->border_right = true;
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)) {
view->border_left = con->x - con->current_gaps != ws->x; con->border_left = con->x - con->current_gaps != ws->x;
int right_x = con->x + con->width + con->current_gaps; int right_x = con->x + con->width + con->current_gaps;
view->border_right = right_x != ws->x + ws->width; con->border_right = right_x != ws->x + ws->width;
} }
if (config->hide_edge_borders == E_BOTH if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_HORIZONTAL || config->hide_edge_borders == E_HORIZONTAL
|| (smart && !other_views && no_gaps)) { || (smart && !other_views && no_gaps)) {
view->border_top = con->y - con->current_gaps != ws->y; con->border_top = con->y - con->current_gaps != ws->y;
int bottom_y = con->y + con->height + con->current_gaps; int bottom_y = con->y + con->height + con->current_gaps;
view->border_bottom = bottom_y != ws->y + ws->height; con->border_bottom = bottom_y != ws->y + ws->height;
} }
double x, y, width, height; double x, y, width, height;
@ -252,14 +252,14 @@ void view_autoconfigure(struct sway_view *view) {
enum sway_container_layout layout = container_parent_layout(con); enum sway_container_layout layout = container_parent_layout(con);
if (layout == L_TABBED && !container_is_floating(con)) { if (layout == L_TABBED && !container_is_floating(con)) {
y_offset = container_titlebar_height(); y_offset = container_titlebar_height();
view->border_top = false; con->border_top = false;
} else if (layout == L_STACKED && !container_is_floating(con)) { } else if (layout == L_STACKED && !container_is_floating(con)) {
list_t *siblings = container_get_siblings(con); list_t *siblings = container_get_siblings(con);
y_offset = container_titlebar_height() * siblings->length; y_offset = container_titlebar_height() * siblings->length;
view->border_top = false; con->border_top = false;
} }
switch (view->border) { switch (con->border) {
case B_CSD: case B_CSD:
case B_NONE: case B_NONE:
x = con->x; x = con->x;
@ -268,29 +268,29 @@ void view_autoconfigure(struct sway_view *view) {
height = con->height - y_offset; height = con->height - y_offset;
break; break;
case B_PIXEL: case B_PIXEL:
x = con->x + view->border_thickness * view->border_left; x = con->x + con->border_thickness * con->border_left;
y = con->y + view->border_thickness * view->border_top + y_offset; y = con->y + con->border_thickness * con->border_top + y_offset;
width = con->width width = con->width
- view->border_thickness * view->border_left - con->border_thickness * con->border_left
- view->border_thickness * view->border_right; - con->border_thickness * con->border_right;
height = con->height - y_offset height = con->height - y_offset
- view->border_thickness * view->border_top - con->border_thickness * con->border_top
- view->border_thickness * view->border_bottom; - con->border_thickness * con->border_bottom;
break; break;
case B_NORMAL: case B_NORMAL:
// Height is: 1px border + 3px pad + title height + 3px pad + 1px border // Height is: 1px border + 3px pad + title height + 3px pad + 1px border
x = con->x + view->border_thickness * view->border_left; x = con->x + con->border_thickness * con->border_left;
width = con->width width = con->width
- view->border_thickness * view->border_left - con->border_thickness * con->border_left
- view->border_thickness * view->border_right; - con->border_thickness * con->border_right;
if (y_offset) { if (y_offset) {
y = con->y + y_offset; y = con->y + y_offset;
height = con->height - y_offset height = con->height - y_offset
- view->border_thickness * view->border_bottom; - con->border_thickness * con->border_bottom;
} else { } else {
y = con->y + container_titlebar_height(); y = con->y + container_titlebar_height();
height = con->height - container_titlebar_height() height = con->height - container_titlebar_height()
- view->border_thickness * view->border_bottom; - con->border_thickness * con->border_bottom;
} }
break; break;
} }
@ -347,13 +347,14 @@ void view_set_csd_from_server(struct sway_view *view, bool enabled) {
void view_update_csd_from_client(struct sway_view *view, bool enabled) { void view_update_csd_from_client(struct sway_view *view, bool enabled) {
wlr_log(WLR_DEBUG, "View %p updated CSD to %i", view, enabled); wlr_log(WLR_DEBUG, "View %p updated CSD to %i", view, enabled);
if (enabled && view->border != B_CSD) { struct sway_container *con = view->container;
view->saved_border = view->border; if (enabled && con && con->border != B_CSD) {
if (view->container && container_is_floating(view->container)) { con->saved_border = con->border;
view->border = B_CSD; if (container_is_floating(con)) {
con->border = B_CSD;
} }
} else if (!enabled && view->border == B_CSD) { } else if (!enabled && con && con->border == B_CSD) {
view->border = view->saved_border; con->border = con->saved_border;
} }
view->using_csd = enabled; view->using_csd = enabled;
} }
@ -584,12 +585,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
view->surface_new_subsurface.notify = view_handle_surface_new_subsurface; view->surface_new_subsurface.notify = view_handle_surface_new_subsurface;
if (view->impl->wants_floating && view->impl->wants_floating(view)) { if (view->impl->wants_floating && view->impl->wants_floating(view)) {
view->border = config->floating_border; view->container->border = config->floating_border;
view->border_thickness = config->floating_border_thickness; view->container->border_thickness = config->floating_border_thickness;
container_set_floating(view->container, true); container_set_floating(view->container, true);
} else { } else {
view->border = config->border; view->container->border = config->border;
view->border_thickness = config->border_thickness; view->container->border_thickness = config->border_thickness;
view_set_tiled(view, true); view_set_tiled(view, true);
} }