/*
 * @(#)sunosi.h 1.14 91/06/24
 */

#ifndef _sunosi_h
#define _sunosi_h

/* these should be moved after all the system header files
 * There is currently a conflict with input.h declaring
 * event_action as an enumerated type, and sunwindow/win_input.h
 * defining event_action as a macro. Therefore, input.h must
 * be included first.  someday.....
 */
#include <NeWS/PostScript.h>
#include <NeWS/input.h>
#include <NeWS/environ.h>
#include <npsiSun/time.h>

/*
 * Using a non-modified version of struct pixrect so match
 * the structure used by the kernel.  The NeWS version of
 * struct pixrect has an extra int in it.
 */
#ifdef SYSV
#include <sys/pixrect.h>
#include <sys/pr_util.h>
#include <sys/memvar.h>
#include <sys/pr_planegroups.h>
#include <sys/rect.h>
#include <sys/rectlist.h>
#include <sys/win_screen.h>
#include <sys/win_struct.h>
#include <sys/cms.h>
#include <sys/win_input.h>
#include <sys/win_ioctl.h>
#include <sys/win_cursor.h>
#include <sys/win_lock.h>
#else /* SYSV */
#include <pixrect/pixrect.h>
#include <pixrect/pr_util.h>
#include <pixrect/memvar.h>
#include <pixrect/pr_planegroups.h>
#include <sunwindow/rect.h>
#include <sunwindow/rectlist.h>
#include <sunwindow/win_screen.h>
#include <sunwindow/win_struct.h>
#include <sunwindow/cms.h>
#include <sunwindow/win_input.h>
#include <sunwindow/win_ioctl.h>
#include <sunwindow/win_cursor.h>
#include <sunwindow/win_lock.h>
#endif /* SYSV */

struct sunwin {
    int		fd;
    int		placeholder_fd;
    int		sunCreatedRoot;
    int		sun_winnum;
    int		sun_clipid;
    int		sun_lockcount;
    int		sun_heavy_unlock;
    int         sun_ms_focus;
    int         sun_kbd_focus;
    Rect	sun_wl_rect;
    Rectlist	sun_rl_latest;
    Win_lock_block	*sun_win_lock;

    /* Dummy windows to preserve xnews-created colormap segments */
    int		monoseg_fd;			
    int		defseg_fd;
};

#define osprivate(scr)	((struct sunwin *)((scr)->ospriv))

#define	INPBUFSIZE	256
#define MAX_ENTRIES 10
#define DEFAULTKBDDEV   "/dev/kbd"

#define CAN_USE_SUNWINDOW_DRIVER(screen) \
    (((VISUAL_INFO)Get_Raster((screen)->display,RAS_VISUAL_INFO))->sv_support_level !=  \
							SUNVIEW_NOT_SUPPORTED)

#define CAN_RUN_SUNVIEW_APPS(screen) \
    (((VISUAL_INFO)Get_Raster((screen)->display,RAS_VISUAL_INFO))->sv_support_level == \
							SUNVIEW_INPUT_AND_APPS)

/*
 * KIOCLAYOUT, etc. are only defined on 4.1 systems.
 * This allows us to build on 4.0.x
 */

#ifndef KIOCLAYOUT
#define KIOCLAYOUT	_IOR(k, 20, int)
#define KIOCSLED        _IOW(k, 14, char)
#define KIOCGLED        _IOR(k, 15, char)
#define LED_NUM_LOCK	0x01
#define LED_COMPOSE	0x02
#define LED_SCROLL_LOCK	0x04
#define LED_CAPS_LOCK	0x08
#endif

struct xnews_wsq_node {
    struct inputevent		wsqn_event;
    SCREENINFO			wsqn_screen;
    short			wsqn_prev;	/* Not currently used */
    short			wsqn_next;	/* Not currently used */
    char			devid;		/* Device Id */
};

struct xnews_wsq {
    struct xnews_wsq_node 	wsq_events[INPBUFSIZE];
    short			wsq_first;	/* Not currently used */
    short			wsq_last;
    int				wsq_kbdtrans;
};

enum kbd_translation {
    UNENCODED_KEYBOARD, NORMAL_KEYBOARD
};

struct  hosts_entry {
  char inet_num[20];
  char name[40];
};

struct  pos_struct {
    int x, y;
    int fd;
};

struct InputDevStruct {		/* Dynamic Input Device structure */
    int		fd;			/* file descriptor of device */
    char	devid;			/* Device Identification */
    char	devname[32];		/* eg. "/dev/kbd", "/dev/mouse" */
    char	libname[32];		/* shared library name */
    void	*dlhandle;		/* jw - not sure if this is useful */
    int		(*InitInputDev)();	/* Initialize device and library */
    int		(*InputPending)();	/* returns TRUE if pending input */
    void	(*ReadInputDev)();	/* sorts and stuffs events onto q */
    int		(*ProcessInput)();	/* process and send event up */
    int		(*CntrlInputDev)();	/* miscellaneous control */
    int		(*TerminateInputDev)();	/* clean up and close down device */
    caddr_t	privatedata;		/* just in case... */
};

/* jw - we should probably come up with something better than this,
 *	but for the time being, let's just get it working.
 */
#define MAXINPUTDEVS	8	/* PFA */
extern struct InputDevStruct  InputDevice[MAXINPUTDEVS];
extern int InputDevCount;

/* Hardcoded Device IDs */
#define	PRIVDEV		0	/* Used for sunwindowdev or evq device */
#define MSDEV		1	/* Mouse will always be entry 1 */
#define KBDDEV		2	/* Keyboard will always be entry 2 */

/* these routines are declared in osi_screen.c and defined by any one of
 * the shared libraries libSunWIN, libSunEVQ, libSunVUID, etc.
 */
extern void (*ringbell)();
extern int  (*svenv_get)();
extern void (*svenv_setserver)();
extern void (*lockdevice)();
extern void (*unlockdevice)();
extern void (*update_colors)();
extern void (*window_acquire)();
extern int  (*setscreenposition)();
extern void (*setmouseposition)();
extern int  (*setmstranslation)();
extern void (*startkbdandms)();
extern void (*enable_kbd_input)();
extern void (*enable_pick_input)();
extern void (*get_seg_info)();

#ifdef DEBUG
#	define PrintEventCode(a, b)		PrintEventCodeFunc(a, b)
#	define TraceEvent(cond, code)		if (cond) code
	extern int PrintEventCodeIsOn;
#else
#	define PrintEventCode(a, b)
#	define TraceEvent(cond, code) 
#endif

/* when screensaver has kicked on, check core devices if cursor is in a
 * sunview window
 */
#define CHECK_DEVICE_TIME 1		/* seconds */

#endif /* _sunosi_h */

