parent
							
								
									a4f7bf23b2
								
							
						
					
					
						commit
						8463a2896a
					
				| @ -0,0 +1,25 @@ | ||||
| #ifndef _SWAY_NAGBAR_TYPES_H | ||||
| #define _SWAY_NAGBAR_TYPES_H | ||||
| 
 | ||||
| struct sway_nagbar_type { | ||||
| 	char *name; | ||||
| 	uint32_t button_background; | ||||
| 	uint32_t background; | ||||
| 	uint32_t text; | ||||
| 	uint32_t border; | ||||
| 	uint32_t border_bottom; | ||||
| }; | ||||
| 
 | ||||
| void nagbar_types_add_default(list_t *types); | ||||
| 
 | ||||
| struct sway_nagbar_type *nagbar_type_get(list_t *types, char *name); | ||||
| 
 | ||||
| struct sway_nagbar_type *nagbar_type_clone(struct sway_nagbar_type *type); | ||||
| 
 | ||||
| void nagbar_type_free(struct sway_nagbar_type *type); | ||||
| 
 | ||||
| void nagbar_types_free(list_t *types); | ||||
| 
 | ||||
| int nagbar_parse_type(int argc, char **argv, struct sway_nagbar_type *type); | ||||
| 
 | ||||
| #endif | ||||
| @ -0,0 +1,57 @@ | ||||
| swaynag(5) | ||||
| 
 | ||||
| # NAME | ||||
| 
 | ||||
| swaynag - swaynag configuration file | ||||
| 
 | ||||
| # SYNOPSIS | ||||
| 
 | ||||
| $HOME/.swaynag/config, $XDG\_CONFIG\_HOME/swaynag/config, | ||||
| SYSCONFDIR/swaynag/config | ||||
| 
 | ||||
| # CONFIG FILE | ||||
| At the top of the config file, _swaynag_ options can be set using the format | ||||
| _long-option=value_. These will be used as default values if _swaynag_ is not | ||||
| given the option. This can be useful for setting a preferred font, output, and | ||||
| edge. | ||||
| 
 | ||||
| Below the options, custom types may be defined. To define a type, use the | ||||
| following format: | ||||
| 
 | ||||
| ``` | ||||
| [name-of-type] | ||||
| color=RRGGBB[AA] | ||||
| ``` | ||||
| 
 | ||||
| All colors may be given in the form _RRGGBB_ or _RRGGBBAA_. The following | ||||
| colors can be set: | ||||
| 
 | ||||
| *background* | ||||
| 	The background color for _swaynag_. | ||||
| 
 | ||||
| *border* | ||||
| 	The color to use for borders of buttons. | ||||
| 
 | ||||
| *border-bottom* | ||||
| 	The color of the border line at the bottom of _swaynag_. | ||||
| 
 | ||||
| *button-background* | ||||
| 	The background color for the buttons. | ||||
| 
 | ||||
| *text* | ||||
| 	The color of the text. | ||||
| 
 | ||||
| # EXAMPLE | ||||
| ``` | ||||
| font=Monospace 12 | ||||
| 
 | ||||
| [green] | ||||
| background=00AA00 | ||||
| border=006600 | ||||
| border-bottom=004400 | ||||
| text=FFFFFF | ||||
| button-background=00CC00 | ||||
| ``` | ||||
| 
 | ||||
| # SEE | ||||
| swaynag(1) | ||||
| @ -0,0 +1,116 @@ | ||||
| #define _XOPEN_SOURCE 500 | ||||
| #include <getopt.h> | ||||
| #include <stdbool.h> | ||||
| #include <stdlib.h> | ||||
| #include <stdint.h> | ||||
| #include <string.h> | ||||
| #include <strings.h> | ||||
| #include "list.h" | ||||
| #include "swaynag/types.h" | ||||
| #include "util.h" | ||||
| 
 | ||||
| void nagbar_types_add_default(list_t *types) { | ||||
| 	struct sway_nagbar_type *type_error; | ||||
| 	type_error = calloc(1, sizeof(struct sway_nagbar_type)); | ||||
| 	type_error->name = strdup("error"); | ||||
| 	type_error->button_background = 0x680A0AFF; | ||||
| 	type_error->background = 0x900000FF; | ||||
| 	type_error->text = 0xFFFFFFFF; | ||||
| 	type_error->border = 0xD92424FF; | ||||
| 	type_error->border_bottom = 0x470909FF; | ||||
| 	list_add(types, type_error); | ||||
| 
 | ||||
| 	struct sway_nagbar_type *type_warning; | ||||
| 	type_warning = calloc(1, sizeof(struct sway_nagbar_type)); | ||||
| 	type_warning->name = strdup("warning"); | ||||
| 	type_warning->button_background = 0xFFC100FF; | ||||
| 	type_warning->background = 0xFFA800FF; | ||||
| 	type_warning->text = 0x000000FF; | ||||
| 	type_warning->border = 0xAB7100FF; | ||||
| 	type_warning->border_bottom = 0xAB7100FF; | ||||
| 	list_add(types, type_warning); | ||||
| } | ||||
| 
 | ||||
| struct sway_nagbar_type *nagbar_type_get(list_t *types, char *name) { | ||||
| 	for (int i = 0; i < types->length; i++) { | ||||
| 		struct sway_nagbar_type *type = types->items[i]; | ||||
| 		if (strcasecmp(type->name, name) == 0) { | ||||
| 			return type; | ||||
| 		} | ||||
| 	} | ||||
| 	return NULL; | ||||
| } | ||||
| 
 | ||||
| struct sway_nagbar_type *nagbar_type_clone(struct sway_nagbar_type *type) { | ||||
| 	struct sway_nagbar_type *clone; | ||||
| 	clone = calloc(1, sizeof(struct sway_nagbar_type)); | ||||
| 	clone->name = strdup(type->name); | ||||
| 	clone->button_background = type->button_background; | ||||
| 	clone->background = type->background; | ||||
| 	clone->text = type->text; | ||||
| 	clone->border = type->border; | ||||
| 	clone->border_bottom = type->border_bottom; | ||||
| 	return clone; | ||||
| } | ||||
| 
 | ||||
| void nagbar_type_free(struct sway_nagbar_type *type) { | ||||
| 	free(type->name); | ||||
| 	free(type); | ||||
| } | ||||
| 
 | ||||
| void nagbar_types_free(list_t *types) { | ||||
| 	while (types->length) { | ||||
| 		struct sway_nagbar_type *type = types->items[0]; | ||||
| 		nagbar_type_free(type); | ||||
| 		list_del(types, 0); | ||||
| 	} | ||||
| 	list_free(types); | ||||
| } | ||||
| 
 | ||||
| int nagbar_parse_type(int argc, char **argv, struct sway_nagbar_type *type) { | ||||
| 	enum color_option { | ||||
| 		COLOR_BACKGROUND, | ||||
| 		COLOR_BORDER, | ||||
| 		COLOR_BORDER_BOTTOM, | ||||
| 		COLOR_BUTTON, | ||||
| 		COLOR_TEXT, | ||||
| 	}; | ||||
| 
 | ||||
| 	static struct option opts[] = { | ||||
| 		{"background", required_argument, NULL, COLOR_BACKGROUND}, | ||||
| 		{"border", required_argument, NULL, COLOR_BORDER}, | ||||
| 		{"border-bottom", required_argument, NULL, COLOR_BORDER_BOTTOM}, | ||||
| 		{"button-background", required_argument, NULL, COLOR_BUTTON}, | ||||
| 		{"text", required_argument, NULL, COLOR_TEXT}, | ||||
| 		{0, 0, 0, 0} | ||||
| 	}; | ||||
| 
 | ||||
| 	optind = 1; | ||||
| 	while (1) { | ||||
| 		int c = getopt_long(argc, argv, "", opts, NULL); | ||||
| 		if (c == -1) { | ||||
| 			break; | ||||
| 		} | ||||
| 		switch (c) { | ||||
| 			case COLOR_BACKGROUND: | ||||
| 				type->background = parse_color(optarg); | ||||
| 				break; | ||||
| 			case COLOR_BORDER: | ||||
| 				type->border = parse_color(optarg); | ||||
| 				break; | ||||
| 			case COLOR_BORDER_BOTTOM: | ||||
| 				type->border_bottom = parse_color(optarg); | ||||
| 				break; | ||||
| 			case COLOR_BUTTON: | ||||
| 				type->button_background = parse_color(optarg); | ||||
| 				break; | ||||
| 			case COLOR_TEXT: | ||||
| 				type->text = parse_color(optarg); | ||||
| 				break; | ||||
| 			default: | ||||
| 				break; | ||||
| 		} | ||||
| 	} | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
					Loading…
					
					
				
		Reference in new issue