mirror of
https://github.com/labwc/labwc.git
synced 2025-11-05 13:29:58 -05:00
ssd: Allocate struct ssd and struct ssd_hover_state separately
- Store a pointer to the `struct view` in `struct ssd` - Pass `struct ssd *` instead of `struct view *` to ssd functions - Add `ssd_get_margin()` convenience function
This commit is contained in:
parent
cfa51ab628
commit
1e8b0414fe
15 changed files with 112 additions and 65 deletions
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "common/mem.h"
|
||||
#include "common/scene-helpers.h"
|
||||
#include "labwc.h"
|
||||
#include "ssd.h"
|
||||
|
|
@ -16,6 +17,7 @@
|
|||
struct border
|
||||
ssd_thickness(struct view *view)
|
||||
{
|
||||
assert(view);
|
||||
/*
|
||||
* Check preconditions for displaying SSD. Note that this
|
||||
* needs to work even before ssd_create() has been called.
|
||||
|
|
@ -35,6 +37,7 @@ ssd_thickness(struct view *view)
|
|||
struct wlr_box
|
||||
ssd_max_extents(struct view *view)
|
||||
{
|
||||
assert(view);
|
||||
struct border border = ssd_thickness(view);
|
||||
return (struct wlr_box){
|
||||
.x = view->x - border.left,
|
||||
|
|
@ -61,7 +64,7 @@ ssd_get_part_type(const struct ssd *ssd, struct wlr_scene_node *node)
|
|||
} else if (node->type == WLR_SCENE_NODE_BUFFER
|
||||
&& lab_wlr_surface_from_node(node)) {
|
||||
return LAB_SSD_CLIENT;
|
||||
} else if (!ssd->tree) {
|
||||
} else if (!ssd) {
|
||||
return LAB_SSD_NONE;
|
||||
}
|
||||
|
||||
|
|
@ -114,6 +117,7 @@ ssd_get_part_type(const struct ssd *ssd, struct wlr_scene_node *node)
|
|||
enum ssd_part_type
|
||||
ssd_at(const struct ssd *ssd, struct wlr_scene *scene, double lx, double ly)
|
||||
{
|
||||
assert(scene);
|
||||
double sx, sy;
|
||||
struct wlr_scene_node *node = wlr_scene_node_at(
|
||||
&scene->tree.node, lx, ly, &sx, &sy);
|
||||
|
|
@ -145,34 +149,43 @@ ssd_resize_edges(enum ssd_part_type type)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
struct ssd *
|
||||
ssd_create(struct view *view, bool active)
|
||||
{
|
||||
struct ssd *ssd = &view->ssd;
|
||||
assert(!ssd->tree);
|
||||
assert(view);
|
||||
struct ssd *ssd = znew(*ssd);
|
||||
|
||||
ssd->view = view;
|
||||
ssd->tree = wlr_scene_tree_create(view->scene_tree);
|
||||
wlr_scene_node_lower_to_bottom(&ssd->tree->node);
|
||||
ssd_extents_create(ssd);
|
||||
ssd_border_create(ssd);
|
||||
ssd_titlebar_create(ssd);
|
||||
ssd->margin = ssd_thickness(view);
|
||||
ssd_set_active(view, active);
|
||||
ssd_set_active(ssd, active);
|
||||
|
||||
ssd->state.width = view->w;
|
||||
ssd->state.height = view->h;
|
||||
ssd->state.x = view->x;
|
||||
ssd->state.y = view->y;
|
||||
|
||||
return ssd;
|
||||
}
|
||||
|
||||
struct border
|
||||
ssd_get_margin(const struct ssd *ssd)
|
||||
{
|
||||
return ssd ? ssd->margin : (struct border){ 0 };
|
||||
}
|
||||
|
||||
void
|
||||
ssd_update_geometry(struct view *view)
|
||||
ssd_update_geometry(struct ssd *ssd)
|
||||
{
|
||||
struct ssd *ssd = &view->ssd;
|
||||
if (!ssd->tree) {
|
||||
if (!ssd) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct view *view = ssd->view;
|
||||
if (view->w == ssd->state.width && view->h == ssd->state.height) {
|
||||
if (view->x != ssd->state.x || view->y != ssd->state.y) {
|
||||
/* Dynamically resize extents based on position and usable_area */
|
||||
|
|
@ -193,16 +206,16 @@ ssd_update_geometry(struct view *view)
|
|||
}
|
||||
|
||||
void
|
||||
ssd_destroy(struct view *view)
|
||||
ssd_destroy(struct ssd *ssd)
|
||||
{
|
||||
struct ssd *ssd = &view->ssd;
|
||||
if (!ssd->tree) {
|
||||
if (!ssd) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Maybe reset hover view */
|
||||
struct view *view = ssd->view;
|
||||
struct ssd_hover_state *hover_state;
|
||||
hover_state = &view->server->ssd_hover_state;
|
||||
hover_state = view->server->ssd_hover_state;
|
||||
if (hover_state->view == view) {
|
||||
hover_state->view = NULL;
|
||||
hover_state->node = NULL;
|
||||
|
|
@ -213,8 +226,8 @@ ssd_destroy(struct view *view)
|
|||
ssd_border_destroy(ssd);
|
||||
ssd_extents_destroy(ssd);
|
||||
wlr_scene_node_destroy(&ssd->tree->node);
|
||||
ssd->tree = NULL;
|
||||
ssd->margin = (struct border){ 0 };
|
||||
|
||||
free(ssd);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
@ -256,10 +269,9 @@ ssd_part_contains(enum ssd_part_type whole, enum ssd_part_type candidate)
|
|||
}
|
||||
|
||||
void
|
||||
ssd_set_active(struct view *view, bool active)
|
||||
ssd_set_active(struct ssd *ssd, bool active)
|
||||
{
|
||||
struct ssd *ssd = &view->ssd;
|
||||
if (!ssd->tree) {
|
||||
if (!ssd) {
|
||||
return;
|
||||
}
|
||||
wlr_scene_node_set_enabled(&ssd->border.active.tree->node, active);
|
||||
|
|
@ -268,10 +280,16 @@ ssd_set_active(struct view *view, bool active)
|
|||
wlr_scene_node_set_enabled(&ssd->titlebar.inactive.tree->node, !active);
|
||||
}
|
||||
|
||||
struct ssd_hover_state *
|
||||
ssd_hover_state_new(void)
|
||||
{
|
||||
return znew(struct ssd_hover_state);
|
||||
}
|
||||
|
||||
bool
|
||||
ssd_debug_is_root_node(const struct ssd *ssd, struct wlr_scene_node *node)
|
||||
{
|
||||
if (!ssd->tree || !node) {
|
||||
if (!ssd || !node) {
|
||||
return false;
|
||||
}
|
||||
return node == &ssd->tree->node;
|
||||
|
|
@ -280,7 +298,7 @@ ssd_debug_is_root_node(const struct ssd *ssd, struct wlr_scene_node *node)
|
|||
const char *
|
||||
ssd_debug_get_node_name(const struct ssd *ssd, struct wlr_scene_node *node)
|
||||
{
|
||||
if (!ssd->tree || !node) {
|
||||
if (!ssd || !node) {
|
||||
return NULL;
|
||||
}
|
||||
if (node == &ssd->tree->node) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
void
|
||||
ssd_border_create(struct ssd *ssd)
|
||||
{
|
||||
struct view *view = wl_container_of(ssd, view, ssd);
|
||||
struct view *view = ssd->view;
|
||||
struct theme *theme = view->server->theme;
|
||||
int width = view->w;
|
||||
int height = view->h;
|
||||
|
|
@ -51,7 +51,7 @@ ssd_border_create(struct ssd *ssd)
|
|||
void
|
||||
ssd_border_update(struct ssd *ssd)
|
||||
{
|
||||
struct view *view = wl_container_of(ssd, view, ssd);
|
||||
struct view *view = ssd->view;
|
||||
struct theme *theme = view->server->theme;
|
||||
|
||||
int width = view->w;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ lab_wlr_output_layout_layout_coords(struct wlr_output_layout *layout,
|
|||
void
|
||||
ssd_extents_create(struct ssd *ssd)
|
||||
{
|
||||
struct view *view = wl_container_of(ssd, view, ssd);
|
||||
struct view *view = ssd->view;
|
||||
struct theme *theme = view->server->theme;
|
||||
struct wl_list *part_list = &ssd->extents.parts;
|
||||
int extended_area = EXTENDED_AREA;
|
||||
|
|
@ -98,7 +98,7 @@ ssd_extents_create(struct ssd *ssd)
|
|||
void
|
||||
ssd_extents_update(struct ssd *ssd)
|
||||
{
|
||||
struct view *view = wl_container_of(ssd, view, ssd);
|
||||
struct view *view = ssd->view;
|
||||
if (view->maximized || view->fullscreen) {
|
||||
wlr_scene_node_set_enabled(&ssd->extents.tree->node, false);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
void
|
||||
ssd_titlebar_create(struct ssd *ssd)
|
||||
{
|
||||
struct view *view = wl_container_of(ssd, view, ssd);
|
||||
struct view *view = ssd->view;
|
||||
struct theme *theme = view->server->theme;
|
||||
int width = view->w;
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ ssd_titlebar_create(struct ssd *ssd)
|
|||
corner_top_right, close_button_unpressed,
|
||||
width - BUTTON_WIDTH * 1, view);
|
||||
} FOR_EACH_END
|
||||
ssd_update_title(view);
|
||||
ssd_update_title(ssd);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
@ -90,7 +90,7 @@ is_direct_child(struct wlr_scene_node *node, struct ssd_sub_tree *subtree)
|
|||
void
|
||||
ssd_titlebar_update(struct ssd *ssd)
|
||||
{
|
||||
struct view *view = wl_container_of(ssd, view, ssd);
|
||||
struct view *view = ssd->view;
|
||||
int width = view->w;
|
||||
if (width == ssd->state.width) {
|
||||
return;
|
||||
|
|
@ -131,7 +131,7 @@ ssd_titlebar_update(struct ssd *ssd)
|
|||
}
|
||||
}
|
||||
} FOR_EACH_END
|
||||
ssd_update_title(view);
|
||||
ssd_update_title(ssd);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -169,7 +169,7 @@ ssd_titlebar_destroy(struct ssd *ssd)
|
|||
static void
|
||||
ssd_update_title_positions(struct ssd *ssd)
|
||||
{
|
||||
struct view *view = wl_container_of(ssd, view, ssd);
|
||||
struct view *view = ssd->view;
|
||||
struct theme *theme = view->server->theme;
|
||||
int width = view->w;
|
||||
int title_bg_width = width - BUTTON_WIDTH * BUTTON_COUNT;
|
||||
|
|
@ -219,13 +219,13 @@ ssd_update_title_positions(struct ssd *ssd)
|
|||
}
|
||||
|
||||
void
|
||||
ssd_update_title(struct view *view)
|
||||
ssd_update_title(struct ssd *ssd)
|
||||
{
|
||||
struct ssd *ssd = &view->ssd;
|
||||
if (!ssd->tree) {
|
||||
if (!ssd) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct view *view = ssd->view;
|
||||
char *title = (char *)view_get_string_prop(view, "title");
|
||||
if (!title || !*title) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue