dat.h 6.8 KB

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