2022-02-21 03:18:38 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Helpers for view server side decorations
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) Johan Malm 2020-2021
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "common/scene-helpers.h"
|
2022-02-21 03:18:38 +01:00
|
|
|
#include "labwc.h"
|
|
|
|
|
#include "ssd.h"
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "theme.h"
|
|
|
|
|
#include "view.h"
|
2022-02-21 03:18:38 +01:00
|
|
|
|
|
|
|
|
struct border
|
|
|
|
|
ssd_thickness(struct view *view)
|
|
|
|
|
{
|
2022-11-21 15:38:20 -05:00
|
|
|
if (!view->ssd_enabled) {
|
2022-11-26 02:22:03 -05:00
|
|
|
return (struct border){ 0 };
|
2022-06-28 19:42:40 +02:00
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
struct theme *theme = view->server->theme;
|
2022-11-26 02:22:03 -05:00
|
|
|
return (struct border){
|
2022-03-09 08:52:33 +01:00
|
|
|
.top = theme->title_height + theme->border_width,
|
2022-02-21 03:18:38 +01:00
|
|
|
.bottom = theme->border_width,
|
|
|
|
|
.left = theme->border_width,
|
|
|
|
|
.right = theme->border_width,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_box
|
|
|
|
|
ssd_max_extents(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
struct border border = ssd_thickness(view);
|
2022-11-26 02:22:03 -05:00
|
|
|
return (struct wlr_box){
|
2022-02-21 03:18:38 +01:00
|
|
|
.x = view->x - border.left,
|
|
|
|
|
.y = view->y - border.top,
|
|
|
|
|
.width = view->w + border.left + border.right,
|
|
|
|
|
.height = view->h + border.top + border.bottom,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ssd_is_button(enum ssd_part_type type)
|
|
|
|
|
{
|
|
|
|
|
return type == LAB_SSD_BUTTON_CLOSE
|
|
|
|
|
|| type == LAB_SSD_BUTTON_MAXIMIZE
|
|
|
|
|
|| type == LAB_SSD_BUTTON_ICONIFY
|
|
|
|
|
|| type == LAB_SSD_BUTTON_WINDOW_MENU;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ssd_part_type
|
|
|
|
|
ssd_get_part_type(struct view *view, struct wlr_scene_node *node)
|
|
|
|
|
{
|
|
|
|
|
if (!node) {
|
|
|
|
|
return LAB_SSD_NONE;
|
2022-05-26 00:39:04 +02:00
|
|
|
} else if (node->type == WLR_SCENE_NODE_BUFFER
|
|
|
|
|
&& lab_wlr_surface_from_node(node)) {
|
2022-02-21 03:18:38 +01:00
|
|
|
return LAB_SSD_CLIENT;
|
|
|
|
|
} else if (!view->ssd.tree) {
|
|
|
|
|
return LAB_SSD_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wl_list *part_list = NULL;
|
2022-06-05 15:17:35 +02:00
|
|
|
struct wlr_scene_tree *grandparent =
|
|
|
|
|
node->parent ? node->parent->node.parent : NULL;
|
2022-09-08 13:16:19 -04:00
|
|
|
struct wlr_scene_tree *greatgrandparent =
|
|
|
|
|
grandparent ? grandparent->node.parent : NULL;
|
2022-02-21 03:18:38 +01:00
|
|
|
|
|
|
|
|
/* active titlebar */
|
2022-06-05 15:17:35 +02:00
|
|
|
if (node->parent == view->ssd.titlebar.active.tree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
part_list = &view->ssd.titlebar.active.parts;
|
2022-06-05 15:17:35 +02:00
|
|
|
} else if (grandparent == view->ssd.titlebar.active.tree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
part_list = &view->ssd.titlebar.active.parts;
|
2022-09-08 13:16:19 -04:00
|
|
|
} else if (greatgrandparent == view->ssd.titlebar.active.tree) {
|
|
|
|
|
part_list = &view->ssd.titlebar.active.parts;
|
2022-02-21 03:18:38 +01:00
|
|
|
|
|
|
|
|
/* extents */
|
2022-06-05 15:17:35 +02:00
|
|
|
} else if (node->parent == view->ssd.extents.tree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
part_list = &view->ssd.extents.parts;
|
|
|
|
|
|
|
|
|
|
/* active border */
|
2022-06-05 15:17:35 +02:00
|
|
|
} else if (node->parent == view->ssd.border.active.tree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
part_list = &view->ssd.border.active.parts;
|
|
|
|
|
|
|
|
|
|
/* inactive titlebar */
|
2022-06-05 15:17:35 +02:00
|
|
|
} else if (node->parent == view->ssd.titlebar.inactive.tree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
part_list = &view->ssd.titlebar.inactive.parts;
|
2022-06-05 15:17:35 +02:00
|
|
|
} else if (grandparent == view->ssd.titlebar.inactive.tree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
part_list = &view->ssd.titlebar.inactive.parts;
|
2022-09-08 13:16:19 -04:00
|
|
|
} else if (greatgrandparent == view->ssd.titlebar.inactive.tree) {
|
|
|
|
|
part_list = &view->ssd.titlebar.inactive.parts;
|
2022-02-21 03:18:38 +01:00
|
|
|
|
|
|
|
|
/* inactive border */
|
2022-06-05 15:17:35 +02:00
|
|
|
} else if (node->parent == view->ssd.border.inactive.tree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
part_list = &view->ssd.border.inactive.parts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (part_list) {
|
|
|
|
|
struct ssd_part *part;
|
|
|
|
|
wl_list_for_each(part, part_list, link) {
|
|
|
|
|
if (node == part->node) {
|
|
|
|
|
return part->type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return LAB_SSD_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ssd_part_type
|
|
|
|
|
ssd_at(struct view *view, double lx, double ly)
|
|
|
|
|
{
|
|
|
|
|
double sx, sy;
|
|
|
|
|
struct wlr_scene_node *node = wlr_scene_node_at(
|
2022-06-04 23:38:37 +02:00
|
|
|
&view->server->scene->tree.node, lx, ly, &sx, &sy);
|
2022-02-21 03:18:38 +01:00
|
|
|
return ssd_get_part_type(view, node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
|
ssd_resize_edges(enum ssd_part_type type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case LAB_SSD_PART_TOP:
|
|
|
|
|
return WLR_EDGE_TOP;
|
|
|
|
|
case LAB_SSD_PART_RIGHT:
|
|
|
|
|
return WLR_EDGE_RIGHT;
|
|
|
|
|
case LAB_SSD_PART_BOTTOM:
|
|
|
|
|
return WLR_EDGE_BOTTOM;
|
|
|
|
|
case LAB_SSD_PART_LEFT:
|
|
|
|
|
return WLR_EDGE_LEFT;
|
|
|
|
|
case LAB_SSD_PART_CORNER_TOP_LEFT:
|
|
|
|
|
return WLR_EDGE_TOP | WLR_EDGE_LEFT;
|
|
|
|
|
case LAB_SSD_PART_CORNER_TOP_RIGHT:
|
|
|
|
|
return WLR_EDGE_RIGHT | WLR_EDGE_TOP;
|
|
|
|
|
case LAB_SSD_PART_CORNER_BOTTOM_RIGHT:
|
|
|
|
|
return WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT;
|
|
|
|
|
case LAB_SSD_PART_CORNER_BOTTOM_LEFT:
|
|
|
|
|
return WLR_EDGE_BOTTOM | WLR_EDGE_LEFT;
|
|
|
|
|
default:
|
2022-09-16 02:23:44 +02:00
|
|
|
return WLR_EDGE_NONE;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-11-26 02:17:04 -05:00
|
|
|
ssd_create(struct view *view, bool active)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2022-11-26 02:17:04 -05:00
|
|
|
assert(!view->ssd.tree);
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2022-06-05 15:17:35 +02:00
|
|
|
view->ssd.tree = wlr_scene_tree_create(view->scene_tree);
|
2022-02-21 03:18:38 +01:00
|
|
|
wlr_scene_node_lower_to_bottom(&view->ssd.tree->node);
|
|
|
|
|
ssd_extents_create(view);
|
2022-03-06 17:06:14 +00:00
|
|
|
ssd_border_create(view);
|
2022-03-10 06:50:42 +01:00
|
|
|
ssd_titlebar_create(view);
|
2022-11-21 15:13:43 -05:00
|
|
|
view->ssd.margin = ssd_thickness(view);
|
2022-11-26 02:17:04 -05:00
|
|
|
ssd_set_active(view, active);
|
2022-11-26 02:23:15 -05:00
|
|
|
|
|
|
|
|
view->ssd.state.width = view->w;
|
|
|
|
|
view->ssd.state.height = view->h;
|
|
|
|
|
view->ssd.state.x = view->x;
|
|
|
|
|
view->ssd.state.y = view->y;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ssd_update_geometry(struct view *view)
|
|
|
|
|
{
|
2022-11-26 02:00:38 -05:00
|
|
|
if (!view->ssd.tree) {
|
2022-03-10 06:50:42 +01:00
|
|
|
return;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-26 02:22:03 -05:00
|
|
|
if (view->w == view->ssd.state.width && view->h == view->ssd.state.height) {
|
2022-03-10 06:50:42 +01:00
|
|
|
if (view->x != view->ssd.state.x || view->y != view->ssd.state.y) {
|
|
|
|
|
/* Dynamically resize extents based on position and usable_area */
|
|
|
|
|
ssd_extents_update(view);
|
|
|
|
|
view->ssd.state.x = view->x;
|
|
|
|
|
view->ssd.state.y = view->y;
|
|
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ssd_extents_update(view);
|
|
|
|
|
ssd_border_update(view);
|
|
|
|
|
ssd_titlebar_update(view);
|
|
|
|
|
|
2022-11-26 02:22:03 -05:00
|
|
|
view->ssd.state.width = view->w;
|
|
|
|
|
view->ssd.state.height = view->h;
|
2022-03-10 06:50:42 +01:00
|
|
|
view->ssd.state.x = view->x;
|
|
|
|
|
view->ssd.state.y = view->y;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ssd_destroy(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
if (!view->ssd.tree) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Maybe reset hover view */
|
|
|
|
|
struct ssd_hover_state *hover_state;
|
|
|
|
|
hover_state = &view->server->ssd_hover_state;
|
|
|
|
|
if (hover_state->view == view) {
|
|
|
|
|
hover_state->view = NULL;
|
|
|
|
|
hover_state->node = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Destroy subcomponents */
|
|
|
|
|
ssd_titlebar_destroy(view);
|
|
|
|
|
ssd_border_destroy(view);
|
|
|
|
|
ssd_extents_destroy(view);
|
|
|
|
|
wlr_scene_node_destroy(&view->ssd.tree->node);
|
|
|
|
|
view->ssd.tree = NULL;
|
2022-11-26 02:23:15 -05:00
|
|
|
view->ssd.margin = (struct border){ 0 };
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ssd_part_contains(enum ssd_part_type whole, enum ssd_part_type candidate)
|
|
|
|
|
{
|
|
|
|
|
if (whole == candidate) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (whole == LAB_SSD_PART_TITLEBAR) {
|
|
|
|
|
return candidate >= LAB_SSD_BUTTON_CLOSE
|
|
|
|
|
&& candidate <= LAB_SSD_PART_TITLE;
|
|
|
|
|
}
|
2022-09-08 13:20:48 -04:00
|
|
|
if (whole == LAB_SSD_PART_TITLE) {
|
|
|
|
|
/* "Title" includes blank areas of "Titlebar" as well */
|
|
|
|
|
return candidate >= LAB_SSD_PART_TITLEBAR
|
|
|
|
|
&& candidate <= LAB_SSD_PART_TITLE;
|
|
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
if (whole == LAB_SSD_FRAME) {
|
|
|
|
|
return candidate >= LAB_SSD_BUTTON_CLOSE
|
|
|
|
|
&& candidate <= LAB_SSD_CLIENT;
|
|
|
|
|
}
|
|
|
|
|
if (whole == LAB_SSD_PART_TOP) {
|
|
|
|
|
return candidate == LAB_SSD_PART_CORNER_TOP_LEFT
|
|
|
|
|
|| candidate == LAB_SSD_PART_CORNER_BOTTOM_LEFT;
|
|
|
|
|
}
|
|
|
|
|
if (whole == LAB_SSD_PART_RIGHT) {
|
|
|
|
|
return candidate == LAB_SSD_PART_CORNER_TOP_RIGHT
|
|
|
|
|
|| candidate == LAB_SSD_PART_CORNER_BOTTOM_RIGHT;
|
|
|
|
|
}
|
|
|
|
|
if (whole == LAB_SSD_PART_BOTTOM) {
|
|
|
|
|
return candidate == LAB_SSD_PART_CORNER_BOTTOM_RIGHT
|
|
|
|
|
|| candidate == LAB_SSD_PART_CORNER_BOTTOM_LEFT;
|
|
|
|
|
}
|
|
|
|
|
if (whole == LAB_SSD_PART_LEFT) {
|
|
|
|
|
return candidate == LAB_SSD_PART_CORNER_TOP_LEFT
|
|
|
|
|
|| candidate == LAB_SSD_PART_CORNER_BOTTOM_LEFT;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-08-26 02:02:19 -04:00
|
|
|
ssd_set_active(struct view *view, bool active)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
|
|
|
|
if (!view->ssd.tree) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-08-26 02:02:19 -04:00
|
|
|
wlr_scene_node_set_enabled(&view->ssd.border.active.tree->node, active);
|
|
|
|
|
wlr_scene_node_set_enabled(&view->ssd.titlebar.active.tree->node, active);
|
|
|
|
|
wlr_scene_node_set_enabled(&view->ssd.border.inactive.tree->node, !active);
|
|
|
|
|
wlr_scene_node_set_enabled(&view->ssd.titlebar.inactive.tree->node, !active);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|