src/video/fbcon/SDL_fbevents.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 07 Jul 2011 11:50:30 -0700
branchSDL-1.2
changeset 5560 98ae43d3d2f4
parent 5559 9f181779cfdd
child 6137 4720145f848b
permissions -rw-r--r--
Minor whitespace cleanup.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
     2
    SDL - Simple DirectMedia Layer
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 1787
diff changeset
     3
    Copyright (C) 1997-2009 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
     5
    This library is free software; you can redistribute it and/or
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
     7
    License as published by the Free Software Foundation; either
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    10
    This library is distributed in the hope that it will be useful,
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    13
    Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    16
    License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    19
    Sam Lantinga
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    20
    slouken@libsdl.org
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1241
diff changeset
    21
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
    22
#include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
/* Handle the event stream, converting console events into SDL events */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
    26
#include <stdio.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
#include <sys/types.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
#include <sys/time.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
#include <sys/ioctl.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
#include <unistd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
#include <fcntl.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
#include <errno.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    33
#include <limits.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    34
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    35
/* For parsing /proc */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    36
#include <dirent.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    37
#include <ctype.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    38
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    39
#include <linux/vt.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    40
#include <linux/kd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    41
#include <linux/keyboard.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    42
1359
1e4ba2e063b4 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    43
#include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    44
#include "SDL_mutex.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
    45
#include "../SDL_sysvideo.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
    46
#include "../../events/SDL_sysevents.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
    47
#include "../../events/SDL_events_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    48
#include "SDL_fbvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    49
#include "SDL_fbevents_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    50
#include "SDL_fbkeys.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    51
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    52
#include "SDL_fbelo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    53
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    54
#ifndef GPM_NODE_FIFO
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    55
#define GPM_NODE_FIFO	"/dev/gpmdata"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    56
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    57
1778
e28233f37f8c Fixed detection of current vt when not running as root.
Sam Lantinga <slouken@libsdl.org>
parents: 1776
diff changeset
    58
/*#define DEBUG_KEYBOARD*/
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
    59
/*#define DEBUG_MOUSE*/
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    60
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    61
/* The translation tables from a console scancode to a SDL keysym */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    62
#define NUM_VGAKEYMAPS	(1<<KG_CAPSSHIFT)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    63
static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    64
static SDLKey keymap[128];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    65
static Uint16 keymap_temp[128]; /* only used at startup */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    66
static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    67
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    68
/* Ugh, we have to duplicate the kernel's keysym mapping code...
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    69
   Oh, it's not so bad. :-)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    70
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    71
   FIXME: Add keyboard LED handling code
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    72
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    73
static void FB_vgainitkeymaps(int fd)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    74
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    75
	struct kbentry entry;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    76
	int map, i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    77
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    78
	/* Don't do anything if we are passed a closed keyboard */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    79
	if ( fd < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    80
		return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    81
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    82
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    83
	/* Load all the keysym mappings */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    84
	for ( map=0; map<NUM_VGAKEYMAPS; ++map ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1323
diff changeset
    85
		SDL_memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    86
		for ( i=0; i<NR_KEYS; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    87
			entry.kb_table = map;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    88
			entry.kb_index = i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    89
			if ( ioctl(fd, KDGKBENT, &entry) == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    90
				/* fill keytemp. This replaces SDL_fbkeys.h */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    91
				if ( (map == 0) && (i<128) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    92
					keymap_temp[i] = entry.kb_value;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    93
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    94
				/* The "Enter" key is a special case */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    95
				if ( entry.kb_value == K_ENTER ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    96
					entry.kb_value = K(KT_ASCII,13);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    97
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    98
				/* Handle numpad specially as well */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    99
				if ( KTYP(entry.kb_value) == KT_PAD ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   100
					switch ( entry.kb_value ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   101
					case K_P0:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   102
					case K_P1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   103
					case K_P2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   104
					case K_P3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   105
					case K_P4:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   106
					case K_P5:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   107
					case K_P6:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   108
					case K_P7:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   109
					case K_P8:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   110
					case K_P9:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   111
						vga_keymap[map][i]=entry.kb_value;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   112
						vga_keymap[map][i]+= '0';
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   113
						break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   114
										case K_PPLUS:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   115
						vga_keymap[map][i]=K(KT_ASCII,'+');
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   116
						break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   117
										case K_PMINUS:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   118
						vga_keymap[map][i]=K(KT_ASCII,'-');
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   119
						break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   120
										case K_PSTAR:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   121
						vga_keymap[map][i]=K(KT_ASCII,'*');
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   122
						break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   123
										case K_PSLASH:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   124
						vga_keymap[map][i]=K(KT_ASCII,'/');
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   125
						break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   126
										case K_PENTER:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   127
						vga_keymap[map][i]=K(KT_ASCII,'\r');
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   128
						break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   129
										case K_PCOMMA:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   130
						vga_keymap[map][i]=K(KT_ASCII,',');
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   131
						break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   132
										case K_PDOT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   133
						vga_keymap[map][i]=K(KT_ASCII,'.');
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   134
						break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   135
					default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   136
						break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   137
					}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   138
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   139
				/* Do the normal key translation */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   140
				if ( (KTYP(entry.kb_value) == KT_LATIN) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   141
					 (KTYP(entry.kb_value) == KT_ASCII) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   142
					 (KTYP(entry.kb_value) == KT_LETTER) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   143
					vga_keymap[map][i] = entry.kb_value;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   144
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   145
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   146
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   147
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   148
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   149
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   150
int FB_InGraphicsMode(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   151
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   152
	return((keyboard_fd >= 0) && (saved_kbd_mode >= 0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   153
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   154
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   155
int FB_EnterGraphicsMode(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   156
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
	struct termios keyboard_termios;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   158
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   159
	/* Set medium-raw keyboard mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   160
	if ( (keyboard_fd >= 0) && !FB_InGraphicsMode(this) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   161
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   162
		/* Switch to the correct virtual terminal */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   163
		if ( current_vt > 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   164
			struct vt_stat vtstate;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   165
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   166
			if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
				saved_vt = vtstate.v_active;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   168
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   169
			if ( ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   170
				ioctl(keyboard_fd, VT_WAITACTIVE, current_vt);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   171
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   172
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   173
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   174
		/* Set the terminal input mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   175
		if ( tcgetattr(keyboard_fd, &saved_kbd_termios) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   176
			SDL_SetError("Unable to get terminal attributes");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   177
			if ( keyboard_fd > 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   178
				close(keyboard_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   179
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   180
			keyboard_fd = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   181
			return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   182
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   183
		if ( ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   184
			SDL_SetError("Unable to get current keyboard mode");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   185
			if ( keyboard_fd > 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   186
				close(keyboard_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   187
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   188
			keyboard_fd = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   189
			return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   190
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   191
		keyboard_termios = saved_kbd_termios;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   192
		keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   193
		keyboard_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   194
		keyboard_termios.c_cc[VMIN] = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   195
		keyboard_termios.c_cc[VTIME] = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   196
		if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   197
			FB_CloseKeyboard(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   198
			SDL_SetError("Unable to set terminal attributes");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   199
			return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   200
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   201
		/* This will fail if we aren't root or this isn't our tty */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   202
		if ( ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   203
			FB_CloseKeyboard(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   204
			SDL_SetError("Unable to set keyboard in raw mode");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   205
			return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   206
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   207
		if ( ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   208
			FB_CloseKeyboard(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   209
			SDL_SetError("Unable to set keyboard in graphics mode");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   210
			return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   211
		}
1780
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   212
		/* Prevent switching the virtual terminal */
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   213
		ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   214
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   215
	return(keyboard_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   216
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   217
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   218
void FB_LeaveGraphicsMode(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   219
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   220
	if ( FB_InGraphicsMode(this) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   221
		ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   222
		ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   223
		tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   224
		saved_kbd_mode = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   225
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   226
		/* Head back over to the original virtual terminal */
1780
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   227
		ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   228
		if ( saved_vt > 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   229
			ioctl(keyboard_fd, VT_ACTIVATE, saved_vt);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   230
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   231
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   232
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   233
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   234
void FB_CloseKeyboard(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   235
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   236
	if ( keyboard_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   237
		FB_LeaveGraphicsMode(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   238
		if ( keyboard_fd > 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   239
			close(keyboard_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   240
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   241
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   242
	keyboard_fd = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   243
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   244
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   245
int FB_OpenKeyboard(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   246
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   247
	/* Open only if not already opened */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   248
 	if ( keyboard_fd < 0 ) {
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 69
diff changeset
   249
		static const char * const tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 69
diff changeset
   250
		static const char * const vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   251
		int i, tty0_fd;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   252
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   253
		/* Try to query for a free virtual terminal */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   254
		tty0_fd = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   255
		for ( i=0; tty0[i] && (tty0_fd < 0); ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   256
			tty0_fd = open(tty0[i], O_WRONLY, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   257
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   258
		if ( tty0_fd < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   259
			tty0_fd = dup(0); /* Maybe stdin is a VT? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   260
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   261
		ioctl(tty0_fd, VT_OPENQRY, &current_vt);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   262
		close(tty0_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   263
		if ( (geteuid() == 0) && (current_vt > 0) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   264
			for ( i=0; vcs[i] && (keyboard_fd < 0); ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   265
				char vtpath[12];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   266
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
   267
				SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], current_vt);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   268
				keyboard_fd = open(vtpath, O_RDWR, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   269
#ifdef DEBUG_KEYBOARD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   270
				fprintf(stderr, "vtpath = %s, fd = %d\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   271
					vtpath, keyboard_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   272
#endif /* DEBUG_KEYBOARD */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   273
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   274
				/* This needs to be our controlling tty
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   275
				   so that the kernel ioctl() calls work
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   276
				*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   277
				if ( keyboard_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   278
					tty0_fd = open("/dev/tty", O_RDWR, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   279
					if ( tty0_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   280
						ioctl(tty0_fd, TIOCNOTTY, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   281
						close(tty0_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   282
					}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   283
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   284
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   285
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   286
 		if ( keyboard_fd < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   287
			/* Last resort, maybe our tty is a usable VT */
1778
e28233f37f8c Fixed detection of current vt when not running as root.
Sam Lantinga <slouken@libsdl.org>
parents: 1776
diff changeset
   288
			struct vt_stat vtstate;
e28233f37f8c Fixed detection of current vt when not running as root.
Sam Lantinga <slouken@libsdl.org>
parents: 1776
diff changeset
   289
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   290
			keyboard_fd = open("/dev/tty", O_RDWR);
1778
e28233f37f8c Fixed detection of current vt when not running as root.
Sam Lantinga <slouken@libsdl.org>
parents: 1776
diff changeset
   291
e28233f37f8c Fixed detection of current vt when not running as root.
Sam Lantinga <slouken@libsdl.org>
parents: 1776
diff changeset
   292
			if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) {
e28233f37f8c Fixed detection of current vt when not running as root.
Sam Lantinga <slouken@libsdl.org>
parents: 1776
diff changeset
   293
				current_vt = vtstate.v_active;
e28233f37f8c Fixed detection of current vt when not running as root.
Sam Lantinga <slouken@libsdl.org>
parents: 1776
diff changeset
   294
			} else {
e28233f37f8c Fixed detection of current vt when not running as root.
Sam Lantinga <slouken@libsdl.org>
parents: 1776
diff changeset
   295
				current_vt = 0;
e28233f37f8c Fixed detection of current vt when not running as root.
Sam Lantinga <slouken@libsdl.org>
parents: 1776
diff changeset
   296
			}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   297
 		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   298
#ifdef DEBUG_KEYBOARD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   299
		fprintf(stderr, "Current VT: %d\n", current_vt);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   300
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   301
 		saved_kbd_mode = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   302
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   303
		/* Make sure that our input is a console terminal */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   304
		{ int dummy;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   305
		  if ( ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   306
			close(keyboard_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   307
			keyboard_fd = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   308
			SDL_SetError("Unable to open a console terminal");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   309
		  }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   310
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   311
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   312
		/* Set up keymap */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   313
		FB_vgainitkeymaps(keyboard_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   314
 	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   315
 	return(keyboard_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   316
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   317
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   318
static enum {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   319
	MOUSE_NONE = -1,
109
5a9c36a45db1 Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents: 104
diff changeset
   320
	MOUSE_MSC,	/* Note: GPM uses the MSC protocol */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   321
	MOUSE_PS2,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   322
	MOUSE_IMPS2,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   323
	MOUSE_MS,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   324
	MOUSE_BM,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   325
	MOUSE_ELO,
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   326
	MOUSE_TSLIB,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   327
	NUM_MOUSE_DRVS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   328
} mouse_drv = MOUSE_NONE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   329
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   330
void FB_CloseMouse(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   331
{
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
   332
#if SDL_INPUT_TSLIB
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   333
	if (ts_dev != NULL) {
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   334
		ts_close(ts_dev);
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   335
		ts_dev = NULL;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   336
		mouse_fd = -1;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   337
	}
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
   338
#endif /* SDL_INPUT_TSLIB */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   339
	if ( mouse_fd > 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   340
		close(mouse_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   341
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   342
	mouse_fd = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   343
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   344
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   345
/* Returns processes listed in /proc with the desired name */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   346
static int find_pid(DIR *proc, const char *wanted_name)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   347
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   348
	struct dirent *entry;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   349
	int pid;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   350
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   351
	/* First scan proc for the gpm process */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   352
	pid = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   353
	while ( (pid == 0) && ((entry=readdir(proc)) != NULL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   354
		if ( isdigit(entry->d_name[0]) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   355
			FILE *status;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   356
			char path[PATH_MAX];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   357
			char name[PATH_MAX];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   358
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
   359
			SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", entry->d_name);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   360
			status=fopen(path, "r");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   361
			if ( status ) {
5559
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   362
				int matches = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   363
				name[0] = '\0';
5559
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   364
				matches = fscanf(status, "Name: %s", name);
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   365
				if ( (matches == 1) && (SDL_strcmp(name, wanted_name) == 0) ) {
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   366
					pid = SDL_atoi(entry->d_name);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   367
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   368
				fclose(status);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   369
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   370
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   371
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   372
	return pid;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   373
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   374
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   375
/* Returns true if /dev/gpmdata is being written to by gpm */
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   376
static int gpm_available(char *proto, size_t protolen)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   377
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   378
	int available;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   379
	DIR *proc;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   380
	int pid;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   381
	int cmdline, len, arglen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   382
	char path[PATH_MAX];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   383
	char args[PATH_MAX], *arg;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   384
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   385
	/* Don't bother looking if the fifo isn't there */
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   386
#ifdef DEBUG_MOUSE 
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   387
	fprintf(stderr,"testing gpm\n");
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   388
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   389
	if ( access(GPM_NODE_FIFO, F_OK) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   390
		return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   391
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   392
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   393
	available = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   394
	proc = opendir("/proc");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   395
	if ( proc ) {
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   396
		char raw_proto[10] = { '\0' };
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   397
		char repeat_proto[10] = { '\0' };
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   398
		while ( !available && (pid=find_pid(proc, "gpm")) > 0 ) {
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
   399
			SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   400
			cmdline = open(path, O_RDONLY, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   401
			if ( cmdline >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   402
				len = read(cmdline, args, sizeof(args));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   403
				arg = args;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   404
				while ( len > 0 ) {
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   405
					arglen = SDL_strlen(arg)+1;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   406
#ifdef DEBUG_MOUSE 
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   407
				        fprintf(stderr,"gpm arg %s len %d\n",arg,arglen);
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   408
#endif
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   409
					if ( SDL_strcmp(arg, "-t") == 0) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   410
						/* protocol string, keep it for later */
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   411
						char *t, *s;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   412
						t = arg + arglen;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   413
						s = SDL_strchr(t, ' ');
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   414
						if (s) *s = 0;
1776
ed39aa7383ea SDL_strncpy doesn't exist
Sam Lantinga <slouken@libsdl.org>
parents: 1772
diff changeset
   415
						SDL_strlcpy(raw_proto, t, SDL_arraysize(raw_proto));
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   416
						if (s) *s = ' ';
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   417
					}
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   418
					if ( SDL_strncmp(arg, "-R", 2) == 0 ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   419
						char *t, *s;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   420
						available = 1;
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   421
						t = arg + 2;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   422
						s = SDL_strchr(t, ' ');
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   423
						if (s) *s = 0;
1776
ed39aa7383ea SDL_strncpy doesn't exist
Sam Lantinga <slouken@libsdl.org>
parents: 1772
diff changeset
   424
						SDL_strlcpy(repeat_proto, t, SDL_arraysize(repeat_proto));
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   425
						if (s) *s = ' ';
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   426
					}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   427
					len -= arglen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   428
					arg += arglen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   429
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   430
				close(cmdline);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   431
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   432
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   433
		closedir(proc);
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   434
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   435
		if ( available ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   436
			if ( SDL_strcmp(repeat_proto, "raw") == 0 ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   437
				SDL_strlcpy(proto, raw_proto, protolen);
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   438
			} else if ( *repeat_proto ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   439
				SDL_strlcpy(proto, repeat_proto, protolen);
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   440
			} else {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   441
				SDL_strlcpy(proto, "msc", protolen);
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   442
			}
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   443
		}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   444
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   445
	return available;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   446
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   447
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   448
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   449
/* rcg06112001 Set up IMPS/2 mode, if possible. This gives
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   450
 *  us access to the mousewheel, etc. Returns zero if
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   451
 *  writes to device failed, but you still need to query the
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   452
 *  device to see which mode it's actually in.
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   453
 */
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   454
static int set_imps2_mode(int fd)
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   455
{
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   456
	/* If you wanted to control the mouse mode (and we do :)  ) ...
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   457
		Set IMPS/2 protocol:
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   458
			{0xf3,200,0xf3,100,0xf3,80}
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   459
		Reset mouse device:
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   460
			{0xFF}
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   461
	*/
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   462
	Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80};
1780
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   463
	/*Uint8 reset = 0xff;*/
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   464
	fd_set fdset;
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   465
	struct timeval tv;
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   466
	int retval = 0;
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   467
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   468
	if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) {
1584
b786d9c15e42 Fixed bug #61
Sam Lantinga <slouken@libsdl.org>
parents: 1582
diff changeset
   469
		/* Don't reset it, that'll clear IMPS/2 mode on some mice
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   470
		if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) {
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   471
			retval = 1;
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   472
		}
1584
b786d9c15e42 Fixed bug #61
Sam Lantinga <slouken@libsdl.org>
parents: 1582
diff changeset
   473
		*/
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   474
	}
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   475
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   476
	/* Get rid of any chatter from the above */
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   477
	FD_ZERO(&fdset);
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   478
	FD_SET(fd, &fdset);
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   479
	tv.tv_sec = 0;
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   480
	tv.tv_usec = 0;
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   481
	while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   482
		char temp[32];
5559
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   483
		if (read(fd, temp, sizeof(temp)) <= 0) {
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   484
			break;
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   485
		}
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   486
	}
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   487
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   488
	return retval;
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   489
}
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   490
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   491
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   492
/* Returns true if the mouse uses the IMPS/2 protocol */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   493
static int detect_imps2(int fd)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   494
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   495
	int imps2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   496
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   497
	imps2 = 0;
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   498
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1323
diff changeset
   499
	if ( SDL_getenv("SDL_MOUSEDEV_IMPS2") ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   500
		imps2 = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   501
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   502
	if ( ! imps2 ) {
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   503
		Uint8 query_ps2 = 0xF2;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   504
		fd_set fdset;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   505
		struct timeval tv;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   506
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   507
		/* Get rid of any mouse motion noise */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   508
		FD_ZERO(&fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   509
		FD_SET(fd, &fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   510
		tv.tv_sec = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   511
		tv.tv_usec = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   512
		while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   513
			char temp[32];
5559
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   514
			if (read(fd, temp, sizeof(temp)) <= 0) {
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   515
				break;
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   516
			}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   517
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   518
5560
98ae43d3d2f4 Minor whitespace cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 5559
diff changeset
   519
		/* Query for the type of mouse protocol */
98ae43d3d2f4 Minor whitespace cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 5559
diff changeset
   520
		if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) {
98ae43d3d2f4 Minor whitespace cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 5559
diff changeset
   521
			Uint8 ch = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   522
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   523
			/* Get the mouse protocol response */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   524
			do {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   525
				FD_ZERO(&fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   526
				FD_SET(fd, &fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   527
				tv.tv_sec = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   528
				tv.tv_usec = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   529
				if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   530
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   531
				}
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   532
			} while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) &&
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   533
			          ((ch == 0xFA) || (ch == 0xAA)) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   534
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   535
			/* Experimental values (Logitech wheelmouse) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   536
#ifdef DEBUG_MOUSE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   537
fprintf(stderr, "Last mouse mode: 0x%x\n", ch);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   538
#endif
104
a746656b7599 Detect more types of IMPS/2 mouse
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
   539
			if ( (ch == 3) || (ch == 4) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   540
				imps2 = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   541
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   542
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   543
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   544
	return imps2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   545
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   546
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   547
int FB_OpenMouse(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   548
{
69
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   549
	int i;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   550
	const char *mousedev;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   551
	const char *mousedrv;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   552
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1323
diff changeset
   553
	mousedrv = SDL_getenv("SDL_MOUSEDRV");
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1323
diff changeset
   554
	mousedev = SDL_getenv("SDL_MOUSEDEV");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   555
	mouse_fd = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   556
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
   557
#if SDL_INPUT_TSLIB
1585
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   558
	if ( mousedrv && (SDL_strcmp(mousedrv, "TSLIB") == 0) ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1323
diff changeset
   559
		if (mousedev == NULL) mousedev = SDL_getenv("TSLIB_TSDEVICE");
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   560
		if (mousedev != NULL) {
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   561
			ts_dev = ts_open(mousedev, 1);
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   562
			if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) {
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   563
#ifdef DEBUG_MOUSE
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   564
				fprintf(stderr, "Using tslib touchscreen\n");
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   565
#endif
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   566
				mouse_drv = MOUSE_TSLIB;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   567
				mouse_fd = ts_fd(ts_dev);
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   568
				return mouse_fd;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   569
			}
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   570
		}
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   571
		mouse_drv = MOUSE_NONE;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   572
		return mouse_fd;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   573
	}
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
   574
#endif /* SDL_INPUT_TSLIB */
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   575
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   576
	/* ELO TOUCHSCREEN SUPPORT */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   577
1585
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   578
	if ( mousedrv && (SDL_strcmp(mousedrv, "ELO") == 0) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   579
		mouse_fd = open(mousedev, O_RDWR);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   580
		if ( mouse_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   581
			if(eloInitController(mouse_fd)) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   582
#ifdef DEBUG_MOUSE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   583
fprintf(stderr, "Using ELO touchscreen\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   584
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   585
   				mouse_drv = MOUSE_ELO;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   586
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   587
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   588
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   589
		else if ( mouse_fd < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   590
			mouse_drv = MOUSE_NONE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   591
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   592
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   593
		return(mouse_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   594
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   595
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   596
	/* STD MICE */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   597
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   598
	if ( mousedev == NULL ) {
69
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   599
		/* FIXME someday... allow multiple mice in this driver */
1584
b786d9c15e42 Fixed bug #61
Sam Lantinga <slouken@libsdl.org>
parents: 1582
diff changeset
   600
		static const char *ps2mice[] = {
69
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   601
		    "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   602
		};
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   603
		/* First try to use GPM in repeater mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   604
		if ( mouse_fd < 0 ) {
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   605
			char proto[10];
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   606
			if ( gpm_available(proto, SDL_arraysize(proto)) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   607
				mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   608
				if ( mouse_fd >= 0 ) {
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   609
					if ( SDL_strcmp(proto, "msc") == 0 ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   610
						mouse_drv = MOUSE_MSC;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   611
					} else if ( SDL_strcmp(proto, "ps2") == 0 ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   612
						mouse_drv = MOUSE_PS2;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   613
					} else if ( SDL_strcmp(proto, "imps2") == 0 ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   614
						mouse_drv = MOUSE_IMPS2;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   615
					} else if ( SDL_strcmp(proto, "ms") == 0 ||
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   616
					            SDL_strcmp(proto, "bare") == 0 ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   617
						mouse_drv = MOUSE_MS;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   618
					} else if ( SDL_strcmp(proto, "bm") == 0 ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   619
						mouse_drv = MOUSE_BM;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   620
					} else {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   621
						/* Unknown protocol... */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   622
#ifdef DEBUG_MOUSE
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   623
						fprintf(stderr, "GPM mouse using unknown protocol = %s\n", proto);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   624
#endif
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   625
						close(mouse_fd);
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   626
						mouse_fd = -1;
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   627
					}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   628
				}
1772
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   629
#ifdef DEBUG_MOUSE
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   630
				if ( mouse_fd >= 0 ) {
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   631
					fprintf(stderr, "Using GPM mouse, protocol = %s\n", proto);
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   632
				}
5115185b6e3c Fixed bug #102
Sam Lantinga <slouken@libsdl.org>
parents: 1585
diff changeset
   633
#endif /* DEBUG_MOUSE */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   634
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   635
		}
69
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   636
		/* Now try to use a modern PS/2 mouse */
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   637
		for ( i=0; (mouse_fd < 0) && ps2mice[i]; ++i ) {
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   638
			mouse_fd = open(ps2mice[i], O_RDWR, 0);
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   639
			if (mouse_fd < 0) {
69
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   640
				mouse_fd = open(ps2mice[i], O_RDONLY, 0);
59
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   641
			}
b685c94f8db7 Ryan's IMPS/2 mouse fix
Sam Lantinga <slouken@lokigames.com>
parents: 4
diff changeset
   642
			if (mouse_fd >= 0) {
69
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   643
				/* rcg06112001 Attempt to set IMPS/2 mode */
1584
b786d9c15e42 Fixed bug #61
Sam Lantinga <slouken@libsdl.org>
parents: 1582
diff changeset
   644
				set_imps2_mode(mouse_fd);
69
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   645
				if (detect_imps2(mouse_fd)) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   646
#ifdef DEBUG_MOUSE
69
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   647
fprintf(stderr, "Using IMPS2 mouse\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   648
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   649
					mouse_drv = MOUSE_IMPS2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   650
				} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   651
#ifdef DEBUG_MOUSE
69
280ff3af2ecc Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents: 60
diff changeset
   652
fprintf(stderr, "Using PS2 mouse\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   653
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   654
					mouse_drv = MOUSE_PS2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   655
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   656
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   657
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   658
		/* Next try to use a PPC ADB port mouse */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   659
		if ( mouse_fd < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   660
			mouse_fd = open("/dev/adbmouse", O_RDONLY, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   661
			if ( mouse_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   662
#ifdef DEBUG_MOUSE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   663
fprintf(stderr, "Using ADB mouse\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   664
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   665
				mouse_drv = MOUSE_BM;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   666
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   667
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   668
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   669
	/* Default to a serial Microsoft mouse */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   670
	if ( mouse_fd < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   671
		if ( mousedev == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   672
			mousedev = "/dev/mouse";
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   673
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   674
		mouse_fd = open(mousedev, O_RDONLY, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   675
		if ( mouse_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   676
			struct termios mouse_termios;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   677
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   678
			/* Set the sampling speed to 1200 baud */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   679
			tcgetattr(mouse_fd, &mouse_termios);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   680
			mouse_termios.c_iflag = IGNBRK | IGNPAR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   681
			mouse_termios.c_oflag = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   682
			mouse_termios.c_lflag = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   683
			mouse_termios.c_line = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   684
			mouse_termios.c_cc[VTIME] = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   685
			mouse_termios.c_cc[VMIN] = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   686
			mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   687
			mouse_termios.c_cflag |= CS8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   688
			mouse_termios.c_cflag |= B1200;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   689
			tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios);
1585
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   690
			if ( mousedrv && (SDL_strcmp(mousedrv, "PS2") == 0) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   691
#ifdef DEBUG_MOUSE
1585
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   692
fprintf(stderr, "Using (user specified) PS2 mouse on %s\n", mousedev);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   693
#endif
1585
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   694
				mouse_drv = MOUSE_PS2;
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   695
			} else {
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   696
#ifdef DEBUG_MOUSE
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   697
fprintf(stderr, "Using (default) MS mouse on %s\n", mousedev);
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   698
#endif
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   699
				mouse_drv = MOUSE_MS;
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   700
			}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   701
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   702
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   703
	if ( mouse_fd < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   704
		mouse_drv = MOUSE_NONE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   705
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   706
	return(mouse_fd);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   707
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   708
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   709
static int posted = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   710
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   711
void FB_vgamousecallback(int button, int relative, int dx, int dy)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   712
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   713
	int button_1, button_3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   714
	int button_state;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   715
	int state_changed;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   716
	int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   717
	Uint8 state;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   718
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   719
	if ( dx || dy ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   720
		posted += SDL_PrivateMouseMotion(0, relative, dx, dy);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   721
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   722
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   723
	/* Swap button 1 and 3 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   724
	button_1 = (button & 0x04) >> 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   725
	button_3 = (button & 0x01) << 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   726
	button &= ~0x05;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   727
	button |= (button_1|button_3);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   728
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   729
	/* See what changed */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   730
	button_state = SDL_GetMouseState(NULL, NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   731
	state_changed = button_state ^ button;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   732
	for ( i=0; i<8; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   733
		if ( state_changed & (1<<i) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   734
			if ( button & (1<<i) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   735
				state = SDL_PRESSED;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   736
			} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   737
				state = SDL_RELEASED;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   738
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   739
			posted += SDL_PrivateMouseButton(state, i+1, 0, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   740
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   741
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   742
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   743
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   744
/* Handle input from tslib */
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
   745
#if SDL_INPUT_TSLIB
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   746
static void handle_tslib(_THIS)
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   747
{
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   748
	struct ts_sample sample;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   749
	int button;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   750
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   751
	while (ts_read(ts_dev, &sample, 1) > 0) {
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   752
		button = (sample.pressure > 0) ? 1 : 0;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   753
		button <<= 2;	/* must report it as button 3 */
1323
be736c197ceb Fixed compile warning
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   754
		FB_vgamousecallback(button, 0, sample.x, sample.y);
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   755
	}
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   756
	return;
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   757
}
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
   758
#endif /* SDL_INPUT_TSLIB */
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   759
109
5a9c36a45db1 Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents: 104
diff changeset
   760
/* For now, use MSC, PS/2, and MS protocols
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   761
   Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   762
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   763
static void handle_mouse(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   764
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   765
	static int start = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   766
	static unsigned char mousebuf[BUFSIZ];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   767
	static int relative = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   768
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   769
	int i, nread;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   770
	int button = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   771
	int dx = 0, dy = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   772
	int packetsize = 0;
4
4f6c5f021323 Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   773
	int realx, realy;
4f6c5f021323 Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   774
	
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   775
	/* Figure out the mouse packet size */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   776
	switch (mouse_drv) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   777
		case MOUSE_NONE:
5559
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   778
			break;  /* carry on to read from device and discard it. */
109
5a9c36a45db1 Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents: 104
diff changeset
   779
		case MOUSE_MSC:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   780
			packetsize = 5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   781
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   782
		case MOUSE_IMPS2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   783
			packetsize = 4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   784
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   785
		case MOUSE_PS2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   786
		case MOUSE_MS:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   787
		case MOUSE_BM:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   788
			packetsize = 3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   789
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   790
		case MOUSE_ELO:
1323
be736c197ceb Fixed compile warning
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   791
			/* try to read the next packet */
be736c197ceb Fixed compile warning
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   792
			if(eloReadPosition(this, mouse_fd, &dx, &dy, &button, &realx, &realy)) {
be736c197ceb Fixed compile warning
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   793
				button = (button & 0x01) << 2;
be736c197ceb Fixed compile warning
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   794
				FB_vgamousecallback(button, 0, dx, dy);
be736c197ceb Fixed compile warning
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   795
			}
be736c197ceb Fixed compile warning
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   796
			return; /* nothing left to do */
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   797
		case MOUSE_TSLIB:
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1359
diff changeset
   798
#if SDL_INPUT_TSLIB
1201
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   799
			handle_tslib(this);
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   800
#endif
718d00094f82 Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents: 1022
diff changeset
   801
			return; /* nothing left to do */
1323
be736c197ceb Fixed compile warning
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   802
		default:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   803
			/* Uh oh.. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   804
			packetsize = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   805
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   806
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   807
4
4f6c5f021323 Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   808
	/* Special handling for the quite sensitive ELO controller */
4f6c5f021323 Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   809
	if (mouse_drv == MOUSE_ELO) {
4f6c5f021323 Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   810
	
4f6c5f021323 Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   811
	}
4f6c5f021323 Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   812
	
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   813
	/* Read as many packets as possible */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   814
	nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   815
	if ( nread < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   816
		return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   817
	}
5559
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   818
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   819
	if (mouse_drv == MOUSE_NONE) {
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   820
		return;  /* we're done; just draining the input queue. */
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   821
	}
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   822
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   823
	nread += start;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   824
#ifdef DEBUG_MOUSE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   825
	fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   826
#endif
5559
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   827
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   828
	for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   829
		switch (mouse_drv) {
5559
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   830
			case MOUSE_NONE: /* shouldn't actually hit this. */
9f181779cfdd Cleaned up compiler warnings about unchecked return values.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   831
				break;  /* just throw everything away. */
109
5a9c36a45db1 Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents: 104
diff changeset
   832
			case MOUSE_MSC:
5a9c36a45db1 Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents: 104
diff changeset
   833
				/* MSC protocol has 0x80 in high byte */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   834
				if ( (mousebuf[i] & 0xF8) != 0x80 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   835
					/* Go to next byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   836
					i -= (packetsize-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   837
					continue;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   838
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   839
				/* Get current mouse state */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   840
				button = (~mousebuf[i]) & 0x07;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   841
				dx =   (signed char)(mousebuf[i+1]) +
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   842
				       (signed char)(mousebuf[i+3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   843
				dy = -((signed char)(mousebuf[i+2]) +
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   844
				       (signed char)(mousebuf[i+4]));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   845
				break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   846
			case MOUSE_PS2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   847
				/* PS/2 protocol has nothing in high byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   848
				if ( (mousebuf[i] & 0xC0) != 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   849
					/* Go to next byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   850
					i -= (packetsize-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   851
					continue;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   852
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   853
				/* Get current mouse state */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   854
				button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   855
		  			 (mousebuf[i] & 0x02) >> 1 | /*Right*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   856
		  			 (mousebuf[i] & 0x01) << 2;  /*Left*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   857
		  		dx = (mousebuf[i] & 0x10) ?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   858
		  		      mousebuf[i+1] - 256 : mousebuf[i+1];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   859
		  		dy = (mousebuf[i] & 0x20) ?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   860
		  		      -(mousebuf[i+2] - 256) : -mousebuf[i+2];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   861
				break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   862
			case MOUSE_IMPS2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   863
				/* Get current mouse state */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   864
				button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   865
		  			 (mousebuf[i] & 0x02) >> 1 | /*Right*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   866
		  			 (mousebuf[i] & 0x01) << 2 | /*Left*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   867
		  			 (mousebuf[i] & 0x40) >> 3 | /* 4 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   868
		  			 (mousebuf[i] & 0x80) >> 3;  /* 5 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   869
		  		dx = (mousebuf[i] & 0x10) ?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   870
		  		      mousebuf[i+1] - 256 : mousebuf[i+1];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   871
		  		dy = (mousebuf[i] & 0x20) ?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   872
		  		      -(mousebuf[i+2] - 256) : -mousebuf[i+2];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   873
				switch (mousebuf[i+3]&0x0F) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   874
				    case 0x0E: /* DX = +1 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   875
				    case 0x02: /* DX = -1 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   876
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   877
				    case 0x0F: /* DY = +1 (map button 4) */
132
2604a7be65af Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents: 109
diff changeset
   878
                                       FB_vgamousecallback(button | (1<<3),
2604a7be65af Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents: 109
diff changeset
   879
                                                           1, 0, 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   880
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   881
				    case 0x01: /* DY = -1 (map button 5) */
132
2604a7be65af Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents: 109
diff changeset
   882
                                       FB_vgamousecallback(button | (1<<4),
2604a7be65af Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents: 109
diff changeset
   883
                                                           1, 0, 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   884
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   885
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   886
				break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   887
			case MOUSE_MS:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   888
				/* Microsoft protocol has 0x40 in high byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   889
				if ( (mousebuf[i] & 0x40) != 0x40 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   890
					/* Go to next byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   891
					i -= (packetsize-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   892
					continue;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   893
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   894
				/* Get current mouse state */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   895
				button = ((mousebuf[i] & 0x20) >> 3) |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   896
				         ((mousebuf[i] & 0x10) >> 4);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   897
				dx = (signed char)(((mousebuf[i] & 0x03) << 6) |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   898
				                   (mousebuf[i + 1] & 0x3F));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   899
				dy = (signed char)(((mousebuf[i] & 0x0C) << 4) |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   900
				                    (mousebuf[i + 2] & 0x3F));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   901
				break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   902
			case MOUSE_BM:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   903
				/* BusMouse protocol has 0xF8 in high byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   904
				if ( (mousebuf[i] & 0xF8) != 0x80 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   905
					/* Go to next byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   906
					i -= (packetsize-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   907
					continue;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   908
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   909
				/* Get current mouse state */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   910
				button = (~mousebuf[i]) & 0x07;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   911
				dx =  (signed char)mousebuf[i+1];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   912
				dy = -(signed char)mousebuf[i+2];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   913
				break;
1323
be736c197ceb Fixed compile warning
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   914
			default:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   915
				/* Uh oh.. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   916
				dx = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   917
				dy = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   918
				break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   919
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   920
		FB_vgamousecallback(button, relative, dx, dy);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   921
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   922
	if ( i < nread ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1323
diff changeset
   923
		SDL_memcpy(mousebuf, &mousebuf[i], (nread-i));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   924
		start = (nread-i);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   925
	} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   926
		start = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   927
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   928
	return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   929
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   930
1780
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   931
/* Handle switching to another VC, returns when our VC is back */
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   932
static void switch_vt_prep(_THIS)
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   933
{
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   934
	SDL_Surface *screen = SDL_VideoSurface;
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   935
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   936
	SDL_PrivateAppActive(0, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   937
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   938
	/* Save the contents of the screen, and go to text mode */
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   939
	wait_idle(this);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   940
	screen_arealen = ((screen->h + (2*this->offset_y)) * screen->pitch);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   941
	screen_contents = (Uint8 *)SDL_malloc(screen_arealen);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   942
	if ( screen_contents ) {
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   943
		SDL_memcpy(screen_contents, screen->pixels, screen_arealen);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   944
	}
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   945
	FB_SavePaletteTo(this, 256, screen_palette);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   946
	ioctl(console_fd, FBIOGET_VSCREENINFO, &screen_vinfo);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   947
	ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   948
	ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   949
}
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   950
static void switch_vt_done(_THIS)
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   951
{
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   952
	SDL_Surface *screen = SDL_VideoSurface;
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   953
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   954
	/* Restore graphics mode and the contents of the screen */
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   955
	ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   956
	ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   957
	ioctl(console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   958
	FB_RestorePaletteFrom(this, 256, screen_palette);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   959
	if ( screen_contents ) {
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   960
		SDL_memcpy(screen->pixels, screen_contents, screen_arealen);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   961
		SDL_free(screen_contents);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   962
		screen_contents = NULL;
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   963
	}
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   964
1781
d8030f368b84 Get updates to the shadow surface while switched away
Sam Lantinga <slouken@libsdl.org>
parents: 1780
diff changeset
   965
	/* Get updates to the shadow surface while switched away */
d8030f368b84 Get updates to the shadow surface while switched away
Sam Lantinga <slouken@libsdl.org>
parents: 1780
diff changeset
   966
	if ( SDL_ShadowSurface ) {
d8030f368b84 Get updates to the shadow surface while switched away
Sam Lantinga <slouken@libsdl.org>
parents: 1780
diff changeset
   967
		SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
d8030f368b84 Get updates to the shadow surface while switched away
Sam Lantinga <slouken@libsdl.org>
parents: 1780
diff changeset
   968
	}
d8030f368b84 Get updates to the shadow surface while switched away
Sam Lantinga <slouken@libsdl.org>
parents: 1780
diff changeset
   969
1780
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   970
	SDL_PrivateAppActive(1, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   971
}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   972
static void switch_vt(_THIS, unsigned short which)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   973
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   974
	struct vt_stat vtstate;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   975
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   976
	/* Figure out whether or not we're switching to a new console */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   977
	if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   978
	     (which == vtstate.v_active) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   979
		return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   980
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   981
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   982
	/* New console, switch to it */
1780
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   983
	SDL_mutexP(hw_lock);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   984
	switch_vt_prep(this);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   985
	if ( ioctl(keyboard_fd, VT_ACTIVATE, which) == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   986
		ioctl(keyboard_fd, VT_WAITACTIVE, which);
1780
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   987
		switched_away = 1;
1585
980d2a0dc2a3 Date: Tue, 4 Mar 2003 15:05:31 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 1584
diff changeset
   988
	} else {
1780
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
   989
		switch_vt_done(this);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   990
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   991
	SDL_mutexV(hw_lock);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   992
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   993
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   994
static void handle_keyboard(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   995
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   996
	unsigned char keybuf[BUFSIZ];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   997
	int i, nread;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   998
	int pressed;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   999
	int scancode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1000
	SDL_keysym keysym;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1001
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1002
	nread = read(keyboard_fd, keybuf, BUFSIZ);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1003
	for ( i=0; i<nread; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1004
		scancode = keybuf[i] & 0x7F;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1005
		if ( keybuf[i] & 0x80 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1006
			pressed = SDL_RELEASED;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1007
		} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1008
			pressed = SDL_PRESSED;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1009
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1010
		TranslateKey(scancode, &keysym);
1582
43a565749fbf Fixed bug #50
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
  1011
		/* Handle Ctrl-Alt-FN for vt switch */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1012
		switch (keysym.sym) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1013
		    case SDLK_F1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1014
		    case SDLK_F2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1015
		    case SDLK_F3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1016
		    case SDLK_F4:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1017
		    case SDLK_F5:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1018
		    case SDLK_F6:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1019
		    case SDLK_F7:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1020
		    case SDLK_F8:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1021
		    case SDLK_F9:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1022
		    case SDLK_F10:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1023
		    case SDLK_F11:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1024
		    case SDLK_F12:
1582
43a565749fbf Fixed bug #50
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
  1025
			if ( (SDL_GetModState() & KMOD_CTRL) &&
43a565749fbf Fixed bug #50
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
  1026
			     (SDL_GetModState() & KMOD_ALT) ) {
109
5a9c36a45db1 Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents: 104
diff changeset
  1027
				if ( pressed ) {
5a9c36a45db1 Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents: 104
diff changeset
  1028
					switch_vt(this, (keysym.sym-SDLK_F1)+1);
5a9c36a45db1 Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents: 104
diff changeset
  1029
				}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1030
				break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1031
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1032
			/* Fall through to normal processing */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1033
		    default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1034
			posted += SDL_PrivateKeyboard(pressed, &keysym);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1035
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1036
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1037
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1038
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1039
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1040
void FB_PumpEvents(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1041
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1042
	fd_set fdset;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1043
	int max_fd;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1044
	static struct timeval zero;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1045
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1046
	do {
1780
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1047
		if ( switched_away ) {
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1048
			struct vt_stat vtstate;
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1049
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1050
			SDL_mutexP(hw_lock);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1051
			if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) &&
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1052
			     vtstate.v_active == current_vt ) {
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1053
				switched_away = 0;
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1054
				switch_vt_done(this);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1055
			}
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1056
			SDL_mutexV(hw_lock);
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1057
		}
7a36f01acf71 Fixed bug #49
Sam Lantinga <slouken@libsdl.org>
parents: 1778
diff changeset
  1058
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1059
		posted = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1060
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1061
		FD_ZERO(&fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1062
		max_fd = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1063
		if ( keyboard_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1064
			FD_SET(keyboard_fd, &fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1065
			if ( max_fd < keyboard_fd ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1066
				max_fd = keyboard_fd;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1067
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1068
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1069
		if ( mouse_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1070
			FD_SET(mouse_fd, &fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1071
			if ( max_fd < mouse_fd ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1072
				max_fd = mouse_fd;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1073
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1074
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1075
		if ( select(max_fd+1, &fdset, NULL, NULL, &zero) > 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1076
			if ( keyboard_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1077
				if ( FD_ISSET(keyboard_fd, &fdset) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1078
					handle_keyboard(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1079
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1080
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1081
			if ( mouse_fd >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1082
				if ( FD_ISSET(mouse_fd, &fdset) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1083
					handle_mouse(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1084
				}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1085
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1086
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1087
	} while ( posted );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1088
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1089
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1090
void FB_InitOSKeymap(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1091
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1092
	int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1093
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1094
	/* Initialize the Linux key translation table */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1095
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1096
	/* First get the ascii keys and others not well handled */
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
  1097
	for (i=0; i<SDL_arraysize(keymap); ++i) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1098
	  switch(i) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1099
	  /* These aren't handled by the x86 kernel keymapping (?) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1100
	  case SCANCODE_PRINTSCREEN:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1101
	    keymap[i] = SDLK_PRINT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1102
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1103
	  case SCANCODE_BREAK:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1104
	    keymap[i] = SDLK_BREAK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1105
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1106
	  case SCANCODE_BREAK_ALTERNATIVE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1107
	    keymap[i] = SDLK_PAUSE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1108
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1109
	  case SCANCODE_LEFTSHIFT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1110
	    keymap[i] = SDLK_LSHIFT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1111
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1112
	  case SCANCODE_RIGHTSHIFT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1113
	    keymap[i] = SDLK_RSHIFT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1114
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1115
	  case SCANCODE_LEFTCONTROL:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1116
	    keymap[i] = SDLK_LCTRL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1117
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1118
	  case SCANCODE_RIGHTCONTROL:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1119
	    keymap[i] = SDLK_RCTRL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1120
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1121
	  case SCANCODE_RIGHTWIN:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1122
	    keymap[i] = SDLK_RSUPER;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1123
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1124
	  case SCANCODE_LEFTWIN:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1125
	    keymap[i] = SDLK_LSUPER;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1126
	    break;
1787
15ae67aa6b4b Fixed bug #201
Sam Lantinga <slouken@libsdl.org>
parents: 1781
diff changeset
  1127
	  case SCANCODE_LEFTALT:
15ae67aa6b4b Fixed bug #201
Sam Lantinga <slouken@libsdl.org>
parents: 1781
diff changeset
  1128
	    keymap[i] = SDLK_LALT;
15ae67aa6b4b Fixed bug #201
Sam Lantinga <slouken@libsdl.org>
parents: 1781
diff changeset
  1129
	    break;
15ae67aa6b4b Fixed bug #201
Sam Lantinga <slouken@libsdl.org>
parents: 1781
diff changeset
  1130
	  case SCANCODE_RIGHTALT:
15ae67aa6b4b Fixed bug #201
Sam Lantinga <slouken@libsdl.org>
parents: 1781
diff changeset
  1131
	    keymap[i] = SDLK_RALT;
15ae67aa6b4b Fixed bug #201
Sam Lantinga <slouken@libsdl.org>
parents: 1781
diff changeset
  1132
	    break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1133
	  case 127:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1134
	    keymap[i] = SDLK_MENU;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1135
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1136
	  /* this should take care of all standard ascii keys */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1137
	  default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1138
	    keymap[i] = KVAL(vga_keymap[0][i]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1139
	    break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1140
          }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1141
	}
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
  1142
	for (i=0; i<SDL_arraysize(keymap); ++i) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents: