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: effects.c 2360 2008-06-11 16:23:46Z 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 <stdio.h> |
---|
17 | #include <stdlib.h> |
---|
18 | #include <string.h> |
---|
19 | #include <cucul.h> |
---|
20 | #include <caca.h> |
---|
21 | #include <config.h> |
---|
22 | #include <time.h> |
---|
23 | #include <sys/wait.h> |
---|
24 | #include <sys/types.h> |
---|
25 | |
---|
26 | #include "neercs.h" |
---|
27 | |
---|
28 | void draw_thumbnails(struct screen_list *screen_list) |
---|
29 | { |
---|
30 | char const * const *fonts; |
---|
31 | cucul_dither_t *d; |
---|
32 | cucul_font_t *f; |
---|
33 | uint8_t *buf; |
---|
34 | int i; |
---|
35 | int miniw, minih; |
---|
36 | |
---|
37 | if(screen_list->count) |
---|
38 | { |
---|
39 | fonts = cucul_get_font_list(); |
---|
40 | f = cucul_load_font(fonts[0], 0); |
---|
41 | |
---|
42 | miniw = cucul_get_canvas_width(screen_list->screen[0]->cv) |
---|
43 | * cucul_get_font_width(f); |
---|
44 | minih = cucul_get_canvas_height(screen_list->screen[0]->cv) |
---|
45 | * cucul_get_font_height(f); |
---|
46 | buf = malloc(4 * miniw * minih); |
---|
47 | |
---|
48 | #if defined(HAVE_ENDIAN_H) |
---|
49 | if(__BYTE_ORDER == __BIG_ENDIAN) |
---|
50 | #else |
---|
51 | /* This is compile-time optimised with at least -O1 or -Os */ |
---|
52 | uint32_t const tmp = 0x12345678; |
---|
53 | if(*(uint8_t const *)&tmp == 0x12) |
---|
54 | #endif |
---|
55 | d = cucul_create_dither(32, miniw, minih, 4 * miniw, |
---|
56 | 0xff0000, 0xff00, 0xff, 0x0); |
---|
57 | else |
---|
58 | d = cucul_create_dither(32, miniw, minih, 4 * miniw, |
---|
59 | 0xff00, 0xff0000, 0xff000000, 0x0); |
---|
60 | |
---|
61 | for(i = 0; i < screen_list->count; i++) |
---|
62 | { |
---|
63 | cucul_render_canvas(screen_list->screen[i]->cv, f, buf, |
---|
64 | miniw, minih, miniw * 4); |
---|
65 | cucul_dither_bitmap(screen_list->cv, 20 * i, |
---|
66 | cucul_get_canvas_height(screen_list->cv) - 6, 19, 6, d, buf); |
---|
67 | cucul_set_color_ansi(screen_list->cv, CUCUL_WHITE, CUCUL_BLUE); |
---|
68 | |
---|
69 | if(screen_list->pty == i) |
---|
70 | cucul_draw_cp437_box(screen_list->cv,20 * i, |
---|
71 | cucul_get_canvas_height(screen_list->cv) - 6, 19, 6); |
---|
72 | cucul_printf(screen_list->cv, 20 * i, |
---|
73 | cucul_get_canvas_height(screen_list->cv) - 6, "(%i)", i+1); |
---|
74 | } |
---|
75 | |
---|
76 | cucul_free_dither(d); |
---|
77 | cucul_free_font(f); |
---|
78 | |
---|
79 | free(buf); |
---|
80 | } |
---|
81 | |
---|
82 | } |
---|
83 | |
---|
84 | /* FIXME, make this stuff more configurable */ |
---|
85 | void draw_status(struct screen_list *screen_list) |
---|
86 | { |
---|
87 | int x = 0, y = cucul_get_canvas_height(screen_list->cv) - 1; |
---|
88 | |
---|
89 | |
---|
90 | cucul_set_color_ansi(screen_list->cv, CUCUL_BLUE, CUCUL_BLUE); |
---|
91 | cucul_fill_box(screen_list->cv, |
---|
92 | x, y, |
---|
93 | cucul_get_canvas_width(screen_list->cv), 1, '#'); |
---|
94 | |
---|
95 | /* Hour */ |
---|
96 | { |
---|
97 | time_t now = time ((time_t *) 0); |
---|
98 | struct tm *t = localtime(&now); |
---|
99 | char hour[256]; |
---|
100 | sprintf(hour, "%02d:%02d", t->tm_hour, t->tm_min); |
---|
101 | |
---|
102 | cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); |
---|
103 | cucul_printf(screen_list->cv, x, y, |
---|
104 | "["); |
---|
105 | |
---|
106 | cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); |
---|
107 | cucul_printf(screen_list->cv, x+1, y, |
---|
108 | hour); |
---|
109 | cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); |
---|
110 | cucul_printf(screen_list->cv, x + strlen(hour) + 1, y, |
---|
111 | "]"); |
---|
112 | x += 7; |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | /* Window */ |
---|
117 | { |
---|
118 | char text[256]; |
---|
119 | sprintf(text, "%d/%d", screen_list->pty+1, screen_list->count); |
---|
120 | x++; |
---|
121 | cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); |
---|
122 | cucul_printf(screen_list->cv, x, y, "Window:"); |
---|
123 | cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); |
---|
124 | cucul_printf(screen_list->cv, x+8, y, text); |
---|
125 | x+= 8+strlen(text); |
---|
126 | } |
---|
127 | |
---|
128 | /* Window Manager */ |
---|
129 | { |
---|
130 | char text[256]; |
---|
131 | |
---|
132 | switch(screen_list->wm_type) |
---|
133 | { |
---|
134 | case WM_CARD: |
---|
135 | strcpy(text, "card"); |
---|
136 | break; |
---|
137 | case WM_HSPLIT: |
---|
138 | strcpy(text, "hsplit"); |
---|
139 | break; |
---|
140 | case WM_VSPLIT: |
---|
141 | strcpy(text, "vsplit"); |
---|
142 | break; |
---|
143 | case WM_FULL: |
---|
144 | default: |
---|
145 | strcpy(text, "full"); |
---|
146 | break; |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | x++; |
---|
151 | cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); |
---|
152 | cucul_printf(screen_list->cv, x, y, "WM:"); |
---|
153 | cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); |
---|
154 | cucul_printf(screen_list->cv, x+4, y, text); |
---|
155 | x+= 4+strlen(text); |
---|
156 | } |
---|
157 | |
---|
158 | /* Help (must be the last one )*/ |
---|
159 | { |
---|
160 | char text[256]; |
---|
161 | sprintf(text, "Help: ctrl-a-h"); |
---|
162 | x = cucul_get_canvas_width(screen_list->cv) - strlen(text); |
---|
163 | |
---|
164 | cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); |
---|
165 | cucul_printf(screen_list->cv, x, y, text); |
---|
166 | } |
---|
167 | |
---|
168 | |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | void draw_help(struct screen_list *screen_list) |
---|
173 | { |
---|
174 | int w = 65, h = 20; |
---|
175 | int x = (cucul_get_canvas_width(screen_list->cv) - w) / 2; |
---|
176 | int y = (cucul_get_canvas_height(screen_list->cv) - h) / 2; |
---|
177 | |
---|
178 | |
---|
179 | cucul_set_color_ansi(screen_list->cv, CUCUL_BLUE, CUCUL_BLUE); |
---|
180 | cucul_fill_box(screen_list->cv, |
---|
181 | x, y, |
---|
182 | w, h, '#'); |
---|
183 | cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); |
---|
184 | cucul_draw_cp437_box(screen_list->cv, |
---|
185 | x, y, |
---|
186 | w, h); |
---|
187 | |
---|
188 | x+=2; |
---|
189 | y++; |
---|
190 | cucul_printf(screen_list->cv, |
---|
191 | (cucul_get_canvas_width(screen_list->cv) - strlen(PACKAGE_STRING)) / 2, |
---|
192 | y-1, |
---|
193 | PACKAGE_STRING); |
---|
194 | cucul_printf(screen_list->cv, x, y++, "Copyright (c) 2006-2008 "); |
---|
195 | cucul_printf(screen_list->cv, x, y++, " Sam Hocevar <sam@zoy.org>"); |
---|
196 | cucul_printf(screen_list->cv, x, y++, " Jean-Yves Lamoureux <jylam@lnxscene.org>"); |
---|
197 | cucul_printf(screen_list->cv, x, y++, " Pascal Terjan <pterjan@linuxfr.org>"); |
---|
198 | cucul_printf(screen_list->cv, x, y++, ""); |
---|
199 | cucul_printf(screen_list->cv, x, y++, ""); |
---|
200 | cucul_printf(screen_list->cv, x, y++, "All shortcuts are in format 'ctrl-a-X' where X is :"); |
---|
201 | cucul_printf(screen_list->cv, x, y++, "n:\t Next window"); |
---|
202 | cucul_printf(screen_list->cv, x, y++, "p:\t Previous window"); |
---|
203 | cucul_printf(screen_list->cv, x, y++, "w:\t Switch window manager"); |
---|
204 | cucul_printf(screen_list->cv, x, y++, "c:\t Create new window"); |
---|
205 | cucul_printf(screen_list->cv, x, y++, "m:\t Thumbnails"); |
---|
206 | cucul_printf(screen_list->cv, x, y++, "d:\t Detach"); |
---|
207 | cucul_printf(screen_list->cv, x, y++, "k:\t Close window and kill associated process"); |
---|
208 | cucul_printf(screen_list->cv, x, y++, "h:\t This help"); |
---|
209 | cucul_printf(screen_list->cv, x, y++, ""); |
---|
210 | cucul_printf(screen_list->cv, x, y++, ""); |
---|
211 | cucul_printf(screen_list->cv, x, y++, "See http://libcaca.zoy.org/wiki/neercs for more informations"); |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | /* Close a window by animating it collapsing */ |
---|
217 | /* Total close time */ |
---|
218 | #define DELAY 500000.0f |
---|
219 | int close_screen_recurrent(struct screen_list* screen_list, struct recurrent* rec, void *user, long long unsigned int t) |
---|
220 | { |
---|
221 | long long unsigned int delta = t - rec->start_time; |
---|
222 | |
---|
223 | screen_list->dont_update_coords = 1; |
---|
224 | rec->kill_me = 0; |
---|
225 | if(delta>=DELAY) |
---|
226 | { |
---|
227 | rec->kill_me = 1; |
---|
228 | remove_screen(screen_list, screen_list->pty, 1); |
---|
229 | screen_list->pty = screen_list->prevpty; |
---|
230 | screen_list->prevpty = 0; |
---|
231 | screen_list->dont_update_coords = 0; |
---|
232 | } |
---|
233 | else |
---|
234 | { |
---|
235 | float r = 1 - ((DELAY - (DELAY - delta)) / DELAY); |
---|
236 | cucul_canvas_t *old, *new; |
---|
237 | struct screen *s = screen_list->screen[screen_list->pty]; |
---|
238 | int w = s->orig_w * r; |
---|
239 | int h = s->orig_h * r; |
---|
240 | |
---|
241 | /* libcucul canvas resize function is bugged, do it by hand */ |
---|
242 | old = s->cv; |
---|
243 | new = cucul_create_canvas(w, h); |
---|
244 | cucul_blit(new, 0, 0, old, NULL); |
---|
245 | s->cv = new; |
---|
246 | cucul_free_canvas(old); |
---|
247 | set_tty_size(s->fd, w, h); |
---|
248 | |
---|
249 | s->w = w; |
---|
250 | s->h = h; |
---|
251 | |
---|
252 | s->x = |
---|
253 | (s->orig_x * r) + |
---|
254 | ((s->orig_w/2) - s->w/2); |
---|
255 | s->y = |
---|
256 | (s->orig_y * r) + |
---|
257 | ((s->orig_h/2) - s->h/2); |
---|
258 | } |
---|
259 | return 1; |
---|
260 | } |
---|