[IMPROVE] Build: add provides swap-probe
[platform/core/system/swap-probe.git] / probe_event / orientation.c
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Jaewon Lim <jaewon81.lim@samsung.com>
9  * Woojin Jung <woojin2.jung@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  *
12  * This library is free software; you can redistribute it and/or modify it under
13  * the terms of the GNU Lesser General Public License as published by the
14  * Free Software Foundation; either version 2.1 of the License, or (at your option)
15  * any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this library; if not, write to the Free Software Foundation, Inc., 51
24  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  *
29  */
30
31 #include <Ecore.h>
32 #include <Ecore_X.h>
33
34 #include "daprobe.h"
35 #include "dahelper.h"
36
37 static int init_orient = 0;
38
39 Ecore_Event_Handler *register_orientation_event_listener();
40 void unregister_orientation_event_listener(Ecore_Event_Handler **handler);
41
42 Ecore_Event_Handler *handler = NULL;
43
44 EAPI int ecore_x_init(const char *name)
45 {
46         static int (*ecore_x_initp)(const char *name);
47         int res;
48
49         probeBlockStart();
50         GET_REAL_FUNC(ecore_x_init, LIBOSP_UIFW);
51
52         probeBlockEnd();
53         res = ecore_x_initp(name);
54
55         if ((init_orient == 0) && (res == 1)) {
56                 handler = register_orientation_event_listener();
57                 init_orient = 1;
58         }
59         return res;
60 }
61
62 EAPI int ecore_x_shutdown(void)
63 {
64         static int (*ecore_x_shutdownp)(void);
65         int res;
66
67         probeBlockStart();
68         GET_REAL_FUNC(ecore_x_shutdown, LIBOSP_UIFW);
69
70         probeBlockEnd();
71         res = ecore_x_shutdownp();
72
73         if ((init_orient == 1) && (res == 0)) {
74                 unregister_orientation_event_listener(&handler);
75                 init_orient = 0;
76         }
77
78         return res;
79 }
80
81 Eina_Bool _da_onclientmessagereceived(void __unused *pData, int __unused type,
82                                       void *pEvent)
83 {
84         Ecore_X_Event_Client_Message *pClientEvent;
85
86         probeBlockStart();
87         pClientEvent = (Ecore_X_Event_Client_Message*)pEvent;
88
89         //This code from ecore_x
90         //So I don't know what 32 does mean
91         if (pClientEvent->format != 32)
92                 return ECORE_CALLBACK_PASS_ON;
93
94         if (pClientEvent != NULL) {
95                 if (pClientEvent->message_type ==
96                     ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE) {
97                         int orientation = (int)pClientEvent->data.l[1];
98                         on_orientation_changed(orientation, false);
99                 }
100         }
101         probeBlockEnd();
102
103         return ECORE_CALLBACK_RENEW;
104 }
105
106 Ecore_Event_Handler *register_orientation_event_listener()
107 {
108         Ecore_Event_Handler *handler;
109         probeBlockStart();
110
111         handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
112                                           _da_onclientmessagereceived, NULL);
113
114         probeBlockEnd();
115
116         return handler;
117 }
118
119 void unregister_orientation_event_listener(Ecore_Event_Handler **handler)
120 {
121         probeBlockStart();
122         if (*handler) {
123                 ecore_event_handler_del(*handler);
124                 *handler = NULL;
125         }
126         probeBlockEnd();
127 }