mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	xbm: parse_xbm_builtin() remove hard-coded values
This commit is contained in:
		
							parent
							
								
									5dbc87a1f9
								
							
						
					
					
						commit
						5ea1527558
					
				
					 3 changed files with 15 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -26,6 +26,6 @@ struct pixmap parse_xbm_tokens(struct token *tokens);
 | 
			
		|||
 * parse_xbm_builtin - parse builtin xbm button and create pixmap
 | 
			
		||||
 * @button: button byte array (xbm format)
 | 
			
		||||
 */
 | 
			
		||||
struct pixmap parse_xbm_builtin(const char *button);
 | 
			
		||||
struct pixmap parse_xbm_builtin(const char *button, int size);
 | 
			
		||||
 | 
			
		||||
#endif /* __LABWC_PARSE_H */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,6 +12,7 @@
 | 
			
		|||
#include <stdbool.h>
 | 
			
		||||
 | 
			
		||||
#include "theme/xbm/parse.h"
 | 
			
		||||
#include "common/bug-on.h"
 | 
			
		||||
 | 
			
		||||
/* TODO: should be window.active.button.unpressed.image.color */
 | 
			
		||||
static unsigned char defaultcolor[] = { 255, 255, 255, 255 };
 | 
			
		||||
| 
						 | 
				
			
			@ -71,21 +72,25 @@ out:
 | 
			
		|||
	return pixmap;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Assuming a 6x6 button for the time being */
 | 
			
		||||
/* TODO: pass width, height, vargs bytes */
 | 
			
		||||
struct pixmap parse_xbm_builtin(const char *button)
 | 
			
		||||
/*
 | 
			
		||||
 * Openbox built-in icons are not bigger than 8x8, so have only written this
 | 
			
		||||
 * function to cope wit that max size
 | 
			
		||||
 */
 | 
			
		||||
#define LABWC_BUILTIN_ICON_MAX_SIZE (8)
 | 
			
		||||
struct pixmap parse_xbm_builtin(const char *button, int size)
 | 
			
		||||
{
 | 
			
		||||
	struct pixmap pixmap = { 0 };
 | 
			
		||||
 | 
			
		||||
	pixmap.width = 6;
 | 
			
		||||
	pixmap.height = 6;
 | 
			
		||||
	BUG_ON(size > LABWC_BUILTIN_ICON_MAX_SIZE);
 | 
			
		||||
	pixmap.width = size;
 | 
			
		||||
	pixmap.height = size;
 | 
			
		||||
 | 
			
		||||
	struct token t[7];
 | 
			
		||||
	for (int i = 0; i < 6; i++) {
 | 
			
		||||
	struct token t[LABWC_BUILTIN_ICON_MAX_SIZE + 1];
 | 
			
		||||
	for (int i = 0; i < size; i++) {
 | 
			
		||||
		t[i].value = button[i];
 | 
			
		||||
		t[i].type = TOKEN_INT;
 | 
			
		||||
	}
 | 
			
		||||
	t[6].type = 0;
 | 
			
		||||
	t[size].type = 0;
 | 
			
		||||
	process_bytes(&pixmap, t);
 | 
			
		||||
	return pixmap;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ static struct wlr_texture *texture_from_pixmap(struct wlr_renderer *renderer,
 | 
			
		|||
static struct wlr_texture *texture_from_builtin(struct wlr_renderer *renderer,
 | 
			
		||||
						const char *button)
 | 
			
		||||
{
 | 
			
		||||
	struct pixmap pixmap = parse_xbm_builtin(button);
 | 
			
		||||
	struct pixmap pixmap = parse_xbm_builtin(button, 6);
 | 
			
		||||
	struct wlr_texture *texture = texture_from_pixmap(renderer, &pixmap);
 | 
			
		||||
	if (pixmap.data)
 | 
			
		||||
		free(pixmap.data);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue