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_swap.h"
19
20 void config_swap_init(struct node* n) {
21 n->data = NULL;
22 n->type = CTYPE_SWAP;
23 n->loadfunc = &config_swap_load;
24 n->loadkey = &load_swap_key;
25 }
26
27 void load_swap_key(struct node* n, char* key, char* val) {
28 }
29
30 int config_swap_load(struct node* n) {
31 long total;
32 long free;
33 int percent;
34
35 FILE* fd = fopen("/proc/meminfo", "r");
36 fscanf(fd, "SwapTotal: %ld kB ", &total);
37 fscanf(fd, "SwapFree: %ld kB ", &free);
38 fclose(fd);
39
40 percent = (total - free) * 100 / total;
41
42 if(percent < 20) {
43 strcpy(n->color, C_GREEN);
44 } else if(percent < 40) {
45 strcpy(n->color, C_YELLOW);
46 } else if(percent < 60) {
47 strcpy(n->color, C_ORANGE);
48 } else {
49 strcpy(n->color, C_RED);
50 }
51 strcpy(n->label_color, C_LGREY);
52
53 if(strcmp(n->display, "bar") == 0) {
54 print_bar(12, (double)(total - free) / total, n->text);
55 } else {
56 sprintf(n->text, "%02d%%", percent);
57 }
58
59 return 0;
60 }
|