1 /**
2 * I3cstatus prints a configurable status bar for the i3 window manager
3 * Copyright (C) 2021 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 out->interval = 0;
29 out->lastrun = 0;
30 out->width = 12;
31 strcpy(out->color, "#eeeeee");
32 strcpy(out->label_color, "#eeeeee");
33 init_callback(out);
34 return out;
35 }
36
37
38 struct node* lladd(struct node* list, struct node* next) {
39 while(list->next)
40 list = list->next;
41 list->next = next;
42 return next;
43 }
44
45 void llfree(struct node* list) {
46 struct node* next = list;
47 while(next) {
48 next = list->next;
49 free(list);
50 }
51 }
52
53 void _load_node_key(struct node* n, char* key, char* val) {
54 if(strcmp(key, "color") == 0)
55 strcpy(n->color, val);
56 else if(strcmp(key, "label_color") == 0)
57 strcpy(n->label_color, val);
58 else if(strcmp(key, "label") == 0)
59 strcpy(n->label, val);
60 else if(strcmp(key, "text") == 0)
61 strcpy(n->text, val);
62 else if(strcmp(key, "display") == 0)
63 strcpy(n->display, val);
64 else if(strcmp(key, "interval") == 0)
65 n->interval = strtol(val, NULL, 10);
66 else if(strcmp(key, "width") == 0)
67 n->width = strtol(val, NULL, 10);
68 else
69 printf("ERROR: Unknown node key %s\n", key);
70 }
71
72 void node_print(struct node* n) {
73 printf("{ \"full_text\":\" %s\", \"color\": \"%s\", \"separator\":false },",
74 n->label,
75 n->label_color);
76 printf("{ \"full_text\":\"%s \", \"color\":\"%s\" }", n->text, n->color);
77 if(n->next)
78 printf(",");
79 printf("\n");
80 fflush(stdout);
81 }
|