summaryrefslogtreecommitdiff
path: root/src/config_swap.c
blob: c8469d583bb32f3cb32cec3dd3e8efe900962f24 (plain)
    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_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   n->width = 12;
   26 }
   27 
   28 void load_swap_key(struct node* n, char* key, char* val) {
   29 }
   30 
   31 int config_swap_load(struct node* n) {
   32   long total;
   33   long free;
   34   int percent;
   35 
   36   FILE* fd = fopen("/proc/meminfo", "r");
   37   fscanf(fd, "SwapTotal: %ld kB ", &total);
   38   fscanf(fd, "SwapFree: %ld kB ", &free);
   39   fclose(fd);
   40 
   41   percent = (total - free) * 100 / total;
   42 
   43   if(percent < 20) {
   44     strcpy(n->color, C_GREEN);
   45   } else if(percent < 40) {
   46     strcpy(n->color, C_YELLOW);
   47   } else if(percent < 60) {
   48     strcpy(n->color, C_ORANGE);
   49   } else {
   50     strcpy(n->color, C_RED);
   51   }
   52   strcpy(n->label_color, C_LGREY);
   53 
   54   if(strcmp(n->display, "bar") == 0) {
   55     print_bar(n->width, (double)(total - free) / total, n->text);
   56   } else {
   57     sprintf(n->text, "%02d%%", percent);
   58   }
   59 
   60   return 0;
   61 }

Generated by cgit