2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
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 <xnest-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#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"
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
DevPrivateKeyRec xnestColormapPrivateKeyRec;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
static DevPrivateKeyRec cmapScrPrivateKeyRec;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
|
|
|
|
|
|
|
|
#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
|
|
|
|
#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
Bool
|
|
|
|
xnestCreateColormap(ColormapPtr pCmap)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
VisualPtr pVisual;
|
|
|
|
XColor *colors;
|
|
|
|
int i, ncolors;
|
|
|
|
Pixel red, green, blue;
|
|
|
|
Pixel redInc, greenInc, blueInc;
|
|
|
|
|
|
|
|
pVisual = pCmap->pVisual;
|
|
|
|
ncolors = pVisual->ColormapEntries;
|
|
|
|
|
|
|
|
xnestColormapPriv(pCmap)->colormap =
|
|
|
|
XCreateColormap(xnestDisplay,
|
|
|
|
xnestDefaultWindows[pCmap->pScreen->myNum],
|
|
|
|
xnestVisual(pVisual),
|
|
|
|
(pVisual->class & DynamicClass) ? AllocAll : AllocNone);
|
|
|
|
|
|
|
|
switch (pVisual->class) {
|
|
|
|
case StaticGray: /* read only */
|
2016-05-29 06:02:34 -06:00
|
|
|
colors = xallocarray(ncolors, sizeof(XColor));
|
2012-06-10 07:21:05 -06:00
|
|
|
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 */
|
2016-05-29 06:02:34 -06:00
|
|
|
colors = xallocarray(ncolors, sizeof(XColor));
|
2012-06-10 07:21:05 -06:00
|
|
|
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 */
|
2016-05-29 06:02:34 -06:00
|
|
|
colors = xallocarray(ncolors, sizeof(XColor));
|
2012-06-10 07:21:05 -06:00
|
|
|
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;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
return True;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xnestDestroyColormap(ColormapPtr pCmap)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XFreeColormap(xnestDisplay, xnestColormap(pCmap));
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SEARCH_PREDICATE \
|
|
|
|
(xnestWindow(pWin) != None && wColormap(pWin) == icws->cmapIDs[i])
|
|
|
|
|
|
|
|
static int
|
2014-09-27 11:52:59 -06:00
|
|
|
xnestCountInstalledColormapWindows(WindowPtr pWin, void *ptr)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
xnestInstalledColormapWindows *icws = (xnestInstalledColormapWindows *) ptr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < icws->numCmapIDs; i++)
|
|
|
|
if (SEARCH_PREDICATE) {
|
|
|
|
icws->numWindows++;
|
|
|
|
return WT_DONTWALKCHILDREN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WT_WALKCHILDREN;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-27 11:52:59 -06:00
|
|
|
xnestGetInstalledColormapWindows(WindowPtr pWin, void *ptr)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
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;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Window *xnestOldInstalledColormapWindows = NULL;
|
|
|
|
static int xnestNumOldInstalledColormapWindows = 0;
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
xnestSameInstalledColormapWindows(Window *windows, int numWindows)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (xnestNumOldInstalledColormapWindows != numWindows)
|
|
|
|
return False;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (xnestOldInstalledColormapWindows == windows)
|
|
|
|
return True;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (xnestOldInstalledColormapWindows == NULL || windows == NULL)
|
|
|
|
return False;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (memcmp(xnestOldInstalledColormapWindows, windows,
|
|
|
|
numWindows * sizeof(Window)))
|
|
|
|
return False;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
return True;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xnestSetInstalledColormapWindows(ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
xnestInstalledColormapWindows icws;
|
|
|
|
int numWindows;
|
|
|
|
|
2016-05-29 06:02:34 -06:00
|
|
|
icws.cmapIDs = xallocarray(pScreen->maxInstalledCmaps, sizeof(Colormap));
|
2012-06-10 07:21:05 -06:00
|
|
|
icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs);
|
|
|
|
icws.numWindows = 0;
|
2014-09-27 11:52:59 -06:00
|
|
|
WalkTree(pScreen, xnestCountInstalledColormapWindows, (void *) &icws);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (icws.numWindows) {
|
2016-05-29 06:02:34 -06:00
|
|
|
icws.windows = xallocarray(icws.numWindows + 1, sizeof(Window));
|
2012-06-10 07:21:05 -06:00
|
|
|
icws.index = 0;
|
2014-09-27 11:52:59 -06:00
|
|
|
WalkTree(pScreen, xnestGetInstalledColormapWindows, (void *) &icws);
|
2012-06-10 07:21:05 -06:00
|
|
|
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)) {
|
|
|
|
free(xnestOldInstalledColormapWindows);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifdef _XSERVER64
|
2012-06-10 07:21:05 -06:00
|
|
|
{
|
|
|
|
int i;
|
2016-05-29 06:02:34 -06:00
|
|
|
Window64 *windows = xallocarray(numWindows, sizeof(Window64));
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
for (i = 0; i < numWindows; ++i)
|
|
|
|
windows[i] = icws.windows[i];
|
|
|
|
XSetWMColormapWindows(xnestDisplay,
|
|
|
|
xnestDefaultWindows[pScreen->myNum], windows,
|
|
|
|
numWindows);
|
|
|
|
free(windows);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#else
|
2012-06-10 07:21:05 -06:00
|
|
|
XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
|
|
|
|
icws.windows, numWindows);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
xnestOldInstalledColormapWindows = icws.windows;
|
|
|
|
xnestNumOldInstalledColormapWindows = icws.numWindows;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifdef DUMB_WINDOW_MANAGERS
|
2015-09-16 13:10:19 -06:00
|
|
|
/*
|
2012-06-10 07:21:05 -06:00
|
|
|
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))
|
2014-09-27 11:52:59 -06:00
|
|
|
dixLookupResourceByType((void **) &pCmap, wColormap(pWin),
|
2012-06-10 07:21:05 -06:00
|
|
|
RT_COLORMAP, serverClient,
|
|
|
|
DixUseAccess);
|
|
|
|
else
|
2014-09-27 11:52:59 -06:00
|
|
|
dixLookupResourceByType((void **) &pCmap,
|
2012-06-10 07:21:05 -06:00
|
|
|
pScreen->defColormap, RT_COLORMAP,
|
|
|
|
serverClient, DixUseAccess);
|
|
|
|
|
|
|
|
XSetWindowColormap(xnestDisplay,
|
|
|
|
xnestDefaultWindows[pScreen->myNum],
|
|
|
|
xnestColormap(pCmap));
|
|
|
|
}
|
|
|
|
#endif /* DUMB_WINDOW_MANAGERS */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
free(icws.windows);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xnestSetScreenSaverColormapWindow(ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
free(xnestOldInstalledColormapWindows);
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef _XSERVER64
|
2012-06-10 07:21:05 -06:00
|
|
|
{
|
|
|
|
Window64 window;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
window = xnestScreenSaverWindows[pScreen->myNum];
|
|
|
|
XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
|
|
|
|
&window, 1);
|
|
|
|
xnestScreenSaverWindows[pScreen->myNum] = window;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#else
|
2012-06-10 07:21:05 -06:00
|
|
|
XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
|
|
|
|
&xnestScreenSaverWindows[pScreen->myNum], 1);
|
|
|
|
#endif /* _XSERVER64 */
|
|
|
|
|
|
|
|
xnestOldInstalledColormapWindows = NULL;
|
|
|
|
xnestNumOldInstalledColormapWindows = 0;
|
|
|
|
|
|
|
|
xnestDirectUninstallColormaps(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xnestDirectInstallColormaps(ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i, n;
|
|
|
|
Colormap pCmapIDs[MAXCMAPS];
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!xnestDoDirectColormaps)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
n = (*pScreen->ListInstalledColormaps) (pScreen, pCmapIDs);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
ColormapPtr pCmap;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
dixLookupResourceByType((void **) &pCmap, pCmapIDs[i], RT_COLORMAP,
|
2012-06-10 07:21:05 -06:00
|
|
|
serverClient, DixInstallAccess);
|
|
|
|
if (pCmap)
|
|
|
|
XInstallColormap(xnestDisplay, xnestColormap(pCmap));
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xnestDirectUninstallColormaps(ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i, n;
|
|
|
|
Colormap pCmapIDs[MAXCMAPS];
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!xnestDoDirectColormaps)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
n = (*pScreen->ListInstalledColormaps) (pScreen, pCmapIDs);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
ColormapPtr pCmap;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
dixLookupResourceByType((void **) &pCmap, pCmapIDs[i], RT_COLORMAP,
|
2012-06-10 07:21:05 -06:00
|
|
|
serverClient, DixUninstallAccess);
|
|
|
|
if (pCmap)
|
|
|
|
XUninstallColormap(xnestDisplay, xnestColormap(pCmap));
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xnestInstallColormap(ColormapPtr pCmap)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
ColormapPtr pOldCmap = GetInstalledColormap(pCmap->pScreen);
|
|
|
|
|
|
|
|
if (pCmap != pOldCmap) {
|
|
|
|
xnestDirectUninstallColormaps(pCmap->pScreen);
|
|
|
|
|
|
|
|
/* Uninstall pInstalledMap. Notify all interested parties. */
|
|
|
|
if (pOldCmap != (ColormapPtr) None)
|
2014-09-27 11:52:59 -06:00
|
|
|
WalkTree(pCmap->pScreen, TellLostMap, (void *) &pOldCmap->mid);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
SetInstalledColormap(pCmap->pScreen, pCmap);
|
2014-09-27 11:52:59 -06:00
|
|
|
WalkTree(pCmap->pScreen, TellGainedMap, (void *) &pCmap->mid);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
xnestSetInstalledColormapWindows(pCmap->pScreen);
|
|
|
|
xnestDirectInstallColormaps(pCmap->pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xnestUninstallColormap(ColormapPtr pCmap)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
ColormapPtr pCurCmap = GetInstalledColormap(pCmap->pScreen);
|
|
|
|
|
|
|
|
if (pCmap == pCurCmap) {
|
|
|
|
if (pCmap->mid != pCmap->pScreen->defColormap) {
|
2014-09-27 11:52:59 -06:00
|
|
|
dixLookupResourceByType((void **) &pCurCmap,
|
2012-06-10 07:21:05 -06:00
|
|
|
pCmap->pScreen->defColormap,
|
|
|
|
RT_COLORMAP,
|
|
|
|
serverClient, DixInstallAccess);
|
|
|
|
(*pCmap->pScreen->InstallColormap) (pCurCmap);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool xnestInstalledDefaultColormap = False;
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
xnestListInstalledColormaps(ScreenPtr pScreen, Colormap * pCmapIDs)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (xnestInstalledDefaultColormap) {
|
|
|
|
*pCmapIDs = GetInstalledColormap(pScreen)->mid;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
xnestStoreColors(ColormapPtr pCmap, int nColors, xColorItem * pColors)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pCmap->pVisual->class & DynamicClass)
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef _XSERVER64
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i;
|
2016-05-29 06:02:34 -06:00
|
|
|
XColor *pColors64 = xallocarray(nColors, sizeof(XColor));
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
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);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
#else
|
2012-06-10 07:21:05 -06:00
|
|
|
XStoreColors(xnestDisplay, xnestColormap(pCmap),
|
|
|
|
(XColor *) pColors, nColors);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xnestResolveColor(unsigned short *pRed, unsigned short *pGreen,
|
2012-06-10 07:21:05 -06:00
|
|
|
unsigned short *pBlue, VisualPtr pVisual)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int shift;
|
|
|
|
unsigned int lim;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
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;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
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;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
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;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
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;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
xnestCreateDefaultColormap(ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
VisualPtr pVisual;
|
|
|
|
ColormapPtr pCmap;
|
|
|
|
unsigned short zero = 0, ones = 0xFFFF;
|
|
|
|
Pixel wp, bp;
|
|
|
|
|
|
|
|
if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
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;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|