blob: ffab51f02e492dbe65b36b6b859c629199f9879a (
plain)
1 /**
2 * I3cstat prints a configurable status bar for the i3 window manager
3 * Copyright (C) 2022 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 <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <time.h>
23
24 #include <locale.h>
25
26 #include "common.h"
27 #include "config.h"
28
29 #define xstr(s) str(s)
30 #define str(s) #s
31
32
33 int main(int argc, char* argv[]) {
34 char confpath[256];
35 int sleeptime = 500 * 1000; // 500 ms
36 struct node* list = NULL;
37 struct node* cur = NULL;
38
39 // Required for unicode symbols to work
40 setlocale(LC_ALL, "");
41
42 // Build the config path
43 sprintf(confpath, "%s/.config/i3cstat.conf", getenv("HOME"));
44
45 list = config_load(confpath);
46 if(!list) {
47 printf("Error: Could load config file from %s\n", confpath);
48 return 2;
49 }
50 cur = list;
51
52 printf("{ \"version\": 1 }\n");
53 printf("[\n[],\n");
54
55 while(1) {
56 printf("[\n");
57 while(cur) {
58 if(time(NULL) - cur->lastrun >= cur->interval) {
59 cur->loadfunc(cur);
60 cur->lastrun = time(NULL);
61 }
62 node_print(cur);
63 cur = cur->next;
64 }
65 cur = list;
66 printf("],\n");
67 usleep(sleeptime);
68 }
69 config_free(cur);
70
71 return 0;
72 }
|