summaryrefslogtreecommitdiff
path: root/hw/xfree86/os-support/solaris/sun_kbd.c
blob: 56929d69b265cd38ac4a06781ceae5372d990e10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
84
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
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.c,v 1.1 2001/05/28 02:42:31 tsi Exp $ */
/*
 * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
 * Copyright 1993 by David Dawes <dawes@XFree86.org>
 * Copyright 1999 by David Holland <davidh@iquest.net)
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the names of Thomas Roell, David Dawes, and David Holland not be used
 * in advertising or publicity pertaining to distribution of the software
 * without specific, written prior permission.  Thomas Roell, David Dawes, and
 * David Holland make no representations about the suitability of this software
 * for any purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 * THOMAS ROELL, DAVID DAWES, AND DAVID HOLLAND DISCLAIM ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS.  IN NO EVENT SHALL THOMAS ROELL, DAVID DAWES, OR DAVID HOLLAND
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.c,v 1.3 2004/06/13 04:50:21 alanc Exp $ */

#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"

static int sun_otranslation = -1;
static int sun_odirect = -1;
int sun_ktype;

int
xf86GetKbdLeds()
{
	int leds;

	ioctl(xf86Info.kbdFd, KIOCGLED, &leds);
	return leds;
}

void
xf86SetKbdRepeat(char rad)
{
    /* Nothing to do */
}

/*
 * Save initial keyboard state.  This is called at the start of each server
 * generation.
 */

void
xf86KbdInit()
{
	int	klayout;
	const char *ktype_name;

	if (xf86Info.kbdFd < 0) {
		xf86Info.kbdFd = open("/dev/kbd", O_RDWR|O_NONBLOCK);
		if(xf86Info.kbdFd < 0)
			FatalError("Unable to open keyboard: /dev/kbd\n");
	}

	/*
	 * None of the following should ever fail.  If it does, something is
	 * broken (IMO) - DWH 8/21/99
	 */

	if (ioctl(xf86Info.kbdFd, KIOCTYPE, &sun_ktype) < 0)
		FatalError("Unable to determine keyboard type: %d\n", errno);

	if (ioctl(xf86Info.kbdFd, KIOCLAYOUT, &klayout) < 0)
		FatalError("Unable to determine keyboard layout: %d\n", errno);

	if (ioctl(xf86Info.kbdFd, KIOCGTRANS, &sun_otranslation) < 0)
		FatalError("Unable to determine keyboard translation mode\n");

	if (ioctl(xf86Info.kbdFd, KIOCGDIRECT, &sun_odirect) < 0)
		FatalError("Unable to determine keyboard direct setting\n");

	switch (sun_ktype) {
	case KB_SUN3:
	    ktype_name = "Sun Type 3"; break;
	case KB_SUN4:
	    ktype_name = "Sun Type 4/5/6"; break;
	case KB_USB:
	    ktype_name = "USB"; break;
	case KB_PC:
	    ktype_name = "PC"; break;
	default:
	    ktype_name = "Unknown"; break;
	}
	xf86Msg(X_PROBED, "Keyboard type: %s (%d)\n", ktype_name, sun_ktype);
	xf86Msg(X_PROBED, "Keyboard layout: %d\n", klayout);
}

int
xf86KbdOn(void)
{
	int	tmp = 1;

	if (ioctl(xf86Info.kbdFd, KIOCSDIRECT, &tmp) == -1)
		FatalError("Setting keyboard direct mode on\n");

	/* Setup translation */

	tmp = TR_UNTRANS_EVENT;

	if (ioctl(xf86Info.kbdFd, KIOCTRANS, &tmp) == -1)
		FatalError("Setting keyboard translation\n");

	return xf86Info.kbdFd;
}

int
xf86KbdOff()
{
	if ((sun_otranslation != -1) &&
	   (ioctl(xf86Info.kbdFd, KIOCTRANS, &sun_otranslation) < 0))
		FatalError("Unable to restore keyboard translation mode\n");

	if ((sun_odirect != 0) &&
	   (ioctl(xf86Info.kbdFd, KIOCSDIRECT, &sun_odirect) < 0 ))
		FatalError("Unable to restore keyboard direct setting\n");

	return xf86Info.kbdFd;
}