#ifdef HAVE_DMX_CONFIG_H
#include <dmx-config.h>
#endif
#include "dmx.h"
#include "dmxinit.h"
#include "dmxextension.h"
#include "dmxwindow.h"
#include "dmxcb.h"
#include "dmxcursor.h"
#include "dmxpixmap.h"
#include "dmxgc.h"
#include "dmxfont.h"
#include "dmxcmap.h"
#ifdef RENDER
#include "dmxpict.h"
#endif
#include "dmxinput.h"
#include "dmxsync.h"
#include "dmxscrinit.h"
#include "input/dmxinputinit.h"
#include "windowstr.h"
#include "inputstr.h"
#include <X11/extensions/dmxproto.h>
#include "cursorstr.h"
#undef Xmalloc
#undef Xcalloc
#undef Xrealloc
#undef Xfree
extern FontPtr defaultFont;
Bool dmxGetScreenAttributes(int physical, DMXScreenAttributesPtr attr)
{
DMXScreenInfo *dmxScreen;
if (physical < 0 || physical >= dmxNumScreens) return FALSE;
dmxScreen = &dmxScreens[physical];
attr->displayName = dmxScreen->name;
#ifdef PANORAMIX
attr->logicalScreen = noPanoramiXExtension ? dmxScreen->index : 0;
#else
attr->logicalScreen = dmxScreen->index;
#endif
attr->screenWindowWidth = dmxScreen->scrnWidth;
attr->screenWindowHeight = dmxScreen->scrnHeight;
attr->screenWindowXoffset = dmxScreen->scrnX;
attr->screenWindowYoffset = dmxScreen->scrnY;
attr->rootWindowWidth = dmxScreen->rootWidth;
attr->rootWindowHeight = dmxScreen->rootHeight;
attr->rootWindowXoffset = dmxScreen->rootX;
attr->rootWindowYoffset = dmxScreen->rootY;
attr->rootWindowXorigin = dmxScreen->rootXOrigin;
attr->rootWindowYorigin = dmxScreen->rootYOrigin;
return TRUE;
}
Bool dmxGetWindowAttributes(WindowPtr pWindow, DMXWindowAttributesPtr attr)
{
dmxWinPrivPtr pWinPriv = DMX_GET_WINDOW_PRIV(pWindow);
attr->screen = pWindow->drawable.pScreen->myNum;
attr->window = pWinPriv->window;
attr->pos.x = pWindow->drawable.x;
attr->pos.y = pWindow->drawable.y;
attr->pos.width = pWindow->drawable.width;
attr->pos.height = pWindow->drawable.height;
if (!pWinPriv->window || pWinPriv->offscreen) {
attr->vis.x = 0;
attr->vis.y = 0;
attr->vis.height = 0;
attr->vis.width = 0;
return pWinPriv->window ? TRUE : FALSE;
}
attr->vis.x = pWindow->drawable.x;
attr->vis.y = pWindow->drawable.y;
attr->vis.width = pWindow->drawable.width;
attr->vis.height = pWindow->drawable.height;
if (attr->pos.x < 0) {
attr->vis.x -= attr->pos.x;
attr->vis.width = attr->pos.x + attr->pos.width - attr->vis.x;
}
if (attr->pos.x + attr->pos.width > pWindow->drawable.pScreen->width) {
if (attr->pos.x < 0)
attr->vis.width = pWindow->drawable.pScreen->width;
else
attr->vis.width = pWindow->drawable.pScreen->width - attr->pos.x;
}
if (attr->pos.y < 0) {
attr->vis.y -= attr->pos.y;
attr->vis.height = attr->pos.y + attr->pos.height - attr->vis.y;
}
if (attr->pos.y + attr->pos.height > pWindow->drawable.pScreen->height) {
if (attr->pos.y < 0)
attr->vis.height = pWindow->drawable.pScreen->height;
else
attr->vis.height = pWindow->drawable.pScreen->height - attr->pos.y;
}
attr->vis.x -= attr->pos.x;
attr->vis.y -= attr->pos.y;
return TRUE;
}
void dmxGetDesktopAttributes(DMXDesktopAttributesPtr attr)
{
attr->width = dmxGlobalWidth;
attr->height = dmxGlobalHeight;
attr->shiftX = 0;
attr->shiftY = 0;
}
int dmxGetInputCount(void)
{
int i, total;
for (total = i = 0; i < dmxNumInputs; i++) total += dmxInputs[i].numDevs;
return total;
}
int dmxGetInputAttributes(int deviceId, DMXInputAttributesPtr attr)
{
int i, j;
DMXInputInfo *dmxInput;
if (deviceId < 0) return -1;
for (i = 0; i < dmxNumInputs; i++) {
dmxInput = &dmxInputs[i];
for (j = 0; j < dmxInput->numDevs; j++) {
DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[j];
if (deviceId != dmxLocal->pDevice->id) continue;
attr->isCore = !!dmxLocal->isCore;
attr->sendsCore = !!dmxLocal->sendsCore;
attr->detached = !!dmxInput->detached;
attr->physicalScreen = -1;
attr->physicalId = -1;
attr->name = NULL;
switch (dmxLocal->extType) {
case DMX_LOCAL_TYPE_LOCAL:
attr->inputType = 0;
break;
case DMX_LOCAL_TYPE_CONSOLE:
attr->inputType = 1;
attr->name = dmxInput->name;
attr->physicalId = dmxLocal->deviceId;
break;
case DMX_LOCAL_TYPE_BACKEND:
case DMX_LOCAL_TYPE_COMMON:
attr->inputType = 2;
attr->physicalScreen = dmxInput->scrnIdx;
attr->name = dmxInput->name;
attr->physicalId = dmxLocal->deviceId;
break;
}
return 0;
}
}
return -1;
}
static void dmxAdjustCursorBoundaries(void)
{
int i;
dmxReInitOrigins();
dmxInitOverlap();
dmxComputeWidthHeight(DMX_NO_RECOMPUTE_BOUNDING_BOX);
dmxConnectionBlockCallback();
for (i = 0; i < dmxNumInputs; i++) {
DMXInputInfo *dmxInput = &dmxInputs[i];
if (!dmxInput->detached) dmxInputReInit(dmxInput);
}
dmxCheckCursor();
for (i = 0; i < dmxNumInputs; i++) {
DMXInputInfo *dmxInput = &dmxInputs[i];
if (!dmxInput->detached) dmxInputLateReInit(dmxInput);
}
}
int dmxAddInput(DMXInputAttributesPtr attr, int *id)
{
int retcode = BadValue;
if (attr->inputType == 1)
retcode = dmxInputAttachConsole(attr->name, attr->sendsCore, id);
else if (attr->inputType == 2)
retcode = dmxInputAttachBackend(attr->physicalScreen,
attr->sendsCore,id);
if (retcode == Success) {
dmxAdjustCursorBoundaries();
dmxSync(NULL, TRUE);
}
return retcode;
}
int dmxRemoveInput(int id)
{
return dmxInputDetachId(id);
}
unsigned long dmxGetNumScreens(void)
{
return dmxNumScreens;
}
void dmxForceWindowCreation(WindowPtr pWindow)
{
dmxWinPrivPtr pWinPriv = DMX_GET_WINDOW_PRIV(pWindow);
if (!pWinPriv->window) dmxCreateAndRealizeWindow(pWindow, TRUE);
}
void dmxFlushPendingSyncs(void)
{
dmxSync(NULL, TRUE);
}
void dmxUpdateScreenResources(ScreenPtr pScreen, int x, int y, int w, int h)
{
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
WindowPtr pRoot = WindowTable[pScreen->myNum];
WindowPtr pChild;
Bool anyMarked = FALSE;
if (w == 0 || h == 0) {
w = 1;
h = 1;
}
pScreen->width = w;
pScreen->height = h;
pRoot->drawable.width = w;
pRoot->drawable.height = h;
pRoot->winSize.extents.x1 = 0;
pRoot->winSize.extents.y1 = 0;
pRoot->winSize.extents.x2 = w;
pRoot->winSize.extents.y2 = h;
pRoot->borderSize.extents.x1 = 0;
pRoot->borderSize.extents.y1 = 0;
pRoot->borderSize.extents.x2 = w;
pRoot->borderSize.extents.y2 = h;
pScreen->mmWidth =
(w * 254 + dmxScreen->beXDPI * 5) / (dmxScreen->beXDPI * 10);
pScreen->mmHeight =
(h * 254 + dmxScreen->beYDPI * 5) / (dmxScreen->beYDPI * 10);
for (pChild = pRoot->firstChild; pChild; pChild = pChild->nextSib)
anyMarked |= pScreen->MarkOverlappedWindows(pChild, pChild,
(WindowPtr *)NULL);
pRoot->borderClip.extents.x1 = 0;
pRoot->borderClip.extents.y1 = 0;
pRoot->borderClip.extents.x2 = w;
pRoot->borderClip.extents.y2 = h;
if (anyMarked) {
REGION_BREAK(pScreen, &pRoot->clipList);
} else {
pRoot->clipList.extents.x1 = 0;
pRoot->clipList.extents.y1 = 0;
pRoot->clipList.extents.x2 = w;
pRoot->clipList.extents.y2 = h;
}
if (anyMarked) {
pScreen->ValidateTree(pRoot, NULL, VTBroken);
pScreen->HandleExposures(pRoot);
if (pScreen->PostValidateTree)
pScreen->PostValidateTree(pRoot, NULL, VTBroken);
}
}
#ifdef PANORAMIX
#include "panoramiXsrv.h"
static void dmxConfigureScreenWindow(int idx,
int x, int y, int w, int h)
{
DMXScreenInfo *dmxScreen = &dmxScreens[idx];
ScreenPtr pScreen = screenInfo.screens[idx];
if (dmxScreen->scrnX != x ||
dmxScreen->scrnY != y ||
dmxScreen->scrnWidth != w ||
dmxScreen->scrnHeight != h) {
dmxResizeScreenWindow(pScreen, x, y, w, h);
}
dmxScreen->scrnX = x;
dmxScreen->scrnY = y;
dmxScreen->scrnWidth = w;
dmxScreen->scrnHeight = h;
}
static void dmxConfigureRootWindow(int idx, int x, int y, int w, int h)
{
DMXScreenInfo *dmxScreen = &dmxScreens[idx];
WindowPtr pRoot = WindowTable[idx];
if (dmxScreen->rootX != x ||
dmxScreen->rootY != y ||
dmxScreen->rootWidth != w ||
dmxScreen->rootHeight != h) {
dmxResizeRootWindow(pRoot, x, y, w, h);
}
if (dmxScreen->rootWidth != w ||
dmxScreen->rootHeight != h) {
dmxUpdateScreenResources(screenInfo.screens[idx], x, y, w, h);
}
dmxScreen->rootX = x;
dmxScreen->rootY = y;
dmxScreen->rootWidth = w;
dmxScreen->rootHeight = h;
}
static void dmxSetRootWindowOrigin(int idx, int x, int y)
{
DMXScreenInfo *dmxScreen = &dmxScreens[idx];
ScreenPtr pScreen = screenInfo.screens[idx];
WindowPtr pRoot = WindowTable[idx];
WindowPtr pChild;
int xoff;
int yoff;
dmxScreen->rootXOrigin = x;
dmxScreen->rootYOrigin = y;
xoff = x - dixScreenOrigins[idx].x;
yoff = y - dixScreenOrigins[idx].y;
dixScreenOrigins[idx].x = dmxScreen->rootXOrigin;
dixScreenOrigins[idx].y = dmxScreen->rootYOrigin;
XineramaReinitData(pScreen);
if (!idx) ReinitializeRootWindow(WindowTable[0], xoff, yoff);
pChild = pRoot->firstChild;
while (pChild) {
pScreen->MoveWindow(pChild,
pChild->origin.x - wBorderWidth(pChild) - xoff,
pChild->origin.y - wBorderWidth(pChild) - yoff,
pChild->nextSib,
VTMove);
pChild = pChild->nextSib;
}
}
int dmxConfigureScreenWindows(int nscreens,
CARD32 *screens,
DMXScreenAttributesPtr attribs,
int *errorScreen)
{
int i;
for (i = 0; i < nscreens; i++) {
DMXScreenAttributesPtr attr = &attribs[i];
int idx = screens[i];
DMXScreenInfo *dmxScreen = &dmxScreens[idx];
if (errorScreen) *errorScreen = i;
if (!dmxScreen->beDisplay) return DMX_BAD_VALUE;
if (idx < 0 || idx >= dmxNumScreens) return BadValue;
if (attr->screenWindowWidth <= 0 || attr->screenWindowHeight <= 0 ||
attr->rootWindowWidth < 0 || attr->rootWindowHeight < 0)
return DMX_BAD_VALUE;
if (attr->screenWindowXoffset < 0 ||
attr->screenWindowYoffset < 0 ||
attr->screenWindowXoffset
+ attr->screenWindowWidth > (unsigned)dmxScreen->beWidth ||
attr->screenWindowYoffset
+ attr->screenWindowHeight > (unsigned)dmxScreen->beHeight)
return DMX_BAD_VALUE;
if (attr->rootWindowXoffset < 0 ||
attr->rootWindowYoffset < 0 ||
attr->rootWindowXoffset
+ attr->rootWindowWidth > attr->screenWindowWidth ||
attr->rootWindowYoffset
+ attr->rootWindowHeight > attr->screenWindowHeight)
return DMX_BAD_VALUE;
if (attr->rootWindowXorigin < 0 ||
attr->rootWindowYorigin < 0 ||
attr->rootWindowXorigin + attr->rootWindowWidth > 32767 ||
attr->rootWindowYorigin + attr->rootWindowHeight > 32767)
return DMX_BAD_VALUE;
if (attr->rootWindowXorigin
+ attr->rootWindowWidth > (unsigned)dmxGlobalWidth ||
attr->rootWindowYorigin
+ attr->rootWindowHeight > (unsigned)dmxGlobalHeight)
return DMX_BAD_VALUE;
}
if (errorScreen) *errorScreen = 0;
for (i = 0; i < nscreens; i++) {
DMXScreenAttributesPtr attr = &attribs[i];
int idx = screens[i];
DMXScreenInfo *dmxScreen = &dmxScreens[idx];
dmxLog(dmxInfo, "Changing screen #%d attributes "
"from %dx%d+%d+%d %dx%d+%d+%d +%d+%d "
"to %dx%d+%d+%d %dx%d+%d+%d +%d+%d\n",
idx,
dmxScreen->scrnWidth, dmxScreen->scrnHeight,
dmxScreen->scrnX, dmxScreen->scrnY,
dmxScreen->rootWidth, dmxScreen->rootHeight,
dmxScreen->rootX, dmxScreen->rootY,
dmxScreen->rootXOrigin, dmxScreen->rootYOrigin,
attr->screenWindowWidth, attr->screenWindowHeight,
attr->screenWindowXoffset, attr->screenWindowYoffset,
attr->rootWindowWidth, attr->rootWindowHeight,
attr->rootWindowXoffset, attr->rootWindowYoffset,
attr->rootWindowXorigin, attr->rootWindowYorigin);
dmxConfigureScreenWindow(idx,
attr->screenWindowXoffset,
attr->screenWindowYoffset,
attr->screenWindowWidth,
attr->screenWindowHeight);
dmxConfigureRootWindow(idx,
attr->rootWindowXoffset,
attr->rootWindowYoffset,
attr->rootWindowWidth,
attr->rootWindowHeight);
dmxSetRootWindowOrigin(idx,
attr->rootWindowXorigin,
attr->rootWindowYorigin);
}
dmxAdjustCursorBoundaries();
dmxSync(NULL, TRUE);
return Success;
}
int dmxConfigureDesktop(DMXDesktopAttributesPtr attribs)
{
if (attribs->width <= 0 || attribs->width >= 32767 ||
attribs->height <= 0 || attribs->height >= 32767)
return DMX_BAD_VALUE;
if (attribs->width < dmxGlobalWidth || attribs->height < dmxGlobalHeight) {
int i;
for (i = 0; i < dmxNumScreens; i++) {
DMXScreenInfo *dmxScreen = &dmxScreens[i];
if (dmxScreen->rootXOrigin
+ dmxScreen->rootWidth > attribs->width ||
dmxScreen->rootYOrigin
+ dmxScreen->rootHeight > attribs->height) {
int w, h;
if ((w = attribs->width - dmxScreen->rootXOrigin) < 0) w = 0;
if ((h = attribs->height - dmxScreen->rootYOrigin) < 0) h = 0;
if (w > dmxScreen->scrnWidth) w = dmxScreen->scrnWidth;
if (h > dmxScreen->scrnHeight) h = dmxScreen->scrnHeight;
if (w > dmxScreen->rootWidth) w = dmxScreen->rootWidth;
if (h > dmxScreen->rootHeight) h = dmxScreen->rootHeight;
dmxConfigureRootWindow(i,
dmxScreen->rootX,
dmxScreen->rootY,
w, h);
}
}
}
dmxSetWidthHeight(attribs->width, attribs->height);
if (attribs->shiftX || attribs->shiftY) {
int i;
for (i = 0; i < dmxNumScreens; i++) {
ScreenPtr pScreen = screenInfo.screens[i];
WindowPtr pChild = WindowTable[i]->firstChild;
while (pChild) {
pScreen->MoveWindow(pChild,
pChild->origin.x - wBorderWidth(pChild)
- attribs->shiftX,
pChild->origin.y - wBorderWidth(pChild)
- attribs->shiftY,
pChild->nextSib,
VTMove);
pChild = pChild->nextSib;
}
}
}
dmxAdjustCursorBoundaries();
dmxSync(NULL, TRUE);
return Success;
}
#endif
static void dmxBECreateScratchGCs(int scrnNum)
{
ScreenPtr pScreen = screenInfo.screens[scrnNum];
GCPtr *ppGC = pScreen->GCperDepth;
int i;
for (i = 0; i <= pScreen->numDepths; i++)
dmxBECreateGC(pScreen, ppGC[i]);
}
#ifdef PANORAMIX
static Bool FoundPixImage;
static void dmxBERestorePixmapImage(pointer value, XID id, RESTYPE type,
pointer p)
{
if ((type & TypeMask) == (XRT_PIXMAP & TypeMask)) {
PixmapPtr pDst = (PixmapPtr)p;
int idx = pDst->drawable.pScreen->myNum;
PanoramiXRes *pXinPix = (PanoramiXRes *)value;
PixmapPtr pPix;
int i;
pPix = (PixmapPtr)LookupIDByType(pXinPix->info[idx].id, RT_PIXMAP);
if (pPix != pDst) return;
for (i = 0; i < PanoramiXNumScreens; i++) {
PixmapPtr pSrc;
dmxPixPrivPtr pSrcPriv = NULL;
if (i == idx) continue;
pSrc =
(PixmapPtr)LookupIDByType(pXinPix->info[i].id, RT_PIXMAP);
pSrcPriv = DMX_GET_PIXMAP_PRIV(pSrc);
if (pSrcPriv->pixmap) {
DMXScreenInfo *dmxSrcScreen = &dmxScreens[i];
DMXScreenInfo *dmxDstScreen = &dmxScreens[idx];
dmxPixPrivPtr pDstPriv = DMX_GET_PIXMAP_PRIV(pDst);
XImage *img;
int j;
XlibGC gc = NULL;
if (pSrc->drawable.width != pDst->drawable.width ||
pSrc->drawable.height != pDst->drawable.height)
return;
img = XGetImage(dmxSrcScreen->beDisplay,
pSrcPriv->pixmap,
0, 0,
pSrc->drawable.width, pSrc->drawable.height,
-1,
ZPixmap);
for (j = 0; j < dmxDstScreen->beNumPixmapFormats; j++) {
if (dmxDstScreen->bePixmapFormats[j].depth == img->depth) {
unsigned long m;
XGCValues v;
m = GCFunction | GCPlaneMask | GCClipMask;
v.function = GXcopy;
v.plane_mask = AllPlanes;
v.clip_mask = None;
gc = XCreateGC(dmxDstScreen->beDisplay,
dmxDstScreen->scrnDefDrawables[j],
m, &v);
break;
}
}
if (gc) {
XPutImage(dmxDstScreen->beDisplay,
pDstPriv->pixmap,
gc, img, 0, 0, 0, 0,
pDst->drawable.width, pDst->drawable.height);
XFreeGC(dmxDstScreen->beDisplay, gc);
FoundPixImage = True;
} else {
dmxLog(dmxWarning, "Could not create GC\n");
}
XDestroyImage(img);
return;
}
}
}
}
#endif
static void dmxBERestorePixmap(PixmapPtr pPixmap)
{
#ifdef PANORAMIX
int i;
if (noPanoramiXExtension) {
dmxLog(dmxWarning, "Cannot restore pixmap image\n");
return;
}
FoundPixImage = False;
for (i = currentMaxClients; --i >= 0; )
if (clients[i])
FindAllClientResources(clients[i], dmxBERestorePixmapImage,
(pointer)pPixmap);
if (!FoundPixImage) {
dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pPixmap);
if (pPixPriv->detachedImage) {
ScreenPtr pScreen = pPixmap->drawable.pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
XlibGC gc = NULL;
for (i = 0; i < dmxScreen->beNumPixmapFormats; i++) {
if (dmxScreen->bePixmapFormats[i].depth ==
pPixPriv->detachedImage->depth) {
unsigned long m;
XGCValues v;
m = GCFunction | GCPlaneMask | GCClipMask;
v.function = GXcopy;
v.plane_mask = AllPlanes;
v.clip_mask = None;
gc = XCreateGC(dmxScreen->beDisplay,
dmxScreen->scrnDefDrawables[i],
m, &v);
break;
}
}
if (gc) {
XPutImage(dmxScreen->beDisplay,
pPixPriv->pixmap,
gc,
pPixPriv->detachedImage,
0, 0, 0, 0,
pPixmap->drawable.width, pPixmap->drawable.height);
XFreeGC(dmxScreen->beDisplay, gc);
} else {
dmxLog(dmxWarning, "Cannot restore pixmap image\n");
}
XDestroyImage(pPixPriv->detachedImage);
pPixPriv->detachedImage = NULL;
} else {
dmxLog(dmxWarning, "Cannot restore pixmap image\n");
}
}
#else
dmxLog(dmxWarning, "Cannot restore pixmap image\n");
return;
#endif
}
static void dmxBECreateResources(pointer value, XID id, RESTYPE type,
pointer n)
{
int scrnNum = (int)n;
ScreenPtr pScreen = screenInfo.screens[scrnNum];
if ((type & TypeMask) == (RT_WINDOW & TypeMask)) {
} else if ((type & TypeMask) == (RT_PIXMAP & TypeMask)) {
PixmapPtr pPix = value;
if (pPix->drawable.pScreen->myNum == scrnNum) {
dmxBECreatePixmap(pPix);
dmxBERestorePixmap(pPix);
}
} else if ((type & TypeMask) == (RT_GC & TypeMask)) {
GCPtr pGC = value;
if (pGC->pScreen->myNum == scrnNum) {
dmxBECreateGC(pScreen, pGC);
if (!pGC->tileIsPixel) {
dmxBECreatePixmap(pGC->tile.pixmap);
dmxBERestorePixmap(pGC->tile.pixmap);
}
if (pGC->stipple != pScreen->PixmapPerDepth[0]) {
dmxBECreatePixmap(pGC->stipple);
dmxBERestorePixmap(pGC->stipple);
}
if (pGC->font != defaultFont) {
(void)dmxBELoadFont(pScreen, pGC->font);
}
dmxChangeGC(pGC, -1L);
}
} else if ((type & TypeMask) == (RT_FONT & TypeMask)) {
(void)dmxBELoadFont(pScreen, (FontPtr)value);
} else if ((type & TypeMask) == (RT_CURSOR & TypeMask)) {
dmxBECreateCursor(pScreen, (CursorPtr)value);
} else if ((type & TypeMask) == (RT_COLORMAP & TypeMask)) {
ColormapPtr pCmap = value;
if (pCmap->pScreen->myNum == scrnNum)
(void)dmxBECreateColormap((ColormapPtr)value);
#if 0
#ifdef RENDER
} else if ((type & TypeMask) == (PictureType & TypeMask)) {
} else if ((type & TypeMask) == (GlyphSetType & TypeMask)) {
dmxBEFreeGlyphSet(pScreen, (GlyphSetPtr)value);
#endif
#endif
} else {
}
}
static void dmxBECreateWindowTree(int idx)
{
DMXScreenInfo *dmxScreen = &dmxScreens[idx];
WindowPtr pRoot = WindowTable[idx];
dmxWinPrivPtr pWinPriv = DMX_GET_WINDOW_PRIV(pRoot);
WindowPtr pWin;
if (!pRoot->borderIsPixel) {
dmxBECreatePixmap(pRoot->border.pixmap);
dmxBERestorePixmap(pRoot->border.pixmap);
}
if (pRoot->backgroundState == BackgroundPixmap) {
dmxBECreatePixmap(pRoot->background.pixmap);
dmxBERestorePixmap(pRoot->background.pixmap);
}
dmxScreen->rootWin = pWinPriv->window = dmxCreateRootWindow(pRoot);
XMapWindow(dmxScreen->beDisplay, dmxScreen->rootWin);
pWin = pRoot->lastChild;
while (pWin) {
pWinPriv = DMX_GET_WINDOW_PRIV(pWin);
if (!pWin->borderIsPixel) {
dmxBECreatePixmap(pWin->border.pixmap);
dmxBERestorePixmap(pWin->border.pixmap);
}
if (pWin->backgroundState == BackgroundPixmap) {
dmxBECreatePixmap(pWin->background.pixmap);
dmxBERestorePixmap(pWin->background.pixmap);
}
dmxGetDefaultWindowAttributes(pWin,
&pWinPriv->cmap,
&pWinPriv->visual);
if (pWinPriv->mapped && !pWinPriv->offscreen)
dmxCreateAndRealizeWindow(pWin, TRUE);
if (pWin->lastChild) {
pWin = pWin->lastChild;
continue;
}
while (!pWin->prevSib && (pWin != pRoot))
pWin = pWin->parent;
if (pWin->prevSib) {
pWin = pWin->prevSib;
continue;
}
if (pWin == pRoot)
break;
}
}
static void dmxForceExposures(int idx)
{
ScreenPtr pScreen = screenInfo.screens[idx];
WindowPtr pRoot = WindowTable[idx];
Bool anyMarked = FALSE;
WindowPtr pChild;
for (pChild = pRoot->firstChild; pChild; pChild = pChild->nextSib)
anyMarked |= pScreen->MarkOverlappedWindows(pChild, pChild,
(WindowPtr *)NULL);
if (anyMarked) {
REGION_BREAK(pScreen, &pRoot->clipList);
pScreen->ValidateTree(pRoot, NULL, VTBroken);
pScreen->HandleExposures(pRoot);
if (pScreen->PostValidateTree)
pScreen->PostValidateTree(pRoot, NULL, VTBroken);
}
}
static Bool dmxCompareScreens(DMXScreenInfo *new, DMXScreenInfo *old)
{
int i;
if (new->beWidth != old->beWidth) return FALSE;
if (new->beHeight != old->beHeight) return FALSE;
if (new->beDepth != old->beDepth) return FALSE;
if (new->beBPP != old->beBPP) return FALSE;
if (new->beNumDepths != old->beNumDepths) return FALSE;
for (i = 0; i < old->beNumDepths; i++)
if (new->beDepths[i] != old->beDepths[i]) return FALSE;
if (new->beNumPixmapFormats != old->beNumPixmapFormats) return FALSE;
for (i = 0; i < old->beNumPixmapFormats; i++) {
if (new->bePixmapFormats[i].depth !=
old->bePixmapFormats[i].depth) return FALSE;
if (new->bePixmapFormats[i].bits_per_pixel !=
old->bePixmapFormats[i].bits_per_pixel) return FALSE;
if (new->bePixmapFormats[i].scanline_pad !=
old->bePixmapFormats[i].scanline_pad) return FALSE;
}
if (new->beNumVisuals != old->beNumVisuals) return FALSE;
for (i = 0; i < old->beNumVisuals; i++) {
if (new->beVisuals[i].visualid !=
old->beVisuals[i].visualid) return FALSE;
if (new->beVisuals[i].screen !=
old->beVisuals[i].screen) return FALSE;
if (new->beVisuals[i].depth !=
old->beVisuals[i].depth) return FALSE;
if (new->beVisuals[i].class !=
old->beVisuals[i].class) return FALSE;
if (new->beVisuals[i].red_mask !=
old->beVisuals[i].red_mask) return FALSE;
if (new->beVisuals[i].green_mask !=
old->beVisuals[i].green_mask) return FALSE;
if (new->beVisuals[i].blue_mask !=
old->beVisuals[i].blue_mask) return FALSE;
if (new->beVisuals[i].colormap_size !=
old->beVisuals[i].colormap_size) return FALSE;
if (new->beVisuals[i].bits_per_rgb !=
old->beVisuals[i].bits_per_rgb) return FALSE;
}
if (new->beDefVisualIndex != old->beDefVisualIndex) return FALSE;
return TRUE;
}
#ifdef RENDER
static void dmxBERestoreRenderPict(pointer value, XID id, pointer n)
{
PicturePtr pPicture = value;
DrawablePtr pDraw = pPicture->pDrawable;
int scrnNum = (int)n;
if (pDraw->pScreen->myNum != scrnNum) {
return;
}
if (pDraw->type == DRAWABLE_PIXMAP) {
PixmapPtr pPixmap = (PixmapPtr)pDraw;
dmxBECreatePixmap(pPixmap);
dmxBERestorePixmap(pPixmap);
}
dmxBECreatePicture(pPicture);
}
static void dmxBERestoreRenderGlyph(pointer value, XID id, pointer n)
{
GlyphSetPtr glyphSet = value;
int scrnNum = (int)n;
dmxGlyphPrivPtr glyphPriv = DMX_GET_GLYPH_PRIV(glyphSet);
DMXScreenInfo *dmxScreen = &dmxScreens[scrnNum];
GlyphRefPtr table;
char *images;
Glyph *gids;
XGlyphInfo *glyphs;
char *pos;
int beret;
int len_images = 0;
int i;
int ctr;
if (glyphPriv->glyphSets[scrnNum]) {
return;
}
if ((beret = dmxBECreateGlyphSet(scrnNum, glyphSet)) != Success) {
dmxLog(dmxWarning,
"\tdmxBERestoreRenderGlyph failed to create glyphset!\n");
return;
}
table = glyphSet->hash.table;
for (i = 0; i < glyphSet->hash.hashSet->size; i++) {
GlyphRefPtr gr = &table[i];
GlyphPtr gl = gr->glyph;
if (!gl || gl == DeletedGlyph) continue;
len_images += gl->size - sizeof(gl->info);
}
images = xcalloc(len_images, sizeof(char));
gids = xalloc(glyphSet->hash.tableEntries*sizeof(Glyph));
glyphs = xalloc(glyphSet->hash.tableEntries*sizeof(XGlyphInfo));
pos = images;
ctr = 0;
for (i = 0; i < glyphSet->hash.hashSet->size; i++) {
GlyphRefPtr gr = &table[i];
GlyphPtr gl = gr->glyph;
if (!gl || gl == DeletedGlyph) continue;
gids[ctr] = gr->signature;
glyphs[ctr].width = gl->info.width;
glyphs[ctr].height = gl->info.height;
glyphs[ctr].x = gl->info.x;
glyphs[ctr].y = gl->info.y;
glyphs[ctr].xOff = gl->info.xOff;
glyphs[ctr].yOff = gl->info.yOff;
memcpy(pos, gl+1, gl->size - sizeof(gl->info));
pos += gl->size - sizeof(gl->info);
ctr++;
}
XRenderAddGlyphs(dmxScreen->beDisplay, glyphPriv->glyphSets[scrnNum],
gids,glyphs, glyphSet->hash.tableEntries, images,
len_images);
xfree(len_images);
xfree(gids);
xfree(glyphs);
}
#endif
int dmxAttachScreen(int idx, DMXScreenAttributesPtr attr)
{
ScreenPtr pScreen;
DMXScreenInfo *dmxScreen;
CARD32 scrnNum = idx;
DMXScreenInfo oldDMXScreen;
int i;
if (!dmxAddRemoveScreens) {
dmxLog(dmxWarning,
"Attempting to add a screen, but the AddRemoveScreen\n");
dmxLog(dmxWarning,
"extension has not been enabled. To enable this extension\n");
dmxLog(dmxWarning,
"add the \"-addremovescreens\" option either to the command\n");
dmxLog(dmxWarning,
"line or in the configuration file.\n");
return 1;
}
if (idx < 0 || idx >= dmxNumScreens) return 1;
pScreen = screenInfo.screens[idx];
dmxScreen = &dmxScreens[idx];
if (dmxScreen->beDisplay) {
dmxLog(dmxWarning,
"Attempting to add screen #%d but a screen already exists\n",
idx);
return 1;
}
dmxLogOutput(dmxScreen, "Attaching screen #%d\n", idx);
oldDMXScreen = *dmxScreen;
dmxScreen->name = strdup(attr->displayName);
if (!dmxOpenDisplay(dmxScreen)) {
dmxLog(dmxWarning,
"dmxOpenDisplay: Unable to open display %s\n",
dmxScreen->name);
*dmxScreen = oldDMXScreen;
return 1;
}
dmxSetErrorHandler(dmxScreen);
dmxCheckForWM(dmxScreen);
dmxGetScreenAttribs(dmxScreen);
if (!dmxGetVisualInfo(dmxScreen)) {
dmxLog(dmxWarning, "dmxGetVisualInfo: No matching visuals found\n");
XFree(dmxScreen->beVisuals);
XCloseDisplay(dmxScreen->beDisplay);
*dmxScreen = oldDMXScreen;
return 1;
}
dmxGetColormaps(dmxScreen);
dmxGetPixmapFormats(dmxScreen);
if (!dmxCompareScreens(dmxScreen, &oldDMXScreen)) {
dmxLog(dmxWarning,
"New screen data (%s) does not match previously\n",
dmxScreen->name);
dmxLog(dmxWarning,
"attached screen data (%s)\n",
oldDMXScreen.name);
dmxLog(dmxWarning,
"All data must match in order to attach to screen #%d\n",
idx);
XFree(dmxScreen->beVisuals);
XFree(dmxScreen->beDepths);
XFree(dmxScreen->bePixmapFormats);
XCloseDisplay(dmxScreen->beDisplay);
*dmxScreen = oldDMXScreen;
return 1;
}
dmxBEScreenInit(idx, screenInfo.screens[idx]);
dmxBECreatePixmap(pScreen->PixmapPerDepth[0]);
dmxBERestorePixmap(pScreen->PixmapPerDepth[0]);
dmxBECreateScratchGCs(idx);
(void)dmxBELoadFont(pScreen, defaultFont);
for (i = currentMaxClients; --i >= 0; )
if (clients[i])
FindAllClientResources(clients[i], dmxBECreateResources,
(pointer)idx);
dmxBECreateWindowTree(idx);
#ifdef RENDER
for (i = currentMaxClients; --i >= 0; )
if (clients[i])
FindClientResourcesByType(clients[i],PictureType,
dmxBERestoreRenderPict,(pointer)idx);
for (i = currentMaxClients; --i >= 0; )
if (clients[i])
FindClientResourcesByType(clients[i],GlyphSetType,
dmxBERestoreRenderGlyph,(pointer)idx);
#endif
dmxForceExposures(idx);
dmxSync(&dmxScreens[idx], TRUE);
XFree(oldDMXScreen.beVisuals);
XFree(oldDMXScreen.beDepths);
XFree(oldDMXScreen.bePixmapFormats);
#ifdef PANORAMIX
if (!noPanoramiXExtension)
return dmxConfigureScreenWindows(1, &scrnNum, attr, NULL);
else
#endif
return 0;
}
#ifdef PANORAMIX
static void dmxBEFindPixmapImage(pointer value, XID id, RESTYPE type,
pointer p)
{
if ((type & TypeMask) == (XRT_PIXMAP & TypeMask)) {
PixmapPtr pDst = (PixmapPtr)p;
int idx = pDst->drawable.pScreen->myNum;
PanoramiXRes *pXinPix = (PanoramiXRes *)value;
PixmapPtr pPix;
int i;
pPix = (PixmapPtr)LookupIDByType(pXinPix->info[idx].id, RT_PIXMAP);
if (pPix != pDst) return;
for (i = 0; i < PanoramiXNumScreens; i++) {
PixmapPtr pSrc;
dmxPixPrivPtr pSrcPriv = NULL;
if (i == idx) continue;
pSrc =
(PixmapPtr)LookupIDByType(pXinPix->info[i].id, RT_PIXMAP);
pSrcPriv = DMX_GET_PIXMAP_PRIV(pSrc);
if (pSrcPriv->pixmap) {
FoundPixImage = True;
return;
}
}
}
}
#endif
static void dmxBESavePixmap(PixmapPtr pPixmap)
{
#ifdef PANORAMIX
int i;
if (noPanoramiXExtension) return;
FoundPixImage = False;
for (i = currentMaxClients; --i >= 0; )
if (clients[i])
FindAllClientResources(clients[i], dmxBEFindPixmapImage,
(pointer)pPixmap);
if (!FoundPixImage) {
dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pPixmap);
if (!pPixPriv->detachedImage) {
ScreenPtr pScreen = pPixmap->drawable.pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
pPixPriv->detachedImage = XGetImage(dmxScreen->beDisplay,
pPixPriv->pixmap,
0, 0,
pPixmap->drawable.width,
pPixmap->drawable.height,
-1,
ZPixmap);
if (!pPixPriv->detachedImage)
dmxLog(dmxWarning, "Cannot save pixmap image\n");
}
}
#else
return;
#endif
}
static void dmxBEDestroyResources(pointer value, XID id, RESTYPE type,
pointer n)
{
int scrnNum = (int)n;
ScreenPtr pScreen = screenInfo.screens[scrnNum];
if ((type & TypeMask) == (RT_WINDOW & TypeMask)) {
} else if ((type & TypeMask) == (RT_PIXMAP & TypeMask)) {
PixmapPtr pPix = value;
if (pPix->drawable.pScreen->myNum == scrnNum) {
dmxBESavePixmap(pPix);
dmxBEFreePixmap(pPix);
}
} else if ((type & TypeMask) == (RT_GC & TypeMask)) {
GCPtr pGC = value;
if (pGC->pScreen->myNum == scrnNum)
dmxBEFreeGC(pGC);
} else if ((type & TypeMask) == (RT_FONT & TypeMask)) {
dmxBEFreeFont(pScreen, (FontPtr)value);
} else if ((type & TypeMask) == (RT_CURSOR & TypeMask)) {
dmxBEFreeCursor(pScreen, (CursorPtr)value);
} else if ((type & TypeMask) == (RT_COLORMAP & TypeMask)) {
ColormapPtr pCmap = value;
if (pCmap->pScreen->myNum == scrnNum)
dmxBEFreeColormap((ColormapPtr)value);
#ifdef RENDER
} else if ((type & TypeMask) == (PictureType & TypeMask)) {
PicturePtr pPict = value;
if (pPict->pDrawable->pScreen->myNum == scrnNum) {
if (pPict->pDrawable->type == DRAWABLE_PIXMAP) {
PixmapPtr pPixmap = (PixmapPtr)(pPict->pDrawable);
dmxBESavePixmap(pPixmap);
dmxBEFreePixmap(pPixmap);
}
dmxBEFreePicture((PicturePtr)value);
}
} else if ((type & TypeMask) == (GlyphSetType & TypeMask)) {
dmxBEFreeGlyphSet(pScreen, (GlyphSetPtr)value);
#endif
} else {
}
}
static void dmxBEDestroyScratchGCs(int scrnNum)
{
ScreenPtr pScreen = screenInfo.screens[scrnNum];
GCPtr *ppGC = pScreen->GCperDepth;
int i;
for (i = 0; i <= pScreen->numDepths; i++)
dmxBEFreeGC(ppGC[i]);
}
static void dmxBEDestroyWindowTree(int idx)
{
WindowPtr pWin = WindowTable[idx];
WindowPtr pChild = pWin;
while (1) {
if (pChild->firstChild) {
pChild = pChild->firstChild;
continue;
}
dmxBEDestroyWindow(pChild);
if (!pChild->borderIsPixel) {
dmxBESavePixmap(pChild->border.pixmap);
dmxBEFreePixmap(pChild->border.pixmap);
}
if (pChild->backgroundState == BackgroundPixmap) {
dmxBESavePixmap(pChild->background.pixmap);
dmxBEFreePixmap(pChild->background.pixmap);
}
while (!pChild->nextSib && (pChild != pWin)) {
pChild = pChild->parent;
dmxBEDestroyWindow(pChild);
if (!pChild->borderIsPixel) {
dmxBESavePixmap(pChild->border.pixmap);
dmxBEFreePixmap(pChild->border.pixmap);
}
if (pChild->backgroundState == BackgroundPixmap) {
dmxBESavePixmap(pChild->background.pixmap);
dmxBEFreePixmap(pChild->background.pixmap);
}
}
if (pChild == pWin)
break;
pChild = pChild->nextSib;
}
}
int dmxDetachScreen(int idx)
{
DMXScreenInfo *dmxScreen = &dmxScreens[idx];
int i;
if (!dmxAddRemoveScreens) {
dmxLog(dmxWarning,
"Attempting to remove a screen, but the AddRemoveScreen\n");
dmxLog(dmxWarning,
"extension has not been enabled. To enable this extension\n");
dmxLog(dmxWarning,
"add the \"-addremovescreens\" option either to the command\n");
dmxLog(dmxWarning,
"line or in the configuration file.\n");
return 1;
}
if (idx < 0 || idx >= dmxNumScreens) return 1;
if (!dmxScreen->beDisplay) {
dmxLog(dmxWarning,
"Attempting to remove screen #%d but it has not been opened\n",
idx);
return 1;
}
dmxLogOutput(dmxScreen, "Detaching screen #%d\n", idx);
dmxInputDetachAll(dmxScreen);
for (i = currentMaxClients; --i >= 0; )
if (clients[i])
FindAllClientResources(clients[i], dmxBEDestroyResources,
(pointer)idx);
dmxBEDestroyScratchGCs(idx);
dmxBEDestroyWindowTree(idx);
dmxBESavePixmap(screenInfo.screens[idx]->PixmapPerDepth[0]);
dmxBEFreePixmap(screenInfo.screens[idx]->PixmapPerDepth[0]);
dmxBECloseScreen(screenInfo.screens[idx]);
dmxAdjustCursorBoundaries();
return 0;
}