]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/pc/mouse.c
kernel: cleanup the software mouse cursor mess
[plan9front.git] / sys / src / 9 / pc / mouse.c
index 66bc1f937d70f5dd72aa8de5fb8cf70ea3e2c7f9..9d69095f944405cc4fe083da235477b725375862 100644 (file)
@@ -104,15 +104,16 @@ ps2mouseputc(int c, int shift)
        /* 
         *  check byte 0 for consistency
         */
-       if(nb==0 && (c&0xc8)!=0x08)
+       if(nb==0 && (c&0xc8)!=0x08){
                if(intellimouse && (c==0x00 || c==0x01 || c==0xFF)){
                        /* last byte of 4-byte packet */
                        packetsize = 4;
-                       return;
                }
+               return;
+       }
 
        msg[nb] = c;
-       if(++nb == packetsize){
+       if(++nb >= packetsize){
                nb = 0;
                if(msg[0] & 0x10)
                        msg[1] |= 0xFF00;
@@ -151,7 +152,6 @@ ps2mouseputc(int c, int shift)
                dy = -msg[2];
                mousetrack(dx, dy, buttons, TK2MS(MACHP(0)->ticks));
        }
-       return;
 }
 
 /*
@@ -163,14 +163,12 @@ ps2mouse(void)
        if(mousetype == MousePS2)
                return;
 
-       i8042auxenable(ps2mouseputc);
-       /* make mouse streaming, enabled */
-       i8042auxcmd(0xEA);
-       i8042auxcmd(0xF4);
-
        mousetype = MousePS2;
        packetsize = 3;
-       mousehwaccel = 1;
+       mousehwaccel = 0;
+
+       i8042auxenable(ps2mouseputc);
+       i8042auxcmd(0xEA);      /* set stream mode */
 }
 
 /*
@@ -239,7 +237,7 @@ setintellimouse(void)
                i8042auxcmd(0x50);
                break;
        case Mouseserial:
-               i8250setmouseputc(mouseport, m5mouseputc);
+               uartsetmouseputc(mouseport, m5mouseputc);
                break;
        }
 }
@@ -254,7 +252,26 @@ resetmouse(void)
                i8042auxcmd(0xEA);      /* streaming */
                i8042auxcmd(0xE8);      /* set resolution */
                i8042auxcmd(3);
-               i8042auxcmd(0xF4);      /* enabled */
+               break;
+       }
+}
+
+static void
+setstream(int on)
+{
+       int i;
+
+       switch(mousetype){
+       case MousePS2:
+               /*
+                * disabling streaming can fail when
+                * a packet is currently transmitted.
+                */
+               for(i=0; i<4; i++){
+                       if(i8042auxcmd(on ? 0xF4 : 0xF5) != -1)
+                               break;
+                       delay(50);
+               }
                break;
        }
 }
@@ -273,27 +290,37 @@ mousectl(Cmdbuf *cb)
        ct = lookupcmd(cb, mousectlmsg, nelem(mousectlmsg));
        switch(ct->index){
        case CMaccelerated:
+               setstream(0);
                setaccelerated(cb->nf == 1 ? 1 : atoi(cb->f[1]));
+               setstream(1);
                break;
        case CMintellimouse:
+               setstream(0);
                setintellimouse();
+               setstream(1);
                break;
        case CMlinear:
+               setstream(0);
                setlinear();
+               setstream(1);
                break;
        case CMps2:
                intellimouse = 0;
                ps2mouse();
+               setstream(1);
                break;
        case CMps2intellimouse:
                ps2mouse();
                setintellimouse();
+               setstream(1);
                break;
        case CMres:
+               setstream(0);
                if(cb->nf >= 2)
                        setres(atoi(cb->f[1]));
                else
                        setres(1);
+               setstream(1);
                break;
        case CMreset:
                resetmouse();
@@ -303,6 +330,7 @@ mousectl(Cmdbuf *cb)
                        setres(resolution);
                if(intellimouse)
                        setintellimouse();
+               setstream(1);
                break;
        case CMserial:
                if(mousetype == Mouseserial)
@@ -310,16 +338,17 @@ mousectl(Cmdbuf *cb)
 
                if(cb->nf > 2){
                        if(strcmp(cb->f[2], "M") == 0)
-                               i8250mouse(cb->f[1], m3mouseputc, 0);
+                               uartmouse(cb->f[1], m3mouseputc, 0);
                        else if(strcmp(cb->f[2], "MI") == 0)
-                               i8250mouse(cb->f[1], m5mouseputc, 0);
+                               uartmouse(cb->f[1], m5mouseputc, 0);
                        else
-                               i8250mouse(cb->f[1], mouseputc, cb->nf == 1);
+                               uartmouse(cb->f[1], mouseputc, cb->nf == 1);
                } else
-                       i8250mouse(cb->f[1], mouseputc, cb->nf == 1);
+                       uartmouse(cb->f[1], mouseputc, cb->nf == 1);
 
                mousetype = Mouseserial;
                strncpy(mouseport, cb->f[1], sizeof(mouseport)-1);
+               mouseport[sizeof(mouseport)-1] = 0;
                packetsize = 3;
                break;
        case CMhwaccel: