ce4638ed
Miguel Barão
Initial commit
|
1
2
|
#ifndef __FreeBSD__
#error Only works on FreeBSD
|
140b270e
Miguel Barão
add support for l...
|
3
|
#endif
|
ce4638ed
Miguel Barão
Initial commit
|
4
|
|
407581b9
Miguel Barão
use a different s...
|
5
6
7
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
|
ce4638ed
Miguel Barão
Initial commit
|
8
|
#include <sys/sysctl.h>
|
fbcc53ca
Miguel Barão
refactor
|
9
10
|
const char *bat_icons[] = {
|
ce4638ed
Miguel Barão
Initial commit
|
11
|
"\uf58d", /* 0% */
|
407581b9
Miguel Barão
use a different s...
|
12
|
"\uf579",
|
cb150c6a
Miguel Barão
fix icons
|
13
|
"\uf57a",
|
407581b9
Miguel Barão
use a different s...
|
14
15
16
|
"\uf57b",
"\uf57c",
"\uf57d", /* 50% */
|
cb150c6a
Miguel Barão
fix icons
|
17
|
"\uf57e",
|
ae8c717f
Miguel Barão
fix icons on linux
|
18
|
"\uf57f",
|
cb150c6a
Miguel Barão
fix icons
|
19
|
"\uf580",
|
407581b9
Miguel Barão
use a different s...
|
20
|
"\uf581",
|
140b270e
Miguel Barão
add support for l...
|
21
22
23
24
25
|
"\uf578", /* 100% */
};
int main() {
int life, state;
|
6e56c017
Miguel Barão
fix freebsd version
|
26
|
size_t len = sizeof(int);
|
140b270e
Miguel Barão
add support for l...
|
27
28
|
if (sysctlbyname("hw.acpi.battery.state", &state, &len, NULL, 0) ||
|
cb150c6a
Miguel Barão
fix icons
|
29
|
sysctlbyname("hw.acpi.battery.life", &life, &len, NULL, 0)) {
|
fbcc53ca
Miguel Barão
refactor
|
30
|
puts("(no battery)");
|
140b270e
Miguel Barão
add support for l...
|
31
|
exit(EXIT_FAILURE);
|
fbcc53ca
Miguel Barão
refactor
|
32
|
}
|
140b270e
Miguel Barão
add support for l...
|
33
|
|
fbcc53ca
Miguel Barão
refactor
|
34
35
36
|
if (life > 100)
life = 100;
else if (life < 0)
|
140b270e
Miguel Barão
add support for l...
|
37
|
life = 0;
|
6e56c017
Miguel Barão
fix freebsd version
|
38
|
|
140b270e
Miguel Barão
add support for l...
|
39
40
41
|
switch (state) {
case 0: /* fully charged */
printf("\uf583 Full");
|
6e56c017
Miguel Barão
fix freebsd version
|
42
|
break;
|
140b270e
Miguel Barão
add support for l...
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
case 1: /* discharging */
printf("%s %d%%\n", bat_icons[life / 10], life);
break;
case 2: /* charging */
printf("\uf583 %d%%\n", life);
break;
case 7: /* disconnected */
printf("\uf492");
break;
default: /* unknown code */
printf("\uf590");
}
return EXIT_SUCCESS;
}
|
7ad151d0
Miguel Barão
add UNKNOWN to li...
|
|
|
fbcc53ca
Miguel Barão
refactor
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
6e56c017
Miguel Barão
fix freebsd version
|
|
|
ce4638ed
Miguel Barão
Initial commit
|
|
|
6e56c017
Miguel Barão
fix freebsd version
|
|
|
ce4638ed
Miguel Barão
Initial commit
|
|
|
6e56c017
Miguel Barão
fix freebsd version
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
6e56c017
Miguel Barão
fix freebsd version
|
|
|
fbcc53ca
Miguel Barão
refactor
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
fbcc53ca
Miguel Barão
refactor
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
fbcc53ca
Miguel Barão
refactor
|
|
|
6e56c017
Miguel Barão
fix freebsd version
|
|
|
fbcc53ca
Miguel Barão
refactor
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
fbcc53ca
Miguel Barão
refactor
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
c53116a8
Miguel Barão
fix charging icon...
|
|
|
8e1ef252
Miguel Barão
update to light r...
|
|
|
c53116a8
Miguel Barão
fix charging icon...
|
|
|
fbcc53ca
Miguel Barão
refactor
|
|
|
6e56c017
Miguel Barão
fix freebsd version
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
cb150c6a
Miguel Barão
fix icons
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
cb150c6a
Miguel Barão
fix icons
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
cb150c6a
Miguel Barão
fix icons
|
|
|
140b270e
Miguel Barão
add support for l...
|
|
|
ce4638ed
Miguel Barão
Initial commit
|
|
|
7887053e
Miguel Barão
Unknown and plugg...
|
|
|
ce4638ed
Miguel Barão
Initial commit
|
|
|