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

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