Ignore:
Timestamp:
Mar 8, 2006, 11:33:01 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Finished moving everything driver-specific to the apropriate driver_*.c files. Phew. Now they just need a few comments.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/driver_ncurses.c

    r549 r550  
    2828#endif
    2929
     30#include <stdlib.h>
     31#include <string.h>
     32
    3033#if defined(HAVE_SIGNAL_H)
    3134#   include <signal.h>
     
    4851static caca_t *sigwinch_kk; /* FIXME: we ought to get rid of this */
    4952#endif
     53#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
     54static void ncurses_check_terminal(void);
     55#endif
     56
     57struct driver_private
     58{
     59    int attr[16*16];
     60    mmask_t oldmask;
     61};
    5062
    5163static int ncurses_init_graphics(caca_t *kk)
     
    7688    int fg, bg, max;
    7789
     90    kk->drv.p = malloc(sizeof(struct driver_private));
     91
     92#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
     93    ncurses_check_terminal();
     94#endif
     95
    7896#if defined(HAVE_SIGNAL)
    7997    sigwinch_kk = kk;
     
    91109    /* Activate mouse */
    92110    newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS;
    93     mousemask(newmask, &kk->ncurses.oldmask);
     111    mousemask(newmask, &kk->drv.p->oldmask);
    94112    mouseinterval(-1); /* No click emulation */
    95113
     
    116134            int col = ((max + 7 - fg) % max) + max * bg;
    117135            init_pair(col, curses_colors[fg], curses_colors[bg]);
    118             kk->ncurses.attr[fg + 16 * bg] = COLOR_PAIR(col);
     136            kk->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col);
    119137
    120138            if(max == 8)
    121139            {
    122140                /* Bright fg on simple bg */
    123                 kk->ncurses.attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
     141                kk->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
    124142                /* Simple fg on bright bg */
    125                 kk->ncurses.attr[fg + 16 * (bg + 8)] = A_BLINK
     143                kk->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK
    126144                                                    | COLOR_PAIR(col);
    127145                /* Bright fg on bright bg */
    128                 kk->ncurses.attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
     146                kk->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
    129147                                                        | COLOR_PAIR(col);
    130148            }
     
    138156static int ncurses_end_graphics(caca_t *kk)
    139157{
    140     mousemask(kk->ncurses.oldmask, NULL);
     158    mousemask(kk->drv.p->oldmask, NULL);
    141159    curs_set(1);
    142160    noraw();
    143161    endwin();
     162
     163    free(kk->drv.p);
    144164
    145165    return 0;
     
    173193        for(x = kk->qq->width; x--; )
    174194        {
    175             attrset(kk->ncurses.attr[*attr++]);
     195            attrset(kk->drv.p->attr[*attr++]);
    176196            addch(*chars++ & 0x7f);
    177197        }
     
    397417#endif
    398418
     419#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
     420static void ncurses_check_terminal(void)
     421{
     422    char *term, *colorterm, *other;
     423
     424    term = getenv("TERM");
     425    colorterm = getenv("COLORTERM");
     426
     427    if(term && !strcmp(term, "xterm"))
     428    {
     429        /* If we are using gnome-terminal, it's really a 16 colour terminal */
     430        if(colorterm && !strcmp(colorterm, "gnome-terminal"))
     431        {
     432            SCREEN *screen;
     433            screen = newterm("xterm-16color", stdout, stdin);
     434            if(screen == NULL)
     435                return;
     436            endwin();
     437            (void)putenv("TERM=xterm-16color");
     438            return;
     439        }
     440
     441        /* Ditto if we are using Konsole */
     442        other = getenv("KONSOLE_DCOP_SESSION");
     443        if(other)
     444        {
     445            SCREEN *screen;
     446            screen = newterm("xterm-16color", stdout, stdin);
     447            if(screen == NULL)
     448                return;
     449            endwin();
     450            (void)putenv("TERM=xterm-16color");
     451            return;
     452        }
     453    }
     454}
     455#endif
     456
    399457/*
    400458 * Driver initialisation
     
    403461void ncurses_init_driver(caca_t *kk)
    404462{
    405     kk->driver.driver = CACA_DRIVER_NCURSES;
    406 
    407     kk->driver.init_graphics = ncurses_init_graphics;
    408     kk->driver.end_graphics = ncurses_end_graphics;
    409     kk->driver.set_window_title = ncurses_set_window_title;
    410     kk->driver.get_window_width = ncurses_get_window_width;
    411     kk->driver.get_window_height = ncurses_get_window_height;
    412     kk->driver.display = ncurses_display;
    413     kk->driver.handle_resize = ncurses_handle_resize;
    414     kk->driver.get_event = ncurses_get_event;
     463    kk->drv.driver = CACA_DRIVER_NCURSES;
     464
     465    kk->drv.init_graphics = ncurses_init_graphics;
     466    kk->drv.end_graphics = ncurses_end_graphics;
     467    kk->drv.set_window_title = ncurses_set_window_title;
     468    kk->drv.get_window_width = ncurses_get_window_width;
     469    kk->drv.get_window_height = ncurses_get_window_height;
     470    kk->drv.display = ncurses_display;
     471    kk->drv.handle_resize = ncurses_handle_resize;
     472    kk->drv.get_event = ncurses_get_event;
    415473}
    416474
Note: See TracChangeset for help on using the changeset viewer.