| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-01 08:18:37 -04:00
										 |  |  | #include "swaybar/config.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-28 23:04:20 -04:00
										 |  |  | #include "wlr-layer-shell-unstable-v1-client-protocol.h"
 | 
					
						
							| 
									
										
										
										
											2018-12-09 15:10:41 +00:00
										 |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-08 11:40:13 -04:00
										 |  |  | #include "stringop.h"
 | 
					
						
							|  |  |  | #include "list.h"
 | 
					
						
							| 
									
										
										
										
											2019-01-20 13:51:12 -05:00
										 |  |  | #include "log.h"
 | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | uint32_t parse_position(const char *position) { | 
					
						
							| 
									
										
										
										
											2018-03-28 23:04:20 -04:00
										 |  |  | 	uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | | 
					
						
							|  |  |  | 		ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	if (strcmp("top", position) == 0) { | 
					
						
							| 
									
										
										
										
											2018-03-28 23:04:20 -04:00
										 |  |  | 		return ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | horiz; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	} else if (strcmp("bottom", position) == 0) { | 
					
						
							| 
									
										
										
										
											2018-03-28 23:04:20 -04:00
										 |  |  | 		return ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | horiz; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2019-01-20 13:51:12 -05:00
										 |  |  | 		sway_log(SWAY_ERROR, "Invalid position: %s, defaulting to bottom", position); | 
					
						
							| 
									
										
										
										
											2018-03-28 23:04:20 -04:00
										 |  |  | 		return ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | horiz; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 13:58:49 +03:00
										 |  |  | struct swaybar_config *init_config(void) { | 
					
						
							| 
									
										
										
										
											2018-03-28 23:04:20 -04:00
										 |  |  | 	struct swaybar_config *config = calloc(1, sizeof(struct swaybar_config)); | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	config->status_command = NULL; | 
					
						
							| 
									
										
										
										
											2016-10-20 16:43:38 +03:00
										 |  |  | 	config->pango_markup = false; | 
					
						
							| 
									
										
										
										
											2018-03-28 23:04:20 -04:00
										 |  |  | 	config->position = parse_position("bottom"); | 
					
						
							| 
									
										
										
										
											2022-07-01 12:23:04 +02:00
										 |  |  | 	config->font_description = pango_font_description_from_string("monospace 10"); | 
					
						
							| 
									
										
										
										
											2018-10-12 20:32:48 +01:00
										 |  |  | 	config->mode = strdup("dock"); | 
					
						
							|  |  |  | 	config->hidden_state = strdup("hide"); | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	config->sep_symbol = NULL; | 
					
						
							|  |  |  | 	config->strip_workspace_numbers = false; | 
					
						
							| 
									
										
										
										
											2018-11-17 16:11:28 +00:00
										 |  |  | 	config->strip_workspace_name = false; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	config->binding_mode_indicator = true; | 
					
						
							| 
									
										
										
										
											2016-07-17 11:26:38 -04:00
										 |  |  | 	config->wrap_scroll = false; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	config->workspace_buttons = true; | 
					
						
							| 
									
										
										
										
											2020-10-03 15:45:26 +02:00
										 |  |  | 	config->workspace_min_width = 0; | 
					
						
							| 
									
										
										
										
											2018-10-08 11:40:13 -04:00
										 |  |  | 	config->bindings = create_list(); | 
					
						
							| 
									
										
										
										
											2018-03-28 23:56:02 -04:00
										 |  |  | 	wl_list_init(&config->outputs); | 
					
						
							| 
									
										
										
										
											2019-01-10 23:43:45 -05:00
										 |  |  | 	config->status_padding = 1; | 
					
						
							| 
									
										
										
										
											2019-01-11 00:12:24 -05:00
										 |  |  | 	config->status_edge_padding = 3; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 00:23:09 +01:00
										 |  |  | 	/* height */ | 
					
						
							|  |  |  | 	config->height = 0; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-28 11:23:48 -05:00
										 |  |  | 	/* gaps */ | 
					
						
							|  |  |  | 	config->gaps.top = 0; | 
					
						
							|  |  |  | 	config->gaps.right = 0; | 
					
						
							|  |  |  | 	config->gaps.bottom = 0; | 
					
						
							|  |  |  | 	config->gaps.left = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	/* colors */ | 
					
						
							|  |  |  | 	config->colors.background = 0x000000FF; | 
					
						
							| 
									
										
										
										
											2018-03-29 11:58:54 -04:00
										 |  |  | 	config->colors.focused_background = 0x000000FF; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	config->colors.statusline = 0xFFFFFFFF; | 
					
						
							| 
									
										
										
										
											2018-03-29 15:16:12 -04:00
										 |  |  | 	config->colors.focused_statusline = 0xFFFFFFFF; | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	config->colors.separator = 0x666666FF; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	config->colors.focused_workspace.border = 0x4C7899FF; | 
					
						
							|  |  |  | 	config->colors.focused_workspace.background = 0x285577FF; | 
					
						
							|  |  |  | 	config->colors.focused_workspace.text = 0xFFFFFFFF; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	config->colors.active_workspace.border = 0x333333FF; | 
					
						
							|  |  |  | 	config->colors.active_workspace.background = 0x5F676AFF; | 
					
						
							|  |  |  | 	config->colors.active_workspace.text = 0xFFFFFFFF; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	config->colors.inactive_workspace.border = 0x333333FF; | 
					
						
							|  |  |  | 	config->colors.inactive_workspace.background = 0x222222FF; | 
					
						
							|  |  |  | 	config->colors.inactive_workspace.text = 0x888888FF; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	config->colors.urgent_workspace.border = 0x2F343AFF; | 
					
						
							|  |  |  | 	config->colors.urgent_workspace.background = 0x900000FF; | 
					
						
							|  |  |  | 	config->colors.urgent_workspace.text = 0xFFFFFFFF; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	config->colors.binding_mode.border = 0x2F343AFF; | 
					
						
							|  |  |  | 	config->colors.binding_mode.background = 0x900000FF; | 
					
						
							|  |  |  | 	config->colors.binding_mode.text = 0xFFFFFFFF; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 15:10:41 +00:00
										 |  |  | #if HAVE_TRAY
 | 
					
						
							|  |  |  | 	config->tray_padding = 2; | 
					
						
							| 
									
										
										
										
											2019-01-15 21:25:28 -05:00
										 |  |  | 	wl_list_init(&config->tray_bindings); | 
					
						
							| 
									
										
										
										
											2018-12-09 15:10:41 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	return config; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-02 21:41:11 -04:00
										 |  |  | void free_binding(struct swaybar_binding *binding) { | 
					
						
							| 
									
										
										
										
											2018-10-09 08:12:02 -04:00
										 |  |  | 	if (!binding) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	free(binding->command); | 
					
						
							|  |  |  | 	free(binding); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 21:25:28 -05:00
										 |  |  | #if HAVE_TRAY
 | 
					
						
							| 
									
										
										
										
											2019-09-02 21:41:11 -04:00
										 |  |  | void free_tray_binding(struct tray_binding *binding) { | 
					
						
							| 
									
										
										
										
											2019-01-15 21:25:28 -05:00
										 |  |  | 	if (!binding) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	free(binding->command); | 
					
						
							|  |  |  | 	free(binding); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-28 23:04:20 -04:00
										 |  |  | void free_config(struct swaybar_config *config) { | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	free(config->status_command); | 
					
						
							| 
									
										
										
										
											2022-07-01 12:23:04 +02:00
										 |  |  | 	pango_font_description_free(config->font_description); | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	free(config->mode); | 
					
						
							| 
									
										
										
										
											2018-10-12 20:32:48 +01:00
										 |  |  | 	free(config->hidden_state); | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	free(config->sep_symbol); | 
					
						
							| 
									
										
										
										
											2018-10-09 08:12:02 -04:00
										 |  |  | 	for (int i = 0; i < config->bindings->length; i++) { | 
					
						
							|  |  |  | 		struct swaybar_binding *binding = config->bindings->items[i]; | 
					
						
							|  |  |  | 		free_binding(binding); | 
					
						
							| 
									
										
										
										
											2018-10-08 11:40:13 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	list_free(config->bindings); | 
					
						
							| 
									
										
										
										
											2018-04-24 22:04:19 +01:00
										 |  |  | 	struct config_output *coutput, *tmp; | 
					
						
							|  |  |  | 	wl_list_for_each_safe(coutput, tmp, &config->outputs, link) { | 
					
						
							|  |  |  | 		wl_list_remove(&coutput->link); | 
					
						
							|  |  |  | 		free(coutput->name); | 
					
						
							|  |  |  | 		free(coutput); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-12-09 15:10:41 +00:00
										 |  |  | #if HAVE_TRAY
 | 
					
						
							|  |  |  | 	list_free_items_and_destroy(config->tray_outputs); | 
					
						
							| 
									
										
										
										
											2019-01-15 21:25:28 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	struct tray_binding *tray_bind = NULL, *tmp_tray_bind = NULL; | 
					
						
							|  |  |  | 	wl_list_for_each_safe(tray_bind, tmp_tray_bind, &config->tray_bindings, | 
					
						
							|  |  |  | 			link) { | 
					
						
							|  |  |  | 		wl_list_remove(&tray_bind->link); | 
					
						
							|  |  |  | 		free_tray_binding(tray_bind); | 
					
						
							| 
									
										
										
										
											2018-12-09 15:10:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-01-15 21:25:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 15:10:41 +00:00
										 |  |  | 	free(config->icon_theme); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-01-23 02:47:44 +01:00
										 |  |  | 	free(config); | 
					
						
							|  |  |  | } |