Skip to content

Commit

Permalink
[tklock] Add setting for lid open/close actions. Fixes MER#1202
Browse files Browse the repository at this point in the history
The actions taken when lid sensor indicates that cover is closed or opened
are hard coded without any possibility for users to tweak the behavior.

Add settings for tweaking of actions to taken when cover is closed:
  * disabled - do nothing
  * blank    - just turn off the display
  * tklock   - turn off display and activate lockscreen

Default is 'tklock' and can be changed via:
  mcetool --set-lid-close-actions=<disabled|blank|tklock>


Add settings for tweaking of actions to taken when cover is opened:
  * disabled - do nothing
  * unblank  - just turn on the display
  * tkunlock - turn on display and deactivate lockscreen (if possible)

Default is 'unblank' and can be changed via:
  mcetool --set-lid-open-actions=<disabled|unblank|tkunlock>

The values of the settings persists over mce / device restarts.
  • Loading branch information
spiiroin committed Aug 5, 2015
1 parent 30d4f73 commit a69dd71
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 18 deletions.
10 changes: 10 additions & 0 deletions builtin-gconf.c
Expand Up @@ -1237,6 +1237,16 @@ static const setting_t gconf_defaults[] =
.type = "b",
.def = G_STRINGIFY(DEFAULT_FILTER_LID_WITH_ALS),
},
{
.key = MCE_GCONF_TK_LID_OPEN_ACTIONS,
.type = "i",
.def = G_STRINGIFY(DEFAULT_LID_OPEN_ACTION),
},
{
.key = MCE_GCONF_TK_LID_CLOSE_ACTIONS,
.type = "i",
.def = G_STRINGIFY(DEFAULT_LID_CLOSE_ACTION),
},
{
.key = MCE_GCONF_AUTOLOCK_DELAY,
.type = "i",
Expand Down
129 changes: 111 additions & 18 deletions tklock.c
Expand Up @@ -266,6 +266,8 @@ static void tklock_dtcalib_stop(void);
// settings from gconf

static void tklock_gconf_sanitize_doubletap_gesture_policy(void);
static void tklock_gconf_sanitize_lid_open_actions(void);
static void tklock_gconf_sanitize_lid_close_actions(void);

static void tklock_gconf_cb(GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data);

Expand Down Expand Up @@ -400,6 +402,16 @@ static gint tklock_blank_disable = DEFAULT_TK_AUTO_BLANK_DISABLE;
/** GConf notifier id for tracking tklock_blank_disable changes */
static guint tklock_blank_disable_id = 0;

/** Lid sensor open actions */
static gint tklock_lid_open_actions = DEFAULT_LID_OPEN_ACTION;
/** GConf callback ID for tklock_lid_open_actions */
static guint tklock_lid_open_actions_cb_id = 0;

/** Lid sensor close actions */
static gint tklock_lid_close_actions = DEFAULT_LID_CLOSE_ACTION;
/** GConf callback ID for tklock_lid_close_actions */
static guint tklock_lid_close_actions_cb_id = 0;

/** Flag: Is the lid sensor used for display blanking */
static gboolean lid_sensor_enabled = DEFAULT_LID_SENSOR_ENABLED;
/** GConf callback ID for lid_sensor_enabled */
Expand Down Expand Up @@ -2289,11 +2301,12 @@ static void tklock_lid_sensor_rethink(void)
/* Previous settings toggle; initialize not to match TRUE / FALSE */
static int enabled_prev = -1;

/* Previous action take; initialize to no action taken */
static cover_state_t action_prev = COVER_UNDEF;
/* Previous action taken; initialize to no action taken */
static cover_state_t action_curr = COVER_UNDEF;
cover_state_t action_prev = action_curr;

/* Assume action is based on sensor state */
cover_state_t action_curr = lid_cover_sensor_state;
action_curr = lid_cover_sensor_state;

/* Filter based on disable/enable toggle */
if( !lid_sensor_enabled ) {
Expand Down Expand Up @@ -2366,16 +2379,23 @@ static void tklock_lid_sensor_rethink(void)
/* Then execute the required actions */
switch( action_curr ) {
case COVER_CLOSED:
mce_log(LL_DEVEL, "lid closed - blank");
/* need to se non-zero lux before blanking again */
nonzero_lux_seen_at = 0;
/* lock ui + blank display */
execute_datapipe(&tk_lock_pipe,
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);

/* Blank display + lock ui */
if( tklock_lid_close_actions != LID_CLOSE_ACTION_DISABLED ) {
mce_log(LL_DEVEL, "lid closed - blank");
execute_datapipe(&display_state_req_pipe,
GINT_TO_POINTER(MCE_DISPLAY_OFF),
USE_INDATA, CACHE_INDATA);
}

if( tklock_lid_close_actions == LID_CLOSE_ACTION_TKLOCK ) {
mce_log(LL_DEBUG, "lid closed - tklock");
execute_datapipe(&tk_lock_pipe,
GINT_TO_POINTER(LOCK_ON),
USE_INDATA, CACHE_INDATA);
}
break;

case COVER_OPEN:
Expand All @@ -2385,11 +2405,20 @@ static void tklock_lid_sensor_rethink(void)
break;
}

mce_log(LL_DEVEL, "lid open - unblank");
/* unblank display */
execute_datapipe(&display_state_req_pipe,
GINT_TO_POINTER(MCE_DISPLAY_ON),
USE_INDATA, CACHE_INDATA);
/* Unblank display + unlock ui */
if( tklock_lid_open_actions != LID_OPEN_ACTION_DISABLED ) {
mce_log(LL_DEVEL, "lid open - unblank");
execute_datapipe(&display_state_req_pipe,
GINT_TO_POINTER(MCE_DISPLAY_ON),
USE_INDATA, CACHE_INDATA);
}

if( tklock_lid_open_actions == LID_OPEN_ACTION_TKUNLOCK ) {
mce_log(LL_DEBUG, "lid open - untklock");
execute_datapipe(&tk_lock_pipe,
GINT_TO_POINTER(LOCK_OFF),
USE_INDATA, CACHE_INDATA);
}
break;

default:
Expand All @@ -2398,8 +2427,6 @@ static void tklock_lid_sensor_rethink(void)
break;
}

action_prev = action_curr;

EXIT:
return;
}
Expand Down Expand Up @@ -3945,6 +3972,38 @@ static void tklock_gconf_sanitize_doubletap_gesture_policy(void)
}
}

static void tklock_gconf_sanitize_lid_open_actions(void)
{
switch( tklock_lid_open_actions ) {
case LID_OPEN_ACTION_DISABLED:
case LID_OPEN_ACTION_UNBLANK:
case LID_OPEN_ACTION_TKUNLOCK:
break;

default:
mce_log(LL_WARN, "Lid open has invalid policy: %d; "
"using default", tklock_lid_open_actions);
tklock_lid_open_actions = DEFAULT_LID_OPEN_ACTION;
break;
}
}

static void tklock_gconf_sanitize_lid_close_actions(void)
{
switch( tklock_lid_close_actions ) {
case LID_CLOSE_ACTION_DISABLED:
case LID_CLOSE_ACTION_BLANK:
case LID_CLOSE_ACTION_TKLOCK:
break;

default:
mce_log(LL_WARN, "Lid close has invalid policy: %d; "
"using default", tklock_lid_close_actions);
tklock_lid_close_actions = DEFAULT_LID_CLOSE_ACTION;
break;
}
}

/** GConf callback for touchscreen/keypad lock related settings
*
* @param gcc Unused
Expand Down Expand Up @@ -3997,6 +4056,16 @@ static void tklock_gconf_cb(GConfClient *const gcc, const guint id,
tklock_gconf_sanitize_doubletap_gesture_policy();
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();
tklock_evctrl_rethink();
}
else if( id == tklock_lid_close_actions_cb_id ) {
tklock_lid_close_actions = gconf_value_get_int(gcv);
tklock_gconf_sanitize_lid_close_actions();
tklock_evctrl_rethink();
}
else if( id == tklock_blank_disable_id ) {
gint old = tklock_blank_disable;

Expand Down Expand Up @@ -4151,6 +4220,24 @@ static void tklock_gconf_init(void)

tklock_gconf_sanitize_doubletap_gesture_policy();

/* Lid sensor open policy */
mce_gconf_track_int(MCE_GCONF_TK_LID_OPEN_ACTIONS,
&tklock_lid_open_actions,
DEFAULT_LID_OPEN_ACTION,
tklock_gconf_cb,
&tklock_lid_open_actions_cb_id);

tklock_gconf_sanitize_lid_open_actions();

/* Lid sensor close policy */
mce_gconf_track_int(MCE_GCONF_TK_LID_CLOSE_ACTIONS,
&tklock_lid_close_actions,
DEFAULT_LID_CLOSE_ACTION,
tklock_gconf_cb,
&tklock_lid_close_actions_cb_id);

tklock_gconf_sanitize_lid_close_actions();

/** Touchscreen double tap gesture mode */
mce_gconf_track_int(MCE_GCONF_DOUBLETAP_MODE,
&doubletap_enable_mode,
Expand Down Expand Up @@ -4279,6 +4366,12 @@ 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(tklock_lid_open_actions_cb_id),
tklock_lid_open_actions_cb_id = 0;

mce_gconf_notifier_remove(tklock_lid_close_actions_cb_id),
tklock_lid_close_actions_cb_id = 0;

mce_gconf_notifier_remove(tk_autolock_enabled_cb_id),
tk_autolock_enabled_cb_id = 0;

Expand Down
36 changes: 36 additions & 0 deletions tklock.h
Expand Up @@ -124,6 +124,42 @@ typedef enum
#define MCE_GCONF_FILTER_LID_WITH_ALS MCE_GCONF_LOCK_PATH"/filter_lid_with_als"
#define DEFAULT_FILTER_LID_WITH_ALS true

/** Lid sensor open actions */
typedef enum
{
/** Actions disabled */
LID_OPEN_ACTION_DISABLED = 0,

/** Just show lockscreen */
LID_OPEN_ACTION_UNBLANK = 1,

/* Deactivate lockscreen */
LID_OPEN_ACTION_TKUNLOCK = 2,

} lid_open_action_t;

/** Lid sensor open action GConf setting */
#define MCE_GCONF_TK_LID_OPEN_ACTIONS MCE_GCONF_LOCK_PATH "/lid_open_actions"
#define DEFAULT_LID_OPEN_ACTION 1 // = LID_OPEN_ACTION_UNBLANK

/** Lid sensor close actions */
typedef enum
{
/** Actions disabled */
LID_CLOSE_ACTION_DISABLED = 0,

/** Just blank screen */
LID_CLOSE_ACTION_BLANK = 1,

/* Activate lockscreen */
LID_CLOSE_ACTION_TKLOCK = 2,

} lid_close_action_t;

/** Lid sensor close action GConf setting */
#define MCE_GCONF_TK_LID_CLOSE_ACTIONS MCE_GCONF_LOCK_PATH "/lid_close_actions"
#define DEFAULT_LID_CLOSE_ACTION 2 // = LID_CLOSE_ACTION_TKLOCK

/** Autolock delay GConf setting [ms]*/
# define MCE_GCONF_AUTOLOCK_DELAY MCE_GCONF_LOCK_PATH "/autolock_delay"
# define DEFAULT_AUTOLOCK_DELAY 30000
Expand Down
90 changes: 90 additions & 0 deletions tools/mcetool.c
Expand Up @@ -2754,6 +2754,76 @@ static void xmce_get_lid_sensor_mode(void)
printf("%-"PAD1"s %s\n", "Use lid sensor mode:", txt);
}

/** Lookup table for lid open actions
*/
static const symbol_t lid_open_actions[] = {
{ "disabled", LID_OPEN_ACTION_DISABLED },
{ "unblank", LID_OPEN_ACTION_UNBLANK },
{ "tkunlock", LID_OPEN_ACTION_TKUNLOCK },
{ NULL, -1 }
};

/** Set lid open actions
*
* @param args string that can be parsed to lid open actions
*/
static bool xmce_set_lid_open_actions(const char *args)
{
int val = lookup(lid_open_actions, args);
if( val < 0 ) {
errorf("%s: invalid lid open actions\n", args);
exit(EXIT_FAILURE);
}
mcetool_gconf_set_int(MCE_GCONF_TK_LID_OPEN_ACTIONS, val);
return true;
}

/** Get current lid open actions from mce and print it out
*/
static void xmce_get_lid_open_actions(void)
{
gint val = 0;
const char *txt = 0;
if( mcetool_gconf_get_int(MCE_GCONF_TK_LID_OPEN_ACTIONS, &val) )
txt = rlookup(lid_open_actions, val);
printf("%-"PAD1"s %s \n", "Lid open actions:", txt ?: "unknown");
}

/** Lookup table for lid close actions
*/
static const symbol_t lid_close_actions[] = {
{ "disabled", LID_CLOSE_ACTION_DISABLED },
{ "blank", LID_CLOSE_ACTION_BLANK },
{ "tklock", LID_CLOSE_ACTION_TKLOCK },
{ NULL, -1 }
};

/** Set lid close actions
*
* @param args string that can be parsed to lid close actions
*/
static bool xmce_set_lid_close_actions(const char *args)
{
int val = lookup(lid_close_actions, args);
if( val < 0 ) {
errorf("%s: invalid lid close actions\n", args);
exit(EXIT_FAILURE);
}
mcetool_gconf_set_int(MCE_GCONF_TK_LID_CLOSE_ACTIONS, val);
return true;
}

/** Get current lid close actions from mce and print it out
*/
static void xmce_get_lid_close_actions(void)
{
gint val = 0;
const char *txt = 0;
if( mcetool_gconf_get_int(MCE_GCONF_TK_LID_CLOSE_ACTIONS, &val) )
txt = rlookup(lid_close_actions, val);
printf("%-"PAD1"s %s \n", "Lid close actions:", txt ?: "unknown");
}

/* ------------------------------------------------------------------------- *
* orientation sensor
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -4581,6 +4651,8 @@ static bool xmce_get_status(const char *args)
xmce_get_ps_acts_as_lid();
xmce_get_lid_sensor_mode();
xmce_get_filter_lid_with_als();
xmce_get_lid_open_actions();
xmce_get_lid_close_actions();
xmce_get_dim_timeouts();
xmce_get_brightness_fade();
xmce_get_suspend_policy();
Expand Down Expand Up @@ -5280,6 +5352,24 @@ static const mce_opt_t options[] =
"set the lid sensor mode; valid modes are:\n"
"'enabled' and 'disabled'\n"
},
{
.name = "set-lid-open-actions",
.with_arg = xmce_set_lid_open_actions,
.values = "disabled|unblank|tkunlock",
"set the lid open actions; valid modes are:\n"
"'disabled' ignore lid open\n"
"'unblank' unblank (and show lockscreen)\n"
"'tkunlock' unblank and deactivate lockscreen (if possible)\n"
},
{
.name = "set-lid-close-actions",
.with_arg = xmce_set_lid_close_actions,
.values = "disabled|blank|tklock",
"set the lid close actions; valid modes are:\n"
"'disabled' ignore lid close\n"
"'blank' blank display\n"
"'tklock' blank display and activate lockscreen\n"
},
{
.name = "set-filter-lid-with-als",
.with_arg = xmce_set_filter_lid_with_als,
Expand Down

0 comments on commit a69dd71

Please sign in to comment.