/*
 * @(#)evq_input.h 1.4 91/03/12
 */

/*
 * Copyright (c) 1988 by Sun Microsystems, Inc.
 */

/*
 * Event Queue related input definitions.
 */

#ifndef	evq_input_DEFINED
#define	evq_input_DEFINED

#ifdef SYSV
#include <sys/vuid_event.h>
#else
#include <sundev/vuid_event.h>
#endif

#include <npsiSun/time.h>

/*
 * Workstation device related definitions (see <sundev/vuid_event.h>)
 * that are SunWindows window device related.
 */
#define	LOC_MOVE		(VKEY_FIRSTPSEUDO+0)		/* 32512 */
#define	LOC_STILL		(VKEY_FIRSTPSEUDO+1)		/* 32513 */
#define LOC_WINENTER            (VKEY_FIRSTPSEUDO+2)            /* 32514 */
#define LOC_WINEXIT             (VKEY_FIRSTPSEUDO+3)            /* 32515 */
#define	LOC_MOVEWHILEBUTDOWN	(VKEY_FIRSTPSEUDO+4)		/* 32516 */
#define	LOC_DRAG		LOC_MOVEWHILEBUTDOWN		/* 32516 */
#define	LOC_TRAJECTORY		(VKEY_FIRSTPSEUDO+11)		/* 32523 */
#define	KBD_USE			(VKEY_FIRSTPSEUDO+12)		/* 32524 */
#define	KBD_DONE		(VKEY_FIRSTPSEUDO+13)		/* 32525 */
#define	KBD_REQUEST		(VKEY_FIRSTPSEUDO+14)		/* 32526 */

/*
 * The inputmask consists of a input code array + flags that indicates those
 * user actions to be placed in the input queue.
 */

#define	BITSPERBYTE	8

#define VKEY_CODES      VKEY_KBD_CODES
				/* The number of the virtual keyboard device
				   codes that are contained within the input
				   mask. */

typedef	struct inputmask {
	short	im_flags;
#define	IM_NEGEVENT	(0x01)	/* send input negative events too */
#define	IM_POSASCII	(0x02)	/* OBSOLETE:no neg ASCII even if IM_NEGEVENT */
#define	IM_ANSI		(0x04)	/* OBSOLETE: ansi with funcs encoded in ESC[ */
#define	IM_UNENCODED	(0x08)	/* OBSOLETE: pure device codes */
#define	IM_ASCII	(0x10)	/* enable ASCII codes 0-127 */
#define	IM_META		(0x20)	/* enable META codes 128-255 */
#define	IM_NEGASCII	(0x40)	/* enable negative ASCII codes 0-127 */
#define	IM_NEGMETA	(0x80)	/* enable negative META codes 128-255 */
#define	IM_TOP		(0x100)	/* enable TOP codes 256-511 */
#define	IM_NEGTOP	(0x200)	/* enable negative TOP codes 256-511 */
#define	IM_INTRANSIT	(0x400)	/* don't surpress locator events when
				   in-transit over window */
#define	IM_CODEARRAYSIZE (VKEY_CODES/((sizeof(char))*BITSPERBYTE))
	char	im_inputcode[IM_CODEARRAYSIZE];
	short   im_shifts;              /* OBSOLETE */
#define IM_SHIFTARRAYSIZE (sizeof(short)*BITSPERBYTE)
        short   im_shiftcodes[IM_SHIFTARRAYSIZE]; /* OBSOLETE */
} Inputmask;

#define	INPUTMASK_NULL	((Inputmask *)0)

#define isworkstationdevid(code) \
	( (( (code) >> 8 ) & 0xff) == WORKSTATION_DEVID )
#define	evq_setinputcodebit(im,code) \
	(im)->im_inputcode[((code)-VKEY_FIRST)/BITSPERBYTE] |= \
		(isworkstationdevid(code))? \
	    (1<<((BITSPERBYTE-1)-(((code)-VKEY_FIRST)%BITSPERBYTE))): \
	    0
#define	evq_unsetinputcodebit(im,code) \
	(im)->im_inputcode[((code)-VKEY_FIRST)/BITSPERBYTE] &= \
		(isworkstationdevid(code))? \
	    (~(1<<((BITSPERBYTE-1)-(((code)-VKEY_FIRST)%BITSPERBYTE)))): \
	    0xff
#define	evq_getinputcodebit(im,code) \
	((isworkstationdevid(code))? \
	((im)->im_inputcode[((code)-VKEY_FIRST)/BITSPERBYTE] & \
	    (1<<((BITSPERBYTE-1)-(((code)-VKEY_FIRST)%BITSPERBYTE)))): 0)


/*
 * An input event structure is that which is filled in on a readrecord call.
 * ie_code contains the input code involved.  IE_NEGEVENT is used to indicate
 * a negative event.
 *
 * ie_shiftmask contains selected shift state.
 *
 * The locator position (window relative) is placed in ie_loc*.
 * The time of the input event is put in ie_time (seconds & microseconds).
 * Time zone and daylight savings flag available via system call.
 */

typedef	struct	inputevent {
	short	ie_code;		/* input code */
	short	ie_flags;
#define	IE_NEGEVENT	(0x01)		/* input code is negative */
	short	ie_shiftmask;		/* input code shift state */
#ifndef	CAPSLOCK	/* Same as sundev/kbd.h */
#define	CAPSLOCK	0		/* Caps Lock key */
#define	CAPSMASK	0x0001
#define	SHIFTLOCK	1		/* Shift Lock key */
#define	LEFTSHIFT	2		/* Left-hand shift key */
#define	RIGHTSHIFT	3		/* Right-hand shift key */
#define	SHIFTMASK	0x000E
#define	LEFTCTRL	4		/* Left-hand (or only) control key */
#define	RIGHTCTRL	5		/* Right-hand control key */
#define	CTRLMASK	0x0030
#endif	CAPSLOCK
#ifndef	META_SHIFT_MASK
#define	META_SHIFT_MASK	0x0040		/* Meta shift mask */
					/* Same as 'unused...	0x0040' in */
					/* sundev/kbd.h */
#endif	META_SHIFT_MASK
	short	ie_locx, ie_locy;	/* locator (usually a mouse) position */
	struct	timeval ie_time;	/* time of event */
} Event;

typedef struct {
    unsigned short  ceiling;
    unsigned short  factor;
}   Ev_scale;

#define WS_SCALE_MAX_COUNT      16
#define WS_SCALE_MAX_CEILING 0xffff

typedef struct {
    Ev_scale        scales[WS_SCALE_MAX_COUNT];
}   Ev_scale_list;

#endif	evq_input_DEFINED

