dat.h 7.3 KB

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