/* SDL - Simple DirectMedia Layer Copyright (C) 1997-2012 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Sam Lantinga slouken@libsdl.org */ #include "SDL_config.h" /* Handle the event stream, converting GGI events into SDL events */ #include #include #include #include #include #include #include "SDL_ggikeys.h" #include "SDL.h" #include "../SDL_sysvideo.h" #include "../../events/SDL_sysevents.h" #include "../../events/SDL_events_c.h" #include "SDL_ggivideo.h" #include "SDL_ggievents_c.h" /* The translation tables from a GGI keycode to a SDL keysym */ static SDLKey keymap[128]; static SDL_keysym *GGI_TranslateKey(ggi_event *ev, SDL_keysym *keysym); static int posted = 0; void GGI_PumpEvents(_THIS) { struct timeval *tvp, tv = { 0, 0 }; ggi_event ev; tvp = &tv; /* ggiFlush(VIS); */ while (ggiEventPoll(VIS, emAll, tvp)) /* while (ggiEventPoll(VIS, (emKeyboard | emPointer | emCommand), tvp)) */ { int queueevent_mouse = 0, queueevent_kbd = 0; static int buttons = 0; static int mouse_x = 0, mouse_y = 0, mouse_z = 0; int x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0; int pressed_mouse, pressed_kbd; SDL_keysym keysym; posted = 0; /* FIXME: We do not actually want all events, only * mouse and keyboard events. Having to handle all * events will slow things down. */ ggiEventRead(VIS, &ev, emAll); /* ggiEventRead(VIS, &ev, (emKeyboard | emPointer | emCommand)); */ switch (ev.any.type) { case evPtrRelative: x = ev.pmove.x; y = ev.pmove.y; z = ev.pmove.wheel; posted += SDL_PrivateMouseMotion(0, 1, x, y); break; case evPtrAbsolute: if (mouse_x != ev.pmove.x || mouse_y != ev.pmove.y || mouse_z != ev.pmove.wheel) { x = ev.pmove.x - mouse_x; y = ev.pmove.y - mouse_y; z = ev.pmove.wheel - mouse_z; mouse_x = ev.pmove.x; mouse_y = ev.pmove.y; mouse_z = ev.pmove.wheel; posted += SDL_PrivateMouseMotion(0, 1, x, y); } break; case evPtrButtonPress: posted += SDL_PrivateMouseButton(SDL_PRESSED, ev.pbutton.button, 0, 0); break; case evPtrButtonRelease: posted += SDL_PrivateMouseButton(SDL_RELEASED, ev.pbutton.button, 0, 0); break; case evKeyPress: case evKeyRepeat: posted += SDL_PrivateKeyboard(SDL_PRESSED, GGI_TranslateKey(&ev, &keysym)); break; case evKeyRelease: posted += SDL_PrivateKeyboard(SDL_RELEASED, GGI_TranslateKey(&ev, &keysym)); break; case evCommand: fprintf(stderr, "Command event %x recieved\n", ev.cmd.code); break; default: fprintf(stderr, "Unhandled event type %d\n", ev.any.type); break; } } } void GGI_InitOSKeymap(_THIS) { int i; /* Initialize the GGI key translation table */ for ( i=0; iscancode = ev->key.button; keysym->sym = keymap[ev->key.button]; keysym->mod = KMOD_NONE; /* If UNICODE is on, get the UNICODE value for the key */ keysym->unicode = 0; if (SDL_TranslateUNICODE) { keysym->unicode = GII_UNICODE(ev->key.sym); } return keysym; }