Skip to content

Commit

Permalink
Merge pull request #221 from spiiroin/jb23653_rewrite_powerkey_handler
Browse files Browse the repository at this point in the history
Rewrite powerkey handler to allow more flexible configuration
  • Loading branch information
spiiroin committed Oct 29, 2014
2 parents b808849 + e74cf6c commit cc58458
Show file tree
Hide file tree
Showing 15 changed files with 3,169 additions and 1,173 deletions.
5 changes: 3 additions & 2 deletions Makefile
Expand Up @@ -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\
Expand Down Expand Up @@ -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)
Expand Down
50 changes: 50 additions & 0 deletions builtin-gconf.c
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions datapipe.c
Expand Up @@ -42,6 +42,9 @@ datapipe_struct led_pattern_activate_pipe;
/** LED pattern to deactivate; read only */
datapipe_struct led_pattern_deactivate_pipe;

/** resumed from suspend notification; read only */
datapipe_struct device_resumed_pipe;

/** Non-synthetized user activity; read only */
datapipe_struct user_activity_pipe;

Expand Down Expand Up @@ -802,6 +805,8 @@ void mce_datapipe_init(void)
0, GINT_TO_POINTER(0));
setup_datapipe(&led_pattern_activate_pipe, READ_ONLY, FREE_CACHE,
0, NULL);
setup_datapipe(&device_resumed_pipe, READ_ONLY, DONT_FREE_CACHE,
0, NULL);
setup_datapipe(&led_pattern_deactivate_pipe, READ_ONLY, FREE_CACHE,
0, NULL);
setup_datapipe(&user_activity_pipe, READ_ONLY, DONT_FREE_CACHE,
Expand Down Expand Up @@ -905,6 +910,7 @@ void mce_datapipe_quit(void)
free_datapipe(&user_activity_pipe);
free_datapipe(&led_pattern_deactivate_pipe);
free_datapipe(&led_pattern_activate_pipe);
free_datapipe(&device_resumed_pipe);
free_datapipe(&led_brightness_pipe);
free_datapipe(&lpm_brightness_pipe);
free_datapipe(&display_brightness_pipe);
Expand Down
1 change: 1 addition & 0 deletions datapipe.h
Expand Up @@ -79,6 +79,7 @@ extern datapipe_struct lpm_brightness_pipe;
extern datapipe_struct device_inactive_pipe;
extern datapipe_struct led_pattern_activate_pipe;
extern datapipe_struct led_pattern_deactivate_pipe;
extern datapipe_struct device_resumed_pipe;
extern datapipe_struct user_activity_pipe;
extern datapipe_struct display_state_pipe;
extern datapipe_struct display_state_req_pipe;
Expand Down
65 changes: 0 additions & 65 deletions inifiles/mce.ini
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions mce-gconf.c
Expand Up @@ -23,6 +23,9 @@

#include "mce-log.h"

#include <stdlib.h>
#include <string.h>

/** Pointer to the GConf client */
static GConfClient *gconf_client = NULL;
/** Is GConf disabled on purpose */
Expand Down Expand Up @@ -412,6 +415,68 @@ void mce_gconf_notifier_remove_cb(gpointer cb_id, gpointer user_data)
mce_gconf_notifier_remove(GPOINTER_TO_INT(cb_id));
}

/** Helper for getting path of gconf key
*/
static gchar *mce_gconf_get_path(const gchar *key)
{
gchar *res = 0;
const gchar *end = strrchr(key, '/');

if( end )
res = g_strndup(key, end - key);

return res;
}

/** Get initial value of integer setting and start tracking changes
*
* @param key key name
* @param val where to store the initial value
* @param def default value to use if getting key value fails;
* or -1 to leave *val unmodified
* @param cb change notification callback
* @param cb_id where to store notification callback id
*/
void mce_gconf_track_int(const gchar *key, gint *val, gint def,
GConfClientNotifyFunc cb, guint *cb_id)
{
gchar *path = mce_gconf_get_path(key);

if( path && cb && cb_id )
mce_gconf_notifier_add(path, key, cb, cb_id);

if( !mce_gconf_get_int(key, val) && def != -1 )
*val = def;

g_free(path);
}

/** Get initial value of integer setting and start tracking changes
*
* Note: Caller must release returned string with g_free() when it
* is no longer needed.
*
* @param key key name
* @param val where to store the initial value
* @param def default value to use if getting key value fails;
* or NULL to leave *val unmodified
* @param cb change notification callback
* @param cb_id where to store notification callback id
*/
void mce_gconf_track_string(const gchar *key, gchar **val, const gchar *def,
GConfClientNotifyFunc cb, guint *cb_id)
{
gchar *path = mce_gconf_get_path(key);

if( path && cb && cb_id )
mce_gconf_notifier_add(path, key, cb, cb_id);

if( !mce_gconf_get_string(key, val) && def != 0 )
*val = g_strdup(def);

g_free(path);
}

/**
* Init function for the mce-gconf component
*
Expand Down
5 changes: 5 additions & 0 deletions mce-gconf.h
Expand Up @@ -36,6 +36,11 @@ gboolean mce_gconf_notifier_add(const gchar *path, const gchar *key,
void mce_gconf_notifier_remove(guint id);
void mce_gconf_notifier_remove_cb(gpointer cb_id, gpointer user_data);

void mce_gconf_track_int(const gchar *key, gint *val, gint def,
GConfClientNotifyFunc cb, guint *cb_id);
void mce_gconf_track_string(const gchar *key, gchar **val, const gchar *def,
GConfClientNotifyFunc cb, guint *cb_id);

gboolean mce_gconf_init(void);
void mce_gconf_exit(void);

Expand Down
5 changes: 5 additions & 0 deletions mce-io.c
Expand Up @@ -187,6 +187,11 @@ static void io_detect_resume(void)
mce_log(LL_DEVEL, "time skip: assume %"PRId64".%03"PRId64"s suspend",
skip / 1000, skip % 1000);

// notify in case some timers need re-evaluating
execute_datapipe_output_triggers(&device_resumed_pipe,
&prev,
USE_INDATA);

EXIT:
return;
}
Expand Down
1 change: 1 addition & 0 deletions mce.c
Expand Up @@ -156,6 +156,7 @@ static void mce_cleanup_wakelocks(void)
wakelock_unlock("mce_bluez_wait");
wakelock_unlock("mce_led_breathing");
wakelock_unlock("mce_lpm_off");
wakelock_unlock("mce_tklock_notify");
}
#endif // ENABLE_WAKELOCKS

Expand Down

0 comments on commit cc58458

Please sign in to comment.