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

Last change on this file since 4335 was 4335, checked in by Pascal Terjan, 11 years ago

Whitespace fixes

  • Property svn:keywords set to Id
File size: 13.9 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 4335 2010-02-08 08:35:40Z pterjan $
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
34enum mouse_report
35{
36    MOUSE_NONE,
37    MOUSE_X10,
38    MOUSE_VT200,
39    MOUSE_VT200_HIGHLIGHT,
40    MOUSE_BTN_EVENT,
41    MOUSE_ANY_EVENT,
42};
43
44
45/* ISO-2022 Conversion State */
46struct iso2022_conv_state
47{
48    /* cs = coding system/coding method: */
49    /* (with standard return) */
50    /* '@' = ISO-2022, */
51    /* 'G' = UTF-8 without implementation level, */
52    /* '8' = UTF-8 (Linux console and imitators), */
53    /* and many others that are rarely used; */
54    /* (without standard return) */
55    /* '/G' = UTF-8 Level 1, */
56    /* '/H' = UTF-8 Level 2, */
57    /* '/I' = UTF-8 Level 3, */
58    /* and many others that are rarely used */
59    uint32_t cs;
60    /* ctrl8bit = allow 8-bit controls */
61    uint8_t ctrl8bit;
62    /* cn[0] = C0 control charset (0x00 ... 0x1f):
63     * '@' = ISO 646,
64     * '~' = empty,
65     * and many others that are rarely used */
66    /* cn[1] = C1 control charset (0x80 ... 0x9f):
67     * 'C' = ISO 6429-1983,
68     * '~' = empty,
69     * and many others that are rarely used */
70    uint32_t cn[2];
71    /* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e,
72     *                              94x94-char. 0x21/0x21 ... 0x7e/0x7e),
73     * and
74     * glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe,
75     *                              96-char. 0xa0 ... 0xff,
76     *                              94x94-char. 0xa1/0xa1 ... 0xfe/0xfe,
77     *                              96x96-char. 0xa0/0xa0 ... 0xff/0xff):
78     * 0 = G0, 1 = G1, 2 = G2, 3 = G3 */
79    uint8_t glr[2];
80    /* gn[i] = G0/G1/G2/G3 graphic charset state:
81     * (94-char. sets)
82     * '0' = DEC ACS (VT100 and imitators),
83     * 'B' = US-ASCII,
84     * and many others that are rarely used for e.g. various national ASCII variations;
85     * (96-char. sets)
86     * '.A' = ISO 8859-1 "Latin 1" GR,
87     * '.~' = empty 96-char. set,
88     * and many others that are rarely used for e.g. ISO 8859-n GR;
89     * (double-byte 94x94-charsets)
90     * '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978),
91     * '$A' = Chinese Character Set (GB 2312),
92     * '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983),
93     * '$C' = Korean Graphic Character Set (KSC 5601:1987),
94     * '$D' = Supplementary Japanese Graphic Character Set (JIS X0212),
95     * '$E' = CCITT Chinese Set (GB 2312 + GB 8565),
96     * '$G' = CNS 11643 plane 1,
97     * '$H' = CNS 11643 plane 2,
98     * '$I' = CNS 11643 plane 3,
99     * '$J' = CNS 11643 plane 4,
100     * '$K' = CNS 11643 plane 5,
101     * '$L' = CNS 11643 plane 6,
102     * '$M' = CNS 11643 plane 7,
103     * '$O' = JIS X 0213 plane 1,
104     * '$P' = JIS X 0213 plane 2,
105     * '$Q' = JIS X 0213-2004 Plane 1,
106     * and many others that are rarely used for e.g. traditional
107     * ideographic Vietnamese and BlissSymbolics;
108     * (double-byte 96x96-charsets)
109     * none standardized or in use on terminals AFAIK (Mule does use
110     * some internally)
111     */
112    uint32_t gn[4];
113    /* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */
114    uint8_t ss;
115};
116
117struct screen
118{
119    /* Graphics stuff */
120    int init;
121    caca_canvas_t *cv;
122    uint32_t clearattr;
123    uint8_t fg, bg;   /* ANSI-context fg/bg */
124    uint8_t dfg, dbg; /* Default fg/bg */
125    uint8_t bold, blink, italics, negative, concealed, underline;
126    uint8_t faint, strike, proportional; /* unsupported */
127    struct iso2022_conv_state conv_state; /* charset mess */
128
129    /* Other stuff */
130    int visible;                 /* Draw canvas and border flag */
131    int fd;                      /* pty fd */
132    unsigned char *buf;          /* text buffer */
133    long int total;              /* buffer length */
134    char *title;                 /* tty title */
135    int bell;                    /* bell occuring */
136    unsigned int scroll, s1, s2; /* FIXME, ANSI scroll properties */
137    int pid;                     /* running program pid */
138    int changed;                 /* content was updated */
139
140    int x, y;                    /* Canvas position */
141    int w, h;                    /* Canvas size */
142
143    int orig_x, orig_y;          /* Used by recurrents */
144    int orig_w, orig_h;          /* Used by recurrents */
145   
146    int report_mouse;            /* ANSI */
147};
148
149enum socket_type
150{
151    SOCK_SERVER=0,
152    SOCK_CLIENT=1
153};
154
155struct cube_props
156{
157    int in_switch;
158    int side;
159    long long unsigned int duration;
160};
161
162struct interpreter_props
163{
164    /* Input box */
165        struct input_box *box;
166};
167
168struct screensaver
169{
170    /* ScreenSaver stuff */
171    long long unsigned int timeout;     /* Screensaver timeout in us */
172    int in_screensaver;
173    void *data; 
174};
175
176struct comm
177{
178    /* Detaching */
179    int attached;                /* Are we attached to a terminal */
180    int socket[2];               /* Sockets to write to the server / to the client */
181    char *socket_path[2];        /* Sockets to write to the server / to the client */
182    char *socket_dir;            /* Where to create the socket */
183    char *session_name;          /* Name of the session */
184};
185
186struct lock
187{
188    int locked;
189    int lock_offset;
190    int lock_on_detach;
191    long long unsigned int  autolock_timeout;
192    char lockpass[1024];
193    char lockmsg[1024];   
194};
195
196struct modals
197{
198    /* Add-ons*/
199    int mini;                    /* Thumbnails */
200    int status;                  /* Status bar */
201    int help;                    /* Help */
202    int python_command;          /* Python command */
203    int window_list;             /* Window list */
204    int cur_in_list;             /* Window list */ 
205};
206
207struct sys
208{
209    char *default_shell;
210    char *user_path;
211    int  *to_grab;
212    char **to_start;
213    int  nb_to_grab;
214    int  attach, forceattach;   
215};
216
217struct screen_list
218{
219    int outfd;                   /* Debug */
220    int in_bell;                 /* Bell occuring in a window  */
221    int was_in_bell;
222    int dont_update_coords;      /* Used by recurrents */
223    int changed;                 /* Global redraw (e.g. adding a screen) */
224    int delay;                   /* Minimal time between two refresh (ms) */
225    int requested_delay;
226    int force_refresh;
227    int need_refresh;            /* If we skipped a refresh, do it next time */
228    int command;
229    int eyecandy;                /* Eye Candy */
230   
231    long long unsigned int last_key_time;
232    long long unsigned int last_refresh_time;
233   
234    struct comm comm;            /* Client/Server communications */
235    struct lock lock;            /* Lock */
236    struct modals modals;        /* Modal windows */
237    struct interpreter_props interpreter_props; /* Python interpreter */
238    struct screensaver screensaver;/* Screensaver stuff */
239   
240    int pty, prevpty;            /* Current and previous window */
241    int count;                   /* Window count */
242    int wm_type;                 /* Window manager type */   
243    int border_size;             /* Borders */
244    struct cube_props cube;      /* Cube */
245    long long unsigned int last_switch; /* Cube */
246   
247    struct screen **screen;      /* Windows */
248    struct option *config;       /* Option parsing and configuration */
249    struct sys sys;              /* System stuff */
250   
251    struct recurrent_list *recurrent_list;  /* Recurrents functions */
252   
253    char *title;                 /* Window title */
254    int width, height;           /* caca window size */
255    int old_x, old_y;            /* Mouse */
256    int mouse_button;
257    caca_canvas_t *cv;
258    caca_display_t *dp;
259};
260
261/* Configuration */
262struct option
263{
264    char *key;
265    char *value;
266   
267    struct option *next;
268};
269struct config_line
270{
271    const char name[32];
272    int  (*set) (const char *argv, struct screen_list * screen_list);
273    char* (*get) (struct screen_list * screen_list);
274};
275
276/* Recurrents */
277struct recurrent
278{
279    int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
280    void *user;
281    long long unsigned int  start_time;
282    int kill_me;
283};
284
285struct recurrent_list
286{
287    int count;
288    struct recurrent **recurrent;
289};
290
291
292
293void version(void);
294void usage(int argc, char **argv);
295
296int handle_command_line(int argc, char *argv[], struct screen_list *screen_list);
297
298struct screen_list *create_screen_list(void);
299void free_screen_list(struct screen_list *screen_list);
300
301int start_client(struct screen_list * screen_list);
302/** \defgroup client neercs client
303 * @{ */
304void mainloop(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
388
389/* Recurrents */
390int handle_recurrents(struct screen_list* screen_list);
391int add_recurrent(struct recurrent_list *list,
392                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
393                  void *user);
394int remove_recurrent(struct recurrent_list *list, int n);
395
396
397
398/* Configuration file */
399int read_configuration_file(char *filename, struct screen_list *screen_list);
400int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
401int get_key_value(char *line, struct option *option);
402int fill_config(struct screen_list *screen_list);
403struct config_line *get_config(const char *name);
404struct config_line *get_config_option(void);
405
406/* Python interpreter */
407#ifdef USE_PYTHON
408int python_init(struct screen_list *sl);
409int python_close(struct screen_list *sl);
410int  python_command_handle_key(struct screen_list *screen_list, unsigned int c);
411void draw_python_command(struct screen_list *screen_list);
412#endif
413
414#if defined DEBUG
415#   include <stdio.h>
416#   include <stdarg.h>
417static inline void debug(const char *format, ...)
418{
419    va_list args;
420    va_start(args, format);
421    fprintf(stderr, "** neercs debug ** ");
422    vfprintf(stderr, format, args);
423    fprintf(stderr, "\n");
424    va_end(args);
425}
426#else
427#   define debug(format, ...) do {} while(0)
428#endif
429#endif /* _NEERCS_H_ */
Note: See TracBrowser for help on using the repository browser.