17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _KBTRANS_LOWER_H
287c478bd9Sstevel@tonic-gate #define	_KBTRANS_LOWER_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef __cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * This structure describes the state of the keyboard.
367c478bd9Sstevel@tonic-gate  * and also specifies the keytables.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate struct kbtrans_lower {
397c478bd9Sstevel@tonic-gate 	/* Generating pre-4.1 events? */
407c478bd9Sstevel@tonic-gate 	int	kbtrans_compat;
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate 	/* key to repeat in TR_ASCII mode */
437c478bd9Sstevel@tonic-gate 	kbtrans_key_t kbtrans_repeatkey;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate 	/* Current state of the LED's */
467c478bd9Sstevel@tonic-gate 	uchar_t	kbtrans_led_state;
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate 	/* Pointer to keyboard maps */
497c478bd9Sstevel@tonic-gate 	struct  keyboard *kbtrans_keyboard;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate 	/* Current shift state */
527c478bd9Sstevel@tonic-gate 	uint_t   kbtrans_shiftmask;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	uchar_t  kbtrans_state;		/* compose state */
557c478bd9Sstevel@tonic-gate 	uint_t   kbtrans_buckybits;	/* current buckybits */
567c478bd9Sstevel@tonic-gate 	uint_t   kbtrans_togglemask;   	/* Toggle shifts state */
57*adc2b73dSToomas Soome 	kbtrans_key_t kbtrans_compose_key;	/* first compose key */
58*adc2b73dSToomas Soome 	kbtrans_key_t kbtrans_fltaccent_entry; /* floating accent entry */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	/*
617c478bd9Sstevel@tonic-gate 	 * Various mapping tables.
627c478bd9Sstevel@tonic-gate 	 */
637c478bd9Sstevel@tonic-gate 	signed char			*kbtrans_compose_map;
647c478bd9Sstevel@tonic-gate 	struct compose_sequence_t	*kbtrans_compose_table;
657c478bd9Sstevel@tonic-gate 	struct fltaccent_sequence_t	*kbtrans_fltaccent_table;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	/* Strings sent by various keys */
687c478bd9Sstevel@tonic-gate 	char				(*kbtrans_keystringtab)[KTAB_STRLEN];
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	/* Num lock table */
717c478bd9Sstevel@tonic-gate 	unsigned char			*kbtrans_numlock_table;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	/*
747c478bd9Sstevel@tonic-gate 	 * The kbtrans structure specifies the state of the
757c478bd9Sstevel@tonic-gate 	 * stream.
767c478bd9Sstevel@tonic-gate 	 */
777c478bd9Sstevel@tonic-gate 	struct kbtrans			*kbtrans_upper;
787c478bd9Sstevel@tonic-gate };
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Different functions must be called based upon the type of translation
837c478bd9Sstevel@tonic-gate  * mode.  Each translation mode such as TR_ASCII, TR_EVENT, TR_NONE, etc.
847c478bd9Sstevel@tonic-gate  * has an instance of this structure.
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate struct keyboard_callback {
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	/*
897c478bd9Sstevel@tonic-gate 	 * Raw (untranslated) keypress
907c478bd9Sstevel@tonic-gate 	 */
917c478bd9Sstevel@tonic-gate 	void (*kc_keypressed_raw)(struct kbtrans *, kbtrans_key_t);
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	/*
947c478bd9Sstevel@tonic-gate 	 * Raw (untranslated) keyrelease
957c478bd9Sstevel@tonic-gate 	 */
967c478bd9Sstevel@tonic-gate 	void (*kc_keyreleased_raw)(struct kbtrans *, kbtrans_key_t);
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	/*
997c478bd9Sstevel@tonic-gate 	 * Keypress
1007c478bd9Sstevel@tonic-gate 	 */
1017c478bd9Sstevel@tonic-gate 	void (*kc_keypressed)(struct kbtrans *, uint_t, kbtrans_key_t, uint_t);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	/*
1047c478bd9Sstevel@tonic-gate 	 * Keyrelease
1057c478bd9Sstevel@tonic-gate 	 */
1067c478bd9Sstevel@tonic-gate 	void (*kc_keyreleased)(struct kbtrans *, kbtrans_key_t);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	/*
1097c478bd9Sstevel@tonic-gate 	 * Initialize a repeat character
1107c478bd9Sstevel@tonic-gate 	 */
1117c478bd9Sstevel@tonic-gate 	void (*kc_setup_repeat)(struct kbtrans *, uint_t, kbtrans_key_t);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	/*
1147c478bd9Sstevel@tonic-gate 	 * Cancel a repeat character
1157c478bd9Sstevel@tonic-gate 	 */
1167c478bd9Sstevel@tonic-gate 	void (*kc_cancel_repeat)(struct kbtrans *);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	/*
1197c478bd9Sstevel@tonic-gate 	 * Process the led state change
1207c478bd9Sstevel@tonic-gate 	 */
1217c478bd9Sstevel@tonic-gate 	void (*kc_setled)(struct kbtrans *);
1227c478bd9Sstevel@tonic-gate };
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  * Process a scancode.  This routine will call the functions in
1267c478bd9Sstevel@tonic-gate  * keyboard_callback to handle the translated key.
1277c478bd9Sstevel@tonic-gate  */
128*adc2b73dSToomas Soome void kbtrans_processkey(struct kbtrans_lower *, struct keyboard_callback *,
129*adc2b73dSToomas Soome     kbtrans_key_t, enum keystate);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * This routine finds the entry for the specified keycode based on the
1337c478bd9Sstevel@tonic-gate  * specified shift mask.
1347c478bd9Sstevel@tonic-gate  */
135*adc2b73dSToomas Soome keymap_entry_t *kbtrans_find_entry(struct kbtrans_lower *, uint_t,
136*adc2b73dSToomas Soome     kbtrans_key_t);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate  * Debug printing
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate #ifndef DPRINTF
1427c478bd9Sstevel@tonic-gate #ifdef DEBUG
1437c478bd9Sstevel@tonic-gate #define	DPRINTF(l, m, args) \
1447c478bd9Sstevel@tonic-gate 	(((l) >= kbtrans_errlevel) && ((m) & kbtrans_errmask) ? \
1457c478bd9Sstevel@tonic-gate 		kbtrans_dprintf args :                          \
1467c478bd9Sstevel@tonic-gate 		(void) 0)
1477c478bd9Sstevel@tonic-gate #else
1487c478bd9Sstevel@tonic-gate #define	DPRINTF(l, m, args)
1497c478bd9Sstevel@tonic-gate #endif
1507c478bd9Sstevel@tonic-gate #endif
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate  * Severity levels for printing
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate #define	PRINT_L0	0	/* print every message */
1567c478bd9Sstevel@tonic-gate #define	PRINT_L1	1	/* debug */
1577c478bd9Sstevel@tonic-gate #define	PRINT_L2	2	/* minor errors */
1587c478bd9Sstevel@tonic-gate #define	PRINT_L3	3	/* major errors */
1597c478bd9Sstevel@tonic-gate #define	PRINT_L4	4	/* catastophic errors */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * Masks
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #define	PRINT_MASK_ALL		0xFFFFFFFF
1667c478bd9Sstevel@tonic-gate #define	PRINT_MASK_OPEN		0x00000002
1677c478bd9Sstevel@tonic-gate #define	PRINT_MASK_PACKET	0x00000008
1687c478bd9Sstevel@tonic-gate #define	PRINT_MASK_CLOSE	0x00000004
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate #ifdef DEBUG
1717c478bd9Sstevel@tonic-gate extern int	kbtrans_errmask;
1727c478bd9Sstevel@tonic-gate extern int	kbtrans_errlevel;
1737c478bd9Sstevel@tonic-gate extern void	kbtrans_dprintf(void *, const char *fmt, ...);
1747c478bd9Sstevel@tonic-gate #endif
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate #endif
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate #endif	/* _KBTRANS_LOWER_H */
181