home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / dev / m68k / evio.h < prev    next >
Text File  |  1993-10-19  |  11KB  |  247 lines

  1. /******************************************************************************
  2.  
  3.     evio.h
  4.     Ioctl calls for the events driver
  5.     Leovitch 02Jan88
  6.     
  7.     Copyright 1988 NeXT, Inc.
  8.     
  9.     Modified:
  10.     
  11.     09Dec88 Leo  Broken out from evsio.h
  12.     24Aug89 Ted  ANSI function prototyping.
  13.     19Feb90 Ted  Major revision for multiple driver support.
  14.     26Feb90 Ted  New evioScreen structure and EVIOST ioctl.
  15.     12Mar90 Ted  New ev_unregister_screen function, SCREENTOKEN constant.
  16.     06May90 Ted  Added AALastEventSent and AALastEventConsumed to EvVars.
  17.     22May90 Trey More wait cursor vars in EvVars.
  18.     13Jun90 Ted  NXCursorData structure.
  19.     18Jun90 Ted  Default wait cursor constants.
  20.     26Sep90 Ted  Enhanced cursor system to support intelligent drivers.
  21.     26Nov90 Ted  Removed NXSaveCursor and NXCursorData structures
  22.     28Nov90 Ted  Remove EvVars, rolled into EventGlobals
  23.     28Nov90 Ted  Renamed EventGlobals -> EvGlobals, eventGlobals -> evg
  24.  
  25. ******************************************************************************/
  26.  
  27. #ifndef _M68K_DEV_EVIO_
  28. #define _M68K_DEV_EVIO_
  29.  
  30. #import <sys/ioctl.h>
  31. #import <mach/port.h>
  32. #import <mach/message.h>
  33. #import <bsd/dev/ev_types.h>
  34. #import <bsd/dev/m68k/event.h>
  35.  
  36. /* Default Wait Cursor Contants (in 68Hz ticks) */
  37. #define DefaultWCSustain 20    /* 0.3 seconds */    
  38. #define DefaultWCFrameRate 5    /* 13.6 frames/second */
  39. #define DefaultWCThreshold 80    /* 1.2 seconds */
  40.  
  41. /* Pressure Constants */
  42. #define MINPRESSURE 0
  43. #define MAXPRESSURE 255
  44.  
  45. /* Mouse Button Constants  */
  46. #define RB        (0x01)
  47. #define LB        (0x04)
  48. #define MOUSEBUTTONMASK    (LB | RB)
  49.  
  50. #ifndef MAXMOUSESCALINGS
  51. /* Maximum length of SetMouseScaling arrays */
  52. #define MAXMOUSESCALINGS NX_MAXMOUSESCALINGS
  53. #endif MAXMOUSESCALINGS
  54.  
  55. #define SCREENTOKEN 256    /* Some non-zero token to or with screen number */
  56. #define    LLEQSIZE 80    /* Entries in low-level event queue */
  57.  
  58. typedef struct _NXEQElStruct {
  59.     short next;        /* Slot of lleq for next event */
  60.     short sema;        /* Is high-level code is reading this event now? */
  61.     NXEvent event;    /* The event itself */
  62. } NXEQElement;
  63.  
  64. /* The following typedefs are defined here for compatibility with PostScript */
  65.  
  66. #if !defined(__Point__) && !defined(BINTREE_H)
  67. #define __Point__
  68. typedef struct { short x, y; } Point;
  69. #endif
  70.  
  71. #if !defined(__Bounds__) && !defined(BINTREE_H)
  72. #define __Bounds__
  73. typedef struct { short minx, maxx, miny, maxy; } Bounds;
  74. #endif
  75.  
  76. typedef struct _evRetry {
  77.     unsigned level:1;
  78.     unsigned cursor:2;
  79.     unsigned :29;
  80. } EvRetry;
  81.  
  82. /******************************************************************************
  83.     EvScreen
  84.     This structure is used both by the ev driver and screen drivers.
  85.     It holds information about a single screen: how much private shmem it owns,
  86.     where its private shmem region starts, its global bounds and four procedure
  87.     vectors. This structure is allocated by the ev driver and is filled in
  88.     when a driver calls ev_register_screen(). This structure is correspondingly
  89.     passed to each procedure vector as the first argument to allow a driver to
  90.     know which screen the call refers to (in the case a driver controls more
  91.     than one screen for instance).
  92.  
  93.     The priv field is the only field a driver is permitted to modify at any
  94.     given time.  Every other field is off limits.  This structure may grow
  95.     in length, but the field order will not change.
  96.  
  97.     The procedure vectors allow the kernel to direct cursor activity and
  98.     delegate responsibility for drawing, erasing, and moving the cursor to
  99.     screen drivers. (See video.c for the MegaPixel driver's implementation).
  100.     Each procedure must return an error status.  Returning "0" means that
  101.     a procedure successfully processed the given message.  Returning "1"
  102.     signifies that it wasn't successful in processing the message and should
  103.     be retried at a later time. This should releave most error conditions that
  104.     might arrive and prevents drivers from (god for bin) having to spin within
  105.     time-critical interrupt periods. Usually a retry is requested if a driver's
  106.     cursor semaphore or lock is busy. 
  107. ******************************************************************************/
  108.  
  109. typedef volatile struct _evScreen {
  110.     void *priv;        /* Driver's private use */
  111.     void *shmemPtr;    /* Ptr to private shmem (if non-zero size) */
  112.     int shmemSize;    /* Size of private shmem */
  113.     Bounds bounds;    /* Screen's bounds in device coordinates */
  114.     EvRetry retry;    /* private to ev driver */
  115.     int (*hide)(struct _evScreen *esp);
  116.     int (*move)(struct _evScreen *esp, Point loc, int frame);
  117.     int (*show)(struct _evScreen *esp, Point loc, int frame);
  118.     int (*level)(struct _evScreen *esp, int brightness);
  119. } EvScreen;
  120.  
  121. /******************************************************************************
  122.     SHARED MEMORY OVERVIEW
  123.     
  124.     PERSPECTIVE
  125.     The ev driver and PostScript share at least one page of wired memory.
  126.     This memory contains the low-level event queue which ev deposits events
  127.     into and PostScript reads events from. Also, this memory contains other
  128.     important data such as wait cursor state and some general cursor state.
  129.     This memory is critical for speed.  That is, we avoid having to make
  130.     system calls for common operations.
  131.     
  132.     SHARED MEMORY REGIONS
  133.     There are currently three "regions" or "zones" delineated within this
  134.     shared memory.  The first zone is the EvOffsets structure. This structure
  135.     contains two offsets from the beginning of shared memory. The first offset
  136.     is to the second zone, EvGlobals. The second offset is to the third
  137.     zone, private shmem for drivers.
  138.     
  139.     INITIALIZATION OF SHARED MEMORY
  140.     When the WindowServer starts up, it finds all screens that will be active.
  141.     It then opens the ev driver and calls the EVIOSSCR ioctl repeatedly for
  142.     each screen in use. This lets the ev driver set up the evScreen array
  143.     and fill in each element. This ioctl also returns to PostScript a running
  144.     total shared memory size with which to allocate. PostScript then allocates
  145.     a region of memory this size and calls evmmap to "map in" this shared
  146.     region.  Evmmap initializes and fills in the EvOffsets and EvGlobals.
  147.     Next the WindowServer calls each screen in turn to register itself with
  148.     the ev driver in the same sequence as presented to EVIOSSCR.  Each screen
  149.     driver calls ev_register_screen() which among other things allocates a
  150.     part of the private shmem (of the third shared memory zone) for the driver.
  151.     
  152.     DEBUGGING NOTES
  153.     You can easily display and set this shared memory from kgdb, but usually
  154.     cannot do so from within PostScript.  Gdb (or some weird interaction
  155.     between gdb and the os) chokes on this shmem.  So if you read or write
  156.     this area of memory, copy-on-write will occur and you'll get a completely
  157.     new page for PostScript.  This will render the shared memory scheme
  158.     useless and you will have to restart PostScript.  It was my understanding
  159.     that before, we were able to "read" this area from PS, but not write to
  160.     it (the idea behind copy-on-WRITE).  However, this seems to be broken
  161.     in 2.0.  We think this is a kernel bug.
  162. ******************************************************************************/
  163.  
  164. typedef volatile struct _evOffsets {
  165.     int    evGlobalsOffset;    /* Offset to EvGlobals structure */
  166.     int evShmemOffset;        /* Offset to private shmem regions */
  167. } EvOffsets;
  168.  
  169. /******************************************************************************
  170.     EvGlobals
  171.     This structures defines the portion of the events driver data structure
  172.     that is exported to the PostScript server. It contains the event queue
  173.     which is in memory shared between the driver and the PostScript server.
  174.     All the variables necessary to read and process events from the queue are
  175.     contained here.
  176. ******************************************************************************/
  177.  
  178. typedef volatile struct _evGlobals {
  179.     short LLEHead;        /* The next event to be read */
  180.     short LLETail;        /* Where the next event will go */
  181.     short LLELast;        /* The last event entered */
  182.     short eNum;            /* Unique id for mouse events */
  183.     int buttons;        /* State of the mouse buttons 1==down, 0==up */
  184.     int eventFlags;        /* The current value of event.flags */
  185.     int VertRetraceClock;    /* The current value of event.time */
  186.     int cursorSema;         /* set to disable interrupt code */
  187.     Point cursorLoc;        /* The current location of the cursor */
  188.     int frame;            /* current cursor frame */
  189.     Bounds workBounds;        /* bounding box of all screens */
  190.     Bounds mouseRect;        /* Rect for mouse-exited events */
  191.     unsigned reserved:27;
  192.     unsigned wantPressure:1;    /* pressure in current mouseRect? */
  193.     unsigned wantPrecision:1;    /* precise coordinates in current mouseRect? */
  194.     unsigned dontWantCoalesce:1;/* coalesce within the current mouseRect? */
  195.     unsigned dontCoalesce:1;    /* actual flag which determines coalescing */
  196.     unsigned mouseRectValid:1;    /* If nonzero, post a mouse-exited
  197.                    whenever mouse outside mouseRect. */
  198.     int movedMask;        /* This contains an event mask for the
  199.                    three events MOUSEMOVED,
  200.                    LMOUSEDRAGGED,  and RMOUSEDRAGGED.
  201.                    It says whether driver should
  202.                    generate those events. */
  203.     int AALastEventSent;    /* timestamp for wait cursor */
  204.     int AALastEventConsumed;    /* timestamp for wait cursor */    
  205.     int waitCursorUp;        /* Is wait cursor up? */
  206.     char ctxtTimedOut;        /* Has wait cursor timer expired? */
  207.     char waitCursorEnabled;    /* Play wait cursor game (per ctxt)? */
  208.     char globalWaitCursorEnabled; /* Play wait cursor game (global)? */
  209.     char waitCursorSema;    /* protects wait cursor fields */
  210.     short waitThreshold;    /* time before wait cursor appears */
  211.     NXEQElement lleq[LLEQSIZE];    /* The event queue itself */
  212. } EvGlobals;
  213.  
  214. /* These evio structs are used in various ioctls supported by the ev driver. */
  215.  
  216. struct evioLLEvent {
  217.     int type;
  218.     Point location;
  219.     NXEventData data;
  220. };
  221.  
  222. /* This structure is used privately by the WindowServer */
  223. struct evioSetScreen {
  224.     int totalShmemSize;        /* out: returned size of shmem to allocate */
  225.     int totalScreens;        /* in:  number of screens in the screen list */
  226.     int screenIndex;        /* in:  this screen (0..totalScreens) */
  227.     int screenShmemSize;    /* in:  this screen's desired shmem size */
  228.     Bounds screenBounds;    /* in:  this screen's global bounds */
  229. };
  230.  
  231. /* General ioctls */
  232.  
  233. #define EVIOSEP      _IOW('e', 1, port_t)           /* Set event port */
  234. #define EVIOLLPE  _IOW('e', 2, struct evioLLEvent) /* Low-level Post Event */
  235. #define EVIOMM      _IOR('e', 3, void)           /* mini_mon (gone) */
  236. #define EVIOSSCR  _IOWR('e', 4, struct evioSetScreen) /* set up screens */
  237.  
  238. /* Mouse-related ioctls */
  239.  
  240. #define EVIOSD      _IOWR('e', 66, int)           /* StillDown */
  241. #define    EVIORSD      _IOWR('e', 67, int)           /* RightStillDown */
  242. #define    EVIOSM      _IOW('e', 68, Point)           /* SetMouse */
  243. #define    EVIOCM      _IOR('e', 69, Point)           /* CurrentMouse */
  244. #define EVIOST    _IO('e', 70)               /* StartCursor */
  245.  
  246. #endif _M68K_DEV_EVIO_
  247.