/* 5/4/93 Chris Lloyd - lloyd@world.std.com */

#import "Preserve.h"

#import <appkit/Application.h>

#import <dpsclient/wraps.h>

/* For 2.0, uncomment this, and comment the next one */

//#import <nextdev/evsio.h>
#import <dev/m68k/evsio.h>

#import <libc.h>

@implementation Preserve

static void handler(DPSTimedEntry h,double n,void *udata)
{
   Preserve *self=udata;
   int dimmed=0;

   ioctl(self->evs,EVSIOCADS,&dimmed);
   if(dimmed)
    [NXApp unhide:self];
}

-(BOOL)constrainFrameRect:(NXRect *)theFrame toScreen:(const NXScreen *)screen
{
   return NO;
}

-initContent:(const NXRect *)contentRect style:(int)aStyle
  backing:(int)bufferingType buttonMask:(int)mask defer:(BOOL)flag
{
   const NXScreen *screen;

   [super initContent:contentRect style:aStyle backing:bufferingType
          buttonMask:mask defer:flag];

   screen=[self screen];
   [self setBackgroundGray:NX_BLACK];
   [self moveTo:0:0];
   [self sizeWindow:screen->screenBounds.size.width:
                    screen->screenBounds.size.height-2];
   [self addToEventMask:NX_MOUSEMOVEDMASK];

   DPSAddTimedEntry(60,handler,self,NX_MODALRESPTHRESHOLD+1);

   if((evs=open("/dev/evs0",O_RDONLY,0))<0)
    printf("blegh\n");

   PSobscurecursor();
   PSsetgray(0.0);
   PSsetexposurecolor();
   return self;
}

-orderWindow:(int)place relativeTo:(int)otherWin
{
   [super orderWindow:place relativeTo:otherWin];

   if(place==NX_ABOVE)
   {
    PSsetwindowlevel(NX_MAINMENULEVEL*10,windowNum);
    PSobscurecursor();
   }
   return self;
}

-mouseMoved:(NXEvent *)theEvent
{
   PSobscurecursor();
   return self;
}

-mouseDown:(NXEvent *)theEvent
{
   [NXApp hide:self];
   return self;
}


@end
