~ubuntu-branches/ubuntu/breezy/xfree86-driver-synaptics/breezy

« back to all changes in this revision

Viewing changes to synaptics.c

  • Committer: Bazaar Package Importer
  • Author(s): Mattia Dongili (ma.d.)
  • Date: 2004-12-18 20:07:15 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041218200715-p5y2c27b63vszun1
Tags: 0.13.6-2
* Install in /usr/X11R6/lib as all the xfree drivers on 64 bit archs.  (closes: #280658)
* Provided an alternative patch for debian-kernel users. (closes: #282359)

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
#define M_PI 3.14159265358979323846
104
104
#endif
105
105
 
 
106
#ifndef M_SQRT1_2
 
107
#define M_SQRT1_2  0.70710678118654752440  /* 1/sqrt(2) */
 
108
#endif
 
109
 
106
110
/*****************************************************************************
107
111
 * Forward declaration
108
112
 ****************************************************************************/
117
121
static Bool DeviceInit(DeviceIntPtr);
118
122
static Bool DeviceOn(DeviceIntPtr);
119
123
static Bool DeviceOff(DeviceIntPtr);
120
 
static Bool DeviceInit(DeviceIntPtr);
121
124
 
122
125
 
123
126
InputDriverRec SYNAPTICS = {
332
335
    pars->tap_action[F3_TAP] = xf86SetIntOption(local->options, "TapButton3",     3);
333
336
    pars->circular_scrolling = xf86SetBoolOption(local->options, "CircularScrolling", FALSE);
334
337
    pars->circular_trigger   = xf86SetIntOption(local->options, "CircScrollTrigger", 0);
 
338
    pars->circular_pad       = xf86SetBoolOption(local->options, "CircularPad", FALSE);
335
339
 
336
340
    str_par = xf86FindOptionValue(local->options, "MinSpeed");
337
341
    if ((!str_par) || (xf86sscanf(str_par, "%lf", &pars->min_speed) != 1))
392
396
    local->flags |= XI86_CONFIGURED;
393
397
 
394
398
    if (local->fd != -1) {
395
 
        xf86RemoveEnabledDevice(local);
396
399
        if (priv->comm.buffer) {
397
400
            XisbFree(priv->comm.buffer);
398
401
            priv->comm.buffer = NULL;
404
407
 
405
408
 SetupProc_fail:
406
409
    if (local->fd >= 0) {
407
 
        RemoveEnabledDevice(local->fd);
408
410
        xf86CloseSerial(local->fd);
409
411
        local->fd = -1;
410
412
    }
460
462
        RetValue = DeviceOff( dev );
461
463
        break;
462
464
    case DEVICE_CLOSE:
463
 
        {
464
 
            int shmid;
465
 
            LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
466
 
            SynapticsPrivate *priv = (SynapticsPrivate *) (local->private);
467
 
            RetValue = DeviceOff( dev );
468
 
            if (priv->shm_config)
469
 
                if ((shmid = xf86shmget(SHM_SYNAPTICS, 0, 0)) != -1)
470
 
                    xf86shmctl(shmid, XF86IPC_RMID, NULL);
471
 
        }
 
465
        RetValue = DeviceOff( dev );
472
466
        break;
473
467
    default:
474
468
        RetValue = BadValue;
519
513
    DBG(3, ErrorF("Synaptics DeviceOff called\n"));
520
514
 
521
515
    if (local->fd != -1) {
 
516
        TimerFree(priv->timer);
 
517
        priv->timer = NULL;
522
518
        xf86RemoveEnabledDevice(local);
523
519
        priv->proto_ops->DeviceOffHook(local);
524
520
        if (priv->comm.buffer) {
564
560
    return xf86sqrt((dx * dx) + (dy * dy));
565
561
}
566
562
 
 
563
/*
 
564
 * Convert from absolute X/Y coordinates to a coordinate system where
 
565
 * -1 corresponds to the left/upper edge and +1 corresponds to the
 
566
 * right/lower edge.
 
567
 */
 
568
static void relative_coords(SynapticsPrivate *priv, int x, int y,
 
569
                            double* relX, double* relY)
 
570
{
 
571
    int minX = priv->synpara->left_edge;
 
572
    int maxX = priv->synpara->right_edge;
 
573
    int minY = priv->synpara->top_edge;
 
574
    int maxY = priv->synpara->bottom_edge;
 
575
    double xCenter = (minX + maxX) / 2.0;
 
576
    double yCenter = (minY + maxY) / 2.0;
 
577
 
 
578
    if ((maxX - xCenter > 0) && (maxY - yCenter > 0)) {
 
579
        *relX = (x - xCenter) / (maxX - xCenter);
 
580
        *relY = (y - yCenter) / (maxY - yCenter);
 
581
    } else {
 
582
        *relX = 0;
 
583
        *relY = 0;
 
584
    }
 
585
}
 
586
 
567
587
/* return angle of point relative to center */
568
588
static double
569
589
angle(SynapticsPrivate *priv, int x, int y)
587
607
}
588
608
 
589
609
static edge_type
 
610
circular_edge_detection(SynapticsPrivate *priv, int x, int y)
 
611
{
 
612
    edge_type edge = 0;
 
613
    double relX, relY, relR;
 
614
 
 
615
    relative_coords(priv, x, y, &relX, &relY);
 
616
    relR = relX * relX + relY * relY;
 
617
 
 
618
    if (relR > 1) {
 
619
        /* we are outside the ellipse enclosed by the edge parameters */
 
620
        if (relX > M_SQRT1_2)
 
621
            edge |= RIGHT_EDGE;
 
622
        else if (relX < -M_SQRT1_2)
 
623
            edge |= LEFT_EDGE;
 
624
 
 
625
        if (relY < -M_SQRT1_2)
 
626
            edge |= TOP_EDGE;
 
627
        else if (relY > M_SQRT1_2)
 
628
            edge |= BOTTOM_EDGE;
 
629
    }
 
630
 
 
631
    return edge;
 
632
}
 
633
 
 
634
static edge_type
590
635
edge_detection(SynapticsPrivate *priv, int x, int y)
591
636
{
592
637
    edge_type edge = 0;
593
638
 
 
639
    if (priv->synpara->circular_pad)
 
640
        return circular_edge_detection(priv, x, y);
 
641
 
594
642
    if (x > priv->synpara->right_edge)
595
643
        edge |= RIGHT_EDGE;
596
644
    else if (x < priv->synpara->left_edge)
1046
1094
                int minSpd = para->edge_motion_min_speed;
1047
1095
                int maxSpd = para->edge_motion_max_speed;
1048
1096
                int edge_speed;
 
1097
                int x_edge_speed = 0;
 
1098
                int y_edge_speed = 0;
1049
1099
 
1050
1100
                if (hw->z <= minZ) {
1051
1101
                    edge_speed = minSpd;
1054
1104
                } else {
1055
1105
                    edge_speed = minSpd + (hw->z - minZ) * (maxSpd - minSpd) / (maxZ - minZ);
1056
1106
                }
1057
 
                if (edge & RIGHT_EDGE) {
1058
 
                    dx += clamp(edge_speed - dx, 0, edge_speed);
1059
 
                } else if (edge & LEFT_EDGE) {
1060
 
                    dx -= clamp(edge_speed + dx, 0, edge_speed);
1061
 
                }
1062
 
                if (edge & TOP_EDGE) {
1063
 
                    dy -= clamp(edge_speed + dy, 0, edge_speed);
1064
 
                } else if (edge & BOTTOM_EDGE) {
1065
 
                    dy += clamp(edge_speed - dy, 0, edge_speed);
1066
 
                }
 
1107
                if (!priv->synpara->circular_pad) {
 
1108
                    /* on rectangular pad */
 
1109
                    if (edge & RIGHT_EDGE) {
 
1110
                        x_edge_speed = edge_speed;
 
1111
                    } else if (edge & LEFT_EDGE) {
 
1112
                        x_edge_speed = -edge_speed;
 
1113
                    }
 
1114
                    if (edge & TOP_EDGE) {
 
1115
                        y_edge_speed = -edge_speed;
 
1116
                    } else if (edge & BOTTOM_EDGE) {
 
1117
                        y_edge_speed = edge_speed;
 
1118
                    }
 
1119
                } else if (edge) {
 
1120
                    /* at edge of circular pad */
 
1121
                    double relX, relY;
 
1122
 
 
1123
                    relative_coords(priv, hw->x, hw->y, &relX, &relY);
 
1124
                    x_edge_speed = (int)(edge_speed * relX);
 
1125
                    y_edge_speed = (int)(edge_speed * relY);
 
1126
                }
 
1127
                dx += x_edge_speed;
 
1128
                dy += y_edge_speed;
1067
1129
            }
1068
1130
 
1069
1131
            /* speed depending on distance/packet */
1261
1323
    hw->up |= hw->multi[0];
1262
1324
    hw->down |= hw->multi[1];
1263
1325
 
 
1326
    if (!para->guestmouse_off) {
 
1327
        hw->left |= hw->guest_left;
 
1328
        hw->middle |= hw->guest_mid;
 
1329
        hw->right |= hw->guest_right;
 
1330
    }
 
1331
 
1264
1332
    /* 3rd button emulation */
1265
1333
    hw->middle |= HandleMidButtonEmulation(priv, hw, &delay);
1266
1334
 
1307
1375
    timeleft = ComputeDeltas(priv, hw, edge, &dx, &dy);
1308
1376
    delay = MIN(delay, timeleft);
1309
1377
 
1310
 
 
1311
 
    buttons = (((hw->left || hw->guest_left)   ? 0x01 : 0) |
1312
 
               ((hw->middle || hw->guest_mid)  ? 0x02 : 0) |
1313
 
               ((hw->right || hw->guest_right) ? 0x04 : 0) |
1314
 
               (hw->up                         ? 0x08 : 0) |
1315
 
               (hw->down                       ? 0x10 : 0) |
1316
 
               (hw->multi[2]                   ? 0x20 : 0) |
1317
 
               (hw->multi[3]                   ? 0x40 : 0));
 
1378
    buttons = ((hw->left     ? 0x01 : 0) |
 
1379
               (hw->middle   ? 0x02 : 0) |
 
1380
               (hw->right    ? 0x04 : 0) |
 
1381
               (hw->up       ? 0x08 : 0) |
 
1382
               (hw->down     ? 0x10 : 0) |
 
1383
               (hw->multi[2] ? 0x20 : 0) |
 
1384
               (hw->multi[3] ? 0x40 : 0));
1318
1385
 
1319
1386
    if (priv->tap_button > 0) {
1320
1387
        int tap_mask = 1 << (priv->tap_button - 1);