src/ssd/ssd_part.c: ensure button is found

This fixes an issue detected by the static analyzer.
It currently is not a real bug but it could become
one in the future if `add_toggled_icon()` is called
before `add_scene_button()`.

Rather than having `add_toggled_icon()` go through
the list, find the root button and then fetch its
node descriptor just supply the button as argument.
This commit is contained in:
Consolatis 2024-04-08 17:56:56 +02:00
parent b959e23d6d
commit 59c95ceb26
3 changed files with 13 additions and 10 deletions

View file

@ -123,9 +123,9 @@ struct ssd_part *add_scene_button(
struct wlr_scene_tree *parent, float *bg_color,
struct wlr_buffer *icon_buffer, struct wlr_buffer *hover_buffer,
int x, struct view *view);
void
add_toggled_icon(struct wl_list *part_list, enum ssd_part_type type,
struct wlr_buffer *icon_buffer, struct wlr_buffer *hover_buffer);
void add_toggled_icon(struct ssd_button *button, struct wl_list *part_list,
enum ssd_part_type type, struct wlr_buffer *icon_buffer,
struct wlr_buffer *hover_buffer);
struct ssd_part *add_scene_button_corner(
struct wl_list *part_list, enum ssd_part_type type,
enum ssd_part_type corner_type, struct wlr_scene_tree *parent,

View file

@ -194,12 +194,10 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
}
void
add_toggled_icon(struct wl_list *part_list, enum ssd_part_type type,
struct wlr_buffer *icon_buffer, struct wlr_buffer *hover_buffer)
add_toggled_icon(struct ssd_button *button, struct wl_list *part_list,
enum ssd_part_type type, struct wlr_buffer *icon_buffer,
struct wlr_buffer *hover_buffer)
{
struct ssd_part *part = ssd_get_part(part_list, type);
struct ssd_button *button = node_ssd_button_from_node(part->node);
/* Alternate icon */
struct wlr_box icon_geo = get_scale_box(icon_buffer,
SSD_BUTTON_WIDTH, rc.theme->title_height);

View file

@ -99,11 +99,16 @@ ssd_titlebar_create(struct ssd *ssd)
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent,
color, iconify_button_unpressed, iconify_button_hover,
width - SSD_BUTTON_WIDTH * 3, view);
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE, parent,
/* Maximize button has an alternate state when maximized */
struct ssd_part *btn_max_root = add_scene_button(
&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE, parent,
color, maximize_button_unpressed, maximize_button_hover,
width - SSD_BUTTON_WIDTH * 2, view);
add_toggled_icon(&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE,
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,
restore_button_unpressed, restore_button_hover);
add_scene_button_corner(&subtree->parts,
LAB_SSD_BUTTON_CLOSE, LAB_SSD_PART_CORNER_TOP_RIGHT, parent,
corner_top_right, close_button_unpressed, close_button_hover,