mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	Support icon colors
xbm/parse: support specifiying color when loading icon theme.c: parse window.active.button.unpressed.image.color
This commit is contained in:
		
							parent
							
								
									4f96230ebf
								
							
						
					
					
						commit
						5122a9be69
					
				
					 5 changed files with 22 additions and 10 deletions
				
			
		| 
						 | 
					@ -14,6 +14,7 @@ struct theme {
 | 
				
			||||||
	float window_active_title_bg_color[4];
 | 
						float window_active_title_bg_color[4];
 | 
				
			||||||
	float window_active_handle_bg_color[4];
 | 
						float window_active_handle_bg_color[4];
 | 
				
			||||||
	float window_inactive_title_bg_color[4];
 | 
						float window_inactive_title_bg_color[4];
 | 
				
			||||||
 | 
						float window_active_button_unpressed_image_color[4];
 | 
				
			||||||
	struct wlr_texture *xbm_close;
 | 
						struct wlr_texture *xbm_close;
 | 
				
			||||||
	struct wlr_texture *xbm_maximize;
 | 
						struct wlr_texture *xbm_maximize;
 | 
				
			||||||
	struct wlr_texture *xbm_iconify;
 | 
						struct wlr_texture *xbm_iconify;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,12 @@ struct pixmap {
 | 
				
			||||||
	int height;
 | 
						int height;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * parse_set_color - set color to be used when parsing icons
 | 
				
			||||||
 | 
					 * @rgba: four floats representing red, green, blue, alpha
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void parse_set_color(float *rgba);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * parse_xbm_tokens - parse xbm tokens and create pixmap
 | 
					 * parse_xbm_tokens - parse xbm tokens and create pixmap
 | 
				
			||||||
 * @tokens: token vector
 | 
					 * @tokens: token vector
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,6 +49,8 @@ static void entry(const char *key, const char *value)
 | 
				
			||||||
		parse_hexstr(value, theme.window_active_handle_bg_color);
 | 
							parse_hexstr(value, theme.window_active_handle_bg_color);
 | 
				
			||||||
	if (match(key, "window.inactive.title.bg.color"))
 | 
						if (match(key, "window.inactive.title.bg.color"))
 | 
				
			||||||
		parse_hexstr(value, theme.window_inactive_title_bg_color);
 | 
							parse_hexstr(value, theme.window_inactive_title_bg_color);
 | 
				
			||||||
 | 
						if (match(key, "window.active.button.unpressed.image.color"))
 | 
				
			||||||
 | 
							parse_hexstr(value, theme.window_active_button_unpressed_image_color);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void rtrim(char **s)
 | 
					static void rtrim(char **s)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,16 +14,20 @@
 | 
				
			||||||
#include "theme/xbm/parse.h"
 | 
					#include "theme/xbm/parse.h"
 | 
				
			||||||
#include "common/bug-on.h"
 | 
					#include "common/bug-on.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* TODO: should be window.active.button.unpressed.image.color */
 | 
					static uint32_t color;
 | 
				
			||||||
static unsigned char defaultcolor[] = { 255, 255, 255, 255 };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint32_t u32(unsigned char *rgba)
 | 
					static uint32_t u32(float *rgba)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t r[4] = { 0 };
 | 
						uint32_t r[4] = { 0 };
 | 
				
			||||||
	for (int i = 0; i < 4; i++)
 | 
						for (int i = 0; i < 4; i++)
 | 
				
			||||||
		r[i] = rgba[i];
 | 
							r[i] = rgba[i] * 255;
 | 
				
			||||||
	return ((r[3] & 0xff) << 24) | ((r[2] & 0xff) << 16) |
 | 
						return ((r[3] & 0xff) << 24) | ((r[0] & 0xff) << 16) |
 | 
				
			||||||
	       ((r[1] & 0xff) << 8) | (r[0] & 0xff);
 | 
						       ((r[1] & 0xff) << 8) | (r[2] & 0xff);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void parse_set_color(float *rgba)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						color = u32(rgba);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void process_bytes(struct pixmap *pixmap, struct token *tokens)
 | 
					static void process_bytes(struct pixmap *pixmap, struct token *tokens)
 | 
				
			||||||
| 
						 | 
					@ -44,8 +48,7 @@ static void process_bytes(struct pixmap *pixmap, struct token *tokens)
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			int bit = 1 << (col % 8);
 | 
								int bit = 1 << (col % 8);
 | 
				
			||||||
			if (t->value & bit)
 | 
								if (t->value & bit)
 | 
				
			||||||
				pixmap->data[row * pixmap->width + col] =
 | 
									pixmap->data[row * pixmap->width + col] = color;
 | 
				
			||||||
					u32(defaultcolor);
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		++t;
 | 
							++t;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,8 +71,8 @@ out:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void xbm_load(struct wlr_renderer *r)
 | 
					void xbm_load(struct wlr_renderer *r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						parse_set_color(theme.window_active_button_unpressed_image_color);
 | 
				
			||||||
	load_button(r, "close.xbm", &theme.xbm_close, close_button_normal);
 | 
						load_button(r, "close.xbm", &theme.xbm_close, close_button_normal);
 | 
				
			||||||
	load_button(r, "max.xbm", &theme.xbm_maximize, max_button_normal);
 | 
						load_button(r, "max.xbm", &theme.xbm_maximize, max_button_normal);
 | 
				
			||||||
	load_button(r, "iconify.xbm", &theme.xbm_iconify,
 | 
						load_button(r, "iconify.xbm", &theme.xbm_iconify, iconify_button_normal);
 | 
				
			||||||
		    iconify_button_normal);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue