devmouse: differential handling of /dev/mousein buttons

This commit is contained in:
cinap_lenrek 2013-10-07 06:34:24 +02:00
parent ad1111cb3e
commit 6c6bd66ed1

View file

@ -71,6 +71,7 @@ Mouseinfo mouse;
Cursorinfo cursor; Cursorinfo cursor;
int mouseshifted; int mouseshifted;
Cursor curs; Cursor curs;
int mouseinbuttons;
void Cursortocursor(Cursor*); void Cursortocursor(Cursor*);
int mousechanged(void*); int mousechanged(void*);
@ -192,6 +193,9 @@ mouseopen(Chan *c, int omode)
case Qmousein: case Qmousein:
if(!iseve()) if(!iseve())
error(Eperm); error(Eperm);
c->aux = malloc(sizeof(Mousestate));
if(c->aux == nil)
error(Enomem);
break; break;
default: default:
incref(&mouse); incref(&mouse);
@ -220,6 +224,9 @@ mouseclose(Chan *c)
mouse.open = 0; mouse.open = 0;
else if(c->qid.path == Qmousein){ else if(c->qid.path == Qmousein){
unlock(&mouse); unlock(&mouse);
mouseinbuttons &= ~((Mousestate*)c->aux)->buttons;
free(c->aux); /* Mousestate */
c->aux = nil;
return; return;
} }
if(--mouse.ref != 0){ if(--mouse.ref != 0){
@ -368,6 +375,7 @@ mousewrite(Chan *c, void *va, long n, vlong)
Cmdtab *ct; Cmdtab *ct;
char buf[64]; char buf[64];
int b, msec; int b, msec;
Mousestate *m;
p = va; p = va;
switch((ulong)c->qid.path){ switch((ulong)c->qid.path){
@ -448,6 +456,13 @@ mousewrite(Chan *c, void *va, long n, vlong)
msec = strtol(p, &p, 0); msec = strtol(p, &p, 0);
if(msec == 0) if(msec == 0)
msec = TK2MS(MACHP(0)->ticks); msec = TK2MS(MACHP(0)->ticks);
m = (Mousestate*)c->aux;
m->xy = pt;
m->msec = msec;
b ^= m->buttons;
m->buttons ^= b;
mouseinbuttons = (m->buttons & b) | (mouseinbuttons & ~b);
b = mouse.buttons & ~b;
if(buf[0] == 'A') if(buf[0] == 'A')
absmousetrack(pt.x, pt.y, b, msec); absmousetrack(pt.x, pt.y, b, msec);
else else
@ -598,6 +613,8 @@ absmousetrack(int x, int y, int b, int msec)
if(y >= gscreen->clipr.max.y) if(y >= gscreen->clipr.max.y)
y = gscreen->clipr.max.y; y = gscreen->clipr.max.y;
b |= mouseinbuttons;
lastb = mouse.buttons; lastb = mouse.buttons;
mouse.xy = Pt(x, y); mouse.xy = Pt(x, y);
mouse.buttons = b; mouse.buttons = b;