home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / ix_sigwinch.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  4.1 KB  |  171 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.07.04.19.16.36;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @add an input-device handler that scans size changes of windows, and
  17. if necessary sends a SIGWINCH to a related process.
  18. @
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/*
  27.  *  This file is part of ixemul.library for the Amiga.
  28.  *  Copyright (C) 1991, 1992  Markus M. Wild
  29.  *
  30.  *  This library is free software; you can redistribute it and/or
  31.  *  modify it under the terms of the GNU Library General Public
  32.  *  License as published by the Free Software Foundation; either
  33.  *  version 2 of the License, or (at your option) any later version.
  34.  *
  35.  *  This library is distributed in the hope that it will be useful,
  36.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  37.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  38.  *  Library General Public License for more details.
  39.  *
  40.  *  You should have received a copy of the GNU Library General Public
  41.  *  License along with this library; if not, write to the Free
  42.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  43.  *
  44.  *  $Id$
  45.  *
  46.  *  $Log$
  47.  */
  48. #define KERNEL
  49. #include "ixemul.h"
  50. #include <intuition/intuition.h>
  51. #include <devices/input.h>
  52. #include <devices/inputevent.h>
  53.  
  54. #undef DEBUG
  55.  
  56. #ifdef DEBUG
  57. #define DP(arg) kprintf arg
  58. #else
  59. #define DP(arg)
  60. #endif
  61. extern struct IOStdReq *CreateStdIO (struct MsgPort *);
  62.  
  63. static struct InputEvent *
  64. sigwinch_input_handler ()
  65. {
  66.   register struct InputEvent *_old_chain asm ("a0");
  67.   register struct Task *_me asm ("a1");
  68.   register struct InputEvent *old_chain = _old_chain;
  69.   register struct Task *me = _me;
  70.   struct user *user = (struct user *) me->tc_TrapData;
  71.   struct Window *w= user->u_window;
  72.   struct InputEvent *ie;
  73.   
  74.   for (ie = old_chain; ie; ie = ie->ie_NextEvent)
  75.     {
  76.       if (ie->ie_Class == IECLASS_SIZEWINDOW)
  77.         {
  78.           DP(("SIZEWINDOW. Ourwindow = $%lx, thiswindow = $%lx\n",
  79.           w, ie->ie_EventAddress));
  80.           if (w == (struct Window *) ie->ie_EventAddress)
  81.             _psignal (me, SIGWINCH);
  82.         }
  83.     }
  84.  
  85.   /* always return the old chain, since we don't consume or generate events */
  86.   return old_chain;
  87. }
  88.  
  89.  
  90. void
  91. ix_install_sigwinch ()
  92. {
  93.   struct ConUnit *cu;
  94.   struct IOStdReq *ios;
  95.   struct InfoData *info;
  96.   struct Window *w;
  97.   struct MsgPort *handler;
  98.   struct Process *me = (struct Process *) FindTask(0);
  99.   struct StandardPacket *sp;
  100.  
  101.   info = alloca (sizeof (struct InfoData) + 2);
  102.   info = LONG_ALIGN (info);
  103.   bzero (info, sizeof (struct InfoData));
  104.   
  105.   sp = alloca (sizeof (struct StandardPacket));
  106.   sp = LONG_ALIGN (sp);
  107.  
  108.   handler = (struct MsgPort *) me->pr_ConsoleTask;
  109.   if (! handler)
  110.     {
  111.       DP(("No ConsoleTask, GASP!\n"));
  112.       return;
  113.     }
  114.     
  115.   __init_std_packet (sp);
  116.   sp->sp_Pkt.dp_Port = u.u_sync_mp;
  117.   sp->sp_Pkt.dp_Type = ACTION_DISK_INFO;
  118.   sp->sp_Pkt.dp_Arg1 = CTOBPTR (info);
  119.  
  120.   PutPacket (handler, sp);
  121.   __wait_sync_packet (sp);
  122.   if (sp->sp_Pkt.dp_Res1 != -1)
  123.     {
  124.       DP(("ACTION_DISK_INFO failed (%ld)\n", sp->sp_Pkt.dp_Res2));
  125.       return;
  126.     }
  127.  
  128.   w = (struct Window *) info->id_VolumeNode;
  129.   if (! w) 
  130.     {
  131.       DP(("No window pointer!\n"));
  132.       return;
  133.     }
  134.  
  135.   if (!(u.u_idev_req = CreateStdIO (u.u_sync_mp)))
  136.     return;
  137.  
  138.   if (OpenDevice ("input.device", 0, 
  139.           (struct IORequest *) u.u_idev_req, sizeof (struct IOStdReq)))
  140.     {
  141.       DeleteStdIO (u.u_idev_req);
  142.       u.u_idev_req = 0;
  143.       return;
  144.     }
  145.  
  146.   u.u_window = w;
  147.   u.u_idev_int.is_Code = (void *) sigwinch_input_handler;
  148.   u.u_idev_int.is_Data = (void *) me;
  149.   u.u_idev_int.is_Node.ln_Pri = 10;    /* must be before console.device */
  150.   u.u_idev_int.is_Node.ln_Name = "ixemul SIGWINCH handler";
  151.   u.u_idev_req->io_Data = (APTR) &u.u_idev_int;
  152.   u.u_idev_req->io_Command = IND_ADDHANDLER;
  153.   DoIO ((struct IORequest *) u.u_idev_req);
  154. }
  155.  
  156.  
  157. void
  158. ix_remove_sigwinch ()
  159. {
  160.   if (u.u_idev_req)
  161.     {
  162.       u.u_idev_req->io_Data = (APTR) &u.u_idev_int;
  163.       u.u_idev_req->io_Command = IND_REMHANDLER;
  164.       DoIO ((struct IORequest *) u.u_idev_req);
  165.       CloseDevice ((struct IORequest *) u.u_idev_req);
  166.       DeleteStdIO (u.u_idev_req);
  167.       u.u_idev_req = 0;
  168.     }
  169. }
  170. @
  171.