2022-02-21 03:18:38 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
2024-08-25 16:33:41 +09:00
|
|
|
#include <assert.h>
|
2024-01-31 22:09:15 +01:00
|
|
|
#include <pixman.h>
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "common/mem.h"
|
|
|
|
|
#include "common/scene-helpers.h"
|
2025-01-17 11:07:07 -05:00
|
|
|
#include "config/rcxml.h"
|
2022-02-21 03:18:38 +01:00
|
|
|
#include "labwc.h"
|
2022-11-26 16:53:35 -05:00
|
|
|
#include "ssd-internal.h"
|
2022-02-21 03:18:38 +01:00
|
|
|
#include "theme.h"
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "view.h"
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2022-03-10 06:50:42 +01:00
|
|
|
static struct ssd_part *
|
|
|
|
|
add_extent(struct wl_list *part_list, enum ssd_part_type type,
|
2022-06-05 15:17:35 +02:00
|
|
|
struct wlr_scene_tree *parent)
|
2022-03-10 06:50:42 +01:00
|
|
|
{
|
|
|
|
|
float invisible[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
|
|
|
|
struct ssd_part *part = add_scene_part(part_list, type);
|
|
|
|
|
part->node = &wlr_scene_rect_create(parent, 0, 0, invisible)->node;
|
|
|
|
|
return part;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-21 03:18:38 +01:00
|
|
|
void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_extents_create(struct ssd *ssd)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2022-11-26 16:46:28 -05:00
|
|
|
struct view *view = ssd->view;
|
2022-02-21 03:18:38 +01:00
|
|
|
struct theme *theme = view->server->theme;
|
2022-11-26 16:06:22 -05:00
|
|
|
struct wl_list *part_list = &ssd->extents.parts;
|
2025-01-17 11:07:07 -05:00
|
|
|
|
|
|
|
|
int border_width = MAX(0, MAX(rc.resize_minimum_area, theme->border_width));
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd->extents.tree = wlr_scene_tree_create(ssd->tree);
|
|
|
|
|
struct wlr_scene_tree *parent = ssd->extents.tree;
|
view: implement separate horizontal/vertical maximize
This is a useful (if lesser-known) feature of at least a few popular X11
window managers, for example Openbox and XFWM4. Typically right-click on
the maximize button toggles horizontal maximize, while middle-click
toggles vertical maximize.
Support in labwc uses the same configuration syntax as Openbox, where the
Maximize/ToggleMaximize actions have an optional "direction" argument:
horizontal, vertical, or both (default). The default mouse bindings match
the XFWM4 defaults (not sure what Openbox has by default).
Most of the external protocols still assume "maximized" is a Boolean,
which is no longer true internally. For the sake of the outside world,
a view is only "maximized" if maximized in both directions.
Internally, I've taken the following approach:
- SSD code decorates the view as "maximized" (i.e. hiding borders) only
if maximized in both directions.
- Layout code (interactive move/resize, tiling, etc.) generally treats
the view as "maximized" (with the restrictions that entails) if
maximized in either direction. For example, moving a vertically-
maximized view first restores the natural geometry (this differs from
Openbox, which instead allows the view to move only horizontally.)
v2: use enum view_axis for view->maximized
v3:
- update docs
- allow resizing if partly maximized
- add TODOs & corrections noted by Consolatis
2023-10-26 00:38:29 -04:00
|
|
|
if (view->fullscreen || view->maximized == VIEW_AXIS_BOTH) {
|
2022-06-05 15:17:35 +02:00
|
|
|
wlr_scene_node_set_enabled(&parent->node, false);
|
2022-03-04 04:38:06 +01:00
|
|
|
}
|
2022-11-26 16:06:22 -05:00
|
|
|
wl_list_init(&ssd->extents.parts);
|
2022-06-05 15:17:35 +02:00
|
|
|
wlr_scene_node_set_position(&parent->node,
|
2025-01-17 11:07:07 -05:00
|
|
|
-border_width, -(ssd->titlebar.height + border_width));
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2024-08-25 16:33:41 +09:00
|
|
|
add_extent(part_list, LAB_SSD_PART_TOP, parent);
|
|
|
|
|
add_extent(part_list, LAB_SSD_PART_LEFT, parent);
|
|
|
|
|
add_extent(part_list, LAB_SSD_PART_RIGHT, parent);
|
|
|
|
|
add_extent(part_list, LAB_SSD_PART_BOTTOM, parent);
|
2022-03-11 06:23:08 +01:00
|
|
|
|
|
|
|
|
/* Initial manual update to keep X11 applications happy */
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_extents_update(ssd);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_extents_update(struct ssd *ssd)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2022-11-26 16:46:28 -05:00
|
|
|
struct view *view = ssd->view;
|
view: implement separate horizontal/vertical maximize
This is a useful (if lesser-known) feature of at least a few popular X11
window managers, for example Openbox and XFWM4. Typically right-click on
the maximize button toggles horizontal maximize, while middle-click
toggles vertical maximize.
Support in labwc uses the same configuration syntax as Openbox, where the
Maximize/ToggleMaximize actions have an optional "direction" argument:
horizontal, vertical, or both (default). The default mouse bindings match
the XFWM4 defaults (not sure what Openbox has by default).
Most of the external protocols still assume "maximized" is a Boolean,
which is no longer true internally. For the sake of the outside world,
a view is only "maximized" if maximized in both directions.
Internally, I've taken the following approach:
- SSD code decorates the view as "maximized" (i.e. hiding borders) only
if maximized in both directions.
- Layout code (interactive move/resize, tiling, etc.) generally treats
the view as "maximized" (with the restrictions that entails) if
maximized in either direction. For example, moving a vertically-
maximized view first restores the natural geometry (this differs from
Openbox, which instead allows the view to move only horizontally.)
v2: use enum view_axis for view->maximized
v3:
- update docs
- allow resizing if partly maximized
- add TODOs & corrections noted by Consolatis
2023-10-26 00:38:29 -04:00
|
|
|
if (view->fullscreen || view->maximized == VIEW_AXIS_BOTH) {
|
2022-11-26 16:06:22 -05:00
|
|
|
wlr_scene_node_set_enabled(&ssd->extents.tree->node, false);
|
2022-03-04 04:38:06 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2022-11-26 16:06:22 -05:00
|
|
|
if (!ssd->extents.tree->node.enabled) {
|
|
|
|
|
wlr_scene_node_set_enabled(&ssd->extents.tree->node, true);
|
2022-03-04 04:38:06 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-10 06:50:42 +01:00
|
|
|
if (!view->output) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-21 03:18:38 +01:00
|
|
|
struct theme *theme = view->server->theme;
|
|
|
|
|
|
2023-02-08 23:19:14 -05:00
|
|
|
int width = view->current.width;
|
2023-08-08 03:39:35 +02:00
|
|
|
int height = view_effective_height(view, /* use_pending */ false);
|
2023-04-14 09:01:13 +02:00
|
|
|
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;
|
2025-01-17 11:07:07 -05:00
|
|
|
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
|
|
|
|
2022-03-10 06:50:42 +01:00
|
|
|
struct wlr_box part_box;
|
|
|
|
|
struct wlr_box result_box;
|
2022-02-21 03:18:38 +01:00
|
|
|
struct ssd_part *part;
|
|
|
|
|
struct wlr_scene_rect *rect;
|
2024-08-25 16:33:41 +09:00
|
|
|
struct wlr_box target;
|
2022-03-10 06:50:42 +01:00
|
|
|
|
2023-04-14 09:01:13 +02:00
|
|
|
/* Make sure we update the y offset based on titlebar shown / hidden */
|
|
|
|
|
wlr_scene_node_set_position(&ssd->extents.tree->node,
|
2025-01-17 11:07:07 -05:00
|
|
|
-border_width, -(ssd->titlebar.height + border_width));
|
2023-04-14 09:01:13 +02:00
|
|
|
|
2024-01-31 22:09:15 +01:00
|
|
|
/*
|
|
|
|
|
* Convert all output usable areas that the
|
|
|
|
|
* view is currently on into a pixman region
|
|
|
|
|
*/
|
|
|
|
|
int nrects;
|
|
|
|
|
pixman_region32_t usable;
|
|
|
|
|
pixman_region32_t intersection;
|
|
|
|
|
pixman_region32_init(&usable);
|
|
|
|
|
pixman_region32_init(&intersection);
|
|
|
|
|
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);
|
|
|
|
|
}
|
2022-03-10 06:50:42 +01:00
|
|
|
|
|
|
|
|
/* Remember base layout coordinates */
|
|
|
|
|
int base_x, base_y;
|
2022-11-26 16:06:22 -05:00
|
|
|
wlr_scene_node_coords(&ssd->extents.tree->node, &base_x, &base_y);
|
2022-03-10 06:50:42 +01:00
|
|
|
|
2022-11-26 16:06:22 -05:00
|
|
|
wl_list_for_each(part, &ssd->extents.parts, link) {
|
2023-12-03 16:36:20 +08:00
|
|
|
rect = wlr_scene_rect_from_node(part->node);
|
2022-02-21 03:18:38 +01:00
|
|
|
switch (part->type) {
|
|
|
|
|
case LAB_SSD_PART_TOP:
|
2025-02-01 14:51:47 +09:00
|
|
|
target.x = 0;
|
2024-08-25 16:33:41 +09:00
|
|
|
target.y = 0;
|
2025-02-01 14:51:47 +09:00
|
|
|
target.width = full_width + extended_area * 2;
|
2024-08-25 16:33:41 +09:00
|
|
|
target.height = extended_area;
|
2022-03-10 06:50:42 +01:00
|
|
|
break;
|
2022-02-21 03:18:38 +01:00
|
|
|
case LAB_SSD_PART_LEFT:
|
2024-08-25 16:33:41 +09:00
|
|
|
target.x = 0;
|
2025-02-01 14:51:47 +09:00
|
|
|
target.y = extended_area;
|
2024-08-25 16:33:41 +09:00
|
|
|
target.width = extended_area;
|
2025-02-01 14:51:47 +09:00
|
|
|
target.height = full_height;
|
2022-03-10 06:50:42 +01:00
|
|
|
break;
|
2022-02-21 03:18:38 +01:00
|
|
|
case LAB_SSD_PART_RIGHT:
|
2024-08-25 16:33:41 +09:00
|
|
|
target.x = extended_area + full_width;
|
2025-02-01 14:51:47 +09:00
|
|
|
target.y = extended_area;
|
2024-08-25 16:33:41 +09:00
|
|
|
target.width = extended_area;
|
2025-02-01 14:51:47 +09:00
|
|
|
target.height = full_height;
|
2022-03-10 06:50:42 +01:00
|
|
|
break;
|
2022-02-21 03:18:38 +01:00
|
|
|
case LAB_SSD_PART_BOTTOM:
|
2025-02-01 14:51:47 +09:00
|
|
|
target.x = 0;
|
2024-08-25 16:33:41 +09:00
|
|
|
target.y = extended_area + full_height;
|
2025-02-01 14:51:47 +09:00
|
|
|
target.width = full_width + extended_area * 2;
|
2024-08-25 16:33:41 +09:00
|
|
|
target.height = extended_area;
|
2022-03-10 06:50:42 +01:00
|
|
|
break;
|
2022-02-21 03:18:38 +01:00
|
|
|
default:
|
2024-08-25 16:33:41 +09:00
|
|
|
/* not reached */
|
|
|
|
|
assert(false);
|
|
|
|
|
/* suppress warnings with NDEBUG */
|
|
|
|
|
target = (struct wlr_box){0};
|
2022-03-10 06:50:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get layout geometry of what the part *should* be */
|
2024-08-25 16:33:41 +09:00
|
|
|
part_box.x = base_x + target.x;
|
|
|
|
|
part_box.y = base_y + target.y;
|
|
|
|
|
part_box.width = target.width;
|
|
|
|
|
part_box.height = target.height;
|
2022-03-10 06:50:42 +01:00
|
|
|
|
|
|
|
|
/* Constrain part to output->usable_area */
|
2024-01-31 22:09:15 +01:00
|
|
|
pixman_region32_clear(&intersection);
|
|
|
|
|
pixman_region32_intersect_rect(&intersection, &usable,
|
|
|
|
|
part_box.x, part_box.y, part_box.width, part_box.height);
|
|
|
|
|
const pixman_box32_t *inter_rects =
|
|
|
|
|
pixman_region32_rectangles(&intersection, &nrects);
|
|
|
|
|
|
|
|
|
|
if (nrects == 0) {
|
2022-03-10 06:50:42 +01:00
|
|
|
/* Not visible */
|
|
|
|
|
wlr_scene_node_set_enabled(part->node, false);
|
|
|
|
|
continue;
|
2024-01-31 22:09:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!part->node->enabled) {
|
2022-03-10 06:50:42 +01:00
|
|
|
wlr_scene_node_set_enabled(part->node, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (part_box.width != result_box.width
|
|
|
|
|
|| part_box.height != result_box.height) {
|
|
|
|
|
/* Partly visible */
|
2022-04-04 20:53:36 +01:00
|
|
|
wlr_scene_rect_set_size(rect, result_box.width,
|
|
|
|
|
result_box.height);
|
2022-03-10 06:50:42 +01:00
|
|
|
wlr_scene_node_set_position(part->node,
|
2024-08-25 16:33:41 +09:00
|
|
|
target.x + (result_box.x - part_box.x),
|
|
|
|
|
target.y + (result_box.y - part_box.y));
|
|
|
|
|
} else {
|
|
|
|
|
/* Fully visible */
|
|
|
|
|
wlr_scene_node_set_position(part->node, target.x, target.y);
|
|
|
|
|
wlr_scene_rect_set_size(rect, target.width, target.height);
|
2022-03-10 06:50:42 +01:00
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
2024-01-31 22:09:15 +01:00
|
|
|
pixman_region32_fini(&intersection);
|
|
|
|
|
pixman_region32_fini(&usable);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_extents_destroy(struct ssd *ssd)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2022-11-26 16:06:22 -05:00
|
|
|
if (!ssd->extents.tree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_destroy_parts(&ssd->extents.parts);
|
|
|
|
|
wlr_scene_node_destroy(&ssd->extents.tree->node);
|
|
|
|
|
ssd->extents.tree = NULL;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|