1 | /* |
---|
2 | * neercs console-based window manager |
---|
3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
---|
4 | * 2008 Jean-Yves Lamoureux <jylam@lnxscene.org> |
---|
5 | * All Rights Reserved |
---|
6 | * |
---|
7 | * $Id: neercs.h 2624 2008-08-01 13:44:49Z pterjan $ |
---|
8 | * |
---|
9 | * This program is free software. It comes without any warranty, to |
---|
10 | * the extent permitted by applicable law. You can redistribute it |
---|
11 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
12 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
13 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
14 | */ |
---|
15 | |
---|
16 | #include <stdint.h> |
---|
17 | |
---|
18 | #include <caca.h> |
---|
19 | |
---|
20 | enum wm_types |
---|
21 | { |
---|
22 | WM_FULL, |
---|
23 | WM_CARD, |
---|
24 | WM_HSPLIT, |
---|
25 | WM_VSPLIT, |
---|
26 | |
---|
27 | WM_MAX, |
---|
28 | }; |
---|
29 | |
---|
30 | struct option |
---|
31 | { |
---|
32 | char *key; |
---|
33 | char *value; |
---|
34 | |
---|
35 | struct option *next; |
---|
36 | }; |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | /* ISO-2022 Conversion State */ |
---|
41 | struct iso2022_conv_state |
---|
42 | { |
---|
43 | /* cs = coding system/coding method: */ |
---|
44 | /* (with standard return) */ |
---|
45 | /* '@' = ISO-2022, */ |
---|
46 | /* 'G' = UTF-8 without implementation level, */ |
---|
47 | /* '8' = UTF-8 (Linux console and imitators), */ |
---|
48 | /* and many others that are rarely used; */ |
---|
49 | /* (without standard return) */ |
---|
50 | /* '/G' = UTF-8 Level 1, */ |
---|
51 | /* '/H' = UTF-8 Level 2, */ |
---|
52 | /* '/I' = UTF-8 Level 3, */ |
---|
53 | /* and many others that are rarely used */ |
---|
54 | uint32_t cs; |
---|
55 | /* ctrl8bit = allow 8-bit controls */ |
---|
56 | uint8_t ctrl8bit; |
---|
57 | /* cn[0] = C0 control charset (0x00 ... 0x1f): |
---|
58 | * '@' = ISO 646, |
---|
59 | * '~' = empty, |
---|
60 | * and many others that are rarely used */ |
---|
61 | /* cn[1] = C1 control charset (0x80 ... 0x9f): |
---|
62 | * 'C' = ISO 6429-1983, |
---|
63 | * '~' = empty, |
---|
64 | * and many others that are rarely used */ |
---|
65 | uint32_t cn[2]; |
---|
66 | /* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e, |
---|
67 | * 94x94-char. 0x21/0x21 ... 0x7e/0x7e), |
---|
68 | * and |
---|
69 | * glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe, |
---|
70 | * 96-char. 0xa0 ... 0xff, |
---|
71 | * 94x94-char. 0xa1/0xa1 ... 0xfe/0xfe, |
---|
72 | * 96x96-char. 0xa0/0xa0 ... 0xff/0xff): |
---|
73 | * 0 = G0, 1 = G1, 2 = G2, 3 = G3 */ |
---|
74 | uint8_t glr[2]; |
---|
75 | /* gn[i] = G0/G1/G2/G3 graphic charset state: |
---|
76 | * (94-char. sets) |
---|
77 | * '0' = DEC ACS (VT100 and imitators), |
---|
78 | * 'B' = US-ASCII, |
---|
79 | * and many others that are rarely used for e.g. various national ASCII variations; |
---|
80 | * (96-char. sets) |
---|
81 | * '.A' = ISO 8859-1 "Latin 1" GR, |
---|
82 | * '.~' = empty 96-char. set, |
---|
83 | * and many others that are rarely used for e.g. ISO 8859-n GR; |
---|
84 | * (double-byte 94x94-charsets) |
---|
85 | * '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978), |
---|
86 | * '$A' = Chinese Character Set (GB 2312), |
---|
87 | * '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983), |
---|
88 | * '$C' = Korean Graphic Character Set (KSC 5601:1987), |
---|
89 | * '$D' = Supplementary Japanese Graphic Character Set (JIS X0212), |
---|
90 | * '$E' = CCITT Chinese Set (GB 2312 + GB 8565), |
---|
91 | * '$G' = CNS 11643 plane 1, |
---|
92 | * '$H' = CNS 11643 plane 2, |
---|
93 | * '$I' = CNS 11643 plane 3, |
---|
94 | * '$J' = CNS 11643 plane 4, |
---|
95 | * '$K' = CNS 11643 plane 5, |
---|
96 | * '$L' = CNS 11643 plane 6, |
---|
97 | * '$M' = CNS 11643 plane 7, |
---|
98 | * '$O' = JIS X 0213 plane 1, |
---|
99 | * '$P' = JIS X 0213 plane 2, |
---|
100 | * '$Q' = JIS X 0213-2004 Plane 1, |
---|
101 | * and many others that are rarely used for e.g. traditional |
---|
102 | * ideographic Vietnamese and BlissSymbolics; |
---|
103 | * (double-byte 96x96-charsets) |
---|
104 | * none standardized or in use on terminals AFAIK (Mule does use |
---|
105 | * some internally) |
---|
106 | */ |
---|
107 | uint32_t gn[4]; |
---|
108 | /* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */ |
---|
109 | uint8_t ss; |
---|
110 | }; |
---|
111 | |
---|
112 | struct screen |
---|
113 | { |
---|
114 | /* Graphics stuff */ |
---|
115 | int init; |
---|
116 | cucul_canvas_t *cv; |
---|
117 | uint32_t clearattr; |
---|
118 | uint8_t fg, bg; /* ANSI-context fg/bg */ |
---|
119 | uint8_t dfg, dbg; /* Default fg/bg */ |
---|
120 | uint8_t bold, blink, italics, negative, concealed, underline; |
---|
121 | uint8_t faint, strike, proportional; /* unsupported */ |
---|
122 | struct iso2022_conv_state conv_state; /* charset mess */ |
---|
123 | |
---|
124 | /* Other stuff */ |
---|
125 | int visible; /* Draw canvas and border flag */ |
---|
126 | int fd; /* pty fd */ |
---|
127 | unsigned char *buf; /* text buffer */ |
---|
128 | long int total; /* buffer length */ |
---|
129 | char *title; /* tty title */ |
---|
130 | int bell; /* bell occuring */ |
---|
131 | unsigned int scroll, s1, s2; /* FIXME, ANSI scroll properties */ |
---|
132 | int pid; /* running program pid */ |
---|
133 | |
---|
134 | int x, y; /* Canvas position */ |
---|
135 | int w, h; /* Canvas size */ |
---|
136 | |
---|
137 | int orig_x, orig_y; /* Used by recurrents */ |
---|
138 | int orig_w, orig_h; /* Used by recurrents */ |
---|
139 | }; |
---|
140 | |
---|
141 | enum socket_type |
---|
142 | { |
---|
143 | SOCK_SERVER=0, |
---|
144 | SOCK_CLIENT=1 |
---|
145 | }; |
---|
146 | |
---|
147 | struct screen_list |
---|
148 | { |
---|
149 | int wm_type; /* Window manager type */ |
---|
150 | int in_bell; /* Bell occuring in a window */ |
---|
151 | int dont_update_coords; /* Used by recurrents */ |
---|
152 | |
---|
153 | /* Detaching */ |
---|
154 | int attached; /* Are we attached to a terminal */ |
---|
155 | int socket[2]; /* Sockets to write to the server / to the client */ |
---|
156 | char *socket_path[2]; /* Sockets to write to the server / to the client */ |
---|
157 | char *socket_dir; /* Where to create the socket */ |
---|
158 | char *session_name; /* Name of the session */ |
---|
159 | |
---|
160 | /* Lock */ |
---|
161 | int locked; |
---|
162 | int lock_offset; |
---|
163 | long long unsigned int autolock_timeout; |
---|
164 | char lockpass[1024]; |
---|
165 | char lockmsg[1024]; |
---|
166 | |
---|
167 | /* Add-ons*/ |
---|
168 | int mini; /* Thumbnails */ |
---|
169 | int status; /* Status bar */ |
---|
170 | int help; /* help */ |
---|
171 | |
---|
172 | /* ScreenSaver stuff */ |
---|
173 | long long unsigned int screensaver_timeout; /* Screensaver timeout in us */ |
---|
174 | int in_screensaver; |
---|
175 | void *screensaver_data; |
---|
176 | |
---|
177 | int pty, prevpty; /* Current and previous window */ |
---|
178 | int count; /* Window count */ |
---|
179 | int width, height; /* caca window size */ |
---|
180 | struct screen **screen; /* Windows */ |
---|
181 | |
---|
182 | struct option *config; |
---|
183 | char *default_shell; |
---|
184 | struct recurrent_list *recurrent_list; |
---|
185 | |
---|
186 | cucul_canvas_t *cv; |
---|
187 | caca_display_t *dp; |
---|
188 | }; |
---|
189 | |
---|
190 | |
---|
191 | struct recurrent |
---|
192 | { |
---|
193 | int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t); |
---|
194 | void *user; |
---|
195 | long long unsigned int start_time; |
---|
196 | int kill_me; |
---|
197 | }; |
---|
198 | |
---|
199 | struct recurrent_list |
---|
200 | { |
---|
201 | int count; |
---|
202 | struct recurrent **recurrent; |
---|
203 | }; |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | void version(void); |
---|
208 | void usage(int argc, char **argv); |
---|
209 | |
---|
210 | |
---|
211 | struct screen_list *create_screen_list(void); |
---|
212 | |
---|
213 | int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid); |
---|
214 | int create_pty_grab(long pid, unsigned int w, unsigned int h); |
---|
215 | int grab_process(long pid, char *ptyname, int ptyfd); |
---|
216 | |
---|
217 | long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size); |
---|
218 | int set_tty_size(int fd, unsigned int w, unsigned int h); |
---|
219 | int update_terms(struct screen_list* screen_list); |
---|
220 | void refresh_screens(struct screen_list *screen_list); |
---|
221 | int update_screens_contents(struct screen_list* screen_list); |
---|
222 | long long get_us(void); |
---|
223 | |
---|
224 | int detach(struct screen_list* screen_list); |
---|
225 | int request_attach(struct screen_list* screen_list); |
---|
226 | char * build_socket_path(char *socket_dir, char *session_name, enum socket_type socktype); |
---|
227 | int create_socket(struct screen_list* screen_list, enum socket_type socktype); |
---|
228 | char * connect_socket(struct screen_list* screen_list, enum socket_type socktype); |
---|
229 | char ** list_sockets(char *socket_dir, char *session_name); |
---|
230 | int start_server(int *to_grab, char **to_start, struct screen_list *screen_list); |
---|
231 | int send_event(caca_event_t ev, struct screen_list* screen_list); |
---|
232 | |
---|
233 | /* Screens management */ |
---|
234 | struct screen* create_screen(int w, int h, char *command); |
---|
235 | struct screen* create_screen_grab(int w, int h, int pid); |
---|
236 | int destroy_screen(struct screen *s); |
---|
237 | int add_screen(struct screen_list *list, struct screen *s); |
---|
238 | int remove_screen(struct screen_list *list, int n, int please_kill); |
---|
239 | void resize_screen(struct screen *s, int z, int h); |
---|
240 | |
---|
241 | /* Window managers */ |
---|
242 | void update_windows_props(struct screen_list *screen_list); |
---|
243 | void update_windows_props_cards(struct screen_list *screen_list); |
---|
244 | void update_windows_props_hsplit(struct screen_list *screen_list); |
---|
245 | void update_windows_props_full(struct screen_list *screen_list); |
---|
246 | void update_windows_props_vsplit(struct screen_list *screen_list); |
---|
247 | |
---|
248 | /* Effects and addons */ |
---|
249 | void draw_thumbnails(struct screen_list *screen_list); |
---|
250 | void draw_status(struct screen_list *screen_list); |
---|
251 | void draw_help(struct screen_list *screen_list); |
---|
252 | void draw_lock(struct screen_list *screen_list); |
---|
253 | int update_lock(int c, struct screen_list *screen_list); |
---|
254 | int validate_lock(struct screen_list *screen_list, char *user, char *pass); |
---|
255 | |
---|
256 | int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t); |
---|
257 | |
---|
258 | /* Input to ANSI */ |
---|
259 | void *convert_input_ansi(unsigned int *c, int *size); |
---|
260 | int handle_command_input(struct screen_list*screen_list, unsigned int c); |
---|
261 | |
---|
262 | |
---|
263 | /* Screensavers */ |
---|
264 | void screensaver_init(struct screen_list *screen_list); |
---|
265 | void screensaver_kill(struct screen_list *screen_list); |
---|
266 | |
---|
267 | void draw_screensaver(struct screen_list *screen_list); |
---|
268 | void screensaver_flying_toasters(struct screen_list *screen_list); |
---|
269 | |
---|
270 | void screensaver_flying_toasters_init(struct screen_list *screen_list); |
---|
271 | |
---|
272 | void screensaver_flying_toasters_kill(struct screen_list *screen_list); |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | /* Recurrents */ |
---|
277 | int handle_recurrents(struct screen_list* screen_list); |
---|
278 | int add_recurrent(struct recurrent_list *list, |
---|
279 | int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t), |
---|
280 | void *user); |
---|
281 | int remove_recurrent(struct recurrent_list *list, int n); |
---|
282 | |
---|
283 | |
---|
284 | |
---|
285 | /* Configuration file */ |
---|
286 | int read_configuration_file(char *filename, struct screen_list *screen_list); |
---|
287 | int parse_conf_line(char *buf, int size, struct screen_list *screen_list); |
---|
288 | int get_key_value(char *line, struct option *option); |
---|
289 | int fill_config(struct screen_list *screen_list); |
---|
290 | |
---|
291 | #if defined DEBUG |
---|
292 | # include <stdio.h> |
---|
293 | # include <stdarg.h> |
---|
294 | static inline void debug(const char *format, ...) |
---|
295 | { |
---|
296 | va_list args; |
---|
297 | va_start(args, format); |
---|
298 | fprintf(stderr, "** neercs debug ** "); |
---|
299 | vfprintf(stderr, format, args); |
---|
300 | fprintf(stderr, "\n"); |
---|
301 | va_end(args); |
---|
302 | } |
---|
303 | #else |
---|
304 | # define debug(format, ...) do {} while(0) |
---|
305 | #endif |
---|
306 | |
---|