opt: optmize structruing\

This commit is contained in:
DreamMaoMao 2026-06-22 14:18:56 +08:00
parent afd7135fa6
commit b8ca3a3c34
11 changed files with 234 additions and 239 deletions

View file

@ -69,17 +69,17 @@ You can also color-code windows based on their state:
### Tab Bar For Monocle Layout
| Setting | Default | Description |
| :--- | :--- | :--- |
| `tab_bar_height` | `50` | Height of the tab bar for monocle layout. |
| `tab_bar_decorate_fg_color` | `0xc4939dff` | text color.
| `tab_bar_decorate_bg_color` | `0x201b14ff` | background color.|
| `tab_bar_decorate_focus_fg_color` | `0x201b14ff` | text color for focus. |
| `tab_bar_decorate_focus_bg_color` | `0xc4939dff` | background color for focus.|
| `tab_bar_decorate_border_color` | `0x8BAA9Bff` | border color.|
| `tab_bar_decorate_border_width` | `4` | border width.|
| `tab_bar_decorate_corner_radius` | `5` | corner radius.|
| `tab_bar_decorate_padding_x` | `0` | horizontal padding.|
| `tab_bar_decorate_padding_y` | `0` | vertical padding.|
| `tab_bar_decorate_font_desc` | `monospace Bold 16` | font set.|
| `group_bar_height` | `50` | Height of the tab bar for monocle layout. |
| `group_bar_decorate_fg_color` | `0xc4939dff` | text color.
| `group_bar_decorate_bg_color` | `0x201b14ff` | background color.|
| `group_bar_decorate_focus_fg_color` | `0x201b14ff` | text color for focus. |
| `group_bar_decorate_focus_bg_color` | `0xc4939dff` | background color for focus.|
| `group_bar_decorate_border_color` | `0x8BAA9Bff` | border color.|
| `group_bar_decorate_border_width` | `4` | border width.|
| `group_bar_decorate_corner_radius` | `5` | corner radius.|
| `group_bar_decorate_padding_x` | `0` | horizontal padding.|
| `group_bar_decorate_padding_y` | `0` | vertical padding.|
| `group_bar_decorate_font_desc` | `monospace Bold 16` | font set.|
## Borders

View file

@ -57,14 +57,14 @@ void client_tile_resize(Client *c, struct wlr_box geo, int32_t interact) {
if (!ISFAKETILED(c))
return;
if (c->isfullscreen && c->tab_bar_node) {
wlr_scene_node_set_enabled(&c->tab_bar_node->scene_buffer->node, false);
if (c->isfullscreen && c->group_bar) {
wlr_scene_node_set_enabled(&c->group_bar->scene_buffer->node, false);
}
if (!c->mon->isoverview && c->tab_bar_node && !c->isfullscreen &&
if (!c->mon->isoverview && c->group_bar && !c->isfullscreen &&
(c->group_next || c->group_prev)) {
geo.y = geo.y + config.tab_bar_height;
geo.height -= config.tab_bar_height;
geo.y = geo.y + config.group_bar_height;
geo.height -= config.group_bar_height;
}
if ((!c->isfullscreen && !c->ismaximizescreen) ||
@ -115,27 +115,22 @@ void client_add_jump_label_node(Client *c) {
wlr_scene_node_set_enabled(&c->jump_label_node->scene_buffer->node, false);
}
void client_add_tab_bar_node(Client *c) {
void client_add_group_bar(Client *c) {
if (config.tab_bar_height <= 0) {
if (config.group_bar_height <= 0) {
return;
}
MangoCustomDecorate *MangoCustomDecorate =
ecalloc(1, sizeof(MangoCustomDecorate));
MangoCustomDecorate->node_data = c;
MangoCustomDecorate->node_type = MANGO_TITLE_NODE;
MangoCustomDecorate->type = CustomDecorate;
uint32_t layer = c->isoverlay ? LyrOverlay
: c->isfloating || c->isfullscreen ? LyrTop
: c->ismaximizescreen ? LyrMaximize
: LyrTile;
c->tab_bar_node = mango_tab_bar_node_create(
MangoCustomDecorate, layers[layer], config.tabdata, 0, 0);
wlr_scene_node_lower_to_bottom(&c->tab_bar_node->scene_buffer->node);
wlr_scene_node_set_enabled(&c->tab_bar_node->scene_buffer->node, false);
mango_tab_bar_node_update(c->tab_bar_node, client_get_title(c), 1.0);
c->group_bar = mango_group_bar_create(c, GroupBar, layers[layer],
config.tabdata, 0, 0);
wlr_scene_node_lower_to_bottom(&c->group_bar->scene_buffer->node);
wlr_scene_node_set_enabled(&c->group_bar->scene_buffer->node, false);
mango_group_bar_update(c->group_bar, client_get_title(c), 1.0);
}
void client_focus_group_member(Client *c) {
@ -165,11 +160,11 @@ void client_focus_group_member(Client *c) {
cur_focusing->isgroupfocusing = false;
c->mon = cur_focusing->mon;
client_replace(c, cur_focusing, true);
mango_tab_bar_node_set_focus(cur_focusing->tab_bar_node, false);
mango_group_bar_set_focus(cur_focusing->group_bar, false);
}
c->isgroupfocusing = true;
mango_tab_bar_node_set_focus(c->tab_bar_node, true);
mango_group_bar_set_focus(c->group_bar, true);
client_reparent_group(c);
@ -189,14 +184,14 @@ void client_check_tab_node_visible(Client *c) {
Client *cur = head;
while (cur) {
if (!c->mon->isoverview && cur->tab_bar_node &&
if (!c->mon->isoverview && cur->group_bar &&
(cur->group_next || cur->group_prev) && VISIBLEON(c, c->mon) &&
ISNORMAL(c) && !c->isfullscreen &&
(!is_monocle_layout(c->mon) || c == c->mon->sel)) {
wlr_scene_node_set_enabled(&cur->tab_bar_node->scene_buffer->node,
wlr_scene_node_set_enabled(&cur->group_bar->scene_buffer->node,
true);
} else {
wlr_scene_node_set_enabled(&cur->tab_bar_node->scene_buffer->node,
wlr_scene_node_set_enabled(&cur->group_bar->scene_buffer->node,
false);
}
cur = cur->group_next;
@ -216,8 +211,8 @@ void client_raise_group(Client *c) {
Client *cur = head;
while (cur) {
if (cur->tab_bar_node) {
wlr_scene_node_raise_to_top(&cur->tab_bar_node->scene_buffer->node);
if (cur->group_bar) {
wlr_scene_node_raise_to_top(&cur->group_bar->scene_buffer->node);
wlr_scene_node_raise_to_top(&cur->scene->node);
}
cur = cur->group_next;
@ -225,7 +220,7 @@ void client_raise_group(Client *c) {
}
void client_reparent_group(Client *c) {
if (!c || !c->tab_bar_node)
if (!c || !c->group_bar)
return;
if (!c->group_prev && !c->group_next)
@ -242,8 +237,8 @@ void client_reparent_group(Client *c) {
Client *cur = head;
while (cur) {
if (cur->tab_bar_node) {
wlr_scene_node_reparent(&cur->tab_bar_node->scene_buffer->node,
if (cur->group_bar) {
wlr_scene_node_reparent(&cur->group_bar->scene_buffer->node,
layers[layer]);
wlr_scene_node_reparent(&cur->scene->node, layers[layer]);
}
@ -251,13 +246,13 @@ void client_reparent_group(Client *c) {
}
}
void client_handle_decorate_click(MangoCustomDecorate *md) {
void client_handle_decorate_click(MangoGroupBar *gb) {
if (!md)
if (!gb)
return;
if (md->node_type == MANGO_TITLE_NODE) {
Client *c = md->node_data;
if (gb->node_data) {
Client *c = gb->node_data;
client_focus_group_member(c);
}
}

View file

@ -414,12 +414,12 @@ void client_draw_shadow(Client *c) {
void client_draw_title(Client *c) {
if (!c || !c->tab_bar_node)
if (!c || !c->group_bar)
return;
if (!c->group_next && !c->group_prev && c->tab_bar_node &&
c->tab_bar_node->scene_buffer->node.enabled) {
wlr_scene_node_set_enabled(&c->tab_bar_node->scene_buffer->node, false);
if (!c->group_next && !c->group_prev && c->group_bar &&
c->group_bar->scene_buffer->node.enabled) {
wlr_scene_node_set_enabled(&c->group_bar->scene_buffer->node, false);
return;
}
@ -438,21 +438,21 @@ void client_draw_title(Client *c) {
}
int32_t tab_x = c->animation.current.x;
int32_t tab_y = c->animation.current.y - config.tab_bar_height;
int32_t tab_y = c->animation.current.y - config.group_bar_height;
int32_t tw = c->animation.current.width;
int32_t th = config.tab_bar_height;
int32_t th = config.group_bar_height;
int32_t left_over = c->mon->m.x - tab_x;
int32_t right_over = tab_x + tw - c->mon->m.x - c->mon->m.width;
int32_t top_over = c->mon->m.y - tab_y;
int32_t bottom_over =
tab_y + config.tab_bar_height - c->mon->m.y - c->mon->m.height;
tab_y + config.group_bar_height - c->mon->m.y - c->mon->m.height;
if (c != grabc &&
(ISSCROLLTILED(c) || c->animation.tagining || c->animation.tagouting)) {
if (top_over > 0) {
tab_y = c->mon->m.y;
th = config.tab_bar_height - top_over;
th = config.group_bar_height - top_over;
}
if (bottom_over > 0) {
th = th - bottom_over;
@ -469,9 +469,9 @@ void client_draw_title(Client *c) {
if (tw <= 0 || th <= 0) {
cur = head;
while (cur) {
if (cur->tab_bar_node)
wlr_scene_node_set_enabled(
&cur->tab_bar_node->scene_buffer->node, false);
if (cur->group_bar)
wlr_scene_node_set_enabled(&cur->group_bar->scene_buffer->node,
false);
cur = cur->group_next;
}
return;
@ -486,7 +486,7 @@ void client_draw_title(Client *c) {
for (int i = 0; i < count && cur; i++) {
int32_t w = bar_w + (i < rem ? 1 : 0);
global_draw_tab_bar(cur, x, tab_y, w, th);
global_draw_group_bar(cur, x, tab_y, w, th);
x += w;
cur = cur->group_next;
}
@ -532,17 +532,17 @@ void client_draw_blur(Client *c, struct wlr_box clip_box, struct ivec2 offset) {
}
}
void global_draw_tab_bar(Client *c, int32_t x, int32_t y, int32_t width,
int32_t height) {
if (!c->tab_bar_node)
void global_draw_group_bar(Client *c, int32_t x, int32_t y, int32_t width,
int32_t height) {
if (!c->group_bar)
return;
if (height <= 0) {
wlr_scene_node_set_enabled(&c->tab_bar_node->scene_buffer->node, false);
wlr_scene_node_set_enabled(&c->group_bar->scene_buffer->node, false);
}
wlr_scene_node_set_position(&c->tab_bar_node->scene_buffer->node, x, y);
mango_tab_bar_node_set_size(c->tab_bar_node, width, height);
wlr_scene_node_set_position(&c->group_bar->scene_buffer->node, x, y);
mango_group_bar_set_size(c->group_bar, width, height);
}
void apply_split_border(Client *c, bool hit_no_border) {

View file

@ -333,7 +333,7 @@ typedef struct {
uint32_t gappoh;
uint32_t gappov;
uint32_t borderpx;
uint32_t tab_bar_height;
uint32_t group_bar_height;
float scratchpad_width_ratio;
float scratchpad_height_ratio;
float rootcolor[4];
@ -1774,75 +1774,75 @@ bool parse_option(Config *config, char *key, char *value) {
config->cursor_size = atoi(value);
} else if (strcmp(key, "cursor_theme") == 0) {
config->cursor_theme = strdup(value);
} else if (strcmp(key, "tab_bar_decorate_font_desc") == 0) {
} else if (strcmp(key, "group_bar_decorate_font_desc") == 0) {
config->tabdata.font_desc = strdup(value);
} else if (strcmp(key, "tab_bar_decorate_fg_color") == 0) {
} else if (strcmp(key, "group_bar_decorate_fg_color") == 0) {
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr,
"\033[1m\033[31m[ERROR]:\033[33m Invalid "
"tab_bar_decorate_fg_color "
"group_bar_decorate_fg_color "
"format: %s\n",
value);
return false;
} else {
convert_hex_to_rgba(config->tabdata.fg_color, color);
}
} else if (strcmp(key, "tab_bar_decorate_bg_color") == 0) {
} else if (strcmp(key, "group_bar_decorate_bg_color") == 0) {
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr,
"\033[1m\033[31m[ERROR]:\033[33m Invalid "
"tab_bar_decorate_bg_color "
"group_bar_decorate_bg_color "
"format: %s\n",
value);
return false;
} else {
convert_hex_to_rgba(config->tabdata.bg_color, color);
}
} else if (strcmp(key, "tab_bar_decorate_focus_fg_color") == 0) {
} else if (strcmp(key, "group_bar_decorate_focus_fg_color") == 0) {
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr,
"\033[1m\033[31m[ERROR]:\033[33m Invalid "
"tab_bar_decorate_focus_fg_color "
"group_bar_decorate_focus_fg_color "
"format: %s\n",
value);
return false;
} else {
convert_hex_to_rgba(config->tabdata.focus_fg_color, color);
}
} else if (strcmp(key, "tab_bar_decorate_focus_bg_color") == 0) {
} else if (strcmp(key, "group_bar_decorate_focus_bg_color") == 0) {
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr,
"\033[1m\033[31m[ERROR]:\033[33m Invalid "
"tab_bar_decorate_focus_bg_color "
"group_bar_decorate_focus_bg_color "
"format: %s\n",
value);
return false;
} else {
convert_hex_to_rgba(config->tabdata.focus_bg_color, color);
}
} else if (strcmp(key, "tab_bar_decorate_border_color") == 0) {
} else if (strcmp(key, "group_bar_decorate_border_color") == 0) {
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr,
"\033[1m\033[31m[ERROR]:\033[33m Invalid "
"tab_bar_decorate_border_color "
"group_bar_decorate_border_color "
"format: %s\n",
value);
return false;
} else {
convert_hex_to_rgba(config->tabdata.border_color, color);
}
} else if (strcmp(key, "tab_bar_decorate_border_width") == 0) {
} else if (strcmp(key, "group_bar_decorate_border_width") == 0) {
config->tabdata.border_width = CLAMP_INT(atoi(value), 0, 100);
} else if (strcmp(key, "tab_bar_decorate_corner_radius") == 0) {
} else if (strcmp(key, "group_bar_decorate_corner_radius") == 0) {
config->tabdata.corner_radius = CLAMP_INT(atoi(value), 0, 100);
} else if (strcmp(key, "tab_bar_decorate_padding_x") == 0) {
} else if (strcmp(key, "group_bar_decorate_padding_x") == 0) {
config->tabdata.padding_x = CLAMP_INT(atoi(value), 0, 100);
} else if (strcmp(key, "tab_bar_decorate_padding_y") == 0) {
} else if (strcmp(key, "group_bar_decorate_padding_y") == 0) {
config->tabdata.padding_y = CLAMP_INT(atoi(value), 0, 100);
} else if (strcmp(key, "jump_label_decorate_font_desc") == 0) {
config->jumplabeldata.font_desc = strdup(value);
@ -1960,8 +1960,8 @@ bool parse_option(Config *config, char *key, char *value) {
config->scratchpad_height_ratio = atof(value);
} else if (strcmp(key, "borderpx") == 0) {
config->borderpx = atoi(value);
} else if (strcmp(key, "tab_bar_height") == 0) {
config->tab_bar_height = atoi(value);
} else if (strcmp(key, "group_bar_height") == 0) {
config->group_bar_height = atoi(value);
} else if (strcmp(key, "rootcolor") == 0) {
int64_t color = parse_color(value);
if (color == -1) {
@ -3581,7 +3581,7 @@ void override_config(void) {
config.scratchpad_height_ratio =
CLAMP_FLOAT(config.scratchpad_height_ratio, 0.1f, 1.0f);
config.borderpx = CLAMP_INT(config.borderpx, 0, 200);
config.tab_bar_height = CLAMP_INT(config.tab_bar_height, 0, 500);
config.group_bar_height = CLAMP_INT(config.group_bar_height, 0, 500);
config.smartgaps = CLAMP_INT(config.smartgaps, 0, 1);
config.blur = CLAMP_INT(config.blur, 0, 1);
config.blur_layer = CLAMP_INT(config.blur_layer, 0, 1);
@ -3713,7 +3713,7 @@ void set_value_default() {
config.idleinhibit_ignore_visible = 0;
config.borderpx = 4;
config.tab_bar_height = 50;
config.group_bar_height = 50;
config.overviewgappi = 5;
config.overviewgappo = 30;
config.cursor_hide_timeout = 0;
@ -4130,7 +4130,7 @@ void reapply_property(void) {
mango_jump_label_node_apply_config(c->jump_label_node,
&config.jumplabeldata);
mango_tab_bar_node_apply_config(c->tab_bar_node, &config.tabdata);
mango_group_bar_apply_config(c->group_bar, &config.tabdata);
wlr_scene_rect_set_color(c->droparea, config.dropcolor);
wlr_scene_rect_set_color(c->splitindicator[0], config.splitcolor);

View file

@ -59,10 +59,9 @@ static const struct wlr_buffer_impl text_buffer_impl = {
.end_data_ptr_access = text_buffer_end_data_ptr_access,
};
struct mango_jump_label_node *
mango_jump_label_node_create(struct wlr_scene_tree *parent,
DecorateDrawData data) {
struct mango_jump_label_node *node = calloc(1, sizeof(*node));
MangoJumpLabel *mango_jump_label_node_create(struct wlr_scene_tree *parent,
DecorateDrawData data) {
MangoJumpLabel *node = calloc(1, sizeof(*node));
if (!node)
return NULL;
@ -104,7 +103,7 @@ mango_jump_label_node_create(struct wlr_scene_tree *parent,
return node;
}
void mango_jump_label_node_destroy(struct mango_jump_label_node *node) {
void mango_jump_label_node_destroy(MangoJumpLabel *node) {
if (!node)
return;
@ -136,8 +135,8 @@ void mango_jump_label_node_destroy(struct mango_jump_label_node *node) {
free(node);
}
void mango_jump_label_node_set_background(struct mango_jump_label_node *node,
float r, float g, float b, float a) {
void mango_jump_label_node_set_background(MangoJumpLabel *node, float r,
float g, float b, float a) {
if (!node)
return;
node->bg_color[0] = r;
@ -146,9 +145,9 @@ void mango_jump_label_node_set_background(struct mango_jump_label_node *node,
node->bg_color[3] = a;
}
void mango_jump_label_node_set_border(struct mango_jump_label_node *node,
float r, float g, float b, float a,
int32_t width, int32_t radius) {
void mango_jump_label_node_set_border(MangoJumpLabel *node, float r, float g,
float b, float a, int32_t width,
int32_t radius) {
if (!node)
return;
node->border_color[0] = r;
@ -159,17 +158,16 @@ void mango_jump_label_node_set_border(struct mango_jump_label_node *node,
node->corner_radius = radius;
}
void mango_jump_label_node_set_padding(struct mango_jump_label_node *node,
int32_t pad_x, int32_t pad_y) {
void mango_jump_label_node_set_padding(MangoJumpLabel *node, int32_t pad_x,
int32_t pad_y) {
if (!node)
return;
node->padding_x = pad_x >= 0 ? pad_x : 0;
node->padding_y = pad_y >= 0 ? pad_y : 0;
}
static void get_text_pixel_size(struct mango_jump_label_node *node,
const char *text, float scale, int32_t *out_w,
int32_t *out_h) {
static void get_text_pixel_size(MangoJumpLabel *node, const char *text,
float scale, int32_t *out_w, int32_t *out_h) {
if (node->measure_scale != scale) {
pango_cairo_context_set_resolution(node->measure_context, 96.0 * scale);
node->measure_scale = scale;
@ -193,8 +191,8 @@ static void draw_rounded_rect(cairo_t *cr, double x, double y, double w,
cairo_close_path(cr);
}
void mango_jump_label_node_update(struct mango_jump_label_node *node,
const char *text, float scale) {
void mango_jump_label_node_update(MangoJumpLabel *node, const char *text,
float scale) {
if (!node || !text)
return;
if (scale <= 0.0f)
@ -407,8 +405,7 @@ void mango_jump_label_node_update(struct mango_jump_label_node *node,
node->logical_height);
}
void mango_jump_label_node_set_focus(struct mango_jump_label_node *node,
bool focused) {
void mango_jump_label_node_set_focus(MangoJumpLabel *node, bool focused) {
if (!node || node->focused == focused)
return;
node->focused = focused;
@ -419,55 +416,61 @@ void mango_jump_label_node_set_focus(struct mango_jump_label_node *node,
}
}
struct mango_tab_bar_node *
mango_tab_bar_node_create(void *mango_node_data, struct wlr_scene_tree *parent,
DecorateDrawData data, int32_t width,
int32_t height) {
struct mango_tab_bar_node *node = calloc(1, sizeof(*node));
if (!node)
MangoGroupBar *mango_group_bar_create(void *cdata, uint32_t type,
struct wlr_scene_tree *parent,
DecorateDrawData data, int32_t width,
int32_t height) {
MangoGroupBar *mangobar = calloc(1, sizeof(*mangobar));
if (!mangobar)
return NULL;
node->scene_buffer = wlr_scene_buffer_create(parent, NULL);
if (!node->scene_buffer) {
free(node);
mangobar->scene_buffer = wlr_scene_buffer_create(parent, NULL);
if (!mangobar->scene_buffer) {
free(mangobar);
return NULL;
}
memcpy(node->fg_color, data.fg_color, sizeof(node->fg_color));
memcpy(node->bg_color, data.bg_color, sizeof(node->bg_color));
memcpy(node->focus_fg_color, data.focus_fg_color,
sizeof(node->focus_fg_color));
memcpy(node->focus_bg_color, data.focus_bg_color,
sizeof(node->focus_bg_color));
memcpy(node->border_color, data.border_color, sizeof(node->border_color));
node->border_width = data.border_width;
node->corner_radius = data.corner_radius;
node->padding_x = data.padding_x;
node->padding_y = data.padding_y;
node->font_desc =
memcpy(mangobar->fg_color, data.fg_color, sizeof(mangobar->fg_color));
memcpy(mangobar->bg_color, data.bg_color, sizeof(mangobar->bg_color));
memcpy(mangobar->focus_fg_color, data.focus_fg_color,
sizeof(mangobar->focus_fg_color));
memcpy(mangobar->focus_bg_color, data.focus_bg_color,
sizeof(mangobar->focus_bg_color));
memcpy(mangobar->border_color, data.border_color,
sizeof(mangobar->border_color));
mangobar->border_width = data.border_width;
mangobar->corner_radius = data.corner_radius;
mangobar->padding_x = data.padding_x;
mangobar->padding_y = data.padding_y;
mangobar->font_desc =
g_strdup(data.font_desc ? data.font_desc : "monospace Bold 16");
node->target_width = width;
node->target_height = height;
node->focused = false;
node->cached_focused = false;
mangobar->target_width = width;
mangobar->target_height = height;
mangobar->focused = false;
mangobar->cached_focused = false;
node->measure_surface =
mangobar->measure_surface =
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
node->measure_cr = cairo_create(node->measure_surface);
node->measure_context = pango_cairo_create_context(node->measure_cr);
node->measure_layout = pango_layout_new(node->measure_context);
node->measure_scale = 1.0f;
mangobar->measure_cr = cairo_create(mangobar->measure_surface);
mangobar->measure_context =
pango_cairo_create_context(mangobar->measure_cr);
mangobar->measure_layout = pango_layout_new(mangobar->measure_context);
mangobar->measure_scale = 1.0f;
node->cached_scale = -1.0f;
node->last_text = NULL;
node->last_scale = 0.0f;
node->scene_buffer->node.data = mango_node_data;
mangobar->cached_scale = -1.0f;
mangobar->last_text = NULL;
mangobar->last_scale = 0.0f;
return node;
mangobar->type = type;
mangobar->node_data = cdata;
mangobar->scene_buffer->node.data = mangobar;
return mangobar;
}
void mango_tab_bar_node_destroy(struct mango_tab_bar_node *node) {
void mango_group_bar_destroy(MangoGroupBar *node) {
if (!node)
return;
@ -492,19 +495,15 @@ void mango_tab_bar_node_destroy(struct mango_tab_bar_node *node) {
if (node->measure_cr)
cairo_destroy(node->measure_cr);
void *data = node->scene_buffer->node.data;
wlr_scene_node_destroy(&node->scene_buffer->node);
g_free(node->font_desc);
g_free(node->cached_text);
g_free(node->cached_font_desc);
g_free(node->last_text);
free(data);
free(node);
}
void mango_tab_bar_node_set_size(struct mango_tab_bar_node *node, int32_t width,
int32_t height) {
void mango_group_bar_set_size(MangoGroupBar *node, int32_t width,
int32_t height) {
if (!node)
return;
@ -522,11 +521,11 @@ void mango_tab_bar_node_set_size(struct mango_tab_bar_node *node, int32_t width,
const char *redraw_text = node->last_text ? node->last_text : "";
float redraw_scale = node->last_scale > 0.0f ? node->last_scale : 1.0f;
mango_tab_bar_node_update(node, redraw_text, redraw_scale);
mango_group_bar_update(node, redraw_text, redraw_scale);
}
void mango_tab_bar_node_update(struct mango_tab_bar_node *node,
const char *text, float scale) {
void mango_group_bar_update(MangoGroupBar *node, const char *text,
float scale) {
if (!node || !text)
return;
if (scale <= 0.0f)
@ -765,19 +764,18 @@ void mango_tab_bar_node_update(struct mango_tab_bar_node *node,
node->logical_height);
}
void mango_tab_bar_node_set_focus(struct mango_tab_bar_node *node,
bool focused) {
void mango_group_bar_set_focus(MangoGroupBar *node, bool focused) {
if (!node || node->focused == focused)
return;
node->focused = focused;
if (node->last_text) {
float scale = node->last_scale > 0.0f ? node->last_scale : 1.0f;
mango_tab_bar_node_update(node, node->last_text, scale);
mango_group_bar_update(node, node->last_text, scale);
}
}
void mango_tab_bar_node_set_colors(struct mango_tab_bar_node *node,
const float fg[4], const float bg[4]) {
void mango_group_bar_set_colors(MangoGroupBar *node, const float fg[4],
const float bg[4]) {
if (!node)
return;
@ -786,11 +784,11 @@ void mango_tab_bar_node_set_colors(struct mango_tab_bar_node *node,
if (!node->focused && node->last_text) {
float scale = node->last_scale > 0.0f ? node->last_scale : 1.0f;
mango_tab_bar_node_update(node, node->last_text, scale);
mango_group_bar_update(node, node->last_text, scale);
}
}
void mango_jump_label_node_apply_config(struct mango_jump_label_node *node,
void mango_jump_label_node_apply_config(MangoJumpLabel *node,
const DecorateDrawData *data) {
if (!node || !data)
return;
@ -817,8 +815,8 @@ void mango_jump_label_node_apply_config(struct mango_jump_label_node *node,
}
}
void mango_tab_bar_node_apply_config(struct mango_tab_bar_node *node,
const DecorateDrawData *data) {
void mango_group_bar_apply_config(MangoGroupBar *node,
const DecorateDrawData *data) {
if (!node || !data)
return;
@ -840,6 +838,6 @@ void mango_tab_bar_node_apply_config(struct mango_tab_bar_node *node,
if (node->last_text) {
float scale = node->last_scale > 0.0f ? node->last_scale : 1.0f;
mango_tab_bar_node_update(node, node->last_text, scale);
mango_group_bar_update(node, node->last_text, scale);
}
}

View file

@ -26,8 +26,7 @@ struct mango_text_buffer {
struct wlr_buffer base;
cairo_surface_t *surface;
};
struct mango_jump_label_node {
typedef struct {
struct wlr_scene_buffer *scene_buffer;
struct mango_text_buffer *buffer;
cairo_surface_t *surface;
@ -70,13 +69,15 @@ struct mango_jump_label_node {
int32_t logical_width;
int32_t logical_height;
};
} MangoJumpLabel;
struct mango_tab_bar_node {
typedef struct {
uint32_t type;
struct wlr_scene_buffer *scene_buffer;
struct mango_text_buffer *buffer;
cairo_surface_t *surface;
int surface_pixel_w, surface_pixel_h;
void *node_data; // 存储窗口指针
// 初始配置
float fg_color[4];
@ -126,41 +127,38 @@ struct mango_tab_bar_node {
int32_t logical_width;
int32_t logical_height;
};
} MangoGroupBar;
void mango_text_global_finish(void);
struct mango_jump_label_node *
mango_jump_label_node_create(struct wlr_scene_tree *parent,
DecorateDrawData data);
void mango_jump_label_node_destroy(struct mango_jump_label_node *node);
void mango_jump_label_node_set_background(struct mango_jump_label_node *node,
float r, float g, float b, float a);
void mango_jump_label_node_set_border(struct mango_jump_label_node *node,
float r, float g, float b, float a,
int32_t width, int32_t radius);
void mango_jump_label_node_set_padding(struct mango_jump_label_node *node,
int32_t pad_x, int32_t pad_y);
void mango_jump_label_node_update(struct mango_jump_label_node *node,
const char *text, float scale);
MangoJumpLabel *mango_jump_label_node_create(struct wlr_scene_tree *parent,
DecorateDrawData data);
void mango_jump_label_node_destroy(MangoJumpLabel *node);
void mango_jump_label_node_set_background(MangoJumpLabel *node, float r,
float g, float b, float a);
void mango_jump_label_node_set_border(MangoJumpLabel *node, float r, float g,
float b, float a, int32_t width,
int32_t radius);
void mango_jump_label_node_set_padding(MangoJumpLabel *node, int32_t pad_x,
int32_t pad_y);
void mango_jump_label_node_update(MangoJumpLabel *node, const char *text,
float scale);
struct mango_tab_bar_node *
mango_tab_bar_node_create(void *mango_node_data, struct wlr_scene_tree *parent,
DecorateDrawData data, int32_t width, int32_t height);
void mango_tab_bar_node_destroy(struct mango_tab_bar_node *node);
void mango_tab_bar_node_set_size(struct mango_tab_bar_node *node, int32_t width,
int32_t height);
void mango_tab_bar_node_update(struct mango_tab_bar_node *node,
const char *text, float scale);
MangoGroupBar *mango_group_bar_create(void *cdata, uint32_t type,
struct wlr_scene_tree *parent,
DecorateDrawData data, int32_t width,
int32_t height);
void mango_group_bar_destroy(MangoGroupBar *node);
void mango_group_bar_set_size(MangoGroupBar *node, int32_t width,
int32_t height);
void mango_group_bar_update(MangoGroupBar *node, const char *text, float scale);
void mango_jump_label_node_set_focus(struct mango_jump_label_node *node,
bool focused);
void mango_tab_bar_node_set_focus(struct mango_tab_bar_node *node,
bool focused);
void mango_jump_label_node_set_focus(MangoJumpLabel *node, bool focused);
void mango_group_bar_set_focus(MangoGroupBar *node, bool focused);
void mango_tab_bar_node_set_colors(struct mango_tab_bar_node *node,
const float fg[4], const float bg[4]);
void mango_jump_label_node_apply_config(struct mango_jump_label_node *node,
void mango_group_bar_set_colors(MangoGroupBar *node, const float fg[4],
const float bg[4]);
void mango_jump_label_node_apply_config(MangoJumpLabel *node,
const DecorateDrawData *data);
void mango_tab_bar_node_apply_config(struct mango_tab_bar_node *node,
const DecorateDrawData *data);
void mango_group_bar_apply_config(MangoGroupBar *node,
const DecorateDrawData *data);
#endif // jump_label_node_H

View file

@ -27,6 +27,7 @@ struct dwl_input_method_relay {
};
struct dwl_input_method_popup {
uint32_t type;
struct wlr_input_popup_surface_v2 *popup_surface;
struct wlr_scene_tree *tree;
struct wlr_scene_tree *scene_surface;
@ -404,6 +405,8 @@ static void handle_input_method_new_popup_surface(struct wl_listener *listener,
popup->tree = wlr_scene_tree_create(layers[LyrIMPopup]);
popup->scene_surface = wlr_scene_subsurface_tree_create(
popup->tree, popup->popup_surface->surface);
popup->type = XdgImPopup;
popup->scene_surface->node.data = popup;
wl_list_insert(&relay->popups, &popup->link);

View file

@ -100,13 +100,12 @@ static bool layer_ignores_focus(LayerSurface *l) {
}
void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc,
LayerSurface **pl, MangoCustomDecorate **pd, double *nx,
double *ny) {
LayerSurface **pl, MangoGroupBar **gb, double *nx, double *ny) {
struct wlr_scene_node *node = NULL, *pnode = NULL;
struct wlr_surface *surface = NULL;
Client *c = NULL;
LayerSurface *l = NULL;
MangoCustomDecorate *mangocustomdecorate = NULL;
MangoGroupBar *mangogroupbar = NULL;
int32_t layer;
Client *ovc = NULL;
@ -116,8 +115,8 @@ void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc,
*pc = NULL;
if (pl)
*pl = NULL;
if (pd)
*pd = NULL;
if (gb)
*gb = NULL;
for (layer = NUM_LAYERS - 1; layer >= 0; layer--) {
if (layer == LyrFadeOut)
@ -152,8 +151,8 @@ void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc,
Client *temp_c = (Client *)data;
if (temp_c->type == LayerShell) {
l = (LayerSurface *)temp_c;
} else if (temp_c->type == CustomDecorate) {
mangocustomdecorate = (MangoCustomDecorate *)temp_c;
} else if (temp_c->type == GroupBar) {
mangogroupbar = (MangoGroupBar *)temp_c;
} else if (temp_c->type == XDGShell || temp_c->type == X11) {
c = temp_c;
}
@ -175,8 +174,8 @@ void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc,
*pc = c;
if (pl)
*pl = l;
if (pd)
*pd = mangocustomdecorate;
if (gb)
*gb = mangogroupbar;
if (selmon && selmon->isoverview && config.ov_no_resize) {
ovc = xytoclient(x, y);
@ -196,8 +195,8 @@ void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc,
*psurface = ovc ? client_surface(ovc) : NULL;
if (pl)
*pl = NULL;
if (pd)
*pd = NULL;
if (gb)
*gb = NULL;
}
}
}

View file

@ -1132,7 +1132,7 @@ void pre_caculate_before_arrange(Monitor *m, bool want_animation,
client_add_jump_label_node(c);
}
if (c->tab_bar_node && c->tab_bar_node->scene_buffer->node.enabled) {
if (c->group_bar && c->group_bar->scene_buffer->node.enabled) {
client_check_tab_node_visible(c);
}

View file

@ -698,7 +698,7 @@ void vertical_scroller(Monitor *m) {
} else {
bar_height = !root_client->isfullscreen && (root_client->group_prev ||
root_client->group_next)
? config.tab_bar_height
? config.group_bar_height
: 0;
target_geom.y = root_client->geom.y - bar_height;
@ -718,7 +718,7 @@ void vertical_scroller(Monitor *m) {
bar_height = !heads[focus_index - i + 1]->client->isfullscreen &&
(heads[focus_index - i + 1]->client->group_prev ||
heads[focus_index - i + 1]->client->group_next)
? config.tab_bar_height
? config.group_bar_height
: 0;
up_geom.y = heads[focus_index - i + 1]->client->geom.y - cur_gappiv -

View file

@ -165,9 +165,17 @@ enum { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT };
enum { VERTICAL, HORIZONTAL };
enum { SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT };
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11, CustomDecorate, Snapshot }; /* client types */
enum { AxisUp, AxisDown, AxisLeft, AxisRight }; // 滚轮滚动的方向
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum {
XDGShell,
LayerShell,
X11,
Snapshot,
XdgPopup,
XdgImPopup,
GroupBar
}; /* client types */
enum { AxisUp, AxisDown, AxisLeft, AxisRight }; // 滚轮滚动的方向
enum {
LyrBg,
LyrBlur,
@ -182,8 +190,6 @@ enum {
NUM_LAYERS
}; /* scene layers */
enum mango_node_type { MANGO_TITLE_NODE, MANGO_JUMP_NODE };
#ifdef XWAYLAND
enum {
NetWMWindowTypeDialog,
@ -249,13 +255,6 @@ typedef struct {
uint32_t ui2;
Client *tc;
} Arg;
typedef struct {
uint32_t type;
enum mango_node_type node_type;
void *node_data;
} MangoCustomDecorate;
typedef struct {
uint32_t mod;
uint32_t button;
@ -347,8 +346,8 @@ struct Client {
struct wlr_ext_image_capture_source_v1 *image_capture_source;
struct wlr_scene_surface *image_capture_scene_surface;
struct wlr_scene_tree *overview_scene_surface;
struct mango_jump_label_node *jump_label_node;
struct mango_tab_bar_node *tab_bar_node;
MangoJumpLabel *jump_label_node;
MangoGroupBar *group_bar;
struct wl_list link;
struct wl_list flink;
struct wl_list fadeout_link;
@ -540,6 +539,7 @@ typedef struct {
} LayerSurface;
typedef struct {
uint32_t type;
struct wlr_xdg_popup *wlr_popup;
struct wl_listener destroy;
struct wl_listener commit;
@ -805,7 +805,7 @@ static Monitor *get_monitor_nearest_to(int32_t x, int32_t y);
static void handle_iamge_copy_capture_new_session(struct wl_listener *listener,
void *data);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, MangoCustomDecorate **pd,
Client **pc, LayerSurface **pl, MangoGroupBar **tb,
double *nx, double *ny);
static void clear_fullscreen_flag(Client *c);
static pid_t getparentprocess(pid_t p);
@ -943,8 +943,8 @@ static void overview_backup_surface(Client *c);
static void create_jump_hints(Monitor *m);
static void finish_jump_mode(Monitor *m);
static void begin_jump_mode(Monitor *m);
static void global_draw_tab_bar(Client *c, int32_t x, int32_t y, int32_t width,
int32_t height);
static void global_draw_group_bar(Client *c, int32_t x, int32_t y,
int32_t width, int32_t height);
static void client_reparent_group(Client *c);
@ -1333,7 +1333,7 @@ void client_replace(Client *c, Client *w, bool isgroupaction) {
}
if (c->isgroupfocusing)
mango_tab_bar_node_set_focus(c->tab_bar_node, true);
mango_group_bar_set_focus(c->group_bar, true);
}
if (w->overview_scene_surface) {
@ -1346,8 +1346,8 @@ void client_replace(Client *c, Client *w, bool isgroupaction) {
overview_backup_surface(c);
}
if (w->tab_bar_node && !isgroupaction) {
wlr_scene_node_set_enabled(&w->tab_bar_node->scene_buffer->node, false);
if (w->group_bar && !isgroupaction) {
wlr_scene_node_set_enabled(&w->group_bar->scene_buffer->node, false);
}
if (c->link.prev && c->link.next && c->link.prev != &c->link) {
@ -2436,7 +2436,7 @@ bool handle_buttonpress(struct wlr_pointer_button_event *event) {
uint32_t hard_mods, mods;
Client *c = NULL;
LayerSurface *l = NULL;
MangoCustomDecorate *md = NULL;
MangoGroupBar *gb = NULL;
struct wlr_surface *surface;
Client *tmpc = NULL;
int32_t ji;
@ -2458,7 +2458,7 @@ bool handle_buttonpress(struct wlr_pointer_button_event *event) {
if (locked)
break;
xytonode(cursor->x, cursor->y, &surface, NULL, NULL, &md, NULL, NULL);
xytonode(cursor->x, cursor->y, &surface, NULL, NULL, &gb, NULL, NULL);
if (toplevel_from_wlr_surface(surface, &c, &l) >= 0) {
if (c && c->scene->node.enabled &&
(!client_is_unmanaged(c) || client_wants_focus(c)))
@ -2489,7 +2489,7 @@ bool handle_buttonpress(struct wlr_pointer_button_event *event) {
}
// handle click on tile node
client_handle_decorate_click(md);
client_handle_decorate_click(gb);
// 当鼠标焦点在layer上的时候不检测虚拟键盘的mod状态
// 避免layer虚拟键盘锁死mod按键状态
@ -3154,6 +3154,8 @@ static void createpopup(struct wl_listener *listener, void *data) {
if (!popup)
return;
popup->type = XdgPopup;
popup->destroy.notify = destroypopup;
wl_signal_add(&wlr_popup->events.destroy, &popup->destroy);
@ -4521,7 +4523,7 @@ void init_client_properties(Client *c) {
c->grid_col_per = 1.0f;
c->grid_row_per = 1.0f;
c->jump_label_node = NULL;
c->tab_bar_node = NULL;
c->group_bar = NULL;
c->overview_scene_surface = NULL;
c->drop_direction = UNDIR;
c->enable_drop_area_draw = false;
@ -4698,7 +4700,7 @@ mapnotify(struct wl_listener *listener, void *data) {
wlr_scene_node_set_enabled(&c->splitindicator[i]->node, false);
}
client_add_tab_bar_node(c);
client_add_group_bar(c);
c->droparea = wlr_scene_rect_create(c->scene, 0, 0, config.dropcolor);
wlr_scene_node_lower_to_bottom(&c->droparea->node);
@ -5716,9 +5718,9 @@ void reset_maximizescreen_size(Client *c) {
geom.width = c->mon->w.width - 2 * config.gappoh;
geom.height = c->mon->w.height - 2 * config.gappov;
if ((c->group_next || c->group_prev) && c->tab_bar_node) {
geom.height -= config.tab_bar_height;
geom.y += config.tab_bar_height;
if ((c->group_next || c->group_prev) && c->group_bar) {
geom.height -= config.group_bar_height;
geom.y += config.group_bar_height;
}
resize(c, geom, 0);
@ -5763,9 +5765,9 @@ void setmaximizescreen(Client *c, int32_t maximizescreen, bool rearrange) {
maximizescreen_box.width = c->mon->w.width - 2 * config.gappoh;
maximizescreen_box.height = c->mon->w.height - 2 * config.gappov;
if ((c->group_next || c->group_prev) && c->tab_bar_node) {
maximizescreen_box.height -= config.tab_bar_height;
maximizescreen_box.y += config.tab_bar_height;
if ((c->group_next || c->group_prev) && c->group_bar) {
maximizescreen_box.height -= config.group_bar_height;
maximizescreen_box.y += config.group_bar_height;
}
wlr_scene_node_raise_to_top(&c->scene->node);
@ -6853,9 +6855,9 @@ void unmapnotify(struct wl_listener *listener, void *data) {
mango_jump_label_node_destroy(c->jump_label_node);
c->jump_label_node = NULL;
}
if (c->tab_bar_node) {
mango_tab_bar_node_destroy(c->tab_bar_node);
c->tab_bar_node = NULL;
if (c->group_bar) {
mango_group_bar_destroy(c->group_bar);
c->group_bar = NULL;
}
wlr_scene_node_destroy(&c->image_capture_scene_surface->buffer->node);
@ -7015,7 +7017,7 @@ void updatetitle(struct wl_listener *listener, void *data) {
const char *title;
title = client_get_title(c);
mango_tab_bar_node_update(c->tab_bar_node, title, 1.0);
mango_group_bar_update(c->group_bar, title, 1.0);
if (title && c->foreign_toplevel)
wlr_foreign_toplevel_handle_v1_set_title(c->foreign_toplevel, title);
if (title && c->ext_foreign_toplevel) {