devdraw: correct mouse event buffering on OS X

This commit is contained in:
Russ Cox 2008-07-10 00:07:57 -04:00
parent c752966bcb
commit 1f74e1b758

View file

@ -45,6 +45,7 @@ struct Kbdbuf
struct Mousebuf struct Mousebuf
{ {
Mouse m[32]; Mouse m[32];
Mouse last;
int ri; int ri;
int wi; int wi;
int stall; int stall;
@ -201,7 +202,6 @@ runmsg(Wsysmsg *m)
mousetags.wi = 0; mousetags.wi = 0;
if(mousetags.wi == mousetags.ri) if(mousetags.wi == mousetags.ri)
sysfatal("too many queued mouse reads"); sysfatal("too many queued mouse reads");
/* fprint(2, "mouse unstall\n"); */
mouse.stall = 0; mouse.stall = 0;
matchmouse(); matchmouse();
zunlock(); zunlock();
@ -379,21 +379,28 @@ mousetrack(int x, int y, int b, int ms)
y = mouserect.max.y; y = mouserect.max.y;
zlock(); zlock();
m = &mouse.m[mouse.wi]; // If reader has stopped reading, don't bother.
m->xy.x = x; // If reader is completely caught up, definitely queue.
m->xy.y = y; // Otherwise, queue only button change events.
m->buttons = b; if(!mouse.stall)
m->msec = ms; if(mouse.wi == mouse.ri || mouse.last.buttons != b){
mouse.wi++; m = &mouse.last;
if(mouse.wi == nelem(mouse.m)) m->xy.x = x;
mouse.wi = 0; m->xy.y = y;
if(mouse.wi == mouse.ri){ m->buttons = b;
mouse.stall = 1; m->msec = ms;
mouse.ri = 0;
mouse.wi = 1; mouse.m[mouse.wi] = *m;
mouse.m[0] = *m; if(++mouse.wi == nelem(mouse.m))
mouse.wi = 0;
if(mouse.wi == mouse.ri){
mouse.stall = 1;
mouse.ri = 0;
mouse.wi = 1;
mouse.m[0] = *m;
}
matchmouse();
} }
matchmouse();
zunlock(); zunlock();
} }