hurd_kbd.c revision b425557e
1/*
2 * Copyright 1997,1998 by UCHIYAMA Yasushi
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of UCHIYAMA Yasushi not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission.  UCHIYAMA Yasushi makes no representations
11 * about the suitability of this software for any purpose.  It is provided
12 * "as is" without express or implied warranty.
13 *
14 * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <xorg-server.h>
29#include <X11/X.h>
30
31#include "compiler.h"
32
33#include "xf86.h"
34#include "xf86Priv.h"
35#include "xf86_OSlib.h"
36
37#include "xf86Xinput.h"
38#include "xf86OSKbd.h"
39#include "atKeynames.h"
40#include "xf86Keymap.h"
41
42#include <stdio.h>
43#include <errno.h>
44#include <sys/time.h>
45#include <sys/file.h>
46#include <assert.h>
47#include <mach.h>
48#include <sys/ioctl.h>
49
50typedef unsigned short kev_type;		/* kd event type */
51typedef unsigned char Scancode;
52
53struct mouse_motion {
54    short mm_deltaX;		/* units? */
55    short mm_deltaY;
56};
57
58typedef struct {
59    kev_type type;			/* see below */
60    struct timeval time;		/* timestamp */
61    union {				/* value associated with event */
62	boolean_t up;		/* MOUSE_LEFT .. MOUSE_RIGHT */
63	Scancode sc;		/* KEYBD_EVENT */
64	struct mouse_motion mmotion;	/* MOUSE_MOTION */
65    } value;
66} kd_event;
67
68/*
69 * kd_event ID's.
70 */
71#define MOUSE_LEFT	1		/* mouse left button up/down */
72#define MOUSE_MIDDLE	2
73#define MOUSE_RIGHT	3
74#define MOUSE_MOTION	4		/* mouse motion */
75#define KEYBD_EVENT	5		/* key up/down */
76
77/***********************************************************************
78 * Keyboard
79 **********************************************************************/
80static void
81SoundKbdBell(InputInfoPtr pInfo, int loudness,int pitch,int duration)
82{
83    return;
84}
85
86static void
87SetKbdLeds(InputInfoPtr pInfo, int leds)
88{
89    return;
90}
91
92static int
93GetKbdLeds(InputInfoPtr pInfo)
94{
95    return 0;
96}
97
98static void
99SetKbdRepeat(InputInfoPtr pInfo, char rad)
100{
101    return;
102}
103
104static void
105KbdGetMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap)
106{
107    pKeySyms->map        = map;
108    pKeySyms->mapWidth   = GLYPHS_PER_KEY;
109    pKeySyms->minKeyCode = MIN_KEYCODE;
110    pKeySyms->maxKeyCode = MAX_KEYCODE;
111    return;
112}
113
114static int
115KbdOn(InputInfoPtr pInfo, int what)
116{
117    int data = 1;
118    if( ioctl( pInfo->fd, _IOW('k', 1, int),&data) < 0)
119	FatalError("Cannot set event mode on keyboard (%s)\n",strerror(errno));
120    return Success;
121}
122static int
123KbdOff(InputInfoPtr pInfo, int what)
124{
125    int data = 2;
126    if( ioctl( pInfo->fd, _IOW('k', 1, int),&data) < 0)
127	FatalError("can't reset keyboard mode (%s)\n",strerror(errno));
128    return Success;
129}
130
131static int
132KbdInit(InputInfoPtr pInfo, int what)
133{
134    return Success;
135}
136
137static void
138ReadInput(InputInfoPtr pInfo)
139{
140    KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
141    kd_event ke;
142    while( read(pInfo->fd, &ke, sizeof(ke)) == sizeof(ke) )
143	pKbd->PostEvent(pInfo, ke.value.sc & 0x7f, ke.value.sc & 0x80 ? FALSE : TRUE);
144}
145
146static Bool
147OpenKeyboard(InputInfoPtr pInfo)
148{
149    pInfo->fd = xf86Info.consoleFd;
150    return TRUE;
151}
152
153Bool
154xf86OSKbdPreInit(InputInfoPtr pInfo)
155{
156    KbdDevPtr pKbd = pInfo->private;
157
158    pKbd->KbdInit       = KbdInit;
159    pKbd->KbdOn         = KbdOn;
160    pKbd->KbdOff        = KbdOff;
161    pKbd->Bell          = SoundKbdBell;
162    pKbd->SetLeds       = SetKbdLeds;
163    pKbd->GetLeds       = GetKbdLeds;
164    pKbd->SetKbdRepeat  = SetKbdRepeat;
165    pKbd->KbdGetMapping = KbdGetMapping;
166    pKbd->RemapScanCode = ATScancode;
167    pKbd->OpenKeyboard  = OpenKeyboard;
168    pKbd->vtSwitchSupported = FALSE;
169    pKbd->CustomKeycodes = FALSE;
170    pKbd->private       = NULL;
171    pInfo->read_input   = ReadInput;
172    return TRUE;
173}
174