hurd_kbd.c revision ee3138f1
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/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/hurd/hurd_io.c,v 1.8 2002/10/11 01:40:35 dawes Exp $ */
24
25#define NEED_EVENTS
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
30#include <X11/X.h>
31
32#include "compiler.h"
33
34#include "xf86.h"
35#include "xf86Priv.h"
36#include "xf86_OSlib.h"
37
38#include "xf86Xinput.h"
39#include "xf86OSKbd.h"
40#include "atKeynames.h"
41#include "xf86Keymap.h"
42
43#include <stdio.h>
44#include <errno.h>
45#include <sys/time.h>
46#include <sys/file.h>
47#include <assert.h>
48#include <mach.h>
49#include <sys/ioctl.h>
50
51typedef unsigned short kev_type;		/* kd event type */
52typedef unsigned char Scancode;
53
54struct mouse_motion {
55    short mm_deltaX;		/* units? */
56    short mm_deltaY;
57};
58
59typedef struct {
60    kev_type type;			/* see below */
61    struct timeval time;		/* timestamp */
62    union {				/* value associated with event */
63	boolean_t up;		/* MOUSE_LEFT .. MOUSE_RIGHT */
64	Scancode sc;		/* KEYBD_EVENT */
65	struct mouse_motion mmotion;	/* MOUSE_MOTION */
66    } value;
67} kd_event;
68
69/*
70 * kd_event ID's.
71 */
72#define MOUSE_LEFT	1		/* mouse left button up/down */
73#define MOUSE_MIDDLE	2
74#define MOUSE_RIGHT	3
75#define MOUSE_MOTION	4		/* mouse motion */
76#define KEYBD_EVENT	5		/* key up/down */
77
78/***********************************************************************
79 * Keyboard
80 **********************************************************************/
81static void
82SoundKbdBell(InputInfoPtr pInfo, int loudness,int pitch,int duration)
83{
84    return;
85}
86
87static void
88SetKbdLeds(InputInfoPtr pInfo, int leds)
89{
90    return;
91}
92
93static int
94GetKbdLeds(InputInfoPtr pInfo)
95{
96    return 0;
97}
98
99static void
100SetKbdRepeat(InputInfoPtr pInfo, char rad)
101{
102    return;
103}
104
105static void
106KbdGetMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap)
107{
108    pKeySyms->map        = map;
109    pKeySyms->mapWidth   = GLYPHS_PER_KEY;
110    pKeySyms->minKeyCode = MIN_KEYCODE;
111    pKeySyms->maxKeyCode = MAX_KEYCODE;
112    return;
113}
114
115static int
116KbdOn(InputInfoPtr pInfo, int what)
117{
118    int data = 1;
119    if( ioctl( pInfo->fd, _IOW('k', 1, int),&data) < 0)
120	FatalError("Cannot set event mode on keyboard (%s)\n",strerror(errno));
121    return Success;
122}
123static int
124KbdOff(InputInfoPtr pInfo, int what)
125{
126    int data = 2;
127    if( ioctl( pInfo->fd, _IOW('k', 1, int),&data) < 0)
128	FatalError("can't reset keyboard mode (%s)\n",strerror(errno));
129    return Success;
130}
131
132static int
133KbdInit(InputInfoPtr pInfo, int what)
134{
135    return Success;
136}
137
138static void
139ReadInput(InputInfoPtr pInfo)
140{
141    KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
142    kd_event ke;
143    while( read(pInfo->fd, &ke, sizeof(ke)) == sizeof(ke) )
144	pKbd->PostEvent(pInfo, ke.value.sc & 0x7f, ke.value.sc & 0x80 ? FALSE : TRUE);
145}
146
147static Bool
148OpenKeyboard(InputInfoPtr pInfo)
149{
150    pInfo->fd = xf86Info.consoleFd;
151    return TRUE;
152}
153
154Bool
155xf86OSKbdPreInit(InputInfoPtr pInfo)
156{
157    KbdDevPtr pKbd = pInfo->private;
158
159    pKbd->KbdInit       = KbdInit;
160    pKbd->KbdOn         = KbdOn;
161    pKbd->KbdOff        = KbdOff;
162    pKbd->Bell          = SoundKbdBell;
163    pKbd->SetLeds       = SetKbdLeds;
164    pKbd->GetLeds       = GetKbdLeds;
165    pKbd->SetKbdRepeat  = SetKbdRepeat;
166    pKbd->KbdGetMapping = KbdGetMapping;
167    pKbd->SpecialKey    = NULL;
168    pKbd->RemapScanCode = ATScancode;
169    pKbd->GetSpecialKey = NULL;
170    pKbd->OpenKeyboard  = OpenKeyboard;
171    pKbd->vtSwitchSupported = FALSE;
172    pKbd->CustomKeycodes = FALSE;
173    pKbd->private       = NULL;
174    pInfo->read_input   = ReadInput;
175    return TRUE;
176}
177