rotation: added vconf handler for auto_rotation 67/67067/2
authorJuyeon Lee <juyeonne.lee@samsung.com>
Mon, 25 Apr 2016 04:31:52 +0000 (13:31 +0900)
committerDoyoun Kang <doyoun.kang@samsung.com>
Mon, 25 Apr 2016 05:01:35 +0000 (22:01 -0700)
Change-Id: I8227e47ee75ed6fc3734cb360d7eca8a262aba90

packaging/e-mod-tizen-wm-policy.spec
src/Makefile.am
src/rotation/e_mod_rotation.c
src/rotation/e_mod_rotation_settings.c [new file with mode: 0644]
src/rotation/e_mod_rotation_settings.h [new file with mode: 0644]
src/rotation/e_mod_sensord.c
src/rotation/e_mod_sensord.h

index c37cc1a..3378b50 100644 (file)
@@ -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)
index 49c916a..6d73298 100644 (file)
@@ -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 \
index 1dc0942..526c06f 100644 (file)
@@ -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 (file)
index 0000000..39448f7
--- /dev/null
@@ -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 <vconf.h>
+
+#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 (file)
index 0000000..bae8f20
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef E_MOD_ROTATION_SETTINGS_H
+#define E_MOD_ROTATION_SETTINGS_H
+#include <e.h>
+
+EINTERN void e_mod_rot_settings_init(void);
+EINTERN void e_mod_rot_settings_shutdown(void);
+
+#endif
index eff5568..c12d680 100644 (file)
@@ -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();
 }
 
index 208db19..3b97269 100644 (file)
@@ -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