diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-01-24 09:46:28 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-01-24 09:46:28 -0500 |
commit | 4b48a8399a33f3bb5f5d55f87213bb4692a5f1f9 (patch) | |
tree | 1d820cd07f6ba693a89d43caf01b3c8b01390609 /swaybar/config.c | |
parent | numlen(0) == 1 (diff) | |
parent | swaybar: cleanup CmakeLists.txt (diff) | |
download | sway-4b48a8399a33f3bb5f5d55f87213bb4692a5f1f9.tar.gz sway-4b48a8399a33f3bb5f5d55f87213bb4692a5f1f9.tar.zst sway-4b48a8399a33f3bb5f5d55f87213bb4692a5f1f9.zip |
Merge pull request #467 from mikkeloscar/swaybar-refactor
[WIP] Swaybar refactor
Diffstat (limited to 'swaybar/config.c')
-rw-r--r-- | swaybar/config.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/swaybar/config.c b/swaybar/config.c new file mode 100644 index 00000000..28b609e6 --- /dev/null +++ b/swaybar/config.c | |||
@@ -0,0 +1,92 @@ | |||
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 config *init_config() { | ||
45 | struct config *config = calloc(1, sizeof(struct config)); | ||
46 | config->status_command = NULL; | ||
47 | config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | ||
48 | config->font = strdup("monospace 10"); | ||
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 | /* height */ | ||
56 | config->height = 0; | ||
57 | |||
58 | /* colors */ | ||
59 | config->colors.background = 0x000000FF; | ||
60 | config->colors.statusline = 0xFFFFFFFF; | ||
61 | config->colors.separator = 0x666666FF; | ||
62 | |||
63 | config->colors.focused_workspace.border = 0x4C7899FF; | ||
64 | config->colors.focused_workspace.background = 0x285577FF; | ||
65 | config->colors.focused_workspace.text = 0xFFFFFFFF; | ||
66 | |||
67 | config->colors.active_workspace.border = 0x333333FF; | ||
68 | config->colors.active_workspace.background = 0x5F676AFF; | ||
69 | config->colors.active_workspace.text = 0xFFFFFFFF; | ||
70 | |||
71 | config->colors.inactive_workspace.border = 0x333333FF; | ||
72 | config->colors.inactive_workspace.background = 0x222222FF; | ||
73 | config->colors.inactive_workspace.text = 0x888888FF; | ||
74 | |||
75 | config->colors.urgent_workspace.border = 0x2F343AFF; | ||
76 | config->colors.urgent_workspace.background = 0x900000FF; | ||
77 | config->colors.urgent_workspace.text = 0xFFFFFFFF; | ||
78 | |||
79 | config->colors.binding_mode.border = 0x2F343AFF; | ||
80 | config->colors.binding_mode.background = 0x900000FF; | ||
81 | config->colors.binding_mode.text = 0xFFFFFFFF; | ||
82 | |||
83 | return config; | ||
84 | } | ||
85 | |||
86 | void free_config(struct config *config) { | ||
87 | free(config->status_command); | ||
88 | free(config->font); | ||
89 | free(config->mode); | ||
90 | free(config->sep_symbol); | ||
91 | free(config); | ||
92 | } | ||