xref: /illumos-gate/usr/src/uts/common/io/kbtrans/kbtrans_lower.h (revision 142d813a06c6f9a6142e2c276b62129a17a31a65)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _KBTRANS_LOWER_H
28 #define	_KBTRANS_LOWER_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * This structure describes the state of the keyboard.
36  * and also specifies the keytables.
37  */
38 struct kbtrans_lower {
39 	/* Generating pre-4.1 events? */
40 	int	kbtrans_compat;
41 
42 	/* key to repeat in TR_ASCII mode */
43 	kbtrans_key_t kbtrans_repeatkey;
44 
45 	/* Current state of the LED's */
46 	uchar_t	kbtrans_led_state;
47 
48 	/* Pointer to keyboard maps */
49 	struct  keyboard *kbtrans_keyboard;
50 
51 	/* Current shift state */
52 	uint_t   kbtrans_shiftmask;
53 
54 	uchar_t  kbtrans_state;		/* compose state */
55 	uint_t   kbtrans_buckybits;	/* current buckybits */
56 	uint_t   kbtrans_togglemask;   	/* Toggle shifts state */
57 	kbtrans_key_t kbtrans_compose_key;	/* first compose key */
58 	kbtrans_key_t kbtrans_fltaccent_entry; /* floating accent entry */
59 
60 	/*
61 	 * Various mapping tables.
62 	 */
63 	signed char			*kbtrans_compose_map;
64 	struct compose_sequence_t	*kbtrans_compose_table;
65 	struct fltaccent_sequence_t	*kbtrans_fltaccent_table;
66 
67 	/* Strings sent by various keys */
68 	char				(*kbtrans_keystringtab)[KTAB_STRLEN];
69 
70 	/* Num lock table */
71 	unsigned char			*kbtrans_numlock_table;
72 
73 	/*
74 	 * The kbtrans structure specifies the state of the
75 	 * stream.
76 	 */
77 	struct kbtrans			*kbtrans_upper;
78 };
79 
80 
81 /*
82  * Different functions must be called based upon the type of translation
83  * mode.  Each translation mode such as TR_ASCII, TR_EVENT, TR_NONE, etc.
84  * has an instance of this structure.
85  */
86 struct keyboard_callback {
87 
88 	/*
89 	 * Raw (untranslated) keypress
90 	 */
91 	void (*kc_keypressed_raw)(struct kbtrans *, kbtrans_key_t);
92 
93 	/*
94 	 * Raw (untranslated) keyrelease
95 	 */
96 	void (*kc_keyreleased_raw)(struct kbtrans *, kbtrans_key_t);
97 
98 	/*
99 	 * Keypress
100 	 */
101 	void (*kc_keypressed)(struct kbtrans *, uint_t, kbtrans_key_t, uint_t);
102 
103 	/*
104 	 * Keyrelease
105 	 */
106 	void (*kc_keyreleased)(struct kbtrans *, kbtrans_key_t);
107 
108 	/*
109 	 * Initialize a repeat character
110 	 */
111 	void (*kc_setup_repeat)(struct kbtrans *, uint_t, kbtrans_key_t);
112 
113 	/*
114 	 * Cancel a repeat character
115 	 */
116 	void (*kc_cancel_repeat)(struct kbtrans *);
117 
118 	/*
119 	 * Process the led state change
120 	 */
121 	void (*kc_setled)(struct kbtrans *);
122 };
123 
124 /*
125  * Process a scancode.  This routine will call the functions in
126  * keyboard_callback to handle the translated key.
127  */
128 void kbtrans_processkey(struct kbtrans_lower *, struct keyboard_callback *,
129     kbtrans_key_t, enum keystate);
130 
131 /*
132  * This routine finds the entry for the specified keycode based on the
133  * specified shift mask.
134  */
135 keymap_entry_t *kbtrans_find_entry(struct kbtrans_lower *, uint_t,
136     kbtrans_key_t);
137 
138 /*
139  * Debug printing
140  */
141 #ifndef DPRINTF
142 #ifdef DEBUG
143 #define	DPRINTF(l, m, args) \
144 	(((l) >= kbtrans_errlevel) && ((m) & kbtrans_errmask) ? \
145 		kbtrans_dprintf args :                          \
146 		(void) 0)
147 #else
148 #define	DPRINTF(l, m, args)
149 #endif
150 #endif
151 
152 /*
153  * Severity levels for printing
154  */
155 #define	PRINT_L0	0	/* print every message */
156 #define	PRINT_L1	1	/* debug */
157 #define	PRINT_L2	2	/* minor errors */
158 #define	PRINT_L3	3	/* major errors */
159 #define	PRINT_L4	4	/* catastophic errors */
160 
161 /*
162  * Masks
163  */
164 
165 #define	PRINT_MASK_ALL		0xFFFFFFFF
166 #define	PRINT_MASK_OPEN		0x00000002
167 #define	PRINT_MASK_PACKET	0x00000008
168 #define	PRINT_MASK_CLOSE	0x00000004
169 
170 #ifdef DEBUG
171 extern int	kbtrans_errmask;
172 extern int	kbtrans_errlevel;
173 extern void	kbtrans_dprintf(void *, const char *fmt, ...);
174 #endif
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif	/* _KBTRANS_LOWER_H */
181