Skip to content

Commit

Permalink
Add setting for enabling/disabling orientation sensor use
Browse files Browse the repository at this point in the history
If orientation sensor is available, mce uses it for generating user
activity (delay automatic display blanking) and detecting device flip
over gestures (snooze alarm, silence incoming call). Sometimes neither
feature is desired, but there is no way to disable use of orientation
sensor.

Add disable/enable setting for using orientation sensor.

By default the setting is enabled, but can be changed for example by
installing hw specific mce configuration files or from command line

  mcetool --set-orientation-sensor-mode=<enabled|disabled>

The setting persists over mce/device restarts.

[mce] Add setting for enabling/disabling orientation sensor use. Fixes JB#27427
  • Loading branch information
spiiroin committed May 5, 2015
1 parent 8db00d9 commit 0e9f8b4
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 6 deletions.
5 changes: 5 additions & 0 deletions builtin-gconf.c
Expand Up @@ -1163,6 +1163,11 @@ static const setting_t gconf_defaults[] =
.type = "ai",
.def = CUSTOM_STRINGIFY(DEFAULT_DISPLAY_DIM_TIMEOUT_LIST),
},
{
.key = MCE_GCONF_ORIENTATION_SENSOR_ENABLED,
.type = "b",
.def = G_STRINGIFY(DEFAULT_ORIENTATION_SENSOR_ENABLED),
},
{
// Hint for settings UI. Not used by MCE itself.
.key = "/system/osso/dsm/display/possible_display_blank_timeouts",
Expand Down
68 changes: 62 additions & 6 deletions modules/display.c
Expand Up @@ -531,6 +531,7 @@ static void mdy_autosuspend_gconf_cb(GConfClient *const client, c

static void mdy_orientation_changed_cb(int state);
static void mdy_orientation_generate_activity(void);
static bool mdy_orientation_sensor_wanted(void);
static void mdy_orientation_sensor_rethink(void);

/* ------------------------------------------------------------------------- *
Expand Down Expand Up @@ -2103,6 +2104,12 @@ static gint mdy_brightness_fade_duration_unblank_ms = DEFAULT_BRIGHTNESS_FADE_UN
/** GConf change notification id for mdy_brightness_fade_duration_unblank_ms */
static guint mdy_brightness_fade_duration_unblank_ms_gconf_cb_id = 0;

/** Use of orientation sensor enabled */
static gboolean mdy_orientation_sensor_enabled = DEFAULT_ORIENTATION_SENSOR_ENABLED;

/** GConf change notification id for mdy_orientation_sensor_enabled */
static guint mdy_orientation_sensor_enabled_gconf_cb_id = 0;

/** Set display brightness via sysfs write */
static void mdy_brightness_set_level_default(int number)
{
Expand Down Expand Up @@ -5254,10 +5261,16 @@ static void mdy_orientation_generate_activity(void)
}
}

/** Start/stop orientation sensor based on display state
/** Check if orientation sensor should be enabled
*/
static void mdy_orientation_sensor_rethink(void)
static bool mdy_orientation_sensor_wanted(void)
{
bool wanted = false;

/* Skip disabled in settings */
if( !mdy_orientation_sensor_enabled )
goto EXIT;

/* Enable orientation sensor in ON|DIM */

/* Start the orientation sensor already when powering up
Expand All @@ -5269,21 +5282,50 @@ static void mdy_orientation_sensor_rethink(void)
case MCE_DISPLAY_ON:
case MCE_DISPLAY_LPM_ON:
case MCE_DISPLAY_POWER_UP:
/* Add notification before enabling to get initial guess */
mce_sensorfw_orient_set_notify(mdy_orientation_changed_cb);
mce_sensorfw_orient_enable();
wanted = true;
break;

default:
case MCE_DISPLAY_UNDEF:
case MCE_DISPLAY_OFF:
case MCE_DISPLAY_LPM_OFF:
case MCE_DISPLAY_POWER_DOWN:
break;
}

EXIT:
return wanted;
}

/** Start/stop orientation sensor based on display state
*/
static void mdy_orientation_sensor_rethink(void)
{
static bool was_enabled = false;

bool enable = mdy_orientation_sensor_wanted();

if( was_enabled == enable )
goto EXIT;

was_enabled = enable;

mce_log(LL_DEBUG, "%s orientation sensor", enable ? "enable" : "disable");

if( enable ) {
/* Add notification before enabling to get initial guess */
mce_sensorfw_orient_set_notify(mdy_orientation_changed_cb);
mce_sensorfw_orient_enable();
}
else {
/* Remove notification after disabling to get final state */
mce_sensorfw_orient_disable();
mce_sensorfw_orient_set_notify(0);
break;
}

EXIT:
return;

}

/* ========================================================================= *
Expand Down Expand Up @@ -7941,6 +7983,10 @@ static void mdy_gconf_cb(GConfClient *const gcc, const guint id,
mce_log(LL_NOTICE, "display off override = %d",
mdy_dbus_display_off_override);
}
else if (id == mdy_orientation_sensor_enabled_gconf_cb_id) {
mdy_orientation_sensor_enabled = gconf_value_get_bool(gcv);
mdy_orientation_sensor_rethink();
}
else {
mce_log(LL_WARN, "Spurious GConf value received; confused!");
}
Expand Down Expand Up @@ -8216,6 +8262,13 @@ static void mdy_gconf_init(void)
DEFAULT_DISPLAY_OFF_OVERRIDE,
mdy_gconf_cb,
&mdy_dbus_display_off_override_gconf_cb_id);

/* Use orientation sensor */
mce_gconf_track_bool(MCE_GCONF_ORIENTATION_SENSOR_ENABLED,
&mdy_orientation_sensor_enabled,
DEFAULT_ORIENTATION_SENSOR_ENABLED,
mdy_gconf_cb,
&mdy_orientation_sensor_enabled_gconf_cb_id);
}

static void mdy_gconf_quit(void)
Expand Down Expand Up @@ -8288,6 +8341,9 @@ static void mdy_gconf_quit(void)
mce_gconf_notifier_remove(mdy_dbus_display_off_override_gconf_cb_id),
mdy_dbus_display_off_override_gconf_cb_id = 0;

mce_gconf_notifier_remove(mdy_orientation_sensor_enabled_gconf_cb_id),
mdy_orientation_sensor_enabled_gconf_cb_id = 0;

/* Free dynamic data obtained from config */

g_slist_free(mdy_possible_dim_timeouts), mdy_possible_dim_timeouts = 0;
Expand Down
6 changes: 6 additions & 0 deletions modules/display.h
Expand Up @@ -305,4 +305,10 @@ enum
/** Default value for MCE_GCONF_DISPLAY_DIM_TIMEOUT_LIST setting */
#define DEFAULT_DISPLAY_DIM_TIMEOUT_LIST 15,30,60,120,180

/** Use Orientation sensor GConf setting */
# define MCE_GCONF_ORIENTATION_SENSOR_ENABLED MCE_GCONF_DISPLAY_PATH"/orientation_sensor_enabled"

/** Default value for MCE_GCONF_ORIENTATION_SENSOR_ENABLED setting */
#define DEFAULT_ORIENTATION_SENSOR_ENABLED true

#endif /* _DISPLAY_H_ */
36 changes: 36 additions & 0 deletions tools/mcetool.c
Expand Up @@ -2450,6 +2450,34 @@ static void xmce_get_lid_sensor_mode(void)
printf("%-"PAD1"s %s\n", "Use lid sensor mode:", txt);
}

/* ------------------------------------------------------------------------- *
* orientation sensor
* ------------------------------------------------------------------------- */

/* Set orientation_sensor use mode
*
* @param args string suitable for interpreting as enabled/disabled
*/
static bool xmce_set_orientation_sensor_mode(const char *args)
{
debugf("%s(%s)\n", __FUNCTION__, args);
gboolean val = xmce_parse_enabled(args);
mcetool_gconf_set_bool(MCE_GCONF_ORIENTATION_SENSOR_ENABLED, val);
return true;
}

/** Get current orientation_sensor mode from mce and print it out
*/
static void xmce_get_orientation_sensor_mode(void)
{
gboolean val = 0;
char txt[32] = "unknown";

if( mcetool_gconf_get_bool(MCE_GCONF_ORIENTATION_SENSOR_ENABLED, &val) )
snprintf(txt, sizeof txt, "%s", val ? "enabled" : "disabled");
printf("%-"PAD1"s %s\n", "Use orientation sensor mode:", txt);
}

/* ------------------------------------------------------------------------- *
* ps
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -4194,6 +4222,7 @@ static bool xmce_get_status(const char *args)
xmce_get_als_mode();
xmce_get_als_input_filter();
xmce_get_als_sample_time();
xmce_get_orientation_sensor_mode();
xmce_get_ps_mode();
xmce_get_ps_blocks_touch();
xmce_get_lid_sensor_mode();
Expand Down Expand Up @@ -4881,6 +4910,13 @@ static const mce_opt_t options[] =
"set the lid sensor mode; valid modes are:\n"
"'enabled' and 'disabled'\n"
},
{
.name = "set-orientation-sensor-mode",
.with_arg = xmce_set_orientation_sensor_mode,
.values = "enabled|disabled",
"set the orientation sensor mode; valid modes are:\n"
"'enabled' and 'disabled'\n"
},
{
.name = "get-color-profile-ids",
.flag = 'a',
Expand Down

0 comments on commit 0e9f8b4

Please sign in to comment.