quakeforge/libs/video/targets/in_sdl.c

610 lines
12 KiB
C
Raw Normal View History

/*
in_sdl.c
general sdl input driver
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <SDL.h>
#include "QF/cdaudio.h"
#include "QF/cvar.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/mathlib.h"
#include "QF/qargs.h"
#include "QF/sound.h"
2001-08-27 01:00:03 +00:00
#include "QF/sys.h"
#include "QF/vid.h"
2001-08-27 01:00:03 +00:00
#include "compat.h"
cvar_t *in_snd_block;
static keydest_t old_key_dest = key_none;
static int have_focus = 1;
static void
event_focusout (void)
{
if (have_focus) {
have_focus = 0;
if (in_snd_block->int_val) {
S_BlockSound ();
CDAudio_Pause ();
}
}
}
static void
event_focusin (void)
{
have_focus = 1;
if (in_snd_block->int_val) {
S_UnblockSound ();
CDAudio_Resume ();
}
}
void
IN_LL_ProcessEvents (void)
{
SDL_Event event;
int sym, state, but;
knum_t ksym;
short unicode;
while (SDL_PollEvent (&event)) {
// Ugly key repeat handling. Should use a key_dest callback...
if (old_key_dest != key_dest) {
old_key_dest = key_dest;
if (key_dest == key_game)
SDL_EnableKeyRepeat (0, SDL_DEFAULT_REPEAT_INTERVAL);
else
SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY,
SDL_DEFAULT_REPEAT_INTERVAL);
}
switch (event.type) {
case SDL_ACTIVEEVENT:
if (event.active.state == SDL_APPINPUTFOCUS) {
if (event.active.gain)
event_focusin ();
else
event_focusout ();
}
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
sym = event.key.keysym.sym;
state = event.key.state;
unicode = event.key.keysym.unicode;
switch (sym) {
case SDLK_UNKNOWN:
2001-10-28 04:23:37 +00:00
ksym = QFK_UNKNOWN;
break;
case SDLK_BACKSPACE:
2001-10-28 04:23:37 +00:00
ksym = QFK_BACKSPACE;
break;
case SDLK_TAB:
2001-10-28 04:23:37 +00:00
ksym = QFK_TAB;
break;
case SDLK_CLEAR:
2001-10-28 04:23:37 +00:00
ksym = QFK_CLEAR;
break;
case SDLK_RETURN:
2001-10-28 04:23:37 +00:00
ksym = QFK_RETURN;
break;
case SDLK_PAUSE:
2001-10-28 04:23:37 +00:00
ksym = QFK_PAUSE;
break;
case SDLK_ESCAPE:
2001-10-28 04:23:37 +00:00
ksym = QFK_ESCAPE;
break;
case SDLK_SPACE:
2001-10-28 04:23:37 +00:00
ksym = QFK_SPACE;
break;
case SDLK_EXCLAIM:
2001-10-28 04:23:37 +00:00
ksym = QFK_EXCLAIM;
break;
case SDLK_QUOTEDBL:
2001-10-28 04:23:37 +00:00
ksym = QFK_QUOTEDBL;
break;
case SDLK_HASH:
2001-10-28 04:23:37 +00:00
ksym = QFK_HASH;
break;
case SDLK_DOLLAR:
2001-10-28 04:23:37 +00:00
ksym = QFK_DOLLAR;
break;
case SDLK_AMPERSAND:
2001-10-28 04:23:37 +00:00
ksym = QFK_AMPERSAND;
break;
case SDLK_QUOTE:
2001-10-28 04:23:37 +00:00
ksym = QFK_QUOTE;
break;
case SDLK_LEFTPAREN:
2001-10-28 04:23:37 +00:00
ksym = QFK_LEFTPAREN;
break;
case SDLK_RIGHTPAREN:
2001-10-28 04:23:37 +00:00
ksym = QFK_RIGHTPAREN;
break;
case SDLK_ASTERISK:
2001-10-28 04:23:37 +00:00
ksym = QFK_ASTERISK;
break;
case SDLK_PLUS:
2001-10-28 04:23:37 +00:00
ksym = QFK_PLUS;
break;
case SDLK_COMMA:
2001-10-28 04:23:37 +00:00
ksym = QFK_COMMA;
break;
case SDLK_MINUS:
2001-10-28 04:23:37 +00:00
ksym = QFK_MINUS;
break;
case SDLK_PERIOD:
2001-10-28 04:23:37 +00:00
ksym = QFK_PERIOD;
break;
case SDLK_SLASH:
2001-10-28 04:23:37 +00:00
ksym = QFK_SLASH;
break;
case SDLK_0:
2001-10-28 04:23:37 +00:00
ksym = QFK_0;
break;
case SDLK_1:
2001-10-28 04:23:37 +00:00
ksym = QFK_1;
break;
case SDLK_2:
2001-10-28 04:23:37 +00:00
ksym = QFK_2;
break;
case SDLK_3:
2001-10-28 04:23:37 +00:00
ksym = QFK_3;
break;
case SDLK_4:
2001-10-28 04:23:37 +00:00
ksym = QFK_4;
break;
case SDLK_5:
2001-10-28 04:23:37 +00:00
ksym = QFK_5;
break;
case SDLK_6:
2001-10-28 04:23:37 +00:00
ksym = QFK_6;
break;
case SDLK_7:
2001-10-28 04:23:37 +00:00
ksym = QFK_7;
break;
case SDLK_8:
2001-10-28 04:23:37 +00:00
ksym = QFK_8;
break;
case SDLK_9:
2001-10-28 04:23:37 +00:00
ksym = QFK_9;
break;
case SDLK_COLON:
2001-10-28 04:23:37 +00:00
ksym = QFK_COLON;
break;
case SDLK_SEMICOLON:
2001-10-28 04:23:37 +00:00
ksym = QFK_SEMICOLON;
break;
case SDLK_LESS:
2001-10-28 04:23:37 +00:00
ksym = QFK_LESS;
break;
case SDLK_EQUALS:
2001-10-28 04:23:37 +00:00
ksym = QFK_EQUALS;
break;
case SDLK_GREATER:
2001-10-28 04:23:37 +00:00
ksym = QFK_GREATER;
break;
case SDLK_QUESTION:
2001-10-28 04:23:37 +00:00
ksym = QFK_QUESTION;
break;
case SDLK_AT:
2001-10-28 04:23:37 +00:00
ksym = QFK_AT;
break;
case SDLK_LEFTBRACKET:
2001-10-28 04:23:37 +00:00
ksym = QFK_LEFTBRACKET;
break;
case SDLK_BACKSLASH:
2001-10-28 04:23:37 +00:00
ksym = QFK_BACKSLASH;
break;
case SDLK_RIGHTBRACKET:
2001-10-28 04:23:37 +00:00
ksym = QFK_RIGHTBRACKET;
break;
case SDLK_CARET:
2001-10-28 04:23:37 +00:00
ksym = QFK_CARET;
break;
case SDLK_UNDERSCORE:
2001-10-28 04:23:37 +00:00
ksym = QFK_UNDERSCORE;
break;
case SDLK_BACKQUOTE:
2001-10-28 04:23:37 +00:00
ksym = QFK_BACKQUOTE;
break;
case SDLK_a:
2001-10-28 04:23:37 +00:00
ksym = QFK_a;
break;
case SDLK_b:
2001-10-28 04:23:37 +00:00
ksym = QFK_b;
break;
case SDLK_c:
2001-10-28 04:23:37 +00:00
ksym = QFK_c;
break;
case SDLK_d:
2001-10-28 04:23:37 +00:00
ksym = QFK_d;
break;
case SDLK_e:
2001-10-28 04:23:37 +00:00
ksym = QFK_e;
break;
case SDLK_f:
2001-10-28 04:23:37 +00:00
ksym = QFK_f;
break;
case SDLK_g:
2001-10-28 04:23:37 +00:00
ksym = QFK_g;
break;
case SDLK_h:
2001-10-28 04:23:37 +00:00
ksym = QFK_h;
break;
case SDLK_i:
2001-10-28 04:23:37 +00:00
ksym = QFK_i;
break;
case SDLK_j:
2001-10-28 04:23:37 +00:00
ksym = QFK_j;
break;
case SDLK_k:
2001-10-28 04:23:37 +00:00
ksym = QFK_k;
break;
case SDLK_l:
2001-10-28 04:23:37 +00:00
ksym = QFK_l;
break;
case SDLK_m:
2001-10-28 04:23:37 +00:00
ksym = QFK_m;
break;
case SDLK_n:
2001-10-28 04:23:37 +00:00
ksym = QFK_n;
break;
case SDLK_o:
2001-10-28 04:23:37 +00:00
ksym = QFK_o;
break;
case SDLK_p:
2001-10-28 04:23:37 +00:00
ksym = QFK_p;
break;
case SDLK_q:
2001-10-28 04:23:37 +00:00
ksym = QFK_q;
break;
case SDLK_r:
2001-10-28 04:23:37 +00:00
ksym = QFK_r;
break;
case SDLK_s:
2001-10-28 04:23:37 +00:00
ksym = QFK_s;
break;
case SDLK_t:
2001-10-28 04:23:37 +00:00
ksym = QFK_t;
break;
case SDLK_u:
2001-10-28 04:23:37 +00:00
ksym = QFK_u;
break;
case SDLK_v:
2001-10-28 04:23:37 +00:00
ksym = QFK_v;
break;
case SDLK_w:
2001-10-28 04:23:37 +00:00
ksym = QFK_w;
break;
case SDLK_x:
2001-10-28 04:23:37 +00:00
ksym = QFK_x;
break;
case SDLK_y:
2001-10-28 04:23:37 +00:00
ksym = QFK_y;
break;
case SDLK_z:
2001-10-28 04:23:37 +00:00
ksym = QFK_z;
break;
case SDLK_DELETE:
2001-10-28 04:23:37 +00:00
ksym = QFK_DELETE;
break;
case SDLK_KP0:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP0;
break;
case SDLK_KP1:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP1;
break;
case SDLK_KP2:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP2;
break;
case SDLK_KP3:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP3;
break;
case SDLK_KP4:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP4;
break;
case SDLK_KP5:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP5;
break;
case SDLK_KP6:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP6;
break;
case SDLK_KP7:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP7;
break;
case SDLK_KP8:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP8;
break;
case SDLK_KP9:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP9;
break;
case SDLK_KP_PERIOD:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP_PERIOD;
break;
case SDLK_KP_DIVIDE:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP_DIVIDE;
break;
case SDLK_KP_MULTIPLY:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP_MULTIPLY;
break;
case SDLK_KP_MINUS:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP_MINUS;
break;
case SDLK_KP_PLUS:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP_PLUS;
break;
case SDLK_KP_ENTER:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP_ENTER;
break;
case SDLK_KP_EQUALS:
2001-10-28 04:23:37 +00:00
ksym = QFK_KP_EQUALS;
break;
case SDLK_UP:
2001-10-28 04:23:37 +00:00
ksym = QFK_UP;
break;
case SDLK_DOWN:
2001-10-28 04:23:37 +00:00
ksym = QFK_DOWN;
break;
case SDLK_RIGHT:
2001-10-28 04:23:37 +00:00
ksym = QFK_RIGHT;
break;
case SDLK_LEFT:
2001-10-28 04:23:37 +00:00
ksym = QFK_LEFT;
break;
case SDLK_INSERT:
2001-10-28 04:23:37 +00:00
ksym = QFK_INSERT;
break;
case SDLK_HOME:
2001-10-28 04:23:37 +00:00
ksym = QFK_HOME;
break;
case SDLK_END:
2001-10-28 04:23:37 +00:00
ksym = QFK_END;
break;
case SDLK_PAGEUP:
2001-10-28 04:23:37 +00:00
ksym = QFK_PAGEUP;
break;
case SDLK_PAGEDOWN:
2001-10-28 04:23:37 +00:00
ksym = QFK_PAGEDOWN;
break;
case SDLK_F1:
2001-10-28 04:23:37 +00:00
ksym = QFK_F1;
break;
case SDLK_F2:
2001-10-28 04:23:37 +00:00
ksym = QFK_F2;
break;
case SDLK_F3:
2001-10-28 04:23:37 +00:00
ksym = QFK_F3;
break;
case SDLK_F4:
2001-10-28 04:23:37 +00:00
ksym = QFK_F4;
break;
case SDLK_F5:
2001-10-28 04:23:37 +00:00
ksym = QFK_F5;
break;
case SDLK_F6:
2001-10-28 04:23:37 +00:00
ksym = QFK_F6;
break;
case SDLK_F7:
2001-10-28 04:23:37 +00:00
ksym = QFK_F7;
break;
case SDLK_F8:
2001-10-28 04:23:37 +00:00
ksym = QFK_F8;
break;
case SDLK_F9:
2001-10-28 04:23:37 +00:00
ksym = QFK_F9;
break;
case SDLK_F10:
2001-10-28 04:23:37 +00:00
ksym = QFK_F10;
break;
case SDLK_F11:
2001-10-28 04:23:37 +00:00
ksym = QFK_F11;
break;
case SDLK_F12:
2001-10-28 04:23:37 +00:00
ksym = QFK_F12;
break;
case SDLK_F13:
2001-10-28 04:23:37 +00:00
ksym = QFK_F13;
break;
case SDLK_F14:
2001-10-28 04:23:37 +00:00
ksym = QFK_F14;
break;
case SDLK_F15:
2001-10-28 04:23:37 +00:00
ksym = QFK_F15;
break;
case SDLK_NUMLOCK:
2001-10-28 04:23:37 +00:00
ksym = QFK_NUMLOCK;
break;
case SDLK_CAPSLOCK:
2001-10-28 04:23:37 +00:00
ksym = QFK_CAPSLOCK;
break;
case SDLK_SCROLLOCK:
2001-10-28 04:23:37 +00:00
ksym = QFK_SCROLLOCK;
break;
case SDLK_RSHIFT:
2001-10-28 04:23:37 +00:00
ksym = QFK_RSHIFT;
break;
case SDLK_LSHIFT:
2001-10-28 04:23:37 +00:00
ksym = QFK_LSHIFT;
break;
case SDLK_RCTRL:
2001-10-28 04:23:37 +00:00
ksym = QFK_RCTRL;
break;
case SDLK_LCTRL:
2001-10-28 04:23:37 +00:00
ksym = QFK_LCTRL;
break;
case SDLK_RALT:
2001-10-28 04:23:37 +00:00
ksym = QFK_RALT;
break;
case SDLK_LALT:
2001-10-28 04:23:37 +00:00
ksym = QFK_LALT;
break;
case SDLK_RMETA:
2001-10-28 04:23:37 +00:00
ksym = QFK_RMETA;
break;
case SDLK_LMETA:
2001-10-28 04:23:37 +00:00
ksym = QFK_LMETA;
break;
case SDLK_LSUPER:
2001-10-28 04:23:37 +00:00
ksym = QFK_LSUPER;
break;
case SDLK_RSUPER:
2001-10-28 04:23:37 +00:00
ksym = QFK_RSUPER;
break;
case SDLK_MODE:
2001-10-28 04:23:37 +00:00
ksym = QFK_MODE;
break;
case SDLK_COMPOSE:
2001-10-28 04:23:37 +00:00
ksym = QFK_COMPOSE;
break;
case SDLK_HELP:
2001-10-28 04:23:37 +00:00
ksym = QFK_HELP;
break;
case SDLK_PRINT:
2001-10-28 04:23:37 +00:00
ksym = QFK_PRINT;
break;
case SDLK_SYSREQ:
2001-10-28 04:23:37 +00:00
ksym = QFK_SYSREQ;
break;
case SDLK_BREAK:
2001-10-28 04:23:37 +00:00
ksym = QFK_BREAK;
break;
case SDLK_MENU:
2001-10-28 04:23:37 +00:00
ksym = QFK_MENU;
break;
case SDLK_POWER:
2001-10-28 04:23:37 +00:00
ksym = QFK_POWER;
break;
case SDLK_EURO:
2001-10-28 04:23:37 +00:00
ksym = QFK_EURO;
break;
case SDLK_UNDO:
ksym = QFK_UNDO;
break;
case SDLK_LAST:
2001-10-28 04:23:37 +00:00
ksym = QFK_LAST;
break;
default:
2001-10-28 04:23:37 +00:00
ksym = QFK_UNKNOWN;
break;
}
if (unicode > 255)
unicode = 0;
Key_Event (ksym, unicode, state);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
but = event.button.button;
if (but == 2)
but = 3;
else if (but == 3)
but = 2;
switch (but) {
case 1:
case 2:
case 3:
2001-10-28 04:23:37 +00:00
Key_Event (QFM_BUTTON1 + but - 1, 0,
event.type == SDL_MOUSEBUTTONDOWN);
break;
case 4:
Key_Event (QFM_WHEEL_UP, 0,
event.type == SDL_MOUSEBUTTONDOWN);
break;
case 5:
Key_Event (QFM_WHEEL_DOWN, 0,
event.type == SDL_MOUSEBUTTONDOWN);
break;
}
break;
case SDL_MOUSEMOTION:
in_mouse_x += event.motion.xrel;
in_mouse_y += event.motion.yrel;
break;
case SDL_QUIT:
Sys_Quit ();
break;
default:
break;
}
}
}
void
IN_LL_Grab_Input (int grab)
{
static int input_grabbed = 0;
if ((input_grabbed && grab) || (!input_grabbed && !grab))
return;
input_grabbed = (SDL_GRAB_ON == SDL_WM_GrabInput (grab ? SDL_GRAB_ON
: SDL_GRAB_OFF));
}
void
IN_LL_Init (void)
{
SDL_EnableUNICODE (1); // Enable UNICODE translation for keyboard input
if (COM_CheckParm ("-nomouse"))
return;
in_mouse_x = in_mouse_y = 0.0;
in_mouse_avail = 1;
}
void
IN_LL_Init_Cvars (void)
{
in_snd_block = Cvar_Get ("in_snd_block", "0", CVAR_ARCHIVE, NULL,
"block sound output on window focus loss");
}
void
IN_LL_Shutdown (void)
{
in_mouse_avail = 0;
}
void
IN_LL_ClearStates (void)
{
}