ssd: Cosmetic cleanups

- Minimize includes in `ssd.h`
- Avoid repetitive `view->ssd.margin` pattern
- Use `struct ssd *` or `const struct ssd *` rather than `struct view *`
  where convenient

Part of the motivation is to make it easier to separate `struct ssd`
from `struct view` in a future commit.
This commit is contained in:
John Lindgren 2022-11-26 16:06:22 -05:00 committed by Johan Malm
parent 9dd55f0490
commit 957d9e5926
9 changed files with 163 additions and 145 deletions

View file

@ -2,8 +2,7 @@
#ifndef __LABWC_SSD_H #ifndef __LABWC_SSD_H
#define __LABWC_SSD_H #define __LABWC_SSD_H
#include "buffer.h" #include <wayland-server-core.h>
#include <wlr/util/box.h>
#define BUTTON_COUNT 4 #define BUTTON_COUNT 4
#define BUTTON_WIDTH 26 #define BUTTON_WIDTH 26
@ -50,10 +49,10 @@ enum ssd_part_type {
/* Forward declare arguments */ /* Forward declare arguments */
struct view; struct view;
struct wl_list; struct wlr_buffer;
struct wlr_box; struct wlr_scene;
struct wlr_scene_node;
struct wlr_scene_tree; struct wlr_scene_tree;
struct scaled_font_buffer;
struct border { struct border {
int top; int top;
@ -155,9 +154,10 @@ void ssd_update_button_hover(struct wlr_scene_node *node,
struct ssd_hover_state *hover_state); struct ssd_hover_state *hover_state);
/* Public SSD helpers */ /* Public SSD helpers */
enum ssd_part_type ssd_at(struct view *view, double lx, double ly); enum ssd_part_type ssd_at(const struct ssd *ssd,
enum ssd_part_type ssd_get_part_type( struct wlr_scene *scene, double lx, double ly);
struct view *view, struct wlr_scene_node *node); enum ssd_part_type ssd_get_part_type(const struct ssd *ssd,
struct wlr_scene_node *node);
uint32_t ssd_resize_edges(enum ssd_part_type type); uint32_t ssd_resize_edges(enum ssd_part_type type);
bool ssd_is_button(enum ssd_part_type type); bool ssd_is_button(enum ssd_part_type type);
bool ssd_part_contains(enum ssd_part_type whole, enum ssd_part_type candidate); bool ssd_part_contains(enum ssd_part_type whole, enum ssd_part_type candidate);
@ -189,17 +189,17 @@ struct ssd_part *ssd_get_part(
void ssd_destroy_parts(struct wl_list *list); void ssd_destroy_parts(struct wl_list *list);
/* SSD internal */ /* SSD internal */
void ssd_titlebar_create(struct view *view); void ssd_titlebar_create(struct ssd *ssd);
void ssd_titlebar_update(struct view *view); void ssd_titlebar_update(struct ssd *ssd);
void ssd_titlebar_destroy(struct view *view); void ssd_titlebar_destroy(struct ssd *ssd);
void ssd_border_create(struct view *view); void ssd_border_create(struct ssd *ssd);
void ssd_border_update(struct view *view); void ssd_border_update(struct ssd *ssd);
void ssd_border_destroy(struct view *view); void ssd_border_destroy(struct ssd *ssd);
void ssd_extents_create(struct view *view); void ssd_extents_create(struct ssd *ssd);
void ssd_extents_update(struct view *view); void ssd_extents_update(struct ssd *ssd);
void ssd_extents_destroy(struct view *view); void ssd_extents_destroy(struct ssd *ssd);
/* TODO: clean up / update */ /* TODO: clean up / update */
struct border ssd_thickness(struct view *view); struct border ssd_thickness(struct view *view);

View file

@ -161,8 +161,8 @@ show_menu(struct server *server, struct view *view, const char *menu_name)
if (!view) { if (!view) {
return; return;
} }
enum ssd_part_type type = ssd_at(view, server->seat.cursor->x, enum ssd_part_type type = ssd_at(&view->ssd, server->scene,
server->seat.cursor->y); server->seat.cursor->x, server->seat.cursor->y);
if (type == LAB_SSD_BUTTON_WINDOW_MENU) { if (type == LAB_SSD_BUTTON_WINDOW_MENU) {
force_menu_top_left = true; force_menu_top_left = true;
} else if (ssd_part_contains(LAB_SSD_PART_TITLEBAR, type)) { } else if (ssd_part_contains(LAB_SSD_PART_TITLEBAR, type)) {

View file

@ -339,7 +339,7 @@ get_cursor_context(struct server *server)
case LAB_NODE_DESC_VIEW: case LAB_NODE_DESC_VIEW:
case LAB_NODE_DESC_XDG_POPUP: case LAB_NODE_DESC_XDG_POPUP:
ret.view = desc->data; ret.view = desc->data;
ret.type = ssd_get_part_type(ret.view, ret.node); ret.type = ssd_get_part_type(&ret.view->ssd, ret.node);
if (ret.type == LAB_SSD_CLIENT) { if (ret.type == LAB_SSD_CLIENT) {
ret.surface = lab_wlr_surface_from_node(ret.node); ret.surface = lab_wlr_surface_from_node(ret.node);
} }

View file

@ -54,50 +54,50 @@ ssd_is_button(enum ssd_part_type type)
} }
enum ssd_part_type enum ssd_part_type
ssd_get_part_type(struct view *view, struct wlr_scene_node *node) ssd_get_part_type(const struct ssd *ssd, struct wlr_scene_node *node)
{ {
if (!node) { if (!node) {
return LAB_SSD_NONE; return LAB_SSD_NONE;
} else if (node->type == WLR_SCENE_NODE_BUFFER } else if (node->type == WLR_SCENE_NODE_BUFFER
&& lab_wlr_surface_from_node(node)) { && lab_wlr_surface_from_node(node)) {
return LAB_SSD_CLIENT; return LAB_SSD_CLIENT;
} else if (!view->ssd.tree) { } else if (!ssd->tree) {
return LAB_SSD_NONE; return LAB_SSD_NONE;
} }
struct wl_list *part_list = NULL; const struct wl_list *part_list = NULL;
struct wlr_scene_tree *grandparent = struct wlr_scene_tree *grandparent =
node->parent ? node->parent->node.parent : NULL; node->parent ? node->parent->node.parent : NULL;
struct wlr_scene_tree *greatgrandparent = struct wlr_scene_tree *greatgrandparent =
grandparent ? grandparent->node.parent : NULL; grandparent ? grandparent->node.parent : NULL;
/* active titlebar */ /* active titlebar */
if (node->parent == view->ssd.titlebar.active.tree) { if (node->parent == ssd->titlebar.active.tree) {
part_list = &view->ssd.titlebar.active.parts; part_list = &ssd->titlebar.active.parts;
} else if (grandparent == view->ssd.titlebar.active.tree) { } else if (grandparent == ssd->titlebar.active.tree) {
part_list = &view->ssd.titlebar.active.parts; part_list = &ssd->titlebar.active.parts;
} else if (greatgrandparent == view->ssd.titlebar.active.tree) { } else if (greatgrandparent == ssd->titlebar.active.tree) {
part_list = &view->ssd.titlebar.active.parts; part_list = &ssd->titlebar.active.parts;
/* extents */ /* extents */
} else if (node->parent == view->ssd.extents.tree) { } else if (node->parent == ssd->extents.tree) {
part_list = &view->ssd.extents.parts; part_list = &ssd->extents.parts;
/* active border */ /* active border */
} else if (node->parent == view->ssd.border.active.tree) { } else if (node->parent == ssd->border.active.tree) {
part_list = &view->ssd.border.active.parts; part_list = &ssd->border.active.parts;
/* inactive titlebar */ /* inactive titlebar */
} else if (node->parent == view->ssd.titlebar.inactive.tree) { } else if (node->parent == ssd->titlebar.inactive.tree) {
part_list = &view->ssd.titlebar.inactive.parts; part_list = &ssd->titlebar.inactive.parts;
} else if (grandparent == view->ssd.titlebar.inactive.tree) { } else if (grandparent == ssd->titlebar.inactive.tree) {
part_list = &view->ssd.titlebar.inactive.parts; part_list = &ssd->titlebar.inactive.parts;
} else if (greatgrandparent == view->ssd.titlebar.inactive.tree) { } else if (greatgrandparent == ssd->titlebar.inactive.tree) {
part_list = &view->ssd.titlebar.inactive.parts; part_list = &ssd->titlebar.inactive.parts;
/* inactive border */ /* inactive border */
} else if (node->parent == view->ssd.border.inactive.tree) { } else if (node->parent == ssd->border.inactive.tree) {
part_list = &view->ssd.border.inactive.parts; part_list = &ssd->border.inactive.parts;
} }
if (part_list) { if (part_list) {
@ -112,12 +112,12 @@ ssd_get_part_type(struct view *view, struct wlr_scene_node *node)
} }
enum ssd_part_type enum ssd_part_type
ssd_at(struct view *view, double lx, double ly) ssd_at(const struct ssd *ssd, struct wlr_scene *scene, double lx, double ly)
{ {
double sx, sy; double sx, sy;
struct wlr_scene_node *node = wlr_scene_node_at( struct wlr_scene_node *node = wlr_scene_node_at(
&view->server->scene->tree.node, lx, ly, &sx, &sy); &scene->tree.node, lx, ly, &sx, &sy);
return ssd_get_part_type(view, node); return ssd_get_part_type(ssd, node);
} }
uint32_t uint32_t
@ -148,52 +148,55 @@ ssd_resize_edges(enum ssd_part_type type)
void void
ssd_create(struct view *view, bool active) ssd_create(struct view *view, bool active)
{ {
assert(!view->ssd.tree); struct ssd *ssd = &view->ssd;
assert(!ssd->tree);
view->ssd.tree = wlr_scene_tree_create(view->scene_tree); ssd->tree = wlr_scene_tree_create(view->scene_tree);
wlr_scene_node_lower_to_bottom(&view->ssd.tree->node); wlr_scene_node_lower_to_bottom(&ssd->tree->node);
ssd_extents_create(view); ssd_extents_create(ssd);
ssd_border_create(view); ssd_border_create(ssd);
ssd_titlebar_create(view); ssd_titlebar_create(ssd);
view->ssd.margin = ssd_thickness(view); ssd->margin = ssd_thickness(view);
ssd_set_active(view, active); ssd_set_active(view, active);
view->ssd.state.width = view->w; ssd->state.width = view->w;
view->ssd.state.height = view->h; ssd->state.height = view->h;
view->ssd.state.x = view->x; ssd->state.x = view->x;
view->ssd.state.y = view->y; ssd->state.y = view->y;
} }
void void
ssd_update_geometry(struct view *view) ssd_update_geometry(struct view *view)
{ {
if (!view->ssd.tree) { struct ssd *ssd = &view->ssd;
if (!ssd->tree) {
return; return;
} }
if (view->w == view->ssd.state.width && view->h == view->ssd.state.height) { if (view->w == ssd->state.width && view->h == ssd->state.height) {
if (view->x != view->ssd.state.x || view->y != view->ssd.state.y) { if (view->x != ssd->state.x || view->y != ssd->state.y) {
/* Dynamically resize extents based on position and usable_area */ /* Dynamically resize extents based on position and usable_area */
ssd_extents_update(view); ssd_extents_update(ssd);
view->ssd.state.x = view->x; ssd->state.x = view->x;
view->ssd.state.y = view->y; ssd->state.y = view->y;
} }
return; return;
} }
ssd_extents_update(view); ssd_extents_update(ssd);
ssd_border_update(view); ssd_border_update(ssd);
ssd_titlebar_update(view); ssd_titlebar_update(ssd);
view->ssd.state.width = view->w; ssd->state.width = view->w;
view->ssd.state.height = view->h; ssd->state.height = view->h;
view->ssd.state.x = view->x; ssd->state.x = view->x;
view->ssd.state.y = view->y; ssd->state.y = view->y;
} }
void void
ssd_destroy(struct view *view) ssd_destroy(struct view *view)
{ {
if (!view->ssd.tree) { struct ssd *ssd = &view->ssd;
if (!ssd->tree) {
return; return;
} }
@ -206,12 +209,12 @@ ssd_destroy(struct view *view)
} }
/* Destroy subcomponents */ /* Destroy subcomponents */
ssd_titlebar_destroy(view); ssd_titlebar_destroy(ssd);
ssd_border_destroy(view); ssd_border_destroy(ssd);
ssd_extents_destroy(view); ssd_extents_destroy(ssd);
wlr_scene_node_destroy(&view->ssd.tree->node); wlr_scene_node_destroy(&ssd->tree->node);
view->ssd.tree = NULL; ssd->tree = NULL;
view->ssd.margin = (struct border){ 0 }; ssd->margin = (struct border){ 0 };
} }
bool bool
@ -255,11 +258,12 @@ ssd_part_contains(enum ssd_part_type whole, enum ssd_part_type candidate)
void void
ssd_set_active(struct view *view, bool active) ssd_set_active(struct view *view, bool active)
{ {
if (!view->ssd.tree) { struct ssd *ssd = &view->ssd;
if (!ssd->tree) {
return; return;
} }
wlr_scene_node_set_enabled(&view->ssd.border.active.tree->node, active); wlr_scene_node_set_enabled(&ssd->border.active.tree->node, active);
wlr_scene_node_set_enabled(&view->ssd.titlebar.active.tree->node, active); wlr_scene_node_set_enabled(&ssd->titlebar.active.tree->node, active);
wlr_scene_node_set_enabled(&view->ssd.border.inactive.tree->node, !active); wlr_scene_node_set_enabled(&ssd->border.inactive.tree->node, !active);
wlr_scene_node_set_enabled(&view->ssd.titlebar.inactive.tree->node, !active); wlr_scene_node_set_enabled(&ssd->titlebar.inactive.tree->node, !active);
} }

View file

@ -6,13 +6,14 @@
#include "theme.h" #include "theme.h"
#include "view.h" #include "view.h"
#define FOR_EACH_STATE(view, tmp) FOR_EACH(tmp, \ #define FOR_EACH_STATE(ssd, tmp) FOR_EACH(tmp, \
&(view)->ssd.border.active, \ &(ssd)->border.active, \
&(view)->ssd.border.inactive) &(ssd)->border.inactive)
void void
ssd_border_create(struct view *view) ssd_border_create(struct ssd *ssd)
{ {
struct view *view = wl_container_of(ssd, view, ssd);
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->w; int width = view->w;
int height = view->h; int height = view->h;
@ -22,11 +23,11 @@ ssd_border_create(struct view *view)
struct wlr_scene_tree *parent; struct wlr_scene_tree *parent;
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(ssd, subtree) {
subtree->tree = wlr_scene_tree_create(view->ssd.tree); subtree->tree = wlr_scene_tree_create(ssd->tree);
parent = subtree->tree; parent = subtree->tree;
wlr_scene_node_set_position(&parent->node, -theme->border_width, 0); wlr_scene_node_set_position(&parent->node, -theme->border_width, 0);
if (subtree == &view->ssd.border.active) { if (subtree == &ssd->border.active) {
color = theme->window_active_border_color; color = theme->window_active_border_color;
} else { } else {
color = theme->window_inactive_border_color; color = theme->window_inactive_border_color;
@ -48,8 +49,9 @@ ssd_border_create(struct view *view)
} }
void void
ssd_border_update(struct view *view) ssd_border_update(struct ssd *ssd)
{ {
struct view *view = wl_container_of(ssd, view, ssd);
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->w; int width = view->w;
@ -59,7 +61,7 @@ ssd_border_update(struct view *view)
struct ssd_part *part; struct ssd_part *part;
struct wlr_scene_rect *rect; struct wlr_scene_rect *rect;
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(ssd, subtree) {
wl_list_for_each(part, &subtree->parts, link) { wl_list_for_each(part, &subtree->parts, link) {
rect = lab_wlr_scene_get_rect(part->node); rect = lab_wlr_scene_get_rect(part->node);
switch (part->type) { switch (part->type) {
@ -92,14 +94,14 @@ ssd_border_update(struct view *view)
} }
void void
ssd_border_destroy(struct view *view) ssd_border_destroy(struct ssd *ssd)
{ {
if (!view->ssd.border.active.tree) { if (!ssd->border.active.tree) {
return; return;
} }
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(ssd, subtree) {
ssd_destroy_parts(&subtree->parts); ssd_destroy_parts(&subtree->parts);
wlr_scene_node_destroy(&subtree->tree->node); wlr_scene_node_destroy(&subtree->tree->node);
subtree->tree = NULL; subtree->tree = NULL;

View file

@ -35,19 +35,20 @@ lab_wlr_output_layout_layout_coords(struct wlr_output_layout *layout,
} }
void void
ssd_extents_create(struct view *view) ssd_extents_create(struct ssd *ssd)
{ {
struct view *view = wl_container_of(ssd, view, ssd);
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
struct wl_list *part_list = &view->ssd.extents.parts; struct wl_list *part_list = &ssd->extents.parts;
int extended_area = EXTENDED_AREA; int extended_area = EXTENDED_AREA;
int corner_size = extended_area + theme->border_width + BUTTON_WIDTH / 2; int corner_size = extended_area + theme->border_width + BUTTON_WIDTH / 2;
view->ssd.extents.tree = wlr_scene_tree_create(view->ssd.tree); ssd->extents.tree = wlr_scene_tree_create(ssd->tree);
struct wlr_scene_tree *parent = view->ssd.extents.tree; struct wlr_scene_tree *parent = ssd->extents.tree;
if (view->maximized || view->fullscreen) { if (view->maximized || view->fullscreen) {
wlr_scene_node_set_enabled(&parent->node, false); wlr_scene_node_set_enabled(&parent->node, false);
} }
wl_list_init(&view->ssd.extents.parts); wl_list_init(&ssd->extents.parts);
wlr_scene_node_set_position(&parent->node, wlr_scene_node_set_position(&parent->node,
-(theme->border_width + extended_area), -(theme->border_width + extended_area),
-(theme->title_height + theme->border_width + extended_area)); -(theme->title_height + theme->border_width + extended_area));
@ -91,18 +92,19 @@ ssd_extents_create(struct view *view)
p->geometry->height = corner_size; p->geometry->height = corner_size;
/* Initial manual update to keep X11 applications happy */ /* Initial manual update to keep X11 applications happy */
ssd_extents_update(view); ssd_extents_update(ssd);
} }
void void
ssd_extents_update(struct view *view) ssd_extents_update(struct ssd *ssd)
{ {
struct view *view = wl_container_of(ssd, view, ssd);
if (view->maximized || view->fullscreen) { if (view->maximized || view->fullscreen) {
wlr_scene_node_set_enabled(&view->ssd.extents.tree->node, false); wlr_scene_node_set_enabled(&ssd->extents.tree->node, false);
return; return;
} }
if (!view->ssd.extents.tree->node.enabled) { if (!ssd->extents.tree->node.enabled) {
wlr_scene_node_set_enabled(&view->ssd.extents.tree->node, true); wlr_scene_node_set_enabled(&ssd->extents.tree->node, true);
} }
if (!view->output) { if (!view->output) {
@ -133,10 +135,10 @@ ssd_extents_update(struct view *view)
/* Remember base layout coordinates */ /* Remember base layout coordinates */
int base_x, base_y; int base_x, base_y;
wlr_scene_node_coords(&view->ssd.extents.tree->node, &base_x, &base_y); wlr_scene_node_coords(&ssd->extents.tree->node, &base_x, &base_y);
struct wlr_box *target; struct wlr_box *target;
wl_list_for_each(part, &view->ssd.extents.parts, link) { wl_list_for_each(part, &ssd->extents.parts, link) {
rect = lab_wlr_scene_get_rect(part->node); rect = lab_wlr_scene_get_rect(part->node);
target = part->geometry; target = part->geometry;
switch (part->type) { switch (part->type) {
@ -206,13 +208,13 @@ ssd_extents_update(struct view *view)
} }
void void
ssd_extents_destroy(struct view *view) ssd_extents_destroy(struct ssd *ssd)
{ {
if (!view->ssd.extents.tree) { if (!ssd->extents.tree) {
return; return;
} }
ssd_destroy_parts(&view->ssd.extents.parts); ssd_destroy_parts(&ssd->extents.parts);
wlr_scene_node_destroy(&view->ssd.extents.tree->node); wlr_scene_node_destroy(&ssd->extents.tree->node);
view->ssd.extents.tree = NULL; ssd->extents.tree = NULL;
} }

View file

@ -3,6 +3,7 @@
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "buffer.h"
#include "common/mem.h" #include "common/mem.h"
#include "common/scaled_font_buffer.h" #include "common/scaled_font_buffer.h"
#include "common/scene-helpers.h" #include "common/scene-helpers.h"
@ -12,13 +13,14 @@
#include "theme.h" #include "theme.h"
#include "view.h" #include "view.h"
#define FOR_EACH_STATE(view, tmp) FOR_EACH(tmp, \ #define FOR_EACH_STATE(ssd, tmp) FOR_EACH(tmp, \
&(view)->ssd.titlebar.active, \ &(ssd)->titlebar.active, \
&(view)->ssd.titlebar.inactive) &(ssd)->titlebar.inactive)
void void
ssd_titlebar_create(struct view *view) ssd_titlebar_create(struct ssd *ssd)
{ {
struct view *view = wl_container_of(ssd, view, ssd);
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->w; int width = view->w;
@ -33,11 +35,11 @@ ssd_titlebar_create(struct view *view)
struct wlr_buffer *close_button_unpressed; struct wlr_buffer *close_button_unpressed;
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(ssd, subtree) {
subtree->tree = wlr_scene_tree_create(view->ssd.tree); subtree->tree = wlr_scene_tree_create(ssd->tree);
parent = subtree->tree; parent = subtree->tree;
wlr_scene_node_set_position(&parent->node, 0, -theme->title_height); wlr_scene_node_set_position(&parent->node, 0, -theme->title_height);
if (subtree == &view->ssd.titlebar.active) { if (subtree == &ssd->titlebar.active) {
color = theme->window_active_title_bg_color; color = theme->window_active_title_bg_color;
corner_top_left = &theme->corner_top_left_active_normal->base; corner_top_left = &theme->corner_top_left_active_normal->base;
corner_top_right = &theme->corner_top_right_active_normal->base; corner_top_right = &theme->corner_top_right_active_normal->base;
@ -86,17 +88,18 @@ is_direct_child(struct wlr_scene_node *node, struct ssd_sub_tree *subtree)
} }
void void
ssd_titlebar_update(struct view *view) ssd_titlebar_update(struct ssd *ssd)
{ {
struct view *view = wl_container_of(ssd, view, ssd);
int width = view->w; int width = view->w;
if (width == view->ssd.state.width) { if (width == ssd->state.width) {
return; return;
} }
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
struct ssd_part *part; struct ssd_part *part;
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(ssd, subtree) {
wl_list_for_each(part, &subtree->parts, link) { wl_list_for_each(part, &subtree->parts, link) {
switch (part->type) { switch (part->type) {
case LAB_SSD_PART_TITLEBAR: case LAB_SSD_PART_TITLEBAR:
@ -132,22 +135,22 @@ ssd_titlebar_update(struct view *view)
} }
void void
ssd_titlebar_destroy(struct view *view) ssd_titlebar_destroy(struct ssd *ssd)
{ {
if (!view->ssd.titlebar.active.tree) { if (!ssd->titlebar.active.tree) {
return; return;
} }
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(ssd, subtree) {
ssd_destroy_parts(&subtree->parts); ssd_destroy_parts(&subtree->parts);
wlr_scene_node_destroy(&subtree->tree->node); wlr_scene_node_destroy(&subtree->tree->node);
subtree->tree = NULL; subtree->tree = NULL;
} FOR_EACH_END } FOR_EACH_END
if (view->ssd.state.title.text) { if (ssd->state.title.text) {
free(view->ssd.state.title.text); free(ssd->state.title.text);
view->ssd.state.title.text = NULL; ssd->state.title.text = NULL;
} }
} }
@ -164,8 +167,9 @@ ssd_titlebar_destroy(struct view *view)
*/ */
static void static void
ssd_update_title_positions(struct view *view) ssd_update_title_positions(struct ssd *ssd)
{ {
struct view *view = wl_container_of(ssd, view, ssd);
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->w; int width = view->w;
int title_bg_width = width - BUTTON_WIDTH * BUTTON_COUNT; int title_bg_width = width - BUTTON_WIDTH * BUTTON_COUNT;
@ -174,7 +178,7 @@ ssd_update_title_positions(struct view *view)
int buffer_height, buffer_width; int buffer_height, buffer_width;
struct ssd_part *part; struct ssd_part *part;
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(ssd, subtree) {
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE); part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE);
if (!part || !part->node) { if (!part || !part->node) {
/* view->surface never been mapped */ /* view->surface never been mapped */
@ -217,7 +221,8 @@ ssd_update_title_positions(struct view *view)
void void
ssd_update_title(struct view *view) ssd_update_title(struct view *view)
{ {
if (!view->ssd.tree) { struct ssd *ssd = &view->ssd;
if (!ssd->tree) {
return; return;
} }
@ -227,7 +232,7 @@ ssd_update_title(struct view *view)
} }
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
struct ssd_state_title *state = &view->ssd.state.title; struct ssd_state_title *state = &ssd->state.title;
bool title_unchanged = state->text && !strcmp(title, state->text); bool title_unchanged = state->text && !strcmp(title, state->text);
float *text_color; float *text_color;
@ -236,8 +241,8 @@ ssd_update_title(struct view *view)
struct ssd_state_title_width *dstate; struct ssd_state_title_width *dstate;
int title_bg_width = view->w - BUTTON_WIDTH * BUTTON_COUNT; int title_bg_width = view->w - BUTTON_WIDTH * BUTTON_COUNT;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(ssd, subtree) {
if (subtree == &view->ssd.titlebar.active) { if (subtree == &ssd->titlebar.active) {
dstate = &state->active; dstate = &state->active;
text_color = theme->window_active_label_text_color; text_color = theme->window_active_label_text_color;
} else { } else {
@ -287,7 +292,7 @@ ssd_update_title(struct view *view)
} }
state->text = xstrdup(title); state->text = xstrdup(title);
} }
ssd_update_title_positions(view); ssd_update_title_positions(ssd);
} }
void void

View file

@ -87,11 +87,13 @@ view_get_edge_snap_box(struct view *view, struct output *output,
base_height = usable.height - 2 * rc.gap; base_height = usable.height - 2 * rc.gap;
break; break;
} }
struct border margin = view->ssd.margin;
struct wlr_box dst = { struct wlr_box dst = {
.x = x_offset + usable.x + view->ssd.margin.left, .x = x_offset + usable.x + margin.left,
.y = y_offset + usable.y + view->ssd.margin.top, .y = y_offset + usable.y + margin.top,
.width = base_width - view->ssd.margin.left - view->ssd.margin.right, .width = base_width - margin.left - margin.right,
.height = base_height - view->ssd.margin.top - view->ssd.margin.bottom, .height = base_height - margin.top - margin.bottom,
}; };
return dst; return dst;
@ -276,9 +278,10 @@ view_compute_centered_position(struct view *view, int w, int h, int *x, int *y)
return false; return false;
} }
struct border margin = view->ssd.margin;
struct wlr_box usable = output_usable_area_in_layout_coords(output); struct wlr_box usable = output_usable_area_in_layout_coords(output);
int width = w + view->ssd.margin.left + view->ssd.margin.right; int width = w + margin.left + margin.right;
int height = h + view->ssd.margin.top + view->ssd.margin.bottom; int height = h + margin.top + margin.bottom;
*x = usable.x + (usable.width - width) / 2; *x = usable.x + (usable.width - width) / 2;
*y = usable.y + (usable.height - height) / 2; *y = usable.y + (usable.height - height) / 2;
@ -293,8 +296,8 @@ view_compute_centered_position(struct view *view, int w, int h, int *x, int *y)
#if HAVE_XWAYLAND #if HAVE_XWAYLAND
/* TODO: refactor xwayland.c functions to get rid of this */ /* TODO: refactor xwayland.c functions to get rid of this */
if (view->type == LAB_XWAYLAND_VIEW) { if (view->type == LAB_XWAYLAND_VIEW) {
*x += view->ssd.margin.left; *x += margin.left;
*y += view->ssd.margin.top; *y += margin.top;
} }
#endif #endif
@ -726,6 +729,8 @@ view_move_to_edge(struct view *view, const char *direction)
wlr_log(WLR_ERROR, "invalid edge"); wlr_log(WLR_ERROR, "invalid edge");
return; return;
} }
struct border margin = view->ssd.margin;
struct wlr_box usable = output_usable_area_in_layout_coords(output); struct wlr_box usable = output_usable_area_in_layout_coords(output);
if (usable.height == output->wlr_output->height if (usable.height == output->wlr_output->height
&& output->wlr_output->scale != 1) { && output->wlr_output->scale != 1) {
@ -738,18 +743,18 @@ view_move_to_edge(struct view *view, const char *direction)
int x = 0, y = 0; int x = 0, y = 0;
if (!strcasecmp(direction, "left")) { if (!strcasecmp(direction, "left")) {
x = usable.x + view->ssd.margin.left + rc.gap; x = usable.x + margin.left + rc.gap;
y = view->y; y = view->y;
} else if (!strcasecmp(direction, "up")) { } else if (!strcasecmp(direction, "up")) {
x = view->x; x = view->x;
y = usable.y + view->ssd.margin.top + rc.gap; y = usable.y + margin.top + rc.gap;
} else if (!strcasecmp(direction, "right")) { } else if (!strcasecmp(direction, "right")) {
x = usable.x + usable.width - view->w - view->ssd.margin.right x = usable.x + usable.width - view->w - margin.right
- rc.gap; - rc.gap;
y = view->y; y = view->y;
} else if (!strcasecmp(direction, "down")) { } else if (!strcasecmp(direction, "down")) {
x = view->x; x = view->x;
y = usable.y + usable.height - view->h - view->ssd.margin.bottom y = usable.y + usable.height - view->h - margin.bottom
- rc.gap; - rc.gap;
} else { } else {
wlr_log(WLR_ERROR, "invalid edge"); wlr_log(WLR_ERROR, "invalid edge");

View file

@ -7,12 +7,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include "buffer.h"
#include "common/font.h" #include "common/font.h"
#include "common/graphic-helpers.h" #include "common/graphic-helpers.h"
#include "common/list.h" #include "common/list.h"
#include "common/mem.h" #include "common/mem.h"
#include "labwc.h" #include "labwc.h"
#include "view.h"
#include "workspaces.h" #include "workspaces.h"
/* Internal helpers */ /* Internal helpers */