1 /**
2 * I3cstatus prints a configurable status bar for the i3 window manager
3 * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "config_node.h"
19
20
21 struct node* node_new(void (*init_callback)(struct node*)) {
22 struct node* out = malloc(sizeof(struct node));
23 out->data = NULL;
24 out->next = NULL;
25 out->display[0] = '\0';
26 out->text[0] = '\0';
27 out->label[0] = '\0';
28 strcpy(out->color, "#eeeeee");
29 strcpy(out->label_color, "#eeeeee");
30 init_callback(out);
31 return out;
32 }
33
34
35 struct node* lladd(struct node* list, struct node* next) {
36 while(list->next)
37 list = list->next;
38 list->next = next;
39 return next;
40 }
41
42 void llfree(struct node* list) {
43 struct node* next = list;
44 while(next) {
45 next = list->next;
46 free(list);
47 }
48 }
49
50 void _load_node_key(struct node* n, char* key, char* val) {
51 if(strcmp(key, "color") == 0)
52 strcpy(n->color, val);
53 else if(strcmp(key, "label_color") == 0)
54 strcpy(n->label_color, val);
55 else if(strcmp(key, "label") == 0)
56 strcpy(n->label, val);
57 else if(strcmp(key, "text") == 0)
58 strcpy(n->text, val);
59 else if(strcmp(key, "display") == 0)
60 strcpy(n->display, val);
61 else
62 printf("ERROR: Unknown node key %s\n", key);
63 }
64
65 void node_print(struct node* n) {
66 printf("{ \"full_text\":\" %s\", \"color\": \"%s\", \"separator\":false },",
67 n->label,
68 n->label_color);
69 printf("{ \"full_text\":\"%s \", \"color\":\"%s\" }", n->text, n->color);
70 if(n->next)
71 printf(",");
72 printf("\n");
73 fflush(stdout);
74 }
|