summaryrefslogtreecommitdiff
path: root/source/in_evdev.c
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2008-05-05 21:18:52 +0000
committerAndrey Nazarov <skuller@skuller.net>2008-05-05 21:18:52 +0000
commit0bd55fbf794d11385bcc64b01b81e8e478295bad (patch)
treeab548c3ad37fc13c555a5cca9da4348f3e35d84c /source/in_evdev.c
parent49e6170b49fbb933eddec6d0e3f946320c68832f (diff)
Brought SDL window resizing policy in compliance to ICCCM.
Renamed `vid_placement' cvar to `vid_geometry'. Load *.pkz files by default. Do not allow backed-up quake paths at all. Apply `--enable-dsound' and `--enable-dinput' options to Unix too. Replaced `s_driver' and `in_driver' cvars with `s_direct' and `in_direct'. Renamed `s_initsound' cva to `s_enable'. Improved SDL input grabs handling in windowed mode. Allow `cl_noskins' to be dynamically changed. Run client at 10 fps if minimuzed, at 60 fps if not active (client is disconnected or in background). Fixed Sys_ExecDefault. Use absolute mouse positioning for UI. Hide custom UI cursor in windowed mode.
Diffstat (limited to 'source/in_evdev.c')
-rw-r--r--source/in_evdev.c102
1 files changed, 47 insertions, 55 deletions
diff --git a/source/in_evdev.c b/source/in_evdev.c
index 932b3fa..8eb1c1d 100644
--- a/source/in_evdev.c
+++ b/source/in_evdev.c
@@ -34,19 +34,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static cvar_t *in_device;
-static qboolean mouseinitialized;
-static qboolean mouseactive;
-static int evdev_fd;
+static struct {
+ qboolean initialized;
+ qboolean grabbed;
+ int fd;
+ int dx, dy;
+} evdev;
#define MAX_EVENTS 64
#define EVENT_SIZE sizeof( struct input_event )
/*
===========
-Evdev_SendMouseMoveEvents
+Evdev_RunMouse
===========
*/
-static void Evdev_SendMouseMoveEvents( void ) {
+static void Evdev_RunMouse( void ) {
struct input_event ev[MAX_EVENTS];
fd_set fdset;
struct timeval timeout;
@@ -55,27 +58,23 @@ static void Evdev_SendMouseMoveEvents( void ) {
int i, button;
unsigned time;
- if( !mouseinitialized ) {
- return;
- }
-
- if( !mouseactive ) {
+ if( !evdev.initialized || !evdev.grabbed ) {
return;
}
FD_ZERO( &fdset );
- FD_SET( evdev_fd, &fdset );
+ FD_SET( evdev.fd, &fdset );
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if( select( FD_SETSIZE, &fdset, NULL, NULL, &timeout ) == -1 ) {
return;
}
- if( !FD_ISSET( evdev_fd, &fdset ) ) {
+ if( !FD_ISSET( evdev.fd, &fdset ) ) {
return;
}
- bytes = read( evdev_fd, ev, EVENT_SIZE * MAX_EVENTS );
+ bytes = read( evdev.fd, ev, EVENT_SIZE * MAX_EVENTS );
if( bytes < EVENT_SIZE ) {
return;
}
@@ -98,10 +97,10 @@ static void Evdev_SendMouseMoveEvents( void ) {
case EV_REL:
switch( ev[i].code ) {
case REL_X:
- dx += ( int )ev[i].value;
+ evdev.dx += ( int )ev[i].value;
break;
case REL_Y:
- dy += ( int )ev[i].value;
+ evdev.dy += ( int )ev[i].value;
break;
case REL_WHEEL:
if( ( int )ev[i].value == 1 ) {
@@ -119,12 +118,17 @@ static void Evdev_SendMouseMoveEvents( void ) {
break;
}
}
+}
-
- if( dx || dy ) {
- CL_MouseEvent( dx, dy );
- }
-
+static qboolean Evdev_GetMouseMotion( int *dx, int *dy ) {
+ if( !evdev.initialized || !evdev.grabbed ) {
+ return qfalse;
+ }
+ *dx = evdev.dx;
+ *dy = evdev.dy;
+ evdev.dx = 0;
+ evdev.dy = 0;
+ return qtrue;
}
/*
@@ -133,12 +137,11 @@ Evdev_ShutdownMouse
===========
*/
static void Evdev_ShutdownMouse( void ) {
- if( !mouseinitialized ) {
+ if( !evdev.initialized ) {
return;
}
- close( evdev_fd );
- mouseinitialized = qfalse;
- mouseactive = qfalse;
+ close( evdev.fd );
+ memset( &evdev, 0, sizeof( evdev ) );
}
/*
@@ -149,79 +152,68 @@ Evdev_StartupMouse
static qboolean Evdev_InitMouse( void ) {
in_device = Cvar_Get( "in_device", "/dev/input/event2", CVAR_LATCH );
- evdev_fd = open( in_device->string, O_RDONLY );
-
- if( evdev_fd == -1 ) {
+ evdev.fd = open( in_device->string, O_RDONLY );
+ if( evdev.fd == -1 ) {
Com_EPrintf( "Couldn't open %s: %s\n", in_device->string,
- strerror( errno ) );
+ strerror( errno ) );
return qfalse;
}
- fcntl( evdev_fd, F_SETFL, fcntl( evdev_fd, F_GETFL, 0 ) | FNDELAY );
+ fcntl( evdev.fd, F_SETFL, fcntl( evdev.fd, F_GETFL, 0 ) | FNDELAY );
Com_Printf( "Event interface initialized.\n" );
- mouseinitialized = qtrue;
+ evdev.initialized = qtrue;
return qtrue;
}
/*
===========
-Evdev_ActivateMouse
-
-Called when the main window gains or loses focus.
-The window may have been destroyed and recreated
-between a deactivate and an activate.
+Evdev_GrabMouse
===========
*/
-static void Evdev_ActivateMouse( qboolean active ) {
- if( !mouseinitialized ) {
+static void Evdev_GrabMouse( grab_t grab ) {
+ if( !evdev.initialized ) {
return;
}
- if( mouseactive == active ) {
+ if( evdev.grabbed == grab ) {
return;
}
#ifdef EVIOCGRAB
- if( ioctl( evdev_fd, EVIOCGRAB, active ) == -1 ) {
+ if( ioctl( evdev.fd, EVIOCGRAB, active ) == -1 ) {
Com_EPrintf( "Grab/Release failed: %s\n", strerror( errno ) );
}
#endif // EVIOCGRAB
- if( active ) {
+ if( grab ) {
struct input_event ev;
SDL_ShowCursor( SDL_DISABLE );
- while( read( evdev_fd, &ev, EVENT_SIZE ) == EVENT_SIZE )
+ while( read( evdev.fd, &ev, EVENT_SIZE ) == EVENT_SIZE )
;
} else {
SDL_ShowCursor( SDL_ENABLE );
}
- mouseactive = active;
-}
-
-/*
-===================
-Evdev_ClearMouseStates
-===================
-*/
-static void Evdev_ClearMouseStates( void ) {
+ evdev.dx = 0;
+ evdev.dy = 0;
+ evdev.grabbed = grab;
}
/*
@@@@@@@@@@@@@@@@@@@
-Evdev_FillAPI
+DI_FillAPI
@@@@@@@@@@@@@@@@@@@
*/
-void Evdev_FillAPI( inputAPI_t *api ) {
+void DI_FillAPI( inputAPI_t *api ) {
api->Init = Evdev_InitMouse;
api->Shutdown = Evdev_ShutdownMouse;
- api->Activate = Evdev_ActivateMouse;
- api->Frame = Evdev_SendMouseMoveEvents;
- api->ClearStates = Evdev_ClearMouseStates;
+ api->Grab = Evdev_GrabMouse;
+ api->GetEvents = Evdev_GetMouseEvents;
+ api->GetMotion = Evdev_GetMouseMotion;
}