summaryrefslogtreecommitdiff
path: root/src/config_swap.c
blob: e53b2e9b00b57b7aff03bf0d8488384442b7e581 (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 "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 
   37   // Return early if swap is not enabled
   38   if(si.totalswap == 0) {
   39     strcpy(n->color, C_YELLOW);
   40     strcpy(n->text, "none");
   41     return 0;
   42   }
   43 
   44   percent = (si.totalswap - si.freeswap) * 100 / si.totalswap;
   45 
   46   if(percent < 20) {
   47     strcpy(n->color, C_GREEN);
   48   } else if(percent < 40) {
   49     strcpy(n->color, C_YELLOW);
   50   } else if(percent < 60) {
   51     strcpy(n->color, C_ORANGE);
   52   } else {
   53     strcpy(n->color, C_RED);
   54   }
   55   strcpy(n->label_color, C_LGREY);
   56 
   57   if(strcmp(n->display, "bar") == 0) {
   58     print_bar(n->width,
   59         (double)(si.totalswap - si.freeswap) / si.totalswap,
   60         n->text);
   61   } else {
   62     sprintf(n->text, "%02d%%", percent);
   63   }
   64 
   65   return 0;
   66 }

Generated by cgit