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

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