dat.h 6.7 KB

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