1 module x11.extensions.XI;
2 
3 import std.string : string;
4 import core.stdc.config;
5 
6 /* Definitions used by the server, library and client */
7 
8 const int sz_xGetExtensionVersionReq            = 8;
9 const int sz_xGetExtensionVersionReply          = 32;
10 const int sz_xListInputDevicesReq               = 4;
11 const int sz_xListInputDevicesReply             = 32;
12 const int sz_xOpenDeviceReq                     = 8;
13 const int sz_xOpenDeviceReply                   = 32;
14 const int sz_xCloseDeviceReq                    = 8;
15 const int sz_xSetDeviceModeReq                  = 8;
16 const int sz_xSetDeviceModeReply                = 32;
17 const int sz_xSelectExtensionEventReq           = 12;
18 const int sz_xGetSelectedExtensionEventsReq     = 8;
19 const int sz_xGetSelectedExtensionEventsReply   = 32;
20 const int sz_xChangeDeviceDontPropagateListReq  = 12;
21 const int sz_xGetDeviceDontPropagateListReq     = 8;
22 const int sz_xGetDeviceDontPropagateListReply   = 32;
23 const int sz_xGetDeviceMotionEventsReq          = 16;
24 const int sz_xGetDeviceMotionEventsReply        = 32;
25 const int sz_xChangeKeyboardDeviceReq           = 8;
26 const int sz_xChangeKeyboardDeviceReply         = 32;
27 const int sz_xChangePointerDeviceReq            = 8;
28 const int sz_xChangePointerDeviceReply          = 32;
29 const int sz_xGrabDeviceReq                     = 20;
30 const int sz_xGrabDeviceReply                   = 32;
31 const int sz_xUngrabDeviceReq                   = 12;
32 const int sz_xGrabDeviceKeyReq                  = 20;
33 const int sz_xGrabDeviceKeyReply                = 32;
34 const int sz_xUngrabDeviceKeyReq                = 16;
35 const int sz_xGrabDeviceButtonReq               = 20;
36 const int sz_xGrabDeviceButtonReply             = 32;
37 const int sz_xUngrabDeviceButtonReq             = 16;
38 const int sz_xAllowDeviceEventsReq              = 12;
39 const int sz_xGetDeviceFocusReq                 = 8;
40 const int sz_xGetDeviceFocusReply               = 32;
41 const int sz_xSetDeviceFocusReq                 = 16;
42 const int sz_xGetFeedbackControlReq             = 8;
43 const int sz_xGetFeedbackControlReply           = 32;
44 const int sz_xChangeFeedbackControlReq          = 12;
45 const int sz_xGetDeviceKeyMappingReq            = 8;
46 const int sz_xGetDeviceKeyMappingReply          = 32;
47 const int sz_xChangeDeviceKeyMappingReq         = 8;
48 const int sz_xGetDeviceModifierMappingReq       = 8;
49 const int sz_xSetDeviceModifierMappingReq       = 8;
50 const int sz_xSetDeviceModifierMappingReply     = 32;
51 const int sz_xGetDeviceButtonMappingReq         = 8;
52 const int sz_xGetDeviceButtonMappingReply       = 32;
53 const int sz_xSetDeviceButtonMappingReq         = 8;
54 const int sz_xSetDeviceButtonMappingReply       = 32;
55 const int sz_xQueryDeviceStateReq               = 8;
56 const int sz_xQueryDeviceStateReply             = 32;
57 const int sz_xSendExtensionEventReq             = 16;
58 const int sz_xDeviceBellReq                     = 8;
59 const int sz_xSetDeviceValuatorsReq             = 8;
60 const int sz_xSetDeviceValuatorsReply           = 32;
61 const int sz_xGetDeviceControlReq               = 8;
62 const int sz_xGetDeviceControlReply             = 32;
63 const int sz_xChangeDeviceControlReq            = 8;
64 const int sz_xChangeDeviceControlReply          = 32;
65 const int sz_xListDevicePropertiesReq           = 8;
66 const int sz_xListDevicePropertiesReply         = 32;
67 const int sz_xChangeDevicePropertyReq           = 20;
68 const int sz_xDeleteDevicePropertyReq           = 12;
69 const int sz_xGetDevicePropertyReq              = 24;
70 const int sz_xGetDevicePropertyReply            = 32;
71 
72 const string INAME = "XInputExtension";
73 
74 enum {
75     XI_KEYBOARD                         = "KEYBOARD",
76     XI_MOUSE                            = "MOUSE",
77     XI_TABLET                           = "TABLET",
78     XI_TOUCHSCREEN                      = "TOUCHSCREEN",
79     XI_TOUCHPAD                         = "TOUCHPAD",
80     XI_BARCODE                          = "BARCODE",
81     XI_BUTTONBOX                        = "BUTTONBOX",
82     XI_KNOB_BOX                         = "KNOB_BOX",
83     XI_ONE_KNOB                         = "ONE_KNOB",
84     XI_NINE_KNOB                        = "NINE_KNOB",
85     XI_TRACKBALL                        = "TRACKBALL",
86     XI_QUADRATURE                       = "QUADRATURE",
87     XI_ID_MODULE                        = "ID_MODULE",
88     XI_SPACEBALL                        = "SPACEBALL",
89     XI_DATAGLOVE                        = "DATAGLOVE",
90     XI_EYETRACKER                       = "EYETRACKER",
91     XI_CURSORKEYS                       = "CURSORKEYS",
92     XI_FOOTMOUSE                        = "FOOTMOUSE",
93     XI_JOYSTICK                         = "JOYSTICK"
94 }
95 
96 /* Indices into the versions[] array (XExtInt.c). Used as a index to
97  * retrieve the minimum version of XI from _XiCheckExtInit */
98 enum {
99     Dont_Check                          = 0,
100     XInput_Initial_Release              = 1,
101     XInput_Add_XDeviceBell              = 2,
102     XInput_Add_XSetDeviceValuators      = 3,
103     XInput_Add_XChangeDeviceControl     = 4,
104     XInput_Add_DevicePresenceNotify     = 5,
105     XInput_Add_DeviceProperties         = 6
106 }
107 /* DO NOT ADD TO HERE -> XI2 */
108 
109 enum {
110     XI_Absent                           = 0,
111     XI_Present                          = 1
112 }
113 
114 enum {
115     XI_Initial_Release_Major            = 1,
116     XI_Initial_Release_Minor            = 0
117 }
118 
119 enum {
120     XI_Add_XDeviceBell_Major            = 1,
121     XI_Add_XDeviceBell_Minor            = 1
122 }
123 
124 enum {
125     XI_Add_XSetDeviceValuators_Major    = 1,
126     XI_Add_XSetDeviceValuators_Minor    = 2
127 }
128 
129 enum {
130     XI_Add_XChangeDeviceControl_Major   = 1,
131     XI_Add_XChangeDeviceControl_Minor   = 3
132 }
133 
134 enum {
135     XI_Add_DevicePresenceNotify_Major   = 1,
136     XI_Add_DevicePresenceNotify_Minor   = 4
137 }
138 
139 enum {
140     XI_Add_DeviceProperties_Major       = 1,
141     XI_Add_DeviceProperties_Minor       = 5
142 }
143 
144 enum {
145     DEVICE_RESOLUTION                   = 1,
146     DEVICE_ABS_CALIB                    = 2,
147     DEVICE_CORE                         = 3,
148     DEVICE_ENABLE                       = 4,
149     DEVICE_ABS_AREA                     = 5
150 }
151 
152 const int NoSuchExtension           = 1;
153 
154 const int COUNT                     = 0;
155 const int CREATE                    = 1;
156 
157 const int NewPointer                = 0;
158 const int NewKeyboard               = 1;
159 
160 const int XPOINTER                  = 0;
161 const int XKEYBOARD                 = 1;
162 
163 const int UseXKeyboard              = 0xFF;
164 
165 enum {
166     IsXPointer                          = 0,
167     IsXKeyboard                         = 1,
168     IsXExtensionDevice                  = 2,
169     IsXExtensionKeyboard                = 3,
170     IsXExtensionPointer                 = 4
171 }
172 
173 enum {
174     AsyncThisDevice                     = 0,
175     SyncThisDevice                      = 1,
176     ReplayThisDevice                    = 2,
177     AsyncOtherDevices                   = 3,
178     AsyncAll                            = 4,
179     SyncAll                             = 5
180 }
181 
182     const int FollowKeyboard            = 3;
183     const int RevertToFollowKeyboard    = 3;
184 
185     const c_long DvAccelNum             = (1L << 0);
186     const c_long DvAccelDenom           = (1L << 1);
187     const c_long DvThreshold            = (1L << 2);
188 
189     const c_long DvKeyClickPercent      = (1L<<0);
190     const c_long DvPercent              = (1L<<1);
191     const c_long DvPitch                = (1L<<2);
192     const c_long DvDuration             = (1L<<3);
193     const c_long DvLed                  = (1L<<4);
194     const c_long DvLedMode              = (1L<<5);
195     const c_long DvKey                  = (1L<<6);
196     const c_long DvAutoRepeatMode       = (1L<<7);
197 
198     const c_long DvString               = (1L << 0);
199 
200     const c_long DvInteger              = (1L << 0);
201 
202 enum {
203     DeviceMode                          = (1L << 0),
204     Relative                            = 0,
205     Absolute                            = 1
206 }
207 
208 enum {
209     ProximityState                      = (1L << 1),
210     InProximity                         = (0L << 1),
211     OutOfProximity                      = (1L << 1)
212 }
213 
214 const int AddToList                 = 0;
215 const int DeleteFromList            = 1;
216 
217 enum {
218     KeyClass                            = 0,
219     ButtonClass                         = 1,
220     ValuatorClass                       = 2,
221     FeedbackClass                       = 3,
222     ProximityClass                      = 4,
223     FocusClass                          = 5,
224     OtherClass                          = 6,
225     AttachClass                         = 7
226 }
227 
228 enum {
229     KbdFeedbackClass                    = 0,
230     PtrFeedbackClass                    = 1,
231     StringFeedbackClass                 = 2,
232     IntegerFeedbackClass                = 3,
233     LedFeedbackClass                    = 4,
234     BellFeedbackClass                   = 5
235 }
236 
237 enum {
238     _devicePointerMotionHint            = 0,
239     _deviceButton1Motion                = 1,
240     _deviceButton2Motion                = 2,
241     _deviceButton3Motion                = 3,
242     _deviceButton4Motion                = 4,
243     _deviceButton5Motion                = 5,
244     _deviceButtonMotion                 = 6,
245     _deviceButtonGrab                   = 7,
246     _deviceOwnerGrabButton              = 8,
247     _noExtensionEvent                   = 9
248 }
249 
250 const int _devicePresence           = 0;
251 
252 const int _deviceEnter              = 0;
253 const int _deviceLeave              = 1;
254 
255 /* Device presence notify states */
256 enum {
257     DeviceAdded                         = 0,
258     DeviceRemoved                       = 1,
259     DeviceEnabled                       = 2,
260     DeviceDisabled                      = 3,
261     DeviceUnrecoverable                 = 4,
262     DeviceControlChanged                = 5
263 }
264 
265 /* XI Errors */
266 enum {
267     XI_BadDevice                        = 0,
268     XI_BadEvent                         = 1,
269     XI_BadMode                          = 2,
270     XI_DeviceBusy                       = 3,
271     XI_BadClass                         = 4
272 }
273 
274 /*
275  * Make XEventClass be a CARD32 for 64 bit servers.  Don't affect client
276  * definition of XEventClass since that would be a library interface change.
277  * See the top of X.h for more _XSERVER64 magic.
278  *
279  * But, don't actually use the CARD32 type.  We can't get it defined here
280  * without polluting the namespace.
281  */
282 version(_XSERVER64){
283     alias XEventClass = uint;
284 }else{
285     alias XEventClass = c_ulong;
286 }
287 
288 /*******************************************************************
289  *
290  * Extension version structure.
291  *
292  */
293 
294 struct XExtensionVersion{
295     int     present;
296     short   major_version;
297     short   minor_version;
298 }