Skip to content

Commit

Permalink
[display] Add setting for blanking pause mode. Fixes JB#27486
Browse files Browse the repository at this point in the history
Usually navigation applications use blank prevent to keep display on.
Sometimes - say when navigating while driving with bike - it might
be desirable to still allow display to dim (or blank) to save battery.

Add setting for controlling blank prevent handling to make it possible
to allow display to dim or even blank while application is using blank
prevention D-Bus interface.

The supported modes are:

  * keep-on: blank prevent sessions keep the display on as before
  * allow-dim: display can be dimmed even if blank prevent is used
  * disabled: display can be blanked even if blank prevent is used

By default the "keep-on" mode is used and blank prevention works just
like it did before the changes. The mode can be changed via:

  mcetool --set-blank-prevent-mode=<disabled|keep-on|allow-dim>

The value of the setting persists over mce / device restarts.
  • Loading branch information
spiiroin committed Jul 30, 2015
1 parent d064f99 commit bb13490
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 5 deletions.
5 changes: 5 additions & 0 deletions builtin-gconf.c
Expand Up @@ -1170,6 +1170,11 @@ static const setting_t gconf_defaults[] =
.type = "b",
.def = G_STRINGIFY(DEFAULT_ORIENTATION_SENSOR_ENABLED),
},
{
.key = MCE_GCONF_DISPLAY_BLANKING_PAUSE_MODE,
.type = "i",
.def = G_STRINGIFY(DEFAULT_BLANKING_PAUSE_MODE),
},
{
// Hint for settings UI. Not used by MCE itself.
.key = "/system/osso/dsm/display/possible_display_blank_timeouts",
Expand Down
149 changes: 144 additions & 5 deletions modules/display.c
Expand Up @@ -254,6 +254,7 @@ enum

static inline bool mdy_str_eq_p(const char *s1, const char *s2);
static int64_t mdy_get_boot_tick(void);
static const char *blanking_pause_mode_repr(blanking_pause_mode_t mode);

/* ------------------------------------------------------------------------- *
* SHUTDOWN
Expand Down Expand Up @@ -440,6 +441,8 @@ static void mdy_blanking_stop_pause_period(void);
static void mdy_blanking_start_pause_period(void);

static bool mdy_blanking_is_paused(void);
static bool mdy_blanking_pause_can_dim(void);
static bool mdy_blanking_pause_is_allowed(void);

static void mdy_blanking_add_pause_client(const gchar *name);
static gboolean mdy_blanking_remove_pause_client(const gchar *name);
Expand Down Expand Up @@ -874,6 +877,12 @@ static filewatcher_t *mdy_update_mode_watcher = 0;
* GCONF_SETTINGS
* ------------------------------------------------------------------------- */

/** Setting for allowing dimming while blanking is paused */
static gint mdy_blanking_pause_mode = DEFAULT_BLANKING_PAUSE_MODE;

/** GConf callback ID for mdy_blanking_pause_mode */
static guint mdy_blanking_pause_mode_gconf_cb_id = 0;

/** Display blanking timeout setting */
static gint mdy_blank_timeout = DEFAULT_BLANK_TIMEOUT;

Expand Down Expand Up @@ -999,6 +1008,25 @@ static int64_t mdy_get_boot_tick(void)

return res;
}
/** Convert blanking_pause_mode_t enum to human readable string
*
* @param mode blanking_pause_mode_t enumeration value
*
* @return human readable representation of mode
*/
static const char *blanking_pause_mode_repr(blanking_pause_mode_t mode)
{
const char *res = "unknown";

switch( mode ) {
case BLANKING_PAUSE_MODE_DISABLED: res = "disabled"; break;
case BLANKING_PAUSE_MODE_KEEP_ON: res = "keep-on"; break;
case BLANKING_PAUSE_MODE_ALLOW_DIM: res = "allow-dim"; break;
default: break;
}

return res;
}

/* ========================================================================= *
* DATAPIPE_TRACKING
Expand Down Expand Up @@ -3444,6 +3472,14 @@ static void mdy_blanking_schedule_off(void)
timeout = ACTDEAD_MAX_OFF_TIMEOUT;
}

/* Blanking pause can optionally stay in dimmed state */
if( display_state == MCE_DISPLAY_DIM &&
mdy_blanking_is_paused() &&
mdy_blanking_pause_can_dim() ) {
mdy_blanking_cancel_off();
goto EXIT;
}

if( mdy_blanking_off_cb_id ) {
g_source_remove(mdy_blanking_off_cb_id);
mce_log(LL_DEBUG, "BLANK timer rescheduled @ %d secs", timeout);
Expand All @@ -3462,6 +3498,7 @@ static void mdy_blanking_schedule_off(void)

mdy_blanking_inhibit_schedule_broadcast();

EXIT:
return;
}

Expand Down Expand Up @@ -3595,6 +3632,24 @@ static bool mdy_blanking_is_paused(void)
//return mdy_blanking_pause_clients != 0;
}

/** Dimming allowed while blanking is paused predicate
*
* returns true if dimming is allowed, false otherwise
*/
static bool mdy_blanking_pause_can_dim(void)
{
return mdy_blanking_pause_mode == BLANKING_PAUSE_MODE_ALLOW_DIM;
}

/** Blanking pause is allowed predicate
*
* returns true if blanking pause is allowed, false otherwise
*/
static bool mdy_blanking_pause_is_allowed(void)
{
return mdy_blanking_pause_mode != BLANKING_PAUSE_MODE_DISABLED;
}

/** Add blanking pause client
*
* @param name The private the D-Bus name of the client
Expand All @@ -3606,8 +3661,26 @@ static void mdy_blanking_add_pause_client(const gchar *name)
if( !name )
goto EXIT;

// check if the feature is disabled
if( !mdy_blanking_pause_is_allowed() ) {
mce_log(LL_DEBUG, "blanking pause request from`%s ignored';"
" feature is disabled", name);
goto EXIT;
}

// display must be on
if( display_state != MCE_DISPLAY_ON ) {
switch( display_state ) {
case MCE_DISPLAY_ON:
// always allowed
break;

case MCE_DISPLAY_DIM:
// optionally allowed
if( mdy_blanking_pause_can_dim() )
break;
// fall through

default:
mce_log(LL_WARN, "blanking pause request from`%s ignored';"
" display not on", name);
goto EXIT;
Expand Down Expand Up @@ -3894,8 +3967,22 @@ static void mdy_blanking_rethink_timers(bool force)
if( prev_display_state != display_state ) {
force = true;

// always stop blanking pause period
mdy_blanking_stop_pause_period();
/* Stop blanking pause period, unless toggling between
* ON and DIM states while dimming during blanking
* pause is allowed */

if( (prev_display_state == MCE_DISPLAY_ON ||
prev_display_state == MCE_DISPLAY_DIM) &&
(display_state == MCE_DISPLAY_ON ||
display_state == MCE_DISPLAY_DIM) &&
mdy_blanking_is_paused() &&
mdy_blanking_pause_can_dim() ) {
// keep existing blanking pause timer alive
}
else {
// stop blanking pause period
mdy_blanking_stop_pause_period();
}

// handle adaptive blanking states
switch( display_state ) {
Expand Down Expand Up @@ -3985,7 +4072,7 @@ static void mdy_blanking_rethink_timers(bool force)
break;
}

if( mdy_blanking_is_paused() )
if( mdy_blanking_is_paused() && !mdy_blanking_pause_can_dim() )
break;

mdy_blanking_schedule_dim();
Expand Down Expand Up @@ -5611,8 +5698,19 @@ static void mdy_orientation_sensor_rethink(void)
static void mdy_display_state_changed(void)
{
/* Disable blanking pause if display != ON */
if( display_state != MCE_DISPLAY_ON )
switch( display_state ) {
case MCE_DISPLAY_ON:
break;

case MCE_DISPLAY_DIM:
if( mdy_blanking_is_paused() && mdy_blanking_pause_can_dim() )
break;
// fall through

default:
mdy_blanking_remove_pause_clients();
break;
}

/* Program dim/blank timers */
mdy_blanking_rethink_timers(false);
Expand Down Expand Up @@ -7019,6 +7117,10 @@ static gboolean mdy_dbus_send_blanking_inhibit_status(DBusMessage *const method_
static int prev = -1;
bool curr = false;

/* Having blanking pause active counts as inhibit active too */
if( mdy_blanking_is_paused() )
curr = true;

/* In display on/dim state we should have either dimming or
* blanking timer active. If that is not the case, some form of
* blanking inhibit is active. This should catch things like
Expand Down Expand Up @@ -8389,6 +8491,33 @@ static void mdy_gconf_cb(GConfClient *const gcc, const guint id,
mce_log(LL_NOTICE, "display off override = %d",
mdy_dbus_display_off_override);
}

else if( id == mdy_blanking_pause_mode_gconf_cb_id ) {
gint old = mdy_blanking_pause_mode;
mdy_blanking_pause_mode = gconf_value_get_int(gcv);

mce_log(LL_NOTICE, "blanking pause mode = %s",
blanking_pause_mode_repr(mdy_blanking_pause_mode));

if( mdy_blanking_pause_mode == old ) {
/* nop */
}
else if( mdy_blanking_pause_is_allowed() ) {
/* Reprogram dim timer as needed when toggling between
* keep-on and allow-dimming modes.
*
* Note that re-enabling after disable means that active
* client side renew sessions are out of sync and hiccups
* can occur (i.e. display can blank once after enabling).
*/
mdy_blanking_rethink_timers(true);
}
else {
/* Flush any active sessions there might be and reprogram
* display off timer as needed. */
mdy_blanking_remove_pause_clients();
}
}
else if (id == mdy_orientation_sensor_enabled_gconf_cb_id) {
mdy_orientation_sensor_enabled = gconf_value_get_bool(gcv);
mdy_orientation_sensor_rethink();
Expand Down Expand Up @@ -8675,6 +8804,13 @@ static void mdy_gconf_init(void)
DEFAULT_ORIENTATION_SENSOR_ENABLED,
mdy_gconf_cb,
&mdy_orientation_sensor_enabled_gconf_cb_id);

/* Blanking pause mode */
mce_gconf_track_int(MCE_GCONF_DISPLAY_BLANKING_PAUSE_MODE,
&mdy_blanking_pause_mode,
DEFAULT_BLANKING_PAUSE_MODE,
mdy_gconf_cb,
&mdy_blanking_pause_mode_gconf_cb_id);
}

static void mdy_gconf_quit(void)
Expand Down Expand Up @@ -8750,6 +8886,9 @@ static void mdy_gconf_quit(void)
mce_gconf_notifier_remove(mdy_orientation_sensor_enabled_gconf_cb_id),
mdy_orientation_sensor_enabled_gconf_cb_id = 0;

mce_gconf_notifier_remove(mdy_blanking_pause_mode_gconf_cb_id),
mdy_blanking_pause_mode_gconf_cb_id = 0;

/* Free dynamic data obtained from config */

g_slist_free(mdy_possible_dim_timeouts), mdy_possible_dim_timeouts = 0;
Expand Down
18 changes: 18 additions & 0 deletions modules/display.h
Expand Up @@ -338,4 +338,22 @@ enum
/** Default value for MCE_GCONF_ORIENTATION_SENSOR_ENABLED setting */
#define DEFAULT_ORIENTATION_SENSOR_ENABLED true

/** Display blanking pause modes */
typedef enum {
/** Ignore blanking pause requests */
BLANKING_PAUSE_MODE_DISABLED = 0,

/** Blanking pause keeps display on */
BLANKING_PAUSE_MODE_KEEP_ON = 1,

/** Display can be dimmed during Blanking pause */
BLANKING_PAUSE_MODE_ALLOW_DIM = 2,
} blanking_pause_mode_t;

/** Blanking pause mode GConf setting */
#define MCE_GCONF_DISPLAY_BLANKING_PAUSE_MODE MCE_GCONF_DISPLAY_PATH "/blanking_pause_mode"

/** Default value for MCE_GCONF_DISPLAY_BLANK_FROM_LOCKSCREEN_TIMEOUT setting */
#define DEFAULT_BLANKING_PAUSE_MODE 1 // = BLANKING_PAUSE_MODE_KEEP_ON

#endif /* _DISPLAY_H_ */
46 changes: 46 additions & 0 deletions tools/mcetool.c
Expand Up @@ -2305,6 +2305,41 @@ static bool xmce_allow_display_blanking(const char *arg)
return true;
}

/** Lookup table for display blanking pause modes
*/
static const symbol_t blanking_pause_modes[] = {
{ "disabled", BLANKING_PAUSE_MODE_DISABLED },
{ "keep-on", BLANKING_PAUSE_MODE_KEEP_ON },
{ "allow-dim", BLANKING_PAUSE_MODE_ALLOW_DIM },
{ NULL, -1 }
};

/** Set display blank prevent mode setting
*
* @param args string that can be parsed to blank prevent mode
*/
static bool xmce_set_blank_prevent_mode(const char *args)
{
int val = lookup(blanking_pause_modes, args);
if( val < 0 ) {
errorf("%s: invalid display blank prevent mode\n", args);
exit(EXIT_FAILURE);
}
mcetool_gconf_set_int(MCE_GCONF_DISPLAY_BLANKING_PAUSE_MODE, val);
return true;
}

/** Get current display blank prevent mode from mce and print it out
*/
static void xmce_get_blank_prevent_mode(void)
{
gint val = 0;
const char *txt = 0;
if( mcetool_gconf_get_int(MCE_GCONF_DISPLAY_BLANKING_PAUSE_MODE, &val) )
txt = rlookup(blanking_pause_modes, val);
printf("%-"PAD1"s %s \n", "Display blank prevent mode:", txt ?: "unknown");
}

/* ------------------------------------------------------------------------- *
* display brightness
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -4490,6 +4525,7 @@ static bool xmce_get_status(const char *args)
xmce_get_never_blank();
xmce_get_blank_timeout();
xmce_get_inhibit_mode();
xmce_get_blank_prevent_mode();
xmce_get_keyboard_backlight_state();
xmce_get_inactivity_state();
xmce_get_power_saving_mode();
Expand Down Expand Up @@ -4681,6 +4717,16 @@ static const mce_opt_t options[] =
.usage =
"send cancel blank prevent request\n"
},
{
.name = "set-blank-prevent-mode",
.with_arg = xmce_set_blank_prevent_mode,
.values = "disabled|keep-on|allow-dim",
.usage =
"set blank prevent mode; valid modes are:\n"
" 'disabled' all blank prevent requests are ignored\n"
" 'keep-on' display is kept on as requested\n"
" 'allow-dim' display can be dimmed during blank prevent\n"
},
{
.name = "set-dim-timeout",
.flag = 'G',
Expand Down

0 comments on commit bb13490

Please sign in to comment.