/* 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 X11 events into SDL events */ #include #include #include #include #include #include "SDL.h" #include "SDL_thread.h" #include "../../events/SDL_sysevents.h" #include "../../events/SDL_events_c.h" #include "SDL_vglvideo.h" #include "SDL_vglevents_c.h" /* The translation tables from a console scancode to a SDL keysym */ /* FIXME: Free the keymap when we shut down the video mode */ static keymap_t *vga_keymap = NULL; static SDLKey keymap[128]; static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym); static int posted = 0; static int oldx = -1; static int oldy = -1; static struct mouse_info mouseinfo; /* Ugh, we have to duplicate the kernel's keysym mapping code... Oh, it's not so bad. :-) FIXME: Add keyboard LED handling code */ int VGL_initkeymaps(int fd) { vga_keymap = SDL_malloc(sizeof(keymap_t)); if ( ! vga_keymap ) { SDL_OutOfMemory(); return(-1); } if (ioctl(fd, GIO_KEYMAP, vga_keymap) == -1) { SDL_free(vga_keymap); vga_keymap = NULL; SDL_SetError("Unable to get keyboard map"); return(-1); } return(0); } static void handle_keyboard(_THIS) { SDL_keysym keysym; int c, pressed, scancode; while ((c = VGLKeyboardGetCh()) != 0) { scancode = c & 0x7F; if (c & 0x80) { pressed = SDL_RELEASED; } else { pressed = SDL_PRESSED; } posted += SDL_PrivateKeyboard(pressed, TranslateKey(scancode, &keysym)); } } int VGL_initmouse(int fd) { mouseinfo.operation = MOUSE_GETINFO; if (ioctl(fd, CONS_MOUSECTL, &mouseinfo) != 0) return -1; return 0; } static void handle_mouse(_THIS) { char buttons; int x, y; int button_state, state_changed, state; int i; ioctl(0, CONS_MOUSECTL, &mouseinfo); x = mouseinfo.u.data.x; y = mouseinfo.u.data.y; buttons = mouseinfo.u.data.buttons; if ((x != oldx) || (y != oldy)) { posted += SDL_PrivateMouseMotion(0, 0, x, y); oldx = x; oldy = y; } /* See what's changed */ button_state = SDL_GetMouseState(NULL, NULL); state_changed = button_state ^ buttons; for (i = 0; i < 8; i++) { if (state_changed & (1<scancode = scancode; keysym->sym = keymap[scancode]; keysym->mod = KMOD_NONE; /* If UNICODE is on, get the UNICODE value for the key */ keysym->unicode = 0; if ( SDL_TranslateUNICODE && vga_keymap ) { int map; SDLMod modstate; modstate = SDL_GetModState(); map = 0; if ( modstate & KMOD_SHIFT ) { map += 1; } if ( modstate & KMOD_CTRL ) { map += 2; } if ( modstate & KMOD_ALT ) { map += 4; } if ( !(vga_keymap->key[scancode].spcl & (0x80 >> map)) ) { keysym->unicode = vga_keymap->key[scancode].map[map]; } } return(keysym); }