Blob


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