Unified · Split
| @@ -31,7 +31,6 @@ · 30 unmodified lines | |||
| 31 | #define topLeft(r) (((Point *) &(r))[0]) | 31 | #define topLeft(r) (((Point *) &(r))[0]) |
| 32 | #define botRight(r) (((Point *) &(r))[1]) | 32 | #define botRight(r) (((Point *) &(r))[1]) |
| 33 | 33 | ||
| 34 | extern int mousequeue; | ||
| 35 | static int depth; | 34 | static int depth; |
| 36 | Boolean gDone; | 35 | Boolean gDone; |
| 37 | RgnHandle gCursorRegionHdl; | 36 | RgnHandle gCursorRegionHdl; |
| @@ -269,32 +268,10 @@ static inline int convert_key(UInt32 key, UInt32 charcode) · 231 unmodified lines | |||
| 269 | } | 268 | } |
| 270 | } | 269 | } |
| 271 | 270 | ||
| 272 | void | 271 | static void |
| 273 | sendbuttons(int b, int x, int y) | 272 | sendbuttons(int b, int x, int y) |
| 274 | { | 273 | { |
| 275 | int i; | 274 | absmousetrack(x, y, b, ticks()); |
| 276 | lock(&mouse.lk); | ||
| 277 | i = mouse.wi; | ||
| 278 | if(mousequeue) { | ||
| 279 | if(i == mouse.ri || mouse.lastb != b || mouse.trans) { | ||
| 280 | mouse.wi = (i+1)%Mousequeue; | ||
| 281 | if(mouse.wi == mouse.ri) | ||
| 282 | mouse.ri = (mouse.ri+1)%Mousequeue; | ||
| 283 | mouse.trans = mouse.lastb != b; | ||
| 284 | } else { | ||
| 285 | i = (i-1+Mousequeue)%Mousequeue; | ||
| 286 | } | ||
| 287 | } else { | ||
| 288 | mouse.wi = (i+1)%Mousequeue; | ||
| 289 | mouse.ri = i; | ||
| 290 | } | ||
| 291 | mouse.queue[i].xy.x = x; | ||
| 292 | mouse.queue[i].xy.y = y; | ||
| 293 | mouse.queue[i].buttons = b; | ||
| 294 | mouse.queue[i].msec = ticks(); | ||
| 295 | mouse.lastb = b; | ||
| 296 | unlock(&mouse.lk); | ||
| 297 | wakeup(&mouse.r); | ||
| 298 | } | 275 | } |
| 299 | 276 | ||
| 300 | static Ptr fullScreenRestore; | 277 | static Ptr fullScreenRestore; |
| @@ -19,7 +19,6 @@ · 18 unmodified lines | |||
| 19 | Memimage *gscreen; | 19 | Memimage *gscreen; |
| 20 | Screeninfo screen; | 20 | Screeninfo screen; |
| 21 | 21 | ||
| 22 | extern int mousequeue; | ||
| 23 | static int depth; | 22 | static int depth; |
| 24 | 23 | ||
| 25 | static HINSTANCE inst; | 24 | static HINSTANCE inst; |
| @@ -210,8 +209,6 @@ winproc(void *a) · 184 unmodified lines | |||
| 210 | readybit = 1; | 209 | readybit = 1; |
| 211 | wakeup(&rend); | 210 | wakeup(&rend); |
| 212 | 211 | ||
| 213 | screen.reshaped = 0; | ||
| 214 | |||
| 215 | while(GetMessage(&msg, NULL, 0, 0)) { | 212 | while(GetMessage(&msg, NULL, 0, 0)) { |
| 216 | TranslateMessage(&msg); | 213 | TranslateMessage(&msg); |
| 217 | DispatchMessage(&msg); | 214 | DispatchMessage(&msg); |
| @@ -387,28 +384,7 @@ WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) · 169 unmodified lines | |||
| 387 | else | 384 | else |
| 388 | b |= 4; | 385 | b |= 4; |
| 389 | } | 386 | } |
| 390 | lock(&mouse.lk); | 387 | absmousetrack(x, y, b, ticks()); |
| 391 | i = mouse.wi; | ||
| 392 | if(mousequeue) { | ||
| 393 | if(i == mouse.ri || mouse.lastb != b || mouse.trans) { | ||
| 394 | mouse.wi = (i+1)%Mousequeue; | ||
| 395 | if(mouse.wi == mouse.ri) | ||
| 396 | mouse.ri = (mouse.ri+1)%Mousequeue; | ||
| 397 | mouse.trans = mouse.lastb != b; | ||
| 398 | } else { | ||
| 399 | i = (i-1+Mousequeue)%Mousequeue; | ||
| 400 | } | ||
| 401 | } else { | ||
| 402 | mouse.wi = (i+1)%Mousequeue; | ||
| 403 | mouse.ri = i; | ||
| 404 | } | ||
| 405 | mouse.queue[i].xy.x = x; | ||
| 406 | mouse.queue[i].xy.y = y; | ||
| 407 | mouse.queue[i].buttons = b; | ||
| 408 | mouse.queue[i].msec = ticks(); | ||
| 409 | mouse.lastb = b; | ||
| 410 | unlock(&mouse.lk); | ||
| 411 | wakeup(&mouse.r); | ||
| 412 | break; | 388 | break; |
| 413 | 389 | ||
| 414 | case WM_CHAR: | 390 | case WM_CHAR: |
| @@ -112,8 +112,6 @@ static XColor map7[128]; /* Plan 9 colormap array */ · 111 unmodified lines | |||
| 112 | static uchar map7to8[128][2]; | 112 | static uchar map7to8[128][2]; |
| 113 | static Colormap xcmap; /* Default shared colormap */ | 113 | static Colormap xcmap; /* Default shared colormap */ |
| 114 | 114 | ||
| 115 | extern int mousequeue; | ||
| 116 | |||
| 117 | /* for copy/paste, lifted from plan9ports */ | 115 | /* for copy/paste, lifted from plan9ports */ |
| 118 | static Atom clipboard; | 116 | static Atom clipboard; |
| 119 | static Atom utf8string; | 117 | static Atom utf8string; |
| @@ -969,25 +967,7 @@ xmouse(XEvent *e) · 849 unmodified lines | |||
| 969 | if(s & Button5Mask) | 967 | if(s & Button5Mask) |
| 970 | ms.buttons |= 16; | 968 | ms.buttons |= 16; |
| 971 | 969 | ||
| 972 | lock(&mouse.lk); | 970 | absmousetrack(ms.x, ms.y, ms.buttons, ms.msec); |
| 973 | i = mouse.wi; | ||
| 974 | if(mousequeue) { | ||
| 975 | if(i == mouse.ri || mouse.lastb != ms.buttons || mouse.trans) { | ||
| 976 | mouse.wi = (i+1)%Mousequeue; | ||
| 977 | if(mouse.wi == mouse.ri) | ||
| 978 | mouse.ri = (mouse.ri+1)%Mousequeue; | ||
| 979 | mouse.trans = mouse.lastb != ms.buttons; | ||
| 980 | } else { | ||
| 981 | i = (i-1+Mousequeue)%Mousequeue; | ||
| 982 | } | ||
| 983 | } else { | ||
| 984 | mouse.wi = (i+1)%Mousequeue; | ||
| 985 | mouse.ri = i; | ||
| 986 | } | ||
| 987 | mouse.queue[i] = ms; | ||
| 988 | mouse.lastb = ms.buttons; | ||
| 989 | unlock(&mouse.lk); | ||
| 990 | wakeup(&mouse.r); | ||
| 991 | } | 971 | } |
| 992 | 972 | ||
| 993 | void | 973 | void |
| @@ -8,8 +8,6 @@ · 7 unmodified lines | |||
| 8 | #include "memdraw.h" | 8 | #include "memdraw.h" |
| 9 | #include "screen.h" | 9 | #include "screen.h" |
| 10 | 10 | ||
| 11 | int mousequeue = 1; | ||
| 12 | |||
| 13 | Mouseinfo mouse; | 11 | Mouseinfo mouse; |
| 14 | Cursorinfo cursor; | 12 | Cursorinfo cursor; |
| 15 | Cursorinfo arrow = { | 13 | Cursorinfo arrow = { |
| @@ -96,13 +94,9 @@ mouseopen(Chan *c, int omode) · 80 unmodified lines | |||
| 96 | error(Eperm); | 94 | error(Eperm); |
| 97 | break; | 95 | break; |
| 98 | case Qmouse: | 96 | case Qmouse: |
| 99 | lock(&mouse.lk); | 97 | if(tas(&mouse.open) != 0) |
| 100 | if(mouse.open){ | ||
| 101 | unlock(&mouse.lk); | ||
| 102 | error(Einuse); | 98 | error(Einuse); |
| 103 | } | 99 | mouse.lastcounter = mouse.state.counter; |
| 104 | mouse.open = 1; | ||
| 105 | unlock(&mouse.lk); | ||
| 106 | break; | 100 | break; |
| 107 | } | 101 | } |
| 108 | c->mode = openmode(omode); | 102 | c->mode = openmode(omode); |
| @@ -119,9 +113,7 @@ mouseclose(Chan *c) · 10 unmodified lines | |||
| 119 | 113 | ||
| 120 | switch((long)c->qid.path) { | 114 | switch((long)c->qid.path) { |
| 121 | case Qmouse: | 115 | case Qmouse: |
| 122 | lock(&mouse.lk); | ||
| 123 | mouse.open = 0; | 116 | mouse.open = 0; |
| 124 | unlock(&mouse.lk); | ||
| 125 | cursor = arrow; | 117 | cursor = arrow; |
| 126 | setcursor(); | 118 | setcursor(); |
| 127 | } | 119 | } |
| @@ -131,9 +123,9 @@ long · 3 unmodified lines | |||
| 131 | mouseread(Chan *c, void *va, long n, vlong offset) | 123 | mouseread(Chan *c, void *va, long n, vlong offset) |
| 132 | { | 124 | { |
| 133 | char buf[4*12+1]; | 125 | char buf[4*12+1]; |
| 126 | Mousestate m; | ||
| 134 | uchar *p; | 127 | uchar *p; |
| 135 | int i, nn, b; | 128 | int b; |
| 136 | ulong msec; | ||
| 137 | 129 | ||
| 138 | p = va; | 130 | p = va; |
| 139 | switch((long)c->qid.path){ | 131 | switch((long)c->qid.path){ |
| @@ -158,46 +150,27 @@ mouseread(Chan *c, void *va, long n, vlong offset) · 18 unmodified lines | |||
| 158 | while(mousechanged(0) == 0) | 150 | while(mousechanged(0) == 0) |
| 159 | sleep(&mouse.r, mousechanged, 0); | 151 | sleep(&mouse.r, mousechanged, 0); |
| 160 | 152 | ||
| 161 | lock(&screen.lk); | ||
| 162 | if(screen.reshaped) { | ||
| 163 | screen.reshaped = 0; | ||
| 164 | sprint(buf, "t%11d %11d", 0, ticks()); | ||
| 165 | if(n > 1+2*12) | ||
| 166 | n = 1+2*12; | ||
| 167 | memmove(va, buf, n); | ||
| 168 | unlock(&screen.lk); | ||
| 169 | return n; | ||
| 170 | } | ||
| 171 | unlock(&screen.lk); | ||
| 172 | |||
| 173 | lock(&mouse.lk); | 153 | lock(&mouse.lk); |
| 174 | i = mouse.ri; | 154 | if(mouse.ri != mouse.wi) |
| 175 | nn = (mouse.wi + Mousequeue - i) % Mousequeue; | 155 | m = mouse.queue[mouse.ri++ % nelem(mouse.queue)]; |
| 176 | if(nn < 1) | 156 | else |
| 177 | panic("empty mouse queue"); | 157 | m = mouse.state; |
| 178 | msec = ticks(); | 158 | unlock(&mouse.lk); |
| 179 | while(nn > 1) { | 159 | |
| 180 | if(mouse.queue[i].msec + Mousewindow > msec) | 160 | b = buttonmap[m.buttons&7]; |
| 181 | break; | ||
| 182 | i = (i+1)%Mousequeue; | ||
| 183 | nn--; | ||
| 184 | } | ||
| 185 | b = buttonmap[mouse.queue[i].buttons&7]; | ||
| 186 | /* put buttons 4 and 5 back in */ | 161 | /* put buttons 4 and 5 back in */ |
| 187 | b |= mouse.queue[i].buttons & (3<<3); | 162 | b |= m.buttons & (3<<3); |
| 188 | if(scrollswap){ | 163 | if (scrollswap) { |
| 189 | if(b == 8) | 164 | if (b == 8) |
| 190 | b = 16; | 165 | b = 16; |
| 191 | else if(b == 16) | 166 | else if (b == 16) |
| 192 | b = 8; | 167 | b = 8; |
| 193 | } | 168 | } |
| 194 | sprint(buf, "m%11d %11d %11d %11d", | 169 | sprint(buf, "m%11d %11d %11d %11lud ", |
| 195 | mouse.queue[i].xy.x, | 170 | m.xy.x, m.xy.y, b, m.msec); |
| 196 | mouse.queue[i].xy.y, | 171 | |
| 197 | b, | 172 | mouse.lastcounter = m.counter; |
| 198 | mouse.queue[i].msec); | 173 | |
| 199 | mouse.ri = (i+1)%Mousequeue; | ||
| 200 | unlock(&mouse.lk); | ||
| 201 | if(n > 1+4*12) | 174 | if(n > 1+4*12) |
| 202 | n = 1+4*12; | 175 | n = 1+4*12; |
| 203 | memmove(va, buf, n); | 176 | memmove(va, buf, n); |
| @@ -335,8 +308,42 @@ int · 131 unmodified lines | |||
| 335 | mousechanged(void *a) | 308 | mousechanged(void *a) |
| 336 | { | 309 | { |
| 337 | USED(a); | 310 | USED(a); |
| 311 | return mouse.lastcounter != mouse.state.counter; | ||
| 312 | } | ||
| 313 | |||
| 314 | void | ||
| 315 | absmousetrack(int x, int y, int b, int msec) | ||
| 316 | { | ||
| 317 | int lastb; | ||
| 318 | |||
| 319 | if(gscreen==nil) | ||
| 320 | return; | ||
| 338 | 321 | ||
| 339 | return mouse.ri != mouse.wi || screen.reshaped; | 322 | if(x < gscreen->clipr.min.x) |
| 323 | x = gscreen->clipr.min.x; | ||
| 324 | if(x >= gscreen->clipr.max.x) | ||
| 325 | x = gscreen->clipr.max.x-1; | ||
| 326 | if(y < gscreen->clipr.min.y) | ||
| 327 | y = gscreen->clipr.min.y; | ||
| 328 | if(y >= gscreen->clipr.max.y) | ||
| 329 | y = gscreen->clipr.max.y-1; | ||
| 330 | |||
| 331 | lock(&mouse.lk); | ||
| 332 | mouse.state.xy = Pt(x, y); | ||
| 333 | lastb = mouse.state.buttons; | ||
| 334 | mouse.state.buttons = b; | ||
| 335 | mouse.state.msec = msec; | ||
| 336 | mouse.state.counter++; | ||
| 337 | |||
| 338 | /* | ||
| 339 | * if the queue fills, don't queue any more events until a | ||
| 340 | * reader polls the mouse. | ||
| 341 | */ | ||
| 342 | if(b != lastb && (mouse.wi-mouse.ri) < nelem(mouse.queue)) | ||
| 343 | mouse.queue[mouse.wi++ % nelem(mouse.queue)] = mouse.state; | ||
| 344 | unlock(&mouse.lk); | ||
| 345 | |||
| 346 | wakeup(&mouse.r); | ||
| 340 | } | 347 | } |
| 341 | 348 | ||
| 342 | Dev mousedevtab = { | 349 | Dev mousedevtab = { |
| @@ -3,23 +3,22 @@ typedef struct Mousestate Mousestate; · 2 unmodified lines | |||
| 3 | typedef struct Cursorinfo Cursorinfo; | 3 | typedef struct Cursorinfo Cursorinfo; |
| 4 | typedef struct Screeninfo Screeninfo; | 4 | typedef struct Screeninfo Screeninfo; |
| 5 | 5 | ||
| 6 | #define Mousequeue 16 /* queue can only have Mousequeue-1 elements */ | ||
| 7 | #define Mousewindow 500 /* mouse event window in millisec */ | ||
| 8 | |||
| 9 | struct Mousestate { | 6 | struct Mousestate { |
| 10 | int buttons; | ||
| 11 | Point xy; | 7 | Point xy; |
| 8 | int buttons; | ||
| 9 | ulong counter; | ||
| 12 | ulong msec; | 10 | ulong msec; |
| 13 | }; | 11 | }; |
| 14 | 12 | ||
| 15 | struct Mouseinfo { | 13 | struct Mouseinfo { |
| 16 | Lock lk; | 14 | Lock lk; |
| 17 | Mousestate queue[Mousequeue]; | 15 | Mousestate state; |
| 18 | int ri, wi; | 16 | ulong lastcounter; |
| 19 | int lastb; | 17 | Rendez r; |
| 20 | int trans; | 18 | int open; |
| 21 | int open; | 19 | Mousestate queue[16]; /* circular buffer of click events */ |
| 22 | Rendez r; | 20 | ulong ri; /* read index into queue */ |
| 21 | ulong wi; /* write index into queue */ | ||
| 23 | }; | 22 | }; |
| 24 | 23 | ||
| 25 | struct Cursorinfo { | 24 | struct Cursorinfo { |
| @@ -30,11 +29,9 @@ struct Cursorinfo { · 4 unmodified lines | |||
| 30 | }; | 29 | }; |
| 31 | 30 | ||
| 32 | struct Screeninfo { | 31 | struct Screeninfo { |
| 33 | Lock lk; | 32 | Lock lk; |
| 34 | Memimage *newsoft; | 33 | int depth; |
| 35 | int reshaped; | 34 | int dibtype; |
| 36 | int depth; | ||
| 37 | int dibtype; | ||
| 38 | }; | 35 | }; |
| 39 | 36 | ||
| 40 | extern Memimage *gscreen; | 37 | extern Memimage *gscreen; |
| @@ -55,6 +52,8 @@ void flushmemscreen(Rectangle); · 14 unmodified lines | |||
| 55 | uchar* attachscreen(Rectangle*, ulong*, int*, int*, int*); | 52 | uchar* attachscreen(Rectangle*, ulong*, int*, int*, int*); |
| 56 | 53 | ||
| 57 | extern QLock drawlock; | 54 | extern QLock drawlock; |
| 58 | #define ishwimage(i) 1 | 55 | #define ishwimage(i) 0 |
| 59 | 56 | ||
| 60 | void terminit(void); | 57 | void terminit(void); |
| 58 | |||
| 59 | void absmousetrack(int, int, int, int); | ||