2022-02-21 03:18:38 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <string.h>
|
2022-11-26 16:06:22 -05:00
|
|
|
#include "buffer.h"
|
2022-09-16 18:41:02 -04:00
|
|
|
#include "common/mem.h"
|
2022-06-12 21:22:49 +02:00
|
|
|
#include "common/scaled_font_buffer.h"
|
2022-02-21 03:18:38 +01:00
|
|
|
#include "common/scene-helpers.h"
|
2024-01-19 19:06:07 +00:00
|
|
|
#include "common/string-helpers.h"
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "labwc.h"
|
2022-06-08 19:51:02 +02:00
|
|
|
#include "node.h"
|
2022-11-26 16:53:35 -05:00
|
|
|
#include "ssd-internal.h"
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "theme.h"
|
|
|
|
|
#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)->titlebar.active, \
|
|
|
|
|
&(ssd)->titlebar.inactive)
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2023-08-25 15:37:28 +02:00
|
|
|
static void set_squared_corners(struct ssd *ssd, bool enable);
|
2023-12-06 22:07:06 +01:00
|
|
|
static void set_maximize_alt_icon(struct ssd *ssd, bool enable);
|
2023-08-25 15:37:28 +02:00
|
|
|
|
2022-02-21 03:18:38 +01:00
|
|
|
void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_titlebar_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;
|
2023-02-08 23:19:14 -05:00
|
|
|
int width = view->current.width;
|
2022-02-21 03:18:38 +01:00
|
|
|
|
|
|
|
|
float *color;
|
2022-06-05 15:17:35 +02:00
|
|
|
struct wlr_scene_tree *parent;
|
2022-02-21 03:18:38 +01:00
|
|
|
struct wlr_buffer *corner_top_left;
|
|
|
|
|
struct wlr_buffer *corner_top_right;
|
|
|
|
|
|
2022-11-20 23:38:17 -06:00
|
|
|
struct wlr_buffer *menu_button_unpressed;
|
|
|
|
|
struct wlr_buffer *iconify_button_unpressed;
|
|
|
|
|
struct wlr_buffer *maximize_button_unpressed;
|
2023-12-06 20:33:26 +00:00
|
|
|
struct wlr_buffer *restore_button_unpressed;
|
2022-11-20 23:38:17 -06:00
|
|
|
struct wlr_buffer *close_button_unpressed;
|
|
|
|
|
|
2023-12-06 20:33:26 +00:00
|
|
|
struct wlr_buffer *menu_button_hover;
|
|
|
|
|
struct wlr_buffer *iconify_button_hover;
|
|
|
|
|
struct wlr_buffer *maximize_button_hover;
|
|
|
|
|
struct wlr_buffer *restore_button_hover;
|
|
|
|
|
struct wlr_buffer *close_button_hover;
|
|
|
|
|
|
2023-04-14 09:01:13 +02:00
|
|
|
ssd->titlebar.tree = wlr_scene_tree_create(ssd->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) {
|
2023-04-14 09:01:13 +02:00
|
|
|
subtree->tree = wlr_scene_tree_create(ssd->titlebar.tree);
|
2022-06-05 15:17:35 +02:00
|
|
|
parent = subtree->tree;
|
|
|
|
|
wlr_scene_node_set_position(&parent->node, 0, -theme->title_height);
|
2022-11-26 16:06:22 -05:00
|
|
|
if (subtree == &ssd->titlebar.active) {
|
2022-02-21 03:18:38 +01:00
|
|
|
color = theme->window_active_title_bg_color;
|
|
|
|
|
corner_top_left = &theme->corner_top_left_active_normal->base;
|
|
|
|
|
corner_top_right = &theme->corner_top_right_active_normal->base;
|
2023-08-04 22:30:16 +01:00
|
|
|
menu_button_unpressed = &theme->button_menu_active_unpressed->base;
|
|
|
|
|
iconify_button_unpressed = &theme->button_iconify_active_unpressed->base;
|
|
|
|
|
close_button_unpressed = &theme->button_close_active_unpressed->base;
|
|
|
|
|
maximize_button_unpressed = &theme->button_maximize_active_unpressed->base;
|
2023-12-06 20:33:26 +00:00
|
|
|
restore_button_unpressed = &theme->button_restore_active_unpressed->base;
|
2023-12-16 09:56:45 -05:00
|
|
|
|
2023-12-06 20:33:26 +00:00
|
|
|
menu_button_hover = &theme->button_menu_active_hover->base;
|
|
|
|
|
iconify_button_hover = &theme->button_iconify_active_hover->base;
|
|
|
|
|
close_button_hover = &theme->button_close_active_hover->base;
|
|
|
|
|
maximize_button_hover = &theme->button_maximize_active_hover->base;
|
|
|
|
|
restore_button_hover = &theme->button_restore_active_hover->base;
|
2022-02-21 03:18:38 +01:00
|
|
|
} else {
|
|
|
|
|
color = theme->window_inactive_title_bg_color;
|
|
|
|
|
corner_top_left = &theme->corner_top_left_inactive_normal->base;
|
|
|
|
|
corner_top_right = &theme->corner_top_right_inactive_normal->base;
|
2023-08-04 22:30:16 +01:00
|
|
|
menu_button_unpressed = &theme->button_menu_inactive_unpressed->base;
|
|
|
|
|
iconify_button_unpressed = &theme->button_iconify_inactive_unpressed->base;
|
2023-08-04 22:34:07 +01:00
|
|
|
maximize_button_unpressed =
|
|
|
|
|
&theme->button_maximize_inactive_unpressed->base;
|
2023-12-06 20:33:26 +00:00
|
|
|
restore_button_unpressed = &theme->button_restore_inactive_unpressed->base;
|
2023-08-04 22:30:16 +01:00
|
|
|
close_button_unpressed = &theme->button_close_inactive_unpressed->base;
|
2023-12-16 09:56:45 -05:00
|
|
|
|
2023-12-06 20:33:26 +00:00
|
|
|
menu_button_hover = &theme->button_menu_inactive_hover->base;
|
|
|
|
|
iconify_button_hover = &theme->button_iconify_inactive_hover->base;
|
|
|
|
|
close_button_hover = &theme->button_close_inactive_hover->base;
|
|
|
|
|
maximize_button_hover = &theme->button_maximize_inactive_hover->base;
|
|
|
|
|
restore_button_hover = &theme->button_restore_inactive_hover->base;
|
2023-12-16 09:56:45 -05:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
/* Title */
|
|
|
|
|
add_scene_rect(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent,
|
2023-01-06 15:56:44 +01:00
|
|
|
width - SSD_BUTTON_WIDTH * SSD_BUTTON_COUNT, theme->title_height,
|
|
|
|
|
SSD_BUTTON_WIDTH, 0, color);
|
2022-02-21 03:18:38 +01:00
|
|
|
/* Buttons */
|
2022-06-08 14:37:30 +02:00
|
|
|
add_scene_button_corner(&subtree->parts,
|
|
|
|
|
LAB_SSD_BUTTON_WINDOW_MENU, LAB_SSD_PART_CORNER_TOP_LEFT, parent,
|
2023-12-06 20:33:26 +00:00
|
|
|
corner_top_left, menu_button_unpressed, menu_button_hover, 0, view);
|
2022-02-21 03:18:38 +01:00
|
|
|
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent,
|
2023-12-06 20:33:26 +00:00
|
|
|
color, iconify_button_unpressed, iconify_button_hover,
|
2023-01-06 15:56:44 +01:00
|
|
|
width - SSD_BUTTON_WIDTH * 3, view);
|
2024-04-08 17:56:56 +02:00
|
|
|
|
|
|
|
|
/* Maximize button has an alternate state when maximized */
|
|
|
|
|
struct ssd_part *btn_max_root = add_scene_button(
|
|
|
|
|
&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE, parent,
|
2023-12-06 20:33:26 +00:00
|
|
|
color, maximize_button_unpressed, maximize_button_hover,
|
2023-01-06 15:56:44 +01:00
|
|
|
width - SSD_BUTTON_WIDTH * 2, view);
|
2024-04-08 17:56:56 +02:00
|
|
|
struct ssd_button *btn_max = node_ssd_button_from_node(btn_max_root->node);
|
|
|
|
|
add_toggled_icon(btn_max, &subtree->parts, LAB_SSD_BUTTON_MAXIMIZE,
|
2023-12-06 20:33:26 +00:00
|
|
|
restore_button_unpressed, restore_button_hover);
|
2024-04-08 17:56:56 +02:00
|
|
|
|
2022-06-08 14:37:30 +02:00
|
|
|
add_scene_button_corner(&subtree->parts,
|
|
|
|
|
LAB_SSD_BUTTON_CLOSE, LAB_SSD_PART_CORNER_TOP_RIGHT, parent,
|
2023-12-06 20:33:26 +00:00
|
|
|
corner_top_right, close_button_unpressed, close_button_hover,
|
2023-01-06 15:56:44 +01:00
|
|
|
width - SSD_BUTTON_WIDTH * 1, view);
|
2022-02-21 03:18:38 +01:00
|
|
|
} FOR_EACH_END
|
2023-08-25 15:37:28 +02:00
|
|
|
|
2022-11-26 16:46:28 -05:00
|
|
|
ssd_update_title(ssd);
|
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) {
|
|
|
|
|
set_squared_corners(ssd, true);
|
2023-12-06 22:07:06 +01:00
|
|
|
set_maximize_alt_icon(ssd, true);
|
|
|
|
|
ssd->state.was_maximized = true;
|
2023-08-25 15:37:28 +02:00
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
is_direct_child(struct wlr_scene_node *node, struct ssd_sub_tree *subtree)
|
|
|
|
|
{
|
2022-06-05 15:17:35 +02:00
|
|
|
return node->parent == subtree->tree;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-23 04:42:30 +02:00
|
|
|
static void
|
|
|
|
|
set_squared_corners(struct ssd *ssd, bool enable)
|
|
|
|
|
{
|
|
|
|
|
struct ssd_part *part;
|
|
|
|
|
struct ssd_sub_tree *subtree;
|
|
|
|
|
enum ssd_part_type ssd_type[2] = { LAB_SSD_BUTTON_WINDOW_MENU, LAB_SSD_BUTTON_CLOSE };
|
|
|
|
|
|
|
|
|
|
FOR_EACH_STATE(ssd, subtree) {
|
2023-09-16 22:25:41 +01:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(ssd_type); i++) {
|
2023-08-23 04:42:30 +02:00
|
|
|
part = ssd_get_part(&subtree->parts, ssd_type[i]);
|
|
|
|
|
struct ssd_button *button = node_ssd_button_from_node(part->node);
|
|
|
|
|
|
|
|
|
|
/* Toggle background between invisible and titlebar background color */
|
2023-12-03 16:36:20 +08:00
|
|
|
struct wlr_scene_rect *rect = wlr_scene_rect_from_node(button->background);
|
2023-08-23 04:42:30 +02:00
|
|
|
wlr_scene_rect_set_color(rect, !enable ? (float[4]) {0, 0, 0, 0} : (
|
|
|
|
|
subtree == &ssd->titlebar.active
|
|
|
|
|
? rc.theme->window_active_title_bg_color
|
|
|
|
|
: rc.theme->window_inactive_title_bg_color));
|
|
|
|
|
|
|
|
|
|
/* Toggle rounded corner image itself */
|
|
|
|
|
struct wlr_scene_node *rounded_corner =
|
|
|
|
|
wl_container_of(part->node->link.prev, rounded_corner, link);
|
|
|
|
|
wlr_scene_node_set_enabled(rounded_corner, !enable);
|
|
|
|
|
}
|
|
|
|
|
} FOR_EACH_END
|
2023-12-06 22:07:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_maximize_alt_icon(struct ssd *ssd, bool enable)
|
|
|
|
|
{
|
|
|
|
|
struct ssd_part *part;
|
|
|
|
|
struct ssd_button *button;
|
|
|
|
|
struct ssd_sub_tree *subtree;
|
|
|
|
|
|
|
|
|
|
FOR_EACH_STATE(ssd, subtree) {
|
|
|
|
|
part = ssd_get_part(&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE);
|
|
|
|
|
button = node_ssd_button_from_node(part->node);
|
|
|
|
|
|
|
|
|
|
if (button->toggled) {
|
|
|
|
|
wlr_scene_node_set_enabled(button->toggled, enable);
|
|
|
|
|
wlr_scene_node_set_enabled(button->normal, !enable);
|
|
|
|
|
}
|
2023-08-23 04:42:30 +02:00
|
|
|
|
2023-12-06 22:07:06 +01:00
|
|
|
if (button->toggled_hover) {
|
|
|
|
|
wlr_scene_node_set_enabled(button->toggled_hover, enable);
|
|
|
|
|
wlr_scene_node_set_enabled(button->hover, !enable);
|
|
|
|
|
}
|
|
|
|
|
} FOR_EACH_END
|
2023-08-23 04:42:30 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-21 03:18:38 +01:00
|
|
|
void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_titlebar_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;
|
2023-02-08 23:19:14 -05:00
|
|
|
int width = view->current.width;
|
2023-08-23 04:42:30 +02:00
|
|
|
struct theme *theme = view->server->theme;
|
|
|
|
|
|
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
|
|
|
bool maximized = (view->maximized == VIEW_AXIS_BOTH);
|
2023-12-06 22:07:06 +01:00
|
|
|
if (ssd->state.was_maximized != maximized) {
|
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
|
|
|
set_squared_corners(ssd, maximized);
|
2023-12-06 22:07:06 +01:00
|
|
|
set_maximize_alt_icon(ssd, maximized);
|
|
|
|
|
ssd->state.was_maximized = maximized;
|
2023-08-23 04:42:30 +02:00
|
|
|
}
|
|
|
|
|
|
2023-02-08 23:19:14 -05:00
|
|
|
if (width == ssd->state.geometry.width) {
|
2022-02-21 03:18:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ssd_part *part;
|
|
|
|
|
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) {
|
|
|
|
|
switch (part->type) {
|
|
|
|
|
case LAB_SSD_PART_TITLEBAR:
|
2022-04-04 20:53:36 +01:00
|
|
|
wlr_scene_rect_set_size(
|
2023-12-03 16:36:20 +08:00
|
|
|
wlr_scene_rect_from_node(part->node),
|
2023-01-06 15:56:44 +01:00
|
|
|
width - SSD_BUTTON_WIDTH * SSD_BUTTON_COUNT,
|
2022-03-09 05:40:54 +01:00
|
|
|
theme->title_height);
|
2022-02-21 03:18:38 +01:00
|
|
|
continue;
|
|
|
|
|
case LAB_SSD_BUTTON_ICONIFY:
|
|
|
|
|
if (is_direct_child(part->node, subtree)) {
|
|
|
|
|
wlr_scene_node_set_position(part->node,
|
2023-01-06 15:56:44 +01:00
|
|
|
width - SSD_BUTTON_WIDTH * 3, 0);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
continue;
|
2023-12-06 20:33:26 +00:00
|
|
|
case LAB_SSD_BUTTON_MAXIMIZE:
|
2022-02-21 03:18:38 +01:00
|
|
|
if (is_direct_child(part->node, subtree)) {
|
|
|
|
|
wlr_scene_node_set_position(part->node,
|
2023-01-06 15:56:44 +01:00
|
|
|
width - SSD_BUTTON_WIDTH * 2, 0);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
continue;
|
2022-06-08 14:37:30 +02:00
|
|
|
case LAB_SSD_PART_CORNER_TOP_RIGHT:
|
2022-02-21 03:18:38 +01:00
|
|
|
if (is_direct_child(part->node, subtree)) {
|
|
|
|
|
wlr_scene_node_set_position(part->node,
|
2023-01-06 15:56:44 +01:00
|
|
|
width - SSD_BUTTON_WIDTH * 1, 0);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
default:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} FOR_EACH_END
|
2022-11-26 16:46:28 -05:00
|
|
|
ssd_update_title(ssd);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_titlebar_destroy(struct ssd *ssd)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2023-04-14 09:01:13 +02:00
|
|
|
if (!ssd->titlebar.tree) {
|
2022-02-21 03:18:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2022-11-26 16:06:22 -05:00
|
|
|
if (ssd->state.title.text) {
|
|
|
|
|
free(ssd->state.title.text);
|
|
|
|
|
ssd->state.title.text = NULL;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
2023-04-14 09:01:13 +02:00
|
|
|
|
|
|
|
|
wlr_scene_node_destroy(&ssd->titlebar.tree->node);
|
|
|
|
|
ssd->titlebar.tree = NULL;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* For ssd_update_title* we do not early out because
|
|
|
|
|
* .active and .inactive may result in different sizes
|
|
|
|
|
* of the title (font family/size) or background of
|
|
|
|
|
* the title (different button/border width).
|
2022-08-12 14:12:31 +02:00
|
|
|
*
|
|
|
|
|
* Both, wlr_scene_node_set_enabled() and wlr_scene_node_set_position()
|
|
|
|
|
* check for actual changes and return early if there is no change in state.
|
|
|
|
|
* Always using wlr_scene_node_set_enabled(node, true) will thus not cause
|
|
|
|
|
* any unnecessary screen damage and makes the code easier to follow.
|
2022-02-21 03:18:38 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_update_title_positions(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;
|
2023-02-08 23:19:14 -05:00
|
|
|
int width = view->current.width;
|
2023-01-06 15:56:44 +01:00
|
|
|
int title_bg_width = width - SSD_BUTTON_WIDTH * SSD_BUTTON_COUNT;
|
2022-02-21 03:18:38 +01:00
|
|
|
|
|
|
|
|
int x, y;
|
2022-05-26 15:34:08 +02:00
|
|
|
int buffer_height, buffer_width;
|
2022-02-21 03:18:38 +01:00
|
|
|
struct ssd_part *part;
|
|
|
|
|
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
|
|
|
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE);
|
2022-06-12 21:22:49 +02:00
|
|
|
if (!part || !part->node) {
|
2022-02-24 01:27:29 +01:00
|
|
|
/* view->surface never been mapped */
|
2022-06-12 21:22:49 +02:00
|
|
|
/* Or we somehow failed to allocate a scaled titlebar buffer */
|
2022-02-21 03:18:38 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 21:22:49 +02:00
|
|
|
buffer_width = part->buffer ? part->buffer->width : 0;
|
|
|
|
|
buffer_height = part->buffer ? part->buffer->height : 0;
|
2023-01-06 15:56:44 +01:00
|
|
|
x = SSD_BUTTON_WIDTH;
|
2022-05-26 15:34:08 +02:00
|
|
|
y = (theme->title_height - buffer_height) / 2;
|
2022-08-12 14:12:31 +02:00
|
|
|
|
2022-06-05 15:17:15 +02:00
|
|
|
if (title_bg_width <= 0) {
|
2022-08-12 14:12:31 +02:00
|
|
|
wlr_scene_node_set_enabled(part->node, false);
|
2022-02-21 03:18:38 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2022-08-12 14:12:31 +02:00
|
|
|
wlr_scene_node_set_enabled(part->node, true);
|
2022-02-21 03:18:38 +01:00
|
|
|
|
|
|
|
|
if (theme->window_label_text_justify == LAB_JUSTIFY_CENTER) {
|
2023-01-06 15:56:44 +01:00
|
|
|
if (buffer_width + SSD_BUTTON_WIDTH * 2 <= title_bg_width) {
|
2022-02-21 03:18:38 +01:00
|
|
|
/* Center based on the full width */
|
2022-06-05 15:17:15 +02:00
|
|
|
x = (width - buffer_width) / 2;
|
2022-02-21 03:18:38 +01:00
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* Center based on the width between the buttons.
|
|
|
|
|
* Title jumps around once this is hit but its still
|
|
|
|
|
* better than to hide behind the buttons on the right.
|
|
|
|
|
*/
|
2022-06-05 15:17:15 +02:00
|
|
|
x += (title_bg_width - buffer_width) / 2;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
} else if (theme->window_label_text_justify == LAB_JUSTIFY_RIGHT) {
|
2022-06-05 15:17:15 +02:00
|
|
|
x += title_bg_width - buffer_width;
|
2022-02-21 03:18:38 +01:00
|
|
|
} else if (theme->window_label_text_justify == LAB_JUSTIFY_LEFT) {
|
|
|
|
|
/* TODO: maybe add some theme x padding here? */
|
|
|
|
|
}
|
|
|
|
|
wlr_scene_node_set_position(part->node, x, y);
|
|
|
|
|
} FOR_EACH_END
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2022-11-26 16:46:28 -05:00
|
|
|
ssd_update_title(struct ssd *ssd)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2022-11-26 16:46:28 -05:00
|
|
|
if (!ssd) {
|
2022-02-21 03:18:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-26 16:46:28 -05:00
|
|
|
struct view *view = ssd->view;
|
2022-02-21 03:18:38 +01:00
|
|
|
char *title = (char *)view_get_string_prop(view, "title");
|
2024-01-19 19:06:07 +00:00
|
|
|
if (string_null_or_empty(title)) {
|
2022-02-21 03:18:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct theme *theme = view->server->theme;
|
2022-11-26 16:06:22 -05:00
|
|
|
struct ssd_state_title *state = &ssd->state.title;
|
2022-02-21 03:18:38 +01:00
|
|
|
bool title_unchanged = state->text && !strcmp(title, state->text);
|
|
|
|
|
|
2024-03-16 22:20:40 -04:00
|
|
|
const float *text_color;
|
|
|
|
|
const float *bg_color;
|
2023-12-07 09:28:27 +01:00
|
|
|
struct font *font = NULL;
|
2022-02-21 03:18:38 +01:00
|
|
|
struct ssd_part *part;
|
|
|
|
|
struct ssd_sub_tree *subtree;
|
|
|
|
|
struct ssd_state_title_width *dstate;
|
2023-02-08 23:19:14 -05:00
|
|
|
int title_bg_width = view->current.width
|
|
|
|
|
- SSD_BUTTON_WIDTH * SSD_BUTTON_COUNT;
|
2022-02-24 01:27:29 +01:00
|
|
|
|
2022-11-26 16:06:22 -05:00
|
|
|
FOR_EACH_STATE(ssd, subtree) {
|
|
|
|
|
if (subtree == &ssd->titlebar.active) {
|
2022-02-21 03:18:38 +01:00
|
|
|
dstate = &state->active;
|
|
|
|
|
text_color = theme->window_active_label_text_color;
|
2024-03-16 22:20:40 -04:00
|
|
|
bg_color = theme->window_active_title_bg_color;
|
2023-12-07 09:28:27 +01:00
|
|
|
font = &rc.font_activewindow;
|
2022-02-21 03:18:38 +01:00
|
|
|
} else {
|
|
|
|
|
dstate = &state->inactive;
|
|
|
|
|
text_color = theme->window_inactive_label_text_color;
|
2024-03-16 22:20:40 -04:00
|
|
|
bg_color = theme->window_inactive_title_bg_color;
|
2023-12-07 09:28:27 +01:00
|
|
|
font = &rc.font_inactivewindow;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
2022-02-24 01:27:29 +01:00
|
|
|
|
2022-06-05 15:17:15 +02:00
|
|
|
if (title_bg_width <= 0) {
|
2022-02-24 01:27:29 +01:00
|
|
|
dstate->truncated = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-21 03:18:38 +01:00
|
|
|
if (title_unchanged
|
2022-06-05 15:17:15 +02:00
|
|
|
&& !dstate->truncated && dstate->width < title_bg_width) {
|
2022-02-21 03:18:38 +01:00
|
|
|
/* title the same + we don't need to resize title */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-02-24 01:27:29 +01:00
|
|
|
|
2022-02-21 03:18:38 +01:00
|
|
|
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE);
|
|
|
|
|
if (!part) {
|
2022-05-26 15:34:08 +02:00
|
|
|
/* Initialize part and wlr_scene_buffer without attaching a buffer */
|
2022-02-21 03:18:38 +01:00
|
|
|
part = add_scene_part(&subtree->parts, LAB_SSD_PART_TITLE);
|
2022-06-12 21:22:49 +02:00
|
|
|
part->buffer = scaled_font_buffer_create(subtree->tree);
|
|
|
|
|
if (part->buffer) {
|
|
|
|
|
part->node = &part->buffer->scene_buffer->node;
|
|
|
|
|
} else {
|
|
|
|
|
wlr_log(WLR_ERROR, "Failed to create title node");
|
|
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
2022-05-26 15:34:08 +02:00
|
|
|
|
2022-06-12 21:22:49 +02:00
|
|
|
if (part->buffer) {
|
2022-08-02 22:00:24 +01:00
|
|
|
scaled_font_buffer_update(part->buffer, title,
|
2023-12-07 09:28:27 +01:00
|
|
|
title_bg_width, font,
|
2024-03-16 22:20:40 -04:00
|
|
|
text_color, bg_color, NULL);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
2022-05-26 15:34:08 +02:00
|
|
|
|
|
|
|
|
/* And finally update the cache */
|
2022-06-12 21:22:49 +02:00
|
|
|
dstate->width = part->buffer ? part->buffer->width : 0;
|
2022-06-05 15:17:15 +02:00
|
|
|
dstate->truncated = title_bg_width <= dstate->width;
|
2022-06-12 21:22:49 +02:00
|
|
|
|
2022-02-21 03:18:38 +01:00
|
|
|
} FOR_EACH_END
|
|
|
|
|
|
2022-02-24 01:37:19 +01:00
|
|
|
if (!title_unchanged) {
|
|
|
|
|
if (state->text) {
|
|
|
|
|
free(state->text);
|
|
|
|
|
}
|
2022-09-16 18:41:02 -04:00
|
|
|
state->text = xstrdup(title);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
2022-11-26 16:06:22 -05:00
|
|
|
ssd_update_title_positions(ssd);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-06 22:07:06 +01:00
|
|
|
static void
|
|
|
|
|
ssd_button_set_hover(struct ssd_button *button, bool enabled)
|
|
|
|
|
{
|
|
|
|
|
assert(button);
|
|
|
|
|
wlr_scene_node_set_enabled(&button->hover_tree->node, enabled);
|
|
|
|
|
wlr_scene_node_set_enabled(&button->icon_tree->node, !enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 19:51:02 +02:00
|
|
|
void
|
|
|
|
|
ssd_update_button_hover(struct wlr_scene_node *node,
|
|
|
|
|
struct ssd_hover_state *hover_state)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2022-06-08 19:51:02 +02:00
|
|
|
struct ssd_button *button = NULL;
|
|
|
|
|
if (!node || !node->data) {
|
|
|
|
|
goto disable_old_hover;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-08 19:51:02 +02:00
|
|
|
struct node_descriptor *desc = node->data;
|
|
|
|
|
if (desc->type == LAB_NODE_DESC_SSD_BUTTON) {
|
|
|
|
|
button = node_ssd_button_from_node(node);
|
2023-12-06 22:07:06 +01:00
|
|
|
if (button == hover_state->button) {
|
2022-06-08 19:51:02 +02:00
|
|
|
/* Cursor is still on the same button */
|
|
|
|
|
return;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
2022-06-08 19:51:02 +02:00
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2022-06-08 19:51:02 +02:00
|
|
|
disable_old_hover:
|
2023-12-06 22:07:06 +01:00
|
|
|
if (hover_state->button) {
|
|
|
|
|
ssd_button_set_hover(hover_state->button, false);
|
2022-06-08 19:51:02 +02:00
|
|
|
hover_state->view = NULL;
|
2023-12-06 22:07:06 +01:00
|
|
|
hover_state->button = NULL;
|
2022-06-08 19:51:02 +02:00
|
|
|
}
|
|
|
|
|
if (button) {
|
2023-12-06 22:07:06 +01:00
|
|
|
ssd_button_set_hover(button, true);
|
2022-06-08 19:51:02 +02:00
|
|
|
hover_state->view = button->view;
|
2023-12-06 22:07:06 +01:00
|
|
|
hover_state->button = button;
|
2022-06-08 19:51:02 +02:00
|
|
|
}
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef FOR_EACH_STATE
|