1
/** Tintitko - the X Input driver for Linux input drivers
2
* XFree86 v 3.3 dependend code
3
* (c) 2000 0rfelyus (Tuhyk-Labs)
6
#include "tuntitko-common.h"
7
#include <linux/input.h>
9
#include <fcntl.h> /* for `open' etc. */
10
#include <unistd.h> /* for `close' .. */
12
/**********************************************************************/
14
#define TUN_INPUT_REG(NUM) \
15
xf86AddDeviceAssoc (&linput ## NUM ## _assoc)
17
#define TUN_INPUT_GEN(NUM) \
19
static LocalDevicePtr \
20
tunAllocate ## NUM () \
22
return tunAllocate (NUM, "LInput" #NUM); \
25
DeviceAssocRec linput ## NUM ## _assoc = \
27
"linput" #NUM, /* config_section_name */ \
28
tunAllocate ## NUM /* device_allocate */ \
31
/***********************************************************************/
38
#define MOUSEWHEELHACK 6
41
#define NOAUTOCONFIG 9
44
#define REL_VALUATOR 12
45
#define ABS_VALUATOR 13
48
#define DONT_FINISH_UNASIGNED 16
51
static SymTabRec ValuatorTab [] = {
52
{ ENDVALUATOR, "endvaluator"},
58
{ REVERSE, "reverse" },
59
{ MOUSEWHEELHACK, "mousewheelhack"},
60
{ DISABLE, "disable"},
64
static SymTabRec TunTab [] = {
65
{ ENDSUBSECTION, "endsubsection"},
66
{ DONT_FINISH_UNASIGNED, "dontfinishunasigned"},
68
{ DEVICENAME, "devicename" },
70
{ NOAUTOCONFIG, "noautoconfig"},
71
{ ABSOLUTE, "absolute"},
72
{ TIMEDELTA, "timedelta"},
74
{ REL_VALUATOR, "relativevaluator"},
75
{ ABS_VALUATOR, "absolutevaluator"},
91
tunConfigAbsValuator (LocalDevicePtr local,
93
TunValuatorPtr valuator,
98
TLOG ("[%s] Configuring valuator %d (%s)", local->name,
99
valuator->lid, tunGetAbsValuatorName (valuator->lid));
101
while ((token = xf86GetToken (ValuatorTab)) != ENDVALUATOR)
105
if (xf86GetToken (NULL) != NUMBER || val->num < 0)
106
xf86ConfigError ("Valuator number expected");
108
if (valuator->xiv >= 0)
109
tun->xval_to_lval_tbl [valuator->xiv] = NULL;
111
tunDeviceRecForceXValuators (tun, val->num);
113
if (tun->xval_to_lval_tbl [val->num] != NULL)
114
tun->xval_to_lval_tbl [val->num] -> xiv = TUN_VALUATOR_UNASSIGNED;
116
tun->xval_to_lval_tbl [val->num] = valuator;
117
valuator->xiv = val->num;
121
if (xf86GetToken (NULL) != NUMBER)
122
xf86ConfigError ("0 or 1 expected");
123
valuator->upsidedown = (val->num != 0);
127
if (valuator->xiv >= 0)
128
tun->xval_to_lval_tbl [valuator->xiv] = NULL;
129
valuator->xiv = TUN_VALUATOR_DISABLED;
135
xf86ConfigError ("Only relative valuators can use this option");
139
FatalError("Unexpected EOF (missing EndSubSection)");
142
xf86ConfigError("LInput valuator subsection keyword expected");
149
tunConfigRelValuator (LocalDevicePtr local,
151
TunValuatorPtr valuator,
156
TLOG ("[%s] Configuring valuator %d (%s)", local->name,
157
valuator->lid, tunGetRelValuatorName (valuator->lid));
159
while ((token = xf86GetToken (ValuatorTab)) != ENDVALUATOR)
163
if (xf86GetToken (NULL) != NUMBER || val->num < 0)
164
xf86ConfigError ("Valuator number expected");
166
if (valuator->xiv >= 0)
167
tun->xval_to_lval_tbl [valuator->xiv] = NULL;
169
tunDeviceRecForceXValuators (tun, val->num);
171
if (tun->xval_to_lval_tbl [val->num] != NULL)
172
tun->xval_to_lval_tbl [val->num] -> xiv = TUN_VALUATOR_UNASSIGNED;
174
tun->xval_to_lval_tbl [val->num] = valuator;
175
valuator->xiv = val->num;
179
if (xf86GetToken (NULL) != NUMBER)
180
xf86ConfigError ("0 or 1 expected");
181
valuator->upsidedown = (val->num != 0);
185
if (valuator->xiv >= 0)
186
tun->xval_to_lval_tbl [valuator->xiv] = NULL;
187
valuator->xiv = TUN_VALUATOR_DISABLED;
191
if (xf86GetToken (NULL) != NUMBER)
192
xf86ConfigError ("Number expected");
194
valuator->min = val->num;
198
if (xf86GetToken (NULL) != NUMBER)
199
xf86ConfigError ("Number expected");
201
valuator->max = val->num;
205
if (xf86GetToken (NULL) != NUMBER)
206
xf86ConfigError ("0 or 1 expected");
208
valuator->mouse_wheel_hack = (val->num != 0);
212
FatalError("Unexpected EOF (missing EndSubSection)");
215
xf86ConfigError("LInput valuator subsection keyword expected");
220
/** Parse SubSection of XF86Config file
223
tunConfig (LocalDevicePtr *array,
228
LocalDevicePtr local = array [index];
229
TunDevicePtr tun = (TunDevicePtr) local -> private;
230
int token, fd, i, finish = TRUE;
232
TunDeviceVersionInfo version_info;
233
TunDeviceInfo device_info;
235
if (tun_switch_device == NULL)
236
for (i = 0; i < max; i++)
237
if (strcmp (array [i]->name, "SWITCH") == 0)
238
{ tun_switch_device = array [i]; }
240
if (! tun_switch_device)
241
TLOG ("Can not found SWITCH device :(");
243
TLOG ("Config of device %s", local -> name);
245
if ((token = xf86GetToken (TunTab)) == DEVICE)
247
if (xf86GetToken (NULL) != STRING)
248
xf86ConfigError ("String expected");
250
t_free (tun->input_device);
251
tun->input_device = strdup (val->str);
252
token = xf86GetToken (TunTab);
255
if ((fd = open (tun->input_device, O_RDONLY)) == 0)
257
ErrorF ("Can not open %s file", tun->input_device);
258
xf86ConfigError ("Can not open linux input device file");
261
if (tunQueryLinuxDriverVesrion (fd, &version_info) != Success)
262
xf86ConfigError ("Bad Linux Input driver version or IOCTL interface does not work :(");
264
tunQueryDeviceID (fd, tun->device_ID);
267
char *name = tunQueryDeviceName (fd);
268
TLOG ("[%s]: %s", local->name, name);
272
tunQueryDevice (fd, device_info);
273
tunInitDeviceRec (fd, local, tun, device_info);
275
TLOG ("TOKEN: %d", token);
276
if (token != NOAUTOCONFIG)
277
tunAutoconfigDeviceRec (local, tun, device_info);
279
token = xf86GetToken (TunTab);
281
for ( /* NOP ! (WOW :) */ ;
282
(token != ENDSUBSECTION) ;
283
token = xf86GetToken (TunTab))
287
if (xf86GetToken (NULL) != STRING)
288
xf86ConfigError ("Option string expected");
289
TLOG ("LInput X device name changed from %s to %s", local->name, val->str);
291
local->name = strdup (val->str);
296
xf86ConfigError ("This option is only allowed at the beginning of this section");
300
if (xf86GetToken (NULL) != NUMBER)
301
xf86ConfigError ("Expected 0 or positive integer.");
303
tun->is_absolute = (val->num != 0);
307
if (xf86GetToken (NULL) != NUMBER)
308
xf86ConfigError ("Number expected.");
310
tun->delta_time = val->num;
316
switch (xf86GetToken (NULL))
318
case NUMBER: lid = val->num; break;
319
case STRING: lid = tunLookUpAbsValuator (val->str); break;
323
xf86ConfigError ("Abs valuator name or id expected");
325
if (TUN_DEVICE_TEST_VAL_ABS (device_info, lid))
326
tunConfigAbsValuator (local, tun,
327
tun->avaluators + (lid - tun->first_avaluator),
330
TLOG ("[%s] device does not have valuator %d (%s)",
331
local->name, lid, tunGetAbsValuatorName (lid)) ;
338
switch (xf86GetToken (NULL))
340
case NUMBER: lid = val->num; break;
341
case STRING: lid = tunLookUpRelValuator (val->str); break;
345
xf86ConfigError ("Abs valuator name or id expected");
348
if (TUN_DEVICE_TEST_VAL_REL (device_info, lid))
349
tunConfigRelValuator (local, tun,
350
tun->rvaluators + (lid - tun->first_rvaluator),
353
TLOG ("[%s] device does not have valuator %d (%s)",
354
local->name, lid, tunGetRelValuatorName (lid)) ;
360
int but = -5, lbut = -1;
362
switch (xf86GetToken (NULL))
365
lbut = KEY_TO_BUTTON (tunLookUpKey (val->str));
372
xf86ConfigError ("Button identifier expected");
374
switch (xf86GetToken (NULL))
381
if (StrCaseCmp (val->str, "disabled") == 0)
382
but = TUN_BUTTON_UNASSIGNED;
383
else if (StrCaseCmp (val->str, "proximity") == 0)
384
but = TUN_BUTTON_PROXIMITY;
388
if (TUN_DEVICE_TEST_KEY (device_info, lbut) == 0)
390
TLOG ("Warning: button %s not found in device %s. IGNORED",
391
tunGetKeyName (lbut), local->name);
396
xf86ConfigError ("Expected positive integer, \"Disabled\" or \"Proximity\"");
398
tun->lbut_to_xbut_tbl [lbut - tun->first_lbutton] = but;
402
case DONT_FINISH_UNASIGNED:
407
FatalError("Unexpected EOF (missing EndSubSection)");
410
xf86ConfigError("LInput subsection keyword expected");
415
tunFinishUnasigned (local, tun, device_info);
417
tunDeviceRecFinalize (tun);
421
ErrorF("%s %s: Configured.\n", XCONFIG_GIVEN, local->name);
426
/** Init module on X server start.
430
init_module (unsigned long server_version)
435
"******************************************************************************************");
436
TLOG ("Tuntitko 0.1 - Linux Input Driver... Loaded");
447
if (server_version != XF86_VERSION_CURRENT)
449
ErrorF ("Warning: Tuntitko compiled for version %s\n", XF86_VERSION);