/*
 * @(#)evq_data.h 1.4 91/03/21
 */

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

/*
 * This header file defines the Event Queue related kernel data structures,
 * including the Workstation (input control), Desktop (screen managment),
 * Evqdev (event queue management).
 */

#ifndef evq_data_DEFINED
#define evq_data_DEFINED

#ifdef KERNEL
#include <sys/param.h> /* has machine/param h/types h/signal */
#include <sys/dir.h>
#include <sys/user.h>	/* has machine/pcb h/dmap h/time h/resource */
#include <sys/proc.h>
#include <sys/termios.h>
#include <sys/stropts.h>
#include <sys/stream.h>
#include <sys/vnode.h>
#include <sys/map.h>
#endif KERNEL

#include <sys/filio.h>
/* jw - ?? */
#include <npsiSun/evq_input.h>

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


#ifndef TRUE
#define TRUE    1
#endif
#ifndef FALSE
#define FALSE   0
#endif

#ifndef coord
#define coord   short
#endif

#define SCR_NAMESIZE    20
#define SCR_NORTH 	0
#define SCR_EAST        1
#define SCR_SOUTH       2
#define SCR_WEST        3
#define SCR_POSITIONS	4

typedef struct rect {
        coord   r_left, r_top;
        short   r_width, r_height;
} Rect;

#define rect_construct(r,x,y,w,h) \
        {(r)->r_left=(x);(r)->r_top=(y);(r)->r_width=(w);(r)->r_height=(h);}
#define rect_isnull(r)          ((r)->r_width == 0 || (r)->r_height == 0)
#define rect_right(rect)        ((rect)->r_left+(rect)->r_width-1)
#define rect_bottom(rect)       ((rect)->r_top+(rect)->r_height-1)

struct screen {
#ifdef SYSV
        char    scr_kbdname[SCR_NAMESIZE];/* keyboard device name */
        char    scr_msname[SCR_NAMESIZE]; /* mouse device name */
	struct rect scr_rect;		  /* position/size in device coord */
#else
	struct rect scr_rect;		/* position/size in device coord */
	int scrfd;			/* fd of screen device */ 
#endif SYSV
};

/* The shared event queue */

typedef struct evq_shared_eventqueue {
        int size;                       /* size of event buffer */
        int head;                       /* index into events */
        int tail;                       /* index into events */
        struct inputevent events[1];    /* input event buffer */
} Evq_shared_eventqueue;

/*
 * The workstation input device structure is used to describe a
 * physical input device that the kernel is polling for input.
 * The input device is opened in a user process and reopened by
 * the kernel so as to have the device's reference count bumped.
 * Input device drivers should talk in vuid (virtual user input
 * device format) although ascii will be accepted.
 */
typedef	struct	wsindev {
	int	wsid_flags;
#define	WSID_TREAT_AS_ASCII	0x01	/* Should expect ascii from this dev */
#define	WSID_DIRECT_VALID	0x02	/* "direct" flag is valid */
	long	wsid_iflag;		/* Remembered struct tios.c_iflag */
	long	wsid_oflag;		/* Remembered struct tios.c_oflag */
	long	wsid_cflag;		/* Remembered struct tios.c_cflag */
	long	wsid_lflag;		/* Remembered struct tios.c_lflag */
	struct	file *wsid_fp;		/* File ptr to open input device */
	dev_t	wsid_dev;		/* Input device */
	struct	vnode *wsid_vp;		/* Vnode ptr of open input device */
	int	*wsid_direct_flag;	/* Direct flag saved (/dev/kbd) */
	char	wsid_name[SCR_NAMESIZE];/* Device name */
	struct	wsindev *wsid_next;	/* Next node (when put as list) */
	int	wsid_previous_mode;	/* Result of VUIDGFORMAT */
} Wsindev;
#define	WSINDEV_NULL	((Wsindev *)0)
#define	WSID_DEVNONE	-1

/*
 * Evqdev data structure defines the characteristics of an event
 * queue psuedo device.
 */
struct	evqdev {
	int	ev_flags;
#define	EVF_OPEN		0x01	/* device is open */
#define	EVF_RCOLL		0x02	/* select collided */
#define	EVF_NBIO		0x04	/* non-blocking i/o wanted */
#define	EVF_WANTINPUT		0x08	/* currently waiting on input */
#define	EVF_ASYNC		0x10	/* use asyncronous input */
#define EVF_KBD_MASK_SET        0x20    /* kbd mask has been set explicitly */

	int	ev_pid;			/* pid that will be signalled */
	struct  inputmask ev_kbdmask;   /* kbd focus input mask */
        struct  inputmask ev_pickmask;  /* pick focus input mask */
	struct	proc *ev_rsel;		/* process selecting */
	struct	proc *ev_aproc;		/* proc for FIOASYNC */
	int	ev_apid;		/* pid for FIOASYNC */
};
extern struct evqdev *Evqdev;

extern	evq_errno;


/*
 * The workstation is defined to be some number of screens and some
 * number of input devices with which a single user interacts.  A single
 * workstation shares a single extant cursor among all its screens.
 */
struct	workstation {
	int	ws_flags;
#define	WSF_PRESENT		0x01	/* the workstation exists */
#define	WSF_LOC_UPDATED		0x02	/* changed locator position when read */
#define	WSF_EXITING		0x04	/* in middle of ev_close */
	/*
	 * Device management:
	 */
	struct	desktop *ws_dtop;	/* the list of desktops for workstation */
	struct	wsindev *ws_indev;	/* input devices */
	/*
	 * Input queue management (linked list):
	 */
	Vuid_queue ws_q;		/* global input q */
        Evq_shared_eventqueue *ws_sharedq;    /* shared event q */
	caddr_t	ws_qdata;		/* address of ws_q data block */
	u_int	ws_qbytes;		/* number of bytes used for ws_qdata */
	/*
	 * Virtual user input device state management:
	 */
	Vuid_state ws_instate;		/* virtual input device state that */
					/* user processes see (locator pos */
					/* data relative to ws_pickfocus's */
					/* dtop) */
	int	ws_shiftmask;		/* usertime shiftmask */
	struct	inputmask ws_surpress_mask;
					/* when send escape sequence, turn on */
					/* func key bit here so don't send up */
	/*
	 * Cursor management:
	 */
	Vuid_state ws_rtstate;		/* real time vuid state (locator pos */
					/* data relative to ws_loc_dtop) */
	struct	desktop *ws_loc_dtop;	/* desktop locator currently on */
	int	ws_quietticks;		/* # of ticks since no input received */
	int	ws_loc_stillticks;	/* # of ticks locator has been still */
	struct evqdev *ws_evq;		/* event queue */
};
extern struct workstation *Workstation;

/*
 * The desktop is a per-screen structure.
 *
 * This structure records physical attributes: whether the device
 * for the surface is present, its type (color, b/w, etc),
 * the physical addresses of the device, and the location of the
 * other screens in the system relative to this one (for use by its
 * workstation for multiplexing a single mouse among several screens.)
 */

typedef	struct	desktop {
	int	dt_flags;
#define	DTF_PRESENT		0x01	/* the screen exists */

	struct  screen dt_screen;       /* external screen description */
	struct  desktop *dt_neighbors[SCR_POSITIONS]; /* where are other dts? */
	int	dt_x;			/* x for this desktop */
	int	dt_y;			/* y for this desktop */
	struct  desktop *dt_next;	/* next desktop on this workstation */
} Desktop;
#define	DESKTOP_NULL	((Desktop *)0)


#define	spl_timeout()	spl1()

#endif evq_data_DEFINED

