/* * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No * part of the UCB release of Plan 9, including this file, may be copied, * modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ #include #include #include #include #include #include #include #include "flayer.h" #include "samterm.h" int cursorfd; int plumbfd = -1; int input; int got; int block; int kbdc; int resized; uint8_t *hostp; uint8_t *hoststop; uint8_t *plumbbase; uint8_t *plumbp; uint8_t *plumbstop; Channel *plumbc; Channel *hostc; Mousectl *mousectl; Mouse *mousep; Keyboardctl *keyboardctl; void panic(char*); void closeio(void) { closekeyboard(keyboardctl); closemouse(mousectl); } void initio(void) { threadsetname("main"); mousectl = initmouse(nil, display->image); if(mousectl == nil){ jehanne_fprint(2, "samterm: mouse init failed: %r\n"); threadexitsall("mouse"); } mousep = (Mouse *)mousectl; keyboardctl = initkeyboard(nil); if(keyboardctl == nil){ jehanne_fprint(2, "samterm: keyboard init failed: %r\n"); threadexitsall("kbd"); } jehanne_atexit(closeio); hoststart(); if(plumbstart() < 0) extstart(); } void getmouse(void) { if(readmouse(mousectl) < 0) panic("mouse"); } void mouseunblock(void) { got &= ~(1<buttons&(1<<(but-1)); } void externload(int i) { plumbbase = jehanne_malloc(plumbbuf[i].n); if(plumbbase == 0) return; jehanne_memmove(plumbbase, plumbbuf[i].data, plumbbuf[i].n); plumbp = plumbbase; plumbstop = plumbbase + plumbbuf[i].n; got |= 1<c; alts[RKeyboard].v = &r; alts[RKeyboard].op = CHANRCV; if(block & (1<c; alts[RMouse].v = &mousectl->Mouse; alts[RMouse].op = CHANRCV; if(block & (1<resizec; alts[RResize].v = nil; alts[RResize].op = CHANRCV; if(block & (1<= plumbstop){ got &= ~(1<= 0) return 1; if(nbrecv(keyboardctl->c, &r) > 0){ kpeekc = r; return 1; } return 0; } int ekbd(void) { int c; Rune r; if(kpeekc >= 0){ c = kpeekc; kpeekc = -1; return c; } if(recv(keyboardctl->c, &r) < 0){ jehanne_fprint(2, "samterm: keybard recv error: %r\n"); panic("kbd"); } return r; } int kbdchar(void) { int c, i; c = externchar(); if(c > 0) return c; if(got & (1<0){ externload(i); c = externchar(); if(c > 0) return c; } if(!ecankbd()) return -1; return ekbd(); } int qpeekc(void) { return kbdc; } int RESIZED(void) { if(resized){ if(getwindow(display, Refnone) < 0) panic("can't reattach to window"); resized = 0; return 1; } return 0; }