source: neercs/trunk/src/neercs.h @ 3944

Last change on this file since 3944 was 3944, checked in by Jean-Yves Lamoureux, 11 years ago
  • Explode server_main()
  • Property svn:keywords set to Id
File size: 11.9 KB
Line 
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 3944 2009-11-18 16:34:45Z jylam $
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
20enum wm_types
21{
22    WM_FULL,
23    WM_CARD,
24    WM_HSPLIT,
25    WM_VSPLIT,
26    WM_CUBE,
27
28    WM_MAX,
29};
30
31struct option
32{
33    char *key;
34    char *value;
35
36    struct option *next;
37};
38
39
40
41/* ISO-2022 Conversion State */
42struct iso2022_conv_state
43{
44    /* cs = coding system/coding method: */
45    /* (with standard return) */
46    /* '@' = ISO-2022, */
47    /* 'G' = UTF-8 without implementation level, */
48    /* '8' = UTF-8 (Linux console and imitators), */
49    /* and many others that are rarely used; */
50    /* (without standard return) */
51    /* '/G' = UTF-8 Level 1, */
52    /* '/H' = UTF-8 Level 2, */
53    /* '/I' = UTF-8 Level 3, */
54    /* and many others that are rarely used */
55    uint32_t cs;
56    /* ctrl8bit = allow 8-bit controls */
57    uint8_t ctrl8bit;
58    /* cn[0] = C0 control charset (0x00 ... 0x1f):
59     * '@' = ISO 646,
60     * '~' = empty,
61     * and many others that are rarely used */
62    /* cn[1] = C1 control charset (0x80 ... 0x9f):
63     * 'C' = ISO 6429-1983,
64     * '~' = empty,
65     * and many others that are rarely used */
66    uint32_t cn[2];
67    /* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e,
68     *                              94x94-char. 0x21/0x21 ... 0x7e/0x7e),
69     * and
70     * glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe,
71     *                              96-char. 0xa0 ... 0xff,
72     *                              94x94-char. 0xa1/0xa1 ... 0xfe/0xfe,
73     *                              96x96-char. 0xa0/0xa0 ... 0xff/0xff):
74     * 0 = G0, 1 = G1, 2 = G2, 3 = G3 */
75    uint8_t glr[2];
76    /* gn[i] = G0/G1/G2/G3 graphic charset state:
77     * (94-char. sets)
78     * '0' = DEC ACS (VT100 and imitators),
79     * 'B' = US-ASCII,
80     * and many others that are rarely used for e.g. various national ASCII variations;
81     * (96-char. sets)
82     * '.A' = ISO 8859-1 "Latin 1" GR,
83     * '.~' = empty 96-char. set,
84     * and many others that are rarely used for e.g. ISO 8859-n GR;
85     * (double-byte 94x94-charsets)
86     * '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978),
87     * '$A' = Chinese Character Set (GB 2312),
88     * '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983),
89     * '$C' = Korean Graphic Character Set (KSC 5601:1987),
90     * '$D' = Supplementary Japanese Graphic Character Set (JIS X0212),
91     * '$E' = CCITT Chinese Set (GB 2312 + GB 8565),
92     * '$G' = CNS 11643 plane 1,
93     * '$H' = CNS 11643 plane 2,
94     * '$I' = CNS 11643 plane 3,
95     * '$J' = CNS 11643 plane 4,
96     * '$K' = CNS 11643 plane 5,
97     * '$L' = CNS 11643 plane 6,
98     * '$M' = CNS 11643 plane 7,
99     * '$O' = JIS X 0213 plane 1,
100     * '$P' = JIS X 0213 plane 2,
101     * '$Q' = JIS X 0213-2004 Plane 1,
102     * and many others that are rarely used for e.g. traditional
103     * ideographic Vietnamese and BlissSymbolics;
104     * (double-byte 96x96-charsets)
105     * none standardized or in use on terminals AFAIK (Mule does use
106     * some internally)
107     */
108    uint32_t gn[4];
109    /* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */
110    uint8_t ss;
111};
112
113struct screen
114{
115    /* Graphics stuff */
116    int init;
117    caca_canvas_t *cv;
118    uint32_t clearattr;
119    uint8_t fg, bg;   /* ANSI-context fg/bg */
120    uint8_t dfg, dbg; /* Default fg/bg */
121    uint8_t bold, blink, italics, negative, concealed, underline;
122    uint8_t faint, strike, proportional; /* unsupported */
123    struct iso2022_conv_state conv_state; /* charset mess */
124
125    /* Other stuff */
126    int visible;                 /* Draw canvas and border flag */
127    int fd;                      /* pty fd */
128    unsigned char *buf;          /* text buffer */
129    long int total;              /* buffer length */
130    char *title;                 /* tty title */
131    int bell;                    /* bell occuring */
132    unsigned int scroll, s1, s2; /* FIXME, ANSI scroll properties */
133    int pid;                     /* running program pid */
134    int changed;                 /* content was updated */
135
136    int x, y;                    /* Canvas position */
137    int w, h;                    /* Canvas size */
138
139    int orig_x, orig_y;          /* Used by recurrents */
140    int orig_w, orig_h;          /* Used by recurrents */
141};
142
143enum socket_type
144{
145    SOCK_SERVER=0,
146    SOCK_CLIENT=1
147};
148
149struct cube_props
150{
151    int in_switch;
152        int side;
153    long long unsigned int duration;
154};
155
156struct screen_list
157{
158    int wm_type;                 /* Window manager type */
159    int in_bell;                 /* Bell occuring in a window  */
160    int dont_update_coords;      /* Used by recurrents */
161    int changed;                 /* Global redraw needed (e.g. adding a screen) */
162    int delay;                   /* Minimal time between two refresh (ms) */
163    int force_refresh;
164    long long unsigned int last_key_time;
165    int command;
166
167    /* Detaching */
168    int attached;                /* Are we attached to a terminal */
169    int socket[2];               /* Sockets to write to the server / to the client */
170    char *socket_path[2];        /* Sockets to write to the server / to the client */
171    char *socket_dir;            /* Where to create the socket */
172    char *session_name;          /* Name of the session */
173
174    /* Lock */
175    int locked;
176    int lock_offset;
177    int lock_on_detach;
178    long long unsigned int  autolock_timeout;
179    char lockpass[1024];
180    char lockmsg[1024];
181
182    /* Add-ons*/
183    int mini;                    /* Thumbnails */
184    int status;                  /* Status bar */
185    int help;                    /* Help */
186    int window_list;             /* Window list */
187    int cur_in_list;             /* Window list */
188    char *title;                 /* Window title */
189    struct cube_props cube;      /* Cube */
190    long long unsigned int last_switch; /* Cube */
191
192    /* ScreenSaver stuff */
193    long long unsigned int screensaver_timeout;     /* Screensaver timeout in us */
194    int in_screensaver;
195    void *screensaver_data;
196
197    int pty, prevpty;            /* Current and previous window */
198    int count;                   /* Window count */
199    int width, height;           /* caca window size */
200    struct screen **screen;      /* Windows */
201
202    /* Option parsing and configuration */
203    struct option *config;
204    char *default_shell;
205    struct recurrent_list *recurrent_list;
206    char *user_path;
207    int *to_grab;
208    char **to_start;
209    int nb_to_grab;
210    int attach, forceattach;
211    int requested_delay;
212
213    caca_canvas_t *cv;
214    caca_display_t *dp;
215};
216
217
218struct recurrent
219{
220    int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
221    void *user;
222    long long unsigned int  start_time;
223    int kill_me;
224};
225
226struct recurrent_list
227{
228    int count;
229    struct recurrent **recurrent;
230};
231
232
233
234void version(void);
235void usage(int argc, char **argv);
236
237int handle_command_line(int argc, char *argv[], struct screen_list *screen_list);
238
239struct screen_list *create_screen_list(void);
240void free_screen_list(struct screen_list *screen_list);
241
242void mainloop(struct screen_list *screen_list);
243
244int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
245int create_pty_grab(long pid, unsigned int w, unsigned int h, int *cpid);
246int grab_process(long pid, char *ptyname, int ptyfd, int *newpid);
247long select_process(struct screen_list* screen_list);
248
249long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
250int set_tty_size(int fd, unsigned int w, unsigned int h);
251int update_terms(struct screen_list* screen_list);
252void refresh_screens(struct screen_list *screen_list);
253int update_screens_contents(struct screen_list* screen_list);
254long long get_us(void);
255
256void attach(struct screen_list* screen_list);
257int detach(struct screen_list* screen_list);
258int request_attach(struct screen_list* screen_list);
259char * build_socket_path(char *socket_dir, char *session_name, enum socket_type socktype);
260int create_socket(struct screen_list* screen_list, enum socket_type socktype);
261char * connect_socket(struct screen_list* screen_list, enum socket_type socktype);
262char ** list_sockets(char *socket_dir, char *session_name);
263int start_server(struct screen_list *screen_list);
264int send_event(caca_event_t ev, struct screen_list* screen_list);
265int send_delay(struct screen_list* screen_list);
266
267/* Screens management */
268struct screen* create_screen(int w, int h, char *command);
269struct screen* create_screen_grab(int w, int h, int pid);
270int destroy_screen(struct screen *s);
271int add_screen(struct screen_list *list, struct screen *s);
272int remove_screen(struct screen_list *list, int n, int please_kill);
273void resize_screen(struct screen *s, int z, int h);
274
275/* Window managers */
276void update_windows_props(struct screen_list *screen_list);
277void update_windows_props_cards(struct screen_list *screen_list);
278void update_windows_props_hsplit(struct screen_list *screen_list);
279void update_windows_props_full(struct screen_list *screen_list);
280void update_windows_props_vsplit(struct screen_list *screen_list);
281void update_windows_props_cube(struct screen_list *screen_list);
282
283void wm_refresh(struct screen_list *screen_list);
284void wm_refresh_card(struct screen_list *screen_list);
285void wm_refresh_cube(struct screen_list *screen_list);
286void wm_refresh_full(struct screen_list *screen_list);
287void wm_refresh_hsplit(struct screen_list *screen_list);
288void wm_refresh_vsplit(struct screen_list *screen_list);
289int switch_screen_recurrent(struct screen_list* screen_list, struct recurrent* rec, void *user, long long unsigned int t);
290
291
292/* Effects and addons */
293void draw_thumbnails(struct screen_list *screen_list);
294void draw_status(struct screen_list *screen_list);
295void draw_help(struct screen_list *screen_list);
296int update_window_list(int c, struct screen_list *screen_list);
297void draw_list(struct screen_list *screen_list);
298void draw_lock(struct screen_list *screen_list);
299int update_lock(int c, struct screen_list *screen_list);
300int validate_lock(struct screen_list *screen_list, char *user, char *pass);
301
302int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
303
304/* Input to ANSI */
305void *convert_input_ansi(unsigned int *c, int *size);
306int  handle_command_input(struct screen_list*screen_list, unsigned int c);
307
308
309/* Screensavers */
310void screensaver_init(struct screen_list *screen_list);
311void screensaver_kill(struct screen_list *screen_list);
312
313void draw_screensaver(struct screen_list *screen_list);
314void screensaver_flying_toasters(struct screen_list *screen_list);
315
316void screensaver_flying_toasters_init(struct screen_list *screen_list);
317
318void screensaver_flying_toasters_kill(struct screen_list *screen_list);
319
320
321
322/* Recurrents */
323int handle_recurrents(struct screen_list* screen_list);
324int add_recurrent(struct recurrent_list *list,
325                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
326                  void *user);
327int remove_recurrent(struct recurrent_list *list, int n);
328
329
330
331/* Configuration file */
332int read_configuration_file(char *filename, struct screen_list *screen_list);
333int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
334int get_key_value(char *line, struct option *option);
335int fill_config(struct screen_list *screen_list);
336
337#if defined DEBUG
338#   include <stdio.h>
339#   include <stdarg.h>
340static inline void debug(const char *format, ...)
341{
342    va_list args;
343    va_start(args, format);
344    fprintf(stderr, "** neercs debug ** ");
345    vfprintf(stderr, format, args);
346    fprintf(stderr, "\n");
347    va_end(args);
348}
349#else
350#   define debug(format, ...) do {} while(0)
351#endif
352
Note: See TracBrowser for help on using the repository browser.