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

Last change on this file since 4033 was 4033, checked in by Jean-Yves Lamoureux, 11 years ago
  • Added basic and non-working python interpreter
  • 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 4033 2009-11-25 11:47:40Z 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;
153};
154
155struct screen_list
156{
157    int outfd;                   /* Debug */
158    int wm_type;                 /* Window manager type */
159    int in_bell;                 /* Bell occuring in a window  */
160    int was_in_bell;
161    int dont_update_coords;      /* Used by recurrents */
162    int changed;                 /* Global redraw needed (e.g. adding a screen) */
163    int delay;                   /* Minimal time between two refresh (ms) */
164    int force_refresh;
165    int command;
166    long long unsigned int last_key_time;
167    long long unsigned int last_refresh_time;
168
169
170    /* Detaching */
171    int attached;                /* Are we attached to a terminal */
172    int socket[2];               /* Sockets to write to the server / to the client */
173    char *socket_path[2];        /* Sockets to write to the server / to the client */
174    char *socket_dir;            /* Where to create the socket */
175    char *session_name;          /* Name of the session */
176
177    /* Lock */
178    int locked;
179    int lock_offset;
180    int lock_on_detach;
181    long long unsigned int  autolock_timeout;
182    char lockpass[1024];
183    char lockmsg[1024];
184
185    /* Add-ons*/
186    int eyecandy;                /* Eye Candy */
187    int mini;                    /* Thumbnails */
188    int status;                  /* Status bar */
189    int help;                    /* Help */
190    int python_command;          /* Python command */
191    int border_size;             /* Borders */
192    int window_list;             /* Window list */
193    int cur_in_list;             /* Window list */
194    char *title;                 /* Window title */
195    struct cube_props cube;      /* Cube */
196    long long unsigned int last_switch; /* Cube */
197    struct interpreter_props interpreter_props;
198
199    /* ScreenSaver stuff */
200    long long unsigned int screensaver_timeout;     /* Screensaver timeout in us */
201    int in_screensaver;
202    void *screensaver_data;
203
204    int pty, prevpty;            /* Current and previous window */
205    int count;                   /* Window count */
206    int width, height;           /* caca window size */
207    struct screen **screen;      /* Windows */
208
209    /* Option parsing and configuration */
210    struct option *config;
211    char *default_shell;
212    struct recurrent_list *recurrent_list;
213    char *user_path;
214    int *to_grab;
215    char **to_start;
216    int nb_to_grab;
217    int attach, forceattach;
218    int requested_delay;
219
220    caca_canvas_t *cv;
221    caca_display_t *dp;
222};
223
224/* Configuration */
225struct option
226{
227    char *key;
228    char *value;
229   
230    struct option *next;
231};
232struct config_line
233{
234    const char name[32];
235    int  (*set) (const char *argv, struct screen_list * screen_list);
236    char* (*get) (struct screen_list * screen_list);
237};
238
239/* Recurrents */
240struct recurrent
241{
242    int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
243    void *user;
244    long long unsigned int  start_time;
245    int kill_me;
246};
247
248struct recurrent_list
249{
250    int count;
251    struct recurrent **recurrent;
252};
253
254
255
256void version(void);
257void usage(int argc, char **argv);
258
259int handle_command_line(int argc, char *argv[], struct screen_list *screen_list);
260
261struct screen_list *create_screen_list(void);
262void free_screen_list(struct screen_list *screen_list);
263
264int start_client(struct screen_list * screen_list);
265void mainloop(struct screen_list *screen_list);
266
267int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
268int create_pty_grab(long pid, unsigned int w, unsigned int h, int *cpid);
269int grab_process(long pid, char *ptyname, int ptyfd, int *newpid);
270long select_process(struct screen_list* screen_list);
271
272long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
273int set_tty_size(int fd, unsigned int w, unsigned int h);
274int update_terms(struct screen_list* screen_list);
275void refresh_screens(struct screen_list *screen_list);
276int update_screens_contents(struct screen_list* screen_list);
277int install_fds(struct screen_list *screen_list);
278long long get_us(void);
279
280void attach(struct screen_list* screen_list);
281int detach(struct screen_list* screen_list);
282int request_attach(struct screen_list* screen_list);
283char * build_socket_path(char *socket_dir, char *session_name, enum socket_type socktype);
284int create_socket(struct screen_list* screen_list, enum socket_type socktype);
285char * connect_socket(struct screen_list* screen_list, enum socket_type socktype);
286char ** list_sockets(char *socket_dir, char *session_name);
287int start_server(struct screen_list *screen_list);
288int send_event(caca_event_t ev, struct screen_list* screen_list);
289int send_delay(struct screen_list* screen_list);
290int send_ansi_sequence(struct screen_list *screen_list, char *str);
291
292/* Screens management */
293struct screen* create_screen(int w, int h, char *command);
294struct screen* create_screen_grab(int w, int h, int pid);
295int destroy_screen(struct screen *s);
296int add_screen(struct screen_list *list, struct screen *s);
297int remove_screen(struct screen_list *list, int n, int please_kill);
298void resize_screen(struct screen *s, int z, int h);
299
300/* Window managers */
301void update_windows_props(struct screen_list *screen_list);
302void update_windows_props_cards(struct screen_list *screen_list);
303void update_windows_props_hsplit(struct screen_list *screen_list);
304void update_windows_props_full(struct screen_list *screen_list);
305void update_windows_props_vsplit(struct screen_list *screen_list);
306void update_windows_props_cube(struct screen_list *screen_list);
307
308void wm_refresh(struct screen_list *screen_list);
309void wm_refresh_card(struct screen_list *screen_list);
310void wm_refresh_cube(struct screen_list *screen_list);
311void wm_refresh_full(struct screen_list *screen_list);
312void wm_refresh_hsplit(struct screen_list *screen_list);
313void wm_refresh_vsplit(struct screen_list *screen_list);
314int switch_screen_recurrent(struct screen_list* screen_list, struct recurrent* rec, void *user, long long unsigned int t);
315
316
317/* Effects and addons */
318void draw_thumbnails(struct screen_list *screen_list);
319void draw_status(struct screen_list *screen_list);
320void draw_help(struct screen_list *screen_list);
321int help_handle_key(struct screen_list *screen_list, unsigned int c);
322int update_window_list(int c, struct screen_list *screen_list);
323void draw_list(struct screen_list *screen_list);
324void draw_lock(struct screen_list *screen_list);
325int update_lock(int c, struct screen_list *screen_list);
326int validate_lock(struct screen_list *screen_list, char *user, char *pass);
327
328int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
329
330/* Input to ANSI */
331void *convert_input_ansi(unsigned int *c, int *size);
332int  handle_command_input(struct screen_list*screen_list, unsigned int c);
333
334
335/* Screensavers */
336void screensaver_init(struct screen_list *screen_list);
337void screensaver_kill(struct screen_list *screen_list);
338
339void draw_screensaver(struct screen_list *screen_list);
340void screensaver_flying_toasters(struct screen_list *screen_list);
341
342void screensaver_flying_toasters_init(struct screen_list *screen_list);
343
344void screensaver_flying_toasters_kill(struct screen_list *screen_list);
345
346
347
348/* Recurrents */
349int handle_recurrents(struct screen_list* screen_list);
350int add_recurrent(struct recurrent_list *list,
351                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
352                  void *user);
353int remove_recurrent(struct recurrent_list *list, int n);
354
355
356
357/* Configuration file */
358int read_configuration_file(char *filename, struct screen_list *screen_list);
359int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
360int get_key_value(char *line, struct option *option);
361int fill_config(struct screen_list *screen_list);
362
363
364/* Python interpreter */
365#ifdef USE_PYTHON
366int python_init(struct screen_list *sl);
367int python_close(struct screen_list *sl);
368int  python_command_handle_key(struct screen_list *screen_list, unsigned int c);
369void draw_python_command(struct screen_list *screen_list);
370#endif
371
372#if defined DEBUG
373#   include <stdio.h>
374#   include <stdarg.h>
375static inline void debug(const char *format, ...)
376{
377    va_list args;
378    va_start(args, format);
379    fprintf(stderr, "** neercs debug ** ");
380    vfprintf(stderr, format, args);
381    fprintf(stderr, "\n");
382    va_end(args);
383}
384#else
385#   define debug(format, ...) do {} while(0)
386#endif
387
Note: See TracBrowser for help on using the repository browser.