Skip to content

Commit

Permalink
Hook new Backlight.Changed signal by Clightd and, at least for laptop…
Browse files Browse the repository at this point in the history
…s, integrate clight with external backlight changing tools.
  • Loading branch information
FedeDP committed Jun 17, 2020
1 parent 5782989 commit 767e184
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 1 addition & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [x] Expose SensAvailable state property
- [x] Rename "Calibrate" method to "Capture"
- [x] Capture method to take 2 booleans, exposing capture_upd fields
- [x] Hook Backlight.Changed Clightd signal to update state.current_bl. Easy for laptop's internal monitor; impossibile with ddcutil, but possible through ddcci-kernel-driver only for software changes, not hardware ones (ie: through monitor buttons)

### Keyboard
- [x] Split keyboard settings from backlight
Expand Down Expand Up @@ -118,6 +119,3 @@
### BACKLIGHT multiple-monitors curves
- [ ] Add support for config files to give each monitor its own backlight curves. Something like /etc/clight/clight.conf + /etc/clight/mon.d/$MONITOR_SERIAL.conf (where MONITOR_SERIAL can be found through org.clightd.clightd.Backlight.GetAll)
- [ ] If any conf file is found in /etc/clight/mon.d/, avoid calling SetAll, and just call Set on each serial.

### Backlight
- [ ] Add a backlight Changed signal in Clightd? Then hook the signal to update state.current_bl. Easy for laptop's internal monitor; impossibile with ddcutil, but possible through ddcci-kernel-driver only for software changes, not hardware ones (ie: through monitor buttons)
2 changes: 1 addition & 1 deletion src/commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define LAT_UNDEFINED 91.0 // Undefined (ie: unset) value for latitude
#define LON_UNDEFINED 181.0 // Undefined (ie: unset) value for longitude
#define MINIMUM_CLIGHTD_VERSION_MAJ 4 // Clightd minimum required maj version
#define MINIMUM_CLIGHTD_VERSION_MIN 1 // Clightd minimum required min version -> new wizard: Backlight.{Get,Set} with empty "serial" param support
#define MINIMUM_CLIGHTD_VERSION_MIN 2 // Clightd minimum required min version -> Backlight.Changed signal

/** Generic structs **/

Expand Down
25 changes: 20 additions & 5 deletions src/modules/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static void interface_timeout_callback(timeout_upd *up);
static void dimmed_callback(void);
static void time_callback(int old_val, int is_event);
static int on_sensor_change(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
static int on_bl_changed(sd_bus_message *m, UNUSED void *userdata, UNUSED sd_bus_error *ret_error);
static int get_current_timeout(void);
static void on_lid_update(void);
static void pause_mod(enum backlight_pause type);
Expand All @@ -26,7 +27,7 @@ static void resume_mod(enum backlight_pause type);
static int bl_fd = -1;
static int paused_state;
static bool paused_fd_recv;
static sd_bus_slot *slot;
static sd_bus_slot *sens_slot, *bl_slot;

DECLARE_MSG(bl_msg, BL_UPD);
DECLARE_MSG(amb_msg, AMBIENT_BR_UPD);
Expand Down Expand Up @@ -65,8 +66,11 @@ static bool evaluate(void) {
}

static void destroy(void) {
if (slot) {
slot = sd_bus_slot_unref(slot);
if (sens_slot) {
sens_slot = sd_bus_slot_unref(sens_slot);
}
if (bl_slot) {
bl_slot = sd_bus_slot_unref(bl_slot);
}
if (bl_fd >= 0) {
close(bl_fd);
Expand Down Expand Up @@ -94,8 +98,11 @@ static void receive_waiting_init(const msg_t *const msg, UNUSED const void* user
m_unbecome();

/* We do not fail if this fails */
SYSBUS_ARG(args, CLIGHTD_SERVICE, "/org/clightd/clightd/Sensor", "org.clightd.clightd.Sensor", "Changed");
add_match(&args, &slot, on_sensor_change);
SYSBUS_ARG(sens_args, CLIGHTD_SERVICE, "/org/clightd/clightd/Sensor", "org.clightd.clightd.Sensor", "Changed");
add_match(&sens_args, &sens_slot, on_sensor_change);

SYSBUS_ARG(bl_args, CLIGHTD_SERVICE, "/org/clightd/clightd/Backlight", "org.clightd.clightd.Backlight", "Changed");
add_match(&bl_args, &bl_slot, on_bl_changed);

bl_fd = start_timer(CLOCK_BOOTTIME, 0, get_current_timeout() > 0);
m_register_fd(bl_fd, false, NULL);
Expand Down Expand Up @@ -438,6 +445,14 @@ static int on_sensor_change(UNUSED sd_bus_message *m, UNUSED void *userdata, UNU
return 0;
}

static int on_bl_changed(sd_bus_message *m, UNUSED void *userdata, UNUSED sd_bus_error *ret_error) {
const char *syspath = NULL;
sd_bus_message_read(m, "sd", &syspath, &state.current_bl_pct);
DEBUG("Backlight level updated: %.2lf.\n", state.current_bl_pct);
return 0;
}


static inline int get_current_timeout(void) {
if (state.in_event) {
return conf.bl_conf.timeout[state.ac_state][IN_EVENT];
Expand Down

0 comments on commit 767e184

Please sign in to comment.