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

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