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

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