home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk416.lzh / WTF / source / main.c < prev    next >
C/C++ Source or Header  |  1990-12-16  |  3KB  |  149 lines

  1. #include <exec/types.h>
  2. #include <devices/input.h>
  3. #include <exec/execbase.h>
  4. #include <exec/interrupts.h>
  5. #include <exec/io.h>
  6. #include <graphics/clip.h>
  7. #include <graphics/layers.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/intuitionbase.h>
  10. #include <intuition/screens.h>
  11. #include <proto/exec.h>
  12. #include <proto/intuition.h>
  13. #include <proto/layers.h>
  14.  
  15. long _stack = 4000;
  16. char *_procname = "WTF";
  17. long _priority = 0;
  18. long _BackGroundIO = 0;
  19.  
  20. extern struct ExecBase *SysBase;
  21. struct IntuitionBase *IntuitionBase;
  22. struct Library *LayersBase;
  23.  
  24. struct MsgPort *InputPort;
  25. struct IOStdReq *InputReq;
  26. struct Interrupt Handler;
  27.  
  28. extern struct MsgPort *CreatePort();
  29. extern void DeletePort();
  30. extern struct IOStdReq *CreateStdIO();
  31. extern void DeleteStdIO();
  32.  
  33. extern struct InputEvent *KHandler();
  34.  
  35. struct
  36. {
  37.     struct Task *TaskAddr;
  38.     BYTE Signal;
  39. } Common;
  40.  
  41.  
  42. struct NewWindow WindowDef =
  43. {
  44.     20,30,
  45.     160,10,
  46.     -1,-1,
  47.     CLOSEWINDOW,
  48.     WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SIMPLE_REFRESH|ACTIVATE,
  49.     NULL,
  50.     NULL,
  51.     "WTF",
  52.     NULL,
  53.     NULL,
  54.     0,0,
  55.     0,0,
  56.     WBENCHSCREEN
  57. };
  58. struct Window *WTFWindow;
  59. ULONG SigMask;
  60.  
  61.  
  62. int CXBRK()
  63.  
  64. {
  65.     return(0);
  66. }
  67.  
  68.  
  69. void OpenAll()
  70.  
  71. {
  72.     void CloseAll();
  73.     
  74.     if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0L)))  CloseAll();
  75.     if (!(LayersBase = OpenLibrary("layers.library",0L)))  CloseAll();
  76.     
  77.     if ((Common.Signal = AllocSignal(-1L)) == -1)  CloseAll();
  78.     Common.TaskAddr = SysBase->ThisTask;
  79.     
  80.     if (!(InputPort = CreatePort(NULL,0)))  CloseAll();
  81.     if (!(InputReq = CreateStdIO(InputPort)))  CloseAll();
  82.     if (OpenDevice("input.device",0,(struct IORequest *) InputReq,0))  CloseAll();
  83.     Handler.is_Node.ln_Pri = 51;
  84.     Handler.is_Node.ln_Name = "WTF_Input_Handler";
  85.     Handler.is_Code = (void (*)) KHandler;
  86.     InputReq->io_Command = IND_ADDHANDLER;
  87.     InputReq->io_Data = (APTR) &Handler;
  88.     SendIO((struct IORequest *) InputReq);
  89.     
  90.     if (!(WTFWindow = OpenWindow(&WindowDef)))  CloseAll();
  91.     
  92.     SigMask = 1 << Common.Signal | 1 << WTFWindow->UserPort->mp_SigBit;
  93. }
  94.  
  95.  
  96. void CloseAll()
  97.  
  98. {
  99.     if (WTFWindow)  CloseWindow(WTFWindow);
  100.     
  101.     if (InputReq->io_Command)
  102.     {
  103.         InputReq->io_Command = IND_REMHANDLER;
  104.         InputReq->io_Data = (APTR) &Handler;
  105.         DoIO((struct IORequest *) InputReq);
  106.         CloseDevice((struct IORequest *) InputReq);
  107.     };
  108.     if (InputReq) DeleteStdIO(InputReq);
  109.     if (InputPort) DeletePort(InputPort);
  110.     
  111.     if (Common.Signal)  FreeSignal(Common.Signal);
  112.     
  113.     if (LayersBase)  CloseLibrary(LayersBase);
  114.     if (IntuitionBase)  CloseLibrary((struct Library *) IntuitionBase);
  115.     
  116.     exit(0);
  117. }
  118.  
  119.  
  120. void _main()
  121.  
  122. {
  123.     struct Screen *WdScreen;
  124.     struct Layer_Info *li;
  125.     struct Layer *ly;
  126.     WORD xPos, yPos;
  127.     
  128.     OpenAll();
  129.     
  130.     FOREVER
  131.     {
  132.         if (Wait(SigMask) == 1 << Common.Signal)
  133.             {
  134.                 Forbid();
  135.                 
  136.                 WdScreen = IntuitionBase->ActiveScreen;
  137.                 xPos = WdScreen->MouseX; yPos = WdScreen->MouseY;
  138.                 li = &WdScreen->LayerInfo;
  139.                 if (ly = WhichLayer(li,xPos,yPos))
  140.                     WindowToFront((struct Window *) ly->Window);
  141.                     
  142.                 Permit();
  143.             }
  144.             else
  145.                 CloseAll();
  146.     };
  147. }
  148.  
  149.