feat: titlebar support click focus

This commit is contained in:
DreamMaoMao 2026-06-17 16:32:40 +08:00
parent 00d2d93e65
commit 4a526bf713
4 changed files with 46 additions and 16 deletions

View file

@ -57,13 +57,15 @@ You can also color-code windows based on their state:
| Setting | Default | Description | | Setting | Default | Description |
| :--- | :--- | :--- | | :--- | :--- | :--- |
| `text_decorate_fg_color` | `0xc4939dff` | label text color. | | `text_decorate_fg_color` | `0xc4939dff` | label text color. |
| `text_decorate_bg_color` | `0x201b14ff` | label background color. | `text_decorate_bg_color` | `0x201b14ff` | label background color.|
| `text_decorate_border_color` | `0x8BAA9Bff` | label border color. | `text_decorate_focus_fg_color` | `0x201b14ff` | label text color for focus. |
| `text_decorate_border_width` | `4` | label border width. | `text_decorate_focus_bg_color` | `0xc4939dff` | label background color for focus.|
| `text_decorate_corner_radius` | `5` | label corner radius. | `text_decorate_border_color` | `0x8BAA9Bff` | label border color.|
| `text_decorate_padding_x` | `10` | label horizontal padding. | `text_decorate_border_width` | `4` | label border width.|
| `text_decorate_padding_y` | `10` | label vertical padding. | `text_decorate_corner_radius` | `5` | label corner radius.|
| `text_decorate_font_desc` | `monospace Bold 24` | label font set.| | `text_decorate_padding_x` | `10` | label horizontal padding.|
| `text_decorate_padding_y` | `10` | label vertical padding.|
| `text_decorate_font_desc` | `monospace Bold 12` | label font set.|
## Cursor Theme ## Cursor Theme

View file

@ -83,7 +83,7 @@ struct mango_text_node *mango_text_node_create(struct wlr_scene_tree *parent,
node->padding_x = data.padding_x; node->padding_x = data.padding_x;
node->padding_y = data.padding_y; node->padding_y = data.padding_y;
node->font_desc = node->font_desc =
g_strdup(data.font_desc ? data.font_desc : "monospace Bold 24"); g_strdup(data.font_desc ? data.font_desc : "monospace Bold 12");
node->cached_text = NULL; node->cached_text = NULL;
node->cached_scale = -1.0f; node->cached_scale = -1.0f;
@ -98,6 +98,8 @@ struct mango_text_node *mango_text_node_create(struct wlr_scene_tree *parent,
node->measure_layout = pango_layout_new(node->measure_context); node->measure_layout = pango_layout_new(node->measure_context);
node->measure_scale = 1.0f; node->measure_scale = 1.0f;
node->scene_buffer->node.data = NULL;
return node; return node;
} }
@ -414,8 +416,8 @@ void mango_text_node_set_focus(struct mango_text_node *node, bool focused) {
} }
struct mango_titlebar_node * struct mango_titlebar_node *
mango_titlebar_node_create(struct wlr_scene_tree *parent, TextDrawData data, mango_titlebar_node_create(void *mango_node_data, struct wlr_scene_tree *parent,
int32_t width, int32_t height) { TextDrawData data, int32_t width, int32_t height) {
struct mango_titlebar_node *node = calloc(1, sizeof(*node)); struct mango_titlebar_node *node = calloc(1, sizeof(*node));
if (!node) if (!node)
return NULL; return NULL;
@ -438,7 +440,7 @@ mango_titlebar_node_create(struct wlr_scene_tree *parent, TextDrawData data,
node->padding_x = data.padding_x; node->padding_x = data.padding_x;
node->padding_y = data.padding_y; node->padding_y = data.padding_y;
node->font_desc = node->font_desc =
g_strdup(data.font_desc ? data.font_desc : "monospace Bold 24"); g_strdup(data.font_desc ? data.font_desc : "monospace Bold 12");
node->target_width = width; node->target_width = width;
node->target_height = height; node->target_height = height;
@ -455,6 +457,7 @@ mango_titlebar_node_create(struct wlr_scene_tree *parent, TextDrawData data,
node->cached_scale = -1.0f; node->cached_scale = -1.0f;
node->last_text = NULL; node->last_text = NULL;
node->last_scale = 0.0f; node->last_scale = 0.0f;
node->scene_buffer->node.data = mango_node_data;
return node; return node;
} }
@ -484,13 +487,14 @@ void mango_titlebar_node_destroy(struct mango_titlebar_node *node) {
if (node->measure_cr) if (node->measure_cr)
cairo_destroy(node->measure_cr); cairo_destroy(node->measure_cr);
void *data = node->scene_buffer->node.data;
wlr_scene_node_destroy(&node->scene_buffer->node); wlr_scene_node_destroy(&node->scene_buffer->node);
g_free(node->font_desc); g_free(node->font_desc);
g_free(node->cached_text); g_free(node->cached_text);
g_free(node->cached_font_desc); g_free(node->cached_font_desc);
g_free(node->last_text); g_free(node->last_text);
free(data);
free(node); free(node);
} }

View file

@ -143,8 +143,8 @@ void mango_text_node_update(struct mango_text_node *node, const char *text,
float scale); float scale);
struct mango_titlebar_node * struct mango_titlebar_node *
mango_titlebar_node_create(struct wlr_scene_tree *parent, TextDrawData data, mango_titlebar_node_create(void *mango_node_data, struct wlr_scene_tree *parent,
int32_t width, int32_t height); TextDrawData data, int32_t width, int32_t height);
void mango_titlebar_node_destroy(struct mango_titlebar_node *node); void mango_titlebar_node_destroy(struct mango_titlebar_node *node);
void mango_titlebar_node_set_size(struct mango_titlebar_node *node, void mango_titlebar_node_set_size(struct mango_titlebar_node *node,
int32_t width, int32_t height); int32_t width, int32_t height);

View file

@ -170,6 +170,7 @@ enum {
LyrBlur, LyrBlur,
LyrBottom, LyrBottom,
LyrTile, LyrTile,
LyrDecorate,
LyrTop, LyrTop,
LyrFadeOut, LyrFadeOut,
LyrOverlay, LyrOverlay,
@ -177,6 +178,9 @@ enum {
LyrBlock, LyrBlock,
NUM_LAYERS NUM_LAYERS
}; /* scene layers */ }; /* scene layers */
enum mango_node_type { MANGO_TITLE_NODE, MANGO_TEXT_NODE };
#ifdef XWAYLAND #ifdef XWAYLAND
enum { enum {
NetWMWindowTypeDialog, NetWMWindowTypeDialog,
@ -243,6 +247,11 @@ typedef struct {
Client *tc; Client *tc;
} Arg; } Arg;
typedef struct {
enum mango_node_type type;
void *node_data;
} MangoNodeData;
typedef struct { typedef struct {
uint32_t mod; uint32_t mod;
uint32_t button; uint32_t button;
@ -2379,6 +2388,17 @@ bool handle_buttonpress(struct wlr_pointer_button_event *event) {
return true; return true;
} }
// handle click on tile node
struct wlr_scene_node *node = wlr_scene_node_at(
&layers[LyrDecorate]->node, cursor->x, cursor->y, NULL, NULL);
if (node && node->data) {
MangoNodeData *mangonodedata = (MangoNodeData *)node->data;
if (mangonodedata->type == MANGO_TITLE_NODE) {
Client *c = mangonodedata->node_data;
focusclient(c, 1);
}
}
// 当鼠标焦点在layer上的时候不检测虚拟键盘的mod状态 // 当鼠标焦点在layer上的时候不检测虚拟键盘的mod状态
// 避免layer虚拟键盘锁死mod按键状态 // 避免layer虚拟键盘锁死mod按键状态
hard_keyboard = &kb_group->wlr_group->keyboard; hard_keyboard = &kb_group->wlr_group->keyboard;
@ -4557,8 +4577,12 @@ mapnotify(struct wl_listener *listener, void *data) {
wlr_scene_node_lower_to_bottom(&c->text_node->scene_buffer->node); wlr_scene_node_lower_to_bottom(&c->text_node->scene_buffer->node);
wlr_scene_node_set_enabled(&c->text_node->scene_buffer->node, false); wlr_scene_node_set_enabled(&c->text_node->scene_buffer->node, false);
c->titlebar_node = MangoNodeData *mangonodedata = ecalloc(1, sizeof(MangoNodeData));
mango_titlebar_node_create(layers[LyrTile], config.textdata, 0, 0); mangonodedata->node_data = c;
mangonodedata->type = MANGO_TITLE_NODE;
c->titlebar_node = mango_titlebar_node_create(
mangonodedata, layers[LyrDecorate], config.textdata, 0, 0);
wlr_scene_node_lower_to_bottom(&c->titlebar_node->scene_buffer->node); wlr_scene_node_lower_to_bottom(&c->titlebar_node->scene_buffer->node);
wlr_scene_node_set_enabled(&c->titlebar_node->scene_buffer->node, false); wlr_scene_node_set_enabled(&c->titlebar_node->scene_buffer->node, false);