From 4c99c905bc10c36778b9b681cee9cba51b4e7433 Mon Sep 17 00:00:00 2001 From: Juyeon Lee Date: Mon, 25 Apr 2016 13:31:52 +0900 Subject: [PATCH] rotation: added vconf handler for auto_rotation Change-Id: I8227e47ee75ed6fc3734cb360d7eca8a262aba90 --- packaging/e-mod-tizen-wm-policy.spec | 1 + src/Makefile.am | 4 +- src/rotation/e_mod_rotation.c | 4 ++ src/rotation/e_mod_rotation_settings.c | 81 ++++++++++++++++++++++++++++++++++ src/rotation/e_mod_rotation_settings.h | 8 ++++ src/rotation/e_mod_sensord.c | 11 +++++ src/rotation/e_mod_sensord.h | 1 + 7 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/rotation/e_mod_rotation_settings.c create mode 100644 src/rotation/e_mod_rotation_settings.h diff --git a/packaging/e-mod-tizen-wm-policy.spec b/packaging/e-mod-tizen-wm-policy.spec index c37cc1a..3378b50 100644 --- a/packaging/e-mod-tizen-wm-policy.spec +++ b/packaging/e-mod-tizen-wm-policy.spec @@ -11,6 +11,7 @@ Source0: %{name}-%{version}.tar.bz2 BuildRequires: pkgconfig(enlightenment) BuildRequires: pkgconfig(ttrace) BuildRequires: libsensord-devel +BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(capi-system-device) %if %{with x} BuildRequires: pkgconfig(x11) diff --git a/src/Makefile.am b/src/Makefile.am index 49c916a..6d73298 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,7 +13,9 @@ pkg_LTLIBRARIES = module.la WL_SRC = ROT_SRC = rotation/e_mod_rotation.c \ - rotation/e_mod_rotation.h + rotation/e_mod_rotation.h \ + rotation/e_mod_rotation_settings.c \ + rotation/e_mod_rotation_settings.h if HAVE_AUTO_ROTATION ROT_SRC += rotation/e_mod_sensord.c \ diff --git a/src/rotation/e_mod_rotation.c b/src/rotation/e_mod_rotation.c index 1dc0942..526c06f 100644 --- a/src/rotation/e_mod_rotation.c +++ b/src/rotation/e_mod_rotation.c @@ -25,6 +25,8 @@ #include "e_mod_sensord.h" #endif +#include "e_mod_rotation_settings.h" + const static char *_wr_log_dom_name = "e-rot"; int _wr_log_dom = -1; @@ -119,6 +121,7 @@ e_mod_pol_rotation_init(void) if (_wr_log_dom < 0) goto err_log; + e_mod_rot_settings_init(); #ifdef HAVE_AUTO_ROTATION e_mod_sensord_init(); #endif @@ -149,6 +152,7 @@ err_log: EINTERN void e_mod_pol_rotation_shutdown(void) { + e_mod_rot_settings_shutdown(); #ifdef HAVE_AUTO_ROTATION e_mod_sensord_deinit(); #endif diff --git a/src/rotation/e_mod_rotation_settings.c b/src/rotation/e_mod_rotation_settings.c new file mode 100644 index 0000000..39448f7 --- /dev/null +++ b/src/rotation/e_mod_rotation_settings.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * This file is a modified version of BSD licensed file and + * licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Please, see the COPYING file for the original copyright owner and + * license. + */ +#include "e_mod_rotation.h" +#include "e_mod_rotation_settings.h" +#include + +#ifdef HAVE_AUTO_ROTATION +#include "e_mod_sensord.h" +#endif + +static Eina_Bool rot_lock = EINA_FALSE; + +static void +_e_mod_rot_settings_lock(int rot) +{ + E_Zone *zone; + Eina_List *l; + const char *name_hint = "vconf"; + Eina_Bool lock = !rot; + + if (lock == rot_lock) return; + + EINA_LIST_FOREACH(e_comp->zones, l, zone) + { + if (lock) e_zone_rotation_set(zone, 0); +#ifdef HAVE_AUTO_ROTATION + else e_zone_rotation_set(zone, e_mod_sensord_cur_angle_get()); +#endif + e_zone_rotation_block_set(zone, name_hint, lock); + } + rot_lock = lock; +} + +static void +_e_mod_rot_settings_cb_autorotate(keynode_t *node, void *data) +{ + int rot; + + rot = vconf_keynode_get_bool(node); + if (rot < 0) return; + + _e_mod_rot_settings_lock(rot); +} + +/* externally accessible functions */ +EINTERN void +e_mod_rot_settings_init(void) +{ + int rot = 0; + if (vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &rot) == VCONF_OK) + { + vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, + _e_mod_rot_settings_cb_autorotate, + NULL); + // if vconf auto_rotate is false, rotation is blocked + if (rot == 0) _e_mod_rot_settings_lock(rot); + } +} + +EINTERN void +e_mod_rot_settings_shutdown(void) +{ + rot_lock = EINA_FALSE; +} diff --git a/src/rotation/e_mod_rotation_settings.h b/src/rotation/e_mod_rotation_settings.h new file mode 100644 index 0000000..bae8f20 --- /dev/null +++ b/src/rotation/e_mod_rotation_settings.h @@ -0,0 +1,8 @@ +#ifndef E_MOD_ROTATION_SETTINGS_H +#define E_MOD_ROTATION_SETTINGS_H +#include + +EINTERN void e_mod_rot_settings_init(void); +EINTERN void e_mod_rot_settings_shutdown(void); + +#endif diff --git a/src/rotation/e_mod_sensord.c b/src/rotation/e_mod_sensord.c index eff5568..c12d680 100644 --- a/src/rotation/e_mod_sensord.c +++ b/src/rotation/e_mod_sensord.c @@ -15,6 +15,7 @@ struct _Pol_Sensord int retry_count; Eina_Bool lock; Eina_Bool connected; + int angle; }; /* static global variables */ @@ -68,6 +69,7 @@ _sensor_rotation_changed_cb(sensor_t sensor, e_zone_rotation_set(zone, ang); _pol_sensor.event = event; + _pol_sensor.angle = ang; } static Eina_Bool @@ -196,17 +198,26 @@ _sensor_disconnect(void) _pol_sensor.handle = -1; _pol_sensor.connected = EINA_FALSE; + _pol_sensor.angle = -1; ERR("sensord_disconnect succeeded"); return EINA_TRUE; error: return EINA_FALSE; } +EINTERN int +e_mod_sensord_cur_angle_get(void) +{ + if (_pol_sensor.connected) return _pol_sensor.angle; + return -1; +} + EINTERN Eina_Bool e_mod_sensord_init(void) { _pol_sensor.connected = EINA_FALSE; _pol_sensor.retry_count = 0; + _pol_sensor.angle = -1; return _sensor_connect(); } diff --git a/src/rotation/e_mod_sensord.h b/src/rotation/e_mod_sensord.h index 208db19..3b97269 100644 --- a/src/rotation/e_mod_sensord.h +++ b/src/rotation/e_mod_sensord.h @@ -4,5 +4,6 @@ EINTERN Eina_Bool e_mod_sensord_init(void); EINTERN Eina_Bool e_mod_sensord_deinit(void); +EINTERN int e_mod_sensord_cur_angle_get(void); #endif -- 2.7.4