2010-02-15 23:26:55 +00:00
|
|
|
|
/*
|
|
|
|
|
Copyright (C) 1996-2001 Id Software, Inc.
|
|
|
|
|
Copyright (C) 2002-2005 John Fitzgibbons and others
|
|
|
|
|
Copyright (C) 2007-2008 Kristian Duske
|
|
|
|
|
|
|
|
|
|
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 the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
2012-08-16 04:51:41 +00:00
|
|
|
|
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
|
|
|
|
|
#include <SDL/SDL.h>
|
|
|
|
|
#else
|
2010-06-19 22:50:48 +00:00
|
|
|
|
#include "SDL.h"
|
2012-08-16 04:51:41 +00:00
|
|
|
|
#endif
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
2012-06-25 11:20:38 +00:00
|
|
|
|
static qboolean prev_gamekey;
|
|
|
|
|
|
2012-01-07 08:26:32 +00:00
|
|
|
|
#ifdef __APPLE__
|
2012-01-07 08:50:11 +00:00
|
|
|
|
/* Mouse acceleration needs to be disabled on OS X */
|
2012-01-07 08:26:32 +00:00
|
|
|
|
#define MACOS_X_ACCELERATION_HACK
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef MACOS_X_ACCELERATION_HACK
|
|
|
|
|
#include <IOKit/IOTypes.h>
|
|
|
|
|
#include <IOKit/hidsystem/IOHIDLib.h>
|
|
|
|
|
#include <IOKit/hidsystem/IOHIDParameter.h>
|
|
|
|
|
#include <IOKit/hidsystem/event_status_driver.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-02-18 11:33:12 +00:00
|
|
|
|
static qboolean no_mouse = false;
|
|
|
|
|
|
2011-12-16 14:11:37 +00:00
|
|
|
|
static int buttonremap[] =
|
|
|
|
|
{
|
|
|
|
|
K_MOUSE1,
|
|
|
|
|
K_MOUSE3, /* right button */
|
|
|
|
|
K_MOUSE2, /* middle button */
|
|
|
|
|
K_MWHEELUP,
|
|
|
|
|
K_MWHEELDOWN,
|
|
|
|
|
K_MOUSE4,
|
|
|
|
|
K_MOUSE5
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* mouse variables */
|
2011-12-28 22:01:33 +00:00
|
|
|
|
cvar_t m_filter = {"m_filter","0",CVAR_NONE};
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
2011-12-16 14:11:37 +00:00
|
|
|
|
/* total accumulated mouse movement since last frame,
|
|
|
|
|
* gets updated from the main game loop via IN_MouseMove */
|
2010-02-18 11:33:12 +00:00
|
|
|
|
static int total_dx, total_dy = 0;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
2010-02-18 11:33:12 +00:00
|
|
|
|
static int FilterMouseEvents (const SDL_Event *event)
|
2010-02-15 23:26:55 +00:00
|
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
|
switch (event->type)
|
|
|
|
|
{
|
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 08:26:32 +00:00
|
|
|
|
#ifdef MACOS_X_ACCELERATION_HACK
|
2012-01-07 09:22:43 +00:00
|
|
|
|
static cvar_t in_disablemacosxmouseaccel = {"in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE};
|
|
|
|
|
static double originalMouseSpeed = -1.0;
|
|
|
|
|
|
2012-01-07 08:50:11 +00:00
|
|
|
|
static io_connect_t IN_GetIOHandle(void)
|
2012-01-07 08:26:32 +00:00
|
|
|
|
{
|
|
|
|
|
io_connect_t iohandle = MACH_PORT_NULL;
|
|
|
|
|
io_service_t iohidsystem = MACH_PORT_NULL;
|
|
|
|
|
mach_port_t masterport;
|
2012-01-07 09:22:43 +00:00
|
|
|
|
kern_return_t status;
|
2012-01-07 08:50:11 +00:00
|
|
|
|
|
2012-01-07 08:26:32 +00:00
|
|
|
|
status = IOMasterPort(MACH_PORT_NULL, &masterport);
|
2012-01-07 08:50:11 +00:00
|
|
|
|
if (status != KERN_SUCCESS)
|
2012-01-07 08:26:32 +00:00
|
|
|
|
return 0;
|
2012-01-07 08:50:11 +00:00
|
|
|
|
|
2012-01-07 08:26:32 +00:00
|
|
|
|
iohidsystem = IORegistryEntryFromPath(masterport, kIOServicePlane ":/IOResources/IOHIDSystem");
|
2012-01-07 08:50:11 +00:00
|
|
|
|
if (!iohidsystem)
|
2012-01-07 08:26:32 +00:00
|
|
|
|
return 0;
|
2012-01-07 08:50:11 +00:00
|
|
|
|
|
2012-01-07 08:26:32 +00:00
|
|
|
|
status = IOServiceOpen(iohidsystem, mach_task_self(), kIOHIDParamConnectType, &iohandle);
|
|
|
|
|
IOObjectRelease(iohidsystem);
|
2012-01-07 08:50:11 +00:00
|
|
|
|
|
2012-01-07 08:26:32 +00:00
|
|
|
|
return iohandle;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 09:22:43 +00:00
|
|
|
|
static void IN_DisableOSXMouseAccel (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
|
{
|
2012-01-07 09:22:43 +00:00
|
|
|
|
io_connect_t mouseDev = IN_GetIOHandle();
|
|
|
|
|
if (mouseDev != 0)
|
2012-01-07 08:26:32 +00:00
|
|
|
|
{
|
2012-01-07 09:22:43 +00:00
|
|
|
|
if (IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess)
|
2012-01-07 08:26:32 +00:00
|
|
|
|
{
|
2012-01-07 09:22:43 +00:00
|
|
|
|
if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess)
|
2012-01-07 08:26:32 +00:00
|
|
|
|
{
|
2012-01-07 09:22:43 +00:00
|
|
|
|
Cvar_Set("in_disablemacosxmouseaccel", "0");
|
|
|
|
|
Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
|
2012-01-07 08:26:32 +00:00
|
|
|
|
}
|
2012-01-07 08:50:11 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-01-07 09:22:43 +00:00
|
|
|
|
Cvar_Set("in_disablemacosxmouseaccel", "0");
|
|
|
|
|
Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n");
|
2012-01-07 08:26:32 +00:00
|
|
|
|
}
|
2012-01-07 09:22:43 +00:00
|
|
|
|
IOServiceClose(mouseDev);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Cvar_Set("in_disablemacosxmouseaccel", "0");
|
|
|
|
|
Con_Printf("WARNING: Could not disable mouse acceleration (failed at IO_GetIOHandle).\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void IN_ReenableOSXMouseAccel (void)
|
|
|
|
|
{
|
|
|
|
|
io_connect_t mouseDev = IN_GetIOHandle();
|
|
|
|
|
if (mouseDev != 0)
|
|
|
|
|
{
|
|
|
|
|
if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess)
|
|
|
|
|
Con_Printf("WARNING: Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
|
|
|
|
|
IOServiceClose(mouseDev);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Con_Printf("WARNING: Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n");
|
2012-01-07 08:26:32 +00:00
|
|
|
|
}
|
2012-01-07 09:22:43 +00:00
|
|
|
|
originalMouseSpeed = -1;
|
|
|
|
|
}
|
|
|
|
|
#endif /* MACOS_X_ACCELERATION_HACK */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IN_Activate (void)
|
|
|
|
|
{
|
|
|
|
|
if (no_mouse)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
#ifdef MACOS_X_ACCELERATION_HACK
|
|
|
|
|
/* Save the status of mouse acceleration */
|
|
|
|
|
if (originalMouseSpeed == -1 && in_disablemacosxmouseaccel.value)
|
|
|
|
|
IN_DisableOSXMouseAccel();
|
2012-01-07 08:50:11 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
|
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_ON)
|
|
|
|
|
{
|
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
|
|
|
|
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_ON)
|
|
|
|
|
Con_Printf("WARNING: SDL_WM_GrabInput(SDL_GRAB_ON) failed.\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SDL_ShowCursor(SDL_QUERY) != SDL_DISABLE)
|
|
|
|
|
{
|
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
|
|
|
if (SDL_ShowCursor(SDL_QUERY) != SDL_DISABLE)
|
|
|
|
|
Con_Printf("WARNING: SDL_ShowCursor(SDL_DISABLE) failed.\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SDL_GetEventFilter() != NULL)
|
|
|
|
|
SDL_SetEventFilter(NULL);
|
|
|
|
|
|
|
|
|
|
total_dx = 0;
|
|
|
|
|
total_dy = 0;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IN_Deactivate (qboolean free_cursor)
|
|
|
|
|
{
|
2010-02-18 11:33:12 +00:00
|
|
|
|
if (no_mouse)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-01-07 08:26:32 +00:00
|
|
|
|
#ifdef MACOS_X_ACCELERATION_HACK
|
2012-01-07 09:22:43 +00:00
|
|
|
|
if (originalMouseSpeed != -1)
|
|
|
|
|
IN_ReenableOSXMouseAccel();
|
2012-01-07 08:50:11 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
|
if (free_cursor)
|
|
|
|
|
{
|
|
|
|
|
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_OFF)
|
|
|
|
|
{
|
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
|
|
|
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_OFF)
|
|
|
|
|
Con_Printf("WARNING: SDL_WM_GrabInput(SDL_GRAB_OFF) failed.\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SDL_ShowCursor(SDL_QUERY) != SDL_ENABLE)
|
|
|
|
|
{
|
|
|
|
|
SDL_ShowCursor(SDL_ENABLE);
|
|
|
|
|
if (SDL_ShowCursor(SDL_QUERY) != SDL_ENABLE)
|
|
|
|
|
Con_Printf("WARNING: SDL_ShowCursor(SDL_ENABLE) failed.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-16 14:11:37 +00:00
|
|
|
|
/* discard all mouse events when input is deactivated */
|
2010-02-17 23:32:04 +00:00
|
|
|
|
if (SDL_GetEventFilter() != FilterMouseEvents)
|
|
|
|
|
SDL_SetEventFilter(FilterMouseEvents);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IN_Init (void)
|
|
|
|
|
{
|
2012-10-06 18:09:23 +00:00
|
|
|
|
prev_gamekey = ((key_dest == key_game && !con_forcedup) ||
|
|
|
|
|
(key_dest == key_menu && m_state == m_keys && m_keys_bind_grab));
|
2012-06-25 11:20:38 +00:00
|
|
|
|
SDL_EnableUNICODE (!prev_gamekey);
|
2010-02-17 23:32:04 +00:00
|
|
|
|
if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1)
|
|
|
|
|
Con_Printf("Warning: SDL_EnableKeyRepeat() failed.\n");
|
|
|
|
|
|
2010-08-29 12:55:41 +00:00
|
|
|
|
if (safemode || COM_CheckParm("-nomouse"))
|
2010-02-18 11:33:12 +00:00
|
|
|
|
{
|
|
|
|
|
no_mouse = true;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
/* discard all mouse events when input is deactivated */
|
2010-02-18 11:33:12 +00:00
|
|
|
|
SDL_SetEventFilter(FilterMouseEvents);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 08:26:32 +00:00
|
|
|
|
#ifdef MACOS_X_ACCELERATION_HACK
|
|
|
|
|
Cvar_RegisterVariable(&in_disablemacosxmouseaccel);
|
|
|
|
|
#endif
|
2012-01-07 08:50:11 +00:00
|
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
|
IN_Activate();
|
2010-02-15 23:26:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IN_Shutdown (void)
|
|
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
|
IN_Deactivate(true);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IN_Commands (void)
|
|
|
|
|
{
|
2011-12-16 14:11:37 +00:00
|
|
|
|
/* TODO: implement this for joystick support */
|
2010-02-15 23:26:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-16 14:11:37 +00:00
|
|
|
|
extern cvar_t cl_maxpitch; /* johnfitz -- variable pitch clamping */
|
|
|
|
|
extern cvar_t cl_minpitch; /* johnfitz -- variable pitch clamping */
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IN_MouseMove(int dx, int dy)
|
|
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
|
total_dx += dx;
|
|
|
|
|
total_dy += dy;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IN_Move (usercmd_t *cmd)
|
|
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
|
int dmx, dmy;
|
|
|
|
|
|
|
|
|
|
/* TODO: fix this
|
|
|
|
|
if (m_filter.value)
|
|
|
|
|
{
|
|
|
|
|
dmx = (2*mx - dmx) * 0.5;
|
|
|
|
|
dmy = (2*my - dmy) * 0.5;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
dmx = total_dx * sensitivity.value;
|
|
|
|
|
dmy = total_dy * sensitivity.value;
|
|
|
|
|
|
|
|
|
|
total_dx = 0;
|
|
|
|
|
total_dy = 0;
|
|
|
|
|
|
|
|
|
|
if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
|
|
|
|
|
cmd->sidemove += m_side.value * dmx;
|
|
|
|
|
else
|
|
|
|
|
cl.viewangles[YAW] -= m_yaw.value * dmx;
|
|
|
|
|
|
|
|
|
|
if (in_mlook.state & 1)
|
2011-08-25 21:37:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (dmx || dmy)
|
|
|
|
|
V_StopPitchDrift ();
|
|
|
|
|
}
|
2010-02-17 23:32:04 +00:00
|
|
|
|
|
|
|
|
|
if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
|
|
|
|
|
{
|
|
|
|
|
cl.viewangles[PITCH] += m_pitch.value * dmy;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
/* johnfitz -- variable pitch clamping */
|
2010-02-17 23:32:04 +00:00
|
|
|
|
if (cl.viewangles[PITCH] > cl_maxpitch.value)
|
|
|
|
|
cl.viewangles[PITCH] = cl_maxpitch.value;
|
|
|
|
|
if (cl.viewangles[PITCH] < cl_minpitch.value)
|
|
|
|
|
cl.viewangles[PITCH] = cl_minpitch.value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((in_strafe.state & 1) && noclip_anglehack)
|
|
|
|
|
cmd->upmove -= m_forward.value * dmy;
|
|
|
|
|
else
|
|
|
|
|
cmd->forwardmove -= m_forward.value * dmy;
|
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IN_ClearStates (void)
|
|
|
|
|
{
|
|
|
|
|
}
|
2010-02-17 23:32:04 +00:00
|
|
|
|
|
2011-12-16 14:11:37 +00:00
|
|
|
|
void IN_SendKeyEvents (void)
|
|
|
|
|
{
|
|
|
|
|
SDL_Event event;
|
2012-09-27 12:19:19 +00:00
|
|
|
|
int sym, usym, state, modstate;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
qboolean gamekey;
|
|
|
|
|
|
2012-10-06 18:09:23 +00:00
|
|
|
|
gamekey = ((key_dest == key_game && !con_forcedup) ||
|
|
|
|
|
(key_dest == key_menu && m_state == m_keys && m_keys_bind_grab));
|
2012-06-08 20:06:40 +00:00
|
|
|
|
if (gamekey != prev_gamekey)
|
2011-12-16 14:11:37 +00:00
|
|
|
|
{
|
2012-06-08 20:06:40 +00:00
|
|
|
|
prev_gamekey = gamekey;
|
2012-06-25 11:20:38 +00:00
|
|
|
|
Key_ClearStates();
|
|
|
|
|
SDL_EnableUNICODE(!gamekey);
|
2011-12-16 14:11:37 +00:00
|
|
|
|
}
|
2010-04-24 16:25:08 +00:00
|
|
|
|
|
2011-12-16 14:11:37 +00:00
|
|
|
|
while (SDL_PollEvent(&event))
|
|
|
|
|
{
|
|
|
|
|
switch (event.type)
|
|
|
|
|
{
|
|
|
|
|
case SDL_ACTIVEEVENT:
|
|
|
|
|
if (event.active.state & (SDL_APPINPUTFOCUS|SDL_APPACTIVE))
|
|
|
|
|
{
|
|
|
|
|
if (event.active.gain)
|
|
|
|
|
S_UnblockSound();
|
2012-06-25 11:20:38 +00:00
|
|
|
|
else S_BlockSound();
|
2011-12-16 14:11:37 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
|
if ((event.key.keysym.sym == SDLK_RETURN) &&
|
|
|
|
|
(event.key.keysym.mod & KMOD_ALT))
|
|
|
|
|
{
|
|
|
|
|
VID_Toggle();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-06-25 11:20:38 +00:00
|
|
|
|
if ((event.key.keysym.sym == SDLK_ESCAPE) &&
|
|
|
|
|
(event.key.keysym.mod & KMOD_SHIFT))
|
2011-12-16 14:11:37 +00:00
|
|
|
|
{
|
|
|
|
|
Con_ToggleConsole_f();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-06-25 11:20:38 +00:00
|
|
|
|
/* fallthrough */
|
2011-12-16 14:11:37 +00:00
|
|
|
|
case SDL_KEYUP:
|
|
|
|
|
sym = event.key.keysym.sym;
|
|
|
|
|
state = event.key.state;
|
|
|
|
|
modstate = SDL_GetModState();
|
|
|
|
|
|
|
|
|
|
switch (key_dest)
|
|
|
|
|
{
|
|
|
|
|
case key_game:
|
2012-09-27 12:19:19 +00:00
|
|
|
|
if (event.key.keysym.unicode != 0)
|
2011-12-16 14:11:37 +00:00
|
|
|
|
{ /* only use unicode for ~ and ` in game mode */
|
|
|
|
|
if ((event.key.keysym.unicode & 0xFF80) == 0)
|
|
|
|
|
{
|
2012-09-27 12:19:19 +00:00
|
|
|
|
usym = event.key.keysym.unicode & 0x7F;
|
|
|
|
|
if (usym == '`' || usym == '~')
|
|
|
|
|
sym = usym;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case key_message:
|
|
|
|
|
case key_console:
|
2012-09-27 12:19:19 +00:00
|
|
|
|
if (event.key.keysym.unicode != 0)
|
2011-12-16 14:11:37 +00:00
|
|
|
|
{
|
2012-02-10 22:04:43 +00:00
|
|
|
|
#if defined(__APPLE__) && defined(__MACH__)
|
|
|
|
|
if (sym == SDLK_BACKSPACE)
|
|
|
|
|
break; /* avoid change to SDLK_DELETE */
|
|
|
|
|
#endif /* Mac OS X */
|
2011-12-16 14:11:37 +00:00
|
|
|
|
#if defined(__QNX__)
|
|
|
|
|
if ((sym == SDLK_BACKSPACE) || (sym == SDLK_RETURN))
|
|
|
|
|
break; /* S.A: fixes QNX weirdness */
|
|
|
|
|
#endif /* __QNX__ */
|
|
|
|
|
if ((event.key.keysym.unicode & 0xFF80) == 0)
|
2012-09-27 10:41:07 +00:00
|
|
|
|
{
|
2012-09-27 12:19:19 +00:00
|
|
|
|
usym = event.key.keysym.unicode & 0x7F;
|
2012-09-27 12:55:03 +00:00
|
|
|
|
if (modstate & KMOD_CTRL && usym < 32 && sym >= 32)
|
2012-09-27 12:19:19 +00:00
|
|
|
|
{
|
2012-09-27 12:55:03 +00:00
|
|
|
|
/* control characters */
|
2012-09-27 10:41:07 +00:00
|
|
|
|
if (modstate & KMOD_SHIFT)
|
2012-09-27 12:19:19 +00:00
|
|
|
|
usym += 64;
|
|
|
|
|
else usym += 96;
|
|
|
|
|
}
|
|
|
|
|
sym = usym;
|
2012-09-27 10:41:07 +00:00
|
|
|
|
}
|
2011-12-16 14:11:37 +00:00
|
|
|
|
/* else: it's an international character */
|
|
|
|
|
}
|
|
|
|
|
/* printf("You pressed %s (%d) (%c)\n", SDL_GetKeyName(sym), sym, sym);*/
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-04-24 16:25:08 +00:00
|
|
|
|
|
2011-12-16 14:11:37 +00:00
|
|
|
|
switch (sym)
|
|
|
|
|
{
|
|
|
|
|
case SDLK_DELETE:
|
|
|
|
|
sym = K_DEL;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_BACKSPACE:
|
|
|
|
|
sym = K_BACKSPACE;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F1:
|
|
|
|
|
sym = K_F1;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F2:
|
|
|
|
|
sym = K_F2;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F3:
|
|
|
|
|
sym = K_F3;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F4:
|
|
|
|
|
sym = K_F4;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F5:
|
|
|
|
|
sym = K_F5;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F6:
|
|
|
|
|
sym = K_F6;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F7:
|
|
|
|
|
sym = K_F7;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F8:
|
|
|
|
|
sym = K_F8;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F9:
|
|
|
|
|
sym = K_F9;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F10:
|
|
|
|
|
sym = K_F10;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F11:
|
|
|
|
|
sym = K_F11;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F12:
|
|
|
|
|
sym = K_F12;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_BREAK:
|
|
|
|
|
case SDLK_PAUSE:
|
|
|
|
|
sym = K_PAUSE;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_UP:
|
|
|
|
|
sym = K_UPARROW;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_DOWN:
|
|
|
|
|
sym = K_DOWNARROW;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_RIGHT:
|
|
|
|
|
sym = K_RIGHTARROW;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_LEFT:
|
|
|
|
|
sym = K_LEFTARROW;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_INSERT:
|
|
|
|
|
sym = K_INS;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_HOME:
|
|
|
|
|
sym = K_HOME;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_END:
|
|
|
|
|
sym = K_END;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_PAGEUP:
|
|
|
|
|
sym = K_PGUP;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_PAGEDOWN:
|
|
|
|
|
sym = K_PGDN;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_RSHIFT:
|
|
|
|
|
case SDLK_LSHIFT:
|
|
|
|
|
sym = K_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_RCTRL:
|
|
|
|
|
case SDLK_LCTRL:
|
|
|
|
|
sym = K_CTRL;
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_RALT:
|
|
|
|
|
case SDLK_LALT:
|
|
|
|
|
sym = K_ALT;
|
|
|
|
|
break;
|
2012-09-28 21:41:31 +00:00
|
|
|
|
case SDLK_RMETA:
|
|
|
|
|
case SDLK_LMETA:
|
|
|
|
|
sym = K_COMMAND;
|
|
|
|
|
break;
|
2012-06-10 06:09:50 +00:00
|
|
|
|
case SDLK_NUMLOCK:
|
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_NUMLOCK;
|
2012-06-10 06:09:50 +00:00
|
|
|
|
else sym = 0;
|
|
|
|
|
break;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
case SDLK_KP0:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_INS;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_0 : K_INS;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP1:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_END;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_1 : K_END;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP2:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_DOWNARROW;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_2 : K_DOWNARROW;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP3:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_PGDN;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_3 : K_PGDN;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP4:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_LEFTARROW;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_4 : K_LEFTARROW;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP5:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_5;
|
|
|
|
|
else sym = SDLK_5;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP6:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_RIGHTARROW;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_6 : K_RIGHTARROW;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP7:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_HOME;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_7 : K_HOME;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP8:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_UPARROW;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_8 : K_UPARROW;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP9:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_PGUP;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_9 : K_PGUP;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP_PERIOD:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_DEL;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = (modstate & KMOD_NUM) ? SDLK_PERIOD : K_DEL;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP_DIVIDE:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_SLASH;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = SDLK_SLASH;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP_MULTIPLY:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_STAR;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = SDLK_ASTERISK;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP_MINUS:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_MINUS;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = SDLK_MINUS;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP_PLUS:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_PLUS;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = SDLK_PLUS;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP_ENTER:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
2012-06-25 11:20:38 +00:00
|
|
|
|
sym = K_KP_ENTER;
|
2012-06-08 19:27:12 +00:00
|
|
|
|
else sym = SDLK_RETURN;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case SDLK_KP_EQUALS:
|
2012-06-08 19:27:12 +00:00
|
|
|
|
if (gamekey)
|
|
|
|
|
sym = 0;
|
|
|
|
|
else sym = SDLK_EQUALS;
|
2011-12-16 14:11:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case 178: /* the '<27>' key */
|
|
|
|
|
sym = '~';
|
|
|
|
|
break;
|
2012-09-29 14:50:54 +00:00
|
|
|
|
default:
|
2012-09-28 21:41:31 +00:00
|
|
|
|
/* If we are not directly handled and still above 255,
|
|
|
|
|
* just force it to 0. kill unsupported international
|
|
|
|
|
* characters, too. */
|
2012-09-29 14:50:54 +00:00
|
|
|
|
if ((sym >= SDLK_WORLD_0 && sym <= SDLK_WORLD_95) ||
|
|
|
|
|
sym > 255)
|
|
|
|
|
sym = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-12-16 14:11:37 +00:00
|
|
|
|
Key_Event (sym, state);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
|
if (event.button.button < 1 ||
|
|
|
|
|
event.button.button > sizeof(buttonremap) / sizeof(buttonremap[0]))
|
|
|
|
|
{
|
|
|
|
|
Con_Printf ("Ignored event for mouse button %d\n",
|
|
|
|
|
event.button.button);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Key_Event(buttonremap[event.button.button - 1], event.button.state == SDL_PRESSED);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
|
IN_MouseMove(event.motion.xrel, event.motion.yrel);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SDL_QUIT:
|
|
|
|
|
CL_Disconnect ();
|
|
|
|
|
Sys_Quit ();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2010-04-24 16:25:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|