Changeset 3946


Ignore:
Timestamp:
11/18/09 18:09:26 (4 years ago)
Author:
jylam
Message:
  • Explode server.c a bit more. KABOOOOM. (Maybe) fix a bug of missing refresh after cube transition
Location:
neercs/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/neercs.h

    r3944 r3946  
    164164    long long unsigned int last_key_time; 
    165165    int command; 
     166    int was_in_bell; 
     167    long long unsigned int last_refresh_time; 
     168 
    166169 
    167170    /* Detaching */ 
  • neercs/trunk/src/server.c

    r3945 r3946  
    3737 
    3838static void server_init(struct screen_list *screen_list); 
    39 static int handle_key(struct screen_list *screen_list, unsigned int c); 
     39static int refresh_screen(struct screen_list *screen_list, int refresh); 
     40static int handle_key(struct screen_list *screen_list, unsigned int c, int refresh); 
    4041static int handle_attach(struct screen_list *screen_list, char *buf); 
    4142 
     
    6566    char buf[1024]; 
    6667    int bytes; 
    67     char *title; 
     68    char *title = NULL; 
    6869 
    6970    if (screen_list->attached) 
     
    204205{ 
    205206    int i; 
    206     int eof = 0, refresh = 1, was_in_bell = 0; 
    207     long long unsigned int last_refresh_time = 0; 
     207    int eof = 0, refresh = 1; 
    208208 
    209209    screen_list->last_key_time = 0; 
    210210    screen_list->attached = 0; 
    211211    screen_list->command = 0; 
     212    screen_list->was_in_bell = 0; 
     213    screen_list->last_refresh_time = 0; 
    212214 
    213215    server_init(screen_list); 
     
    255257            { 
    256258                unsigned int c = atoi(buf + 4); 
    257                 refresh |= handle_key(screen_list, c); 
     259                refresh |= handle_key(screen_list, c, refresh); 
    258260            } 
    259261            else 
     
    278280 
    279281        /* Refresh screen */ 
    280         if (!screen_list->attached) 
    281         { 
    282             /* No need to refresh Don't use the CPU too much Would be better 
    283                to select on terms + socket */ 
    284             sleep(1); 
    285         } 
    286         else 
    287         { 
    288             long long unsigned int current_time = get_us(); 
    289             long long int tdiff = (current_time - last_refresh_time) / 1000; 
    290             /* Draw lock window */ 
    291             if (screen_list->locked) 
    292             { 
    293                 draw_lock(screen_list); 
    294                 refresh = 1; 
    295             } 
    296             else if ((current_time - screen_list->last_key_time >= 
    297                       screen_list->autolock_timeout)) 
    298             { 
    299                 screen_list->locked = 1; 
    300                 refresh = 1; 
    301             } 
    302             else if ((current_time - screen_list->last_key_time >= 
    303                       screen_list->screensaver_timeout)) 
    304             { 
    305                 if (!screen_list->in_screensaver) 
    306                 { 
    307                     screensaver_init(screen_list); 
    308                     screen_list->in_screensaver = 1; 
    309                     set_cursor(0, screen_list); 
    310                 } 
    311                 draw_screensaver(screen_list); 
    312                 refresh = 1; 
    313             } 
    314             else if (refresh || was_in_bell) 
    315             { 
    316                 if (tdiff >= screen_list->delay) 
    317                 { 
    318                     was_in_bell = screen_list->in_bell; 
    319                     refresh_screens(screen_list); 
    320                     set_title(screen_list); 
    321                     refresh = 1; 
    322                 } 
    323             } 
    324             if (refresh) 
    325             { 
    326                 if (tdiff >= screen_list->delay) 
    327                 { 
    328                     request_refresh(screen_list); 
    329                     refresh = 0; 
    330                     last_refresh_time = current_time; 
    331                 } 
    332                 else 
    333                     debug("Skipping refresh (%lld < %d)", tdiff, 
    334                           screen_list->delay); 
    335             } 
    336         } 
    337  
    338         if (screen_list->force_refresh) 
    339         { 
    340             wm_refresh(screen_list); 
    341             request_refresh(screen_list); 
    342         } 
     282        refresh |= refresh_screen(screen_list, refresh); 
    343283 
    344284        eof = 1; 
     
    357297} 
    358298 
     299static int refresh_screen(struct screen_list *screen_list, int refresh) 
     300{     
     301    if (!screen_list->attached) 
     302    { 
     303        /* No need to refresh Don't use the CPU too much Would be better to 
     304           select on terms + socket */ 
     305        sleep(1); 
     306    } 
     307    else 
     308    { 
     309        long long unsigned int current_time = get_us(); 
     310        long long int tdiff = (current_time - screen_list->last_refresh_time) / 1000; 
     311         
     312         
     313        if (screen_list->force_refresh) 
     314        { 
     315            wm_refresh(screen_list); 
     316            request_refresh(screen_list); 
     317        } 
     318         
     319         
     320        /* Draw lock window */ 
     321        if (screen_list->locked) 
     322        { 
     323            draw_lock(screen_list); 
     324            refresh = 1; 
     325        } 
     326        else if ((current_time - screen_list->last_key_time >= 
     327                  screen_list->autolock_timeout)) 
     328        { 
     329            screen_list->locked = 1; 
     330            refresh = 1; 
     331        } 
     332        else if ((current_time - screen_list->last_key_time >= 
     333                  screen_list->screensaver_timeout)) 
     334        { 
     335            if (!screen_list->in_screensaver) 
     336            { 
     337                screensaver_init(screen_list); 
     338                screen_list->in_screensaver = 1; 
     339                set_cursor(0, screen_list); 
     340            } 
     341            draw_screensaver(screen_list); 
     342            refresh = 1; 
     343        } 
     344        else if (refresh || screen_list->was_in_bell) 
     345        { 
     346            if (tdiff >= screen_list->delay) 
     347            { 
     348                screen_list->was_in_bell = screen_list->in_bell; 
     349                refresh_screens(screen_list); 
     350                set_title(screen_list); 
     351                refresh = 1; 
     352            } 
     353        } 
     354        if (refresh) 
     355        { 
     356            if (tdiff >= screen_list->delay) 
     357            { 
     358                request_refresh(screen_list); 
     359                refresh = 0; 
     360                screen_list->last_refresh_time = current_time; 
     361            } 
     362            else 
     363            { 
     364                debug("Skipping refresh (%lld < %d)", tdiff, 
     365                      screen_list->delay); 
     366            } 
     367        } 
     368    } 
     369   
     370    return 1; 
     371} 
    359372 
    360373static void server_init(struct screen_list *screen_list) 
     
    428441} 
    429442 
    430 static int handle_key(struct screen_list *screen_list, unsigned int c) 
    431 { 
    432     int refresh = 0; 
     443static int handle_key(struct screen_list *screen_list, unsigned int c, int refresh) 
     444{ 
    433445    char *str = NULL; 
    434446    int size = 0; 
     
    549561    screen_list->cv = caca_create_canvas(0, 0); 
    550562    screen_list->dp = caca_create_display(screen_list->cv); 
    551      
     563 
    552564    if (!screen_list->dp) 
    553565        return -3; 
    554      
     566 
    555567    caca_set_display_time(screen_list->dp, screen_list->delay * 1000); 
    556568    caca_set_cursor(screen_list->dp, 1); 
Note: See TracChangeset for help on using the changeset viewer.