From 1c94119ae26b94a60bb2c2b33494ed43c3b8a52f Mon Sep 17 00:00:00 2001 From: marha Date: Sun, 16 May 2010 20:50:58 +0000 Subject: svn merge -r588:HEAD ^/branches/released . --- xorg-server/hw/xnest/Color.c | 990 ++++++++++++++++++++-------------------- xorg-server/hw/xnest/Cursor.c | 366 +++++++-------- xorg-server/hw/xnest/Display.c | 386 ++++++++-------- xorg-server/hw/xnest/Font.c | 172 +++---- xorg-server/hw/xnest/GC.c | 678 +++++++++++++-------------- xorg-server/hw/xnest/Keyboard.c | 514 ++++++++++----------- xorg-server/hw/xnest/Pixmap.c | 282 ++++++------ xorg-server/hw/xnest/Screen.c | 841 +++++++++++++++++----------------- 8 files changed, 2114 insertions(+), 2115 deletions(-) (limited to 'xorg-server/hw/xnest') diff --git a/xorg-server/hw/xnest/Color.c b/xorg-server/hw/xnest/Color.c index 2e6de15e4..985b5ad95 100644 --- a/xorg-server/hw/xnest/Color.c +++ b/xorg-server/hw/xnest/Color.c @@ -1,495 +1,495 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - -#ifdef HAVE_XNEST_CONFIG_H -#include -#endif - -#include -#include -#include "scrnintstr.h" -#include "window.h" -#include "windowstr.h" -#include "colormapst.h" -#include "resource.h" - -#include "Xnest.h" - - -#include "Display.h" -#include "Screen.h" -#include "Color.h" -#include "Visual.h" -#include "XNWindow.h" -#include "Args.h" - -static int cmapScrPrivateKeyIndex; -static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex; - -#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey)) -#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c)) - -Bool -xnestCreateColormap(ColormapPtr pCmap) -{ - VisualPtr pVisual; - XColor *colors; - int i, ncolors; - Pixel red, green, blue; - Pixel redInc, greenInc, blueInc; - - pVisual = pCmap->pVisual; - ncolors = pVisual->ColormapEntries; - - pCmap->devPriv = (pointer)xalloc(sizeof(xnestPrivColormap)); - - xnestColormapPriv(pCmap)->colormap = - XCreateColormap(xnestDisplay, - xnestDefaultWindows[pCmap->pScreen->myNum], - xnestVisual(pVisual), - (pVisual->class & DynamicClass) ? - AllocAll : AllocNone); - - - switch (pVisual->class) { - case StaticGray: /* read only */ - colors = (XColor *)xalloc(ncolors * sizeof(XColor)); - for (i = 0; i < ncolors; i++) - colors[i].pixel = i; - XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors); - for (i = 0; i < ncolors; i++) { - pCmap->red[i].co.local.red = colors[i].red; - pCmap->red[i].co.local.green = colors[i].red; - pCmap->red[i].co.local.blue = colors[i].red; - } - xfree(colors); - break; - - case StaticColor: /* read only */ - colors = (XColor *)xalloc(ncolors * sizeof(XColor)); - for (i = 0; i < ncolors; i++) - colors[i].pixel = i; - XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors); - for (i = 0; i < ncolors; i++) { - pCmap->red[i].co.local.red = colors[i].red; - pCmap->red[i].co.local.green = colors[i].green; - pCmap->red[i].co.local.blue = colors[i].blue; - } - xfree(colors); - break; - - case TrueColor: /* read only */ - colors = (XColor *)xalloc(ncolors * sizeof(XColor)); - red = green = blue = 0L; - redInc = lowbit(pVisual->redMask); - greenInc = lowbit(pVisual->greenMask); - blueInc = lowbit(pVisual->blueMask); - for (i = 0; i < ncolors; i++) { - colors[i].pixel = red | green | blue; - red += redInc; - if (red > pVisual->redMask) red = 0L; - green += greenInc; - if (green > pVisual->greenMask) green = 0L; - blue += blueInc; - if (blue > pVisual->blueMask) blue = 0L; - } - XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors); - for (i = 0; i < ncolors; i++) { - pCmap->red[i].co.local.red = colors[i].red; - pCmap->green[i].co.local.green = colors[i].green; - pCmap->blue[i].co.local.blue = colors[i].blue; - } - xfree(colors); - break; - - case GrayScale: /* read and write */ - break; - - case PseudoColor: /* read and write */ - break; - - case DirectColor: /* read and write */ - break; - } - - return True; -} - -void -xnestDestroyColormap(ColormapPtr pCmap) -{ - XFreeColormap(xnestDisplay, xnestColormap(pCmap)); - xfree(pCmap->devPriv); -} - -#define SEARCH_PREDICATE \ - (xnestWindow(pWin) != None && wColormap(pWin) == icws->cmapIDs[i]) - -static int -xnestCountInstalledColormapWindows(WindowPtr pWin, pointer ptr) -{ - xnestInstalledColormapWindows *icws = (xnestInstalledColormapWindows *)ptr; - int i; - - for (i = 0; i < icws->numCmapIDs; i++) - if (SEARCH_PREDICATE) { - icws->numWindows++; - return WT_DONTWALKCHILDREN; - } - - return WT_WALKCHILDREN; -} - -static int -xnestGetInstalledColormapWindows(WindowPtr pWin, pointer ptr) -{ - xnestInstalledColormapWindows *icws = (xnestInstalledColormapWindows *)ptr; - int i; - - for (i = 0; i < icws->numCmapIDs; i++) - if (SEARCH_PREDICATE) { - icws->windows[icws->index++] = xnestWindow(pWin); - return WT_DONTWALKCHILDREN; - } - - return WT_WALKCHILDREN; -} - -static Window *xnestOldInstalledColormapWindows = NULL; -static int xnestNumOldInstalledColormapWindows = 0; - -static Bool -xnestSameInstalledColormapWindows(Window *windows, int numWindows) -{ - if (xnestNumOldInstalledColormapWindows != numWindows) - return False; - - if (xnestOldInstalledColormapWindows == windows) - return True; - - if (xnestOldInstalledColormapWindows == NULL || windows == NULL) - return False; - - if (memcmp(xnestOldInstalledColormapWindows, windows, - numWindows * sizeof(Window))) - return False; - - return True; -} - -void -xnestSetInstalledColormapWindows(ScreenPtr pScreen) -{ - xnestInstalledColormapWindows icws; - int numWindows; - - icws.cmapIDs = (Colormap *)xalloc(pScreen->maxInstalledCmaps * - sizeof(Colormap)); - icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs); - icws.numWindows = 0; - WalkTree(pScreen, xnestCountInstalledColormapWindows, (pointer)&icws); - if (icws.numWindows) { - icws.windows = (Window *)xalloc((icws.numWindows + 1) * sizeof(Window)); - icws.index = 0; - WalkTree(pScreen, xnestGetInstalledColormapWindows, (pointer)&icws); - icws.windows[icws.numWindows] = xnestDefaultWindows[pScreen->myNum]; - numWindows = icws.numWindows + 1; - } - else { - icws.windows = NULL; - numWindows = 0; - } - - xfree(icws.cmapIDs); - - if (!xnestSameInstalledColormapWindows(icws.windows, icws.numWindows)) { - if (xnestOldInstalledColormapWindows) - xfree(xnestOldInstalledColormapWindows); - -#ifdef _XSERVER64 - { - int i; - Window64 *windows = (Window64 *)xalloc(numWindows * sizeof(Window64)); - - for(i = 0; i < numWindows; ++i) - windows[i] = icws.windows[i]; - XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], - windows, numWindows); - xfree(windows); - } -#else - XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], - icws.windows, numWindows); -#endif - - xnestOldInstalledColormapWindows = icws.windows; - xnestNumOldInstalledColormapWindows = icws.numWindows; - -#ifdef DUMB_WINDOW_MANAGERS - /* - This code is for dumb window managers. - This will only work with default local visual colormaps. - */ - if (icws.numWindows) - { - WindowPtr pWin; - Visual *visual; - ColormapPtr pCmap; - - pWin = xnestWindowPtr(icws.windows[0]); - visual = xnestVisualFromID(pScreen, wVisual(pWin)); - - if (visual == xnestDefaultVisual(pScreen)) - dixLookupResourceByType((pointer *)&pCmap, wColormap(pWin), - RT_COLORMAP, serverClient, DixUseAccess); - else - dixLookupResourceByType((pointer *)&pCmap, pScreen->defColormap, - RT_COLORMAP, serverClient, DixUseAccess); - - XSetWindowColormap(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], - xnestColormap(pCmap)); - } -#endif /* DUMB_WINDOW_MANAGERS */ - } - else - if (icws.windows) xfree(icws.windows); -} - -void -xnestSetScreenSaverColormapWindow(ScreenPtr pScreen) -{ - if (xnestOldInstalledColormapWindows) - xfree(xnestOldInstalledColormapWindows); - -#ifdef _XSERVER64 - { - Window64 window; - - window = xnestScreenSaverWindows[pScreen->myNum]; - XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], - &window, 1); - xnestScreenSaverWindows[pScreen->myNum] = window; - } -#else - XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], - &xnestScreenSaverWindows[pScreen->myNum], 1); -#endif /* _XSERVER64 */ - - xnestOldInstalledColormapWindows = NULL; - xnestNumOldInstalledColormapWindows = 0; - - xnestDirectUninstallColormaps(pScreen); -} - -void -xnestDirectInstallColormaps(ScreenPtr pScreen) -{ - int i, n; - Colormap pCmapIDs[MAXCMAPS]; - - if (!xnestDoDirectColormaps) return; - - n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs); - - for (i = 0; i < n; i++) { - ColormapPtr pCmap; - - dixLookupResourceByType((pointer *)&pCmap, pCmapIDs[i], RT_COLORMAP, - serverClient, DixInstallAccess); - if (pCmap) - XInstallColormap(xnestDisplay, xnestColormap(pCmap)); - } -} - -void -xnestDirectUninstallColormaps(ScreenPtr pScreen) -{ - int i, n; - Colormap pCmapIDs[MAXCMAPS]; - - if (!xnestDoDirectColormaps) return; - - n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs); - - for (i = 0; i < n; i++) { - ColormapPtr pCmap; - - dixLookupResourceByType((pointer *)&pCmap, pCmapIDs[i], RT_COLORMAP, - serverClient, DixUninstallAccess); - if (pCmap) - XUninstallColormap(xnestDisplay, xnestColormap(pCmap)); - } -} - -void -xnestInstallColormap(ColormapPtr pCmap) -{ - ColormapPtr pOldCmap = GetInstalledColormap(pCmap->pScreen); - - if(pCmap != pOldCmap) - { - xnestDirectUninstallColormaps(pCmap->pScreen); - - /* Uninstall pInstalledMap. Notify all interested parties. */ - if(pOldCmap != (ColormapPtr)None) - WalkTree(pCmap->pScreen, TellLostMap, (pointer)&pOldCmap->mid); - - SetInstalledColormap(pCmap->pScreen, pCmap); - WalkTree(pCmap->pScreen, TellGainedMap, (pointer)&pCmap->mid); - - xnestSetInstalledColormapWindows(pCmap->pScreen); - xnestDirectInstallColormaps(pCmap->pScreen); - } -} - -void -xnestUninstallColormap(ColormapPtr pCmap) -{ - ColormapPtr pCurCmap = GetInstalledColormap(pCmap->pScreen); - - if(pCmap == pCurCmap) - { - if (pCmap->mid != pCmap->pScreen->defColormap) - { - dixLookupResourceByType((pointer *)&pCurCmap, - pCmap->pScreen->defColormap, - RT_COLORMAP, - serverClient, DixInstallAccess); - (*pCmap->pScreen->InstallColormap)(pCurCmap); - } - } -} - -static Bool xnestInstalledDefaultColormap = False; - -int -xnestListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapIDs) -{ - if (xnestInstalledDefaultColormap) { - *pCmapIDs = GetInstalledColormap(pScreen)->mid; - return 1; - } - else - return 0; -} - -void -xnestStoreColors(ColormapPtr pCmap, int nColors, xColorItem *pColors) -{ - if (pCmap->pVisual->class & DynamicClass) -#ifdef _XSERVER64 - { - int i; - XColor *pColors64 = (XColor *)xalloc(nColors * sizeof(XColor) ); - - for(i = 0; i < nColors; ++i) - { - pColors64[i].pixel = pColors[i].pixel; - pColors64[i].red = pColors[i].red; - pColors64[i].green = pColors[i].green; - pColors64[i].blue = pColors[i].blue; - pColors64[i].flags = pColors[i].flags; - } - XStoreColors(xnestDisplay, xnestColormap(pCmap), pColors64, nColors); - xfree(pColors64); - } -#else - XStoreColors(xnestDisplay, xnestColormap(pCmap), - (XColor *)pColors, nColors); -#endif -} - -void -xnestResolveColor(unsigned short *pRed, unsigned short *pGreen, - unsigned short *pBlue, VisualPtr pVisual) -{ - int shift; - unsigned int lim; - - shift = 16 - pVisual->bitsPerRGBValue; - lim = (1 << pVisual->bitsPerRGBValue) - 1; - - if ((pVisual->class == PseudoColor) || (pVisual->class == DirectColor)) - { - /* rescale to rgb bits */ - *pRed = ((*pRed >> shift) * 65535) / lim; - *pGreen = ((*pGreen >> shift) * 65535) / lim; - *pBlue = ((*pBlue >> shift) * 65535) / lim; - } - else if (pVisual->class == GrayScale) - { - /* rescale to gray then rgb bits */ - *pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100; - *pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim; - } - else if (pVisual->class == StaticGray) - { - unsigned int limg; - - limg = pVisual->ColormapEntries - 1; - /* rescale to gray then [0..limg] then [0..65535] then rgb bits */ - *pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100; - *pRed = ((((*pRed * (limg + 1))) >> 16) * 65535) / limg; - *pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim; - } - else - { - unsigned limr, limg, limb; - - limr = pVisual->redMask >> pVisual->offsetRed; - limg = pVisual->greenMask >> pVisual->offsetGreen; - limb = pVisual->blueMask >> pVisual->offsetBlue; - /* rescale to [0..limN] then [0..65535] then rgb bits */ - *pRed = ((((((*pRed * (limr + 1)) >> 16) * - 65535) / limr) >> shift) * 65535) / lim; - *pGreen = ((((((*pGreen * (limg + 1)) >> 16) * - 65535) / limg) >> shift) * 65535) / lim; - *pBlue = ((((((*pBlue * (limb + 1)) >> 16) * - 65535) / limb) >> shift) * 65535) / lim; - } -} - -Bool -xnestCreateDefaultColormap(ScreenPtr pScreen) -{ - VisualPtr pVisual; - ColormapPtr pCmap; - unsigned short zero = 0, ones = 0xFFFF; - Pixel wp, bp; - - for (pVisual = pScreen->visuals; - pVisual->vid != pScreen->rootVisual; - pVisual++); - - if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &pCmap, - (pVisual->class & DynamicClass) ? AllocNone : AllocAll, 0) - != Success) - return False; - - wp = pScreen->whitePixel; - bp = pScreen->blackPixel; - if ((AllocColor(pCmap, &ones, &ones, &ones, &wp, 0) != - Success) || - (AllocColor(pCmap, &zero, &zero, &zero, &bp, 0) != - Success)) - return FALSE; - pScreen->whitePixel = wp; - pScreen->blackPixel = bp; - (*pScreen->InstallColormap)(pCmap); - - xnestInstalledDefaultColormap = True; - - return True; -} +/* + +Copyright 1993 by Davor Matic + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. Davor Matic makes no representations about +the suitability of this software for any purpose. It is provided "as +is" without express or implied warranty. + +*/ + +#ifdef HAVE_XNEST_CONFIG_H +#include +#endif + +#include +#include +#include "scrnintstr.h" +#include "window.h" +#include "windowstr.h" +#include "colormapst.h" +#include "resource.h" + +#include "Xnest.h" + + +#include "Display.h" +#include "Screen.h" +#include "Color.h" +#include "Visual.h" +#include "XNWindow.h" +#include "Args.h" + +static int cmapScrPrivateKeyIndex; +static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex; + +#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey)) +#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c)) + +Bool +xnestCreateColormap(ColormapPtr pCmap) +{ + VisualPtr pVisual; + XColor *colors; + int i, ncolors; + Pixel red, green, blue; + Pixel redInc, greenInc, blueInc; + + pVisual = pCmap->pVisual; + ncolors = pVisual->ColormapEntries; + + pCmap->devPriv = (pointer)malloc(sizeof(xnestPrivColormap)); + + xnestColormapPriv(pCmap)->colormap = + XCreateColormap(xnestDisplay, + xnestDefaultWindows[pCmap->pScreen->myNum], + xnestVisual(pVisual), + (pVisual->class & DynamicClass) ? + AllocAll : AllocNone); + + + switch (pVisual->class) { + case StaticGray: /* read only */ + colors = (XColor *)malloc(ncolors * sizeof(XColor)); + for (i = 0; i < ncolors; i++) + colors[i].pixel = i; + XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors); + for (i = 0; i < ncolors; i++) { + pCmap->red[i].co.local.red = colors[i].red; + pCmap->red[i].co.local.green = colors[i].red; + pCmap->red[i].co.local.blue = colors[i].red; + } + free(colors); + break; + + case StaticColor: /* read only */ + colors = (XColor *)malloc(ncolors * sizeof(XColor)); + for (i = 0; i < ncolors; i++) + colors[i].pixel = i; + XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors); + for (i = 0; i < ncolors; i++) { + pCmap->red[i].co.local.red = colors[i].red; + pCmap->red[i].co.local.green = colors[i].green; + pCmap->red[i].co.local.blue = colors[i].blue; + } + free(colors); + break; + + case TrueColor: /* read only */ + colors = (XColor *)malloc(ncolors * sizeof(XColor)); + red = green = blue = 0L; + redInc = lowbit(pVisual->redMask); + greenInc = lowbit(pVisual->greenMask); + blueInc = lowbit(pVisual->blueMask); + for (i = 0; i < ncolors; i++) { + colors[i].pixel = red | green | blue; + red += redInc; + if (red > pVisual->redMask) red = 0L; + green += greenInc; + if (green > pVisual->greenMask) green = 0L; + blue += blueInc; + if (blue > pVisual->blueMask) blue = 0L; + } + XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors); + for (i = 0; i < ncolors; i++) { + pCmap->red[i].co.local.red = colors[i].red; + pCmap->green[i].co.local.green = colors[i].green; + pCmap->blue[i].co.local.blue = colors[i].blue; + } + free(colors); + break; + + case GrayScale: /* read and write */ + break; + + case PseudoColor: /* read and write */ + break; + + case DirectColor: /* read and write */ + break; + } + + return True; +} + +void +xnestDestroyColormap(ColormapPtr pCmap) +{ + XFreeColormap(xnestDisplay, xnestColormap(pCmap)); + free(pCmap->devPriv); +} + +#define SEARCH_PREDICATE \ + (xnestWindow(pWin) != None && wColormap(pWin) == icws->cmapIDs[i]) + +static int +xnestCountInstalledColormapWindows(WindowPtr pWin, pointer ptr) +{ + xnestInstalledColormapWindows *icws = (xnestInstalledColormapWindows *)ptr; + int i; + + for (i = 0; i < icws->numCmapIDs; i++) + if (SEARCH_PREDICATE) { + icws->numWindows++; + return WT_DONTWALKCHILDREN; + } + + return WT_WALKCHILDREN; +} + +static int +xnestGetInstalledColormapWindows(WindowPtr pWin, pointer ptr) +{ + xnestInstalledColormapWindows *icws = (xnestInstalledColormapWindows *)ptr; + int i; + + for (i = 0; i < icws->numCmapIDs; i++) + if (SEARCH_PREDICATE) { + icws->windows[icws->index++] = xnestWindow(pWin); + return WT_DONTWALKCHILDREN; + } + + return WT_WALKCHILDREN; +} + +static Window *xnestOldInstalledColormapWindows = NULL; +static int xnestNumOldInstalledColormapWindows = 0; + +static Bool +xnestSameInstalledColormapWindows(Window *windows, int numWindows) +{ + if (xnestNumOldInstalledColormapWindows != numWindows) + return False; + + if (xnestOldInstalledColormapWindows == windows) + return True; + + if (xnestOldInstalledColormapWindows == NULL || windows == NULL) + return False; + + if (memcmp(xnestOldInstalledColormapWindows, windows, + numWindows * sizeof(Window))) + return False; + + return True; +} + +void +xnestSetInstalledColormapWindows(ScreenPtr pScreen) +{ + xnestInstalledColormapWindows icws; + int numWindows; + + icws.cmapIDs = (Colormap *)malloc(pScreen->maxInstalledCmaps * + sizeof(Colormap)); + icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs); + icws.numWindows = 0; + WalkTree(pScreen, xnestCountInstalledColormapWindows, (pointer)&icws); + if (icws.numWindows) { + icws.windows = (Window *)malloc((icws.numWindows + 1) * sizeof(Window)); + icws.index = 0; + WalkTree(pScreen, xnestGetInstalledColormapWindows, (pointer)&icws); + icws.windows[icws.numWindows] = xnestDefaultWindows[pScreen->myNum]; + numWindows = icws.numWindows + 1; + } + else { + icws.windows = NULL; + numWindows = 0; + } + + free(icws.cmapIDs); + + if (!xnestSameInstalledColormapWindows(icws.windows, icws.numWindows)) { + if (xnestOldInstalledColormapWindows) + free(xnestOldInstalledColormapWindows); + +#ifdef _XSERVER64 + { + int i; + Window64 *windows = (Window64 *)malloc(numWindows * sizeof(Window64)); + + for(i = 0; i < numWindows; ++i) + windows[i] = icws.windows[i]; + XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], + windows, numWindows); + free(windows); + } +#else + XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], + icws.windows, numWindows); +#endif + + xnestOldInstalledColormapWindows = icws.windows; + xnestNumOldInstalledColormapWindows = icws.numWindows; + +#ifdef DUMB_WINDOW_MANAGERS + /* + This code is for dumb window managers. + This will only work with default local visual colormaps. + */ + if (icws.numWindows) + { + WindowPtr pWin; + Visual *visual; + ColormapPtr pCmap; + + pWin = xnestWindowPtr(icws.windows[0]); + visual = xnestVisualFromID(pScreen, wVisual(pWin)); + + if (visual == xnestDefaultVisual(pScreen)) + dixLookupResourceByType((pointer *)&pCmap, wColormap(pWin), + RT_COLORMAP, serverClient, DixUseAccess); + else + dixLookupResourceByType((pointer *)&pCmap, pScreen->defColormap, + RT_COLORMAP, serverClient, DixUseAccess); + + XSetWindowColormap(xnestDisplay, + xnestDefaultWindows[pScreen->myNum], + xnestColormap(pCmap)); + } +#endif /* DUMB_WINDOW_MANAGERS */ + } + else + if (icws.windows) free(icws.windows); +} + +void +xnestSetScreenSaverColormapWindow(ScreenPtr pScreen) +{ + if (xnestOldInstalledColormapWindows) + free(xnestOldInstalledColormapWindows); + +#ifdef _XSERVER64 + { + Window64 window; + + window = xnestScreenSaverWindows[pScreen->myNum]; + XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], + &window, 1); + xnestScreenSaverWindows[pScreen->myNum] = window; + } +#else + XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], + &xnestScreenSaverWindows[pScreen->myNum], 1); +#endif /* _XSERVER64 */ + + xnestOldInstalledColormapWindows = NULL; + xnestNumOldInstalledColormapWindows = 0; + + xnestDirectUninstallColormaps(pScreen); +} + +void +xnestDirectInstallColormaps(ScreenPtr pScreen) +{ + int i, n; + Colormap pCmapIDs[MAXCMAPS]; + + if (!xnestDoDirectColormaps) return; + + n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs); + + for (i = 0; i < n; i++) { + ColormapPtr pCmap; + + dixLookupResourceByType((pointer *)&pCmap, pCmapIDs[i], RT_COLORMAP, + serverClient, DixInstallAccess); + if (pCmap) + XInstallColormap(xnestDisplay, xnestColormap(pCmap)); + } +} + +void +xnestDirectUninstallColormaps(ScreenPtr pScreen) +{ + int i, n; + Colormap pCmapIDs[MAXCMAPS]; + + if (!xnestDoDirectColormaps) return; + + n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs); + + for (i = 0; i < n; i++) { + ColormapPtr pCmap; + + dixLookupResourceByType((pointer *)&pCmap, pCmapIDs[i], RT_COLORMAP, + serverClient, DixUninstallAccess); + if (pCmap) + XUninstallColormap(xnestDisplay, xnestColormap(pCmap)); + } +} + +void +xnestInstallColormap(ColormapPtr pCmap) +{ + ColormapPtr pOldCmap = GetInstalledColormap(pCmap->pScreen); + + if(pCmap != pOldCmap) + { + xnestDirectUninstallColormaps(pCmap->pScreen); + + /* Uninstall pInstalledMap. Notify all interested parties. */ + if(pOldCmap != (ColormapPtr)None) + WalkTree(pCmap->pScreen, TellLostMap, (pointer)&pOldCmap->mid); + + SetInstalledColormap(pCmap->pScreen, pCmap); + WalkTree(pCmap->pScreen, TellGainedMap, (pointer)&pCmap->mid); + + xnestSetInstalledColormapWindows(pCmap->pScreen); + xnestDirectInstallColormaps(pCmap->pScreen); + } +} + +void +xnestUninstallColormap(ColormapPtr pCmap) +{ + ColormapPtr pCurCmap = GetInstalledColormap(pCmap->pScreen); + + if(pCmap == pCurCmap) + { + if (pCmap->mid != pCmap->pScreen->defColormap) + { + dixLookupResourceByType((pointer *)&pCurCmap, + pCmap->pScreen->defColormap, + RT_COLORMAP, + serverClient, DixInstallAccess); + (*pCmap->pScreen->InstallColormap)(pCurCmap); + } + } +} + +static Bool xnestInstalledDefaultColormap = False; + +int +xnestListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapIDs) +{ + if (xnestInstalledDefaultColormap) { + *pCmapIDs = GetInstalledColormap(pScreen)->mid; + return 1; + } + else + return 0; +} + +void +xnestStoreColors(ColormapPtr pCmap, int nColors, xColorItem *pColors) +{ + if (pCmap->pVisual->class & DynamicClass) +#ifdef _XSERVER64 + { + int i; + XColor *pColors64 = (XColor *)malloc(nColors * sizeof(XColor) ); + + for(i = 0; i < nColors; ++i) + { + pColors64[i].pixel = pColors[i].pixel; + pColors64[i].red = pColors[i].red; + pColors64[i].green = pColors[i].green; + pColors64[i].blue = pColors[i].blue; + pColors64[i].flags = pColors[i].flags; + } + XStoreColors(xnestDisplay, xnestColormap(pCmap), pColors64, nColors); + free(pColors64); + } +#else + XStoreColors(xnestDisplay, xnestColormap(pCmap), + (XColor *)pColors, nColors); +#endif +} + +void +xnestResolveColor(unsigned short *pRed, unsigned short *pGreen, + unsigned short *pBlue, VisualPtr pVisual) +{ + int shift; + unsigned int lim; + + shift = 16 - pVisual->bitsPerRGBValue; + lim = (1 << pVisual->bitsPerRGBValue) - 1; + + if ((pVisual->class == PseudoColor) || (pVisual->class == DirectColor)) + { + /* rescale to rgb bits */ + *pRed = ((*pRed >> shift) * 65535) / lim; + *pGreen = ((*pGreen >> shift) * 65535) / lim; + *pBlue = ((*pBlue >> shift) * 65535) / lim; + } + else if (pVisual->class == GrayScale) + { + /* rescale to gray then rgb bits */ + *pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100; + *pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim; + } + else if (pVisual->class == StaticGray) + { + unsigned int limg; + + limg = pVisual->ColormapEntries - 1; + /* rescale to gray then [0..limg] then [0..65535] then rgb bits */ + *pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100; + *pRed = ((((*pRed * (limg + 1))) >> 16) * 65535) / limg; + *pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim; + } + else + { + unsigned limr, limg, limb; + + limr = pVisual->redMask >> pVisual->offsetRed; + limg = pVisual->greenMask >> pVisual->offsetGreen; + limb = pVisual->blueMask >> pVisual->offsetBlue; + /* rescale to [0..limN] then [0..65535] then rgb bits */ + *pRed = ((((((*pRed * (limr + 1)) >> 16) * + 65535) / limr) >> shift) * 65535) / lim; + *pGreen = ((((((*pGreen * (limg + 1)) >> 16) * + 65535) / limg) >> shift) * 65535) / lim; + *pBlue = ((((((*pBlue * (limb + 1)) >> 16) * + 65535) / limb) >> shift) * 65535) / lim; + } +} + +Bool +xnestCreateDefaultColormap(ScreenPtr pScreen) +{ + VisualPtr pVisual; + ColormapPtr pCmap; + unsigned short zero = 0, ones = 0xFFFF; + Pixel wp, bp; + + for (pVisual = pScreen->visuals; + pVisual->vid != pScreen->rootVisual; + pVisual++); + + if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &pCmap, + (pVisual->class & DynamicClass) ? AllocNone : AllocAll, 0) + != Success) + return False; + + wp = pScreen->whitePixel; + bp = pScreen->blackPixel; + if ((AllocColor(pCmap, &ones, &ones, &ones, &wp, 0) != + Success) || + (AllocColor(pCmap, &zero, &zero, &zero, &bp, 0) != + Success)) + return FALSE; + pScreen->whitePixel = wp; + pScreen->blackPixel = bp; + (*pScreen->InstallColormap)(pCmap); + + xnestInstalledDefaultColormap = True; + + return True; +} diff --git a/xorg-server/hw/xnest/Cursor.c b/xorg-server/hw/xnest/Cursor.c index 12f47e725..290074d4e 100644 --- a/xorg-server/hw/xnest/Cursor.c +++ b/xorg-server/hw/xnest/Cursor.c @@ -1,183 +1,183 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - -#ifdef HAVE_XNEST_CONFIG_H -#include -#endif - -#include -#include -#include "screenint.h" -#include "input.h" -#include "misc.h" -#include "cursor.h" -#include "cursorstr.h" -#include "scrnintstr.h" -#include "servermd.h" -#include "mipointrst.h" - -#include "Xnest.h" - -#include "Display.h" -#include "Screen.h" -#include "XNCursor.h" -#include "Visual.h" -#include "Keyboard.h" -#include "Args.h" - -xnestCursorFuncRec xnestCursorFuncs = {NULL}; - -Bool -xnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) -{ - XImage *ximage; - Pixmap source, mask; - XColor fg_color, bg_color; - unsigned long valuemask; - XGCValues values; - - valuemask = GCFunction | - GCPlaneMask | - GCForeground | - GCBackground | - GCClipMask; - - values.function = GXcopy; - values.plane_mask = AllPlanes; - values.foreground = 1L; - values.background = 0L; - values.clip_mask = None; - - XChangeGC(xnestDisplay, xnestBitmapGC, valuemask, &values); - - source = XCreatePixmap(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], - pCursor->bits->width, - pCursor->bits->height, - 1); - - mask = XCreatePixmap(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], - pCursor->bits->width, - pCursor->bits->height, - 1); - - ximage = XCreateImage(xnestDisplay, - xnestDefaultVisual(pScreen), - 1, XYBitmap, 0, - (char *)pCursor->bits->source, - pCursor->bits->width, - pCursor->bits->height, - BitmapPad(xnestDisplay), 0); - - XPutImage(xnestDisplay, source, xnestBitmapGC, ximage, - 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height); - - XFree(ximage); - - ximage = XCreateImage(xnestDisplay, - xnestDefaultVisual(pScreen), - 1, XYBitmap, 0, - (char *)pCursor->bits->mask, - pCursor->bits->width, - pCursor->bits->height, - BitmapPad(xnestDisplay), 0); - - XPutImage(xnestDisplay, mask, xnestBitmapGC, ximage, - 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height); - - XFree(ximage); - - fg_color.red = pCursor->foreRed; - fg_color.green = pCursor->foreGreen; - fg_color.blue = pCursor->foreBlue; - - bg_color.red = pCursor->backRed; - bg_color.green = pCursor->backGreen; - bg_color.blue = pCursor->backBlue; - - xnestSetCursorPriv(pCursor, pScreen, xalloc(sizeof(xnestPrivCursor))); - xnestCursor(pCursor, pScreen) = - XCreatePixmapCursor(xnestDisplay, source, mask, &fg_color, &bg_color, - pCursor->bits->xhot, pCursor->bits->yhot); - - XFreePixmap(xnestDisplay, source); - XFreePixmap(xnestDisplay, mask); - - return True; -} - -Bool -xnestUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) -{ - XFreeCursor(xnestDisplay, xnestCursor(pCursor, pScreen)); - xfree(xnestGetCursorPriv(pCursor, pScreen)); - return True; -} - -void -xnestRecolorCursor(ScreenPtr pScreen, CursorPtr pCursor, Bool displayed) -{ - XColor fg_color, bg_color; - - fg_color.red = pCursor->foreRed; - fg_color.green = pCursor->foreGreen; - fg_color.blue = pCursor->foreBlue; - - bg_color.red = pCursor->backRed; - bg_color.green = pCursor->backGreen; - bg_color.blue = pCursor->backBlue; - - XRecolorCursor(xnestDisplay, - xnestCursor(pCursor, pScreen), - &fg_color, &bg_color); -} - -void xnestSetCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, int y) -{ - if (pCursor) - { - XDefineCursor(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], - xnestCursor(pCursor, pScreen)); - } -} - -void -xnestMoveCursor (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) -{ -} - -Bool -xnestDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen) -{ - xnestCursorFuncPtr pScreenPriv; - - pScreenPriv = (xnestCursorFuncPtr) - dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey); - - pScreenPriv->spriteFuncs->DeviceCursorInitialize(pDev, pScreen); - return TRUE; -} - -void -xnestDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen) -{ - xnestCursorFuncPtr pScreenPriv; - - pScreenPriv = (xnestCursorFuncPtr) - dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey); - - pScreenPriv->spriteFuncs->DeviceCursorCleanup(pDev, pScreen); -} +/* + +Copyright 1993 by Davor Matic + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. Davor Matic makes no representations about +the suitability of this software for any purpose. It is provided "as +is" without express or implied warranty. + +*/ + +#ifdef HAVE_XNEST_CONFIG_H +#include +#endif + +#include +#include +#include "screenint.h" +#include "input.h" +#include "misc.h" +#include "cursor.h" +#include "cursorstr.h" +#include "scrnintstr.h" +#include "servermd.h" +#include "mipointrst.h" + +#include "Xnest.h" + +#include "Display.h" +#include "Screen.h" +#include "XNCursor.h" +#include "Visual.h" +#include "Keyboard.h" +#include "Args.h" + +xnestCursorFuncRec xnestCursorFuncs = {NULL}; + +Bool +xnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) +{ + XImage *ximage; + Pixmap source, mask; + XColor fg_color, bg_color; + unsigned long valuemask; + XGCValues values; + + valuemask = GCFunction | + GCPlaneMask | + GCForeground | + GCBackground | + GCClipMask; + + values.function = GXcopy; + values.plane_mask = AllPlanes; + values.foreground = 1L; + values.background = 0L; + values.clip_mask = None; + + XChangeGC(xnestDisplay, xnestBitmapGC, valuemask, &values); + + source = XCreatePixmap(xnestDisplay, + xnestDefaultWindows[pScreen->myNum], + pCursor->bits->width, + pCursor->bits->height, + 1); + + mask = XCreatePixmap(xnestDisplay, + xnestDefaultWindows[pScreen->myNum], + pCursor->bits->width, + pCursor->bits->height, + 1); + + ximage = XCreateImage(xnestDisplay, + xnestDefaultVisual(pScreen), + 1, XYBitmap, 0, + (char *)pCursor->bits->source, + pCursor->bits->width, + pCursor->bits->height, + BitmapPad(xnestDisplay), 0); + + XPutImage(xnestDisplay, source, xnestBitmapGC, ximage, + 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height); + + XFree(ximage); + + ximage = XCreateImage(xnestDisplay, + xnestDefaultVisual(pScreen), + 1, XYBitmap, 0, + (char *)pCursor->bits->mask, + pCursor->bits->width, + pCursor->bits->height, + BitmapPad(xnestDisplay), 0); + + XPutImage(xnestDisplay, mask, xnestBitmapGC, ximage, + 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height); + + XFree(ximage); + + fg_color.red = pCursor->foreRed; + fg_color.green = pCursor->foreGreen; + fg_color.blue = pCursor->foreBlue; + + bg_color.red = pCursor->backRed; + bg_color.green = pCursor->backGreen; + bg_color.blue = pCursor->backBlue; + + xnestSetCursorPriv(pCursor, pScreen, malloc(sizeof(xnestPrivCursor))); + xnestCursor(pCursor, pScreen) = + XCreatePixmapCursor(xnestDisplay, source, mask, &fg_color, &bg_color, + pCursor->bits->xhot, pCursor->bits->yhot); + + XFreePixmap(xnestDisplay, source); + XFreePixmap(xnestDisplay, mask); + + return True; +} + +Bool +xnestUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) +{ + XFreeCursor(xnestDisplay, xnestCursor(pCursor, pScreen)); + free(xnestGetCursorPriv(pCursor, pScreen)); + return True; +} + +void +xnestRecolorCursor(ScreenPtr pScreen, CursorPtr pCursor, Bool displayed) +{ + XColor fg_color, bg_color; + + fg_color.red = pCursor->foreRed; + fg_color.green = pCursor->foreGreen; + fg_color.blue = pCursor->foreBlue; + + bg_color.red = pCursor->backRed; + bg_color.green = pCursor->backGreen; + bg_color.blue = pCursor->backBlue; + + XRecolorCursor(xnestDisplay, + xnestCursor(pCursor, pScreen), + &fg_color, &bg_color); +} + +void xnestSetCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, int y) +{ + if (pCursor) + { + XDefineCursor(xnestDisplay, + xnestDefaultWindows[pScreen->myNum], + xnestCursor(pCursor, pScreen)); + } +} + +void +xnestMoveCursor (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) +{ +} + +Bool +xnestDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen) +{ + xnestCursorFuncPtr pScreenPriv; + + pScreenPriv = (xnestCursorFuncPtr) + dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey); + + pScreenPriv->spriteFuncs->DeviceCursorInitialize(pDev, pScreen); + return TRUE; +} + +void +xnestDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen) +{ + xnestCursorFuncPtr pScreenPriv; + + pScreenPriv = (xnestCursorFuncPtr) + dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey); + + pScreenPriv->spriteFuncs->DeviceCursorCleanup(pDev, pScreen); +} diff --git a/xorg-server/hw/xnest/Display.c b/xorg-server/hw/xnest/Display.c index 01290417c..72c640186 100644 --- a/xorg-server/hw/xnest/Display.c +++ b/xorg-server/hw/xnest/Display.c @@ -1,193 +1,193 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - - -#ifdef HAVE_XNEST_CONFIG_H -#include -#endif - -#include -#include -#include "screenint.h" -#include "input.h" -#include "misc.h" -#include "scrnintstr.h" -#include "servermd.h" - -#include "Xnest.h" - -#include "Display.h" -#include "Init.h" -#include "Args.h" - -#include "icon" -#include "screensaver" - -Display *xnestDisplay = NULL; -XVisualInfo *xnestVisuals; -int xnestNumVisuals; -int xnestDefaultVisualIndex; -Colormap *xnestDefaultColormaps; -static int xnestNumDefaultColormaps; -int *xnestDepths; -int xnestNumDepths; -XPixmapFormatValues *xnestPixmapFormats; -int xnestNumPixmapFormats; -Pixel xnestBlackPixel; -Pixel xnestWhitePixel; -Drawable xnestDefaultDrawables[MAXDEPTH + 1]; -Pixmap xnestIconBitmap; -Pixmap xnestScreenSaverPixmap; -XlibGC xnestBitmapGC; -unsigned long xnestEventMask; - -void -xnestOpenDisplay(int argc, char *argv[]) -{ - XVisualInfo vi; - long mask; - int i, j; - - if (!xnestDoFullGeneration) return; - - xnestCloseDisplay(); - - xnestDisplay = XOpenDisplay(xnestDisplayName); - if (xnestDisplay == NULL) - FatalError("Unable to open display \"%s\".\n", - XDisplayName(xnestDisplayName)); - - if (xnestSynchronize) - XSynchronize(xnestDisplay, True); - - mask = VisualScreenMask; - vi.screen = DefaultScreen(xnestDisplay); - xnestVisuals = XGetVisualInfo(xnestDisplay, mask, &vi, &xnestNumVisuals); - if (xnestNumVisuals == 0 || xnestVisuals == NULL) - FatalError("Unable to find any visuals.\n"); - - if (xnestUserDefaultClass || xnestUserDefaultDepth) { - xnestDefaultVisualIndex = UNDEFINED; - for (i = 0; i < xnestNumVisuals; i++) - if ((!xnestUserDefaultClass || - xnestVisuals[i].class == xnestDefaultClass) - && - (!xnestUserDefaultDepth || - xnestVisuals[i].depth == xnestDefaultDepth)) { - xnestDefaultVisualIndex = i; - break; - } - if (xnestDefaultVisualIndex == UNDEFINED) - FatalError("Unable to find desired default visual.\n"); - } - else { - vi.visualid = XVisualIDFromVisual(DefaultVisual(xnestDisplay, - DefaultScreen(xnestDisplay))); - xnestDefaultVisualIndex = 0; - for (i = 0; i < xnestNumVisuals; i++) - if (vi.visualid == xnestVisuals[i].visualid) - xnestDefaultVisualIndex = i; - } - - xnestNumDefaultColormaps = xnestNumVisuals; - xnestDefaultColormaps = (Colormap *)xalloc(xnestNumDefaultColormaps * - sizeof(Colormap)); - for (i = 0; i < xnestNumDefaultColormaps; i++) - xnestDefaultColormaps[i] = XCreateColormap(xnestDisplay, - DefaultRootWindow(xnestDisplay), - xnestVisuals[i].visual, - AllocNone); - - xnestDepths = XListDepths(xnestDisplay, DefaultScreen(xnestDisplay), - &xnestNumDepths); - - xnestPixmapFormats = XListPixmapFormats(xnestDisplay, - &xnestNumPixmapFormats); - - xnestBlackPixel = BlackPixel(xnestDisplay, DefaultScreen(xnestDisplay)); - xnestWhitePixel = WhitePixel(xnestDisplay, DefaultScreen(xnestDisplay)); - - if (xnestParentWindow != (Window) 0) - xnestEventMask = StructureNotifyMask; - else - xnestEventMask = 0L; - - for (i = 0; i <= MAXDEPTH; i++) - xnestDefaultDrawables[i] = None; - - for (i = 0; i < xnestNumPixmapFormats; i++) - for (j = 0; j < xnestNumDepths; j++) - if (xnestPixmapFormats[i].depth == 1 || - xnestPixmapFormats[i].depth == xnestDepths[j]) { - xnestDefaultDrawables[xnestPixmapFormats[i].depth] = - XCreatePixmap(xnestDisplay, DefaultRootWindow(xnestDisplay), - 1, 1, xnestPixmapFormats[i].depth); - } - - xnestBitmapGC = XCreateGC(xnestDisplay, xnestDefaultDrawables[1], 0L, NULL); - - if (!(xnestUserGeometry & XValue)) - xnestX = 0; - - if (!(xnestUserGeometry & YValue)) - xnestY = 0; - - if (xnestParentWindow == 0) { - if (!(xnestUserGeometry & WidthValue)) - xnestWidth = 3 * DisplayWidth(xnestDisplay, - DefaultScreen(xnestDisplay)) / 4; - - if (!(xnestUserGeometry & HeightValue)) - xnestHeight = 3 * DisplayHeight(xnestDisplay, - DefaultScreen(xnestDisplay)) / 4; - } - - if (!xnestUserBorderWidth) - xnestBorderWidth = 1; - - xnestIconBitmap = - XCreateBitmapFromData(xnestDisplay, - DefaultRootWindow(xnestDisplay), - (char *)icon_bits, - icon_width, - icon_height); - - xnestScreenSaverPixmap = - XCreatePixmapFromBitmapData(xnestDisplay, - DefaultRootWindow(xnestDisplay), - (char *)screensaver_bits, - screensaver_width, - screensaver_height, - xnestWhitePixel, - xnestBlackPixel, - DefaultDepth(xnestDisplay, - DefaultScreen(xnestDisplay))); -} - -void -xnestCloseDisplay(void) -{ - if (!xnestDoFullGeneration || !xnestDisplay) return; - - /* - If xnestDoFullGeneration all x resources will be destroyed upon closing - the display connection. There is no need to generate extra protocol. - */ - - xfree(xnestDefaultColormaps); - XFree(xnestVisuals); - XFree(xnestDepths); - XFree(xnestPixmapFormats); - XCloseDisplay(xnestDisplay); -} +/* + +Copyright 1993 by Davor Matic + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. Davor Matic makes no representations about +the suitability of this software for any purpose. It is provided "as +is" without express or implied warranty. + +*/ + + +#ifdef HAVE_XNEST_CONFIG_H +#include +#endif + +#include +#include +#include "screenint.h" +#include "input.h" +#include "misc.h" +#include "scrnintstr.h" +#include "servermd.h" + +#include "Xnest.h" + +#include "Display.h" +#include "Init.h" +#include "Args.h" + +#include "icon" +#include "screensaver" + +Display *xnestDisplay = NULL; +XVisualInfo *xnestVisuals; +int xnestNumVisuals; +int xnestDefaultVisualIndex; +Colormap *xnestDefaultColormaps; +static int xnestNumDefaultColormaps; +int *xnestDepths; +int xnestNumDepths; +XPixmapFormatValues *xnestPixmapFormats; +int xnestNumPixmapFormats; +Pixel xnestBlackPixel; +Pixel xnestWhitePixel; +Drawable xnestDefaultDrawables[MAXDEPTH + 1]; +Pixmap xnestIconBitmap; +Pixmap xnestScreenSaverPixmap; +XlibGC xnestBitmapGC; +unsigned long xnestEventMask; + +void +xnestOpenDisplay(int argc, char *argv[]) +{ + XVisualInfo vi; + long mask; + int i, j; + + if (!xnestDoFullGeneration) return; + + xnestCloseDisplay(); + + xnestDisplay = XOpenDisplay(xnestDisplayName); + if (xnestDisplay == NULL) + FatalError("Unable to open display \"%s\".\n", + XDisplayName(xnestDisplayName)); + + if (xnestSynchronize) + XSynchronize(xnestDisplay, True); + + mask = VisualScreenMask; + vi.screen = DefaultScreen(xnestDisplay); + xnestVisuals = XGetVisualInfo(xnestDisplay, mask, &vi, &xnestNumVisuals); + if (xnestNumVisuals == 0 || xnestVisuals == NULL) + FatalError("Unable to find any visuals.\n"); + + if (xnestUserDefaultClass || xnestUserDefaultDepth) { + xnestDefaultVisualIndex = UNDEFINED; + for (i = 0; i < xnestNumVisuals; i++) + if ((!xnestUserDefaultClass || + xnestVisuals[i].class == xnestDefaultClass) + && + (!xnestUserDefaultDepth || + xnestVisuals[i].depth == xnestDefaultDepth)) { + xnestDefaultVisualIndex = i; + break; + } + if (xnestDefaultVisualIndex == UNDEFINED) + FatalError("Unable to find desired default visual.\n"); + } + else { + vi.visualid = XVisualIDFromVisual(DefaultVisual(xnestDisplay, + DefaultScreen(xnestDisplay))); + xnestDefaultVisualIndex = 0; + for (i = 0; i < xnestNumVisuals; i++) + if (vi.visualid == xnestVisuals[i].visualid) + xnestDefaultVisualIndex = i; + } + + xnestNumDefaultColormaps = xnestNumVisuals; + xnestDefaultColormaps = (Colormap *)malloc(xnestNumDefaultColormaps * + sizeof(Colormap)); + for (i = 0; i < xnestNumDefaultColormaps; i++) + xnestDefaultColormaps[i] = XCreateColormap(xnestDisplay, + DefaultRootWindow(xnestDisplay), + xnestVisuals[i].visual, + AllocNone); + + xnestDepths = XListDepths(xnestDisplay, DefaultScreen(xnestDisplay), + &xnestNumDepths); + + xnestPixmapFormats = XListPixmapFormats(xnestDisplay, + &xnestNumPixmapFormats); + + xnestBlackPixel = BlackPixel(xnestDisplay, DefaultScreen(xnestDisplay)); + xnestWhitePixel = WhitePixel(xnestDisplay, DefaultScreen(xnestDisplay)); + + if (xnestParentWindow != (Window) 0) + xnestEventMask = StructureNotifyMask; + else + xnestEventMask = 0L; + + for (i = 0; i <= MAXDEPTH; i++) + xnestDefaultDrawables[i] = None; + + for (i = 0; i < xnestNumPixmapFormats; i++) + for (j = 0; j < xnestNumDepths; j++) + if (xnestPixmapFormats[i].depth == 1 || + xnestPixmapFormats[i].depth == xnestDepths[j]) { + xnestDefaultDrawables[xnestPixmapFormats[i].depth] = + XCreatePixmap(xnestDisplay, DefaultRootWindow(xnestDisplay), + 1, 1, xnestPixmapFormats[i].depth); + } + + xnestBitmapGC = XCreateGC(xnestDisplay, xnestDefaultDrawables[1], 0L, NULL); + + if (!(xnestUserGeometry & XValue)) + xnestX = 0; + + if (!(xnestUserGeometry & YValue)) + xnestY = 0; + + if (xnestParentWindow == 0) { + if (!(xnestUserGeometry & WidthValue)) + xnestWidth = 3 * DisplayWidth(xnestDisplay, + DefaultScreen(xnestDisplay)) / 4; + + if (!(xnestUserGeometry & HeightValue)) + xnestHeight = 3 * DisplayHeight(xnestDisplay, + DefaultScreen(xnestDisplay)) / 4; + } + + if (!xnestUserBorderWidth) + xnestBorderWidth = 1; + + xnestIconBitmap = + XCreateBitmapFromData(xnestDisplay, + DefaultRootWindow(xnestDisplay), + (char *)icon_bits, + icon_width, + icon_height); + + xnestScreenSaverPixmap = + XCreatePixmapFromBitmapData(xnestDisplay, + DefaultRootWindow(xnestDisplay), + (char *)screensaver_bits, + screensaver_width, + screensaver_height, + xnestWhitePixel, + xnestBlackPixel, + DefaultDepth(xnestDisplay, + DefaultScreen(xnestDisplay))); +} + +void +xnestCloseDisplay(void) +{ + if (!xnestDoFullGeneration || !xnestDisplay) return; + + /* + If xnestDoFullGeneration all x resources will be destroyed upon closing + the display connection. There is no need to generate extra protocol. + */ + + free(xnestDefaultColormaps); + XFree(xnestVisuals); + XFree(xnestDepths); + XFree(xnestPixmapFormats); + XCloseDisplay(xnestDisplay); +} diff --git a/xorg-server/hw/xnest/Font.c b/xorg-server/hw/xnest/Font.c index 7b388f0f4..87e622680 100644 --- a/xorg-server/hw/xnest/Font.c +++ b/xorg-server/hw/xnest/Font.c @@ -1,86 +1,86 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - -#ifdef HAVE_XNEST_CONFIG_H -#include -#endif - -#include -#include -#include -#include "misc.h" -#include "regionstr.h" -#include -#include -#include "scrnintstr.h" - -#include "Xnest.h" - -#include "Display.h" -#include "XNFont.h" - -int xnestFontPrivateIndex; - -Bool -xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont) -{ - pointer priv; - Atom name_atom, value_atom; - int nprops; - FontPropPtr props; - int i; - const char *name; - - FontSetPrivate(pFont, xnestFontPrivateIndex, NULL); - - name_atom = MakeAtom("FONT", 4, True); - value_atom = 0L; - - nprops = pFont->info.nprops; - props = pFont->info.props; - - for (i = 0; i < nprops; i++) - if (props[i].name == name_atom) { - value_atom = props[i].value; - break; - } - - if (!value_atom) return False; - - name = NameForAtom(value_atom); - - if (!name) return False; - - priv = (pointer)xalloc(sizeof(xnestPrivFont)); - FontSetPrivate(pFont, xnestFontPrivateIndex, priv); - - xnestFontPriv(pFont)->font_struct = XLoadQueryFont(xnestDisplay, name); - - if (!xnestFontStruct(pFont)) return False; - - return True; -} - - -Bool -xnestUnrealizeFont(ScreenPtr pScreen, FontPtr pFont) -{ - if (xnestFontPriv(pFont)) { - if (xnestFontStruct(pFont)) - XFreeFont(xnestDisplay, xnestFontStruct(pFont)); - xfree(xnestFontPriv(pFont)); - FontSetPrivate(pFont, xnestFontPrivateIndex, NULL); - } - return True; -} +/* + +Copyright 1993 by Davor Matic + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. Davor Matic makes no representations about +the suitability of this software for any purpose. It is provided "as +is" without express or implied warranty. + +*/ + +#ifdef HAVE_XNEST_CONFIG_H +#include +#endif + +#include +#include +#include +#include "misc.h" +#include "regionstr.h" +#include +#include +#include "scrnintstr.h" + +#include "Xnest.h" + +#include "Display.h" +#include "XNFont.h" + +int xnestFontPrivateIndex; + +Bool +xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont) +{ + pointer priv; + Atom name_atom, value_atom; + int nprops; + FontPropPtr props; + int i; + const char *name; + + FontSetPrivate(pFont, xnestFontPrivateIndex, NULL); + + name_atom = MakeAtom("FONT", 4, True); + value_atom = 0L; + + nprops = pFont->info.nprops; + props = pFont->info.props; + + for (i = 0; i < nprops; i++) + if (props[i].name == name_atom) { + value_atom = props[i].value; + break; + } + + if (!value_atom) return False; + + name = NameForAtom(value_atom); + + if (!name) return False; + + priv = (pointer)malloc(sizeof(xnestPrivFont)); + FontSetPrivate(pFont, xnestFontPrivateIndex, priv); + + xnestFontPriv(pFont)->font_struct = XLoadQueryFont(xnestDisplay, name); + + if (!xnestFontStruct(pFont)) return False; + + return True; +} + + +Bool +xnestUnrealizeFont(ScreenPtr pScreen, FontPtr pFont) +{ + if (xnestFontPriv(pFont)) { + if (xnestFontStruct(pFont)) + XFreeFont(xnestDisplay, xnestFontStruct(pFont)); + free(xnestFontPriv(pFont)); + FontSetPrivate(pFont, xnestFontPrivateIndex, NULL); + } + return True; +} diff --git a/xorg-server/hw/xnest/GC.c b/xorg-server/hw/xnest/GC.c index 65425e98f..9df015728 100644 --- a/xorg-server/hw/xnest/GC.c +++ b/xorg-server/hw/xnest/GC.c @@ -1,339 +1,339 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - -#ifdef HAVE_XNEST_CONFIG_H -#include -#endif - -#include -#include -#include "gcstruct.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "scrnintstr.h" -#include -#include "mistruct.h" -#include "region.h" - -#include "Xnest.h" - -#include "Display.h" -#include "XNGC.h" -#include "GCOps.h" -#include "Drawable.h" -#include "XNFont.h" -#include "Color.h" - -static int xnestGCPrivateKeyIndex; -DevPrivateKey xnestGCPrivateKey = &xnestGCPrivateKeyIndex; - -static GCFuncs xnestFuncs = { - xnestValidateGC, - xnestChangeGC, - xnestCopyGC, - xnestDestroyGC, - xnestChangeClip, - xnestDestroyClip, - xnestCopyClip, -}; - -static GCOps xnestOps = { - xnestFillSpans, - xnestSetSpans, - xnestPutImage, - xnestCopyArea, - xnestCopyPlane, - xnestPolyPoint, - xnestPolylines, - xnestPolySegment, - xnestPolyRectangle, - xnestPolyArc, - xnestFillPolygon, - xnestPolyFillRect, - xnestPolyFillArc, - xnestPolyText8, - xnestPolyText16, - xnestImageText8, - xnestImageText16, - xnestImageGlyphBlt, - xnestPolyGlyphBlt, - xnestPushPixels -}; - -Bool -xnestCreateGC(GCPtr pGC) -{ - pGC->clientClipType = CT_NONE; - pGC->clientClip = NULL; - - pGC->funcs = &xnestFuncs; - pGC->ops = &xnestOps; - - pGC->miTranslate = 1; - - xnestGCPriv(pGC)->gc = XCreateGC(xnestDisplay, - xnestDefaultDrawables[pGC->depth], - 0L, NULL); - xnestGCPriv(pGC)->nClipRects = 0; - - return True; -} - -void -xnestValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable) -{ - pGC->lastWinOrg.x = pDrawable->x; - pGC->lastWinOrg.y = pDrawable->y; -} - -void -xnestChangeGC(GCPtr pGC, unsigned long mask) -{ - XGCValues values; - - if (mask & GCFunction) - values.function = pGC->alu; - - if (mask & GCPlaneMask) - values.plane_mask = pGC->planemask; - - if (mask & GCForeground) - values.foreground = xnestPixel(pGC->fgPixel); - - if (mask & GCBackground) - values.background = xnestPixel(pGC->bgPixel); - - if (mask & GCLineWidth) - values.line_width = pGC->lineWidth; - - if (mask & GCLineStyle) - values.line_style = pGC->lineStyle; - - if (mask & GCCapStyle) - values.cap_style = pGC->capStyle; - - if (mask & GCJoinStyle) - values.join_style = pGC->joinStyle; - - if (mask & GCFillStyle) - values.fill_style = pGC->fillStyle; - - if (mask & GCFillRule) - values.fill_rule = pGC->fillRule; - - if (mask & GCTile) { - if (pGC->tileIsPixel) - mask &= ~GCTile; - else - values.tile = xnestPixmap(pGC->tile.pixmap); - } - - if (mask & GCStipple) - values.stipple = xnestPixmap(pGC->stipple); - - if (mask & GCTileStipXOrigin) - values.ts_x_origin = pGC->patOrg.x; - - if (mask & GCTileStipYOrigin) - values.ts_y_origin = pGC->patOrg.y; - - if (mask & GCFont) - values.font = xnestFont(pGC->font); - - if (mask & GCSubwindowMode) - values.subwindow_mode = pGC->subWindowMode; - - if (mask & GCGraphicsExposures) - values.graphics_exposures = pGC->graphicsExposures; - - if (mask & GCClipXOrigin) - values.clip_x_origin = pGC->clipOrg.x; - - if (mask & GCClipYOrigin) - values.clip_y_origin = pGC->clipOrg.y; - - if (mask & GCClipMask) /* this is handled in change clip */ - mask &= ~GCClipMask; - - if (mask & GCDashOffset) - values.dash_offset = pGC->dashOffset; - - if (mask & GCDashList) { - mask &= ~GCDashList; - XSetDashes(xnestDisplay, xnestGC(pGC), - pGC->dashOffset, (char *)pGC->dash, pGC->numInDashList); - } - - if (mask & GCArcMode) - values.arc_mode = pGC->arcMode; - - if (mask) - XChangeGC(xnestDisplay, xnestGC(pGC), mask, &values); -} - -void -xnestCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst) -{ - XCopyGC(xnestDisplay, xnestGC(pGCSrc), mask, xnestGC(pGCDst)); -} - -void -xnestDestroyGC(GCPtr pGC) -{ - XFreeGC(xnestDisplay, xnestGC(pGC)); -} - -void -xnestChangeClip(GCPtr pGC, int type, pointer pValue, int nRects) -{ - int i, size; - BoxPtr pBox; - XRectangle *pRects; - - xnestDestroyClipHelper(pGC); - - switch(type) - { - case CT_NONE: - XSetClipMask(xnestDisplay, xnestGC(pGC), None); - break; - - case CT_REGION: - nRects = REGION_NUM_RECTS((RegionPtr)pValue); - size = nRects * sizeof(*pRects); - pRects = (XRectangle *) xalloc(size); - pBox = REGION_RECTS((RegionPtr)pValue); - for (i = nRects; i-- > 0; ) { - pRects[i].x = pBox[i].x1; - pRects[i].y = pBox[i].y1; - pRects[i].width = pBox[i].x2 - pBox[i].x1; - pRects[i].height = pBox[i].y2 - pBox[i].y1; - } - XSetClipRectangles(xnestDisplay, xnestGC(pGC), 0, 0, - pRects, nRects, Unsorted); - xfree((char *) pRects); - break; - - case CT_PIXMAP: - XSetClipMask(xnestDisplay, xnestGC(pGC), - xnestPixmap((PixmapPtr)pValue)); - /* - * Need to change into region, so subsequent uses are with - * current pixmap contents. - */ - pGC->clientClip = (pointer) (*pGC->pScreen->BitmapToRegion)((PixmapPtr)pValue); - (*pGC->pScreen->DestroyPixmap)((PixmapPtr)pValue); - pValue = pGC->clientClip; - type = CT_REGION; - break; - - case CT_UNSORTED: - XSetClipRectangles(xnestDisplay, xnestGC(pGC), - pGC->clipOrg.x, pGC->clipOrg.y, - (XRectangle *)pValue, nRects, Unsorted); - break; - - case CT_YSORTED: - XSetClipRectangles(xnestDisplay, xnestGC(pGC), - pGC->clipOrg.x, pGC->clipOrg.y, - (XRectangle *)pValue, nRects, YSorted); - break; - - case CT_YXSORTED: - XSetClipRectangles(xnestDisplay, xnestGC(pGC), - pGC->clipOrg.x, pGC->clipOrg.y, - (XRectangle *)pValue, nRects, YXSorted); - break; - - case CT_YXBANDED: - XSetClipRectangles(xnestDisplay, xnestGC(pGC), - pGC->clipOrg.x, pGC->clipOrg.y, - (XRectangle *)pValue, nRects, YXBanded); - break; - } - - switch(type) - { - default: - break; - - case CT_UNSORTED: - case CT_YSORTED: - case CT_YXSORTED: - case CT_YXBANDED: - - /* - * other parts of server can only deal with CT_NONE, - * CT_PIXMAP and CT_REGION client clips. - */ - pGC->clientClip = (pointer) RECTS_TO_REGION(pGC->pScreen, nRects, - (xRectangle *)pValue, type); - xfree(pValue); - pValue = pGC->clientClip; - type = CT_REGION; - - break; - } - - pGC->clientClipType = type; - pGC->clientClip = pValue; - xnestGCPriv(pGC)->nClipRects = nRects; -} - -void -xnestDestroyClip(GCPtr pGC) -{ - xnestDestroyClipHelper(pGC); - - XSetClipMask(xnestDisplay, xnestGC(pGC), None); - - pGC->clientClipType = CT_NONE; - pGC->clientClip = NULL; - xnestGCPriv(pGC)->nClipRects = 0; -} - -void -xnestDestroyClipHelper(GCPtr pGC) -{ - switch (pGC->clientClipType) - { - default: - case CT_NONE: - break; - - case CT_REGION: - REGION_DESTROY(pGC->pScreen, pGC->clientClip); - break; - } -} - -void -xnestCopyClip(GCPtr pGCDst, GCPtr pGCSrc) -{ - RegionPtr pRgn; - - switch (pGCSrc->clientClipType) - { - default: - case CT_NONE: - xnestDestroyClip(pGCDst); - break; - - case CT_REGION: - pRgn = REGION_CREATE(pGCDst->pScreen, NULL, 1); - REGION_COPY(pGCDst->pScreen, pRgn, pGCSrc->clientClip); - xnestChangeClip(pGCDst, CT_REGION, pRgn, 0); - break; - } -} +/* + +Copyright 1993 by Davor Matic + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. Davor Matic makes no representations about +the suitability of this software for any purpose. It is provided "as +is" without express or implied warranty. + +*/ + +#ifdef HAVE_XNEST_CONFIG_H +#include +#endif + +#include +#include +#include "gcstruct.h" +#include "windowstr.h" +#include "pixmapstr.h" +#include "scrnintstr.h" +#include +#include "mistruct.h" +#include "region.h" + +#include "Xnest.h" + +#include "Display.h" +#include "XNGC.h" +#include "GCOps.h" +#include "Drawable.h" +#include "XNFont.h" +#include "Color.h" + +static int xnestGCPrivateKeyIndex; +DevPrivateKey xnestGCPrivateKey = &xnestGCPrivateKeyIndex; + +static GCFuncs xnestFuncs = { + xnestValidateGC, + xnestChangeGC, + xnestCopyGC, + xnestDestroyGC, + xnestChangeClip, + xnestDestroyClip, + xnestCopyClip, +}; + +static GCOps xnestOps = { + xnestFillSpans, + xnestSetSpans, + xnestPutImage, + xnestCopyArea, + xnestCopyPlane, + xnestPolyPoint, + xnestPolylines, + xnestPolySegment, + xnestPolyRectangle, + xnestPolyArc, + xnestFillPolygon, + xnestPolyFillRect, + xnestPolyFillArc, + xnestPolyText8, + xnestPolyText16, + xnestImageText8, + xnestImageText16, + xnestImageGlyphBlt, + xnestPolyGlyphBlt, + xnestPushPixels +}; + +Bool +xnestCreateGC(GCPtr pGC) +{ + pGC->clientClipType = CT_NONE; + pGC->clientClip = NULL; + + pGC->funcs = &xnestFuncs; + pGC->ops = &xnestOps; + + pGC->miTranslate = 1; + + xnestGCPriv(pGC)->gc = XCreateGC(xnestDisplay, + xnestDefaultDrawables[pGC->depth], + 0L, NULL); + xnestGCPriv(pGC)->nClipRects = 0; + + return True; +} + +void +xnestValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable) +{ + pGC->lastWinOrg.x = pDrawable->x; + pGC->lastWinOrg.y = pDrawable->y; +} + +void +xnestChangeGC(GCPtr pGC, unsigned long mask) +{ + XGCValues values; + + if (mask & GCFunction) + values.function = pGC->alu; + + if (mask & GCPlaneMask) + values.plane_mask = pGC->planemask; + + if (mask & GCForeground) + values.foreground = xnestPixel(pGC->fgPixel); + + if (mask & GCBackground) + values.background = xnestPixel(pGC->bgPixel); + + if (mask & GCLineWidth) + values.line_width = pGC->lineWidth; + + if (mask & GCLineStyle) + values.line_style = pGC->lineStyle; + + if (mask & GCCapStyle) + values.cap_style = pGC->capStyle; + + if (mask & GCJoinStyle) + values.join_style = pGC->joinStyle; + + if (mask & GCFillStyle) + values.fill_style = pGC->fillStyle; + + if (mask & GCFillRule) + values.fill_rule = pGC->fillRule; + + if (mask & GCTile) { + if (pGC->tileIsPixel) + mask &= ~GCTile; + else + values.tile = xnestPixmap(pGC->tile.pixmap); + } + + if (mask & GCStipple) + values.stipple = xnestPixmap(pGC->stipple); + + if (mask & GCTileStipXOrigin) + values.ts_x_origin = pGC->patOrg.x; + + if (mask & GCTileStipYOrigin) + values.ts_y_origin = pGC->patOrg.y; + + if (mask & GCFont) + values.font = xnestFont(pGC->font); + + if (mask & GCSubwindowMode) + values.subwindow_mode = pGC->subWindowMode; + + if (mask & GCGraphicsExposures) + values.graphics_exposures = pGC->graphicsExposures; + + if (mask & GCClipXOrigin) + values.clip_x_origin = pGC->clipOrg.x; + + if (mask & GCClipYOrigin) + values.clip_y_origin = pGC->clipOrg.y; + + if (mask & GCClipMask) /* this is handled in change clip */ + mask &= ~GCClipMask; + + if (mask & GCDashOffset) + values.dash_offset = pGC->dashOffset; + + if (mask & GCDashList) { + mask &= ~GCDashList; + XSetDashes(xnestDisplay, xnestGC(pGC), + pGC->dashOffset, (char *)pGC->dash, pGC->numInDashList); + } + + if (mask & GCArcMode) + values.arc_mode = pGC->arcMode; + + if (mask) + XChangeGC(xnestDisplay, xnestGC(pGC), mask, &values); +} + +void +xnestCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst) +{ + XCopyGC(xnestDisplay, xnestGC(pGCSrc), mask, xnestGC(pGCDst)); +} + +void +xnestDestroyGC(GCPtr pGC) +{ + XFreeGC(xnestDisplay, xnestGC(pGC)); +} + +void +xnestChangeClip(GCPtr pGC, int type, pointer pValue, int nRects) +{ + int i, size; + BoxPtr pBox; + XRectangle *pRects; + + xnestDestroyClipHelper(pGC); + + switch(type) + { + case CT_NONE: + XSetClipMask(xnestDisplay, xnestGC(pGC), None); + break; + + case CT_REGION: + nRects = REGION_NUM_RECTS((RegionPtr)pValue); + size = nRects * sizeof(*pRects); + pRects = (XRectangle *) malloc(size); + pBox = REGION_RECTS((RegionPtr)pValue); + for (i = nRects; i-- > 0; ) { + pRects[i].x = pBox[i].x1; + pRects[i].y = pBox[i].y1; + pRects[i].width = pBox[i].x2 - pBox[i].x1; + pRects[i].height = pBox[i].y2 - pBox[i].y1; + } + XSetClipRectangles(xnestDisplay, xnestGC(pGC), 0, 0, + pRects, nRects, Unsorted); + free((char *) pRects); + break; + + case CT_PIXMAP: + XSetClipMask(xnestDisplay, xnestGC(pGC), + xnestPixmap((PixmapPtr)pValue)); + /* + * Need to change into region, so subsequent uses are with + * current pixmap contents. + */ + pGC->clientClip = (pointer) (*pGC->pScreen->BitmapToRegion)((PixmapPtr)pValue); + (*pGC->pScreen->DestroyPixmap)((PixmapPtr)pValue); + pValue = pGC->clientClip; + type = CT_REGION; + break; + + case CT_UNSORTED: + XSetClipRectangles(xnestDisplay, xnestGC(pGC), + pGC->clipOrg.x, pGC->clipOrg.y, + (XRectangle *)pValue, nRects, Unsorted); + break; + + case CT_YSORTED: + XSetClipRectangles(xnestDisplay, xnestGC(pGC), + pGC->clipOrg.x, pGC->clipOrg.y, + (XRectangle *)pValue, nRects, YSorted); + break; + + case CT_YXSORTED: + XSetClipRectangles(xnestDisplay, xnestGC(pGC), + pGC->clipOrg.x, pGC->clipOrg.y, + (XRectangle *)pValue, nRects, YXSorted); + break; + + case CT_YXBANDED: + XSetClipRectangles(xnestDisplay, xnestGC(pGC), + pGC->clipOrg.x, pGC->clipOrg.y, + (XRectangle *)pValue, nRects, YXBanded); + break; + } + + switch(type) + { + default: + break; + + case CT_UNSORTED: + case CT_YSORTED: + case CT_YXSORTED: + case CT_YXBANDED: + + /* + * other parts of server can only deal with CT_NONE, + * CT_PIXMAP and CT_REGION client clips. + */ + pGC->clientClip = (pointer) RECTS_TO_REGION(pGC->pScreen, nRects, + (xRectangle *)pValue, type); + free(pValue); + pValue = pGC->clientClip; + type = CT_REGION; + + break; + } + + pGC->clientClipType = type; + pGC->clientClip = pValue; + xnestGCPriv(pGC)->nClipRects = nRects; +} + +void +xnestDestroyClip(GCPtr pGC) +{ + xnestDestroyClipHelper(pGC); + + XSetClipMask(xnestDisplay, xnestGC(pGC), None); + + pGC->clientClipType = CT_NONE; + pGC->clientClip = NULL; + xnestGCPriv(pGC)->nClipRects = 0; +} + +void +xnestDestroyClipHelper(GCPtr pGC) +{ + switch (pGC->clientClipType) + { + default: + case CT_NONE: + break; + + case CT_REGION: + REGION_DESTROY(pGC->pScreen, pGC->clientClip); + break; + } +} + +void +xnestCopyClip(GCPtr pGCDst, GCPtr pGCSrc) +{ + RegionPtr pRgn; + + switch (pGCSrc->clientClipType) + { + default: + case CT_NONE: + xnestDestroyClip(pGCDst); + break; + + case CT_REGION: + pRgn = REGION_CREATE(pGCDst->pScreen, NULL, 1); + REGION_COPY(pGCDst->pScreen, pRgn, pGCSrc->clientClip); + xnestChangeClip(pGCDst, CT_REGION, pRgn, 0); + break; + } +} diff --git a/xorg-server/hw/xnest/Keyboard.c b/xorg-server/hw/xnest/Keyboard.c index 1835c7071..473724a04 100644 --- a/xorg-server/hw/xnest/Keyboard.c +++ b/xorg-server/hw/xnest/Keyboard.c @@ -1,257 +1,257 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - -#ifdef HAVE_XNEST_CONFIG_H -#include -#endif - -#include -#include -#include -#include "screenint.h" -#include "inputstr.h" -#include "misc.h" -#include "scrnintstr.h" -#include "servermd.h" - -#include "Xnest.h" - -#include "Display.h" -#include "Screen.h" -#include "Keyboard.h" -#include "Args.h" -#include "Events.h" - -#include -#include "xkbsrv.h" -#include - -extern Bool -XkbQueryExtension( - Display * /* dpy */, - int * /* opcodeReturn */, - int * /* eventBaseReturn */, - int * /* errorBaseReturn */, - int * /* majorRtrn */, - int * /* minorRtrn */ -); - -extern XkbDescPtr XkbGetKeyboard( - Display * /* dpy */, - unsigned int /* which */, - unsigned int /* deviceSpec */ -); - -extern Status XkbGetControls( - Display * /* dpy */, - unsigned long /* which */, - XkbDescPtr /* desc */ -); - -DeviceIntPtr xnestKeyboardDevice = NULL; - -void -xnestBell(int volume, DeviceIntPtr pDev, pointer ctrl, int cls) -{ - XBell(xnestDisplay, volume); -} - -void -DDXRingBell(int volume, int pitch, int duration) -{ - XBell(xnestDisplay, volume); -} - -void -xnestChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) -{ -#if 0 - unsigned long value_mask; - XKeyboardControl values; - int i; - - value_mask = KBKeyClickPercent | - KBBellPercent | - KBBellPitch | - KBBellDuration | - KBAutoRepeatMode; - - values.key_click_percent = ctrl->click; - values.bell_percent = ctrl->bell; - values.bell_pitch = ctrl->bell_pitch; - values.bell_duration = ctrl->bell_duration; - values.auto_repeat_mode = ctrl->autoRepeat ? - AutoRepeatModeOn : AutoRepeatModeOff; - - XChangeKeyboardControl(xnestDisplay, value_mask, &values); - - /* - value_mask = KBKey | KBAutoRepeatMode; - At this point, we need to walk through the vector and compare it - to the current server vector. If there are differences, report them. - */ - - value_mask = KBLed | KBLedMode; - for (i = 1; i <= 32; i++) { - values.led = i; - values.led_mode = (ctrl->leds & (1 << (i - 1))) ? LedModeOn : LedModeOff; - XChangeKeyboardControl(xnestDisplay, value_mask, &values); - } -#endif -} - -int -xnestKeyboardProc(DeviceIntPtr pDev, int onoff) -{ - KeySym *keymap; - int mapWidth; - int min_keycode, max_keycode; - KeySymsRec keySyms; - int i; - XKeyboardState values; - XkbDescPtr xkb; - int op, event, error, major, minor; - - switch (onoff) - { - case DEVICE_INIT: - XDisplayKeycodes(xnestDisplay, &min_keycode, &max_keycode); -#ifdef _XSERVER64 - { - KeySym64 *keymap64; - int i, len; - keymap64 = XGetKeyboardMapping(xnestDisplay, - min_keycode, - max_keycode - min_keycode + 1, - &mapWidth); - len = (max_keycode - min_keycode + 1) * mapWidth; - keymap = (KeySym *)xalloc(len * sizeof(KeySym)); - for(i = 0; i < len; ++i) - keymap[i] = keymap64[i]; - XFree(keymap64); - } -#else - keymap = XGetKeyboardMapping(xnestDisplay, - min_keycode, - max_keycode - min_keycode + 1, - &mapWidth); -#endif - - keySyms.minKeyCode = min_keycode; - keySyms.maxKeyCode = max_keycode; - keySyms.mapWidth = mapWidth; - keySyms.map = keymap; - - if (XkbQueryExtension(xnestDisplay, &op, &event, &error, &major, &minor) == 0) { - ErrorF("Unable to initialize XKEYBOARD extension.\n"); - goto XkbError; - } - xkb = XkbGetKeyboard(xnestDisplay, XkbGBN_AllComponentsMask, XkbUseCoreKbd); - if (xkb == NULL || xkb->geom == NULL) { - ErrorF("Couldn't get keyboard.\n"); - goto XkbError; - } - XkbGetControls(xnestDisplay, XkbAllControlsMask, xkb); - - InitKeyboardDeviceStruct(pDev, NULL, - xnestBell, xnestChangeKeyboardControl); - XkbDDXChangeControls(pDev, xkb->ctrls, xkb->ctrls); - XkbFreeKeyboard(xkb, 0, False); - xfree(keymap); - break; - case DEVICE_ON: - xnestEventMask |= XNEST_KEYBOARD_EVENT_MASK; - for (i = 0; i < xnestNumScreens; i++) - XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); - break; - case DEVICE_OFF: - xnestEventMask &= ~XNEST_KEYBOARD_EVENT_MASK; - for (i = 0; i < xnestNumScreens; i++) - XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); - break; - case DEVICE_CLOSE: - break; - } - return Success; - -XkbError: - XGetKeyboardControl(xnestDisplay, &values); - memmove((char *)defaultKeyboardControl.autoRepeats, - (char *)values.auto_repeats, - sizeof(values.auto_repeats)); - - InitKeyboardDeviceStruct(pDev, NULL, - xnestBell, xnestChangeKeyboardControl); - xfree(keymap); - return Success; -} - -Bool -LegalModifier(unsigned int key, DeviceIntPtr pDev) -{ - return TRUE; -} - -void -xnestUpdateModifierState(unsigned int state) -{ - DeviceIntPtr pDev = xnestKeyboardDevice; - KeyClassPtr keyc = pDev->key; - int i; - CARD8 mask; - int xkb_state; - - if (!pDev) - return; - - xkb_state = XkbStateFieldFromRec(&pDev->key->xkbInfo->state); - state = state & 0xff; - - if (xkb_state == state) - return; - - for (i = 0, mask = 1; i < 8; i++, mask <<= 1) { - int key; - - /* Modifier is down, but shouldn't be - */ - if ((xkb_state & mask) && !(state & mask)) { - int count = keyc->modifierKeyCount[i]; - - for (key = 0; key < MAP_LENGTH; key++) - if (keyc->xkbInfo->desc->map->modmap[key] & mask) { - int bit; - BYTE *kptr; - - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); - - if (*kptr & bit) - xnestQueueKeyEvent(KeyRelease, key); - - if (--count == 0) - break; - } - } - - /* Modifier shoud be down, but isn't - */ - if (!(xkb_state & mask) && (state & mask)) - for (key = 0; key < MAP_LENGTH; key++) - if (keyc->xkbInfo->desc->map->modmap[key] & mask) { - xnestQueueKeyEvent(KeyPress, key); - break; - } - } -} +/* + +Copyright 1993 by Davor Matic + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. Davor Matic makes no representations about +the suitability of this software for any purpose. It is provided "as +is" without express or implied warranty. + +*/ + +#ifdef HAVE_XNEST_CONFIG_H +#include +#endif + +#include +#include +#include +#include "screenint.h" +#include "inputstr.h" +#include "misc.h" +#include "scrnintstr.h" +#include "servermd.h" + +#include "Xnest.h" + +#include "Display.h" +#include "Screen.h" +#include "Keyboard.h" +#include "Args.h" +#include "Events.h" + +#include +#include "xkbsrv.h" +#include + +extern Bool +XkbQueryExtension( + Display * /* dpy */, + int * /* opcodeReturn */, + int * /* eventBaseReturn */, + int * /* errorBaseReturn */, + int * /* majorRtrn */, + int * /* minorRtrn */ +); + +extern XkbDescPtr XkbGetKeyboard( + Display * /* dpy */, + unsigned int /* which */, + unsigned int /* deviceSpec */ +); + +extern Status XkbGetControls( + Display * /* dpy */, + unsigned long /* which */, + XkbDescPtr /* desc */ +); + +DeviceIntPtr xnestKeyboardDevice = NULL; + +void +xnestBell(int volume, DeviceIntPtr pDev, pointer ctrl, int cls) +{ + XBell(xnestDisplay, volume); +} + +void +DDXRingBell(int volume, int pitch, int duration) +{ + XBell(xnestDisplay, volume); +} + +void +xnestChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) +{ +#if 0 + unsigned long value_mask; + XKeyboardControl values; + int i; + + value_mask = KBKeyClickPercent | + KBBellPercent | + KBBellPitch | + KBBellDuration | + KBAutoRepeatMode; + + values.key_click_percent = ctrl->click; + values.bell_percent = ctrl->bell; + values.bell_pitch = ctrl->bell_pitch; + values.bell_duration = ctrl->bell_duration; + values.auto_repeat_mode = ctrl->autoRepeat ? + AutoRepeatModeOn : AutoRepeatModeOff; + + XChangeKeyboardControl(xnestDisplay, value_mask, &values); + + /* + value_mask = KBKey | KBAutoRepeatMode; + At this point, we need to walk through the vector and compare it + to the current server vector. If there are differences, report them. + */ + + value_mask = KBLed | KBLedMode; + for (i = 1; i <= 32; i++) { + values.led = i; + values.led_mode = (ctrl->leds & (1 << (i - 1))) ? LedModeOn : LedModeOff; + XChangeKeyboardControl(xnestDisplay, value_mask, &values); + } +#endif +} + +int +xnestKeyboardProc(DeviceIntPtr pDev, int onoff) +{ + KeySym *keymap; + int mapWidth; + int min_keycode, max_keycode; + KeySymsRec keySyms; + int i; + XKeyboardState values; + XkbDescPtr xkb; + int op, event, error, major, minor; + + switch (onoff) + { + case DEVICE_INIT: + XDisplayKeycodes(xnestDisplay, &min_keycode, &max_keycode); +#ifdef _XSERVER64 + { + KeySym64 *keymap64; + int i, len; + keymap64 = XGetKeyboardMapping(xnestDisplay, + min_keycode, + max_keycode - min_keycode + 1, + &mapWidth); + len = (max_keycode - min_keycode + 1) * mapWidth; + keymap = (KeySym *)malloc(len * sizeof(KeySym)); + for(i = 0; i < len; ++i) + keymap[i] = keymap64[i]; + XFree(keymap64); + } +#else + keymap = XGetKeyboardMapping(xnestDisplay, + min_keycode, + max_keycode - min_keycode + 1, + &mapWidth); +#endif + + keySyms.minKeyCode = min_keycode; + keySyms.maxKeyCode = max_keycode; + keySyms.mapWidth = mapWidth; + keySyms.map = keymap; + + if (XkbQueryExtension(xnestDisplay, &op, &event, &error, &major, &minor) == 0) { + ErrorF("Unable to initialize XKEYBOARD extension.\n"); + goto XkbError; + } + xkb = XkbGetKeyboard(xnestDisplay, XkbGBN_AllComponentsMask, XkbUseCoreKbd); + if (xkb == NULL || xkb->geom == NULL) { + ErrorF("Couldn't get keyboard.\n"); + goto XkbError; + } + XkbGetControls(xnestDisplay, XkbAllControlsMask, xkb); + + InitKeyboardDeviceStruct(pDev, NULL, + xnestBell, xnestChangeKeyboardControl); + XkbDDXChangeControls(pDev, xkb->ctrls, xkb->ctrls); + XkbFreeKeyboard(xkb, 0, False); + free(keymap); + break; + case DEVICE_ON: + xnestEventMask |= XNEST_KEYBOARD_EVENT_MASK; + for (i = 0; i < xnestNumScreens; i++) + XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); + break; + case DEVICE_OFF: + xnestEventMask &= ~XNEST_KEYBOARD_EVENT_MASK; + for (i = 0; i < xnestNumScreens; i++) + XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); + break; + case DEVICE_CLOSE: + break; + } + return Success; + +XkbError: + XGetKeyboardControl(xnestDisplay, &values); + memmove((char *)defaultKeyboardControl.autoRepeats, + (char *)values.auto_repeats, + sizeof(values.auto_repeats)); + + InitKeyboardDeviceStruct(pDev, NULL, + xnestBell, xnestChangeKeyboardControl); + free(keymap); + return Success; +} + +Bool +LegalModifier(unsigned int key, DeviceIntPtr pDev) +{ + return TRUE; +} + +void +xnestUpdateModifierState(unsigned int state) +{ + DeviceIntPtr pDev = xnestKeyboardDevice; + KeyClassPtr keyc = pDev->key; + int i; + CARD8 mask; + int xkb_state; + + if (!pDev) + return; + + xkb_state = XkbStateFieldFromRec(&pDev->key->xkbInfo->state); + state = state & 0xff; + + if (xkb_state == state) + return; + + for (i = 0, mask = 1; i < 8; i++, mask <<= 1) { + int key; + + /* Modifier is down, but shouldn't be + */ + if ((xkb_state & mask) && !(state & mask)) { + int count = keyc->modifierKeyCount[i]; + + for (key = 0; key < MAP_LENGTH; key++) + if (keyc->xkbInfo->desc->map->modmap[key] & mask) { + int bit; + BYTE *kptr; + + kptr = &keyc->down[key >> 3]; + bit = 1 << (key & 7); + + if (*kptr & bit) + xnestQueueKeyEvent(KeyRelease, key); + + if (--count == 0) + break; + } + } + + /* Modifier shoud be down, but isn't + */ + if (!(xkb_state & mask) && (state & mask)) + for (key = 0; key < MAP_LENGTH; key++) + if (keyc->xkbInfo->desc->map->modmap[key] & mask) { + xnestQueueKeyEvent(KeyPress, key); + break; + } + } +} diff --git a/xorg-server/hw/xnest/Pixmap.c b/xorg-server/hw/xnest/Pixmap.c index 676a2ba95..cd2245b46 100644 --- a/xorg-server/hw/xnest/Pixmap.c +++ b/xorg-server/hw/xnest/Pixmap.c @@ -1,141 +1,141 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - -#ifdef HAVE_XNEST_CONFIG_H -#include -#endif - -#include -#include -#include "regionstr.h" -#include "pixmapstr.h" -#include "scrnintstr.h" -#include "regionstr.h" -#include "gc.h" -#include "servermd.h" -#include "privates.h" -#include "mi.h" - -#include "Xnest.h" - -#include "Display.h" -#include "Screen.h" -#include "XNPixmap.h" - -static int xnestPixmapPrivateKeyIndex; -DevPrivateKey xnestPixmapPrivateKey = &xnestPixmapPrivateKeyIndex; - -PixmapPtr -xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth, - unsigned usage_hint) -{ - PixmapPtr pPixmap; - - pPixmap = AllocatePixmap(pScreen, sizeof(xnestPrivPixmap)); - if (!pPixmap) - return NullPixmap; - pPixmap->drawable.type = DRAWABLE_PIXMAP; - pPixmap->drawable.class = 0; - pPixmap->drawable.depth = depth; - pPixmap->drawable.bitsPerPixel = depth; - pPixmap->drawable.id = 0; - pPixmap->drawable.x = 0; - pPixmap->drawable.y = 0; - pPixmap->drawable.width = width; - pPixmap->drawable.height = height; - pPixmap->drawable.pScreen = pScreen; - pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pPixmap->refcnt = 1; - pPixmap->devKind = PixmapBytePad(width, depth); - pPixmap->usage_hint = usage_hint; - dixSetPrivate(&pPixmap->devPrivates, xnestPixmapPrivateKey, - (char *)pPixmap + pScreen->totalPixmapSize); - if (width && height) - xnestPixmapPriv(pPixmap)->pixmap = - XCreatePixmap(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], - width, height, depth); - else - xnestPixmapPriv(pPixmap)->pixmap = 0; - - return pPixmap; -} - -Bool -xnestDestroyPixmap(PixmapPtr pPixmap) -{ - if(--pPixmap->refcnt) - return TRUE; - XFreePixmap(xnestDisplay, xnestPixmap(pPixmap)); - dixFreePrivates(pPixmap->devPrivates); - xfree(pPixmap); - return TRUE; -} - -RegionPtr -xnestPixmapToRegion(PixmapPtr pPixmap) -{ - XImage *ximage; - register RegionPtr pReg, pTmpReg; - register int x, y; - unsigned long previousPixel, currentPixel; - BoxRec Box = { 0, 0, 0, 0 }; - Bool overlap; - - ximage = XGetImage(xnestDisplay, xnestPixmap(pPixmap), 0, 0, - pPixmap->drawable.width, pPixmap->drawable.height, - 1, XYPixmap); - - pReg = REGION_CREATE(pPixmap->drawable.pScreen, NULL, 1); - pTmpReg = REGION_CREATE(pPixmap->drawable.pScreen, NULL, 1); - if(!pReg || !pTmpReg) { - XDestroyImage(ximage); - return NullRegion; - } - - for (y = 0; y < pPixmap->drawable.height; y++) { - Box.y1 = y; - Box.y2 = y + 1; - previousPixel = 0L; - for (x = 0; x < pPixmap->drawable.width; x++) { - currentPixel = XGetPixel(ximage, x, y); - if (previousPixel != currentPixel) { - if (previousPixel == 0L) { - /* left edge */ - Box.x1 = x; - } - else if (currentPixel == 0L) { - /* right edge */ - Box.x2 = x; - REGION_RESET(pPixmap->drawable.pScreen, pTmpReg, &Box); - REGION_APPEND(pPixmap->drawable.pScreen, pReg, pTmpReg); - } - previousPixel = currentPixel; - } - } - if (previousPixel != 0L) { - /* right edge because of the end of pixmap */ - Box.x2 = pPixmap->drawable.width; - REGION_RESET(pPixmap->drawable.pScreen, pTmpReg, &Box); - REGION_APPEND(pPixmap->drawable.pScreen, pReg, pTmpReg); - } - } - - REGION_DESTROY(pPixmap->drawable.pScreen, pTmpReg); - XDestroyImage(ximage); - - REGION_VALIDATE(pPixmap->drawable.pScreen, pReg, &overlap); - - return(pReg); -} +/* + +Copyright 1993 by Davor Matic + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. Davor Matic makes no representations about +the suitability of this software for any purpose. It is provided "as +is" without express or implied warranty. + +*/ + +#ifdef HAVE_XNEST_CONFIG_H +#include +#endif + +#include +#include +#include "regionstr.h" +#include "pixmapstr.h" +#include "scrnintstr.h" +#include "regionstr.h" +#include "gc.h" +#include "servermd.h" +#include "privates.h" +#include "mi.h" + +#include "Xnest.h" + +#include "Display.h" +#include "Screen.h" +#include "XNPixmap.h" + +static int xnestPixmapPrivateKeyIndex; +DevPrivateKey xnestPixmapPrivateKey = &xnestPixmapPrivateKeyIndex; + +PixmapPtr +xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth, + unsigned usage_hint) +{ + PixmapPtr pPixmap; + + pPixmap = AllocatePixmap(pScreen, sizeof(xnestPrivPixmap)); + if (!pPixmap) + return NullPixmap; + pPixmap->drawable.type = DRAWABLE_PIXMAP; + pPixmap->drawable.class = 0; + pPixmap->drawable.depth = depth; + pPixmap->drawable.bitsPerPixel = depth; + pPixmap->drawable.id = 0; + pPixmap->drawable.x = 0; + pPixmap->drawable.y = 0; + pPixmap->drawable.width = width; + pPixmap->drawable.height = height; + pPixmap->drawable.pScreen = pScreen; + pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; + pPixmap->refcnt = 1; + pPixmap->devKind = PixmapBytePad(width, depth); + pPixmap->usage_hint = usage_hint; + dixSetPrivate(&pPixmap->devPrivates, xnestPixmapPrivateKey, + (char *)pPixmap + pScreen->totalPixmapSize); + if (width && height) + xnestPixmapPriv(pPixmap)->pixmap = + XCreatePixmap(xnestDisplay, + xnestDefaultWindows[pScreen->myNum], + width, height, depth); + else + xnestPixmapPriv(pPixmap)->pixmap = 0; + + return pPixmap; +} + +Bool +xnestDestroyPixmap(PixmapPtr pPixmap) +{ + if(--pPixmap->refcnt) + return TRUE; + XFreePixmap(xnestDisplay, xnestPixmap(pPixmap)); + dixFreePrivates(pPixmap->devPrivates); + free(pPixmap); + return TRUE; +} + +RegionPtr +xnestPixmapToRegion(PixmapPtr pPixmap) +{ + XImage *ximage; + register RegionPtr pReg, pTmpReg; + register int x, y; + unsigned long previousPixel, currentPixel; + BoxRec Box = { 0, 0, 0, 0 }; + Bool overlap; + + ximage = XGetImage(xnestDisplay, xnestPixmap(pPixmap), 0, 0, + pPixmap->drawable.width, pPixmap->drawable.height, + 1, XYPixmap); + + pReg = REGION_CREATE(pPixmap->drawable.pScreen, NULL, 1); + pTmpReg = REGION_CREATE(pPixmap->drawable.pScreen, NULL, 1); + if(!pReg || !pTmpReg) { + XDestroyImage(ximage); + return NullRegion; + } + + for (y = 0; y < pPixmap->drawable.height; y++) { + Box.y1 = y; + Box.y2 = y + 1; + previousPixel = 0L; + for (x = 0; x < pPixmap->drawable.width; x++) { + currentPixel = XGetPixel(ximage, x, y); + if (previousPixel != currentPixel) { + if (previousPixel == 0L) { + /* left edge */ + Box.x1 = x; + } + else if (currentPixel == 0L) { + /* right edge */ + Box.x2 = x; + REGION_RESET(pPixmap->drawable.pScreen, pTmpReg, &Box); + REGION_APPEND(pPixmap->drawable.pScreen, pReg, pTmpReg); + } + previousPixel = currentPixel; + } + } + if (previousPixel != 0L) { + /* right edge because of the end of pixmap */ + Box.x2 = pPixmap->drawable.width; + REGION_RESET(pPixmap->drawable.pScreen, pTmpReg, &Box); + REGION_APPEND(pPixmap->drawable.pScreen, pReg, pTmpReg); + } + } + + REGION_DESTROY(pPixmap->drawable.pScreen, pTmpReg); + XDestroyImage(ximage); + + REGION_VALIDATE(pPixmap->drawable.pScreen, pReg, &overlap); + + return(pReg); +} diff --git a/xorg-server/hw/xnest/Screen.c b/xorg-server/hw/xnest/Screen.c index ca903d7ac..5a035ac8f 100644 --- a/xorg-server/hw/xnest/Screen.c +++ b/xorg-server/hw/xnest/Screen.c @@ -1,421 +1,420 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - -#ifdef HAVE_XNEST_CONFIG_H -#include -#endif - -#include -#include -#include "scrnintstr.h" -#include "dix.h" -#include "mi.h" -#include "mibstore.h" -#include "micmap.h" -#include "colormapst.h" -#include "resource.h" - -#include "Xnest.h" - -#include "Display.h" -#include "Screen.h" -#include "XNGC.h" -#include "GCOps.h" -#include "Drawable.h" -#include "XNFont.h" -#include "Color.h" -#include "XNCursor.h" -#include "Visual.h" -#include "Events.h" -#include "Init.h" -#include "mipointer.h" -#include "Args.h" -#include "mipointrst.h" - -Window xnestDefaultWindows[MAXSCREENS]; -Window xnestScreenSaverWindows[MAXSCREENS]; -static int xnestCursorScreenKeyIndex; -DevPrivateKey xnestCursorScreenKey = &xnestCursorScreenKeyIndex; - -ScreenPtr -xnestScreen(Window window) -{ - int i; - - for (i = 0; i < xnestNumScreens; i++) - if (xnestDefaultWindows[i] == window) - return screenInfo.screens[i]; - - return NULL; -} - -static int -offset(unsigned long mask) -{ - int count; - - for (count = 0; !(mask & 1) && count < 32; count++) - mask >>= 1; - - return count; -} - -static Bool -xnestSaveScreen(ScreenPtr pScreen, int what) -{ - if (xnestSoftwareScreenSaver) - return False; - else { - switch (what) { - case SCREEN_SAVER_ON: - XMapRaised(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]); - xnestSetScreenSaverColormapWindow(pScreen); - break; - - case SCREEN_SAVER_OFF: - XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]); - xnestSetInstalledColormapWindows(pScreen); - break; - - case SCREEN_SAVER_FORCER: - lastEventTime = GetTimeInMillis(); - XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]); - xnestSetInstalledColormapWindows(pScreen); - break; - - case SCREEN_SAVER_CYCLE: - XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]); - xnestSetInstalledColormapWindows(pScreen); - break; - } - return True; - } -} - -static Bool -xnestCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y) -{ - return FALSE; -} - -static void -xnestCrossScreen(ScreenPtr pScreen, Bool entering) -{ -} - -static miPointerScreenFuncRec xnestPointerCursorFuncs = -{ - xnestCursorOffScreen, - xnestCrossScreen, - miPointerWarpCursor -}; - -static miPointerSpriteFuncRec xnestPointerSpriteFuncs = -{ - xnestRealizeCursor, - xnestUnrealizeCursor, - xnestSetCursor, - xnestMoveCursor, - xnestDeviceCursorInitialize, - xnestDeviceCursorCleanup -}; - -Bool -xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[]) -{ - VisualPtr visuals; - DepthPtr depths; - int numVisuals, numDepths; - int i, j, depthIndex; - unsigned long valuemask; - XSetWindowAttributes attributes; - XWindowAttributes gattributes; - XSizeHints sizeHints; - VisualID defaultVisual; - int rootDepth; - miPointerScreenPtr PointPriv; - - if (!dixRequestPrivate(xnestWindowPrivateKey, sizeof(xnestPrivWin))) - return False; - if (!dixRequestPrivate(xnestGCPrivateKey, sizeof(xnestPrivGC))) - return False; - - visuals = (VisualPtr)xalloc(xnestNumVisuals * sizeof(VisualRec)); - numVisuals = 0; - - depths = (DepthPtr)xalloc(MAXDEPTH * sizeof(DepthRec)); - depths[0].depth = 1; - depths[0].numVids = 0; - depths[0].vids = (VisualID *)xalloc(MAXVISUALSPERDEPTH * sizeof(VisualID)); - numDepths = 1; - - for (i = 0; i < xnestNumVisuals; i++) { - visuals[numVisuals].class = xnestVisuals[i].class; - visuals[numVisuals].bitsPerRGBValue = xnestVisuals[i].bits_per_rgb; - visuals[numVisuals].ColormapEntries = xnestVisuals[i].colormap_size; - visuals[numVisuals].nplanes = xnestVisuals[i].depth; - visuals[numVisuals].redMask = xnestVisuals[i].red_mask; - visuals[numVisuals].greenMask = xnestVisuals[i].green_mask; - visuals[numVisuals].blueMask = xnestVisuals[i].blue_mask; - visuals[numVisuals].offsetRed = offset(xnestVisuals[i].red_mask); - visuals[numVisuals].offsetGreen = offset(xnestVisuals[i].green_mask); - visuals[numVisuals].offsetBlue = offset(xnestVisuals[i].blue_mask); - - /* Check for and remove duplicates. */ - for (j = 0; j < numVisuals; j++) { - if (visuals[numVisuals].class == visuals[j].class && - visuals[numVisuals].bitsPerRGBValue == visuals[j].bitsPerRGBValue && - visuals[numVisuals].ColormapEntries == visuals[j].ColormapEntries && - visuals[numVisuals].nplanes == visuals[j].nplanes && - visuals[numVisuals].redMask == visuals[j].redMask && - visuals[numVisuals].greenMask == visuals[j].greenMask && - visuals[numVisuals].blueMask == visuals[j].blueMask && - visuals[numVisuals].offsetRed == visuals[j].offsetRed && - visuals[numVisuals].offsetGreen == visuals[j].offsetGreen && - visuals[numVisuals].offsetBlue == visuals[j].offsetBlue) - break; - } - if (j < numVisuals) - break; - - visuals[numVisuals].vid = FakeClientID(0); - - depthIndex = UNDEFINED; - for (j = 0; j < numDepths; j++) - if (depths[j].depth == xnestVisuals[i].depth) { - depthIndex = j; - break; - } - - if (depthIndex == UNDEFINED) { - depthIndex = numDepths; - depths[depthIndex].depth = xnestVisuals[i].depth; - depths[depthIndex].numVids = 0; - depths[depthIndex].vids = - (VisualID *)xalloc(MAXVISUALSPERDEPTH * sizeof(VisualID)); - numDepths++; - } - if (depths[depthIndex].numVids >= MAXVISUALSPERDEPTH) { - FatalError("Visual table overflow"); - } - depths[depthIndex].vids[depths[depthIndex].numVids] = - visuals[numVisuals].vid; - depths[depthIndex].numVids++; - - numVisuals++; - } - visuals = (VisualPtr)xrealloc(visuals, numVisuals * sizeof(VisualRec)); - - defaultVisual = visuals[xnestDefaultVisualIndex].vid; - rootDepth = visuals[xnestDefaultVisualIndex].nplanes; - - if (xnestParentWindow != 0) { - XGetWindowAttributes(xnestDisplay, xnestParentWindow, &gattributes); - xnestWidth = gattributes.width; - xnestHeight = gattributes.height; - } - - /* myNum */ - /* id */ - miScreenInit(pScreen, NULL, xnestWidth, xnestHeight, 1, 1, xnestWidth, - rootDepth, - numDepths, depths, - defaultVisual, /* root visual */ - numVisuals, visuals); - -/* miInitializeBackingStore(pScreen); */ - - pScreen->defColormap = (Colormap) FakeClientID(0); - pScreen->minInstalledCmaps = MINCMAPS; - pScreen->maxInstalledCmaps = MAXCMAPS; - pScreen->backingStoreSupport = NotUseful; - pScreen->saveUnderSupport = NotUseful; - pScreen->whitePixel = xnestWhitePixel; - pScreen->blackPixel = xnestBlackPixel; - /* rgf */ - /* GCperDepth */ - /* PixmapPerDepth */ - pScreen->devPrivate = NULL; - /* WindowPrivateLen */ - /* WindowPrivateSizes */ - /* totalWindowSize */ - /* GCPrivateLen */ - /* GCPrivateSizes */ - /* totalGCSize */ - - /* Random screen procedures */ - - pScreen->QueryBestSize = xnestQueryBestSize; - pScreen->SaveScreen = xnestSaveScreen; - pScreen->GetImage = xnestGetImage; - pScreen->GetSpans = xnestGetSpans; - pScreen->PointerNonInterestBox = NULL; - pScreen->SourceValidate = NULL; - - /* Window Procedures */ - - pScreen->CreateWindow = xnestCreateWindow; - pScreen->DestroyWindow = xnestDestroyWindow; - pScreen->PositionWindow = xnestPositionWindow; - pScreen->ChangeWindowAttributes = xnestChangeWindowAttributes; - pScreen->RealizeWindow = xnestRealizeWindow; - pScreen->UnrealizeWindow = xnestUnrealizeWindow; - pScreen->PostValidateTree = NULL; - pScreen->WindowExposures = xnestWindowExposures; - pScreen->CopyWindow = xnestCopyWindow; - pScreen->ClipNotify = xnestClipNotify; - - /* Pixmap procedures */ - - pScreen->CreatePixmap = xnestCreatePixmap; - pScreen->DestroyPixmap = xnestDestroyPixmap; - - /* Font procedures */ - - pScreen->RealizeFont = xnestRealizeFont; - pScreen->UnrealizeFont = xnestUnrealizeFont; - - /* GC procedures */ - - pScreen->CreateGC = xnestCreateGC; - - /* Colormap procedures */ - - pScreen->CreateColormap = xnestCreateColormap; - pScreen->DestroyColormap = xnestDestroyColormap; - pScreen->InstallColormap = xnestInstallColormap; - pScreen->UninstallColormap = xnestUninstallColormap; - pScreen->ListInstalledColormaps = xnestListInstalledColormaps; - pScreen->StoreColors = xnestStoreColors; - pScreen->ResolveColor = xnestResolveColor; - - pScreen->BitmapToRegion = xnestPixmapToRegion; - - /* OS layer procedures */ - - pScreen->BlockHandler = (ScreenBlockHandlerProcPtr)NoopDDA; - pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr)NoopDDA; - pScreen->blockData = NULL; - pScreen->wakeupData = NULL; - - miDCInitialize(pScreen, &xnestPointerCursorFuncs); /* init SW rendering */ - PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); - xnestCursorFuncs.spriteFuncs = PointPriv->spriteFuncs; - dixSetPrivate(&pScreen->devPrivates, xnestCursorScreenKey, &xnestCursorFuncs); - PointPriv->spriteFuncs = &xnestPointerSpriteFuncs; - - pScreen->mmWidth = xnestWidth * DisplayWidthMM(xnestDisplay, - DefaultScreen(xnestDisplay)) / - DisplayWidth(xnestDisplay, - DefaultScreen(xnestDisplay)); - pScreen->mmHeight = xnestHeight * DisplayHeightMM(xnestDisplay, - DefaultScreen(xnestDisplay)) / - DisplayHeight(xnestDisplay, - DefaultScreen(xnestDisplay)); - - /* overwrite miCloseScreen with our own */ - pScreen->CloseScreen = xnestCloseScreen; - - if (!miScreenDevPrivateInit(pScreen, xnestWidth, NULL)) - return FALSE; - - /* overwrite miSetShape with our own */ - pScreen->SetShape = xnestSetShape; - - /* devPrivates */ - -#define POSITION_OFFSET (pScreen->myNum * (xnestWidth + xnestHeight) / 32) - - if (xnestDoFullGeneration) { - - valuemask = CWBackPixel | CWEventMask | CWColormap; - attributes.background_pixel = xnestWhitePixel; - attributes.event_mask = xnestEventMask; - attributes.colormap = xnestDefaultVisualColormap(xnestDefaultVisual(pScreen)); - - if (xnestParentWindow != 0) { - xnestDefaultWindows[pScreen->myNum] = xnestParentWindow; - XSelectInput (xnestDisplay, xnestDefaultWindows[pScreen->myNum], - xnestEventMask); - } else - xnestDefaultWindows[pScreen->myNum] = - XCreateWindow(xnestDisplay, - DefaultRootWindow(xnestDisplay), - xnestX + POSITION_OFFSET, - xnestY + POSITION_OFFSET, - xnestWidth, xnestHeight, - xnestBorderWidth, - pScreen->rootDepth, - InputOutput, - xnestDefaultVisual(pScreen), - valuemask, &attributes); - - if (!xnestWindowName) - xnestWindowName = argv[0]; - - sizeHints.flags = PPosition | PSize | PMaxSize; - sizeHints.x = xnestX + POSITION_OFFSET; - sizeHints.y = xnestY + POSITION_OFFSET; - sizeHints.width = sizeHints.max_width = xnestWidth; - sizeHints.height = sizeHints.max_height = xnestHeight; - if (xnestUserGeometry & XValue || xnestUserGeometry & YValue) - sizeHints.flags |= USPosition; - if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue) - sizeHints.flags |= USSize; - XSetStandardProperties(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], - xnestWindowName, - xnestWindowName, - xnestIconBitmap, - argv, argc, &sizeHints); - - XMapWindow(xnestDisplay, xnestDefaultWindows[pScreen->myNum]); - - valuemask = CWBackPixmap | CWColormap; - attributes.background_pixmap = xnestScreenSaverPixmap; - attributes.colormap = - DefaultColormap(xnestDisplay, DefaultScreen(xnestDisplay)); - xnestScreenSaverWindows[pScreen->myNum] = - XCreateWindow(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], - 0, 0, xnestWidth, xnestHeight, 0, - DefaultDepth(xnestDisplay, DefaultScreen(xnestDisplay)), - InputOutput, - DefaultVisual(xnestDisplay, DefaultScreen(xnestDisplay)), - valuemask, &attributes); - } - - if (!xnestCreateDefaultColormap(pScreen)) return False; - - return True; -} - -Bool -xnestCloseScreen(int index, ScreenPtr pScreen) -{ - int i; - - for (i = 0; i < pScreen->numDepths; i++) - xfree(pScreen->allowedDepths[i].vids); - xfree(pScreen->allowedDepths); - xfree(pScreen->visuals); - xfree(pScreen->devPrivate); - - /* - If xnestDoFullGeneration all x resources will be destroyed upon closing - the display connection. There is no need to generate extra protocol. - */ - - return True; -} +/* + +Copyright 1993 by Davor Matic + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. Davor Matic makes no representations about +the suitability of this software for any purpose. It is provided "as +is" without express or implied warranty. + +*/ + +#ifdef HAVE_XNEST_CONFIG_H +#include +#endif + +#include +#include +#include "scrnintstr.h" +#include "dix.h" +#include "mi.h" +#include "mibstore.h" +#include "micmap.h" +#include "colormapst.h" +#include "resource.h" + +#include "Xnest.h" + +#include "Display.h" +#include "Screen.h" +#include "XNGC.h" +#include "GCOps.h" +#include "Drawable.h" +#include "XNFont.h" +#include "Color.h" +#include "XNCursor.h" +#include "Visual.h" +#include "Events.h" +#include "Init.h" +#include "mipointer.h" +#include "Args.h" +#include "mipointrst.h" + +Window xnestDefaultWindows[MAXSCREENS]; +Window xnestScreenSaverWindows[MAXSCREENS]; +static int xnestCursorScreenKeyIndex; +DevPrivateKey xnestCursorScreenKey = &xnestCursorScreenKeyIndex; + +ScreenPtr +xnestScreen(Window window) +{ + int i; + + for (i = 0; i < xnestNumScreens; i++) + if (xnestDefaultWindows[i] == window) + return screenInfo.screens[i]; + + return NULL; +} + +static int +offset(unsigned long mask) +{ + int count; + + for (count = 0; !(mask & 1) && count < 32; count++) + mask >>= 1; + + return count; +} + +static Bool +xnestSaveScreen(ScreenPtr pScreen, int what) +{ + if (xnestSoftwareScreenSaver) + return False; + else { + switch (what) { + case SCREEN_SAVER_ON: + XMapRaised(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]); + xnestSetScreenSaverColormapWindow(pScreen); + break; + + case SCREEN_SAVER_OFF: + XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]); + xnestSetInstalledColormapWindows(pScreen); + break; + + case SCREEN_SAVER_FORCER: + lastEventTime = GetTimeInMillis(); + XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]); + xnestSetInstalledColormapWindows(pScreen); + break; + + case SCREEN_SAVER_CYCLE: + XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]); + xnestSetInstalledColormapWindows(pScreen); + break; + } + return True; + } +} + +static Bool +xnestCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y) +{ + return FALSE; +} + +static void +xnestCrossScreen(ScreenPtr pScreen, Bool entering) +{ +} + +static miPointerScreenFuncRec xnestPointerCursorFuncs = +{ + xnestCursorOffScreen, + xnestCrossScreen, + miPointerWarpCursor +}; + +static miPointerSpriteFuncRec xnestPointerSpriteFuncs = +{ + xnestRealizeCursor, + xnestUnrealizeCursor, + xnestSetCursor, + xnestMoveCursor, + xnestDeviceCursorInitialize, + xnestDeviceCursorCleanup +}; + +Bool +xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[]) +{ + VisualPtr visuals; + DepthPtr depths; + int numVisuals, numDepths; + int i, j, depthIndex; + unsigned long valuemask; + XSetWindowAttributes attributes; + XWindowAttributes gattributes; + XSizeHints sizeHints; + VisualID defaultVisual; + int rootDepth; + miPointerScreenPtr PointPriv; + + if (!dixRequestPrivate(xnestWindowPrivateKey, sizeof(xnestPrivWin))) + return False; + if (!dixRequestPrivate(xnestGCPrivateKey, sizeof(xnestPrivGC))) + return False; + + visuals = (VisualPtr)malloc(xnestNumVisuals * sizeof(VisualRec)); + numVisuals = 0; + + depths = (DepthPtr)malloc(MAXDEPTH * sizeof(DepthRec)); + depths[0].depth = 1; + depths[0].numVids = 0; + depths[0].vids = (VisualID *)malloc(MAXVISUALSPERDEPTH * sizeof(VisualID)); + numDepths = 1; + + for (i = 0; i < xnestNumVisuals; i++) { + visuals[numVisuals].class = xnestVisuals[i].class; + visuals[numVisuals].bitsPerRGBValue = xnestVisuals[i].bits_per_rgb; + visuals[numVisuals].ColormapEntries = xnestVisuals[i].colormap_size; + visuals[numVisuals].nplanes = xnestVisuals[i].depth; + visuals[numVisuals].redMask = xnestVisuals[i].red_mask; + visuals[numVisuals].greenMask = xnestVisuals[i].green_mask; + visuals[numVisuals].blueMask = xnestVisuals[i].blue_mask; + visuals[numVisuals].offsetRed = offset(xnestVisuals[i].red_mask); + visuals[numVisuals].offsetGreen = offset(xnestVisuals[i].green_mask); + visuals[numVisuals].offsetBlue = offset(xnestVisuals[i].blue_mask); + + /* Check for and remove duplicates. */ + for (j = 0; j < numVisuals; j++) { + if (visuals[numVisuals].class == visuals[j].class && + visuals[numVisuals].bitsPerRGBValue == visuals[j].bitsPerRGBValue && + visuals[numVisuals].ColormapEntries == visuals[j].ColormapEntries && + visuals[numVisuals].nplanes == visuals[j].nplanes && + visuals[numVisuals].redMask == visuals[j].redMask && + visuals[numVisuals].greenMask == visuals[j].greenMask && + visuals[numVisuals].blueMask == visuals[j].blueMask && + visuals[numVisuals].offsetRed == visuals[j].offsetRed && + visuals[numVisuals].offsetGreen == visuals[j].offsetGreen && + visuals[numVisuals].offsetBlue == visuals[j].offsetBlue) + break; + } + if (j < numVisuals) + break; + + visuals[numVisuals].vid = FakeClientID(0); + + depthIndex = UNDEFINED; + for (j = 0; j < numDepths; j++) + if (depths[j].depth == xnestVisuals[i].depth) { + depthIndex = j; + break; + } + + if (depthIndex == UNDEFINED) { + depthIndex = numDepths; + depths[depthIndex].depth = xnestVisuals[i].depth; + depths[depthIndex].numVids = 0; + depths[depthIndex].vids = + (VisualID *)malloc(MAXVISUALSPERDEPTH * sizeof(VisualID)); + numDepths++; + } + if (depths[depthIndex].numVids >= MAXVISUALSPERDEPTH) { + FatalError("Visual table overflow"); + } + depths[depthIndex].vids[depths[depthIndex].numVids] = + visuals[numVisuals].vid; + depths[depthIndex].numVids++; + + numVisuals++; + } + visuals = (VisualPtr)realloc(visuals, numVisuals * sizeof(VisualRec)); + + defaultVisual = visuals[xnestDefaultVisualIndex].vid; + rootDepth = visuals[xnestDefaultVisualIndex].nplanes; + + if (xnestParentWindow != 0) { + XGetWindowAttributes(xnestDisplay, xnestParentWindow, &gattributes); + xnestWidth = gattributes.width; + xnestHeight = gattributes.height; + } + + /* myNum */ + /* id */ + miScreenInit(pScreen, NULL, xnestWidth, xnestHeight, 1, 1, xnestWidth, + rootDepth, + numDepths, depths, + defaultVisual, /* root visual */ + numVisuals, visuals); + +/* miInitializeBackingStore(pScreen); */ + + pScreen->defColormap = (Colormap) FakeClientID(0); + pScreen->minInstalledCmaps = MINCMAPS; + pScreen->maxInstalledCmaps = MAXCMAPS; + pScreen->backingStoreSupport = NotUseful; + pScreen->saveUnderSupport = NotUseful; + pScreen->whitePixel = xnestWhitePixel; + pScreen->blackPixel = xnestBlackPixel; + /* rgf */ + /* GCperDepth */ + /* PixmapPerDepth */ + pScreen->devPrivate = NULL; + /* WindowPrivateLen */ + /* WindowPrivateSizes */ + /* totalWindowSize */ + /* GCPrivateLen */ + /* GCPrivateSizes */ + /* totalGCSize */ + + /* Random screen procedures */ + + pScreen->QueryBestSize = xnestQueryBestSize; + pScreen->SaveScreen = xnestSaveScreen; + pScreen->GetImage = xnestGetImage; + pScreen->GetSpans = xnestGetSpans; + pScreen->SourceValidate = NULL; + + /* Window Procedures */ + + pScreen->CreateWindow = xnestCreateWindow; + pScreen->DestroyWindow = xnestDestroyWindow; + pScreen->PositionWindow = xnestPositionWindow; + pScreen->ChangeWindowAttributes = xnestChangeWindowAttributes; + pScreen->RealizeWindow = xnestRealizeWindow; + pScreen->UnrealizeWindow = xnestUnrealizeWindow; + pScreen->PostValidateTree = NULL; + pScreen->WindowExposures = xnestWindowExposures; + pScreen->CopyWindow = xnestCopyWindow; + pScreen->ClipNotify = xnestClipNotify; + + /* Pixmap procedures */ + + pScreen->CreatePixmap = xnestCreatePixmap; + pScreen->DestroyPixmap = xnestDestroyPixmap; + + /* Font procedures */ + + pScreen->RealizeFont = xnestRealizeFont; + pScreen->UnrealizeFont = xnestUnrealizeFont; + + /* GC procedures */ + + pScreen->CreateGC = xnestCreateGC; + + /* Colormap procedures */ + + pScreen->CreateColormap = xnestCreateColormap; + pScreen->DestroyColormap = xnestDestroyColormap; + pScreen->InstallColormap = xnestInstallColormap; + pScreen->UninstallColormap = xnestUninstallColormap; + pScreen->ListInstalledColormaps = xnestListInstalledColormaps; + pScreen->StoreColors = xnestStoreColors; + pScreen->ResolveColor = xnestResolveColor; + + pScreen->BitmapToRegion = xnestPixmapToRegion; + + /* OS layer procedures */ + + pScreen->BlockHandler = (ScreenBlockHandlerProcPtr)NoopDDA; + pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr)NoopDDA; + pScreen->blockData = NULL; + pScreen->wakeupData = NULL; + + miDCInitialize(pScreen, &xnestPointerCursorFuncs); /* init SW rendering */ + PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); + xnestCursorFuncs.spriteFuncs = PointPriv->spriteFuncs; + dixSetPrivate(&pScreen->devPrivates, xnestCursorScreenKey, &xnestCursorFuncs); + PointPriv->spriteFuncs = &xnestPointerSpriteFuncs; + + pScreen->mmWidth = xnestWidth * DisplayWidthMM(xnestDisplay, + DefaultScreen(xnestDisplay)) / + DisplayWidth(xnestDisplay, + DefaultScreen(xnestDisplay)); + pScreen->mmHeight = xnestHeight * DisplayHeightMM(xnestDisplay, + DefaultScreen(xnestDisplay)) / + DisplayHeight(xnestDisplay, + DefaultScreen(xnestDisplay)); + + /* overwrite miCloseScreen with our own */ + pScreen->CloseScreen = xnestCloseScreen; + + if (!miScreenDevPrivateInit(pScreen, xnestWidth, NULL)) + return FALSE; + + /* overwrite miSetShape with our own */ + pScreen->SetShape = xnestSetShape; + + /* devPrivates */ + +#define POSITION_OFFSET (pScreen->myNum * (xnestWidth + xnestHeight) / 32) + + if (xnestDoFullGeneration) { + + valuemask = CWBackPixel | CWEventMask | CWColormap; + attributes.background_pixel = xnestWhitePixel; + attributes.event_mask = xnestEventMask; + attributes.colormap = xnestDefaultVisualColormap(xnestDefaultVisual(pScreen)); + + if (xnestParentWindow != 0) { + xnestDefaultWindows[pScreen->myNum] = xnestParentWindow; + XSelectInput (xnestDisplay, xnestDefaultWindows[pScreen->myNum], + xnestEventMask); + } else + xnestDefaultWindows[pScreen->myNum] = + XCreateWindow(xnestDisplay, + DefaultRootWindow(xnestDisplay), + xnestX + POSITION_OFFSET, + xnestY + POSITION_OFFSET, + xnestWidth, xnestHeight, + xnestBorderWidth, + pScreen->rootDepth, + InputOutput, + xnestDefaultVisual(pScreen), + valuemask, &attributes); + + if (!xnestWindowName) + xnestWindowName = argv[0]; + + sizeHints.flags = PPosition | PSize | PMaxSize; + sizeHints.x = xnestX + POSITION_OFFSET; + sizeHints.y = xnestY + POSITION_OFFSET; + sizeHints.width = sizeHints.max_width = xnestWidth; + sizeHints.height = sizeHints.max_height = xnestHeight; + if (xnestUserGeometry & XValue || xnestUserGeometry & YValue) + sizeHints.flags |= USPosition; + if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue) + sizeHints.flags |= USSize; + XSetStandardProperties(xnestDisplay, + xnestDefaultWindows[pScreen->myNum], + xnestWindowName, + xnestWindowName, + xnestIconBitmap, + argv, argc, &sizeHints); + + XMapWindow(xnestDisplay, xnestDefaultWindows[pScreen->myNum]); + + valuemask = CWBackPixmap | CWColormap; + attributes.background_pixmap = xnestScreenSaverPixmap; + attributes.colormap = + DefaultColormap(xnestDisplay, DefaultScreen(xnestDisplay)); + xnestScreenSaverWindows[pScreen->myNum] = + XCreateWindow(xnestDisplay, + xnestDefaultWindows[pScreen->myNum], + 0, 0, xnestWidth, xnestHeight, 0, + DefaultDepth(xnestDisplay, DefaultScreen(xnestDisplay)), + InputOutput, + DefaultVisual(xnestDisplay, DefaultScreen(xnestDisplay)), + valuemask, &attributes); + } + + if (!xnestCreateDefaultColormap(pScreen)) return False; + + return True; +} + +Bool +xnestCloseScreen(int index, ScreenPtr pScreen) +{ + int i; + + for (i = 0; i < pScreen->numDepths; i++) + free(pScreen->allowedDepths[i].vids); + free(pScreen->allowedDepths); + free(pScreen->visuals); + free(pScreen->devPrivate); + + /* + If xnestDoFullGeneration all x resources will be destroyed upon closing + the display connection. There is no need to generate extra protocol. + */ + + return True; +} -- cgit v1.2.3