diff options
Diffstat (limited to 'swaybar/config.c')
-rw-r--r-- | swaybar/config.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/swaybar/config.c b/swaybar/config.c new file mode 100644 index 00000000..388daa55 --- /dev/null +++ b/swaybar/config.c | |||
@@ -0,0 +1,96 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | |||
4 | #include "wayland-desktop-shell-client-protocol.h" | ||
5 | #include "log.h" | ||
6 | #include "config.h" | ||
7 | |||
8 | uint32_t parse_color(const char *color) { | ||
9 | if (color[0] != '#') { | ||
10 | sway_log(L_DEBUG, "Invalid color %s, defaulting to color 0xFFFFFFFF", color); | ||
11 | return 0xFFFFFFFF; | ||
12 | } | ||
13 | char *end; | ||
14 | uint32_t res = (uint32_t)strtol(color + 1, &end, 16); | ||
15 | if (strlen(color) == 7) { | ||
16 | res = (res << 8) | 0xFF; | ||
17 | } | ||
18 | return res; | ||
19 | } | ||
20 | |||
21 | uint32_t parse_position(const char *position) { | ||
22 | if (strcmp("top", position) == 0) { | ||
23 | return DESKTOP_SHELL_PANEL_POSITION_TOP; | ||
24 | } else if (strcmp("bottom", position) == 0) { | ||
25 | return DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | ||
26 | } else if (strcmp("left", position) == 0) { | ||
27 | return DESKTOP_SHELL_PANEL_POSITION_LEFT; | ||
28 | } else if (strcmp("right", position) == 0) { | ||
29 | return DESKTOP_SHELL_PANEL_POSITION_RIGHT; | ||
30 | } else { | ||
31 | return DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | char *parse_font(const char *font) { | ||
36 | char *new_font = NULL; | ||
37 | if (strncmp("pango:", font, 6) == 0) { | ||
38 | new_font = strdup(font + 6); | ||
39 | } | ||
40 | |||
41 | return new_font; | ||
42 | } | ||
43 | |||
44 | struct swaybar_config *init_config() { | ||
45 | struct swaybar_config *config = calloc(1, sizeof(struct swaybar_config)); | ||
46 | config->status_command = NULL; | ||
47 | config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | ||
48 | config->font = NULL; | ||
49 | config->mode = NULL; | ||
50 | config->sep_symbol = NULL; | ||
51 | config->strip_workspace_numbers = false; | ||
52 | config->binding_mode_indicator = true; | ||
53 | config->workspace_buttons = true; | ||
54 | |||
55 | /* layout */ | ||
56 | config->margin = 3; | ||
57 | config->ws_horizontal_padding = 5; | ||
58 | config->ws_vertical_padding = 1.5; | ||
59 | config->ws_spacing = 1; | ||
60 | config->text_height = 30; | ||
61 | |||
62 | /* colors */ | ||
63 | config->colors.background = 0x000000FF; | ||
64 | config->colors.statusline = 0xFFFFFFFF; | ||
65 | config->colors.separator = 0x666666FF; | ||
66 | |||
67 | config->colors.focused_workspace.border = 0x4C7899FF; | ||
68 | config->colors.focused_workspace.background = 0x285577FF; | ||
69 | config->colors.focused_workspace.text = 0xFFFFFFFF; | ||
70 | |||
71 | config->colors.active_workspace.border = 0x333333FF; | ||
72 | config->colors.active_workspace.background = 0x5F676AFF; | ||
73 | config->colors.active_workspace.text = 0xFFFFFFFF; | ||
74 | |||
75 | config->colors.inactive_workspace.border = 0x333333FF; | ||
76 | config->colors.inactive_workspace.background = 0x222222FF; | ||
77 | config->colors.inactive_workspace.text = 0x888888FF; | ||
78 | |||
79 | config->colors.urgent_workspace.border = 0x2F343AFF; | ||
80 | config->colors.urgent_workspace.background = 0x900000FF; | ||
81 | config->colors.urgent_workspace.text = 0xFFFFFFFF; | ||
82 | |||
83 | config->colors.binding_mode.border = 0x2F343AFF; | ||
84 | config->colors.binding_mode.background = 0x900000FF; | ||
85 | config->colors.binding_mode.text = 0xFFFFFFFF; | ||
86 | |||
87 | return config; | ||
88 | } | ||
89 | |||
90 | void free_config(struct swaybar_config *config) { | ||
91 | free(config->status_command); | ||
92 | free(config->font); | ||
93 | free(config->mode); | ||
94 | free(config->sep_symbol); | ||
95 | free(config); | ||
96 | } | ||