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.
30 #include "appcore-internal.h"
36 /*Fixme: to be added for wayland works*/
37 #define _MAKE_ATOM(a, s) \
39 a = ecore_x_atom_get(s); \
41 _ERR("##s creation failed.\n"); \
44 #define STR_ATOM_ROTATION_LOCK "_E_ROTATION_LOCK"
46 static Ecore_X_Atom ATOM_ROTATION_LOCK = 0;
47 static Ecore_X_Window root;
52 int (*callback) (enum appcore_rm, void *);
59 struct ui_wm_rotate* wm_rotate;
61 static struct rot_s rot;
64 enum accelerometer_rotate_state re;
68 static struct rot_evt re_to_rm[] = {
71 APPCORE_RM_PORTRAIT_NORMAL,
75 APPCORE_RM_LANDSCAPE_NORMAL,
79 APPCORE_RM_PORTRAIT_REVERSE,
83 APPCORE_RM_LANDSCAPE_REVERSE,
87 static enum appcore_rm __get_mode(int event_data)
92 m = APPCORE_RM_UNKNOWN;
94 for (i = 0; i < sizeof(re_to_rm) / sizeof(re_to_rm[0]); i++) {
95 if (re_to_rm[i].re == event_data) {
104 static void __changed_cb(unsigned int event_type, sensor_event_data_t *event,
114 if (event_type != ACCELEROMETER_EVENT_ROTATION_CHECK) {
119 cb_event_data = (int *)(event->event_data);
121 m = __get_mode(*cb_event_data);
123 _DBG("[APP %d] Rotation: %d -> %d", getpid(), rot.mode, m);
126 if (rot.cb_set && rot.mode != m) {
127 _DBG("[APP %d] Rotation: %d -> %d", getpid(), rot.mode, m);
128 rot.callback(m, data);
134 static void __lock_cb(keynode_t *node, void *data)
140 rot.lock = !vconf_keynode_get_bool(node);
143 m = APPCORE_RM_PORTRAIT_NORMAL;
145 rot.callback(m, data);
148 _DBG("[APP %d] Rotation locked", getpid());
152 _DBG("[APP %d] Rotation unlocked", getpid());
155 r = appcore_get_rotation_state(&m);
156 _DBG("[APP %d] Rotmode prev %d -> curr %d", getpid(),
158 if (!r && rot.mode != m) {
159 rot.callback(m, data);
166 static void __add_rotlock(void *data)
172 r = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
174 _DBG("[APP %d] Rotation vconf get bool failed", getpid());
179 vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb,
183 static void __del_rotlock(void)
185 vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb);
189 EXPORT_API int appcore_set_rotation_cb(int (*cb) (enum appcore_rm, void *),
193 return rot.wm_rotate->set_rotation_cb(cb, data);
204 if (rot.callback != NULL) {
209 handle = sf_connect(ACCELEROMETER_SENSOR);
211 _ERR("sf_connect failed: %d", handle);
215 r = sf_register_event(handle, ACCELEROMETER_EVENT_ROTATION_CHECK,
216 NULL, __changed_cb, data);
218 _ERR("sf_register_event failed: %d", r);
219 sf_disconnect(handle);
227 r = sf_start(handle, 0);
229 _ERR("sf_start failed: %d", r);
230 r = sf_unregister_event(handle, ACCELEROMETER_EVENT_ROTATION_CHECK);
232 _ERR("sf_unregister_event failed: %d", r);
238 sf_disconnect(handle);
247 _MAKE_ATOM(ATOM_ROTATION_LOCK, STR_ATOM_ROTATION_LOCK );
248 root = ecore_x_window_root_first_get();
249 XSelectInput(ecore_x_display_get(), root, PropertyChangeMask);
255 EXPORT_API int appcore_unset_rotation_cb(void)
258 return rot.wm_rotate->unset_rotation_cb();
263 _retv_if(rot.callback == NULL, 0);
268 r = sf_unregister_event(rot.handle,
269 ACCELEROMETER_EVENT_ROTATION_CHECK);
271 _ERR("sf_unregister_event failed: %d", r);
279 if (rot.sf_started == 1) {
280 r = sf_stop(rot.handle);
282 _ERR("sf_stop failed: %d", r);
288 r = sf_disconnect(rot.handle);
290 _ERR("sf_disconnect failed: %d", r);
298 EXPORT_API int appcore_get_rotation_state(enum appcore_rm *curr)
301 return rot.wm_rotate->get_rotation_state(curr);
312 r = sf_check_rotation(&event);
314 _ERR("sf_check_rotation failed: %d", r);
315 *curr = APPCORE_RM_UNKNOWN;
319 *curr = __get_mode(event);
324 EXPORT_API int appcore_pause_rotation_cb(void)
327 return rot.wm_rotate->pause_rotation_cb();
332 _retv_if(rot.callback == NULL, 0);
333 _DBG("[APP %d] appcore_pause_rotation_cb is called", getpid());
338 r = sf_unregister_event(rot.handle,
339 ACCELEROMETER_EVENT_ROTATION_CHECK);
341 _ERR("sf_unregister_event in appcore_internal_sf_stop failed: %d", r);
347 if (rot.sf_started == 1) {
348 r = sf_stop(rot.handle);
350 _ERR("sf_stop in appcore_internal_sf_stop failed: %d",
361 EXPORT_API int appcore_resume_rotation_cb(void)
364 return rot.wm_rotate->resume_rotation_cb();
370 _retv_if(rot.callback == NULL, 0);
371 _DBG("[APP %d] appcore_resume_rotation_cb is called", getpid());
373 if (rot.cb_set == 0) {
374 r = sf_register_event(rot.handle,
375 ACCELEROMETER_EVENT_ROTATION_CHECK, NULL,
376 __changed_cb, rot.cbdata);
378 _ERR("sf_register_event in appcore_internal_sf_start failed: %d", r);
384 if (rot.sf_started == 0) {
385 r = sf_start(rot.handle, 0);
387 _ERR("sf_start in appcore_internal_sf_start failed: %d",
389 ret = sf_unregister_event(rot.handle,
390 ACCELEROMETER_EVENT_ROTATION_CHECK);
392 _ERR("sf_unregister_event failed: %d", ret);
399 __add_rotlock(rot.cbdata);
401 r = appcore_get_rotation_state(&m);
402 _DBG("[APP %d] Rotmode prev %d -> curr %d", getpid(), rot.mode, m);
403 if (!r && rot.mode != m && rot.lock == 0) {
404 rot.callback(m, rot.cbdata);
411 EXPORT_API int appcore_set_wm_rotation(struct ui_wm_rotate* wm_rotate)
413 if (!wm_rotate) return -1;
416 wm_rotate->set_rotation_cb(rot.callback, rot.cbdata);
417 appcore_unset_rotation_cb();
419 rot.wm_rotate = wm_rotate;
420 _DBG("[APP %d] Support wm rotate:%p", getpid(), wm_rotate);