2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
in_sun.c
|
|
|
|
|
|
|
|
@description@
|
|
|
|
|
|
|
|
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 <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// typedefs and defines
|
|
|
|
//
|
|
|
|
|
|
|
|
#define MOUSE_SCALE 4
|
|
|
|
|
|
|
|
//
|
|
|
|
// externs
|
|
|
|
//
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
extern Display *x_disp;
|
|
|
|
extern int x_screen, x_screen_width, x_screen_height;
|
|
|
|
extern int x_center_height, x_center_width;
|
|
|
|
extern int x_std_event_mask;
|
|
|
|
extern Window x_win, x_root_win;
|
|
|
|
extern qboolean x_fullscreen;
|
|
|
|
extern qboolean x_focus;
|
|
|
|
extern int global_dx, global_dy;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
//
|
|
|
|
// globals
|
|
|
|
//
|
|
|
|
|
2001-04-11 07:57:08 +00:00
|
|
|
cvar_t *m_filter;
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *_windowed_mouse;
|
|
|
|
int x_root, y_root;
|
|
|
|
int x_root_old, y_root_old;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
//
|
|
|
|
// locals
|
|
|
|
//
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int x_mouse_num, x_mouse_denom, x_mouse_thresh;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
static qboolean x_grabbed = false;
|
|
|
|
|
|
|
|
//
|
|
|
|
// IN_CenterMouse - center the mouse in the screen
|
|
|
|
//
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_CenterMouse (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
CheckMouseState ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!x_grabbed)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
XSelectInput (x_disp, x_win, x_std_event_mask & ~PointerMotionMask);
|
|
|
|
XWarpPointer (x_disp, None, x_root_win, 0, 0, 0, 0, x_center_width,
|
|
|
|
x_center_height);
|
|
|
|
XSelectInput (x_disp, x_win, x_std_event_mask);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check to see if we have grabbed the mouse or not and deal with it
|
|
|
|
// appropriately
|
|
|
|
//
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
CheckMouseState (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (x_focus && _windowed_mouse->int_val && !x_grabbed) {
|
|
|
|
x_grabbed = true;
|
2001-02-26 06:48:02 +00:00
|
|
|
printf ("fooling with mouse!\n");
|
|
|
|
if (XGetPointerControl
|
|
|
|
(x_disp, &x_mouse_num, &x_mouse_denom,
|
|
|
|
&x_mouse_thresh)) printf ("XGetPointerControl failed!\n");
|
|
|
|
// printf( "mouse %d/%d thresh %d\n", x_mouse_num, x_mouse_denom,
|
|
|
|
// x_mouse_thresh );
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// make input rawer
|
2001-02-26 06:48:02 +00:00
|
|
|
XAutoRepeatOff (x_disp);
|
|
|
|
XGrabKeyboard (x_disp, x_win, True, GrabModeAsync, GrabModeAsync,
|
|
|
|
CurrentTime);
|
|
|
|
XGrabPointer (x_disp, x_win, True,
|
|
|
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
|
|
|
|
GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// if (XChangePointerControl( x_disp, True, True, 1, MOUSE_SCALE, x_mouse_thresh ))
|
|
|
|
// printf( "XChangePointerControl failed!\n" );
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
IN_CenterMouse ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// safe initial values
|
|
|
|
x_root = x_root_old = vid.width >> 1;
|
|
|
|
y_root = y_root_old = vid.height >> 1;
|
|
|
|
} else if (x_grabbed && (!_windowed_mouse->int_val || !x_focus)) {
|
2001-02-26 06:48:02 +00:00
|
|
|
printf ("fooling with mouse!\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
x_grabbed = false;
|
|
|
|
// undo mouse warp
|
2001-02-26 06:48:02 +00:00
|
|
|
if (XChangePointerControl
|
|
|
|
(x_disp, True, True, x_mouse_num, x_mouse_denom, x_mouse_thresh))
|
|
|
|
printf ("XChangePointerControl failed!\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
XUngrabPointer (x_disp, CurrentTime);
|
|
|
|
XUngrabKeyboard (x_disp, CurrentTime);
|
|
|
|
XAutoRepeatOn (x_disp);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// IN_Init - setup mouse input
|
|
|
|
//
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!x_disp)
|
|
|
|
Sys_Error ("X display not open!\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-04-10 23:39:30 +00:00
|
|
|
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
|
|
|
|
"None");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// we really really want to clean these up...
|
2001-02-26 06:48:02 +00:00
|
|
|
atexit (IN_Shutdown);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// IN_Shutdown - clean up mouse settings (must be done from signal handler too!)
|
|
|
|
//
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!x_disp)
|
|
|
|
return;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// undo mouse warp
|
2001-02-26 06:48:02 +00:00
|
|
|
if (XChangePointerControl
|
|
|
|
(x_disp, True, True, x_mouse_num, x_mouse_denom,
|
|
|
|
x_mouse_thresh)) printf ("XChangePointerControl failed!\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
XUngrabPointer (x_disp, CurrentTime);
|
|
|
|
XUngrabKeyboard (x_disp, CurrentTime);
|
|
|
|
XAutoRepeatOn (x_disp);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// IN_Commands - process buttons
|
|
|
|
//
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_Commands (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
// done in X event handler
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// IN_Move - process mouse moves
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
2001-04-11 07:57:08 +00:00
|
|
|
IN_Move (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
static int last_dx, last_dy;
|
2001-02-19 21:15:25 +00:00
|
|
|
static long long last_movement;
|
2001-02-26 06:48:02 +00:00
|
|
|
long long now, gethrtime ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int dx, dy;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
CheckMouseState ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!x_grabbed)
|
2001-02-26 06:48:02 +00:00
|
|
|
return; // no mouse movement
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
now = gethrtime ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
dx = global_dx;
|
|
|
|
global_dx = 0;
|
|
|
|
|
|
|
|
dy = global_dy;
|
|
|
|
global_dy = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
// printf("GOT: dx %d dy %d\n", dx, dy);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
dx *= sensitivity->value;
|
|
|
|
dy *= sensitivity->value;
|
|
|
|
|
|
|
|
//
|
2001-02-26 06:48:02 +00:00
|
|
|
// implement low pass filter to smooth motion a bit
|
|
|
|
//
|
2001-02-19 21:15:25 +00:00
|
|
|
if (now - last_movement > 100000000) {
|
|
|
|
dx = .6 * dx;
|
|
|
|
dy = .6 * dy;
|
|
|
|
}
|
|
|
|
last_movement = now;
|
|
|
|
|
|
|
|
dx = .6 * dx + .4 * last_dx;
|
|
|
|
dy = .6 * dy + .4 * last_dy;
|
|
|
|
|
|
|
|
|
|
|
|
last_dx = dx;
|
|
|
|
last_dy = dy;
|
|
|
|
|
|
|
|
if (!dx && !dy) {
|
2001-02-26 06:48:02 +00:00
|
|
|
if (in_mlook.state & 1)
|
2001-02-19 21:15:25 +00:00
|
|
|
V_StopPitchDrift ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// add mouse X/Y movement to cmd
|
|
|
|
if ((in_strafe.state & 1) || (lookstrafe->int_val && (in_mlook.state & 1)))
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.position[0] += dx;
|
2001-02-26 06:48:02 +00:00
|
|
|
else
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.angles[YAW] -= dx;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.angles[PITCH] += dy;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-04-15 04:18:22 +00:00
|
|
|
if (in_strafe.state & 1)
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.position[1] -= dy;
|
2001-02-26 06:48:02 +00:00
|
|
|
else
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.position[2] -= dy;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
IN_HandlePause (qboolean pause)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|