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

Last change on this file since 3456 was 3456, checked in by Pascal Terjan, 11 years ago
  • Allow configuring max refresh rate
  • Property svn:keywords set to Id
File size: 10.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 3456 2009-05-14 15:42:41Z 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
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    int changed;                 /* content was updated */
134
135    int x, y;                    /* Canvas position */
136    int w, h;                    /* Canvas size */
137
138    int orig_x, orig_y;          /* Used by recurrents */
139    int orig_w, orig_h;          /* Used by recurrents */
140};
141
142enum socket_type
143{
144    SOCK_SERVER=0,
145    SOCK_CLIENT=1
146};
147
148struct screen_list
149{
150    int wm_type;                 /* Window manager type */
151    int in_bell;                 /* Bell occuring in a window  */
152    int dont_update_coords;      /* Used by recurrents */
153    int changed;                 /* Global redraw needed (e.g. adding a screen) */
154    int delay;                   /* Minimal time between two refresh (ms) */
155
156    /* Detaching */
157    int attached;                /* Are we attached to a terminal */
158    int socket[2];               /* Sockets to write to the server / to the client */
159    char *socket_path[2];        /* Sockets to write to the server / to the client */
160    char *socket_dir;            /* Where to create the socket */
161    char *session_name;          /* Name of the session */
162
163    /* Lock */
164    int locked;
165    int lock_offset;
166    long long unsigned int  autolock_timeout;
167    char lockpass[1024];
168    char lockmsg[1024];
169
170    /* Add-ons*/
171    int mini;                    /* Thumbnails */
172    int status;                  /* Status bar */
173    int help;                    /* Help */
174    int window_list;             /* Window list */
175    int cur_in_list;             /* Window list */
176    char *title;                 /* Window title */
177
178    /* ScreenSaver stuff */
179    long long unsigned int screensaver_timeout;     /* Screensaver timeout in us */
180    int in_screensaver;
181    void *screensaver_data;
182
183    int pty, prevpty;            /* Current and previous window */
184    int count;                   /* Window count */
185    int width, height;           /* caca window size */
186    struct screen **screen;      /* Windows */
187
188    /* Option parsing and configuration */
189    struct option *config;
190    char *default_shell;
191    struct recurrent_list *recurrent_list;
192    char *user_path;
193    int *to_grab;
194    char **to_start;
195    int nb_to_grab;
196    int attach, forceattach;
197    int requested_delay;
198
199    caca_canvas_t *cv;
200    caca_display_t *dp;
201};
202
203
204struct recurrent
205{
206    int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
207    void *user;
208    long long unsigned int  start_time;
209    int kill_me;
210};
211
212struct recurrent_list
213{
214    int count;
215    struct recurrent **recurrent;
216};
217
218
219
220void version(void);
221void usage(int argc, char **argv);
222
223int handle_command_line(int argc, char *argv[], struct screen_list *screen_list);
224
225struct screen_list *create_screen_list(void);
226
227int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
228int create_pty_grab(long pid, unsigned int w, unsigned int h);
229int grab_process(long pid, char *ptyname, int ptyfd);
230
231long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
232int set_tty_size(int fd, unsigned int w, unsigned int h);
233int update_terms(struct screen_list* screen_list);
234void refresh_screens(struct screen_list *screen_list);
235int update_screens_contents(struct screen_list* screen_list);
236long long get_us(void);
237
238void attach(struct screen_list* screen_list);
239int detach(struct screen_list* screen_list);
240int request_attach(struct screen_list* screen_list);
241char * build_socket_path(char *socket_dir, char *session_name, enum socket_type socktype);
242int create_socket(struct screen_list* screen_list, enum socket_type socktype);
243char * connect_socket(struct screen_list* screen_list, enum socket_type socktype);
244char ** list_sockets(char *socket_dir, char *session_name);
245int start_server(struct screen_list *screen_list);
246int send_event(caca_event_t ev, struct screen_list* screen_list);
247
248/* Screens management */
249struct screen* create_screen(int w, int h, char *command);
250struct screen* create_screen_grab(int w, int h, int pid);
251int destroy_screen(struct screen *s);
252int add_screen(struct screen_list *list, struct screen *s);
253int remove_screen(struct screen_list *list, int n, int please_kill);
254void resize_screen(struct screen *s, int z, int h);
255
256/* Window managers */
257void update_windows_props(struct screen_list *screen_list);
258void update_windows_props_cards(struct screen_list *screen_list);
259void update_windows_props_hsplit(struct screen_list *screen_list);
260void update_windows_props_full(struct screen_list *screen_list);
261void update_windows_props_vsplit(struct screen_list *screen_list);
262
263/* Effects and addons */
264void draw_thumbnails(struct screen_list *screen_list);
265void draw_status(struct screen_list *screen_list);
266void draw_help(struct screen_list *screen_list);
267int update_window_list(int c, struct screen_list *screen_list);
268void draw_list(struct screen_list *screen_list);
269void draw_lock(struct screen_list *screen_list);
270int update_lock(int c, struct screen_list *screen_list);
271int validate_lock(struct screen_list *screen_list, char *user, char *pass);
272
273int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
274
275/* Input to ANSI */
276void *convert_input_ansi(unsigned int *c, int *size);
277int  handle_command_input(struct screen_list*screen_list, unsigned int c);
278
279
280/* Screensavers */
281void screensaver_init(struct screen_list *screen_list);
282void screensaver_kill(struct screen_list *screen_list);
283
284void draw_screensaver(struct screen_list *screen_list);
285void screensaver_flying_toasters(struct screen_list *screen_list);
286
287void screensaver_flying_toasters_init(struct screen_list *screen_list);
288
289void screensaver_flying_toasters_kill(struct screen_list *screen_list);
290
291
292
293/* Recurrents */
294int handle_recurrents(struct screen_list* screen_list);
295int add_recurrent(struct recurrent_list *list,
296                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
297                  void *user);
298int remove_recurrent(struct recurrent_list *list, int n);
299
300
301
302/* Configuration file */
303int read_configuration_file(char *filename, struct screen_list *screen_list);
304int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
305int get_key_value(char *line, struct option *option);
306int fill_config(struct screen_list *screen_list);
307
308#if defined DEBUG
309#   include <stdio.h>
310#   include <stdarg.h>
311static inline void debug(const char *format, ...)
312{
313    va_list args;
314    va_start(args, format);
315    fprintf(stderr, "** neercs debug ** ");
316    vfprintf(stderr, format, args);
317    fprintf(stderr, "\n");
318    va_end(args);
319}
320#else
321#   define debug(format, ...) do {} while(0)
322#endif
323
Note: See TracBrowser for help on using the repository browser.