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

Last change on this file since 3974 was 3974, checked in by jylam, 5 years ago
  • Moved client initialisation to client.c
  • Property svn:keywords set to Id
File size: 12.0 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$
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#include <stdint.h>
17
18#include <caca.h>
19
20enum wm_types
21{
22    WM_FULL,
23    WM_CARD,
24    WM_HSPLIT,
25    WM_VSPLIT,
26    WM_CUBE,
27
28    WM_MAX,
29};
30
31struct option
32{
33    char *key;
34    char *value;
35
36    struct option *next;
37};
38
39
40
41/* ISO-2022 Conversion State */
42struct iso2022_conv_state
43{
44    /* cs = coding system/coding method: */
45    /* (with standard return) */
46    /* '@' = ISO-2022, */
47    /* 'G' = UTF-8 without implementation level, */
48    /* '8' = UTF-8 (Linux console and imitators), */
49    /* and many others that are rarely used; */
50    /* (without standard return) */
51    /* '/G' = UTF-8 Level 1, */
52    /* '/H' = UTF-8 Level 2, */
53    /* '/I' = UTF-8 Level 3, */
54    /* and many others that are rarely used */
55    uint32_t cs;
56    /* ctrl8bit = allow 8-bit controls */
57    uint8_t ctrl8bit;
58    /* cn[0] = C0 control charset (0x00 ... 0x1f):
59     * '@' = ISO 646,
60     * '~' = empty,
61     * and many others that are rarely used */
62    /* cn[1] = C1 control charset (0x80 ... 0x9f):
63     * 'C' = ISO 6429-1983,
64     * '~' = empty,
65     * and many others that are rarely used */
66    uint32_t cn[2];
67    /* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e,
68     *                              94x94-char. 0x21/0x21 ... 0x7e/0x7e),
69     * and
70     * glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe,
71     *                              96-char. 0xa0 ... 0xff,
72     *                              94x94-char. 0xa1/0xa1 ... 0xfe/0xfe,
73     *                              96x96-char. 0xa0/0xa0 ... 0xff/0xff):
74     * 0 = G0, 1 = G1, 2 = G2, 3 = G3 */
75    uint8_t glr[2];
76    /* gn[i] = G0/G1/G2/G3 graphic charset state:
77     * (94-char. sets)
78     * '0' = DEC ACS (VT100 and imitators),
79     * 'B' = US-ASCII,
80     * and many others that are rarely used for e.g. various national ASCII variations;
81     * (96-char. sets)
82     * '.A' = ISO 8859-1 "Latin 1" GR,
83     * '.~' = empty 96-char. set,
84     * and many others that are rarely used for e.g. ISO 8859-n GR;
85     * (double-byte 94x94-charsets)
86     * '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978),
87     * '$A' = Chinese Character Set (GB 2312),
88     * '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983),
89     * '$C' = Korean Graphic Character Set (KSC 5601:1987),
90     * '$D' = Supplementary Japanese Graphic Character Set (JIS X0212),
91     * '$E' = CCITT Chinese Set (GB 2312 + GB 8565),
92     * '$G' = CNS 11643 plane 1,
93     * '$H' = CNS 11643 plane 2,
94     * '$I' = CNS 11643 plane 3,
95     * '$J' = CNS 11643 plane 4,
96     * '$K' = CNS 11643 plane 5,
97     * '$L' = CNS 11643 plane 6,
98     * '$M' = CNS 11643 plane 7,
99     * '$O' = JIS X 0213 plane 1,
100     * '$P' = JIS X 0213 plane 2,
101     * '$Q' = JIS X 0213-2004 Plane 1,
102     * and many others that are rarely used for e.g. traditional
103     * ideographic Vietnamese and BlissSymbolics;
104     * (double-byte 96x96-charsets)
105     * none standardized or in use on terminals AFAIK (Mule does use
106     * some internally)
107     */
108    uint32_t gn[4];
109    /* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */
110    uint8_t ss;
111};
112
113struct screen
114{
115    /* Graphics stuff */
116    int init;
117    caca_canvas_t *cv;
118    uint32_t clearattr;
119    uint8_t fg, bg;   /* ANSI-context fg/bg */
120    uint8_t dfg, dbg; /* Default fg/bg */
121    uint8_t bold, blink, italics, negative, concealed, underline;
122    uint8_t faint, strike, proportional; /* unsupported */
123    struct iso2022_conv_state conv_state; /* charset mess */
124
125    /* Other stuff */
126    int visible;                 /* Draw canvas and border flag */
127    int fd;                      /* pty fd */
128    unsigned char *buf;          /* text buffer */
129    long int total;              /* buffer length */
130    char *title;                 /* tty title */
131    int bell;                    /* bell occuring */
132    unsigned int scroll, s1, s2; /* FIXME, ANSI scroll properties */
133    int pid;                     /* running program pid */
134    int changed;                 /* content was updated */
135
136    int x, y;                    /* Canvas position */
137    int w, h;                    /* Canvas size */
138
139    int orig_x, orig_y;          /* Used by recurrents */
140    int orig_w, orig_h;          /* Used by recurrents */
141};
142
143enum socket_type
144{
145    SOCK_SERVER=0,
146    SOCK_CLIENT=1
147};
148
149struct cube_props
150{
151    int in_switch;
152        int side;
153    long long unsigned int duration;
154};
155
156struct screen_list
157{
158    int wm_type;                 /* Window manager type */
159    int in_bell;                 /* Bell occuring in a window  */
160    int dont_update_coords;      /* Used by recurrents */
161    int changed;                 /* Global redraw needed (e.g. adding a screen) */
162    int delay;                   /* Minimal time between two refresh (ms) */
163    int force_refresh;
164    long long unsigned int last_key_time;
165    int command;
166    int was_in_bell;
167    long long unsigned int last_refresh_time;
168
169
170    /* Detaching */
171    int attached;                /* Are we attached to a terminal */
172    int socket[2];               /* Sockets to write to the server / to the client */
173    char *socket_path[2];        /* Sockets to write to the server / to the client */
174    char *socket_dir;            /* Where to create the socket */
175    char *session_name;          /* Name of the session */
176
177    /* Lock */
178    int locked;
179    int lock_offset;
180    int lock_on_detach;
181    long long unsigned int  autolock_timeout;
182    char lockpass[1024];
183    char lockmsg[1024];
184
185    /* Add-ons*/
186    int mini;                    /* Thumbnails */
187    int status;                  /* Status bar */
188    int help;                    /* Help */
189    int window_list;             /* Window list */
190    int cur_in_list;             /* Window list */
191    char *title;                 /* Window title */
192    struct cube_props cube;      /* Cube */
193    long long unsigned int last_switch; /* Cube */
194
195    /* ScreenSaver stuff */
196    long long unsigned int screensaver_timeout;     /* Screensaver timeout in us */
197    int in_screensaver;
198    void *screensaver_data;
199
200    int pty, prevpty;            /* Current and previous window */
201    int count;                   /* Window count */
202    int width, height;           /* caca window size */
203    struct screen **screen;      /* Windows */
204
205    /* Option parsing and configuration */
206    struct option *config;
207    char *default_shell;
208    struct recurrent_list *recurrent_list;
209    char *user_path;
210    int *to_grab;
211    char **to_start;
212    int nb_to_grab;
213    int attach, forceattach;
214    int requested_delay;
215
216    caca_canvas_t *cv;
217    caca_display_t *dp;
218};
219
220
221struct recurrent
222{
223    int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
224    void *user;
225    long long unsigned int  start_time;
226    int kill_me;
227};
228
229struct recurrent_list
230{
231    int count;
232    struct recurrent **recurrent;
233};
234
235
236
237void version(void);
238void usage(int argc, char **argv);
239
240int handle_command_line(int argc, char *argv[], struct screen_list *screen_list);
241
242struct screen_list *create_screen_list(void);
243void free_screen_list(struct screen_list *screen_list);
244
245int start_client(struct screen_list * screen_list);
246void mainloop(struct screen_list *screen_list);
247
248int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
249int create_pty_grab(long pid, unsigned int w, unsigned int h, int *cpid);
250int grab_process(long pid, char *ptyname, int ptyfd, int *newpid);
251long select_process(struct screen_list* screen_list);
252
253long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
254int set_tty_size(int fd, unsigned int w, unsigned int h);
255int update_terms(struct screen_list* screen_list);
256void refresh_screens(struct screen_list *screen_list);
257int update_screens_contents(struct screen_list* screen_list);
258long long get_us(void);
259
260void attach(struct screen_list* screen_list);
261int detach(struct screen_list* screen_list);
262int request_attach(struct screen_list* screen_list);
263char * build_socket_path(char *socket_dir, char *session_name, enum socket_type socktype);
264int create_socket(struct screen_list* screen_list, enum socket_type socktype);
265char * connect_socket(struct screen_list* screen_list, enum socket_type socktype);
266char ** list_sockets(char *socket_dir, char *session_name);
267int start_server(struct screen_list *screen_list);
268int send_event(caca_event_t ev, struct screen_list* screen_list);
269int send_delay(struct screen_list* screen_list);
270
271/* Screens management */
272struct screen* create_screen(int w, int h, char *command);
273struct screen* create_screen_grab(int w, int h, int pid);
274int destroy_screen(struct screen *s);
275int add_screen(struct screen_list *list, struct screen *s);
276int remove_screen(struct screen_list *list, int n, int please_kill);
277void resize_screen(struct screen *s, int z, int h);
278
279/* Window managers */
280void update_windows_props(struct screen_list *screen_list);
281void update_windows_props_cards(struct screen_list *screen_list);
282void update_windows_props_hsplit(struct screen_list *screen_list);
283void update_windows_props_full(struct screen_list *screen_list);
284void update_windows_props_vsplit(struct screen_list *screen_list);
285void update_windows_props_cube(struct screen_list *screen_list);
286
287void wm_refresh(struct screen_list *screen_list);
288void wm_refresh_card(struct screen_list *screen_list);
289void wm_refresh_cube(struct screen_list *screen_list);
290void wm_refresh_full(struct screen_list *screen_list);
291void wm_refresh_hsplit(struct screen_list *screen_list);
292void wm_refresh_vsplit(struct screen_list *screen_list);
293int switch_screen_recurrent(struct screen_list* screen_list, struct recurrent* rec, void *user, long long unsigned int t);
294
295
296/* Effects and addons */
297void draw_thumbnails(struct screen_list *screen_list);
298void draw_status(struct screen_list *screen_list);
299void draw_help(struct screen_list *screen_list);
300int update_window_list(int c, struct screen_list *screen_list);
301void draw_list(struct screen_list *screen_list);
302void draw_lock(struct screen_list *screen_list);
303int update_lock(int c, struct screen_list *screen_list);
304int validate_lock(struct screen_list *screen_list, char *user, char *pass);
305
306int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
307
308/* Input to ANSI */
309void *convert_input_ansi(unsigned int *c, int *size);
310int  handle_command_input(struct screen_list*screen_list, unsigned int c);
311
312
313/* Screensavers */
314void screensaver_init(struct screen_list *screen_list);
315void screensaver_kill(struct screen_list *screen_list);
316
317void draw_screensaver(struct screen_list *screen_list);
318void screensaver_flying_toasters(struct screen_list *screen_list);
319
320void screensaver_flying_toasters_init(struct screen_list *screen_list);
321
322void screensaver_flying_toasters_kill(struct screen_list *screen_list);
323
324
325
326/* Recurrents */
327int handle_recurrents(struct screen_list* screen_list);
328int add_recurrent(struct recurrent_list *list,
329                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
330                  void *user);
331int remove_recurrent(struct recurrent_list *list, int n);
332
333
334
335/* Configuration file */
336int read_configuration_file(char *filename, struct screen_list *screen_list);
337int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
338int get_key_value(char *line, struct option *option);
339int fill_config(struct screen_list *screen_list);
340
341#if defined DEBUG
342#   include <stdio.h>
343#   include <stdarg.h>
344static inline void debug(const char *format, ...)
345{
346    va_list args;
347    va_start(args, format);
348    fprintf(stderr, "** neercs debug ** ");
349    vfprintf(stderr, format, args);
350    fprintf(stderr, "\n");
351    va_end(args);
352}
353#else
354#   define debug(format, ...) do {} while(0)
355#endif
356
Note: See TracBrowser for help on using the repository browser.