117ca54c3Smrg/************************************************************
217ca54c3SmrgCopyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
317ca54c3Smrg
417ca54c3SmrgPermission to use, copy, modify, and distribute this
517ca54c3Smrgsoftware and its documentation for any purpose and without
617ca54c3Smrgfee is hereby granted, provided that the above copyright
717ca54c3Smrgnotice appear in all copies and that both that copyright
817ca54c3Smrgnotice and this permission notice appear in supporting
9ea1d6981Smrgdocumentation, and that the name of Silicon Graphics not be
10ea1d6981Smrgused in advertising or publicity pertaining to distribution
1117ca54c3Smrgof the software without specific prior written permission.
12ea1d6981SmrgSilicon Graphics makes no representation about the suitability
1317ca54c3Smrgof this software for any purpose. It is provided "as is"
1417ca54c3Smrgwithout any express or implied warranty.
1517ca54c3Smrg
16ea1d6981SmrgSILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17ea1d6981SmrgSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1817ca54c3SmrgAND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19ea1d6981SmrgGRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20ea1d6981SmrgDAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21ea1d6981SmrgDATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
2217ca54c3SmrgOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
2317ca54c3SmrgTHE USE OR PERFORMANCE OF THIS SOFTWARE.
2417ca54c3Smrg
2517ca54c3Smrg********************************************************/
2617ca54c3Smrg
2717ca54c3Smrg#ifndef _XKBSTR_H_
2817ca54c3Smrg#define	_XKBSTR_H_
2917ca54c3Smrg
30d63b911fSmrg#include <X11/Xfuncproto.h>
3117ca54c3Smrg#include <X11/extensions/XKB.h>
3217ca54c3Smrg
3317ca54c3Smrg#define	XkbCharToInt(v)		((v)&0x80?(int)((v)|(~0xff)):(int)((v)&0x7f))
3417ca54c3Smrg#define	XkbIntTo2Chars(i,h,l)	(((h)=((i>>8)&0xff)),((l)=((i)&0xff)))
3517ca54c3Smrg#define	Xkb2CharsToInt(h,l)	((short)(((h)<<8)|(l)))
3617ca54c3Smrg
3717ca54c3Smrg/*
3817ca54c3Smrg * The Xkb structs are full of implicit padding to properly align members.
3917ca54c3Smrg * We can't clean that up without breaking ABI, so tell clang not to bother
4017ca54c3Smrg * complaining about it.
4117ca54c3Smrg */
4217ca54c3Smrg#ifdef __clang__
4317ca54c3Smrg#pragma clang diagnostic push
4417ca54c3Smrg#pragma clang diagnostic ignored "-Wpadded"
4517ca54c3Smrg#endif
4617ca54c3Smrg
4717ca54c3Smrg	/*
4817ca54c3Smrg	 * Common data structures and access macros
4917ca54c3Smrg	 */
5017ca54c3Smrg
5117ca54c3Smrgtypedef struct _XkbStateRec {
5217ca54c3Smrg	unsigned char	group;
5317ca54c3Smrg	unsigned char   locked_group;
5417ca54c3Smrg	unsigned short	base_group;
5517ca54c3Smrg	unsigned short	latched_group;
5617ca54c3Smrg	unsigned char	mods;
5717ca54c3Smrg	unsigned char	base_mods;
5817ca54c3Smrg	unsigned char	latched_mods;
5917ca54c3Smrg	unsigned char	locked_mods;
6017ca54c3Smrg	unsigned char	compat_state;
6117ca54c3Smrg	unsigned char	grab_mods;
6217ca54c3Smrg	unsigned char	compat_grab_mods;
6317ca54c3Smrg	unsigned char	lookup_mods;
6417ca54c3Smrg	unsigned char	compat_lookup_mods;
6517ca54c3Smrg	unsigned short	ptr_buttons;
6617ca54c3Smrg} XkbStateRec,*XkbStatePtr;
6717ca54c3Smrg#define	XkbModLocks(s)	 ((s)->locked_mods)
6817ca54c3Smrg#define	XkbStateMods(s)	 ((s)->base_mods|(s)->latched_mods|XkbModLocks(s))
6917ca54c3Smrg#define	XkbGroupLock(s)	 ((s)->locked_group)
7017ca54c3Smrg#define	XkbStateGroup(s) ((s)->base_group+(s)->latched_group+XkbGroupLock(s))
7117ca54c3Smrg#define	XkbStateFieldFromRec(s)	XkbBuildCoreState((s)->lookup_mods,(s)->group)
7217ca54c3Smrg#define	XkbGrabStateFromRec(s)	XkbBuildCoreState((s)->grab_mods,(s)->group)
7317ca54c3Smrg
7417ca54c3Smrgtypedef struct _XkbMods {
7517ca54c3Smrg	unsigned char	mask;	/* effective mods */
7617ca54c3Smrg	unsigned char	real_mods;
7717ca54c3Smrg	unsigned short	vmods;
7817ca54c3Smrg} XkbModsRec,*XkbModsPtr;
7917ca54c3Smrg
8017ca54c3Smrgtypedef struct _XkbKTMapEntry {
8117ca54c3Smrg	Bool		active;
8217ca54c3Smrg	unsigned char	level;
8317ca54c3Smrg	XkbModsRec	mods;
8417ca54c3Smrg} XkbKTMapEntryRec,*XkbKTMapEntryPtr;
8517ca54c3Smrg
8617ca54c3Smrgtypedef struct _XkbKeyType {
8717ca54c3Smrg	XkbModsRec		mods;
8817ca54c3Smrg	unsigned char	  	num_levels;
8917ca54c3Smrg	unsigned char	  	map_count;
9017ca54c3Smrg	/* map is an array of map_count XkbKTMapEntryRec structs */
9117ca54c3Smrg	XkbKTMapEntryPtr  	map;
9217ca54c3Smrg	/* preserve is an array of map_count XkbModsRec structs */
9317ca54c3Smrg	XkbModsPtr  		preserve;
9417ca54c3Smrg	Atom		  	name;
9517ca54c3Smrg	/* level_names is an array of num_levels Atoms */
9617ca54c3Smrg	Atom *			level_names;
9717ca54c3Smrg} XkbKeyTypeRec, *XkbKeyTypePtr;
9817ca54c3Smrg
9917ca54c3Smrg#define	XkbNumGroups(g)			((g)&0x0f)
10017ca54c3Smrg#define	XkbOutOfRangeGroupInfo(g)	((g)&0xf0)
10117ca54c3Smrg#define	XkbOutOfRangeGroupAction(g)	((g)&0xc0)
10217ca54c3Smrg#define	XkbOutOfRangeGroupNumber(g)	(((g)&0x30)>>4)
10317ca54c3Smrg#define	XkbSetGroupInfo(g,w,n)	(((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
10417ca54c3Smrg#define	XkbSetNumGroups(g,n)	(((g)&0xf0)|((n)&0x0f))
10517ca54c3Smrg
10617ca54c3Smrg	/*
10717ca54c3Smrg	 * Structures and access macros used primarily by the server
10817ca54c3Smrg	 */
10917ca54c3Smrg
11017ca54c3Smrgtypedef struct _XkbBehavior {
11117ca54c3Smrg	unsigned char	type;
11217ca54c3Smrg	unsigned char	data;
11317ca54c3Smrg} XkbBehavior;
11417ca54c3Smrg
11517ca54c3Smrg#define	XkbAnyActionDataSize 7
11617ca54c3Smrgtypedef	struct _XkbAnyAction {
11717ca54c3Smrg	unsigned char	type;
11817ca54c3Smrg	unsigned char	data[XkbAnyActionDataSize];
11917ca54c3Smrg} XkbAnyAction;
12017ca54c3Smrg
12117ca54c3Smrgtypedef struct _XkbModAction {
12217ca54c3Smrg	unsigned char	type;
12317ca54c3Smrg	unsigned char	flags;
12417ca54c3Smrg	unsigned char	mask;
12517ca54c3Smrg	unsigned char	real_mods;
12617ca54c3Smrg	unsigned char	vmods1;
12717ca54c3Smrg	unsigned char	vmods2;
12817ca54c3Smrg} XkbModAction;
12917ca54c3Smrg#define	XkbModActionVMods(a)      \
13017ca54c3Smrg	((short)(((a)->vmods1<<8)|((a)->vmods2)))
13117ca54c3Smrg#define	XkbSetModActionVMods(a,v) \
13217ca54c3Smrg	(((a)->vmods1=(((v)>>8)&0xff)),(a)->vmods2=((v)&0xff))
13317ca54c3Smrg
13417ca54c3Smrgtypedef struct _XkbGroupAction {
13517ca54c3Smrg	unsigned char	type;
13617ca54c3Smrg	unsigned char	flags;
13717ca54c3Smrg	char		group_XXX;
13817ca54c3Smrg} XkbGroupAction;
13917ca54c3Smrg#define	XkbSAGroup(a)		(XkbCharToInt((a)->group_XXX))
14017ca54c3Smrg#define	XkbSASetGroup(a,g)	((a)->group_XXX=(g))
14117ca54c3Smrg
14217ca54c3Smrgtypedef struct _XkbISOAction {
14317ca54c3Smrg	unsigned char	type;
14417ca54c3Smrg	unsigned char	flags;
14517ca54c3Smrg	unsigned char	mask;
14617ca54c3Smrg	unsigned char	real_mods;
14717ca54c3Smrg	char		group_XXX;
14817ca54c3Smrg	unsigned char	affect;
14917ca54c3Smrg	unsigned char	vmods1;
15017ca54c3Smrg	unsigned char	vmods2;
15117ca54c3Smrg} XkbISOAction;
15217ca54c3Smrg
15317ca54c3Smrgtypedef struct _XkbPtrAction {
15417ca54c3Smrg	unsigned char	type;
15517ca54c3Smrg	unsigned char	flags;
15617ca54c3Smrg	unsigned char	high_XXX;
15717ca54c3Smrg	unsigned char	low_XXX;
15817ca54c3Smrg	unsigned char	high_YYY;
15917ca54c3Smrg	unsigned char	low_YYY;
16017ca54c3Smrg} XkbPtrAction;
16117ca54c3Smrg#define	XkbPtrActionX(a)      (Xkb2CharsToInt((a)->high_XXX,(a)->low_XXX))
16217ca54c3Smrg#define	XkbPtrActionY(a)      (Xkb2CharsToInt((a)->high_YYY,(a)->low_YYY))
16317ca54c3Smrg#define	XkbSetPtrActionX(a,x) (XkbIntTo2Chars(x,(a)->high_XXX,(a)->low_XXX))
16417ca54c3Smrg#define	XkbSetPtrActionY(a,y) (XkbIntTo2Chars(y,(a)->high_YYY,(a)->low_YYY))
16517ca54c3Smrg
16617ca54c3Smrgtypedef struct _XkbPtrBtnAction {
16717ca54c3Smrg	unsigned char	type;
16817ca54c3Smrg	unsigned char	flags;
16917ca54c3Smrg	unsigned char	count;
17017ca54c3Smrg	unsigned char	button;
17117ca54c3Smrg} XkbPtrBtnAction;
17217ca54c3Smrg
17317ca54c3Smrgtypedef struct _XkbPtrDfltAction {
17417ca54c3Smrg	unsigned char	type;
17517ca54c3Smrg	unsigned char	flags;
17617ca54c3Smrg	unsigned char	affect;
17717ca54c3Smrg	char		valueXXX;
17817ca54c3Smrg} XkbPtrDfltAction;
17917ca54c3Smrg#define	XkbSAPtrDfltValue(a)		(XkbCharToInt((a)->valueXXX))
18017ca54c3Smrg#define	XkbSASetPtrDfltValue(a,c)	((a)->valueXXX= ((c)&0xff))
18117ca54c3Smrg
18217ca54c3Smrgtypedef struct _XkbSwitchScreenAction {
18317ca54c3Smrg	unsigned char	type;
18417ca54c3Smrg	unsigned char	flags;
18517ca54c3Smrg	char		screenXXX;
18617ca54c3Smrg} XkbSwitchScreenAction;
18717ca54c3Smrg#define	XkbSAScreen(a)			(XkbCharToInt((a)->screenXXX))
18817ca54c3Smrg#define	XkbSASetScreen(a,s)		((a)->screenXXX= ((s)&0xff))
18917ca54c3Smrg
19017ca54c3Smrgtypedef struct _XkbCtrlsAction {
19117ca54c3Smrg	unsigned char	type;
19217ca54c3Smrg	unsigned char	flags;
19317ca54c3Smrg	unsigned char	ctrls3;
19417ca54c3Smrg	unsigned char	ctrls2;
19517ca54c3Smrg	unsigned char	ctrls1;
19617ca54c3Smrg	unsigned char	ctrls0;
19717ca54c3Smrg} XkbCtrlsAction;
19817ca54c3Smrg#define	XkbActionSetCtrls(a,c)	(((a)->ctrls3=(((c)>>24)&0xff)),\
19917ca54c3Smrg					((a)->ctrls2=(((c)>>16)&0xff)),\
20017ca54c3Smrg					((a)->ctrls1=(((c)>>8)&0xff)),\
20117ca54c3Smrg					((a)->ctrls0=((c)&0xff)))
20217ca54c3Smrg#define	XkbActionCtrls(a) ((((unsigned int)(a)->ctrls3)<<24)|\
20317ca54c3Smrg			   (((unsigned int)(a)->ctrls2)<<16)|\
20417ca54c3Smrg			   (((unsigned int)(a)->ctrls1)<<8)|\
20517ca54c3Smrg			   ((unsigned int)((a)->ctrls0)))
20617ca54c3Smrg
20717ca54c3Smrgtypedef struct _XkbMessageAction {
20817ca54c3Smrg	unsigned char	type;
20917ca54c3Smrg	unsigned char	flags;
21017ca54c3Smrg	unsigned char	message[6];
21117ca54c3Smrg} XkbMessageAction;
21217ca54c3Smrg
21317ca54c3Smrgtypedef struct	_XkbRedirectKeyAction {
21417ca54c3Smrg	unsigned char	type;
21517ca54c3Smrg	unsigned char	new_key;
21617ca54c3Smrg	unsigned char	mods_mask;
21717ca54c3Smrg	unsigned char	mods;
21817ca54c3Smrg	unsigned char	vmods_mask0;
21917ca54c3Smrg	unsigned char	vmods_mask1;
22017ca54c3Smrg	unsigned char	vmods0;
22117ca54c3Smrg	unsigned char	vmods1;
22217ca54c3Smrg} XkbRedirectKeyAction;
22317ca54c3Smrg
22417ca54c3Smrg#define	XkbSARedirectVMods(a)		((((unsigned int)(a)->vmods1)<<8)|\
22517ca54c3Smrg					((unsigned int)(a)->vmods0))
22617ca54c3Smrg#define	XkbSARedirectSetVMods(a,m)	(((a)->vmods1=(((m)>>8)&0xff)),\
22717ca54c3Smrg					 ((a)->vmods0=((m)&0xff)))
22817ca54c3Smrg#define	XkbSARedirectVModsMask(a)	((((unsigned int)(a)->vmods_mask1)<<8)|\
22917ca54c3Smrg					((unsigned int)(a)->vmods_mask0))
23017ca54c3Smrg#define	XkbSARedirectSetVModsMask(a,m)	(((a)->vmods_mask1=(((m)>>8)&0xff)),\
23117ca54c3Smrg					 ((a)->vmods_mask0=((m)&0xff)))
23217ca54c3Smrg
23317ca54c3Smrgtypedef struct _XkbDeviceBtnAction {
23417ca54c3Smrg	unsigned char	type;
23517ca54c3Smrg	unsigned char	flags;
23617ca54c3Smrg	unsigned char	count;
23717ca54c3Smrg	unsigned char	button;
23817ca54c3Smrg	unsigned char	device;
23917ca54c3Smrg} XkbDeviceBtnAction;
24017ca54c3Smrg
24117ca54c3Smrgtypedef struct _XkbDeviceValuatorAction {
24217ca54c3Smrg	unsigned char	type;
24317ca54c3Smrg	unsigned char	device;
24417ca54c3Smrg	unsigned char	v1_what;
24517ca54c3Smrg	unsigned char	v1_ndx;
24617ca54c3Smrg	unsigned char	v1_value;
24717ca54c3Smrg	unsigned char	v2_what;
24817ca54c3Smrg	unsigned char	v2_ndx;
24917ca54c3Smrg	unsigned char	v2_value;
25017ca54c3Smrg} XkbDeviceValuatorAction;
25117ca54c3Smrg
25217ca54c3Smrgtypedef	union _XkbAction {
25317ca54c3Smrg	XkbAnyAction		any;
25417ca54c3Smrg	XkbModAction		mods;
25517ca54c3Smrg	XkbGroupAction		group;
25617ca54c3Smrg	XkbISOAction		iso;
25717ca54c3Smrg	XkbPtrAction		ptr;
25817ca54c3Smrg	XkbPtrBtnAction		btn;
25917ca54c3Smrg	XkbPtrDfltAction	dflt;
26017ca54c3Smrg	XkbSwitchScreenAction	screen;
26117ca54c3Smrg	XkbCtrlsAction		ctrls;
26217ca54c3Smrg	XkbMessageAction	msg;
26317ca54c3Smrg	XkbRedirectKeyAction	redirect;
26417ca54c3Smrg	XkbDeviceBtnAction	devbtn;
26517ca54c3Smrg	XkbDeviceValuatorAction	devval;
26617ca54c3Smrg	unsigned char 		type;
26717ca54c3Smrg} XkbAction;
26817ca54c3Smrg
26917ca54c3Smrgtypedef	struct _XkbControls {
27017ca54c3Smrg	unsigned char	mk_dflt_btn;
27117ca54c3Smrg	unsigned char	num_groups;
27217ca54c3Smrg	unsigned char	groups_wrap;
27317ca54c3Smrg	XkbModsRec	internal;
27417ca54c3Smrg	XkbModsRec	ignore_lock;
27517ca54c3Smrg	unsigned int	enabled_ctrls;
27617ca54c3Smrg	unsigned short	repeat_delay;
27717ca54c3Smrg	unsigned short	repeat_interval;
27817ca54c3Smrg	unsigned short	slow_keys_delay;
27917ca54c3Smrg	unsigned short	debounce_delay;
28017ca54c3Smrg	unsigned short	mk_delay;
28117ca54c3Smrg	unsigned short	mk_interval;
28217ca54c3Smrg	unsigned short	mk_time_to_max;
28317ca54c3Smrg	unsigned short	mk_max_speed;
28417ca54c3Smrg		 short	mk_curve;
28517ca54c3Smrg	unsigned short	ax_options;
28617ca54c3Smrg	unsigned short	ax_timeout;
28717ca54c3Smrg	unsigned short	axt_opts_mask;
28817ca54c3Smrg	unsigned short	axt_opts_values;
28917ca54c3Smrg	unsigned int	axt_ctrls_mask;
29017ca54c3Smrg	unsigned int	axt_ctrls_values;
29117ca54c3Smrg	unsigned char	per_key_repeat[XkbPerKeyBitArraySize];
29217ca54c3Smrg} XkbControlsRec, *XkbControlsPtr;
29317ca54c3Smrg
29417ca54c3Smrg#define	XkbAX_AnyFeedback(c)	((c)->enabled_ctrls&XkbAccessXFeedbackMask)
29517ca54c3Smrg#define	XkbAX_NeedOption(c,w)	((c)->ax_options&(w))
29617ca54c3Smrg#define	XkbAX_NeedFeedback(c,w)	(XkbAX_AnyFeedback(c)&&XkbAX_NeedOption(c,w))
29717ca54c3Smrg
29817ca54c3Smrgtypedef struct _XkbServerMapRec {
29917ca54c3Smrg	/* acts is an array of XkbActions structs, with size_acts entries
30017ca54c3Smrg	   allocated, and num_acts entries used. */
30117ca54c3Smrg	unsigned short		 num_acts;
30217ca54c3Smrg	unsigned short		 size_acts;
30317ca54c3Smrg	XkbAction		*acts;
30417ca54c3Smrg
30517ca54c3Smrg	/* behaviors, key_acts, explicit, & vmodmap are all arrays with
30617ca54c3Smrg	   (xkb->max_key_code + 1) entries allocated for each. */
30717ca54c3Smrg	XkbBehavior		*behaviors;
30817ca54c3Smrg	unsigned short		*key_acts;
30917ca54c3Smrg#if defined(__cplusplus) || defined(c_plusplus)
31017ca54c3Smrg	/* explicit is a C++ reserved word */
31117ca54c3Smrg	unsigned char		*c_explicit;
31217ca54c3Smrg#else
31317ca54c3Smrg	unsigned char		*explicit;
31417ca54c3Smrg#endif
31517ca54c3Smrg	unsigned char		 vmods[XkbNumVirtualMods];
31617ca54c3Smrg	unsigned short		*vmodmap;
31717ca54c3Smrg} XkbServerMapRec, *XkbServerMapPtr;
31817ca54c3Smrg
31917ca54c3Smrg#define	XkbSMKeyActionsPtr(m,k) (&(m)->acts[(m)->key_acts[k]])
32017ca54c3Smrg
32117ca54c3Smrg	/*
32217ca54c3Smrg	 * Structures and access macros used primarily by clients
32317ca54c3Smrg	 */
32417ca54c3Smrg
32517ca54c3Smrgtypedef	struct _XkbSymMapRec {
32617ca54c3Smrg	unsigned char	 kt_index[XkbNumKbdGroups];
32717ca54c3Smrg	unsigned char	 group_info;
32817ca54c3Smrg	unsigned char	 width;
32917ca54c3Smrg	unsigned short	 offset;
33017ca54c3Smrg} XkbSymMapRec, *XkbSymMapPtr;
33117ca54c3Smrg
33217ca54c3Smrgtypedef struct _XkbClientMapRec {
33317ca54c3Smrg	/* types is an array of XkbKeyTypeRec structs, with size_types entries
33417ca54c3Smrg	   allocated, and num_types entries used. */
33517ca54c3Smrg	unsigned char		 size_types;
33617ca54c3Smrg	unsigned char		 num_types;
33717ca54c3Smrg	XkbKeyTypePtr		 types;
33817ca54c3Smrg
33917ca54c3Smrg	/* syms is an array of size_syms KeySyms, in which num_syms are used */
34017ca54c3Smrg	unsigned short		 size_syms;
34117ca54c3Smrg	unsigned short		 num_syms;
34217ca54c3Smrg	KeySym			*syms;
34317ca54c3Smrg	/* key_sym_map is an array of (max_key_code + 1) XkbSymMapRec structs */
34417ca54c3Smrg	XkbSymMapPtr		 key_sym_map;
34517ca54c3Smrg
34617ca54c3Smrg	/* modmap is an array of (max_key_code + 1) unsigned chars */
34717ca54c3Smrg	unsigned char		*modmap;
34817ca54c3Smrg} XkbClientMapRec, *XkbClientMapPtr;
34917ca54c3Smrg
35017ca54c3Smrg#define	XkbCMKeyGroupInfo(m,k)  ((m)->key_sym_map[k].group_info)
35117ca54c3Smrg#define	XkbCMKeyNumGroups(m,k)	 (XkbNumGroups((m)->key_sym_map[k].group_info))
35217ca54c3Smrg#define	XkbCMKeyGroupWidth(m,k,g) (XkbCMKeyType(m,k,g)->num_levels)
35317ca54c3Smrg#define	XkbCMKeyGroupsWidth(m,k) ((m)->key_sym_map[k].width)
35417ca54c3Smrg#define	XkbCMKeyTypeIndex(m,k,g) ((m)->key_sym_map[k].kt_index[g&0x3])
35517ca54c3Smrg#define	XkbCMKeyType(m,k,g)	 (&(m)->types[XkbCMKeyTypeIndex(m,k,g)])
35617ca54c3Smrg#define	XkbCMKeyNumSyms(m,k) (XkbCMKeyGroupsWidth(m,k)*XkbCMKeyNumGroups(m,k))
35717ca54c3Smrg#define	XkbCMKeySymsOffset(m,k)	((m)->key_sym_map[k].offset)
35817ca54c3Smrg#define	XkbCMKeySymsPtr(m,k)	(&(m)->syms[XkbCMKeySymsOffset(m,k)])
35917ca54c3Smrg
36017ca54c3Smrg	/*
36117ca54c3Smrg	 * Compatibility structures and access macros
36217ca54c3Smrg	 */
36317ca54c3Smrg
36417ca54c3Smrgtypedef struct _XkbSymInterpretRec {
36517ca54c3Smrg	KeySym		sym;
36617ca54c3Smrg	unsigned char	flags;
36717ca54c3Smrg	unsigned char	match;
36817ca54c3Smrg	unsigned char	mods;
36917ca54c3Smrg	unsigned char	virtual_mod;
37017ca54c3Smrg	XkbAnyAction	act;
37117ca54c3Smrg} XkbSymInterpretRec,*XkbSymInterpretPtr;
37217ca54c3Smrg
37317ca54c3Smrgtypedef struct _XkbCompatMapRec {
37417ca54c3Smrg	/* sym_interpret is an array of XkbSymInterpretRec structs,
37517ca54c3Smrg	   in which size_si are allocated & num_si are used. */
37617ca54c3Smrg	XkbSymInterpretPtr	 sym_interpret;
37717ca54c3Smrg	XkbModsRec		 groups[XkbNumKbdGroups];
37817ca54c3Smrg	unsigned short		 num_si;
37917ca54c3Smrg	unsigned short		 size_si;
38017ca54c3Smrg} XkbCompatMapRec, *XkbCompatMapPtr;
38117ca54c3Smrg
38217ca54c3Smrgtypedef struct _XkbIndicatorMapRec {
38317ca54c3Smrg	unsigned char	flags;
38417ca54c3Smrg	unsigned char	which_groups;
38517ca54c3Smrg	unsigned char	groups;
38617ca54c3Smrg	unsigned char	which_mods;
38717ca54c3Smrg	XkbModsRec	mods;
38817ca54c3Smrg	unsigned int	ctrls;
38917ca54c3Smrg} XkbIndicatorMapRec, *XkbIndicatorMapPtr;
39017ca54c3Smrg
39117ca54c3Smrg#define	XkbIM_IsAuto(i)	((((i)->flags&XkbIM_NoAutomatic)==0)&&\
39217ca54c3Smrg			    (((i)->which_groups&&(i)->groups)||\
39317ca54c3Smrg			     ((i)->which_mods&&(i)->mods.mask)||\
39417ca54c3Smrg			     ((i)->ctrls)))
39517ca54c3Smrg#define	XkbIM_InUse(i)	(((i)->flags)||((i)->which_groups)||\
39617ca54c3Smrg					((i)->which_mods)||((i)->ctrls))
397ea1d6981Smrg
39817ca54c3Smrg
39917ca54c3Smrgtypedef struct _XkbIndicatorRec {
40017ca54c3Smrg	unsigned long	  	phys_indicators;
40117ca54c3Smrg	XkbIndicatorMapRec	maps[XkbNumIndicators];
40217ca54c3Smrg} XkbIndicatorRec,*XkbIndicatorPtr;
40317ca54c3Smrg
40417ca54c3Smrgtypedef	struct _XkbKeyNameRec {
405d63b911fSmrg	char	name[XkbKeyNameLength]	_X_NONSTRING;
40617ca54c3Smrg} XkbKeyNameRec,*XkbKeyNamePtr;
40717ca54c3Smrg
40817ca54c3Smrgtypedef struct _XkbKeyAliasRec {
409d63b911fSmrg	char	real[XkbKeyNameLength]	_X_NONSTRING;
410d63b911fSmrg	char	alias[XkbKeyNameLength]	_X_NONSTRING;
41117ca54c3Smrg} XkbKeyAliasRec,*XkbKeyAliasPtr;
41217ca54c3Smrg
41317ca54c3Smrg	/*
414ea1d6981Smrg	 * Names for everything
41517ca54c3Smrg	 */
41617ca54c3Smrgtypedef struct _XkbNamesRec {
41717ca54c3Smrg	Atom		  keycodes;
41817ca54c3Smrg	Atom		  geometry;
41917ca54c3Smrg	Atom		  symbols;
42017ca54c3Smrg	Atom              types;
42117ca54c3Smrg	Atom		  compat;
42217ca54c3Smrg	Atom		  vmods[XkbNumVirtualMods];
42317ca54c3Smrg	Atom		  indicators[XkbNumIndicators];
42417ca54c3Smrg	Atom		  groups[XkbNumKbdGroups];
42517ca54c3Smrg	/* keys is an array of (xkb->max_key_code + 1) XkbKeyNameRec entries */
42617ca54c3Smrg	XkbKeyNamePtr	  keys;
42717ca54c3Smrg	/* key_aliases is an array of num_key_aliases XkbKeyAliasRec entries */
42817ca54c3Smrg	XkbKeyAliasPtr	  key_aliases;
42917ca54c3Smrg	/* radio_groups is an array of num_rg Atoms */
43017ca54c3Smrg	Atom		 *radio_groups;
43117ca54c3Smrg	Atom		  phys_symbols;
43217ca54c3Smrg
43317ca54c3Smrg	/* num_keys seems to be unused in libX11 */
43417ca54c3Smrg	unsigned char	  num_keys;
43517ca54c3Smrg	unsigned char	  num_key_aliases;
43617ca54c3Smrg	unsigned short	  num_rg;
43717ca54c3Smrg} XkbNamesRec,*XkbNamesPtr;
43817ca54c3Smrg
43917ca54c3Smrgtypedef	struct _XkbGeometry	*XkbGeometryPtr;
44017ca54c3Smrg	/*
44117ca54c3Smrg	 * Tie it all together into one big keyboard description
44217ca54c3Smrg	 */
44317ca54c3Smrgtypedef	struct _XkbDesc {
44417ca54c3Smrg	struct _XDisplay *	dpy;
44517ca54c3Smrg	unsigned short	 	flags;
44617ca54c3Smrg	unsigned short		device_spec;
44717ca54c3Smrg	KeyCode			min_key_code;
44817ca54c3Smrg	KeyCode			max_key_code;
44917ca54c3Smrg
45017ca54c3Smrg	XkbControlsPtr		ctrls;
45117ca54c3Smrg	XkbServerMapPtr		server;
45217ca54c3Smrg	XkbClientMapPtr		map;
45317ca54c3Smrg	XkbIndicatorPtr		indicators;
45417ca54c3Smrg	XkbNamesPtr		names;
45517ca54c3Smrg	XkbCompatMapPtr		compat;
45617ca54c3Smrg	XkbGeometryPtr		geom;
45717ca54c3Smrg} XkbDescRec, *XkbDescPtr;
45817ca54c3Smrg#define	XkbKeyKeyTypeIndex(d,k,g)	(XkbCMKeyTypeIndex((d)->map,k,g))
45917ca54c3Smrg#define	XkbKeyKeyType(d,k,g)		(XkbCMKeyType((d)->map,k,g))
46017ca54c3Smrg#define	XkbKeyGroupWidth(d,k,g)		(XkbCMKeyGroupWidth((d)->map,k,g))
46117ca54c3Smrg#define	XkbKeyGroupsWidth(d,k)		(XkbCMKeyGroupsWidth((d)->map,k))
46217ca54c3Smrg#define	XkbKeyGroupInfo(d,k)		(XkbCMKeyGroupInfo((d)->map,(k)))
46317ca54c3Smrg#define	XkbKeyNumGroups(d,k)		(XkbCMKeyNumGroups((d)->map,(k)))
46417ca54c3Smrg#define	XkbKeyNumSyms(d,k)		(XkbCMKeyNumSyms((d)->map,(k)))
46517ca54c3Smrg#define	XkbKeySymsPtr(d,k)		(XkbCMKeySymsPtr((d)->map,(k)))
46617ca54c3Smrg#define	XkbKeySym(d,k,n)		(XkbKeySymsPtr(d,k)[n])
46717ca54c3Smrg#define	XkbKeySymEntry(d,k,sl,g) \
46817ca54c3Smrg	(XkbKeySym(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))))
46917ca54c3Smrg#define	XkbKeyAction(d,k,n) \
47017ca54c3Smrg	(XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
47117ca54c3Smrg#define	XkbKeyActionEntry(d,k,sl,g) \
47217ca54c3Smrg	(XkbKeyHasActions(d,k)?\
47317ca54c3Smrg		XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
47417ca54c3Smrg
47517ca54c3Smrg#define	XkbKeyHasActions(d,k)	((d)->server->key_acts[k]!=0)
47617ca54c3Smrg#define	XkbKeyNumActions(d,k)	(XkbKeyHasActions(d,k)?XkbKeyNumSyms(d,k):1)
47717ca54c3Smrg#define	XkbKeyActionsPtr(d,k)	(XkbSMKeyActionsPtr((d)->server,k))
47817ca54c3Smrg#define	XkbKeycodeInRange(d,k)	(((k)>=(d)->min_key_code)&&\
47917ca54c3Smrg				 ((k)<=(d)->max_key_code))
48017ca54c3Smrg#define	XkbNumKeys(d)		((d)->max_key_code-(d)->min_key_code+1)
48117ca54c3Smrg
48217ca54c3Smrg
48317ca54c3Smrg	/*
48417ca54c3Smrg	 * The following structures can be used to track changes
48517ca54c3Smrg	 * to a keyboard device
48617ca54c3Smrg	 */
48717ca54c3Smrgtypedef struct _XkbMapChanges {
48817ca54c3Smrg	unsigned short		 changed;
48917ca54c3Smrg	KeyCode			 min_key_code;
49017ca54c3Smrg	KeyCode			 max_key_code;
49117ca54c3Smrg	unsigned char		 first_type;
49217ca54c3Smrg	unsigned char		 num_types;
49317ca54c3Smrg	KeyCode			 first_key_sym;
49417ca54c3Smrg	unsigned char		 num_key_syms;
49517ca54c3Smrg	KeyCode			 first_key_act;
49617ca54c3Smrg	unsigned char		 num_key_acts;
49717ca54c3Smrg	KeyCode			 first_key_behavior;
49817ca54c3Smrg	unsigned char		 num_key_behaviors;
49917ca54c3Smrg	KeyCode 		 first_key_explicit;
50017ca54c3Smrg	unsigned char		 num_key_explicit;
50117ca54c3Smrg	KeyCode			 first_modmap_key;
50217ca54c3Smrg	unsigned char		 num_modmap_keys;
50317ca54c3Smrg	KeyCode			 first_vmodmap_key;
50417ca54c3Smrg	unsigned char		 num_vmodmap_keys;
50517ca54c3Smrg	unsigned char		 pad;
50617ca54c3Smrg	unsigned short		 vmods;
50717ca54c3Smrg} XkbMapChangesRec,*XkbMapChangesPtr;
50817ca54c3Smrg
50917ca54c3Smrgtypedef struct _XkbControlsChanges {
51017ca54c3Smrg	unsigned int 		 changed_ctrls;
51117ca54c3Smrg	unsigned int		 enabled_ctrls_changes;
51217ca54c3Smrg	Bool			 num_groups_changed;
51317ca54c3Smrg} XkbControlsChangesRec,*XkbControlsChangesPtr;
51417ca54c3Smrg
51517ca54c3Smrgtypedef struct _XkbIndicatorChanges {
51617ca54c3Smrg	unsigned int		 state_changes;
51717ca54c3Smrg	unsigned int		 map_changes;
51817ca54c3Smrg} XkbIndicatorChangesRec,*XkbIndicatorChangesPtr;
51917ca54c3Smrg
52017ca54c3Smrgtypedef struct _XkbNameChanges {
52117ca54c3Smrg	unsigned int 		changed;
52217ca54c3Smrg	unsigned char		first_type;
52317ca54c3Smrg	unsigned char		num_types;
52417ca54c3Smrg	unsigned char		first_lvl;
52517ca54c3Smrg	unsigned char		num_lvls;
52617ca54c3Smrg	unsigned char		num_aliases;
52717ca54c3Smrg	unsigned char		num_rg;
52817ca54c3Smrg	unsigned char		first_key;
52917ca54c3Smrg	unsigned char		num_keys;
53017ca54c3Smrg	unsigned short		changed_vmods;
53117ca54c3Smrg	unsigned long		changed_indicators;
53217ca54c3Smrg	unsigned char		changed_groups;
53317ca54c3Smrg} XkbNameChangesRec,*XkbNameChangesPtr;
53417ca54c3Smrg
53517ca54c3Smrgtypedef struct _XkbCompatChanges {
53617ca54c3Smrg	unsigned char		changed_groups;
53717ca54c3Smrg	unsigned short		first_si;
53817ca54c3Smrg	unsigned short		num_si;
53917ca54c3Smrg} XkbCompatChangesRec,*XkbCompatChangesPtr;
54017ca54c3Smrg
54117ca54c3Smrgtypedef struct _XkbChanges {
54217ca54c3Smrg	unsigned short		 device_spec;
54317ca54c3Smrg	unsigned short		 state_changes;
54417ca54c3Smrg	XkbMapChangesRec	 map;
54517ca54c3Smrg	XkbControlsChangesRec	 ctrls;
54617ca54c3Smrg	XkbIndicatorChangesRec	 indicators;
54717ca54c3Smrg	XkbNameChangesRec	 names;
54817ca54c3Smrg	XkbCompatChangesRec	 compat;
54917ca54c3Smrg} XkbChangesRec, *XkbChangesPtr;
55017ca54c3Smrg
55117ca54c3Smrg	/*
552ea1d6981Smrg	 * These data structures are used to construct a keymap from
55317ca54c3Smrg	 * a set of components or to list components in the server
55417ca54c3Smrg	 * database.
55517ca54c3Smrg	 */
55617ca54c3Smrgtypedef struct _XkbComponentNames {
55717ca54c3Smrg	char *			 keymap;
55817ca54c3Smrg	char *			 keycodes;
55917ca54c3Smrg	char *			 types;
56017ca54c3Smrg	char *			 compat;
56117ca54c3Smrg	char *			 symbols;
56217ca54c3Smrg	char *			 geometry;
56317ca54c3Smrg} XkbComponentNamesRec, *XkbComponentNamesPtr;
56417ca54c3Smrg
56517ca54c3Smrgtypedef struct _XkbComponentName {
56617ca54c3Smrg	unsigned short		flags;
56717ca54c3Smrg	char *			name;
56817ca54c3Smrg} XkbComponentNameRec,*XkbComponentNamePtr;
56917ca54c3Smrg
57017ca54c3Smrgtypedef struct _XkbComponentList {
57117ca54c3Smrg	int			num_keymaps;
57217ca54c3Smrg	int			num_keycodes;
57317ca54c3Smrg	int			num_types;
57417ca54c3Smrg	int			num_compat;
57517ca54c3Smrg	int			num_symbols;
57617ca54c3Smrg	int			num_geometry;
57717ca54c3Smrg	XkbComponentNamePtr	keymaps;
57817ca54c3Smrg	XkbComponentNamePtr 	keycodes;
57917ca54c3Smrg	XkbComponentNamePtr	types;
58017ca54c3Smrg	XkbComponentNamePtr	compat;
58117ca54c3Smrg	XkbComponentNamePtr	symbols;
58217ca54c3Smrg	XkbComponentNamePtr	geometry;
58317ca54c3Smrg} XkbComponentListRec, *XkbComponentListPtr;
58417ca54c3Smrg
58517ca54c3Smrg	/*
586ea1d6981Smrg	 * The following data structures describe and track changes to a
587ea1d6981Smrg	 * non-keyboard extension device
58817ca54c3Smrg	 */
58917ca54c3Smrgtypedef struct _XkbDeviceLedInfo {
59017ca54c3Smrg	unsigned short			led_class;
59117ca54c3Smrg	unsigned short			led_id;
59217ca54c3Smrg	unsigned int			phys_indicators;
59317ca54c3Smrg	unsigned int			maps_present;
59417ca54c3Smrg	unsigned int			names_present;
59517ca54c3Smrg	unsigned int			state;
59617ca54c3Smrg	Atom 				names[XkbNumIndicators];
59717ca54c3Smrg	XkbIndicatorMapRec		maps[XkbNumIndicators];
59817ca54c3Smrg} XkbDeviceLedInfoRec,*XkbDeviceLedInfoPtr;
59917ca54c3Smrg
60017ca54c3Smrgtypedef struct _XkbDeviceInfo {
60117ca54c3Smrg	char *			name;
60217ca54c3Smrg	Atom			type;
60317ca54c3Smrg	unsigned short		device_spec;
60417ca54c3Smrg	Bool			has_own_state;
60517ca54c3Smrg	unsigned short		supported;
60617ca54c3Smrg	unsigned short		unsupported;
60717ca54c3Smrg
60817ca54c3Smrg	/* btn_acts is an array of num_btn XkbAction entries */
60917ca54c3Smrg	unsigned short		num_btns;
61017ca54c3Smrg	XkbAction *		btn_acts;
61117ca54c3Smrg
61217ca54c3Smrg	unsigned short		sz_leds;
61317ca54c3Smrg	unsigned short		num_leds;
61417ca54c3Smrg	unsigned short		dflt_kbd_fb;
61517ca54c3Smrg	unsigned short		dflt_led_fb;
61617ca54c3Smrg	/* leds is an array of XkbDeviceLedInfoRec in which
61717ca54c3Smrg	   sz_leds entries are allocated and num_leds entries are used */
61817ca54c3Smrg	XkbDeviceLedInfoPtr	leds;
61917ca54c3Smrg} XkbDeviceInfoRec,*XkbDeviceInfoPtr;
62017ca54c3Smrg
62117ca54c3Smrg#define	XkbXI_DevHasBtnActs(d)	(((d)->num_btns>0)&&((d)->btn_acts!=NULL))
62217ca54c3Smrg#define	XkbXI_LegalDevBtn(d,b)	(XkbXI_DevHasBtnActs(d)&&((b)<(d)->num_btns))
62317ca54c3Smrg#define	XkbXI_DevHasLeds(d)	(((d)->num_leds>0)&&((d)->leds!=NULL))
62417ca54c3Smrg
62517ca54c3Smrgtypedef struct _XkbDeviceLedChanges {
62617ca54c3Smrg	unsigned short		led_class;
62717ca54c3Smrg	unsigned short		led_id;
62817ca54c3Smrg	unsigned int		defined; /* names or maps changed */
62917ca54c3Smrg	struct _XkbDeviceLedChanges *next;
63017ca54c3Smrg} XkbDeviceLedChangesRec,*XkbDeviceLedChangesPtr;
63117ca54c3Smrg
63217ca54c3Smrgtypedef struct _XkbDeviceChanges {
63317ca54c3Smrg	unsigned int		changed;
63417ca54c3Smrg	unsigned short		first_btn;
63517ca54c3Smrg	unsigned short		num_btns;
63617ca54c3Smrg	XkbDeviceLedChangesRec 	leds;
63717ca54c3Smrg} XkbDeviceChangesRec,*XkbDeviceChangesPtr;
63817ca54c3Smrg
63917ca54c3Smrg#ifdef __clang__
64017ca54c3Smrg#pragma clang diagnostic pop
64117ca54c3Smrg#endif
64217ca54c3Smrg
64317ca54c3Smrg#endif /* _XKBSTR_H_ */
644