home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d534 / term.lha / Term / Source.LZH / termHotkeys.c < prev    next >
C/C++ Source or Header  |  1991-07-20  |  5KB  |  259 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: termHotkeys.c
  6.  *    Created ..: Monday 19-Jun-91 18:36
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    19-Jun-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17. enum    {    CX_TERMSCREENTOFRONT,CX_BUFFERSCREENTOFRONT,CX_SKIPDIALENTRY };
  18.  
  19.     /* Asynchronous hotkey task. */
  20.  
  21. STATIC struct Task *CxTask;
  22.  
  23.     /* CreateBroker(struct MsgPort *CxPort):
  24.      *
  25.      *    Set up a CxObj commodity broker.
  26.      */
  27.  
  28. STATIC CxObj *
  29. CreateBroker(struct MsgPort *CxPort)
  30. {
  31.     CxObj *Broker;
  32.  
  33.         /* Set the commodity priority. */
  34.  
  35.     NewTermBroker . nb_Pri = Hotkeys . CommodityPriority;
  36.  
  37.         /* Create the broker. */
  38.  
  39.     if(Broker = CxBroker(&NewTermBroker,NULL))
  40.     {
  41.             /* Add the hotkeys. */
  42.  
  43.         AttachCxObj(Broker,HotKey(Hotkeys . termScreenToFront,CxPort,CX_TERMSCREENTOFRONT));
  44.         AttachCxObj(Broker,HotKey(Hotkeys . BufferScreenToFront,CxPort,CX_BUFFERSCREENTOFRONT));
  45.         AttachCxObj(Broker,HotKey(Hotkeys . SkipDialEntry,CxPort,CX_SKIPDIALENTRY));
  46.  
  47.             /* Did an error show up? */
  48.  
  49.         if(!CxObjError(Broker))
  50.         {
  51.                 /* Broker has been added, now activate it. */
  52.  
  53.             ActivateCxObj(Broker,Hotkeys . HotkeysEnabled);
  54.  
  55.             return(Broker);
  56.         }
  57.  
  58.         DeleteCxObjAll(Broker);
  59.     }
  60.  
  61.     return(NULL);
  62. }
  63.  
  64.     /* TermCxServer():
  65.      *
  66.      *    Asynchronous hotkey server.
  67.      */
  68.  
  69. STATIC VOID __saveds
  70. TermCxServer()
  71. {
  72.     CxObj        *Broker;
  73.     struct MsgPort    *CxPort;
  74.     CxMsg        *Message;
  75.  
  76.         /* Create a reply port. */
  77.  
  78.     if(CxPort = CreateMsgPort())
  79.     {
  80.             /* Add the port to the public list. */
  81.  
  82.         CxPort -> mp_Node . ln_Name = NewTermBroker . nb_Name;
  83.  
  84.         AddPort(CxPort);
  85.  
  86.             /* Install the port. */
  87.  
  88.         NewTermBroker . nb_Port    = CxPort;
  89.  
  90.             /* Create the broker. */
  91.  
  92.         if(Broker = CreateBroker(CxPort))
  93.         {
  94.             ULONG    SignalSet;
  95.             BYTE    Terminated = FALSE;
  96.  
  97.                 /* Signal father task that we're done. */
  98.  
  99.             Signal(ThisProcess,SIGBREAKF_CTRL_C);
  100.  
  101.                 /* Loop and loop... */
  102.  
  103.             while(!Terminated)
  104.             {
  105.                     /* Wait for some signal. */
  106.  
  107.                 SignalSet = Wait(SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | (1 << CxPort -> mp_SigBit));
  108.  
  109.                     /* ^C aborts. */
  110.  
  111.                 if(SignalSet & SIGBREAKF_CTRL_C)
  112.                     Terminated = TRUE;
  113.  
  114.                     /* ^D removes the broker and
  115.                      * creates a new one.
  116.                      */
  117.  
  118.                 if(SignalSet & SIGBREAKF_CTRL_D)
  119.                 {
  120.                     DeleteCxObjAll(Broker);
  121.  
  122.                     Broker = CreateBroker(CxPort);
  123.                 }
  124.  
  125.                     /* A commodity message. */
  126.  
  127.                 if(SignalSet & (1 << CxPort -> mp_SigBit))
  128.                 {
  129.                     ULONG MessageType,MessageID;
  130.  
  131.                         /* Remove all messages. */
  132.  
  133.                     while(Message = (CxMsg *)GetMsg(CxPort))
  134.                     {
  135.                             /* Extract type and ID. */
  136.  
  137.                         MessageType    = CxMsgID(Message);
  138.                         MessageID    = CxMsgType(Message);
  139.  
  140.                         ReplyMsg((struct Message *)Message);
  141.  
  142.                             /* Take a look at the type... */
  143.  
  144.                         switch(MessageID)
  145.                         {
  146.                                 /* A hotkey was pressed. */
  147.  
  148.                             case CXM_IEVENT:    switch(MessageType)
  149.                                         {
  150.                                             case CX_TERMSCREENTOFRONT:    BumpWindow(TopWindow);
  151.                                                             break;
  152.  
  153.                                             case CX_BUFFERSCREENTOFRONT:    if(BufferProcess)
  154.                                                                 Signal(BufferProcess,SIGBREAKF_CTRL_D);
  155.  
  156.                                                             break;
  157.  
  158.                                             case CX_SKIPDIALENTRY:        Signal(ThisProcess,SIGBREAKF_CTRL_F);
  159.                                                             break;
  160.                                         }
  161.  
  162.                                         break;
  163.  
  164.                                 /* An internal commodity command. */
  165.  
  166.                             case CXM_COMMAND:    switch(MessageType)
  167.                                         {
  168.                                             case CXCMD_DISABLE:    ActivateCxObj(Broker,Hotkeys . HotkeysEnabled = FALSE);
  169.                                                         break;
  170.  
  171.                                             case CXCMD_ENABLE:    ActivateCxObj(Broker,Hotkeys . HotkeysEnabled = TRUE);
  172.                                                         break;
  173.  
  174.                                             default:        break;
  175.                                         }
  176.  
  177.                                         break;
  178.                         }
  179.                     }
  180.                 }
  181.             }
  182.  
  183.                 /* Remove the broker. */
  184.  
  185.             DeleteCxObjAll(Broker);
  186.         }
  187.  
  188.             /* Remove the port from the public list. */
  189.  
  190.         RemPort(CxPort);
  191.  
  192.             /* Remove all pendig messages. */
  193.  
  194.         while(Message = (CxMsg *)GetMsg(CxPort))
  195.             ReplyMsg((struct Message *)Message);
  196.  
  197.             /* Delete the reply port. */
  198.  
  199.         DeleteMsgPort(CxPort);
  200.     }
  201.  
  202.     Forbid();
  203.  
  204.         /* Clear the task ID. */
  205.  
  206.     CxTask = NULL;
  207.  
  208.         /* Signal father process that we're done. */
  209.  
  210.     Signal(ThisProcess,SIGBREAKF_CTRL_C);
  211.  
  212.         /* Remove ourselves. */
  213.  
  214.     RemTask(SysBase -> ThisTask);
  215. }
  216.  
  217.     /* ShutdownCx():
  218.      *
  219.      *    Remove the hotkey task.
  220.      */
  221.  
  222. VOID
  223. ShutdownCx()
  224. {
  225.     if(CxTask)
  226.     {
  227.         Signal(CxTask,SIGBREAKF_CTRL_C);
  228.  
  229.         Wait(SIGBREAKF_CTRL_C);
  230.     }
  231. }
  232.  
  233.     /* SetupCx():
  234.      *
  235.      *    Create the hotkey task.
  236.      */
  237.  
  238. BYTE
  239. SetupCx()
  240. {
  241.         /* If the task is already running, tell it to
  242.          * update the hotkey settings.
  243.          */
  244.  
  245.     if(CxTask)
  246.         Signal(CxTask,SIGBREAKF_CTRL_D);
  247.     else
  248.     {
  249.         CxTask = CreateTask("term Hotkey Task",0,TermCxServer,4000);
  250.  
  251.         Wait(SIGBREAKF_CTRL_C);
  252.  
  253.         if(!CxTask)
  254.             return(FALSE);
  255.     }
  256.  
  257.     return(TRUE);
  258. }
  259.