Skip to content

Commit d724b8e

Browse files
committed
backlight: fix restore_on_exit with no_auto_calib mode
When both restore_on_exit and no_auto_calib are enabled: - Skip forcing 100% brightness at startup to preserve user's setting - Initialize current_bl_pct from hardware for correct DIMMER restore - Use synchronous D-Bus call on exit to ensure restore completes Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
1 parent 149d6dc commit d724b8e

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

src/modules/backlight.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ static void receive_waiting_init(const msg_t *const msg, UNUSED const void* user
236236
* Note: set smooth field from conf to allow keyboard and gamma to react;
237237
* > if (up->smooth || conf.bl_conf.no_smooth) { ... }
238238
*/
239-
set_backlight_level(1.0, !conf.bl_conf.smooth.no_smooth, 0, 0);
239+
if (!conf.bl_conf.restore)
240+
set_backlight_level(1.0, !conf.bl_conf.smooth.no_smooth, 0, 0);
240241
pause_mod(AUTOCALIB);
241242
}
242243
if (state.lid_state) {
@@ -250,6 +251,23 @@ static void receive_waiting_init(const msg_t *const msg, UNUSED const void* user
250251
// Store current backlight to later restore them if requested
251252
SYSBUS_ARG_REPLY(args, parse_bus_reply, NULL, CLIGHTD_SERVICE, "/org/clightd/clightd/Backlight2", "org.clightd.clightd.Backlight2", "Get");
252253
call(&args, NULL);
254+
255+
/*
256+
* When restore_on_exit is set and auto calibration is disabled,
257+
* initialize current_bl_pct from hardware so DIMMER knows
258+
* the correct brightness to restore after dimming.
259+
*/
260+
if (conf.bl_conf.no_auto_calib && conf.bl_conf.restore && map_length(bls) > 0) {
261+
map_itr_t *itr = map_itr_new(bls);
262+
if (itr) {
263+
double *val = map_itr_get_data(itr);
264+
if (val) {
265+
state.current_bl_pct = *val;
266+
DEBUG("Initial backlight level: %.2lf.\n", state.current_bl_pct);
267+
}
268+
free(itr);
269+
}
270+
}
253271
}
254272
}
255273

@@ -544,6 +562,10 @@ static void publish_bl_upd(const double pct, const bool is_smooth, const double
544562
M_PUB(bl_msg);
545563
}
546564

565+
static int noop_reply_cb(UNUSED sd_bus_message *reply, UNUSED const char *member, UNUSED void *userdata) {
566+
return 0;
567+
}
568+
547569
static void set_each_brightness(double pct, const double step, const int timeout) {
548570
const bool restoring = pct == -1.0f;
549571
sensor_conf_t *sens_conf = &conf.sens_conf;
@@ -571,8 +593,14 @@ static void set_each_brightness(double pct, const double step, const int timeout
571593
r = call(&args, "d(du)", real_pct, step, timeout);
572594
} else {
573595
DEBUG("Using default curve for '%s'\n", mon_id);
574-
/* Use non-adjusted (default) curve value */
575-
r = call(&args, "d(du)", restoring ? *val : pct, step, timeout);
596+
if (restoring) {
597+
/* Synchronous call to ensure completion before exit */
598+
SYSBUS_ARG_REPLY(sync_args, noop_reply_cb, NULL, CLIGHTD_SERVICE, path, "org.clightd.clightd.Backlight2.Server", "Set");
599+
r = call(&sync_args, "d(du)", *val, step, timeout);
600+
} else {
601+
/* Use non-adjusted (default) curve value */
602+
r = call(&args, "d(du)", pct, step, timeout);
603+
}
576604
}
577605
if (r < 0) {
578606
WARN("Failed to set backlight on %s.\n", mon_id);

0 commit comments

Comments
 (0)