1 enum 2 { 3 Qdir, /* /dev for this window */ 4 Qcons, 5 Qconsctl, 6 Qcursor, 7 Qwdir, 8 Qwinid, 9 Qwinname, 10 Qkbdin, 11 Qlabel, 12 Qmouse, 13 Qnew, 14 Qscreen, 15 Qsnarf, 16 Qtext, 17 Qwctl, 18 Qwindow, 19 Qwsys, /* directory of window directories */ 20 Qwsysdir, /* window directory, child of wsys */ 21 22 QMAX, 23 }; 24 25 enum 26 { 27 Kscrolloneup = KF|0x20, 28 Kscrollonedown = KF|0x21, 29 }; 30 31 #define STACK 8192 32 33 typedef struct Consreadmesg Consreadmesg; 34 typedef struct Conswritemesg Conswritemesg; 35 typedef struct Stringpair Stringpair; 36 typedef struct Dirtab Dirtab; 37 typedef struct Fid Fid; 38 typedef struct Filsys Filsys; 39 typedef struct Mouseinfo Mouseinfo; 40 typedef struct Mousereadmesg Mousereadmesg; 41 typedef struct Mousestate Mousestate; 42 typedef struct Ref Ref; 43 typedef struct Timer Timer; 44 typedef struct Wctlmesg Wctlmesg; 45 typedef struct Window Window; 46 typedef struct Xfid Xfid; 47 48 enum 49 { 50 Selborder = 4, /* border of selected window */ 51 Unselborder = 1, /* border of unselected window */ 52 Scrollwid = 12, /* width of scroll bar */ 53 Scrollgap = 4, /* gap right of scroll bar */ 54 BIG = 3, /* factor by which window dimension can exceed screen */ 55 TRUE = 1, 56 FALSE = 0, 57 }; 58 59 #define QID(w,q) ((w<<8)|(q)) 60 #define WIN(q) ((((ulong)(q).path)>>8) & 0xFFFFFF) 61 #define FILE(q) (((ulong)(q).path) & 0xFF) 62 63 enum /* control messages */ 64 { 65 Wakeup, 66 Reshaped, 67 Moved, 68 Refresh, 69 Movemouse, 70 Rawon, 71 Rawoff, 72 Holdon, 73 Holdoff, 74 Deleted, 75 Exited, 76 }; 77 78 struct Wctlmesg 79 { 80 int type; 81 Rectangle r; 82 Image *image; 83 }; 84 85 struct Conswritemesg 86 { 87 Channel *cw; /* chan(Stringpair) */ 88 }; 89 90 struct Consreadmesg 91 { 92 Channel *c1; /* chan(tuple(char*, int) == Stringpair) */ 93 Channel *c2; /* chan(tuple(char*, int) == Stringpair) */ 94 }; 95 96 struct Mousereadmesg 97 { 98 Channel *cm; /* chan(Mouse) */ 99 }; 100 101 struct Stringpair /* rune and nrune or byte and nbyte */ 102 { 103 void *s; 104 int ns; 105 }; 106 107 struct Mousestate 108 { 109 Mouse; 110 ulong counter; /* serial no. of mouse event */ 111 }; 112 113 struct Mouseinfo 114 { 115 Mousestate queue[16]; 116 int ri; /* read index into queue */ 117 int wi; /* write index */ 118 ulong counter; /* serial no. of last mouse event we received */ 119 ulong lastcounter; /* serial no. of last mouse event sent to client */ 120 int lastb; /* last button state we received */ 121 uchar qfull; /* filled the queue; no more recording until client comes back */ 122 }; 123 124 struct Window 125 { 126 Ref; 127 QLock; 128 Frame; 129 Image *i; 130 Mousectl mc; 131 Mouseinfo mouse; 132 Channel *ck; /* chan(Rune[10]) */ 133 Channel *cctl; /* chan(Wctlmesg)[20] */ 134 Channel *conswrite; /* chan(Conswritemesg) */ 135 Channel *consread; /* chan(Consreadmesg) */ 136 Channel *mouseread; /* chan(Mousereadmesg) */ 137 Channel *wctlread; /* chan(Consreadmesg) */ 138 uint nr; /* number of runes in window */ 139 uint maxr; /* number of runes allocated in r */ 140 Rune *r; 141 uint nraw; 142 Rune *raw; 143 uint org; 144 uint q0; 145 uint q1; 146 uint qh; 147 int id; 148 char name[32]; 149 uint namecount; 150 Rectangle scrollr; 151 /* 152 * Rio once used originwindow, so screenr could be different from i->r. 153 * Now they're always the same but the code doesn't assume so. 154 */ 155 Rectangle screenr; /* screen coordinates of window */ 156 int resized; 157 int wctlready; 158 Rectangle lastsr; 159 int topped; 160 int notefd; 161 uchar scrolling; 162 Cursor cursor; 163 Cursor *cursorp; 164 uchar holding; 165 uchar rawing; 166 uchar ctlopen; 167 uchar wctlopen; 168 uchar deleted; 169 uchar mouseopen; 170 char *label; 171 int pid; 172 char *dir; 173 }; 174 175 int winborder(Window*, Point); 176 void winctl(void*); 177 void winshell(void*); 178 Window* wlookid(int); 179 Window* wmk(Image*, Mousectl*, Channel*, Channel*, int); 180 Window* wpointto(Point); 181 Window* wtop(Point); 182 void wtopme(Window*); 183 void wbottomme(Window*); 184 char* wcontents(Window*, int*); 185 int wbswidth(Window*, Rune); 186 int wclickmatch(Window*, int, int, int, uint*); 187 int wclose(Window*); 188 int wctlmesg(Window*, int, Rectangle, Image*); 189 int wctlmesg(Window*, int, Rectangle, Image*); 190 uint wbacknl(Window*, uint, uint); 191 uint winsert(Window*, Rune*, int, uint); 192 void waddraw(Window*, Rune*, int); 193 void wborder(Window*, int); 194 void wclosewin(Window*); 195 void wcurrent(Window*); 196 void wcut(Window*); 197 void wdelete(Window*, uint, uint); 198 void wdoubleclick(Window*, uint*, uint*); 199 void wfill(Window*); 200 void wframescroll(Window*, int); 201 void wkeyctl(Window*, Rune); 202 void wmousectl(Window*); 203 void wmovemouse(Window*, Point); 204 void wpaste(Window*); 205 void wplumb(Window*); 206 void wrefresh(Window*, Rectangle); 207 void wrepaint(Window*); 208 void wresize(Window*, Image*, int); 209 void wscrdraw(Window*); 210 void wscroll(Window*, int); 211 void wselect(Window*); 212 void wsendctlmesg(Window*, int, Rectangle, Image*); 213 void wsetcursor(Window*, int); 214 void wsetname(Window*); 215 void wsetorigin(Window*, uint, int); 216 void wsetpid(Window*, int, int); 217 void wsetselect(Window*, uint, uint); 218 void wshow(Window*, uint); 219 void wsnarf(Window*); 220 void wscrsleep(Window*, uint); 221 void wsetcols(Window*); 222 223 struct Dirtab 224 { 225 char *name; 226 uchar type; 227 uint qid; 228 uint perm; 229 }; 230 231 struct Fid 232 { 233 int fid; 234 int busy; 235 int open; 236 int mode; 237 Qid qid; 238 Window *w; 239 Dirtab *dir; 240 Fid *next; 241 int nrpart; 242 uchar rpart[UTFmax]; 243 }; 244 245 struct Xfid 246 { 247 Ref; 248 Xfid *next; 249 Xfid *free; 250 Fcall; 251 Channel *c; /* chan(void(*)(Xfid*)) */ 252 Fid *f; 253 uchar *buf; 254 Filsys *fs; 255 QLock active; 256 int flushing; /* another Xfid is trying to flush us */ 257 int flushtag; /* our tag, so flush can find us */ 258 Channel *flushc; /* channel(int) to notify us we're being flushed */ 259 }; 260 261 Channel* xfidinit(void); 262 void xfidctl(void*); 263 void xfidflush(Xfid*); 264 void xfidattach(Xfid*); 265 void xfidopen(Xfid*); 266 void xfidclose(Xfid*); 267 void xfidread(Xfid*); 268 void xfidwrite(Xfid*); 269 270 enum 271 { 272 Nhash = 16, 273 }; 274 275 struct Filsys 276 { 277 int cfd; 278 int sfd; 279 int pid; 280 char *user; 281 Channel *cxfidalloc; /* chan(Xfid*) */ 282 Fid *fids[Nhash]; 283 }; 284 285 Filsys* filsysinit(Channel*); 286 int filsysmount(Filsys*, int); 287 Xfid* filsysrespond(Filsys*, Xfid*, Fcall*, char*); 288 void filsyscancel(Xfid*); 289 290 void wctlproc(void*); 291 void wctlthread(void*); 292 293 void deletetimeoutproc(void*); 294 295 struct Timer 296 { 297 int dt; 298 int cancel; 299 Channel *c; /* chan(int) */ 300 Timer *next; 301 }; 302 303 Font *font; 304 Mousectl *mousectl; 305 Mouse *mouse; 306 Keyboardctl *keyboardctl; 307 Display *display; 308 Image *view; 309 Screen *wscreen; 310 Cursor boxcursor; 311 Cursor crosscursor; 312 Cursor sightcursor; 313 Cursor whitearrow; 314 Cursor query; 315 Cursor *corners[9]; 316 Image *background; 317 Image *lightgrey; 318 Image *red; 319 Window **window; 320 Window *wkeyboard; /* window of simulated keyboard */ 321 int nwindow; 322 int snarffd; 323 Window *input; 324 QLock all; /* BUG */ 325 Filsys *filsys; 326 Window *hidden[100]; 327 int nhidden; 328 int nsnarf; 329 Rune* snarf; 330 int scrolling; 331 int maxtab; 332 Channel* winclosechan; 333 Channel* deletechan; 334 char *startdir; 335 int sweeping; 336 int wctlfd; 337 char srvpipe[]; 338 char srvwctl[]; 339 int errorshouldabort; 340 int menuing; /* menu action is pending; waiting for window to be indicated */ 341 int snarfversion; /* updated each time it is written */ 342 int messagesize; /* negotiated in 9P version setup */ 343