home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / ix_sigwinch.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  4KB  |  124 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  *  $Id: ix_sigwinch.c,v 1.2 1994/06/19 15:13:17 rluebbert Exp $
  21.  *
  22.  *  $Log: ix_sigwinch.c,v $
  23.  *  Revision 1.2  1994/06/19  15:13:17  rluebbert
  24.  *  *** empty log message ***
  25.  *
  26.  */
  27. #define _KERNEL
  28. #include "ixemul.h"
  29. #include "kprintf.h"
  30. #include <string.h>
  31. #include <intuition/intuition.h>
  32. #include <devices/input.h>
  33. #include <devices/inputevent.h>
  34.  
  35. extern struct IOStdReq *CreateStdIO (struct MsgPort *);
  36.  
  37. static struct InputEvent *sigwinch_input_handler (void)
  38. {
  39.   register struct InputEvent *_old_chain asm ("a0");
  40.   register struct Task *_me asm ("a1");
  41.   register struct InputEvent *old_chain = _old_chain;
  42.   register struct Task *me = _me;
  43.   struct user *user = (struct user *) me->tc_TrapData;
  44.   struct Window *w= user->u_window;
  45.   struct InputEvent *ie;
  46.   
  47.   for (ie = old_chain; ie; ie = ie->ie_NextEvent)
  48.       if (ie->ie_Class == IECLASS_SIZEWINDOW)
  49.           if (w == (struct Window *) ie->ie_EventAddress)
  50.             _psignal (me, SIGWINCH);
  51.  
  52.   /* always return the old chain, since we don't consume or generate events */
  53.   return old_chain;
  54. }
  55.  
  56.  
  57. void ix_install_sigwinch (void)
  58. {
  59.   struct InfoData *info;
  60.   struct Window *w;
  61.   struct MsgPort *handler;
  62.   struct Process *me = (struct Process *) FindTask(0);
  63.   struct StandardPacket *sp;
  64.  
  65.   info = alloca (sizeof (struct InfoData) + 2);
  66.   info = LONG_ALIGN (info);
  67.   bzero (info, sizeof (struct InfoData));
  68.   
  69.   sp = alloca (sizeof (struct StandardPacket) + 2);
  70.   sp = LONG_ALIGN (sp);
  71.  
  72.   handler = (struct MsgPort *) me->pr_ConsoleTask;
  73.   if (! handler)
  74.       return;
  75.     
  76.   __init_std_packet (sp);
  77.   sp->sp_Pkt.dp_Port = u.u_sync_mp;
  78.   sp->sp_Pkt.dp_Type = ACTION_DISK_INFO;
  79.   sp->sp_Pkt.dp_Arg1 = CTOBPTR (info);
  80.  
  81.   PutPacket (handler, sp);
  82.   __wait_sync_packet (sp);
  83.   if (sp->sp_Pkt.dp_Res1 != -1)
  84.       return;
  85.  
  86.   w = (struct Window *) info->id_VolumeNode;
  87.   if (! w) 
  88.       return;
  89.  
  90.   if (!(u.u_idev_req = CreateStdIO (u.u_sync_mp)))
  91.     return;
  92.  
  93.   if (OpenDevice ("input.device", 0, 
  94.           (struct IORequest *) u.u_idev_req, sizeof (struct IOStdReq)))
  95.     {
  96.       DeleteStdIO (u.u_idev_req);
  97.       u.u_idev_req = 0;
  98.       return;
  99.     }
  100.  
  101.   u.u_window = w;
  102.   u.u_idev_int.is_Code = (void *) sigwinch_input_handler;
  103.   u.u_idev_int.is_Data = (void *) me;
  104.   u.u_idev_int.is_Node.ln_Pri = 10;    /* must be before console.device */
  105.   u.u_idev_int.is_Node.ln_Name = "ixemul SIGWINCH handler";
  106.   u.u_idev_req->io_Data = (APTR) &u.u_idev_int;
  107.   u.u_idev_req->io_Command = IND_ADDHANDLER;
  108.   DoIO ((struct IORequest *) u.u_idev_req);
  109. }
  110.  
  111.  
  112. void ix_remove_sigwinch (void)
  113. {
  114.   if (u.u_idev_req)
  115.     {
  116.       u.u_idev_req->io_Data = (APTR) &u.u_idev_int;
  117.       u.u_idev_req->io_Command = IND_REMHANDLER;
  118.       DoIO ((struct IORequest *) u.u_idev_req);
  119.       CloseDevice ((struct IORequest *) u.u_idev_req);
  120.       DeleteStdIO (u.u_idev_req);
  121.       u.u_idev_req = 0;
  122.     }
  123. }
  124.