summaryrefslogtreecommitdiff
path: root/src/multitouch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/multitouch.c')
-rw-r--r--src/multitouch.c64
1 files changed, 61 insertions, 3 deletions
diff --git a/src/multitouch.c b/src/multitouch.c
index c18f3d3..7ea1f92 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -25,9 +25,18 @@
25 25
26//////////////////////////////////////////////////////////////////////////// 26////////////////////////////////////////////////////////////////////////////
27 27
28static int device_init(LocalDevicePtr local) 28static void pointer_control(DeviceIntPtr dev, PtrCtrl *ctrl)
29{
30}
31
32////////////////////////////////////////////////////////////////////////////
33
34static int device_init(DeviceIntPtr dev, LocalDevicePtr local)
29{ 35{
30 struct MTouch *mt = local->private; 36 struct MTouch *mt = local->private;
37 unsigned char btmap[DIM_BUTTON];
38 int i;
39
31 local->fd = xf86OpenSerial(local->options); 40 local->fd = xf86OpenSerial(local->options);
32 if (local->fd < 0) { 41 if (local->fd < 0) {
33 xf86Msg(X_ERROR, "multitouch: cannot configure device\n"); 42 xf86Msg(X_ERROR, "multitouch: cannot configure device\n");
@@ -36,6 +45,32 @@ static int device_init(LocalDevicePtr local)
36 if (configure_mtouch(mt, local->fd)) 45 if (configure_mtouch(mt, local->fd))
37 return -1; 46 return -1;
38 xf86CloseSerial(local->fd); 47 xf86CloseSerial(local->fd);
48
49 for (i = 0; i < DIM_BUTTON; i++)
50 btmap[i] = i;
51
52 InitPointerDeviceStruct((DevicePtr)dev,
53 btmap,
54 DIM_BUTTON,
55 GetMotionHistory,
56 pointer_control,
57 GetMotionHistorySize(),
58 2);
59
60 xf86InitValuatorAxisStruct(dev, 0,
61 mt->caps.abs_position_x.minimum,
62 mt->caps.abs_position_x.maximum,
63 1, 0, 1);
64 xf86InitValuatorDefaults(dev, 0);
65 xf86InitValuatorAxisStruct(dev, 1,
66 mt->caps.abs_position_y.minimum,
67 mt->caps.abs_position_y.maximum,
68 1, 0, 1);
69 xf86InitValuatorDefaults(dev, 1);
70
71 //InitDeviceProperties(local);
72 //XIRegisterPropertyHandler(dev, SetProperty, NULL, NULL);
73
39 return 0; 74 return 0;
40} 75}
41 76
@@ -75,6 +110,26 @@ static void device_close(LocalDevicePtr local)
75 110
76//////////////////////////////////////////////////////////////////////////// 111////////////////////////////////////////////////////////////////////////////
77 112
113static void handle_state(LocalDevicePtr local,
114 const struct State *os,
115 const struct State *ns)
116{
117 const struct FingerState *fs, *p, *e = ns->finger + ns->nfinger;
118 int dx = 0, dy = 0, i;
119 for (p = ns->finger; p != e; p++) {
120 if (fs = find_finger(os, p->id)) {
121 dx += p->hw.position_x - fs->hw.position_x;
122 dy += p->hw.position_y - fs->hw.position_y;
123 }
124 }
125 if (dx || dy) {
126 xf86Msg(X_INFO, "motion: %d %d\n", dx, dy);
127 xf86PostMotionEvent(local->dev, 0, 0, 2, dx, dy);
128 }
129}
130
131////////////////////////////////////////////////////////////////////////////
132
78/* called for each full received packet from the touchpad */ 133/* called for each full received packet from the touchpad */
79static void read_input(LocalDevicePtr local) 134static void read_input(LocalDevicePtr local)
80{ 135{
@@ -82,7 +137,8 @@ static void read_input(LocalDevicePtr local)
82 if (local->fd >= 0) { 137 if (local->fd >= 0) {
83 while (read_synchronized_event(mt, local->fd)) { 138 while (read_synchronized_event(mt, local->fd)) {
84 modify_state(&mt->ns, &mt->hw, &mt->caps); 139 modify_state(&mt->ns, &mt->hw, &mt->caps);
85 output_state(&mt->ns); 140 //output_state(&mt->ns);
141 handle_state(local, &mt->os, &mt->ns);
86 mt->os = mt->ns; 142 mt->os = mt->ns;
87 } 143 }
88 } 144 }
@@ -96,16 +152,18 @@ static Bool device_control(DeviceIntPtr dev, int mode)
96 switch (mode) { 152 switch (mode) {
97 case DEVICE_INIT: 153 case DEVICE_INIT:
98 xf86Msg(X_INFO, "device control: init\n"); 154 xf86Msg(X_INFO, "device control: init\n");
99 if (device_init(local)) 155 if (device_init(dev, local))
100 return !Success; 156 return !Success;
101 return Success; 157 return Success;
102 case DEVICE_ON: 158 case DEVICE_ON:
103 xf86Msg(X_INFO, "device control: on\n"); 159 xf86Msg(X_INFO, "device control: on\n");
104 if (device_on(local)) 160 if (device_on(local))
105 return !Success; 161 return !Success;
162 dev->public.on = TRUE;
106 return Success; 163 return Success;
107 case DEVICE_OFF: 164 case DEVICE_OFF:
108 xf86Msg(X_INFO, "device control: off\n"); 165 xf86Msg(X_INFO, "device control: off\n");
166 dev->public.on = FALSE;
109 device_off(local); 167 device_off(local);
110 return Success; 168 return Success;
111 case DEVICE_CLOSE: 169 case DEVICE_CLOSE: