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

Last change on this file since 3940 was 3940, checked in by Jean-Yves Lamoureux, 11 years ago
  • Move client's mainloop to client.c
  • Property svn:keywords set to Id
File size: 11.8 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 3940 2009-11-18 14:55:57Z 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
165    /* Detaching */
166    int attached;                /* Are we attached to a terminal */
167    int socket[2];               /* Sockets to write to the server / to the client */
168    char *socket_path[2];        /* Sockets to write to the server / to the client */
169    char *socket_dir;            /* Where to create the socket */
170    char *session_name;          /* Name of the session */
171
172    /* Lock */
173    int locked;
174    int lock_offset;
175    int lock_on_detach;
176    long long unsigned int  autolock_timeout;
177    char lockpass[1024];
178    char lockmsg[1024];
179
180    /* Add-ons*/
181    int mini;                    /* Thumbnails */
182    int status;                  /* Status bar */
183    int help;                    /* Help */
184    int window_list;             /* Window list */
185    int cur_in_list;             /* Window list */
186    char *title;                 /* Window title */
187    struct cube_props cube;      /* Cube */
188    long long unsigned int last_switch; /* Cube */
189
190    /* ScreenSaver stuff */
191    long long unsigned int screensaver_timeout;     /* Screensaver timeout in us */
192    int in_screensaver;
193    void *screensaver_data;
194
195    int pty, prevpty;            /* Current and previous window */
196    int count;                   /* Window count */
197    int width, height;           /* caca window size */
198    struct screen **screen;      /* Windows */
199
200    /* Option parsing and configuration */
201    struct option *config;
202    char *default_shell;
203    struct recurrent_list *recurrent_list;
204    char *user_path;
205    int *to_grab;
206    char **to_start;
207    int nb_to_grab;
208    int attach, forceattach;
209    int requested_delay;
210
211    caca_canvas_t *cv;
212    caca_display_t *dp;
213};
214
215
216struct recurrent
217{
218    int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
219    void *user;
220    long long unsigned int  start_time;
221    int kill_me;
222};
223
224struct recurrent_list
225{
226    int count;
227    struct recurrent **recurrent;
228};
229
230
231
232void version(void);
233void usage(int argc, char **argv);
234
235int handle_command_line(int argc, char *argv[], struct screen_list *screen_list);
236
237struct screen_list *create_screen_list(void);
238void free_screen_list(struct screen_list *screen_list);
239
240void mainloop(struct screen_list *screen_list);
241
242int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
243int create_pty_grab(long pid, unsigned int w, unsigned int h, int *cpid);
244int grab_process(long pid, char *ptyname, int ptyfd, int *newpid);
245long select_process(struct screen_list* screen_list);
246
247long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
248int set_tty_size(int fd, unsigned int w, unsigned int h);
249int update_terms(struct screen_list* screen_list);
250void refresh_screens(struct screen_list *screen_list);
251int update_screens_contents(struct screen_list* screen_list);
252long long get_us(void);
253
254void attach(struct screen_list* screen_list);
255int detach(struct screen_list* screen_list);
256int request_attach(struct screen_list* screen_list);
257char * build_socket_path(char *socket_dir, char *session_name, enum socket_type socktype);
258int create_socket(struct screen_list* screen_list, enum socket_type socktype);
259char * connect_socket(struct screen_list* screen_list, enum socket_type socktype);
260char ** list_sockets(char *socket_dir, char *session_name);
261int start_server(struct screen_list *screen_list);
262int send_event(caca_event_t ev, struct screen_list* screen_list);
263int send_delay(struct screen_list* screen_list);
264
265/* Screens management */
266struct screen* create_screen(int w, int h, char *command);
267struct screen* create_screen_grab(int w, int h, int pid);
268int destroy_screen(struct screen *s);
269int add_screen(struct screen_list *list, struct screen *s);
270int remove_screen(struct screen_list *list, int n, int please_kill);
271void resize_screen(struct screen *s, int z, int h);
272
273/* Window managers */
274void update_windows_props(struct screen_list *screen_list);
275void update_windows_props_cards(struct screen_list *screen_list);
276void update_windows_props_hsplit(struct screen_list *screen_list);
277void update_windows_props_full(struct screen_list *screen_list);
278void update_windows_props_vsplit(struct screen_list *screen_list);
279void update_windows_props_cube(struct screen_list *screen_list);
280
281void wm_refresh(struct screen_list *screen_list);
282void wm_refresh_card(struct screen_list *screen_list);
283void wm_refresh_cube(struct screen_list *screen_list);
284void wm_refresh_full(struct screen_list *screen_list);
285void wm_refresh_hsplit(struct screen_list *screen_list);
286void wm_refresh_vsplit(struct screen_list *screen_list);
287int switch_screen_recurrent(struct screen_list* screen_list, struct recurrent* rec, void *user, long long unsigned int t);
288
289
290/* Effects and addons */
291void draw_thumbnails(struct screen_list *screen_list);
292void draw_status(struct screen_list *screen_list);
293void draw_help(struct screen_list *screen_list);
294int update_window_list(int c, struct screen_list *screen_list);
295void draw_list(struct screen_list *screen_list);
296void draw_lock(struct screen_list *screen_list);
297int update_lock(int c, struct screen_list *screen_list);
298int validate_lock(struct screen_list *screen_list, char *user, char *pass);
299
300int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
301
302/* Input to ANSI */
303void *convert_input_ansi(unsigned int *c, int *size);
304int  handle_command_input(struct screen_list*screen_list, unsigned int c);
305
306
307/* Screensavers */
308void screensaver_init(struct screen_list *screen_list);
309void screensaver_kill(struct screen_list *screen_list);
310
311void draw_screensaver(struct screen_list *screen_list);
312void screensaver_flying_toasters(struct screen_list *screen_list);
313
314void screensaver_flying_toasters_init(struct screen_list *screen_list);
315
316void screensaver_flying_toasters_kill(struct screen_list *screen_list);
317
318
319
320/* Recurrents */
321int handle_recurrents(struct screen_list* screen_list);
322int add_recurrent(struct recurrent_list *list,
323                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
324                  void *user);
325int remove_recurrent(struct recurrent_list *list, int n);
326
327
328
329/* Configuration file */
330int read_configuration_file(char *filename, struct screen_list *screen_list);
331int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
332int get_key_value(char *line, struct option *option);
333int fill_config(struct screen_list *screen_list);
334
335#if defined DEBUG
336#   include <stdio.h>
337#   include <stdarg.h>
338static inline void debug(const char *format, ...)
339{
340    va_list args;
341    va_start(args, format);
342    fprintf(stderr, "** neercs debug ** ");
343    vfprintf(stderr, format, args);
344    fprintf(stderr, "\n");
345    va_end(args);
346}
347#else
348#   define debug(format, ...) do {} while(0)
349#endif
350
Note: See TracBrowser for help on using the repository browser.