source: neercs/trunk/src/screensaver.c @ 2448

Last change on this file since 2448 was 2448, checked in by Jean-Yves Lamoureux, 13 years ago
  • Made Screensaver Engine (called a glazillon times) cleaner
  • Set default screensaver timeout to 60 seconds
  • Don't send key event that caused screensaver to quit to active terminal
File size: 4.7 KB
Line 
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: main.c 2401 2008-06-15 12:50:12Z 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 "config.h"
17
18#include <stdio.h>
19#include <string.h>
20#include <stdlib.h>
21#include <sys/types.h>
22#include <signal.h>
23#include <sys/wait.h>
24#include <errno.h>
25#include <unistd.h>
26
27#include <cucul.h>
28#include <caca.h>
29
30#include "neercs.h"
31
32
33void screensaver_init(cucul_canvas_t *cv,
34                      caca_display_t *dp,
35                      struct screen_list *screen_list)
36{
37
38    screensaver_flying_toasters_init(cv, dp, screen_list);
39}
40
41void screensaver_kill(cucul_canvas_t *cv,
42                      caca_display_t *dp,
43                      struct screen_list *screen_list)
44{
45
46    screensaver_flying_toasters_kill(cv, dp, screen_list);
47}
48
49void draw_screensaver(cucul_canvas_t *cv,
50                      caca_display_t *dp,
51                      struct screen_list *screen_list)
52{
53    screensaver_flying_toasters(cv, dp, screen_list);
54}
55
56
57
58
59/* Flying Toasters */
60
61#define COUNT 15
62#define PRECISION 100
63
64char toaster1_text[] = {
65"      __._ \n"
66"   .-'== _',\n"
67"  <|_= .-'  |\n"
68"   | --|   \\'.-_ \n"
69"   |   | \\  \" _.\n"
70"    `-_|.-\\_.-\n"};
71
72char toaster2_text[] = {
73"      __._ \n"
74"   .-'== _',\n"
75"  \\|_= .-'  |\n"
76"   | --|  __'-.\n"
77"   |   | ___.-\n"
78"    `-_|.-\n"
79};
80
81char toaster3_text[] = {
82"   _- __._\n"
83"  /.-'== _',_.-.\n"
84"  \\|_= .-'/  _.'\n"
85"   | --| / .-\n"
86"   |   |  _.|\n"
87"    `-_|.-\n"};
88
89struct flying_toaster
90{
91    int x[COUNT], y[COUNT], s[COUNT];
92    cucul_canvas_t **toaster;
93};
94
95void screensaver_flying_toasters_init(cucul_canvas_t *cv,
96                                      caca_display_t *dp,
97                                      struct screen_list *screen_list)
98{
99    struct flying_toaster *flying_toaster;
100    int w = cucul_get_canvas_width(cv);
101    int h = cucul_get_canvas_height(cv);
102    int i;
103
104    flying_toaster = malloc(sizeof(struct flying_toaster));
105    flying_toaster->toaster = (cucul_canvas_t **)malloc(sizeof(cucul_canvas_t*)*3);
106
107
108    flying_toaster->toaster[0] = cucul_create_canvas(0, 0);
109    flying_toaster->toaster[1] = cucul_create_canvas(0, 0);
110    flying_toaster->toaster[2] = cucul_create_canvas(0, 0);
111
112
113    cucul_import_memory(flying_toaster->toaster[0],
114                        toaster1_text,
115                        strlen(toaster1_text), "ansi");
116    cucul_import_memory(flying_toaster->toaster[1],
117                        toaster2_text,
118                        strlen(toaster2_text), "ansi");
119    cucul_import_memory(flying_toaster->toaster[2],
120                        toaster3_text,
121                        strlen(toaster3_text), "ansi");
122
123    for(i = 0; i < COUNT; i++)
124    {
125        flying_toaster->x[i] = (rand()%w) * PRECISION;
126        flying_toaster->y[i] = (rand()%h) * PRECISION;
127        flying_toaster->s[i] = (rand()%3) * PRECISION;
128    }
129
130
131    screen_list->screensaver_data = flying_toaster;
132}
133
134void screensaver_flying_toasters_kill(cucul_canvas_t *cv,
135                                      caca_display_t *dp,
136                                      struct screen_list *screen_list)
137{
138    struct flying_toaster *flying_toaster = screen_list->screensaver_data;
139
140    cucul_free_canvas(flying_toaster->toaster[0]);
141    cucul_free_canvas(flying_toaster->toaster[1]);
142    cucul_free_canvas(flying_toaster->toaster[2]);
143    free(flying_toaster->toaster);
144    free(flying_toaster);
145    screen_list->screensaver_data = NULL;
146}
147
148void screensaver_flying_toasters(cucul_canvas_t *cv,
149                                 caca_display_t *dp,
150                                 struct screen_list *screen_list)
151{
152    struct flying_toaster *d = screen_list->screensaver_data;
153    int i, w, h;
154    if(!d) return;
155
156    w = cucul_get_canvas_width(cv);
157    h = cucul_get_canvas_height(cv);
158
159
160    cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
161    cucul_clear_canvas(cv);
162
163
164
165    for(i = 0; i < COUNT; i++)
166    {
167        cucul_blit(cv, d->x[i]/PRECISION, d->y[i]/PRECISION, d->toaster[d->s[i]/PRECISION], NULL);
168
169        d->x[i]-=40;
170        d->y[i]+=10;
171
172        if((d->x[i]/PRECISION) + cucul_get_canvas_width(d->toaster[d->s[i]/PRECISION])<=0)
173            d->x[i] = ((rand()%w)+w) * PRECISION;
174        if((d->y[i]/PRECISION)>=h)
175            d->y[i] = ((rand()%h)-h) * PRECISION;
176
177        d->s[i] = ((d->s[i]+24)%(3*PRECISION));
178    }
179}
Note: See TracBrowser for help on using the repository browser.