home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / dec / ws / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-26  |  7.0 KB  |  251 lines

  1. /***********************************************************
  2. Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /* $XConsortium: init.c,v 1.4 91/08/26 13:27:24 rws Exp $ */
  26.  
  27. #include <stdio.h>
  28. #include <sys/types.h>
  29. #include <sys/file.h>
  30. #include <sys/time.h>
  31. #include <sys/tty.h>
  32. #include <errno.h>
  33. #include <sys/devio.h>
  34.  
  35. #include "X.h"
  36.  
  37. #include "scrnintstr.h"
  38. #include "servermd.h"
  39.  
  40. #include "input.h"
  41. /* XXX */
  42. #include <sys/workstation.h>
  43. #include <sys/inputdevice.h>
  44. #include "ws.h"
  45.  
  46. extern void wsMouseProc();
  47. extern void wsKeybdProc();
  48. extern void wsClick();
  49. extern void wsChangePointerControl();
  50. extern KeybdCtrl defaultKeyboardControl;
  51. ws_event_queue    *queue;
  52.  
  53. #define NUMFORMATS 2
  54. static    PixmapFormatRec formats[] = {
  55.     {1, 1, BITMAP_SCANLINE_PAD},     /* 1 bit deep */
  56.     {8, 8, BITMAP_SCANLINE_PAD},     /* 8-bit deep */
  57.     {24, 32, BITMAP_SCANLINE_PAD},
  58. };
  59.  
  60. Bool fbInitProc();
  61. extern int num_accelerator_types;
  62.  
  63. extern wsAcceleratorTypes types[];
  64.  
  65. ws_screen_descriptor screenDesc[MAXSCREENS];
  66.  
  67. Bool
  68. commandLineMatch( argc, argv, pat, pmatch)
  69.     int         argc;           /* may NOT be changed */
  70.     char *      argv[];         /* may NOT be changed */
  71.     char *      pat;
  72. {
  73.     int         ic;
  74.  
  75.     for ( ic=0; ic<argc; ic++)
  76.         if ( strcmp( argv[ic], pat) == 0)
  77.             return TRUE;
  78.     return FALSE;
  79. }
  80.  
  81. Bool
  82. commandLinePairMatch( argc, argv, pat, pmatch)
  83.     int         argc;           /* may NOT be changed */
  84.     char *      argv[];         /* may NOT be changed */
  85.     char *      pat;
  86.     char **     pmatch;         /* RETURN */
  87. {
  88.     register int         ic;
  89.  
  90.     for ( ic=0; ic<argc; ic++)
  91.         if ( strcmp( argv[ic], pat) == 0) {
  92.             *pmatch = argv[ ic+1];
  93.             return TRUE;
  94.     }
  95.     return FALSE;
  96. }
  97.  
  98. ws_descriptor wsinfo;
  99. int wsFd;
  100. int ws_cpu;
  101.  
  102. int wsScreenPrivateIndex;
  103. /* the following filth is forced by a broken dix interface */
  104.  
  105. InitOutput(screenInfo, argc, argv)
  106.     ScreenInfo *screenInfo;
  107.     int argc;
  108.     char **argv;
  109. {
  110.     int i;
  111.     int si = 0;
  112.     static int inited = FALSE;
  113.     static int ma = 4;
  114.     static int mt = 4;
  115.     static PtrCtrl ctrl;
  116.     static int  clicklevel;
  117.  
  118.     screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
  119.     screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
  120.     screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
  121.     screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
  122.     screenInfo->numPixmapFormats = NUMFORMATS;
  123.  
  124.     for (i=0; i< NUMFORMATS; i++) {
  125.     screenInfo->formats[i].depth = formats[i].depth;
  126.     screenInfo->formats[i].bitsPerPixel = formats[i].bitsPerPixel;
  127.     screenInfo->formats[i].scanlinePad = formats[i].scanlinePad;
  128.     }
  129.  
  130.     if (!inited) {
  131.     char *clickvolume;
  132.     char *mouseAcceleration;
  133.     char *mouseThreshold;
  134.     ws_keyboard_control control;
  135.         inited = TRUE;
  136.         if ((wsFd = open("/dev/mouse",  O_RDWR, 0)) < 0) {
  137.         ErrorF("couldn't open device\n");
  138.         exit (1);
  139.     }
  140.     if (ioctl (wsFd, GET_WORKSTATION_INFO, &wsinfo) != 0) {
  141.         ErrorF("GET_WORKSTATION_INFO failed \n");
  142.         exit(1);
  143.     }
  144.     control.device_number = wsinfo.console_keyboard;
  145.     if (ioctl(wsFd, GET_KEYBOARD_CONTROL, &control) == -1) {
  146.         ErrorF("GET_KEYBOARD_CONTROL failed\n");
  147.         exit(1);
  148.     }
  149.     defaultKeyboardControl.click = control.click;
  150.     defaultKeyboardControl.bell = control.bell;
  151.     defaultKeyboardControl.bell_pitch = control.bell_pitch;
  152.     defaultKeyboardControl.bell_duration = control.bell_duration;
  153.     defaultKeyboardControl.autoRepeat = control.auto_repeat;
  154.     defaultKeyboardControl.leds = control.leds;
  155.     bcopy (control.autorepeats, defaultKeyboardControl.autoRepeats, 32);
  156.     
  157.     /* turn off cursors on additional screens initially */
  158. /* 
  159.  * jmg - have to do a lot of other stuff here dealing with visuals
  160.  *  and depths 
  161.  */
  162.        /*
  163.     * deal with arguments.  Note we don't bother until we've successfully
  164.     * opened the device.
  165.     */
  166.  
  167.     if (commandLinePairMatch( argc, argv, "c", &clickvolume))
  168.         sscanf( clickvolume, "%d", &clicklevel);
  169.     if (commandLinePairMatch( argc, argv, "-a", &mouseAcceleration))
  170.         sscanf( mouseAcceleration, "%d", &ma);
  171.     if (commandLinePairMatch( argc, argv, "-t", &mouseThreshold))
  172.         sscanf( mouseThreshold, "%d", &mt);
  173.  
  174.     }
  175.     ctrl.num = ma;
  176.     ctrl.den = 1;
  177.     ctrl.threshold = mt;
  178.     wsChangePointerControl( (DevicePtr) NULL, &ctrl);
  179.     wsClick(clicklevel);
  180.     if (commandLineMatch(argc, argv, "-c")) wsClick(0);
  181.     wsScreenPrivateIndex = AllocateScreenPrivateIndex();
  182.     ws_cpu = wsinfo.cpu;
  183.     for(i = 0; i < wsinfo.num_screens_exist; i++) {
  184.     int j, DECaccelerator = FALSE;
  185.     screenDesc[si].screen = i;
  186.     if (ioctl(wsFd,     GET_SCREEN_INFO, &screenDesc[si]) == -1) {
  187.         ErrorF("GET_SCREEN_INFO failed\n");
  188.         exit(1);
  189.     }
  190.     if (si >= MAXSCREENS) {
  191.         ErrorF ("Server configured for %d screens, can't configure screen %d\n", MAXSCREENS, si);
  192.         break;
  193.     }
  194.     for (j = 0; j < num_accelerator_types; j++) {
  195.         if (strcmp (screenDesc[si].moduleID, types[j].moduleID) == 0) {
  196.         DECaccelerator = TRUE;
  197.         break;
  198.         }
  199.     }
  200.         if(DECaccelerator)
  201.         j = AddScreen(types[j].createProc, argc, argv);
  202.     else
  203.         j = AddScreen(fbInitProc, argc, argv);
  204.     /*
  205.      * AddScreen either returns -1 (error) or # of screens installed
  206.      * (current index).  screenDesc[] is exactly parallel to
  207.      * screenInfo.screens[] since the initProc() arg will be called
  208.      * with AddScreen's index, which in turn gets used for screenDesc[].
  209.      */
  210.     if (j == -1) {
  211.         ErrorF("Could not AddScreen, ID = %s\n",
  212.             screenDesc[si].moduleID);
  213.     } else
  214.         si = j+1;
  215.     }
  216. #ifdef XINPUT
  217.     ExtInitOutput(screenInfo, argc, argv);
  218. #endif
  219. }
  220.  
  221.  
  222.  
  223. void
  224. InitInput(argc, argv)
  225.     int argc;
  226.     char *argv[];
  227. {
  228.     DevicePtr p, k;
  229.     static int inited = FALSE;
  230.     
  231.     p = AddInputDevice(wsMouseProc, TRUE);
  232.  
  233.     k = AddInputDevice(wsKeybdProc, TRUE);
  234.  
  235.     RegisterPointerDevice(p);
  236.     RegisterKeyboardDevice(k);
  237.  
  238. #ifdef XINPUT
  239.     ExtInitInput(argc, argv);
  240. #endif
  241.  
  242.     if (!inited) {
  243.     inited = TRUE;
  244.     if (ioctl(wsFd,  GET_AND_MAP_EVENT_QUEUE, &queue) == -1)  {
  245.         ErrorF("GET_AND_MAP_EVENT_QUEUE failed\n");
  246.         exit(1);
  247.     }
  248.     }
  249.     SetTimeSinceLastInputEvent ();
  250. }
  251.