Skip to content

Commit

Permalink
Allow blanking via lpm when powerkey is pressed
Browse files Browse the repository at this point in the history
By default pressing power key now goes to lpm mode before really
powering off the display.

The default can be changed via:
  mcetool --set-powerkey-blanking=off|lpm

[mce] Allow blanking via lpm when powerkey is pressed
  • Loading branch information
spiiroin committed Aug 4, 2014
1 parent 4415684 commit 97ae90c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 3 deletions.
6 changes: 6 additions & 0 deletions builtin-gconf.c
Expand Up @@ -1422,6 +1422,12 @@ static const setting_t gconf_defaults[] =
.type = "i",
.def = "1",
},
{
// MCE_GCONF_POWERKEY_BLANKING_MODE @ powerkey.h
.key = "/system/osso/dsm/powerkey/blanking_mode",
.type = "i",
.def = "1", // = PWRKEY_BLANK_TO_LPM
},
{
.key = NULL,
}
Expand Down
51 changes: 48 additions & 3 deletions powerkey.c
Expand Up @@ -121,6 +121,12 @@ static gint powerkey_action_mode = PWRKEY_ENABLE_DEFAULT;
/** GConf callback ID for powerkey_action_mode */
static guint powerkey_action_mode_cb_id = 0;

/** Power key press blanking mode */
static gint powerkey_blanking_mode = PWRKEY_BLANK_TO_OFF;

/** GConf callback ID for powerkey_blanking_mode */
static guint powerkey_blanking_mode_cb_id = 0;

/** GConf callback for powerkey related settings
*
* @param gcc (not used)
Expand Down Expand Up @@ -149,6 +155,12 @@ static void powerkey_gconf_cb(GConfClient *const gcc, const guint id,
mce_log(LL_NOTICE, "powerkey_action_mode: %d -> %d",
old, powerkey_action_mode);
}
else if( id == powerkey_blanking_mode_cb_id ) {
gint old = powerkey_blanking_mode;
powerkey_blanking_mode = gconf_value_get_int(gcv);
mce_log(LL_NOTICE, "powerkey_blanking_mode: %d -> %d",
old, powerkey_blanking_mode);
}
else {
mce_log(LL_WARN, "Spurious GConf value received; confused!");
}
Expand All @@ -168,6 +180,16 @@ static void powerkey_gconf_init(void)
&powerkey_action_mode_cb_id);

mce_gconf_get_int(MCE_GCONF_POWERKEY_MODE, &powerkey_action_mode);

/* Power key display blanking mode */
mce_gconf_notifier_add(MCE_GCONF_POWERKEY_PATH,
MCE_GCONF_POWERKEY_BLANKING_MODE,
powerkey_gconf_cb,
&powerkey_blanking_mode_cb_id);

mce_gconf_get_int(MCE_GCONF_POWERKEY_BLANKING_MODE,
&powerkey_blanking_mode);

}

/** Remove gconf change notifiers
Expand All @@ -177,6 +199,10 @@ static void powerkey_gconf_quit(void)
/* Power key press handling mode */
mce_gconf_notifier_remove(powerkey_action_mode_cb_id),
powerkey_action_mode_cb_id = 0;

/* Power key press blanking mode */
mce_gconf_notifier_remove(powerkey_blanking_mode_cb_id),
powerkey_blanking_mode_cb_id = 0;
}

/** Helper for sending powerkey feedback dbus signal
Expand Down Expand Up @@ -267,6 +293,27 @@ static bool powerkey_ignore_action(void)
return ignore_powerkey;
}

/** Blank display according to current powerkey_blanking_mode
*/
static void powerkey_blank_display(void)
{
display_state_t request = MCE_DISPLAY_OFF;

switch( powerkey_blanking_mode ) {
case PWRKEY_BLANK_TO_LPM:
request = MCE_DISPLAY_LPM_ON;
break;

case PWRKEY_BLANK_TO_OFF:
default:
break;
}

execute_datapipe(&display_state_req_pipe,
GINT_TO_POINTER(request),
USE_INDATA, CACHE_INDATA);
}

/**
* Generic logic for key presses
*
Expand Down Expand Up @@ -333,9 +380,7 @@ static void generic_powerkey_handler(poweraction_t action,
GINT_TO_POINTER(LOCK_ON),
USE_INDATA, CACHE_INDATA);

execute_datapipe(&display_state_req_pipe,
GINT_TO_POINTER(MCE_DISPLAY_OFF),
USE_INDATA, CACHE_INDATA);
powerkey_blank_display();
break;

default:
Expand Down
12 changes: 12 additions & 0 deletions powerkey.h
Expand Up @@ -29,6 +29,9 @@
/** Path to the powerkey mode GConf setting */
# define MCE_GCONF_POWERKEY_MODE MCE_GCONF_POWERKEY_PATH "/mode"

/** Path to the powerkey blanking mode GConf setting */
# define MCE_GCONF_POWERKEY_BLANKING_MODE MCE_GCONF_POWERKEY_PATH "/blanking_mode"

/** Power key action enable modes */
typedef enum
{
Expand All @@ -44,6 +47,15 @@ typedef enum
PWRKEY_ENABLE_DEFAULT = PWRKEY_ENABLE_ALWAYS,
} pwrkey_mode_t;

typedef enum
{
/** Pressing power key turns display off */
PWRKEY_BLANK_TO_OFF,

/** Pressing power key puts display to lpm state */
PWRKEY_BLANK_TO_LPM,
} pwrkey_blanking_mode_t;

/** Configuration value used for the disabled policy */
#define POWER_DISABLED_STR "disabled"

Expand Down
44 changes: 44 additions & 0 deletions tools/mcetool.c
Expand Up @@ -2293,6 +2293,41 @@ static void xmce_get_powerkey_action(void)
printf("%-"PAD1"s %s \n", "Powerkey wakeup policy:", txt ?: "unknown");
}

/** Lookup table for powerkey blanking modess
*/
static const symbol_t powerkey_blanking[] = {
{ "off", PWRKEY_BLANK_TO_OFF },
{ "lpm", PWRKEY_BLANK_TO_LPM },
{ NULL, -1 }
};

/** Set powerkey wakeup mode
*
* @param args string that can be parsed to powerkey wakeup mode
*/
static bool xmce_set_powerkey_blanking(const char *args)
{
debugf("%s(%s)\n", __FUNCTION__, args);
int val = lookup(powerkey_blanking, args);
if( val < 0 ) {
errorf("%s: invalid powerkey blanking value\n", args);
exit(EXIT_FAILURE);
}
mcetool_gconf_set_int(MCE_GCONF_POWERKEY_BLANKING_MODE, val);
return true;
}

/** Get current powerkey wakeup mode from mce and print it out
*/
static void xmce_get_powerkey_blanking(void)
{
gint val = 0;
const char *txt = 0;
if( mcetool_gconf_get_int(MCE_GCONF_POWERKEY_BLANKING_MODE, &val) )
txt = rlookup(powerkey_blanking, val);
printf("%-"PAD1"s %s \n", "Powerkey blanking mode:", txt ?: "unknown");
}

/* ------------------------------------------------------------------------- *
* doubletab
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -2939,6 +2974,7 @@ static bool xmce_get_status(const char *args)
xmce_get_doubletap_mode();
xmce_get_doubletap_wakeup();
xmce_get_powerkey_action();
xmce_get_powerkey_blanking();
xmce_get_low_power_mode();
xmce_get_als_mode();
xmce_get_ps_mode();
Expand Down Expand Up @@ -3251,6 +3287,14 @@ static const mce_opt_t options[] =
"set the doubletap wakeup mode; valid modes are:\n"
"'never', 'always', 'proximity'\n"
},
{
.name = "set-powerkey-blanking",
.with_arg = xmce_set_powerkey_blanking,
.values = "off|lpm",
.usage =
"set the doubletap blanking mode; valid modes are:\n"
"'off', 'lpm'\n"
},
{
.name = "enable-radio",
.flag = 'r',
Expand Down

0 comments on commit 97ae90c

Please sign in to comment.