these are now in libs/video/targets

This commit is contained in:
Bill Currie 2001-04-15 04:40:09 +00:00
parent 9d8c1d33c0
commit 6a696881b3
12 changed files with 0 additions and 4590 deletions

View file

@ -1,157 +0,0 @@
/*
in_fbdev.c
fix this!
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "client.h"
#include "QF/cvar.h"
#include "QF/keys.h"
cvar_t *_windowed_mouse;
int
fd_blocking (int fd, int on)
{
int x;
#if defined(_POSIX_SOURCE) || !defined(FIONBIO)
#if !defined(O_NONBLOCK)
# if defined(O_NDELAY)
# define O_NONBLOCK O_NDELAY
# endif
#endif
if ((x = fcntl(fd, F_GETFL, 0)) == -1)
return -1;
if (on)
x &= ~O_NONBLOCK;
else
x |= O_NONBLOCK;
return fcntl(fd, F_SETFL, x);
#else
x = !on;
return ioctl(fd, FIONBIO, &x);
#endif
}
static struct termios old_tty, new_tty;
static int tty_fd = 0;
void
IN_Init (void)
{
fd_blocking(0, 0);
tcgetattr(tty_fd, &old_tty);
new_tty = old_tty;
new_tty.c_cc[VMIN] = 1;
new_tty.c_cc[VTIME] = 0;
new_tty.c_lflag &= ~ICANON;
new_tty.c_iflag &= ~IXON;
tcsetattr(tty_fd, TCSADRAIN, &new_tty);
}
void
IN_Init_Cvars (void)
{
}
void
IN_Shutdown (void)
{
}
void
IN_SendKeyEvents (void)
{
int k, down;
char buf[4];
if (read(0, buf, 1) == 1) {
k = buf[0];
switch (k) {
case '\r':
case '\n':
k = K_ENTER;
break;
case '\033':
if (read(0, buf, 2) != 2)
break;
switch (buf[1]) {
case 'A':
k = K_UPARROW;
break;
case 'B':
k = K_DOWNARROW;
break;
case 'C':
k = K_RIGHTARROW;
break;
case 'D':
k = K_LEFTARROW;
break;
}
break;
}
down = 1;
Key_Event(k, -1, down);
Key_Event(k, -1, !down);
}
}
void
IN_Commands (void)
{
}
void
IN_Move (void)
{
}
/*
IN_ModeChanged
*/
void
IN_ModeChanged (void)
{
}
void
IN_HandlePause (qboolean paused)
{
}

View file

@ -1,73 +0,0 @@
/*
in_null.c
for systems without a mouse
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "quakedef.h"
void
IN_Init (void)
{
}
void
IN_Init_Cvars (void)
{
}
void
IN_Shutdown (void)
{
}
void
IN_Commands (void)
{
}
void
IN_Move (null)
{
}
/*
===========
IN_ModeChanged
===========
*/
void
IN_ModeChanged (void)
{
}
void
IN_HandlePause (qboolean paused)
{
}

View file

@ -1,434 +0,0 @@
/*
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 "client.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "draw.h"
#include "host.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/sys.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "vid.h"
#include "view.h"
#ifdef WIN32
// FIXME: this is evil...
# include <windows.h>
HWND mainwindow;
#endif
cvar_t *m_filter;
cvar_t *_windowed_mouse;
int old_windowed_mouse;
int modestate; // FIXME: just to avoid cross-comp.
// errors - remove later
static qboolean mouse_avail;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int mouse_oldbuttonstate = 0;
extern viddef_t vid; // global video state
/*
IN_SendKeyEvents
*/
void
IN_SendKeyEvents (void)
{
SDL_Event event;
int sym, state, but;
int modstate;
while (SDL_PollEvent (&event)) {
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
sym = event.key.keysym.sym;
state = event.key.state;
modstate = SDL_GetModState ();
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;
case SDLK_CAPSLOCK:
sym = K_CAPSLOCK;
break;
case SDLK_KP0:
if (modstate & KMOD_NUM)
sym = K_INS;
else
sym = SDLK_0;
break;
case SDLK_KP1:
if (modstate & KMOD_NUM)
sym = K_END;
else
sym = SDLK_1;
break;
case SDLK_KP2:
if (modstate & KMOD_NUM)
sym = K_DOWNARROW;
else
sym = SDLK_2;
break;
case SDLK_KP3:
if (modstate & KMOD_NUM)
sym = K_PGDN;
else
sym = SDLK_3;
break;
case SDLK_KP4:
if (modstate & KMOD_NUM)
sym = K_LEFTARROW;
else
sym = SDLK_4;
break;
case SDLK_KP5:
sym = SDLK_5;
break;
case SDLK_KP6:
if (modstate & KMOD_NUM)
sym = K_RIGHTARROW;
else
sym = SDLK_6;
break;
case SDLK_KP7:
if (modstate & KMOD_NUM)
sym = K_HOME;
else
sym = SDLK_7;
break;
case SDLK_KP8:
if (modstate & KMOD_NUM)
sym = K_UPARROW;
else
sym = SDLK_8;
break;
case SDLK_KP9:
if (modstate & KMOD_NUM)
sym = K_PGUP;
else
sym = SDLK_9;
break;
case SDLK_KP_PERIOD:
if (modstate & KMOD_NUM)
sym = K_DEL;
else
sym = SDLK_PERIOD;
break;
case SDLK_KP_DIVIDE:
sym = SDLK_SLASH;
break;
case SDLK_KP_MULTIPLY:
sym = SDLK_ASTERISK;
break;
case SDLK_KP_MINUS:
sym = SDLK_MINUS;
break;
case SDLK_KP_PLUS:
sym = SDLK_PLUS;
break;
case SDLK_KP_ENTER:
sym = SDLK_RETURN;
break;
case SDLK_KP_EQUALS:
sym = SDLK_EQUALS;
break;
}
// If we're not directly handled and still above 255
// just force it to 0
if (sym > 255)
sym = 0;
Key_Event (sym, -1, 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:
Key_Event (K_MOUSE1 + but - 1, 0, event.type
== SDL_MOUSEBUTTONDOWN);
break;
case 4:
Key_Event (K_MWHEELUP, 0, event.type == SDL_MOUSEBUTTONDOWN);
break;
case 5:
Key_Event (K_MWHEELDOWN, 0, event.type == SDL_MOUSEBUTTONDOWN);
break;
}
break;
case SDL_MOUSEMOTION:
if (_windowed_mouse->value) {
if ((event.motion.x != (vid.width / 2))
|| (event.motion.y != (vid.height / 2))) {
// *2 for vid_sdl.c, *10 for vid_sgl.c.
mouse_x = event.motion.xrel * 5;
mouse_y = event.motion.yrel * 5;
if ((event.motion.x < ((vid.width / 2) - (vid.width / 4)))
|| (event.motion.x >
((vid.width / 2) + (vid.width / 4)))
|| (event.motion.y <
((vid.height / 2) - (vid.height / 4)))
|| (event.motion.y >
((vid.height / 2) + (vid.height / 4))))
SDL_WarpMouse (vid.width / 2, vid.height / 2);
}
} else {
// following are *2 in vid_sdl.c, vid_sgl.c is *10
mouse_x = event.motion.xrel * 5;
mouse_y = event.motion.yrel * 5;
}
break;
case SDL_QUIT:
CL_Disconnect ();
Sys_Quit ();
break;
default:
break;
}
}
}
void
IN_Commands (void)
{
JOY_Command ();
if (old_windowed_mouse != _windowed_mouse->value) {
old_windowed_mouse = _windowed_mouse->value;
if (!_windowed_mouse->value) {
// SDL_ShowCursor (0);
SDL_WM_GrabInput (SDL_GRAB_OFF);
} else {
SDL_WM_GrabInput (SDL_GRAB_ON);
// SDL_ShowCursor (1);
}
}
}
void
IN_Init (void)
{
JOY_Init ();
if (COM_CheckParm ("-nomouse") && !_windowed_mouse->value)
return;
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
// SDL_ShowCursor (0);
// SDL_WM_GrabInput (SDL_GRAB_ON);
// FIXME: disable DGA if in_dgamouse says to.
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
_windowed_mouse =
Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
"If set to 1, quake will grab the mouse in X");
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL, "Toggle mouse input filtering");
}
void
IN_Shutdown (void)
{
mouse_avail = 0;
}
void
IN_Frame (void)
{
int i;
int mouse_buttonstate;
if (!mouse_avail)
return;
i = SDL_GetMouseState (NULL, NULL);
/* Quake swaps the second and third buttons */
mouse_buttonstate = (i & ~0x06) | ((i & 0x02) << 1) | ((i & 0x04) >> 1);
for (i = 0; i < 3; i++) {
if ((mouse_buttonstate & (1 << i))
&& !(mouse_oldbuttonstate & (1 << i)))
Key_Event (K_MOUSE1 + i, 0, true);
if (!(mouse_buttonstate & (1 << i))
&& (mouse_oldbuttonstate & (1 << i)))
Key_Event (K_MOUSE1 + i, 0, false);
}
mouse_oldbuttonstate = mouse_buttonstate;
}
void
IN_Move (void)
{
JOY_Move ();
if (!mouse_avail)
return;
if (m_filter->value) {
mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
}
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
if ((in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1)))
viewdelta.position[0] += mouse_x;
else
viewdelta.angles[YAW] -= mouse_x;
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
mouse_x = mouse_y = 0.0;
}
void
IN_HandlePause (qboolean paused)
{
}

View file

@ -1,410 +0,0 @@
/*
in_svgalib.c
(description)
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 1999,2000 contributors of the QuakeForge project
Please see the file "AUTHORS" for a list of contributors
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <vga.h>
#include <vgakeyboard.h>
#include <vgamouse.h>
#include "client.h"
#include "QF/cmd.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "host.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/qargs.h"
#include "QF/sys.h"
#include "view.h"
static int UseKeyboard = 1;
static int UseMouse = 1;
static int in_svgalib_inited = 0;
static unsigned char scantokey[128];
static int mouse_buttons;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int mx, my;
static void IN_InitKeyboard (void);
static void IN_InitMouse (void);
cvar_t *_windowed_mouse;
cvar_t *m_filter;
static void
keyhandler (int scancode, int state)
{
int sc;
sc = scancode & 0x7f;
#if 0
Con_Printf ("scancode=%x (%d%s)\n", scancode, sc,
scancode & 0x80 ? "+128" : "");
#endif
Key_Event (scantokey[sc], -1, state == KEY_EVENTPRESS);
}
static void
mousehandler (int buttonstate, int dx, int dy, int dz, int drx, int dry,
int drz)
{
mouse_buttonstate = buttonstate;
mx += dx;
my += dy;
if (drx > 0) {
Key_Event (K_MWHEELUP, 0, 1);
Key_Event (K_MWHEELUP, 0, 0);
} else if (drx < 0) {
Key_Event (K_MWHEELDOWN, 0, 1);
Key_Event (K_MWHEELDOWN, 0, 0);
}
}
void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
void
IN_Init (void)
{
if (COM_CheckParm ("-nokbd"))
UseKeyboard = 0;
if (COM_CheckParm ("-nomouse"))
UseMouse = 0;
if (UseKeyboard)
IN_InitKeyboard ();
if (UseMouse)
IN_InitMouse ();
JOY_Init ();
in_svgalib_inited = 1;
return;
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL,
"Toggle mouse input filtering.");
}
static void
IN_InitKeyboard (void)
{
int i;
for (i = 0; i < 128; i++) {
scantokey[i] = ' ';
}
scantokey[1] = K_ESCAPE;
scantokey[2] = '1';
scantokey[3] = '2';
scantokey[4] = '3';
scantokey[5] = '4';
scantokey[6] = '5';
scantokey[7] = '6';
scantokey[8] = '7';
scantokey[9] = '8';
scantokey[10] = '9';
scantokey[11] = '0';
scantokey[12] = '-';
scantokey[13] = '=';
scantokey[14] = K_BACKSPACE;
scantokey[15] = K_TAB;
scantokey[16] = 'q';
scantokey[17] = 'w';
scantokey[18] = 'e';
scantokey[19] = 'r';
scantokey[20] = 't';
scantokey[21] = 'y';
scantokey[22] = 'u';
scantokey[23] = 'i';
scantokey[24] = 'o';
scantokey[25] = 'p';
scantokey[26] = '[';
scantokey[27] = ']';
scantokey[28] = K_ENTER;
scantokey[29] = K_CTRL; /* left */
scantokey[30] = 'a';
scantokey[31] = 's';
scantokey[32] = 'd';
scantokey[33] = 'f';
scantokey[34] = 'g';
scantokey[35] = 'h';
scantokey[36] = 'j';
scantokey[37] = 'k';
scantokey[38] = 'l';
scantokey[39] = ';';
scantokey[40] = '\'';
scantokey[41] = '`';
scantokey[42] = K_SHIFT; /* left */
scantokey[43] = '\\';
scantokey[44] = 'z';
scantokey[45] = 'x';
scantokey[46] = 'c';
scantokey[47] = 'v';
scantokey[48] = 'b';
scantokey[49] = 'n';
scantokey[50] = 'm';
scantokey[51] = ',';
scantokey[52] = '.';
scantokey[53] = '/';
scantokey[54] = K_SHIFT; /* right */
scantokey[55] = KP_MULTIPLY;
scantokey[56] = K_ALT; /* left */
scantokey[57] = ' ';
scantokey[58] = K_CAPSLOCK;
scantokey[59] = K_F1;
scantokey[60] = K_F2;
scantokey[61] = K_F3;
scantokey[62] = K_F4;
scantokey[63] = K_F5;
scantokey[64] = K_F6;
scantokey[65] = K_F7;
scantokey[66] = K_F8;
scantokey[67] = K_F9;
scantokey[68] = K_F10;
scantokey[69] = KP_NUMLCK;
scantokey[70] = K_SCRLCK;
scantokey[71] = KP_HOME;
scantokey[72] = KP_UPARROW;
scantokey[73] = KP_PGUP;
scantokey[74] = KP_MINUS;
scantokey[75] = KP_LEFTARROW;
scantokey[76] = KP_5;
scantokey[77] = KP_RIGHTARROW;
scantokey[79] = KP_END;
scantokey[78] = KP_PLUS;
scantokey[80] = KP_DOWNARROW;
scantokey[81] = KP_PGDN;
scantokey[82] = KP_INS;
scantokey[83] = KP_DEL;
/* 84 to 86 not used */
scantokey[87] = K_F11;
scantokey[88] = K_F12;
/* 89 to 95 not used */
scantokey[96] = KP_ENTER; /* keypad enter */
scantokey[97] = K_CTRL; /* right */
scantokey[98] = KP_DIVIDE;
scantokey[99] = K_PRNTSCR; /* print screen */
scantokey[100] = K_ALT; /* right */
scantokey[101] = K_PAUSE; /* break */
scantokey[102] = K_HOME;
scantokey[103] = K_UPARROW;
scantokey[104] = K_PGUP;
scantokey[105] = K_LEFTARROW;
scantokey[106] = K_RIGHTARROW;
scantokey[107] = K_END;
scantokey[108] = K_DOWNARROW;
scantokey[109] = K_PGDN;
scantokey[110] = K_INS;
scantokey[111] = K_DEL;
scantokey[119] = K_PAUSE;
if (keyboard_init ()) {
Sys_Error ("keyboard_init() failed");
}
keyboard_seteventhandler (keyhandler);
}
static void
IN_InitMouse (void)
{
int mtype;
char *mousedev;
int mouserate = MOUSE_DEFAULTSAMPLERATE;
Cmd_AddCommand ("force_centerview", Force_CenterView_f,
"Force viewpoint of player to center");
mouse_buttons = 3;
mtype = vga_getmousetype ();
mousedev = "/dev/mouse";
if (getenv ("MOUSEDEV"))
mousedev = getenv ("MOUSEDEV");
if (COM_CheckParm ("-mdev")) {
mousedev = com_argv[COM_CheckParm ("-mdev") + 1];
}
if (getenv ("MOUSERATE"))
mouserate = atoi (getenv ("MOUSERATE"));
if (COM_CheckParm ("-mrate")) {
mouserate = atoi (com_argv[COM_CheckParm ("-mrate") + 1]);
}
#if 0
printf ("Mouse: dev=%s,type=%s,speed=%d\n",
mousedev, mice[mtype].name, mouserate);
#endif
if (mouse_init (mousedev, mtype, mouserate)) {
Con_Printf ("No mouse found\n");
UseMouse = 0;
} else {
mouse_seteventhandler ((void *) mousehandler);
}
}
void
IN_Shutdown (void)
{
JOY_Shutdown ();
Con_Printf ("IN_Shutdown\n");
if (UseMouse)
mouse_close ();
if (UseKeyboard)
keyboard_close ();
in_svgalib_inited = 0;
}
void
IN_SendKeyEvents (void)
{
if (!in_svgalib_inited)
return;
if (UseKeyboard) {
while ((keyboard_update ()));
}
}
void
IN_Commands (void)
{
JOY_Command ();
if (UseMouse) {
/* Poll mouse values */
while (mouse_update ());
/* Perform button actions */
if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
Key_Event (K_MOUSE1, 0, true);
else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
Key_Event (K_MOUSE1, 0, false);
if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
Key_Event (K_MOUSE2, 0, true);
else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
Key_Event (K_MOUSE2, 0, false);
if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
Key_Event (K_MOUSE3, 0, true);
else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
Key_Event (K_MOUSE3, 0, false);
mouse_oldbuttonstate = mouse_buttonstate;
}
}
void
IN_Move (void)
{
JOY_Move ();
if (!UseMouse)
return;
/* Poll mouse values */
while (mouse_update ());
if (m_filter->int_val) {
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
} else {
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
/* Clear for next update */
mx = my = 0;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
/* Add mouse X/Y movement to cmd */
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook)) {
viewdelta.position[0] += mouse_x;
} else {
viewdelta.angles[YAW] -= mouse_x;
}
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack) {
viewdelta.position[1] -= mouse_y;
} else {
viewdelta.position[2] -= mouse_y;
}
}
}
void
IN_HandlePause (qboolean paused)
{
}

View file

@ -1,673 +0,0 @@
/*
in_win.c
windows 95 mouse stuff
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
$Id$
*/
// 02/21/97 JCB Added extended DirectInput code to support external controllers.
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "winquake.h"
#include <dinput.h>
#include "client.h"
#include "QF/keys.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/qargs.h"
#include "QF/cmd.h"
#include "QF/input.h"
#include "view.h"
#include "host.h"
#define DINPUT_BUFFERSIZE 16
#define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
HRESULT (WINAPI * pDirectInputCreate) (HINSTANCE hinst, DWORD dwVersion,
LPDIRECTINPUT * lplpDirectInput,
LPUNKNOWN punkOuter);
// mouse public variables
float mouse_x, mouse_y;
qboolean mouseactive;
unsigned int uiWheelMessage;
// mouse local variables
static int mouse_buttons;
static int mouse_oldbuttonstate;
static POINT current_pos;
static float old_mouse_x, old_mouse_y, mx_accum, my_accum;
static qboolean mouseinitialized;
static cvar_t *m_filter;
static qboolean restore_spi;
static int originalmouseparms[3], newmouseparms[3] = { 0, 0, 1 };
static qboolean mouseparmsvalid, mouseactivatetoggle;
static qboolean mouseshowtoggle = 1;
static qboolean dinput_acquired;
static unsigned int mstate_di;
// misc locals
static LPDIRECTINPUT g_pdi;
static LPDIRECTINPUTDEVICE g_pMouse;
static HINSTANCE hInstDI;
static qboolean dinput;
typedef struct MYDATA {
LONG lX; // X axis goes here
LONG lY; // Y axis goes here
LONG lZ; // Z axis goes here
BYTE bButtonA; // One button goes here
BYTE bButtonB; // Another button goes here
BYTE bButtonC; // Another button goes here
BYTE bButtonD; // Another button goes here
} MYDATA;
static DIOBJECTDATAFORMAT rgodf[] = {
{&GUID_XAxis, FIELD_OFFSET (MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{&GUID_YAxis, FIELD_OFFSET (MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{&GUID_ZAxis, FIELD_OFFSET (MYDATA, lZ),
0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonC),
0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonD),
0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
};
#define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
static DIDATAFORMAT df = {
sizeof (DIDATAFORMAT), // this structure
sizeof (DIOBJECTDATAFORMAT), // size of object data format
DIDF_RELAXIS, // absolute axis coordinates
sizeof (MYDATA), // device data size
NUM_OBJECTS, // number of objects
rgodf, // and here they are
};
// forward-referenced functions, joy
extern void JOY_Command(void);
extern void JOY_Init_Cvars(void);
extern void JOY_Init (void);
extern void JOY_AdvancedUpdate_f (void);
extern void JOY_Move (void);
/*
Force_CenterView_f
*/
static void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
/*
IN_UpdateClipCursor
*/
void
IN_UpdateClipCursor (void)
{
if (mouseinitialized && mouseactive && !dinput) {
ClipCursor (&window_rect);
}
}
/*
IN_ShowMouse
*/
void
IN_ShowMouse (void)
{
if (!mouseshowtoggle) {
ShowCursor (TRUE);
mouseshowtoggle = 1;
}
}
/*
IN_HideMouse
*/
void
IN_HideMouse (void)
{
if (mouseshowtoggle) {
ShowCursor (FALSE);
mouseshowtoggle = 0;
}
}
/*
IN_ActivateMouse
*/
void
IN_ActivateMouse (void)
{
mouseactivatetoggle = true;
if (mouseinitialized) {
if (dinput) {
if (g_pMouse) {
if (!dinput_acquired) {
IDirectInputDevice_Acquire (g_pMouse);
dinput_acquired = true;
}
} else {
return;
}
} else {
if (mouseparmsvalid)
restore_spi =
SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
SetCursorPos (window_center_x, window_center_y);
SetCapture (mainwindow);
ClipCursor (&window_rect);
}
mouseactive = true;
}
}
/*
IN_SetQuakeMouseState
*/
void
IN_SetQuakeMouseState (void)
{
if (mouseactivatetoggle)
IN_ActivateMouse ();
}
/*
IN_DeactivateMouse
*/
void
IN_DeactivateMouse (void)
{
mouseactivatetoggle = false;
if (mouseinitialized) {
if (dinput) {
if (g_pMouse) {
if (dinput_acquired) {
IDirectInputDevice_Unacquire (g_pMouse);
dinput_acquired = false;
}
}
} else {
if (restore_spi)
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
ClipCursor (NULL);
ReleaseCapture ();
}
mouseactive = false;
}
}
/*
IN_RestoreOriginalMouseState
*/
void
IN_RestoreOriginalMouseState (void)
{
if (mouseactivatetoggle) {
IN_DeactivateMouse ();
mouseactivatetoggle = true;
}
// try to redraw the cursor so it gets reinitialized, because sometimes it
// has garbage after the mode switch
ShowCursor (TRUE);
ShowCursor (FALSE);
}
/*
IN_InitDInput
*/
static qboolean
IN_InitDInput (void)
{
HRESULT hr;
DIPROPDWORD dipdw = {
{
sizeof (DIPROPDWORD), // diph.dwSize
sizeof (DIPROPHEADER), // diph.dwHeaderSize
0, // diph.dwObj
DIPH_DEVICE, // diph.dwHow
}
,
DINPUT_BUFFERSIZE, // dwData
};
if (!hInstDI) {
hInstDI = LoadLibrary ("dinput.dll");
if (hInstDI == NULL) {
Con_Printf ("Couldn't load dinput.dll\n");
return false;
}
}
if (!pDirectInputCreate) {
pDirectInputCreate =
(void *) GetProcAddress (hInstDI, "DirectInputCreateA");
if (!pDirectInputCreate) {
Con_Printf ("Couldn't get DI proc addr\n");
return false;
}
}
// register with DirectInput and get an IDirectInput to play with.
hr =
iDirectInputCreate (global_hInstance, DIRECTINPUT_VERSION, &g_pdi,
NULL);
if (FAILED (hr)) {
return false;
}
// obtain an interface to the system mouse device.
hr = IDirectInput_CreateDevice (g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
if (FAILED (hr)) {
Con_Printf ("Couldn't open DI mouse device\n");
return false;
}
// set the data format to "mouse format".
hr = IDirectInputDevice_SetDataFormat (g_pMouse, &df);
if (FAILED (hr)) {
Con_Printf ("Couldn't set DI mouse format\n");
return false;
}
// set the cooperativity level.
hr = IDirectInputDevice_SetCooperativeLevel (g_pMouse, mainwindow,
DISCL_EXCLUSIVE |
DISCL_FOREGROUND);
if (FAILED (hr)) {
Con_Printf ("Couldn't set DI coop level\n");
return false;
}
// set the buffer size to DINPUT_BUFFERSIZE elements.
// the buffer size is a DWORD property associated with the device
hr =
IDirectInputDevice_SetProperty (g_pMouse, DIPROP_BUFFERSIZE,
&dipdw.diph);
if (FAILED (hr)) {
Con_Printf ("Couldn't set DI buffersize\n");
return false;
}
return true;
}
/*
IN_StartupMouse
*/
static void
IN_StartupMouse (void)
{
// HDC hdc;
if (COM_CheckParm ("-nomouse"))
return;
mouseinitialized = true;
if (COM_CheckParm ("-dinput")) {
dinput = IN_InitDInput ();
if (dinput) {
Con_Printf ("DirectInput initialized\n");
} else {
Con_Printf ("DirectInput not initialized\n");
}
}
if (!dinput) {
mouseparmsvalid =
SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
if (mouseparmsvalid) {
if (COM_CheckParm ("-noforcemspd"))
newmouseparms[2] = originalmouseparms[2];
if (COM_CheckParm ("-noforcemaccel")) {
newmouseparms[0] = originalmouseparms[0];
newmouseparms[1] = originalmouseparms[1];
}
if (COM_CheckParm ("-noforcemparms")) {
newmouseparms[0] = originalmouseparms[0];
newmouseparms[1] = originalmouseparms[1];
newmouseparms[2] = originalmouseparms[2];
}
}
}
mouse_buttons = 3;
// if a fullscreen video mode was set before the mouse was initialized,
// set the mouse state appropriately
if (mouseactivatetoggle)
IN_ActivateMouse ();
}
/*
IN_Init
*/
void
IN_Init (void)
{
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force view of player to center");
uiWheelMessage = RegisterWindowMessage ("MSWHEEL_ROLLMSG");
IN_StartupMouse ();
JOY_Init ();
}
void
IN_Init_Cvars (void)
{
// mouse variables
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL,
"Toggle mouse input filtering.");
JOY_Init_Cvars();
}
/*
IN_Shutdown
*/
void
IN_Shutdown (void)
{
IN_DeactivateMouse ();
IN_ShowMouse ();
if (g_pMouse) {
IDirectInputDevice_Release (g_pMouse);
g_pMouse = NULL;
}
if (g_pdi) {
IDirectInput_Release (g_pdi);
g_pdi = NULL;
}
}
/*
IN_MouseEvent
*/
void
IN_MouseEvent (int mstate)
{
int i;
if (mouseactive && !dinput) {
// perform button actions
for (i = 0; i < mouse_buttons; i++) {
if ((mstate & (1 << i)) && !(mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, true);
}
if (!(mstate & (1 << i)) && (mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, false);
}
}
mouse_oldbuttonstate = mstate;
}
}
/*
IN_MouseMove
*/
void
IN_MouseMove (void)
{
int mx, my;
// HDC hdc;
int i;
DIDEVICEOBJECTDATA od;
DWORD dwElements;
HRESULT hr;
if (!mouseactive)
return;
if (dinput) {
mx = 0;
my = 0;
for (;;) {
dwElements = 1;
hr = IDirectInputDevice_GetDeviceData (g_pMouse,
sizeof (DIDEVICEOBJECTDATA),
&od, &dwElements, 0);
if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED)) {
dinput_acquired = true;
IDirectInputDevice_Acquire (g_pMouse);
break;
}
/* Unable to read data or no data available */
if (FAILED (hr) || dwElements == 0) {
break;
}
/* Look at the element to see what happened */
switch (od.dwOfs) {
case DIMOFS_X:
mx += od.dwData;
break;
case DIMOFS_Y:
my += od.dwData;
break;
case DIMOFS_BUTTON0:
if (od.dwData & 0x80)
mstate_di |= 1;
else
mstate_di &= ~1;
break;
case DIMOFS_BUTTON1:
if (od.dwData & 0x80)
mstate_di |= (1 << 1);
else
mstate_di &= ~(1 << 1);
break;
case DIMOFS_BUTTON2:
if (od.dwData & 0x80)
mstate_di |= (1 << 2);
else
mstate_di &= ~(1 << 2);
break;
}
}
// perform button actions
for (i = 0; i < mouse_buttons; i++) {
if ((mstate_di & (1 << i)) && !(mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, true);
}
if (!(mstate_di & (1 << i)) && (mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, false);
}
}
mouse_oldbuttonstate = mstate_di;
} else {
GetCursorPos (&current_pos);
mx = current_pos.x - window_center_x + mx_accum;
my = current_pos.y - window_center_y + my_accum;
mx_accum = 0;
my_accum = 0;
}
if (m_filter->value) {
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
} else {
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
// add mouse X/Y movement to cmd
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
viewdelta.position[0] += mouse_x;
else
viewdelta.angles[YAW] -= mouse_x;
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
// if the mouse has moved, force it to the center, so there's room to move
if (mx || my) {
SetCursorPos (window_center_x, window_center_y);
}
}
/*
IN_Move
*/
void
IN_Move (void)
{
if (ActiveApp && !Minimized) {
IN_MouseMove ();
JOY_Move ();
}
}
/*
IN_Accumulate
*/
void
IN_Accumulate (void)
{
// int mx, my;
// HDC hdc;
// if (dinput) return; // If using dinput we don't probably need this
if (mouseactive) {
GetCursorPos (&current_pos);
mx_accum += current_pos.x - window_center_x;
my_accum += current_pos.y - window_center_y;
// force the mouse to the center, so there's room to move
SetCursorPos (window_center_x, window_center_y);
}
}
/*
IN_ClearStates
*/
void
IN_ClearStates (void)
{
if (mouseactive) {
mx_accum = 0;
my_accum = 0;
mouse_oldbuttonstate = 0;
}
}
/*
IN_Commands
*/
void
IN_Commands (void)
{
// Joystick
JOY_Command();
}
void
IN_HandlePause (qboolean paused)
{
}

View file

@ -1,562 +0,0 @@
/*
in_x11.c
general x11 input driver
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 1999,2000 contributors of the QuakeForge project
Please see the file "AUTHORS" for a list of contributors
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#define _BSD
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#ifdef HAVE_DGA
# include <X11/extensions/XShm.h>
# include <X11/extensions/xf86dga.h>
#endif
#include "client.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "context_x11.h"
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "dga_check.h"
#include "host.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/qargs.h"
#include "QF/sys.h"
#include "view.h"
cvar_t *_windowed_mouse;
cvar_t *m_filter;
cvar_t *in_dga;
cvar_t *in_dga_mouseaccel;
static qboolean dga_avail;
static qboolean dga_active;
static keydest_t old_key_dest = key_none;
static qboolean mouse_avail;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int p_mouse_x, p_mouse_y;
#define KEY_MASK (KeyPressMask | KeyReleaseMask)
#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
#define INPUT_MASK (KEY_MASK | MOUSE_MASK)
static int
XLateKey (XKeyEvent * ev, qboolean modified)
{
char tmp[2];
int key = 0;
KeySym keysym;
if (!modified) {
keysym = XLookupKeysym (ev, 0);
} else {
XLookupString (ev, tmp, 1, &keysym, NULL);
}
switch (keysym) {
case XK_KP_Page_Up:
key = KP_PGUP;
break;
case XK_Page_Up:
key = K_PGUP;
break;
case XK_KP_Page_Down:
key = KP_PGDN;
break;
case XK_Page_Down:
key = K_PGDN;
break;
case XK_KP_Home:
key = KP_HOME;
break;
case XK_Home:
key = K_HOME;
break;
case XK_KP_End:
key = KP_END;
break;
case XK_End:
key = K_END;
break;
case XK_KP_Left:
key = KP_LEFTARROW;
break;
case XK_Left:
key = K_LEFTARROW;
break;
case XK_KP_Right:
key = KP_RIGHTARROW;
break;
case XK_Right:
key = K_RIGHTARROW;
break;
case XK_KP_Down:
key = KP_DOWNARROW;
break;
case XK_Down:
key = K_DOWNARROW;
break;
case XK_KP_Up:
key = KP_UPARROW;
break;
case XK_Up:
key = K_UPARROW;
break;
case XK_Escape:
key = K_ESCAPE;
break;
case XK_KP_Enter:
key = KP_ENTER;
break;
case XK_Return:
key = K_ENTER;
break;
case XK_Tab:
key = K_TAB;
break;
case XK_F1:
key = K_F1;
break;
case XK_F2:
key = K_F2;
break;
case XK_F3:
key = K_F3;
break;
case XK_F4:
key = K_F4;
break;
case XK_F5:
key = K_F5;
break;
case XK_F6:
key = K_F6;
break;
case XK_F7:
key = K_F7;
break;
case XK_F8:
key = K_F8;
break;
case XK_F9:
key = K_F9;
break;
case XK_F10:
key = K_F10;
break;
case XK_F11:
key = K_F11;
break;
case XK_F12:
key = K_F12;
break;
case XK_BackSpace:
key = K_BACKSPACE;
break;
case XK_KP_Delete:
key = KP_DEL;
break;
case XK_Delete:
key = K_DEL;
break;
case XK_Pause:
key = K_PAUSE;
break;
case XK_Shift_L:
case XK_Shift_R:
key = K_SHIFT;
break;
case XK_Execute:
case XK_Control_L:
case XK_Control_R:
key = K_CTRL;
break;
case XK_Mode_switch:
case XK_Alt_L:
case XK_Meta_L:
case XK_Alt_R:
case XK_Meta_R:
key = K_ALT;
break;
case XK_Caps_Lock:
key = K_CAPSLOCK;
break;
case XK_KP_Begin:
key = KP_5;
break;
case XK_Insert:
key = K_INS;
break;
case XK_KP_Insert:
key = KP_INS;
break;
case XK_KP_Multiply:
key = KP_MULTIPLY;
break;
case XK_KP_Add:
key = KP_PLUS;
break;
case XK_KP_Subtract:
key = KP_MINUS;
break;
case XK_KP_Divide:
key = KP_DIVIDE;
break;
/* For Sun keyboards */
case XK_F27:
key = K_HOME;
break;
case XK_F29:
key = K_PGUP;
break;
case XK_F33:
key = K_END;
break;
case XK_F35:
key = K_PGDN;
break;
default:
if (keysym < 128) {
/* ASCII keys */
key = keysym;
if (!modified && ((key >= 'A') && (key <= 'Z'))) {
key = key + ('a' - 'A');
}
}
break;
}
return key;
}
static void
event_key (XEvent * event)
{
if (old_key_dest != key_dest) {
old_key_dest = key_dest;
if (key_dest == key_game) {
XAutoRepeatOff (x_disp);
} else {
XAutoRepeatOn (x_disp);
}
}
Key_Event (XLateKey (&event->xkey, 0), XLateKey (&event->xkey, 1),
event->type == KeyPress);
}
static void
event_button (XEvent * event)
{
int but;
but = event->xbutton.button;
if (but == 2)
but = 3;
else if (but == 3)
but = 2;
switch (but) {
case 1:
case 2:
case 3:
Key_Event (K_MOUSE1 + but - 1, 0, event->type == ButtonPress);
break;
case 4:
Key_Event (K_MWHEELUP, 0, event->type == ButtonPress);
break;
case 5:
Key_Event (K_MWHEELDOWN, 0, event->type == ButtonPress);
break;
}
}
static void
center_pointer (void)
{
XEvent event;
event.type = MotionNotify;
event.xmotion.display = x_disp;
event.xmotion.window = x_win;
event.xmotion.x = vid.width / 2;
event.xmotion.y = vid.height / 2;
XSendEvent (x_disp, x_win, False, PointerMotionMask, &event);
XWarpPointer (x_disp, None, x_win, 0, 0, 0, 0,
vid.width / 2, vid.height / 2);
}
static void
event_motion (XEvent * event)
{
if (dga_active) {
mouse_x += event->xmotion.x_root * in_dga_mouseaccel->value;
mouse_y += event->xmotion.y_root * in_dga_mouseaccel->value;
} else {
if (vid_fullscreen->int_val || _windowed_mouse->int_val) {
if (!event->xmotion.send_event) {
mouse_x += (event->xmotion.x - p_mouse_x);
mouse_y += (event->xmotion.y - p_mouse_y);
if (abs (vid.width / 2 - event->xmotion.x) > vid.width / 4
|| abs (vid.height / 2 - event->xmotion.y) > vid.height / 4) {
center_pointer ();
}
}
} else {
mouse_x += (event->xmotion.x - p_mouse_x);
mouse_y += (event->xmotion.y - p_mouse_y);
}
p_mouse_x = event->xmotion.x;
p_mouse_y = event->xmotion.y;
}
}
void
IN_Commands (void)
{
static int old_windowed_mouse;
static int old_in_dga;
JOY_Command ();
if ((old_windowed_mouse != _windowed_mouse->int_val)
|| (old_in_dga != in_dga->int_val)) {
old_windowed_mouse = _windowed_mouse->int_val;
old_in_dga = in_dga->int_val;
if (_windowed_mouse->int_val) { // grab the pointer
XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
#ifdef HAVE_DGA
if (dga_avail && in_dga->int_val && !dga_active) {
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp),
XF86DGADirectMouse);
dga_active = true;
}
#endif
} else { // ungrab the pointer
#ifdef HAVE_DGA
if (dga_avail && in_dga->int_val && dga_active) {
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
dga_active = false;
}
#endif
XUngrabPointer (x_disp, CurrentTime);
}
}
}
void
IN_SendKeyEvents (void)
{
/* Get events from X server. */
x11_process_events ();
}
void
IN_Move (void)
{
JOY_Move ();
if (!mouse_avail)
return;
if (m_filter->int_val) {
mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
}
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
viewdelta.position[0] += mouse_x;
else
viewdelta.angles[YAW] -= mouse_x;
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
mouse_x = mouse_y = 0.0;
}
/*
Called at shutdown
*/
void
IN_Shutdown (void)
{
JOY_Shutdown ();
Con_Printf ("IN_Shutdown\n");
mouse_avail = 0;
if (x_disp) {
XAutoRepeatOn (x_disp);
#ifdef HAVE_DGA
if (dga_avail)
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
#endif
}
x11_close_display ();
}
void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
void
IN_Init (void)
{
// open the display
if (!x_disp)
Sys_Error ("IN: No display!!\n");
if (!x_win)
Sys_Error ("IN: No window!!\n");
x11_open_display (); // call to increment the reference
// counter
{
int attribmask = CWEventMask;
XWindowAttributes attribs_1;
XSetWindowAttributes attribs_2;
XGetWindowAttributes (x_disp, x_win, &attribs_1);
attribs_2.event_mask = attribs_1.your_event_mask | INPUT_MASK;
XChangeWindowAttributes (x_disp, x_win, attribmask, &attribs_2);
}
JOY_Init ();
XAutoRepeatOff (x_disp);
if (COM_CheckParm ("-nomouse"))
return;
dga_avail = VID_CheckDGA (x_disp, NULL, NULL, NULL);
if (vid_fullscreen->int_val) {
Cvar_Set (_windowed_mouse, "1");
_windowed_mouse->flags |= CVAR_ROM;
}
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
x11_add_event (KeyPress, &event_key);
x11_add_event (KeyRelease, &event_key);
x11_add_event (ButtonPress, &event_button);
x11_add_event (ButtonRelease, &event_button);
x11_add_event (MotionNotify, &event_motion);
Cmd_AddCommand ("force_centerview", Force_CenterView_f,
"Force view of player to center");
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
_windowed_mouse =
Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
"With this set to 1, quake will grab the mouse from X");
m_filter =
Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL,
"Toggle mouse input filtering.");
in_dga = Cvar_Get ("in_dga", "1", CVAR_ARCHIVE, NULL, "DGA Input support");
in_dga_mouseaccel = Cvar_Get ("in_dga_mouseaccel", "1", CVAR_ARCHIVE, NULL,
"DGA Mouse accelleration multiplier");
}
void
IN_HandlePause (qboolean paused)
{
}

View file

@ -1,152 +0,0 @@
/*
in_fbdev.c
fix this!
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "protocol.h"
#include "QF/cvar.h"
#include "QF/keys.h"
cvar_t *_windowed_mouse;
int
fd_blocking (int fd, int on)
{
int x;
#if defined(_POSIX_SOURCE) || !defined(FIONBIO)
#if !defined(O_NONBLOCK)
# if defined(O_NDELAY)
# define O_NONBLOCK O_NDELAY
# endif
#endif
if ((x = fcntl(fd, F_GETFL, 0)) == -1)
return -1;
if (on)
x &= ~O_NONBLOCK;
else
x |= O_NONBLOCK;
return fcntl(fd, F_SETFL, x);
#else
x = !on;
return ioctl(fd, FIONBIO, &x);
#endif
}
static struct termios old_tty, new_tty;
static int tty_fd = 0;
void
IN_Init (void)
{
fd_blocking(0, 0);
tcgetattr(tty_fd, &old_tty);
new_tty = old_tty;
new_tty.c_cc[VMIN] = 1;
new_tty.c_cc[VTIME] = 0;
new_tty.c_lflag &= ~ICANON;
new_tty.c_iflag &= ~IXON;
tcsetattr(tty_fd, TCSADRAIN, &new_tty);
}
void
IN_Init_Cvars (void)
{
}
void
IN_Shutdown (void)
{
}
void
IN_SendKeyEvents (void)
{
int k, down;
char buf[4];
if (read(0, buf, 1) == 1) {
k = buf[0];
switch (k) {
case '\r':
case '\n':
k = K_ENTER;
break;
case '\033':
if (read(0, buf, 2) != 2)
break;
switch (buf[1]) {
case 'A':
k = K_UPARROW;
break;
case 'B':
k = K_DOWNARROW;
break;
case 'C':
k = K_RIGHTARROW;
break;
case 'D':
k = K_LEFTARROW;
break;
}
break;
}
down = 1;
Key_Event(k, -1, down);
Key_Event(k, -1, !down);
}
}
void
IN_Commands (void)
{
}
void
IN_Move (void)
{
}
/*
IN_ModeChanged
*/
void
IN_ModeChanged (void)
{
}

View file

@ -1,64 +0,0 @@
/*
in_null.c
for systems without a mouse
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
void
IN_Init (void)
{
}
void
IN_Init_Cvars (void)
{
}
void
IN_Shutdown (void)
{
}
void
IN_Commands (void)
{
}
void
IN_Move (usercmd_t *cmd)
{
}
/*
IN_ModeChanged
*/
void
IN_ModeChanged (void)
{
}

View file

@ -1,434 +0,0 @@
/*
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 "client.h"
#include "cl_input.h"
#include "cl_main.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "draw.h"
#include "host.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/sys.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "vid.h"
#include "view.h"
#ifdef WIN32
// FIXME: this is evil...
# include <windows.h>
HWND mainwindow;
#endif
cvar_t *m_filter;
cvar_t *_windowed_mouse;
int old_windowed_mouse;
int modestate; // FIXME: just to avoid cross-comp.
// errors - remove later
static qboolean mouse_avail;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int mouse_oldbuttonstate = 0;
extern viddef_t vid; // global video state
/*
IN_SendKeyEvents
*/
void
IN_SendKeyEvents (void)
{
SDL_Event event;
int sym, state, but;
int modstate;
while (SDL_PollEvent (&event)) {
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
sym = event.key.keysym.sym;
state = event.key.state;
modstate = SDL_GetModState ();
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;
case SDLK_CAPSLOCK:
sym = K_CAPSLOCK;
break;
case SDLK_KP0:
if (modstate & KMOD_NUM)
sym = K_INS;
else
sym = SDLK_0;
break;
case SDLK_KP1:
if (modstate & KMOD_NUM)
sym = K_END;
else
sym = SDLK_1;
break;
case SDLK_KP2:
if (modstate & KMOD_NUM)
sym = K_DOWNARROW;
else
sym = SDLK_2;
break;
case SDLK_KP3:
if (modstate & KMOD_NUM)
sym = K_PGDN;
else
sym = SDLK_3;
break;
case SDLK_KP4:
if (modstate & KMOD_NUM)
sym = K_LEFTARROW;
else
sym = SDLK_4;
break;
case SDLK_KP5:
sym = SDLK_5;
break;
case SDLK_KP6:
if (modstate & KMOD_NUM)
sym = K_RIGHTARROW;
else
sym = SDLK_6;
break;
case SDLK_KP7:
if (modstate & KMOD_NUM)
sym = K_HOME;
else
sym = SDLK_7;
break;
case SDLK_KP8:
if (modstate & KMOD_NUM)
sym = K_UPARROW;
else
sym = SDLK_8;
break;
case SDLK_KP9:
if (modstate & KMOD_NUM)
sym = K_PGUP;
else
sym = SDLK_9;
break;
case SDLK_KP_PERIOD:
if (modstate & KMOD_NUM)
sym = K_DEL;
else
sym = SDLK_PERIOD;
break;
case SDLK_KP_DIVIDE:
sym = SDLK_SLASH;
break;
case SDLK_KP_MULTIPLY:
sym = SDLK_ASTERISK;
break;
case SDLK_KP_MINUS:
sym = SDLK_MINUS;
break;
case SDLK_KP_PLUS:
sym = SDLK_PLUS;
break;
case SDLK_KP_ENTER:
sym = SDLK_RETURN;
break;
case SDLK_KP_EQUALS:
sym = SDLK_EQUALS;
break;
}
// If we're not directly handled and still above 255
// just force it to 0
if (sym > 255)
sym = 0;
Key_Event (sym, -1, 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:
Key_Event (K_MOUSE1 + but - 1, 0, event.type
== SDL_MOUSEBUTTONDOWN);
break;
case 4:
Key_Event (K_MWHEELUP, 0,
event.type == SDL_MOUSEBUTTONDOWN);
break;
case 5:
Key_Event (K_MWHEELDOWN, 0,
event.type == SDL_MOUSEBUTTONDOWN);
break;
}
break;
case SDL_MOUSEMOTION:
if (_windowed_mouse->value) {
if ((event.motion.x != (vid.width / 2))
|| (event.motion.y != (vid.height / 2))) {
// *2 for vid_sdl.c, *10 for vid_sgl.c.
mouse_x = event.motion.xrel * 5;
mouse_y = event.motion.yrel * 5;
if (
(event.motion.x <
((vid.width / 2) - (vid.width / 4)))
|| (event.motion.x >
((vid.width / 2) + (vid.width / 4)))
|| (event.motion.y <
((vid.height / 2) - (vid.height / 4)))
|| (event.motion.y >
((vid.height / 2) + (vid.height / 4))))
SDL_WarpMouse (vid.width / 2, vid.height / 2);
}
} else {
// following are *2 in vid_sdl.c, vid_sgl.c is *10
mouse_x = event.motion.xrel * 5;
mouse_y = event.motion.yrel * 5;
}
break;
case SDL_QUIT:
CL_Disconnect ();
Sys_Quit ();
break;
default:
break;
}
}
}
void
IN_Commands (void)
{
JOY_Command ();
if (old_windowed_mouse != _windowed_mouse->value) {
old_windowed_mouse = _windowed_mouse->value;
if (!_windowed_mouse->value) {
// SDL_ShowCursor (0);
SDL_WM_GrabInput (SDL_GRAB_OFF);
} else {
SDL_WM_GrabInput (SDL_GRAB_ON);
// SDL_ShowCursor (1);
}
}
}
void
IN_Init (void)
{
JOY_Init ();
if (COM_CheckParm ("-nomouse") && !_windowed_mouse->value)
return;
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
// SDL_ShowCursor (0);
// SDL_WM_GrabInput (SDL_GRAB_ON);
// FIXME: disable DGA if in_dgamouse says to.
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL, "If set to 1, quake will grab the mouse in X");
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL, "Toggle mouse input filtering");
}
void
IN_Shutdown (void)
{
mouse_avail = 0;
}
void
IN_Frame (void)
{
int i;
int mouse_buttonstate;
if (!mouse_avail)
return;
i = SDL_GetMouseState (NULL, NULL);
/* Quake swaps the second and third buttons */
mouse_buttonstate = (i & ~0x06) | ((i & 0x02) << 1) | ((i & 0x04) >> 1);
for (i = 0; i < 3; i++) {
if ((mouse_buttonstate & (1 << i))
&& !(mouse_oldbuttonstate & (1 << i))) Key_Event (K_MOUSE1 + i, 0,
true);
if (!(mouse_buttonstate & (1 << i))
&& (mouse_oldbuttonstate & (1 << i))) Key_Event (K_MOUSE1 + i, 0,
false);
}
mouse_oldbuttonstate = mouse_buttonstate;
}
void
IN_Move (void)
{
JOY_Move ();
if (!mouse_avail)
return;
if (m_filter->value) {
mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
}
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
if ((in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1)))
viewdelta.position[0] += mouse_x;
else
viewdelta.angles[YAW] -= mouse_x;
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
mouse_x = mouse_y = 0.0;
}

View file

@ -1,402 +0,0 @@
/*
in_svgalib.c
(description)
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 1999,2000 contributors of the QuakeForge project
Please see the file "AUTHORS" for a list of contributors
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <vga.h>
#include <vgakeyboard.h>
#include <vgamouse.h>
#include "cl_input.h"
#include "client.h"
#include "QF/cmd.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "host.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/qargs.h"
#include "QF/sys.h"
#include "view.h"
static int UseKeyboard = 1;
static int UseMouse = 1;
static int in_svgalib_inited = 0;
static unsigned char scantokey[128];
static int mouse_buttons;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int mx, my;
static void IN_InitKeyboard (void);
static void IN_InitMouse (void);
cvar_t *_windowed_mouse;
cvar_t *m_filter;
static void
keyhandler (int scancode, int state)
{
int sc;
sc = scancode & 0x7f;
#if 0
Con_Printf ("scancode=%x (%d%s)\n", scancode, sc,
scancode & 0x80 ? "+128" : "");
#endif
Key_Event (scantokey[sc], -1, state == KEY_EVENTPRESS);
}
static void
mousehandler (int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz)
{
mouse_buttonstate = buttonstate;
mx += dx;
my += dy;
if (drx > 0) {
Key_Event (K_MWHEELUP, 0, 1);
Key_Event (K_MWHEELUP, 0, 0);
} else if (drx < 0) {
Key_Event (K_MWHEELDOWN, 0, 1);
Key_Event (K_MWHEELDOWN, 0, 0);
}
}
void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
void
IN_Init (void)
{
if (COM_CheckParm ("-nokbd"))
UseKeyboard = 0;
if (COM_CheckParm ("-nomouse"))
UseMouse = 0;
if (UseKeyboard)
IN_InitKeyboard ();
if (UseMouse)
IN_InitMouse ();
JOY_Init ();
in_svgalib_inited = 1;
return;
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL,
"Toggle mouse input filtering.");
}
static void
IN_InitKeyboard (void)
{
int i;
for (i = 0; i < 128; i++) {
scantokey[i] = ' ';
}
scantokey[1] = K_ESCAPE;
scantokey[2] = '1';
scantokey[3] = '2';
scantokey[4] = '3';
scantokey[5] = '4';
scantokey[6] = '5';
scantokey[7] = '6';
scantokey[8] = '7';
scantokey[9] = '8';
scantokey[10] = '9';
scantokey[11] = '0';
scantokey[12] = '-';
scantokey[13] = '=';
scantokey[14] = K_BACKSPACE;
scantokey[15] = K_TAB;
scantokey[16] = 'q';
scantokey[17] = 'w';
scantokey[18] = 'e';
scantokey[19] = 'r';
scantokey[20] = 't';
scantokey[21] = 'y';
scantokey[22] = 'u';
scantokey[23] = 'i';
scantokey[24] = 'o';
scantokey[25] = 'p';
scantokey[26] = '[';
scantokey[27] = ']';
scantokey[28] = K_ENTER;
scantokey[29] = K_CTRL; /* left */
scantokey[30] = 'a';
scantokey[31] = 's';
scantokey[32] = 'd';
scantokey[33] = 'f';
scantokey[34] = 'g';
scantokey[35] = 'h';
scantokey[36] = 'j';
scantokey[37] = 'k';
scantokey[38] = 'l';
scantokey[39] = ';';
scantokey[40] = '\'';
scantokey[41] = '`';
scantokey[42] = K_SHIFT; /* left */
scantokey[43] = '\\';
scantokey[44] = 'z';
scantokey[45] = 'x';
scantokey[46] = 'c';
scantokey[47] = 'v';
scantokey[48] = 'b';
scantokey[49] = 'n';
scantokey[50] = 'm';
scantokey[51] = ',';
scantokey[52] = '.';
scantokey[53] = '/';
scantokey[54] = K_SHIFT; /* right */
scantokey[55] = KP_MULTIPLY;
scantokey[56] = K_ALT; /* left */
scantokey[57] = ' ';
scantokey[58] = K_CAPSLOCK;
scantokey[59] = K_F1;
scantokey[60] = K_F2;
scantokey[61] = K_F3;
scantokey[62] = K_F4;
scantokey[63] = K_F5;
scantokey[64] = K_F6;
scantokey[65] = K_F7;
scantokey[66] = K_F8;
scantokey[67] = K_F9;
scantokey[68] = K_F10;
scantokey[69] = KP_NUMLCK;
scantokey[70] = K_SCRLCK;
scantokey[71] = KP_HOME;
scantokey[72] = KP_UPARROW;
scantokey[73] = KP_PGUP;
scantokey[74] = KP_MINUS;
scantokey[75] = KP_LEFTARROW;
scantokey[76] = KP_5;
scantokey[77] = KP_RIGHTARROW;
scantokey[79] = KP_END;
scantokey[78] = KP_PLUS;
scantokey[80] = KP_DOWNARROW;
scantokey[81] = KP_PGDN;
scantokey[82] = KP_INS;
scantokey[83] = KP_DEL;
/* 84 to 86 not used */
scantokey[87] = K_F11;
scantokey[88] = K_F12;
/* 89 to 95 not used */
scantokey[96] = KP_ENTER; /* keypad enter */
scantokey[97] = K_CTRL; /* right */
scantokey[98] = KP_DIVIDE;
scantokey[99] = K_PRNTSCR; /* print screen */
scantokey[100] = K_ALT; /* right */
scantokey[101] = K_PAUSE; /* break */
scantokey[102] = K_HOME;
scantokey[103] = K_UPARROW;
scantokey[104] = K_PGUP;
scantokey[105] = K_LEFTARROW;
scantokey[106] = K_RIGHTARROW;
scantokey[107] = K_END;
scantokey[108] = K_DOWNARROW;
scantokey[109] = K_PGDN;
scantokey[110] = K_INS;
scantokey[111] = K_DEL;
scantokey[119] = K_PAUSE;
if (keyboard_init ()) {
Sys_Error ("keyboard_init() failed");
}
keyboard_seteventhandler (keyhandler);
}
static void
IN_InitMouse (void)
{
int mtype;
char *mousedev;
int mouserate = MOUSE_DEFAULTSAMPLERATE;
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force viewpoint of player to center");
mouse_buttons = 3;
mtype = vga_getmousetype ();
mousedev = "/dev/mouse";
if (getenv ("MOUSEDEV"))
mousedev = getenv ("MOUSEDEV");
if (COM_CheckParm ("-mdev")) {
mousedev = com_argv[COM_CheckParm ("-mdev") + 1];
}
if (getenv ("MOUSERATE"))
mouserate = atoi (getenv ("MOUSERATE"));
if (COM_CheckParm ("-mrate")) {
mouserate = atoi (com_argv[COM_CheckParm ("-mrate") + 1]);
}
#if 0
printf ("Mouse: dev=%s,type=%s,speed=%d\n",
mousedev, mice[mtype].name, mouserate);
#endif
if (mouse_init (mousedev, mtype, mouserate)) {
Con_Printf ("No mouse found\n");
UseMouse = 0;
} else {
mouse_seteventhandler ((void *) mousehandler);
}
}
void
IN_Shutdown (void)
{
JOY_Shutdown ();
Con_Printf ("IN_Shutdown\n");
if (UseMouse)
mouse_close ();
if (UseKeyboard)
keyboard_close ();
in_svgalib_inited = 0;
}
void
IN_SendKeyEvents (void)
{
if (!in_svgalib_inited)
return;
if (UseKeyboard) {
while ((keyboard_update ()));
}
}
void
IN_Commands (void)
{
JOY_Command ();
if (UseMouse) {
/* Poll mouse values */
while (mouse_update ());
/* Perform button actions */
if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
Key_Event (K_MOUSE1, 0, true);
else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
Key_Event (K_MOUSE1, 0, false);
if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
Key_Event (K_MOUSE2, 0, true);
else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
Key_Event (K_MOUSE2, 0, false);
if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
Key_Event (K_MOUSE3, 0, true);
else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
Key_Event (K_MOUSE3, 0, false);
mouse_oldbuttonstate = mouse_buttonstate;
}
}
void
IN_Move (void)
{
JOY_Move ();
if (!UseMouse)
return;
/* Poll mouse values */
while (mouse_update ());
if (m_filter->int_val) {
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
} else {
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
/* Clear for next update */
mx = my = 0;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
/* Add mouse X/Y movement to cmd */
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook)) {
viewdelta.position[0] += mouse_x;
} else {
viewdelta.angles[YAW] -= mouse_x;
}
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack) {
viewdelta.position[1] -= mouse_y;
} else {
viewdelta.position[2] -= mouse_y;
}
}
}

View file

@ -1,671 +0,0 @@
/*
in_win.c
windows 95 mouse stuff
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
$Id$
*/
// 02/21/97 JCB Added extended DirectInput code to support external controllers.
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "winquake.h"
#include <dinput.h>
#include "client.h"
#include "QF/keys.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/qargs.h"
#include "QF/cmd.h"
#include "QF/input.h"
#include "cl_input.h"
#include "view.h"
#include "host.h"
#define DINPUT_BUFFERSIZE 16
#define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
HRESULT (WINAPI * pDirectInputCreate) (HINSTANCE hinst, DWORD dwVersion,
LPDIRECTINPUT * lplpDirectInput,
LPUNKNOWN punkOuter);
// mouse public variables
float mouse_x, mouse_y;
qboolean mouseactive;
unsigned int uiWheelMessage;
// mouse local variables
static int mouse_buttons;
static int mouse_oldbuttonstate;
static POINT current_pos;
static float old_mouse_x, old_mouse_y, mx_accum, my_accum;
static qboolean mouseinitialized;
static cvar_t *m_filter;
static qboolean restore_spi;
static int originalmouseparms[3], newmouseparms[3] = { 0, 0, 1 };
static qboolean mouseparmsvalid, mouseactivatetoggle;
static qboolean mouseshowtoggle = 1;
static qboolean dinput_acquired;
static unsigned int mstate_di;
// misc locals
static LPDIRECTINPUT g_pdi;
static LPDIRECTINPUTDEVICE g_pMouse;
static HINSTANCE hInstDI;
static qboolean dinput;
typedef struct MYDATA {
LONG lX; // X axis goes here
LONG lY; // Y axis goes here
LONG lZ; // Z axis goes here
BYTE bButtonA; // One button goes here
BYTE bButtonB; // Another button goes here
BYTE bButtonC; // Another button goes here
BYTE bButtonD; // Another button goes here
} MYDATA;
static DIOBJECTDATAFORMAT rgodf[] = {
{&GUID_XAxis, FIELD_OFFSET (MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{&GUID_YAxis, FIELD_OFFSET (MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{&GUID_ZAxis, FIELD_OFFSET (MYDATA, lZ),
0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonC),
0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonD),
0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
};
#define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
static DIDATAFORMAT df = {
sizeof (DIDATAFORMAT), // this structure
sizeof (DIOBJECTDATAFORMAT), // size of object data format
DIDF_RELAXIS, // absolute axis coordinates
sizeof (MYDATA), // device data size
NUM_OBJECTS, // number of objects
rgodf, // and here they are
};
// forward-referenced functions, joy
extern void JOY_Command(void);
extern void JOY_Init_Cvars(void);
extern void JOY_Init (void);
extern void JOY_AdvancedUpdate_f (void);
extern void JOY_Move (void);
/*
Force_CenterView_f
*/
static void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
/*
IN_UpdateClipCursor
*/
void
IN_UpdateClipCursor (void)
{
if (mouseinitialized && mouseactive && !dinput) {
ClipCursor (&window_rect);
}
}
/*
IN_ShowMouse
*/
void
IN_ShowMouse (void)
{
if (!mouseshowtoggle) {
ShowCursor (TRUE);
mouseshowtoggle = 1;
}
}
/*
IN_HideMouse
*/
void
IN_HideMouse (void)
{
if (mouseshowtoggle) {
ShowCursor (FALSE);
mouseshowtoggle = 0;
}
}
/*
IN_ActivateMouse
*/
void
IN_ActivateMouse (void)
{
mouseactivatetoggle = true;
if (mouseinitialized) {
if (dinput) {
if (g_pMouse) {
if (!dinput_acquired) {
IDirectInputDevice_Acquire (g_pMouse);
dinput_acquired = true;
}
} else {
return;
}
} else {
if (mouseparmsvalid)
restore_spi =
SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
SetCursorPos (window_center_x, window_center_y);
SetCapture (mainwindow);
ClipCursor (&window_rect);
}
mouseactive = true;
}
}
/*
IN_SetQuakeMouseState
*/
void
IN_SetQuakeMouseState (void)
{
if (mouseactivatetoggle)
IN_ActivateMouse ();
}
/*
IN_DeactivateMouse
*/
void
IN_DeactivateMouse (void)
{
mouseactivatetoggle = false;
if (mouseinitialized) {
if (dinput) {
if (g_pMouse) {
if (dinput_acquired) {
IDirectInputDevice_Unacquire (g_pMouse);
dinput_acquired = false;
}
}
} else {
if (restore_spi)
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
ClipCursor (NULL);
ReleaseCapture ();
}
mouseactive = false;
}
}
/*
IN_RestoreOriginalMouseState
*/
void
IN_RestoreOriginalMouseState (void)
{
if (mouseactivatetoggle) {
IN_DeactivateMouse ();
mouseactivatetoggle = true;
}
// try to redraw the cursor so it gets reinitialized, because sometimes it
// has garbage after the mode switch
ShowCursor (TRUE);
ShowCursor (FALSE);
}
/*
IN_InitDInput
*/
static qboolean
IN_InitDInput (void)
{
HRESULT hr;
DIPROPDWORD dipdw = {
{
sizeof (DIPROPDWORD), // diph.dwSize
sizeof (DIPROPHEADER), // diph.dwHeaderSize
0, // diph.dwObj
DIPH_DEVICE, // diph.dwHow
}
,
DINPUT_BUFFERSIZE, // dwData
};
if (!hInstDI) {
hInstDI = LoadLibrary ("dinput.dll");
if (hInstDI == NULL) {
Con_Printf ("Couldn't load dinput.dll\n");
return false;
}
}
if (!pDirectInputCreate) {
pDirectInputCreate =
(void *) GetProcAddress (hInstDI, "DirectInputCreateA");
if (!pDirectInputCreate) {
Con_Printf ("Couldn't get DI proc addr\n");
return false;
}
}
// register with DirectInput and get an IDirectInput to play with.
hr =
iDirectInputCreate (global_hInstance, DIRECTINPUT_VERSION, &g_pdi,
NULL);
if (FAILED (hr)) {
return false;
}
// obtain an interface to the system mouse device.
hr = IDirectInput_CreateDevice (g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
if (FAILED (hr)) {
Con_Printf ("Couldn't open DI mouse device\n");
return false;
}
// set the data format to "mouse format".
hr = IDirectInputDevice_SetDataFormat (g_pMouse, &df);
if (FAILED (hr)) {
Con_Printf ("Couldn't set DI mouse format\n");
return false;
}
// set the cooperativity level.
hr = IDirectInputDevice_SetCooperativeLevel (g_pMouse, mainwindow,
DISCL_EXCLUSIVE |
DISCL_FOREGROUND);
if (FAILED (hr)) {
Con_Printf ("Couldn't set DI coop level\n");
return false;
}
// set the buffer size to DINPUT_BUFFERSIZE elements.
// the buffer size is a DWORD property associated with the device
hr =
IDirectInputDevice_SetProperty (g_pMouse, DIPROP_BUFFERSIZE,
&dipdw.diph);
if (FAILED (hr)) {
Con_Printf ("Couldn't set DI buffersize\n");
return false;
}
return true;
}
/*
IN_StartupMouse
*/
static void
IN_StartupMouse (void)
{
// HDC hdc;
if (COM_CheckParm ("-nomouse"))
return;
mouseinitialized = true;
if (COM_CheckParm ("-dinput")) {
dinput = IN_InitDInput ();
if (dinput) {
Con_Printf ("DirectInput initialized\n");
} else {
Con_Printf ("DirectInput not initialized\n");
}
}
if (!dinput) {
mouseparmsvalid =
SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
if (mouseparmsvalid) {
if (COM_CheckParm ("-noforcemspd"))
newmouseparms[2] = originalmouseparms[2];
if (COM_CheckParm ("-noforcemaccel")) {
newmouseparms[0] = originalmouseparms[0];
newmouseparms[1] = originalmouseparms[1];
}
if (COM_CheckParm ("-noforcemparms")) {
newmouseparms[0] = originalmouseparms[0];
newmouseparms[1] = originalmouseparms[1];
newmouseparms[2] = originalmouseparms[2];
}
}
}
mouse_buttons = 3;
// if a fullscreen video mode was set before the mouse was initialized,
// set the mouse state appropriately
if (mouseactivatetoggle)
IN_ActivateMouse ();
}
/*
IN_Init
*/
void
IN_Init (void)
{
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force view of player to center");
uiWheelMessage = RegisterWindowMessage ("MSWHEEL_ROLLMSG");
IN_StartupMouse ();
JOY_Init ();
}
void
IN_Init_Cvars (void)
{
// mouse variables
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL,
"Toggle mouse input filtering.");
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
"Grab the mouse from X while playing quake");
JOY_Init_Cvars();
}
/*
IN_Shutdown
*/
void
IN_Shutdown (void)
{
IN_DeactivateMouse ();
IN_ShowMouse ();
if (g_pMouse) {
IDirectInputDevice_Release (g_pMouse);
g_pMouse = NULL;
}
if (g_pdi) {
IDirectInput_Release (g_pdi);
g_pdi = NULL;
}
}
/*
IN_MouseEvent
*/
void
IN_MouseEvent (int mstate)
{
int i;
if (mouseactive && !dinput) {
// perform button actions
for (i = 0; i < mouse_buttons; i++) {
if ((mstate & (1 << i)) && !(mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, true);
}
if (!(mstate & (1 << i)) && (mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, false);
}
}
mouse_oldbuttonstate = mstate;
}
}
/*
IN_MouseMove
*/
void
IN_MouseMove (void)
{
int mx, my;
// HDC hdc;
int i;
DIDEVICEOBJECTDATA od;
DWORD dwElements;
HRESULT hr;
if (!mouseactive)
return;
if (dinput) {
mx = 0;
my = 0;
for (;;) {
dwElements = 1;
hr = IDirectInputDevice_GetDeviceData (g_pMouse,
sizeof (DIDEVICEOBJECTDATA),
&od, &dwElements, 0);
if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED)) {
dinput_acquired = true;
IDirectInputDevice_Acquire (g_pMouse);
break;
}
/* Unable to read data or no data available */
if (FAILED (hr) || dwElements == 0) {
break;
}
/* Look at the element to see what happened */
switch (od.dwOfs) {
case DIMOFS_X:
mx += od.dwData;
break;
case DIMOFS_Y:
my += od.dwData;
break;
case DIMOFS_BUTTON0:
if (od.dwData & 0x80)
mstate_di |= 1;
else
mstate_di &= ~1;
break;
case DIMOFS_BUTTON1:
if (od.dwData & 0x80)
mstate_di |= (1 << 1);
else
mstate_di &= ~(1 << 1);
break;
case DIMOFS_BUTTON2:
if (od.dwData & 0x80)
mstate_di |= (1 << 2);
else
mstate_di &= ~(1 << 2);
break;
}
}
// perform button actions
for (i = 0; i < mouse_buttons; i++) {
if ((mstate_di & (1 << i)) && !(mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, true);
}
if (!(mstate_di & (1 << i)) && (mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, false);
}
}
mouse_oldbuttonstate = mstate_di;
} else {
GetCursorPos (&current_pos);
mx = current_pos.x - window_center_x + mx_accum;
my = current_pos.y - window_center_y + my_accum;
mx_accum = 0;
my_accum = 0;
}
if (m_filter->value) {
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
} else {
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
// add mouse X/Y movement to cmd
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
viewdelta.position[0] += mouse_x;
else
viewdelta.angles[YAW] -= mouse_x;
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
// if the mouse has moved, force it to the center, so there's room to move
if (mx || my) {
SetCursorPos (window_center_x, window_center_y);
}
}
/*
IN_Move
*/
void
IN_Move (void)
{
if (ActiveApp && !Minimized) {
IN_MouseMove ();
JOY_Move ();
}
}
/*
IN_Accumulate
*/
void
IN_Accumulate (void)
{
// int mx, my;
// HDC hdc;
// if (dinput) return; // If using dinput we don't probably need this
if (mouseactive) {
GetCursorPos (&current_pos);
mx_accum += current_pos.x - window_center_x;
my_accum += current_pos.y - window_center_y;
// force the mouse to the center, so there's room to move
SetCursorPos (window_center_x, window_center_y);
}
}
/*
IN_ClearStates
*/
void
IN_ClearStates (void)
{
if (mouseactive) {
mx_accum = 0;
my_accum = 0;
mouse_oldbuttonstate = 0;
}
}
/*
IN_Commands
*/
void
IN_Commands (void)
{
// Joystick
JOY_Command();
}

View file

@ -1,558 +0,0 @@
/*
in_x11.c
general x11 input driver
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 1999,2000 contributors of the QuakeForge project
Please see the file "AUTHORS" for a list of contributors
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#define _BSD
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#ifdef HAVE_DGA
# include <X11/extensions/XShm.h>
# include <X11/extensions/xf86dga.h>
#endif
#include "cl_input.h"
#include "client.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "context_x11.h"
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "dga_check.h"
#include "host.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/qargs.h"
#include "QF/sys.h"
#include "view.h"
cvar_t *_windowed_mouse;
cvar_t *m_filter;
cvar_t *in_dga;
cvar_t *in_dga_mouseaccel;
static qboolean dga_avail;
static qboolean dga_active;
static keydest_t old_key_dest = key_none;
static qboolean mouse_avail;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int p_mouse_x, p_mouse_y;
#define KEY_MASK (KeyPressMask | KeyReleaseMask)
#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
#define INPUT_MASK (KEY_MASK | MOUSE_MASK)
static int
XLateKey (XKeyEvent * ev, qboolean modified)
{
char tmp[2];
int key = 0;
KeySym keysym;
if (!modified) {
keysym = XLookupKeysym (ev, 0);
} else {
XLookupString (ev, tmp, 1, &keysym, NULL);
}
switch (keysym) {
case XK_KP_Page_Up:
key = KP_PGUP;
break;
case XK_Page_Up:
key = K_PGUP;
break;
case XK_KP_Page_Down:
key = KP_PGDN;
break;
case XK_Page_Down:
key = K_PGDN;
break;
case XK_KP_Home:
key = KP_HOME;
break;
case XK_Home:
key = K_HOME;
break;
case XK_KP_End:
key = KP_END;
break;
case XK_End:
key = K_END;
break;
case XK_KP_Left:
key = KP_LEFTARROW;
break;
case XK_Left:
key = K_LEFTARROW;
break;
case XK_KP_Right:
key = KP_RIGHTARROW;
break;
case XK_Right:
key = K_RIGHTARROW;
break;
case XK_KP_Down:
key = KP_DOWNARROW;
break;
case XK_Down:
key = K_DOWNARROW;
break;
case XK_KP_Up:
key = KP_UPARROW;
break;
case XK_Up:
key = K_UPARROW;
break;
case XK_Escape:
key = K_ESCAPE;
break;
case XK_KP_Enter:
key = KP_ENTER;
break;
case XK_Return:
key = K_ENTER;
break;
case XK_Tab:
key = K_TAB;
break;
case XK_F1:
key = K_F1;
break;
case XK_F2:
key = K_F2;
break;
case XK_F3:
key = K_F3;
break;
case XK_F4:
key = K_F4;
break;
case XK_F5:
key = K_F5;
break;
case XK_F6:
key = K_F6;
break;
case XK_F7:
key = K_F7;
break;
case XK_F8:
key = K_F8;
break;
case XK_F9:
key = K_F9;
break;
case XK_F10:
key = K_F10;
break;
case XK_F11:
key = K_F11;
break;
case XK_F12:
key = K_F12;
break;
case XK_BackSpace:
key = K_BACKSPACE;
break;
case XK_KP_Delete:
key = KP_DEL;
break;
case XK_Delete:
key = K_DEL;
break;
case XK_Pause:
key = K_PAUSE;
break;
case XK_Shift_L:
case XK_Shift_R:
key = K_SHIFT;
break;
case XK_Execute:
case XK_Control_L:
case XK_Control_R:
key = K_CTRL;
break;
case XK_Mode_switch:
case XK_Alt_L:
case XK_Meta_L:
case XK_Alt_R:
case XK_Meta_R:
key = K_ALT;
break;
case XK_Caps_Lock:
key = K_CAPSLOCK;
break;
case XK_KP_Begin:
key = KP_5;
break;
case XK_Insert:
key = K_INS;
break;
case XK_KP_Insert:
key = KP_INS;
break;
case XK_KP_Multiply:
key = KP_MULTIPLY;
break;
case XK_KP_Add:
key = KP_PLUS;
break;
case XK_KP_Subtract:
key = KP_MINUS;
break;
case XK_KP_Divide:
key = KP_DIVIDE;
break;
/* For Sun keyboards */
case XK_F27:
key = K_HOME;
break;
case XK_F29:
key = K_PGUP;
break;
case XK_F33:
key = K_END;
break;
case XK_F35:
key = K_PGDN;
break;
default:
if (keysym < 128) {
/* ASCII keys */
key = keysym;
if (!modified && ((key >= 'A') && (key <= 'Z'))) {
key = key + ('a' - 'A');
}
}
break;
}
return key;
}
static void
event_key (XEvent * event)
{
if (old_key_dest != key_dest) {
old_key_dest = key_dest;
if (key_dest == key_game) {
XAutoRepeatOff (x_disp);
} else {
XAutoRepeatOn (x_disp);
}
}
Key_Event (XLateKey (&event->xkey, 0), XLateKey (&event->xkey, 1),
event->type == KeyPress);
}
static void
event_button (XEvent * event)
{
int but;
but = event->xbutton.button;
if (but == 2)
but = 3;
else if (but == 3)
but = 2;
switch (but) {
case 1:
case 2:
case 3:
Key_Event (K_MOUSE1 + but - 1, 0, event->type == ButtonPress);
break;
case 4:
Key_Event (K_MWHEELUP, 0, event->type == ButtonPress);
break;
case 5:
Key_Event (K_MWHEELDOWN, 0, event->type == ButtonPress);
break;
}
}
static void
center_pointer (void)
{
XEvent event;
event.type = MotionNotify;
event.xmotion.display = x_disp;
event.xmotion.window = x_win;
event.xmotion.x = vid.width / 2;
event.xmotion.y = vid.height / 2;
XSendEvent (x_disp, x_win, False, PointerMotionMask, &event);
XWarpPointer (x_disp, None, x_win, 0, 0, 0, 0,
vid.width / 2, vid.height / 2);
}
static void
event_motion (XEvent * event)
{
if (dga_active) {
mouse_x += event->xmotion.x_root * in_dga_mouseaccel->value;
mouse_y += event->xmotion.y_root * in_dga_mouseaccel->value;
} else {
if (vid_fullscreen->int_val || _windowed_mouse->int_val) {
if (!event->xmotion.send_event) {
mouse_x += (event->xmotion.x - p_mouse_x);
mouse_y += (event->xmotion.y - p_mouse_y);
if (abs (vid.width / 2 - event->xmotion.x) > vid.width / 4
|| abs (vid.height / 2 - event->xmotion.y) > vid.height / 4) {
center_pointer ();
}
}
} else {
mouse_x += (event->xmotion.x - p_mouse_x);
mouse_y += (event->xmotion.y - p_mouse_y);
}
p_mouse_x = event->xmotion.x;
p_mouse_y = event->xmotion.y;
}
}
void
IN_Commands (void)
{
static int old_windowed_mouse;
static int old_in_dga;
JOY_Command ();
if ((old_windowed_mouse != _windowed_mouse->int_val)
|| (old_in_dga != in_dga->int_val)) {
old_windowed_mouse = _windowed_mouse->int_val;
old_in_dga = in_dga->int_val;
if (_windowed_mouse->int_val) { // grab the pointer
XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
#ifdef HAVE_DGA
if (dga_avail && in_dga->int_val && !dga_active) {
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp),
XF86DGADirectMouse);
dga_active = true;
}
#endif
} else { // ungrab the pointer
#ifdef HAVE_DGA
if (dga_avail && in_dga->int_val && dga_active) {
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
dga_active = false;
}
#endif
XUngrabPointer (x_disp, CurrentTime);
}
}
}
void
IN_SendKeyEvents (void)
{
/* Get events from X server. */
X11_ProcessEvents ();
}
void
IN_Move (void)
{
JOY_Move ();
if (!mouse_avail)
return;
if (m_filter->int_val) {
mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
}
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
viewdelta.position[0] += mouse_x;
else
viewdelta.angles[YAW] -= mouse_x;
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
mouse_x = mouse_y = 0.0;
}
/*
Called at shutdown
*/
void
IN_Shutdown (void)
{
JOY_Shutdown ();
Con_Printf ("IN_Shutdown\n");
mouse_avail = 0;
if (x_disp) {
XAutoRepeatOn (x_disp);
#ifdef HAVE_DGA
if (dga_avail)
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
#endif
}
X11_CloseDisplay ();
}
void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
void
IN_Init (void)
{
// open the display
if (!x_disp)
Sys_Error ("IN: No display!!\n");
if (!x_win)
Sys_Error ("IN: No window!!\n");
X11_OpenDisplay (); // call to increment the reference counter
{
int attribmask = CWEventMask;
XWindowAttributes attribs_1;
XSetWindowAttributes attribs_2;
XGetWindowAttributes (x_disp, x_win, &attribs_1);
attribs_2.event_mask = attribs_1.your_event_mask | INPUT_MASK;
XChangeWindowAttributes (x_disp, x_win, attribmask, &attribs_2);
}
JOY_Init ();
XAutoRepeatOff (x_disp);
if (COM_CheckParm ("-nomouse"))
return;
dga_avail = VID_CheckDGA (x_disp, NULL, NULL, NULL);
if (vid_fullscreen->int_val) {
Cvar_Set (_windowed_mouse, "1");
_windowed_mouse->flags |= CVAR_ROM;
}
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
X11_AddEvent (KeyPress, &event_key);
X11_AddEvent (KeyRelease, &event_key);
X11_AddEvent (ButtonPress, &event_button);
X11_AddEvent (ButtonRelease, &event_button);
X11_AddEvent (MotionNotify, &event_motion);
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force view of player to center");
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
"With this set to 1, quake will grab the mouse from X");
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL,
"Toggle mouse input filtering.");
in_dga = Cvar_Get ("in_dga", "1", CVAR_ARCHIVE, NULL,
"DGA Input support");
in_dga_mouseaccel = Cvar_Get ("in_dga_mouseaccel", "1", CVAR_ARCHIVE, NULL,
"DGA Mouse accelleration multiplier");
}