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

Last change on this file since 4048 was 4048, checked in by Jean-Yves Lamoureux, 11 years ago
  • Created widgets.[c,h] and an unfinished (but working) input box
  • Python interpreter now uses generic input box code
  • 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 4048 2009-11-26 17:20: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#ifndef _NEERCS_H_
17#define _NEERCS_H_
18
19#include <stdint.h>
20#include <caca.h>
21
22#include "widgets.h"
23
24enum wm_types
25{
26    WM_FULL,
27    WM_CARD,
28    WM_HSPLIT,
29    WM_VSPLIT,
30
31    WM_MAX,
32};
33
34
35/* ISO-2022 Conversion State */
36struct iso2022_conv_state
37{
38    /* cs = coding system/coding method: */
39    /* (with standard return) */
40    /* '@' = ISO-2022, */
41    /* 'G' = UTF-8 without implementation level, */
42    /* '8' = UTF-8 (Linux console and imitators), */
43    /* and many others that are rarely used; */
44    /* (without standard return) */
45    /* '/G' = UTF-8 Level 1, */
46    /* '/H' = UTF-8 Level 2, */
47    /* '/I' = UTF-8 Level 3, */
48    /* and many others that are rarely used */
49    uint32_t cs;
50    /* ctrl8bit = allow 8-bit controls */
51    uint8_t ctrl8bit;
52    /* cn[0] = C0 control charset (0x00 ... 0x1f):
53     * '@' = ISO 646,
54     * '~' = empty,
55     * and many others that are rarely used */
56    /* cn[1] = C1 control charset (0x80 ... 0x9f):
57     * 'C' = ISO 6429-1983,
58     * '~' = empty,
59     * and many others that are rarely used */
60    uint32_t cn[2];
61    /* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e,
62     *                              94x94-char. 0x21/0x21 ... 0x7e/0x7e),
63     * and
64     * glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe,
65     *                              96-char. 0xa0 ... 0xff,
66     *                              94x94-char. 0xa1/0xa1 ... 0xfe/0xfe,
67     *                              96x96-char. 0xa0/0xa0 ... 0xff/0xff):
68     * 0 = G0, 1 = G1, 2 = G2, 3 = G3 */
69    uint8_t glr[2];
70    /* gn[i] = G0/G1/G2/G3 graphic charset state:
71     * (94-char. sets)
72     * '0' = DEC ACS (VT100 and imitators),
73     * 'B' = US-ASCII,
74     * and many others that are rarely used for e.g. various national ASCII variations;
75     * (96-char. sets)
76     * '.A' = ISO 8859-1 "Latin 1" GR,
77     * '.~' = empty 96-char. set,
78     * and many others that are rarely used for e.g. ISO 8859-n GR;
79     * (double-byte 94x94-charsets)
80     * '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978),
81     * '$A' = Chinese Character Set (GB 2312),
82     * '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983),
83     * '$C' = Korean Graphic Character Set (KSC 5601:1987),
84     * '$D' = Supplementary Japanese Graphic Character Set (JIS X0212),
85     * '$E' = CCITT Chinese Set (GB 2312 + GB 8565),
86     * '$G' = CNS 11643 plane 1,
87     * '$H' = CNS 11643 plane 2,
88     * '$I' = CNS 11643 plane 3,
89     * '$J' = CNS 11643 plane 4,
90     * '$K' = CNS 11643 plane 5,
91     * '$L' = CNS 11643 plane 6,
92     * '$M' = CNS 11643 plane 7,
93     * '$O' = JIS X 0213 plane 1,
94     * '$P' = JIS X 0213 plane 2,
95     * '$Q' = JIS X 0213-2004 Plane 1,
96     * and many others that are rarely used for e.g. traditional
97     * ideographic Vietnamese and BlissSymbolics;
98     * (double-byte 96x96-charsets)
99     * none standardized or in use on terminals AFAIK (Mule does use
100     * some internally)
101     */
102    uint32_t gn[4];
103    /* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */
104    uint8_t ss;
105};
106
107struct screen
108{
109    /* Graphics stuff */
110    int init;
111    caca_canvas_t *cv;
112    uint32_t clearattr;
113    uint8_t fg, bg;   /* ANSI-context fg/bg */
114    uint8_t dfg, dbg; /* Default fg/bg */
115    uint8_t bold, blink, italics, negative, concealed, underline;
116    uint8_t faint, strike, proportional; /* unsupported */
117    struct iso2022_conv_state conv_state; /* charset mess */
118
119    /* Other stuff */
120    int visible;                 /* Draw canvas and border flag */
121    int fd;                      /* pty fd */
122    unsigned char *buf;          /* text buffer */
123    long int total;              /* buffer length */
124    char *title;                 /* tty title */
125    int bell;                    /* bell occuring */
126    unsigned int scroll, s1, s2; /* FIXME, ANSI scroll properties */
127    int pid;                     /* running program pid */
128    int changed;                 /* content was updated */
129
130    int x, y;                    /* Canvas position */
131    int w, h;                    /* Canvas size */
132
133    int orig_x, orig_y;          /* Used by recurrents */
134    int orig_w, orig_h;          /* Used by recurrents */
135};
136
137enum socket_type
138{
139    SOCK_SERVER=0,
140    SOCK_CLIENT=1
141};
142
143struct cube_props
144{
145    int in_switch;
146        int side;
147    long long unsigned int duration;
148};
149
150struct interpreter_props
151{
152    /* Input box */
153        struct input_box *box;
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);
363struct config_line *get_config(const char *name);
364struct config_line *get_config_option(void);
365
366/* Python interpreter */
367#ifdef USE_PYTHON
368int python_init(struct screen_list *sl);
369int python_close(struct screen_list *sl);
370int  python_command_handle_key(struct screen_list *screen_list, unsigned int c);
371void draw_python_command(struct screen_list *screen_list);
372#endif
373
374#if defined DEBUG
375#   include <stdio.h>
376#   include <stdarg.h>
377static inline void debug(const char *format, ...)
378{
379    va_list args;
380    va_start(args, format);
381    fprintf(stderr, "** neercs debug ** ");
382    vfprintf(stderr, format, args);
383    fprintf(stderr, "\n");
384    va_end(args);
385}
386#else
387#   define debug(format, ...) do {} while(0)
388#endif
389#endif /* _NEERCS_H_ */
Note: See TracBrowser for help on using the repository browser.