]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/rio/dat.h
rio: /dev/kbd cleanup
[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         Deleted,
72         Exited,
73 };
74
75 struct Wctlmesg
76 {
77         int             type;
78         Rectangle       r;
79         void            *p;
80 };
81
82 struct Conswritemesg
83 {
84         Channel *cw;            /* chan(Stringpair) */
85 };
86
87 struct Consreadmesg
88 {
89         Channel *c1;            /* chan(tuple(char*, int) == Stringpair) */
90         Channel *c2;            /* chan(tuple(char*, int) == Stringpair) */
91 };
92
93 struct Mousereadmesg
94 {
95         Channel *cm;            /* chan(Mouse) */
96 };
97
98 struct Stringpair       /* rune and nrune or byte and nbyte */
99 {
100         void            *s;
101         int             ns;
102 };
103
104 struct Mousestate
105 {
106         Mouse;
107         ulong   counter;        /* serial no. of mouse event */
108 };
109
110 struct Mouseinfo
111 {
112         Mousestate      queue[16];
113         int     ri;     /* read index into queue */
114         int     wi;     /* write index */
115         ulong   counter;        /* serial no. of last mouse event we received */
116         ulong   lastcounter;    /* serial no. of last mouse event sent to client */
117         int     lastb;  /* last button state we received */
118         uchar   qfull;  /* filled the queue; no more recording until client comes back */       
119 };      
120
121 struct Window
122 {
123         Ref;
124         QLock;
125         Frame;
126         Image           *i;             /* window image, nil when deleted */
127         Mousectl        mc;
128         Mouseinfo       mouse;
129         Channel         *ck;            /* chan(char*) */
130         Channel         *cctl;          /* chan(Wctlmesg)[4] */
131         Channel         *conswrite;     /* chan(Conswritemesg) */
132         Channel         *consread;      /* chan(Consreadmesg) */
133         Channel         *mouseread;     /* chan(Mousereadmesg) */
134         Channel         *wctlread;      /* chan(Consreadmesg) */
135         Channel         *kbdread;       /* chan(Consreadmesg) */
136         Channel         *complete;      /* chan(Completion*) */
137         Channel         *gone;          /* chan(char*) */
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         uchar           kbdopen;
171         char                    *label;
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, 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 Channel*        deletechan;
345 char            *startdir;
346 int             sweeping;
347 int             wctlfd;
348 char            srvpipe[];
349 char            srvwctl[];
350 int             errorshouldabort;
351 int             menuing;                /* menu action is pending; waiting for window to be indicated */
352 int             snarfversion;   /* updated each time it is written */
353 int             messagesize;            /* negotiated in 9P version setup */
354 int             shiftdown;
355 int             debug;