From c329a40f918f5998d480a65cd9923cc3f2b8f7c6 Mon Sep 17 00:00:00 2001 From: TheAvidDev Date: Mon, 2 Nov 2020 20:32:31 -0500 Subject: [PATCH] Add border texture class usage --- include/sway/tree/container.h | 2 ++ sway/desktop/render.c | 40 ++++++++++++++++++++++++++++------- sway/tree/container.c | 8 +++++++ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 136d618b2..c24816be4 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -260,6 +260,8 @@ void container_floating_move_to_center(struct sway_container *con); bool container_has_urgent_child(struct sway_container *container); +bool container_has_focused_child(struct sway_container *container); + /** * If the container is involved in a drag or resize operation via a mouse, this * ends the operation. diff --git a/sway/desktop/render.c b/sway/desktop/render.c index ee6d13c14..0ed40d42a 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -818,6 +818,30 @@ struct output_and_damage { pixman_region32_t *damage; }; +/** + * Determines which border texture class to render for a given container. + */ +struct border_textures *get_border_textures_for_container( + struct sway_container *con) { + if (container_has_urgent_child(con)) { + return &config->border_textures.urgent; + } + if (container_has_focused_child(con) || con->current.focused) { + return &config->border_textures.focused; + } + if (!con->children) { + return &config->border_textures.unfocused; + } + + for (int i = 0; i < con->children->length; ++i) { + struct sway_container *child = con->children->items[i]; + if (child == con->current.focused_inactive_child) { + return &config->border_textures.focused_inactive; + } + } + return &config->border_textures.unfocused; +} + /** * Render all of the border textures for a container. */ @@ -842,18 +866,19 @@ static void render_border_textures_for_container(struct sway_container *con, return; } - struct border_textures *textures; -bypass_border_checks: - // TODO: Use the appropriate border_texture based on children - textures = &config->border_textures.focused; - struct sway_container_state *state = &con->current; + struct border_textures *textures; + struct sway_container_state *state; struct wlr_box box; + struct output_and_damage *oad; +bypass_border_checks: + state = &con->current; box.x = state->x; box.y = state->y; box.width = state->width; box.height = state->height; - struct output_and_damage *oad = (struct output_and_damage *) data; + oad = (struct output_and_damage *) data; + textures = get_border_textures_for_container(con); render_border_textures(oad->output, oad->damage, &box, textures->texture, con->alpha); } @@ -868,9 +893,8 @@ static void render_border_textures_for_workspace(struct sway_output *output, struct wlr_box box; workspace_get_box(ws, &box); - // TODO: Use the appropriate border_texture based on children - struct border_textures *textures = &config->border_textures.focused; struct sway_container *con = ws->tiling->items[0]; + struct border_textures *textures = get_border_textures_for_container(con); render_border_textures(output, damage, &box, textures->texture, con->alpha); return; } diff --git a/sway/tree/container.c b/sway/tree/container.c index 858a839b9..ab47d904b 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -965,6 +965,14 @@ bool container_has_urgent_child(struct sway_container *container) { return container_find_child(container, find_urgent_iterator, NULL); } +static bool find_focused_iterator(struct sway_container *con, void *data) { + return con->current.focused; +} + +bool container_has_focused_child(struct sway_container *container) { + return container_find_child(container, find_focused_iterator, NULL); +} + void container_end_mouse_operation(struct sway_container *container) { struct sway_seat *seat; wl_list_for_each(seat, &server.input->seats, link) {