X11R4 patch for SCO XENIX (part02)

Chain Lee chain at paul.rutgers.edu
Mon Jan 7 13:22:13 AEST 1991


*** X11R4.ORIG/mit/server/ddx/xenix/vga/kbd_mode.c	Sun Jan  6 01:03:01 1991
--- X11R4/mit/server/ddx/xenix/vga/kbd_mode.c	Sat Jan  5 17:50:19 1991
***************
*** 0 ****
--- 1,107 ----
+ /*
+  * kbd_mode.c			Modified for Xenix by Chain Lee 08/90
+  */
+ 
+ /************************************************************
+ Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
+ 
+                     All Rights Reserved
+ 
+ Permission  to  use,  copy,  modify,  and  distribute   this
+ software  and  its documentation for any purpose and without
+ fee is hereby granted, provided that the above copyright no-
+ tice  appear  in all copies and that both that copyright no-
+ tice and this permission notice appear in  supporting  docu-
+ mentation,  and  that the names of Sun or MIT not be used in
+ advertising or publicity pertaining to distribution  of  the
+ software  without specific prior written permission. Sun and
+ M.I.T. make no representations about the suitability of this
+ software for any purpose. It is provided "as is" without any
+ express or implied warranty.
+ 
+ SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+ NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+ PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ 
+ ********************************************************/
+ 
+ #ifndef lint
+ static  char sccsid[] = "@(#)kbd_mode.c 7.1 87/04/13";
+ #endif
+ 
+ /*
+  * Copyright (c) 1986 by Sun Microsystems, Inc.
+  *
+  *      kbd_mode:       set keyboard encoding mode
+  */
+ 
+ #include <sys/types.h>
+ #include <fcntl.h>
+ #include <sys/vtkd.h>
+ #include <stdio.h>
+ 
+ static void	die(), usage();
+ static int	kbd_fd=0;
+ 
+ main(argc, argv)
+ int	argc;
+ char	*argv[];
+ {
+ 	int	code, translate;
+ 
+ 	argc--; 
+ 	argv++;
+ 	if (argc-- && **argv == '-') {
+ 		code = *(++*argv);
+ 	} else {
+ 		usage();
+ 	}
+ 	switch (code) {
+ 	case 'a':
+ 	case 'A':
+ 		translate = K_XLATE;
+ 		break;
+ 	case 'r':
+ 	case 'R':
+ 		translate = K_RAW;
+ 		break;
+ 	default:
+ 		usage();
+ 	}
+ 	if (ioctl(kbd_fd, KDSKBMODE, translate)) {
+ 		die("Couldn't initialize translation to Event");
+ 	}
+ 	exit(0);
+ }
+ 
+ static void
+ die(msg)
+ char	*msg;
+ {
+ 	fprintf(stderr, "%s\n", msg);
+ 	exit(1);
+ }
+ 
+ static void
+ usage()
+ {
+ 	int	translate;
+ #if XENIX_HAS_NO_BUGS
+ 	if ((translate = ioctl(kbd_fd, KDGKBMODE, &translate)) == -1) {
+ 		die("Couldn't inquire current translation");
+ 	}
+ #endif
+ 	fprintf(stderr, "kbd_mode { -a | -r }\n");
+ 	fprintf(stderr, "\tfor ascii, or raw event.\n");
+ 	fprintf(stderr, "Current mode is %s.\n",
+ 	    ( translate == K_XLATE ?    "a (ascii bytes)" :
+ 	    ( translate == K_RAW ? "r (raw events)" : "unknown mode")));
+ 	exit(1);
+ }
+ 
+ 
*** X11R4.ORIG/mit/server/ddx/xenix/vga/xenixKbd.c	Sun Jan  6 01:03:03 1991
--- X11R4/mit/server/ddx/xenix/vga/xenixKbd.c	Mon Dec 10 00:26:22 1990
***************
*** 0 ****
--- 1,500 ----
+ /*
+  * xenixKbd.c			Modified for Xenix by Chain Lee 08/90
+  */
+ 
+ /*-
+  *
+  * Copyright (c) 1987 by the Regents of the University of California
+  *
+  * Permission to use, copy, modify, and distribute this
+  * software and its documentation for any purpose and without
+  * fee is hereby granted, provided that the above copyright
+  * notice appear in all copies.  The University of California
+  * makes no representations about the suitability of this
+  * software for any purpose.  It is provided "as is" without
+  * express or implied warranty.
+  *
+  */
+ 
+ /************************************************************
+ Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
+ 
+                     All Rights Reserved
+ 
+ Permission  to  use,  copy,  modify,  and  distribute   this
+ software  and  its documentation for any purpose and without
+ fee is hereby granted, provided that the above copyright no-
+ tice  appear  in all copies and that both that copyright no-
+ tice and this permission notice appear in  supporting  docu-
+ mentation,  and  that the names of Sun or MIT not be used in
+ advertising or publicity pertaining to distribution  of  the
+ software  without specific prior written permission. Sun and
+ M.I.T. make no representations about the suitability of this
+ software for any purpose. It is provided "as is" without any
+ express or implied warranty.
+ 
+ SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+ NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+ PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ 
+ ********************************************************/
+ 
+ #define NEED_EVENTS
+ #include "xenix.h"
+ #include "Xproto.h"
+ #include "keysym.h"
+ #include "inputstr.h"
+ 
+ typedef struct {
+     int	    	  trans;          	/* Original translation form */
+ } SunKbPrivRec, *SunKbPrivPtr;
+ 
+ extern CARD8 *xenixModMap[];
+ extern CARD8 ibmAT101ModMap[];
+ extern KeySymsRec xenixKeySyms[];
+ 
+ extern CARD8 keyCodePrefix1, keyCodePrefix2, keyCodeCapsLock;
+ 
+ extern void	ProcessInputEvents();
+ extern void	miPointerPosition();
+ 
+ static void 	xenixBell();
+ static void 	xenixKbdCtrl();
+ void	 	xenixKbdProcessEvent();
+ static void 	xenixKbdDoneEvents();
+ 
+ int		click = 0;
+ 
+ int	  	autoRepeatKeyDown = 0;
+ int	  	autoRepeatDebug = 0;
+ int	  	autoRepeatReady;
+ long	  	autoRepeatInitiate = 1000 * AUTOREPEAT_INITIATE;
+ long	  	autoRepeatDelay = 1000 * AUTOREPEAT_DELAY;
+ static int	autoRepeatFirst;
+ struct timeval  autoRepeatLastKeyDownTv;
+ struct timeval  autoRepeatDeltaTv;
+ 
+ static KeybdCtrl sysKbCtrl;
+ 
+ static KbPrivRec	sysKbPriv = {
+     -1,				/* Type	of keyboard */
+     xenixKbdProcessEvent,	/* Function to process an event	*/
+     xenixKbdDoneEvents,		/* Function called when	all events */
+ 				/* have	been handled. */
+     (pointer) NULL,		/* Private to keyboard device */
+     0,				/* offset for device keycodes */
+     &sysKbCtrl,			/* Initial full	duration = .20 sec. */
+ };
+ 
+ static void
+ sigsegv(){
+     reset_tty(0);
+     ev_close();
+     abort();
+ }
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixKbdProc --
+  *	Handle the initialization, etc. of a keyboard.
+  *
+  * Results:
+  *	None.
+  *
+  * Side Effects:
+  *
+  * Note:
+  *	When using xenixwindows, all input comes off a single fd, stored in the
+  *	global windowFd.  Therefore, only one device should be enabled and
+  *	disabled, even though the application still sees both mouse and
+  *	keyboard.  We have arbitrarily chosen to enable and disable windowFd
+  *	in the keyboard routine xenixKbdProc rather than in xenixMouseProc.
+  *
+  *-----------------------------------------------------------------------
+  */
+ int
+ xenixKbdProc (pKeyboard, what)
+     DevicePtr	  pKeyboard;	/* Keyboard to manipulate */
+     int	    	  what;	    	/* What to do to it */
+ {
+     int		qfd;
+     dmask_t	dmask =	D_STRING | D_REL | D_BUTTON;
+     static int	kbdFd=0;
+ 
+     switch (what) {
+ 	case DEVICE_INIT:
+ 
+ 	    signal(SIGSEGV, sigsegv);
+ 
+ 	    if (pKeyboard != LookupKeyboardDevice()) {
+ 		ErrorF ("Cannot open non-system keyboard");
+ 		return (!Success);
+ 	    }
+ 	    
+ 	    /*
+ 	     * First open the event manager.
+ 	     */
+ 	    if (ev_init() < 0) {
+ 		ErrorF("xenixKbdProc: cannot init event manager\n");
+ 		return (!Success); 
+ 	    }
+ 	    if ((qfd = ev_open(&dmask)) < 0) {
+ 	    	ErrorF("xenixKbdProc: cannot open event manager\n");
+ 	    	return (!Success);
+ 	    }
+ 	    if (dmask != (D_STRING | D_REL | D_BUTTON)) {
+ 	    	Error("xenixKbdProc: cannot attach mouse and keyboard\n");
+ 	    	return (!Success);
+ 	    }
+ 
+ 	    pKeyboard->devicePrivate = (pointer)&sysKbPriv;
+ 	    pKeyboard->on = FALSE;
+ 	    sysKbCtrl =	defaultKeyboardControl;
+ 	    sysKbPriv.ctrl = &sysKbCtrl;
+ 
+ 	    sysKbPriv.type = KBTYPE_IBMAT;
+ 	    if (xenixKeySyms[sysKbPriv.type].minKeyCode	< MIN_KEYCODE) {
+ 		int offset=MIN_KEYCODE-xenixKeySyms[sysKbPriv.type].minKeyCode;
+ 
+ 		xenixKeySyms[sysKbPriv.type].minKeyCode	+= offset;
+ 		xenixKeySyms[sysKbPriv.type].maxKeyCode	+= offset;
+ 		sysKbPriv.offset = offset;
+ 	    }
+ 
+ 	    /* set up keyboard for raw event generating mode */
+ 	    /* set up tty to raw mode */
+ 	    set_tty(0);
+ 
+ 	    InitKeyboardDeviceStruct(
+ 		    pKeyboard,
+ 		    &(xenixKeySyms[sysKbPriv.type]),
+ 		    (xenixModMap[sysKbPriv.type]),
+ 		    xenixBell,
+ 		    xenixKbdCtrl);
+ 	    break;
+ 
+ 	case DEVICE_ON:
+ /*	    AddEnabledDevice(windowFd);
+ */	    pKeyboard->on = TRUE;
+ 	    break;
+ 
+ 	case DEVICE_OFF:
+ /*	    RemoveEnabledDevice(kbdFd);
+ */	    pKeyboard->on = FALSE;
+ 	    break;
+ 	case DEVICE_CLOSE:
+ /*	    RemoveEnabledDevice(kbdFd);
+ */	    pKeyboard->on = FALSE;
+ 	    reset_tty(0);
+ 	    ev_close();
+ 	    break;
+     }
+     return (Success);
+ }
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixBell --
+  *	Ring the terminal/keyboard bell
+  *
+  * Results:
+  *	Ring the keyboard bell for an amount of time proportional to
+  *	"loudness."
+  *
+  * Side Effects:
+  *	None, really...
+  *
+  *-----------------------------------------------------------------------
+  */
+ static void
+ xenixBell (loudness, pKeyboard)
+     int	    	  loudness;	    /* Percentage of full volume */
+     DevicePtr	  pKeyboard;	    /* Keyboard to ring */
+ {
+     static int	bell_fd = -1;
+  
+     if (loudness == 0) {
+  	return;
+     }
+     if (bell_fd < 0)
+     	if ((bell_fd = open("/dev/bell", O_RDWR, 0)) < 0) {
+ 	    ErrorF("xenixBell: cannot \"/dev/bell\"\n");
+ 	    return;
+ 	}
+     write(bell_fd, "\002", 1 );
+     nap(loudness);
+     write(bell_fd,"\003",1);
+ }
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixKbdCtrl --
+  *	Alter some of the keyboard control parameters
+  *
+  * Results:
+  *	None.
+  *
+  * Side Effects:
+  *	Some...
+  *
+  *-----------------------------------------------------------------------
+  */
+ static void
+ xenixKbdCtrl (pKeyboard, ctrl)
+     DevicePtr	  pKeyboard;	    /* Keyboard to alter */
+     KeybdCtrl     *ctrl;
+ {
+     /* LEDS */
+     ioctl(0, KDSETLED, ctrl->leds);
+     /* keyboard click */
+     click = ctrl->click;
+ }
+ 
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixKbdProcessEvent --
+  *
+  * Results:
+  *
+  * Side Effects:
+  *
+  * Caveat:
+  *      To reduce duplication of code and logic (and therefore bugs), the
+  *      xenixwindows version of kbd processing (xenixKbdProcessEventSunWin())
+  *      counterfeits a firm event and calls this routine.  This
+  *      couunterfeiting relies on the fact this this routine only looks at the
+  *      id, time, and value fields of the firm event which it is passed.  If
+  *      this ever changes, the xenixKbdProcessEventSunWin will also have to
+  *      change.
+  *
+  *-----------------------------------------------------------------------
+  */
+ void
+ xenixKbdProcessEvent (pKeyboard, evp)
+     DevicePtr	  pKeyboard;
+     EVENT	  *evp;
+ {
+     xEvent		xE;
+     int			delta;
+     static xEvent	autoRepeatEvent;
+     BYTE		key;
+     CARD8		keyModifiers;
+     
+     /* we need to encode three states of the cap lock key */
+     static int		capsLockDown = 0;
+     static int		capsLockOn = 0;
+ 
+ #if OK
+     if (autoRepeatKeyDown && fe->id == AUTOREPEAT_EVENTID) {
+ 	pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
+ 	if (pPriv->ctrl->autoRepeat != AutoRepeatModeOn) {
+ 		autoRepeatKeyDown = 0;
+ 		return;
+ 	}
+ 	/*
+ 	 * Generate auto repeat event.	XXX one for now.
+ 	 * Update time & pointer location of saved KeyPress event.
+ 	 */
+ 	if (autoRepeatDebug)
+ 	    ErrorF("xenixKbdProcessEvent: autoRepeatKeyDown = %d\n",
+ 			autoRepeatKeyDown);
+ 
+ 	delta = TVTOMILLI(autoRepeatDeltaTv);
+ 	autoRepeatFirst = FALSE;
+ 
+ 	/*
+ 	 * Fake a key up event and a key down event
+ 	 * for the last key pressed.
+ 	 */
+ 	autoRepeatEvent.u.keyButtonPointer.time += delta;
+ 	miPointerPosition (screenInfo.screens[0],
+ 			   &autoRepeatEvent.u.keyButtonPointer.rootX,
+ 			   &autoRepeatEvent.u.keyButtonPointer.rootY);
+ 	autoRepeatEvent.u.u.type = KeyRelease;
+ 	(* pKeyboard->processInputProc) (&autoRepeatEvent, pKeyboard, 1);
+ 
+ 	autoRepeatEvent.u.u.type = KeyPress;
+ 	(* pKeyboard->processInputProc) (&autoRepeatEvent, pKeyboard, 1);
+ 
+ 	/* Update time of last key down */
+ 	tvplus(autoRepeatLastKeyDownTv, autoRepeatLastKeyDownTv, 
+ 			autoRepeatDeltaTv);
+ 
+ 	return;
+     }
+ #endif
+ 
+     key = EV_BUF(*evp)[0];
+ 
+     /* caps lock flip flop */
+     if (key == (0x80 | keyCodeCapsLock)) {
+     	capsLockDown = 0;
+ 	return;
+     }
+ 
+     if (key == keyCodeCapsLock) {
+     	if (capsLockDown)
+ 	    return;
+ 	else 
+ 	    capsLockDown = 1;
+  
+ 	if (capsLockOn) {
+ 	    EV_BUF(*evp)[0] |= 0x80;
+ 	    capsLockOn = 0;
+ 	}
+ 	else
+ 	{
+ 	    capsLockOn = 1;
+ 	}
+     }
+ 
+     /* keyboard click */
+     if (!(key & 0x80)) 
+ 	if (click >= 0)
+ 	    xenixBell(click, pKeyboard);
+ 
+     key &= 0x7f;
+ 
+ /*
+     keyModifiers = ((DeviceIntPtr)pKeyboard)->key->modifierMap[key];
+ */
+     keyModifiers = ibmAT101ModMap[key];
+     key += sysKbPriv.offset;
+ 
+         if (autoRepeatKeyDown && (keyModifiers == 0) &&
+ 	(!(EV_BUF(*evp)[0] & 0x80) || (key == autoRepeatEvent.u.u.detail))) {
+ 	/*
+ 	 * Kill AutoRepeater on any real non-modifier key down, or auto key up
+ 	 */
+ 	autoRepeatKeyDown = 0;
+ 	if (autoRepeatDebug)
+ 	    ErrorF("xenixKbdProcessEvent: autoRepeat off\n");
+     }
+ 
+     xE.u.keyButtonPointer.time = EV_TIME(*evp);
+     miPointerPosition (screenInfo.screens[0],
+ 		       &xE.u.keyButtonPointer.rootX,
+ 		       &xE.u.keyButtonPointer.rootY);
+     xE.u.u.type = ((EV_BUF(*evp)[0] & 0x80) ? KeyRelease : KeyPress);
+     xE.u.u.detail = key;
+ 
+ #if OK
+     if (keyModifiers & LockMask) {
+ 	if (xE.u.u.type == KeyRelease)
+ 	    return; /* this assumes autorepeat is not desired */
+ 	if (BitIsOn(((DeviceIntPtr)pKeyboard)->key->down, key))
+ 	    xE.u.u.type = KeyRelease;
+     }
+ 
+     if ((xE.u.u.type == KeyPress) && (keyModifiers == 0)) {
+ 	/* initialize new AutoRepeater event & mark AutoRepeater on */
+ 	if (autoRepeatDebug)
+             ErrorF("xenixKbdProcessEvent: VKEY_DOWN\n");
+ 	autoRepeatEvent = xE;
+ 	autoRepeatFirst = TRUE;
+ 	autoRepeatKeyDown++;
+ 	autoRepeatLastKeyDownTv = EV_TIME(*evp);
+     }
+ #endif
+     (* pKeyboard->processInputProc) (&xE, pKeyboard, 1);
+ }
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixDoneEvents --
+  *	Nothing to do, here...
+  *
+  * Results:
+  *
+  * Side Effects:
+  *
+  *-----------------------------------------------------------------------
+  */
+ /*ARGSUSED*/
+ static void
+ xenixKbdDoneEvents (pKeyboard)
+     DevicePtr	  pKeyboard;
+ {
+ 
+ }
+ 
+ /*ARGSUSED*/
+ Bool
+ LegalModifier(key)
+ {
+     return (TRUE);
+ }
+ 
+ static KeybdCtrl *pKbdCtrl = (KeybdCtrl *) 0;
+ 
+ /*ARGSUSED*/
+ void
+ xenixBlockHandler(nscreen, pbdata, pptv, pReadmask)
+     int nscreen;
+     pointer pbdata;
+     struct timeval **pptv;
+     pointer pReadmask;
+ {
+     static struct timeval artv = { 0, 0 };	/* autorepeat timeval */
+ #if OK
+     if (!autoRepeatKeyDown)
+ 	return;
+ 
+     if (pKbdCtrl == (KeybdCtrl *) 0)
+ 	pKbdCtrl = ((KbPrivPtr) LookupKeyboardDevice()->devicePrivate)->ctrl;
+ 
+     if (pKbdCtrl->autoRepeat != AutoRepeatModeOn)
+ 	return;
+ 
+     if (autoRepeatFirst == TRUE)
+ 	artv.tv_usec = autoRepeatInitiate;
+     else
+ 	artv.tv_usec = autoRepeatDelay;
+     *pptv = &artv;
+ 
+     if (autoRepeatDebug)
+ 	ErrorF("xenixBlockHandler(%d,%d): \n", artv.tv_sec, artv.tv_usec);
+ #endif
+ }
+ 
+ /*ARGSUSED*/
+ void
+ xenixWakeupHandler(nscreen, pbdata, err, pReadmask)
+     int nscreen;
+     pointer pbdata;
+     unsigned long err;
+     pointer pReadmask;
+ {
+     struct timeval tv;
+ #if OK
+     if (autoRepeatDebug)
+ 	ErrorF("xenixWakeupHandler(ar=%d, err=%d):\n", autoRepeatKeyDown, err);
+ 
+     if (pKbdCtrl == (KeybdCtrl *) 0)
+ 	pKbdCtrl = ((KbPrivPtr) LookupKeyboardDevice()->devicePrivate)->ctrl;
+ 
+     if (pKbdCtrl->autoRepeat != AutoRepeatModeOn)
+ 	return;
+ 
+     if (autoRepeatKeyDown) {
+ 	gettimeofday(&tv, (struct timezone *) NULL);
+ 	tvminus(autoRepeatDeltaTv, tv, autoRepeatLastKeyDownTv);
+ 	if (autoRepeatDeltaTv.tv_sec > 0 ||
+ 			(!autoRepeatFirst && autoRepeatDeltaTv.tv_usec >
+ 				autoRepeatDelay) ||
+ 			(autoRepeatDeltaTv.tv_usec >
+ 				autoRepeatInitiate))
+ 		autoRepeatReady++;
+     }
+     
+     if (autoRepeatReady)
+ 	ProcessInputEvents();
+     autoRepeatReady = 0;
+ #endif
+ }
*** X11R4.ORIG/mit/server/ddx/xenix/vga/xenixMouse.c	Sun Jan  6 01:03:07 1991
--- X11R4/mit/server/ddx/xenix/vga/xenixMouse.c	Mon Dec 10 00:31:49 1990
***************
*** 0 ****
--- 1,367 ----
+ /*
+  * xenixMouse.c			Modified for Xenix by Chain Lee 08/90
+  */
+ 
+ /*-
+  * sunMouse.c --
+  *	Functions for playing cat and mouse... sorry.
+  *
+  * Copyright (c) 1987 by the Regents of the University of California
+  *
+  * Permission to use, copy, modify, and distribute this
+  * software and its documentation for any purpose and without
+  * fee is hereby granted, provided that the above copyright
+  * notice appear in all copies.  The University of California
+  * makes no representations about the suitability of this
+  * software for any purpose.  It is provided "as is" without
+  * express or implied warranty.
+  *
+  *
+  */
+ 
+ /************************************************************
+ Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
+ 
+                     All Rights Reserved
+ 
+ Permission  to  use,  copy,  modify,  and  distribute   this
+ software  and  its documentation for any purpose and without
+ fee is hereby granted, provided that the above copyright no-
+ tice  appear  in all copies and that both that copyright no-
+ tice and this permission notice appear in  supporting  docu-
+ mentation,  and  that the names of Sun or MIT not be used in
+ advertising or publicity pertaining to distribution  of  the
+ software  without specific prior written permission. Sun and
+ M.I.T. make no representations about the suitability of this
+ software for any purpose. It is provided "as is" without any
+ express or implied warranty.
+ 
+ SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+ NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+ PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ 
+ ********************************************************/
+ 
+ #define	NEED_EVENTS
+ 
+ #include    "xenix.h"
+ #include    "mipointer.h"
+ #include    "misprite.h"
+ 
+ #define	ABS(a)	(((a)>0)?(a):-(a))
+ 
+ Bool ActiveZaphod = TRUE;
+ 
+ extern void xenixSuspendX();
+ 
+ static long xenixEventTime();
+ static Bool xenixCursorOffScreen();
+ static void xenixCrossScreen();
+ extern void miPointerQueueEvent();
+ 
+ miPointerCursorFuncRec xenixPointerCursorFuncs = {
+     xenixEventTime,
+     xenixCursorOffScreen,
+     xenixCrossScreen,
+     miPointerQueueEvent,
+ };
+ 
+ typedef struct {
+     int	    bmask;	    /* Current button state */
+     Bool    mouseMoved;	    /* Mouse has moved */
+ } XenixMsPrivRec, *XenixMsPrivPtr;
+ 
+ static void 	  	xenixMouseCtrl();
+ static int 	  	xenixMouseGetMotionEvents();
+ void	 	  	xenixMouseProcessEvent();
+ static void 	  	xenixMouseDoneEvents();
+ 
+ static XenixMsPrivRec	xenixMousePriv;
+ static PtrPrivRec	sysMousePriv = {
+     xenixMouseProcessEvent,	/* Function to process an event	*/
+     xenixMouseDoneEvents,		/* When	all the	events have been */
+ 				/* handled, this function will be */
+ 				/* called. */
+     0,				/* Current X coordinate	of pointer */
+     0,				/* Current Y coordinate	*/
+     (pointer)&xenixMousePriv,	/* Field private to device */
+ };
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixMouseProc --
+  *	Handle the initialization, etc. of a mouse
+  *
+  * Results:
+  *	none.
+  *
+  * Side Effects:
+  *
+  * Note:
+  *	When using xenixwindows, all input comes off a single fd, stored in the
+  *	global windowFd.  Therefore, only one device should be enabled and
+  *	disabled, even though the application still sees both mouse and
+  *	keyboard.  We have arbitrarily chosen to enable and disable windowFd
+  *	in the keyboard routine xenixKbdProc rather than in xenixMouseProc.
+  *
+  *-----------------------------------------------------------------------
+  */
+ int
+ xenixMouseProc (pMouse, what)
+     DevicePtr	  pMouse;   	/* Mouse to play with */
+     int	    	  what;	    	/* What to do with it */
+ {
+     register int  fd;
+     int	    	  format;
+     static int	  oformat;
+     BYTE    	  map[4];
+ 
+     switch (what) {
+ 	case DEVICE_INIT:
+ 	    if (pMouse != LookupPointerDevice()) {
+ 		ErrorF ("Cannot open non-system mouse");	
+ 		return (!Success);
+ 	    }
+ 
+ 	    sysMousePriv.x = 0;
+ 	    sysMousePriv.y = 0;
+ 
+ 	    xenixMousePriv.mouseMoved =	FALSE;
+ 	    pMouse->devicePrivate = (pointer) &sysMousePriv;
+ 
+ 	    pMouse->on = FALSE;
+ 	    map[1] = 1;
+ 	    map[2] = 2;
+ 	    map[3] = 3;
+ 	    InitPointerDeviceStruct(
+ 		pMouse, map, 3, xenixMouseGetMotionEvents, xenixMouseCtrl, 0);
+ 	    break;
+ 
+ 	case DEVICE_ON:
+ 
+ /*	    AddEnabledDevice (((PtrPrivPtr)pMouse->devicePrivate)->fd);
+ */
+ 	    pMouse->on = TRUE;
+ 	    break;
+ 
+ 	case DEVICE_CLOSE:
+ 	    break;
+ 
+ 	case DEVICE_OFF:
+ /*	    RemoveEnabledDevice (((PtrPrivPtr)pMouse->devicePrivate)->fd);
+ */	    pMouse->on = FALSE;
+ 	    break;
+     }
+     return (Success);
+ }
+ 	    
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixMouseCtrl --
+  *	Alter the control parameters for the mouse. Since acceleration
+  *	etc. is done from the PtrCtrl record in the mouse's device record,
+  *	there's nothing to do here.
+  *
+  * Results:
+  *	None.
+  *
+  * Side Effects:
+  *	None.
+  *
+  *-----------------------------------------------------------------------
+  */
+ /*ARGSUSED*/
+ static void
+ xenixMouseCtrl (pMouse)
+     DevicePtr	  pMouse;
+ {
+ }
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixMouseGetMotionEvents --
+  *	Return the (number of) motion events in the "motion history
+  *	buffer" (snicker) between the given times.
+  *
+  * Results:
+  *	The number of events stuffed.
+  *
+  * Side Effects:
+  *	The relevant xTimecoord's are stuffed in the passed memory.
+  *
+  *-----------------------------------------------------------------------
+  */
+ /*ARGSUSED*/
+ static int
+ xenixMouseGetMotionEvents (buff, start, stop, pScreen)
+     CARD32 start, stop;
+     xTimecoord *buff;
+     ScreenPtr pScreen;
+ {
+     return 0;
+ }
+ 
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixMouseProcessEvent --
+  *	Given a Firm_event for a mouse, pass it off the the dix layer
+  *	properly converted...
+  *
+  * Results:
+  *	None.
+  *
+  * Side Effects:
+  *	The cursor may be redrawn...? devPrivate/x/y will be altered.
+  *
+  *-----------------------------------------------------------------------
+  */
+ void
+ xenixMouseProcessEvent (pMouse, evp)
+     DevicePtr	  pMouse;   	/* Mouse from which the event came */
+     EVENT	  *evp;	    	/* Event to process */
+ {
+     xEvent	xE;
+     register XenixMsPrivPtr pXenixPriv; /* Private data for mouse */
+     static	int	button = 0;	/* previous button state */
+     int		b;			/* current button state */
+     int		bKey;			/* button value expected by X */
+     static	int	mouseMoved = 0;
+ 
+ 
+     xE.u.keyButtonPointer.time = EV_TIME(*evp);
+ 
+     if (EV_TAG(*evp) & T_BUTTON) {
+     	b = EV_BUTTONS(*evp);
+ 
+ 	if (b == 7) {
+  	    xenixSuspendX();
+  	    return;
+         }
+ 	switch (ABS(b - button)) {
+ 	    case LT_BUTTON:	bKey = 1;	break;
+ 	    case MD_BUTTON:	bKey = 2;	break;
+ 	    case RT_BUTTON:	bKey = 3;	break;
+ 	    default:		return;
+ 	}
+ 	/*
+ 	 * A button changed state. Sometimes we will get two events
+ 	 * for a single state change. Should we get a button event which
+ 	 * reflects the current state of affairs, that event is discarded.
+ 	 *
+ 	 * Mouse buttons start at 1.
+ 	 */
+ 	xE.u.u.detail = bKey;
+ 	if (button - b > 0)
+ 		xE.u.u.type = ButtonRelease;
+ 	else
+ 		xE.u.u.type = ButtonPress;
+ 	button = b;
+ 
+ 	/*
+ 	 * If the mouse has moved, we must update any interested client
+ 	 * as well as DIX before sending a button event along.
+ 	 */
+ 	if (mouseMoved) {
+ 	    xenixMouseDoneEvents (pMouse, FALSE);
+ 	}
+     
+ 	miPointerPosition (screenInfo.screens[0],
+ 			   &xE.u.keyButtonPointer.rootX,
+ 			   &xE.u.keyButtonPointer.rootY);
+     
+ 	(* pMouse->processInputProc) (&xE, pMouse, 1);
+     } 
+     if (EV_TAG(*evp) & T_REL_LOCATOR) { 
+ 	miPointerDeltaCursor (screenInfo.screens[0], 
+ 			      EV_DX(*evp),
+ 			      -EV_DY(*evp), 
+ 			      TRUE);
+     }
+ }
+ 
+ /*ARGSUSED*/
+ static Bool
+ xenixCursorOffScreen (pScreen, x, y)
+     ScreenPtr	*pScreen;
+     int		*x, *y;
+ {
+     int	    index;
+ 
+     /*
+      * Active Zaphod implementation:
+      *    increment or decrement the current screen
+      *    if the x is to the right or the left of
+      *    the current screen.
+      */
+     if (ActiveZaphod &&
+ 	screenInfo.numScreens > 1 && (*x >= (*pScreen)->width || *x < 0))
+     {
+ 	index = (*pScreen)->myNum;
+ 	if (*x < 0)
+ 	{
+ 	    index = (index ? index : screenInfo.numScreens) - 1;
+ 	    *pScreen = screenInfo.screens[index];
+ 	    *x += (*pScreen)->width;
+ 	}
+ 	else
+ 	{
+ 	    *x -= (*pScreen)->width;
+ 	    index = (index + 1) % screenInfo.numScreens;
+ 	    *pScreen = screenInfo.screens[index];
+ 	}
+ 	return TRUE;
+     }
+     return FALSE;
+ }
+ 
+ /*ARGSUSED*/
+ static long
+ xenixEventTime (pScreen)
+     ScreenPtr	pScreen;
+ {
+     return lastEventTime;
+ }
+ 
+ static void
+ xenixCrossScreen (pScreen, entering)
+     ScreenPtr	pScreen;
+     Bool	entering;
+ {
+     uchar_t  select;
+ 
+     select = 1;
+     if (entering)
+ 	select = 0;
+     if (xenixFbs[pScreen->myNum].EnterLeave)
+ 	(*xenixFbs[pScreen->myNum].EnterLeave) (pScreen, select);
+ }
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * xenixMouseDoneEvents --
+  *	Finish off any mouse motions we haven't done yet. (At the moment
+  *	this code is unused since we never save mouse motions as I'm
+  *	unsure of the effect of getting a keystroke at a given [x,y] w/o
+  *	having gotten a motion event to that [x,y])
+  *
+  * Results:
+  *	None.
+  *
+  * Side Effects:
+  *	A MotionNotify event may be generated.
+  *
+  *-----------------------------------------------------------------------
+  */
+ /*ARGSUSED*/
+ static void
+ xenixMouseDoneEvents (pMouse,final)
+     DevicePtr	  pMouse;
+     Bool	  final;
+ {
+ }



More information about the Alt.sources mailing list