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>
|
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
|
|
|
|
2022-11-26 16:06:22 -05:00
|
|
|
#define FOR_EACH_STATE(ssd, tmp) FOR_EACH(tmp, \
|
|
|
|
|
&(ssd)->border.active, \
|
|
|
|
|
&(ssd)->border.inactive)
|
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;
|
|
|
|
|
|
|
|
|
|
float *color;
|
2022-06-05 15:17:35 +02:00
|
|
|
struct wlr_scene_tree *parent;
|
2022-02-21 03:18:38 +01:00
|
|
|
struct ssd_sub_tree *subtree;
|
|
|
|
|
|
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);
|
|
|
|
|
|
2022-11-26 16:06:22 -05:00
|
|
|
FOR_EACH_STATE(ssd, subtree) {
|
2023-08-23 01:04:40 +02:00
|
|
|
subtree->tree = wlr_scene_tree_create(ssd->border.tree);
|
2022-06-05 15:17:35 +02:00
|
|
|
parent = subtree->tree;
|
2022-11-26 16:06:22 -05:00
|
|
|
if (subtree == &ssd->border.active) {
|
2022-02-21 03:18:38 +01:00
|
|
|
color = theme->window_active_border_color;
|
|
|
|
|
} else {
|
|
|
|
|
color = theme->window_inactive_border_color;
|
2022-06-05 15:17:35 +02:00
|
|
|
wlr_scene_node_set_enabled(&parent->node, false);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
wl_list_init(&subtree->parts);
|
|
|
|
|
add_scene_rect(&subtree->parts, LAB_SSD_PART_LEFT, parent,
|
|
|
|
|
theme->border_width, height, 0, 0, color);
|
|
|
|
|
add_scene_rect(&subtree->parts, LAB_SSD_PART_RIGHT, parent,
|
|
|
|
|
theme->border_width, height,
|
|
|
|
|
theme->border_width + width, 0, color);
|
|
|
|
|
add_scene_rect(&subtree->parts, LAB_SSD_PART_BOTTOM, parent,
|
2022-03-09 08:52:33 +01:00
|
|
|
full_width, theme->border_width, 0, height, color);
|
2022-03-06 17:06:14 +00:00
|
|
|
add_scene_rect(&subtree->parts, LAB_SSD_PART_TOP, parent,
|
2024-07-20 11:33:57 +03:00
|
|
|
width - 2 * theme->window_button_width, theme->border_width,
|
|
|
|
|
theme->border_width + theme->window_button_width,
|
2023-04-14 09:01:13 +02:00
|
|
|
-(ssd->titlebar.height + theme->border_width), color);
|
2022-02-21 03:18:38 +01:00
|
|
|
} FOR_EACH_END
|
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-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
|
2024-07-20 11:33:57 +03:00
|
|
|
: width - 2 * theme->window_button_width;
|
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-07-20 11:33:57 +03:00
|
|
|
: theme->border_width + theme->window_button_width;
|
2024-06-22 23:27:37 +02:00
|
|
|
|
2022-02-21 03:18:38 +01:00
|
|
|
struct ssd_part *part;
|
|
|
|
|
struct wlr_scene_rect *rect;
|
|
|
|
|
struct ssd_sub_tree *subtree;
|
2022-11-26 16:06:22 -05:00
|
|
|
FOR_EACH_STATE(ssd, subtree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
wl_list_for_each(part, &subtree->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_LEFT:
|
2022-04-04 20:53:36 +01:00
|
|
|
wlr_scene_rect_set_size(rect,
|
2024-06-22 23:27:37 +02:00
|
|
|
theme->border_width,
|
|
|
|
|
side_height);
|
|
|
|
|
wlr_scene_node_set_position(part->node,
|
|
|
|
|
0,
|
|
|
|
|
side_y);
|
2022-02-21 03:18:38 +01:00
|
|
|
continue;
|
|
|
|
|
case LAB_SSD_PART_RIGHT:
|
2022-04-04 20:53:36 +01:00
|
|
|
wlr_scene_rect_set_size(rect,
|
2024-06-22 23:27:37 +02:00
|
|
|
theme->border_width,
|
|
|
|
|
side_height);
|
2022-04-04 20:53:36 +01:00
|
|
|
wlr_scene_node_set_position(part->node,
|
2024-06-22 23:27:37 +02:00
|
|
|
theme->border_width + width,
|
|
|
|
|
side_y);
|
2022-02-21 03:18:38 +01:00
|
|
|
continue;
|
|
|
|
|
case LAB_SSD_PART_BOTTOM:
|
2022-04-04 20:53:36 +01:00
|
|
|
wlr_scene_rect_set_size(rect,
|
2024-06-22 23:27:37 +02:00
|
|
|
full_width,
|
|
|
|
|
theme->border_width);
|
2022-04-04 20:53:36 +01:00
|
|
|
wlr_scene_node_set_position(part->node,
|
2024-06-22 23:27:37 +02:00
|
|
|
0,
|
|
|
|
|
height);
|
2022-02-21 03:18:38 +01:00
|
|
|
continue;
|
2022-03-06 17:06:14 +00:00
|
|
|
case LAB_SSD_PART_TOP:
|
2024-06-22 23:27:37 +02:00
|
|
|
wlr_scene_rect_set_size(rect,
|
|
|
|
|
top_width,
|
|
|
|
|
theme->border_width);
|
|
|
|
|
wlr_scene_node_set_position(part->node,
|
|
|
|
|
top_x,
|
|
|
|
|
-(ssd->titlebar.height + theme->border_width));
|
2022-03-06 17:06:14 +00:00
|
|
|
continue;
|
2022-02-21 03:18:38 +01:00
|
|
|
default:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} FOR_EACH_END
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
struct ssd_sub_tree *subtree;
|
2022-11-26 16:06:22 -05:00
|
|
|
FOR_EACH_STATE(ssd, subtree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
ssd_destroy_parts(&subtree->parts);
|
|
|
|
|
wlr_scene_node_destroy(&subtree->tree->node);
|
|
|
|
|
subtree->tree = NULL;
|
|
|
|
|
} FOR_EACH_END
|
2023-08-23 01:04:40 +02:00
|
|
|
|
|
|
|
|
wlr_scene_node_destroy(&ssd->border.tree->node);
|
|
|
|
|
ssd->border.tree = NULL;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef FOR_EACH_STATE
|