]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/rio/dat.h
fix ref822 again: remove uniqarray(), fix case with many entries in 'n'.
[plan9front.git] / sys / src / cmd / rio / dat.h
1 enum
2 {
3         Qdir,                   /* /dev for this window */
4         Qcons,
5         Qconsctl,
6         Qcursor,
7         Qwdir,
8         Qwinid,
9         Qwinname,
10         Qlabel,
11         Qkbd,
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 #define STACK   8192
26 #define MAXSNARF        100*1024
27
28 typedef struct  Consreadmesg Consreadmesg;
29 typedef struct  Conswritemesg Conswritemesg;
30 typedef struct  Kbdreadmesg Kbdreadmesg;
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
44 enum
45 {
46         Selborder               = 4,            /* border of selected window */
47         Unselborder     = 1,            /* border of unselected window */
48         Scrollwid               = 12,           /* width of scroll bar */
49         Scrollgap               = 4,            /* gap right of scroll bar */
50         BIG                     = 3,            /* factor by which window dimension can exceed screen */
51         TRUE            = 1,
52         FALSE           = 0,
53 };
54
55 #define QID(w,q)        ((w<<8)|(q))
56 #define WIN(q)  ((((ulong)(q).path)>>8) & 0xFFFFFF)
57 #define FILE(q) (((ulong)(q).path) & 0xFF)
58
59 enum    /* control messages */
60 {
61         Wakeup,
62         Reshaped,
63         Topped,
64         Repaint,
65         Refresh,
66         Movemouse,
67         Rawon,
68         Rawoff,
69         Holdon,
70         Holdoff,
71         Truncate,
72         Deleted,
73         Exited,
74 };
75
76 struct Wctlmesg
77 {
78         int             type;
79         Rectangle       r;
80         void            *p;
81 };
82
83 struct Conswritemesg
84 {
85         Channel *cw;            /* chan(Stringpair) */
86 };
87
88 struct Consreadmesg
89 {
90         Channel *c1;            /* chan(tuple(char*, int) == Stringpair) */
91         Channel *c2;            /* chan(tuple(char*, int) == Stringpair) */
92 };
93
94 struct Mousereadmesg
95 {
96         Channel *cm;            /* chan(Mouse) */
97 };
98
99 struct Stringpair       /* rune and nrune or byte and nbyte */
100 {
101         void            *s;
102         int             ns;
103 };
104
105 struct Mousestate
106 {
107         Mouse;
108         ulong   counter;        /* serial no. of mouse event */
109 };
110
111 struct Mouseinfo
112 {
113         Mousestate      queue[16];
114         int     ri;     /* read index into queue */
115         int     wi;     /* write index */
116         ulong   counter;        /* serial no. of last mouse event we received */
117         ulong   lastcounter;    /* serial no. of last mouse event sent to client */
118         int     lastb;  /* last button state we received */
119         uchar   qfull;  /* filled the queue; no more recording until client comes back */       
120 };      
121
122 struct Window
123 {
124         Ref;
125         QLock;
126         Frame;
127         Image           *i;             /* window image, nil when deleted */
128         Mousectl        mc;
129         Mouseinfo       mouse;
130         Channel         *ck;            /* chan(char*) */
131         Channel         *cctl;          /* chan(Wctlmesg)[4] */
132         Channel         *conswrite;     /* chan(Conswritemesg) */
133         Channel         *consread;      /* chan(Consreadmesg) */
134         Channel         *mouseread;     /* chan(Mousereadmesg) */
135         Channel         *wctlread;      /* chan(Consreadmesg) */
136         Channel         *kbdread;       /* chan(Consreadmesg) */
137         Channel         *complete;      /* chan(Completion*) */
138         Channel         *gone;          /* chan(char*) */
139         uint                    nr;                     /* number of runes in window */
140         uint                    maxr;           /* number of runes allocated in r */
141         Rune                    *r;
142         uint                    nraw;
143         Rune                    *raw;
144         uint                    org;
145         uint                    q0;
146         uint                    q1;
147         uint                    qh;
148         int                     id;
149         char                    name[32];
150         uint                    namecount;
151         Rectangle               scrollr;
152         /*
153          * Rio once used originwindow, so screenr could be different from i->r.
154          * Now they're always the same but the code doesn't assume so.
155         */
156         Rectangle               screenr;        /* screen coordinates of window */
157         int                     resized;
158         int                     wctlready;
159         Rectangle               lastsr;
160         int                     topped;
161         int                     notefd;
162         uchar           scrolling;
163         Cursor          cursor;
164         Cursor          *cursorp;
165         uchar           holding;
166         uchar           rawing;
167         uchar           ctlopen;
168         uchar           wctlopen;
169         uchar           deleted;
170         uchar           mouseopen;
171         uchar           kbdopen;
172         char                    *label;
173         char                    *dir;
174 };
175
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, void*);
189 uint            wbacknl(Window*, uint, uint);
190 uint            winsert(Window*, Rune*, int, uint);
191 void            waddraw(Window*, Rune*, int);
192 void            wborder(Window*, int);
193 void            wclunk(Window*);
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            wlook(Window*);
207 void            wrefresh(Window*);
208 void            wrepaint(Window*);
209 void            wresize(Window*, Image*);
210 void            wscrdraw(Window*);
211 void            wscroll(Window*, int);
212 void            wselect(Window*);
213 void            wsendctlmesg(Window*, int, Rectangle, void*);
214 void            wsetcursor(Window*, int);
215 void            wsetname(Window*);
216 void            wsetorigin(Window*, uint, int);
217 void            wsetpid(Window*, int, int);
218 void            wsetselect(Window*, uint, uint);
219 void            wshow(Window*, uint);
220 void            wsnarf(Window*);
221 void            wscrsleep(Window*, uint);
222 void            wsetcols(Window*, int);
223
224 struct Dirtab
225 {
226         char            *name;
227         uchar   type;
228         uint            qid;
229         uint            perm;
230 };
231
232 struct Fid
233 {
234         int             fid;
235         int             busy;
236         int             open;
237         int             mode;
238         Qid             qid;
239         Window  *w;
240         Dirtab  *dir;
241         Fid             *next;
242         int             nrpart;
243         uchar   rpart[UTFmax];
244 };
245
246 struct Xfid
247 {
248                 Ref;
249                 Xfid            *next;
250                 Xfid            *free;
251                 Fcall;
252                 Channel *c;     /* chan(void(*)(Xfid*)) */
253                 Fid             *f;
254                 uchar   *buf;
255                 Filsys  *fs;
256                 int             flushtag;       /* our tag, so flush can find us */
257                 Channel *flushc;        /* channel(int) to notify us we're being flushed */
258 };
259
260 Channel*        xfidinit(void);
261 void            xfidctl(void*);
262 void            xfidflush(Xfid*);
263 void            xfidattach(Xfid*);
264 void            xfidopen(Xfid*);
265 void            xfidclose(Xfid*);
266 void            xfidread(Xfid*);
267 void            xfidwrite(Xfid*);
268
269 enum
270 {
271         Nhash   = 16,
272 };
273
274 struct Filsys
275 {
276                 int             cfd;
277                 int             sfd;
278                 int             pid;
279                 char            *user;
280                 Channel *cxfidalloc;    /* chan(Xfid*) */
281                 Channel *csyncflush;    /* chan(int) */
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 Display *display;
307 Image   *view;
308 Screen  *wscreen;
309 Cursor  boxcursor;
310 Cursor  crosscursor;
311 Cursor  sightcursor;
312 Cursor  whitearrow;
313 Cursor  query;
314 Cursor  *corners[9];
315
316 Image   *background;
317 Image   *cols[NCOL];
318 Image   *titlecol;
319 Image   *lighttitlecol;
320 Image   *dholdcol;
321 Image   *holdcol;
322 Image   *lightholdcol;
323 Image   *paleholdcol;
324 Image   *paletextcol;
325 Image   *sizecol;
326 int     reverse;        /* there are no pastel paints in the dungeons and dragons world -- rob pike */
327
328 Window  **window;
329 Window  *wkeyboard;     /* window of simulated keyboard */
330 int             nwindow;
331 int             snarffd;
332 int             gotscreen;
333 int             servekbd;
334 Window  *input;
335 QLock   all;                    /* BUG */
336 Filsys  *filsys;
337 Window  *hidden[100];
338 int             nhidden;
339 int             nsnarf;
340 Rune*   snarf;
341 int             scrolling;
342 int             maxtab;
343 Channel*        winclosechan;
344 char            *startdir;
345 int             sweeping;
346 int             wctlfd;
347 char            srvpipe[];
348 char            srvwctl[];
349 int             errorshouldabort;
350 int             menuing;                /* menu action is pending; waiting for window to be indicated */
351 int             snarfversion;   /* updated each time it is written */
352 int             messagesize;            /* negotiated in 9P version setup */
353 int             shiftdown;
354 int             debug;