summaryrefslogtreecommitdiff
path: root/src/config_swap.c
blob: 090117f452a8ccd3ccf49a84b25b4798b28d20be (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   struct sysinfo si;
   33   int percent;
   34 
   35   sysinfo(&si);
   36   percent = (si.totalswap - si.freeswap) * 100 / si.totalswap;
   37 
   38   if(percent < 20) {
   39     strcpy(n->color, C_GREEN);
   40   } else if(percent < 40) {
   41     strcpy(n->color, C_YELLOW);
   42   } else if(percent < 60) {
   43     strcpy(n->color, C_ORANGE);
   44   } else {
   45     strcpy(n->color, C_RED);
   46   }
   47   strcpy(n->label_color, C_LGREY);
   48 
   49   if(strcmp(n->display, "bar") == 0) {
   50     print_bar(n->width,
   51         (double)(si.totalswap - si.freeswap) / si.totalswap,
   52         n->text);
   53   } else {
   54     sprintf(n->text, "%02d%%", percent);
   55   }
   56 
   57   return 0;
   58 }

Generated by cgit