aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_input.c
blob: c0338c22a5b468a868bbca38f97d488cf721d5f2 (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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include "ecore_xcb_private.h"
#ifdef ECORE_XCB_XINPUT
# include <xcb/xinput.h>
# include <xcb/xcb_event.h>
#endif

/* FIXME: this is a guess. can't find defines for touch events in xcb libs
 * online */
/* these are not yet defined in xcb support for xi2 - so manually create */
#ifndef XCB_INPUT_DEVICE_TOUCH_BEGIN
#define XCB_INPUT_DEVICE_TOUCH_BEGIN    18
#endif
#ifndef XCB_INPUT_DEVICE_TOUCH_END
#define XCB_INPUT_DEVICE_TOUCH_END      19
#endif
#ifndef XCB_INPUT_DEVICE_TOUCH_UPDATE
#define XCB_INPUT_DEVICE_TOUCH_UPDATE   21
#endif

#ifndef XCB_INPUT_POINTER_EMULATED_MASK
#define XCB_INPUT_POINTER_EMULATED_MASK (1 << 16)
#endif

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

/* external variables */
int _ecore_xcb_event_input = 0;

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

#ifdef ECORE_XCB_XINPUT
   xcb_prefetch_extension_data(_ecore_xcb_conn, &xcb_input_id);
#endif
}

void
_ecore_xcb_input_finalize(void)
{
#ifdef ECORE_XCB_XINPUT
   xcb_input_get_extension_version_cookie_t cookie;
   xcb_input_get_extension_version_reply_t *reply;
   char buff[128];
#endif

   LOGFN(__FILE__, __LINE__, __FUNCTION__);

#ifdef ECORE_XCB_XINPUT
   cookie =
     xcb_input_get_extension_version_unchecked(_ecore_xcb_conn, 127, buff);
   reply =
     xcb_input_get_extension_version_reply(_ecore_xcb_conn, cookie, NULL);
   if (reply)
     {
        _input_avail = EINA_TRUE;
        free(reply);
     }

   if (_input_avail)
     {
        const xcb_query_extension_reply_t *ext_reply;

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

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

void
#ifdef ECORE_XCB_XINPUT
_ecore_xcb_input_handle_event(xcb_generic_event_t *event)
#else
_ecore_xcb_input_handle_event(xcb_generic_event_t * event __UNUSED__)
#endif
{
#ifdef ECORE_XCB_XINPUT
   xcb_ge_event_t *ev;
#endif

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN;

   /* FIXME: look at xlib ecore_x_xi2.c to copy logic in when i can find an
    * xcb-input lib to test with */
#ifdef ECORE_XCB_XINPUT
   ev = (xcb_ge_event_t *)event;
   switch (ev->event_type)
     {
      case XCB_INPUT_DEVICE_MOTION_NOTIFY:
      {
         xcb_input_device_motion_notify_event_t *de;
         unsigned int child_win = 0;

         de = (xcb_input_device_motion_notify_event_t *)ev->pad1;
         child_win = (de->child ? de->child : de->event);
         _ecore_xcb_event_mouse_move(de->time, de->state, de->event_x,
                                     de->event_y, de->root_x, de->root_y,
                                     de->event, child_win, de->root,
                                     de->same_screen, de->device_id,
                                     1, 1, 1.0, 0.0,
                                     de->event_x, de->event_y,
                                     de->root_x, de->root_y);
      }
      break;

      case XCB_INPUT_DEVICE_BUTTON_PRESS:
      {
         xcb_input_device_button_press_event_t *de;
         unsigned int child_win = 0;

         de = (xcb_input_device_button_press_event_t *)ev->pad1;
         child_win = (de->child ? de->child : de->event);
         _ecore_xcb_event_mouse_button(ECORE_EVENT_MOUSE_BUTTON_DOWN,
                                       de->time, de->state, de->detail,
                                       de->event_x, de->event_y,
                                       de->root_x, de->root_y, de->event,
                                       child_win, de->root,
                                       de->same_screen, de->device_id,
                                       1, 1, 1.0, 0.0,
                                       de->event_x, de->event_y,
                                       de->root_x, de->root_y);
      }
      break;

      case XCB_INPUT_DEVICE_BUTTON_RELEASE:
      {
         xcb_input_device_button_release_event_t *de;
         unsigned int child_win = 0;

         de = (xcb_input_device_button_release_event_t *)ev->pad1;
         child_win = (de->child ? de->child : de->event);
         _ecore_xcb_event_mouse_button(ECORE_EVENT_MOUSE_BUTTON_UP,
                                       de->time, de->state, de->detail,
                                       de->event_x, de->event_y,
                                       de->root_x, de->root_y, de->event,
                                       child_win, de->root,
                                       de->same_screen, de->device_id,
                                       1, 1, 1.0, 0.0,
                                       de->event_x, de->event_y,
                                       de->root_x, de->root_y);
      }
      break;

      case XCB_INPUT_DEVICE_TOUCH_UPDATE:
      {
         xcb_input_device_motion_notify_event_t *de;
         unsigned int child_win = 0;

         de = (xcb_input_device_motion_notify_event_t *)ev->pad1;
         child_win = (de->child ? de->child : de->event);
         _ecore_xcb_event_mouse_move(de->time, de->state, de->event_x,
                                     de->event_y, de->root_x, de->root_y,
                                     de->event, child_win, de->root,
                                     de->same_screen, de->device_id,
                                     1, 1, 1.0, 0.0,
                                     de->event_x, de->event_y,
                                     de->root_x, de->root_y);
      }
      break;

      case XCB_INPUT_DEVICE_TOUCH_BEGIN:
      {
         xcb_input_device_button_press_event_t *de;
         unsigned int child_win = 0;

         de = (xcb_input_device_button_press_event_t *)ev->pad1;
         child_win = (de->child ? de->child : de->event);
         _ecore_xcb_event_mouse_button(ECORE_EVENT_MOUSE_BUTTON_DOWN,
                                       de->time, de->state, de->detail,
                                       de->event_x, de->event_y,
                                       de->root_x, de->root_y, de->event,
                                       child_win, de->root,
                                       de->same_screen, de->device_id,
                                       1, 1, 1.0, 0.0,
                                       de->event_x, de->event_y,
                                       de->root_x, de->root_y);
      }
      break;

      case XCB_INPUT_DEVICE_TOUCH_END:
      {
         xcb_input_device_button_release_event_t *de;
         unsigned int child_win = 0;

         de = (xcb_input_device_button_release_event_t *)ev->pad1;
         child_win = (de->child ? de->child : de->event);
         _ecore_xcb_event_mouse_button(ECORE_EVENT_MOUSE_BUTTON_UP,
                                       de->time, de->state, de->detail,
                                       de->event_x, de->event_y,
                                       de->root_x, de->root_y, de->event,
                                       child_win, de->root,
                                       de->same_screen, de->device_id,
                                       1, 1, 1.0, 0.0,
                                       de->event_x, de->event_y,
                                       de->root_x, de->root_y);
      }
      break;

      default:
        break;
     }
#endif
}

EAPI Eina_Bool
ecore_x_input_multi_select(Ecore_X_Window win)
{
   Eina_Bool find = EINA_FALSE;
#ifdef ECORE_XCB_XINPUT
   xcb_input_list_input_devices_cookie_t dcookie;
   xcb_input_list_input_devices_reply_t *dreply;
   xcb_input_device_info_iterator_t diter;
#endif

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN;

   if (!_input_avail) return EINA_FALSE;

   /* FIXME: i can't seemingly test this! no xcb input lib so can't look and
    * test and look at types etc. - look at xlib code and copy logic over
    * when we can */
#ifdef ECORE_XCB_XINPUT
   dcookie = xcb_input_list_input_devices_unchecked(_ecore_xcb_conn);
   dreply =
     xcb_input_list_input_devices_reply(_ecore_xcb_conn, dcookie, NULL);
   if (!dreply) return EINA_FALSE;

   diter = xcb_input_list_input_devices_devices_iterator(dreply);
   while (diter.rem)
     {
        xcb_input_device_info_t *dev;
        const xcb_input_event_class_t iclass[] =
        {
           XCB_INPUT_DEVICE_BUTTON_PRESS,
           XCB_INPUT_DEVICE_BUTTON_RELEASE,
           XCB_INPUT_DEVICE_MOTION_NOTIFY,
           XCB_INPUT_DEVICE_TOUCH_BEGIN,
           XCB_INPUT_DEVICE_TOUCH_END,
           XCB_INPUT_DEVICE_TOUCH_UPDATE
        };

        dev = diter.data;
        if (dev->device_use == XCB_INPUT_DEVICE_USE_IS_X_EXTENSION_DEVICE)
          {
             DBG("Device %d", dev->device_id);
             DBG("\tType: %d", dev->device_type);
             DBG("\tNum Classes: %d", dev->num_class_info);
             DBG("\tUse: %d", dev->device_use);

             xcb_input_select_extension_event(_ecore_xcb_conn, win,
                                              sizeof(iclass) / sizeof(xcb_input_event_class_t),
                                              iclass);
             find = EINA_TRUE;
          }
        xcb_input_device_info_next(&diter);
     }
   free(dreply);
#endif

   return find;
   win = 0;
}