Skip to content

Commit

Permalink
[buttonbacklight] Add setting for backlight off delay. JB#42094
Browse files Browse the repository at this point in the history
The five second delay might be too long for some and too short for others.

Add a setting so that the delay can be customized in device specific
configuration files and/or persistently changed by the user via:

  mcetool --set-button-backlight-off-delay=<ms>

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Nov 20, 2018
1 parent 60bc132 commit b5b680c
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .depend
Expand Up @@ -596,6 +596,7 @@ modules/buttonbacklight.o:\
mce-conf.h\
mce-dbus.h\
mce-log.h\
mce-setting.h\
mce.h\

modules/buttonbacklight.pic.o:\
Expand All @@ -606,6 +607,7 @@ modules/buttonbacklight.pic.o:\
mce-conf.h\
mce-dbus.h\
mce-log.h\
mce-setting.h\
mce.h\

modules/callstate.o:\
Expand Down
5 changes: 5 additions & 0 deletions builtin-gconf.c
Expand Up @@ -1887,6 +1887,11 @@ static const setting_t gconf_defaults[] =
.type = "i",
.def = G_STRINGIFY(MCE_DEFAULT_INACTIVITY_SHUTDOWN_DELAY),
},
{
.key = MCE_SETTING_BUTTONBACKLIGHT_OFF_DELAY,
.type = "i",
.def = G_STRINGIFY(MCE_DEFAULT_BUTTONBACKLIGHT_OFF_DELAY),
},
{
.key = NULL,
}
Expand Down
11 changes: 11 additions & 0 deletions mce-setting.h
Expand Up @@ -61,6 +61,17 @@ typedef enum
# define MCE_SETTING_FPWAKEUP_THROTTLE_DELAY MCE_SETTING_FINGERPRINT_PATH "/throttle_delay"
# define MCE_DEFAULT_FPWAKEUP_THROTTLE_DELAY 250

/* ========================================================================= *
* Button Backlight Settings
* ========================================================================= */

/** Prefix for fingerprint setting keys */
# define MCE_SETTING_BUTTONBACKLIGHT_PATH "/system/osso/dsm/buttonbacklight"

/** When fingerprint wakeup is allowed */
# define MCE_SETTING_BUTTONBACKLIGHT_OFF_DELAY MCE_SETTING_BUTTONBACKLIGHT_PATH "/off_delay"
# define MCE_DEFAULT_BUTTONBACKLIGHT_OFF_DELAY 5000 // = 5 seconds

/* ========================================================================= *
* Functions
* ========================================================================= */
Expand Down
86 changes: 84 additions & 2 deletions modules/buttonbacklight.c
Expand Up @@ -24,6 +24,7 @@
#include "../mce-log.h"
#include "../mce-dbus.h"
#include "../mce-conf.h"
#include "../mce-setting.h"
#include "../evdev.h"

#include <linux/input.h>
Expand Down Expand Up @@ -116,6 +117,14 @@ static bool bbl_config_exists(void);
static void bbl_config_init (void);
static void bbl_config_quit (void);

/* ------------------------------------------------------------------------- *
* BBL_SETTING
* ------------------------------------------------------------------------- */

static void bbl_setting_cb (GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data);
static void bbl_setting_init(void);
static void bbl_setting_quit(void);

/* ------------------------------------------------------------------------- *
* G_MODULE
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -162,6 +171,10 @@ static gchar *bbl_control_value_disable = 0;
/** Timer for: Turn off backlight after user inactivity */
static guint bbl_inactive_id = 0;

/** Setting for: Button backlight off delay [ms] */
static gint bbl_off_delay = MCE_DEFAULT_BUTTONBACKLIGHT_OFF_DELAY;
static guint bbl_off_delay_setting_id = 0;

/* ========================================================================= *
* BBL_SYSFS
* ========================================================================= */
Expand Down Expand Up @@ -221,8 +234,8 @@ bbl_inactive_schedule(void)
{
bbl_inactive_cancel();

if( backlight_state_forced == TRISTATE_UNKNOWN )
bbl_inactive_id = g_timeout_add(5000, bbl_inactive_cb, 0);
if( backlight_state_forced == TRISTATE_UNKNOWN && bbl_off_delay > 0 )
bbl_inactive_id = g_timeout_add(bbl_off_delay, bbl_inactive_cb, 0);
}

/* ========================================================================= *
Expand Down Expand Up @@ -1018,6 +1031,69 @@ bbl_config_quit(void)
bbl_control_value_disable = 0;
}

/* ========================================================================= *
* BBL_SETTING
* ========================================================================= */

/** Setting changed callback
*
* @param gcc Unused
* @param id Connection ID from gconf_client_notify_add()
* @param entry The modified GConf entry
* @param data Unused
*/
static void
bbl_setting_cb(GConfClient *const gcc, const guint id,
GConfEntry *const entry, gpointer const data)
{
(void)gcc;
(void)data;
(void)id;

const GConfValue *gcv = gconf_entry_get_value(entry);

if( !gcv ) {
mce_log(LL_DEBUG, "GConf Key `%s' has been unset",
gconf_entry_get_key(entry));
goto EXIT;
}

if( id == bbl_off_delay_setting_id ) {
gint old = bbl_off_delay;
bbl_off_delay = gconf_value_get_int(gcv);
mce_log(LL_NOTICE, "bbl_off_delay: %d -> %d", old, bbl_off_delay);
/* Restart backlight off timer */
bbl_state_rethink_physical();
}
else {
mce_log(LL_WARN, "Spurious GConf value received; confused!");
}

EXIT:
return;
}

/** Get intial setting values and start tracking changes
*/
static void
bbl_setting_init(void)
{
mce_setting_track_int(MCE_SETTING_BUTTONBACKLIGHT_OFF_DELAY,
&bbl_off_delay,
MCE_DEFAULT_BUTTONBACKLIGHT_OFF_DELAY,
bbl_setting_cb,
&bbl_off_delay_setting_id);
}

/** Stop tracking setting changes
*/
static void
bbl_setting_quit(void)
{
mce_setting_notifier_remove(bbl_off_delay_setting_id),
bbl_off_delay_setting_id = 0;
}

/* ========================================================================= *
* G_MODULE
* ========================================================================= */
Expand All @@ -1037,6 +1113,9 @@ g_module_check_init(GModule *module)
/* Lookup static configuration */
bbl_config_init();

/* Start tracking dynamic configuration */
bbl_setting_init();

/* Install datapipe hooks */
bbl_datapipe_init();

Expand All @@ -1055,6 +1134,9 @@ g_module_unload(GModule *module)
{
(void)module;

/* Stop tracking dynamic configuration */
bbl_setting_quit();

/* Remove dbus handlers */
bbl_dbus_quit();

Expand Down
44 changes: 44 additions & 0 deletions tools/mcetool.c
Expand Up @@ -2475,6 +2475,35 @@ static void xmce_get_call_state(void)
* button backlight
* ------------------------------------------------------------------------- */

/** Set button backlight off delay
*
* @param args string that can be parsed to number
*/
static bool xmce_set_button_backlligut_off_delay(const char *args)
{
const char *key = MCE_SETTING_BUTTONBACKLIGHT_OFF_DELAY;
gint val = xmce_parse_integer(args);
xmce_setting_set_int(key, val);
return true;
}

/** Get current fingerprint wakeup allow delay
*/
static void xmce_get_button_backlligut_off_delay(void)
{
const char *tag = "Button backlight off delay:";
const char *key = MCE_SETTING_BUTTONBACKLIGHT_OFF_DELAY;
gint val = 0;
char txt[64];

if( !xmce_setting_get_int(key, &val) )
snprintf(txt, sizeof txt, "unknown");
else
snprintf(txt, sizeof txt, "%d [ms]", val);

printf("%-"PAD1"s %s\n", tag, txt);
}

/** Set button backlight mode
*
* Note: The set mode gets cancelled when mcetool exits. The
Expand Down Expand Up @@ -5840,6 +5869,7 @@ static bool xmce_get_status(const char *args)
get_led_breathing_limit();
xmce_get_memnotify_limits();
xmce_get_memnotify_level();
xmce_get_button_backlligut_off_delay();
printf("\n");

return true;
Expand Down Expand Up @@ -6856,6 +6886,20 @@ static const mce_opt_t options[] =
"request button backlight mode\n"
"Valid modes are: off|on|policy.\n"
},
{
.name = "set-button-backlight-off-delay",
.with_arg = xmce_set_button_backlligut_off_delay,
.values = "ms",
.usage =
"set delay for powering off button backlight.\n"
"\n"
"Set delay in ms for powering off the backlight for\n"
"menu/home/back buttons.\n"
"\n"
"Use zero to keep the buttons light as long as the\n"
"topmost application / system is prepared to handle\n"
"button presses.\n"
},
{
.name = "enable-led",
.flag = 'l',
Expand Down

0 comments on commit b5b680c

Please sign in to comment.