source: libcaca/trunk/src/io.c @ 341

Last change on this file since 341 was 336, checked in by Sam Hocevar, 16 years ago
  • src/caca.c src/graphics.c src/io.c src/time.c: + Native win32 port.
  • Property svn:keywords set to Id
File size: 21.3 KB
Line 
1/*
2 *  libcaca       ASCII-Art library
3 *  Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  This library is free software; you can redistribute it and/or
7 *  modify it under the terms of the GNU Lesser General Public
8 *  License as published by the Free Software Foundation; either
9 *  version 2 of the License, or (at your option) any later version.
10 *
11 *  This library is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 *  Lesser General Public License for more details.
15 *
16 *  You should have received a copy of the GNU Lesser General Public
17 *  License along with this library; if not, write to the Free Software
18 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 *  02111-1307  USA
20 */
21
22/** \file io.c
23 *  \version \$Id: io.c 336 2004-01-11 05:09:02Z sam $
24 *  \author Sam Hocevar <sam@zoy.org>
25 *  \brief Event handling
26 *
27 *  This file contains event handling functions for keyboard and mouse input.
28 */
29
30#include "config.h"
31
32#if defined(USE_SLANG)
33#   if defined(HAVE_SLANG_SLANG_H)
34#       include <slang/slang.h>
35#   else
36#       include <slang.h>
37#   endif
38#endif
39#if defined(USE_NCURSES)
40#   include <curses.h>
41#endif
42#if defined(USE_CONIO)
43#   include <conio.h>
44#endif
45#if defined(USE_X11)
46#   include <X11/Xlib.h>
47#   include <X11/Xutil.h>
48#   include <X11/keysym.h>
49#endif
50#if defined(USE_WIN32)
51#   include <windows.h>
52#endif
53
54#include "caca.h"
55#include "caca_internals.h"
56
57static unsigned int _get_next_event(void);
58static unsigned int _lowlevel_event(void);
59#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
60static void _push_event(unsigned int);
61static unsigned int _pop_event(void);
62#endif
63
64#if !defined(_DOXYGEN_SKIP_ME)
65#define EVENTBUF_LEN 10
66#endif
67#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
68static unsigned int eventbuf[EVENTBUF_LEN];
69static int events = 0;
70#endif
71
72#if !defined(_DOXYGEN_SKIP_ME)
73/* If no new key was pressed after AUTOREPEAT_THRESHOLD usec, assume the
74 * key was released */
75#define AUTOREPEAT_THRESHOLD 200000
76/* Start repeating key after AUTOREPEAT_TRIGGER usec and send keypress
77 * events every AUTOREPEAT_RATE usec. */
78#define AUTOREPEAT_TRIGGER 300000
79#define AUTOREPEAT_RATE 100000
80#endif
81
82/** \brief Get the next mouse or keyboard input event.
83 *
84 *  This function polls the event queue for mouse or keyboard events matching
85 *  the event mask and returns the first matching event. Non-matching events
86 *  are discarded. \c event_mask must have a non-zero value. This function is
87 *  non-blocking and returns zero if no more events are pending in the queue.
88 *  See also caca_wait_event() for a blocking version of this function.
89 *
90 * \param event_mask Bitmask of requested events.
91 * \return The next matching event in the queue, or 0 if no event is pending.
92 */
93unsigned int caca_get_event(unsigned int event_mask)
94{
95    if(!event_mask)
96        return CACA_EVENT_NONE;
97
98    for( ; ; )
99    {
100        unsigned int event = _get_next_event();
101
102        if(!event || event & event_mask)
103            return event;
104    }
105}
106
107/** \brief Wait for the next mouse or keyboard input event.
108 *
109 *  This function returns the first mouse or keyboard event in the queue
110 *  that matches the event mask. If no event is pending, it blocks until a
111 *  matching event is received. \c event_mask must have a non-zero value.
112 *  See also caca_get_event() for a non-blocking version of this function.
113 *
114 *  \param event_mask Bitmask of requested events.
115 *  \return The next event in the queue.
116 */
117unsigned int caca_wait_event(unsigned int event_mask)
118{
119    if(!event_mask)
120        return CACA_EVENT_NONE;
121
122    for( ; ; )
123    {
124        unsigned int event = _get_next_event();
125
126        if(event & event_mask)
127            return event;
128
129        _caca_sleep(10000);
130    }
131}
132
133/*
134 * XXX: The following functions are local.
135 */
136
137static unsigned int _get_next_event(void)
138{
139#if defined(USE_SLANG) || defined(USE_NCURSES)
140    static struct caca_timer key_timer = CACA_TIMER_INITIALIZER;
141    static unsigned int last_key_ticks = 0;
142    static unsigned int autorepeat_ticks = 0;
143    static unsigned int last_key = 0;
144    unsigned int ticks;
145#endif
146    unsigned int event = _lowlevel_event();
147
148#if defined(USE_SLANG)
149    if(_caca_driver != CACA_DRIVER_SLANG)
150#endif
151#if defined(USE_NCURSES)
152    if(_caca_driver != CACA_DRIVER_NCURSES)
153#endif
154    return event;
155
156#if defined(USE_SLANG) || defined(USE_NCURSES)
157    /* Simulate long keypresses using autorepeat features */
158    ticks = _caca_getticks(&key_timer);
159    last_key_ticks += ticks;
160    autorepeat_ticks += ticks;
161
162    /* Handle autorepeat */
163    if(last_key && autorepeat_ticks > AUTOREPEAT_TRIGGER
164                && autorepeat_ticks > AUTOREPEAT_THRESHOLD
165                && autorepeat_ticks > AUTOREPEAT_RATE)
166    {
167        _push_event(event);
168        autorepeat_ticks -= AUTOREPEAT_RATE;
169        return CACA_EVENT_KEY_PRESS | last_key;
170    }
171
172    /* We are in autorepeat mode and the same key was just pressed, ignore
173     * this event and return the next one by calling ourselves. */
174    if(event == (CACA_EVENT_KEY_PRESS | last_key))
175    {
176        last_key_ticks = 0;
177        return _get_next_event();
178    }
179
180    /* We are in autorepeat mode, but key has expired or a new key was
181     * pressed - store our event and return a key release event first */
182    if(last_key && (last_key_ticks > AUTOREPEAT_THRESHOLD
183                     || (event & CACA_EVENT_KEY_PRESS)))
184    {
185        _push_event(event);
186        event = CACA_EVENT_KEY_RELEASE | last_key;
187        last_key = 0;
188        return event;
189    }
190
191    /* A new key was pressed, enter autorepeat mode */
192    if(event & CACA_EVENT_KEY_PRESS)
193    {
194        last_key_ticks = 0;
195        autorepeat_ticks = 0;
196        last_key = event & 0x00ffffff;
197    }
198
199    return event;
200#endif
201}
202
203static unsigned int _lowlevel_event(void)
204{
205    unsigned int event;
206
207#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
208    event = _pop_event();
209
210    if(event)
211        return event;
212#endif
213
214#if defined(USE_X11)
215    /* The X11 event check routine */
216    if(_caca_driver == CACA_DRIVER_X11)
217    {
218        XEvent xevent;
219        static unsigned int x11_x = 0, x11_y = 0;
220        long int xevent_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
221                                | ButtonReleaseMask | PointerMotionMask;
222        char key;
223
224        while(XCheckWindowEvent(x11_dpy, x11_window, xevent_mask, &xevent)
225               == True)
226        {
227            KeySym keysym;
228
229            /* Check for mouse motion events */
230            if(xevent.type == MotionNotify)
231            {
232                unsigned int newx = xevent.xmotion.x / x11_font_width;
233                unsigned int newy = xevent.xmotion.y / x11_font_height;
234
235                if(newx >= _caca_width)
236                    newx = _caca_width - 1;
237                if(newy >= _caca_height)
238                    newy = _caca_height - 1;
239
240                if(x11_x == newx && x11_y == newy)
241                    continue;
242
243                x11_x = newx & 0xfff;
244                x11_y = newy & 0xfff;
245
246                return CACA_EVENT_MOUSE_MOTION | (newx << 12) | (newy << 0);
247            }
248
249            /* Check for mouse press and release events */
250            if(xevent.type == ButtonPress)
251                return CACA_EVENT_MOUSE_PRESS
252                        | ((XButtonEvent *)&xevent)->button;
253
254            if(xevent.type == ButtonRelease)
255                return CACA_EVENT_MOUSE_RELEASE
256                        | ((XButtonEvent *)&xevent)->button;
257
258            /* Check for key press and release events */
259            if(xevent.type == KeyPress)
260                event |= CACA_EVENT_KEY_PRESS;
261            else if(xevent.type == KeyRelease)
262                event |= CACA_EVENT_KEY_RELEASE;
263            else
264                continue;
265
266            if(XLookupString(&xevent.xkey, &key, 1, NULL, NULL))
267                return event | key;
268
269            keysym = XKeycodeToKeysym(x11_dpy, xevent.xkey.keycode, 0);
270            switch(keysym)
271            {
272            case XK_F1:    return event | CACA_KEY_F1;
273            case XK_F2:    return event | CACA_KEY_F2;
274            case XK_F3:    return event | CACA_KEY_F3;
275            case XK_F4:    return event | CACA_KEY_F4;
276            case XK_F5:    return event | CACA_KEY_F5;
277            case XK_F6:    return event | CACA_KEY_F6;
278            case XK_F7:    return event | CACA_KEY_F7;
279            case XK_F8:    return event | CACA_KEY_F8;
280            case XK_F9:    return event | CACA_KEY_F9;
281            case XK_F10:   return event | CACA_KEY_F10;
282            case XK_F11:   return event | CACA_KEY_F11;
283            case XK_F12:   return event | CACA_KEY_F12;
284            case XK_F13:   return event | CACA_KEY_F13;
285            case XK_F14:   return event | CACA_KEY_F14;
286            case XK_F15:   return event | CACA_KEY_F15;
287            case XK_Left:  return event | CACA_KEY_LEFT;
288            case XK_Right: return event | CACA_KEY_RIGHT;
289            case XK_Up:    return event | CACA_KEY_UP;
290            case XK_Down:  return event | CACA_KEY_DOWN;
291            default:       return CACA_EVENT_NONE;
292            }
293        }
294
295        return CACA_EVENT_NONE;
296    }
297    else
298#endif
299#if defined(USE_NCURSES)
300    if(_caca_driver == CACA_DRIVER_NCURSES)
301    {
302        int intkey = getch();
303        if(intkey == ERR)
304            return CACA_EVENT_NONE;
305
306        if(intkey < 0x100)
307        {
308            return CACA_EVENT_KEY_PRESS | intkey;
309        }
310
311        if(intkey == KEY_MOUSE)
312        {
313            MEVENT mevent;
314            getmouse(&mevent);
315
316            switch(mevent.bstate)
317            {
318                case BUTTON1_PRESSED:
319                    _push_event(CACA_EVENT_MOUSE_PRESS | 1);
320                    break;
321                case BUTTON1_RELEASED:
322                    _push_event(CACA_EVENT_MOUSE_RELEASE | 1);
323                    break;
324                case BUTTON1_CLICKED:
325                    _push_event(CACA_EVENT_MOUSE_PRESS | 1);
326                    _push_event(CACA_EVENT_MOUSE_RELEASE | 1);
327                    break;
328                case BUTTON1_DOUBLE_CLICKED:
329                    _push_event(CACA_EVENT_MOUSE_PRESS | 1);
330                    _push_event(CACA_EVENT_MOUSE_RELEASE | 1);
331                    _push_event(CACA_EVENT_MOUSE_PRESS | 1);
332                    _push_event(CACA_EVENT_MOUSE_RELEASE | 1);
333                    break;
334                case BUTTON1_TRIPLE_CLICKED:
335                    _push_event(CACA_EVENT_MOUSE_PRESS | 1);
336                    _push_event(CACA_EVENT_MOUSE_RELEASE | 1);
337                    _push_event(CACA_EVENT_MOUSE_PRESS | 1);
338                    _push_event(CACA_EVENT_MOUSE_RELEASE | 1);
339                    _push_event(CACA_EVENT_MOUSE_PRESS | 1);
340                    _push_event(CACA_EVENT_MOUSE_RELEASE | 1);
341                    break;
342                case BUTTON1_RESERVED_EVENT:
343                    break;
344
345                case BUTTON2_PRESSED:
346                    _push_event(CACA_EVENT_MOUSE_PRESS | 2);
347                    break;
348                case BUTTON2_RELEASED:
349                    _push_event(CACA_EVENT_MOUSE_RELEASE | 2);
350                    break;
351                case BUTTON2_CLICKED:
352                    _push_event(CACA_EVENT_MOUSE_PRESS | 2);
353                    _push_event(CACA_EVENT_MOUSE_RELEASE | 2);
354                    break;
355                case BUTTON2_DOUBLE_CLICKED:
356                    _push_event(CACA_EVENT_MOUSE_PRESS | 2);
357                    _push_event(CACA_EVENT_MOUSE_RELEASE | 2);
358                    _push_event(CACA_EVENT_MOUSE_PRESS | 2);
359                    _push_event(CACA_EVENT_MOUSE_RELEASE | 2);
360                    break;
361                case BUTTON2_TRIPLE_CLICKED:
362                    _push_event(CACA_EVENT_MOUSE_PRESS | 2);
363                    _push_event(CACA_EVENT_MOUSE_RELEASE | 2);
364                    _push_event(CACA_EVENT_MOUSE_PRESS | 2);
365                    _push_event(CACA_EVENT_MOUSE_RELEASE | 2);
366                    _push_event(CACA_EVENT_MOUSE_PRESS | 2);
367                    _push_event(CACA_EVENT_MOUSE_RELEASE | 2);
368                    break;
369                case BUTTON2_RESERVED_EVENT:
370                    break;
371
372                case BUTTON3_PRESSED:
373                    _push_event(CACA_EVENT_MOUSE_PRESS | 3);
374                    break;
375                case BUTTON3_RELEASED:
376                    _push_event(CACA_EVENT_MOUSE_RELEASE | 3);
377                    break;
378                case BUTTON3_CLICKED:
379                    _push_event(CACA_EVENT_MOUSE_PRESS | 3);
380                    _push_event(CACA_EVENT_MOUSE_RELEASE | 3);
381                    break;
382                case BUTTON3_DOUBLE_CLICKED:
383                    _push_event(CACA_EVENT_MOUSE_PRESS | 3);
384                    _push_event(CACA_EVENT_MOUSE_RELEASE | 3);
385                    _push_event(CACA_EVENT_MOUSE_PRESS | 3);
386                    _push_event(CACA_EVENT_MOUSE_RELEASE | 3);
387                    break;
388                case BUTTON3_TRIPLE_CLICKED:
389                    _push_event(CACA_EVENT_MOUSE_PRESS | 3);
390                    _push_event(CACA_EVENT_MOUSE_RELEASE | 3);
391                    _push_event(CACA_EVENT_MOUSE_PRESS | 3);
392                    _push_event(CACA_EVENT_MOUSE_RELEASE | 3);
393                    _push_event(CACA_EVENT_MOUSE_PRESS | 3);
394                    _push_event(CACA_EVENT_MOUSE_RELEASE | 3);
395                    break;
396                case BUTTON3_RESERVED_EVENT:
397                    break;
398
399                case BUTTON4_PRESSED:
400                    _push_event(CACA_EVENT_MOUSE_PRESS | 4);
401                    break;
402                case BUTTON4_RELEASED:
403                    _push_event(CACA_EVENT_MOUSE_RELEASE | 4);
404                    break;
405                case BUTTON4_CLICKED:
406                    _push_event(CACA_EVENT_MOUSE_PRESS | 4);
407                    _push_event(CACA_EVENT_MOUSE_RELEASE | 4);
408                    break;
409                case BUTTON4_DOUBLE_CLICKED:
410                    _push_event(CACA_EVENT_MOUSE_PRESS | 4);
411                    _push_event(CACA_EVENT_MOUSE_RELEASE | 4);
412                    _push_event(CACA_EVENT_MOUSE_PRESS | 4);
413                    _push_event(CACA_EVENT_MOUSE_RELEASE | 4);
414                    break;
415                case BUTTON4_TRIPLE_CLICKED:
416                    _push_event(CACA_EVENT_MOUSE_PRESS | 4);
417                    _push_event(CACA_EVENT_MOUSE_RELEASE | 4);
418                    _push_event(CACA_EVENT_MOUSE_PRESS | 4);
419                    _push_event(CACA_EVENT_MOUSE_RELEASE | 4);
420                    _push_event(CACA_EVENT_MOUSE_PRESS | 4);
421                    _push_event(CACA_EVENT_MOUSE_RELEASE | 4);
422                    break;
423                case BUTTON4_RESERVED_EVENT:
424                    break;
425
426                default:
427                    break;
428            }
429
430            return CACA_EVENT_MOUSE_MOTION | (mevent.x << 12) | mevent.y;
431        }
432
433        event = CACA_EVENT_KEY_PRESS;
434
435        switch(intkey)
436        {
437            case KEY_UP: return event | CACA_KEY_UP;
438            case KEY_DOWN: return event | CACA_KEY_DOWN;
439            case KEY_LEFT: return event | CACA_KEY_LEFT;
440            case KEY_RIGHT: return event | CACA_KEY_RIGHT;
441
442            case KEY_IC: return event | CACA_KEY_INSERT;
443            case KEY_DC: return event | CACA_KEY_DELETE;
444            case KEY_HOME: return event | CACA_KEY_HOME;
445            case KEY_END: return event | CACA_KEY_END;
446            case KEY_PPAGE: return event | CACA_KEY_PAGEUP;
447            case KEY_NPAGE: return event | CACA_KEY_PAGEDOWN;
448
449            case KEY_F(1): return event | CACA_KEY_F1;
450            case KEY_F(2): return event | CACA_KEY_F2;
451            case KEY_F(3): return event | CACA_KEY_F3;
452            case KEY_F(4): return event | CACA_KEY_F4;
453            case KEY_F(5): return event | CACA_KEY_F5;
454            case KEY_F(6): return event | CACA_KEY_F6;
455            case KEY_F(7): return event | CACA_KEY_F7;
456            case KEY_F(8): return event | CACA_KEY_F8;
457            case KEY_F(9): return event | CACA_KEY_F9;
458            case KEY_F(10): return event | CACA_KEY_F10;
459            case KEY_F(11): return event | CACA_KEY_F11;
460            case KEY_F(12): return event | CACA_KEY_F12;
461        }
462
463        return CACA_EVENT_NONE;
464    }
465    else
466#endif
467#if defined(USE_SLANG)
468    if(_caca_driver == CACA_DRIVER_SLANG)
469    {
470        int intkey;
471
472        if(!SLang_input_pending(0))
473            return CACA_EVENT_NONE;
474
475        /* We first use SLang_getkey() to see whether Esc was pressed
476         * alone, then (if it wasn't) we unget the key and use SLkp_getkey()
477         * instead, so that escape sequences are interpreted. */
478        intkey = SLang_getkey();
479
480        if(intkey != 0x1b /* Esc */ || SLang_input_pending(0))
481        {
482            SLang_ungetkey(intkey);
483            intkey = SLkp_getkey();
484        }
485
486        /* If the key was ASCII, return it immediately */
487        if(intkey < 0x100)
488        {
489            return CACA_EVENT_KEY_PRESS | intkey;
490        }
491
492        if(intkey == 0x3e9)
493        {
494            int button = (SLang_getkey() - ' ' + 1) & 0xf;
495            int x = SLang_getkey() - '!';
496            int y = SLang_getkey() - '!';
497            _push_event(CACA_EVENT_MOUSE_PRESS | button);
498            _push_event(CACA_EVENT_MOUSE_RELEASE | button);
499            return CACA_EVENT_MOUSE_MOTION | (x << 12) | (y << 0);
500        }
501
502        event = CACA_EVENT_KEY_PRESS;
503
504        switch(intkey)
505        {
506            case SL_KEY_UP: return event | CACA_KEY_UP;
507            case SL_KEY_DOWN: return event | CACA_KEY_DOWN;
508            case SL_KEY_LEFT: return event | CACA_KEY_LEFT;
509            case SL_KEY_RIGHT: return event | CACA_KEY_RIGHT;
510
511            case SL_KEY_IC: return event | CACA_KEY_INSERT;
512            case SL_KEY_DELETE: return event | CACA_KEY_DELETE;
513            case SL_KEY_HOME: return event | CACA_KEY_HOME;
514            case SL_KEY_END: return event | CACA_KEY_END;
515            case SL_KEY_PPAGE: return event | CACA_KEY_PAGEUP;
516            case SL_KEY_NPAGE: return event | CACA_KEY_PAGEDOWN;
517
518            case SL_KEY_F(1): return event | CACA_KEY_F1;
519            case SL_KEY_F(2): return event | CACA_KEY_F2;
520            case SL_KEY_F(3): return event | CACA_KEY_F3;
521            case SL_KEY_F(4): return event | CACA_KEY_F4;
522            case SL_KEY_F(5): return event | CACA_KEY_F5;
523            case SL_KEY_F(6): return event | CACA_KEY_F6;
524            case SL_KEY_F(7): return event | CACA_KEY_F7;
525            case SL_KEY_F(8): return event | CACA_KEY_F8;
526            case SL_KEY_F(9): return event | CACA_KEY_F9;
527            case SL_KEY_F(10): return event | CACA_KEY_F10;
528            case SL_KEY_F(11): return event | CACA_KEY_F11;
529            case SL_KEY_F(12): return event | CACA_KEY_F12;
530        }
531
532        return CACA_EVENT_NONE;
533    }
534    else
535#endif
536#if defined(USE_CONIO)
537    if(_caca_driver == CACA_DRIVER_CONIO)
538    {
539        if(!_conio_kbhit())
540            return CACA_EVENT_NONE;
541
542        event = getch();
543        _push_event(CACA_EVENT_KEY_RELEASE | event);
544        return CACA_EVENT_KEY_PRESS | event;
545    }
546    else
547#endif
548#if defined(USE_WIN32)
549    if(_caca_driver == CACA_DRIVER_WIN32)
550    {
551        INPUT_RECORD rec;
552        DWORD num;
553
554        GetNumberOfConsoleInputEvents(win32_hin, &num);
555        if(num == 0)
556            return CACA_EVENT_NONE;
557
558        ReadConsoleInput(win32_hin, &rec, 1, &num);
559        if(rec.EventType == KEY_EVENT)
560        {
561            if(rec.Event.KeyEvent.bKeyDown)
562                event = CACA_EVENT_KEY_PRESS;
563            else
564                event = CACA_EVENT_KEY_RELEASE;
565
566            if(rec.Event.KeyEvent.uChar.AsciiChar)
567                return event | rec.Event.KeyEvent.uChar.AsciiChar;
568        }
569        else if(rec.EventType == MOUSE_EVENT)
570        {
571            if(rec.Event.MouseEvent.dwEventFlags == 0)
572            {
573                if(rec.Event.MouseEvent.dwButtonState & 0x01)
574                    return CACA_EVENT_MOUSE_PRESS | 0x000001;
575
576                if(rec.Event.MouseEvent.dwButtonState & 0x02)
577                    return CACA_EVENT_MOUSE_PRESS | 0x000002;
578            }
579            else if(rec.Event.MouseEvent.dwEventFlags == MOUSE_MOVED)
580            {
581                return CACA_EVENT_MOUSE_MOTION
582                        | (rec.Event.MouseEvent.dwMousePosition.X << 12)
583                        | (rec.Event.MouseEvent.dwMousePosition.Y);
584            }
585#if 0
586            else if(rec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK)
587            {
588                cout << rec.Event.MouseEvent.dwMousePosition.X << "," <<
589                        rec.Event.MouseEvent.dwMousePosition.Y << "  " << flush;
590            }
591            else if(rec.Event.MouseEvent.dwEventFlags == MOUSE_WHEELED)
592            {
593                SetConsoleCursorPosition(hOut,
594                                         WheelWhere);
595                if(rec.Event.MouseEvent.dwButtonState & 0xFF000000)
596                    cout << "Down" << flush;
597                else
598                    cout << "Up  " << flush;
599            }
600#endif
601        }
602
603        return CACA_EVENT_NONE;
604    }
605    else
606#endif
607    {
608        /* Dummy */
609    }
610
611    return CACA_EVENT_NONE;
612}
613
614#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
615static void _push_event(unsigned int event)
616{
617    if(events == EVENTBUF_LEN)
618        return;
619    eventbuf[events] = event;
620    events++;
621}
622
623static unsigned int _pop_event(void)
624{
625    int i;
626    unsigned int event;
627
628    if(events == 0)
629        return CACA_EVENT_NONE;
630
631    event = eventbuf[0];
632    for(i = 1; i < events; i++)
633        eventbuf[i - 1] = eventbuf[i];
634    events--;
635
636    return event;
637}
638#endif
639
Note: See TracBrowser for help on using the repository browser.