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

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