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