Ignore:
Timestamp:
Jan 10, 2004, 8:29:12 PM (19 years ago)
Author:
Sam Hocevar
Message:
  • src/graphics: + Initialise the char buffers in the X11 driver.
  • src/io.c: + caca_get_event() and caca_wait_event() immediately return zero if

event_mask is zero.

+ Added support for the Home, End, PgUp? and PgDown? keys.
+ In the S-Lang driver, added a call to SLang_getkey() before the call to

SLkp_getkey(), otherwise a single Escape call will not be interpreted.

  • test/event.c: + The "quit" sequence now quits the program, instead of "q" alone. + Added a status bar below.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/io.c

    r331 r332  
    7979 *  This function polls the event queue for mouse or keyboard events matching
    8080 *  the event mask and returns the first matching event. Non-matching events
    81  *  are discarded. It is non-blocking and returns zero if no more events are
    82  *  pending in the queue. See also caca_wait_event() for a blocking version
    83  *  of this function.
     81 *  are discarded. \c event_mask must have a non-zero value. This function is
     82 *  non-blocking and returns zero if no more events are pending in the queue.
     83 *  See also caca_wait_event() for a blocking version of this function.
    8484 *
    8585 * \param event_mask Bitmask of requested events.
     
    8888unsigned int caca_get_event(unsigned int event_mask)
    8989{
     90    if(!event_mask)
     91        return CACA_EVENT_NONE;
     92
    9093    for( ; ; )
    9194    {
     
    101104 *  This function returns the first mouse or keyboard event in the queue
    102105 *  that matches the event mask. If no event is pending, it blocks until a
    103  *  matching event is received. See also caca_get_event() for a non-blocking
    104  *  version of this function.
     106 *  matching event is received. \c event_mask must have a non-zero value.
     107 *  See also caca_get_event() for a non-blocking version of this function.
    105108 *
    106109 *  \param event_mask Bitmask of requested events.
     
    109112unsigned int caca_wait_event(unsigned int event_mask)
    110113{
     114    if(!event_mask)
     115        return CACA_EVENT_NONE;
     116
    111117    for( ; ; )
    112118    {
     
    280286            case XK_Up:    return event | CACA_KEY_UP;
    281287            case XK_Down:  return event | CACA_KEY_DOWN;
    282             default:       return 0;
     288            default:       return CACA_EVENT_NONE;
    283289            }
    284290        }
    285291
    286         return 0;
     292        return CACA_EVENT_NONE;
    287293    }
    288294    else
     
    293299        int intkey = getch();
    294300        if(intkey == ERR)
    295             return 0;
     301            return CACA_EVENT_NONE;
    296302
    297303        if(intkey < 0x100)
     
    422428        }
    423429
     430        event = CACA_EVENT_KEY_PRESS;
     431
    424432        switch(intkey)
    425433        {
    426             case KEY_UP: event = CACA_KEY_UP; break;
    427             case KEY_DOWN: event = CACA_KEY_DOWN; break;
    428             case KEY_LEFT: event = CACA_KEY_LEFT; break;
    429             case KEY_RIGHT: event = CACA_KEY_RIGHT; break;
    430 
    431             case KEY_F(1): event = CACA_KEY_F1; break;
    432             case KEY_F(2): event = CACA_KEY_F2; break;
    433             case KEY_F(3): event = CACA_KEY_F3; break;
    434             case KEY_F(4): event = CACA_KEY_F4; break;
    435             case KEY_F(5): event = CACA_KEY_F5; break;
    436             case KEY_F(6): event = CACA_KEY_F6; break;
    437             case KEY_F(7): event = CACA_KEY_F7; break;
    438             case KEY_F(8): event = CACA_KEY_F8; break;
    439             case KEY_F(9): event = CACA_KEY_F9; break;
    440             case KEY_F(10): event = CACA_KEY_F10; break;
    441             case KEY_F(11): event = CACA_KEY_F11; break;
    442             case KEY_F(12): event = CACA_KEY_F12; break;
    443         }
    444 
    445         return CACA_EVENT_KEY_PRESS | event;
     434            case KEY_UP: return event | CACA_KEY_UP;
     435            case KEY_DOWN: return event | CACA_KEY_DOWN;
     436            case KEY_LEFT: return event | CACA_KEY_LEFT;
     437            case KEY_RIGHT: return event | CACA_KEY_RIGHT;
     438
     439            case KEY_IC: return event | CACA_KEY_INSERT;
     440            case KEY_DC: return event | CACA_KEY_DELETE;
     441            case KEY_HOME: return event | CACA_KEY_HOME;
     442            case KEY_END: return event | CACA_KEY_END;
     443            case KEY_PPAGE: return event | CACA_KEY_PAGEUP;
     444            case KEY_NPAGE: return event | CACA_KEY_PAGEDOWN;
     445
     446            case KEY_F(1): return event | CACA_KEY_F1;
     447            case KEY_F(2): return event | CACA_KEY_F2;
     448            case KEY_F(3): return event | CACA_KEY_F3;
     449            case KEY_F(4): return event | CACA_KEY_F4;
     450            case KEY_F(5): return event | CACA_KEY_F5;
     451            case KEY_F(6): return event | CACA_KEY_F6;
     452            case KEY_F(7): return event | CACA_KEY_F7;
     453            case KEY_F(8): return event | CACA_KEY_F8;
     454            case KEY_F(9): return event | CACA_KEY_F9;
     455            case KEY_F(10): return event | CACA_KEY_F10;
     456            case KEY_F(11): return event | CACA_KEY_F11;
     457            case KEY_F(12): return event | CACA_KEY_F12;
     458        }
     459
     460        return CACA_EVENT_NONE;
    446461    }
    447462    else
     
    453468
    454469        if(!SLang_input_pending(0))
    455             return 0;
    456 
    457         intkey = SLkp_getkey();
    458 
     470            return CACA_EVENT_NONE;
     471
     472        /* We first use SLang_getkey() to see whether Esc was pressed
     473         * alone, then (if it wasn't) we unget the key and use SLkp_getkey()
     474         * instead, so that escape sequences are interpreted. */
     475        intkey = SLang_getkey();
     476
     477        if(intkey != 0x1b /* Esc */ || SLang_input_pending(0))
     478        {
     479            SLang_ungetkey(intkey);
     480            intkey = SLkp_getkey();
     481        }
     482
     483        /* If the key was ASCII, return it immediately */
    459484        if(intkey < 0x100)
    460485        {
     
    472497        }
    473498
     499        event = CACA_EVENT_KEY_PRESS;
     500
    474501        switch(intkey)
    475502        {
    476             case SL_KEY_UP: event = CACA_KEY_UP; break;
    477             case SL_KEY_DOWN: event = CACA_KEY_DOWN; break;
    478             case SL_KEY_LEFT: event = CACA_KEY_LEFT; break;
    479             case SL_KEY_RIGHT: event = CACA_KEY_RIGHT; break;
    480 
    481             case SL_KEY_F(1): event = CACA_KEY_F1; break;
    482             case SL_KEY_F(2): event = CACA_KEY_F2; break;
    483             case SL_KEY_F(3): event = CACA_KEY_F3; break;
    484             case SL_KEY_F(4): event = CACA_KEY_F4; break;
    485             case SL_KEY_F(5): event = CACA_KEY_F5; break;
    486             case SL_KEY_F(6): event = CACA_KEY_F6; break;
    487             case SL_KEY_F(7): event = CACA_KEY_F7; break;
    488             case SL_KEY_F(8): event = CACA_KEY_F8; break;
    489             case SL_KEY_F(9): event = CACA_KEY_F9; break;
    490             case SL_KEY_F(10): event = CACA_KEY_F10; break;
    491             case SL_KEY_F(11): event = CACA_KEY_F11; break;
    492             case SL_KEY_F(12): event = CACA_KEY_F12; break;
    493         }
    494 
    495         return CACA_EVENT_KEY_PRESS | event;
     503            case SL_KEY_UP: return event | CACA_KEY_UP;
     504            case SL_KEY_DOWN: return event | CACA_KEY_DOWN;
     505            case SL_KEY_LEFT: return event | CACA_KEY_LEFT;
     506            case SL_KEY_RIGHT: return event | CACA_KEY_RIGHT;
     507
     508            case SL_KEY_IC: return event | CACA_KEY_INSERT;
     509            case SL_KEY_DELETE: return event | CACA_KEY_DELETE;
     510            case SL_KEY_HOME: return event | CACA_KEY_HOME;
     511            case SL_KEY_END: return event | CACA_KEY_END;
     512            case SL_KEY_PPAGE: return event | CACA_KEY_PAGEUP;
     513            case SL_KEY_NPAGE: return event | CACA_KEY_PAGEDOWN;
     514
     515            case SL_KEY_F(1): return event | CACA_KEY_F1;
     516            case SL_KEY_F(2): return event | CACA_KEY_F2;
     517            case SL_KEY_F(3): return event | CACA_KEY_F3;
     518            case SL_KEY_F(4): return event | CACA_KEY_F4;
     519            case SL_KEY_F(5): return event | CACA_KEY_F5;
     520            case SL_KEY_F(6): return event | CACA_KEY_F6;
     521            case SL_KEY_F(7): return event | CACA_KEY_F7;
     522            case SL_KEY_F(8): return event | CACA_KEY_F8;
     523            case SL_KEY_F(9): return event | CACA_KEY_F9;
     524            case SL_KEY_F(10): return event | CACA_KEY_F10;
     525            case SL_KEY_F(11): return event | CACA_KEY_F11;
     526            case SL_KEY_F(12): return event | CACA_KEY_F12;
     527        }
     528
     529        return CACA_EVENT_NONE;
    496530    }
    497531    else
     
    501535    {
    502536        if(!_conio_kbhit())
    503             return 0;
     537            return CACA_EVENT_NONE;
    504538
    505539        event = getch();
     
    513547    }
    514548
    515     return 0;
     549    return CACA_EVENT_NONE;
    516550}
    517551
     
    530564
    531565    if(events == 0)
    532         return 0;
     566        return CACA_EVENT_NONE;
    533567
    534568    event = eventbuf[0];
Note: See TracChangeset for help on using the changeset viewer.