mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
rcxml: use fixed arrays for rc.title_buttons_*
These are just lists of enum lab_node_type, with a bounded size and no middle-insertions/removals, so linked lists are overkill. Also, the use of wl_list_for_each[_reverse] just to access the first or last entry in the list (corner button) was weird.
This commit is contained in:
parent
e17ec0203c
commit
bca0ec07ac
4 changed files with 38 additions and 57 deletions
|
|
@ -14,6 +14,9 @@
|
|||
|
||||
#define BUTTON_MAP_MAX 16
|
||||
|
||||
/* max of one button of each type (no repeats) */
|
||||
#define TITLE_BUTTONS_MAX ((LAB_NODE_BUTTON_LAST + 1) - LAB_NODE_BUTTON_FIRST)
|
||||
|
||||
enum adaptive_sync_mode {
|
||||
LAB_ADAPTIVE_SYNC_DISABLED,
|
||||
LAB_ADAPTIVE_SYNC_ENABLED,
|
||||
|
|
@ -48,11 +51,6 @@ struct button_map_entry {
|
|||
uint32_t to;
|
||||
};
|
||||
|
||||
struct title_button {
|
||||
enum lab_node_type type;
|
||||
struct wl_list link;
|
||||
};
|
||||
|
||||
struct usable_area_override {
|
||||
struct border margin;
|
||||
char *output;
|
||||
|
|
@ -88,8 +86,12 @@ struct rcxml {
|
|||
char *theme_name;
|
||||
char *icon_theme_name;
|
||||
char *fallback_app_icon_name;
|
||||
struct wl_list title_buttons_left;
|
||||
struct wl_list title_buttons_right;
|
||||
|
||||
enum lab_node_type title_buttons_left[TITLE_BUTTONS_MAX];
|
||||
int nr_title_buttons_left;
|
||||
enum lab_node_type title_buttons_right[TITLE_BUTTONS_MAX];
|
||||
int nr_title_buttons_right;
|
||||
|
||||
int corner_radius;
|
||||
bool show_title;
|
||||
bool title_layout_loaded;
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@ parse_window_type(const char *type)
|
|||
* desk D All-desktops toggle (aka omnipresent)
|
||||
*/
|
||||
static void
|
||||
fill_section(const char *content, struct wl_list *list, uint32_t *found_buttons)
|
||||
fill_section(const char *content, enum lab_node_type *buttons, int *count,
|
||||
uint32_t *found_buttons /* bitmask */)
|
||||
{
|
||||
gchar **identifiers = g_strsplit(content, ",", -1);
|
||||
for (size_t i = 0; identifiers[i]; ++i) {
|
||||
|
|
@ -162,9 +163,8 @@ fill_section(const char *content, struct wl_list *list, uint32_t *found_buttons)
|
|||
|
||||
*found_buttons |= (1 << type);
|
||||
|
||||
struct title_button *item = znew(*item);
|
||||
item->type = type;
|
||||
wl_list_append(list, &item->link);
|
||||
assert(*count < TITLE_BUTTONS_MAX);
|
||||
buttons[(*count)++] = type;
|
||||
}
|
||||
g_strfreev(identifiers);
|
||||
}
|
||||
|
|
@ -172,15 +172,8 @@ fill_section(const char *content, struct wl_list *list, uint32_t *found_buttons)
|
|||
static void
|
||||
clear_title_layout(void)
|
||||
{
|
||||
struct title_button *button, *button_tmp;
|
||||
wl_list_for_each_safe(button, button_tmp, &rc.title_buttons_left, link) {
|
||||
wl_list_remove(&button->link);
|
||||
zfree(button);
|
||||
}
|
||||
wl_list_for_each_safe(button, button_tmp, &rc.title_buttons_right, link) {
|
||||
wl_list_remove(&button->link);
|
||||
zfree(button);
|
||||
}
|
||||
rc.nr_title_buttons_left = 0;
|
||||
rc.nr_title_buttons_right = 0;
|
||||
rc.title_layout_loaded = false;
|
||||
}
|
||||
|
||||
|
|
@ -189,11 +182,6 @@ fill_title_layout(char *content)
|
|||
{
|
||||
clear_title_layout();
|
||||
|
||||
struct wl_list *sections[] = {
|
||||
&rc.title_buttons_left,
|
||||
&rc.title_buttons_right,
|
||||
};
|
||||
|
||||
gchar **parts = g_strsplit(content, ":", -1);
|
||||
|
||||
if (g_strv_length(parts) != 2) {
|
||||
|
|
@ -202,9 +190,10 @@ fill_title_layout(char *content)
|
|||
}
|
||||
|
||||
uint32_t found_buttons = 0;
|
||||
for (size_t i = 0; parts[i]; ++i) {
|
||||
fill_section(parts[i], sections[i], &found_buttons);
|
||||
}
|
||||
fill_section(parts[0], rc.title_buttons_left,
|
||||
&rc.nr_title_buttons_left, &found_buttons);
|
||||
fill_section(parts[1], rc.title_buttons_right,
|
||||
&rc.nr_title_buttons_right, &found_buttons);
|
||||
|
||||
rc.title_layout_loaded = true;
|
||||
err:
|
||||
|
|
@ -1362,8 +1351,6 @@ rcxml_init(void)
|
|||
static bool has_run;
|
||||
|
||||
if (!has_run) {
|
||||
wl_list_init(&rc.title_buttons_left);
|
||||
wl_list_init(&rc.title_buttons_right);
|
||||
wl_list_init(&rc.usable_area_overrides);
|
||||
wl_list_init(&rc.keybinds);
|
||||
wl_list_init(&rc.mousebinds);
|
||||
|
|
|
|||
|
|
@ -81,7 +81,6 @@ ssd_titlebar_create(struct ssd *ssd)
|
|||
LAB_NODE_TITLE, view, /*data*/ NULL);
|
||||
|
||||
/* Buttons */
|
||||
struct title_button *b;
|
||||
int x = theme->window_titlebar_padding_width;
|
||||
|
||||
/* Center vertically within titlebar */
|
||||
|
|
@ -90,20 +89,22 @@ ssd_titlebar_create(struct ssd *ssd)
|
|||
wl_list_init(&subtree->buttons_left);
|
||||
wl_list_init(&subtree->buttons_right);
|
||||
|
||||
wl_list_for_each(b, &rc.title_buttons_left, link) {
|
||||
for (int b = 0; b < rc.nr_title_buttons_left; b++) {
|
||||
enum lab_node_type type = rc.title_buttons_left[b];
|
||||
struct lab_img **imgs =
|
||||
theme->window[active].button_imgs[b->type];
|
||||
attach_ssd_button(&subtree->buttons_left, b->type, parent,
|
||||
theme->window[active].button_imgs[type];
|
||||
attach_ssd_button(&subtree->buttons_left, type, parent,
|
||||
imgs, x, y, view);
|
||||
x += theme->window_button_width + theme->window_button_spacing;
|
||||
}
|
||||
|
||||
x = width - theme->window_titlebar_padding_width + theme->window_button_spacing;
|
||||
wl_list_for_each_reverse(b, &rc.title_buttons_right, link) {
|
||||
for (int b = rc.nr_title_buttons_right - 1; b >= 0; b--) {
|
||||
x -= theme->window_button_width + theme->window_button_spacing;
|
||||
enum lab_node_type type = rc.title_buttons_right[b];
|
||||
struct lab_img **imgs =
|
||||
theme->window[active].button_imgs[b->type];
|
||||
attach_ssd_button(&subtree->buttons_right, b->type, parent,
|
||||
theme->window[active].button_imgs[type];
|
||||
attach_ssd_button(&subtree->buttons_right, type, parent,
|
||||
imgs, x, y, view);
|
||||
}
|
||||
}
|
||||
|
|
@ -223,8 +224,8 @@ update_visible_buttons(struct ssd *ssd)
|
|||
int width = MAX(view->current.width - 2 * theme->window_titlebar_padding_width, 0);
|
||||
int button_width = theme->window_button_width;
|
||||
int button_spacing = theme->window_button_spacing;
|
||||
int button_count_left = wl_list_length(&rc.title_buttons_left);
|
||||
int button_count_right = wl_list_length(&rc.title_buttons_right);
|
||||
int button_count_left = rc.nr_title_buttons_left;
|
||||
int button_count_right = rc.nr_title_buttons_right;
|
||||
|
||||
/* Make sure infinite loop never occurs */
|
||||
assert(button_width > 0);
|
||||
|
|
|
|||
27
src/theme.c
27
src/theme.c
|
|
@ -231,25 +231,16 @@ load_button(struct theme *theme, struct button *b, int active)
|
|||
struct lab_img **rounded_img =
|
||||
&button_imgs[b->type][b->state_set | LAB_BS_ROUNDED];
|
||||
|
||||
struct title_button *leftmost_button;
|
||||
wl_list_for_each(leftmost_button,
|
||||
&rc.title_buttons_left, link) {
|
||||
if (leftmost_button->type == b->type) {
|
||||
*rounded_img = lab_img_copy(*img);
|
||||
lab_img_add_modifier(*rounded_img,
|
||||
round_left_corner_button);
|
||||
}
|
||||
break;
|
||||
if (rc.nr_title_buttons_left > 0
|
||||
&& b->type == rc.title_buttons_left[0]) {
|
||||
*rounded_img = lab_img_copy(*img);
|
||||
lab_img_add_modifier(*rounded_img, round_left_corner_button);
|
||||
}
|
||||
struct title_button *rightmost_button;
|
||||
wl_list_for_each_reverse(rightmost_button,
|
||||
&rc.title_buttons_right, link) {
|
||||
if (rightmost_button->type == b->type) {
|
||||
*rounded_img = lab_img_copy(*img);
|
||||
lab_img_add_modifier(*rounded_img,
|
||||
round_right_corner_button);
|
||||
}
|
||||
break;
|
||||
if (rc.nr_title_buttons_right > 0
|
||||
&& b->type == rc.title_buttons_right
|
||||
[rc.nr_title_buttons_right - 1]) {
|
||||
*rounded_img = lab_img_copy(*img);
|
||||
lab_img_add_modifier(*rounded_img, round_right_corner_button);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue