home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / common / ibmInit.c < prev    next >
C/C++ Source or Header  |  1991-09-20  |  8KB  |  265 lines

  1. /*
  2.  * $Id: ibmInit.c,v 1.1 1991/09/20 19:59:51 mtranle Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that 
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22.  * SOFTWARE.
  23.  *
  24. */
  25. /***********************************************************
  26. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  27. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  28.  
  29.             All Rights Reserved
  30.  
  31. Permission to use, copy, modify, and distribute this software and its
  32. documentation for any purpose and without fee is hereby granted,
  33. provided that the above copyright notice appear in all copies and that
  34. both that copyright notice and this permission notice appear in
  35. supporting documentation, and that the names of Digital or MIT not be
  36. used in advertising or publicity pertaining to distribution of the
  37. software without specific, written prior permission.
  38.  
  39. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  40. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  41. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  42. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  43. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  44. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  45. SOFTWARE.
  46.  
  47. ******************************************************************/
  48.  
  49. #include "X.h"
  50. #include "servermd.h"
  51. #include "site.h"
  52. #include "misc.h"
  53. #include "miscstruct.h"
  54. #include "input.h"
  55. #include "opaque.h"
  56. #include "scrnintstr.h"
  57. #include "cursorstr.h"
  58.  
  59. #include "ibmScreen.h"
  60.  
  61. #include "ibmKeybd.h"
  62. #include "ibmMouse.h"
  63.  
  64. #include "ibmCmdArgs.h"
  65.  
  66. #include "OSio.h"
  67.  
  68. #include "ibmTrace.h"
  69.  
  70. extern void ibmInfoMsg() ;
  71.  
  72. #define NUMDEVICES 2
  73.  
  74. /* Command-Line Globals */
  75. int ibmOpenAllScreens = FALSE ;
  76. int ibmScreensWanted = 0 ;
  77.  
  78. static Bool
  79. ibmFormatExists( screenInfo, newFmt )
  80. ScreenInfo *screenInfo ;
  81. PixmapFormatPtr newFmt ;
  82. {
  83.     PixmapFormatPtr oldFmt ;
  84.     int ndx ;
  85.  
  86.     TRACE( ("ibmFormatExisits(screenInfo=0x%x,newFmt=0x%x(%d,%d,%d))\n",
  87.        screenInfo, newFmt, newFmt->depth,
  88.        newFmt->bitsPerPixel, newFmt->scanlinePad ) ) ;
  89.  
  90.     for ( ndx = 0 ; ndx < screenInfo->numPixmapFormats ; ndx++ ) {
  91.     oldFmt = &screenInfo->formats[ndx] ;
  92.     if ( ( newFmt->depth == oldFmt->depth )
  93.       && ( newFmt->bitsPerPixel == oldFmt->bitsPerPixel )
  94.       && ( newFmt->scanlinePad == oldFmt->scanlinePad ) )
  95.         return TRUE ;
  96.     }
  97.     return FALSE ;
  98. }
  99.  
  100. /***==================================================================***/
  101.  
  102. static int
  103. ibmFindSomeScreens()
  104. {
  105. register ibmPerScreenInfo **scrPtr = ibmPossibleScreens ;
  106. register ibmPerScreenInfo *scr ;
  107. extern void OS_GetDefaultScreens() ;
  108.  
  109.     TRACE(("ibmFindSomeScreens()\n")) ;
  110.     OS_GetDefaultScreens() ;
  111.     if ( !ibmNumScreens ) {
  112.     while ( ( scr = *scrPtr++ ) && scr->ibm_ScreenFlag ) {
  113.         if ( ( scr->ibm_ScreenFD = (* scr->ibm_ProbeFunc)() ) >= 0 ) {
  114.         ibmScreens[ibmNumScreens++]= scr ;
  115.         if ( !ibmOpenAllScreens )
  116.             return TRUE ;
  117.         }
  118.         else
  119.         scr->ibm_ScreenFD = -1 ;
  120.     }
  121.     }
  122.     else
  123.     return TRUE ;
  124.  
  125.     return ( ibmNumScreens > 0 ) && ibmOpenAllScreens ;
  126. }
  127.  
  128. /***==================================================================***/
  129.  
  130. static void
  131. ibmAddScreens( screenInfo, argc, argv )
  132. ScreenInfo *screenInfo ;
  133. int argc ;
  134. char *argv[] ;
  135. {
  136.     PixmapFormatPtr newFmt, oldFmt ;
  137.     int ndx, fmtNdx ;
  138.     static int been_here ;
  139.  
  140.     TRACE( ( "ibmAddScreens(screenInfo=0x%x,argc= %d,argv=x%x)\n",
  141.        screenInfo, argc, argv ) ) ;
  142.  
  143.     for ( ndx = 0 ; ndx < ibmNumScreens ; ndx++ ) {
  144.     if ( !been_here ) {
  145.         if ( ibmScreens[ndx]->ibm_Wanted ) {
  146.         ErrorF( "Multiple requests for screen '%s'  -- ignored\n",
  147.             ibmScreenFlag( ndx ) ) ;
  148.         continue ;
  149.         }
  150.         ibmScreens[ndx]->ibm_Wanted = TRUE ;
  151. #if !defined(AIXrt) && !defined(IBM_OS_HAS_HFT)
  152.         if ( ndx > 0 ) {
  153.         ibmScreenMinX( ndx ) += ibmScreenMaxX( ndx - 1 ) ;
  154.         ibmScreenMaxX( ndx ) += ibmScreenMaxX( ndx - 1 ) ;
  155.         }
  156. #endif /* AIX/HFT */
  157.     }
  158.  
  159.     for ( fmtNdx = 0 ; fmtNdx < ibmNumFormats( ndx ) ; fmtNdx++ ) {
  160.         if ( !ibmFormatExists( screenInfo,
  161.                    &ibmScreenFormats( ndx )[ fmtNdx ] ) ) {
  162.         newFmt = &ibmScreenFormats( ndx )[ fmtNdx ] ;
  163.         oldFmt = &screenInfo->formats[ screenInfo->numPixmapFormats++] ;
  164.         oldFmt->depth = newFmt->depth ;
  165.         oldFmt->bitsPerPixel = newFmt->bitsPerPixel ;
  166.         oldFmt->scanlinePad = newFmt->scanlinePad ;
  167.         if ( screenInfo->numPixmapFormats > MAXFORMATS ) {
  168.             ErrorF( "WSGO!! Too many formats! Exiting\n" ) ;
  169.             exit( 1 ) ;
  170.         }
  171.         }
  172.     }
  173.     ibmSetScreenState( ndx, SCREEN_ACTIVE ) ;
  174.     AddScreen( ibmScreenInit( ndx ), argc, argv ) ;
  175.     }
  176.     been_here = TRUE ;
  177.     return ;
  178. }
  179.  
  180. /***==================================================================***/
  181.  
  182. static DevicePtr keyboard ;
  183. static DevicePtr mouse ;
  184.  
  185. void
  186. InitInput()
  187. {
  188. extern DevicePtr OS_MouseProc(), OS_KeybdProc() ;
  189. extern void OS_InitInput() ;
  190. extern void OS_AddAndRegisterOtherDevices() ;
  191.  
  192.     TRACE( ( "InitInput()\n" ) ) ;
  193.  
  194.     OS_InitInput() ;
  195.     mouse = AddInputDevice( OS_MouseProc, TRUE ) ;
  196.     keyboard = AddInputDevice( OS_KeybdProc, TRUE ) ;
  197.  
  198.     RegisterPointerDevice( mouse ) ;
  199.     RegisterKeyboardDevice( keyboard ) ;
  200.  
  201.     OS_AddAndRegisterOtherDevices() ;
  202.     return ;
  203. }
  204.  
  205. /***==================================================================***/
  206.  
  207. extern void ibmPrintBuildDate() ;
  208. extern int ibmAllowBackingStore ;
  209. extern Bool disableBackingStore ;
  210.  
  211. void
  212. InitOutput( screenInfo, argc, argv )
  213.     ScreenInfo *screenInfo ;
  214.     int argc ;
  215.     char *argv[] ;
  216. {
  217.     static int been_here = 0 ;
  218.     extern void OS_PreScreenInit() ;    /* usually opens /dev/bus */
  219.     extern void OS_PostScreenInit() ;
  220.  
  221.     TRACE( ( "InitOutput(screenInfo=0x%x)\n", screenInfo ) ) ;
  222.  
  223.     screenInfo->imageByteOrder = IMAGE_BYTE_ORDER ;
  224.     screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT ;
  225.     screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD ;
  226.     screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER ;
  227.  
  228.     screenInfo->numPixmapFormats = 1 ;
  229.     screenInfo->formats[0].depth = 1 ;
  230.     screenInfo->formats[0].bitsPerPixel = 1 ;
  231.     screenInfo->formats[0].scanlinePad = BITMAP_SCANLINE_PAD ;
  232.  
  233.     if ( !been_here ) {
  234.     been_here = TRUE ;
  235.  
  236.     /*
  237.      * let dix command parsing figure out if we do backing store.
  238.      */
  239.     ibmAllowBackingStore = !disableBackingStore;
  240.  
  241.     if ( ibmNumScreens != ibmScreensWanted ) {
  242.         ErrorF( "Couldn't open all requested screens.\n" ) ;
  243.         exit( 1 ) ;
  244.     }
  245.     else if ( !ibmNumScreens && !ibmFindSomeScreens() ) {
  246.         ErrorF( "Couldn't open any screens.\n" ) ;
  247.         exit( 1 ) ;
  248.     }
  249.  
  250.     /* Informational Messages */
  251.     ibmPrintBuildDate() ;
  252.     ibmInfoMsg(
  253.   "X Window System protocol version %d, revision %d (vendor release %d)\n",
  254.         X_PROTOCOL, X_PROTOCOL_REVISION, VENDOR_RELEASE ) ;
  255.  
  256.     OS_PreScreenInit() ;    /* usually opens /dev/bus */
  257.     ibmInfoMsg( ibmUsePCKeys
  258.             ? "Using PC keyboard layout...\n"
  259.             : "Using RT keyboard layout...\n" ) ;
  260.     }
  261.     ibmAddScreens( screenInfo, argc, argv ) ;
  262.     OS_PostScreenInit() ;
  263.     return ;
  264. }
  265.