mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	ssd: do not draw background for individual buttons
This commit is contained in:
		
							parent
							
								
									6a1ecd6b7d
								
							
						
					
					
						commit
						7125a312aa
					
				
					 3 changed files with 46 additions and 81 deletions
				
			
		| 
						 | 
					@ -22,7 +22,6 @@ struct ssd_button {
 | 
				
			||||||
	struct wlr_scene_node *hover;
 | 
						struct wlr_scene_node *hover;
 | 
				
			||||||
	struct wlr_scene_node *toggled;
 | 
						struct wlr_scene_node *toggled;
 | 
				
			||||||
	struct wlr_scene_node *toggled_hover;
 | 
						struct wlr_scene_node *toggled_hover;
 | 
				
			||||||
	struct wlr_scene_node *background;
 | 
					 | 
				
			||||||
	struct wlr_scene_tree *icon_tree;
 | 
						struct wlr_scene_tree *icon_tree;
 | 
				
			||||||
	struct wlr_scene_tree *hover_tree;
 | 
						struct wlr_scene_tree *hover_tree;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -127,17 +126,11 @@ struct ssd_part *add_scene_buffer(
 | 
				
			||||||
	struct wlr_scene_tree *parent, struct wlr_buffer *buffer, int x, int y);
 | 
						struct wlr_scene_tree *parent, struct wlr_buffer *buffer, int x, int y);
 | 
				
			||||||
struct ssd_part *add_scene_button(
 | 
					struct ssd_part *add_scene_button(
 | 
				
			||||||
	struct wl_list *part_list, enum ssd_part_type type,
 | 
						struct wl_list *part_list, enum ssd_part_type type,
 | 
				
			||||||
	struct wlr_scene_tree *parent, float *bg_color,
 | 
						struct wlr_scene_tree *parent, struct wlr_buffer *icon_buffer,
 | 
				
			||||||
	struct wlr_buffer *icon_buffer, struct wlr_buffer *hover_buffer,
 | 
						struct wlr_buffer *hover_buffer, int x, struct view *view);
 | 
				
			||||||
	int x, struct view *view);
 | 
					 | 
				
			||||||
void add_toggled_icon(struct ssd_button *button, struct wl_list *part_list,
 | 
					void add_toggled_icon(struct ssd_button *button, struct wl_list *part_list,
 | 
				
			||||||
	enum ssd_part_type type, struct wlr_buffer *icon_buffer,
 | 
						enum ssd_part_type type, struct wlr_buffer *icon_buffer,
 | 
				
			||||||
	struct wlr_buffer *hover_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,
 | 
					 | 
				
			||||||
	struct wlr_buffer *corner_buffer, struct wlr_buffer *icon_buffer,
 | 
					 | 
				
			||||||
	struct wlr_buffer *hover_buffer, int x, struct view *view);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* SSD internal helpers */
 | 
					/* SSD internal helpers */
 | 
				
			||||||
struct ssd_part *ssd_get_part(
 | 
					struct ssd_part *ssd_get_part(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,42 +78,6 @@ add_scene_buffer(struct wl_list *list, enum ssd_part_type type,
 | 
				
			||||||
	return part;
 | 
						return part;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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,
 | 
					 | 
				
			||||||
		struct wlr_buffer *corner_buffer, struct wlr_buffer *icon_buffer,
 | 
					 | 
				
			||||||
		struct wlr_buffer *hover_buffer, int x, struct view *view)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int offset_x;
 | 
					 | 
				
			||||||
	float invisible[4] = { 0, 0, 0, 0 };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (corner_type == LAB_SSD_PART_CORNER_TOP_LEFT) {
 | 
					 | 
				
			||||||
		offset_x = rc.theme->border_width;
 | 
					 | 
				
			||||||
	} else if (corner_type == LAB_SSD_PART_CORNER_TOP_RIGHT) {
 | 
					 | 
				
			||||||
		offset_x = 0;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		assert(false && "invalid corner button type");
 | 
					 | 
				
			||||||
		wlr_log(WLR_ERROR, "invalid corner button type");
 | 
					 | 
				
			||||||
		abort();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct ssd_part *button_root = add_scene_part(part_list, corner_type);
 | 
					 | 
				
			||||||
	parent = wlr_scene_tree_create(parent);
 | 
					 | 
				
			||||||
	button_root->node = &parent->node;
 | 
					 | 
				
			||||||
	wlr_scene_node_set_position(button_root->node, x, 0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	 * Background, x and y adjusted for border_width which is
 | 
					 | 
				
			||||||
	 * already included in rendered theme.c / corner_buffer
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	add_scene_buffer(part_list, corner_type, parent, corner_buffer,
 | 
					 | 
				
			||||||
		-offset_x, -rc.theme->border_width);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Finally just put a usual theme button on top, using an invisible hitbox */
 | 
					 | 
				
			||||||
	add_scene_button(part_list, type, parent, invisible, icon_buffer, hover_buffer, 0, view);
 | 
					 | 
				
			||||||
	return button_root;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static struct wlr_box
 | 
					static struct wlr_box
 | 
				
			||||||
get_scale_box(struct wlr_buffer *buffer, double container_width,
 | 
					get_scale_box(struct wlr_buffer *buffer, double container_width,
 | 
				
			||||||
		double container_height)
 | 
							double container_height)
 | 
				
			||||||
| 
						 | 
					@ -142,19 +106,19 @@ get_scale_box(struct wlr_buffer *buffer, double container_width,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct ssd_part *
 | 
					struct ssd_part *
 | 
				
			||||||
add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
 | 
					add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
 | 
				
			||||||
		struct wlr_scene_tree *parent, float *bg_color,
 | 
							struct wlr_scene_tree *parent, struct wlr_buffer *icon_buffer,
 | 
				
			||||||
		struct wlr_buffer *icon_buffer, struct wlr_buffer *hover_buffer,
 | 
							struct wlr_buffer *hover_buffer, int x, struct view *view)
 | 
				
			||||||
		int x, struct view *view)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct ssd_part *button_root = add_scene_part(part_list, type);
 | 
						struct ssd_part *button_root = add_scene_part(part_list, type);
 | 
				
			||||||
	parent = wlr_scene_tree_create(parent);
 | 
						parent = wlr_scene_tree_create(parent);
 | 
				
			||||||
	button_root->node = &parent->node;
 | 
						button_root->node = &parent->node;
 | 
				
			||||||
	wlr_scene_node_set_position(button_root->node, x, 0);
 | 
						wlr_scene_node_set_position(button_root->node, x, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Background */
 | 
						/* Hitbox */
 | 
				
			||||||
	struct ssd_part *bg_rect = add_scene_rect(part_list, type, parent,
 | 
						float invisible[4] = { 0, 0, 0, 0 };
 | 
				
			||||||
 | 
						add_scene_rect(part_list, type, parent,
 | 
				
			||||||
		rc.theme->window_button_width, rc.theme->title_height, 0, 0,
 | 
							rc.theme->window_button_width, rc.theme->title_height, 0, 0,
 | 
				
			||||||
		bg_color);
 | 
							invisible);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Icon */
 | 
						/* Icon */
 | 
				
			||||||
	struct wlr_scene_tree *icon_tree = wlr_scene_tree_create(parent);
 | 
						struct wlr_scene_tree *icon_tree = wlr_scene_tree_create(parent);
 | 
				
			||||||
| 
						 | 
					@ -186,7 +150,6 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
 | 
				
			||||||
	button->view = view;
 | 
						button->view = view;
 | 
				
			||||||
	button->normal = icon_part->node;
 | 
						button->normal = icon_part->node;
 | 
				
			||||||
	button->hover = hover_part->node;
 | 
						button->hover = hover_part->node;
 | 
				
			||||||
	button->background = bg_rect->node;
 | 
					 | 
				
			||||||
	button->toggled = NULL;
 | 
						button->toggled = NULL;
 | 
				
			||||||
	button->toggled_hover = NULL;
 | 
						button->toggled_hover = NULL;
 | 
				
			||||||
	button->icon_tree = icon_tree;
 | 
						button->icon_tree = icon_tree;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,30 +88,34 @@ ssd_titlebar_create(struct ssd *ssd)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		wl_list_init(&subtree->parts);
 | 
							wl_list_init(&subtree->parts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Title */
 | 
							/* Background */
 | 
				
			||||||
		add_scene_rect(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent,
 | 
							add_scene_rect(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent,
 | 
				
			||||||
			width - theme->window_button_width * SSD_BUTTON_COUNT,
 | 
								width - theme->window_button_width * 2, theme->title_height,
 | 
				
			||||||
			theme->title_height, theme->window_button_width, 0, color);
 | 
								theme->window_button_width, 0, color);
 | 
				
			||||||
 | 
							add_scene_buffer(&subtree->parts, LAB_SSD_PART_CORNER_TOP_LEFT, parent,
 | 
				
			||||||
 | 
								corner_top_left, -rc.theme->border_width, -rc.theme->border_width);
 | 
				
			||||||
 | 
							add_scene_buffer(&subtree->parts, LAB_SSD_PART_CORNER_TOP_RIGHT, parent,
 | 
				
			||||||
 | 
								corner_top_right, width - theme->window_button_width,
 | 
				
			||||||
 | 
								-rc.theme->border_width);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Buttons */
 | 
							/* Buttons */
 | 
				
			||||||
		add_scene_button_corner(&subtree->parts,
 | 
							add_scene_button(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU, parent,
 | 
				
			||||||
			LAB_SSD_BUTTON_WINDOW_MENU, LAB_SSD_PART_CORNER_TOP_LEFT, parent,
 | 
								menu_button_unpressed, menu_button_hover, 0, view);
 | 
				
			||||||
			corner_top_left, menu_button_unpressed, menu_button_hover, 0, view);
 | 
					 | 
				
			||||||
		add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent,
 | 
							add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent,
 | 
				
			||||||
			color, iconify_button_unpressed, iconify_button_hover,
 | 
								iconify_button_unpressed, iconify_button_hover,
 | 
				
			||||||
			width - theme->window_button_width * 3, view);
 | 
								width - theme->window_button_width * 3, view);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Maximize button has an alternate state when maximized */
 | 
							/* Maximize button has an alternate state when maximized */
 | 
				
			||||||
		struct ssd_part *btn_max_root = add_scene_button(
 | 
							struct ssd_part *btn_max_root = add_scene_button(
 | 
				
			||||||
			&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE, parent,
 | 
								&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE, parent,
 | 
				
			||||||
			color, maximize_button_unpressed, maximize_button_hover,
 | 
								maximize_button_unpressed, maximize_button_hover,
 | 
				
			||||||
			width - theme->window_button_width * 2, view);
 | 
								width - theme->window_button_width * 2, view);
 | 
				
			||||||
		struct ssd_button *btn_max = node_ssd_button_from_node(btn_max_root->node);
 | 
							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,
 | 
							add_toggled_icon(btn_max, &subtree->parts, LAB_SSD_BUTTON_MAXIMIZE,
 | 
				
			||||||
			restore_button_unpressed, restore_button_hover);
 | 
								restore_button_unpressed, restore_button_hover);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		add_scene_button_corner(&subtree->parts,
 | 
							add_scene_button(&subtree->parts, LAB_SSD_BUTTON_CLOSE, parent,
 | 
				
			||||||
			LAB_SSD_BUTTON_CLOSE, LAB_SSD_PART_CORNER_TOP_RIGHT, parent,
 | 
								close_button_unpressed, close_button_hover,
 | 
				
			||||||
			corner_top_right, close_button_unpressed, close_button_hover,
 | 
					 | 
				
			||||||
			width - theme->window_button_width * 1, view);
 | 
								width - theme->window_button_width * 1, view);
 | 
				
			||||||
	} FOR_EACH_END
 | 
						} FOR_EACH_END
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -138,27 +142,25 @@ is_direct_child(struct wlr_scene_node *node, struct ssd_sub_tree *subtree)
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
set_squared_corners(struct ssd *ssd, bool enable)
 | 
					set_squared_corners(struct ssd *ssd, bool enable)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						struct view *view = ssd->view;
 | 
				
			||||||
 | 
						int width = view->current.width;
 | 
				
			||||||
 | 
						struct theme *theme = view->server->theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct ssd_part *part;
 | 
						struct ssd_part *part;
 | 
				
			||||||
	struct ssd_sub_tree *subtree;
 | 
						struct ssd_sub_tree *subtree;
 | 
				
			||||||
	enum ssd_part_type ssd_type[2] = { LAB_SSD_BUTTON_WINDOW_MENU, LAB_SSD_BUTTON_CLOSE };
 | 
						int x = enable ? 0 : theme->window_button_width;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	FOR_EACH_STATE(ssd, subtree) {
 | 
						FOR_EACH_STATE(ssd, subtree) {
 | 
				
			||||||
		for (size_t i = 0; i < ARRAY_SIZE(ssd_type); i++) {
 | 
							part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
 | 
				
			||||||
			part = ssd_get_part(&subtree->parts, ssd_type[i]);
 | 
							wlr_scene_node_set_position(part->node, x, 0);
 | 
				
			||||||
			struct ssd_button *button = node_ssd_button_from_node(part->node);
 | 
							wlr_scene_rect_set_size(
 | 
				
			||||||
 | 
								wlr_scene_rect_from_node(part->node), width - 2 * x, theme->title_height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* Toggle background between invisible and titlebar background color */
 | 
							part = ssd_get_part(&subtree->parts, LAB_SSD_PART_CORNER_TOP_LEFT);
 | 
				
			||||||
			struct wlr_scene_rect *rect = wlr_scene_rect_from_node(button->background);
 | 
							wlr_scene_node_set_enabled(part->node, !enable);
 | 
				
			||||||
			wlr_scene_rect_set_color(rect, !enable ? (float[4]) {0, 0, 0, 0} : (
 | 
					 | 
				
			||||||
				subtree == &ssd->titlebar.active
 | 
					 | 
				
			||||||
					? rc.theme->window_active_title_bg_color
 | 
					 | 
				
			||||||
					: rc.theme->window_inactive_title_bg_color));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* Toggle rounded corner image itself */
 | 
							part = ssd_get_part(&subtree->parts, LAB_SSD_PART_CORNER_TOP_RIGHT);
 | 
				
			||||||
			struct wlr_scene_node *rounded_corner =
 | 
							wlr_scene_node_set_enabled(part->node, !enable);
 | 
				
			||||||
				wl_container_of(part->node->link.prev, rounded_corner, link);
 | 
					 | 
				
			||||||
			wlr_scene_node_set_enabled(rounded_corner, !enable);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} FOR_EACH_END
 | 
						} FOR_EACH_END
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -212,14 +214,14 @@ ssd_titlebar_update(struct ssd *ssd)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct ssd_part *part;
 | 
						struct ssd_part *part;
 | 
				
			||||||
	struct ssd_sub_tree *subtree;
 | 
						struct ssd_sub_tree *subtree;
 | 
				
			||||||
 | 
						int bg_offset = maximized || tiled_not_maximized ? 0 : theme->window_button_width;
 | 
				
			||||||
	FOR_EACH_STATE(ssd, subtree) {
 | 
						FOR_EACH_STATE(ssd, subtree) {
 | 
				
			||||||
		wl_list_for_each(part, &subtree->parts, link) {
 | 
							wl_list_for_each(part, &subtree->parts, link) {
 | 
				
			||||||
			switch (part->type) {
 | 
								switch (part->type) {
 | 
				
			||||||
			case LAB_SSD_PART_TITLEBAR:
 | 
								case LAB_SSD_PART_TITLEBAR:
 | 
				
			||||||
				wlr_scene_rect_set_size(
 | 
									wlr_scene_rect_set_size(
 | 
				
			||||||
					wlr_scene_rect_from_node(part->node),
 | 
										wlr_scene_rect_from_node(part->node),
 | 
				
			||||||
					width - theme->window_button_width * SSD_BUTTON_COUNT,
 | 
										width - bg_offset * 2, theme->title_height);
 | 
				
			||||||
					theme->title_height);
 | 
					 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			case LAB_SSD_BUTTON_ICONIFY:
 | 
								case LAB_SSD_BUTTON_ICONIFY:
 | 
				
			||||||
				if (is_direct_child(part->node, subtree)) {
 | 
									if (is_direct_child(part->node, subtree)) {
 | 
				
			||||||
| 
						 | 
					@ -233,12 +235,19 @@ ssd_titlebar_update(struct ssd *ssd)
 | 
				
			||||||
						width - theme->window_button_width * 2, 0);
 | 
											width - theme->window_button_width * 2, 0);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			case LAB_SSD_PART_CORNER_TOP_RIGHT:
 | 
								case LAB_SSD_BUTTON_CLOSE:
 | 
				
			||||||
				if (is_direct_child(part->node, subtree)) {
 | 
									if (is_direct_child(part->node, subtree)) {
 | 
				
			||||||
					wlr_scene_node_set_position(part->node,
 | 
										wlr_scene_node_set_position(part->node,
 | 
				
			||||||
						width - theme->window_button_width * 1, 0);
 | 
											width - theme->window_button_width * 1, 0);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
 | 
								case LAB_SSD_PART_CORNER_TOP_RIGHT:
 | 
				
			||||||
 | 
									if (is_direct_child(part->node, subtree)) {
 | 
				
			||||||
 | 
										wlr_scene_node_set_position(part->node,
 | 
				
			||||||
 | 
											width - theme->window_button_width * 1,
 | 
				
			||||||
 | 
											-rc.theme->border_width);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
			default:
 | 
								default:
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue