4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
33 #include "appcore-internal.h"
35 #define _MAKE_ATOM(a, s) \
37 a = ecore_x_atom_get(s); \
39 _ERR("##s creation failed.\n"); \
42 #define STR_ATOM_ROTATION_LOCK "_E_ROTATION_LOCK"
44 static Ecore_X_Atom ATOM_ROTATION_LOCK = 0;
45 static Ecore_X_Window root;
49 int (*callback) (enum appcore_rm, void *);
56 struct ui_wm_rotate* wm_rotate;
58 static struct rot_s rot;
61 enum accelerometer_rotate_state re;
65 static struct rot_evt re_to_rm[] = {
68 APPCORE_RM_PORTRAIT_NORMAL,
72 APPCORE_RM_LANDSCAPE_NORMAL,
76 APPCORE_RM_PORTRAIT_REVERSE,
80 APPCORE_RM_LANDSCAPE_REVERSE,
84 static enum appcore_rm __get_mode(int event_data)
89 m = APPCORE_RM_UNKNOWN;
91 for (i = 0; i < sizeof(re_to_rm) / sizeof(re_to_rm[0]); i++) {
92 if (re_to_rm[i].re == event_data) {
101 static void __changed_cb(unsigned int event_type, sensor_event_data_t *event,
111 if (event_type != ACCELEROMETER_EVENT_ROTATION_CHECK) {
116 cb_event_data = (int *)(event->event_data);
118 m = __get_mode(*cb_event_data);
120 _DBG("[APP %d] Rotation: %d -> %d", getpid(), rot.mode, m);
123 if (rot.cb_set && rot.mode != m) {
124 _DBG("[APP %d] Rotation: %d -> %d", getpid(), rot.mode, m);
125 rot.callback(m, data);
131 static void __lock_cb(keynode_t *node, void *data)
137 rot.lock = !vconf_keynode_get_bool(node);
140 m = APPCORE_RM_PORTRAIT_NORMAL;
142 rot.callback(m, data);
145 _DBG("[APP %d] Rotation locked", getpid());
149 _DBG("[APP %d] Rotation unlocked", getpid());
152 r = appcore_get_rotation_state(&m);
153 _DBG("[APP %d] Rotmode prev %d -> curr %d", getpid(),
155 if (!r && rot.mode != m) {
156 rot.callback(m, data);
163 static void __add_rotlock(void *data)
169 r = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
171 _DBG("[APP %d] Rotation vconf get bool failed", getpid());
176 vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb,
180 static void __del_rotlock(void)
182 vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb);
186 EXPORT_API int appcore_set_rotation_cb(int (*cb) (enum appcore_rm, void *),
190 return rot.wm_rotate->set_rotation_cb(cb, data);
201 if (rot.callback != NULL) {
206 handle = sf_connect(ACCELEROMETER_SENSOR);
208 _ERR("sf_connect failed: %d", handle);
212 r = sf_register_event(handle, ACCELEROMETER_EVENT_ROTATION_CHECK,
213 NULL, __changed_cb, data);
215 _ERR("sf_register_event failed: %d", r);
216 sf_disconnect(handle);
224 r = sf_start(handle, 0);
226 _ERR("sf_start failed: %d", r);
227 r = sf_unregister_event(handle, ACCELEROMETER_EVENT_ROTATION_CHECK);
229 _ERR("sf_unregister_event failed: %d", r);
235 sf_disconnect(handle);
243 _MAKE_ATOM(ATOM_ROTATION_LOCK, STR_ATOM_ROTATION_LOCK );
244 root = ecore_x_window_root_first_get();
245 XSelectInput(ecore_x_display_get(), root, PropertyChangeMask);
250 EXPORT_API int appcore_unset_rotation_cb(void)
253 return rot.wm_rotate->unset_rotation_cb();
258 _retv_if(rot.callback == NULL, 0);
263 r = sf_unregister_event(rot.handle,
264 ACCELEROMETER_EVENT_ROTATION_CHECK);
266 _ERR("sf_unregister_event failed: %d", r);
274 if (rot.sf_started == 1) {
275 r = sf_stop(rot.handle);
277 _ERR("sf_stop failed: %d", r);
283 r = sf_disconnect(rot.handle);
285 _ERR("sf_disconnect failed: %d", r);
293 EXPORT_API int appcore_get_rotation_state(enum appcore_rm *curr)
296 return rot.wm_rotate->get_rotation_state(curr);
307 r = sf_check_rotation(&event);
309 _ERR("sf_check_rotation failed: %d", r);
310 *curr = APPCORE_RM_UNKNOWN;
314 *curr = __get_mode(event);
319 EXPORT_API int appcore_pause_rotation_cb(void)
322 return rot.wm_rotate->pause_rotation_cb();
327 _retv_if(rot.callback == NULL, 0);
328 _DBG("[APP %d] appcore_pause_rotation_cb is called", getpid());
333 r = sf_unregister_event(rot.handle,
334 ACCELEROMETER_EVENT_ROTATION_CHECK);
336 _ERR("sf_unregister_event in appcore_internal_sf_stop failed: %d", r);
342 if (rot.sf_started == 1) {
343 r = sf_stop(rot.handle);
345 _ERR("sf_stop in appcore_internal_sf_stop failed: %d",
356 EXPORT_API int appcore_resume_rotation_cb(void)
359 return rot.wm_rotate->resume_rotation_cb();
365 _retv_if(rot.callback == NULL, 0);
366 _DBG("[APP %d] appcore_resume_rotation_cb is called", getpid());
368 if (rot.cb_set == 0) {
369 r = sf_register_event(rot.handle,
370 ACCELEROMETER_EVENT_ROTATION_CHECK, NULL,
371 __changed_cb, rot.cbdata);
373 _ERR("sf_register_event in appcore_internal_sf_start failed: %d", r);
379 if (rot.sf_started == 0) {
380 r = sf_start(rot.handle, 0);
382 _ERR("sf_start in appcore_internal_sf_start failed: %d",
384 r = sf_unregister_event(rot.handle,
385 ACCELEROMETER_EVENT_ROTATION_CHECK);
387 _ERR("sf_unregister_event failed: %d", r);
395 __add_rotlock(rot.cbdata);
397 r = appcore_get_rotation_state(&m);
398 _DBG("[APP %d] Rotmode prev %d -> curr %d", getpid(), rot.mode, m);
399 if (!r && rot.mode != m && rot.lock == 0) {
400 rot.callback(m, rot.cbdata);
407 EXPORT_API int appcore_set_wm_rotation(struct ui_wm_rotate* wm_rotate)
409 if (!wm_rotate) return -1;
412 wm_rotate->set_rotation_cb(rot.callback, rot.cbdata);
413 appcore_unset_rotation_cb();
415 rot.wm_rotate = wm_rotate;
416 _DBG("[APP %d] Support wm rotate:%p", getpid(), wm_rotate);