add several internal blks; use conditional compilation for internal blks

This commit is contained in:
geommer 2016-03-26 15:41:24 +02:00
parent bd8aa7425c
commit ec105d0f59
3 changed files with 97 additions and 5 deletions

View file

@ -8,15 +8,23 @@
#include "yabar.h"
#define YA_INTERNAL
void ya_int_time(ya_block_t * blk);
void ya_int_uptime(ya_block_t * blk);
void ya_int_memory(ya_block_t * blk);
void ya_int_thermal(ya_block_t *blk);
void ya_int_brightness(ya_block_t *blk);
struct reserved_blk ya_reserved_blks[YA_INTERNAL_LEN] = {
{"YA_INT_TIME", ya_int_time},
{"YA_INT_UPTIME", ya_int_uptime}
{"YA_INT_UPTIME", ya_int_uptime},
{"YA_INT_THERMAL", ya_int_thermal},
{"YA_INT_BRIGHTNESS", ya_int_brightness}
//{"YA_INT_MEMORY", ya_int_memory}
};
//#ifdef YA_INTERNAL
#define YA_INTERNAL
#ifdef YA_INTERNAL
#include <time.h>
void ya_int_time(ya_block_t * blk) {
@ -50,4 +58,82 @@ void ya_int_uptime(ya_block_t *blk) {
}
}
//#endif //YA_INTERNAL
void ya_int_thermal(ya_block_t *blk) {
FILE *tfile;
int temp, wrntemp, crttemp;
uint32_t oldbg, oldfg;
uint32_t wrnbg, wrnfg; //warning colors
uint32_t crtbg, crtfg; //critical colors
if(blk->attr & BLKA_BGCOLOR)
oldbg = blk->bgcolor;
else
oldbg = blk->bar->bgcolor;
oldfg = blk->fgcolor;
char fpath[128];
snprintf(fpath, 128, "/sys/class/thermal/%s/temp", blk->internal->option[0]);
if((blk->internal->option[1]==NULL) ||
(sscanf(blk->internal->option[1], "%d %u %u", &crttemp, &crtfg, &crtbg)!=3)) {
crttemp = 70;
crtbg = 0xFFED303C;
crtfg = blk->fgcolor;
}
if((blk->internal->option[2]==NULL) ||
(sscanf(blk->internal->option[2], "%d %u %u", &wrntemp, &wrnfg, &wrnbg)!=3)) {
wrntemp = 58;
wrnbg = 0xFFF4A345;
wrnfg = blk->fgcolor;
}
tfile = fopen(fpath, "r");
if (tfile == NULL) {
//TODO handle and exit thread
}
fclose(tfile);
while (1) {
tfile = fopen(fpath, "r");
fscanf(tfile, "%d", &temp);
temp/=1000;
if(temp > crttemp) {
xcb_change_gc(ya.c, blk->gc, XCB_GC_FOREGROUND, (const uint32_t[]){crtbg});
blk->fgcolor = crtfg;
}
else if (temp > wrntemp) {
xcb_change_gc(ya.c, blk->gc, XCB_GC_FOREGROUND, (const uint32_t[]){wrnbg});
blk->fgcolor = wrnfg;
}
else {
xcb_change_gc(ya.c, blk->gc, XCB_GC_FOREGROUND, (const uint32_t[]){oldbg});
blk->fgcolor = oldfg;
}
snprintf(blk->buf, 4, "%d", temp);
ya_draw_pango_text(blk);
sleep(blk->sleep);
memset(blk->buf, '\0', 4);
fclose(tfile);
}
}
void ya_int_brightness(ya_block_t *blk) {
int bright;
FILE *tfile;
char fpath[128];
snprintf(fpath, 128, "/sys/class/backlight/%s/brightness", blk->internal->option[0]);
tfile = fopen(fpath, "r");
if (tfile == NULL) {
//TODO handle and exit thread
}
while(1) {
tfile = fopen(fpath, "r");
fscanf(tfile, "%d", &bright);
snprintf(blk->buf, 12, "%d", bright);
ya_draw_pango_text(blk);
sleep(blk->sleep);
memset(blk->buf, '\0', 12);
fclose(tfile);
}
}
#endif //YA_INTERNAL

View file

@ -329,7 +329,13 @@ static void ya_setup_block(config_setting_t * set) {
}
else {
#ifdef YA_INTERNAL
//check if internal found, otherwise set external
ya_check_blk_internal(blk, set, retstr);
#else
//just set it external
blk->attr |= BLKA_EXTERNAL;
#endif //YA_INTERNAL
if (blk->attr & BLKA_EXTERNAL) {
blk->cmd = strdup(retstr);
}

View file

@ -92,7 +92,7 @@ enum {
#define NOT_INHERIT_BLK(blk) (((blk)->attr & BLKA_INHERIT)==0)
#define CMONLEN 16
#define YA_INTERNAL_LEN 2
#define YA_INTERNAL_LEN 4
typedef struct ya_monitor ya_monitor_t;
typedef struct ya_bar ya_bar_t;