labwc/src/ssd/ssd-extents.c

163 lines
5 KiB
C
Raw Normal View History

2022-02-21 03:18:38 +01:00
// SPDX-License-Identifier: GPL-2.0-only
#include <pixman.h>
#include <wlr/types/wlr_scene.h>
#include "config/rcxml.h"
2022-02-21 03:18:38 +01:00
#include "labwc.h"
2025-07-26 15:34:45 -04:00
#include "output.h"
#include "ssd-internal.h"
2022-02-21 03:18:38 +01:00
#include "theme.h"
#include "view.h"
2022-02-21 03:18:38 +01:00
void
ssd_extents_create(struct ssd *ssd)
2022-02-21 03:18:38 +01:00
{
struct view *view = ssd->view;
2022-02-21 03:18:38 +01:00
struct theme *theme = view->server->theme;
int border_width = MAX(0, MAX(rc.resize_minimum_area, theme->border_width));
2022-02-21 03:18:38 +01:00
ssd->extents.tree = wlr_scene_tree_create(ssd->tree);
struct wlr_scene_tree *parent = ssd->extents.tree;
if (view->fullscreen || view->maximized == VIEW_AXIS_BOTH) {
wlr_scene_node_set_enabled(&parent->node, false);
}
wlr_scene_node_set_position(&parent->node,
-border_width, -(ssd->titlebar.height + border_width));
2022-02-21 03:18:38 +01:00
ssd: clean up scene management Our codebase for ssd scenes has grown with a lot of technical debts: - We needed to call `ssd_get_part()` everywhere to get the scene node of a ssd part. We then needed to cast it to `wlr_scene_rect` and `wlr_scene_buffer`. This bloated our codebase and even blocked duplicated button types in `<titlebar><layout>`. - `ssd_get_part_type()` was a dirty hack. It compared parent, grandparent and grandgrandparent of a node with each subtree in the ssd to get the part type of the node. To resolve this issues, this commit changes how ssd scenes are managed: - Access scene rects and scene buffers just as a member of `struct ssd`. - `ssd_part` is now a attachment to a scene node that can be accessed via node_descriptor->data, with a new node-descriptor type `LAB_NODE_DESC_SSD_PART`. `LAB_NODE_DESC_SSD_BUTTON` is unified into it. Now the scene graph under ssd->tree looks like below. The parentheses indicate the type of ssd_part attached to the node: ssd->tree (LAB_SSD_NONE) +--titlebar (LAB_SSD_PART_TITLEBAR) | +--inactive | | +--background bar | | +--left corner | | +--right corner | | +--title (LAB_SSD_PART_TITLE) | | +--iconify button (LAB_SSD_BUTTON_ICONIFY) | | | +--normal close icon image | | | +--hovered close icon image | | | +--... | | +--window icon (LAB_SSD_BUTTON_WINDOW_ICON) | | | +--window icon image | | +--... | +--active | +--... +--border | +--inactive | | +--top | | +--... | +--active | +--top | +--... +--shadow | +--inactive | | +--top | | +--... | +--active | +--top | +--... +--extents +--top +--... When hovering on SSD, `get_cursor_context()` traverses this scene node from the leaf. If it finds a `ssd_part` attached to the node, it returns `ssd_part_type` that represents the resizing direction, button types or `Title`/`Titlebar`.
2025-08-13 21:00:11 +09:00
float invisible[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
ssd->extents.top = wlr_scene_rect_create(parent, 0, 0, invisible);
ssd->extents.left = wlr_scene_rect_create(parent, 0, 0, invisible);
ssd->extents.right = wlr_scene_rect_create(parent, 0, 0, invisible);
ssd->extents.bottom = wlr_scene_rect_create(parent, 0, 0, invisible);
/* Initial manual update to keep X11 applications happy */
ssd_extents_update(ssd);
2022-02-21 03:18:38 +01:00
}
static void
resize_extent_within_usable(struct wlr_scene_rect *rect,
pixman_region32_t *usable, int x, int y, int w, int h)
{
pixman_region32_t intersection;
pixman_region32_init(&intersection);
/* Constrain part to output->usable_area */
pixman_region32_intersect_rect(&intersection, usable, x, y, w, h);
int nrects;
const pixman_box32_t *inter_rects =
pixman_region32_rectangles(&intersection, &nrects);
if (nrects == 0) {
/* Not visible */
wlr_scene_node_set_enabled(&rect->node, false);
goto out;
}
/*
* For each edge, the invisible grab area is resized
* to not cover layer-shell clients such as panels.
* However, only one resize operation is used per edge,
* so if a window is in the unlikely position that it
* is near a panel but also overspills onto another screen,
* the invisible grab-area on the other screen would be
* smaller than would normally be the case.
*
* Thus only use the first intersecting rect, this is
* a compromise as it doesn't require us to create
* multiple scene rects for a given extent edge
* and still works in 95% of the cases.
*/
struct wlr_box result_box = (struct wlr_box) {
.x = inter_rects[0].x1,
.y = inter_rects[0].y1,
.width = inter_rects[0].x2 - inter_rects[0].x1,
.height = inter_rects[0].y2 - inter_rects[0].y1
};
wlr_scene_node_set_enabled(&rect->node, true);
wlr_scene_node_set_position(&rect->node, result_box.x, result_box.y);
wlr_scene_rect_set_size(rect, result_box.width, result_box.height);
out:
pixman_region32_fini(&intersection);
}
2022-02-21 03:18:38 +01:00
void
ssd_extents_update(struct ssd *ssd)
2022-02-21 03:18:38 +01:00
{
struct view *view = ssd->view;
if (view->fullscreen || view->maximized == VIEW_AXIS_BOTH) {
wlr_scene_node_set_enabled(&ssd->extents.tree->node, false);
return;
}
if (!ssd->extents.tree->node.enabled) {
wlr_scene_node_set_enabled(&ssd->extents.tree->node, true);
}
if (!view->output) {
return;
}
2022-02-21 03:18:38 +01:00
struct theme *theme = view->server->theme;
int width = view->current.width;
int height = view_effective_height(view, /* use_pending */ false);
int full_height = height + theme->border_width * 2 + ssd->titlebar.height;
2022-02-21 03:18:38 +01:00
int full_width = width + 2 * theme->border_width;
int border_width = MAX(rc.resize_minimum_area, theme->border_width);
int extended_area = MAX(0, rc.resize_minimum_area - theme->border_width);
2022-02-21 03:18:38 +01:00
/* Make sure we update the y offset based on titlebar shown / hidden */
wlr_scene_node_set_position(&ssd->extents.tree->node,
-border_width, -(ssd->titlebar.height + border_width));
/*
* Convert all output usable areas that the
* view is currently on into a pixman region
*/
pixman_region32_t usable;
pixman_region32_init(&usable);
struct output *output;
wl_list_for_each(output, &view->server->outputs, link) {
if (!view_on_output(view, output)) {
continue;
}
struct wlr_box usable_area =
output_usable_area_in_layout_coords(output);
pixman_region32_union_rect(&usable, &usable, usable_area.x,
usable_area.y, usable_area.width, usable_area.height);
}
/* Move usable area to the coordinate system of extents */
int base_x, base_y;
wlr_scene_node_coords(&ssd->extents.tree->node, &base_x, &base_y);
pixman_region32_translate(&usable, -base_x, -base_y);
ssd: clean up scene management Our codebase for ssd scenes has grown with a lot of technical debts: - We needed to call `ssd_get_part()` everywhere to get the scene node of a ssd part. We then needed to cast it to `wlr_scene_rect` and `wlr_scene_buffer`. This bloated our codebase and even blocked duplicated button types in `<titlebar><layout>`. - `ssd_get_part_type()` was a dirty hack. It compared parent, grandparent and grandgrandparent of a node with each subtree in the ssd to get the part type of the node. To resolve this issues, this commit changes how ssd scenes are managed: - Access scene rects and scene buffers just as a member of `struct ssd`. - `ssd_part` is now a attachment to a scene node that can be accessed via node_descriptor->data, with a new node-descriptor type `LAB_NODE_DESC_SSD_PART`. `LAB_NODE_DESC_SSD_BUTTON` is unified into it. Now the scene graph under ssd->tree looks like below. The parentheses indicate the type of ssd_part attached to the node: ssd->tree (LAB_SSD_NONE) +--titlebar (LAB_SSD_PART_TITLEBAR) | +--inactive | | +--background bar | | +--left corner | | +--right corner | | +--title (LAB_SSD_PART_TITLE) | | +--iconify button (LAB_SSD_BUTTON_ICONIFY) | | | +--normal close icon image | | | +--hovered close icon image | | | +--... | | +--window icon (LAB_SSD_BUTTON_WINDOW_ICON) | | | +--window icon image | | +--... | +--active | +--... +--border | +--inactive | | +--top | | +--... | +--active | +--top | +--... +--shadow | +--inactive | | +--top | | +--... | +--active | +--top | +--... +--extents +--top +--... When hovering on SSD, `get_cursor_context()` traverses this scene node from the leaf. If it finds a `ssd_part` attached to the node, it returns `ssd_part_type` that represents the resizing direction, button types or `Title`/`Titlebar`.
2025-08-13 21:00:11 +09:00
resize_extent_within_usable(ssd->extents.top, &usable,
0, 0,
full_width + extended_area * 2, extended_area);
resize_extent_within_usable(ssd->extents.left, &usable,
0, extended_area,
extended_area, full_height);
resize_extent_within_usable(ssd->extents.right, &usable,
extended_area + full_width, extended_area,
extended_area, full_height);
resize_extent_within_usable(ssd->extents.bottom, &usable,
0, extended_area + full_height,
full_width + extended_area * 2, extended_area);
pixman_region32_fini(&usable);
2022-02-21 03:18:38 +01:00
}
void
ssd_extents_destroy(struct ssd *ssd)
2022-02-21 03:18:38 +01:00
{
if (!ssd->extents.tree) {
2022-02-21 03:18:38 +01:00
return;
}
wlr_scene_node_destroy(&ssd->extents.tree->node);
ssd: clean up scene management Our codebase for ssd scenes has grown with a lot of technical debts: - We needed to call `ssd_get_part()` everywhere to get the scene node of a ssd part. We then needed to cast it to `wlr_scene_rect` and `wlr_scene_buffer`. This bloated our codebase and even blocked duplicated button types in `<titlebar><layout>`. - `ssd_get_part_type()` was a dirty hack. It compared parent, grandparent and grandgrandparent of a node with each subtree in the ssd to get the part type of the node. To resolve this issues, this commit changes how ssd scenes are managed: - Access scene rects and scene buffers just as a member of `struct ssd`. - `ssd_part` is now a attachment to a scene node that can be accessed via node_descriptor->data, with a new node-descriptor type `LAB_NODE_DESC_SSD_PART`. `LAB_NODE_DESC_SSD_BUTTON` is unified into it. Now the scene graph under ssd->tree looks like below. The parentheses indicate the type of ssd_part attached to the node: ssd->tree (LAB_SSD_NONE) +--titlebar (LAB_SSD_PART_TITLEBAR) | +--inactive | | +--background bar | | +--left corner | | +--right corner | | +--title (LAB_SSD_PART_TITLE) | | +--iconify button (LAB_SSD_BUTTON_ICONIFY) | | | +--normal close icon image | | | +--hovered close icon image | | | +--... | | +--window icon (LAB_SSD_BUTTON_WINDOW_ICON) | | | +--window icon image | | +--... | +--active | +--... +--border | +--inactive | | +--top | | +--... | +--active | +--top | +--... +--shadow | +--inactive | | +--top | | +--... | +--active | +--top | +--... +--extents +--top +--... When hovering on SSD, `get_cursor_context()` traverses this scene node from the leaf. If it finds a `ssd_part` attached to the node, it returns `ssd_part_type` that represents the resizing direction, button types or `Title`/`Titlebar`.
2025-08-13 21:00:11 +09:00
ssd->extents = (struct ssd_extents_scene){0};
2022-02-21 03:18:38 +01:00
}