Commit 6154e96c authored by spiiroin's avatar spiiroin

Rewrite powerkey handler to allow more flexible configuration

Taking double powerkey presses in use caused unconditional delay for
single press handling. The actions that could be configured to be taken
were not be differentiated based on display state, which made it
impossible do one thing from display off and another one from display on.
And since static configuration was used, changes did not take effect
without restarting mce.

Make possible actions as small and simple as possible. Allow combining
them freely to choose actions taken. Use separate action combinations
depending on whether display is on or off. Execute common parts of
single and double press actions immediately when 1st powerkey press
is released.

Allow more flexibility for using custom dbus actions by allowing user
configured method call to be made instead of signal broadcast.

Use dynamic runtime changeable settings instead of static configuration
from ini-files and add options to mcetool for changing all of them.

Use the new functionality to:
- apply device lock when double press is made from display on
- unblank and hide lockscreen when double press is made from display off

[mce] Rewrite powerkey handler to allow more flexible configuration. Fixes JB#23653
parent 06958408
......@@ -567,6 +567,9 @@ NORMALIZE_USES_SPC =\
modules/radiostates.h\
modules/sensor-gestures.c\
ofono-dbus-names.h\
powerkey.c\
powerkey.h\
powerkey.dot\
systemui/dbus-names.h\
tklock.c\
tklock.h\
......@@ -616,8 +619,6 @@ NORMALIZE_USES_TAB =\
modules/proximity.c\
modules/proximity.h\
modules/radiostates.c\
powerkey.c\
powerkey.h\
systemui/tklock-dbus-names.h\
NORMALIZE_KNOWN := $(NORMALIZE_USES_SPC) $(NORMALIZE_USES_TAB)
......
......@@ -1482,6 +1482,56 @@ static const setting_t gconf_defaults[] =
.type = "i",
.def = "333",
},
{
.key = MCE_GCONF_POWERKEY_LONG_PRESS_DELAY,
.type = "i",
.def = G_STRINGIFY(DEFAULT_POWERKEY_LONG_DELAY),
},
{
.key = MCE_GCONF_POWERKEY_DOUBLE_PRESS_DELAY,
.type = "i",
.def = G_STRINGIFY(DEFAULT_POWERKEY_DOUBLE_DELAY),
},
{
.key = MCE_GCONF_POWERKEY_ACTIONS_SINGLE_ON,
.type = "s",
.def = DEFAULT_POWERKEY_ACTIONS_SINGLE_ON,
},
{
.key = MCE_GCONF_POWERKEY_ACTIONS_DOUBLE_ON,
.type = "s",
.def = DEFAULT_POWERKEY_ACTIONS_DOUBLE_ON,
},
{
.key = MCE_GCONF_POWERKEY_ACTIONS_LONG_ON,
.type = "s",
.def = DEFAULT_POWERKEY_ACTIONS_LONG_ON,
},
{
.key = MCE_GCONF_POWERKEY_ACTIONS_SINGLE_OFF,
.type = "s",
.def = DEFAULT_POWERKEY_ACTIONS_SINGLE_OFF,
},
{
.key = MCE_GCONF_POWERKEY_ACTIONS_DOUBLE_OFF,
.type = "s",
.def = DEFAULT_POWERKEY_ACTIONS_DOUBLE_OFF,
},
{
.key = MCE_GCONF_POWERKEY_ACTIONS_LONG_OFF,
.type = "s",
.def = DEFAULT_POWERKEY_ACTIONS_LONG_OFF,
},
{
.key = MCE_GCONF_POWERKEY_DBUS_ACTION1,
.type = "s",
.def = DEFAULT_POWERKEY_DBUS_ACTION1,
},
{
.key = MCE_GCONF_POWERKEY_DBUS_ACTION2,
.type = "s",
.def = DEFAULT_POWERKEY_DBUS_ACTION2,
},
{
.key = MCE_GCONF_MEMNOTIFY_WARNING_USED,
.type = "i",
......
......@@ -29,71 +29,6 @@ Modules=radiostates;filter-brightness-als;display;keypad;led;battery-upower;inac
# Timeout in milliseconds, default 800
HomeKeyLongDelay=800
[PowerKey]
# Timeout before keypress is regarded as a medium press
# This delay is used when powering up from charging
#
# Timeout in milliseconds, default 1000
PowerKeyMediumDelay=1000
# Timeout before keypress is regarded as a long press
#
# Timeout in milliseconds, default 1500
PowerKeyLongDelay=1500
# Timeout for double keypresses
#
# Timeout in milliseconds, default 500
PowerKeyDoubleDelay=500
# Short [power] behaviour
#
# WARNING:
# Setting short, long, and double press to disabled will make it
# near impossible to turn off your device without removing the battery!
#
# Valid options:
# disabled - do nothing on short press
# poweroff - shutdown device
# softpoweroff - enter soft poweroff mode
# tklock-lock - lock touchscreen/keypad lock if not locked
# tklock-unlock - unlock the touchscreen/keypad lock if locked
# tklock-both - lock the touchscreen/keypad if not locked,
# unlock the touchscreen/keypad lock if locked
# dbus-signal-<signal name> - send a D-Bus signal with the name <signal name>
PowerKeyShortAction=tklock-lock
# Long [power] behaviour
#
# Valid options:
# disabled - do nothing on long press
# poweroff - shutdown device <default>
# softpoweroff - enter soft poweroff mode
# tklock-lock - lock touchscreen/keypad lock if not locked
# tklock-unlock - unlock the touchscreen/keypad lock if locked
# tklock-both - lock the touchscreen/keypad if not locked,
# unlock the touchscreen/keypad lock if locked
# dbus-signal-<signal name> - send a D-Bus signal with the name <signal name>
PowerKeyLongAction=poweroff
# Double press [power] behaviour
# Note: the double press action is triggered on press, rather than release,
# to avoid the second press to be processed elsewhere before the
# double press action has taken place
#
# Valid options:
# disabled - do nothing on double press <default>
# poweroff - shutdown device
# softpoweroff - enter soft poweroff mode
# tklock-lock - lock touchscreen/keypad lock if not locked
# tklock-unlock - unlock the touchscreen/keypad lock if locked
# tklock-both - lock the touchscreen/keypad if not locked,
# unlock the touchscreen/keypad lock if locked
# dbus-signal-<signal name> - send a D-Bus signal with the name <signal name>
# PowerKeyDoubleAction=dbus-signal-powerkey_double_ind
PowerKeyDoubleAction=disabled
[SoftPowerOff]
# Charger connect policy
......
This diff is collapsed.
/* -*- mode: c -*- */
/* Extra documentation for state transitions made while
* handling power key presses.
*
* To create PNG image, execute:
* dot -Tpng powerkey.dot -o powerkey.png
*/
digraph display_state_machine {
fontsize=10;
label = "MCE POWERKEY STATE MACHINE";
nodesep=0.3;
ranksep=0.2;
node[fontsize=6];
edge[fontsize=6];
edge[arrowsize=0.3];
node[style=filled,fillcolor=skyblue,shape=box];
node[width=0.00001];
node[height=0.00001];
node[fillcolor=yellow];
IDLE;
PRESSED;
RELEASED;
node[shape=oval,fillcolor=pink];
IDLE -> IDLE [label=" released"];
IDLE -> PRESSED [label=" pressed:\l start long press timer\l"];
PRESSED -> IDLE [label=" long press timeout:\l execute long press actions\l"];
PRESSED -> RELEASED [label=" released:\l stop long press timer\l execute common actions\l start double press timer\l"];
RELEASED -> IDLE [label=" double press timeout:\l execute single press actions\l"];
RELEASED -> IDLE [label=" pressed:\l stop double press timer\l execute double press actions\l"];
}
......@@ -26,137 +26,108 @@
/** Path to the GConf settings for the powerkey module */
# define MCE_GCONF_POWERKEY_PATH "/system/osso/dsm/powerkey"
/** Path to the powerkey mode GConf setting */
# define MCE_GCONF_POWERKEY_MODE MCE_GCONF_POWERKEY_PATH "/mode"
/** Powerkey mode 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"
/** Powerkey blanking mode setting */
# define MCE_GCONF_POWERKEY_BLANKING_MODE MCE_GCONF_POWERKEY_PATH "/blanking_mode"
/** Powerkey press count for proximity sensor override */
# define MCE_GCONF_POWERKEY_PS_OVERRIDE_COUNT MCE_GCONF_POWERKEY_PATH "/ps_override_count"
# define MCE_GCONF_POWERKEY_PS_OVERRIDE_COUNT MCE_GCONF_POWERKEY_PATH "/ps_override_count"
/** Maximum delay between powerkey presses for ps override */
# define MCE_GCONF_POWERKEY_PS_OVERRIDE_TIMEOUT MCE_GCONF_POWERKEY_PATH "/ps_override_timeout"
/** Power key action enable modes */
typedef enum
{
/** Power key actions disabled */
PWRKEY_ENABLE_NEVER,
/** Power key actions always enabled */
PWRKEY_ENABLE_ALWAYS,
/** Power key actions enabled if PS is not covered */
PWRKEY_ENABLE_NO_PROXIMITY,
/** Power key actions enabled if PS is not covered or display is on */
PWRKEY_ENABLE_NO_PROXIMITY2,
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"
/** Long press timeout setting */
# define MCE_GCONF_POWERKEY_LONG_PRESS_DELAY MCE_GCONF_POWERKEY_PATH "/long_press_delay"
/** Configuration value used for the device menu policy */
#define POWER_MENU_STR "menu"
/** Double press timeout setting */
# define MCE_GCONF_POWERKEY_DOUBLE_PRESS_DELAY MCE_GCONF_POWERKEY_PATH "/double_press_delay"
/** Configuration value used for poweroff */
#define POWER_POWEROFF_STR "poweroff"
/** Setting for single press actions from display on */
# define MCE_GCONF_POWERKEY_ACTIONS_SINGLE_ON MCE_GCONF_POWERKEY_PATH "/actions_single_on"
/** Configuration value used for soft poweroff */
#define POWER_SOFT_POWEROFF_STR "softpoweroff"
/** Setting for double press actions from display on */
# define MCE_GCONF_POWERKEY_ACTIONS_DOUBLE_ON MCE_GCONF_POWERKEY_PATH "/actions_double_on"
/** Configuration value used for tklock lock */
#define POWER_TKLOCK_UNLOCK_STR "tklock-unlock"
/** Setting for long press actions from display on */
# define MCE_GCONF_POWERKEY_ACTIONS_LONG_ON MCE_GCONF_POWERKEY_PATH "/actions_long_on"
/** Configuration value used for tklock unlock */
#define POWER_TKLOCK_LOCK_STR "tklock-lock"
/** Setting for single press actions from display off */
# define MCE_GCONF_POWERKEY_ACTIONS_SINGLE_OFF MCE_GCONF_POWERKEY_PATH "/actions_single_off"
/** Configuration value used for tklock both */
#define POWER_TKLOCK_BOTH_STR "tklock-both"
/** Setting for double press actions from display off */
# define MCE_GCONF_POWERKEY_ACTIONS_DOUBLE_OFF MCE_GCONF_POWERKEY_PATH "/actions_double_off"
/** Configuration value used for D-Bus signal */
#define POWER_DBUS_SIGNAL_STR "dbus-signal-"
/** Setting for long press actions from display off */
# define MCE_GCONF_POWERKEY_ACTIONS_LONG_OFF MCE_GCONF_POWERKEY_PATH "/actions_long_off"
/** Action to perform on [power] keypress */
typedef enum {
/** Setting for D-Bus action #1 */
# define MCE_GCONF_POWERKEY_DBUS_ACTION1 MCE_GCONF_POWERKEY_PATH "/dbus_action1"
/** No action */
POWER_DISABLED = 0,
/** Setting for D-Bus action #2 */
# define MCE_GCONF_POWERKEY_DBUS_ACTION2 MCE_GCONF_POWERKEY_PATH "/dbus_action2"
/** Show device menu */
POWER_MENU = 1,
/** Default for long press */
DEFAULT_POWERKEY_LONG_ACTION = 2,
/** Shutdown */
POWER_POWEROFF = 2,
/** Soft poweroff */
POWER_SOFT_POWEROFF = 3,
/** Power key action enable modes */
typedef enum
{
/** Power key actions disabled */
PWRKEY_ENABLE_NEVER,
/** Default for short press */
DEFAULT_POWERKEY_SHORT_ACTION = 4,
/** Power key actions always enabled */
PWRKEY_ENABLE_ALWAYS,
/** Lock the TKLock if unlocked */
POWER_TKLOCK_LOCK = 4,
/** Power key actions enabled if PS is not covered */
PWRKEY_ENABLE_NO_PROXIMITY,
/** Unlock the TKLock if locked */
POWER_TKLOCK_UNLOCK = 5,
/** Power key actions enabled if PS is not covered or display is on */
PWRKEY_ENABLE_NO_PROXIMITY2,
/** Lock the TKLock if unlocked, unlock the TKLock if locked */
POWER_TKLOCK_BOTH = 6,
PWRKEY_ENABLE_DEFAULT = PWRKEY_ENABLE_ALWAYS,
} pwrkey_enable_mode_t;
/** Default for double press */
DEFAULT_POWERKEY_DOUBLE_ACTION = 7,
typedef enum
{
/** Pressing power key turns display off */
PWRKEY_BLANK_TO_OFF,
/** Send a D-Bus signal */
POWER_DBUS_SIGNAL = 7
} poweraction_t;
/** Pressing power key puts display to lpm state */
PWRKEY_BLANK_TO_LPM,
} pwrkey_blanking_mode_t;
/** Name of Powerkey configuration group */
#define MCE_CONF_POWERKEY_GROUP "PowerKey"
/** Long delay for the [power] button in milliseconds */
#define DEFAULT_POWERKEY_LONG_DELAY 1500
/** Name of configuration key for medium [power] press delay */
#define MCE_CONF_POWERKEY_MEDIUM_DELAY "PowerKeyMediumDelay"
/** Double press timeout for the [power] button in milliseconds */
#define DEFAULT_POWERKEY_DOUBLE_DELAY 400
/** Name of configuration key for long [power] press delay */
#define MCE_CONF_POWERKEY_LONG_DELAY "PowerKeyLongDelay"
/** Default actions for single press while display is on */
#define DEFAULT_POWERKEY_ACTIONS_SINGLE_ON "blank,tklock"
/** Name of configuration key for double [power] press delay */
#define MCE_CONF_POWERKEY_DOUBLE_DELAY "PowerKeyDoubleDelay"
/** Default actions for double press while display is on */
#define DEFAULT_POWERKEY_ACTIONS_DOUBLE_ON "blank,tklock,devlock"
/** Name of configuration key for short [power] press action */
#define MCE_CONF_POWERKEY_SHORT_ACTION "PowerKeyShortAction"
/** Default actions for long press while display is on */
#define DEFAULT_POWERKEY_ACTIONS_LONG_ON "shutdown"
/** Name of configuration key for long [power] press action */
#define MCE_CONF_POWERKEY_LONG_ACTION "PowerKeyLongAction"
/** Default actions for single press while display is off */
#define DEFAULT_POWERKEY_ACTIONS_SINGLE_OFF "unblank"
/** Name of configuration key for double [power] press action */
#define MCE_CONF_POWERKEY_DOUBLE_ACTION "PowerKeyDoubleAction"
/** Default actions for double press while display is off */
#define DEFAULT_POWERKEY_ACTIONS_DOUBLE_OFF "unblank,tkunlock"
/**
* Long delay for the [power] button in milliseconds; 1.5 seconds
*/
#define DEFAULT_POWER_LONG_DELAY 1500
/** Default actions for long press while display is off
*
* Note: If kernel side reports immediately power key press + release
* when device is suspended, detecting long presses might not
* work when display is off -> leave unset by default. */
#define DEFAULT_POWERKEY_ACTIONS_LONG_OFF ""
/** Medium delay for the [power] button in milliseconds; 1 second */
#define DEFAULT_POWER_MEDIUM_DELAY 1000
/** Default argument for signal sent due to dbus1 action */
#define DEFAULT_POWERKEY_DBUS_ACTION1 "event1"
/** Double press timeout for the [power] button in milliseconds; 0.5 seconds */
#define DEFAULT_POWER_DOUBLE_DELAY 500
/** Default argument for signal sent due to dbus2 action */
#define DEFAULT_POWERKEY_DBUS_ACTION2 "event2"
/* When MCE is made modular, this will be handled differently */
gboolean mce_powerkey_init(void);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment