Ignore:
Timestamp:
Jan 9, 2004, 10:51:53 AM (17 years ago)
Author:
Sam Hocevar
Message:
  • test/event.c: + Do not refresh after each event, but only when there is no event

pending.

+ If the pressed key is a printable character, display it.

  • src/time.c: + Moved _caca_getticks() to this file.
  • src/caca.c: + Set the escape delay to a very low value in the ncurses driver,

because I don't want escape sequences to be entered manually.

  • src/io.c: + Autorepeat emulation in the ncurses and slang drivers: do not

immediately send the key release event.

  • configure.ac: + Check for usleep. + Improvements in the win32 platform detection.
File:
1 edited

Legend:

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

    r329 r331  
    5555
    5656static unsigned int _get_next_event(void);
     57static unsigned int _lowlevel_event(void);
    5758static void _push_event(unsigned int);
    5859static unsigned int _pop_event(void);
     
    6364static unsigned int eventbuf[EVENTBUF_LEN];
    6465static int events = 0;
     66
     67#if !defined(_DOXYGEN_SKIP_ME)
     68/* If no new key was pressed after AUTOREPEAT_THRESHOLD usec, assume the
     69 * key was released */
     70#define AUTOREPEAT_THRESHOLD 200000
     71/* Start repeating key after AUTOREPEAT_TRIGGER usec and send keypress
     72 * events every AUTOREPEAT_RATE usec. */
     73#define AUTOREPEAT_TRIGGER 300000
     74#define AUTOREPEAT_RATE 100000
     75#endif
    6576
    6677/** \brief Get the next mouse or keyboard input event.
     
    105116            return event;
    106117
    107         usleep(1000);
     118#if defined(HAVE_USLEEP)
     119        usleep(10000);
     120#elif defined(HAVE_SLEEP)
     121        Sleep(10);
     122#else
     123        SLEEP
     124#endif
    108125    }
    109126}
     
    114131
    115132static unsigned int _get_next_event(void)
     133{
     134#if defined(USE_SLANG) || defined(USE_NCURSES)
     135    static struct caca_timer key_timer = CACA_TIMER_INITIALIZER;
     136    static unsigned int last_key_ticks = 0;
     137    static unsigned int autorepeat_ticks = 0;
     138    static unsigned int last_key = 0;
     139    unsigned int ticks;
     140#endif
     141    unsigned int event = _lowlevel_event();
     142
     143#if defined(USE_SLANG)
     144    if(_caca_driver != CACA_DRIVER_SLANG)
     145#endif
     146#if defined(USE_NCURSES)
     147    if(_caca_driver != CACA_DRIVER_NCURSES)
     148#endif
     149    return event;
     150
     151#if defined(USE_SLANG) || defined(USE_NCURSES)
     152    /* Simulate long keypresses using autorepeat features */
     153    ticks = _caca_getticks(&key_timer);
     154    last_key_ticks += ticks;
     155    autorepeat_ticks += ticks;
     156
     157    /* Handle autorepeat */
     158    if(last_key && autorepeat_ticks > AUTOREPEAT_TRIGGER
     159                && autorepeat_ticks > AUTOREPEAT_THRESHOLD
     160                && autorepeat_ticks > AUTOREPEAT_RATE)
     161    {
     162        _push_event(event);
     163        autorepeat_ticks -= AUTOREPEAT_RATE;
     164        return CACA_EVENT_KEY_PRESS | last_key;
     165    }
     166
     167    /* We are in autorepeat mode and the same key was just pressed, ignore
     168     * this event and return the next one by calling ourselves. */
     169    if(event == (CACA_EVENT_KEY_PRESS | last_key))
     170    {
     171        last_key_ticks = 0;
     172        return _get_next_event();
     173    }
     174
     175    /* We are in autorepeat mode, but key has expired or a new key was
     176     * pressed - store our event and return a key release event first */
     177    if(last_key && (last_key_ticks > AUTOREPEAT_THRESHOLD
     178                     || (event & CACA_EVENT_KEY_PRESS)))
     179    {
     180        _push_event(event);
     181        event = CACA_EVENT_KEY_RELEASE | last_key;
     182        last_key = 0;
     183        return event;
     184    }
     185
     186    /* A new key was pressed, enter autorepeat mode */
     187    if(event & CACA_EVENT_KEY_PRESS)
     188    {
     189        last_key_ticks = 0;
     190        autorepeat_ticks = 0;
     191        last_key = event & 0x00ffffff;
     192    }
     193
     194    return event;
     195#endif
     196}
     197
     198static unsigned int _lowlevel_event(void)
    116199{
    117200    unsigned int event = _pop_event();
     
    214297        if(intkey < 0x100)
    215298        {
    216             _push_event(CACA_EVENT_KEY_RELEASE | intkey);
    217299            return CACA_EVENT_KEY_PRESS | intkey;
    218300        }
     
    361443        }
    362444
    363         _push_event(CACA_EVENT_KEY_RELEASE | event);
    364445        return CACA_EVENT_KEY_PRESS | event;
    365446    }
     
    378459        if(intkey < 0x100)
    379460        {
    380             _push_event(CACA_EVENT_KEY_RELEASE | intkey);
    381461            return CACA_EVENT_KEY_PRESS | intkey;
    382462        }
     
    413493        }
    414494
    415         _push_event(CACA_EVENT_KEY_RELEASE | event);
    416495        return CACA_EVENT_KEY_PRESS | event;
    417496    }
Note: See TracChangeset for help on using the changeset viewer.