19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef SAVE_RCSID 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic char rcsid = 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "@(#) $Id: libsdl-1.2.11-libcaca.patch,v 1.1 2006/09/18 16:06:06 mr_bones_ Exp $"; 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h> 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <caca.h> 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef CACA_API_VERSION_1 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <caca0.h> 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL.h" 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_sysevents.h" 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h" 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_cacavideo.h" 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_cacaevents_c.h" 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid Caca_PumpEvents(_THIS) 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int posted = 0; 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int event; 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_keysym keysym; 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( ! this->screen ) /* Wait till we got the screen initialised */ 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall do { 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall posted = 0; 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Get libcaca event */ 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_mutexP(Caca_mutex); 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall event = caca_get_event(CACA_EVENT_ANY); 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_mutexV(Caca_mutex); 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( event & (CACA_EVENT_KEY_PRESS | CACA_EVENT_KEY_RELEASE)) { 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int key; 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch ( event & 0xffffff ) 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CACA_KEY_LEFT: key = SDLK_LEFT; break; 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CACA_KEY_RIGHT: key = SDLK_RIGHT; break; 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CACA_KEY_UP: key = SDLK_UP; break; 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CACA_KEY_DOWN: key = SDLK_DOWN; break; 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: key = event & 0xff; break; 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Key pressed */ 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* printf("Key pressed: %d (%c)\n", key, key); */ 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.scancode = key; 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.sym = key; 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.mod = KMOD_NONE; 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.unicode = 0; 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_TranslateUNICODE ) { 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.unicode = key; 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall posted += SDL_PrivateKeyboard((event & CACA_EVENT_KEY_PRESS) ? SDL_PRESSED : SDL_RELEASED, &keysym); 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if ( event & (CACA_EVENT_MOUSE_PRESS | CACA_EVENT_MOUSE_RELEASE) ) { 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* FIXME: we currently ignore the button type! */ 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int button = event & 0x00ffffff; 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( button > 3 ) { 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall button = 1; 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall posted += SDL_PrivateMouseButton((event & CACA_EVENT_MOUSE_PRESS) ? SDL_PRESSED : SDL_RELEASED, button, 0, 0); 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if ( event & CACA_EVENT_MOUSE_MOTION ) { 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int new_x = 0, new_y = 0; 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall new_x = ((event & 0x00fff000) >> 12) * Caca_w / caca_get_width(); 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall new_y = ((event & 0x00000fff) >> 0) * Caca_h / caca_get_height(); 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall posted += SDL_PrivateMouseMotion(0, 0, new_x, new_y); 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } while ( posted ); 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid Caca_InitOSKeymap(_THIS) 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 102