diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2023-01-01 18:37:08 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2023-01-01 18:37:08 +0000 |
commit | 705885553cced0300ed72722b20bad405af2bdce (patch) | |
tree | 80ec1d964bc7a30b4ca55ac08170da3b5dfe4645 /sys/src/9/port | |
parent | ba66d8f69edd895682f2661524a1d07612cb9ba8 (diff) |
mouse: Make /dev/mousein readable to get mouse status without blocking
There is currently no way to get the current mouse position
and button states without blocking.
Diffstat (limited to 'sys/src/9/port')
-rw-r--r-- | sys/src/9/port/devmouse.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/sys/src/9/port/devmouse.c b/sys/src/9/port/devmouse.c index d09d6f7d5..81d2328a7 100644 --- a/sys/src/9/port/devmouse.c +++ b/sys/src/9/port/devmouse.c @@ -88,7 +88,7 @@ static Dirtab mousedir[]={ ".", {Qdir, 0, QTDIR}, 0, DMDIR|0555, "cursor", {Qcursor}, 0, 0666, "mouse", {Qmouse}, 0, 0666, - "mousein", {Qmousein}, 0, 0220, + "mousein", {Qmousein}, 0, 0660, "mousectl", {Qmousectl}, 0, 0220, }; @@ -207,7 +207,9 @@ mouseclose(Chan *c) return; switch((ulong)c->qid.path){ case Qmousein: + ilock(&mouse); mouse.inbuttons &= ~((Mousestate*)c->aux)->buttons; + iunlock(&mouse); free(c->aux); /* Mousestate */ c->aux = nil; return; @@ -232,6 +234,7 @@ mouseread(Chan *c, void *va, long n, vlong off) Cursor curs; Mousestate m; int b; + char t; p = va; switch((ulong)c->qid.path){ @@ -272,23 +275,39 @@ mouseread(Chan *c, void *va, long n, vlong off) m = mouse.Mousestate; iunlock(&mouse); + if(0){ + case Qmousein: + if(offset != 0) + return 0; + + ilock(&mouse); + m = mouse.Mousestate; + iunlock(&mouse); + + t = 'm'; + } else { + /* Qmouse */ + mouse.lastcounter = m.counter; + if(mouse.resize){ + mouse.resize = 0; + t = 'r'; + } else { + t = 'm'; + } + } + b = buttonmap[m.buttons&7]; /* put buttons 4 and 5 back in */ b |= m.buttons & (3<<3); + if (scrollswap) if (b == 8) b = 16; else if (b == 16) b = 8; - sprint(buf, "m%11d %11d %11d %11ld ", - m.xy.x, m.xy.y, b, m.msec); - - mouse.lastcounter = m.counter; - if(mouse.resize){ - mouse.resize = 0; - buf[0] = 'r'; - } + snprint(buf, sizeof(buf), "%c%11d %11d %11d %11ld ", + t, m.xy.x, m.xy.y, b, m.msec); if(n > 1+4*12) n = 1+4*12; memmove(va, buf, n); @@ -446,8 +465,11 @@ mousewrite(Chan *c, void *va, long n, vlong) m->msec = msec; b ^= m->buttons; m->buttons ^= b; + + ilock(&mouse); mouse.inbuttons = (m->buttons & b) | (mouse.inbuttons & ~b); b = mouse.buttons & ~b; + iunlock(&mouse); /* include wheel */ b &= ~(8|16); |