Blame


1 88ed92aa 2020-01-13 rsc
2 88ed92aa 2020-01-13 rsc #define NHASH (1<<5)
3 88ed92aa 2020-01-13 rsc #define HASHMASK (NHASH-1)
4 88ed92aa 2020-01-13 rsc
5 88ed92aa 2020-01-13 rsc typedef struct Kbdbuf Kbdbuf;
6 88ed92aa 2020-01-13 rsc typedef struct Mousebuf Mousebuf;
7 88ed92aa 2020-01-13 rsc typedef struct Tagbuf Tagbuf;
8 88ed92aa 2020-01-13 rsc
9 88ed92aa 2020-01-13 rsc typedef struct Client Client;
10 94d381ec 2020-05-18 rsc typedef struct ClientImpl ClientImpl;
11 88ed92aa 2020-01-13 rsc typedef struct DImage DImage;
12 88ed92aa 2020-01-13 rsc typedef struct DScreen DScreen;
13 88ed92aa 2020-01-13 rsc typedef struct CScreen CScreen;
14 88ed92aa 2020-01-13 rsc typedef struct FChar FChar;
15 88ed92aa 2020-01-13 rsc typedef struct Refresh Refresh;
16 88ed92aa 2020-01-13 rsc typedef struct Refx Refx;
17 88ed92aa 2020-01-13 rsc typedef struct DName DName;
18 88ed92aa 2020-01-13 rsc
19 88ed92aa 2020-01-13 rsc struct Kbdbuf
20 88ed92aa 2020-01-13 rsc {
21 88ed92aa 2020-01-13 rsc Rune r[256];
22 88ed92aa 2020-01-13 rsc int ri;
23 88ed92aa 2020-01-13 rsc int wi;
24 88ed92aa 2020-01-13 rsc int stall;
25 88ed92aa 2020-01-13 rsc int alting;
26 b1a086de 2020-01-13 rsc Rune k[10];
27 b1a086de 2020-01-13 rsc int nk;
28 88ed92aa 2020-01-13 rsc };
29 88ed92aa 2020-01-13 rsc
30 88ed92aa 2020-01-13 rsc struct Mousebuf
31 88ed92aa 2020-01-13 rsc {
32 88ed92aa 2020-01-13 rsc Mouse m[256];
33 88ed92aa 2020-01-13 rsc Mouse last;
34 88ed92aa 2020-01-13 rsc int ri;
35 88ed92aa 2020-01-13 rsc int wi;
36 88ed92aa 2020-01-13 rsc int stall;
37 88ed92aa 2020-01-13 rsc int resized;
38 88ed92aa 2020-01-13 rsc };
39 88ed92aa 2020-01-13 rsc
40 88ed92aa 2020-01-13 rsc struct Tagbuf
41 88ed92aa 2020-01-13 rsc {
42 88ed92aa 2020-01-13 rsc int t[256];
43 88ed92aa 2020-01-13 rsc int ri;
44 88ed92aa 2020-01-13 rsc int wi;
45 88ed92aa 2020-01-13 rsc };
46 88ed92aa 2020-01-13 rsc
47 94d381ec 2020-05-18 rsc struct ClientImpl
48 94d381ec 2020-05-18 rsc {
49 94d381ec 2020-05-18 rsc void (*rpc_resizeimg)(Client*);
50 94d381ec 2020-05-18 rsc void (*rpc_resizewindow)(Client*, Rectangle);
51 94d381ec 2020-05-18 rsc void (*rpc_setcursor)(Client*, Cursor*, Cursor2*);
52 94d381ec 2020-05-18 rsc void (*rpc_setlabel)(Client*, char*);
53 94d381ec 2020-05-18 rsc void (*rpc_setmouse)(Client*, Point);
54 94d381ec 2020-05-18 rsc void (*rpc_topwin)(Client*);
55 94d381ec 2020-05-18 rsc void (*rpc_bouncemouse)(Client*, Mouse);
56 94d381ec 2020-05-18 rsc void (*rpc_flush)(Client*, Rectangle);
57 94d381ec 2020-05-18 rsc };
58 94d381ec 2020-05-18 rsc
59 587933c1 2020-05-18 rsc extern QLock drawlk;
60 587933c1 2020-05-18 rsc
61 88ed92aa 2020-01-13 rsc struct Client
62 88ed92aa 2020-01-13 rsc {
63 41547af3 2020-01-13 rsc int rfd;
64 41547af3 2020-01-13 rsc
65 41547af3 2020-01-13 rsc // wfdlk protects writes to wfd, which can be issued from either
66 41547af3 2020-01-13 rsc // the RPC thread or the graphics thread.
67 41547af3 2020-01-13 rsc QLock wfdlk;
68 41547af3 2020-01-13 rsc int wfd;
69 41547af3 2020-01-13 rsc uchar* mbuf;
70 41547af3 2020-01-13 rsc int nmbuf;
71 41547af3 2020-01-13 rsc
72 892b3c46 2020-01-13 rsc char* wsysid;
73 892b3c46 2020-01-13 rsc
74 587933c1 2020-05-18 rsc // drawlk protects the draw data structures for all clients.
75 41547af3 2020-01-13 rsc // It can be acquired by an RPC thread or a graphics thread
76 41547af3 2020-01-13 rsc // but must not be held on one thread while waiting for the other.
77 88ed92aa 2020-01-13 rsc /*Ref r;*/
78 88ed92aa 2020-01-13 rsc DImage* dimage[NHASH];
79 88ed92aa 2020-01-13 rsc CScreen* cscreen;
80 88ed92aa 2020-01-13 rsc Refresh* refresh;
81 88ed92aa 2020-01-13 rsc Rendez refrend;
82 88ed92aa 2020-01-13 rsc uchar* readdata;
83 88ed92aa 2020-01-13 rsc int nreaddata;
84 88ed92aa 2020-01-13 rsc int busy;
85 88ed92aa 2020-01-13 rsc int clientid;
86 88ed92aa 2020-01-13 rsc int slot;
87 88ed92aa 2020-01-13 rsc int refreshme;
88 88ed92aa 2020-01-13 rsc int infoid;
89 88ed92aa 2020-01-13 rsc int op;
90 88ed92aa 2020-01-13 rsc int displaydpi;
91 88ed92aa 2020-01-13 rsc int forcedpi;
92 88ed92aa 2020-01-13 rsc int waste;
93 88ed92aa 2020-01-13 rsc Rectangle flushrect;
94 88ed92aa 2020-01-13 rsc Memimage *screenimage;
95 88ed92aa 2020-01-13 rsc DScreen* dscreen;
96 88ed92aa 2020-01-13 rsc int nname;
97 88ed92aa 2020-01-13 rsc DName* name;
98 88ed92aa 2020-01-13 rsc int namevers;
99 94d381ec 2020-05-18 rsc ClientImpl* impl;
100 88ed92aa 2020-01-13 rsc
101 41547af3 2020-01-13 rsc // Only accessed/modified by the graphics thread.
102 b1a086de 2020-01-13 rsc const void* view;
103 50923426 2020-01-13 rsc
104 41547af3 2020-01-13 rsc // eventlk protects the keyboard and mouse events.
105 41547af3 2020-01-13 rsc QLock eventlk;
106 88ed92aa 2020-01-13 rsc Kbdbuf kbd;
107 88ed92aa 2020-01-13 rsc Mousebuf mouse;
108 88ed92aa 2020-01-13 rsc Tagbuf kbdtags;
109 88ed92aa 2020-01-13 rsc Tagbuf mousetags;
110 88ed92aa 2020-01-13 rsc Rectangle mouserect;
111 88ed92aa 2020-01-13 rsc };
112 88ed92aa 2020-01-13 rsc
113 88ed92aa 2020-01-13 rsc struct Refresh
114 88ed92aa 2020-01-13 rsc {
115 88ed92aa 2020-01-13 rsc DImage* dimage;
116 88ed92aa 2020-01-13 rsc Rectangle r;
117 88ed92aa 2020-01-13 rsc Refresh* next;
118 88ed92aa 2020-01-13 rsc };
119 88ed92aa 2020-01-13 rsc
120 88ed92aa 2020-01-13 rsc struct Refx
121 88ed92aa 2020-01-13 rsc {
122 88ed92aa 2020-01-13 rsc Client* client;
123 88ed92aa 2020-01-13 rsc DImage* dimage;
124 88ed92aa 2020-01-13 rsc };
125 88ed92aa 2020-01-13 rsc
126 88ed92aa 2020-01-13 rsc struct DName
127 88ed92aa 2020-01-13 rsc {
128 88ed92aa 2020-01-13 rsc char *name;
129 88ed92aa 2020-01-13 rsc Client *client;
130 88ed92aa 2020-01-13 rsc DImage* dimage;
131 88ed92aa 2020-01-13 rsc int vers;
132 88ed92aa 2020-01-13 rsc };
133 88ed92aa 2020-01-13 rsc
134 88ed92aa 2020-01-13 rsc struct FChar
135 88ed92aa 2020-01-13 rsc {
136 88ed92aa 2020-01-13 rsc int minx; /* left edge of bits */
137 88ed92aa 2020-01-13 rsc int maxx; /* right edge of bits */
138 88ed92aa 2020-01-13 rsc uchar miny; /* first non-zero scan-line */
139 88ed92aa 2020-01-13 rsc uchar maxy; /* last non-zero scan-line + 1 */
140 88ed92aa 2020-01-13 rsc schar left; /* offset of baseline */
141 88ed92aa 2020-01-13 rsc uchar width; /* width of baseline */
142 88ed92aa 2020-01-13 rsc };
143 88ed92aa 2020-01-13 rsc
144 88ed92aa 2020-01-13 rsc /*
145 88ed92aa 2020-01-13 rsc * Reference counts in DImages:
146 88ed92aa 2020-01-13 rsc * one per open by original client
147 88ed92aa 2020-01-13 rsc * one per screen image or fill
148 88ed92aa 2020-01-13 rsc * one per image derived from this one by name
149 88ed92aa 2020-01-13 rsc */
150 88ed92aa 2020-01-13 rsc struct DImage
151 88ed92aa 2020-01-13 rsc {
152 88ed92aa 2020-01-13 rsc int id;
153 88ed92aa 2020-01-13 rsc int ref;
154 88ed92aa 2020-01-13 rsc char *name;
155 88ed92aa 2020-01-13 rsc int vers;
156 88ed92aa 2020-01-13 rsc Memimage* image;
157 88ed92aa 2020-01-13 rsc int ascent;
158 88ed92aa 2020-01-13 rsc int nfchar;
159 88ed92aa 2020-01-13 rsc FChar* fchar;
160 88ed92aa 2020-01-13 rsc DScreen* dscreen; /* 0 if not a window */
161 88ed92aa 2020-01-13 rsc DImage* fromname; /* image this one is derived from, by name */
162 88ed92aa 2020-01-13 rsc DImage* next;
163 88ed92aa 2020-01-13 rsc };
164 88ed92aa 2020-01-13 rsc
165 88ed92aa 2020-01-13 rsc struct CScreen
166 88ed92aa 2020-01-13 rsc {
167 88ed92aa 2020-01-13 rsc DScreen* dscreen;
168 88ed92aa 2020-01-13 rsc CScreen* next;
169 88ed92aa 2020-01-13 rsc };
170 88ed92aa 2020-01-13 rsc
171 88ed92aa 2020-01-13 rsc struct DScreen
172 88ed92aa 2020-01-13 rsc {
173 88ed92aa 2020-01-13 rsc int id;
174 88ed92aa 2020-01-13 rsc int public;
175 88ed92aa 2020-01-13 rsc int ref;
176 88ed92aa 2020-01-13 rsc DImage *dimage;
177 88ed92aa 2020-01-13 rsc DImage *dfill;
178 88ed92aa 2020-01-13 rsc Memscreen* screen;
179 88ed92aa 2020-01-13 rsc Client* owner;
180 88ed92aa 2020-01-13 rsc DScreen* next;
181 88ed92aa 2020-01-13 rsc };
182 88ed92aa 2020-01-13 rsc
183 41547af3 2020-01-13 rsc // For the most part, the graphics driver-specific code in files
184 41547af3 2020-01-13 rsc // like mac-screen.m runs in the graphics library's main thread,
185 41547af3 2020-01-13 rsc // while the RPC service code in srv.c runs on the RPC service thread.
186 41547af3 2020-01-13 rsc // The exceptions in each file, which are called by the other,
187 41547af3 2020-01-13 rsc // are marked with special prefixes: gfx_* indicates code that
188 41547af3 2020-01-13 rsc // is in srv.c but nonetheless runs on the main graphics thread,
189 41547af3 2020-01-13 rsc // while rpc_* indicates code that is in, say, mac-screen.m but
190 41547af3 2020-01-13 rsc // nonetheless runs on the RPC service thread.
191 41547af3 2020-01-13 rsc //
192 41547af3 2020-01-13 rsc // The gfx_* and rpc_* calls typically synchronize with the other
193 41547af3 2020-01-13 rsc // code in the file by acquiring a lock (or running a callback on the
194 41547af3 2020-01-13 rsc // target thread, which amounts to the same thing).
195 41547af3 2020-01-13 rsc // To avoid deadlock, callers of those routines must not hold any locks.
196 88ed92aa 2020-01-13 rsc
197 41547af3 2020-01-13 rsc // gfx_* routines are called on the graphics thread,
198 41547af3 2020-01-13 rsc // invoked from graphics driver callbacks to do RPC work.
199 41547af3 2020-01-13 rsc // No locks are held on entry.
200 b1a086de 2020-01-13 rsc void gfx_abortcompose(Client*);
201 b1a086de 2020-01-13 rsc void gfx_keystroke(Client*, int);
202 41547af3 2020-01-13 rsc void gfx_main(void);
203 b1a086de 2020-01-13 rsc void gfx_mousetrack(Client*, int, int, int, uint);
204 41547af3 2020-01-13 rsc void gfx_replacescreenimage(Client*, Memimage*);
205 1f799495 2020-01-15 rsc void gfx_mouseresized(Client*);
206 41547af3 2020-01-13 rsc void gfx_started(void);
207 b1a086de 2020-01-13 rsc
208 41547af3 2020-01-13 rsc // rpc_* routines are called on the RPC thread,
209 41547af3 2020-01-13 rsc // invoked by the RPC server code to do graphics work.
210 41547af3 2020-01-13 rsc // No locks are held on entry.
211 41547af3 2020-01-13 rsc Memimage *rpc_attach(Client*, char*, char*);
212 41547af3 2020-01-13 rsc char* rpc_getsnarf(void);
213 41547af3 2020-01-13 rsc void rpc_putsnarf(char*);
214 41547af3 2020-01-13 rsc void rpc_shutdown(void);
215 41547af3 2020-01-13 rsc void rpc_main(void);
216 b1a086de 2020-01-13 rsc
217 50923426 2020-01-13 rsc // rpc_gfxdrawlock and rpc_gfxdrawunlock
218 50923426 2020-01-13 rsc // are called around drawing operations to lock and unlock
219 50923426 2020-01-13 rsc // access to the graphics display, for systems where the
220 50923426 2020-01-13 rsc // individual memdraw operations use the graphics display (X11, not macOS).
221 50923426 2020-01-13 rsc void rpc_gfxdrawlock(void);
222 50923426 2020-01-13 rsc void rpc_gfxdrawunlock(void);
223 50923426 2020-01-13 rsc
224 41547af3 2020-01-13 rsc // draw* routines are called on the RPC thread,
225 41547af3 2020-01-13 rsc // invoked by the RPC server to do pixel pushing.
226 50923426 2020-01-13 rsc // No locks are held on entry.
227 41547af3 2020-01-13 rsc int draw_dataread(Client*, void*, int);
228 41547af3 2020-01-13 rsc int draw_datawrite(Client*, void*, int);
229 41547af3 2020-01-13 rsc void draw_initdisplaymemimage(Client*, Memimage*);
230 41547af3 2020-01-13 rsc
231 41547af3 2020-01-13 rsc // utility routines
232 41547af3 2020-01-13 rsc int latin1(Rune*, int);
233 41547af3 2020-01-13 rsc int mouseswap(int);
234 41547af3 2020-01-13 rsc int parsewinsize(char*, Rectangle*, int*);
235 41547af3 2020-01-13 rsc
236 892b3c46 2020-01-13 rsc extern Client *client0; // set in single-client mode