
/************************************************************************

5/20/87

   'MouseOff' will cause the mouse pointer to disappear after about 10
   seconds of inactivity. It will reappear again upon movememt of the
   mouse.

   Usage:      Run MouseOff

   'MouseOFF' is public domain.  Please feel free to pass it anywhere
   you want.

   This program was originally written by :
                                    Denny Jenkins
                                    5226 Greensedge Way
                                    Columbus, Ohio  43220

                                    CompuServe ID:  70003,2374
                                    
                                    
   I didn't like the executable size (appearantly Lettuce compile) and that 
   there was no way to turn the program off short of rebooting in the original
   version of this program.  This has led to a major hack on my part.  I
   have included the original version of this program in this archive under
   the name moff.orig
   
   MouseOff now checks for ^C so now supports the 'Break' command.  Ie. the
   program may be exited by the command "break <task_num>" where task_num
   is the process number of MouseOff as returned by the "Status" command.
   
   As a small advertisement for the Aztec C system,  this code, even before
   I really started hacking on it, was much smaller and better behaved after
   being compiled with the Aztec compiler.  The Lattice executable timing
   did not seem to work well, and the pointer got lost on me permanently
   a time or two while playing (not saving) in Preferences.  This has not 
   happened with the Aztec executable. Recompiling with Aztec also cut the
   executable size from over 9k to under 800 bytes !!
   
   A word of warning is still to the wise concerning Preferences and this 
   program :  
   
   BE SURE THAT IF YOU CHANGE PREFERENCES WITH MOUSEOFF RUNNING THAT YOU
   HAVE THE POINTER VISIBLE WHEN YOU SAVE ELSE IT MAY VERY WELL WIND UP
   WITH A TRANSPARANT (READ INVISIBLE) INTUITION POINTER SAVED TO YOUR 
   DEVS:SYSTEM-CONFIGURATION FILE.
   
   As the original author might not recognize this file any more, comments
   questions, whatever may also be sent to me :
   
                                      Tom Smythe
                                      RealTime Associates
                                      254 N.E. 42nd
                                      Seattle, Wa.
                                      98105
                                      
                                      (206)-547-7292
                                      (206)-774-4735 (ALink BBS)
                                      
*************************************************************************/

#ifndef  OFF_HEAD                  /* I usually have all of this broken off  */
#define  OFF_HEAD                  /* into a precompiled header file         */

#include <exec/types.h>            /* we get POINTERSIZE here (=36L)         */
#include <intuition/intuition.h>
#include <functions.h>

#define TIMEOUT   25L              /*  about 1/2 second */
#define SECONDS   10L              /*  about 10 seconds */

     /*  if you wish to change the delay time before the pointer goes off,   */
     /*  then change the value of SECONDS and re-compile.  If you wish to    */
     /*  chang how often the program checks for movement, change the value   */
     /*  of TIMEOUT and recompile.  TIMEOUT is the number of intuiticks      */
     /*  that the program sleeps before checking.  Intuiticks come at a rate */
     /*  of 50 per second, hence the 50L in LIMIT. If you want to screw      */                          
     /*  things up real good, change the relationships in LIMIT              */
     
#define LIMIT     (50L * SECONDS) / TIMEOUT
#define PREFSIZE  232L              /* the size of the Preferences structure */
#define BROKEN    ((_SetSignal(0L, 0x1000L) & 0x1000))  /*  this is ^C       */ 
#define MOUSEX    (w->WScreen->MouseX)
#define MOUSEY    (w->WScreen->MouseY)
#define SILENT    ((LastX == MOUSEX) && (LastY == MOUSEY))
#define ALLPTS    i=0; i<POINTERSIZE; i++ 

#endif

struct   Window           *w, *OpenWindow();
struct   IntuitionBase    *IntuitionBase;
struct   Preferences      MyPrefs;


struct NewWindow nw = 
   {
   0,0,3,10,
   -1,-1,
   NULL,
   NULL,
   NULL, NULL,
   NULL,
   NULL, NULL,
   0,0,0,0,
   WBENCHSCREEN
   };

ULONG  seconds=0;
SHORT  LastX, LastY, i;
USHORT PointerData[POINTERSIZE];
BOOL   Pointer=TRUE;


_main()                            /* lets avoid some overhead !  */
   {

   IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L);
   GetPrefs (&MyPrefs, PREFSIZE );
   for(ALLPTS)
      PointerData[i] = MyPrefs.PointerMatrix[i];
   w = OpenWindow(&nw); 

   while (!BROKEN)
      {
      LastX = MOUSEX;
      LastY = MOUSEY;

      Delay(TIMEOUT);

      if (SILENT)  
         {
         if (Pointer && (++seconds > LIMIT))
            chg_ptr(NULL);
         }
         else
            if (!Pointer) 
               chg_ptr(PointerData);
      
      } 
      
   chg_ptr(PointerData);           /* make sure we exit WITH a visible pointer */
   CloseWindow(w);                 /* It seems that nothing gets trashed if you
   CloseLibrary(IntuitionBase);    don't close Intuition & it saves 30+ bytes  */
   _exit();
   }
   
/************************************************/

chg_ptr(data)
   
   USHORT data[];
   
   {
   for(ALLPTS)                     /* copy in the pointer we want  */
       MyPrefs.PointerMatrix[i] = (data) ? data[i] : NULL;
   SetPrefs(&MyPrefs,PREFSIZE);    /* and reset our preferences    */
   Pointer ^= TRUE;                /* toggle Pointer               */
   seconds = 0;
   }
   
/************************************************/

_exit()                            /* lets avoid some more overhead */
   {
      {
#asm
		clr.l	d0                      ;clear d0 for a zero exit code
		move.l	__savsp#,sp		;get back original stack pointer
		rts                             ;and exit
#endasm
      }
   }
