aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag/types.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-28 09:34:25 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-08-01 22:47:54 -0400
commit8463a2896a932cd99f3dc93608b03cb4aba93293 (patch)
treeb8c4ba994cf4d9ca7510d0f80a1864cce144092a /swaynag/types.c
parentAddress first round review for swaynag (diff)
downloadsway-8463a2896a932cd99f3dc93608b03cb4aba93293.tar.gz
sway-8463a2896a932cd99f3dc93608b03cb4aba93293.tar.zst
sway-8463a2896a932cd99f3dc93608b03cb4aba93293.zip
swaynag: implement config file support
Diffstat (limited to 'swaynag/types.c')
-rw-r--r--swaynag/types.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/swaynag/types.c b/swaynag/types.c
new file mode 100644
index 00000000..8dd99d2a
--- /dev/null
+++ b/swaynag/types.c
@@ -0,0 +1,116 @@
1#define _XOPEN_SOURCE 500
2#include <getopt.h>
3#include <stdbool.h>
4#include <stdlib.h>
5#include <stdint.h>
6#include <string.h>
7#include <strings.h>
8#include "list.h"
9#include "swaynag/types.h"
10#include "util.h"
11
12void nagbar_types_add_default(list_t *types) {
13 struct sway_nagbar_type *type_error;
14 type_error = calloc(1, sizeof(struct sway_nagbar_type));
15 type_error->name = strdup("error");
16 type_error->button_background = 0x680A0AFF;
17 type_error->background = 0x900000FF;
18 type_error->text = 0xFFFFFFFF;
19 type_error->border = 0xD92424FF;
20 type_error->border_bottom = 0x470909FF;
21 list_add(types, type_error);
22
23 struct sway_nagbar_type *type_warning;
24 type_warning = calloc(1, sizeof(struct sway_nagbar_type));
25 type_warning->name = strdup("warning");
26 type_warning->button_background = 0xFFC100FF;
27 type_warning->background = 0xFFA800FF;
28 type_warning->text = 0x000000FF;
29 type_warning->border = 0xAB7100FF;
30 type_warning->border_bottom = 0xAB7100FF;
31 list_add(types, type_warning);
32}
33
34struct sway_nagbar_type *nagbar_type_get(list_t *types, char *name) {
35 for (int i = 0; i < types->length; i++) {
36 struct sway_nagbar_type *type = types->items[i];
37 if (strcasecmp(type->name, name) == 0) {
38 return type;
39 }
40 }
41 return NULL;
42}
43
44struct sway_nagbar_type *nagbar_type_clone(struct sway_nagbar_type *type) {
45 struct sway_nagbar_type *clone;
46 clone = calloc(1, sizeof(struct sway_nagbar_type));
47 clone->name = strdup(type->name);
48 clone->button_background = type->button_background;
49 clone->background = type->background;
50 clone->text = type->text;
51 clone->border = type->border;
52 clone->border_bottom = type->border_bottom;
53 return clone;
54}
55
56void nagbar_type_free(struct sway_nagbar_type *type) {
57 free(type->name);
58 free(type);
59}
60
61void nagbar_types_free(list_t *types) {
62 while (types->length) {
63 struct sway_nagbar_type *type = types->items[0];
64 nagbar_type_free(type);
65 list_del(types, 0);
66 }
67 list_free(types);
68}
69
70int nagbar_parse_type(int argc, char **argv, struct sway_nagbar_type *type) {
71 enum color_option {
72 COLOR_BACKGROUND,
73 COLOR_BORDER,
74 COLOR_BORDER_BOTTOM,
75 COLOR_BUTTON,
76 COLOR_TEXT,
77 };
78
79 static struct option opts[] = {
80 {"background", required_argument, NULL, COLOR_BACKGROUND},
81 {"border", required_argument, NULL, COLOR_BORDER},
82 {"border-bottom", required_argument, NULL, COLOR_BORDER_BOTTOM},
83 {"button-background", required_argument, NULL, COLOR_BUTTON},
84 {"text", required_argument, NULL, COLOR_TEXT},
85 {0, 0, 0, 0}
86 };
87
88 optind = 1;
89 while (1) {
90 int c = getopt_long(argc, argv, "", opts, NULL);
91 if (c == -1) {
92 break;
93 }
94 switch (c) {
95 case COLOR_BACKGROUND:
96 type->background = parse_color(optarg);
97 break;
98 case COLOR_BORDER:
99 type->border = parse_color(optarg);
100 break;
101 case COLOR_BORDER_BOTTOM:
102 type->border_bottom = parse_color(optarg);
103 break;
104 case COLOR_BUTTON:
105 type->button_background = parse_color(optarg);
106 break;
107 case COLOR_TEXT:
108 type->text = parse_color(optarg);
109 break;
110 default:
111 break;
112 }
113 }
114 return 0;
115}
116