Skip to content

Commit

Permalink
[display] Add setting for dim timeout with hw keyboard available. Fix…
Browse files Browse the repository at this point in the history
…es MER#1321

There are users that wish that the display would stay on longer when
a hw keyboard is attached / slider keyboard is open.

Add separate dim-timeout setting that is used when keyboard is available.
Setting it to zero value means: Use the regular dim-timeout even if a hw
keyboard is available.

By default the value is set to zero. This can be changed by installing
configuration files to /etc/mce directory or with mcetool option:
  --set-dim-with-kbdtimeout=<secs>

The value of the setting persists over mce / device restarts.
  • Loading branch information
spiiroin committed Sep 30, 2015
1 parent 47aafe4 commit 6b3faed
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 5 deletions.
10 changes: 7 additions & 3 deletions builtin-gconf.c
Expand Up @@ -1116,10 +1116,14 @@ static const setting_t gconf_defaults[] =
.def = "",
},
{
// MCE_GCONF_DISPLAY_DIM_TIMEOUT @ modules/display.h
.key = "/system/osso/dsm/display/display_dim_timeout",
.key = MCE_GCONF_DISPLAY_DIM_TIMEOUT,
.type = "i",
.def = "30",
.def = G_STRINGIFY(DEFAULT_DIM_TIMEOUT),
},
{
.key = MCE_GCONF_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT,
.type = "i",
.def = G_STRINGIFY(DEFAULT_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT),
},
{
.key = MCE_GCONF_DISPLAY_BLANK_TIMEOUT,
Expand Down
54 changes: 54 additions & 0 deletions modules/display.c
Expand Up @@ -954,6 +954,10 @@ static guint mdy_adaptive_dimming_threshold_gconf_cb_id = 0;
static gint mdy_disp_dim_timeout_default = DEFAULT_DIM_TIMEOUT;
static guint mdy_disp_dim_timeout_default_gconf_cb_id = 0;

/** Display dimming timeout for keyboard available setting */
static gint mdy_disp_dim_timeout_keyboard = DEFAULT_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT;
static guint mdy_disp_dim_timeout_keyboard_gconf_cb_id = 0;

/** Current adaptive display dimming delay */
static gint mdy_disp_dim_timeout_adaptive = 0;

Expand Down Expand Up @@ -1394,6 +1398,29 @@ static void mdy_datapipe_keyboard_slide_input_cb(gconstpointer const data)
return;
}

/** Keypad available output state; assume unknown */
static cover_state_t kbd_available_state = COVER_UNDEF;

static void
mdy_datapipe_keyboard_available_cb(gconstpointer const data)
{
cover_state_t prev = kbd_available_state;
kbd_available_state = GPOINTER_TO_INT(data);

if( kbd_available_state == prev )
goto EXIT;

mce_log(LL_DEBUG, "kbd_available_state = %s -> %s",
cover_state_repr(prev),
cover_state_repr(kbd_available_state));

/* force blanking reprogramming */
mdy_blanking_rethink_timers(true);

EXIT:
return;
}

/** Handle display_brightness_pipe notifications
*
* @note A brightness request is only sent if the value changed
Expand Down Expand Up @@ -1778,6 +1805,10 @@ static datapipe_handler_t mdy_datapipe_handlers[] =
.input_cb = mdy_datapipe_keyboard_slide_input_cb,
},
// output triggers
{
.datapipe = &keyboard_available_pipe,
.output_cb = mdy_datapipe_keyboard_available_cb,
},
{
.datapipe = &display_state_req_pipe,
.output_cb = mdy_datapipe_display_state_req_cb,
Expand Down Expand Up @@ -3326,8 +3357,15 @@ static gboolean mdy_blanking_can_blank_from_low_power_mode(void)
*/
static gint mdy_blanking_get_default_dimming_delay(void)
{
/* Assume the normal setting is used */
gint dim_timeout = mdy_disp_dim_timeout_default;

/* Use different setting if hw kbd is available */
if( kbd_available_state == COVER_OPEN &&
mdy_disp_dim_timeout_keyboard > 0 ) {
dim_timeout = mdy_disp_dim_timeout_keyboard;
}

/* After boot delay */
gint boot_delay = mdy_blanking_get_afterboot_delay();
if( dim_timeout < boot_delay )
Expand Down Expand Up @@ -8623,6 +8661,13 @@ static void mdy_gconf_cb(GConfClient *const gcc, const guint id,
/* Reprogram blanking timers */
mdy_blanking_rethink_timers(true);
}
else if (id == mdy_disp_dim_timeout_keyboard_gconf_cb_id) {
mdy_disp_dim_timeout_keyboard = gconf_value_get_int(gcv);
mdy_gconf_sanitize_dim_timeouts(false);

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

Expand Down Expand Up @@ -8967,6 +9012,12 @@ static void mdy_gconf_init(void)
mdy_gconf_cb,
&mdy_disp_dim_timeout_default_gconf_cb_id);

mce_gconf_track_int(MCE_GCONF_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT,
&mdy_disp_dim_timeout_keyboard,
DEFAULT_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT,
mdy_gconf_cb,
&mdy_disp_dim_timeout_keyboard_gconf_cb_id);

/* Possible dim timeouts */
mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_DIM_TIMEOUT_LIST,
Expand Down Expand Up @@ -9125,6 +9176,9 @@ static void mdy_gconf_quit(void)
mce_gconf_notifier_remove(mdy_disp_dim_timeout_default_gconf_cb_id),
mdy_disp_dim_timeout_default_gconf_cb_id = 0;

mce_gconf_notifier_remove(mdy_disp_dim_timeout_keyboard_gconf_cb_id),
mdy_disp_dim_timeout_keyboard_gconf_cb_id = 0;

mce_gconf_notifier_remove(mdy_possible_dim_timeouts_gconf_cb_id),
mdy_possible_dim_timeouts_gconf_cb_id = 0;

Expand Down
7 changes: 7 additions & 0 deletions modules/display.h
Expand Up @@ -153,6 +153,13 @@
/** Dim timeout GConf setting */
#define MCE_GCONF_DISPLAY_DIM_TIMEOUT MCE_GCONF_DISPLAY_PATH "/display_dim_timeout"

/** Dim timeout with hw keyboard available GConf setting
*
* Zero value: Follow MCE_GCONF_DISPLAY_DIM_TIMEOUT setting
*/
#define MCE_GCONF_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT MCE_GCONF_DISPLAY_PATH "/display_dim_timeout_with_keyboard"
#define DEFAULT_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT 0

/** Blank timeout GConf setting */
#define MCE_GCONF_DISPLAY_BLANK_TIMEOUT MCE_GCONF_DISPLAY_PATH "/display_blank_timeout"

Expand Down
40 changes: 38 additions & 2 deletions tools/mcetool.c
Expand Up @@ -2558,13 +2558,12 @@ static bool xmce_reset_settings(const char *args)
*/
static bool xmce_set_dim_timeout(const char *args)
{
debugf("%s(%s)\n", __FUNCTION__, args);
int val = xmce_parse_integer(args);
mcetool_gconf_set_int(MCE_GCONF_DISPLAY_DIM_TIMEOUT, val);
return true;
}

/** Get current dim timeout from mce and print it out
/** Show current dim timeout
*/
static void xmce_get_dim_timeout(void)
{
Expand All @@ -2577,6 +2576,35 @@ static void xmce_get_dim_timeout(void)
printf("%-"PAD1"s %s (seconds)\n", "Dim timeout:", txt);
}

/** Set display dim with kbd timeout
*
* @param args string that can be parsed to integer
*/
static bool xmce_set_dim_with_kbd_timeout(const char *args)
{
int val = xmce_parse_integer(args);
mcetool_gconf_set_int(MCE_GCONF_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT,
val);
return true;
}

/** Show current dim with kbd timeout
*/
static void xmce_get_dim_with_kbd_timeout(void)
{
gint val = 0;
char txt[32] = "";

if( !mcetool_gconf_get_int(MCE_GCONF_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT, &val) )
strcpy(txt, "unknown");
else if( val <= 0 )
strcpy(txt, "use default");
else
snprintf(txt, sizeof txt, "%d", (int)val);

printf("%-"PAD1"s %s (seconds)\n", "Dim with kbd timeout:", txt);
}

/** Set "allowed" display dim timeouts
*
* @param args string of comma separated integer numbers
Expand Down Expand Up @@ -5001,6 +5029,7 @@ static bool xmce_get_status(const char *args)
xmce_get_compositor_dimming();
xmce_get_cabc_mode();
xmce_get_dim_timeout();
xmce_get_dim_with_kbd_timeout();
xmce_get_adaptive_dimming_mode();
xmce_get_adaptive_dimming_time();
xmce_get_never_blank();
Expand Down Expand Up @@ -5227,6 +5256,13 @@ static const mce_opt_t options[] =
.usage =
"set the automatic dimming timeout\n"
},
{
.name = "set-dim-with-kbdtimeout",
.with_arg = xmce_set_dim_with_kbd_timeout,
.values = "secs",
.usage =
"set the automatic dimming timeout when hw kbd is available\n"
},
{
.name = "set-dim-timeouts",
.flag = 'O',
Expand Down

0 comments on commit 6b3faed

Please sign in to comment.