summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2021-05-30 14:56:06 -0600
committerAaron Ball <nullspoon@oper.io>2021-05-30 14:56:06 -0600
commit0e49a93f9b8935d5194dd915dc9be90ee232afe8 (patch)
treef94e908acb3799591af24d789625ad9304797347
parentecf1d2ae94b46b8c0cffb3b1e8a0295e705c2a5e (diff)
downloadi3cstat-0e49a93f9b8935d5194dd915dc9be90ee232afe8.tar.gz
i3cstat-0e49a93f9b8935d5194dd915dc9be90ee232afe8.tar.xz
Introduce swap support
This adds a new config section titled "swap". It configures the same way as the memory config entity.
-rw-r--r--Makefile5
-rw-r--r--src/config.c3
-rw-r--r--src/config.h1
-rw-r--r--src/config_swap.c62
-rw-r--r--src/config_swap.h30
5 files changed, 100 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 341e1a0..38885f4 100644
--- a/Makefile
+++ b/Makefile
@@ -33,13 +33,16 @@ config_fs: common config_node
config_mem: common config_node
cc $(CCOPTS) src/config_mem.c -c -o obj/config_mem.o
+config_swap: common config_node
+ cc $(CCOPTS) src/config_swap.c -c -o obj/config_swap.o
+
config_net: common config_node
cc $(CCOPTS) src/config_net.c -c -o obj/config_net.o
config_shell: common config_node
cc $(CCOPTS) src/config_shell.c -c -o obj/config_shell.o
-config: config_node config_bat config_fs config_net config_date config_time config_mem config_cpu config_shell
+config: config_node config_bat config_fs config_net config_date config_time config_mem config_swap config_cpu config_shell
cc $(CCOPTS) src/config.c -c -o obj/config.o
install:
diff --git a/src/config.c b/src/config.c
index 07bbc2f..aa4af37 100644
--- a/src/config.c
+++ b/src/config.c
@@ -89,6 +89,9 @@ struct node* config_load(char* path) {
} else if(strcmp(section, "mem") == 0) {
cur = node_new(&config_mem_init);
+ } else if(strcmp(section, "swap") == 0) {
+ cur = node_new(&config_swap_init);
+
} else if(strcmp(section, "cpu") == 0) {
cur = node_new(&config_cpu_init);
diff --git a/src/config.h b/src/config.h
index de0e294..aa8b630 100644
--- a/src/config.h
+++ b/src/config.h
@@ -21,6 +21,7 @@
#include "common.h"
#include "config_node.h"
#include "config_mem.h"
+#include "config_swap.h"
#include "config_cpu.h"
#include "config_net.h"
#include "config_date.h"
diff --git a/src/config_swap.c b/src/config_swap.c
new file mode 100644
index 0000000..5a8ff90
--- /dev/null
+++ b/src/config_swap.c
@@ -0,0 +1,62 @@
+/**
+ * I3cstatus prints a configurable status bar for the i3 window manager
+ * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "config_swap.h"
+
+void config_swap_init(struct node* n) {
+ n->data = NULL;
+ n->type = CTYPE_SWAP;
+ n->loadfunc = &config_swap_load;
+ n->loadkey = &load_swap_key;
+}
+
+void load_swap_key(struct node* n, char* key, char* val) {
+}
+
+int config_swap_load(struct node* n) {
+ long total;
+ long free;
+ int percent;
+
+ FILE* fd = fopen("/proc/meminfo", "r");
+ fscanf(fd, "SwapTotal: %ld kB ", &total);
+ fscanf(fd, "SwapFree: %ld kB ", &free);
+ fclose(fd);
+
+ percent = (total - free) * 100 / total;
+
+ if(percent < 20) {
+ strcpy(n->color, C_GREEN);
+ } else if(percent < 40) {
+ strcpy(n->color, C_YELLOW);
+ } else if(percent < 60) {
+ strcpy(n->color, C_ORANGE);
+ } else {
+ strcpy(n->color, C_RED);
+ }
+ strcpy(n->label_color, C_LGREY);
+
+ if(strcmp(n->display, "bar") == 0) {
+ print_bar(12, (double)(total - free) / total, n->text);
+ } else {
+ sprintf(n->text, "%02d%%", percent);
+ }
+
+ return 0;
+}
+
+
diff --git a/src/config_swap.h b/src/config_swap.h
new file mode 100644
index 0000000..d9fa024
--- /dev/null
+++ b/src/config_swap.h
@@ -0,0 +1,30 @@
+/**
+ * I3cstatus prints a configurable status bar for the i3 window manager
+ * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef CONFIG_SWAP
+#define CONFIG_SWAP
+
+#include "common.h"
+#include "config_node.h"
+
+#define CTYPE_SWAP 65
+
+void config_swap_init(struct node*);
+int config_swap_load(struct node*);
+void load_swap_key(struct node*, char*, char*);
+
+#endif

Generated by cgit