Skip to content

Commit

Permalink
Add setting for selecting automatic lpm ui triggering modes
Browse files Browse the repository at this point in the history
Previously both "from-pocket" and "hover-over" proximity triggering
was enabled implicitly when use_low_power_mode setting was enabled.
The proximity sensor interaction needed for "hover-over" triggering
can be confusing and disabling it was not possible.

Now both triggering types can be disabled/enabled individually via
mcetool - for example:
* only "from-pocket"
  mcetool --set-lpmui-triggering=from-pocket
* both "from-pocket" and "hover-over"
  mcetool --set-lpmui-triggering=from-pocket,hover-over
* neither
  mcetool --set-lpmui-triggering=disabled

Default is to enable "from-pocket" only.

[mce] Add setting for selecting automatic lpm ui triggering modes. Fixes JB#20959
  • Loading branch information
spiiroin committed Aug 12, 2014
1 parent 2e91251 commit eb569a0
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 1 deletion.
6 changes: 6 additions & 0 deletions builtin-gconf.c
Expand Up @@ -1162,6 +1162,12 @@ static const setting_t gconf_defaults[] =
.type = "i",
.def = "1",
},
{
// MCE_GCONF_LPMUI_TRIGGERING @ tklock.h
.key = "/system/osso/dsm/locks/lpm_triggering",
.type = "i",
.def = "1", // = LPMUI_TRIGGERING_FROM_POCKET
},
{
// MCE_GCONF_BLANKING_INHIBIT_MODE @ modules/display.h
.key = "/system/osso/dsm/display/inhibit_blank_mode",
Expand Down
31 changes: 31 additions & 0 deletions tklock.c
Expand Up @@ -2446,6 +2446,12 @@ static void tklock_uiexcept_begin(uiexctype_t type, int64_t linger)
* LOW POWER MODE UI STATE MACHINE
* ========================================================================= */

/** Bitmap of automatic lpm triggering modes */
static gint tklock_lpmui_triggering = LPMUI_TRIGGERING_FROM_POCKET;

/** GConf notifier id for tklock_lpmui_triggering */
static guint tklock_lpmui_triggering_cb_id = 0;

/* Proximity change time limits for low power mode triggering */
enum
{
Expand Down Expand Up @@ -2550,6 +2556,10 @@ static void tklock_lpmui_update_history(cover_state_t state)
static bool tklock_lpmui_probe_from_pocket(void)
{
bool res = false;

if( !(tklock_lpmui_triggering & LPMUI_TRIGGERING_FROM_POCKET) )
goto EXIT;

int64_t now = tklock_monotick_get();
int64_t t;

Expand Down Expand Up @@ -2583,6 +2593,10 @@ static bool tklock_lpmui_probe_from_pocket(void)
static bool tklock_lpmui_probe_on_table(void)
{
bool res = false;

if( !(tklock_lpmui_triggering & LPMUI_TRIGGERING_HOVER_OVER) )
goto EXIT;

int64_t t = tklock_monotick_get();

for( size_t i = 0; ; i += 2 ) {
Expand Down Expand Up @@ -3225,6 +3239,12 @@ static void tklock_gconf_cb(GConfClient *const gcc, const guint id,
mce_log(LL_NOTICE, "doubletap_enable_mode: %d -> %d",
old, doubletap_enable_mode);
}
else if( id == tklock_lpmui_triggering_cb_id ) {
gint old = tklock_lpmui_triggering;
tklock_lpmui_triggering = gconf_value_get_int(gcv);
mce_log(LL_NOTICE, "tklock_lpmui_triggering: %d -> %d",
old, tklock_lpmui_triggering);
}
else {
mce_log(LL_WARN, "Spurious GConf value received; confused!");
}
Expand Down Expand Up @@ -3280,6 +3300,14 @@ static void tklock_gconf_init(void)
&doubletap_enable_mode_cb_id);

mce_gconf_get_int(MCE_GCONF_DOUBLETAP_MODE, &doubletap_enable_mode);

/* Bitmap of automatic lpm triggering modes */
mce_gconf_notifier_add(MCE_GCONF_LOCK_PATH,
MCE_GCONF_LPMUI_TRIGGERING,
tklock_gconf_cb,
&tklock_lpmui_triggering_cb_id);

mce_gconf_get_int(MCE_GCONF_LPMUI_TRIGGERING, &tklock_lpmui_triggering);
}

/** Remove gconf change notifiers
Expand All @@ -3297,6 +3325,9 @@ static void tklock_gconf_quit(void)

mce_gconf_notifier_remove(doubletap_enable_mode_cb_id),
doubletap_enable_mode_cb_id = 0;

mce_gconf_notifier_remove(tklock_lpmui_triggering_cb_id),
tklock_lpmui_triggering_cb_id = 0;
}

/* ========================================================================= *
Expand Down
16 changes: 16 additions & 0 deletions tklock.h
Expand Up @@ -90,6 +90,22 @@
/** Path to the automatic tklock dim/blank disable GConf setting */
#define MCE_GCONF_TK_AUTO_BLANK_DISABLE_PATH MCE_GCONF_LOCK_PATH "/tklock_blank_disable"

/** Automatic lpm triggering modes GConf setting */
# define MCE_GCONF_LPMUI_TRIGGERING MCE_GCONF_LOCK_PATH "/lpm_triggering"

/** Automatic lpm triggering modes */
enum
{
/** Automatic triggering disabled */
LPMUI_TRIGGERING_NONE = 0,

/** Proximity sensor based out-of-pocket triggering */
LPMUI_TRIGGERING_FROM_POCKET = 1<<0,

/** Proximity sensor based hover-over triggering */
LPMUI_TRIGGERING_HOVER_OVER = 1<<1,
};

/** Name of D-Bus callback to provide to Touchscreen/Keypad Lock SystemUI */
#define MCE_TKLOCK_CB_REQ "tklock_callback"

Expand Down
143 changes: 142 additions & 1 deletion tools/mcetool.c
Expand Up @@ -1487,6 +1487,102 @@ static char *mcetool_parse_token(char **ppos)

}

/** Convert bitmap to human readable string via lookup table
*
* @param lut array of symbol_t objects
* @param mask mask of bits to convert
* @param buff buffer to form string in
* @param size size of buff
*
* @return buff, containing mask in human readable form
*/
static char *mcetool_format_bitmask(const symbol_t *lut, int mask,
char *buff, size_t size)
{
const char *none = rlookup(lut, 0) ?: "none";

char *pos = buff;
char *end = buff + size - 1;

auto void add(const char *str)
{
if( pos > buff && pos < end )
*pos++ = ',';
while( pos < end && *str )
*pos++ = *str++;
}

if( !mask ) {
add(none);
goto EXIT;
}

for( int bit = 1; bit > 0; bit <<= 1 ) {
if( !(mask & bit) )
continue;

const char *name = rlookup(lut, bit);
if( name ) {
mask &= ~bit;
add(name);
}
}

if( mask ) {
char hex[32];
snprintf(hex, sizeof hex, "0x%u", (unsigned)mask);
add(hex);
}
EXIT:
*pos = 0;

return buff;
}

/** Convert comma separated list of bit names into bitmask
*
* Note: the function will exit() if unknown bit names are given
*
* @param lut array of symbol_t objects
* @param args string with comma separated bit names
*
* @return bitmask of given bit names
*/
static unsigned mcetool_parse_bitmask(const symbol_t *lut, const char *args)
{
const char *none = rlookup(lut, 0) ?: "none";

unsigned mask = 0;
char *work = 0;

if( !args || !*args || !strcmp(args, none) )
goto EXIT;

if( !(work = strdup(args)) )
goto EXIT;

int bit;
char *end;

for( char *pos = work; pos; pos = end )
{
if( (end = strpbrk(pos, ",|+")) )
*end++ = 0;

if( !(bit = lookup(lut, pos)) ) {
errorf("%s: not a valid bit name\n", pos);
exit(EXIT_FAILURE);
}

mask |= bit;
}

EXIT:
free(work);

return mask;
}

/* ------------------------------------------------------------------------- *
* leds
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -1811,6 +1907,43 @@ static void xmce_get_radio_states(void)
mask & MCE_RADIO_STATE_FMTX ? "enabled" : "disabled");
}

/* ------------------------------------------------------------------------- *
* lpmui triggering
* ------------------------------------------------------------------------- */

/** Lookuptable for mce radio state bits */
static const symbol_t lpmui_triggering_lut[] =
{
{ "from-pocket", LPMUI_TRIGGERING_FROM_POCKET },
{ "hover-over", LPMUI_TRIGGERING_HOVER_OVER },
{ "disabled", LPMUI_TRIGGERING_NONE },
{ 0, 0 }
};

/** Set automatic lpm ui triggering mode
*
* @param args string of comma separated lpm ui triggering names
*/
static bool xmce_set_lpmui_triggering(const char *args)
{
int mask = mcetool_parse_bitmask(lpmui_triggering_lut, args);
mcetool_gconf_set_int(MCE_GCONF_LPMUI_TRIGGERING, mask);
return true;
}

/** Get current lpm ui triggering mode from mce and print it out
*/
static void xmce_get_lpmui_triggering(void)
{
gint mask = 0;
char work[64] = "unknown";
if( mcetool_gconf_get_int(MCE_GCONF_LPMUI_TRIGGERING, &mask) )
mcetool_format_bitmask(lpmui_triggering_lut, mask,
work, sizeof work);

printf("%-"PAD1"s %s\n", "LPM UI triggering:", work);
}

/* ------------------------------------------------------------------------- *
* call state
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -2650,7 +2783,6 @@ static bool xmce_set_touch_unblock_delay(const char *args)
errorf("%d: invalid touch unblock delay\n", val);
return false;
}

mcetool_gconf_set_int(MCE_GCONF_TOUCH_UNBLOCK_DELAY_PATH, val);

return true;
Expand Down Expand Up @@ -3042,6 +3174,7 @@ static bool xmce_get_status(const char *args)
xmce_get_powerkey_action();
xmce_get_powerkey_blanking();
xmce_get_low_power_mode();
xmce_get_lpmui_triggering();
xmce_get_als_mode();
xmce_get_ps_mode();
xmce_get_dim_timeouts();
Expand Down Expand Up @@ -3434,6 +3567,14 @@ static const mce_opt_t options[] =
"set the low power mode; valid modes are:\n"
"'enabled' and 'disabled'\n"
},
{
.name = "set-lpmui-triggering",
.with_arg = xmce_set_lpmui_triggering,
.values = "bit1[,bit2][...]",
.usage =
"set the low power mode ui triggering; valid bits are:\n"
"'disabled', 'from-pocket' and 'hover-over'\n"
},
{
.name = "set-suspend-policy",
.flag = 's',
Expand Down

0 comments on commit eb569a0

Please sign in to comment.