sway/swaybar/config.c

99 lines
3 KiB
C
Raw Normal View History

2017-03-11 04:41:24 +00:00
#define _XOPEN_SOURCE 500
2016-01-23 01:47:44 +00:00
#include <stdlib.h>
#include <string.h>
#include <wlr/util/log.h>
2016-09-01 12:18:37 +00:00
#include "swaybar/config.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
2018-10-08 15:40:13 +00:00
#include "stringop.h"
#include "list.h"
2016-01-23 01:47:44 +00:00
uint32_t parse_position(const char *position) {
uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
2016-01-23 01:47:44 +00:00
if (strcmp("top", position) == 0) {
return ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | horiz;
2016-01-23 01:47:44 +00:00
} else if (strcmp("bottom", position) == 0) {
return ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | horiz;
2016-01-23 01:47:44 +00:00
} else {
wlr_log(WLR_ERROR, "Invalid position: %s, defaulting to bottom", position);
return ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | horiz;
2016-01-23 01:47:44 +00:00
}
}
struct swaybar_config *init_config(void) {
struct swaybar_config *config = calloc(1, sizeof(struct swaybar_config));
2016-01-23 01:47:44 +00:00
config->status_command = NULL;
config->pango_markup = false;
config->position = parse_position("bottom");
2016-01-23 23:23:09 +00:00
config->font = strdup("monospace 10");
config->mode = strdup("dock");
config->hidden_state = strdup("hide");
2016-01-23 01:47:44 +00:00
config->sep_symbol = NULL;
config->strip_workspace_numbers = false;
config->binding_mode_indicator = true;
config->wrap_scroll = false;
2016-01-23 01:47:44 +00:00
config->workspace_buttons = true;
2018-10-08 15:40:13 +00:00
config->bindings = create_list();
2018-03-29 03:56:02 +00:00
wl_list_init(&config->outputs);
2016-01-23 01:47:44 +00:00
2016-01-23 23:23:09 +00:00
/* height */
config->height = 0;
2016-01-23 01:47:44 +00:00
/* colors */
config->colors.background = 0x000000FF;
2018-03-29 15:58:54 +00:00
config->colors.focused_background = 0x000000FF;
2016-01-23 01:47:44 +00:00
config->colors.statusline = 0xFFFFFFFF;
config->colors.focused_statusline = 0xFFFFFFFF;
2016-01-23 01:47:44 +00: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;
return config;
}
static void free_binding(struct swaybar_binding *binding) {
if (!binding) {
return;
}
free(binding->command);
free(binding);
}
void free_config(struct swaybar_config *config) {
2016-01-23 01:47:44 +00:00
free(config->status_command);
free(config->font);
free(config->mode);
free(config->hidden_state);
2016-01-23 01:47:44 +00:00
free(config->sep_symbol);
for (int i = 0; i < config->bindings->length; i++) {
struct swaybar_binding *binding = config->bindings->items[i];
free_binding(binding);
2018-10-08 15:40:13 +00:00
}
list_free(config->bindings);
2018-04-24 21:04:19 +00: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);
}
2016-01-23 01:47:44 +00:00
free(config);
}