2022-02-21 03:18:38 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
2023-08-23 01:04:40 +02:00
|
|
|
#include <assert.h>
|
2025-07-28 01:22:10 -04:00
|
|
|
#include <wlr/types/wlr_scene.h>
|
2025-08-13 21:00:11 +09:00
|
|
|
#include "common/macros.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"
|
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
|
|
|
|
|
|
|
|
void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_border_create(struct ssd *ssd)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2023-08-23 01:04:40 +02:00
|
|
|
assert(ssd);
|
|
|
|
|
assert(!ssd->border.tree);
|
|
|
|
|
|
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;
|
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);
|
2022-02-21 03:18:38 +01:00
|
|
|
int full_width = width + 2 * theme->border_width;
|
2024-09-09 17:43:38 +02:00
|
|
|
int corner_width = ssd_get_corner_width();
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2023-08-23 01:04:40 +02:00
|
|
|
ssd->border.tree = wlr_scene_tree_create(ssd->tree);
|
|
|
|
|
wlr_scene_node_set_position(&ssd->border.tree->node, -theme->border_width, 0);
|
|
|
|
|
|
2025-08-13 21:00:11 +09:00
|
|
|
enum ssd_active_state active;
|
|
|
|
|
FOR_EACH_ACTIVE_STATE(active) {
|
|
|
|
|
struct ssd_border_subtree *subtree = &ssd->border.subtrees[active];
|
2023-08-23 01:04:40 +02:00
|
|
|
subtree->tree = wlr_scene_tree_create(ssd->border.tree);
|
2025-08-13 21:00:11 +09:00
|
|
|
struct wlr_scene_tree *parent = subtree->tree;
|
2024-11-12 10:54:59 +09:00
|
|
|
wlr_scene_node_set_enabled(&parent->node, active);
|
2025-08-13 21:00:11 +09:00
|
|
|
float *color = theme->window[active].border_color;
|
|
|
|
|
|
|
|
|
|
subtree->left = wlr_scene_rect_create(parent,
|
|
|
|
|
theme->border_width, height, color);
|
|
|
|
|
wlr_scene_node_set_position(&subtree->left->node, 0, 0);
|
|
|
|
|
|
|
|
|
|
subtree->right = wlr_scene_rect_create(parent,
|
|
|
|
|
theme->border_width, height, color);
|
|
|
|
|
wlr_scene_node_set_position(&subtree->right->node,
|
|
|
|
|
theme->border_width + width, 0);
|
|
|
|
|
|
|
|
|
|
subtree->bottom = wlr_scene_rect_create(parent,
|
|
|
|
|
full_width, theme->border_width, color);
|
|
|
|
|
wlr_scene_node_set_position(&subtree->bottom->node,
|
|
|
|
|
0, height);
|
|
|
|
|
|
|
|
|
|
subtree->top = wlr_scene_rect_create(parent,
|
|
|
|
|
MAX(width - 2 * corner_width, 0), theme->border_width, color);
|
|
|
|
|
wlr_scene_node_set_position(&subtree->top->node,
|
2024-09-09 17:43:38 +02:00
|
|
|
theme->border_width + corner_width,
|
2025-08-13 21:00:11 +09:00
|
|
|
-(ssd->titlebar.height + theme->border_width));
|
|
|
|
|
}
|
2023-08-25 15:37:28 +02:00
|
|
|
|
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->maximized == VIEW_AXIS_BOTH) {
|
2023-08-25 15:37:28 +02:00
|
|
|
wlr_scene_node_set_enabled(&ssd->border.tree->node, false);
|
|
|
|
|
}
|
2024-07-19 21:45:24 +02:00
|
|
|
|
|
|
|
|
if (view->current.width > 0 && view->current.height > 0) {
|
|
|
|
|
/*
|
|
|
|
|
* The SSD is recreated by a Reconfigure request
|
|
|
|
|
* thus we may need to handle squared corners.
|
|
|
|
|
*/
|
|
|
|
|
ssd_border_update(ssd);
|
|
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_border_update(struct ssd *ssd)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2023-08-23 01:04:40 +02:00
|
|
|
assert(ssd);
|
|
|
|
|
assert(ssd->border.tree);
|
|
|
|
|
|
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->maximized == VIEW_AXIS_BOTH
|
|
|
|
|
&& ssd->border.tree->node.enabled) {
|
2023-08-23 01:04:40 +02:00
|
|
|
/* Disable borders on maximize */
|
|
|
|
|
wlr_scene_node_set_enabled(&ssd->border.tree->node, false);
|
|
|
|
|
ssd->margin = ssd_thickness(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->maximized == VIEW_AXIS_BOTH) {
|
2023-08-23 01:04:40 +02:00
|
|
|
return;
|
|
|
|
|
} else if (!ssd->border.tree->node.enabled) {
|
|
|
|
|
/* And re-enabled them when unmaximized */
|
|
|
|
|
wlr_scene_node_set_enabled(&ssd->border.tree->node, true);
|
|
|
|
|
ssd->margin = ssd_thickness(ssd->view);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2022-02-21 03:18:38 +01:00
|
|
|
int full_width = width + 2 * theme->border_width;
|
2024-09-09 17:43:38 +02:00
|
|
|
int corner_width = ssd_get_corner_width();
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2024-06-22 23:27:37 +02:00
|
|
|
/*
|
|
|
|
|
* From here on we have to cover the following border scenarios:
|
|
|
|
|
* Non-tiled (partial border, rounded corners):
|
|
|
|
|
* _____________
|
|
|
|
|
* o oox
|
|
|
|
|
* |---------------|
|
|
|
|
|
* |_______________|
|
|
|
|
|
*
|
|
|
|
|
* Tiled (full border, squared corners):
|
|
|
|
|
* _______________
|
|
|
|
|
* |o oox|
|
|
|
|
|
* |---------------|
|
|
|
|
|
* |_______________|
|
|
|
|
|
*
|
|
|
|
|
* Tiled or non-tiled with zero title height (full boarder, no title):
|
|
|
|
|
* _______________
|
|
|
|
|
* |_______________|
|
|
|
|
|
*/
|
|
|
|
|
|
2024-08-25 16:33:41 +09:00
|
|
|
int side_height = ssd->state.was_squared
|
2024-06-22 23:27:37 +02:00
|
|
|
? height + ssd->titlebar.height
|
|
|
|
|
: height;
|
2024-08-25 16:33:41 +09:00
|
|
|
int side_y = ssd->state.was_squared
|
2024-06-22 23:27:37 +02:00
|
|
|
? -ssd->titlebar.height
|
|
|
|
|
: 0;
|
2024-08-25 16:33:41 +09:00
|
|
|
int top_width = ssd->titlebar.height <= 0 || ssd->state.was_squared
|
2024-06-22 23:27:37 +02:00
|
|
|
? full_width
|
2025-05-04 22:33:12 +09:00
|
|
|
: MAX(width - 2 * corner_width, 0);
|
2024-08-25 16:33:41 +09:00
|
|
|
int top_x = ssd->titlebar.height <= 0 || ssd->state.was_squared
|
2024-06-22 23:27:37 +02:00
|
|
|
? 0
|
2024-09-09 17:43:38 +02:00
|
|
|
: theme->border_width + corner_width;
|
2024-06-22 23:27:37 +02:00
|
|
|
|
2025-08-13 21:00:11 +09:00
|
|
|
enum ssd_active_state active;
|
|
|
|
|
FOR_EACH_ACTIVE_STATE(active) {
|
|
|
|
|
struct ssd_border_subtree *subtree = &ssd->border.subtrees[active];
|
|
|
|
|
|
|
|
|
|
wlr_scene_rect_set_size(subtree->left,
|
|
|
|
|
theme->border_width, side_height);
|
|
|
|
|
wlr_scene_node_set_position(&subtree->left->node,
|
|
|
|
|
0, side_y);
|
|
|
|
|
|
|
|
|
|
wlr_scene_rect_set_size(subtree->right,
|
|
|
|
|
theme->border_width, side_height);
|
|
|
|
|
wlr_scene_node_set_position(&subtree->right->node,
|
|
|
|
|
theme->border_width + width, side_y);
|
|
|
|
|
|
|
|
|
|
wlr_scene_rect_set_size(subtree->bottom,
|
|
|
|
|
full_width, theme->border_width);
|
|
|
|
|
wlr_scene_node_set_position(&subtree->bottom->node,
|
|
|
|
|
0, height);
|
|
|
|
|
|
|
|
|
|
wlr_scene_rect_set_size(subtree->top,
|
|
|
|
|
top_width, theme->border_width);
|
|
|
|
|
wlr_scene_node_set_position(&subtree->top->node,
|
|
|
|
|
top_x, -(ssd->titlebar.height + theme->border_width));
|
|
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_border_destroy(struct ssd *ssd)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2023-08-23 01:04:40 +02:00
|
|
|
assert(ssd);
|
|
|
|
|
assert(ssd->border.tree);
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2023-08-23 01:04:40 +02:00
|
|
|
wlr_scene_node_destroy(&ssd->border.tree->node);
|
2025-08-13 21:00:11 +09:00
|
|
|
ssd->border = (struct ssd_border_scene){0};
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|