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

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