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;
|
|
|
|
|
int height = view->current.height;
|
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,
|
2023-01-06 15:56:44 +01:00
|
|
|
width - 2 * SSD_BUTTON_WIDTH, theme->border_width,
|
|
|
|
|
theme->border_width + SSD_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);
|
|
|
|
|
}
|
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;
|
|
|
|
|
int height = view->current.height;
|
2022-02-21 03:18:38 +01:00
|
|
|
int full_width = width + 2 * theme->border_width;
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
rect = lab_wlr_scene_get_rect(part->node);
|
|
|
|
|
switch (part->type) {
|
|
|
|
|
case LAB_SSD_PART_LEFT:
|
2022-04-04 20:53:36 +01:00
|
|
|
wlr_scene_rect_set_size(rect,
|
|
|
|
|
theme->border_width, height);
|
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,
|
|
|
|
|
theme->border_width, height);
|
|
|
|
|
wlr_scene_node_set_position(part->node,
|
|
|
|
|
theme->border_width + width, 0);
|
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,
|
|
|
|
|
full_width, theme->border_width);
|
|
|
|
|
wlr_scene_node_set_position(part->node,
|
|
|
|
|
0, height);
|
2022-02-21 03:18:38 +01:00
|
|
|
continue;
|
2022-03-06 17:06:14 +00:00
|
|
|
case LAB_SSD_PART_TOP:
|
2023-04-14 09:01:13 +02:00
|
|
|
if (ssd->titlebar.height > 0) {
|
|
|
|
|
wlr_scene_rect_set_size(rect,
|
|
|
|
|
width - 2 * SSD_BUTTON_WIDTH,
|
|
|
|
|
theme->border_width);
|
|
|
|
|
wlr_scene_node_set_position(part->node,
|
|
|
|
|
theme->border_width + SSD_BUTTON_WIDTH,
|
|
|
|
|
-(ssd->titlebar.height + theme->border_width));
|
|
|
|
|
} else {
|
|
|
|
|
wlr_scene_rect_set_size(rect,
|
|
|
|
|
full_width, theme->border_width);
|
|
|
|
|
wlr_scene_node_set_position(part->node,
|
|
|
|
|
0, -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
|