2022-02-21 03:18:38 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
2025-08-13 21:00:11 +09:00
|
|
|
#include "config/rcxml.h"
|
2022-10-05 08:43:56 +02:00
|
|
|
#include "common/list.h"
|
2022-09-16 18:41:02 -04:00
|
|
|
#include "common/mem.h"
|
2022-06-08 14:37:30 +02:00
|
|
|
#include "node.h"
|
2025-09-02 17:47:01 +09:00
|
|
|
#include "scaled-buffer/scaled-icon-buffer.h"
|
|
|
|
|
#include "scaled-buffer/scaled-img-buffer.h"
|
2025-09-03 05:32:44 -04:00
|
|
|
#include "ssd.h"
|
2022-11-26 16:53:35 -05:00
|
|
|
#include "ssd-internal.h"
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2025-08-13 21:00:11 +09:00
|
|
|
/* Internal API */
|
|
|
|
|
|
2025-09-03 05:32:44 -04:00
|
|
|
struct ssd_button *
|
|
|
|
|
attach_ssd_button(struct wl_list *button_parts, enum lab_node_type type,
|
2024-10-04 15:27:25 +09:00
|
|
|
struct wlr_scene_tree *parent,
|
2024-11-28 19:21:18 +09:00
|
|
|
struct lab_img *imgs[LAB_BS_ALL + 1],
|
2024-09-20 20:59:01 +01:00
|
|
|
int x, int y, struct view *view)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2025-08-13 21:00:11 +09:00
|
|
|
struct wlr_scene_tree *root = wlr_scene_tree_create(parent);
|
|
|
|
|
wlr_scene_node_set_position(&root->node, x, y);
|
2022-06-05 15:17:15 +02:00
|
|
|
|
2025-09-03 05:08:52 -04:00
|
|
|
assert(node_type_contains(LAB_NODE_BUTTON, type));
|
2025-09-03 05:32:44 -04:00
|
|
|
struct ssd_button *button = znew(*button);
|
|
|
|
|
button->node = &root->node;
|
|
|
|
|
button->type = type;
|
|
|
|
|
node_descriptor_create(&root->node, type, view, button);
|
2025-08-13 21:00:11 +09:00
|
|
|
wl_list_append(button_parts, &button->link);
|
2025-01-12 16:43:49 +09:00
|
|
|
|
2024-08-17 14:46:35 +02:00
|
|
|
/* Hitbox */
|
|
|
|
|
float invisible[4] = { 0, 0, 0, 0 };
|
2025-08-13 21:00:11 +09:00
|
|
|
wlr_scene_rect_create(root, rc.theme->window_button_width,
|
|
|
|
|
rc.theme->window_button_height, invisible);
|
2022-06-08 14:37:30 +02:00
|
|
|
|
2024-10-04 15:27:25 +09:00
|
|
|
/* Icons */
|
2025-01-12 16:43:49 +09:00
|
|
|
int button_width = rc.theme->window_button_width;
|
|
|
|
|
int button_height = rc.theme->window_button_height;
|
|
|
|
|
/*
|
|
|
|
|
* Ensure a small amount of horizontal padding within the button
|
|
|
|
|
* area (2px on each side with the default 26px button width).
|
|
|
|
|
* A new theme setting could be added to configure this. Using
|
|
|
|
|
* an existing setting (padding.width or window.button.spacing)
|
|
|
|
|
* was considered, but these settings have distinct purposes
|
|
|
|
|
* already and are zero by default.
|
|
|
|
|
*/
|
|
|
|
|
int icon_padding = button_width / 10;
|
|
|
|
|
|
2025-09-03 05:08:52 -04:00
|
|
|
if (type == LAB_NODE_BUTTON_WINDOW_ICON) {
|
2025-01-12 16:43:49 +09:00
|
|
|
struct scaled_icon_buffer *icon_buffer =
|
2025-08-13 21:00:11 +09:00
|
|
|
scaled_icon_buffer_create(root, view->server,
|
2025-01-12 16:43:49 +09:00
|
|
|
button_width - 2 * icon_padding, button_height);
|
|
|
|
|
assert(icon_buffer);
|
2025-08-13 21:00:11 +09:00
|
|
|
struct wlr_scene_node *icon_node = &icon_buffer->scene_buffer->node;
|
|
|
|
|
scaled_icon_buffer_set_view(icon_buffer, view);
|
|
|
|
|
wlr_scene_node_set_position(icon_node, icon_padding, 0);
|
2025-01-12 16:43:49 +09:00
|
|
|
button->window_icon = icon_buffer;
|
|
|
|
|
} else {
|
|
|
|
|
for (uint8_t state_set = LAB_BS_DEFAULT;
|
|
|
|
|
state_set <= LAB_BS_ALL; state_set++) {
|
|
|
|
|
if (!imgs[state_set]) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
struct scaled_img_buffer *img_buffer = scaled_img_buffer_create(
|
2025-08-13 21:00:11 +09:00
|
|
|
root, imgs[state_set], rc.theme->window_button_width,
|
2025-01-12 16:43:49 +09:00
|
|
|
rc.theme->window_button_height);
|
|
|
|
|
assert(img_buffer);
|
2025-08-13 21:00:11 +09:00
|
|
|
struct wlr_scene_node *icon_node = &img_buffer->scene_buffer->node;
|
|
|
|
|
wlr_scene_node_set_enabled(icon_node, false);
|
2025-01-12 16:43:49 +09:00
|
|
|
button->img_buffers[state_set] = img_buffer;
|
|
|
|
|
}
|
|
|
|
|
/* Initially show non-hover, non-toggled, unrounded variant */
|
|
|
|
|
wlr_scene_node_set_enabled(
|
|
|
|
|
&button->img_buffers[LAB_BS_DEFAULT]->scene_buffer->node, true);
|
2024-10-04 15:27:25 +09:00
|
|
|
}
|
2023-12-06 20:33:26 +00:00
|
|
|
|
2025-08-13 21:00:11 +09:00
|
|
|
return button;
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
2025-09-03 05:32:44 -04:00
|
|
|
/* called from node descriptor destroy */
|
|
|
|
|
void ssd_button_free(struct ssd_button *button)
|
2022-02-21 03:18:38 +01:00
|
|
|
{
|
2025-09-03 05:32:44 -04:00
|
|
|
wl_list_remove(&button->link);
|
|
|
|
|
free(button);
|
2022-02-21 03:18:38 +01:00
|
|
|
}
|