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

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