devmouse.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "u.h"
  10. #include "../port/lib.h"
  11. #include "mem.h"
  12. #include "dat.h"
  13. #include "fns.h"
  14. #include "../port/error.h"
  15. #define Image IMAGE
  16. #include <draw.h>
  17. #include <memdraw.h>
  18. #include <cursor.h>
  19. #include "screen.h"
  20. enum {
  21. ScrollUp = 0x08,
  22. ScrollDown = 0x10,
  23. ScrollLeft = 0x20,
  24. ScrollRight = 0x40,
  25. };
  26. typedef struct Mouseinfo Mouseinfo;
  27. typedef struct Mousestate Mousestate;
  28. struct Mousestate
  29. {
  30. Point xy; /* mouse.xy */
  31. int buttons; /* mouse.buttons */
  32. uint32_t counter; /* increments every update */
  33. uint32_t msec; /* time of last event */
  34. };
  35. struct Mouseinfo
  36. {
  37. Lock _lock;
  38. Mousestate Mousestate;
  39. int dx;
  40. int dy;
  41. int track; /* dx & dy updated */
  42. int redraw; /* update cursor on screen */
  43. uint32_t lastcounter; /* value when /dev/mouse read */
  44. uint32_t lastresize;
  45. uint32_t resize;
  46. Rendez rend;
  47. Ref r;
  48. QLock ql;
  49. int open;
  50. int acceleration;
  51. int maxacc;
  52. Mousestate queue[16]; /* circular buffer of click events */
  53. int ri; /* read index into queue */
  54. int wi; /* write index into queue */
  55. unsigned char qfull; /* queue is full */
  56. };
  57. enum
  58. {
  59. CMbuttonmap,
  60. CMscrollswap,
  61. CMswap,
  62. CMwildcard,
  63. };
  64. static Cmdtab mousectlmsg[] =
  65. {
  66. CMbuttonmap, "buttonmap", 0,
  67. CMscrollswap, "scrollswap", 0,
  68. CMswap, "swap", 1,
  69. CMwildcard, "*", 0,
  70. };
  71. Mouseinfo mouse;
  72. Cursorinfo cursor;
  73. int mouseshifted;
  74. int kbdbuttons;
  75. void (*kbdmouse)(int);
  76. Cursor curs;
  77. void Cursortocursor(Cursor*);
  78. int mousechanged(void*);
  79. static void mouseclock(void);
  80. enum{
  81. Qdir,
  82. Qcursor,
  83. Qmouse,
  84. Qmousein,
  85. Qmousectl,
  86. };
  87. static Dirtab mousedir[]={
  88. ".", {Qdir, 0, QTDIR}, 0, DMDIR|0555,
  89. "cursor", {Qcursor}, 0, 0666,
  90. "mouse", {Qmouse}, 0, 0666,
  91. "mousein", {Qmousein}, 0, 0220,
  92. "mousectl", {Qmousectl}, 0, 0220,
  93. };
  94. static unsigned char buttonmap[8] = {
  95. 0, 1, 2, 3, 4, 5, 6, 7,
  96. };
  97. static int mouseswap;
  98. static int scrollswap;
  99. static uint32_t mousetime;
  100. extern Memimage* gscreen;
  101. extern uint32_t kerndate;
  102. static void
  103. mousereset(void)
  104. {
  105. curs = arrow;
  106. Cursortocursor(&arrow);
  107. /* redraw cursor about 30 times per second */
  108. addclock0link(mouseclock, 33);
  109. }
  110. static void
  111. mousefromkbd(int buttons)
  112. {
  113. kbdbuttons = buttons;
  114. mousetrack(0, 0, 0, TK2MS(machp()->ticks));
  115. }
  116. static int
  117. mousedevgen(Chan *c, char *name, Dirtab *tab, int ntab, int i, Dir *dp)
  118. {
  119. int rc;
  120. rc = devgen(c, name, tab, ntab, i, dp);
  121. if(rc != -1)
  122. dp->atime = mousetime;
  123. return rc;
  124. }
  125. static void
  126. mouseinit(void)
  127. {
  128. curs = arrow;
  129. Cursortocursor(&arrow);
  130. cursoron(1);
  131. kbdmouse = mousefromkbd;
  132. mousetime = seconds();
  133. }
  134. static Chan*
  135. mouseattach(char *spec)
  136. {
  137. return devattach('m', spec);
  138. }
  139. static Walkqid*
  140. mousewalk(Chan *c, Chan *nc, char **name, int nname)
  141. {
  142. Walkqid *wq;
  143. /*
  144. * We use devgen() and not mousedevgen() here
  145. * see "Ugly problem" in dev.c/devwalk()
  146. */
  147. wq = devwalk(c, nc, name, nname, mousedir, nelem(mousedir), devgen);
  148. if(wq != nil && wq->clone != c && wq->clone != nil && (wq->clone->qid.type&QTDIR)==0)
  149. incref(&mouse.r);
  150. return wq;
  151. }
  152. static int
  153. mousestat(Chan *c, unsigned char *db, int n)
  154. {
  155. return devstat(c, db, n, mousedir, nelem(mousedir), mousedevgen);
  156. }
  157. static Chan*
  158. mouseopen(Chan *c, int omode)
  159. {
  160. switch((uint32_t)c->qid.path){
  161. case Qdir:
  162. if(omode != OREAD)
  163. error(Eperm);
  164. break;
  165. case Qmouse:
  166. lock(&mouse.r.l);
  167. if(mouse.open){
  168. unlock(&mouse.r.l);
  169. error(Einuse);
  170. }
  171. mouse.open = 1;
  172. mouse.r.ref++;
  173. mouse.lastresize = mouse.resize;
  174. unlock(&mouse.r.l);
  175. break;
  176. case Qmousein:
  177. if(!iseve())
  178. error(Eperm);
  179. break;
  180. default:
  181. incref(&mouse.r);
  182. }
  183. c->mode = openmode(omode);
  184. c->flag |= COPEN;
  185. c->offset = 0;
  186. return c;
  187. }
  188. static void
  189. mousecreate(Chan *c, char *j, int i, int u)
  190. {
  191. error(Eperm);
  192. }
  193. static void
  194. mouseclose(Chan *c)
  195. {
  196. if((c->qid.type&QTDIR)==0 && (c->flag&COPEN)){
  197. if(c->qid.path == Qmousein)
  198. return;
  199. lock(&mouse.r.l);
  200. if(c->qid.path == Qmouse)
  201. mouse.open = 0;
  202. if(--mouse.r.ref == 0){
  203. cursoroff(1);
  204. curs = arrow;
  205. Cursortocursor(&arrow);
  206. cursoron(1);
  207. }
  208. unlock(&mouse.r.l);
  209. }
  210. }
  211. static int32_t
  212. mouseread(Chan *c, void *va, int32_t n, int64_t off)
  213. {
  214. Proc *up = externup();
  215. char buf[1+4*12+1];
  216. unsigned char *p;
  217. uint32_t offset = off;
  218. Mousestate m;
  219. int b;
  220. p = va;
  221. switch((uint32_t)c->qid.path){
  222. case Qdir:
  223. return devdirread(c, va, n, mousedir, nelem(mousedir), mousedevgen);
  224. case Qcursor:
  225. if(offset != 0)
  226. return 0;
  227. if(n < 2*4+2*2*16)
  228. error(Eshort);
  229. n = 2*4+2*2*16;
  230. lock(&cursor.l);
  231. BPLONG(p+0, curs.offset.x);
  232. BPLONG(p+4, curs.offset.y);
  233. memmove(p+8, curs.clr, 2*16);
  234. memmove(p+40, curs.set, 2*16);
  235. unlock(&cursor.l);
  236. return n;
  237. case Qmouse:
  238. while(mousechanged(0) == 0)
  239. sleep(&mouse.rend, mousechanged, 0);
  240. mouse.qfull = 0;
  241. mousetime = seconds();
  242. /*
  243. * No lock of the indices is necessary here, because ri is only
  244. * updated by us, and there is only one mouse reader
  245. * at a time. I suppose that more than one process
  246. * could try to read the fd at one time, but such behavior
  247. * is degenerate and already violates the calling
  248. * conventions for sleep above.
  249. */
  250. if(mouse.ri != mouse.wi) {
  251. m = mouse.queue[mouse.ri];
  252. if(++mouse.ri == nelem(mouse.queue))
  253. mouse.ri = 0;
  254. } else {
  255. while(!canlock(&cursor.l))
  256. tsleep(&up->sleep, return0, 0, TK2MS(1));
  257. m = mouse.Mousestate;
  258. unlock(&cursor.l);
  259. }
  260. b = buttonmap[m.buttons&7];
  261. /* put buttons 4 and 5 back in */
  262. b |= m.buttons & (3<<3);
  263. if (scrollswap)
  264. if (b == 8)
  265. b = 16;
  266. else if (b == 16)
  267. b = 8;
  268. snprint(buf, sizeof buf, "m%11d %11d %11d %11lu ",
  269. m.xy.x, m.xy.y,
  270. b,
  271. m.msec);
  272. mouse.lastcounter = m.counter;
  273. if(n > 1+4*12)
  274. n = 1+4*12;
  275. if(mouse.lastresize != mouse.resize){
  276. mouse.lastresize = mouse.resize;
  277. buf[0] = 'r';
  278. }
  279. memmove(va, buf, n);
  280. return n;
  281. }
  282. return 0;
  283. }
  284. static void
  285. setbuttonmap(char* map)
  286. {
  287. int i, x, one, two, three;
  288. one = two = three = 0;
  289. for(i = 0; i < 3; i++){
  290. if(map[i] == 0)
  291. error(Ebadarg);
  292. if(map[i] == '1'){
  293. if(one)
  294. error(Ebadarg);
  295. one = 1<<i;
  296. }
  297. else if(map[i] == '2'){
  298. if(two)
  299. error(Ebadarg);
  300. two = 1<<i;
  301. }
  302. else if(map[i] == '3'){
  303. if(three)
  304. error(Ebadarg);
  305. three = 1<<i;
  306. }
  307. else
  308. error(Ebadarg);
  309. }
  310. if(map[i])
  311. error(Ebadarg);
  312. memset(buttonmap, 0, 8);
  313. for(i = 0; i < 8; i++){
  314. x = 0;
  315. if(i & 1)
  316. x |= one;
  317. if(i & 2)
  318. x |= two;
  319. if(i & 4)
  320. x |= three;
  321. buttonmap[x] = i;
  322. }
  323. }
  324. static int32_t
  325. mousewrite(Chan *c, void *va, int32_t n, int64_t r)
  326. {
  327. Proc *up = externup();
  328. char *p;
  329. Point pt;
  330. Cmdbuf *cb;
  331. Cmdtab *ct;
  332. char buf[64];
  333. int b, msec;
  334. p = va;
  335. switch((uint32_t)c->qid.path){
  336. case Qdir:
  337. error(Eisdir);
  338. case Qcursor:
  339. cursoroff(1);
  340. if(n < 2*4+2*2*16){
  341. curs = arrow;
  342. Cursortocursor(&arrow);
  343. }else{
  344. n = 2*4+2*2*16;
  345. curs.offset.x = BGLONG(p+0);
  346. curs.offset.y = BGLONG(p+4);
  347. memmove(curs.clr, p+8, 2*16);
  348. memmove(curs.set, p+40, 2*16);
  349. Cursortocursor(&curs);
  350. }
  351. qlock(&mouse.ql);
  352. mouse.redraw = 1;
  353. mouseclock();
  354. qunlock(&mouse.ql);
  355. cursoron(1);
  356. return n;
  357. case Qmousectl:
  358. cb = parsecmd(va, n);
  359. if(waserror()){
  360. free(cb);
  361. nexterror();
  362. }
  363. ct = lookupcmd(cb, mousectlmsg, nelem(mousectlmsg));
  364. switch(ct->index){
  365. case CMswap:
  366. if(mouseswap)
  367. setbuttonmap("123");
  368. else
  369. setbuttonmap("321");
  370. mouseswap ^= 1;
  371. break;
  372. case CMscrollswap:
  373. scrollswap ^= 1;
  374. break;
  375. case CMbuttonmap:
  376. if(cb->nf == 1)
  377. setbuttonmap("123");
  378. else
  379. setbuttonmap(cb->f[1]);
  380. break;
  381. case CMwildcard:
  382. mousectl(cb);
  383. break;
  384. }
  385. free(cb);
  386. poperror();
  387. return n;
  388. case Qmousein:
  389. if(n > sizeof buf-1)
  390. n = sizeof buf -1;
  391. memmove(buf, va, n);
  392. buf[n] = 0;
  393. p = 0;
  394. pt.x = strtol(buf+1, &p, 0);
  395. if(p == 0)
  396. error(Eshort);
  397. pt.y = strtol(p, &p, 0);
  398. if(p == 0)
  399. error(Eshort);
  400. b = strtol(p, &p, 0);
  401. msec = strtol(p, &p, 0);
  402. if(msec == 0)
  403. msec = TK2MS(machp()->ticks);
  404. mousetrack(pt.x, pt.y, b, msec);
  405. return n;
  406. case Qmouse:
  407. if(n > sizeof buf-1)
  408. n = sizeof buf -1;
  409. memmove(buf, va, n);
  410. buf[n] = 0;
  411. p = 0;
  412. pt.x = strtoul(buf+1, &p, 0);
  413. if(p == 0)
  414. error(Eshort);
  415. pt.y = strtoul(p, 0, 0);
  416. qlock(&mouse.ql);
  417. if(ptinrect(pt, gscreen->r)){
  418. mouse.Mousestate.xy = pt;
  419. mouse.redraw = 1;
  420. mouse.track = 1;
  421. mouseclock();
  422. }
  423. qunlock(&mouse.ql);
  424. return n;
  425. }
  426. error(Egreg);
  427. return -1;
  428. }
  429. Dev mousedevtab = {
  430. .dc = 'm',
  431. .name = "mouse",
  432. .reset = mousereset,
  433. .init = mouseinit,
  434. .shutdown = devshutdown,
  435. .attach = mouseattach,
  436. .walk = mousewalk,
  437. .stat = mousestat,
  438. .open = mouseopen,
  439. .create = mousecreate,
  440. .close = mouseclose,
  441. .read = mouseread,
  442. .bread = devbread,
  443. .write = mousewrite,
  444. .bwrite = devbwrite,
  445. .remove = devremove,
  446. .wstat = devwstat,
  447. };
  448. void
  449. Cursortocursor(Cursor *c)
  450. {
  451. lock(&cursor.l);
  452. memmove(&cursor.c, c, sizeof(Cursor));
  453. setcursor(c);
  454. unlock(&cursor.l);
  455. }
  456. /*
  457. * called by the clock routine to redraw the cursor
  458. */
  459. static void
  460. mouseclock(void)
  461. {
  462. if(mouse.track){
  463. mousetrack(mouse.dx, mouse.dy, mouse.Mousestate.buttons, TK2MS(machp()->ticks));
  464. mouse.track = 0;
  465. mouse.dx = 0;
  466. mouse.dy = 0;
  467. }
  468. if(mouse.redraw && canlock(&cursor.l)){
  469. mouse.redraw = 0;
  470. cursoroff(0);
  471. mouse.redraw = cursoron(0);
  472. unlock(&cursor.l);
  473. }
  474. drawactive(0);
  475. }
  476. static int
  477. scale(int x)
  478. {
  479. int sign = 1;
  480. if(x < 0){
  481. sign = -1;
  482. x = -x;
  483. }
  484. switch(x){
  485. case 0:
  486. case 1:
  487. case 2:
  488. case 3:
  489. break;
  490. case 4:
  491. x = 6 + (mouse.acceleration>>2);
  492. break;
  493. case 5:
  494. x = 9 + (mouse.acceleration>>1);
  495. break;
  496. default:
  497. x *= mouse.maxacc;
  498. break;
  499. }
  500. return sign*x;
  501. }
  502. /*
  503. * called at interrupt level to update the structure and
  504. * awaken any waiting procs.
  505. */
  506. void
  507. mousetrack(int dx, int dy, int b, int msec)
  508. {
  509. int x, y, lastb;
  510. if(gscreen==nil)
  511. return;
  512. if(mouse.acceleration){
  513. dx = scale(dx);
  514. dy = scale(dy);
  515. }
  516. x = mouse.Mousestate.xy.x + dx;
  517. if(x < gscreen->clipr.min.x)
  518. x = gscreen->clipr.min.x;
  519. if(x >= gscreen->clipr.max.x)
  520. x = gscreen->clipr.max.x;
  521. y = mouse.Mousestate.xy.y + dy;
  522. if(y < gscreen->clipr.min.y)
  523. y = gscreen->clipr.min.y;
  524. if(y >= gscreen->clipr.max.y)
  525. y = gscreen->clipr.max.y;
  526. lastb = mouse.Mousestate.buttons;
  527. mouse.Mousestate.xy = Pt(x, y);
  528. mouse.Mousestate.buttons = b|kbdbuttons;
  529. mouse.redraw = 1;
  530. mouse.Mousestate.counter++;
  531. mouse.Mousestate.msec = msec;
  532. /*
  533. * if the queue fills, we discard the entire queue and don't
  534. * queue any more events until a reader polls the mouse.
  535. */
  536. if(!mouse.qfull && lastb != b) { /* add to ring */
  537. mouse.queue[mouse.wi] = mouse.Mousestate;
  538. if(++mouse.wi == nelem(mouse.queue))
  539. mouse.wi = 0;
  540. if(mouse.wi == mouse.ri)
  541. mouse.qfull = 1;
  542. }
  543. wakeup(&mouse.rend);
  544. drawactive(1);
  545. }
  546. /*
  547. * microsoft 3 button, 7 bit bytes
  548. *
  549. * byte 0 - 1 L R Y7 Y6 X7 X6
  550. * byte 1 - 0 X5 X4 X3 X2 X1 X0
  551. * byte 2 - 0 Y5 Y4 Y3 Y2 Y1 Y0
  552. * byte 3 - 0 M x x x x x (optional)
  553. *
  554. * shift & right button is the same as middle button (for 2 button mice)
  555. */
  556. int
  557. m3mouseputc(Queue *queue, int c)
  558. {
  559. static unsigned char msg[3];
  560. static int nb;
  561. static int middle;
  562. static unsigned char b[] = { 0, 4, 1, 5, 0, 2, 1, 3 };
  563. short x;
  564. int dx, dy, newbuttons;
  565. static uint32_t lasttick;
  566. uint32_t m;
  567. /* Resynchronize in stream with timing. */
  568. m = machp()->ticks;
  569. if(TK2SEC(m - lasttick) > 2)
  570. nb = 0;
  571. lasttick = m;
  572. if(nb==0){
  573. /*
  574. * an extra byte comes for middle button motion.
  575. * only two possible values for the extra byte.
  576. */
  577. if(c == 0x00 || c == 0x20){
  578. /* an extra byte gets sent for the middle button */
  579. middle = (c&0x20) ? 2 : 0;
  580. newbuttons = (mouse.Mousestate.buttons & ~2) | middle;
  581. mousetrack(0, 0, newbuttons, TK2MS(machp()->ticks));
  582. return 0;
  583. }
  584. }
  585. msg[nb] = c;
  586. if(++nb == 3){
  587. nb = 0;
  588. newbuttons = middle | b[(msg[0]>>4)&3 | (mouseshifted ? 4 : 0)];
  589. x = (msg[0]&0x3)<<14;
  590. dx = (x>>8) | msg[1];
  591. x = (msg[0]&0xc)<<12;
  592. dy = (x>>8) | msg[2];
  593. mousetrack(dx, dy, newbuttons, TK2MS(machp()->ticks));
  594. }
  595. return 0;
  596. }
  597. /*
  598. * microsoft intellimouse 3 buttons + scroll
  599. * byte 0 - 1 L R Y7 Y6 X7 X6
  600. * byte 1 - 0 X5 X4 X3 X2 X1 X0
  601. * byte 2 - 0 Y5 Y4 Y3 Y2 Y1 Y0
  602. * byte 3 - 0 0 M % % % %
  603. *
  604. * %: 0xf => U , 0x1 => D
  605. *
  606. * L: left
  607. * R: right
  608. * U: up
  609. * D: down
  610. */
  611. int
  612. m5mouseputc(Queue *queue, int c)
  613. {
  614. static unsigned char msg[8];
  615. static int nb;
  616. static uint32_t lasttick;
  617. uint32_t m;
  618. /* Resynchronize in stream with timing. */
  619. m = machp()->ticks;
  620. if(TK2SEC(m - lasttick) > 2)
  621. nb = 0;
  622. lasttick = m;
  623. msg[nb++] = c & 0x7f;
  624. if (nb == 4) {
  625. char dx,dy,newbuttons;
  626. dx = msg[1] | (msg[0] & 0x3) << 6;
  627. dy = msg[2] | (msg[0] & 0xc) << 4;
  628. newbuttons =
  629. (msg[0] & 0x10) >> (mouseshifted ? 3 : 2)
  630. | (msg[0] & 0x20) >> 5
  631. | ( msg[3] == 0x10 ? 0x02 :
  632. msg[3] == 0x0f ? ScrollUp :
  633. msg[3] == 0x01 ? ScrollDown : 0 );
  634. mousetrack(dx, dy, newbuttons, TK2MS(machp()->ticks));
  635. nb = 0;
  636. }
  637. return 0;
  638. }
  639. /*
  640. * Logitech 5 byte packed binary mouse format, 8 bit bytes
  641. *
  642. * shift & right button is the same as middle button (for 2 button mice)
  643. */
  644. int
  645. mouseputc(Queue *queue, int c)
  646. {
  647. static short msg[5];
  648. static int nb;
  649. static unsigned char b[] = {0, 4, 2, 6, 1, 5, 3, 7, 0, 2, 2, 6, 1, 3, 3, 7};
  650. int dx, dy, newbuttons;
  651. static uint32_t lasttick;
  652. uint32_t m;
  653. /* Resynchronize in stream with timing. */
  654. m = machp()->ticks;
  655. if(TK2SEC(m - lasttick) > 2)
  656. nb = 0;
  657. lasttick = m;
  658. if((c&0xF0) == 0x80)
  659. nb=0;
  660. msg[nb] = c;
  661. if(c & 0x80)
  662. msg[nb] |= ~0xFF; /* sign extend */
  663. if(++nb == 5){
  664. newbuttons = b[((msg[0]&7)^7) | (mouseshifted ? 8 : 0)];
  665. dx = msg[1]+msg[3];
  666. dy = -(msg[2]+msg[4]);
  667. mousetrack(dx, dy, newbuttons, TK2MS(machp()->ticks));
  668. nb = 0;
  669. }
  670. return 0;
  671. }
  672. int
  673. mousechanged(void *v)
  674. {
  675. return mouse.lastcounter != mouse.Mousestate.counter ||
  676. mouse.lastresize != mouse.resize;
  677. }
  678. Point
  679. mousexy(void)
  680. {
  681. return mouse.Mousestate.xy;
  682. }
  683. void
  684. mouseaccelerate(int x)
  685. {
  686. mouse.acceleration = x;
  687. if(mouse.acceleration < 3)
  688. mouse.maxacc = 2;
  689. else
  690. mouse.maxacc = mouse.acceleration;
  691. }
  692. /*
  693. * notify reader that screen has been resized
  694. */
  695. void
  696. mouseresize(void)
  697. {
  698. mouse.resize++;
  699. wakeup(&mouse.rend);
  700. }