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 2468 2008-06-20 13:25:34Z 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 | #include <stdint.h> |
---|
17 | #include <caca.h> |
---|
18 | |
---|
19 | enum wm_types |
---|
20 | { |
---|
21 | WM_FULL, |
---|
22 | WM_CARD, |
---|
23 | WM_HSPLIT, |
---|
24 | WM_VSPLIT, |
---|
25 | |
---|
26 | WM_MAX, |
---|
27 | }; |
---|
28 | |
---|
29 | |
---|
30 | struct option |
---|
31 | { |
---|
32 | char *key; |
---|
33 | char *value; |
---|
34 | |
---|
35 | struct option *next; |
---|
36 | }; |
---|
37 | |
---|
38 | |
---|
39 | struct screen |
---|
40 | { |
---|
41 | /* Graphics stuff */ |
---|
42 | int init; |
---|
43 | cucul_canvas_t *cv; |
---|
44 | uint32_t clearattr; |
---|
45 | uint8_t fg, bg; /* ANSI-context fg/bg */ |
---|
46 | uint8_t dfg, dbg; /* Default fg/bg */ |
---|
47 | uint8_t bold, blink, italics, negative, concealed, underline; |
---|
48 | uint8_t faint, strike, proportional; /* unsupported */ |
---|
49 | |
---|
50 | /* Other stuff */ |
---|
51 | int visible; /* Draw canvas and border flag */ |
---|
52 | int fd; /* pty fd */ |
---|
53 | unsigned char *buf; /* text buffer */ |
---|
54 | long int total; /* buffer length */ |
---|
55 | char *title; /* tty title */ |
---|
56 | int bell; /* bell occuring */ |
---|
57 | unsigned int scroll, s1, s2; /* FIXME, ANSI scroll properties */ |
---|
58 | int pid; /* running program pid */ |
---|
59 | |
---|
60 | int x, y; /* Canvas position */ |
---|
61 | int w, h; /* Canvas size */ |
---|
62 | |
---|
63 | int orig_x, orig_y; /* Used by recurrents */ |
---|
64 | int orig_w, orig_h; /* Used by recurrents */ |
---|
65 | |
---|
66 | }; |
---|
67 | |
---|
68 | struct screen_list |
---|
69 | { |
---|
70 | int wm_type; /* Window manager type */ |
---|
71 | int in_bell; /* Bell occuring in a window */ |
---|
72 | int dont_update_coords; /* Used by recurrents */ |
---|
73 | int attached; /* Are we attached to a terminal */ |
---|
74 | |
---|
75 | /* Lock */ |
---|
76 | int locked; |
---|
77 | char lockpass[1024]; |
---|
78 | char lockmsg[1024]; |
---|
79 | |
---|
80 | /* Add-ons*/ |
---|
81 | int mini; /* Thumbnails */ |
---|
82 | int status; /* Status bar */ |
---|
83 | int help; /* help */ |
---|
84 | |
---|
85 | /* ScreenSaver stuff */ |
---|
86 | long long unsigned int screensaver_timeout; /* Screensaver timeout in us */ |
---|
87 | int in_screensaver; |
---|
88 | void *screensaver_data; |
---|
89 | |
---|
90 | int pty, prevpty; /* Current and previous window */ |
---|
91 | int count; /* Window count */ |
---|
92 | int width, height; /* caca window size */ |
---|
93 | struct screen **screen; /* Windows */ |
---|
94 | |
---|
95 | struct option *config; |
---|
96 | |
---|
97 | }; |
---|
98 | |
---|
99 | |
---|
100 | struct recurrent |
---|
101 | { |
---|
102 | int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t); |
---|
103 | void *user; |
---|
104 | long long unsigned int start_time; |
---|
105 | int kill_me; |
---|
106 | }; |
---|
107 | |
---|
108 | struct recurrent_list |
---|
109 | { |
---|
110 | int count; |
---|
111 | struct recurrent **recurrent; |
---|
112 | }; |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | void version(void); |
---|
117 | void usage(int argc, char **argv); |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid); |
---|
122 | int create_pty_grab(pid_t pid, unsigned int w, unsigned int h); |
---|
123 | int grab_process(pid_t pid, char *ptyname, int ptyfd); |
---|
124 | |
---|
125 | long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size); |
---|
126 | int set_tty_size(int fd, unsigned int w, unsigned int h); |
---|
127 | int update_terms(struct screen_list* screen_list); |
---|
128 | void refresh_screens(cucul_canvas_t *cv, |
---|
129 | caca_display_t *dp, |
---|
130 | struct screen_list *screen_list); |
---|
131 | int update_screens_contents(struct screen_list* screen_list); |
---|
132 | long long get_ms(void); |
---|
133 | |
---|
134 | int detach(struct screen_list* screen_list, caca_display_t * dp); |
---|
135 | |
---|
136 | /* Screens management */ |
---|
137 | struct screen* create_screen(int w, int h, char *command); |
---|
138 | struct screen* create_screen_grab(int w, int h, int pid); |
---|
139 | int destroy_screen(struct screen *s); |
---|
140 | int add_screen(struct screen_list *list, struct screen *s); |
---|
141 | int remove_screen(struct screen_list *list, int n, int please_kill); |
---|
142 | void resize_screen(struct screen *s, int z, int h); |
---|
143 | |
---|
144 | /* Window managers */ |
---|
145 | void update_windows_props(cucul_canvas_t *cv, struct screen_list *screen_list); |
---|
146 | void update_windows_props_cards(cucul_canvas_t *cv, struct screen_list *screen_list); |
---|
147 | void update_windows_props_hsplit(cucul_canvas_t *cv, struct screen_list *screen_list); |
---|
148 | void update_windows_props_full(cucul_canvas_t *cv, struct screen_list *screen_list); |
---|
149 | void update_windows_props_vsplit(cucul_canvas_t *cv, struct screen_list *screen_list); |
---|
150 | |
---|
151 | /* Effects and addons */ |
---|
152 | void draw_thumbnails(cucul_canvas_t *cv, struct screen_list *screen_list); |
---|
153 | void draw_status(cucul_canvas_t *cv, struct screen_list *screen_list); |
---|
154 | void draw_help(cucul_canvas_t *cv, struct screen_list *screen_list); |
---|
155 | void draw_lock(cucul_canvas_t *cv, struct screen_list *screen_list); |
---|
156 | int validate_lock(struct screen_list *screen_list, char *user, char *pass); |
---|
157 | |
---|
158 | int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t); |
---|
159 | |
---|
160 | |
---|
161 | /* Screensavers */ |
---|
162 | void screensaver_init(cucul_canvas_t *cv, |
---|
163 | caca_display_t *dp, |
---|
164 | struct screen_list *screen_list); |
---|
165 | void screensaver_kill(cucul_canvas_t *cv, |
---|
166 | caca_display_t *dp, |
---|
167 | struct screen_list *screen_list); |
---|
168 | |
---|
169 | void draw_screensaver(cucul_canvas_t *cv, |
---|
170 | caca_display_t *dp, |
---|
171 | struct screen_list *screen_list); |
---|
172 | void screensaver_flying_toasters(cucul_canvas_t *cv, |
---|
173 | caca_display_t *dp, |
---|
174 | struct screen_list *screen_list); |
---|
175 | |
---|
176 | void screensaver_flying_toasters_init(cucul_canvas_t *cv, |
---|
177 | caca_display_t *dp, |
---|
178 | struct screen_list *screen_list); |
---|
179 | |
---|
180 | void screensaver_flying_toasters_kill(cucul_canvas_t *cv, |
---|
181 | caca_display_t *dp, |
---|
182 | struct screen_list *screen_list); |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | /* Recurrents */ |
---|
187 | int add_recurrent(struct recurrent_list *list, |
---|
188 | int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t), |
---|
189 | void *user); |
---|
190 | int remove_recurrent(struct recurrent_list *list, int n); |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | /* Configuration file */ |
---|
195 | int read_configuration_file(char *filename, struct screen_list *screen_list); |
---|
196 | int parse_conf_line(char *buf, int size, struct screen_list *screen_list); |
---|
197 | int get_key_value(char *line, struct option *option); |
---|
198 | int fill_config(struct screen_list *screen_list); |
---|
199 | |
---|
200 | #if 0 |
---|
201 | # define debug(f, z...) fprintf(stderr, f "\n", z) |
---|
202 | #else |
---|
203 | # define debug(f, z...) do {} while(0) |
---|
204 | #endif |
---|
205 | |
---|