dotfiles

personal configuration files and scripts
git clone https://tongong.net/git/dotfiles.git
Log | Files | Refs | README

commit 89f0b70ddf7baf7c5079ccbeb5f313030937665d
parent 333e9e02bf76b7371c7a1d2fc4812e54785ac88b
Author: tongong <tongong@gmx.net>
Date:   Sun, 11 Jul 2021 22:41:54 +0200

added battery block [dsblocks]

Diffstat:
Asuckless/dsblocks/blocks/battery.c | 46++++++++++++++++++++++++++++++++++++++++++++++
Asuckless/dsblocks/blocks/battery.h | 2++
Msuckless/dsblocks/config.h | 10++++++----
3 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/suckless/dsblocks/blocks/battery.c b/suckless/dsblocks/blocks/battery.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <string.h> + +#include "../util.h" +#include "battery.h" + +#define ICON " " +#define ICON_CHARGE " " +#define ICON_WARNING " " + +#define CAPACITYFILE "/sys/class/power_supply/BAT0/capacity" +#define STATUSFILE "/sys/class/power_supply/BAT0/status" +#define MAX_CHARS_PER_LINE 20 + +size_t batteryu(char *str, int sigval) +{ + int capacity; + _Bool charging; + + char tmpstring[MAX_CHARS_PER_LINE]; + + FILE *statfile; + + statfile = fopen(CAPACITYFILE, "r"); + fgets(tmpstring, MAX_CHARS_PER_LINE, statfile); + fclose(statfile); + sscanf(tmpstring, "%i", &capacity); + + statfile = fopen(STATUSFILE, "r"); + fgets(tmpstring, MAX_CHARS_PER_LINE, statfile); + fclose(statfile); + charging = !strcmp(tmpstring, "Charging\n"); + + if (charging) { + return SPRINTF(str, ICON_CHARGE "%03d%%", capacity); + } else { + char *warn = ICON_WARNING "LOW BATTERY "; + if (capacity > 10) warn = ""; + return SPRINTF(str, "%s" ICON "%03d%%", warn, capacity); + } +} + +void batteryc(int button) +{ + cspawn((char *[]){ "sh", "-c", "notify-send \"$(acpi -b)\"", NULL}); +} diff --git a/suckless/dsblocks/blocks/battery.h b/suckless/dsblocks/blocks/battery.h @@ -0,0 +1,2 @@ +size_t batteryu(char *str, int sigval); +void batteryc(int button); diff --git a/suckless/dsblocks/config.h b/suckless/dsblocks/config.h @@ -1,10 +1,11 @@ +#include "blocks/battery.h" +#include "blocks/calendar.h" +#include "blocks/cpu.h" +#include "blocks/mem.h" #include "blocks/pkgs.h" #include "blocks/temp.h" -#include "blocks/mem.h" -#include "blocks/cpu.h" -#include "blocks/volume.h" -#include "blocks/calendar.h" #include "blocks/time.h" +#include "blocks/volume.h" /* DELIMITERENDCHAR must be less than 32. * At max, DELIMITERENDCHAR - 1 number of clickable blocks are allowed. @@ -48,6 +49,7 @@ static Block blocks[] = { { memu, memc, 2, 4}, { cpuu, cpuc, 2, 3}, { volumeu, volumec, 600, 5}, + { batteryu, batteryc, 2, 8}, { calendaru, calendarc, 600, 2}, { timeu, timec, 1, 1},