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

Last change on this file since 2995 was 2995, checked in by Sam Hocevar, 12 years ago

Port neercs to the unified libcaca 0.99.beta15 API.

  • Property svn:keywords set to Id
File size: 10.6 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 2995 2008-10-18 21:47:35Z sam $
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
27    WM_MAX,
28};
29
30struct option
31{
32    char *key;
33    char *value;
34
35    struct option *next;
36};
37
38
39
40/* ISO-2022 Conversion State */
41struct 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
112struct screen
113{
114    /* Graphics stuff */
115    int init;
116    caca_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
141enum socket_type
142{
143    SOCK_SERVER=0,
144    SOCK_CLIENT=1
145};
146
147struct 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    int window_list;             /* Window list */
172    int cur_in_list;             /* Window list */
173    char *title;                 /* Window title */
174
175    /* ScreenSaver stuff */
176    long long unsigned int screensaver_timeout;     /* Screensaver timeout in us */
177    int in_screensaver;
178    void *screensaver_data;
179
180    int pty, prevpty;            /* Current and previous window */
181    int count;                   /* Window count */
182    int width, height;           /* caca window size */
183    struct screen **screen;      /* Windows */
184
185    /* Option parsing and configuration */
186    struct option *config;
187    char *default_shell;
188    struct recurrent_list *recurrent_list;
189    char *user_path;
190    int *to_grab;
191    char **to_start;
192    int nb_to_grab;
193    int attach, forceattach;
194
195    caca_canvas_t *cv;
196    caca_display_t *dp;
197};
198
199
200struct recurrent
201{
202    int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
203    void *user;
204    long long unsigned int  start_time;
205    int kill_me;
206};
207
208struct recurrent_list
209{
210    int count;
211    struct recurrent **recurrent;
212};
213
214
215
216void version(void);
217void usage(int argc, char **argv);
218
219int handle_command_line(int argc, char *argv[], struct screen_list *screen_list);
220
221struct screen_list *create_screen_list(void);
222
223int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
224int create_pty_grab(long pid, unsigned int w, unsigned int h);
225int grab_process(long pid, char *ptyname, int ptyfd);
226
227long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
228int set_tty_size(int fd, unsigned int w, unsigned int h);
229int update_terms(struct screen_list* screen_list);
230void refresh_screens(struct screen_list *screen_list);
231int update_screens_contents(struct screen_list* screen_list);
232long long get_us(void);
233
234int detach(struct screen_list* screen_list);
235int request_attach(struct screen_list* screen_list);
236char * build_socket_path(char *socket_dir, char *session_name, enum socket_type socktype);
237int create_socket(struct screen_list* screen_list, enum socket_type socktype);
238char * connect_socket(struct screen_list* screen_list, enum socket_type socktype);
239char ** list_sockets(char *socket_dir, char *session_name);
240int start_server(struct screen_list *screen_list);
241int send_event(caca_event_t ev, struct screen_list* screen_list);
242
243/* Screens management */
244struct screen* create_screen(int w, int h, char *command);
245struct screen* create_screen_grab(int w, int h, int pid);
246int destroy_screen(struct screen *s);
247int add_screen(struct screen_list *list, struct screen *s);
248int remove_screen(struct screen_list *list, int n, int please_kill);
249void resize_screen(struct screen *s, int z, int h);
250
251/* Window managers */
252void update_windows_props(struct screen_list *screen_list);
253void update_windows_props_cards(struct screen_list *screen_list);
254void update_windows_props_hsplit(struct screen_list *screen_list);
255void update_windows_props_full(struct screen_list *screen_list);
256void update_windows_props_vsplit(struct screen_list *screen_list);
257
258/* Effects and addons */
259void draw_thumbnails(struct screen_list *screen_list);
260void draw_status(struct screen_list *screen_list);
261void draw_help(struct screen_list *screen_list);
262int update_window_list(int c, struct screen_list *screen_list);
263void draw_list(struct screen_list *screen_list);
264void draw_lock(struct screen_list *screen_list);
265int update_lock(int c, struct screen_list *screen_list);
266int validate_lock(struct screen_list *screen_list, char *user, char *pass);
267
268int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
269
270/* Input to ANSI */
271void *convert_input_ansi(unsigned int *c, int *size);
272int  handle_command_input(struct screen_list*screen_list, unsigned int c);
273
274
275/* Screensavers */
276void screensaver_init(struct screen_list *screen_list);
277void screensaver_kill(struct screen_list *screen_list);
278
279void draw_screensaver(struct screen_list *screen_list);
280void screensaver_flying_toasters(struct screen_list *screen_list);
281
282void screensaver_flying_toasters_init(struct screen_list *screen_list);
283
284void screensaver_flying_toasters_kill(struct screen_list *screen_list);
285
286
287
288/* Recurrents */
289int handle_recurrents(struct screen_list* screen_list);
290int add_recurrent(struct recurrent_list *list,
291                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
292                  void *user);
293int remove_recurrent(struct recurrent_list *list, int n);
294
295
296
297/* Configuration file */
298int read_configuration_file(char *filename, struct screen_list *screen_list);
299int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
300int get_key_value(char *line, struct option *option);
301int fill_config(struct screen_list *screen_list);
302
303#if defined DEBUG
304#   include <stdio.h>
305#   include <stdarg.h>
306static inline void debug(const char *format, ...)
307{
308    va_list args;
309    va_start(args, format);
310    fprintf(stderr, "** neercs debug ** ");
311    vfprintf(stderr, format, args);
312    fprintf(stderr, "\n");
313    va_end(args);
314}
315#else
316#   define debug(format, ...) do {} while(0)
317#endif
318
Note: See TracBrowser for help on using the repository browser.