Changeset 2495


Ignore:
Timestamp:
06/28/08 13:22:26 (5 years ago)
Author:
jylam
Message:
  • Removed general local variables from main() and put it in struct screen_list
  • Moved most of the input handling to input.c
  • Moved lock feature to lock.c
Location:
neercs/trunk/src
Files:
2 added
8 edited

Legend:

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

    r2463 r2495  
    33 
    44neercs_SOURCES = neercs.h mygetopt.c recurrent.c main.c screens.c term.c \ 
    5                  grab.c effects.c wm.c screensaver.c attach.c configuration.c 
     5                 grab.c effects.c wm.c screensaver.c attach.c configuration.c \ 
     6                                                                 input.c lock.c 
    67neercs_CFLAGS = @CACA_CFLAGS@ 
    78neercs_LDADD = @CACA_LIBS@ @UTIL_LIBS@ @PAM_LIBS@ 
  • neercs/trunk/src/effects.c

    r2474 r2495  
    2323#include <sys/wait.h> 
    2424#include <sys/types.h> 
    25 #include <security/pam_appl.h> 
    26 #include <security/pam_misc.h> 
    27 #include <pwd.h> 
    2825 
    2926#include "neercs.h" 
    3027 
    31 static int convpam(int num_msg, const struct pam_message **msg, 
    32         struct pam_response **resp, void *appdata_ptr); 
    33  
    34 void draw_thumbnails(cucul_canvas_t *cv, struct screen_list *screen_list) 
    35 { 
    36                 char const * const *fonts; 
    37                 cucul_dither_t *d; 
    38                 cucul_font_t *f; 
    39                 uint8_t *buf; 
    40                 int i; 
    41                 int miniw, minih; 
    42  
    43                 if(screen_list->count) 
    44                 { 
    45                     fonts = cucul_get_font_list(); 
    46                     f = cucul_load_font(fonts[0], 0); 
    47  
    48                     miniw = cucul_get_canvas_width(screen_list->screen[0]->cv) 
    49                         * cucul_get_font_width(f); 
    50                     minih = cucul_get_canvas_height(screen_list->screen[0]->cv) 
    51                         * cucul_get_font_height(f); 
    52                     buf = malloc(4 * miniw * minih); 
     28void draw_thumbnails(struct screen_list *screen_list) 
     29{ 
     30    char const * const *fonts; 
     31    cucul_dither_t *d; 
     32    cucul_font_t *f; 
     33    uint8_t *buf; 
     34    int i; 
     35    int miniw, minih; 
     36 
     37    if(screen_list->count) 
     38    { 
     39        fonts = cucul_get_font_list(); 
     40        f = cucul_load_font(fonts[0], 0); 
     41 
     42        miniw = cucul_get_canvas_width(screen_list->screen[0]->cv) 
     43            * cucul_get_font_width(f); 
     44        minih = cucul_get_canvas_height(screen_list->screen[0]->cv) 
     45            * cucul_get_font_height(f); 
     46        buf = malloc(4 * miniw * minih); 
    5347 
    5448#if defined(HAVE_ENDIAN_H) 
    55                     if(__BYTE_ORDER == __BIG_ENDIAN) 
     49        if(__BYTE_ORDER == __BIG_ENDIAN) 
    5650#else 
    57                         /* This is compile-time optimised with at least -O1 or -Os */ 
    58                         uint32_t const tmp = 0x12345678; 
    59                     if(*(uint8_t const *)&tmp == 0x12) 
     51            /* This is compile-time optimised with at least -O1 or -Os */ 
     52            uint32_t const tmp = 0x12345678; 
     53        if(*(uint8_t const *)&tmp == 0x12) 
    6054#endif 
    61                         d = cucul_create_dither(32, miniw, minih, 4 * miniw, 
    62                                                 0xff0000, 0xff00, 0xff, 0x0); 
    63                     else 
    64                         d = cucul_create_dither(32, miniw, minih, 4 * miniw, 
    65                                                 0xff00, 0xff0000, 0xff000000, 0x0); 
    66  
    67                     for(i = 0; i < screen_list->count; i++) 
    68                     { 
    69                         cucul_render_canvas(screen_list->screen[i]->cv, f, buf, 
    70                                             miniw, minih, miniw * 4); 
    71                         cucul_dither_bitmap(cv, 20 * i, 
    72                                             cucul_get_canvas_height(cv) - 6, 19, 6, d, buf); 
    73                         cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE); 
    74  
    75                         if(screen_list->pty == i) 
    76                             cucul_draw_cp437_box(cv,20 * i, 
    77                                                  cucul_get_canvas_height(cv) - 6, 19, 6); 
    78                         cucul_printf(cv, 20 * i, 
    79                                      cucul_get_canvas_height(cv) - 6, "(%i)", i+1); 
    80                     } 
    81  
    82                     cucul_free_dither(d); 
    83                     cucul_free_font(f); 
    84  
    85                     free(buf); 
    86                 } 
     55            d = cucul_create_dither(32, miniw, minih, 4 * miniw, 
     56                                    0xff0000, 0xff00, 0xff, 0x0); 
     57        else 
     58            d = cucul_create_dither(32, miniw, minih, 4 * miniw, 
     59                                    0xff00, 0xff0000, 0xff000000, 0x0); 
     60 
     61        for(i = 0; i < screen_list->count; i++) 
     62        { 
     63            cucul_render_canvas(screen_list->screen[i]->cv, f, buf, 
     64                                miniw, minih, miniw * 4); 
     65            cucul_dither_bitmap(screen_list->cv, 20 * i, 
     66                                cucul_get_canvas_height(screen_list->cv) - 6, 19, 6, d, buf); 
     67            cucul_set_color_ansi(screen_list->cv, CUCUL_WHITE, CUCUL_BLUE); 
     68 
     69            if(screen_list->pty == i) 
     70                cucul_draw_cp437_box(screen_list->cv,20 * i, 
     71                                     cucul_get_canvas_height(screen_list->cv) - 6, 19, 6); 
     72            cucul_printf(screen_list->cv, 20 * i, 
     73                         cucul_get_canvas_height(screen_list->cv) - 6, "(%i)", i+1); 
     74        } 
     75 
     76        cucul_free_dither(d); 
     77        cucul_free_font(f); 
     78 
     79        free(buf); 
     80    } 
    8781 
    8882} 
    8983 
    9084/* FIXME, make this stuff more configurable */ 
    91 void draw_status(cucul_canvas_t *cv, struct screen_list *screen_list) 
    92 { 
    93     int x = 0, y = cucul_get_canvas_height(cv) - 1; 
    94  
    95  
    96         cucul_set_color_ansi(cv, CUCUL_BLUE, CUCUL_BLUE); 
    97         cucul_fill_box(cv, 
    98                        x, y, 
    99                        cucul_get_canvas_width(cv), 1, '#'); 
     85void draw_status(struct screen_list *screen_list) 
     86{ 
     87    int x = 0, y = cucul_get_canvas_height(screen_list->cv) - 1; 
     88 
     89 
     90    cucul_set_color_ansi(screen_list->cv, CUCUL_BLUE, CUCUL_BLUE); 
     91    cucul_fill_box(screen_list->cv, 
     92                   x, y, 
     93                   cucul_get_canvas_width(screen_list->cv), 1, '#'); 
    10094 
    10195/* Hour */ 
     
    106100        sprintf(hour, "%02d:%02d", t->tm_hour, t->tm_min); 
    107101 
    108         cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 
    109         cucul_printf(cv, x, y, 
     102        cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 
     103        cucul_printf(screen_list->cv, x, y, 
    110104                     "["); 
    111105 
    112         cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); 
    113         cucul_printf(cv, x+1, y, 
     106        cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 
     107        cucul_printf(screen_list->cv, x+1, y, 
    114108                     hour); 
    115         cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 
    116         cucul_printf(cv, x + strlen(hour) + 1, y, 
     109        cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 
     110        cucul_printf(screen_list->cv, x + strlen(hour) + 1, y, 
    117111                     "]"); 
    118112        x += 7; 
     
    125119        sprintf(text, "%d/%d", screen_list->pty+1, screen_list->count); 
    126120        x++; 
    127         cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 
    128         cucul_printf(cv, x, y, "Window:"); 
    129         cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); 
    130         cucul_printf(cv, x+8, y, text); 
     121        cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 
     122        cucul_printf(screen_list->cv, x, y, "Window:"); 
     123        cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 
     124        cucul_printf(screen_list->cv, x+8, y, text); 
    131125        x+= 8+strlen(text); 
    132126    } 
     
    155149 
    156150        x++; 
    157         cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 
    158         cucul_printf(cv, x, y, "WM:"); 
    159         cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); 
    160         cucul_printf(cv, x+4, y, text); 
     151        cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 
     152        cucul_printf(screen_list->cv, x, y, "WM:"); 
     153        cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 
     154        cucul_printf(screen_list->cv, x+4, y, text); 
    161155        x+= 4+strlen(text); 
    162156    } 
     
    166160        char text[256]; 
    167161        sprintf(text, "Help: ctrl-a-h"); 
    168         x = cucul_get_canvas_width(cv) - strlen(text); 
    169  
    170         cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); 
    171         cucul_printf(cv, x, y, text); 
    172     } 
    173  
    174  
    175 } 
    176  
    177  
    178 void draw_help(cucul_canvas_t *cv, struct screen_list *screen_list) 
     162        x = cucul_get_canvas_width(screen_list->cv) - strlen(text); 
     163 
     164        cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 
     165        cucul_printf(screen_list->cv, x, y, text); 
     166    } 
     167 
     168 
     169} 
     170 
     171 
     172void draw_help(struct screen_list *screen_list) 
    179173{ 
    180174    int w = 65, h = 20; 
    181     int x = (cucul_get_canvas_width(cv) - w) / 2; 
    182     int y = (cucul_get_canvas_height(cv) - h) / 2; 
    183  
    184  
    185     cucul_set_color_ansi(cv, CUCUL_BLUE, CUCUL_BLUE); 
    186     cucul_fill_box(cv, 
     175    int x = (cucul_get_canvas_width(screen_list->cv) - w) / 2; 
     176    int y = (cucul_get_canvas_height(screen_list->cv) - h) / 2; 
     177 
     178 
     179    cucul_set_color_ansi(screen_list->cv, CUCUL_BLUE, CUCUL_BLUE); 
     180    cucul_fill_box(screen_list->cv, 
    187181                   x, y, 
    188182                   w, h, '#'); 
    189     cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); 
    190     cucul_draw_cp437_box(cv, 
     183    cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 
     184    cucul_draw_cp437_box(screen_list->cv, 
    191185                         x, y, 
    192186                         w, h); 
     
    194188    x+=2; 
    195189    y++; 
    196     cucul_printf(cv, 
    197                  (cucul_get_canvas_width(cv) - strlen(PACKAGE_STRING)) / 2, 
     190    cucul_printf(screen_list->cv, 
     191                 (cucul_get_canvas_width(screen_list->cv) - strlen(PACKAGE_STRING)) / 2, 
    198192                 y-1, 
    199193                 PACKAGE_STRING); 
    200     cucul_printf(cv, x, y++, "Copyright (c) 2006-2008 "); 
    201     cucul_printf(cv, x, y++, "              Sam Hocevar <sam@zoy.org>"); 
    202     cucul_printf(cv, x, y++, "              Jean-Yves Lamoureux <jylam@lnxscene.org>"); 
    203     cucul_printf(cv, x, y++, "              Pascal Terjan <pterjan@linuxfr.org>"); 
    204     cucul_printf(cv, x, y++, ""); 
    205     cucul_printf(cv, x, y++, ""); 
    206     cucul_printf(cv, x, y++, "All shortcuts are in format 'ctrl-a-X' where X is :"); 
    207     cucul_printf(cv, x, y++, "n:\t Next window"); 
    208     cucul_printf(cv, x, y++, "p:\t Previous window"); 
    209     cucul_printf(cv, x, y++, "w:\t Switch window manager"); 
    210     cucul_printf(cv, x, y++, "c:\t Create new window"); 
    211     cucul_printf(cv, x, y++, "m:\t Thumbnails"); 
    212     cucul_printf(cv, x, y++, "d:\t Detach"); 
    213     cucul_printf(cv, x, y++, "k:\t Close window and kill associated process"); 
    214     cucul_printf(cv, x, y++, "h:\t This help"); 
    215     cucul_printf(cv, x, y++, ""); 
    216     cucul_printf(cv, x, y++, ""); 
    217     cucul_printf(cv, x, y++, "See http://libcaca.zoy.org/wiki/neercs for more informations"); 
    218 } 
    219  
    220  
    221 void draw_lock(cucul_canvas_t *cv, struct screen_list *screen_list) 
    222 { 
    223     unsigned int i; 
    224     char buffer[1024]; 
    225     gethostname(buffer, sizeof(buffer)-1); 
    226  
    227     int w = 65, h = 20; 
    228     int x = (cucul_get_canvas_width(cv) - w) / 2; 
    229     int y = (cucul_get_canvas_height(cv) - h) / 2; 
    230  
    231  
    232     cucul_set_color_ansi(cv, CUCUL_BLUE, CUCUL_BLUE); 
    233     cucul_fill_box(cv, 
    234                    x, y, 
    235                    w, h, '#'); 
    236     cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); 
    237     cucul_draw_cp437_box(cv, 
    238                          x, y, 
    239                          w, h); 
    240  
    241     x+=2; 
    242     y++; 
    243     cucul_printf(cv, 
    244                  (cucul_get_canvas_width(cv) - strlen(PACKAGE_STRING " locked")) / 2, 
    245                  y-1, 
    246                  PACKAGE_STRING " locked"); 
    247  
    248     cucul_printf(cv, x, y++, "Please type in your password for %s@%s :", getenv("USER"), buffer); 
    249     y+=2; 
    250  
    251     x = (cucul_get_canvas_width(cv)/2) - ((strlen(screen_list->lockpass) / 2) + strlen("Password : ")); 
    252     cucul_printf(cv, x, y, "Password : "); 
    253     x+=strlen("Password : "); 
    254     for(i=0; i<strlen(screen_list->lockpass); i++) 
    255     { 
    256         cucul_put_str(cv, x, y, "*"); 
    257         x++; 
    258     } 
    259  
    260  
    261     if(strlen(screen_list->lockmsg)) 
    262     { 
    263         x = ((cucul_get_canvas_width(cv) - w) / 2) + (strlen(screen_list->lockmsg)); 
    264         y+=2; 
    265         cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_BLUE); 
    266         cucul_printf(cv, x, y, "Error : %s", screen_list->lockmsg); 
    267     } 
    268 } 
    269  
    270  
    271  
    272 /* FIXME, handle this without assuming this is a password auth */ 
    273 static int convpam(int num_msg, const struct pam_message **msg, 
    274                 struct pam_response **resp, void *appdata_ptr) 
    275 { 
    276  
    277     struct pam_response *aresp; 
    278     int i; 
    279     aresp = calloc(num_msg, sizeof(*aresp)); 
    280  
    281     for (i = 0; i < num_msg; ++i) 
    282     { 
    283         switch(msg[i]->msg_style) 
    284         { 
    285         case PAM_PROMPT_ECHO_ON: 
    286         case PAM_PROMPT_ECHO_OFF: 
    287             aresp[i].resp = strdup(appdata_ptr); 
    288             aresp[i].resp_retcode = 0; 
    289             break; 
    290         case PAM_ERROR_MSG: 
    291             break; 
    292         default : 
    293             printf("Unknow message type from PAM\n"); 
    294             break; 
    295         } 
    296     } 
    297  
    298     *resp = aresp; 
    299     return (PAM_SUCCESS); 
    300 } 
    301  
    302  
    303 int validate_lock(struct screen_list *screen_list, char *user, char *pass) 
    304 { 
    305     int ret; 
    306     pam_handle_t *pamh=NULL; 
    307     char buffer[100]; 
    308     const char *service="neercs"; 
    309     struct pam_conv conv = { 
    310         convpam, 
    311         pass, 
    312     }; 
    313  
    314     ret = pam_start(service, user, &conv, &pamh); 
    315     if(ret!=PAM_SUCCESS) 
    316         return 0; 
    317     pam_set_item(pamh, PAM_RUSER, user); 
    318  
    319     ret = gethostname(buffer, sizeof(buffer)-1); 
    320     if (ret) 
    321     { 
    322         perror("failed to look up hostname"); 
    323         ret = pam_end(pamh, PAM_ABORT); 
    324         sprintf(screen_list->lockmsg, "Can't get hostname"); 
    325         pam_end(pamh, PAM_SUCCESS); 
    326         return 0; 
    327     } 
    328  
    329     ret = pam_set_item(pamh, PAM_RHOST, buffer); 
    330     if(ret!=PAM_SUCCESS) 
    331     { 
    332         sprintf(screen_list->lockmsg, "Can't set hostname"); 
    333         pam_end(pamh, PAM_SUCCESS); 
    334         return 0; 
    335     } 
    336  
    337     ret = pam_authenticate(pamh, 0); 
    338     if(ret!=PAM_SUCCESS) 
    339     { 
    340         sprintf(screen_list->lockmsg, "Can't authenticate"); 
    341         pam_end(pamh, PAM_SUCCESS); 
    342         return 0; 
    343     } 
    344  
    345     ret = pam_end(pamh, PAM_SUCCESS); 
    346     return 1; 
    347 } 
     194    cucul_printf(screen_list->cv, x, y++, "Copyright (c) 2006-2008 "); 
     195    cucul_printf(screen_list->cv, x, y++, "              Sam Hocevar <sam@zoy.org>"); 
     196    cucul_printf(screen_list->cv, x, y++, "              Jean-Yves Lamoureux <jylam@lnxscene.org>"); 
     197    cucul_printf(screen_list->cv, x, y++, "              Pascal Terjan <pterjan@linuxfr.org>"); 
     198    cucul_printf(screen_list->cv, x, y++, ""); 
     199    cucul_printf(screen_list->cv, x, y++, ""); 
     200    cucul_printf(screen_list->cv, x, y++, "All shortcuts are in format 'ctrl-a-X' where X is :"); 
     201    cucul_printf(screen_list->cv, x, y++, "n:\t Next window"); 
     202    cucul_printf(screen_list->cv, x, y++, "p:\t Previous window"); 
     203    cucul_printf(screen_list->cv, x, y++, "w:\t Switch window manager"); 
     204    cucul_printf(screen_list->cv, x, y++, "c:\t Create new window"); 
     205    cucul_printf(screen_list->cv, x, y++, "m:\t Thumbnails"); 
     206    cucul_printf(screen_list->cv, x, y++, "d:\t Detach"); 
     207    cucul_printf(screen_list->cv, x, y++, "k:\t Close window and kill associated process"); 
     208    cucul_printf(screen_list->cv, x, y++, "h:\t This help"); 
     209    cucul_printf(screen_list->cv, x, y++, ""); 
     210    cucul_printf(screen_list->cv, x, y++, ""); 
     211    cucul_printf(screen_list->cv, x, y++, "See http://libcaca.zoy.org/wiki/neercs for more informations"); 
     212} 
     213 
    348214 
    349215 
     
    391257            ((s->orig_h/2) - s->h/2); 
    392258    } 
    393  
    394259    return 1; 
    395260} 
  • neercs/trunk/src/main.c

    r2493 r2495  
    7979int main(int argc, char **argv) 
    8080{ 
    81     static cucul_canvas_t *cv = NULL; 
    82     static caca_display_t *dp = NULL; 
    8381    struct screen_list *screen_list = NULL; 
    84     struct recurrent_list *recurrent_list = NULL; 
    8582    struct passwd *user_info; 
    86     char *default_shell = NULL, *user_path = NULL, *session_name = NULL; 
    87     int i, w, h, args, s=0; 
     83    char *user_path = NULL, *session_name = NULL; 
     84    int i, args, s=0; 
    8885    int eof = 0, refresh = 1, command = 0; 
    8986    long long unsigned int last_key_time = 0; 
    90     int lock_offset = 0; 
    9187    int mainret = 0; 
    9288    int attach = 0, forceattach = 0; 
     
    9490    int nb_to_grab = 0; 
    9591 
    96     default_shell = getenv("SHELL"); 
     92    screen_list = create_screen_list(); 
     93    screen_list->default_shell = getenv("SHELL"); 
    9794 
    9895    args = argc -1; 
    99     if(default_shell == NULL  && args <= 0) 
     96    if(screen_list->default_shell == NULL  && args <= 0) 
    10097    { 
    10198        fprintf(stderr, "Environment variable SHELL not set and no arguments given. kthxbye.\n"); 
     
    114111    } 
    115112 
    116     /* Create screen list */ 
    117     screen_list = (struct screen_list*)     malloc(sizeof(struct screen_list)); 
    118     if(!screen_list) 
     113 
     114 
     115    screen_list->recurrent_list = (struct recurrent_list*) malloc(sizeof(struct recurrent_list)); 
     116    screen_list->recurrent_list->recurrent = (struct recurrent**) malloc(sizeof(struct recurrent*)); 
     117    if(!screen_list->recurrent_list->recurrent) 
    119118    { 
    120119        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__); 
    121120        return -1; 
    122121    } 
    123     screen_list->screen = (struct screen**) malloc(sizeof(sizeof(struct screen*))); 
    124     if(!screen_list->screen) 
    125     { 
    126         fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__); 
    127         return -1; 
    128     } 
    129  
    130     screen_list->count = 0; 
    131     screen_list->mini = 1; 
    132     screen_list->help = 0; 
    133     screen_list->status = 1; 
    134     screen_list->wm_type = WM_VSPLIT; 
    135     screen_list->in_bell = 0; 
    136     screen_list->pty = screen_list->prevpty = 0; 
    137     screen_list->dont_update_coords = 0; 
    138     screen_list->screensaver_timeout = (60) * 1000000; 
    139     screen_list->screensaver_data = NULL; 
    140     screen_list->in_screensaver = 0; 
    141     screen_list->locked = 0; 
    142     screen_list->attached = 1; 
    143     screen_list->socket = 0; 
    144     screen_list->socket_dir = NULL; 
    145     screen_list->socket_path = NULL; 
    146     screen_list->session_name = NULL; 
    147     memset(screen_list->lockmsg, 0, 1024); 
    148     memset(screen_list->lockpass, 0, 1024); 
    149  
    150     recurrent_list = (struct recurrent_list*) malloc(sizeof(struct recurrent_list)); 
    151     recurrent_list->recurrent = (struct recurrent**) malloc(sizeof(struct recurrent*)); 
    152     if(!recurrent_list->recurrent) 
    153     { 
    154         fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__); 
    155         return -1; 
    156     } 
    157     recurrent_list->count = 0; 
     122    screen_list->recurrent_list->count = 0; 
    158123 
    159124    for(;;) 
     
    299264 
    300265    /* Create main canvas and associated caca window */ 
    301     cv = cucul_create_canvas(0, 0); 
    302     dp = caca_create_display(cv); 
    303     if(!dp) 
     266    screen_list->cv = cucul_create_canvas(0, 0); 
     267    screen_list->dp = caca_create_display(screen_list->cv); 
     268    if(!screen_list->dp) 
    304269        return 1; 
    305     caca_set_cursor(dp, 1); 
    306  
    307     w = cucul_get_canvas_width(cv); 
    308     h = cucul_get_canvas_height(cv); 
    309  
    310     screen_list->width  = cucul_get_canvas_width(cv); 
    311     screen_list->height = cucul_get_canvas_height(cv) - ((screen_list->mini*6) + (screen_list->status)); 
     270    caca_set_cursor(screen_list->dp, 1); 
     271 
     272    screen_list->width  = cucul_get_canvas_width(screen_list->cv); 
     273    screen_list->height = cucul_get_canvas_height(screen_list->cv) - ((screen_list->mini*6) + (screen_list->status)); 
    312274 
    313275    if(nb_to_grab == 0 && s == argc -1) 
    314276    { 
    315         add_screen(screen_list, create_screen(w, h, default_shell)); 
     277        add_screen(screen_list, 
     278                   create_screen(screen_list->width, 
     279                                 screen_list->height, 
     280                                 screen_list->default_shell)); 
    316281    } 
    317282 
     
    319284    for(i=0; i<nb_to_grab; i++) 
    320285    { 
    321         add_screen(screen_list,create_screen_grab(w, h, to_grab[i])); 
     286        add_screen(screen_list,create_screen_grab(screen_list->width, screen_list->height, to_grab[i])); 
    322287    } 
    323288    free(to_grab); 
     
    326291    for(i=0; i<(argc-1) - s; i++) 
    327292    { 
    328         add_screen(screen_list, create_screen(w, h, argv[i+s+1])); 
     293        add_screen(screen_list, create_screen(screen_list->width, screen_list->height, argv[i+s+1])); 
    329294    } 
    330295 
    331296    /* Windows are in a temporary state, resize them to the right dimensions */ 
    332     update_windows_props(cv, screen_list); 
     297    update_windows_props(screen_list); 
    333298 
    334299    last_key_time = get_us(); 
     
    340305        int ret = 0; 
    341306 
     307        /* Read program output */ 
    342308        refresh |= update_screens_contents(screen_list); 
    343309 
    344         refresh |= read_socket(screen_list, cv, &dp); 
     310        /* If screen was attached, read its output */ 
     311        refresh |= read_socket(screen_list, screen_list->cv, &screen_list->dp); 
    345312 
    346313        /* No more screens, exit */ 
     
    352319        /* Get events, if any */ 
    353320        if(screen_list->attached) 
    354             ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, 0); 
     321            ret = caca_get_event(screen_list->dp, CACA_EVENT_ANY, &ev, 0); 
    355322        else 
    356323            sleep(1); 
     
    359326        { 
    360327            unsigned int c = caca_get_event_key_ch(&ev); 
     328            char *str = NULL; 
     329            int size = 0; 
     330            /* CTRL-A has been pressed before, handle this as a command */ 
    361331            if(command) 
    362332            { 
    363333                command = 0; 
    364  
    365                 switch(c) 
    366                 { 
    367                 case 0x01: //CACA_KEY_CTRL_A: 
    368                     screen_list->pty ^= screen_list->prevpty; 
    369                     screen_list->prevpty ^= screen_list->pty; 
    370                     screen_list->pty ^= screen_list->prevpty; 
    371                     refresh = 1; 
    372                     break; 
    373                 case 'm': 
    374                 case 0x0d: //CACA_KEY_CTRL_M: 
    375                     screen_list->mini = !screen_list->mini; 
    376                     refresh = 1; 
    377                     break; 
    378                 case 'n': 
    379                 case ' ': 
    380                 case '\0': 
    381                 case 0x0e: //CACA_KEY_CTRL_N: 
    382                     screen_list->prevpty = screen_list->pty; 
    383                     screen_list->pty = (screen_list->pty + 1) % screen_list->count; 
    384                     refresh = 1; 
    385                     break; 
    386                 case 'p': 
    387                 case 0x10: //CACA_KEY_CTRL_P: 
    388                     screen_list->prevpty = screen_list->pty; 
    389                     screen_list->pty = (screen_list->pty + screen_list->count - 1) % screen_list->count; 
    390                     refresh = 1; 
    391                     break; 
    392                 case 'c': 
    393                 case 0x03: //CACA_KEY_CTRL_C: 
    394                     screen_list->prevpty = screen_list->pty; 
    395                     screen_list->pty = 
    396                         add_screen(screen_list, create_screen(w, h, default_shell)); 
    397                     refresh = 1; 
    398                     break; 
    399                 case 'w': 
    400                 case 0x17: //CACA_KEY_CTRL_W: 
    401                     screen_list->wm_type = (screen_list->wm_type==(WM_MAX-1)? 
    402                                             screen_list->wm_type=0: 
    403                                             screen_list->wm_type+1); 
    404                     refresh = 1; 
    405                     break; 
    406                 case 0x0b: //CACA_KEY_CTRL_K: 
    407                     add_recurrent(recurrent_list, close_screen_recurrent, cv); 
    408                     refresh = 1; 
    409                     break; 
    410                 case 'x': 
    411                 case 0x18: //CACA_KEY_CTRL_X: 
    412                     memset(screen_list->lockpass, 0, 1024); 
    413                     screen_list->locked = 1; 
    414                     lock_offset = 0; 
    415                     refresh = 1; 
    416                     break; 
    417                 case 'h': 
    418                 case 0x08: //CACA_KEY_CTRL_H: 
    419                     screen_list->help = !screen_list->help; 
    420                     refresh = 1; 
    421                     break; 
    422                 case 'd': 
    423                 case 0x04: //CACA_KEY_CTRL_D: 
    424                     detach(screen_list, dp); 
    425                     break; 
    426                 } 
     334                refresh |= handle_command_input(screen_list, c); 
    427335            } 
    428336            else 
    429337            { 
    430  
     338                /* Not in command mode */ 
    431339                last_key_time = get_us(); 
    432                 caca_set_cursor(dp, 1); 
    433  
     340                caca_set_cursor(screen_list->dp, 1); 
     341 
     342                /* Kill screensaver */ 
    434343                if(screen_list->in_screensaver) 
    435344                { 
    436                     screensaver_kill(cv, dp, screen_list); 
     345                    screensaver_kill(screen_list); 
    437346                    screen_list->in_screensaver = 0; 
    438347                    refresh = 1; 
    439348                    continue; 
    440349                } 
    441                 else if(screen_list->locked) 
    442                 { 
    443                     if(c==0x08) 
    444                     { 
    445                         if(lock_offset) 
    446                         { 
    447                             screen_list->lockpass[lock_offset-1] = 0; 
    448                             lock_offset--; 
    449                         } 
    450                     } 
    451                     else if(c==0x0d) // RETURN 
    452                     { 
    453                         memset(screen_list->lockmsg, 0, 1024); 
    454                         if(validate_lock(screen_list, getenv("USER"), screen_list->lockpass)) 
    455                         { 
    456                             memset(screen_list->lockpass, 0, 1024); 
    457                             screen_list->locked = 0; 
    458                             lock_offset = 0; 
    459                             refresh = 1; 
    460                         } 
    461                         else 
    462                         { 
    463                             memset(screen_list->lockpass, 0, 1024); 
    464                             lock_offset = 0; 
    465                             refresh = 1; 
    466                         } 
    467                     } 
    468                     else 
    469                     { 
    470                         if(lock_offset < 1023) 
    471                         { 
    472                             screen_list->lockpass[lock_offset++] = c; 
    473                             screen_list->lockpass[lock_offset]   = 0; 
    474                         } 
    475                     } 
    476                 } 
     350                /* Handle lock window */ 
     351                if(screen_list->locked) 
     352                    refresh |= update_lock(c, screen_list); 
    477353                else 
    478354                { 
     
    481357                    case 0x01: //CACA_KEY_CTRL_A: 
    482358                        command = 1; break; 
    483                     case CACA_KEY_UP: 
    484                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[A", 3); break; 
    485                     case CACA_KEY_DOWN: 
    486                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[B", 3); break; 
    487                     case CACA_KEY_RIGHT: 
    488                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[C", 3); break; 
    489                     case CACA_KEY_LEFT: 
    490                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[D", 3); break; 
    491                     case CACA_KEY_PAGEUP: 
    492                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[5~", 4); break; 
    493                     case CACA_KEY_PAGEDOWN: 
    494                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[6~", 4); break; 
    495                     case CACA_KEY_HOME: 
    496                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[1~", 4); break; 
    497                     case CACA_KEY_INSERT: 
    498                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[2~", 4); break; 
    499                     case CACA_KEY_DELETE: 
    500                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[3~", 4); break; 
    501                     case CACA_KEY_END: 
    502                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[4~", 4); break; 
    503                     case CACA_KEY_F1: 
    504                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[11~", 5); break; 
    505                     case CACA_KEY_F2: 
    506                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[12~", 5); break; 
    507                     case CACA_KEY_F3: 
    508                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[13~", 5); break; 
    509                     case CACA_KEY_F4: 
    510                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[14~", 5); break; 
    511                     case CACA_KEY_F5: 
    512                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[15~", 5); break; 
    513                     case CACA_KEY_F6: 
    514                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[16~", 5); break; 
    515                     case CACA_KEY_F7: 
    516                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[17~", 5); break; 
    517                     case CACA_KEY_F8: 
    518                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[18~", 5); break; 
    519                     case CACA_KEY_F9: 
    520                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[19~", 5); break; 
    521                     case CACA_KEY_F10: 
    522                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[20~", 5); break; 
    523                     case CACA_KEY_F11: 
    524                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[21~", 5); break; 
    525                     case CACA_KEY_F12: 
    526                         write(screen_list->screen[screen_list->pty]->fd, "\x1b[22~", 5); break; 
    527  
    528359                    case CACA_KEY_ESCAPE: 
    529360                        if(screen_list->help) 
     
    534365                        } 
    535366                    default: 
    536                         write(screen_list->screen[screen_list->pty]->fd, &c, 1); break; 
     367                        /* Normal key, convert it if needed */ 
     368                        str = convert_input_ansi(&c, &size); 
     369                        write(screen_list->screen[screen_list->pty]->fd, str, size); 
     370                        break; 
    537371                    } 
    538372                } 
    539373            } 
    540374        } 
     375        /* Window resized */ 
    541376        else if(ret && (caca_get_event_type(&ev) & CACA_EVENT_RESIZE)) 
    542377        { 
    543             update_windows_props(cv, screen_list); 
    544             cucul_clear_canvas(cv); 
     378            update_windows_props(screen_list); 
     379            cucul_clear_canvas(screen_list->cv); 
    545380            refresh = 1; 
    546381        } 
     382        /* Window closed */ 
    547383        else if(ret && (caca_get_event_type(&ev) & CACA_EVENT_QUIT)) 
    548384        { 
     
    551387        } 
    552388 
    553         /* Recurrent functions */ 
    554         for(i=0; i<recurrent_list->count; i++) 
    555         { 
    556             if(recurrent_list->recurrent[i]->function) 
    557             { 
    558                 refresh |= recurrent_list->recurrent[i]->function(screen_list, 
    559                                                                   recurrent_list->recurrent[i], 
    560                                                                   recurrent_list->recurrent[i]->user, 
    561                                                                   get_us()); 
    562             } 
    563         } 
    564         /* Delete recurrent functions */ 
    565         for(i=0; i<recurrent_list->count; i++) 
    566         { 
    567             if(recurrent_list->recurrent[i]->kill_me) 
    568             { 
    569                 remove_recurrent(recurrent_list, i); 
    570                 i = 0; 
    571             } 
    572         } 
     389        /* Launch reccurents if any */ 
     390        refresh |= handle_recurrents(screen_list); 
    573391 
    574392        /* Resfresh screen */ 
     
    577395            /* No need to refresh */ 
    578396        } 
     397        /* Draw lock window */ 
    579398        else if(screen_list->locked) 
    580399        { 
    581             draw_lock(cv, screen_list); 
     400            draw_lock(screen_list); 
    582401            refresh = 1; 
    583402        } 
     
    587406               (get_us() - last_key_time < screen_list->screensaver_timeout)) 
    588407            { 
    589                 refresh_screens(cv, screen_list); 
     408                refresh_screens(screen_list); 
    590409                if(screen_list->screen[screen_list->pty]->title) 
    591                     caca_set_display_title(dp, screen_list->screen[screen_list->pty]->title); 
     410                    caca_set_display_title(screen_list->dp, screen_list->screen[screen_list->pty]->title); 
    592411                else 
    593                     caca_set_display_title(dp, PACKAGE_STRING); 
     412                    caca_set_display_title(screen_list->dp, PACKAGE_STRING); 
    594413                refresh = 1; 
    595414 
     
    599418            { 
    600419                if(!screen_list->in_screensaver) 
    601                     screensaver_init(cv, dp, screen_list); 
     420                    screensaver_init(screen_list); 
    602421                screen_list->in_screensaver = 1; 
    603422 
    604                 caca_set_cursor(dp, 0); 
    605                 draw_screensaver(cv, dp, screen_list); 
     423                caca_set_cursor(screen_list->dp, 0); 
     424                draw_screensaver(screen_list); 
    606425                refresh = 1; 
    607426            } 
     
    611430        if(refresh) 
    612431        { 
    613             caca_refresh_display(dp); 
     432            caca_refresh_display(screen_list->dp); 
    614433            refresh = 0; 
    615434        } 
     
    624443 
    625444    /* Clean up */ 
    626     if(dp) 
    627         caca_free_display(dp); 
    628     cucul_free_canvas(cv); 
     445    if(screen_list->dp) 
     446        caca_free_display(screen_list->dp); 
     447    cucul_free_canvas(screen_list->cv); 
    629448    for(i = 0; i < screen_list->count; i++) 
    630449    { 
     
    657476        free(screen_list); 
    658477 
    659     for(i=0; i<recurrent_list->count; i++) 
    660     { 
    661         remove_recurrent(recurrent_list, i); 
     478    for(i=0; i<screen_list->recurrent_list->count; i++) 
     479    { 
     480        remove_recurrent(screen_list->recurrent_list, i); 
    662481        i = 0; 
    663482    } 
    664483 
    665     if(recurrent_list->recurrent) free(recurrent_list->recurrent); 
    666     if(recurrent_list)            free(recurrent_list); 
     484    if(screen_list->recurrent_list->recurrent) free(screen_list->recurrent_list->recurrent); 
     485    if(screen_list->recurrent_list)            free(screen_list->recurrent_list); 
    667486 
    668487    return mainret; 
     488} 
     489 
     490 
     491 
     492 
     493struct screen_list *create_screen_list(void) 
     494{ 
     495 
     496    struct screen_list *screen_list = NULL; 
     497 
     498    /* Create screen list */ 
     499    screen_list = (struct screen_list*)     malloc(sizeof(struct screen_list)); 
     500    if(!screen_list) 
     501    { 
     502        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__); 
     503        return NULL; 
     504    } 
     505    screen_list->screen = (struct screen**) malloc(sizeof(sizeof(struct screen*))); 
     506    if(!screen_list->screen) 
     507    { 
     508        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__); 
     509        free(screen_list); 
     510        return NULL; 
     511    } 
     512 
     513    screen_list->count = 0; 
     514    screen_list->mini = 1; 
     515    screen_list->help = 0; 
     516    screen_list->status = 1; 
     517    screen_list->wm_type = WM_VSPLIT; 
     518    screen_list->in_bell = 0; 
     519    screen_list->pty = screen_list->prevpty = 0; 
     520    screen_list->dont_update_coords = 0; 
     521    screen_list->screensaver_timeout = (60) * 1000000; 
     522    screen_list->screensaver_data = NULL; 
     523    screen_list->in_screensaver = 0; 
     524    screen_list->locked = 0; 
     525    screen_list->lock_offset = 0; 
     526    screen_list->attached = 1; 
     527    screen_list->socket = 0; 
     528    screen_list->socket_dir    = NULL; 
     529    screen_list->socket_path   = NULL; 
     530    screen_list->session_name  = NULL; 
     531    screen_list->default_shell = NULL; 
     532 
     533    screen_list->recurrent_list = NULL; 
     534    screen_list->cv = NULL; 
     535    screen_list->dp = NULL; 
     536 
     537    memset(screen_list->lockmsg, 0, 1024); 
     538    memset(screen_list->lockpass, 0, 1024); 
     539 
     540    return screen_list; 
    669541} 
    670542 
  • neercs/trunk/src/neercs.h

    r2488 r2495  
    8080    /* Lock */ 
    8181    int locked; 
     82    int lock_offset; 
    8283    char lockpass[1024]; 
    8384    char lockmsg[1024]; 
     
    99100 
    100101    struct option *config; 
    101  
     102    char *default_shell; 
     103    struct recurrent_list *recurrent_list; 
     104 
     105    cucul_canvas_t *cv; 
     106    caca_display_t *dp; 
    102107}; 
    103108 
     
    123128 
    124129 
     130struct screen_list *create_screen_list(void); 
    125131 
    126132int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid); 
     
    131137int set_tty_size(int fd, unsigned int w, unsigned int h); 
    132138int update_terms(struct screen_list* screen_list); 
    133 void refresh_screens(cucul_canvas_t *cv, struct screen_list *screen_list); 
     139void refresh_screens(struct screen_list *screen_list); 
    134140int update_screens_contents(struct screen_list* screen_list); 
    135141long long get_us(void); 
     
    150156 
    151157/* Window managers */ 
    152 void update_windows_props(cucul_canvas_t *cv, struct screen_list *screen_list); 
    153 void update_windows_props_cards(cucul_canvas_t *cv, struct screen_list *screen_list); 
    154 void update_windows_props_hsplit(cucul_canvas_t *cv, struct screen_list *screen_list); 
    155 void update_windows_props_full(cucul_canvas_t *cv, struct screen_list *screen_list); 
    156 void update_windows_props_vsplit(cucul_canvas_t *cv, struct screen_list *screen_list); 
     158void update_windows_props(struct screen_list *screen_list); 
     159void update_windows_props_cards(struct screen_list *screen_list); 
     160void update_windows_props_hsplit(struct screen_list *screen_list); 
     161void update_windows_props_full(struct screen_list *screen_list); 
     162void update_windows_props_vsplit(struct screen_list *screen_list); 
    157163 
    158164/* Effects and addons */ 
    159 void draw_thumbnails(cucul_canvas_t *cv, struct screen_list *screen_list); 
    160 void draw_status(cucul_canvas_t *cv, struct screen_list *screen_list); 
    161 void draw_help(cucul_canvas_t *cv, struct screen_list *screen_list); 
    162 void draw_lock(cucul_canvas_t *cv, struct screen_list *screen_list); 
     165void draw_thumbnails(struct screen_list *screen_list); 
     166void draw_status(struct screen_list *screen_list); 
     167void draw_help(struct screen_list *screen_list); 
     168void draw_lock(struct screen_list *screen_list); 
     169int update_lock(int c, struct screen_list *screen_list); 
    163170int validate_lock(struct screen_list *screen_list, char *user, char *pass); 
    164171 
    165172int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t); 
    166173 
     174/* Input to ANSI */ 
     175void *convert_input_ansi(unsigned int *c, int *size); 
     176int  handle_command_input(struct screen_list*screen_list, unsigned int c); 
     177 
    167178 
    168179/* Screensavers */ 
    169 void screensaver_init(cucul_canvas_t *cv, 
    170                       caca_display_t *dp, 
    171                       struct screen_list *screen_list); 
    172 void screensaver_kill(cucul_canvas_t *cv, 
    173                       caca_display_t *dp, 
    174                       struct screen_list *screen_list); 
    175  
    176 void draw_screensaver(cucul_canvas_t *cv, 
    177                       caca_display_t *dp, 
    178                       struct screen_list *screen_list); 
    179 void screensaver_flying_toasters(cucul_canvas_t *cv, 
    180                                  caca_display_t *dp, 
    181                                  struct screen_list *screen_list); 
    182  
    183 void screensaver_flying_toasters_init(cucul_canvas_t *cv, 
    184                                  caca_display_t *dp, 
    185                                  struct screen_list *screen_list); 
    186  
    187 void screensaver_flying_toasters_kill(cucul_canvas_t *cv, 
    188                                  caca_display_t *dp, 
    189                                  struct screen_list *screen_list); 
     180void screensaver_init(struct screen_list *screen_list); 
     181void screensaver_kill(struct screen_list *screen_list); 
     182 
     183void draw_screensaver(struct screen_list *screen_list); 
     184void screensaver_flying_toasters(struct screen_list *screen_list); 
     185 
     186void screensaver_flying_toasters_init(struct screen_list *screen_list); 
     187 
     188void screensaver_flying_toasters_kill(struct screen_list *screen_list); 
    190189 
    191190 
    192191 
    193192/* Recurrents */ 
     193int handle_recurrents(struct screen_list* screen_list); 
    194194int add_recurrent(struct recurrent_list *list, 
    195195                  int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t), 
  • neercs/trunk/src/recurrent.c

    r2473 r2495  
    2929 
    3030#include "neercs.h" 
     31 
     32 
     33int handle_recurrents(struct screen_list* screen_list) 
     34{ 
     35    int refresh = 0, i; 
     36    /* Recurrent functions */ 
     37    for(i=0; i<screen_list->recurrent_list->count; i++) 
     38    { 
     39        if(screen_list->recurrent_list->recurrent[i]->function) 
     40        { 
     41            refresh |= screen_list->recurrent_list->recurrent[i]->function(screen_list, 
     42                                                                           screen_list->recurrent_list->recurrent[i], 
     43                                                                           screen_list->recurrent_list->recurrent[i]->user, 
     44                                                                           get_us()); 
     45        } 
     46    } 
     47    /* Delete recurrent functions */ 
     48    for(i=0; i<screen_list->recurrent_list->count; i++) 
     49    { 
     50        if(screen_list->recurrent_list->recurrent[i]->kill_me) 
     51        { 
     52            remove_recurrent(screen_list->recurrent_list, i); 
     53            i = 0; 
     54        } 
     55    } 
     56    return refresh; 
     57} 
     58 
    3159 
    3260/* Add recurrent function. It will be called at each main loop iteration, unless it is removed */ 
  • neercs/trunk/src/screens.c

    r2478 r2495  
    173173 
    174174 
    175 void refresh_screens(cucul_canvas_t *cv, 
    176                      struct screen_list *screen_list) 
     175void refresh_screens(struct screen_list *screen_list) 
    177176{ 
    178177    int i; 
     
    180179    if(!screen_list->count) return; 
    181180 
    182     screen_list->width  = cucul_get_canvas_width(cv); 
    183     screen_list->height = cucul_get_canvas_height(cv) - (screen_list->mini*6); 
     181    screen_list->width  = cucul_get_canvas_width(screen_list->cv); 
     182    screen_list->height = cucul_get_canvas_height(screen_list->cv) - (screen_list->mini*6); 
    184183 
    185184    if(!screen_list->dont_update_coords) 
    186         update_windows_props(cv, screen_list); 
    187  
    188     cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_DEFAULT); 
    189     cucul_clear_canvas(cv); 
    190     cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_BLACK); 
     185        update_windows_props(screen_list); 
     186 
     187    cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_DEFAULT); 
     188    cucul_clear_canvas(screen_list->cv); 
     189    cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTRED, CUCUL_BLACK); 
    191190 
    192191    for(i = screen_list->count - 1; i >=0; i--) 
     
    194193        if(i!=screen_list->pty && screen_list->screen[i]->visible) 
    195194        { 
    196             cucul_blit(cv, 
     195            cucul_blit(screen_list->cv, 
    197196                       screen_list->screen[i]->x, 
    198197                       screen_list->screen[i]->y, 
    199198                       screen_list->screen[i]->cv, NULL); 
    200199 
    201             cucul_draw_cp437_box(cv, 
     200            cucul_draw_cp437_box(screen_list->cv, 
    202201                                 screen_list->screen[i]->x - 1, 
    203202                                 screen_list->screen[i]->y - 1, 
     
    205204                                 screen_list->screen[i]->h + 2); 
    206205            if(screen_list->screen[i]->title) 
    207                 cucul_printf(cv, 
     206                cucul_printf(screen_list->cv, 
    208207                             screen_list->screen[i]->x, 
    209208                             screen_list->screen[i]->y - 1, 
     
    214213    } 
    215214 
    216     cucul_blit(cv, 
     215    cucul_blit(screen_list->cv, 
    217216               screen_list->screen[screen_list->pty]->x, 
    218217               screen_list->screen[screen_list->pty]->y, 
     
    221220    if(screen_list->screen[screen_list->pty]->bell) 
    222221    { 
    223         cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_BLACK); 
     222        cucul_set_color_ansi(screen_list->cv, CUCUL_RED, CUCUL_BLACK); 
    224223        screen_list->screen[screen_list->pty]->bell = 0; 
    225224        screen_list->in_bell--; 
     
    227226    else 
    228227    { 
    229         cucul_set_color_ansi(cv, CUCUL_LIGHTGREEN, CUCUL_BLACK); 
    230     } 
    231  
    232     cucul_draw_cp437_box(cv, 
     228        cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTGREEN, CUCUL_BLACK); 
     229    } 
     230 
     231    cucul_draw_cp437_box(screen_list->cv, 
    233232                         screen_list->screen[screen_list->pty]->x - 1, 
    234233                         screen_list->screen[screen_list->pty]->y - 1, 
     
    238237    if(screen_list->screen[screen_list->pty]->title) 
    239238    { 
    240         cucul_printf(cv, 
     239        cucul_printf(screen_list->cv, 
    241240                     screen_list->screen[screen_list->pty]->x, 
    242241                     screen_list->screen[screen_list->pty]->y - 1, 
     
    246245    } 
    247246 
    248     cucul_gotoxy(cv, 
     247    cucul_gotoxy(screen_list->cv, 
    249248                 screen_list->screen[screen_list->pty]->x + 
    250249                 cucul_get_cursor_x(screen_list->screen[screen_list->pty]->cv), 
     
    255254    if(screen_list->mini) 
    256255    { 
    257         draw_thumbnails(cv, screen_list); 
     256        draw_thumbnails(screen_list); 
    258257    } 
    259258    if(screen_list->status) 
    260259    { 
    261         draw_status(cv, screen_list); 
     260        draw_status(screen_list); 
    262261    } 
    263262    if(screen_list->help) 
    264263    { 
    265         draw_help(cv, screen_list); 
     264        draw_help(screen_list); 
    266265    } 
    267266} 
  • neercs/trunk/src/screensaver.c

    r2448 r2495  
    3131 
    3232 
    33 void screensaver_init(cucul_canvas_t *cv, 
    34                       caca_display_t *dp, 
    35                       struct screen_list *screen_list) 
     33void screensaver_init(struct screen_list *screen_list) 
    3634{ 
    3735 
    38     screensaver_flying_toasters_init(cv, dp, screen_list); 
     36    screensaver_flying_toasters_init(screen_list); 
    3937} 
    4038 
    41 void screensaver_kill(cucul_canvas_t *cv, 
    42                       caca_display_t *dp, 
    43                       struct screen_list *screen_list) 
     39void screensaver_kill(struct screen_list *screen_list) 
    4440{ 
    4541 
    46     screensaver_flying_toasters_kill(cv, dp, screen_list); 
     42    screensaver_flying_toasters_kill(screen_list); 
    4743} 
    4844 
    49 void draw_screensaver(cucul_canvas_t *cv, 
    50                       caca_display_t *dp, 
    51                       struct screen_list *screen_list) 
     45void draw_screensaver(struct screen_list *screen_list) 
    5246{ 
    53     screensaver_flying_toasters(cv, dp, screen_list); 
     47    screensaver_flying_toasters(screen_list); 
    5448} 
    5549 
     
    9387}; 
    9488 
    95 void screensaver_flying_toasters_init(cucul_canvas_t *cv, 
    96                                       caca_display_t *dp, 
    97                                       struct screen_list *screen_list) 
     89void screensaver_flying_toasters_init(struct screen_list *screen_list) 
    9890{ 
    9991    struct flying_toaster *flying_toaster; 
    100     int w = cucul_get_canvas_width(cv); 
    101     int h = cucul_get_canvas_height(cv); 
     92    int w = cucul_get_canvas_width(screen_list->cv); 
     93    int h = cucul_get_canvas_height(screen_list->cv); 
    10294    int i; 
    10395 
     
    132124} 
    133125 
    134 void screensaver_flying_toasters_kill(cucul_canvas_t *cv, 
    135                                       caca_display_t *dp, 
    136                                       struct screen_list *screen_list) 
     126void screensaver_flying_toasters_kill(struct screen_list *screen_list) 
    137127{ 
    138128    struct flying_toaster *flying_toaster = screen_list->screensaver_data; 
     
    146136} 
    147137 
    148 void screensaver_flying_toasters(cucul_canvas_t *cv, 
    149                                  caca_display_t *dp, 
    150                                  struct screen_list *screen_list) 
     138void screensaver_flying_toasters(struct screen_list *screen_list) 
    151139{ 
    152140    struct flying_toaster *d = screen_list->screensaver_data; 
     
    154142    if(!d) return; 
    155143 
    156     w = cucul_get_canvas_width(cv); 
    157     h = cucul_get_canvas_height(cv); 
     144    w = cucul_get_canvas_width(screen_list->cv); 
     145    h = cucul_get_canvas_height(screen_list->cv); 
    158146 
    159147 
    160     cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK); 
    161     cucul_clear_canvas(cv); 
     148    cucul_set_color_ansi(screen_list->cv, CUCUL_WHITE, CUCUL_BLACK); 
     149    cucul_clear_canvas(screen_list->cv); 
    162150 
    163151 
     
    165153    for(i = 0; i < COUNT; i++) 
    166154    { 
    167         cucul_blit(cv, d->x[i]/PRECISION, d->y[i]/PRECISION, d->toaster[d->s[i]/PRECISION], NULL); 
     155        cucul_blit(screen_list->cv, d->x[i]/PRECISION, d->y[i]/PRECISION, d->toaster[d->s[i]/PRECISION], NULL); 
    168156 
    169157        d->x[i]-=40; 
  • neercs/trunk/src/wm.c

    r2445 r2495  
    4747} 
    4848 
    49 void update_windows_props(cucul_canvas_t *cv, struct screen_list *screen_list) 
     49void update_windows_props(struct screen_list *screen_list) 
    5050{ 
    5151    if(!screen_list->count) return; 
     
    5454    { 
    5555    case WM_CARD: 
    56         update_windows_props_cards(cv, screen_list); 
     56        update_windows_props_cards(screen_list); 
    5757        break; 
    5858    case WM_HSPLIT: 
    59         update_windows_props_hsplit(cv, screen_list); 
     59        update_windows_props_hsplit(screen_list); 
    6060        break; 
    6161    case WM_VSPLIT: 
    62         update_windows_props_vsplit(cv, screen_list); 
     62        update_windows_props_vsplit(screen_list); 
    6363        break; 
    6464    case WM_FULL: 
    6565    default: 
    66         update_windows_props_full(cv, screen_list); 
     66        update_windows_props_full(screen_list); 
    6767        break; 
    6868    } 
    6969} 
    7070 
    71 void update_windows_props_hsplit(cucul_canvas_t *cv, struct screen_list *screen_list) 
     71void update_windows_props_hsplit(struct screen_list *screen_list) 
    7272{ 
    7373    int i; 
     
    9292} 
    9393 
    94 void update_windows_props_vsplit(cucul_canvas_t *cv, struct screen_list *screen_list) 
     94void update_windows_props_vsplit(struct screen_list *screen_list) 
    9595{ 
    9696    int i; 
     
    116116 
    117117 
    118 void update_windows_props_full(cucul_canvas_t *cv, struct screen_list *screen_list) 
     118void update_windows_props_full(struct screen_list *screen_list) 
    119119{ 
    120120    int i; 
     
    135135 
    136136 
    137 void update_windows_props_cards(cucul_canvas_t *cv, struct screen_list *screen_list) 
     137void update_windows_props_cards(struct screen_list *screen_list) 
    138138{ 
    139139    int i; 
Note: See TracChangeset for help on using the changeset viewer.