Skip to content

Commit 0416c58

Browse files
committed
Remove ambient-sensor tolerance check, expose and document target
brightness tolerance. We can't rely on values from the sensor proxy - units may differ depending on hardware. We can dampen our responses to changes by only adjusting the backlight when it would be more than a minor percentage adjustment.
1 parent a6b6da5 commit 0416c58

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

plugins/power/csd-power-manager.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,17 @@ abs_to_percentage (int min, int max, int value)
121121
/* Interval between transition steps (ms). */
122122
#define AMBIENT_TRANSITION_STEP_MS (AMBIENT_TRANSITION_DURATION_MS / AMBIENT_TRANSITION_STEPS)
123123

124-
/* Relative tolerance for considering two sensor readings "equal". */
125-
#define AMBIENT_SENSOR_TOLERANCE 0.05
126-
127124
/* After a transition completes, ignore sensor changes for this long (ms)
128125
* to let the sensor settle with the new screen brightness. */
129126
#define AMBIENT_POST_TRANSITION_DEAD_ZONE_MS 500
130127

128+
/* Minimum brightness change (%) required to trigger a transition. */
129+
#define AMBIENT_MIN_BRIGHTNESS_CHANGE 5.0
130+
131131
/* How much of the computed sensor-to-brightness ratio to actually apply.
132132
* 1.0 = full response, 0.5 = half, etc. Lower values reduce feedback from
133133
* screen content affecting the sensor. */
134-
#define AMBIENT_RESPONSE_DAMPENING 0.75
134+
#define AMBIENT_RESPONSE_DAMPENING 0.8
135135

136136
#define CSD_POWER_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CSD_TYPE_POWER_MANAGER, CsdPowerManagerPrivate))
137137

@@ -3701,14 +3701,6 @@ engine_settings_key_changed_cb (GSettings *settings,
37013701
}
37023702
}
37033703

3704-
static gboolean
3705-
ambient_sensors_equal (gdouble a, gdouble b)
3706-
{
3707-
if (a <= 0.0)
3708-
return FALSE;
3709-
return fabs (a - b) / a < AMBIENT_SENSOR_TOLERANCE;
3710-
}
3711-
37123704
static void
37133705
ambient_cancel_timers (CsdPowerManager *manager)
37143706
{
@@ -3805,7 +3797,7 @@ ambient_begin_transition (CsdPowerManager *manager, gdouble target_brightness)
38053797
{
38063798
gdouble current = manager->priv->ambient_brightness_baseline;
38073799

3808-
if (fabs (target_brightness - current) < 1.0) {
3800+
if (fabs (target_brightness - current) < AMBIENT_MIN_BRIGHTNESS_CHANGE) {
38093801
g_debug ("Ambient target %.1f%% too close to current %.1f%%, skipping",
38103802
target_brightness, current);
38113803
manager->priv->ambient_state = AMBIENT_STATE_IDLE;
@@ -3903,7 +3895,7 @@ iio_proxy_changed (CsdPowerManager *manager)
39033895

39043896
switch (manager->priv->ambient_state) {
39053897
case AMBIENT_STATE_IDLE:
3906-
if (ambient_sensors_equal (manager->priv->ambient_baseline_sensor, sensor_value))
3898+
if (sensor_value == manager->priv->ambient_baseline_sensor)
39073899
return;
39083900

39093901
g_debug ("Ambient: sensor changed from %f to %f, starting stabilization",
@@ -3918,14 +3910,14 @@ iio_proxy_changed (CsdPowerManager *manager)
39183910
break;
39193911

39203912
case AMBIENT_STATE_STABILIZING:
3921-
if (ambient_sensors_equal (manager->priv->ambient_baseline_sensor, sensor_value)) {
3913+
if (sensor_value == manager->priv->ambient_baseline_sensor) {
39223914
g_debug ("Ambient: sensor returned to baseline, cancelling");
39233915
ambient_cancel_timers (manager);
39243916
manager->priv->ambient_state = AMBIENT_STATE_IDLE;
39253917
return;
39263918
}
39273919

3928-
if (!ambient_sensors_equal (manager->priv->ambient_pending_sensor, sensor_value)) {
3920+
if (sensor_value != manager->priv->ambient_pending_sensor) {
39293921
g_debug ("Ambient: sensor changed during stabilization (%f -> %f), restarting",
39303922
manager->priv->ambient_pending_sensor, sensor_value);
39313923
if (manager->priv->ambient_stabilize_timer_id > 0)

0 commit comments

Comments
 (0)