source: trunk/tools/neercs/old/neercs.h @ 2183

Last change on this file since 2183 was 2183, checked in by sam, 7 years ago

build: fix the WTFPL site URL in all code comments.

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