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

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