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