2 #include "../port/lib.h"
6 #include "../port/error.h"
25 extern int mouseshifted;
27 static QLock mousectlqlock;
29 static int intellimouse;
30 static int packetsize;
31 static int resolution;
32 static int accelerated;
33 static int mousehwaccel;
34 static char mouseport[5];
49 static Cmdtab mousectlmsg[] =
51 CMaccelerated, "accelerated", 0,
52 CMhwaccel, "hwaccel", 2,
53 CMintellimouse, "intellimouse", 1,
54 CMlinear, "linear", 1,
56 CMps2intellimouse, "ps2intellimouse", 1,
59 CMserial, "serial", 0,
63 * ps/2 mouse message is three bytes
65 * byte 0 - 0 0 SDY SDX 1 M R L
69 * shift & right button is the same as middle button
71 * Intellimouse and AccuPoint with extra buttons deliver
72 * byte 3 - 00 or 01 or FF according to extra button state.
73 * extra buttons are mapped in this code to buttons 4 and 5.
74 * AccuPoint generates repeated events for these buttons;
75 * it and Intellimouse generate 'down' events only, so
76 * user-level code is required to generate button 'up' events
77 * if they are needed by the application.
78 * Also on laptops with AccuPoint AND external mouse, the
79 * controller may deliver 3 or 4 bytes according to the type
80 * of the external mouse; code must adapt.
82 * On the NEC Versa series (and perhaps others?) we seem to
83 * lose a byte from the packet every once in a while, which
84 * means we lose where we are in the instruction stream.
85 * To resynchronize, if we get a byte more than two seconds
86 * after the previous byte, we assume it's the first in a packet.
89 ps2mouseputc(int c, int shift)
93 static uchar b[] = {0, 1, 4, 5, 2, 3, 6, 7, 0, 1, 2, 3, 2, 3, 6, 7 };
94 static ulong lasttick;
98 shift |= mouseshifted;
100 if(TK2SEC(m - lasttick) > 2)
103 if(nb==0 && (c&0xc8)!=0x08)
104 if(intellimouse && (c==0x00 || c==0x01 || c==0xFF)){
110 if(++nb >= packetsize){
117 buttons = b[(msg[0]&7) | (shift ? 8 : 0)];
118 if(intellimouse && packetsize==4){
119 if((msg[3]&0xc8) == 0x08){
124 if((msg[3] >> 3) & 1)
126 else if(msg[3] & 0x7)
132 mousetrack(dx, dy, buttons, TK2MS(MACHP(0)->ticks));
142 if(mousetype == MousePS2)
145 mousetype = MousePS2;
149 // i8042auxenable(ps2mouseputc);
150 // i8042auxcmd(0xEA); // TODO
151 // i8042auxcmd(0xF4);
155 * The PS/2 Trackpoint multiplexor on the IBM Thinkpad T23 ignores
156 * acceleration commands. It is supposed to pass them on
157 * to the attached device, but my Logitech mouse is simply
158 * not behaving any differently. For such devices, we allow
159 * the user to use "hwaccel off" to tell us to back off to
160 * software acceleration even if we're using the PS/2 port.
161 * (Serial mice are always software accelerated.)
162 * For more information on the Thinkpad multiplexor, see
163 * http://wwwcssrv.almaden.ibm.com/trackpoint/
166 setaccelerated(int x)
186 setintellimouse(void)
203 qlock(&mousectlqlock);
205 qunlock(&mousectlqlock);
209 ct = lookupcmd(cb, mousectlmsg, nelem(mousectlmsg));
212 setaccelerated(cb->nf == 1? 1: atoi(cb->f[1]));
223 case CMps2intellimouse:
228 setres(atoi(cb->f[1]));
235 setaccelerated(accelerated);
242 error("serial mice not supported");
245 if(strcmp(cb->f[1], "on")==0)
247 else if(strcmp(cb->f[1], "off")==0)
250 cmderror(cb, "bad mouse control message");
253 qunlock(&mousectlqlock);