Changeset 2448 for neercs


Ignore:
Timestamp:
Jun 18, 2008, 4:50:41 PM (12 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • 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
Location:
neercs/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/main.c

    r2447 r2448  
    122122    screen_list->pty = screen_list->prevpty = 0;
    123123    screen_list->dont_update_coords = 0;
    124     screen_list->screensaver_timeout = (10) * 1000000;
    125 
     124    screen_list->screensaver_timeout = (60) * 1000000;
     125    screen_list->screensaver_data = NULL;
     126    screen_list->in_screensaver = 0;
    126127
    127128    recurrent_list = (struct recurrent_list*) malloc(sizeof(struct recurrent_list));
     
    270271            else
    271272            {
     273
     274                last_key_time = get_ms();
     275                caca_set_cursor(dp, 1);
     276
     277                if(screen_list->in_screensaver)
     278                {
     279                    screensaver_kill(cv, dp, screen_list);
     280                    screen_list->in_screensaver = 0;
     281                    refresh = 1;
     282                    continue;
     283                }
     284
     285
    272286                switch(c)
    273287                {
     
    288302                }
    289303            }
    290             last_key_time = get_ms();
    291             caca_set_cursor(dp, 1);
    292304        }
    293305        else if(ret && (caca_get_event_type(&ev) & CACA_EVENT_RESIZE))
     
    332344        if((get_ms() - last_key_time > screen_list->screensaver_timeout))
    333345        {
     346            if(!screen_list->in_screensaver)
     347                screensaver_init(cv, dp, screen_list);
     348            screen_list->in_screensaver = 1;
     349
    334350            caca_set_cursor(dp, 0);
    335351            draw_screensaver(cv, dp, screen_list);
  • neercs/trunk/src/neercs.h

    r2447 r2448  
    6666    int status;                  /* Status bar */
    6767    int help;                    /* help */
     68
     69    /* ScreenSaver stuff */
    6870    long long unsigned int screensaver_timeout;     /* Screensaver timeout in us */
    69 
     71    int in_screensaver;
     72    void *screensaver_data;
    7073
    7174    int pty, prevpty;            /* Current and previous window */
     
    136139
    137140/* Screensavers */
     141void screensaver_init(cucul_canvas_t *cv,
     142                      caca_display_t *dp,
     143                      struct screen_list *screen_list);
     144void screensaver_kill(cucul_canvas_t *cv,
     145                      caca_display_t *dp,
     146                      struct screen_list *screen_list);
     147
    138148void draw_screensaver(cucul_canvas_t *cv,
    139149                      caca_display_t *dp,
     
    142152                                 caca_display_t *dp,
    143153                                 struct screen_list *screen_list);
     154
     155void screensaver_flying_toasters_init(cucul_canvas_t *cv,
     156                                 caca_display_t *dp,
     157                                 struct screen_list *screen_list);
     158
     159void screensaver_flying_toasters_kill(cucul_canvas_t *cv,
     160                                 caca_display_t *dp,
     161                                 struct screen_list *screen_list);
     162
    144163
    145164
  • neercs/trunk/src/screens.c

    r2445 r2448  
    345345
    346346            if(nr == 0 || errno != EWOULDBLOCK) {
     347
    347348                remove_screen(screen_list, i, 0);
    348349                if(i < screen_list->prevpty) screen_list->prevpty--;
  • neercs/trunk/src/screensaver.c

    r2447 r2448  
    3030#include "neercs.h"
    3131
     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
    3249void draw_screensaver(cucul_canvas_t *cv,
    3350                      caca_display_t *dp,
     
    3754}
    3855
     56
     57
     58
     59/* Flying Toasters */
    3960
    4061#define COUNT 15
     
    6687"    `-_|.-\n"};
    6788
     89struct flying_toaster
     90{
     91    int x[COUNT], y[COUNT], s[COUNT];
     92    cucul_canvas_t **toaster;
     93};
    6894
     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}
    69147
    70148void screensaver_flying_toasters(cucul_canvas_t *cv,
     
    72150                                 struct screen_list *screen_list)
    73151{
    74     static int x[COUNT], y[COUNT], s[COUNT];
    75     static int inited = 0;
    76     cucul_canvas_t **toaster;
    77 
     152    struct flying_toaster *d = screen_list->screensaver_data;
    78153    int i, w, h;
    79 
    80     toaster = (cucul_canvas_t **)malloc(sizeof(cucul_canvas_t *));
    81     toaster[0] = cucul_create_canvas(0, 0);
    82     toaster[1] = cucul_create_canvas(0, 0);
    83     toaster[2] = cucul_create_canvas(0, 0);
     154    if(!d) return;
    84155
    85156    w = cucul_get_canvas_width(cv);
     
    90161    cucul_clear_canvas(cv);
    91162
    92     cucul_import_memory(toaster[0], toaster1_text, strlen(toaster1_text), "ansi");
    93     cucul_import_memory(toaster[1], toaster2_text, strlen(toaster2_text), "ansi");
    94     cucul_import_memory(toaster[2], toaster3_text, strlen(toaster3_text), "ansi");
    95163
    96     if(!inited)
    97     {
    98         for(i = 0; i < COUNT; i++)
    99         {
    100             x[i] = (rand()%w) * PRECISION;
    101             y[i] = (rand()%h) * PRECISION;
    102             s[i] = (rand()%3) * PRECISION;
    103         }
    104         inited = 1;
    105     }
    106164
    107165    for(i = 0; i < COUNT; i++)
    108166    {
    109         cucul_blit(cv, x[i]/PRECISION, y[i]/PRECISION, toaster[s[i]/PRECISION], NULL);
     167        cucul_blit(cv, d->x[i]/PRECISION, d->y[i]/PRECISION, d->toaster[d->s[i]/PRECISION], NULL);
    110168
    111         x[i]-=40;
    112         y[i]+=10;
     169        d->x[i]-=40;
     170        d->y[i]+=10;
    113171
    114         if((x[i]/PRECISION) + cucul_get_canvas_width(toaster[s[i]/PRECISION])<=0)
    115             x[i] = ((rand()%w)+w) * PRECISION;
    116         if((y[i]/PRECISION)>=h)
    117             y[i] = ((rand()%h)-h) * PRECISION;
     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;
    118176
    119         s[i] = ((s[i]+24)%(3*PRECISION));
     177        d->s[i] = ((d->s[i]+24)%(3*PRECISION));
    120178    }
    121179}
Note: See TracChangeset for help on using the changeset viewer.