Skip to content

Commit

Permalink
Allow UPower to run on pinephone. Refs #233.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Oct 19, 2021
1 parent 8047e69 commit 57103f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
14 changes: 10 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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)

10 changes: 7 additions & 3 deletions src/modules/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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]);
Expand Down
23 changes: 13 additions & 10 deletions src/modules/upower.c
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 57103f5

Please sign in to comment.