aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore_x/ecore_x_gesture.c
blob: 15a9efdc1fd436ce603450ea52f41df8bba986a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* ifdef HAVE_CONFIG_H */

#include "ecore_x_private.h"

static Eina_Bool _gesture_available = EINA_FALSE;

#ifdef ECORE_XGESTURE
static int _gesture_major, _gesture_minor, _gesture_patch;
int _gesture_version;
#endif /* ifdef ECORE_XGESTURE */

void
_ecore_x_gesture_init(void)
{
#ifdef ECORE_XGESTURE
   _gesture_major = 0;
   _gesture_minor = 0;
   _gesture_patch = 0;
   _gesture_version = 0;

   if (XGestureQueryVersion(_ecore_x_disp, &_gesture_major, &_gesture_minor, &_gesture_patch))
     {
        _gesture_version = (_gesture_major << 16) | _gesture_minor;
        _gesture_available = EINA_TRUE;
     }
   else
     _gesture_available = EINA_FALSE;
#else /* ifdef ECORE_XGESTURE */
   _gesture_available = EINA_FALSE;
#endif /* ifdef ECORE_XGESTURE */
}

/*
 * @brief Query whether gesture is available or not.
 *
 * @return @c EINA_TRUE, if extension is available, @c EINA_FALSE otherwise.
 */
EAPI Eina_Bool
ecore_x_gesture_supported(void)
{
   return _gesture_available;
}

EAPI Eina_Bool
ecore_x_gesture_events_select(Ecore_X_Window win,
                              Ecore_X_Gesture_Event_Mask mask)
{
#ifdef ECORE_XGESTURE
   if (!_gesture_available)
     return EINA_FALSE;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XGestureSelectEvents(_ecore_x_disp, win, mask);
   if (_ecore_xlib_sync) ecore_x_sync();

   return EINA_TRUE;
#else /* ifdef ECORE_XGESTURE */
   (void) win;
   (void) mask;
   return EINA_FALSE;
#endif /* ifdef ECORE_XGESTURE */
}

EAPI Ecore_X_Gesture_Event_Mask
ecore_x_gesture_events_selected_get(Ecore_X_Window win)
{
#ifdef ECORE_XGESTURE
   Ecore_X_Gesture_Event_Mask mask;

   if (!_gesture_available)
     return ECORE_X_GESTURE_EVENT_MASK_NONE;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   if (GestureSuccess != XGestureGetSelectedEvents(_ecore_x_disp, win, (Mask *)&mask))
     mask = ECORE_X_GESTURE_EVENT_MASK_NONE;
   if (_ecore_xlib_sync) ecore_x_sync();

   return mask;
#else /* ifdef ECORE_XGESTURE */
   (void) win;
   return ECORE_X_GESTURE_EVENT_MASK_NONE;
#endif /* ifdef ECORE_XGESTURE */
}

EAPI Eina_Bool
ecore_x_gesture_event_grab(Ecore_X_Window win,
                           Ecore_X_Gesture_Event_Type type,
                           int num_fingers)
{
#ifdef ECORE_XGESTURE
   Eina_Bool ret;
   if (!_gesture_available)
     return EINA_FALSE;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   ret = (GestureGrabSuccess == XGestureGrabEvent(_ecore_x_disp, win, type, num_fingers, CurrentTime));
   if (_ecore_xlib_sync) ecore_x_sync();
   return ret;
#else /* ifdef ECORE_XGESTURE */
   (void) win;
   (void) type;
   (void) num_fingers;
   return EINA_FALSE;
#endif /* ifdef ECORE_XGESTURE */
}

EAPI Eina_Bool
ecore_x_gesture_event_ungrab(Ecore_X_Window win,
                             Ecore_X_Gesture_Event_Type type,
                             int num_fingers)
{
#ifdef ECORE_XGESTURE
   Eina_Bool ret;

   if (!_gesture_available)
     return EINA_FALSE;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   ret = (GestureUngrabSuccess == XGestureUngrabEvent(_ecore_x_disp, win, type, num_fingers, CurrentTime));
   if (_ecore_xlib_sync) ecore_x_sync();
   return ret;
#else /* ifdef ECORE_XGESTURE */
   (void) win;
   (void) type;
   (void) num_fingers;
   return EINA_FALSE;
#endif /* ifdef ECORE_XGESTURE */
}