aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_x/xcb/ecore_xcb_gesture.c
blob: 263dade86b0ae7dbb383b3cbc7fe9c8dbdc4c1f0 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "ecore_xcb_private.h"
#ifdef ECORE_XCB_XGESTURE
# include <xcb/gesture.h>
# include <xcb/xcb_event.h>
#endif

/* local variables */
static Eina_Bool _gesture_available = EINA_FALSE;

/* external variables */
int _ecore_xcb_event_gesture = -1;

void 
_ecore_xcb_gesture_init(void) 
{
   LOGFN(__FILE__, __LINE__, __FUNCTION__);

#ifdef ECORE_XCB_XGESTURE
   xcb_prefetch_extension_data(_ecore_xcb_conn, &xcb_gesture_id);
#endif
}

void 
_ecore_xcb_gesture_finalize(void) 
{
#ifdef ECORE_XCB_XGESTURE
   xcb_gesture_query_version_cookie_t cookie;
   xcb_gesture_query_version_reply_t *reply;
#endif

   LOGFN(__FILE__, __LINE__, __FUNCTION__);

#ifdef ECORE_XCB_XGESTURE
   cookie = 
     xcb_gesture_query_version_unchecked(_ecore_xcb_conn);
   reply = 
     xcb_gesture_query_version_reply(_ecore_xcb_conn, cookie, NULL);
   if (reply) 
     {
        _gesture_available = EINA_TRUE;
        free(reply);
     }

   if (_gesture_available) 
     {
        const xcb_query_extension_reply_t *ext_reply;

        ext_reply = xcb_get_extension_data(_ecore_xcb_conn, &xcb_gesture_id);
        if (ext_reply) 
          _ecore_xcb_event_gesture = ext_reply->first_event;
     }
#endif
}

void 
_ecore_xcb_gesture_shutdown(void) 
{
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
}

EAPI Eina_Bool
ecore_x_gesture_supported(void)
{
   return _gesture_available;
}

#ifdef ECORE_XCB_XGESTURE
EAPI Eina_Bool
ecore_x_gesture_events_select(Ecore_X_Window win,
                              Ecore_X_Gesture_Event_Mask mask)
#else
EAPI Eina_Bool
ecore_x_gesture_events_select(Ecore_X_Window win __UNUSED__,
                              Ecore_X_Gesture_Event_Mask mask __UNUSED__)
#endif

{
#ifdef ECORE_XCB_XGESTURE
   if (!_gesture_available) return EINA_FALSE;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN

   xcb_gesture_select_events(_ecore_xcb_conn, win, mask);

   return EINA_TRUE;
#else
   return EINA_FALSE;
#endif
}

#ifdef ECORE_XCB_XGESTURE
EAPI Ecore_X_Gesture_Event_Mask
ecore_x_gesture_events_selected_get(Ecore_X_Window win)
#else
EAPI Ecore_X_Gesture_Event_Mask
ecore_x_gesture_events_selected_get(Ecore_X_Window win __UNUSED__)
#endif
{
#ifdef ECORE_XCB_XGESTURE
   xcb_gesture_get_selected_events_cookie_t ecookie;
   xcb_gesture_get_selected_events_reply_t *ereply;
   Ecore_X_Gesture_Event_Mask mask = ECORE_X_GESTURE_EVENT_MASK_NONE;

   if (!_gesture_available) return mask;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN

   ecookie = xcb_gesture_get_selected_events(_ecore_xcb_conn, win);
   ereply = 
     xcb_gesture_get_selected_events_reply(_ecore_xcb_conn, ecookie, NULL);
   if (ereply)
     {
        mask = ereply->mask;
	 free(ereply);
     }

   return mask;
#else
   return ECORE_X_GESTURE_EVENT_MASK_NONE;
#endif
}

#ifdef ECORE_XCB_XGESTURE
EAPI Eina_Bool
ecore_x_gesture_event_grab(Ecore_X_Window win,
                           Ecore_X_Gesture_Event_Type type,
                           int num_fingers)
#else
EAPI Eina_Bool
ecore_x_gesture_event_grab(Ecore_X_Window win __UNUSED__,
                           Ecore_X_Gesture_Event_Type type __UNUSED__,
                           int num_fingers __UNUSED__)
#endif
{
#ifdef ECORE_XCB_XGESTURE
   Eina_Bool status = EINA_TRUE;
   xcb_gesture_grab_event_cookie_t ecookie;
   xcb_gesture_grab_event_reply_t *ereply;

   if (!_gesture_available) return EINA_FALSE;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN

   ecookie = 
     xcb_gesture_grab_event(_ecore_xcb_conn, win, type, num_fingers, 0L);
   ereply = xcb_gesture_grab_event_reply(_ecore_xcb_conn, ecookie, NULL);

   if (ereply)
     {
        if (ereply->status) status = EINA_FALSE;
        free(ereply);
     }
   else
     status = EINA_FALSE;

   return status;
#else
   return EINA_FALSE;
#endif
}

#ifdef ECORE_XCB_XGESTURE
EAPI Eina_Bool
ecore_x_gesture_event_ungrab(Ecore_X_Window win,
                             Ecore_X_Gesture_Event_Type type,
                             int num_fingers)
#else
EAPI Eina_Bool
ecore_x_gesture_event_ungrab(Ecore_X_Window win __UNUSED__,
                             Ecore_X_Gesture_Event_Type type __UNUSED__,
                             int num_fingers __UNUSED__)
#endif
{
#ifdef ECORE_XCB_XGESTURE
   Eina_Bool status = EINA_TRUE;
   xcb_gesture_ungrab_event_cookie_t ecookie;
   xcb_gesture_ungrab_event_reply_t *ereply;

   if (!_gesture_available) return EINA_FALSE;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN

  ecookie = 
     xcb_gesture_ungrab_event(_ecore_xcb_conn, win, type, num_fingers, 0L);
  ereply = xcb_gesture_ungrab_event_reply(_ecore_xcb_conn, ecookie, NULL);

   if (ereply)
     {
        if (ereply->status) status = EINA_FALSE;
        free(ereply);
     }
   else
     status = EINA_FALSE;

   return status;
#else
   return EINA_FALSE;
#endif
}