Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[tklock] Add setting for tweaking volume key input policy. Contribute…
…s to JB#31567

A lot of users think that volume keys should be reserved for adjusting
media volume only.

While it is not yet possible to adjust how ui interprets volume key
presses, we can stop ui from getting any unless there is ongoing music
playback and thus effectively limiting volume keys to only adjusting
media volume.

Add setting for selecting volume key input policy. By default the volume
keys work just as before, but this can be changed via mcetool option:
  --set-volume-key-policy=<default|media-only>

The value of the setting persists over mce / device restarts.
  • Loading branch information
spiiroin committed Sep 30, 2015
1 parent 9a91abe commit 3ff05a5
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builtin-gconf.c
Expand Up @@ -1250,6 +1250,11 @@ static const setting_t gconf_defaults[] =
.type = "i",
.def = "1",
},
{
.key = MCE_GCONF_TK_VOLKEY_POLICY,
.type = "i",
.def = G_STRINGIFY(DEFAULT_VOLKEY_POLICY),
},
{
.key = MCE_GCONF_LPMUI_TRIGGERING,
.type = "i",
Expand Down
28 changes: 28 additions & 0 deletions tklock.c
Expand Up @@ -400,6 +400,10 @@ static gint doubletap_gesture_policy = DBLTAP_ACTION_DEFAULT;
/** GConf callback ID for doubletap_gesture_policy */
static guint doubletap_gesture_policy_cb_id = 0;

/** Volume key input policy */
static gint volkey_policy = DEFAULT_VOLKEY_POLICY;
static guint volkey_policy_cb_id = 0;

/** Touchscreen double tap gesture enable mode */
static gint doubletap_enable_mode = DBLTAP_ENABLE_DEFAULT;
/** GConf callback ID for doubletap_enable_mode */
Expand Down Expand Up @@ -4026,6 +4030,16 @@ static void tklock_evctrl_rethink(void)

bool grab_kp = !enable_kp;

switch( volkey_policy ) {
case VOLKEY_POLICY_MEDIA_ONLY:
if( !music_playback )
grab_kp = true;
break;

default:
break;
}

if( !tk_input_policy_enabled )
grab_kp = false;

Expand Down Expand Up @@ -4315,6 +4329,10 @@ static void tklock_gconf_cb(GConfClient *const gcc, const guint id,
tklock_gconf_sanitize_doubletap_gesture_policy();
tklock_evctrl_rethink();
}
else if( id == volkey_policy_cb_id ) {
volkey_policy = gconf_value_get_int(gcv);
tklock_evctrl_rethink();
}
else if( id == tklock_lid_open_actions_cb_id ) {
tklock_lid_open_actions = gconf_value_get_int(gcv);
tklock_gconf_sanitize_lid_open_actions();
Expand Down Expand Up @@ -4502,6 +4520,13 @@ static void tklock_gconf_init(void)

tklock_gconf_sanitize_doubletap_gesture_policy();

/* Volume key input policy */
mce_gconf_track_int(MCE_GCONF_TK_VOLKEY_POLICY,
&volkey_policy,
DEFAULT_VOLKEY_POLICY,
tklock_gconf_cb,
&volkey_policy_cb_id);

/* Lid sensor open policy */
mce_gconf_track_int(MCE_GCONF_TK_LID_OPEN_ACTIONS,
&tklock_lid_open_actions,
Expand Down Expand Up @@ -4688,6 +4713,9 @@ static void tklock_gconf_quit(void)
mce_gconf_notifier_remove(doubletap_gesture_policy_cb_id),
doubletap_gesture_policy_cb_id = 0;

mce_gconf_notifier_remove(volkey_policy_cb_id),
volkey_policy_cb_id = 0;

mce_gconf_notifier_remove(tklock_lid_open_actions_cb_id),
tklock_lid_open_actions_cb_id = 0;

Expand Down
13 changes: 13 additions & 0 deletions tklock.h
Expand Up @@ -198,6 +198,19 @@ typedef enum {
# define MINIMUM_AUTOLOCK_DELAY 0
# define MAXIMUM_AUTOLOCK_DELAY 600000

/** Volume key input policy modes */
typedef enum {
/** Default rules apply */
VOLKEY_POLICY_DEFAULT = 0,

/** Volume keys are enabled only when there is music playback. */
VOLKEY_POLICY_MEDIA_ONLY = 1,
} volkey_policy_t;

/** Volume key input policy setting */
#define MCE_GCONF_TK_VOLKEY_POLICY MCE_GCONF_LOCK_PATH "/volume_key_input_policy"
#define DEFAULT_VOLKEY_POLICY 0 // = VOLKEY_POLICY_DEFAULT

/** Automatic lpm triggering modes */
enum
{
Expand Down
52 changes: 52 additions & 0 deletions tools/mcetool.c
Expand Up @@ -4191,6 +4191,44 @@ static void xmce_get_display_off_override(void)
printf("%-"PAD1"s %s \n", "Display off override mode:", txt ?: "unknown");
}

/* ------------------------------------------------------------------------- *
* volkey input policy
* ------------------------------------------------------------------------- */

/** Lookup table for volkey input policies
*/
static const symbol_t volkey_input_policies[] = {
{ "default", VOLKEY_POLICY_DEFAULT },
{ "media-only", VOLKEY_POLICY_MEDIA_ONLY },
{ NULL, -1 }
};

/** Set volkey input policy
*
* @param args input policy name
*/
static bool xmce_set_volkey_policy(const char *args)
{
int val = lookup(volkey_input_policies, args);
if( val < 0 ) {
errorf("%s: invalid volkey input policy value\n", args);
return false;
}
mcetool_gconf_set_int(MCE_GCONF_TK_VOLKEY_POLICY, val);
return true;
}

/** Show current volkey input policy
*/
static void xmce_get_volkey_policy(void)
{
gint val = 0;
const char *txt = 0;
if( mcetool_gconf_get_int(MCE_GCONF_TK_VOLKEY_POLICY, &val) )
txt = rlookup(volkey_input_policies, val);
printf("%-"PAD1"s %s \n", "Volumekey input policy:", txt ?: "unknown");
}

/* ------------------------------------------------------------------------- *
* doubletab
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -5076,6 +5114,7 @@ static bool xmce_get_status(const char *args)
xmce_get_lockscreen_unblank_animation();
xmce_get_doubletap_mode();
xmce_get_doubletap_wakeup();
xmce_get_volkey_policy();
xmce_get_powerkey_action();
xmce_get_powerkey_blanking();
xmce_get_powerkey_long_press_delay();
Expand Down Expand Up @@ -5477,6 +5516,19 @@ static const mce_opt_t options[] =
"\n"
"Note: proximity setting applies for lid sensor too."
},
{
.name = "set-volume-key-policy",
.with_arg = xmce_set_volkey_policy,
.values = "default|media-only",
.usage =
"set the volume key input policy; valid modes are:\n"
"\n"
" default - Volume keys are enabled when display is on\n"
" or audio policy indicates music playback\n"
"\n"
" media-only - Volume keys are enabled only when there is\n"
" music playback.\n"
},
{
.name = "set-powerkey-action",
.flag = 'Z',
Expand Down

0 comments on commit 3ff05a5

Please sign in to comment.