~ubuntu-branches/ubuntu/lucid/xf86-input-evtouch/lucid-proposed

« back to all changes in this revision

Viewing changes to .pc/04_server-1.7-ftbfs.diff/evtouch.c

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2010-03-23 12:32:10 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100323123210-tbigv48eub4e2wwh
Tags: 0.8.8-2build1
* Fakesync with Debian unstable (different .orig.tar.gz)
  + Drop fdi files since we no longer use HAL.
  + Fix to calibration code was taken upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * Copyright 2004 by Kenan Esau <kenan.esau@conan.de>, Baltmannsweiler, 
 
4
 * Germany.
 
5
 *
 
6
 * Permission to use, copy, modify, distribute, and sell this software and its
 
7
 * documentation for any purpose is hereby granted without fee, provided that
 
8
 * the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the names of copyright holders not be
 
11
 * used in advertising or publicity pertaining to distribution of the
 
12
 * software without specific, written prior permission.  The copyright holders
 
13
 * make no representations about the suitability of this
 
14
 * software for any purpose.  It is provided "as is" without express or
 
15
 * implied warranty.
 
16
 *
 
17
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
 
18
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 
19
 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
 
20
 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 
21
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 
22
 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 
23
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
24
 *
 
25
 */
 
26
 
 
27
#ifdef HAVE_CONFIG_H
 
28
#include "config.h"
 
29
#endif
 
30
 
 
31
#define _evdev_touch_C_
 
32
 
 
33
#include <xorgVersion.h>
 
34
#define XFREE86_V4
 
35
 
 
36
/*****************************************************************************
 
37
 *        Standard Headers
 
38
 ****************************************************************************/
 
39
#ifdef XFREE86_V4
 
40
#include <unistd.h>
 
41
#else
 
42
#include <stdio.h>
 
43
#include <stdlib.h>
 
44
#endif
 
45
#include <string.h>
 
46
#include <errno.h>
 
47
 
 
48
#include <sys/types.h>
 
49
#include <sys/stat.h>
 
50
#include <fcntl.h>
 
51
#include <sys/ioctl.h>
 
52
 
 
53
#ifndef EVIOCGRAB
 
54
#define EVIOCGRAB _IOW('E', 0x90, int)
 
55
#endif
 
56
 
 
57
#define NEED_EVENTS
 
58
#include <X11/X.h>
 
59
#include <X11/Xproto.h>
 
60
 
 
61
#include "xf86.h"
 
62
 
 
63
#ifdef XINPUT
 
64
#include <X11/extensions/XI.h>
 
65
#include <X11/extensions/XIproto.h>
 
66
#include "extnsionst.h"
 
67
#include "extinit.h"
 
68
#else
 
69
#include "inputstr.h"
 
70
#endif
 
71
 
 
72
#include "xf86_OSproc.h"
 
73
#include "xf86Xinput.h"
 
74
#include "exevents.h"
 
75
#include "randrstr.h"
 
76
 
 
77
#ifndef NEED_XF86_TYPES
 
78
#define NEED_XF86_TYPES /* for xisb.h when !XFree86LOADER */
 
79
#endif
 
80
 
 
81
#define DBG(lvl, f) {if ((lvl) <= debug_level) f;}
 
82
 
 
83
#include "compiler.h"
 
84
#include "xisb.h"
 
85
 
 
86
#include <linux/input.h>
 
87
 
 
88
/*****************************************************************************
 
89
 *        Local Headers
 
90
 ****************************************************************************/
 
91
#include "libtouch.h"
 
92
#include "evtouch.h"
 
93
 
 
94
/*****************************************************************************
 
95
 *        Variables without includable headers
 
96
 ****************************************************************************/
 
97
 
 
98
/*****************************************************************************
 
99
 *        Local Variables
 
100
 ****************************************************************************/
 
101
 
 
102
 
 
103
static InputInfoPtr
 
104
EVTouchPreInit(InputDriverPtr drv, IDevPtr dev, int flags);
 
105
static void
 
106
EVTouchPtrCtrl(DeviceIntPtr device, PtrCtrl *ctrl);
 
107
static Bool
 
108
ConvertProc ( LocalDevicePtr local,
 
109
              int first,
 
110
              int num,
 
111
              int v0,
 
112
              int v1,
 
113
              int v2,
 
114
              int v3,
 
115
              int v4,
 
116
              int v5,
 
117
              int *x,
 
118
              int *y );
 
119
 
 
120
static int debug_level = 0;
 
121
 
 
122
InputDriverRec EVTOUCH = {
 
123
        1,
 
124
        "evtouch",
 
125
        NULL,
 
126
        EVTouchPreInit,
 
127
        /*EVTouchUnInit*/ NULL,
 
128
        NULL,
 
129
        0
 
130
};
 
131
 
 
132
#ifdef XFree86LOADER
 
133
static XF86ModuleVersionInfo VersionRec =
 
134
{
 
135
        "evtouch",
 
136
        "Kenan Esau",
 
137
        MODINFOSTRING1,
 
138
        MODINFOSTRING2,
 
139
        XORG_VERSION_CURRENT,
 
140
        0, 8, 8,
 
141
        ABI_CLASS_XINPUT,
 
142
        ABI_XINPUT_VERSION,
 
143
        MOD_CLASS_XINPUT,
 
144
        {0, 0, 0, 0}         /* signature, to be patched into the file by
 
145
                              * a tool */
 
146
};
 
147
 
 
148
 
 
149
static pointer
 
150
Plug( pointer module,
 
151
      pointer options,
 
152
      int *errmaj,
 
153
      int *errmin )
 
154
{
 
155
        xf86AddInputDriver(&EVTOUCH, module, 0);
 
156
        return module;
 
157
}
 
158
 
 
159
 
 
160
static void
 
161
Unplug(pointer p)
 
162
{
 
163
        DBGOUT(1, "EVTouch: Unplug\n");
 
164
}
 
165
 
 
166
 
 
167
XF86ModuleData evtouchModuleData = {&VersionRec, Plug, Unplug };
 
168
 
 
169
#endif /* XFree86LOADER */
 
170
 
 
171
 
 
172
static const char *default_options[] =
 
173
{
 
174
        "BaudRate", "9600",
 
175
        "StopBits", "1",
 
176
        "DataBits", "8",
 
177
        "Parity", "None",
 
178
        "Vmin", "5",
 
179
        "Vtime", "1",
 
180
        "FlowControl", "None"
 
181
};
 
182
 
 
183
static int
 
184
ControlProc(LocalDevicePtr device, xDeviceCtl *ctrl);
 
185
 
 
186
/*****************************************************************************
 
187
 *        Function Definitions
 
188
 ****************************************************************************/
 
189
 
 
190
 
 
191
static CARD32
 
192
emulate3Timer(OsTimerPtr timer, CARD32 now, pointer _local)
 
193
{
 
194
        int sigstate;
 
195
 
 
196
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
197
 
 
198
        LocalDevicePtr local = (LocalDevicePtr)_local;
 
199
        EVTouchPrivatePtr priv = (EVTouchPrivatePtr) local->private;
 
200
 
 
201
        sigstate = xf86BlockSIGIO();
 
202
 
 
203
        xf86PostMotionEvent(local->dev, TRUE, 0, 2, 
 
204
                            priv->cur_x, 
 
205
                            priv->cur_y);
 
206
 
 
207
        /* 
 
208
         * Emit a button press -- release is handled in EVTouchLBRBEvent
 
209
         */
 
210
        if ( ( priv->touch_flags & LB_STAT ) &&
 
211
             !( priv->touch_flags & RB_STAT ) ) {
 
212
                DBGOUT(2, "EVTouch: Left Press\n");
 
213
                xf86PostButtonEvent (local->dev, TRUE,
 
214
                                     1, 1, 0, 2, 
 
215
                                     priv->cur_x, 
 
216
                                     priv->cur_y);
 
217
        }
 
218
 
 
219
        if ( ( priv->touch_flags & RB_STAT ) &&
 
220
             !( priv->touch_flags & LB_STAT ) ) {
 
221
                DBGOUT(2, "EVTouch: Right Press\n");
 
222
                xf86PostButtonEvent (local->dev, TRUE,
 
223
                                     3, 1, 0, 2, 
 
224
                                     priv->cur_x, 
 
225
                                     priv->cur_y);
 
226
        }
 
227
 
 
228
        /*
 
229
          Handling "middle" button press
 
230
        */
 
231
        if ( ( priv->touch_flags & RB_STAT ) &&
 
232
             ( priv->touch_flags & LB_STAT ) ) {
 
233
                DBGOUT(2, "EVTouch: Middle Press\n");
 
234
                xf86PostButtonEvent (local->dev, TRUE,
 
235
                                     2, 1, 0, 2, 
 
236
                                     priv->cur_x, 
 
237
                                     priv->cur_y);
 
238
        }
 
239
 
 
240
        priv->emulate3_timer_expired = TRUE;
 
241
        xf86UnblockSIGIO(sigstate);
 
242
             
 
243
        return 0;
 
244
}
 
245
 
 
246
static void DoBtnAction(EVTouchPrivatePtr priv) 
 
247
{
 
248
        int btn = 0;
 
249
        LocalDevicePtr local = priv->local;
 
250
        DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__, priv->btn_count);
 
251
 
 
252
        for (btn = 0; btn < priv->btn_count; btn++) {
 
253
                DBGOUT(9, "EVTouch: %s do_it = %d \n", 
 
254
                       __FUNCTION__, priv->btn_actions[btn].do_it);
 
255
                if (priv->btn_actions[btn].do_it != 0) {
 
256
                        if (priv->emulate3_timer != NULL)
 
257
                        {
 
258
                                TimerFree(priv->emulate3_timer);
 
259
                                priv->emulate3_timer=NULL;
 
260
                                priv->emulate3_timer_expired = FALSE;
 
261
                        }
 
262
 
 
263
                        DBGOUT(2, "EVTouch: %s btn = %d action = %d\n", 
 
264
                               __FUNCTION__, btn, 
 
265
                               priv->btn_actions[btn].action);
 
266
 
 
267
                        xf86PostButtonEvent (local->dev, TRUE, btn, 
 
268
                                             priv->btn_actions[btn].action, 
 
269
                                             0, 2,
 
270
                                             priv->cur_x,
 
271
                                             priv->cur_y);
 
272
 
 
273
                        priv->btn_actions[btn].do_it  = 0;
 
274
                        priv->btn_actions[btn].action = 0;
 
275
                }
 
276
        }
 
277
}
 
278
 
 
279
static void SetBtnAction(EVTouchPrivatePtr priv, int btn, int action)
 
280
{
 
281
        DBGOUT(2, "EVTouch: %s btn = %d action = %d\n", __FUNCTION__,
 
282
               btn, action);
 
283
        if (btn < priv->btn_count) {
 
284
                priv->btn_actions[btn].do_it  = 1;
 
285
                priv->btn_actions[btn].action = action;
 
286
        }
 
287
}
 
288
 
 
289
void EVTouchProcessAbs(EVTouchPrivatePtr priv)
 
290
{
 
291
        struct input_event *ev; /* packet being/just read */
 
292
        int pos_changed = 0;
 
293
        ev = &priv->ev;
 
294
 
 
295
        if ( (ev->code == ABS_X) || (ev->code == ABS_Z) ) {
 
296
                priv->raw_x = ev->value;
 
297
                pos_changed = 1;
 
298
        }
 
299
 
 
300
        if ( (ev->code == ABS_Y) || (ev->code == ABS_RX) ) {
 
301
                priv->raw_y = ev->value;
 
302
                pos_changed = 1;
 
303
        }
 
304
 
 
305
        if (pos_changed == 1) {
 
306
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 2
 
307
                ConvertProc(priv->local, 0, 2, 
 
308
                            priv->raw_x, priv->raw_y,
 
309
                            0, 0, 0, 0, 
 
310
                            &priv->cur_x, &priv->cur_y);
 
311
#endif
 
312
 
 
313
                libtouchSetPos(priv->libtouch, priv->cur_x, priv->cur_y);
 
314
                return;
 
315
        }
 
316
 
 
317
        if (ev->code == ABS_WHEEL) {
 
318
                LocalDevicePtr local = priv->local;
 
319
 
 
320
                if (ev->value > 0) {
 
321
                        for (; ev->value > 0; ev->value--) {
 
322
                                xf86PostButtonEvent (local->dev, TRUE,
 
323
                                                     4, 1, 0, 2, 
 
324
                                                     priv->cur_x, 
 
325
                                                     priv->cur_y);
 
326
                                xf86PostButtonEvent (local->dev, TRUE,
 
327
                                                     4, 0, 0, 2, 
 
328
                                                     priv->cur_x, 
 
329
                                                     priv->cur_y);
 
330
                        }
 
331
                } else if (ev->value < 0) {
 
332
                        for (ev->value = -ev->value; ev->value > 0; ev->value--) {
 
333
                                xf86PostButtonEvent (local->dev, TRUE,
 
334
                                                     5, 1, 0, 2, 
 
335
                                                     priv->cur_x, 
 
336
                                                     priv->cur_y);
 
337
                                xf86PostButtonEvent (local->dev, TRUE,
 
338
                                                     5, 0, 0, 2, 
 
339
                                                     priv->cur_x, 
 
340
                                                     priv->cur_y);
 
341
                        }
 
342
                }                       
 
343
        }
 
344
}
 
345
 
 
346
 
 
347
 
 
348
 
 
349
void EVTouchProcessRel(EVTouchPrivatePtr priv)
 
350
{
 
351
        struct input_event *ev; /* packet being/just read */
 
352
 
 
353
        ev = &priv->ev;
 
354
        if ( ev->code == REL_X ) {
 
355
                priv->raw_x += ev->value;
 
356
                if (priv->raw_x > priv->max_x)
 
357
                        priv->raw_x = priv->max_x;
 
358
                if (priv->raw_x < priv->min_x)
 
359
                        priv->raw_x = priv->min_x;
 
360
        } 
 
361
        if ( ev->code == REL_Y ) {
 
362
                priv->raw_y += ev->value;
 
363
                if (priv->raw_y > priv->max_y)
 
364
                        priv->raw_y = priv->max_y;
 
365
                if (priv->raw_y < priv->min_y)
 
366
                        priv->raw_y = priv->min_y;
 
367
        }
 
368
 
 
369
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 2
 
370
        ConvertProc(priv->local, 0, 2,
 
371
                    priv->raw_x, priv->raw_y,
 
372
                    0, 0, 0, 0,
 
373
                    &priv->cur_x, &priv->cur_y);
 
374
#endif
 
375
        
 
376
        libtouchSetPos(priv->libtouch, priv->cur_x, priv->cur_y);
 
377
}
 
378
 
 
379
 
 
380
 
 
381
 
 
382
void EVTouchLBRBEvent(EVTouchPrivatePtr priv)
 
383
{
 
384
        struct input_event *ev; /* packet being/just read */
 
385
        LocalDevicePtr local = priv->local;
 
386
 
 
387
        ev = &priv->ev;
 
388
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
389
 
 
390
        if (priv->emulate3) {
 
391
                if ( (ev->value==1) && (priv->emulate3_timer==NULL) )
 
392
                        priv->emulate3_timer = TimerSet(priv->emulate3_timer, 
 
393
                                                        0,
 
394
                                                        priv->emulate3_timeout,
 
395
                                                        emulate3Timer,
 
396
                                                        local);
 
397
                
 
398
                if ( (ev->value == 1) && (ev->code == BTN_LEFT) ) {
 
399
                        priv->touch_flags |= LB_STAT;
 
400
                }
 
401
                if ( (ev->value == 1) && (ev->code == BTN_RIGHT) ) {
 
402
                        priv->touch_flags |= RB_STAT;
 
403
                }
 
404
 
 
405
                if ( (ev->value == 0) && 
 
406
                     (priv->touch_flags & RB_STAT) && 
 
407
                     (priv->touch_flags & LB_STAT) ) {
 
408
                        DBGOUT(2, "EVTouch: Middle Release\n");
 
409
                        priv->touch_flags &= ~LB_STAT;
 
410
                        priv->touch_flags &= ~RB_STAT;
 
411
                        SetBtnAction(priv, 2, BTN_RELEASE);
 
412
                } else if ( (ev->value == 0) && (ev->code == BTN_LEFT) &&
 
413
                     (priv->touch_flags & LB_STAT) ) {
 
414
                        DBGOUT(2, "EVTouch: Left Release\n");
 
415
                        priv->touch_flags &= ~LB_STAT;
 
416
                        SetBtnAction(priv, 1, BTN_RELEASE);
 
417
                } else if ( (ev->value == 0) && (ev->code == BTN_RIGHT) &&
 
418
                     (priv->touch_flags & RB_STAT) ) {
 
419
                        DBGOUT(2, "EVTouch: Right Release\n");
 
420
                        priv->touch_flags &= ~RB_STAT;
 
421
                        SetBtnAction(priv, 3, BTN_RELEASE);
 
422
                }                                
 
423
        } else {
 
424
                if (ev->code == BTN_LEFT) {
 
425
                        SetBtnAction(priv, 1, ev->value);
 
426
                }
 
427
 
 
428
                if (ev->code == BTN_MIDDLE) {
 
429
                        SetBtnAction(priv, 2, ev->value);
 
430
                }
 
431
 
 
432
                if (ev->code == BTN_RIGHT) {
 
433
                        SetBtnAction(priv, 3, ev->value);
 
434
                }
 
435
        }
 
436
}
 
437
 
 
438
 
 
439
 
 
440
 
 
441
void EVTouchProcessKey(EVTouchPrivatePtr priv)
 
442
{
 
443
        struct input_event *ev; /* packet being/just read */
 
444
 
 
445
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
446
        ev = &priv->ev;
 
447
        if ( (ev->code == BTN_LEFT) || 
 
448
             (ev->code == BTN_RIGHT) ||
 
449
             (ev->code == BTN_MIDDLE) ) {
 
450
 
 
451
                /* give lb and rb-events some special treatment 
 
452
                   (emulate3 or not, ...) */
 
453
                EVTouchLBRBEvent(priv);
 
454
                return;
 
455
        }
 
456
 
 
457
#ifdef _0_
 
458
        switch (ev->code) {
 
459
        case BTN_SIDE:
 
460
                break;
 
461
        case BTN_EXTRA:
 
462
                break;
 
463
        case BTN_FORWARD:
 
464
                break;
 
465
        case BTN_BACK:
 
466
                break;
 
467
        case BTN_TASK:
 
468
                break;
 
469
        default:
 
470
                return;
 
471
        }
 
472
        xf86PostButtonEvent(local->dev, TRUE,
 
473
                            btn, ev->value, 0, 2, 
 
474
                            priv->cur_x, 
 
475
                            priv->cur_y);
 
476
#endif
 
477
 
 
478
        return;
 
479
}
 
480
 
 
481
 
 
482
 
 
483
 
 
484
static Bool
 
485
QueryHardware (LocalDevicePtr local)
 
486
{
 
487
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
488
 
 
489
        return Success;
 
490
}
 
491
 
 
492
 
 
493
 
 
494
 
 
495
static Bool
 
496
DeviceOn (DeviceIntPtr dev)
 
497
{
 
498
        LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
 
499
        EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
 
500
        
 
501
        local->fd = xf86OpenSerial(local->options);
 
502
 
 
503
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__ );
 
504
 
 
505
        if (local->fd == -1)
 
506
        {
 
507
                xf86Msg(X_WARNING, "%s: cannot open input device\n", local->name);
 
508
                return (!Success);
 
509
        }
 
510
 
 
511
        priv->buffer = XisbNew(local->fd, 64);
 
512
 
 
513
        DBG (9, XisbTrace (priv->buffer, 1));
 
514
 
 
515
 
 
516
        if (!priv->buffer) 
 
517
        {
 
518
                xf86CloseSerial(local->fd);
 
519
                local->fd = -1;
 
520
                return (!Success);
 
521
        }
 
522
 
 
523
        if (QueryHardware(local) != Success)
 
524
        {
 
525
                ErrorF ("Unable to query/initialize EVTouch hardware.\n");
 
526
                return (!Success);
 
527
        }
 
528
 
 
529
        xf86FlushInput(local->fd);
 
530
 
 
531
        if (ioctl(local->fd, EVIOCGRAB, (void *)1))
 
532
                xf86Msg(X_ERROR, "%s: Unable to grab device (%s).\n", local->name, strerror(errno));
 
533
 
 
534
 
 
535
#ifndef XFREE86_V4
 
536
        xf86AddEnabledDevice(local);
 
537
#else
 
538
        AddEnabledDevice(local->fd);
 
539
#endif
 
540
 
 
541
        dev->public.on = TRUE;
 
542
 
 
543
        return (Success);
 
544
}
 
545
 
 
546
 
 
547
 
 
548
 
 
549
static Bool
 
550
DeviceOff (DeviceIntPtr dev)
 
551
{
 
552
        LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
 
553
        EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
 
554
 
 
555
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__ );
 
556
 
 
557
        if (local->fd != -1)
 
558
        { 
 
559
                ioctl(local->fd, EVIOCGRAB, (void *)0);
 
560
                xf86RemoveEnabledDevice (local);
 
561
                if (priv->buffer)
 
562
                {
 
563
                        XisbFree(priv->buffer);
 
564
                        priv->buffer = NULL;
 
565
                }
 
566
                xf86CloseSerial(local->fd);
 
567
                local->fd = -1;
 
568
        }
 
569
 
 
570
        dev->public.on = FALSE;
 
571
 
 
572
        if ( (priv->calibrate) && (priv->fifo>0) ){
 
573
                close (priv->fifo);
 
574
        }
 
575
 
 
576
        return (Success);
 
577
}
 
578
 
 
579
 
 
580
 
 
581
 
 
582
static Bool
 
583
DeviceInit (DeviceIntPtr dev)
 
584
{
 
585
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
586
        LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
 
587
        EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
 
588
        unsigned char map[EV_MAX_BUTTONS];
 
589
        int i;
 
590
 
 
591
        for (i = 0; i < EV_MAX_BUTTONS; i++)
 
592
                map[i] = i;
 
593
 
 
594
        priv->btn_count = EV_MAX_BUTTONS;
 
595
 
 
596
        /* 
 
597
         * these have to be here instead of in the SetupProc, because when the
 
598
         * SetupProc is run at server startup, screenInfo is not setup yet
 
599
         */
 
600
 
 
601
        ScrnInfoPtr   pScrn = xf86Screens[priv->screen_num];
 
602
        priv->screen_width  = pScrn->virtualX;     /* It's the virtual screen size ! */
 
603
        priv->screen_height = pScrn->virtualY;
 
604
        priv->pViewPort_X0  = &(pScrn->frameX0);   /* initialize the pointers to the viewport coords */
 
605
        if ( (priv->screen_width != priv->phys_width) ||
 
606
             (priv->screen_height != priv->phys_height) ) 
 
607
              priv->virtual = 1;
 
608
        else  
 
609
                priv->virtual = 0;
 
610
 
 
611
        priv->pViewPort_Y0  = &(pScrn->frameY0);
 
612
        priv->pViewPort_X1  = &(pScrn->frameX1);
 
613
        priv->pViewPort_Y1  = &(pScrn->frameY1);
 
614
 
 
615
        DBGOUT(2, "EVTouch: Display X,Y: %d %d\n", priv->phys_width, priv->phys_height);
 
616
        DBGOUT(2, "EVTouch: Virtual X,Y: %d %d\n", priv->screen_width, priv->screen_height);
 
617
        DBGOUT(2, "EVTouch: DriverName, Rev.: %s %d\n", pScrn->driverName, pScrn->driverVersion);
 
618
        DBGOUT(2, "EVTouch: Viewport X0,Y0: %d %d\n", *priv->pViewPort_X0, *priv->pViewPort_Y0);
 
619
        DBGOUT(2, "EVTouch: Viewport X1,Y1: %d %d\n", *priv->pViewPort_X1, *priv->pViewPort_Y1);
 
620
        DBGOUT(2, "EVTouch: MaxValue H,V: %d %d\n", pScrn->maxHValue, pScrn->maxVValue);
 
621
 
 
622
        priv->screen_width = screenInfo.screens[priv->screen_num]->width;
 
623
        priv->screen_height = screenInfo.screens[priv->screen_num]->height;        
 
624
 
 
625
        /* 
 
626
         * Device reports button press for 5 buttons.
 
627
         */
 
628
        if (InitButtonClassDeviceStruct (dev, EV_MAX_BUTTONS, map) == FALSE)
 
629
        {
 
630
                ErrorF("Unable to allocate EVTouch touchscreen ButtonClassDeviceStruct\n");
 
631
                return BadAlloc;
 
632
        } 
 
633
 
 
634
        DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__, 
 
635
               priv->btn_count);
 
636
        priv->btn_actions = xcalloc(priv->btn_count, sizeof(BtnAction));
 
637
        memset(priv->btn_actions, 0, 
 
638
               priv->btn_count * sizeof(BtnAction));
 
639
        
 
640
        DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__, 
 
641
               priv->btn_count);
 
642
 
 
643
        if (InitFocusClassDeviceStruct(dev) == FALSE) {
 
644
                ErrorF("Unable to allocate EVTouch touchscreen FocusClassDeviceStruct\n");
 
645
                return !Success;
 
646
        }
 
647
 
 
648
        /* 
 
649
         * Device reports motions on 2 axes in absolute coordinates.
 
650
         * Axes min and max values are reported in raw coordinates.
 
651
         */
 
652
        if (InitValuatorClassDeviceStruct(dev, 2,
 
653
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
 
654
                                          xf86GetMotionEvents,
 
655
#endif
 
656
                                          local->history_size, Absolute) == FALSE)
 
657
        {
 
658
                ErrorF ("Unable to allocate EVTouch touchscreen ValuatorClassDeviceStruct\n");
 
659
                return !Success;
 
660
        }
 
661
 
 
662
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 2
 
663
        xf86InitValuatorAxisStruct(dev, 0, 0, priv->screen_width,
 
664
                                   1024,
 
665
                                   EV_AXIS_MIN_RES /* min_res */ ,
 
666
                                   EV_AXIS_MAX_RES /* max_res */ );
 
667
        xf86InitValuatorDefaults(dev, 0);
 
668
        xf86InitValuatorAxisStruct(dev, 1, 0, priv->screen_height,
 
669
                                   1024,
 
670
                                   EV_AXIS_MIN_RES /* min_res */ ,
 
671
                                   EV_AXIS_MAX_RES /* max_res */ );
 
672
        xf86InitValuatorDefaults(dev, 1);
 
673
#else
 
674
        xf86InitValuatorAxisStruct(dev, 0, priv->min_x, priv->max_x,
 
675
        xf86InitValuatorDefaults(dev, 1);
 
676
#endif
 
677
 
 
678
        /* Initial position of pointer on screen: Centered */
 
679
        priv->cur_x=(priv->max_x - priv->min_x)/2;
 
680
        priv->cur_y=(priv->max_y - priv->min_y)/2;
 
681
        priv->raw_x=priv->cur_x;
 
682
        priv->raw_y=priv->cur_y;
 
683
        libtouchSetPos(priv->libtouch, priv->cur_x, priv->cur_y);
 
684
 
 
685
        
 
686
        if (InitProximityClassDeviceStruct (dev) == FALSE)
 
687
        {
 
688
                ErrorF ("Unable to allocate EVTouch touchscreen ProximityClassDeviceStruct\n");
 
689
                return !Success;
 
690
        }
 
691
 
 
692
        if (InitPtrFeedbackClassDeviceStruct(dev, EVTouchPtrCtrl) == FALSE)
 
693
        {
 
694
                ErrorF ("unable to allocate EVTouch touchscreen PtrFeedbackClassDeviceStruct\n");
 
695
                return !Success;
 
696
        }
 
697
 
 
698
        /* 
 
699
         * Allocate the motion events buffer.
 
700
         */
 
701
        xf86MotionHistoryAllocate (local);
 
702
        return (Success);
 
703
}
 
704
 
 
705
 
 
706
 
 
707
 
 
708
static Bool
 
709
DeviceControl (DeviceIntPtr dev,
 
710
               int mode)
 
711
{
 
712
        Bool        RetValue;
 
713
 
 
714
        switch (mode)
 
715
        {
 
716
        case DEVICE_INIT:
 
717
                RetValue = DeviceInit(dev);
 
718
                break;
 
719
        case DEVICE_ON:
 
720
                RetValue = DeviceOn(dev);
 
721
                break;
 
722
        case DEVICE_OFF:
 
723
        case DEVICE_CLOSE:
 
724
                RetValue = DeviceOff(dev);
 
725
                break;
 
726
        default:
 
727
                RetValue = BadValue;
 
728
        }
 
729
 
 
730
        return( RetValue );
 
731
}
 
732
 
 
733
 
 
734
 
 
735
 
 
736
static void
 
737
EVTouchNewPacket (EVTouchPrivatePtr priv)
 
738
{
 
739
        memset(&priv->ev, 0, sizeof(struct input_event));
 
740
        priv->packeti = 0;
 
741
        priv->binary_pkt = FALSE;
 
742
}
 
743
 
 
744
 
 
745
 
 
746
 
 
747
static Bool
 
748
EVTouchGetPacket (EVTouchPrivatePtr priv)
 
749
{
 
750
        static int count = 0;
 
751
        int c;
 
752
        CARD32 now;
 
753
 
 
754
        if (count==0) EVTouchNewPacket(priv);
 
755
 
 
756
        while ((c = XisbRead(priv->buffer)) >= 0) {
 
757
                if (count == 0) {
 
758
                        now = GetTimeInMillis();
 
759
                        libtouchSetTime(priv->libtouch, now);
 
760
                }
 
761
 
 
762
                ((char *)&priv->ev)[count] = c;
 
763
                count ++;
 
764
 
 
765
                if (sizeof(priv->ev) == count) {
 
766
                        count = 0;
 
767
                        EVTouchDumpPacketToLog(priv);
 
768
                        
 
769
                        return Success;
 
770
                }
 
771
        }
 
772
        return (!Success);
 
773
}
 
774
 
 
775
 
 
776
 
 
777
 
 
778
static void ReadInput (LocalDevicePtr local)
 
779
{
 
780
        struct input_event *ev; /* packet being/just read */
 
781
 
 
782
        EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
 
783
 
 
784
        /* 
 
785
         * set blocking to -1 on the first call because we know there is data to
 
786
         * read. Xisb automatically clears it after one successful read so that
 
787
         * succeeding reads are preceeded buy a select with a 0 timeout to prevent
 
788
         * read from blocking infinately.
 
789
         */
 
790
        XisbBlockDuration (priv->buffer, -1);
 
791
        while (EVTouchGetPacket (priv) == Success)
 
792
        {
 
793
                ev = &priv->ev;
 
794
                DBGOUT(2, "EVTouch: %s type:%0.2x code: 0x%0.4x value:%d\n",
 
795
                        __FUNCTION__, ev->type, ev->code, ev->value);
 
796
 
 
797
                xf86XInputSetScreen(local, 
 
798
                                    priv->screen_num, 
 
799
                                    priv->cur_x, 
 
800
                                    priv->cur_y);
 
801
 
 
802
                xf86PostProximityEvent(local->dev, 1, 0, 2,
 
803
                                       priv->cur_x,
 
804
                                       priv->cur_y);
 
805
 
 
806
                switch (ev->type) {
 
807
                case EV_ABS:
 
808
                        EVTouchProcessAbs(priv);
 
809
                        break;
 
810
                case EV_REL:
 
811
                        EVTouchProcessRel(priv);
 
812
                        break;
 
813
                case EV_KEY:
 
814
                        xf86PostMotionEvent (local->dev, TRUE, 0, 2, 
 
815
                                             priv->cur_x,
 
816
                                             priv->cur_y);
 
817
 
 
818
                        if (priv->ev.code == BTN_TOUCH) {
 
819
                                if (priv->ev.value == 1) {
 
820
                                        priv->touch_flags |= TOUCHED;
 
821
                                        DBGOUT(2, "EVTouch: TOUCHED\n");
 
822
                                }
 
823
                                else {
 
824
                                        priv->touch_flags &= ~TOUCHED;
 
825
                                        DBGOUT(2, "EVTouch: UNTOUCHED\n");
 
826
                                }
 
827
                        }
 
828
                        EVTouchProcessKey(priv);
 
829
                        break;
 
830
                case EV_SYN:
 
831
                        xf86PostMotionEvent (local->dev, TRUE, 0, 2, 
 
832
                                             priv->cur_x,
 
833
                                             priv->cur_y);
 
834
 
 
835
                        if ( priv->touch_flags & TOUCHED )
 
836
                                libtouchTriggerSM(priv->libtouch, PEN_TOUCHED);
 
837
                        else
 
838
                                libtouchTriggerSM(priv->libtouch, PEN_UNTOUCHED);
 
839
                        DoBtnAction(priv);
 
840
 
 
841
                        break;
 
842
                }
 
843
 
 
844
                DBGOUT( 2, "EVTouch: setting (x/y)=(%d/%d)\n", 
 
845
                        priv->cur_x, priv->cur_y);
 
846
 
 
847
        }
 
848
}
 
849
 
 
850
 
 
851
 
 
852
 
 
853
static int
 
854
ControlProc(LocalDevicePtr device, xDeviceCtl *ctrl)
 
855
{
 
856
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
857
 
 
858
/*      xDeviceTSCalibrationCtl *c = (xDeviceTSCalibrationCtl *) ctrl; */
 
859
/*      EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private); */
 
860
 
 
861
/*      priv->min_x = c->min_x; */
 
862
/*      priv->max_x = c->max_x; */
 
863
/*      priv->min_y = c->min_y; */
 
864
/*      priv->max_y = c->max_y; */
 
865
        return (Success);
 
866
}
 
867
 
 
868
 
 
869
 
 
870
 
 
871
static void
 
872
CloseProc (LocalDevicePtr local)
 
873
{
 
874
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
875
}
 
876
 
 
877
 
 
878
 
 
879
 
 
880
static int
 
881
SwitchMode (ClientPtr client, DeviceIntPtr dev, int mode)
 
882
{
 
883
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
884
        
 
885
        return (!Success);
 
886
}
 
887
 
 
888
 
 
889
 
 
890
 
 
891
static Bool
 
892
ConvertProc ( LocalDevicePtr local,
 
893
              int first,
 
894
              int num,
 
895
              int v0,
 
896
              int v1,
 
897
              int v2,
 
898
              int v3,
 
899
              int v4,
 
900
              int v5,
 
901
              int *x,
 
902
              int *y )
 
903
{
 
904
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
905
        /*
 
906
          correction factors depending on current position of pointer
 
907
        */
 
908
        float cx[3];
 
909
        float cy[3];
 
910
        float dx = 0, dy = 0;
 
911
 
 
912
        int max_x, max_y;
 
913
        int xc, yc;
 
914
        int screen_width  = 0;
 
915
        int screen_height = 0;
 
916
#ifdef EVDBG
 
917
        int i = 0;
 
918
#endif
 
919
 
 
920
        EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);  
 
921
        ScrnInfoPtr pScrn = xf86Screens[priv->screen_num];
 
922
        Rotation rotation = RRGetRotation(pScrn->pScreen);
 
923
 
 
924
        DBGOUT(2, "EVTouch: FIRST: v0=%d   v1=%d\n", v0, v1);
 
925
 
 
926
        /*write raw coordinates to fifo for calibration programm*/
 
927
        if ( (priv->fifo > 0) && (priv->calibrate) ){
 
928
                DBGOUT(2, "EVTouch: writing to FIFO\n");
 
929
                write (priv->fifo, &v0, sizeof(v0));
 
930
                write (priv->fifo, &v1, sizeof(v1));
 
931
        }
 
932
 
 
933
        /*correction of raw coordinates*/
 
934
        if (!priv->calibrate) {
 
935
                DBGOUT(2, "EVTouch: Scaling coordinates\n");
 
936
                xc = v0 - priv->min_x;
 
937
                yc = v1 - priv->min_y;
 
938
        
 
939
                max_x = priv->max_x - priv->min_x;
 
940
                max_y = priv->max_y - priv->min_y;
 
941
 
 
942
                if (priv->rotate == EV_ROTATE_NONE) {
 
943
                        screen_width  = pScrn->currentMode->HDisplay;
 
944
                        screen_height = pScrn->currentMode->VDisplay;
 
945
                } else {
 
946
                        screen_width  = pScrn->currentMode->VDisplay;
 
947
                        screen_height = pScrn->currentMode->HDisplay;
 
948
                }
 
949
 
 
950
                if ( rotation == RR_Rotate_90 || rotation == RR_Rotate_270 ) {
 
951
                        int tmp = screen_width; screen_width = screen_height;
 
952
                        screen_height = tmp;
 
953
                }
 
954
 
 
955
                if (xc < (max_x / 2)) {
 
956
                        /*
 
957
                          left
 
958
                        */
 
959
                        if (yc>(max_y / 2)) {
 
960
                                /*
 
961
                                  upper
 
962
                                */
 
963
                                cx[1] = ((float) xc / (max_x / 2) );
 
964
                                cx[0] = (float) 1 - cx[1];
 
965
                                cy[0] = ((float) (yc-(max_y/2)) / (max_y/2) );
 
966
                                cy[1] = (float) 1 - cy[0];
 
967
 
 
968
                                dx = ((float) (cx[1] * cy[0] * priv->diff[1][0]) +
 
969
                                      (float)(cx[0] * cy[0] * priv->diff[0][0]) +
 
970
                                      (float)(cx[1] * cy[1] * priv->diff[4][0]) +
 
971
                                      (float)(cx[0] * cy[1] * priv->diff[3][0]));
 
972
                                
 
973
                                dy = ((float) (cx[1] * cy[0] * priv->diff[1][1]) +
 
974
                                      (float)(cx[0] * cy[0] * priv->diff[0][1]) +
 
975
                                      (float)(cx[1] * cy[1] * priv->diff[4][1]) +
 
976
                                      (float)(cx[0] * cy[1] * priv->diff[3][1]));
 
977
                        }
 
978
                        else {
 
979
                                /*
 
980
                                  lower
 
981
                                */
 
982
                                cx[1] = ((float) xc / (max_x/2) );
 
983
                                cx[0] = (float) 1 - cx[1];
 
984
                                cy[0] = ((float) yc / (max_y/2) );
 
985
                                cy[1] = (float) 1 - cy[0];
 
986
 
 
987
                                dx = ((float) (cx[1] * cy[0] * priv->diff[4][0]) +
 
988
                                      (float)(cx[0] * cy[0] * priv->diff[3][0]) +
 
989
                                      (float)(cx[1] * cy[1] * priv->diff[7][0]) +
 
990
                                      (float)(cx[0] * cy[1] * priv->diff[6][0]));
 
991
                                
 
992
                                dy = ((float) (cx[1] * cy[0] * priv->diff[4][1]) +
 
993
                                      (float)(cx[0] * cy[0] * priv->diff[3][1]) +
 
994
                                      (float)(cx[1] * cy[1] * priv->diff[7][1]) +
 
995
                                      (float)(cx[0] * cy[1] * priv->diff[6][1]));
 
996
 
 
997
                        }
 
998
                } else {
 
999
                        /*
 
1000
                          right
 
1001
                        */
 
1002
                        if (yc>(max_y/2)) {
 
1003
                                /*
 
1004
                                  upper
 
1005
                                */
 
1006
                                cx[1] = ((float) (xc-(max_x/2)) / (max_x/2) );
 
1007
                                cx[0] = (float)1 - cx[1];
 
1008
                                cy[0] = ((float) (yc-(max_y/2)) / (max_y/2) );
 
1009
                                cy[1] = (float)1 - cy[0];
 
1010
 
 
1011
                                dx = ((float) (cx[1] * cy[0] * priv->diff[2][0]) +
 
1012
                                      (float)(cx[0] * cy[0] * priv->diff[1][0]) +
 
1013
                                      (float)(cx[1] * cy[1] * priv->diff[5][0]) +
 
1014
                                      (float)(cx[0] * cy[1] * priv->diff[4][0]));
 
1015
                        
 
1016
                                dy = ((float) (cx[1] * cy[0] * priv->diff[2][1]) +
 
1017
                                      (float)(cx[0] * cy[0] * priv->diff[1][1]) +
 
1018
                                      (float)(cx[1] * cy[1] * priv->diff[5][1]) +
 
1019
                                      (float)(cx[0] * cy[1] * priv->diff[4][1]));
 
1020
 
 
1021
                        } else {
 
1022
                                /*
 
1023
                                  lower
 
1024
                                */
 
1025
                                cx[1] = ((float) (xc-(max_x/2)) / (max_x/2) );
 
1026
                                cx[0] = (float) 1 - cx[1];
 
1027
                                cy[0] = ((float) yc / (max_y/2) );
 
1028
                                cy[1] = (float) 1 - cy[0];
 
1029
 
 
1030
                                dx = ((float) (cx[1] * cy[0] * priv->diff[5][0]) +
 
1031
                                      (float)(cx[0] * cy[0] * priv->diff[4][0]) +
 
1032
                                      (float)(cx[1] * cy[1] * priv->diff[8][0]) +
 
1033
                                      (float)(cx[0] * cy[1] * priv->diff[7][0]));
 
1034
                                
 
1035
                                dy = ((float) (cx[1] * cy[0] * priv->diff[5][1]) +
 
1036
                                      (float)(cx[0] * cy[0] * priv->diff[4][1]) +
 
1037
                                      (float)(cx[1] * cy[1] * priv->diff[8][1]) +
 
1038
                                      (float)(cx[0] * cy[1] * priv->diff[7][1]));
 
1039
                        }
 
1040
                }
 
1041
 
 
1042
 
 
1043
#ifdef EVDBG
 
1044
                for (i=0; i<3; i++) 
 
1045
                        xf86ErrorFVerb(2, "cx[%d]=%f   cy[%d]=%f\n", i, cx[i]
 
1046
                                       ,i, cy[i]);
 
1047
                
 
1048
                DBGOUT(2, "EVTouch: ViewPort_X0=%d   ViewPort_Y0=%d\n", 
 
1049
                    *(priv->pViewPort_X0), 
 
1050
                    *(priv->pViewPort_Y0));
 
1051
                DBGOUT(2, "EVTouch: dx=%f   dy=%f\n", dx, dy);
 
1052
#endif
 
1053
 
 
1054
                xc = ( ((float)xc / max_x) * screen_width ) + dx;
 
1055
                yc = ( ((float)yc / max_y) * screen_height) + dy;
 
1056
 
 
1057
                if (priv->swap_y == TRUE)
 
1058
                        yc = screen_height - yc;
 
1059
 
 
1060
                /* ususally we DON'T swap x -- but if swap_x is 1 
 
1061
                   => go on and swap */
 
1062
                if (priv->swap_x == TRUE)
 
1063
                        xc = screen_width - xc;
 
1064
 
 
1065
                int tmp = 0;
 
1066
                /* rotation mixes x and y up a bit */
 
1067
                if (priv->rotate == EV_ROTATE_CW) {
 
1068
                        tmp = xc;
 
1069
                        xc = yc;
 
1070
                        yc = screen_width - tmp;
 
1071
                } else if (priv->rotate == EV_ROTATE_CCW) {
 
1072
                        tmp = xc;
 
1073
                        xc = screen_height - yc;
 
1074
                        yc = tmp;
 
1075
                } else if (priv->rotate == EV_ROTATE_UD) {
 
1076
                        xc = screen_width - xc;
 
1077
                        yc = screen_height - yc;
 
1078
                }
 
1079
 
 
1080
                switch (rotation) {
 
1081
                        case RR_Rotate_0:
 
1082
                                v0 = xc;
 
1083
                                v1 = yc;
 
1084
                                break;
 
1085
                        case RR_Rotate_180:
 
1086
                                v0 = screen_width - xc;
 
1087
                                v1 = screen_height - yc;
 
1088
                                break;
 
1089
                        case RR_Rotate_90:
 
1090
                                tmp = xc;
 
1091
                                v0  = screen_height - yc;
 
1092
                                v1  = tmp;
 
1093
                                break;
 
1094
                        case RR_Rotate_270:
 
1095
                                tmp = xc;
 
1096
                                v0 = yc;
 
1097
                                v1 = screen_width - tmp;
 
1098
                                break;
 
1099
                        default:
 
1100
                                break;
 
1101
                }
 
1102
        }
 
1103
 
 
1104
        DBGOUT(2, "EVTouch: FINAL: v0=%d   v1=%d\n", v0, v1);
 
1105
 
 
1106
        *x = v0;
 
1107
        *y = v1;
 
1108
 
 
1109
        return (TRUE);
 
1110
}
 
1111
 
 
1112
 
 
1113
 
 
1114
 
 
1115
static InputInfoPtr
 
1116
EVTouchPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
 
1117
{
 
1118
        /* LocalDevicePtr local; */
 
1119
        InputInfoPtr local;
 
1120
        EVTouchPrivatePtr priv;
 
1121
        ScrnInfoPtr   pScrn;
 
1122
 
 
1123
        int i = 0;
 
1124
        char *s;
 
1125
        char tmp_str[8];
 
1126
        int timeo = 0;
 
1127
 
 
1128
        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
 
1129
 
 
1130
        priv = xcalloc (1, sizeof (EVTouchPrivateRec));
 
1131
        if (!priv)
 
1132
                return NULL;
 
1133
 
 
1134
        local = xf86AllocateInput(drv, 0);
 
1135
        if (!local) {
 
1136
                xfree(priv);
 
1137
                return NULL;
 
1138
        }
 
1139
 
 
1140
        local->name = xstrdup(dev->identifier);
 
1141
        local->type_name = XI_TOUCHSCREEN;
 
1142
        local->device_control = DeviceControl;
 
1143
        local->read_input = ReadInput;
 
1144
        local->control_proc = ControlProc;
 
1145
        local->close_proc = CloseProc;
 
1146
        local->switch_mode = SwitchMode;
 
1147
        local->conversion_proc = ConvertProc;
 
1148
        local->reverse_conversion_proc = NULL;
 
1149
        local->fd = -1;
 
1150
        local->dev = NULL;
 
1151
        local->private = priv;
 
1152
        priv->local = local;
 
1153
        local->private_flags = 0;
 
1154
        local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
 
1155
        local->conf_idev = dev;
 
1156
 
 
1157
        xf86CollectInputOptions(local, default_options, NULL);
 
1158
 
 
1159
        xf86OptionListReport(local->options);
 
1160
 
 
1161
        priv->libtouch = xcalloc(1, sizeof(LibTouchRec));
 
1162
        libtouchInit(priv->libtouch, local);
 
1163
 
 
1164
        priv->screen_num    = xf86SetIntOption(local->options, "ScreenNumber", 0 );
 
1165
 
 
1166
        priv->calibrate = xf86SetIntOption(local->options, "Calibrate", 0);
 
1167
 
 
1168
        pScrn = xf86Screens[priv->screen_num];
 
1169
        priv->phys_width = pScrn->currentMode->HDisplay;  /* physical screen resolution */
 
1170
        priv->phys_height = pScrn->currentMode->VDisplay;
 
1171
 
 
1172
        priv->min_x = xf86SetIntOption(local->options, "MinX", 0 );
 
1173
        priv->max_x = xf86SetIntOption(local->options, "MaxX", priv->phys_width );
 
1174
        priv->min_y = xf86SetIntOption(local->options, "MinY", 0 );
 
1175
        priv->max_y = xf86SetIntOption(local->options, "MaxY", priv->phys_height );
 
1176
 
 
1177
        priv->button_number = xf86SetIntOption(local->options, "ButtonNumber", 2 );
 
1178
 
 
1179
        priv->emulate3      = xf86SetBoolOption(local->options, "Emulate3Buttons", TRUE);
 
1180
        priv->emulate3_timeout = xf86SetIntOption(local->options, 
 
1181
                                                  "Emulate3Timeout", 50);
 
1182
 
 
1183
        debug_level = xf86SetIntOption(local->options, "DebugLevel", 0);
 
1184
        libtouchSetDebugLevel(debug_level);
 
1185
 
 
1186
        timeo = xf86SetIntOption(local->options, "TapTimer", 90);
 
1187
        libtouchSetTapTimeo(priv->libtouch, timeo);
 
1188
 
 
1189
        timeo = xf86SetIntOption(local->options, "LongtouchTimer", 160);
 
1190
        libtouchSetLongtouchTimeo(priv->libtouch, timeo);
 
1191
 
 
1192
        libtouchSetMoveLimit(priv->libtouch, 
 
1193
                             xf86SetIntOption( local->options, 
 
1194
                                               "MoveLimit", 180 ));
 
1195
 
 
1196
        priv->rotate     = EV_ROTATE_NONE;
 
1197
        s = xf86FindOptionValue(local->options, "Rotate");
 
1198
        if (s) {
 
1199
                if (xf86NameCmp(s, "CW") == 0) {
 
1200
                        priv->rotate = EV_ROTATE_CW;                           
 
1201
                } else if (xf86NameCmp(s, "CCW") == 0 ) {
 
1202
                        priv->rotate = EV_ROTATE_CCW;
 
1203
                } 
 
1204
        }
 
1205
 
 
1206
        if (priv->rotate == EV_ROTATE_NONE) {
 
1207
                priv->max_rel_x = priv->max_x;
 
1208
                priv->max_rel_y = priv->max_y;
 
1209
                priv->min_rel_x = priv->min_x;
 
1210
                priv->min_rel_y = priv->min_y;             
 
1211
        } else {
 
1212
                priv->max_rel_x = priv->max_y;
 
1213
                priv->max_rel_y = priv->max_x;
 
1214
                priv->min_rel_x = priv->min_y;
 
1215
                priv->min_rel_y = priv->min_x;             
 
1216
        }
 
1217
 
 
1218
        priv->swap_y = xf86SetBoolOption(local->options, "SwapY", FALSE);
 
1219
        priv->swap_x = xf86SetBoolOption(local->options, "SwapX", FALSE);
 
1220
 
 
1221
        /* 
 
1222
           get calibration parameters from XF86Config 
 
1223
        */
 
1224
        for (i = 0; i < 9; i++){
 
1225
                sprintf(tmp_str, "x%d", i);
 
1226
                priv->diff[i][0] = xf86SetIntOption( local->options,
 
1227
                                                     tmp_str, 0 );
 
1228
                sprintf(tmp_str, "y%d", i);
 
1229
                priv->diff[i][1] = xf86SetIntOption( local->options,
 
1230
                                                     tmp_str, 0 );
 
1231
                DBGOUT(2, "(diff[%d][0]/diff[%d][1])=(%d/%d)\n", i, i, 
 
1232
                    priv->diff[i][0], priv->diff[i][1]);
 
1233
        }
 
1234
        
 
1235
        priv->touch_flags = 0;
 
1236
        local->history_size = xf86SetIntOption( local->options, "HistorySize", 0 );
 
1237
 
 
1238
        /* prepare to process touch packets */
 
1239
        EVTouchNewPacket (priv);
 
1240
 
 
1241
        /* 
 
1242
           if started in calibration-mode:
 
1243
           - open named pipe 
 
1244
        */
 
1245
        if (priv->calibrate) {
 
1246
                priv->fifo = open("/tmp/ev_calibrate", O_RDWR, 0);
 
1247
                if (priv->fifo < 0)
 
1248
                        xf86ErrorFVerb(2, "open FIFO FAILED\n");
 
1249
        }
 
1250
 
 
1251
        /* this results in an xstrdup that must be freed later */
 
1252
        local->name = xf86SetStrOption( local->options, "DeviceName", "EVTouch TouchScreen" );
 
1253
        xf86ProcessCommonOptions(local, local->options);
 
1254
        local->flags |= XI86_CONFIGURED;
 
1255
 
 
1256
        xf86CloseSerial(local->fd);
 
1257
        local->fd = -1;
 
1258
        return (local);
 
1259
}
 
1260
 
 
1261
 
 
1262
 
 
1263
 
 
1264
static void
 
1265
EVTouchPtrCtrl(DeviceIntPtr device, PtrCtrl *ctrl)
 
1266
{
 
1267
  /* I have no clue what this does, except that registering it stops the 
 
1268
     X server segfaulting in ProcGetPointerMapping()
 
1269
     Ho Hum.
 
1270
  */
 
1271
}