History

do not use ixppending

yiyus committed 15 years agolibixp

Commit f369d001 parent 4e2aafb9 files · +267 −73Browse files

Unified · Split

9 files
  1. devwsys/dat.h +29 −6
  2. devwsys/fns.h +7 −1
  3. devwsys/ixp_fsys.c +47 −43
  4. devwsys/keyboard.c +67 −6
  5. devwsys/mkfile +1 −0
  6. devwsys/mouse.c +87 −15
  7. devwsys/reqbuf.c +27 −0
  8. devwsys/wctl.c +1 −1
  9. devwsys/x11/event.c +1 −1
devwsys/dat.h+29−6
@@ -34,11 +34,18 @@ typedef struct Client Client; /* Defined in devdraw.c: */ · 33 unmodified lines
34typedef struct Kbdbuf Kbdbuf;34typedef struct Kbdbuf Kbdbuf;
35typedef struct Cursor Cursor;35typedef struct Cursor Cursor;
36typedef struct Clip Clip;36typedef struct Clip Clip;
37typedef struct Mousebuf Mousebuf;
38typedef struct Reqbuf Reqbuf;
37typedef struct Window Window;39typedef struct Window Window;
38 40
39/* Used by kbdputc */41/* Keyboard */
40struct Kbdbuf42struct Kbdbuf
41{43{
44 Rune r[32];
45 int ri;
46 int wi;
47 int stall;
48 /* Used by kbdputc */
42 uchar k[5*UTFmax];49 uchar k[5*UTFmax];
43 int alting, nk;50 int alting, nk;
44};51};
@@ -51,6 +58,23 @@ struct Mouse · 6 unmodified lines
51 ulong msec;58 ulong msec;
52};59};
53 60
61struct Mousebuf
62{
63 int open;
64 Mouse m[32];
65 int ri;
66 int wi;
67 int stall;
68 int resized;
69};
70
71struct Reqbuf
72{
73 void *r[32];
74 int ri;
75 int wi;
76};
77
54struct Cursor {78struct Cursor {
55 int hotx;79 int hotx;
56 int hoty;80 int hoty;
@@ -72,8 +96,6 @@ struct Window · 15 unmodified lines
72 int id;96 int id;
73 int fullscreen;97 int fullscreen;
74 int deleted;98 int deleted;
75 int mouseopen;
76 int mousebuttons;
77 int pid;99 int pid;
78 int resized;100 int resized;
79 int visible;101 int visible;
@@ -81,10 +103,11 @@ struct Window · 1 unmodified line
81 char *name;103 char *name;
82 Draw *draw;104 Draw *draw;
83 void *screenimage;105 void *screenimage;
84 Kbdbuf kbd;
85 void *kbdp;
86 void *killr;106 void *killr;
87 void *mousep;107 Kbdbuf kbd;
108 Mousebuf mouse;
109 Reqbuf kbdreqs;
110 Reqbuf mousereqs;
88 Cursor cursor;111 Cursor cursor;
89 Point orig;112 Point orig;
90 Rectangle screenr;113 Rectangle screenr;
devwsys/fns.h+7−1
@@ -8,11 +8,17 @@ void drawreplacescreenimage(Window*); · 7 unmodified lines
8 8
9/* Keyboard */9/* Keyboard */
10void writekbd(Window*, int);10void writekbd(Window*, int);
11void readkbd(Window*, void*);
11 12
12/* Mouse */13/* Mouse */
14void readmouse(Window*, void*);
13void writemouse(Window*, Mouse, int);15void writemouse(Window*, Mouse, int);
14int cursorwrite(Window*, char*, int);16int cursorwrite(Window*, char*, int);
15 17
18/* Reqbuf */
19void addreq(Reqbuf*, void*);
20void* nextreq(Reqbuf *reqs);
21
16/* Window */22/* Window */
17Window* newwin(char*);23Window* newwin(char*);
18void deletewin(Window*);24void deletewin(Window*);
@@ -22,7 +28,7 @@ void setlabel(Window*, char*); · 3 unmodified lines
22int wctlmesg(Window*, char*, int, char*);28int wctlmesg(Window*, char*, int, char*);
23 29
24/* Ixp */30/* Ixp */
25void ixppwrite(void*, char*);31void ixprread(void*, char*);
26int ixpserve(char*);32int ixpserve(char*);
27void killrespond(Window*);33void killrespond(Window*);
28 34
devwsys/ixp_fsys.c+47−43
@@ -31,7 +31,7 @@ const char · 30 unmodified lines
31 *Eshortwrite = "draw write too short";31 *Eshortwrite = "draw write too short";
32 32
33/* Macros */33/* Macros */
34#define debug9p(...) if(0) debug(__VA_ARGS__)34#define debug9p(...) if(1) debug(__VA_ARGS__)
35#define QID(t, i) (((vlong)((t)&0xFF)<<32)|((i)&0xFFFFFFFF))35#define QID(t, i) (((vlong)((t)&0xFF)<<32)|((i)&0xFFFFFFFF))
36 36
37/* Global Vars */37/* Global Vars */
@@ -238,14 +238,6 @@ fs_attach(Ixp9Req *r) { · 200 unmodified lines
238 ixp_respond(r, Enomem);238 ixp_respond(r, Enomem);
239 return;239 return;
240 }240 }
241 if(!(w->kbdp = mallocz(sizeof(IxpPending), 1))){
242 ixp_respond(r, Enomem);
243 return;
244 }
245 if(!(w->mousep = mallocz(sizeof(IxpPending), 1))){
246 ixp_respond(r, Enomem);
247 return;
248 }
249 f->p.window = w;241 f->p.window = w;
250 ixp_respond(r, nil);242 ixp_respond(r, nil);
251}243}
@@ -292,16 +284,12 @@ fs_open(Ixp9Req *r) { · 40 unmodified lines
292 switch(f->tab.type) {284 switch(f->tab.type) {
293 case FsFNew:285 case FsFNew:
294 break;286 break;
295 case FsFCons:
296 ixp_pending_pushfid(w->kbdp, r->fid);
297 break;
298 case FsFMouse:287 case FsFMouse:
299 if(w->mouseopen){288 if(w->mouse.open){
300 ixp_respond(r, Einuse);289 ixp_respond(r, Einuse);
301 return;290 return;
302 }291 }
303 w->mouseopen = 1;292 w->mouse.open = 1;
304 ixp_pending_pushfid(w->mousep, r->fid);
305 break;293 break;
306 case FsFSnarf:294 case FsFSnarf:
307 if((r->ifcall.topen.mode&3) == ORDWR){295 if((r->ifcall.topen.mode&3) == ORDWR){
@@ -352,10 +340,6 @@ fs_read(Ixp9Req *r) { · 44 unmodified lines
352 ixp_srv_readdir(r, lookup_file, dostat);340 ixp_srv_readdir(r, lookup_file, dostat);
353 return;341 return;
354 }342 }
355 if(f->pending) {
356 ixp_pending_respond(r);
357 return;
358 }
359 cl = f->p.client;343 cl = f->p.client;
360 w = f->p.window;344 w = f->p.window;
361 if(!iswindow(f->tab.type))345 if(!iswindow(f->tab.type))
@@ -380,6 +364,9 @@ fs_read(Ixp9Req *r) { · 18 unmodified lines
380 return;364 return;
381 }365 }
382 switch(f->tab.type) {366 switch(f->tab.type) {
367 case FsFCons:
368 readkbd(w, r);
369 return;
383 case FsFKill:370 case FsFKill:
384 w->killr = r;371 w->killr = r;
385 if(w->deleted){372 if(w->deleted){
@@ -393,6 +380,9 @@ fs_read(Ixp9Req *r) { · 7 unmodified lines
393 ixp_srv_readbuf(r, w->label, strlen(w->label));380 ixp_srv_readbuf(r, w->label, strlen(w->label));
394 ixp_respond(r, nil);381 ixp_respond(r, nil);
395 return;382 return;
383 case FsFMouse:
384 readmouse(w, r);
385 return;
396 case FsFSnarf:386 case FsFSnarf:
397 s= xgetsnarf(w);387 s= xgetsnarf(w);
398 ixp_srv_readbuf(r, s, strlen(s));388 ixp_srv_readbuf(r, s, strlen(s));
@@ -522,13 +512,13 @@ fs_write(Ixp9Req *r) { · 123 unmodified lines
522 setlabel(w, label);512 setlabel(w, label);
523 break;513 break;
524 case FsFMouse:514 case FsFMouse:
525 /*
526 * TODO: as we are using ixp_pending to read,
527 * there is no way to get the aux field to write.
528 */
529 break;
530 r->ofcall.io.count = r->ifcall.io.count;515 r->ofcall.io.count = r->ifcall.io.count;
531 pt.x = strtoul(r->ifcall.twrite.data, &p, 0);516 if(r->ifcall.io.count == 0){
517 ixp_respond(r, Eshortwrite);
518 return;
519 }
520 p = &r->ifcall.twrite.data[1];
521 pt.x = strtoul(p, &p, 0);
532 if(p == 0){522 if(p == 0){
533 ixp_respond(r, Eshortwrite);523 ixp_respond(r, Eshortwrite);
534 return;524 return;
@@ -590,17 +580,18 @@ fs_clunk(Ixp9Req *r) { · 55 unmodified lines
590 w = f->p.window;580 w = f->p.window;
591 if(!iswindow(f->tab.type))581 if(!iswindow(f->tab.type))
592 w = drawwindow(cl);582 w = drawwindow(cl);
593 if(f->pending) {
594 /* Should probably be in freefid */
595 if(ixp_pending_clunk(r)) {
596 if(f->tab.type == FsFMouse)
597 w->mouseopen = 0;
598 }
599 return;
600 }
601 583
602 // TODO: ../../inferno-os/emu/port/devdraw.c:971584 // TODO: ../../inferno-os/emu/port/devdraw.c:971
603 switch(f->tab.type){585 switch(f->tab.type){
586 case FsFCons:
587 w->kbd.wi = w->kbd.ri;
588 w->kbdreqs.wi = w->kbdreqs.ri;
589 break;
590 case FsFMouse:
591 w->mouse.open = 0;
592 w->mouse.wi = w->mouse.ri;
593 w->mousereqs.wi = w->mousereqs.ri;
594 break;
604 case FsFSnarf:595 case FsFSnarf:
605 if(r->fid->omode == OWRITE){596 if(r->fid->omode == OWRITE){
606 if(snarfbuf)597 if(snarfbuf)
@@ -624,9 +615,6 @@ fs_flush(Ixp9Req *r) { · 17 unmodified lines
624 615
625 or = r->oldreq;616 or = r->oldreq;
626 f = or->fid->aux;617 f = or->fid->aux;
627 if(f->pending)
628 ixp_pending_flush(r);
629 /* else die() ? */
630 ixp_respond(r->oldreq, Einterrupted);618 ixp_respond(r->oldreq, Einterrupted);
631 ixp_respond(r, nil);619 ixp_respond(r, nil);
632}620}
@@ -678,17 +666,33 @@ Ixp9Srv p9srv = { · 45 unmodified lines
678};666};
679 667
680void668void
681ixppwrite(void *v, char *buf)669killrespond(Window *w)
682{670{
683 IxpPending *p;671 fs_read(w->killr);
684
685 p = v;
686 ixp_pending_write(p, buf, strlen(buf));
687}672}
688 673
674/* Reply a read request */
689void675void
690killrespond(Window *w)676ixprread(void *v, char *buf)
691{677{
692 fs_read(w->killr);678 Ixp9Req *r;
679 IxpFileId *f;
680 Client *cl;
681 Window *w;
682
683 r = v;
684 f = r->fid->aux;
685 // print("XXX ixprread %s\n", f->tab.name);
686 cl = f->p.client;
687 w = f->p.window;
688 if(!iswindow(f->tab.type))
689 w = drawwindow(cl);
690 if(w->deleted){
691 ixp_respond(r, Edeleted);
692 return;
693 }
694 r->ifcall.rread.offset = 0;
695 ixp_srv_readbuf(r, buf, strlen(buf));
696 ixp_respond(r, nil);
693}697}
694 698
devwsys/keyboard.c+67−6
@@ -4,24 +4,85 @@ · 3 unmodified lines
4#include "dat.h"4#include "dat.h"
5#include "fns.h"5#include "fns.h"
6 6
7int kbdputc(Kbdbuf*, int);7static void addkbd(Kbdbuf*, int);
8static void matchkbd(Kbdbuf*, Reqbuf*);
9static void replykbd(Kbdbuf*, void*);
10static int kbdputc(Kbdbuf*, int);
8long latin1(uchar*, int);11long latin1(uchar*, int);
9 12
13void
14readkbd(Window *w, void* r)
15{
16 Kbdbuf *kbd;
17 Reqbuf *kbdreqs;
18
19 kbd = &w->kbd;
20 kbdreqs = &w->kbdreqs;
21
22 addreq(kbdreqs, r);
23 // fprint(2, "kbd unstall\n");
24 kbd->stall = 0;
25 matchkbd(kbd, kbdreqs);
26}
27
10void28void
11writekbd(Window *w, int ch)29writekbd(Window *w, int ch)
12{30{
13 char buf[5];
14 Rune r;
15 Kbdbuf *kbd;31 Kbdbuf *kbd;
32 Reqbuf *kbdreqs;
16 33
17 kbd = &w->kbd;34 kbd = &w->kbd;
18 if((ch = kbdputc(kbd, ch)) == -1)35 kbdreqs = &w->kbdreqs;
36
37 addkbd(kbd, ch);
38 matchkbd(kbd, kbdreqs);
39}
40
41static
42void
43addkbd(Kbdbuf *kbd, int ch)
44{
45 Rune r;
46
47 ch = kbdputc(kbd, ch);
48 if(kbd->stall || ch == -1)
19 return;49 return;
20 r = ch;50 r = ch;
21 sprint(buf, "%C", r);51
22 ixppwrite(w->kbdp, buf);52 kbd->r[kbd->wi++] = r;
53 if(kbd->wi == nelem(kbd->r))
54 kbd->wi = 0;
55 if(kbd->ri == kbd->wi){
56 kbd->stall = 1;
57 /* fprint(2, "kbd stall\n"); */
58 }
59}
60
61static
62void
63matchkbd(Kbdbuf *kbd, Reqbuf *kbdreqs)
64{
65 while(kbd->ri != kbd->wi && kbdreqs->ri != kbdreqs->wi){
66 replykbd(kbd, nextreq(kbdreqs));
67 kbd->ri++;
68 if(kbd->ri == nelem(kbd->r))
69 kbd->ri = 0;
70 }
71}
72
73static
74void
75replykbd(Kbdbuf *kbd, void *r)
76{
77 char buf[5];
78 Rune rune;
79
80 rune = kbd->r[kbd->ri];
81 sprint(buf, "%C", rune);
82 ixprread(r, buf);
23}83}
24 84
85static
25int86int
26kbdputc(Kbdbuf *kbd, int ch)87kbdputc(Kbdbuf *kbd, int ch)
27{88{
devwsys/mkfile+1−0
@@ -26,6 +26,7 @@ OFILES=\ · 25 unmodified lines
26 latin1.$O\26 latin1.$O\
27 main.$O\27 main.$O\
28 mouse.$O\28 mouse.$O\
29 reqbuf.$O\
29 wctl.$O\30 wctl.$O\
30 window.$O\31 window.$O\
31 $SYSHOST-$OBJTYPE.$O\32 $SYSHOST-$OBJTYPE.$O\
devwsys/mouse.c+87−15
@@ -4,25 +4,96 @@ · 3 unmodified lines
4#include "dat.h"4#include "dat.h"
5#include "fns.h"5#include "fns.h"
6 6
7static void addmouse(Mousebuf*, Mouse, int);
8static void matchmouse(Mousebuf*, Reqbuf*);
9static void replymouse(Mousebuf*, void*);
10
11void
12readmouse(Window *w, void* r)
13{
14 Mousebuf *mouse;
15 Reqbuf *mousereqs;
16
17 mouse = &w->mouse;
18 mousereqs = &w->mousereqs;
19
20 addreq(mousereqs, r);
21 // fprint(2, "mouse unstall\n");
22 mouse->stall = 0;
23 matchmouse(mouse, mousereqs);
24}
25
7void26void
8writemouse(Window *w, Mouse m, int resized)27writemouse(Window *w, Mouse m, int resized)
9{28{
10 char buf[50], c;29 Mousebuf *mouse;
30 Reqbuf *mousereqs;
11 31
12 /*32 mouse = &w->mouse;
13 * TODO:33 mousereqs = &w->mousereqs;
14 * Continuous resizes will cause too many redraws.34
15 * The solution is to not queue resize events and instead35 addmouse(mouse, m, resized);
16 * change the response, but IxpPending is too opaque36 matchmouse(mouse, mousereqs);
17 * to do that.37}
18 */38
19 c = 'm';39static
20 if(w->resized)40void
21 c = 'r';41addmouse(Mousebuf *mouse, Mouse m, int resized)
22 sprint(buf, "%c%11d %11d %11d %11ld ", c, m.xy.x, m.xy.y, m.buttons, m.msec);42{
23 w->mousebuttons = m.buttons;43 int p;
24 w->resized = 0;44
25 ixppwrite(w->mousep, buf);45 if(!mouse->open || mouse->stall)
46 return;
47
48 mouse->m[mouse->wi] = m;
49 if(resized){
50 p = mouse->wi - 1;
51 if(p < 0)
52 p = nelem(mouse->m) - 1;
53 mouse->m[mouse->wi] = mouse->m[p];
54 mouse->resized = 1;
55 }
56 mouse->wi++;
57 if(mouse->wi == nelem(mouse->m))
58 mouse->wi = 0;
59 if(mouse->wi == mouse->ri){
60 mouse->stall = 1;
61 mouse->ri = 0;
62 mouse->wi = 1;
63 mouse->m[0] = m;
64 /* fprint(2, "mouse stall\n"); */
65 }
66}
67
68static
69void
70replymouse(Mousebuf *mouse, void *r)
71{
72 int n, resized;
73 char buf[50], c;
74 Mouse m;
75
76 m = mouse->m[mouse->ri];
77 resized = mouse->resized;
78 c = 'm';
79 if(mouse->resized)
80 c = 'r';
81 n = sprint(buf, "%c%11d %11d %11d %11ld ", c, m.xy.x, m.xy.y, m.buttons, m.msec);
82 buf[n] = '\0';
83 ixprread(r, buf);
84 mouse->resized = 0;
85}
86
87static
88void
89matchmouse(Mousebuf *mouse, Reqbuf *mousereqs)
90{
91 while(mouse->ri != mouse->wi && mousereqs->ri != mousereqs->wi){
92 replymouse(mouse, nextreq(mousereqs));
93 mouse->ri++;
94 if(mouse->ri == nelem(mouse->m))
95 mouse->ri = 0;
96 }
26}97}
27 98
28static int99static int
@@ -145,3 +216,4 @@ cursorwrite(Window *w, char *buf, int n) · 116 unmodified lines
145 }216 }
146 return 0;217 return 0;
147}218}
219
devwsys/reqbuf.c+27−0
@@ -0,0 +1,27 @@
1#include <lib9.h>
2#include <draw.h>
3#include "dat.h"
4#include "fns.h"
5
6void
7addreq(Reqbuf *reqs, void* r)
8{
9 reqs->r[reqs->wi] = r;
10 reqs->wi++;
11 if(reqs->wi == nelem(reqs->r))
12 reqs->wi = 0;
13 if(reqs->wi == reqs->ri)
14 sysfatal("too many queued reads");
15}
16
17void*
18nextreq(Reqbuf *reqs)
19{
20 void *r;
21
22 r = reqs->r[reqs->ri];
23 reqs->ri++;
24 if(reqs->ri == nelem(reqs->r))
25 reqs->ri = 0;
26 return r;
27}
devwsys/wctl.c+1−1
@@ -255,7 +255,7 @@ wctlmesg(Window *w, char *a, int n, char *err) · 254 unmodified lines
255 cnt = n;255 cnt = n;
256 a[cnt] = '\0';256 a[cnt] = '\0';
257 id = pid = 0;257 id = pid = 0;
258 buttons = w->mousebuttons;258 buttons = w->mouse.m[w->mouse.ri].buttons;
259 259
260 // print(" XXX wctlmesg: a = %s\n", a);260 // print(" XXX wctlmesg: a = %s\n", a);
261 rect = rectaddpt(w->screenr, w->orig);261 rect = rectaddpt(w->screenr, w->orig);
devwsys/x11/event.c+1−1
@@ -135,7 +135,7 @@ configevent(Window *w, XEvent xev) · 134 unmodified lines
135 * the window has already been resized, but135 * the window has already been resized, but
136 * IxpPending does not let us to do that.136 * IxpPending does not let us to do that.
137 */137 */
138 // writemouse(w, m, 1);138 writemouse(w, m, 1);
139}139}
140 140
141void141void