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

Last change on this file since 3946 was 3946, checked in by Jean-Yves Lamoureux, 11 years ago
  • Explode server.c a bit more. KABOOOOM. (Maybe) fix a bug of missing refresh after cube transition
  • Property svn:keywords set to Id
File size: 12.0 KB
RevLine 
[1437]1/*
2 *  neercs        console-based window manager
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
[2357]4 *                2008 Jean-Yves Lamoureux <jylam@lnxscene.org>
[1437]5 *                All Rights Reserved
6 *
7 *  $Id: neercs.h 3946 2009-11-18 17:09:26Z jylam $
8 *
[1459]9 *  This program is free software. It comes without any warranty, to
[1455]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
[1437]13 *  http://sam.zoy.org/wtfpl/COPYING for more details.
14 */
15
16#include <stdint.h>
[2505]17
[2426]18#include <caca.h>
[1437]19
[2362]20enum wm_types
21{
22    WM_FULL,
23    WM_CARD,
24    WM_HSPLIT,
25    WM_VSPLIT,
[3914]26    WM_CUBE,
[2357]27
[2362]28    WM_MAX,
29};
[2357]30
[2463]31struct option
32{
33    char *key;
34    char *value;
35
36    struct option *next;
37};
38
39
[2582]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
[1437]113struct screen
114{
115    /* Graphics stuff */
116    int init;
[2995]117    caca_canvas_t *cv;
[1437]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 */
[2582]123    struct iso2022_conv_state conv_state; /* charset mess */
[1437]124
125    /* Other stuff */
[2446]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 */
[3453]134    int changed;                 /* content was updated */
[2360]135
[2446]136    int x, y;                    /* Canvas position */
137    int w, h;                    /* Canvas size */
[2421]138
[2446]139    int orig_x, orig_y;          /* Used by recurrents */
140    int orig_w, orig_h;          /* Used by recurrents */
[1437]141};
142
[2614]143enum socket_type
144{
145    SOCK_SERVER=0,
146    SOCK_CLIENT=1
147};
148
[3914]149struct cube_props
150{
151    int in_switch;
152        int side;
[3939]153    long long unsigned int duration;
[3914]154};
155
[2357]156struct screen_list
157{
[2446]158    int wm_type;                 /* Window manager type */
159    int in_bell;                 /* Bell occuring in a window  */
160    int dont_update_coords;      /* Used by recurrents */
[3453]161    int changed;                 /* Global redraw needed (e.g. adding a screen) */
[3455]162    int delay;                   /* Minimal time between two refresh (ms) */
[3914]163    int force_refresh;
[3944]164    long long unsigned int last_key_time;
165    int command;
[3946]166    int was_in_bell;
167    long long unsigned int last_refresh_time;
[2474]168
[3946]169
[2474]170    /* Detaching */
[2458]171    int attached;                /* Are we attached to a terminal */
[2614]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 */
[2474]174    char *socket_dir;            /* Where to create the socket */
[2488]175    char *session_name;          /* Name of the session */
[2457]176
177    /* Lock */
178    int locked;
[2495]179    int lock_offset;
[3896]180    int lock_on_detach;
[2500]181    long long unsigned int  autolock_timeout;
[2457]182    char lockpass[1024];
183    char lockmsg[1024];
184
[2400]185    /* Add-ons*/
[2446]186    int mini;                    /* Thumbnails */
187    int status;                  /* Status bar */
[2641]188    int help;                    /* Help */
189    int window_list;             /* Window list */
190    int cur_in_list;             /* Window list */
[2784]191    char *title;                 /* Window title */
[3914]192    struct cube_props cube;      /* Cube */
193    long long unsigned int last_switch; /* Cube */
[2448]194
195    /* ScreenSaver stuff */
[2447]196    long long unsigned int screensaver_timeout;     /* Screensaver timeout in us */
[2448]197    int in_screensaver;
198    void *screensaver_data;
[2400]199
[2446]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 */
[2463]204
[2642]205    /* Option parsing and configuration */
[2463]206    struct option *config;
[2495]207    char *default_shell;
208    struct recurrent_list *recurrent_list;
[2642]209    char *user_path;
210    int *to_grab;
211    char **to_start;
212    int nb_to_grab;
213    int attach, forceattach;
[3456]214    int requested_delay;
[2463]215
[2995]216    caca_canvas_t *cv;
[2495]217    caca_display_t *dp;
[2357]218};
219
220
[2445]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
[2463]236
[2444]237void version(void);
[2468]238void usage(int argc, char **argv);
[2444]239
[2642]240int handle_command_line(int argc, char *argv[], struct screen_list *screen_list);
[2444]241
[2495]242struct screen_list *create_screen_list(void);
[3876]243void free_screen_list(struct screen_list *screen_list);
[2444]244
[3940]245void mainloop(struct screen_list *screen_list);
246
[2402]247int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
[3891]248int create_pty_grab(long pid, unsigned int w, unsigned int h, int *cpid);
249int grab_process(long pid, char *ptyname, int ptyfd, int *newpid);
[3874]250long select_process(struct screen_list* screen_list);
[2357]251
[2368]252long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
[2362]253int set_tty_size(int fd, unsigned int w, unsigned int h);
[2400]254int update_terms(struct screen_list* screen_list);
[2495]255void refresh_screens(struct screen_list *screen_list);
[2421]256int update_screens_contents(struct screen_list* screen_list);
[2473]257long long get_us(void);
[2359]258
[3324]259void attach(struct screen_list* screen_list);
[2588]260int detach(struct screen_list* screen_list);
261int request_attach(struct screen_list* screen_list);
[2614]262char * build_socket_path(char *socket_dir, char *session_name, enum socket_type socktype);
263int create_socket(struct screen_list* screen_list, enum socket_type socktype);
264char * connect_socket(struct screen_list* screen_list, enum socket_type socktype);
[2488]265char ** list_sockets(char *socket_dir, char *session_name);
[2673]266int start_server(struct screen_list *screen_list);
[2589]267int send_event(caca_event_t ev, struct screen_list* screen_list);
[3457]268int send_delay(struct screen_list* screen_list);
[2445]269
[2357]270/* Screens management */
271struct screen* create_screen(int w, int h, char *command);
[2426]272struct screen* create_screen_grab(int w, int h, int pid);
[2357]273int destroy_screen(struct screen *s);
274int add_screen(struct screen_list *list, struct screen *s);
[2371]275int remove_screen(struct screen_list *list, int n, int please_kill);
[2362]276void resize_screen(struct screen *s, int z, int h);
[2357]277
[2362]278/* Window managers */
[2495]279void update_windows_props(struct screen_list *screen_list);
280void update_windows_props_cards(struct screen_list *screen_list);
281void update_windows_props_hsplit(struct screen_list *screen_list);
282void update_windows_props_full(struct screen_list *screen_list);
283void update_windows_props_vsplit(struct screen_list *screen_list);
[3914]284void update_windows_props_cube(struct screen_list *screen_list);
[2357]285
[3914]286void wm_refresh(struct screen_list *screen_list);
287void wm_refresh_card(struct screen_list *screen_list);
288void wm_refresh_cube(struct screen_list *screen_list);
289void wm_refresh_full(struct screen_list *screen_list);
290void wm_refresh_hsplit(struct screen_list *screen_list);
291void wm_refresh_vsplit(struct screen_list *screen_list);
292int switch_screen_recurrent(struct screen_list* screen_list, struct recurrent* rec, void *user, long long unsigned int t);
293
294
[2367]295/* Effects and addons */
[2495]296void draw_thumbnails(struct screen_list *screen_list);
297void draw_status(struct screen_list *screen_list);
298void draw_help(struct screen_list *screen_list);
[2641]299int update_window_list(int c, struct screen_list *screen_list);
300void draw_list(struct screen_list *screen_list);
[2495]301void draw_lock(struct screen_list *screen_list);
302int update_lock(int c, struct screen_list *screen_list);
[2457]303int validate_lock(struct screen_list *screen_list, char *user, char *pass);
304
[2445]305int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
[2357]306
[2495]307/* Input to ANSI */
308void *convert_input_ansi(unsigned int *c, int *size);
309int  handle_command_input(struct screen_list*screen_list, unsigned int c);
[2367]310
[2495]311
[2447]312/* Screensavers */
[2495]313void screensaver_init(struct screen_list *screen_list);
314void screensaver_kill(struct screen_list *screen_list);
[2448]315
[2495]316void draw_screensaver(struct screen_list *screen_list);
317void screensaver_flying_toasters(struct screen_list *screen_list);
[2447]318
[2495]319void screensaver_flying_toasters_init(struct screen_list *screen_list);
[2447]320
[2495]321void screensaver_flying_toasters_kill(struct screen_list *screen_list);
[2448]322
323
324
[2445]325/* Recurrents */
[2495]326int handle_recurrents(struct screen_list* screen_list);
[2445]327int add_recurrent(struct recurrent_list *list,
328                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
329                  void *user);
330int remove_recurrent(struct recurrent_list *list, int n);
331
332
[2463]333
334/* Configuration file */
335int read_configuration_file(char *filename, struct screen_list *screen_list);
336int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
337int get_key_value(char *line, struct option *option);
338int fill_config(struct screen_list *screen_list);
339
[2510]340#if defined DEBUG
341#   include <stdio.h>
342#   include <stdarg.h>
343static inline void debug(const char *format, ...)
344{
345    va_list args;
346    va_start(args, format);
347    fprintf(stderr, "** neercs debug ** ");
348    vfprintf(stderr, format, args);
349    fprintf(stderr, "\n");
350    va_end(args);
351}
[1437]352#else
[2510]353#   define debug(format, ...) do {} while(0)
[1437]354#endif
355
Note: See TracBrowser for help on using the repository browser.