Tizen 2.1 base
[framework/uifw/ecore.git] / src / lib / ecore_x / xlib / ecore_x_gesture.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #include "ecore_x_private.h"
6
7 static Eina_Bool _gesture_available = EINA_FALSE;
8
9 #ifdef ECORE_XGESTURE
10 static int _gesture_major, _gesture_minor, _gesture_patch;
11 int _gesture_version;
12 #endif /* ifdef ECORE_XGESTURE */
13
14 void
15 _ecore_x_gesture_init(void)
16 {
17 #ifdef ECORE_XGESTURE
18    _gesture_major = 0;
19    _gesture_minor = 0;
20    _gesture_patch = 0;
21    _gesture_version = 0;
22
23    if (XGestureQueryVersion(_ecore_x_disp, &_gesture_major, &_gesture_minor, &_gesture_patch))
24      {
25         _gesture_version = (_gesture_major << 16) | _gesture_minor;
26         _gesture_available = EINA_TRUE;
27      }
28    else
29      _gesture_available = EINA_FALSE;
30 #else /* ifdef ECORE_XGESTURE */
31    _gesture_available = EINA_FALSE;
32 #endif /* ifdef ECORE_XGESTURE */
33 }
34
35 /*
36  * @brief Query whether gesture is available or not.
37  *
38  * @return @c EINA_TRUE, if extension is available, @c EINA_FALSE otherwise.
39  */
40 EAPI Eina_Bool
41 ecore_x_gesture_supported(void)
42 {
43    return _gesture_available;
44 }
45
46 EAPI Eina_Bool
47 ecore_x_gesture_events_select(Ecore_X_Window win,
48                               Ecore_X_Gesture_Event_Mask mask)
49 {
50 #ifdef ECORE_XGESTURE
51    if (!_gesture_available)
52      return EINA_FALSE;
53
54    LOGFN(__FILE__, __LINE__, __FUNCTION__);
55    XGestureSelectEvents(_ecore_x_disp, win, mask);
56
57    return EINA_TRUE;
58 #else /* ifdef ECORE_XGESTURE */
59    return EINA_FALSE;
60    win = 0;
61    mask = 0;
62 #endif /* ifdef ECORE_XGESTURE */
63 }
64
65 EAPI Ecore_X_Gesture_Event_Mask
66 ecore_x_gesture_events_selected_get(Ecore_X_Window win)
67 {
68 #ifdef ECORE_XGESTURE
69    Ecore_X_Gesture_Event_Mask mask;
70
71    if (!_gesture_available)
72      return ECORE_X_GESTURE_EVENT_MASK_NONE;
73
74    LOGFN(__FILE__, __LINE__, __FUNCTION__);
75    if (GestureSuccess != XGestureGetSelectedEvents(_ecore_x_disp, win, &mask))
76      {
77         mask = ECORE_X_GESTURE_EVENT_MASK_NONE;
78         return mask;
79      }
80
81    return mask;
82 #else /* ifdef ECORE_XGESTURE */
83    return ECORE_X_GESTURE_EVENT_MASK_NONE;
84    win = 0;
85 #endif /* ifdef ECORE_XGESTURE */
86 }
87
88 EAPI Eina_Bool
89 ecore_x_gesture_event_grab(Ecore_X_Window win,
90                            Ecore_X_Gesture_Event_Type type,
91                            int num_fingers)
92 {
93 #ifdef ECORE_XGESTURE
94    if (!_gesture_available)
95      return EINA_FALSE;
96
97    LOGFN(__FILE__, __LINE__, __FUNCTION__);
98    if (GestureGrabSuccess != XGestureGrabEvent(_ecore_x_disp, win, type, num_fingers, CurrentTime))
99      {
100         return EINA_FALSE;
101      }
102
103    return EINA_TRUE;
104 #else /* ifdef ECORE_XGESTURE */
105    return EINA_FALSE;
106    win = 0;
107    type = 0;
108    num_fingers = 0;
109 #endif /* ifdef ECORE_XGESTURE */
110 }
111
112 EAPI Eina_Bool
113 ecore_x_gesture_event_ungrab(Ecore_X_Window win,
114                              Ecore_X_Gesture_Event_Type type,
115                              int num_fingers)
116 {
117 #ifdef ECORE_XGESTURE
118    Ecore_X_Gesture_Event_Mask mask;
119
120    if (!_gesture_available)
121      return EINA_FALSE;
122
123    LOGFN(__FILE__, __LINE__, __FUNCTION__);
124    if (GestureUngrabSuccess != XGestureUngrabEvent(_ecore_x_disp, win, type, num_fingers, CurrentTime))
125      {
126         return EINA_FALSE;
127      }
128
129    return EINA_TRUE;
130 #else /* ifdef ECORE_XGESTURE */
131    return EINA_FALSE;
132    win = 0;
133    type = 0;
134    num_fingers = 0;
135 #endif /* ifdef ECORE_XGESTURE */
136 }
137