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

Last change on this file since 2588 was 2588, checked in by Pascal Terjan, 12 years ago
  • Rewrote detach handling, enjoy silent neercs
  • Property svn:keywords set to Id
File size: 9.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 2588 2008-07-26 23:17:04Z 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    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
141struct screen_list
142{
143    int wm_type;                 /* Window manager type */
144    int in_bell;                 /* Bell occuring in a window  */
145    int dont_update_coords;      /* Used by recurrents */
146
147    /* Detaching */
148    int attached;                /* Are we attached to a terminal */
149    int socket;                  /* Socket to ask for attaching */
150    char *socket_path;           /* Socket to ask for attaching */
151    char *socket_dir;            /* Where to create the socket */
152    char *session_name;          /* Name of the session */
153
154    /* Lock */
155    int locked;
156    int lock_offset;
157    long long unsigned int  autolock_timeout;
158    char lockpass[1024];
159    char lockmsg[1024];
160
161    /* Add-ons*/
162    int mini;                    /* Thumbnails */
163    int status;                  /* Status bar */
164    int help;                    /* help */
165
166    /* ScreenSaver stuff */
167    long long unsigned int screensaver_timeout;     /* Screensaver timeout in us */
168    int in_screensaver;
169    void *screensaver_data;
170
171    int pty, prevpty;            /* Current and previous window */
172    int count;                   /* Window count */
173    int width, height;           /* caca window size */
174    struct screen **screen;      /* Windows */
175
176    struct option *config;
177    char *default_shell;
178    struct recurrent_list *recurrent_list;
179
180    cucul_canvas_t *cv;
181    caca_display_t *dp;
182};
183
184
185struct recurrent
186{
187    int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
188    void *user;
189    long long unsigned int  start_time;
190    int kill_me;
191};
192
193struct recurrent_list
194{
195    int count;
196    struct recurrent **recurrent;
197};
198
199
200
201void version(void);
202void usage(int argc, char **argv);
203
204
205struct screen_list *create_screen_list(void);
206
207int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
208int create_pty_grab(long pid, unsigned int w, unsigned int h);
209int grab_process(long pid, char *ptyname, int ptyfd);
210
211long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
212int set_tty_size(int fd, unsigned int w, unsigned int h);
213int update_terms(struct screen_list* screen_list);
214void refresh_screens(struct screen_list *screen_list);
215int update_screens_contents(struct screen_list* screen_list);
216long long get_us(void);
217
218int detach(struct screen_list* screen_list);
219int request_attach(struct screen_list* screen_list);
220char * build_socket_path(char *socket_dir, char *session_name);
221int create_socket(struct screen_list* screen_list);
222char * connect_server(char *socket_path, struct screen_list* screen_list);
223char ** list_sockets(char *socket_dir, char *session_name);
224int server_main(int *to_grab, char **to_start, struct screen_list *screen_list);
225int send_event(caca_event_t ev, int sock);
226
227/* Screens management */
228struct screen* create_screen(int w, int h, char *command);
229struct screen* create_screen_grab(int w, int h, int pid);
230int destroy_screen(struct screen *s);
231int add_screen(struct screen_list *list, struct screen *s);
232int remove_screen(struct screen_list *list, int n, int please_kill);
233void resize_screen(struct screen *s, int z, int h);
234
235/* Window managers */
236void update_windows_props(struct screen_list *screen_list);
237void update_windows_props_cards(struct screen_list *screen_list);
238void update_windows_props_hsplit(struct screen_list *screen_list);
239void update_windows_props_full(struct screen_list *screen_list);
240void update_windows_props_vsplit(struct screen_list *screen_list);
241
242/* Effects and addons */
243void draw_thumbnails(struct screen_list *screen_list);
244void draw_status(struct screen_list *screen_list);
245void draw_help(struct screen_list *screen_list);
246void draw_lock(struct screen_list *screen_list);
247int update_lock(int c, struct screen_list *screen_list);
248int validate_lock(struct screen_list *screen_list, char *user, char *pass);
249
250int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
251
252/* Input to ANSI */
253void *convert_input_ansi(unsigned int *c, int *size);
254int  handle_command_input(struct screen_list*screen_list, unsigned int c);
255
256
257/* Screensavers */
258void screensaver_init(struct screen_list *screen_list);
259void screensaver_kill(struct screen_list *screen_list);
260
261void draw_screensaver(struct screen_list *screen_list);
262void screensaver_flying_toasters(struct screen_list *screen_list);
263
264void screensaver_flying_toasters_init(struct screen_list *screen_list);
265
266void screensaver_flying_toasters_kill(struct screen_list *screen_list);
267
268
269
270/* Recurrents */
271int handle_recurrents(struct screen_list* screen_list);
272int add_recurrent(struct recurrent_list *list,
273                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
274                  void *user);
275int remove_recurrent(struct recurrent_list *list, int n);
276
277
278
279/* Configuration file */
280int read_configuration_file(char *filename, struct screen_list *screen_list);
281int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
282int get_key_value(char *line, struct option *option);
283int fill_config(struct screen_list *screen_list);
284
285#if defined DEBUG
286#   include <stdio.h>
287#   include <stdarg.h>
288static inline void debug(const char *format, ...)
289{
290    va_list args;
291    va_start(args, format);
292    fprintf(stderr, "** neercs debug ** ");
293    vfprintf(stderr, format, args);
294    fprintf(stderr, "\n");
295    va_end(args);
296}
297#else
298#   define debug(format, ...) do {} while(0)
299#endif
300
Note: See TracBrowser for help on using the repository browser.