예제 #1
0
파일: winkeybd.c 프로젝트: 4eremuxa/xserver
int
winKeybdProc (DeviceIntPtr pDeviceInt, int iState)
{
  DevicePtr		pDevice = (DevicePtr) pDeviceInt;
  XkbSrvInfoPtr       xkbi;
  XkbControlsPtr      ctrl;

  switch (iState)
    {
    case DEVICE_INIT:
      winConfigKeyboard (pDeviceInt);

      /* FIXME: Maybe we should use winGetKbdLeds () here? */
      defaultKeyboardControl.leds = g_winInfo.keyboard.leds;

      winErrorFVerb(2, "Rules = \"%s\" Model = \"%s\" Layout = \"%s\""
                    " Variant = \"%s\" Options = \"%s\"\n",
                    g_winInfo.xkb.rules ? g_winInfo.xkb.rules : "none",
                    g_winInfo.xkb.model ? g_winInfo.xkb.model : "none",
                    g_winInfo.xkb.layout ? g_winInfo.xkb.layout : "none",
                    g_winInfo.xkb.variant ? g_winInfo.xkb.variant : "none",
                    g_winInfo.xkb.options ? g_winInfo.xkb.options : "none");

      InitKeyboardDeviceStruct (pDeviceInt,
                                &g_winInfo.xkb,
                                winKeybdBell,
                                winKeybdCtrl);

      xkbi = pDeviceInt->key->xkbInfo;
      if ((xkbi != NULL) && (xkbi->desc != NULL))
        {
          ctrl = xkbi->desc->ctrls;
          ctrl->repeat_delay = g_winInfo.keyboard.delay;
          ctrl->repeat_interval = 1000/g_winInfo.keyboard.rate;
        }
      else
        {
          winErrorFVerb (1, "winKeybdProc - Error initializing keyboard AutoRepeat\n");
        }

      break;
      
    case DEVICE_ON: 
      pDevice->on = TRUE;

      // immediately copy the state of this keyboard device to the VCK
      // (which otherwise happens lazily after the first keypress)
      CopyKeyClass(pDeviceInt, inputInfo.keyboard);
      break;

    case DEVICE_CLOSE:
    case DEVICE_OFF: 
      pDevice->on = FALSE;
      break;
    }

  return Success;
}
예제 #2
0
void
winDetectSupportedEngines(void)
{
    /* Initialize the engine support flags */
    g_dwEnginesSupported = WIN_SERVER_SHADOW_GDI;

    /* Do we have DirectDraw? */
    if (g_hmodDirectDraw != NULL) {
        LPDIRECTDRAW lpdd = NULL;
        LPDIRECTDRAW4 lpdd4 = NULL;
        HRESULT ddrval;

        /* Was the DirectDrawCreate function found? */
        if (g_fpDirectDrawCreate == NULL) {
            /* No DirectDraw support */
            return;
        }

        /* DirectDrawCreate exists, try to call it */
        /* Create a DirectDraw object, store the address at lpdd */
        ddrval = (*g_fpDirectDrawCreate) (NULL, (void **) &lpdd, NULL);
        if (FAILED(ddrval)) {
            /* No DirectDraw support */
            winErrorFVerb(2,
                          "winDetectSupportedEngines - DirectDraw not installed\n");
            return;
        }

        /* Try to query for DirectDraw4 interface */
        ddrval = IDirectDraw_QueryInterface(lpdd,
                                            &IID_IDirectDraw4,
                                            (LPVOID *) &lpdd4);
        if (SUCCEEDED(ddrval)) {
            /* We have DirectDraw4 */
            winErrorFVerb(2,
                          "winDetectSupportedEngines - DirectDraw4 installed, allowing ShadowDDNL\n");
            g_dwEnginesSupported |= WIN_SERVER_SHADOW_DDNL;
        }

        /* Cleanup DirectDraw interfaces */
        if (lpdd4 != NULL)
            IDirectDraw_Release(lpdd4);
        if (lpdd != NULL)
            IDirectDraw_Release(lpdd);
    }

    winErrorFVerb(2,
                  "winDetectSupportedEngines - Returning, supported engines %08x\n",
                  (unsigned int) g_dwEnginesSupported);
}
예제 #3
0
static void
winPointerWarpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
{
  winScreenPriv(pScreen);
  RECT			rcClient;
  static Bool		s_fInitialWarp = TRUE;

  /* Discard first warp call */
  if (s_fInitialWarp)
    {
      /* First warp moves mouse to center of window, just ignore it */

      /* Don't ignore subsequent warps */
      s_fInitialWarp = FALSE;

      winErrorFVerb (2, "winPointerWarpCursor - Discarding first warp: %d %d\n",
	      x, y);
      
      return;
    }

  /*
     Only update the Windows cursor position if root window is active,
     or we are in a rootless mode
  */
  if ((pScreenPriv->hwndScreen == GetForegroundWindow ())
      || pScreenPriv->pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
      || pScreenPriv->pScreenInfo->fMultiWindow
#endif
      )
    {
      /* Get the client area coordinates */
      GetClientRect (pScreenPriv->hwndScreen, &rcClient);
      
      /* Translate the client area coords to screen coords */
      MapWindowPoints (pScreenPriv->hwndScreen,
		       HWND_DESKTOP,
		       (LPPOINT)&rcClient,
		       2);
      
      /* 
       * Update the Windows cursor position so that we don't
       * immediately warp back to the current position.
       */
      SetCursorPos (rcClient.left + x, rcClient.top + y);
    }

  /* Call the mi warp procedure to do the actual warping in X. */
  miPointerWarpCursor (pDev, pScreen, x, y);
}
예제 #4
0
void
winW32ErrorEx(int verb, const char *msg, DWORD errorcode)
{
    LPVOID buffer;
    if (!FormatMessage( 
                FORMAT_MESSAGE_ALLOCATE_BUFFER | 
                FORMAT_MESSAGE_FROM_SYSTEM | 
                FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL,
                errorcode,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                (LPTSTR) &buffer,
                0,
                NULL ))
    {
        winErrorFVerb(verb, "Unknown error in FormatMessage!\n"); 
    }
    else
    {
        winErrorFVerb(verb, "%s %s", msg, (char *)buffer); 
        LocalFree(buffer);
    }
}
예제 #5
0
static void
winInitializeScreen(int i)
{
  winErrorFVerb (2, "winInitializeScreen - %d\n",i);

  /* Initialize default screen values, if needed */
  winInitializeScreenDefaults();

  /* Copy the default screen info */
  g_ScreenInfo[i] = defaultScreenInfo;

  /* Set the screen number */
  g_ScreenInfo[i].dwScreen = i;
}
예제 #6
0
void
winInitializeScreens(int maxscreens)
{
  int i;
  winErrorFVerb (2, "winInitializeScreens - %i\n", maxscreens);

  if (maxscreens > g_iNumScreens)
    {
      /* Reallocate the memory for DDX-specific screen info */
      g_ScreenInfo = realloc(g_ScreenInfo, maxscreens * sizeof (winScreenInfo));

      /* Set default values for any new screens */
      for (i = g_iNumScreens; i < maxscreens ; i++)
        winInitializeScreen(i);

      /* Keep a count of the number of screens */
      g_iNumScreens = maxscreens;
    }
}
예제 #7
0
파일: InitOutput.c 프로젝트: csulmone/X11
void
InitOutput(ScreenInfo * screenInfo, int argc, char *argv[])
{
    int i;

    /* Log the command line */
    winLogCommandLine(argc, argv);

#if CYGDEBUG
    winDebug("InitOutput\n");
#endif

    /* Validate command-line arguments */
    if (serverGeneration == 1 && !winValidateArgs()) {
        FatalError("InitOutput - Invalid command-line arguments found.  "
                   "Exiting.\n");
    }

    /* Check for duplicate invocation on same display number. */
    if (serverGeneration == 1 && !winCheckDisplayNumber()) {
        if (g_fSilentDupError)
            g_fSilentFatalError = TRUE;
        FatalError("InitOutput - Duplicate invocation on display "
                   "number: %s.  Exiting.\n", display);
    }

#ifdef XWIN_XF86CONFIG
    /* Try to read the xorg.conf-style configuration file */
    if (!winReadConfigfile())
        winErrorFVerb(1, "InitOutput - Error reading config file\n");
#else
    winMsg(X_INFO, "xorg.conf is not supported\n");
    winMsg(X_INFO, "See http://x.cygwin.com/docs/faq/cygwin-x-faq.html "
           "for more information\n");
    winConfigFiles();
#endif

    /* Load preferences from XWinrc file */
    LoadPreferences();

    /* Setup global screen info parameters */
    screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
    screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
    screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
    screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
    screenInfo->numPixmapFormats = NUMFORMATS;

    /* Describe how we want common pixmap formats padded */
    for (i = 0; i < NUMFORMATS; i++) {
        screenInfo->formats[i] = g_PixmapFormats[i];
    }

    /* Load pointers to DirectDraw functions */
    winGetDDProcAddresses();

    /* Detect supported engines */
    winDetectSupportedEngines();

    /* Store the instance handle */
    g_hInstance = GetModuleHandle(NULL);

    /* Initialize each screen */
    for (i = 0; i < g_iNumScreens; ++i) {
        /* Initialize the screen */
        if (-1 == AddScreen(winScreenInit, argc, argv)) {
            FatalError("InitOutput - Couldn't add screen %d", i);
        }
    }

#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)

    /* Generate a cookie used by internal clients for authorization */
    if (g_fXdmcpEnabled || g_fAuthEnabled)
        winGenerateAuthorization();

    /* Perform some one time initialization */
    if (1 == serverGeneration) {
        /*
         * setlocale applies to all threads in the current process.
         * Apply locale specified in LANG environment variable.
         */
        setlocale(LC_ALL, "");
    }
#endif

#if CYGDEBUG || YES
    winDebug("InitOutput - Returning.\n");
#endif
}
예제 #8
0
static void
winInitializeScreenDefaults(void)
{
  DWORD dwWidth, dwHeight;
  static Bool fInitializedScreenDefaults = FALSE;

  /* Bail out early if default screen has already been initialized */
  if (fInitializedScreenDefaults)
    return;

  /* Zero the memory used for storing the screen info */
  memset(&defaultScreenInfo, 0, sizeof(winScreenInfo));

  /* Get default width and height */
  /*
   * NOTE: These defaults will cause the window to cover only
   * the primary monitor in the case that we have multiple monitors.
   */
  dwWidth = GetSystemMetrics (SM_CXSCREEN);
  dwHeight = GetSystemMetrics (SM_CYSCREEN);

  winErrorFVerb (2, "winInitializeScreenDefaults - w %d h %d\n",
	  (int) dwWidth, (int) dwHeight);

  /* Set a default DPI, if no parameter was passed */
  if (monitorResolution == 0)
    monitorResolution = WIN_DEFAULT_DPI;

  defaultScreenInfo.dwWidth  = dwWidth;
  defaultScreenInfo.dwHeight = dwHeight;
  defaultScreenInfo.dwUserWidth  = dwWidth;
  defaultScreenInfo.dwUserHeight = dwHeight;
  defaultScreenInfo.fUserGaveHeightAndWidth = WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH;
  defaultScreenInfo.fUserGavePosition = FALSE;
  defaultScreenInfo.dwBPP = WIN_DEFAULT_BPP;
  defaultScreenInfo.dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES;
#ifdef XWIN_EMULATEPSEUDO
  defaultScreenInfo.fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO;
#endif
  defaultScreenInfo.dwRefreshRate = WIN_DEFAULT_REFRESH;
  defaultScreenInfo.pfb = NULL;
  defaultScreenInfo.fFullScreen = FALSE;
  defaultScreenInfo.fDecoration = TRUE;
#ifdef XWIN_MULTIWINDOWEXTWM
  defaultScreenInfo.fMWExtWM = FALSE;
  defaultScreenInfo.fInternalWM = FALSE;
#endif
  defaultScreenInfo.fRootless = FALSE;
#ifdef XWIN_MULTIWINDOW
  defaultScreenInfo.fMultiWindow = FALSE;
#endif
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
  defaultScreenInfo.fMultiMonitorOverride = FALSE;
#endif
  defaultScreenInfo.fMultipleMonitors = FALSE;
  defaultScreenInfo.fLessPointer = FALSE;
  defaultScreenInfo.fScrollbars = FALSE;
  defaultScreenInfo.fNoTrayIcon = FALSE;
  defaultScreenInfo.iE3BTimeout = WIN_E3B_OFF;
  defaultScreenInfo.dwWidth_mm = (dwWidth / WIN_DEFAULT_DPI) * 25.4;
  defaultScreenInfo.dwHeight_mm = (dwHeight / WIN_DEFAULT_DPI) * 25.4;
  defaultScreenInfo.fUseWinKillKey = WIN_DEFAULT_WIN_KILL;
  defaultScreenInfo.fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL;
  defaultScreenInfo.fIgnoreInput = FALSE;
  defaultScreenInfo.fExplicitScreen = FALSE;

  /* Note that the default screen has been initialized */
  fInitializedScreenDefaults = TRUE;
}
static Bool
winBltExposedRegionsShadowDDNL (ScreenPtr pScreen)
{
  winScreenPriv(pScreen);
  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
  RECT			rcSrc, rcDest;
  POINT			ptOrigin;
  HDC			hdcUpdate;
  PAINTSTRUCT		ps;
  HRESULT		ddrval = DD_OK;
  Bool			fReturn = TRUE;
  int			i;

  /* Quite common case. The primary surface was lost (maybe because of depth
   * change). Try to create a new primary surface. Bail out if this fails */
  if (pScreenPriv->pddsPrimary4 == NULL && pScreenPriv->fRetryCreateSurface &&
      !winCreatePrimarySurfaceShadowDDNL(pScreen))
    {
      Sleep(100);
      return FALSE;
    }
  if (pScreenPriv->pddsPrimary4 == NULL)
    return FALSE;  
  
  /* BeginPaint gives us an hdc that clips to the invalidated region */
  hdcUpdate = BeginPaint (pScreenPriv->hwndScreen, &ps);
  if (hdcUpdate == NULL)
    {
      fReturn = FALSE;
      ErrorF ("winBltExposedRegionsShadowDDNL - BeginPaint () returned "
	      "a NULL device context handle.  Aborting blit attempt.\n");
      goto winBltExposedRegionsShadowDDNL_Exit;
    }

  /* Get the origin of the window in the screen coords */
  ptOrigin.x = pScreenInfo->dwXOffset;
  ptOrigin.y = pScreenInfo->dwYOffset;

  MapWindowPoints (pScreenPriv->hwndScreen,
		   HWND_DESKTOP,
		   (LPPOINT)&ptOrigin, 1);
  rcDest.left = ptOrigin.x;
  rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
  rcDest.top = ptOrigin.y;
  rcDest.bottom = ptOrigin.y + pScreenInfo->dwHeight;

  /* Source can be entire shadow surface, as Blt should clip for us */
  rcSrc.left = 0;
  rcSrc.top = 0;
  rcSrc.right = pScreenInfo->dwWidth;
  rcSrc.bottom = pScreenInfo->dwHeight;

  /* Try to regain the primary surface and blit again if we've lost it */
  for (i = 0; i <= WIN_REGAIN_SURFACE_RETRIES; ++i)
    {
      /* Our Blt should be clipped to the invalidated region */
      ddrval = IDirectDrawSurface4_Blt (pScreenPriv->pddsPrimary4,
					&rcDest,
					pScreenPriv->pddsShadow4,
					&rcSrc,
					DDBLT_WAIT,
					NULL);
      if (ddrval == DDERR_SURFACELOST)
	{
	  /* Surface was lost */
	  winErrorFVerb (1, "winBltExposedRegionsShadowDDNL - "
          "IDirectDrawSurface4_Blt reported that the primary "
          "surface was lost, trying to restore, retry: %d\n", i + 1);

	  /* Try to restore the surface, once */
	  
	  ddrval = IDirectDrawSurface4_Restore (pScreenPriv->pddsPrimary4);
	  winDebug ("winBltExposedRegionsShadowDDNL - "
		  "IDirectDrawSurface4_Restore returned: ");
	  if (ddrval == DD_OK)
	    winDebug ("DD_OK\n");
	  else if (ddrval == DDERR_WRONGMODE)
	    winDebug ("DDERR_WRONGMODE\n");
	  else if (ddrval == DDERR_INCOMPATIBLEPRIMARY)
	    winDebug ("DDERR_INCOMPATIBLEPRIMARY\n");
	  else if (ddrval == DDERR_UNSUPPORTED)
	    winDebug ("DDERR_UNSUPPORTED\n");
	  else if (ddrval == DDERR_INVALIDPARAMS)
	    winDebug ("DDERR_INVALIDPARAMS\n");
	  else if (ddrval == DDERR_INVALIDOBJECT)
	    winDebug ("DDERR_INVALIDOBJECT\n");
	  else
	    winDebug ("unknown error: %08x\n", (unsigned int) ddrval);
	  
	  /* Loop around to try the blit one more time */
	  continue;
	}  
      else if (FAILED (ddrval))
	{
	  fReturn = FALSE;
	  winErrorFVerb (1, "winBltExposedRegionsShadowDDNL - "
		  "IDirectDrawSurface4_Blt failed, but surface not "
		  "lost: %08x %d\n",
		  (unsigned int) ddrval, (int) ddrval);
	  goto winBltExposedRegionsShadowDDNL_Exit;
	}
      else
	{
	  /* Success, stop looping */
	  break;
	}
    }

 winBltExposedRegionsShadowDDNL_Exit:
  /* EndPaint frees the DC */
  if (hdcUpdate != NULL)
    EndPaint (pScreenPriv->hwndScreen, &ps);
  return fReturn;
}
예제 #10
0
파일: winscrinit.c 프로젝트: Agnarr/xserver
Bool
winScreenInit (int index,
	       ScreenPtr pScreen,
	       int argc, char **argv)
{
  winScreenInfoPtr      pScreenInfo = &g_ScreenInfo[index];
  winPrivScreenPtr	pScreenPriv;
  HDC			hdc;

#if CYGDEBUG || YES
  winDebug ("winScreenInit - dwWidth: %ld dwHeight: %ld\n",
	  pScreenInfo->dwWidth, pScreenInfo->dwHeight);
#endif

  /* Allocate privates for this screen */
  if (!winAllocatePrivates (pScreen))
    {
      ErrorF ("winScreenInit - Couldn't allocate screen privates\n");
      return FALSE;
    }

  /* Get a pointer to the privates structure that was allocated */
  pScreenPriv = winGetScreenPriv (pScreen);

  /* Save a pointer to this screen in the screen info structure */
  pScreenInfo->pScreen = pScreen;

  /* Save a pointer to the screen info in the screen privates structure */
  /* This allows us to get back to the screen info from a screen pointer */
  pScreenPriv->pScreenInfo = pScreenInfo;

  /*
   * Determine which engine to use.
   *
   * NOTE: This is done once per screen because each screen possibly has
   * a preferred engine specified on the command line.
   */
  if (!winSetEngine (pScreen))
    {
      ErrorF ("winScreenInit - winSetEngine () failed\n");
      return FALSE;
    }

  /* Adjust the video mode for our engine type */
  if (!(*pScreenPriv->pwinAdjustVideoMode) (pScreen))
    {
      ErrorF ("winScreenInit - winAdjustVideoMode () failed\n");
      return FALSE;
    }

  /* Check for supported display depth */
  if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1))))
    {
      ErrorF ("winScreenInit - Unsupported display depth: %d\n" \
	      "Change your Windows display depth to 15, 16, 24, or 32 bits "
	      "per pixel.\n",
	      (int) pScreenInfo->dwBPP);
      ErrorF ("winScreenInit - Supported depths: %08x\n",
	      WIN_SUPPORTED_BPPS);
#if WIN_CHECK_DEPTH
      return FALSE;
#endif
    }

  /*
   * Check that all monitors have the same display depth if we are using
   * multiple monitors
   */
  if (pScreenInfo->fMultipleMonitors 
      && !GetSystemMetrics (SM_SAMEDISPLAYFORMAT))
    {
      ErrorF ("winScreenInit - Monitors do not all have same pixel format / "
	      "display depth.\n"
	      "Using primary display only.\n");
      pScreenInfo->fMultipleMonitors = FALSE;
    }

  /* Create display window */
  if (!(*pScreenPriv->pwinCreateBoundingWindow) (pScreen))
    {
      ErrorF ("winScreenInit - pwinCreateBoundingWindow () "
	      "failed\n");
      return FALSE;
    }

  /* Get a device context */
  hdc = GetDC (pScreenPriv->hwndScreen);

  /* Store the initial height, width, and depth of the display */
  /* Are we using multiple monitors? */
  if (pScreenInfo->fMultipleMonitors)
    {
      pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
      pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);

      /* 
       * In this case, some of the defaults set in
       * winInitializeScreenDefaults() are not correct ...
       */
      if (!pScreenInfo->fUserGaveHeightAndWidth)
	{
	  pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
	  pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
	  pScreenInfo->dwWidth_mm = (pScreenInfo->dwWidth /
				     WIN_DEFAULT_DPI) * 25.4;
	  pScreenInfo->dwHeight_mm = (pScreenInfo->dwHeight /
				      WIN_DEFAULT_DPI) * 25.4;
	}
    }
  else
    {
      pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXSCREEN);
      pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYSCREEN);
    }

  /* Save the original bits per pixel */
  pScreenPriv->dwLastWindowsBitsPixel = GetDeviceCaps (hdc, BITSPIXEL);

  /* Release the device context */
  ReleaseDC (pScreenPriv->hwndScreen, hdc);
    
  /* Clear the visuals list */
  miClearVisualTypes ();
  
  /* Set the padded screen width */
  pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth,
					      pScreenInfo->dwBPP);

  /* Call the engine dependent screen initialization procedure */
  if (!((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv)))
    {
      ErrorF ("winScreenInit - winFinishScreenInit () failed\n");
      return FALSE;
    }

  if (!g_fSoftwareCursor)
    winInitCursor(pScreen);
  else
    winErrorFVerb(2, "winScreenInit - Using software cursor\n");  

  /*
     Note the screen origin in a normalized coordinate space where (0,0) is at the top left
     of the native virtual desktop area
  */
  pScreen->x = pScreenInfo->dwInitialX - GetSystemMetrics(SM_XVIRTUALSCREEN);
  pScreen->y = pScreenInfo->dwInitialY - GetSystemMetrics(SM_YVIRTUALSCREEN);

  ErrorF("Screen %d added at virtual desktop coordinate (%d,%d).\n",
         index, pScreen->x, pScreen->y);

#if CYGDEBUG || YES
  winDebug ("winScreenInit - returning\n");
#endif

  return TRUE;
}
예제 #11
0
파일: winscrinit.c 프로젝트: Agnarr/xserver
/* See Porting Layer Definition - p. 20 */
Bool
winFinishScreenInitFB (int index,
		       ScreenPtr pScreen,
		       int argc, char **argv)
{
  winScreenPriv(pScreen);
  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
  VisualPtr		pVisual = NULL;
  char			*pbits = NULL;
#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
  int			iReturn;
#endif

  /* Create framebuffer */
  if (!(*pScreenPriv->pwinAllocateFB) (pScreen))
    {
      ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n");
      return FALSE;
    }

  /*
   * Grab the number of bits that are used to represent color in each pixel.
   */
  if (pScreenInfo->dwBPP == 8)
    pScreenInfo->dwDepth = 8;
  else
    pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask)
      + winCountBits (pScreenPriv->dwGreenMask)
      + winCountBits (pScreenPriv->dwBlueMask);
  
  winErrorFVerb (2, "winFinishScreenInitFB - Masks: %08x %08x %08x\n",
	  (unsigned int) pScreenPriv->dwRedMask,
	  (unsigned int) pScreenPriv->dwGreenMask,
	  (unsigned int) pScreenPriv->dwBlueMask);

  /* Init visuals */
  if (!(*pScreenPriv->pwinInitVisuals) (pScreen))
    {
      ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n");
      return FALSE;
    }

  /* Setup a local variable to point to the framebuffer */
  pbits = pScreenInfo->pfb;
  
  /* Apparently we need this for the render extension */
  miSetPixmapDepths ();

  /* Start fb initialization */
  if (!fbSetupScreen (pScreen,
		      pScreenInfo->pfb,
		      pScreenInfo->dwWidth, pScreenInfo->dwHeight,
		      monitorResolution, monitorResolution,
		      pScreenInfo->dwStride,
		      pScreenInfo->dwBPP))
    {
      ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n");
      return FALSE;
    }

  /* Override default colormap routines if visual class is dynamic */
  if (pScreenInfo->dwDepth == 8
      && (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
	  || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL
	      && pScreenInfo->fFullScreen)
	  || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
	      && pScreenInfo->fFullScreen)))
    {
      winSetColormapFunctions (pScreen);

      /*
       * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its
       * own colormap, as it cannot allocate 7 planes in the default
       * colormap.  Setting whitePixel to 1 allows Magic to get 7
       * planes in the default colormap, so it doesn't create its
       * own colormap.  This latter situation is highly desireable,
       * as it keeps the Magic window viewable when switching to
       * other X clients that use the default colormap.
       */
      pScreen->blackPixel = 0;
      pScreen->whitePixel = 1;
    }

  /* Place our save screen function */
  pScreen->SaveScreen = winSaveScreen;

  /* Finish fb initialization */
  if (!fbFinishScreenInit (pScreen,
			   pScreenInfo->pfb,
			   pScreenInfo->dwWidth, pScreenInfo->dwHeight,
			   monitorResolution, monitorResolution,
			   pScreenInfo->dwStride,
			   pScreenInfo->dwBPP))
    {
      ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n");
      return FALSE;
    }

  /* Save a pointer to the root visual */
  for (pVisual = pScreen->visuals;
       pVisual->vid != pScreen->rootVisual;
       pVisual++);
  pScreenPriv->pRootVisual = pVisual;

  /* 
   * Setup points to the block and wakeup handlers.  Pass a pointer
   * to the current screen as pWakeupdata.
   */
  pScreen->BlockHandler = winBlockHandler;
  pScreen->WakeupHandler = winWakeupHandler;
  pScreen->blockData = pScreen;
  pScreen->wakeupData = pScreen;

  /* Render extension initialization, calls miPictureInit */
  if (!fbPictureInit (pScreen, NULL, 0))
    {
      ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n");
      return FALSE;
    }

#ifdef RANDR
  /* Initialize resize and rotate support */
  if (!winRandRInit (pScreen))
    {
      ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n");
      return FALSE;
    }
#endif

  /*
   * Backing store support should reduce network traffic and increase
   * performance.
   */
  miInitializeBackingStore (pScreen);

  /* KDrive does miDCInitialize right after miInitializeBackingStore */
  /* Setup the cursor routines */
#if CYGDEBUG
  winDebug ("winFinishScreenInitFB - Calling miDCInitialize ()\n");
#endif
  miDCInitialize (pScreen, &g_winPointerCursorFuncs);

  /* KDrive does winCreateDefColormap right after miDCInitialize */
  /* Create a default colormap */
#if CYGDEBUG
  winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n");
#endif
  if (!winCreateDefColormap (pScreen))
    {
      ErrorF ("winFinishScreenInitFB - Could not create colormap\n");
      return FALSE;
    }

  /* Initialize the shadow framebuffer layer */
  if ((pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
       || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
       || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL)
#ifdef XWIN_MULTIWINDOWEXTWM
      && !pScreenInfo->fMWExtWM
#endif
      )
    {
#if CYGDEBUG
      winDebug ("winFinishScreenInitFB - Calling shadowSetup ()\n");
#endif
      if (!shadowSetup(pScreen))
	{
	  ErrorF ("winFinishScreenInitFB - shadowSetup () failed\n");
	  return FALSE;
	}

      /* Wrap CreateScreenResources so we can add the screen pixmap
         to the Shadow framebuffer after it's been created */
      pScreenPriv->pwinCreateScreenResources = pScreen->CreateScreenResources;
      pScreen->CreateScreenResources = winCreateScreenResources;
    }

#ifdef XWIN_MULTIWINDOWEXTWM
  /* Handle multi-window external window manager mode */
  if (pScreenInfo->fMWExtWM)
    {
      winDebug ("winScreenInit - MultiWindowExtWM - Calling RootlessInit\n");
      
      RootlessInit(pScreen, &winMWExtWMProcs);
      
      winDebug ("winScreenInit - MultiWindowExtWM - RootlessInit returned\n");
      
      rootless_CopyBytes_threshold = 0;
      /* FIXME: How many? Profiling needed? */
      rootless_CopyWindow_threshold = 1;

      winWindowsWMExtensionInit ();
    }
#endif

  /* Handle rootless mode */
  if (pScreenInfo->fRootless)
    {
      /* Define the WRAP macro temporarily for local use */
#define WRAP(a) \
    if (pScreen->a) { \
        pScreenPriv->a = pScreen->a; \
    } else { \
        ErrorF("null screen fn " #a "\n"); \
        pScreenPriv->a = NULL; \
    }

      /* Save a pointer to each lower-level window procedure */
      WRAP(CreateWindow);
      WRAP(DestroyWindow);
      WRAP(RealizeWindow);
      WRAP(UnrealizeWindow);
      WRAP(PositionWindow);
      WRAP(ChangeWindowAttributes);
      WRAP(SetShape);

      /* Assign rootless window procedures to be top level procedures */
      pScreen->CreateWindow = winCreateWindowRootless;
      pScreen->DestroyWindow = winDestroyWindowRootless;
      pScreen->PositionWindow = winPositionWindowRootless;
      /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesRootless;*/
      pScreen->RealizeWindow = winMapWindowRootless;
      pScreen->UnrealizeWindow = winUnmapWindowRootless;
      pScreen->SetShape = winSetShapeRootless;

      /* Undefine the WRAP macro, as it is not needed elsewhere */
#undef WRAP
    }


#ifdef XWIN_MULTIWINDOW
  /* Handle multi window mode */
  else if (pScreenInfo->fMultiWindow)
    {
      /* Define the WRAP macro temporarily for local use */
#define WRAP(a) \
    if (pScreen->a) { \
        pScreenPriv->a = pScreen->a; \
    } else { \
        ErrorF("null screen fn " #a "\n"); \
        pScreenPriv->a = NULL; \
    }

      /* Save a pointer to each lower-level window procedure */
      WRAP(CreateWindow);
      WRAP(DestroyWindow);
      WRAP(RealizeWindow);
      WRAP(UnrealizeWindow);
      WRAP(PositionWindow);
      WRAP(ChangeWindowAttributes);
      WRAP(ReparentWindow);
      WRAP(RestackWindow);
      WRAP(ResizeWindow);
      WRAP(MoveWindow);
      WRAP(CopyWindow);
      WRAP(SetShape);

      /* Assign multi-window window procedures to be top level procedures */
      pScreen->CreateWindow = winCreateWindowMultiWindow;
      pScreen->DestroyWindow = winDestroyWindowMultiWindow;
      pScreen->PositionWindow = winPositionWindowMultiWindow;
      /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow;*/
      pScreen->RealizeWindow = winMapWindowMultiWindow;
      pScreen->UnrealizeWindow = winUnmapWindowMultiWindow;
      pScreen->ReparentWindow = winReparentWindowMultiWindow;
      pScreen->RestackWindow = winRestackWindowMultiWindow;
      pScreen->ResizeWindow = winResizeWindowMultiWindow;
      pScreen->MoveWindow = winMoveWindowMultiWindow;
      pScreen->CopyWindow = winCopyWindowMultiWindow;
      pScreen->SetShape = winSetShapeMultiWindow;

      /* Undefine the WRAP macro, as it is not needed elsewhere */
#undef WRAP
    }
#endif

  /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */
  pScreenPriv->CloseScreen = pScreen->CloseScreen;
  pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;

#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
  /* Create a mutex for modules in separate threads to wait for */
  iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL);
  if (iReturn != 0)
    {
      ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n",
	      iReturn);
      return FALSE;
    }

  /* Own the mutex for modules in separate threads */
  iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted);
  if (iReturn != 0)
    {
      ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n",
	      iReturn);
      return FALSE;
    }

  /* Set the ServerStarted flag to false */
  pScreenPriv->fServerStarted = FALSE;
#endif

#ifdef XWIN_MULTIWINDOWEXTWM
  pScreenPriv->fRestacking = FALSE;
#endif

#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
  if (FALSE
#ifdef XWIN_MULTIWINDOW
      || pScreenInfo->fMultiWindow
#endif
#ifdef XWIN_MULTIWINDOWEXTWM
      || pScreenInfo->fInternalWM
#endif
      )
    { 
#if CYGDEBUG || YES
      winDebug ("winFinishScreenInitFB - Calling winInitWM.\n");
#endif

      /* Initialize multi window mode */
      if (!winInitWM (&pScreenPriv->pWMInfo,
		      &pScreenPriv->ptWMProc,
		      &pScreenPriv->ptXMsgProc,
		      &pScreenPriv->pmServerStarted,
		      pScreenInfo->dwScreen,
		      (HWND)&pScreenPriv->hwndScreen,
#ifdef XWIN_MULTIWINDOWEXTWM
		      pScreenInfo->fInternalWM ||
#endif
		      FALSE))
        {
          ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n");
          return FALSE;
        }
    }      
#endif

  /* Tell the server that we are enabled */
  pScreenPriv->fEnabled = TRUE;

  /* Tell the server that we have a valid depth */
  pScreenPriv->fBadDepth = FALSE;

#if CYGDEBUG || YES
  winDebug ("winFinishScreenInitFB - returning\n");
#endif

  return TRUE;
}
예제 #12
0
LRESULT CALLBACK
winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HWND s_hwndNextViewer;
    static Bool s_fCBCInitialized;

    /* Branch on message type */
    switch (message) {
    case WM_DESTROY:
    {
        winDebug("winClipboardWindowProc - WM_DESTROY\n");

        /* Remove ourselves from the clipboard chain */
        ChangeClipboardChain(hwnd, s_hwndNextViewer);

        s_hwndNextViewer = NULL;

        PostQuitMessage(0);
    }
        return 0;

    case WM_CREATE:
    {
        HWND first, next;
        DWORD error_code = 0;

        winDebug("winClipboardWindowProc - WM_CREATE\n");

        first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
        if (first == hwnd)
            return 0;           /* Make sure it's not us! */
        /* Add ourselves to the clipboard viewer chain */
        next = SetClipboardViewer(hwnd);
        error_code = GetLastError();
        if (SUCCEEDED(error_code) && (next == first))   /* SetClipboardViewer must have succeeded, and the handle */
            s_hwndNextViewer = next;    /* it returned must have been the first window in the chain */
        else
            s_fCBCInitialized = FALSE;
    }
        return 0;

    case WM_CHANGECBCHAIN:
    {
        winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%x) "
                 "lParam(%x) s_hwndNextViewer(%x)\n",
                 wParam, lParam, s_hwndNextViewer);

        if ((HWND) wParam == s_hwndNextViewer) {
            s_hwndNextViewer = (HWND) lParam;
            if (s_hwndNextViewer == hwnd) {
                s_hwndNextViewer = NULL;
                winErrorFVerb(1, "winClipboardWindowProc - WM_CHANGECBCHAIN: "
                              "attempted to set next window to ourselves.");
            }
        }
        else if (s_hwndNextViewer)
            SendMessage(s_hwndNextViewer, message, wParam, lParam);

    }
        winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: Exit\n");
        return 0;

    case WM_WM_REINIT:
    {
        /* Ensure that we're in the clipboard chain.  Some apps,
         * WinXP's remote desktop for one, don't play nice with the
         * chain.  This message is called whenever we receive a
         * WM_ACTIVATEAPP message to ensure that we continue to
         * receive clipboard messages.
         *
         * It might be possible to detect if we're still in the chain
         * by calling SendMessage (GetClipboardViewer(),
         * WM_DRAWCLIPBOARD, 0, 0); and then seeing if we get the
         * WM_DRAWCLIPBOARD message.  That, however, might be more
         * expensive than just putting ourselves back into the chain.
         */

        HWND first, next;
        DWORD error_code = 0;

        winDebug("winClipboardWindowProc - WM_WM_REINIT: Enter\n");

        first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
        if (first == hwnd)
            return 0;           /* Make sure it's not us! */
        winDebug("  WM_WM_REINIT: Replacing us(%x) with %x at head "
                 "of chain\n", hwnd, s_hwndNextViewer);
        s_fCBCInitialized = FALSE;
        ChangeClipboardChain(hwnd, s_hwndNextViewer);
        s_hwndNextViewer = NULL;
        s_fCBCInitialized = FALSE;
        winDebug("  WM_WM_REINIT: Putting us back at head of chain.\n");
        first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
        if (first == hwnd)
            return 0;           /* Make sure it's not us! */
        next = SetClipboardViewer(hwnd);
        error_code = GetLastError();
        if (SUCCEEDED(error_code) && (next == first))   /* SetClipboardViewer must have succeeded, and the handle */
            s_hwndNextViewer = next;    /* it returned must have been the first window in the chain */
        else
            s_fCBCInitialized = FALSE;
    }
        winDebug("winClipboardWindowProc - WM_WM_REINIT: Exit\n");
        return 0;

    case WM_DRAWCLIPBOARD:
    {
        static Atom atomClipboard;
        static int generation;
        static Bool s_fProcessingDrawClipboard = FALSE;
        Display *pDisplay = g_pClipboardDisplay;
        Window iWindow = g_iClipboardWindow;
        int iReturn;

        winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n");

        if (generation != serverGeneration) {
            generation = serverGeneration;
            atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
        }

        /*
         * We've occasionally seen a loop in the clipboard chain.
         * Try and fix it on the first hint of recursion.
         */
        if (!s_fProcessingDrawClipboard) {
            s_fProcessingDrawClipboard = TRUE;
        }
        else {
            /* Attempt to break the nesting by getting out of the chain, twice?, and then fix and bail */
            s_fCBCInitialized = FALSE;
            ChangeClipboardChain(hwnd, s_hwndNextViewer);
            winFixClipboardChain();
            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                          "Nested calls detected.  Re-initing.\n");
            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
            s_fProcessingDrawClipboard = FALSE;
            return 0;
        }

        /* Bail on first message */
        if (!s_fCBCInitialized) {
            s_fCBCInitialized = TRUE;
            s_fProcessingDrawClipboard = FALSE;
            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
            return 0;
        }

        /*
         * NOTE: We cannot bail out when NULL == GetClipboardOwner ()
         * because some applications deal with the clipboard in a manner
         * that causes the clipboard owner to be NULL when they are in
         * fact taking ownership.  One example of this is the Win32
         * native compile of emacs.
         */

        /* Bail when we still own the clipboard */
        if (hwnd == GetClipboardOwner()) {

            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                     "We own the clipboard, returning.\n");
            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
            s_fProcessingDrawClipboard = FALSE;
            if (s_hwndNextViewer)
                SendMessage(s_hwndNextViewer, message, wParam, lParam);
            return 0;
        }

        /*
         * Do not take ownership of the X11 selections when something
         * other than CF_TEXT or CF_UNICODETEXT has been copied
         * into the Win32 clipboard.
         */
        if (!IsClipboardFormatAvailable(CF_TEXT)
            && !IsClipboardFormatAvailable(CF_UNICODETEXT)) {

            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                     "Clipboard does not contain CF_TEXT nor "
                     "CF_UNICODETEXT.\n");

            /*
             * We need to make sure that the X Server has processed
             * previous XSetSelectionOwner messages.
             */
            XSync(pDisplay, FALSE);

            winDebug("winClipboardWindowProc - XSync done.\n");

            /* Release PRIMARY selection if owned */
            iReturn = XGetSelectionOwner(pDisplay, XA_PRIMARY);
            if (iReturn == g_iClipboardWindow) {
                winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                         "PRIMARY selection is owned by us.\n");
                XSetSelectionOwner(pDisplay, XA_PRIMARY, None, CurrentTime);
            }
            else if (BadWindow == iReturn || BadAtom == iReturn)
                winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                              "XGetSelection failed for PRIMARY: %d\n",
                              iReturn);

            /* Release CLIPBOARD selection if owned */
            iReturn = XGetSelectionOwner(pDisplay, atomClipboard);
            if (iReturn == g_iClipboardWindow) {
                winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                         "CLIPBOARD selection is owned by us.\n");
                XSetSelectionOwner(pDisplay, atomClipboard, None, CurrentTime);
            }
            else if (BadWindow == iReturn || BadAtom == iReturn)
                winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                              "XGetSelection failed for CLIPBOARD: %d\n",
                              iReturn);

            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
            s_fProcessingDrawClipboard = FALSE;
            if (s_hwndNextViewer)
                SendMessage(s_hwndNextViewer, message, wParam, lParam);
            return 0;
        }

        /* Reassert ownership of PRIMARY */
        iReturn = XSetSelectionOwner(pDisplay,
                                     XA_PRIMARY, iWindow, CurrentTime);
        if (iReturn == BadAtom || iReturn == BadWindow ||
            XGetSelectionOwner(pDisplay, XA_PRIMARY) != iWindow) {
            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                          "Could not reassert ownership of PRIMARY\n");
        }
        else {
            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                     "Reasserted ownership of PRIMARY\n");
        }

        /* Reassert ownership of the CLIPBOARD */
        iReturn = XSetSelectionOwner(pDisplay,
                                     atomClipboard, iWindow, CurrentTime);

        if (iReturn == BadAtom || iReturn == BadWindow ||
            XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) {
            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                          "Could not reassert ownership of CLIPBOARD\n");
        }
        else {
            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                     "Reasserted ownership of CLIPBOARD\n");
        }

        /* Flush the pending SetSelectionOwner event now */
        XFlush(pDisplay);

        s_fProcessingDrawClipboard = FALSE;
    }
        winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
        /* Pass the message on the next window in the clipboard viewer chain */
        if (s_hwndNextViewer)
            SendMessage(s_hwndNextViewer, message, wParam, lParam);
        return 0;

    case WM_DESTROYCLIPBOARD:
        /*
         * NOTE: Intentionally do nothing.
         * Changes in the Win32 clipboard are handled by WM_DRAWCLIPBOARD
         * above.  We only process this message to conform to the specs
         * for delayed clipboard rendering in Win32.  You might think
         * that we need to release ownership of the X11 selections, but
         * we do not, because a WM_DRAWCLIPBOARD message will closely
         * follow this message and reassert ownership of the X11
         * selections, handling the issue for us.
         */
        winDebug("winClipboardWindowProc - WM_DESTROYCLIPBOARD - Ignored.\n");
        return 0;

    case WM_RENDERFORMAT:
    case WM_RENDERALLFORMATS:
    {
        int iReturn;
        Display *pDisplay = g_pClipboardDisplay;
        Window iWindow = g_iClipboardWindow;
        Bool fConvertToUnicode;

        winDebug("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n");

        /* Flag whether to convert to Unicode or not */
        if (message == WM_RENDERALLFORMATS)
            fConvertToUnicode = FALSE;
        else
            fConvertToUnicode = g_fUnicodeSupport && (CF_UNICODETEXT == wParam);

        /* Request the selection contents */
        iReturn = XConvertSelection(pDisplay,
                                    g_atomLastOwnedSelection,
                                    XInternAtom(pDisplay,
                                                "COMPOUND_TEXT", False),
                                    XInternAtom(pDisplay,
                                                "CYGX_CUT_BUFFER", False),
                                    iWindow, CurrentTime);
        if (iReturn == BadAtom || iReturn == BadWindow) {
            winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMAT - "
                          "XConvertSelection () failed\n");
            break;
        }

        /* Special handling for WM_RENDERALLFORMATS */
        if (message == WM_RENDERALLFORMATS) {
            /* We must open and empty the clipboard */

            /* Close clipboard if we have it open already */
            if (GetOpenClipboardWindow() == hwnd) {
                CloseClipboard();
            }

            if (!OpenClipboard(hwnd)) {
                winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
                              "OpenClipboard () failed: %08x\n",
                              GetLastError());
                break;
            }

            if (!EmptyClipboard()) {
                winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
                              "EmptyClipboard () failed: %08x\n",
                              GetLastError());
                break;
            }
        }

        /* Process the SelectionNotify event */
        iReturn = winProcessXEventsTimeout(hwnd,
                                           iWindow,
                                           pDisplay,
                                           fConvertToUnicode, WIN_POLL_TIMEOUT);

        /*
         * The last call to winProcessXEventsTimeout
         * from above had better have seen a notify event, or else we
         * are dealing with a buggy or old X11 app.  In these cases we
         * have to paste some fake data to the Win32 clipboard to
         * satisfy the requirement that we write something to it.
         */
        if (WIN_XEVENTS_NOTIFY != iReturn) {
            /* Paste no data, to satisfy required call to SetClipboardData */
            if (g_fUnicodeSupport)
                SetClipboardData(CF_UNICODETEXT, NULL);
            SetClipboardData(CF_TEXT, NULL);

            ErrorF
                ("winClipboardWindowProc - timed out waiting for WIN_XEVENTS_NOTIFY\n");
        }

        /* Special handling for WM_RENDERALLFORMATS */
        if (message == WM_RENDERALLFORMATS) {
            /* We must close the clipboard */

            if (!CloseClipboard()) {
                winErrorFVerb(1,
                              "winClipboardWindowProc - WM_RENDERALLFORMATS - "
                              "CloseClipboard () failed: %08x\n",
                              GetLastError());
                break;
            }
        }

        winDebug("winClipboardWindowProc - WM_RENDER*FORMAT - Returning.\n");
        return 0;
    }
    }

    /* Let Windows perform default processing for unhandled messages */
    return DefWindowProc(hwnd, message, wParam, lParam);
}
예제 #13
0
파일: winscrinit.c 프로젝트: csulmone/X11
Bool
winScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
{
    winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index];
    winPrivScreenPtr pScreenPriv;
    HDC hdc;
    DWORD dwInitialBPP;

#if CYGDEBUG || YES
    winDebug("winScreenInit - dwWidth: %ld dwHeight: %ld\n",
             pScreenInfo->dwWidth, pScreenInfo->dwHeight);
#endif

    /* Allocate privates for this screen */
    if (!winAllocatePrivates(pScreen)) {
        ErrorF("winScreenInit - Couldn't allocate screen privates\n");
        return FALSE;
    }

    /* Get a pointer to the privates structure that was allocated */
    pScreenPriv = winGetScreenPriv(pScreen);

    /* Save a pointer to this screen in the screen info structure */
    pScreenInfo->pScreen = pScreen;

    /* Save a pointer to the screen info in the screen privates structure */
    /* This allows us to get back to the screen info from a screen pointer */
    pScreenPriv->pScreenInfo = pScreenInfo;

    /*
     * Determine which engine to use.
     *
     * NOTE: This is done once per screen because each screen possibly has
     * a preferred engine specified on the command line.
     */
    if (!winSetEngine(pScreen)) {
        ErrorF("winScreenInit - winSetEngine () failed\n");
        return FALSE;
    }

    /* Horribly misnamed function: Allow engine to adjust BPP for screen */
    dwInitialBPP = pScreenInfo->dwBPP;

    if (!(*pScreenPriv->pwinAdjustVideoMode) (pScreen)) {
        ErrorF("winScreenInit - winAdjustVideoMode () failed\n");
        return FALSE;
    }

    if (dwInitialBPP == WIN_DEFAULT_BPP) {
        /* No -depth parameter was passed, let the user know the depth being used */
        ErrorF
            ("winScreenInit - Using Windows display depth of %d bits per pixel\n",
             (int) pScreenInfo->dwBPP);
    }
    else if (dwInitialBPP != pScreenInfo->dwBPP) {
        /* Warn user if engine forced a depth different to -depth parameter */
        ErrorF
            ("winScreenInit - Command line depth of %d bpp overidden by engine, using %d bpp\n",
             (int) dwInitialBPP, (int) pScreenInfo->dwBPP);
    }
    else {
        ErrorF("winScreenInit - Using command line depth of %d bpp\n",
               (int) pScreenInfo->dwBPP);
    }

    /* Check for supported display depth */
    if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1)))) {
        ErrorF("winScreenInit - Unsupported display depth: %d\n"
               "Change your Windows display depth to 15, 16, 24, or 32 bits "
               "per pixel.\n", (int) pScreenInfo->dwBPP);
        ErrorF("winScreenInit - Supported depths: %08x\n", WIN_SUPPORTED_BPPS);
#if WIN_CHECK_DEPTH
        return FALSE;
#endif
    }

    /*
     * Check that all monitors have the same display depth if we are using
     * multiple monitors
     */
    if (pScreenInfo->fMultipleMonitors
        && !GetSystemMetrics(SM_SAMEDISPLAYFORMAT)) {
        ErrorF("winScreenInit - Monitors do not all have same pixel format / "
               "display depth.\n");
        if (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI) {
            ErrorF
                ("winScreenInit - Performance may suffer off primary display.\n");
        }
        else {
            ErrorF("winScreenInit - Using primary display only.\n");
            pScreenInfo->fMultipleMonitors = FALSE;
        }
    }

    /* Create display window */
    if (!(*pScreenPriv->pwinCreateBoundingWindow) (pScreen)) {
        ErrorF("winScreenInit - pwinCreateBoundingWindow () " "failed\n");
        return FALSE;
    }

    /* Get a device context */
    hdc = GetDC(pScreenPriv->hwndScreen);

    /* Are we using multiple monitors? */
    if (pScreenInfo->fMultipleMonitors) {
        /* 
         * In this case, some of the defaults set in
         * winInitializeScreenDefaults() are not correct ...
         */
        if (!pScreenInfo->fUserGaveHeightAndWidth) {
            pScreenInfo->dwWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
            pScreenInfo->dwHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
        }
    }

    /* Release the device context */
    ReleaseDC(pScreenPriv->hwndScreen, hdc);

    /* Clear the visuals list */
    miClearVisualTypes();

    /* Call the engine dependent screen initialization procedure */
    if (!((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv))) {
        ErrorF("winScreenInit - winFinishScreenInit () failed\n");

        /* call the engine dependent screen close procedure to clean up from a failure */
        pScreenPriv->pwinCloseScreen(index, pScreen);

        return FALSE;
    }

    if (!g_fSoftwareCursor)
        winInitCursor(pScreen);
    else
        winErrorFVerb(2, "winScreenInit - Using software cursor\n");

    /*
       Note the screen origin in a normalized coordinate space where (0,0) is at the top left
       of the native virtual desktop area
     */
    pScreen->x = pScreenInfo->dwInitialX - GetSystemMetrics(SM_XVIRTUALSCREEN);
    pScreen->y = pScreenInfo->dwInitialY - GetSystemMetrics(SM_YVIRTUALSCREEN);

    ErrorF("Screen %d added at virtual desktop coordinate (%d,%d).\n",
           index, pScreen->x, pScreen->y);

#if CYGDEBUG || YES
    winDebug("winScreenInit - returning\n");
#endif

    return TRUE;
}
예제 #14
0
Bool
winValidateArgs (void)
{
  int		i;
  int		iMaxConsecutiveScreen = 0;
  BOOL		fHasNormalScreen0 = FALSE;

  /*
   * Check for a malformed set of -screen parameters.
   * Examples of malformed parameters:
   *	XWin -screen 1
   *	XWin -screen 0 -screen 2
   *	XWin -screen 1 -screen 2
   */
  for (i = 0; i < MAXSCREENS; i++)
    {
      if (g_ScreenInfo[i].fExplicitScreen)
	iMaxConsecutiveScreen = i + 1;
    }
  winErrorFVerb (2, "winValidateArgs - g_iNumScreens: %d "
		 "iMaxConsecutiveScreen: %d\n",
		 g_iNumScreens, iMaxConsecutiveScreen);
  if (g_iNumScreens < iMaxConsecutiveScreen)
    {
      ErrorF ("winValidateArgs - Malformed set of screen parameter(s).  "
	      "Screens must be specified consecutively starting with "
	      "screen 0.  That is, you cannot have only a screen 1, nor "
	      "could you have screen 0 and screen 2.  You instead must "
	      "have screen 0, or screen 0 and screen 1, respectively.  Of "
	      "you can specify as many screens as you want from 0 up to "
	      "%d.\n", MAXSCREENS - 1);
      return FALSE;
    }

  /* Loop through all screens */
  for (i = 0; i < g_iNumScreens; ++i)
    {
      /*
       * Check for any combination of
       * -multiwindow, -mwextwm, and -rootless.
       */
      {
	int		iCount = 0;

	/* Count conflicting options */
#ifdef XWIN_MULTIWINDOW
	if (g_ScreenInfo[i].fMultiWindow)
	  ++iCount;
#endif
#ifdef XWIN_MULTIWINDOWEXTWM
	if (g_ScreenInfo[i].fMWExtWM)
	  ++iCount;
#endif
	if (g_ScreenInfo[i].fRootless)
	  ++iCount;

	/* Check if the first screen is without rootless and multiwindow */ 
	if (iCount == 0 && i == 0)
	  fHasNormalScreen0 = TRUE;  

	/* Fail if two or more conflicting options */
	if (iCount > 1)
	  {
	    ErrorF ("winValidateArgs - Only one of -multiwindow, -mwextwm, "
		    "and -rootless can be specific at a time.\n");
	    return FALSE;
	  }
      }

      /* Check for -multiwindow or -mwextwm and Xdmcp */
      /* allow xdmcp if screen 0 is normal. */
      if (g_fXdmcpEnabled && !fHasNormalScreen0
	  && (FALSE
#ifdef XWIN_MULTIWINDOW
	      || g_ScreenInfo[i].fMultiWindow
#endif
#ifdef XWIN_MULTIWINDOWEXTWM
	      || g_ScreenInfo[i].fMWExtWM
#endif
	      )
	  )
	{
	  ErrorF ("winValidateArgs - Xdmcp (-query, -broadcast, or -indirect) "
		  "is invalid with -multiwindow or -mwextwm.\n");
	  return FALSE;
	}

      /* Check for -multiwindow, -mwextwm, or -rootless and fullscreen */
      if (g_ScreenInfo[i].fFullScreen
	  && (FALSE
#ifdef XWIN_MULTIWINDOW
	      || g_ScreenInfo[i].fMultiWindow
#endif
#ifdef XWIN_MULTIWINDOWEXTWM
	      || g_ScreenInfo[i].fMWExtWM
#endif
	      || g_ScreenInfo[i].fRootless)
	  )
	{
	  ErrorF ("winValidateArgs - -fullscreen is invalid with "
		  "-multiwindow, -mwextwm, or -rootless.\n");
	  return FALSE;
	}
      
      /* Check for !fullscreen and any fullscreen-only parameters */
      if (!g_ScreenInfo[i].fFullScreen
	  && (g_ScreenInfo[i].dwRefreshRate != WIN_DEFAULT_BPP
	      || g_ScreenInfo[i].dwBPP != WIN_DEFAULT_REFRESH))
	{
	  ErrorF ("winValidateArgs - -refresh and -depth are only valid "
		  "with -fullscreen.\n");
	  return FALSE;
	}

      /* Check for fullscreen and any non-fullscreen parameters */
      if (g_ScreenInfo[i].fFullScreen
	  && (g_ScreenInfo[i].fScrollbars
	      || !g_ScreenInfo[i].fDecoration
	      || g_ScreenInfo[i].fLessPointer))
	{
	  ErrorF ("winValidateArgs - -fullscreen is invalid with "
		  "-scrollbars, -nodecoration, or -lesspointer.\n");
	  return FALSE;
	}
    }

  winDebug ("winValidateArgs - Returning.\n");

  return TRUE;
}
예제 #15
0
파일: winshadddnl.c 프로젝트: L3oV1nc3/VMGL
static Bool
winAdjustVideoModeShadowDDNL (ScreenPtr pScreen)
{
  winScreenPriv(pScreen);
  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
  HDC			hdc = NULL;
  DWORD			dwBPP;

  /* We're in serious trouble if we can't get a DC */
  hdc = GetDC (NULL);
  if (hdc == NULL)
    {
      ErrorF ("winAdjustVideoModeShadowDDNL - GetDC () failed\n");
      return FALSE;
    }

  /* Query GDI for current display depth */
  dwBPP = GetDeviceCaps (hdc, BITSPIXEL);

  /* DirectDraw can only change the depth in fullscreen mode */
  if (pScreenInfo->dwBPP == WIN_DEFAULT_BPP)
    {
      /* No -depth parameter passed, let the user know the depth being used */
      winErrorFVerb (2, "winAdjustVideoModeShadowDDNL - Using Windows display "
	      "depth of %d bits per pixel\n", (int) dwBPP);

      /* Use GDI's depth */
      pScreenInfo->dwBPP = dwBPP;
    }
  else if (pScreenInfo->fFullScreen
	   && pScreenInfo->dwBPP != dwBPP)
    {
      /* FullScreen, and GDI depth differs from -depth parameter */
      winErrorFVerb (2, "winAdjustVideoModeShadowDDNL - FullScreen, using command "
	      "line bpp: %d\n", (int) pScreenInfo->dwBPP);
    }
  else if (dwBPP != pScreenInfo->dwBPP)
    {
      /* Windowed, and GDI depth differs from -depth parameter */
      winErrorFVerb (2, "winAdjustVideoModeShadowDDNL - Windowed, command line "
	      "bpp: %d, using bpp: %d\n",
	      (int) pScreenInfo->dwBPP, (int) dwBPP);

      /* We'll use GDI's depth */
      pScreenInfo->dwBPP = dwBPP;
    }

  /* See if the shadow bitmap will be larger than the DIB size limit */
  if (pScreenInfo->dwWidth * pScreenInfo->dwHeight * pScreenInfo->dwBPP
      >= WIN_DIB_MAXIMUM_SIZE)
    {
      winErrorFVerb (1, "winAdjustVideoModeShadowDDNL - Requested DirectDraw surface "
	      "will be larger than %d MB.  The surface may fail to be "
	      "allocated on Windows 95, 98, or Me, due to a %d MB limit in "
	      "DIB size.  This limit does not apply to Windows NT/2000, and "
	      "this message may be ignored on those platforms.\n",
	      WIN_DIB_MAXIMUM_SIZE_MB, WIN_DIB_MAXIMUM_SIZE_MB);
    }
  
  /* Release our DC */
  ReleaseDC (NULL, hdc);

  return TRUE;
}
예제 #16
0
static void
winInitializeScreenDefaults(void)
{
    DWORD dwWidth, dwHeight;
    static Bool fInitializedScreenDefaults = FALSE;

    /* Bail out early if default screen has already been initialized */
    if (fInitializedScreenDefaults)
        return;

    /* Zero the memory used for storing the screen info */
    memset(&defaultScreenInfo, 0, sizeof(winScreenInfo));

    /* Get default width and height */
    /*
     * NOTE: These defaults will cause the window to cover only
     * the primary monitor in the case that we have multiple monitors.
     */
    dwWidth = GetSystemMetrics(SM_CXSCREEN);
    dwHeight = GetSystemMetrics(SM_CYSCREEN);

    winErrorFVerb(2,
                  "winInitializeScreenDefaults - primary monitor w %d h %d\n",
                  (int) dwWidth, (int) dwHeight);

    /* Set a default DPI, if no '-dpi' option was used */
    if (monitorResolution == 0) {
        HDC hdc = GetDC(NULL);

        if (hdc) {
            int dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
            int dpiY = GetDeviceCaps(hdc, LOGPIXELSY);

            winErrorFVerb(2,
                          "winInitializeScreenDefaults - native DPI x %d y %d\n",
                          dpiX, dpiY);

            monitorResolution = dpiY;
            ReleaseDC(NULL, hdc);
        }
        else {
            winErrorFVerb(1,
                          "winInitializeScreenDefaults - Failed to retrieve native DPI, falling back to default of %d DPI\n",
                          WIN_DEFAULT_DPI);
            monitorResolution = WIN_DEFAULT_DPI;
        }
    }

    defaultScreenInfo.iMonitor = 1;
    defaultScreenInfo.hMonitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
    defaultScreenInfo.dwWidth = dwWidth;
    defaultScreenInfo.dwHeight = dwHeight;
    defaultScreenInfo.dwUserWidth = dwWidth;
    defaultScreenInfo.dwUserHeight = dwHeight;
    defaultScreenInfo.fUserGaveHeightAndWidth =
        WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH;
    defaultScreenInfo.fUserGavePosition = FALSE;
    defaultScreenInfo.dwBPP = WIN_DEFAULT_BPP;
    defaultScreenInfo.dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES;
#ifdef XWIN_EMULATEPSEUDO
    defaultScreenInfo.fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO;
#endif
    defaultScreenInfo.dwRefreshRate = WIN_DEFAULT_REFRESH;
    defaultScreenInfo.pfb = NULL;
    defaultScreenInfo.fFullScreen = FALSE;
    defaultScreenInfo.fDecoration = TRUE;
#ifdef XWIN_MULTIWINDOWEXTWM
    defaultScreenInfo.fMWExtWM = FALSE;
    defaultScreenInfo.fInternalWM = FALSE;
#endif
    defaultScreenInfo.fRootless = FALSE;
#ifdef XWIN_MULTIWINDOW
    defaultScreenInfo.fMultiWindow = FALSE;
#endif
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
    defaultScreenInfo.fMultiMonitorOverride = FALSE;
#endif
    defaultScreenInfo.fMultipleMonitors = FALSE;
    defaultScreenInfo.fLessPointer = FALSE;
    defaultScreenInfo.iResizeMode = resizeWithRandr;
    defaultScreenInfo.fNoTrayIcon = FALSE;
    defaultScreenInfo.iE3BTimeout = WIN_E3B_DEFAULT;
    defaultScreenInfo.fUseWinKillKey = WIN_DEFAULT_WIN_KILL;
    defaultScreenInfo.fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL;
    defaultScreenInfo.fIgnoreInput = FALSE;
    defaultScreenInfo.fExplicitScreen = FALSE;

    /* Note that the default screen has been initialized */
    fInitializedScreenDefaults = TRUE;
}
예제 #17
0
void
InitOutput(ScreenInfo * pScreenInfo, int argc, char *argv[])
{
    int i;

    if (serverGeneration == 1)
        XwinExtensionInit();

    /* Log the command line */
    winLogCommandLine(argc, argv);

#if CYGDEBUG
    winDebug("InitOutput\n");
#endif

    /* Validate command-line arguments */
    if (serverGeneration == 1 && !winValidateArgs()) {
        FatalError("InitOutput - Invalid command-line arguments found.  "
                   "Exiting.\n");
    }

    /* Check for duplicate invocation on same display number. */
    if (serverGeneration == 1 && !winCheckDisplayNumber()) {
        if (g_fSilentDupError)
            g_fSilentFatalError = TRUE;
        FatalError("InitOutput - Duplicate invocation on display "
                   "number: %s.  Exiting.\n", display);
    }

#ifdef XWIN_XF86CONFIG
    /* Try to read the xorg.conf-style configuration file */
    if (!winReadConfigfile())
        winErrorFVerb(1, "InitOutput - Error reading config file\n");
#else
    winMsg(X_INFO, "xorg.conf is not supported\n");
    winMsg(X_INFO, "See http://x.cygwin.com/docs/faq/cygwin-x-faq.html "
           "for more information\n");
    winConfigFiles();
#endif

    /* Load preferences from XWinrc file */
    LoadPreferences();

    /* Setup global screen info parameters */
    pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
    pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
    pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
    pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
    pScreenInfo->numPixmapFormats = NUMFORMATS;

    /* Describe how we want common pixmap formats padded */
    for (i = 0; i < NUMFORMATS; i++) {
        pScreenInfo->formats[i] = g_PixmapFormats[i];
    }

    /* Load pointers to DirectDraw functions */
    winGetDDProcAddresses();

    /* Detect supported engines */
    winDetectSupportedEngines();
#ifdef XWIN_MULTIWINDOW
    /* Load libraries for taskbar grouping */
    winPropertyStoreInit();
#endif

    /* Store the instance handle */
    g_hInstance = GetModuleHandle(NULL);

    /* Create the messaging window */
    if (serverGeneration == 1)
        winCreateMsgWindowThread();

    /* Initialize each screen */
    for (i = 0; i < g_iNumScreens; ++i) {
        /* Initialize the screen */
        if (-1 == AddScreen(winScreenInit, argc, argv)) {
            FatalError("InitOutput - Couldn't add screen %d", i);
        }
    }

  /*
     Unless full xinerama has been explicitly enabled, register all native screens with pseudoramiX
  */
  if (!noPanoramiXExtension)
      noPseudoramiXExtension = TRUE;

  if ((g_ScreenInfo[0].fMultipleMonitors) && !noPseudoramiXExtension)
    {
      int pass;

      PseudoramiXExtensionInit();

      /* Add primary monitor on pass 0, other monitors on pass 1, to ensure
       the primary monitor is first in XINERAMA list */
      for (pass = 0; pass < 2; pass++)
        {
          int iMonitor;

          for (iMonitor = 1; ; iMonitor++)
            {
              struct GetMonitorInfoData data;
              QueryMonitor(iMonitor, &data);
              if (data.bMonitorSpecifiedExists)
                {
                  MONITORINFO mi;
                  mi.cbSize = sizeof(MONITORINFO);

                  if (GetMonitorInfo(data.monitorHandle, &mi))
                    {
                      /* pass == 1 XOR primary monitor flags is set */
                      if ((!(pass == 1)) != (!(mi.dwFlags & MONITORINFOF_PRIMARY)))
                        {
                          /*
                            Note the screen origin in a normalized coordinate space where (0,0) is at the top left
                            of the native virtual desktop area
                          */
                          data.monitorOffsetX = data.monitorOffsetX - GetSystemMetrics(SM_XVIRTUALSCREEN);
                          data.monitorOffsetY = data.monitorOffsetY - GetSystemMetrics(SM_YVIRTUALSCREEN);

                          winDebug ("InitOutput - screen %d added at virtual desktop coordinate (%d,%d) (pseudoramiX) \n",
                                    iMonitor-1, data.monitorOffsetX, data.monitorOffsetY);

                          PseudoramiXAddScreen(data.monitorOffsetX, data.monitorOffsetY,
                                               data.monitorWidth, data.monitorHeight);
                        }
                    }
                }
              else
                break;
            }
        }
    }

#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)

    /* Generate a cookie used by internal clients for authorization */
    if (g_fXdmcpEnabled || g_fAuthEnabled)
        winGenerateAuthorization();

    /* Perform some one time initialization */
    if (1 == serverGeneration) {
        /*
         * setlocale applies to all threads in the current process.
         * Apply locale specified in LANG environment variable.
         */
        setlocale(LC_ALL, "");
    }
#endif

#if CYGDEBUG || YES
    winDebug("InitOutput - Returning.\n");
#endif
}
예제 #18
0
Bool
winSetEngine(ScreenPtr pScreen)
{
    winScreenPriv(pScreen);
    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
    HDC hdc;
    DWORD dwBPP;

    /* Get a DC */
    hdc = GetDC(NULL);
    if (hdc == NULL) {
        ErrorF("winSetEngine - Couldn't get an HDC\n");
        return FALSE;
    }

    /*
     * pScreenInfo->dwBPP may be 0 to indicate that the current screen
     * depth is to be used.  Thus, we must query for the current display
     * depth here.
     */
    dwBPP = GetDeviceCaps(hdc, BITSPIXEL);

    /* Release the DC */
    ReleaseDC(NULL, hdc);
    hdc = NULL;

    /* ShadowGDI is the only engine that supports windowed PseudoColor */
    if (dwBPP == 8 && !pScreenInfo->fFullScreen) {
        winErrorFVerb(2,
                      "winSetEngine - Windowed && PseudoColor => ShadowGDI\n");
        pScreenInfo->dwEngine = WIN_SERVER_SHADOW_GDI;

        /* Set engine function pointers */
        winSetEngineFunctionsShadowGDI(pScreen);
        return TRUE;
    }

    /* ShadowGDI is the only engine that supports Multi Window Mode */
    if (FALSE
#ifdef XWIN_MULTIWINDOWEXTWM
        || pScreenInfo->fMWExtWM
#endif
#ifdef XWIN_MULTIWINDOW
        || pScreenInfo->fMultiWindow
#endif
        ) {
        winErrorFVerb(2,
                      "winSetEngine - Multi Window or Rootless => ShadowGDI\n");
        pScreenInfo->dwEngine = WIN_SERVER_SHADOW_GDI;

        /* Set engine function pointers */
        winSetEngineFunctionsShadowGDI(pScreen);
        return TRUE;
    }

    /* If the user's choice is supported, we'll use that */
    if (g_dwEnginesSupported & pScreenInfo->dwEnginePreferred) {
        winErrorFVerb(2, "winSetEngine - Using user's preference: %d\n",
                      (int) pScreenInfo->dwEnginePreferred);
        pScreenInfo->dwEngine = pScreenInfo->dwEnginePreferred;

        /* Setup engine function pointers */
        switch (pScreenInfo->dwEngine) {
        case WIN_SERVER_SHADOW_GDI:
            winSetEngineFunctionsShadowGDI(pScreen);
            break;
        case WIN_SERVER_SHADOW_DDNL:
            winSetEngineFunctionsShadowDDNL(pScreen);
            break;
        default:
            FatalError("winSetEngine - Invalid engine type\n");
        }
        return TRUE;
    }

    /* ShadowDDNL has good performance, so why not */
    if (g_dwEnginesSupported & WIN_SERVER_SHADOW_DDNL) {
        winErrorFVerb(2, "winSetEngine - Using Shadow DirectDraw NonLocking\n");
        pScreenInfo->dwEngine = WIN_SERVER_SHADOW_DDNL;

        /* Set engine function pointers */
        winSetEngineFunctionsShadowDDNL(pScreen);
        return TRUE;
    }

    /* ShadowGDI is next in line */
    if (g_dwEnginesSupported & WIN_SERVER_SHADOW_GDI) {
        winErrorFVerb(2, "winSetEngine - Using Shadow GDI DIB\n");
        pScreenInfo->dwEngine = WIN_SERVER_SHADOW_GDI;

        /* Set engine function pointers */
        winSetEngineFunctionsShadowGDI(pScreen);
        return TRUE;
    }

    return FALSE;
}
예제 #19
0
void
winDetectSupportedEngines(void)
{
    OSVERSIONINFO osvi;

    /* Initialize the engine support flags */
    g_dwEnginesSupported = WIN_SERVER_SHADOW_GDI;

#ifdef XWIN_NATIVEGDI
    g_dwEnginesSupported |= WIN_SERVER_NATIVE_GDI;
#endif

    /* Get operating system version information */
    ZeroMemory(&osvi, sizeof(osvi));
    osvi.dwOSVersionInfoSize = sizeof(osvi);
    GetVersionEx(&osvi);

    /* Do we have DirectDraw? */
    if (g_hmodDirectDraw != NULL) {
        LPDIRECTDRAW lpdd = NULL;
        LPDIRECTDRAW4 lpdd4 = NULL;
        HRESULT ddrval;

        /* Was the DirectDrawCreate function found? */
        if (g_fpDirectDrawCreate == NULL) {
            /* No DirectDraw support */
            return;
        }

        /* DirectDrawCreate exists, try to call it */
        /* Create a DirectDraw object, store the address at lpdd */
        ddrval = (*g_fpDirectDrawCreate) (NULL, (void **) &lpdd, NULL);
        if (FAILED(ddrval)) {
            /* No DirectDraw support */
            winErrorFVerb(2,
                          "winDetectSupportedEngines - DirectDraw not installed\n");
            return;
        }
        else {
            /* We have DirectDraw */
            winErrorFVerb(2,
                          "winDetectSupportedEngines - DirectDraw installed\n");
            g_dwEnginesSupported |= WIN_SERVER_SHADOW_DD;

#ifdef XWIN_PRIMARYFB
            /* Allow PrimaryDD engine if NT */
            if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
                g_dwEnginesSupported |= WIN_SERVER_PRIMARY_DD;
                winErrorFVerb(2,
                              "winDetectSupportedEngines - Allowing PrimaryDD\n");
            }
#endif
        }

        /* Try to query for DirectDraw4 interface */
        ddrval = IDirectDraw_QueryInterface(lpdd,
                                            &IID_IDirectDraw4,
                                            (LPVOID *) & lpdd4);
        if (SUCCEEDED(ddrval)) {
            /* We have DirectDraw4 */
            winErrorFVerb(2,
                          "winDetectSupportedEngines - DirectDraw4 installed\n");
            g_dwEnginesSupported |= WIN_SERVER_SHADOW_DDNL;
        }

        /* Cleanup DirectDraw interfaces */
        if (lpdd4 != NULL)
            IDirectDraw_Release(lpdd4);
        if (lpdd != NULL)
            IDirectDraw_Release(lpdd);
    }

    winErrorFVerb(2,
                  "winDetectSupportedEngines - Returning, supported engines %08x\n",
                  (unsigned int) g_dwEnginesSupported);
}
예제 #20
0
/*
 * Convert X cursor to Windows cursor
 * FIXME: Perhaps there are more smart code
 */
static HCURSOR
winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
{
  winScreenPriv(pScreen);
  HCURSOR hCursor = NULL;
  unsigned char *pAnd;
  unsigned char *pXor;
  int nCX, nCY;
  int nBytes;
  double dForeY, dBackY;
  BOOL fReverse;
  HBITMAP hAnd, hXor;
  ICONINFO ii;
  unsigned char *pCur;
  int x, y;
  unsigned char bit;
  HDC hDC;
  BITMAPV4HEADER bi;
  BITMAPINFO *pbmi;
  unsigned long *lpBits;

  WIN_DEBUG_MSG("winLoadCursor: Win32: %dx%d X11: %dx%d hotspot: %d,%d\n", 
          pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy,
          pCursor->bits->width, pCursor->bits->height,
          pCursor->bits->xhot, pCursor->bits->yhot
          );

  /* We can use only White and Black, so calc brightness of color 
   * Also check if the cursor is inverted */  
  dForeY = BRIGHTNESS(pCursor->fore);
  dBackY = BRIGHTNESS(pCursor->back);
  fReverse = dForeY < dBackY;
 
  /* Check wether the X11 cursor is bigger than the win32 cursor */
  if (pScreenPriv->cursor.sm_cx < pCursor->bits->width || 
      pScreenPriv->cursor.sm_cy < pCursor->bits->height)
    {
      winErrorFVerb (3, "winLoadCursor - Windows requires %dx%d cursor but X requires %dx%d\n",
	      pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy,
	      pCursor->bits->width, pCursor->bits->height);
    }

  /* Get the number of bytes required to store the whole cursor image 
   * This is roughly (sm_cx * sm_cy) / 8 
   * round up to 8 pixel boundary so we can convert whole bytes */
  nBytes = bits_to_bytes(pScreenPriv->cursor.sm_cx) * pScreenPriv->cursor.sm_cy;

  /* Get the effective width and height */
  nCX = min(pScreenPriv->cursor.sm_cx, pCursor->bits->width);
  nCY = min(pScreenPriv->cursor.sm_cy, pCursor->bits->height);

  /* Allocate memory for the bitmaps */
  pAnd = malloc (nBytes);
  memset (pAnd, 0xFF, nBytes);
  pXor = calloc (1, nBytes);

  /* Convert the X11 bitmap to a win32 bitmap 
   * The first is for an empty mask */
  if (pCursor->bits->emptyMask)
    {
      int x, y, xmax = bits_to_bytes(nCX);
      for (y = 0; y < nCY; ++y)
	for (x = 0; x < xmax; ++x)
	  {
	    int nWinPix = bits_to_bytes(pScreenPriv->cursor.sm_cx) * y + x;
	    int nXPix = BitmapBytePad(pCursor->bits->width) * y + x;

	    pAnd[nWinPix] = 0;
	    if (fReverse)
	      pXor[nWinPix] = reverse (~pCursor->bits->source[nXPix]);
	    else
	      pXor[nWinPix] = reverse (pCursor->bits->source[nXPix]);
	  }
    }
  else
    {
      int x, y, xmax = bits_to_bytes(nCX);
      for (y = 0; y < nCY; ++y)
	for (x = 0; x < xmax; ++x)
	  {
	    int nWinPix = bits_to_bytes(pScreenPriv->cursor.sm_cx) * y + x;
	    int nXPix = BitmapBytePad(pCursor->bits->width) * y + x;

	    unsigned char mask = pCursor->bits->mask[nXPix];
	    pAnd[nWinPix] = reverse (~mask);
	    if (fReverse)
	      pXor[nWinPix] = reverse (~pCursor->bits->source[nXPix] & mask);
	    else
	      pXor[nWinPix] = reverse (pCursor->bits->source[nXPix] & mask);
	  }
    }

  /* prepare the pointers */ 
  hCursor = NULL;
  lpBits = NULL;

  /* We have a truecolor alpha-blended cursor and can use it! */
  if (pCursor->bits->argb) 
    {
      WIN_DEBUG_MSG("winLoadCursor: Trying truecolor alphablended cursor\n"); 
      memset (&bi, 0, sizeof (BITMAPV4HEADER));
      bi.bV4Size = sizeof(BITMAPV4HEADER);
      bi.bV4Width = pScreenPriv->cursor.sm_cx;
      bi.bV4Height = -(pScreenPriv->cursor.sm_cy); /* right-side up */
      bi.bV4Planes = 1;
      bi.bV4BitCount = 32;
      bi.bV4V4Compression = BI_BITFIELDS;
      bi.bV4RedMask = 0x00FF0000;
      bi.bV4GreenMask = 0x0000FF00;
      bi.bV4BlueMask = 0x000000FF;
      bi.bV4AlphaMask = 0xFF000000; 
      
      lpBits = (unsigned long *) calloc (pScreenPriv->cursor.sm_cx*pScreenPriv->cursor.sm_cy,
					 sizeof (unsigned long));
      
      if (lpBits)
	{
	  for (y=0; y<nCY; y++)
	    {
	      unsigned long *src, *dst;
	      src = &(pCursor->bits->argb[y * pCursor->bits->width]);
	      dst = &(lpBits[y * pScreenPriv->cursor.sm_cx]);
	      memcpy (dst, src, 4*nCX);
	    }
	}
    } /* End if-truecolor-icon */
  
  if (!lpBits)
    {
      /* Bicolor, use a palettized DIB */
      WIN_DEBUG_MSG("winLoadCursor: Trying two color cursor\n"); 
      pbmi = (BITMAPINFO*)&bi;
      memset (pbmi, 0, sizeof (BITMAPINFOHEADER));
      pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
      pbmi->bmiHeader.biWidth = pScreenPriv->cursor.sm_cx;
      pbmi->bmiHeader.biHeight = -abs(pScreenPriv->cursor.sm_cy); /* right-side up */
      pbmi->bmiHeader.biPlanes = 1;
      pbmi->bmiHeader.biBitCount = 8;
      pbmi->bmiHeader.biCompression = BI_RGB;
      pbmi->bmiHeader.biSizeImage = 0;
      pbmi->bmiHeader.biClrUsed = 3;
      pbmi->bmiHeader.biClrImportant = 3;
      pbmi->bmiColors[0].rgbRed = 0; /* Empty */
      pbmi->bmiColors[0].rgbGreen = 0;
      pbmi->bmiColors[0].rgbBlue = 0;
      pbmi->bmiColors[0].rgbReserved = 0;
      pbmi->bmiColors[1].rgbRed = pCursor->backRed>>8; /* Background */
      pbmi->bmiColors[1].rgbGreen = pCursor->backGreen>>8;
      pbmi->bmiColors[1].rgbBlue = pCursor->backBlue>>8;
      pbmi->bmiColors[1].rgbReserved = 0;
      pbmi->bmiColors[2].rgbRed = pCursor->foreRed>>8; /* Foreground */
      pbmi->bmiColors[2].rgbGreen = pCursor->foreGreen>>8;
      pbmi->bmiColors[2].rgbBlue = pCursor->foreBlue>>8;
      pbmi->bmiColors[2].rgbReserved = 0;
      
      lpBits = (unsigned long *) calloc (pScreenPriv->cursor.sm_cx*pScreenPriv->cursor.sm_cy,
					 sizeof (char));
      
      pCur = (unsigned char *)lpBits;
      if (lpBits)
	{
	  for (y=0; y<pScreenPriv->cursor.sm_cy; y++)
	    {
	      for (x=0; x<pScreenPriv->cursor.sm_cx; x++)
		{
		  if (x>=nCX || y>=nCY) /* Outside of X11 icon bounds */
		    (*pCur++) = 0;
		  else /* Within X11 icon bounds */
		    {
		      int nWinPix = bits_to_bytes(pScreenPriv->cursor.sm_cx) * y + (x/8);

		      bit = pAnd[nWinPix];
		      bit = bit & (1<<(7-(x&7)));
		      if (!bit) /* Within the cursor mask? */
			{
			  int nXPix = BitmapBytePad(pCursor->bits->width) * y + (x/8);
			  bit = ~reverse(~pCursor->bits->source[nXPix] & pCursor->bits->mask[nXPix]);
			  bit = bit & (1<<(7-(x&7)));
			  if (bit) /* Draw foreground */
			    (*pCur++) = 2;
			  else /* Draw background */
			    (*pCur++) = 1;
			}
		      else /* Outside the cursor mask */
			(*pCur++) = 0;
		    }
		} /* end for (x) */
	    } /* end for (y) */
	} /* end if (lpbits) */
    }
예제 #21
0
int
ddxProcessArgument (int argc, char *argv[], int i)
{
  static Bool		s_fBeenHere = FALSE;
  winScreenInfo	*screenInfoPtr = NULL;

  /* Initialize once */
  if (!s_fBeenHere)
    {
#ifdef DDXOSVERRORF
      /*
       * This initialises our hook into VErrorF () for catching log messages
       * that are generated before OsInit () is called.
       */
      OsVendorVErrorFProc = OsVendorVErrorF;
#endif

      s_fBeenHere = TRUE;

      /* Initialize only if option is not -help */
      if (!IS_OPTION("-help") && !IS_OPTION("-h") && !IS_OPTION("--help") &&
          !IS_OPTION("-version") && !IS_OPTION("--version"))
	{

          /* Log the version information */
          winLogVersionInfo ();

          /* Log the command line */
          winLogCommandLine (argc, argv);

	  /*
	   * Initialize default screen settings.  We have to do this before
	   * OsVendorInit () gets called, otherwise we will overwrite
	   * settings changed by parameters such as -fullscreen, etc.
	   */
	  winErrorFVerb (2, "ddxProcessArgument - Initializing default "
			 "screens\n");
	  winInitializeScreenDefaults();
	}
    }

#if CYGDEBUG
  winDebug ("ddxProcessArgument - arg: %s\n", argv[i]);
#endif

  /*
   * Look for the '-help' and similar options
   */ 
  if (IS_OPTION ("-help") || IS_OPTION("-h") || IS_OPTION("--help"))
    {
      /* Reset logfile. We don't need that helpmessage in the logfile */  
      g_pszLogFile = NULL;
      g_fNoHelpMessageBox = TRUE;
      UseMsg();
      exit (0);
      return 1;
    }

  if (IS_OPTION ("-version") || IS_OPTION("--version"))
    {
      /* Reset logfile. We don't need that versioninfo in the logfile */  
      g_pszLogFile = NULL;
      winLogVersionInfo ();
      exit (0);
      return 1;
    }

  /*
   * Look for the '-screen scr_num [width height]' argument
   */
  if (IS_OPTION ("-screen"))
    {
      int		iArgsProcessed = 1;
      int		nScreenNum;
      int		iWidth, iHeight, iX, iY;
      int		iMonitor;

#if CYGDEBUG
      winDebug ("ddxProcessArgument - screen - argc: %d i: %d\n",
	      argc, i);
#endif

      /* Display the usage message if the argument is malformed */
      if (i + 1 >= argc)
	{
	  return 0;
	}
      
      /* Grab screen number */
      nScreenNum = atoi (argv[i + 1]);

      /* Validate the specified screen number */
      if (nScreenNum < 0)
        {
          ErrorF ("ddxProcessArgument - screen - Invalid screen number %d\n",
		  nScreenNum);
          UseMsg ();
	  return 0;
        }

      /*
        Initialize default values for any new screens

        Note that default values can't change after a -screen option is
        seen, so it's safe to do this for each screen as it is introduced
      */
      winInitializeScreens(nScreenNum+1);

	  /* look for @m where m is monitor number */
	  if (i + 2 < argc
		  && 1 == sscanf(argv[i + 2], "@%d", (int *) &iMonitor)) 
      {
        struct GetMonitorInfoData data;
        if (!QueryMonitor(iMonitor, &data))
        {
            ErrorF ("ddxProcessArgument - screen - "
                    "Querying monitors is not supported on NT4 and Win95\n");
        } else if (data.bMonitorSpecifiedExists == TRUE) 
        {
		  winErrorFVerb(2, "ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor);
		  iArgsProcessed = 3;
		  g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
		  g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
		  g_ScreenInfo[nScreenNum].dwWidth = data.monitorWidth;
		  g_ScreenInfo[nScreenNum].dwHeight = data.monitorHeight;
		  g_ScreenInfo[nScreenNum].dwUserWidth = data.monitorWidth;
		  g_ScreenInfo[nScreenNum].dwUserHeight = data.monitorHeight;
		  g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
		  g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
		}
		else 
        {
		  /* monitor does not exist, error out */
		  ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
				  iMonitor);
		  UseMsg ();
		  exit (0);
		  return 0;
		}
	  }

      /* Look for 'WxD' or 'W D' */
      else if (i + 2 < argc
	  && 2 == sscanf (argv[i + 2], "%dx%d",
			  (int *) &iWidth,
			  (int *) &iHeight))
	{
	  winErrorFVerb (2, "ddxProcessArgument - screen - Found ``WxD'' arg\n");
	  iArgsProcessed = 3;
	  g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
	  g_ScreenInfo[nScreenNum].dwWidth = iWidth;
	  g_ScreenInfo[nScreenNum].dwHeight = iHeight;
	  g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
	  g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
	  /* Look for WxD+X+Y */
	  if (2 == sscanf (argv[i + 2], "%*dx%*d+%d+%d",
			   (int *) &iX,
			   (int *) &iY))
	  {
	    winErrorFVerb (2, "ddxProcessArgument - screen - Found ``X+Y'' arg\n");
	    g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
	    g_ScreenInfo[nScreenNum].dwInitialX = iX;
	    g_ScreenInfo[nScreenNum].dwInitialY = iY;

		/* look for WxD+X+Y@m where m is monitor number. take X,Y to be offsets from monitor's root position */
		if (1 == sscanf (argv[i + 2], "%*dx%*d+%*d+%*d@%d",
						 (int *) &iMonitor)) 
        {
          struct GetMonitorInfoData data;
          if (!QueryMonitor(iMonitor, &data))
          {
              ErrorF ("ddxProcessArgument - screen - "
                      "Querying monitors is not supported on NT4 and Win95\n");
          } else if (data.bMonitorSpecifiedExists == TRUE) 
          {
			g_ScreenInfo[nScreenNum].dwInitialX += data.monitorOffsetX;
			g_ScreenInfo[nScreenNum].dwInitialY += data.monitorOffsetY;
		  }
		  else 
          {
			/* monitor does not exist, error out */
			ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
					iMonitor);
			UseMsg ();
			exit (0);
			return 0;
		  }

		}
	  }

	  /* look for WxD@m where m is monitor number */
	  else if (1 == sscanf(argv[i + 2], "%*dx%*d@%d",
						   (int *) &iMonitor)) 
      {
        struct GetMonitorInfoData data;
        if (!QueryMonitor(iMonitor, &data))
        {
		  ErrorF ("ddxProcessArgument - screen - "
                  "Querying monitors is not supported on NT4 and Win95\n");
        } else if (data.bMonitorSpecifiedExists == TRUE) 
        {
		  winErrorFVerb (2, "ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor);
		  g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
		  g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
		  g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
		}
		else 
        {
		  /* monitor does not exist, error out */
		  ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
				  iMonitor);
		  UseMsg ();
		  exit (0);
		  return 0;
		}

	  }
	}
      else if (i + 3 < argc
	       && 1 == sscanf (argv[i + 2], "%d",
			       (int *) &iWidth)
	       && 1 == sscanf (argv[i + 3], "%d",
			       (int *) &iHeight))
	{
	  winErrorFVerb (2, "ddxProcessArgument - screen - Found ``W D'' arg\n");
	  iArgsProcessed = 4;
	  g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
	  g_ScreenInfo[nScreenNum].dwWidth = iWidth;
	  g_ScreenInfo[nScreenNum].dwHeight = iHeight;
	  g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
	  g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
	  if (i + 5 < argc
	      && 1 == sscanf (argv[i + 4], "%d",
			      (int *) &iX)
	      && 1 == sscanf (argv[i + 5], "%d",
			      (int *) &iY))
	  {
	    winErrorFVerb (2, "ddxProcessArgument - screen - Found ``X Y'' arg\n");
	    iArgsProcessed = 6;
	    g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
	    g_ScreenInfo[nScreenNum].dwInitialX = iX;
	    g_ScreenInfo[nScreenNum].dwInitialY = iY;
	  }
	}
      else
	{
	  winErrorFVerb (2, "ddxProcessArgument - screen - Did not find size arg. "
		  "dwWidth: %d dwHeight: %d\n",
		  (int) g_ScreenInfo[nScreenNum].dwWidth,
		  (int) g_ScreenInfo[nScreenNum].dwHeight);
	  iArgsProcessed = 2;
	  g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
	}

      /* Calculate the screen width and height in millimeters */
      if (g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth)
	{
	  g_ScreenInfo[nScreenNum].dwWidth_mm
	    = (g_ScreenInfo[nScreenNum].dwWidth
	       / monitorResolution) * 25.4;
	  g_ScreenInfo[nScreenNum].dwHeight_mm
	    = (g_ScreenInfo[nScreenNum].dwHeight
	       / monitorResolution) * 25.4;
	}

      /* Flag that this screen was explicity specified by the user */
      g_ScreenInfo[nScreenNum].fExplicitScreen = TRUE;

      /*
       * Keep track of the last screen number seen, as parameters seen
       * before a screen number apply to all screens, whereas parameters
       * seen after a screen number apply to that screen number only.
       */
      iLastScreen = nScreenNum;

      return iArgsProcessed;
    }


  /*
   * Is this parameter attached to a screen or global?
   *
   * If the parameter is for all screens (appears before
   * any -screen option), store it in the default screen
   * info
   *
   * If the parameter is for a single screen (appears
   * after a -screen option), store it in the screen info
   * for that screen
   *
   */
  if (iLastScreen == -1)
    {
      screenInfoPtr = &defaultScreenInfo;
    }
  else
    {
      screenInfoPtr = &(g_ScreenInfo[iLastScreen]);
    }

  /*
   * Look for the '-engine n' argument
   */
  if (IS_OPTION ("-engine"))
    {
      DWORD		dwEngine = 0;
      CARD8		c8OnBits = 0;
      
      /* Display the usage message if the argument is malformed */
      if (++i >= argc)
	{
	  UseMsg ();
	  return 0;
	}

      /* Grab the argument */
      dwEngine = atoi (argv[i]);

      /* Count the one bits in the engine argument */
      c8OnBits = winCountBits (dwEngine);

      /* Argument should only have a single bit on */
      if (c8OnBits != 1)
	{
	  UseMsg ();
	  return 0;
	}

      screenInfoPtr->dwEnginePreferred = dwEngine;
      
      /* Indicate that we have processed the argument */
      return 2;
    }

  /*
   * Look for the '-fullscreen' argument
   */
  if (IS_OPTION ("-fullscreen"))
    {
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
          if (!screenInfoPtr->fMultiMonitorOverride)
            screenInfoPtr->fMultipleMonitors = FALSE;
#endif
	  screenInfoPtr->fFullScreen = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-lesspointer' argument
   */
  if (IS_OPTION ("-lesspointer"))
    {
      screenInfoPtr->fLessPointer = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-nodecoration' argument
   */
  if (IS_OPTION ("-nodecoration"))
    {
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
      if (!screenInfoPtr->fMultiMonitorOverride)
        screenInfoPtr->fMultipleMonitors = FALSE;
#endif
      screenInfoPtr->fDecoration = FALSE;

      /* Indicate that we have processed this argument */
      return 1;
    }

#ifdef XWIN_MULTIWINDOWEXTWM
  /*
   * Look for the '-mwextwm' argument
   */
  if (IS_OPTION ("-mwextwm"))
    {
      if (!screenInfoPtr->fMultiMonitorOverride)
        screenInfoPtr->fMultipleMonitors = TRUE;
      screenInfoPtr->fMWExtWM = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }
  /*
   * Look for the '-internalwm' argument
   */
  if (IS_OPTION ("-internalwm"))
    {
      if (!screenInfoPtr->fMultiMonitorOverride)
        screenInfoPtr->fMultipleMonitors = TRUE;
      screenInfoPtr->fMWExtWM = TRUE;
      screenInfoPtr->fInternalWM = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }
#endif

  /*
   * Look for the '-rootless' argument
   */
  if (IS_OPTION ("-rootless"))
    {
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
      if (!screenInfoPtr->fMultiMonitorOverride)
        screenInfoPtr->fMultipleMonitors = FALSE;
#endif
      screenInfoPtr->fRootless = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }

#ifdef XWIN_MULTIWINDOW
  /*
   * Look for the '-multiwindow' argument
   */
  if (IS_OPTION ("-multiwindow"))
    {
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
      if (!screenInfoPtr->fMultiMonitorOverride)
        screenInfoPtr->fMultipleMonitors = TRUE;
#endif
      screenInfoPtr->fMultiWindow = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }
#endif

  /*
   * Look for the '-multiplemonitors' argument
   */
  if (IS_OPTION ("-multiplemonitors")
      || IS_OPTION ("-multimonitors"))
    {
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
      screenInfoPtr->fMultiMonitorOverride = TRUE;
#endif
      screenInfoPtr->fMultipleMonitors = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-nomultiplemonitors' argument
   */
  if (IS_OPTION ("-nomultiplemonitors")
      || IS_OPTION ("-nomultimonitors"))
    {
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
      screenInfoPtr->fMultiMonitorOverride = TRUE;
#endif
      screenInfoPtr->fMultipleMonitors = FALSE;

      /* Indicate that we have processed this argument */
      return 1;
    }


  /*
   * Look for the '-scrollbars' argument
   */
  if (IS_OPTION ("-scrollbars"))
    {
      screenInfoPtr->fScrollbars = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }


#ifdef XWIN_CLIPBOARD
  /*
   * Look for the '-clipboard' argument
   */
  if (IS_OPTION ("-clipboard"))
    {
      /* Now the default, we still accept the arg for backwards compatibility */
      g_fClipboard = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-noclipboard' argument
   */
  if (IS_OPTION ("-noclipboard"))
    {
      g_fClipboard = FALSE;

      /* Indicate that we have processed this argument */
      return 1;
    }
#endif


  /*
   * Look for the '-ignoreinput' argument
   */
  if (IS_OPTION ("-ignoreinput"))
    {
      screenInfoPtr->fIgnoreInput = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-emulate3buttons' argument
   */
  if (IS_OPTION ("-emulate3buttons"))
    {
      int	iArgsProcessed = 1;
      int	iE3BTimeout = WIN_DEFAULT_E3B_TIME;

      /* Grab the optional timeout value */
      if (i + 1 < argc
	  && 1 == sscanf (argv[i + 1], "%d",
			  &iE3BTimeout))
        {
	  /* Indicate that we have processed the next argument */
	  iArgsProcessed++;
        }
      else
	{
	  /*
	   * sscanf () won't modify iE3BTimeout if it doesn't find
	   * the specified format; however, I want to be explicit
	   * about setting the default timeout in such cases to
	   * prevent some programs (me) from getting confused.
	   */
	  iE3BTimeout = WIN_DEFAULT_E3B_TIME;
	}

      screenInfoPtr->iE3BTimeout = iE3BTimeout;

      /* Indicate that we have processed this argument */
      return iArgsProcessed;
    }

  /*
   * Look for the '-depth n' argument
   */
  if (IS_OPTION ("-depth"))
    {
      DWORD		dwBPP = 0;
      
      /* Display the usage message if the argument is malformed */
      if (++i >= argc)
	{
	  UseMsg ();
	  return 0;
	}

      /* Grab the argument */
      dwBPP = atoi (argv[i]);

      screenInfoPtr->dwBPP = dwBPP;

      /* Indicate that we have processed the argument */
      return 2;
    }

  /*
   * Look for the '-refresh n' argument
   */
  if (IS_OPTION ("-refresh"))
    {
      DWORD		dwRefreshRate = 0;
      
      /* Display the usage message if the argument is malformed */
      if (++i >= argc)
	{
	  UseMsg ();
	  return 0;
	}

      /* Grab the argument */
      dwRefreshRate = atoi (argv[i]);

      screenInfoPtr->dwRefreshRate = dwRefreshRate;

      /* Indicate that we have processed the argument */
      return 2;
    }

  /*
   * Look for the '-clipupdates num_boxes' argument
   */
  if (IS_OPTION ("-clipupdates"))
    {
      DWORD		dwNumBoxes = 0;
      
      /* Display the usage message if the argument is malformed */
      if (++i >= argc)
	{
	  UseMsg ();
	  return 0;
	}

      /* Grab the argument */
      dwNumBoxes = atoi (argv[i]);

      screenInfoPtr->dwClipUpdatesNBoxes = dwNumBoxes;

      /* Indicate that we have processed the argument */
      return 2;
    }

#ifdef XWIN_EMULATEPSEUDO
  /*
   * Look for the '-emulatepseudo' argument
   */
  if (IS_OPTION ("-emulatepseudo"))
    {
      screenInfoPtr->fEmulatePseudo = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }
#endif

  /*
   * Look for the '-nowinkill' argument
   */
  if (IS_OPTION ("-nowinkill"))
    {
      screenInfoPtr->fUseWinKillKey = FALSE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-winkill' argument
   */
  if (IS_OPTION ("-winkill"))
    {
      screenInfoPtr->fUseWinKillKey = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-nounixkill' argument
   */
  if (IS_OPTION ("-nounixkill"))
    {
      screenInfoPtr->fUseUnixKillKey = FALSE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-unixkill' argument
   */
  if (IS_OPTION ("-unixkill"))
    {
      screenInfoPtr->fUseUnixKillKey = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-notrayicon' argument
   */
  if (IS_OPTION ("-notrayicon"))
    {
      screenInfoPtr->fNoTrayIcon = TRUE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-trayicon' argument
   */
  if (IS_OPTION ("-trayicon"))
    {
      screenInfoPtr->fNoTrayIcon = FALSE;

      /* Indicate that we have processed this argument */
      return 1;
    }

  /*
   * Look for the '-fp' argument
   */
  if (IS_OPTION ("-fp"))
    {
      CHECK_ARGS (1);
      g_cmdline.fontPath = argv[++i];
      return 0; /* Let DIX parse this again */
    }

  /*
   * Look for the '-query' argument
   */
  if (IS_OPTION ("-query"))
    {
      CHECK_ARGS (1);
      g_fXdmcpEnabled = TRUE;
      g_pszQueryHost = argv[++i];
      return 0; /* Let DIX parse this again */
    }

  /*
   * Look for the '-auth' argument
   */
  if (IS_OPTION ("-auth"))
    {
      g_fAuthEnabled = TRUE;
      return 0; /* Let DIX parse this again */
    }

  /*
   * Look for the '-indirect' or '-broadcast' arguments
   */
  if (IS_OPTION ("-indirect")
      || IS_OPTION ("-broadcast"))
    {
      g_fXdmcpEnabled = TRUE;
      return 0; /* Let DIX parse this again */
    }

  /*
   * Look for the '-config' argument
   */
  if (IS_OPTION ("-config")
      || IS_OPTION ("-xf86config"))
    {
      CHECK_ARGS (1);
#ifdef XWIN_XF86CONFIG
      g_cmdline.configFile = argv[++i];
#else
      winMessageBoxF ("The %s option is not supported in this "
		      "release.\n"
		      "Ignoring this option and continuing.\n",
		      MB_ICONINFORMATION,
		      argv[i]);
#endif
      return 2;
    }

  /*
   * Look for the '-configdir' argument
   */
  if (IS_OPTION ("-configdir"))
    {
      CHECK_ARGS (1);
#ifdef XWIN_XF86CONFIG
      g_cmdline.configDir = argv[++i];
#else
      winMessageBoxF ("The %s option is not supported in this "
		      "release.\n"
		      "Ignoring this option and continuing.\n",
		      MB_ICONINFORMATION,
		      argv[i]);
#endif
      return 2;
    }

  /*
   * Look for the '-keyboard' argument
   */
  if (IS_OPTION ("-keyboard"))
    {
#ifdef XWIN_XF86CONFIG
      CHECK_ARGS (1);
      g_cmdline.keyboard = argv[++i];
#else
      winMessageBoxF ("The -keyboard option is not supported in this "
		      "release.\n"
		      "Ignoring this option and continuing.\n",
		      MB_ICONINFORMATION);
#endif
      return 2;
    }

  /*
   * Look for the '-logfile' argument
   */
  if (IS_OPTION ("-logfile"))
    {
      CHECK_ARGS (1);
      g_pszLogFile = argv[++i];
#ifdef RELOCATE_PROJECTROOT
      g_fLogFileChanged = TRUE;
#endif
      return 2;
    }

  /*
   * Look for the '-logverbose' argument
   */
  if (IS_OPTION ("-logverbose"))
    {
      CHECK_ARGS (1);
      g_iLogVerbose = atoi(argv[++i]);
      return 2;
    }

#ifdef XWIN_CLIPBOARD
  /*
   * Look for the '-nounicodeclipboard' argument
   */
  if (IS_OPTION ("-nounicodeclipboard"))
    {
      g_fUnicodeClipboard = FALSE;
      /* Indicate that we have processed the argument */
      return 1;
    }
#endif

  if (IS_OPTION ("-xkbrules"))
    {
      CHECK_ARGS (1);
      g_cmdline.xkbRules = argv[++i];
      return 2;
    }
  if (IS_OPTION ("-xkbmodel"))
    {
      CHECK_ARGS (1);
      g_cmdline.xkbModel = argv[++i];
      return 2;
    }
  if (IS_OPTION ("-xkblayout"))
    {
      CHECK_ARGS (1);
      g_cmdline.xkbLayout = argv[++i];
      return 2;
    }
  if (IS_OPTION ("-xkbvariant"))
    {
      CHECK_ARGS (1);
      g_cmdline.xkbVariant = argv[++i];
      return 2;
    }
  if (IS_OPTION ("-xkboptions"))
    {
      CHECK_ARGS (1);
      g_cmdline.xkbOptions = argv[++i];
      return 2;
    }

  if (IS_OPTION ("-keyhook"))
    {
      g_fKeyboardHookLL = TRUE;
      return 1;
    }
  
  if (IS_OPTION ("-nokeyhook"))
    {
      g_fKeyboardHookLL = FALSE;
      return 1;
    }
  
  if (IS_OPTION ("-swcursor"))
    {
      g_fSoftwareCursor = TRUE;
      return 1;
    }
  
  if (IS_OPTION ("-silent-dup-error"))
    {
      g_fSilentDupError = TRUE;
      return 1;
    }

  if (IS_OPTION("-wgl"))
    {
      g_fNativeGl = TRUE;
      return 1;
    }

  if (IS_OPTION("-nowgl"))
    {
      g_fNativeGl = FALSE;
      return 1;
    }

  return 0;
}
예제 #22
0
int
winKeybdProc (DeviceIntPtr pDeviceInt, int iState)
{
  KeySymsRec		keySyms;
  CARD8 		modMap[MAP_LENGTH];
  DevicePtr		pDevice = (DevicePtr) pDeviceInt;
#ifdef XKB
  XkbComponentNamesRec names;
  XkbSrvInfoPtr       xkbi;
  XkbControlsPtr      ctrl;
#endif

  switch (iState)
    {
    case DEVICE_INIT:
      winConfigKeyboard (pDeviceInt);

      winGetKeyMappings (&keySyms, modMap);

#ifdef XKB
      /* FIXME: Maybe we should use winGetKbdLeds () here? */
      defaultKeyboardControl.leds = g_winInfo.keyboard.leds;
#else
      defaultKeyboardControl.leds = g_winInfo.keyboard.leds;
#endif

#ifdef XKB
      if (g_winInfo.xkb.disable) 
	{
#endif
	  InitKeyboardDeviceStruct (pDevice,
				    &keySyms,
				    modMap,
				    winKeybdBell,
				    winKeybdCtrl);
#ifdef XKB
	} 
      else 
	{

	  if (XkbInitialMap) 
	    {
	      names.keymap = XkbInitialMap;
	      names.keycodes = NULL;
	      names.types = NULL;
	      names.compat = NULL;
	      names.symbols = NULL;
	      names.geometry = NULL;
	    } 
	  else 
	    {
	      names.keymap = g_winInfo.xkb.keymap;
	      names.keycodes = g_winInfo.xkb.keycodes;
	      names.types = g_winInfo.xkb.types;
	      names.compat = g_winInfo.xkb.compat;
	      names.symbols = g_winInfo.xkb.symbols;
	      names.geometry = g_winInfo.xkb.geometry;
	    }

	  winErrorFVerb(2, "Rules = \"%s\" Model = \"%s\" Layout = \"%s\""
		 " Variant = \"%s\" Options = \"%s\"\n",
		 g_winInfo.xkb.rules, g_winInfo.xkb.model,
		 g_winInfo.xkb.layout, g_winInfo.xkb.variant,
		 g_winInfo.xkb.options);
          
	  XkbSetRulesDflts (g_winInfo.xkb.rules, g_winInfo.xkb.model, 
			    g_winInfo.xkb.layout, g_winInfo.xkb.variant, 
			    g_winInfo.xkb.options);
	  XkbInitKeyboardDeviceStruct (pDeviceInt, &names, &keySyms,
				       modMap, winKeybdBell, winKeybdCtrl);
	}
#endif

#ifdef XKB
      if (!g_winInfo.xkb.disable)
        {  
          xkbi = pDeviceInt->key->xkbInfo;
          if (xkbi != NULL)
            {  
              ctrl = xkbi->desc->ctrls;
              ctrl->repeat_delay = g_winInfo.keyboard.delay;
              ctrl->repeat_interval = 1000/g_winInfo.keyboard.rate;
            }
          else
            {  
              winErrorFVerb (1, "winKeybdProc - Error initializing keyboard AutoRepeat (No XKB)\n");
            }
        }
#endif

      g_winInternalModeKeyStatesPtr = &(pDeviceInt->key->state);
      break;
      
    case DEVICE_ON: 
      pDevice->on = TRUE;
      g_winInternalModeKeyStatesPtr = &(pDeviceInt->key->state);
      break;

    case DEVICE_CLOSE:
    case DEVICE_OFF: 
      pDevice->on = FALSE;
      g_winInternalModeKeyStatesPtr = NULL;
      break;
    }

  return Success;
}