]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/rio/dat.h
rio: make window focus changes deterministic, cleanup wind.c
[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         uchar           winnameread;
173         char                    *label;
174         char                    *dir;
175 };
176
177 void            winctl(void*);
178 void            winshell(void*);
179 Window* wlookid(int);
180 Window* wmk(Image*, Mousectl*, Channel*, Channel*, int);
181 Window* wpointto(Point);
182 Window* wtop(Point);
183 void            wtopme(Window*);
184 void            wbottomme(Window*);
185 char*   wcontents(Window*, int*);
186 int             wclose(Window*);
187 uint            wbacknl(Window*, uint, uint);
188 void            wcurrent(Window*);
189 void            wuncurrent(Window*);
190 void            wcut(Window*);
191 void            wpaste(Window*);
192 void            wplumb(Window*);
193 void            wlook(Window*);
194 void            wscrdraw(Window*);
195 void            wscroll(Window*, int);
196 void            wsend(Window*);
197 void            wsendctlmesg(Window*, int, Rectangle, void*);
198 void            wsetcursor(Window*, int);
199 void            wsetname(Window*);
200 void            wsetorigin(Window*, uint, int);
201 void            wsetpid(Window*, int, int);
202 void            wshow(Window*, uint);
203 void            wsnarf(Window*);
204 void            wscrsleep(Window*, uint);
205
206 struct Dirtab
207 {
208         char            *name;
209         uchar   type;
210         uint            qid;
211         uint            perm;
212 };
213
214 struct Fid
215 {
216         int             fid;
217         int             busy;
218         int             open;
219         int             mode;
220         Qid             qid;
221         Window  *w;
222         Dirtab  *dir;
223         Fid             *next;
224         int             nrpart;
225         uchar   rpart[UTFmax];
226 };
227
228 struct Xfid
229 {
230                 Ref;
231                 Xfid            *next;
232                 Xfid            *free;
233                 Fcall;
234                 Channel *c;     /* chan(void(*)(Xfid*)) */
235                 Fid             *f;
236                 uchar   *buf;
237                 Filsys  *fs;
238                 int             flushtag;       /* our tag, so flush can find us */
239                 Channel *flushc;        /* channel(int) to notify us we're being flushed */
240 };
241
242 Channel*        xfidinit(void);
243 void            xfidctl(void*);
244 void            xfidflush(Xfid*);
245 void            xfidattach(Xfid*);
246 void            xfidopen(Xfid*);
247 void            xfidclose(Xfid*);
248 void            xfidread(Xfid*);
249 void            xfidwrite(Xfid*);
250
251 enum
252 {
253         Nhash   = 16,
254 };
255
256 struct Filsys
257 {
258                 int             cfd;
259                 int             sfd;
260                 int             pid;
261                 char            *user;
262                 Channel *cxfidalloc;    /* chan(Xfid*) */
263                 Channel *csyncflush;    /* chan(int) */
264                 Fid             *fids[Nhash];
265 };
266
267 Filsys* filsysinit(Channel*);
268 int             filsysmount(Filsys*, int);
269 Xfid*           filsysrespond(Filsys*, Xfid*, Fcall*, char*);
270 void            filsyscancel(Xfid*);
271
272 void            wctlproc(void*);
273 void            wctlthread(void*);
274
275 void            deletetimeoutproc(void*);
276
277 struct Timer
278 {
279         int             dt;
280         int             cancel;
281         Channel *c;     /* chan(int) */
282         Timer   *next;
283 };
284
285 Font            *font;
286 Mousectl        *mousectl;
287 Mouse   *mouse;
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
298 Image   *background;
299 Image   *cols[NCOL];
300 Image   *titlecol;
301 Image   *lighttitlecol;
302 Image   *dholdcol;
303 Image   *holdcol;
304 Image   *lightholdcol;
305 Image   *paleholdcol;
306 Image   *paletextcol;
307 Image   *sizecol;
308 int     reverse;        /* there are no pastel paints in the dungeons and dragons world -- rob pike */
309
310 Window  **window;
311 Window  *wkeyboard;     /* window of simulated keyboard */
312 int             nwindow;
313 int             snarffd;
314 int             gotscreen;
315 int             servekbd;
316 Window  *input;
317 QLock   all;                    /* BUG */
318 Filsys  *filsys;
319 Window  *hidden[100];
320 int             nhidden;
321 int             nsnarf;
322 Rune*   snarf;
323 int             scrolling;
324 int             maxtab;
325 Channel*        winclosechan;
326 char            *startdir;
327 int             sweeping;
328 int             wctlfd;
329 char            srvpipe[];
330 char            srvwctl[];
331 int             errorshouldabort;
332 int             menuing;                /* menu action is pending; waiting for window to be indicated */
333 int             snarfversion;   /* updated each time it is written */
334 int             messagesize;            /* negotiated in 9P version setup */
335 int             shiftdown;
336 int             debug;