summaryrefslogtreecommitdiff
path: root/src/config_time.c
blob: 39c8427bd6a9a294ade8caee786a8f12d2279dde (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_time.h"
   19 
   20 void config_time_init(struct node* n) {
   21   n->data = malloc(sizeof(struct config_time));
   22   n->type = CTYPE_TIME;
   23   n->loadfunc = &config_time_load;
   24   n->loadkey = &load_time_key;
   25 
   26   strcpy(((struct config_time*) n->data)->fmt, "%T");
   27 }
   28 
   29 
   30 void load_time_key(struct node* n, char* key, char* val) {
   31   if(strcmp(key, "tz") == 0)
   32     strcpy(((struct config_time*) n->data)->tz, val);
   33   else if(strcmp(key, "fmt") == 0)
   34     strcpy(((struct config_time*) n->data)->fmt, val);
   35   else
   36     printf("ERROR: Unknown time key %s\n", key);
   37 }
   38 
   39 
   40 int config_time_load(struct node* n) {
   41   time_t timep;
   42   struct tm* info;
   43 
   44   setenv("TZ", ((struct config_time*)n->data)->tz, 1);
   45   time(&timep);
   46   info = localtime(&timep);
   47 
   48   strftime(n->text, 256, ((struct config_time*)n->data)->fmt, info);
   49 
   50   strcpy(n->color, C_DGREY);
   51   strcpy(n->label_color, C_LGREY);
   52 
   53   return 0;
   54 }

Generated by cgit