summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2008-11-08 15:10:49 +0100
committerHenrik Rydberg <rydberg@euromail.se>2008-11-08 15:10:49 +0100
commit9f6a75a35de8d05a8ae2e8b5d5cd10d960d4de4b (patch)
treeeb1c22c2dc172a765d197acf5f1ec55db0031011 /src
parentad124aac8feeaaa1f131ff35d895e777f4ffdc61 (diff)
cleanup
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
-rw-r--r--src/mtouch.c17
-rw-r--r--src/mtouch.h3
-rw-r--r--src/multitouch.c70
3 files changed, 36 insertions, 54 deletions
diff --git a/src/mtouch.c b/src/mtouch.c
index cb1c44c..6952611 100644
--- a/src/mtouch.c
+++ b/src/mtouch.c
@@ -20,28 +20,17 @@ int open_mtouch(struct MTouch *mt, int fd)
20 init_hwdata(&mt->hw); 20 init_hwdata(&mt->hw);
21 init_state(&mt->os); 21 init_state(&mt->os);
22 init_state(&mt->ns); 22 init_state(&mt->ns);
23 if (mt->grabbed)
24 return 0;
25 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)1)); 23 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)1));
26 if (rc < 0) { 24 return rc;
27 xf86Msg(X_WARNING, "multitouch: cannot grab device\n");
28 return rc;
29 }
30 mt->grabbed = 1;
31 return 0;
32} 25}
33 26
34/******************************************************/ 27/******************************************************/
35 28
36void close_mtouch(struct MTouch *mt, int fd) 29int close_mtouch(struct MTouch *mt, int fd)
37{ 30{
38 int rc; 31 int rc;
39 if (!mt->grabbed)
40 return;
41 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)0)); 32 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)0));
42 if (rc < 0) 33 return rc;
43 xf86Msg(X_WARNING, "multitouch: cannot ungrab device\n");
44 mt->grabbed = 0;
45} 34}
46 35
47/******************************************************/ 36/******************************************************/
diff --git a/src/mtouch.h b/src/mtouch.h
index a131b40..5edc6e5 100644
--- a/src/mtouch.h
+++ b/src/mtouch.h
@@ -13,14 +13,13 @@ struct MTouch {
13 struct IOBuffer buf; 13 struct IOBuffer buf;
14 struct HWData hw; 14 struct HWData hw;
15 struct State os, ns; 15 struct State os, ns;
16 bool grabbed;
17}; 16};
18 17
19//////////////////////////////////////////////////////// 18////////////////////////////////////////////////////////
20 19
21int configure_mtouch(struct MTouch *mt, int fd); 20int configure_mtouch(struct MTouch *mt, int fd);
22int open_mtouch(struct MTouch *mt, int fd); 21int open_mtouch(struct MTouch *mt, int fd);
23void close_mtouch(struct MTouch *mt, int fd); 22int close_mtouch(struct MTouch *mt, int fd);
24 23
25bool read_synchronized_event(struct MTouch *mt, int fd); 24bool read_synchronized_event(struct MTouch *mt, int fd);
26 25
diff --git a/src/multitouch.c b/src/multitouch.c
index 0c1f9e3..987cf34 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -31,6 +31,8 @@ static void pointer_control(DeviceIntPtr dev, PtrCtrl *ctrl)
31 xf86Msg(X_INFO, "pointer_control\n"); 31 xf86Msg(X_INFO, "pointer_control\n");
32} 32}
33 33
34////////////////////////////////////////////////////////////////////////////
35
34static int pointer_property(DeviceIntPtr dev, 36static int pointer_property(DeviceIntPtr dev,
35 Atom property, 37 Atom property,
36 XIPropertyValuePtr prop, 38 XIPropertyValuePtr prop,
@@ -45,24 +47,21 @@ static int pointer_property(DeviceIntPtr dev,
45static int device_init(DeviceIntPtr dev, LocalDevicePtr local) 47static int device_init(DeviceIntPtr dev, LocalDevicePtr local)
46{ 48{
47 struct MTouch *mt = local->private; 49 struct MTouch *mt = local->private;
48 unsigned char btmap[DIM_BUTTON]; 50 unsigned char btmap[DIM_BUTTON]={0,1,2};
49 int i;
50 51
51 local->fd = xf86OpenSerial(local->options); 52 local->fd = xf86OpenSerial(local->options);
52 if (local->fd < 0) { 53 if (local->fd < 0) {
54 xf86Msg(X_ERROR, "multitouch: cannot open device\n");
55 return !Success;
56 }
57 if (configure_mtouch(mt, local->fd)) {
53 xf86Msg(X_ERROR, "multitouch: cannot configure device\n"); 58 xf86Msg(X_ERROR, "multitouch: cannot configure device\n");
54 return local->fd; 59 return !Success;
55 } 60 }
56 if (configure_mtouch(mt, local->fd))
57 return -1;
58 xf86CloseSerial(local->fd); 61 xf86CloseSerial(local->fd);
59 62
60 for (i = 0; i < DIM_BUTTON; i++)
61 btmap[i] = i;
62
63 InitPointerDeviceStruct((DevicePtr)dev, 63 InitPointerDeviceStruct((DevicePtr)dev,
64 btmap, 64 btmap, DIM_BUTTON,
65 DIM_BUTTON,
66 GetMotionHistory, 65 GetMotionHistory,
67 pointer_control, 66 pointer_control,
68 GetMotionHistorySize(), 67 GetMotionHistorySize(),
@@ -79,10 +78,9 @@ static int device_init(DeviceIntPtr dev, LocalDevicePtr local)
79 1, 0, 1); 78 1, 0, 1);
80 xf86InitValuatorDefaults(dev, 1); 79 xf86InitValuatorDefaults(dev, 1);
81 80
82 //InitDeviceProperties(local); 81 XIRegisterPropertyHandler(dev, pointer_property, NULL, NULL);
83 //XIRegisterPropertyHandler(dev, pointer_property, NULL, NULL);
84 82
85 return 0; 83 return Success;
86} 84}
87 85
88//////////////////////////////////////////////////////////////////////////// 86////////////////////////////////////////////////////////////////////////////
@@ -93,30 +91,34 @@ static int device_on(LocalDevicePtr local)
93 local->fd = xf86OpenSerial(local->options); 91 local->fd = xf86OpenSerial(local->options);
94 if (local->fd < 0) { 92 if (local->fd < 0) {
95 xf86Msg(X_ERROR, "multitouch: cannot open device\n"); 93 xf86Msg(X_ERROR, "multitouch: cannot open device\n");
96 return local->fd; 94 return !Success;
95 }
96 if (open_mtouch(mt, local->fd)) {
97 xf86Msg(X_ERROR, "multitouch: cannot grab device\n");
98 return !Success;
97 } 99 }
98 if (open_mtouch(mt, local->fd))
99 return -1;
100 xf86AddEnabledDevice(local); 100 xf86AddEnabledDevice(local);
101 return 0; 101 return Success;
102} 102}
103 103
104//////////////////////////////////////////////////////////////////////////// 104////////////////////////////////////////////////////////////////////////////
105 105
106static void device_off(LocalDevicePtr local) 106static int device_off(LocalDevicePtr local)
107{ 107{
108 struct MTouch *mt = local->private; 108 struct MTouch *mt = local->private;
109 if(local->fd < 0)
110 return;
111 xf86RemoveEnabledDevice(local); 109 xf86RemoveEnabledDevice(local);
112 close_mtouch(mt, local->fd); 110 if(close_mtouch(mt, local->fd)) {
111 xf86Msg(X_WARNING, "multitouch: cannot ungrab device\n");
112 }
113 xf86CloseSerial(local->fd); 113 xf86CloseSerial(local->fd);
114 return Success;
114} 115}
115 116
116//////////////////////////////////////////////////////////////////////////// 117////////////////////////////////////////////////////////////////////////////
117 118
118static void device_close(LocalDevicePtr local) 119static int device_close(LocalDevicePtr local)
119{ 120{
121 return Success;
120} 122}
121 123
122//////////////////////////////////////////////////////////////////////////// 124////////////////////////////////////////////////////////////////////////////
@@ -151,12 +153,10 @@ static void handle_state(LocalDevicePtr local,
151static void read_input(LocalDevicePtr local) 153static void read_input(LocalDevicePtr local)
152{ 154{
153 struct MTouch *mt = local->private; 155 struct MTouch *mt = local->private;
154 if (local->fd >= 0) { 156 while (read_synchronized_event(mt, local->fd)) {
155 while (read_synchronized_event(mt, local->fd)) { 157 modify_state(&mt->ns, &mt->hw, &mt->caps);
156 modify_state(&mt->ns, &mt->hw, &mt->caps); 158 handle_state(local, &mt->os, &mt->ns);
157 handle_state(local, &mt->os, &mt->ns); 159 mt->os = mt->ns;
158 mt->os = mt->ns;
159 }
160 } 160 }
161} 161}
162 162
@@ -168,22 +168,16 @@ static Bool device_control(DeviceIntPtr dev, int mode)
168 switch (mode) { 168 switch (mode) {
169 case DEVICE_INIT: 169 case DEVICE_INIT:
170 xf86Msg(X_INFO, "device control: init\n"); 170 xf86Msg(X_INFO, "device control: init\n");
171 if (device_init(dev, local)) 171 return device_init(dev, local);
172 return !Success;
173 return Success;
174 case DEVICE_ON: 172 case DEVICE_ON:
175 xf86Msg(X_INFO, "device control: on\n"); 173 xf86Msg(X_INFO, "device control: on\n");
176 if (device_on(local)) 174 return device_on(local);
177 return !Success;
178 return Success;
179 case DEVICE_OFF: 175 case DEVICE_OFF:
180 xf86Msg(X_INFO, "device control: off\n"); 176 xf86Msg(X_INFO, "device control: off\n");
181 device_off(local); 177 return device_off(local);
182 return Success;
183 case DEVICE_CLOSE: 178 case DEVICE_CLOSE:
184 xf86Msg(X_INFO, "device control: close\n"); 179 xf86Msg(X_INFO, "device control: close\n");
185 device_close(local); 180 return device_close(local);
186 return Success;
187 default: 181 default:
188 xf86Msg(X_INFO, "device control: default\n"); 182 xf86Msg(X_INFO, "device control: default\n");
189 return BadValue; 183 return BadValue;