Fix battery drain sources across suspend, CPUfreq, radios, and daemons
This commit is contained in:
1 parent
4b36aa0726
commit
7f3b3c2c0c
24 files changed
+487
-64
No files matched your search
@@ -20,6 +20,9 @@ typedef struct {
|
||||
char password[128];
|
||||
char bat_text[96];
|
||||
char err_msg[96];
|
||||
int last_min;
|
||||
int last_yday;
|
||||
int timer_ms;
|
||||
bool grabbed;
|
||||
bool checking;
|
||||
} lock_state_t;
|
||||
@@ -99,9 +102,22 @@ static void on_timer(gemui_app_t *app, void *ud) {
|
||||
lock_state_t *st = ud;
|
||||
if (!st->grabbed) {
|
||||
st->grabbed = gemui_grab_input(app);
|
||||
if (st->grabbed && st->timer_ms != 15000) {
|
||||
st->timer_ms = 15000;
|
||||
gemui_set_timer_ms(app, 15000, on_timer, st);
|
||||
}
|
||||
}
|
||||
char prev_bat[96];
|
||||
snprintf(prev_bat, sizeof(prev_bat), "%s", st->bat_text);
|
||||
refresh_battery(st);
|
||||
gemui_request_redraw(app);
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
if (tm.tm_min != st->last_min || tm.tm_yday != st->last_yday ||
|
||||
strcmp(prev_bat, st->bat_text) != 0) {
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
@@ -113,6 +129,8 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
st->last_min = tm.tm_min;
|
||||
st->last_yday = tm.tm_yday;
|
||||
char clock_str[32], date_str[64];
|
||||
strftime(clock_str, sizeof(clock_str), "%H:%M", &tm);
|
||||
strftime(date_str, sizeof(date_str), "%A, %d %B %Y", &tm);
|
||||
@@ -190,6 +208,8 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
|
||||
int main(void) {
|
||||
lock_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.last_min = -1;
|
||||
st.last_yday = -1;
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
snprintf(st.user, sizeof(st.user), "%s", (pw && pw->pw_name) ? pw->pw_name : "user");
|
||||
refresh_battery(&st);
|
||||
@@ -211,7 +231,8 @@ int main(void) {
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
gemui_set_timer_ms(st.app, 1000, on_timer, &st);
|
||||
st.timer_ms = st.grabbed ? 15000 : 250;
|
||||
gemui_set_timer_ms(st.app, st.timer_ms, on_timer, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_ungrab_input(st.app);
|
||||
gemui_destroy(st.app);
|
||||
|
||||
Reference in new issue
Block a user