From 57103f5e4acfda85443fd4eef5833acb506aca57 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Tue, 19 Oct 2021 21:57:01 +0200 Subject: [PATCH] Allow UPower to run on pinephone. Refs #233. Signed-off-by: Federico Di Pierro --- TODO.md | 14 ++++++++++---- src/modules/backlight.c | 10 +++++++--- src/modules/upower.c | 23 +++++++++++++---------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/TODO.md b/TODO.md index 510072c..546adf0 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,18 @@ ## 4.8 -### Backlight -- [ ] Port to clightd.Backlight2 API -- [ ] Drop screen_path bl conf -- [ ] Drop is_smooth option (no need, just specify a step/wait > 0) +### Pinephone + +- [x] Allow upower module even if LidIsPresent is false to properly support pinephone ## 4.x + +### Generic + - [ ] Port to libmodule 6.0.0 (?) - [ ] Add a Dump dbus method (and a DUMP_REQ request) to allow any module to dump their state (module_dump()) to a txt file +### Backlight +- [ ] Port to clightd.Backlight2 API +- [ ] Drop screen_path bl conf +- [ ] Drop is_smooth option (no need, just specify a step/wait > 0) diff --git a/src/modules/backlight.c b/src/modules/backlight.c index 465e4f7..13856a4 100644 --- a/src/modules/backlight.c +++ b/src/modules/backlight.c @@ -283,7 +283,7 @@ static void receive(const msg_t *const msg, UNUSED const void* userdata) { } case SYSTEM_UPD: if (msg->ps_msg->type == LOOP_STOPPED && restore_m && conf.bl_conf.restore) { - set_each_brightness(restore_m, 0, false, 0, 0); + set_each_brightness(restore_m, -1.0f, false, 0, 0); restore_m = NULL; } break; @@ -354,7 +354,7 @@ static void receive_paused(const msg_t *const msg, UNUSED const void* userdata) } case SYSTEM_UPD: if (msg->ps_msg->type == LOOP_STOPPED && restore_m && conf.bl_conf.restore) { - set_each_brightness(restore_m, 0, false, 0, 0); + set_each_brightness(restore_m, -1.0f, false, 0, 0); restore_m = NULL; } break; @@ -489,7 +489,7 @@ static int get_and_set_each_brightness(const double pct, const bool is_smooth, c } static void set_each_brightness(sd_bus_message *m, double pct, const bool is_smooth, const double step, const int timeout) { - const bool restoring = pct == 0; + const bool restoring = pct == -1.0f; sensor_conf_t *sens_conf = &conf.sens_conf; enum ac_states st = state.ac_state; @@ -509,6 +509,10 @@ static void set_each_brightness(sd_bus_message *m, double pct, const bool is_smo /* Set backlight on monitor id */ SYSBUS_ARG_REPLY(args, parse_bus_reply, &ok, CLIGHTD_SERVICE, "/org/clightd/clightd/Backlight", "org.clightd.clightd.Backlight", "Set"); curve_t *c = map_get(sens_conf->specific_curves, mon_id); + /* + * Only if a specific curve has been found and + * we are not restoring a previously saved backlight level + */ if (c && !restoring) { /* Use monitor specific adjustment, properly scaling bl pct */ const double real_pct = get_value_from_curve(pct, &c[st]); diff --git a/src/modules/upower.c b/src/modules/upower.c index 8b505f5..f9f8b1e 100644 --- a/src/modules/upower.c +++ b/src/modules/upower.c @@ -1,5 +1,6 @@ #include "bus.h" +static int parse_bus_reply(sd_bus_message *reply, const char *member, void *userdata); static int upower_check(void); static int upower_init(void); static int on_upower_change(sd_bus_message *m, void *userdata, sd_bus_error *ret_error); @@ -84,17 +85,19 @@ static void destroy(void) { } } +static int parse_bus_reply(sd_bus_message *reply, const char *member, void *userdata) { + int r = -EINVAL; + if (!strcmp(member, "Ping")) { + r = 0; + } + return r; +} + static int upower_check(void) { - bool is_laptop = false; - SYSBUS_ARG(lid_pres_args, "org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "LidIsPresent"); - int r = get_property(&lid_pres_args, "b", &is_laptop); - if (!r) { - if (is_laptop) { - on_upower_change(NULL, NULL, NULL); - } else { - INFO("Not a laptop device. Killing UPower module.\n"); - r = -1; - } + SYSBUS_ARG_REPLY(args, parse_bus_reply, NULL, "org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Peer", "Ping"); + int r = call(&args, NULL); + if (r >= 0) { + on_upower_change(NULL, NULL, NULL); } else { INFO("UPower not present. Killing UPower module.\n"); }