svn update: 48958 (latest:48959)
[framework/uifw/ecore.git] / src / lib / ecore_x / xlib / ecore_x_xi2.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #include <string.h>
10
11 #include "Ecore.h"
12 #include "ecore_x_private.h"
13 #include "Ecore_X.h"
14
15 #ifdef ECORE_XI2
16 #include "Ecore_Input.h"
17 #endif
18
19 int _ecore_x_xi2_opcode = -1;
20
21 #ifdef ECORE_XI2
22 static XIDeviceInfo *_ecore_x_xi2_devs = NULL;
23 static int _ecore_x_xi2_num = 0;
24 #endif
25
26 void
27 _ecore_x_input_init(void)
28 {
29 #ifdef ECORE_XI2
30    int event, error;
31    int major = 2, minor = 0;
32    
33    if (!XQueryExtension(_ecore_x_disp, "XInputExtension", 
34                         &_ecore_x_xi2_opcode, &event, &error))
35      {
36         _ecore_x_xi2_opcode = -1;
37         return;
38      }
39    
40    if (XIQueryVersion(_ecore_x_disp, &major, &minor) == BadRequest)
41      {
42         _ecore_x_xi2_opcode = -1;
43         return;
44      }
45    _ecore_x_xi2_devs = XIQueryDevice(_ecore_x_disp, XIAllDevices, 
46                                      &_ecore_x_xi2_num);
47 #endif   
48 }
49
50 void
51 _ecore_x_input_shutdown(void)
52 {
53 #ifdef ECORE_XI2
54    if (_ecore_x_xi2_devs)
55      {
56         XIFreeDeviceInfo(_ecore_x_xi2_devs);
57         _ecore_x_xi2_devs = NULL;
58      }
59    _ecore_x_xi2_num = 0;
60    _ecore_x_xi2_opcode = -1;
61 #endif   
62 }
63
64 void
65 _ecore_x_input_handler(XEvent* xevent)
66 {
67 #ifdef ECORE_XI2
68    XIDeviceEvent *evd = (XIDeviceEvent *)(xevent->xcookie.data);
69    int devid = evd->deviceid;
70    
71    //printf("deviceID = %d\n", devid);
72    switch (xevent->xcookie.evtype)
73      {
74      case XI_Motion:
75         _ecore_mouse_move
76           (evd->time,
77            0, // state
78            evd->event_x, evd->event_y,
79            evd->root_x, evd->root_y,
80            evd->event,
81            (evd->child ? evd->child : evd->event),
82            evd->root,
83            1, // same_screen
84            devid, 1, 1, 
85            1.0, // pressure
86            0.0, // angle
87            evd->event_x, evd->event_y,
88            evd->root_x, evd->root_y);
89         break;
90      case XI_ButtonPress:
91         _ecore_mouse_button
92           (ECORE_EVENT_MOUSE_BUTTON_DOWN,
93            evd->time,
94            0, // state
95            0, // button
96            evd->event_x, evd->event_y,
97            evd->root_x, evd->root_y,
98            evd->event,
99            (evd->child ? evd->child : evd->event),
100            evd->root,
101            1, // same_screen
102            devid, 1, 1,
103            1.0, // pressure
104            0.0, // angle
105            evd->event_x, evd->event_y,
106            evd->root_x, evd->root_y);
107         break;
108      case XI_ButtonRelease:
109         _ecore_mouse_button
110           (ECORE_EVENT_MOUSE_BUTTON_UP,
111            evd->time,
112            0, // state
113            0, // button
114            evd->event_x, evd->event_y,
115            evd->root_x, evd->root_y,
116            evd->event,
117            (evd->child ? evd->child : evd->event),
118            evd->root,
119            1, // same_screen
120            devid, 1, 1,
121            1.0, // pressure
122            0.0, // angle
123            evd->event_x, evd->event_y,
124            evd->root_x, evd->root_y);
125         break;
126      }
127 #endif   
128 }
129
130 EAPI Eina_Bool
131 ecore_x_input_multi_select(Ecore_X_Window win)
132 {
133 #ifdef ECORE_XI2
134    int i, find = 0;
135
136    if (!_ecore_x_xi2_devs) return 0;
137
138    LOGFN(__FILE__, __LINE__, __FUNCTION__);
139    for (i = 0; i < _ecore_x_xi2_num; i++)
140      {
141         XIDeviceInfo *dev = &(_ecore_x_xi2_devs[i]);
142
143         if (dev->use == XIFloatingSlave)
144           {
145              XIEventMask eventmask;
146              unsigned char mask[1] = { 0 };
147
148              eventmask.deviceid = dev->deviceid;
149              eventmask.mask_len = sizeof(mask);
150              eventmask.mask = mask;
151              XISetMask(mask, XI_ButtonPress);
152              XISetMask(mask, XI_ButtonRelease);
153              XISetMask(mask, XI_Motion);
154              XISelectEvents(_ecore_x_disp, win, &eventmask, 1);
155              find = 1;
156           }
157      }
158
159    return find;
160 #else
161    return 0;
162 #endif
163 }