|
|
1.1 ! root 1: /*- ! 2: * sunInit.c -- ! 3: * Initialization functions for screen/keyboard/mouse, etc. ! 4: * ! 5: * Copyright (c) 1987 by the Regents of the University of California ! 6: * ! 7: * Permission to use, copy, modify, and distribute this ! 8: * software and its documentation for any purpose and without ! 9: * fee is hereby granted, provided that the above copyright ! 10: * notice appear in all copies. The University of California ! 11: * makes no representations about the suitability of this ! 12: * software for any purpose. It is provided "as is" without ! 13: * express or implied warranty. ! 14: * ! 15: * ! 16: */ ! 17: ! 18: /************************************************************ ! 19: Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. ! 20: ! 21: All Rights Reserved ! 22: ! 23: Permission to use, copy, modify, and distribute this ! 24: software and its documentation for any purpose and without ! 25: fee is hereby granted, provided that the above copyright no- ! 26: tice appear in all copies and that both that copyright no- ! 27: tice and this permission notice appear in supporting docu- ! 28: mentation, and that the names of Sun or MIT not be used in ! 29: advertising or publicity pertaining to distribution of the ! 30: software without specific prior written permission. Sun and ! 31: M.I.T. make no representations about the suitability of this ! 32: software for any purpose. It is provided "as is" without any ! 33: express or implied warranty. ! 34: ! 35: SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, ! 36: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- ! 37: NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- ! 38: ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 39: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR ! 40: PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR ! 41: OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH ! 42: THE USE OR PERFORMANCE OF THIS SOFTWARE. ! 43: ! 44: ********************************************************/ ! 45: ! 46: #ifndef lint ! 47: static char sccsid[] = "%W %G Copyright 1987 Sun Micro"; ! 48: #endif ! 49: ! 50: #include "sun.h" ! 51: #include <servermd.h> ! 52: #include "dixstruct.h" ! 53: #include "dix.h" ! 54: #include "opaque.h" ! 55: ! 56: extern int sunMouseProc(); ! 57: extern void sunKbdProc(); ! 58: extern Bool sunBW2Probe(); ! 59: ! 60: extern void SetInputCheck(); ! 61: extern GCPtr CreateScratchGC(); ! 62: ! 63: /* What should this *really* be? */ ! 64: #define MOTION_BUFFER_SIZE 0 ! 65: ! 66: sunFbDataRec sunFbData[] = { ! 67: sunBW2Probe, "/dev/bwtwo0", neverProbed, ! 68: }; ! 69: ! 70: /* ! 71: * NUMSCREENS is the number of supported frame buffers (i.e. the number of ! 72: * structures in sunFbData which have an actual probeProc). ! 73: */ ! 74: #define NUMSCREENS (sizeof(sunFbData)/sizeof(sunFbData[0])) ! 75: ! 76: fbFd sunFbs[NUMSCREENS]; /* Space for descriptors of open frame buffers */ ! 77: ! 78: static PixmapFormatRec formats[] = { ! 79: 1, 1, BITMAP_SCANLINE_PAD, /* 1-bit deep */ ! 80: }; ! 81: #define NUMFORMATS (sizeof formats)/(sizeof formats[0]) ! 82: ! 83: /*- ! 84: *----------------------------------------------------------------------- ! 85: * InitOutput -- ! 86: * Initialize screenInfo for all actually accessible framebuffers. ! 87: * The ! 88: * ! 89: * Results: ! 90: * screenInfo init proc field set ! 91: * ! 92: * Side Effects: ! 93: * None ! 94: * ! 95: *----------------------------------------------------------------------- ! 96: */ ! 97: ! 98: InitOutput(pScreenInfo, argc, argv) ! 99: ScreenInfo *pScreenInfo; ! 100: int argc; ! 101: char **argv; ! 102: { ! 103: int i, index, ac = argc; ! 104: ! 105: pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER; ! 106: pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; ! 107: pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD; ! 108: pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER; ! 109: ! 110: pScreenInfo->numPixmapFormats = NUMFORMATS; ! 111: for (i=0; i< NUMFORMATS; i++) ! 112: { ! 113: pScreenInfo->formats[i] = formats[i]; ! 114: } ! 115: ! 116: for (i = 0, index = 0; i < NUMSCREENS; i++) { ! 117: if ((* sunFbData[i].probeProc) (pScreenInfo, index, i, argc, argv)) { ! 118: /* This display exists OK */ ! 119: index++; ! 120: } else { ! 121: /* This display can't be opened */ ! 122: ; ! 123: } ! 124: } ! 125: if (index == 0) ! 126: FatalError("Can't find any displays\n"); ! 127: ! 128: pScreenInfo->numScreens = index; ! 129: ! 130: sunInitCursor(); ! 131: } ! 132: ! 133: /*- ! 134: *----------------------------------------------------------------------- ! 135: * InitInput -- ! 136: * Initialize all supported input devices...what else is there ! 137: * besides pointer and keyboard? ! 138: * ! 139: * Results: ! 140: * None. ! 141: * ! 142: * Side Effects: ! 143: * Two DeviceRec's are allocated and registered as the system pointer ! 144: * and keyboard devices. ! 145: * ! 146: *----------------------------------------------------------------------- ! 147: */ ! 148: /*ARGSUSED*/ ! 149: InitInput(argc, argv) ! 150: int argc; ! 151: char **argv; ! 152: { ! 153: DevicePtr p, k; ! 154: static int zero = 0; ! 155: ! 156: p = AddInputDevice(sunMouseProc, TRUE); ! 157: k = AddInputDevice(sunKbdProc, TRUE); ! 158: ! 159: RegisterPointerDevice(p, MOTION_BUFFER_SIZE); ! 160: RegisterKeyboardDevice(k); ! 161: ! 162: SetInputCheck (&zero, &isItTimeToYield); ! 163: } ! 164: ! 165: /*- ! 166: *----------------------------------------------------------------------- ! 167: * sunQueryBestSize -- ! 168: * Supposed to hint about good sizes for things. ! 169: * ! 170: * Results: ! 171: * Perhaps change *pwidth (Height irrelevant) ! 172: * ! 173: * Side Effects: ! 174: * None. ! 175: * ! 176: *----------------------------------------------------------------------- ! 177: */ ! 178: /*ARGSUSED*/ ! 179: void ! 180: sunQueryBestSize(class, pwidth, pheight) ! 181: int class; ! 182: short *pwidth; ! 183: short *pheight; ! 184: { ! 185: unsigned width, test; ! 186: ! 187: switch(class) ! 188: { ! 189: case CursorShape: ! 190: case TileShape: ! 191: case StippleShape: ! 192: width = *pwidth; ! 193: if (width > 0) { ! 194: /* Return the closes power of two not less than what they gave me */ ! 195: test = 0x80000000; ! 196: /* Find the highest 1 bit in the width given */ ! 197: while(!(test & width)) ! 198: test >>= 1; ! 199: /* If their number is greater than that, bump up to the next ! 200: * power of two */ ! 201: if((test - 1) & width) ! 202: test <<= 1; ! 203: *pwidth = test; ! 204: } ! 205: /* We don't care what height they use */ ! 206: break; ! 207: } ! 208: } ! 209: ! 210: /*- ! 211: *----------------------------------------------------------------------- ! 212: * sunScreenInit -- ! 213: * Things which must be done for all types of frame buffers... ! 214: * Should be called last of all. ! 215: * ! 216: * Results: ! 217: * None. ! 218: * ! 219: * Side Effects: ! 220: * The graphics context for the screen is created. The CreateGC, ! 221: * CreateWindow and ChangeWindowAttributes vectors are changed in ! 222: * the screen structure. ! 223: * ! 224: * Both a BlockHandler and a WakeupHandler are installed for the ! 225: * first screen. Together, these handlers implement autorepeat ! 226: * keystrokes on the Sun. ! 227: * ! 228: *----------------------------------------------------------------------- ! 229: */ ! 230: void ! 231: sunScreenInit (pScreen) ! 232: ScreenPtr pScreen; ! 233: { ! 234: fbFd *fb; ! 235: DrawablePtr pDrawable; ! 236: ! 237: fb = &sunFbs[pScreen->myNum]; ! 238: ! 239: /* ! 240: * Prepare the GC for cursor functions on this screen. ! 241: * Do this before setting interceptions to avoid looping when ! 242: * putting down the cursor... ! 243: */ ! 244: pDrawable = (DrawablePtr)(pScreen->devPrivate); ! 245: ! 246: fb->pGC = CreateScratchGC (pDrawable->pScreen, pDrawable->depth); ! 247: ! 248: /* ! 249: * By setting graphicsExposures false, we prevent any expose events ! 250: * from being generated in the CopyArea requests used by the cursor ! 251: * routines. ! 252: */ ! 253: fb->pGC->graphicsExposures = FALSE; ! 254: ! 255: /* ! 256: * Preserve the "regular" functions ! 257: */ ! 258: fb->CreateGC = pScreen->CreateGC; ! 259: fb->CreateWindow = pScreen->CreateWindow; ! 260: fb->ChangeWindowAttributes = pScreen->ChangeWindowAttributes; ! 261: fb->GetImage = pScreen->GetImage; ! 262: fb->GetSpans = pScreen->GetSpans; ! 263: ! 264: /* ! 265: * Interceptions ! 266: */ ! 267: pScreen->CreateGC = sunCreateGC; ! 268: pScreen->CreateWindow = sunCreateWindow; ! 269: pScreen->ChangeWindowAttributes = sunChangeWindowAttributes; ! 270: pScreen->QueryBestSize = sunQueryBestSize; ! 271: pScreen->GetImage = sunGetImage; ! 272: pScreen->GetSpans = sunGetSpans; ! 273: ! 274: /* ! 275: * Cursor functions ! 276: */ ! 277: pScreen->RealizeCursor = sunRealizeCursor; ! 278: pScreen->UnrealizeCursor = sunUnrealizeCursor; ! 279: pScreen->DisplayCursor = sunDisplayCursor; ! 280: pScreen->SetCursorPosition = sunSetCursorPosition; ! 281: pScreen->CursorLimits = sunCursorLimits; ! 282: pScreen->PointerNonInterestBox = sunPointerNonInterestBox; ! 283: pScreen->ConstrainCursor = sunConstrainCursor; ! 284: pScreen->RecolorCursor = sunRecolorCursor; ! 285: ! 286: } ! 287: ! 288: /*- ! 289: *----------------------------------------------------------------------- ! 290: * sunOpenFrameBuffer -- ! 291: * Open a frame buffer. ! 292: * ! 293: * Results: ! 294: * The fd of the framebuffer. ! 295: * ! 296: * Side Effects: ! 297: * ! 298: *----------------------------------------------------------------------- ! 299: */ ! 300: int ! 301: sunOpenFrameBuffer(expect, pfbType, index, fbNum, argc, argv) ! 302: int expect; /* The expected type of framebuffer */ ! 303: struct fbtype *pfbType; /* Place to store the fb info */ ! 304: int fbNum; /* Index into the sunFbData array */ ! 305: int index; /* Screen index */ ! 306: int argc; /* Command-line arguments... */ ! 307: char **argv; /* ... */ ! 308: { ! 309: char *name; ! 310: int fd = -1; /* Descriptor to device */ ! 311: ! 312: name = "/dev/fb"; ! 313: fd = open(name, 2); ! 314: if (fd < 0) { ! 315: return (-1); ! 316: } ! 317: if (ioctl(fd, FBIOGTYPE, pfbType) < 0) { ! 318: perror("sunOpenFrameBuffer"); ! 319: (void) close(fd); ! 320: return (-1); ! 321: } ! 322: if (pfbType->fb_type != expect) { ! 323: (void) close(fd); ! 324: return (-1); ! 325: } ! 326: return (fd); ! 327: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.