Skip to content

Commit

Permalink
Provide fallback values dim timeouts setting and track changes
Browse files Browse the repository at this point in the history
No change notification for dim timeouts setting was installed, which
meant change did not get effective without mce restart. Also no
fallback values were provided in case the config item is not available.

Use common defaults for built-in config and fallback values.

If dim timeouts setting changes, adjust related state variables
and reprogram blanking timers.

[mce] Provide fallback values dim timeouts setting and track changes. Contributes to JB#26550
  • Loading branch information
spiiroin committed Feb 18, 2015
1 parent bf406e7 commit ea8e6d9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 28 deletions.
14 changes: 11 additions & 3 deletions builtin-gconf.c
Expand Up @@ -1053,6 +1053,15 @@ typedef struct
const char *def;
} setting_t;

/** Custom stringify macro for comma separated lists
*
* G_STRINGIFY() uses standard two phase expansion - which
* does not work with comma separated lists. Using gcc
* pre-prosessor extension allows also those to work.
*/
#define CUSTOM_STRINGIFY2(v...) #v
#define CUSTOM_STRINGIFY(v) CUSTOM_STRINGIFY2(v)

static const setting_t gconf_defaults[] =
{
{
Expand Down Expand Up @@ -1136,10 +1145,9 @@ static const setting_t gconf_defaults[] =
.def = "5", // Note: Legacy value, migrated at mce startup
},
{
// MCE_GCONF_DISPLAY_DIM_TIMEOUT_LIST @ modules/display.h
.key = "/system/osso/dsm/display/possible_display_dim_timeouts",
.key = MCE_GCONF_DISPLAY_DIM_TIMEOUT_LIST,
.type = "ai",
.def = "15,30,60,120,180",
.def = CUSTOM_STRINGIFY(DEFAULT_DISPLAY_DIM_TIMEOUT_LIST),
},
{
// Hint for settings UI. Not used by MCE itself.
Expand Down
83 changes: 58 additions & 25 deletions modules/display.c
Expand Up @@ -672,6 +672,7 @@ static void mdy_gconf_cb(GConfClient *const gcc, const guint id,
static void mdy_gconf_init(void);
static void mdy_gconf_quit(void);
static void mdy_gconf_sanitize_brightness_settings(void);
static void mdy_gconf_sanitize_dim_timeouts(bool force_update);

/* ------------------------------------------------------------------------- *
* MODULE_LOAD_UNLOAD
Expand Down Expand Up @@ -906,6 +907,9 @@ static guint mdy_adaptive_dimming_enabled_gconf_cb_id = 0;
/** Array of possible display dim timeouts */
static GSList *mdy_possible_dim_timeouts = NULL;

/** GConf callback ID for display blanking timeout setting */
static guint mdy_possible_dim_timeouts_gconf_cb_id = 0;

/** Threshold to use for adaptive timeouts for dimming in milliseconds */
static gint mdy_adaptive_dimming_threshold = DEFAULT_ADAPTIVE_DIMMING_THRESHOLD;

Expand Down Expand Up @@ -7804,21 +7808,20 @@ static void mdy_gconf_cb(GConfClient *const gcc, const guint id,
mdy_adaptive_dimming_threshold = gconf_value_get_int(gcv);
mdy_blanking_stop_adaptive_dimming();
}
else if (id == mdy_possible_dim_timeouts_gconf_cb_id )
{
mdy_gconf_sanitize_dim_timeouts(true);

/* Reprogram blanking timers */
mdy_blanking_rethink_timers(true);
}
else if (id == mdy_disp_dim_timeout_gconf_cb_id) {
mdy_disp_dim_timeout = gconf_value_get_int(gcv);

/* Find the closest match in the list of valid dim timeouts */
mdy_dim_timeout_index = mdy_blanking_find_dim_timeout_index(mdy_disp_dim_timeout);
mdy_adaptive_dimming_index = 0;
mdy_gconf_sanitize_dim_timeouts(false);

/* Reprogram blanking timers */
mdy_blanking_rethink_timers(true);

/* Update inactivity timeout */
execute_datapipe(&inactivity_timeout_pipe,
GINT_TO_POINTER(mdy_disp_dim_timeout +
mdy_disp_blank_timeout),
USE_INDATA, CACHE_INDATA);
}
else if (id == mdy_blanking_inhibit_mode_gconf_cb_id) {
mdy_blanking_inhibit_mode = gconf_value_get_int(gcv);
Expand Down Expand Up @@ -7944,6 +7947,43 @@ static void mdy_gconf_sanitize_brightness_settings(void)
USE_INDATA, CACHE_INDATA);
}

static void mdy_gconf_sanitize_dim_timeouts(bool force_update)
{
/* If asked to, flush existing list of allowed timeouts */
if( force_update && mdy_possible_dim_timeouts ) {
g_slist_free(mdy_possible_dim_timeouts),
mdy_possible_dim_timeouts = 0;
}

/* Make sure we have a list of allowed timeouts */
if( !mdy_possible_dim_timeouts ) {
mce_gconf_get_int_list(MCE_GCONF_DISPLAY_DIM_TIMEOUT_LIST,
&mdy_possible_dim_timeouts);
}

if( !mdy_possible_dim_timeouts ) {
static const int def[] = { DEFAULT_DISPLAY_DIM_TIMEOUT_LIST };

GSList *tmp = 0;
for( size_t i = 0; i < G_N_ELEMENTS(def); ++i )
tmp = g_slist_prepend(tmp, GINT_TO_POINTER(def[i]));
mdy_possible_dim_timeouts = g_slist_reverse(tmp);
}

/* Find the closest match in the list of valid dim timeouts */
mdy_dim_timeout_index = mdy_blanking_find_dim_timeout_index(mdy_disp_dim_timeout);

/* Reset adaptive dimming state */
mdy_adaptive_dimming_index = 0;

/* Update inactivity timeout */
execute_datapipe(&inactivity_timeout_pipe,
GINT_TO_POINTER(mdy_disp_dim_timeout +
mdy_disp_blank_timeout +
mdy_additional_bootup_dim_timeout),
USE_INDATA, CACHE_INDATA);
}

/** Get initial gconf valus and start tracking changes
*/
static void mdy_gconf_init(void)
Expand Down Expand Up @@ -8003,14 +8043,6 @@ static void mdy_gconf_init(void)
mdy_gconf_cb,
&mdy_adaptive_dimming_enabled_gconf_cb_id);

/* Possible dim timeouts */
if( !mce_gconf_get_int_list(MCE_GCONF_DISPLAY_DIM_TIMEOUT_LIST,
&mdy_possible_dim_timeouts) ) {
mce_log(LL_WARN, "no dim timeouts defined");
// FIXME: use some built-in defaults
// FIXME: CHANGE NOTIFIER IS NOT INSTALLED!!!
}

/* Adaptive display dimming threshold timer */
mce_gconf_track_int(MCE_GCONF_DISPLAY_ADAPTIVE_DIM_THRESHOLD,
&mdy_adaptive_dimming_threshold,
Expand All @@ -8025,15 +8057,13 @@ static void mdy_gconf_init(void)
mdy_gconf_cb,
&mdy_disp_dim_timeout_gconf_cb_id);

mdy_dim_timeout_index = mdy_blanking_find_dim_timeout_index(mdy_disp_dim_timeout);
mdy_adaptive_dimming_index = 0;
/* Possible dim timeouts */
mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_DIM_TIMEOUT_LIST,
mdy_gconf_cb,
&mdy_possible_dim_timeouts_gconf_cb_id);

/* Update inactivity timeout */
execute_datapipe(&inactivity_timeout_pipe,
GINT_TO_POINTER(mdy_disp_dim_timeout +
mdy_disp_blank_timeout +
mdy_additional_bootup_dim_timeout),
USE_INDATA, CACHE_INDATA);
mdy_gconf_sanitize_dim_timeouts(true);

/* Use low power mode toggle */
mce_gconf_track_bool(MCE_GCONF_USE_LOW_POWER_MODE,
Expand Down Expand Up @@ -8127,6 +8157,9 @@ static void mdy_gconf_quit(void)
mce_gconf_notifier_remove(mdy_disp_dim_timeout_gconf_cb_id),
mdy_disp_dim_timeout_gconf_cb_id = 0;

mce_gconf_notifier_remove(mdy_possible_dim_timeouts_gconf_cb_id),
mdy_possible_dim_timeouts_gconf_cb_id = 0;

mce_gconf_notifier_remove(mdy_use_low_power_mode_gconf_cb_id),
mdy_use_low_power_mode_gconf_cb_id = 0;

Expand Down
3 changes: 3 additions & 0 deletions modules/display.h
Expand Up @@ -293,4 +293,7 @@ enum
*/
#define DEFAULT_DISPLAY_OFF_OVERRIDE DISPLAY_OFF_OVERRIDE_DISABLED

/** Default value for MCE_GCONF_DISPLAY_DIM_TIMEOUT_LIST setting */
#define DEFAULT_DISPLAY_DIM_TIMEOUT_LIST 15,30,60,120,180

#endif /* _DISPLAY_H_ */

0 comments on commit ea8e6d9

Please sign in to comment.