mirror of
				https://github.com/labwc/labwc.git
				synced 2025-10-29 05:40:24 -04:00 
			
		
		
		
	Load close.xbm based on rc.xml theme name
This commit is contained in:
		
							parent
							
								
									db0df6ed7e
								
							
						
					
					
						commit
						1330071e0c
					
				
					 5 changed files with 69 additions and 9 deletions
				
			
		|  | @ -40,6 +40,8 @@ libxml2, glib-2.0, cairo and pango. | ||||||
| - [ ] Implement client-menu | - [ ] Implement client-menu | ||||||
| - [ ] Implement root-menu | - [ ] Implement root-menu | ||||||
| 
 | 
 | ||||||
|  | For further details see [wiki/Roadmap](https://github.com/johanmalm/labwc/wiki/Roadmap). | ||||||
|  | 
 | ||||||
| ## Inspiration | ## Inspiration | ||||||
| 
 | 
 | ||||||
| Labwc has been inspired and inflenced by [openbox](https://github.com/danakj/openbox), [sway](https://github.com/swaywm/sway), [cage](https://www.hjdskes.nl/blog/cage-01/), [wio](https://wio-project.org/) and [rootston](https://github.com/swaywm/rootston) | Labwc has been inspired and inflenced by [openbox](https://github.com/danakj/openbox), [sway](https://github.com/swaywm/sway), [cage](https://www.hjdskes.nl/blog/cage-01/), [wio](https://wio-project.org/) and [rootston](https://github.com/swaywm/rootston) | ||||||
|  | @ -67,5 +69,5 @@ Suggested apps: | ||||||
| 
 | 
 | ||||||
| To enable ASAN and UBSAN, run meson with `-Db_sanitize=address,undefined` | To enable ASAN and UBSAN, run meson with `-Db_sanitize=address,undefined` | ||||||
| 
 | 
 | ||||||
| For further details see [wiki/Build](https://github.com/labwc/wiki/Build). | For further details see [wiki/Build](https://github.com/johanmalm/labwc/wiki/Build). | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -14,6 +14,15 @@ | ||||||
|   </keyboard> |   </keyboard> | ||||||
| </lab> | </lab> | ||||||
| 
 | 
 | ||||||
|  | <theme> | ||||||
|  |   <name>Clearlooks</name> | ||||||
|  |   <titleLayout>NLIMC</titleLayout> | ||||||
|  |   <font place="ActiveWindow"> | ||||||
|  |     <name>sans</name> | ||||||
|  |     <size>8</size> | ||||||
|  |   </font> | ||||||
|  | </theme> | ||||||
|  | 
 | ||||||
| <keyboard> | <keyboard> | ||||||
|   <keybind key="A-Escape"> |   <keybind key="A-Escape"> | ||||||
|     <action name="Exit"/> |     <action name="Exit"/> | ||||||
|  |  | ||||||
|  | @ -30,6 +30,7 @@ struct keybind *keybind_add(const char *keybind); | ||||||
| 
 | 
 | ||||||
| struct rcxml { | struct rcxml { | ||||||
| 	bool client_side_decorations; | 	bool client_side_decorations; | ||||||
|  | 	char *theme_name; | ||||||
| 	struct wl_list keybinds; | 	struct wl_list keybinds; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -78,8 +78,10 @@ static void entry(xmlNode *node, char *nodename, char *content) | ||||||
| 		fill_keybind(node, nodename, content); | 		fill_keybind(node, nodename, content); | ||||||
| 	if (!strcmp(nodename, "csd.lab")) | 	if (!strcmp(nodename, "csd.lab")) | ||||||
| 		rc.client_side_decorations = get_bool(content); | 		rc.client_side_decorations = get_bool(content); | ||||||
| 	if (!strcmp(nodename, "layout.keyboard.lab")) | 	else if (!strcmp(nodename, "layout.keyboard.lab")) | ||||||
| 		setenv("XKB_DEFAULT_LAYOUT", content, 1); | 		setenv("XKB_DEFAULT_LAYOUT", content, 1); | ||||||
|  | 	else if (!strcmp(nodename, "name.theme")) | ||||||
|  | 		rc.theme_name = strdup(content); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static char *nodename(xmlNode *node, char *buf, int len) | static char *nodename(xmlNode *node, char *buf, int len) | ||||||
|  |  | ||||||
|  | @ -6,9 +6,27 @@ | ||||||
| 
 | 
 | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | #include <sys/stat.h> | ||||||
| 
 | 
 | ||||||
| #include "theme/xbm/xbm.h" | #include "theme/xbm/xbm.h" | ||||||
| #include "theme/xbm/parse.h" | #include "theme/xbm/parse.h" | ||||||
|  | #include "rcxml.h" | ||||||
|  | 
 | ||||||
|  | struct dir { | ||||||
|  | 	const char *prefix; | ||||||
|  | 	const char *path; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static struct dir theme_dirs[] = { | ||||||
|  | 	{ "XDG_DATA_HOME", "themes" }, | ||||||
|  | 	{ "HOME", ".local/share/themes" }, | ||||||
|  | 	{ "HOME", ".themes" }, | ||||||
|  | 	{ "XDG_DATA_HOME", "themes" }, | ||||||
|  | 	{ NULL, "/usr/share/themes" }, | ||||||
|  | 	{ NULL, "/usr/local/share/themes" }, | ||||||
|  | 	{ NULL, "opt/share/themes" }, | ||||||
|  | 	{ NULL, NULL } | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| /* built-in 6x6 buttons */ | /* built-in 6x6 buttons */ | ||||||
| char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 }; | char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 }; | ||||||
|  | @ -16,12 +34,6 @@ char iconify_button_normal[] = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f }; | ||||||
| char max_button_normal[] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f }; | char max_button_normal[] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f }; | ||||||
| char max_button_toggled[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f }; | char max_button_toggled[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f }; | ||||||
| 
 | 
 | ||||||
| /*
 |  | ||||||
|  * TODO: parse rc.xml theme name and look for icons properly. |  | ||||||
|  *       Just using random icon to prove the point. |  | ||||||
|  */ |  | ||||||
| static char filename[] = "/usr/share/themes/Bear2/openbox-3/close.xbm"; |  | ||||||
| 
 |  | ||||||
| static struct wlr_texture *texture_from_pixmap(struct wlr_renderer *renderer, | static struct wlr_texture *texture_from_pixmap(struct wlr_renderer *renderer, | ||||||
| 					       struct pixmap *pixmap) | 					       struct pixmap *pixmap) | ||||||
| { | { | ||||||
|  | @ -42,11 +54,45 @@ static struct wlr_texture *builtin(struct wlr_renderer *renderer, | ||||||
| 	return texture; | 	return texture; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static char *theme_dir(void) | ||||||
|  | { | ||||||
|  | 	static char buffer[4096] = { 0 }; | ||||||
|  | 	if (buffer[0] != '\0') | ||||||
|  | 		return buffer; | ||||||
|  | 
 | ||||||
|  | 	struct stat st; | ||||||
|  | 	for (int i = 0; theme_dirs[i].path; i++) { | ||||||
|  | 		char *prefix = NULL; | ||||||
|  | 		struct dir d = theme_dirs[i]; | ||||||
|  | 		if (d.prefix) { | ||||||
|  | 			prefix = getenv(d.prefix); | ||||||
|  | 			if (!prefix) | ||||||
|  | 				continue; | ||||||
|  | 			snprintf(buffer, sizeof(buffer), "%s/%s/%s/openbox-3", | ||||||
|  | 				 prefix, d.path, rc.theme_name); | ||||||
|  | 		} else { | ||||||
|  | 			snprintf(buffer, sizeof(buffer), "%s/%s/openbox-3", | ||||||
|  | 				 d.path, rc.theme_name); | ||||||
|  | 		} | ||||||
|  | 		if (!stat(buffer, &st) && S_ISDIR(st.st_mode)) | ||||||
|  | 			return buffer; | ||||||
|  | 	} | ||||||
|  | 	buffer[0] = '\0'; | ||||||
|  | 	return buffer; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static char *xbm_path(const char *button) | ||||||
|  | { | ||||||
|  | 	static char buffer[4096] = { 0 }; | ||||||
|  | 	snprintf(buffer, sizeof(buffer), "%s/%s", theme_dir(), button); | ||||||
|  | 	return buffer; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void xbm_load(struct wlr_renderer *renderer) | void xbm_load(struct wlr_renderer *renderer) | ||||||
| { | { | ||||||
| 	struct token *tokens; | 	struct token *tokens; | ||||||
| 
 | 
 | ||||||
| 	char *buffer = xbm_read_file(filename); | 	char *buffer = xbm_read_file(xbm_path("close.xbm")); | ||||||
| 	if (!buffer) { | 	if (!buffer) { | ||||||
| 		fprintf(stderr, "no buffer\n"); | 		fprintf(stderr, "no buffer\n"); | ||||||
| 		goto out; | 		goto out; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Johan Malm
						Johan Malm