source: trunk/tools/neercs/old/effects.c @ 2090

Last change on this file since 2090 was 2090, checked in by sam, 7 years ago

neercs: added a better check for forkpty(), and moved the GL_POINTS
size and texture logic to the vertex shader.

  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1/*
2 *  neercs        console-based window manager
3 *  Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
4 *                2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org>
5 *                All Rights Reserved
6 *
7 *  This program is free software. It comes without any warranty, to
8 *  the extent permitted by applicable law. You can redistribute it
9 *  and/or modify it under the terms of the Do What The Fuck You Want
10 *  To Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14#if defined HAVE_CONFIG_H
15#   include "config.h"
16#endif
17
18#if !defined _WIN32
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <time.h>
24#include <endian.h>
25#include <sys/wait.h>
26#include <sys/types.h>
27#include <caca.h>
28
29#include "neercs.h"
30
31void draw_thumbnails(struct screen_list *screen_list)
32{
33    char const *const *fonts;
34    caca_dither_t *d;
35    caca_font_t *f;
36    uint8_t *buf;
37    int i, y =
38        caca_get_canvas_height(screen_list->cv) - 6 - screen_list->modals.status;
39    int miniw, minih;
40
41    if (screen_list->count)
42    {
43        fonts = caca_get_font_list();
44        f = caca_load_font(fonts[0], 0);
45
46        miniw = caca_get_canvas_width(screen_list->screen[0]->cv)
47            * caca_get_font_width(f);
48        minih = caca_get_canvas_height(screen_list->screen[0]->cv)
49            * caca_get_font_height(f);
50        buf = malloc(4 * miniw * minih);
51
52#if defined(HAVE_ENDIAN_H)
53        if (__BYTE_ORDER == __BIG_ENDIAN)
54#else
55        /* This is compile-time optimised with at least -O1 or -Os */
56        uint32_t const tmp = 0x12345678;
57        if (*(uint8_t const *)&tmp == 0x12)
58#endif
59            d = caca_create_dither(32, miniw, minih, 4 * miniw,
60                                   0xff0000, 0xff00, 0xff, 0x0);
61        else
62            d = caca_create_dither(32, miniw, minih, 4 * miniw,
63                                   0xff00, 0xff0000, 0xff000000, 0x0);
64
65        for (i = 0; i < screen_list->count; i++)
66        {
67            if (!screen_list->screen[i]->changed && !screen_list->changed)
68                continue;
69            caca_render_canvas(screen_list->screen[i]->cv, f, buf,
70                               miniw, minih, miniw * 4);
71            caca_dither_bitmap(screen_list->cv, 20 * i, y, 19, 6, d, buf);
72            caca_set_color_ansi(screen_list->cv, CACA_WHITE, CACA_BLUE);
73
74            if (screen_list->pty == i)
75                caca_draw_cp437_box(screen_list->cv, 20 * i, y, 19, 6);
76            caca_printf(screen_list->cv, 20 * i, y, "(%i)", i + 1);
77        }
78
79        caca_free_dither(d);
80        caca_free_font(f);
81
82        free(buf);
83    }
84
85}
86
87/* FIXME, make this stuff more configurable */
88void draw_status(struct screen_list *screen_list)
89{
90    int x = 0, y = caca_get_canvas_height(screen_list->cv) - 1;
91
92
93    /* caca_fill_box(screen_list->cv, x, y,
94       caca_get_canvas_width(screen_list->cv), 1, '#'); */
95
96    /* Hour */
97    {
98        time_t now = time((time_t *) 0);
99        struct tm *t = localtime(&now);
100        char hour[256];
101        sprintf(hour, "%02d:%02d", t->tm_hour, t->tm_min);
102
103        caca_set_color_ansi(screen_list->cv, CACA_LIGHTBLUE, CACA_BLUE);
104        caca_printf(screen_list->cv, x, y, "[");
105
106        caca_set_color_ansi(screen_list->cv, CACA_DEFAULT, CACA_BLUE);
107        caca_printf(screen_list->cv, x + 1, y, hour);
108        caca_set_color_ansi(screen_list->cv, CACA_LIGHTBLUE, CACA_BLUE);
109        caca_printf(screen_list->cv, x + strlen(hour) + 1, y, "]");
110        x += 7;
111
112    }
113
114    /* Window */
115    {
116        char text[256];
117        sprintf(text, "%d/%d", screen_list->pty + 1, screen_list->count);
118        caca_set_color_ansi(screen_list->cv, CACA_BLUE, CACA_BLUE);
119        caca_put_char(screen_list->cv, x, y, '#');
120        x++;
121        caca_set_color_ansi(screen_list->cv, CACA_LIGHTBLUE, CACA_BLUE);
122        caca_printf(screen_list->cv, x, y, "Window:");
123        caca_set_color_ansi(screen_list->cv, CACA_BLUE, CACA_BLUE);
124        caca_put_char(screen_list->cv, x + 7, y, '#');
125        caca_set_color_ansi(screen_list->cv, CACA_DEFAULT, CACA_BLUE);
126        caca_printf(screen_list->cv, x + 8, y, text);
127        x += 8 + strlen(text);
128    }
129
130    /* Window Manager */
131    {
132        char text[256];
133
134        switch (screen_list->wm_type)
135        {
136        case WM_CARD:
137            strcpy(text, "card");
138            break;
139        case WM_HSPLIT:
140            strcpy(text, "hsplit");
141            break;
142        case WM_VSPLIT:
143            strcpy(text, "vsplit");
144            break;
145        case WM_FULL:
146        default:
147            strcpy(text, "full");
148            break;
149
150        }
151
152        caca_set_color_ansi(screen_list->cv, CACA_BLUE, CACA_BLUE);
153        caca_put_char(screen_list->cv, x, y, '#');
154        x++;
155        caca_set_color_ansi(screen_list->cv, CACA_LIGHTBLUE, CACA_BLUE);
156        caca_printf(screen_list->cv, x, y, "WM:");
157        caca_set_color_ansi(screen_list->cv, CACA_BLUE, CACA_BLUE);
158        caca_put_char(screen_list->cv, x + 3, y, '#');
159        caca_set_color_ansi(screen_list->cv, CACA_DEFAULT, CACA_BLUE);
160        caca_printf(screen_list->cv, x + 4, y, text);
161        x += 4 + strlen(text);
162    }
163
164    /* Help (must be the last one ) */
165    {
166        char text[256];
167        sprintf(text, "Help: ctrl-a-?");
168        caca_set_color_ansi(screen_list->cv, CACA_BLUE, CACA_BLUE);
169        while (x <
170               (int)(caca_get_canvas_width(screen_list->cv) - strlen(text)))
171        {
172            caca_put_char(screen_list->cv, x, y, '#');
173            x++;
174        }
175        caca_set_color_ansi(screen_list->cv, CACA_DEFAULT, CACA_BLUE);
176        caca_printf(screen_list->cv, x, y, text);
177    }
178
179
180}
181
182
183
184int update_window_list(int c, struct screen_list *screen_list)
185{
186    debug("Got %x\n", c);
187
188    switch (c)
189    {
190    case 0x111:
191        if (screen_list->modals.cur_in_list > 0)
192            screen_list->modals.cur_in_list--;
193        break;
194    case 0x112:
195        if (screen_list->modals.cur_in_list < screen_list->count - 1)
196            screen_list->modals.cur_in_list++;
197        break;
198    case 0xd:
199        screen_list->modals.window_list = 0;
200        screen_list->prevpty = screen_list->pty;
201        screen_list->pty = screen_list->modals.cur_in_list;
202        break;
203    case 0x22:
204        screen_list->modals.window_list = 0;
205        break;
206    default:
207        break;
208    }
209
210    return 1;
211}
212
213void draw_list(struct screen_list *screen_list)
214{
215    int i;
216    int w = (caca_get_canvas_width(screen_list->cv));
217    int h = (caca_get_canvas_height(screen_list->cv));
218
219    debug("Drawing list\n");
220    caca_set_color_ansi(screen_list->cv, CACA_BLACK, CACA_BLACK);
221    caca_fill_box(screen_list->cv, 0, 0, w, h, '#');
222    caca_set_color_ansi(screen_list->cv, CACA_DEFAULT, CACA_DEFAULT);
223    caca_draw_cp437_box(screen_list->cv, 0, 0, w, h);
224
225    caca_printf(screen_list->cv, 2, 1, "Num         Name");
226    for (i = 0; i < screen_list->count; i++)
227    {
228        char line[1024];
229        if (screen_list->modals.cur_in_list == i)
230            caca_set_color_ansi(screen_list->cv, CACA_BLACK, CACA_WHITE);
231        else
232            caca_set_color_ansi(screen_list->cv, CACA_DEFAULT, CACA_DEFAULT);
233        sprintf(line, "%d           %s", i + 1, screen_list->screen[i]->title);
234
235        caca_printf(screen_list->cv, 2, i + 3, line);
236    }
237}
238
239/* Close a window by animating it collapsing */
240/* Total close time */
241#define DELAY 500000.0f
242int close_screen_recurrent(struct screen_list *screen_list,
243                           struct recurrent *rec, void *user,
244                           long long unsigned int t)
245{
246    long long unsigned int delta = t - rec->start_time;
247
248    screen_list->dont_update_coords = 1;
249    screen_list->delay = 0;
250    rec->kill_me = 0;
251    if (delta >= DELAY || (!screen_list->eyecandy))
252    {
253        rec->kill_me = 1;
254        remove_screen(screen_list, screen_list->pty, 1);
255        screen_list->pty = screen_list->prevpty>screen_list->count?screen_list->count:screen_list->prevpty;
256        screen_list->prevpty = 0;
257        screen_list->dont_update_coords = 0;
258    }
259    else
260    {
261        float r = 1 - ((DELAY - (DELAY - delta)) / DELAY);
262        caca_canvas_t *old, *new;
263        struct screen *s = screen_list->screen[screen_list->pty];
264        int w = s->orig_w * r;
265        int h = s->orig_h * r;
266
267        /* libcaca canvas resize function is bugged, do it by hand */
268        old = s->cv;
269        new = caca_create_canvas(w, h);
270        caca_blit(new, 0, 0, old, NULL);
271        s->cv = new;
272        caca_free_canvas(old);
273        set_tty_size(s->fd, w, h);
274
275        s->w = w;
276        s->h = h;
277
278        s->x = (s->orig_x * r) + ((s->orig_w / 2) - s->w / 2);
279        s->y = (s->orig_y * r) + ((s->orig_h / 2) - s->h / 2);
280    }
281    screen_list->changed = 1;
282    return 1;
283}
284
285#endif
286
Note: See TracBrowser for help on using the repository browser.