Skip to content

Latest commit

 

History

History
1216 lines (1115 loc) · 31 KB

SDL_fbevents.c

File metadata and controls

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