home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / cxhand.c next >
C/C++ Source or Header  |  1994-10-17  |  4KB  |  200 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10.  
  11. #include <libraries/commodities.h>
  12. #include <devices/inputevent.h>
  13.  
  14. #include "includes.h"
  15. #include "libraries.h"
  16. #include "protos/protos.h"
  17.  
  18. BlankMsg *InterruptMsg;
  19. struct MsgPort *CxPort;
  20. CxObj *ServerBroker, *pHotKey, *bHotKey, *objectList;
  21. LONG timeCount = 0;
  22. struct NewBroker nServerBroker = {
  23.     NB_VERSION, "Garshneblanker", VERS, "Screen blanking for the 21st century",
  24.     NBU_UNIQUE|NBU_NOTIFY, COF_SHOW_HIDE, 0, 0, 0
  25.     };
  26.  
  27. VOID __interrupt __saveds CxBFunc( CxMsg *CxMessage, CxObj *CxObject )
  28. {
  29.     struct InputEvent *Event = ( struct InputEvent * )CxMsgData( CxMessage );
  30.     
  31.     switch( Event->ie_Class )
  32.     {
  33.     case IECLASS_TIMER:
  34.         if( ++timeCount >= Prefs->bp_Timeout )
  35.         {
  36.             InterruptMsg->bm_Flags = BF_INTERNAL;
  37.             InterruptMsg->bm_Type = BM_SENDBLANK;
  38.             PutMsg( ServerPort, ( struct Message * )InterruptMsg );
  39.             timeCount = 0;
  40.         }
  41.         return;
  42.     case IECLASS_RAWMOUSE:
  43.         if(( Event->ie_Code == IECODE_NOBUTTON )&&
  44.            ( Event->ie_Qualifier & IEQUALIFIER_RELATIVEMOUSE )&&
  45.            ( Prefs->bp_BlankCorner || Prefs->bp_DontCorner ))
  46.         {
  47.             Signal( ServerTask, SIGBREAKF_CTRL_D );
  48.         }
  49.         break;
  50.     case IECLASS_RAWKEY:
  51.         if( Event->ie_Code & IECODE_UP_PREFIX )
  52.             return;
  53.     }
  54.  
  55.     if( Blanking )
  56.     {
  57.         Blanking = FALSE;
  58.         InterruptMsg->bm_Flags = BF_INTERNAL;
  59.         InterruptMsg->bm_Type = BM_SENDUNBLANK;
  60.         PutMsg( ServerPort, ( struct Message * )InterruptMsg );
  61.     }
  62.     timeCount = 0;
  63. }
  64.  
  65. LONG HandleCxMess( VOID )
  66. {
  67.     LONG msgid, msgtype;
  68.     CxMsg *msg;
  69.     
  70.     while( msg = ( CxMsg * )GetMsg( CxPort ))
  71.     {
  72.         msgid = CxMsgID( msg );
  73.         msgtype = CxMsgType( msg );
  74.         ReplyMsg(( struct Message * )msg );
  75.         
  76.         switch( msgtype )
  77.         {
  78.         case CXM_IEVENT:
  79.             switch( msgid )
  80.             {
  81.             case EVT_CX_POPUP:
  82.                 openMainWindow();
  83.                 break;
  84.             case EVT_CX_BLANK:
  85.                 InterruptMsg->bm_Flags = BF_INTERNAL;
  86.                 InterruptMsg->bm_Type = BM_SENDBLANK;
  87.                 PutMsg( ServerPort, ( struct Message * )InterruptMsg );
  88.                 break;
  89.             }
  90.             break;
  91.         case CXM_COMMAND:
  92.             switch( msgid )
  93.             {
  94.             case CXCMD_DISABLE:
  95.                 ActivateCxObj( ServerBroker, 0l );
  96.                 break;
  97.             case CXCMD_ENABLE:
  98.                 ActivateCxObj( ServerBroker, 1l );
  99.                 break;
  100.             case CXCMD_KILL:
  101.                 return QUIT;
  102.             case CXCMD_APPEAR:
  103.             case CXCMD_UNIQUE:
  104.                 openMainWindow();
  105.                 break;
  106.             case CXCMD_DISAPPEAR:
  107.                 CloseBlankerWindow();
  108.                 CloseDownScreen();
  109.                 break;
  110.             default:
  111.                 break;
  112.             }
  113.         default:
  114.             break;
  115.         }
  116.     }
  117.  
  118.     return OK;
  119. }
  120.  
  121. VOID ShutdownCX( VOID )
  122. {
  123.     CxMsg *msg;
  124.     
  125.     if( InterruptMsg )
  126.         FreeVec( InterruptMsg );
  127.  
  128.     if( CxPort )
  129.     {
  130.         if( ServerBroker )
  131.             DeleteCxObjAll( ServerBroker );
  132.         ServerBroker = 0L;
  133.         
  134.         while( msg = ( CxMsg * )GetMsg( CxPort ))
  135.             ReplyMsg(( struct Message * )msg );
  136.         DeletePort( CxPort );
  137.         CxPort = 0L;
  138.     }
  139. }
  140.  
  141. LONG UpdateCX( VOID )
  142. {
  143.     ActivateCxObj( ServerBroker, 0l );
  144.     
  145.     DeleteCxObj( objectList );
  146.     DeleteCxObj( pHotKey );
  147.     DeleteCxObj( bHotKey );
  148.     
  149.     if( objectList = CxCustom( CxBFunc, 0L ))
  150.         AttachCxObj( ServerBroker, objectList );
  151.     if( pHotKey = HotKey( Prefs->bp_PopKey, CxPort, EVT_CX_POPUP ))
  152.         AttachCxObj( ServerBroker, pHotKey );
  153.     if( bHotKey = HotKey( Prefs->bp_BlankKey, CxPort, EVT_CX_BLANK ))
  154.         AttachCxObj( ServerBroker, bHotKey );
  155.     
  156.     if( CxObjError( ServerBroker ))
  157.     {
  158.         ShutdownCX();
  159.         return QUIT;
  160.     }
  161.     else
  162.         ActivateCxObj( ServerBroker, 1l );
  163.  
  164.     return OK;
  165. }
  166.  
  167. LONG SetupCX( VOID )
  168. {
  169.     LONG cxError;
  170.     
  171.     if( InterruptMsg = AllocVec( sizeof( BlankMsg ), MEMF_CLEAR|MEMF_PUBLIC ))
  172.     {
  173.         InterruptMsg->bm_Mess.mn_ReplyPort = ServerPort;
  174.         InterruptMsg->bm_Mess.mn_Length = sizeof( BlankMsg );
  175.         
  176.         if( CxPort = CreatePort( 0L, 0L ))
  177.         {
  178.             nServerBroker.nb_Pri = Prefs->bp_Priority;
  179.             nServerBroker.nb_Port = CxPort;
  180.             ServerBroker = CxBroker( &nServerBroker, &cxError );
  181.             if( cxError == CBERR_OK )
  182.                 return UpdateCX();
  183.             else
  184.                 ShutdownCX();
  185.         }
  186.     }
  187.     
  188.     return QUIT;
  189. }
  190.  
  191. LONG CheckCX( VOID )
  192. {
  193.     LONG cxError;
  194.     
  195.     ServerBroker = CxBroker( &nServerBroker, &cxError );
  196.     DeleteCxObj( ServerBroker );
  197.  
  198.     return ( cxError == CBERR_OK ) ? OK : QUIT;
  199. }
  200.