Changeset 2445 for neercs


Ignore:
Timestamp:
Jun 16, 2008, 4:33:19 PM (12 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Added delayed (recurrent) functions, as well as a window-killing eyecandy
Location:
neercs/trunk/src
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/Makefile.am

    r2444 r2445  
    77endif
    88
    9 neercs_SOURCES = neercs.h $(grab_c) mygetopt.c main.c screens.c term.c effects.c wm.c
     9neercs_SOURCES = neercs.h $(grab_c) mygetopt.c recurrent.c main.c screens.c term.c effects.c wm.c
    1010neercs_CFLAGS = @CACA_CFLAGS@
    1111neercs_LDADD = @CACA_LIBS@ @UTIL_LIBS@
  • neercs/trunk/src/effects.c

    r2421 r2445  
    209209    cucul_printf(cv, x, y++, "See http://libcaca.zoy.org/wiki/neercs for more informations");
    210210}
     211
     212
     213
     214
     215#define DELAY 500000.0f
     216
     217int close_screen_recurrent(struct screen_list* screen_list, struct recurrent* rec, void *user, long long unsigned int t)
     218{
     219    long long unsigned int delta = t - rec->start_time;
     220
     221    screen_list->dont_update_coords = 1;
     222    rec->kill_me = 0;
     223    if(delta>=DELAY)
     224    {
     225        rec->kill_me = 1;
     226        remove_screen(screen_list, screen_list->pty, 1);
     227        screen_list->pty = screen_list->prevpty;
     228        screen_list->prevpty = 0;
     229        screen_list->dont_update_coords = 0;
     230    }
     231    else
     232    {
     233        float r = 1 - ((DELAY - (DELAY - delta)) / DELAY);
     234        cucul_canvas_t *old, *new;
     235        struct screen *s = screen_list->screen[screen_list->pty];
     236        int w = s->orig_w * r;
     237        int h = s->orig_h * r;
     238
     239
     240        old = s->cv;
     241        new = cucul_create_canvas(w, h);
     242        cucul_blit(new, 0, 0, old, NULL);
     243        s->cv = new;
     244        cucul_free_canvas(old);
     245        set_tty_size(s->fd, w, h);
     246
     247        s->w = w;
     248        s->h = h;
     249
     250        s->x =
     251            (s->orig_x * r) +
     252            ((s->orig_w/2) - s->w/2);
     253        s->y =
     254            (s->orig_y * r) +
     255            ((s->orig_h/2) - s->h/2);
     256
     257    }
     258
     259    return 1;
     260}
  • neercs/trunk/src/main.c

    r2444 r2445  
    2525#include <sys/types.h>
    2626#include <sys/wait.h>
     27#include <sys/time.h>
     28#include <time.h>
    2729
    2830#if defined HAVE_PTY_H
     
    6870    static caca_display_t *dp;
    6971    struct screen_list *screen_list = NULL;
     72    struct recurrent_list *recurrent_list = NULL;
    7073    char *default_shell = NULL;
    7174    int i, w, h, args, s=0;
     
    117120    screen_list->in_bell = 0;
    118121    screen_list->pty = screen_list->prevpty = 0;
     122    screen_list->dont_update_coords = 0;
     123
     124    recurrent_list = (struct recurrent_list*) malloc(sizeof(struct recurrent_list));
     125    recurrent_list->recurrent = (struct recurrent**) malloc(sizeof(struct recurrent*));
     126    if(!recurrent_list->recurrent)
     127    {
     128        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__);
     129        return -1;
     130    }
     131    recurrent_list->count = 0;
    119132
    120133    for(;;)
     
    172185    update_windows_props(cv, screen_list);
    173186    caca_refresh_display(dp);
    174 
    175187
    176188    for(;;)
     
    239251                    break;
    240252                case 0x0b: //CACA_KEY_CTRL_K:
    241                     remove_screen(screen_list, screen_list->pty, 1);
    242                     screen_list->pty = screen_list->prevpty;
    243                     screen_list->prevpty = 0;
     253                    add_recurrent(recurrent_list, close_screen_recurrent, cv);
    244254                    refresh = 1;
    245255                    break;
     
    283293        }
    284294
     295        /* Recurrent functions */
     296        for(i=0; i<recurrent_list->count; i++)
     297        {
     298            if(recurrent_list->recurrent[i]->function)
     299            {
     300                refresh |= recurrent_list->recurrent[i]->function(screen_list,
     301                                                                  recurrent_list->recurrent[i],
     302                                                                  recurrent_list->recurrent[i]->user,
     303                                                                  get_ms());
     304            }
     305        }
     306       /* Delete recurrent functions */
     307        for(i=0; i<recurrent_list->count; i++)
     308        {
     309            if(recurrent_list->recurrent[i]->kill_me)
     310            {
     311                remove_recurrent(recurrent_list, i);
     312                i = 0;
     313            }
     314        }
     315
    285316        /* Resfresh screen */
    286317        if(refresh || screen_list->in_bell)
     
    306337        destroy_screen(screen_list->screen[i]);
    307338    }
     339
    308340    free(screen_list->screen);
    309341    free(screen_list);
    310342
    311343
     344    for(i=0; i<recurrent_list->count; i++)
     345    {
     346        remove_recurrent(recurrent_list, i);
     347        i = 0;
     348    }
     349
     350    free(recurrent_list->recurrent);
     351    free(recurrent_list);
     352
     353
    312354    return 0;
    313355}
     356
     357
     358
     359long long get_ms(void)
     360{
     361    struct timeval tv;
     362    gettimeofday(&tv, NULL);
     363
     364
     365    return (tv.tv_sec*(1000000) + tv.tv_usec);
     366}
  • neercs/trunk/src/neercs.h

    r2444 r2445  
    2727};
    2828
     29
    2930struct screen
    3031{
     
    5253    int x, y;
    5354    int w, h;
     55
     56    int orig_x, orig_y;
     57    int orig_w, orig_h;
     58
    5459};
    5560
     
    5863    int wm_type;
    5964    int in_bell;
     65    int dont_update_coords;
    6066    /* Add-ons*/
    6167    int mini;
     
    6369    int help;
    6470
    65 
    6671    int pty, prevpty;
    6772    int count;
    6873    int width, height;
    6974    struct screen **screen;
     75};
     76
     77
     78struct recurrent
     79{
     80    int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
     81    void *user;
     82    long long unsigned int  start_time;
     83    int kill_me;
     84};
     85
     86struct recurrent_list
     87{
     88    int count;
     89    struct recurrent **recurrent;
    7090};
    7191
     
    88108                     struct screen_list *screen_list);
    89109int update_screens_contents(struct screen_list* screen_list);
     110long long get_ms(void);
     111
    90112
    91113/* Screens management */
     
    110132void draw_status(cucul_canvas_t *cv, struct screen_list *screen_list);
    111133void draw_help(cucul_canvas_t *cv, struct screen_list *screen_list);
     134int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
     135
     136
     137/* Recurrents */
     138int add_recurrent(struct recurrent_list *list,
     139                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
     140                  void *user);
     141int remove_recurrent(struct recurrent_list *list, int n);
    112142
    113143
  • neercs/trunk/src/screens.c

    r2438 r2445  
    7878    s->scroll = 0;
    7979    s->fd = create_pty(command, w, h, &s->pid);
     80
     81    s->orig_w = s->w;
     82    s->orig_h = s->h;
     83    s->orig_x = s->x;
     84    s->orig_y = s->y;
     85
    8086
    8187    if(s->fd < 0)
     
    180186    screen_list->height = cucul_get_canvas_height(cv) - (screen_list->mini*6);
    181187
    182     update_windows_props(cv, screen_list);
     188    if(!screen_list->dont_update_coords)
     189        update_windows_props(cv, screen_list);
    183190
    184191    if(screen_list->screen[screen_list->pty]->title)
     
    199206                       screen_list->screen[i]->y,
    200207                       screen_list->screen[i]->cv, NULL);
     208
    201209            cucul_draw_cp437_box(cv,
    202210                                 screen_list->screen[i]->x - 1,
  • neercs/trunk/src/term.c

    r2444 r2445  
    618618    for(i = 0; i < screen_list->count; i++)
    619619    {
    620         if(screen_list->screen[i]->total)
     620        if(screen_list->screen[i]->total && !screen_list->dont_update_coords)
    621621        {
    622622            unsigned long int bytes;
  • neercs/trunk/src/wm.c

    r2421 r2445  
    4040    cucul_free_canvas(old);
    4141    set_tty_size(s->fd, w, h);
     42
     43    s->orig_w = s->w;
     44    s->orig_h = s->h;
     45    s->orig_x = s->x;
     46    s->orig_y = s->y;
    4247}
    4348
Note: See TracChangeset for help on using the changeset viewer.