aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/dmx
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-01-21 12:52:35 +0000
committermarha <marha@users.sourceforge.net>2011-01-21 12:52:35 +0000
commit7719409ebcf17c5288114dee8f60cc9ff889fd3e (patch)
treee86379743c048712c638bed954264fccea7798c4 /xorg-server/hw/dmx
parent26ee05a8febfe1ed6da852777a8c1c2a37e4cf9b (diff)
parentb0be6a88c8fecdf15176f642c0799bff99930e0d (diff)
downloadvcxsrv-7719409ebcf17c5288114dee8f60cc9ff889fd3e.tar.gz
vcxsrv-7719409ebcf17c5288114dee8f60cc9ff889fd3e.tar.bz2
vcxsrv-7719409ebcf17c5288114dee8f60cc9ff889fd3e.zip
svn merge ^/branches/released .
Diffstat (limited to 'xorg-server/hw/dmx')
-rw-r--r--xorg-server/hw/dmx/config/xdmxconfig.c2
-rw-r--r--xorg-server/hw/dmx/dmxextension.c3238
-rw-r--r--xorg-server/hw/dmx/dmxgc.c837
-rw-r--r--xorg-server/hw/dmx/input/dmxinputinit.c2580
4 files changed, 3311 insertions, 3346 deletions
diff --git a/xorg-server/hw/dmx/config/xdmxconfig.c b/xorg-server/hw/dmx/config/xdmxconfig.c
index 033b52512..c67077aec 100644
--- a/xorg-server/hw/dmx/config/xdmxconfig.c
+++ b/xorg-server/hw/dmx/config/xdmxconfig.c
@@ -142,7 +142,7 @@ static void dmxConfigGetDims(int *maxWidth, int *maxHeight)
DMXConfigEntryPtr e;
*maxWidth = dmxConfigWallWidth = 0;
- *maxWidth = dmxConfigWallHeight = 0;
+ *maxHeight = dmxConfigWallHeight = 0;
if (!dmxConfigCurrent) return;
dmxConfigWallWidth = dmxConfigCurrent->width;
diff --git a/xorg-server/hw/dmx/dmxextension.c b/xorg-server/hw/dmx/dmxextension.c
index 97f2a04b0..bd326ce2a 100644
--- a/xorg-server/hw/dmx/dmxextension.c
+++ b/xorg-server/hw/dmx/dmxextension.c
@@ -1,1618 +1,1620 @@
-/*
- * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
- *
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation on the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-/*
- * Author:
- * Rickard E. (Rik) Faith <faith@redhat.com>
- * Kevin E. Martin <kem@redhat.com>
- *
- */
-
-/** \file
- * This file provides the only interface to the X server extension support
- * in programs/Xserver/Xext. Those programs should only include dmxext.h
- */
-
-#ifdef HAVE_DMX_CONFIG_H
-#include <dmx-config.h>
-#endif
-
-#include <stdlib.h>
-
-#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"
-#include "dmxpict.h"
-#include "dmxinput.h"
-#include "dmxsync.h"
-#include "dmxscrinit.h"
-#include "input/dmxinputinit.h"
-
-#include "windowstr.h"
-#include "inputstr.h" /* For DeviceIntRec */
-#include <X11/extensions/dmxproto.h> /* For DMX_BAD_* */
-#include "cursorstr.h"
-
-/* The default font is declared in dix/globals.c, but is not included in
- * _any_ header files. */
-extern FontPtr defaultFont;
-
-/** This routine provides information to the DMX protocol extension
- * about a particular screen. */
-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;
-}
-
-/** This routine provides information to the DMX protocol extension
- * about a particular window. */
-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;
- }
-
- /* Compute display-relative coordinates */
- 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;
- }
-
- /* Convert to window-relative coordinates */
- 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; /* NOTE: The upper left hand corner of */
- attr->shiftY = 0; /* the desktop is always <0,0>. */
-}
-
-/** Return the total number of devices, not just #dmxNumInputs. The
- * number returned should be the same as that returned by
- * XListInputDevices. */
-int dmxGetInputCount(void)
-{
- int i, total;
-
- for (total = i = 0; i < dmxNumInputs; i++) total += dmxInputs[i].numDevs;
- return total;
-}
-
-/** Return information about the device with id = \a deviceId. This
- * information is primarily for the #ProcDMXGetInputAttributes()
- * function, which does not have access to the appropriate data
- * structure. */
-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; /* Success */
- }
- }
- return -1; /* Failure */
-}
-
-/** Reinitialized the cursor boundaries. */
-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);
- }
-}
-
-/** Add an input with the specified attributes. If the input is added,
- * the physical id is returned in \a deviceId. */
-int dmxAddInput(DMXInputAttributesPtr attr, int *id)
-{
- int retcode = BadValue;
-
- if (attr->inputType == 1) /* console */
- retcode = dmxInputAttachConsole(attr->name, attr->sendsCore, id);
- else if (attr->inputType == 2) /* backend */
- retcode = dmxInputAttachBackend(attr->physicalScreen,
- attr->sendsCore,id);
-
- if (retcode == Success) {
- /* Adjust the cursor boundaries */
- dmxAdjustCursorBoundaries();
-
- /* Force completion of the changes */
- dmxSync(NULL, TRUE);
- }
-
- return retcode;
-}
-
-/** Remove the input with physical id \a id. */
-int dmxRemoveInput(int id)
-{
- return dmxInputDetachId(id);
-}
-
-/** Return the value of #dmxNumScreens -- the total number of backend
- * screens in use (these are logical screens and may be larger than the
- * number of backend displays). */
-unsigned long dmxGetNumScreens(void)
-{
- return dmxNumScreens;
-}
-
-/** Make sure that #dmxCreateAndRealizeWindow has been called for \a
- * pWindow. */
-void dmxForceWindowCreation(WindowPtr pWindow)
-{
- dmxWinPrivPtr pWinPriv = DMX_GET_WINDOW_PRIV(pWindow);
- if (!pWinPriv->window) dmxCreateAndRealizeWindow(pWindow, TRUE);
-}
-
-/** Flush pending syncs for all screens. */
-void dmxFlushPendingSyncs(void)
-{
- dmxSync(NULL, TRUE);
-}
-
-/** Update DMX's screen resources to match those of the newly moved
- * and/or resized "root" window. */
-void dmxUpdateScreenResources(ScreenPtr pScreen, int x, int y, int w, int h)
-{
- DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
- WindowPtr pRoot = pScreen->root;
- WindowPtr pChild;
- Bool anyMarked = FALSE;
-
- /* Handle special case where width and/or height are zero */
- if (w == 0 || h == 0) {
- w = 1;
- h = 1;
- }
-
- /* Change screen size */
- pScreen->width = w;
- pScreen->height = h;
-
- /* Reset the root window's drawable's size */
- pRoot->drawable.width = w;
- pRoot->drawable.height = h;
-
- /* Set the root window's new winSize and borderSize */
- 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;
-
- /* Recompute this screen's mmWidth & mmHeight */
- pScreen->mmWidth =
- (w * 254 + dmxScreen->beXDPI * 5) / (dmxScreen->beXDPI * 10);
- pScreen->mmHeight =
- (h * 254 + dmxScreen->beYDPI * 5) / (dmxScreen->beYDPI * 10);
-
- /* Recompute this screen's window's clip rects as follows: */
- /* 1. Mark all of root's children's windows */
- for (pChild = pRoot->firstChild; pChild; pChild = pChild->nextSib)
- anyMarked |= pScreen->MarkOverlappedWindows(pChild, pChild,
- (WindowPtr *)NULL);
-
- /* 2. Set the root window's borderClip */
- pRoot->borderClip.extents.x1 = 0;
- pRoot->borderClip.extents.y1 = 0;
- pRoot->borderClip.extents.x2 = w;
- pRoot->borderClip.extents.y2 = h;
-
- /* 3. Set the root window's clipList */
- if (anyMarked) {
- /* If any windows have been marked, set the root window's
- * clipList to be broken since it will be recalculated in
- * ValidateTree()
- */
- RegionBreak(&pRoot->clipList);
- } else {
- /* Otherwise, we just set it directly since there are no
- * windows visible on this screen
- */
- pRoot->clipList.extents.x1 = 0;
- pRoot->clipList.extents.y1 = 0;
- pRoot->clipList.extents.x2 = w;
- pRoot->clipList.extents.y2 = h;
- }
-
- /* 4. Revalidate all clip rects and generate expose events */
- if (anyMarked) {
- pScreen->ValidateTree(pRoot, NULL, VTBroken);
- pScreen->HandleExposures(pRoot);
- if (pScreen->PostValidateTree)
- pScreen->PostValidateTree(pRoot, NULL, VTBroken);
- }
-}
-
-#ifdef PANORAMIX
-#include "panoramiXsrv.h"
-
-/** Change the "screen" window attributes by resizing the actual window
- * on the back-end display (if necessary). */
-static void dmxConfigureScreenWindow(int idx,
- int x, int y, int w, int h)
-{
- DMXScreenInfo *dmxScreen = &dmxScreens[idx];
- ScreenPtr pScreen = screenInfo.screens[idx];
-
- /* Resize "screen" window */
- if (dmxScreen->scrnX != x ||
- dmxScreen->scrnY != y ||
- dmxScreen->scrnWidth != w ||
- dmxScreen->scrnHeight != h) {
- dmxResizeScreenWindow(pScreen, x, y, w, h);
- }
-
- /* Change "screen" window values */
- dmxScreen->scrnX = x;
- dmxScreen->scrnY = y;
- dmxScreen->scrnWidth = w;
- dmxScreen->scrnHeight = h;
-}
-
-/** Change the "root" window position and size by resizing the actual
- * window on the back-end display (if necessary) and updating all of
- * DMX's resources by calling #dmxUpdateScreenResources. */
-static void dmxConfigureRootWindow(int idx, int x, int y, int w, int h)
-{
- DMXScreenInfo *dmxScreen = &dmxScreens[idx];
- WindowPtr pRoot = screenInfo.screens[idx]->root;
-
- /* NOTE: Either this function or the ones that it calls must handle
- * the case where w == 0 || h == 0. Currently, the functions that
- * this one calls handle that case. */
-
- /* 1. Resize "root" window */
- if (dmxScreen->rootX != x ||
- dmxScreen->rootY != y ||
- dmxScreen->rootWidth != w ||
- dmxScreen->rootHeight != h) {
- dmxResizeRootWindow(pRoot, x, y, w, h);
- }
-
- /* 2. Update all of the screen's resources associated with this root
- * window */
- if (dmxScreen->rootWidth != w ||
- dmxScreen->rootHeight != h) {
- dmxUpdateScreenResources(screenInfo.screens[idx], x, y, w, h);
- }
-
- /* Change "root" window values */
- dmxScreen->rootX = x;
- dmxScreen->rootY = y;
- dmxScreen->rootWidth = w;
- dmxScreen->rootHeight = h;
-}
-
-/** Change the "root" window's origin by updating DMX's internal data
- * structures (dix and Xinerama) to use the new origin and adjust the
- * positions of windows that overlap this "root" window. */
-static void dmxSetRootWindowOrigin(int idx, int x, int y)
-{
- DMXScreenInfo *dmxScreen = &dmxScreens[idx];
- ScreenPtr pScreen = screenInfo.screens[idx];
- WindowPtr pRoot = pScreen->root;
- WindowPtr pChild;
- int xoff;
- int yoff;
-
- /* Change "root" window's origin */
- dmxScreen->rootXOrigin = x;
- dmxScreen->rootYOrigin = y;
-
- /* Compute offsets here in case <x,y> has been changed above */
- xoff = x - pScreen->x;
- yoff = y - pScreen->y;
-
- /* Adjust the root window's position */
- pScreen->x = dmxScreen->rootXOrigin;
- pScreen->y = dmxScreen->rootYOrigin;
-
- /* Recalculate the Xinerama regions and data structs */
- XineramaReinitData(pScreen);
-
- /* Adjust each of the root window's children */
- if (!idx) ReinitializeRootWindow(screenInfo.screens[0]->root, xoff, yoff);
- pChild = pRoot->firstChild;
- while (pChild) {
- /* Adjust child window's position */
- pScreen->MoveWindow(pChild,
- pChild->origin.x - wBorderWidth(pChild) - xoff,
- pChild->origin.y - wBorderWidth(pChild) - yoff,
- pChild->nextSib,
- VTMove);
-
- /* Note that the call to MoveWindow will eventually call
- * dmxPositionWindow which will automatically create a
- * window if it is now exposed on screen (for lazy window
- * creation optimization) and it will properly set the
- * offscreen flag.
- */
-
- pChild = pChild->nextSib;
- }
-}
-
-/** Configure the attributes of each "screen" and "root" window. */
-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;
-
- /* Check for illegal values */
- if (idx < 0 || idx >= dmxNumScreens) return BadValue;
-
- /* The "screen" and "root" windows must have valid sizes */
- if (attr->screenWindowWidth <= 0 || attr->screenWindowHeight <= 0 ||
- attr->rootWindowWidth < 0 || attr->rootWindowHeight < 0)
- return DMX_BAD_VALUE;
-
- /* The "screen" window must fit entirely within the BE display */
- 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;
-
- /* The "root" window must fit entirely within the "screen" window */
- if (attr->rootWindowXoffset < 0 ||
- attr->rootWindowYoffset < 0 ||
- attr->rootWindowXoffset
- + attr->rootWindowWidth > attr->screenWindowWidth ||
- attr->rootWindowYoffset
- + attr->rootWindowHeight > attr->screenWindowHeight)
- return DMX_BAD_VALUE;
-
- /* The "root" window must not expose unaddressable coordinates */
- if (attr->rootWindowXorigin < 0 ||
- attr->rootWindowYorigin < 0 ||
- attr->rootWindowXorigin + attr->rootWindowWidth > 32767 ||
- attr->rootWindowYorigin + attr->rootWindowHeight > 32767)
- return DMX_BAD_VALUE;
-
- /* The "root" window must fit within the global bounding box */
- if (attr->rootWindowXorigin
- + attr->rootWindowWidth > (unsigned)dmxGlobalWidth ||
- attr->rootWindowYorigin
- + attr->rootWindowHeight > (unsigned)dmxGlobalHeight)
- return DMX_BAD_VALUE;
-
- /* FIXME: Handle the rest of the illegal value checking */
- }
-
- /* No illegal values found */
- 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);
-
- /* Configure "screen" window */
- dmxConfigureScreenWindow(idx,
- attr->screenWindowXoffset,
- attr->screenWindowYoffset,
- attr->screenWindowWidth,
- attr->screenWindowHeight);
-
- /* Configure "root" window */
- dmxConfigureRootWindow(idx,
- attr->rootWindowXoffset,
- attr->rootWindowYoffset,
- attr->rootWindowWidth,
- attr->rootWindowHeight);
-
-
- /* Set "root" window's origin */
- dmxSetRootWindowOrigin(idx,
- attr->rootWindowXorigin,
- attr->rootWindowYorigin);
- }
-
- /* Adjust the cursor boundaries */
- dmxAdjustCursorBoundaries();
-
- /* Force completion of the changes */
- dmxSync(NULL, TRUE);
-
- return Success;
-}
-
-/** Configure the attributes of the global desktop. */
-int dmxConfigureDesktop(DMXDesktopAttributesPtr attribs)
-{
- if (attribs->width <= 0 || attribs->width >= 32767 ||
- attribs->height <= 0 || attribs->height >= 32767)
- return DMX_BAD_VALUE;
-
- /* If the desktop is shrinking, adjust the "root" windows on each
- * "screen" window to only show the visible desktop. Also, handle
- * the special case where the desktop shrinks such that the it no
- * longer overlaps an portion of a "screen" window. */
- 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);
- }
- }
- }
-
- /* Set the global width/height */
- dmxSetWidthHeight(attribs->width, attribs->height);
-
- /* Handle shift[XY] changes */
- if (attribs->shiftX || attribs->shiftY) {
- int i;
- for (i = 0; i < dmxNumScreens; i++) {
- ScreenPtr pScreen = screenInfo.screens[i];
- WindowPtr pChild = pScreen->root->firstChild;
- while (pChild) {
- /* Adjust child window's position */
- pScreen->MoveWindow(pChild,
- pChild->origin.x - wBorderWidth(pChild)
- - attribs->shiftX,
- pChild->origin.y - wBorderWidth(pChild)
- - attribs->shiftY,
- pChild->nextSib,
- VTMove);
-
- /* Note that the call to MoveWindow will eventually call
- * dmxPositionWindow which will automatically create a
- * window if it is now exposed on screen (for lazy
- * window creation optimization) and it will properly
- * set the offscreen flag.
- */
-
- pChild = pChild->nextSib;
- }
- }
- }
-
- /* Update connection block, Xinerama, etc. -- these appears to
- * already be handled in dmxConnectionBlockCallback(), which is
- * called from dmxAdjustCursorBoundaries() [below]. */
-
- /* Adjust the cursor boundaries */
- dmxAdjustCursorBoundaries();
-
- /* Force completion of the changes */
- dmxSync(NULL, TRUE);
-
- return Success;
-}
-#endif
-
-/** Create the scratch GCs per depth. */
-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;
-
-/** Search the Xinerama XRT_PIXMAP resources for the pixmap that needs
- * to have its image restored. When it is found, see if there is
- * another screen with the same image. If so, copy the pixmap image
- * from the existing screen to the newly created pixmap. */
-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;
-
- dixLookupResourceByType((pointer*) &pPix, pXinPix->info[idx].id,
- RT_PIXMAP, NullClient, DixUnknownAccess);
- if (pPix != pDst) return; /* Not a match.... Next! */
-
- for (i = 0; i < PanoramiXNumScreens; i++) {
- PixmapPtr pSrc;
- dmxPixPrivPtr pSrcPriv = NULL;
-
- if (i == idx) continue; /* Self replication is bad */
-
- dixLookupResourceByType((pointer*) &pSrc, pXinPix->info[i].id,
- RT_PIXMAP, NullClient, DixUnknownAccess);
- 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;
-
- /* This should never happen, but just in case.... */
- if (pSrc->drawable.width != pDst->drawable.width ||
- pSrc->drawable.height != pDst->drawable.height)
- return;
-
- /* Copy from src pixmap to dst pixmap */
- 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
-
-/** Restore the pixmap image either from another screen or from an image
- * that was saved when the screen was previously detached. */
-static void dmxBERestorePixmap(PixmapPtr pPixmap)
-{
-#ifdef PANORAMIX
- int i;
-
- /* If Xinerama is not active, there's nothing we can do (see comment
- * in #else below for more info). */
- 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);
-
- /* No corresponding pixmap image was found on other screens, so we
- * need to copy it from the saved image when the screen was detached
- * (if available). */
- 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
- /* If Xinerama is not enabled, then there is no other copy of the
- * pixmap image that we can restore. Saving all pixmap data is not
- * a feasible option since there is no mechanism for updating pixmap
- * data when a screen is detached, which means that the data that
- * was previously saved would most likely be out of date. */
- dmxLog(dmxWarning, "Cannot restore pixmap image\n");
- return;
-#endif
-}
-
-/** Create resources on the back-end server. This function is called
- * from #dmxAttachScreen() via the dix layer's FindAllResources
- * function. It walks all resources, compares them to the screen
- * number passed in as \a n and calls the appropriate DMX function to
- * create the associated resource on the back-end server. */
-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)) {
- /* Window resources are created below in dmxBECreateWindowTree */
- } 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) {
- /* Create the GC on the back-end server */
- dmxBECreateGC(pScreen, pGC);
- /* Create any pixmaps associated with this GC */
- 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);
- }
- /* Update the GC on the back-end server */
- 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
- /* TODO: Recreate Picture and GlyphSet resources */
- } else if ((type & TypeMask) == (PictureType & TypeMask)) {
- /* Picture resources are created when windows are created */
- } else if ((type & TypeMask) == (GlyphSetType & TypeMask)) {
- dmxBEFreeGlyphSet(pScreen, (GlyphSetPtr)value);
-#endif
- } else {
- /* Other resource types??? */
- }
-}
-
-/** Create window hierachy on back-end server. The window tree is
- * created in a special order (bottom most subwindow first) so that the
- * #dmxCreateNonRootWindow() function does not need to recursively call
- * itself to create each window's parents. This is required so that we
- * have the opportunity to create each window's border and background
- * pixmaps (where appropriate) before the window is created. */
-static void dmxBECreateWindowTree(int idx)
-{
- DMXScreenInfo *dmxScreen = &dmxScreens[idx];
- WindowPtr pRoot = screenInfo.screens[idx]->root;
- dmxWinPrivPtr pWinPriv = DMX_GET_WINDOW_PRIV(pRoot);
- WindowPtr pWin;
-
- /* Create the pixmaps associated with the root window */
- if (!pRoot->borderIsPixel) {
- dmxBECreatePixmap(pRoot->border.pixmap);
- dmxBERestorePixmap(pRoot->border.pixmap);
- }
- if (pRoot->backgroundState == BackgroundPixmap) {
- dmxBECreatePixmap(pRoot->background.pixmap);
- dmxBERestorePixmap(pRoot->background.pixmap);
- }
-
- /* Create root window first */
- dmxScreen->rootWin = pWinPriv->window = dmxCreateRootWindow(pRoot);
- XMapWindow(dmxScreen->beDisplay, dmxScreen->rootWin);
-
- pWin = pRoot->lastChild;
- while (pWin) {
- pWinPriv = DMX_GET_WINDOW_PRIV(pWin);
-
- /* Create the pixmaps regardless of whether or not the
- * window is created or not due to lazy window creation.
- */
- if (!pWin->borderIsPixel) {
- dmxBECreatePixmap(pWin->border.pixmap);
- dmxBERestorePixmap(pWin->border.pixmap);
- }
- if (pWin->backgroundState == BackgroundPixmap) {
- dmxBECreatePixmap(pWin->background.pixmap);
- dmxBERestorePixmap(pWin->background.pixmap);
- }
-
- /* Reset the window attributes */
- dmxGetDefaultWindowAttributes(pWin,
- &pWinPriv->cmap,
- &pWinPriv->visual);
-
- /* Create the window */
- if (pWinPriv->mapped && !pWinPriv->offscreen)
- dmxCreateAndRealizeWindow(pWin, TRUE);
-
- /* Next, create the bottom-most child */
- if (pWin->lastChild) {
- pWin = pWin->lastChild;
- continue;
- }
-
- /* If the window has no children, move on to the next higher window */
- while (!pWin->prevSib && (pWin != pRoot))
- pWin = pWin->parent;
-
- if (pWin->prevSib) {
- pWin = pWin->prevSib;
- continue;
- }
-
- /* When we reach the root window, we are finished */
- if (pWin == pRoot)
- break;
- }
-}
-
-/* Refresh screen by generating exposure events for all windows */
-static void dmxForceExposures(int idx)
-{
- ScreenPtr pScreen = screenInfo.screens[idx];
- WindowPtr pRoot = pScreen->root;
- Bool anyMarked = FALSE;
- WindowPtr pChild;
-
- for (pChild = pRoot->firstChild; pChild; pChild = pChild->nextSib)
- anyMarked |= pScreen->MarkOverlappedWindows(pChild, pChild,
- (WindowPtr *)NULL);
- if (anyMarked) {
- /* If any windows have been marked, set the root window's
- * clipList to be broken since it will be recalculated in
- * ValidateTree()
- */
- RegionBreak(&pRoot->clipList);
- pScreen->ValidateTree(pRoot, NULL, VTBroken);
- pScreen->HandleExposures(pRoot);
- if (pScreen->PostValidateTree)
- pScreen->PostValidateTree(pRoot, NULL, VTBroken);
- }
-}
-
-/** Compare the new and old screens to see if they are compatible. */
-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;
-}
-
-/** Restore Render's picture */
-static void dmxBERestoreRenderPict(pointer value, XID id, pointer n)
-{
- PicturePtr pPicture = value; /* The picture */
- DrawablePtr pDraw = pPicture->pDrawable; /* The picture's drawable */
- int scrnNum = (int)n;
-
- if (pDraw->pScreen->myNum != scrnNum) {
- /* Picture not on the screen we are restoring*/
- return;
- }
-
- if (pDraw->type == DRAWABLE_PIXMAP) {
- PixmapPtr pPixmap = (PixmapPtr)pDraw;
-
- /* Create and restore the pixmap drawable */
- dmxBECreatePixmap(pPixmap);
- dmxBERestorePixmap(pPixmap);
- }
-
- dmxBECreatePicture(pPicture);
-}
-
-/** Restore Render's glyphs */
-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]) {
- /* Only restore glyphs on the screen we are attaching */
- return;
- }
-
- /* First we must create the glyph set on the backend. */
- if ((beret = dmxBECreateGlyphSet(scrnNum, glyphSet)) != Success) {
- dmxLog(dmxWarning,
- "\tdmxBERestoreRenderGlyph failed to create glyphset!\n");
- return;
- }
-
- /* Now for the complex part, restore the glyph data */
- table = glyphSet->hash.table;
-
- /* We need to know how much memory to allocate for this part */
- 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);
- }
-
- /* Now allocate the memory we need */
- images = calloc(len_images, sizeof(char));
- gids = malloc(glyphSet->hash.tableEntries*sizeof(Glyph));
- glyphs = malloc(glyphSet->hash.tableEntries*sizeof(XGlyphInfo));
-
- pos = images;
- ctr = 0;
-
- /* Fill the allocated memory with the proper data */
- for (i = 0; i < glyphSet->hash.hashSet->size; i++) {
- GlyphRefPtr gr = &table[i];
- GlyphPtr gl = gr->glyph;
-
- if (!gl || gl == DeletedGlyph) continue;
-
- /* First lets put the data into gids */
- gids[ctr] = gr->signature;
-
- /* Next do the glyphs data structures */
- 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;
-
- /* Copy the images from the DIX's data into the buffer */
- memcpy(pos, gl+1, gl->size - sizeof(gl->info));
- pos += gl->size - sizeof(gl->info);
- ctr++;
- }
-
- /* Now restore the glyph data */
- XRenderAddGlyphs(dmxScreen->beDisplay, glyphPriv->glyphSets[scrnNum],
- gids,glyphs, glyphSet->hash.tableEntries, images,
- len_images);
-
- /* Clean up */
- free(images);
- free(gids);
- free(glyphs);
-}
-
-/** Reattach previously detached back-end screen. */
-int dmxAttachScreen(int idx, DMXScreenAttributesPtr attr)
-{
- ScreenPtr pScreen;
- DMXScreenInfo *dmxScreen;
- CARD32 scrnNum = idx;
- DMXScreenInfo oldDMXScreen;
- int i;
-
- /* Return failure if dynamic addition/removal of screens is disabled */
- 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;
- }
-
- /* Cannot add a screen that does not exist */
- if (idx < 0 || idx >= dmxNumScreens) return 1;
- pScreen = screenInfo.screens[idx];
- dmxScreen = &dmxScreens[idx];
-
- /* Cannot attach to a screen that is already opened */
- 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);
-
- /* Save old info */
- oldDMXScreen = *dmxScreen;
-
- /* Copy the name to the new screen */
- dmxScreen->name = strdup(attr->displayName);
-
- /* Open display and get all of the screen info */
- if (!dmxOpenDisplay(dmxScreen)) {
- dmxLog(dmxWarning,
- "dmxOpenDisplay: Unable to open display %s\n",
- dmxScreen->name);
-
- /* Restore the old screen */
- *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);
-
- /* Restore the old screen */
- *dmxScreen = oldDMXScreen;
- return 1;
- }
-
- dmxGetColormaps(dmxScreen);
- dmxGetPixmapFormats(dmxScreen);
-
- /* Verify that the screen to be added has the same info as the
- * previously added screen. */
- 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);
-
- /* Restore the old screen */
- *dmxScreen = oldDMXScreen;
- return 1;
- }
-
- /* Initialize the BE screen resources */
- dmxBEScreenInit(idx, screenInfo.screens[idx]);
-
- /* TODO: Handle GLX visual initialization. GLXProxy needs to be
- * updated to handle dynamic addition/removal of screens. */
-
- /* Create default stipple */
- dmxBECreatePixmap(pScreen->PixmapPerDepth[0]);
- dmxBERestorePixmap(pScreen->PixmapPerDepth[0]);
-
- /* Create the scratch GCs */
- dmxBECreateScratchGCs(idx);
-
- /* Create the default font */
- (void)dmxBELoadFont(pScreen, defaultFont);
-
- /* Create all resources that don't depend on windows */
- for (i = currentMaxClients; --i >= 0; )
- if (clients[i])
- FindAllClientResources(clients[i], dmxBECreateResources,
- (pointer)idx);
-
- /* Create window hierarchy (top down) */
- dmxBECreateWindowTree(idx);
-
- /* Restore the picture state for RENDER */
- for (i = currentMaxClients; --i >= 0; )
- if (clients[i])
- FindClientResourcesByType(clients[i],PictureType,
- dmxBERestoreRenderPict,(pointer)idx);
-
- /* Restore the glyph state for RENDER */
- for (i = currentMaxClients; --i >= 0; )
- if (clients[i])
- FindClientResourcesByType(clients[i],GlyphSetType,
- dmxBERestoreRenderGlyph,(pointer)idx);
-
- /* Refresh screen by generating exposure events for all windows */
- dmxForceExposures(idx);
-
- dmxSync(&dmxScreens[idx], TRUE);
-
- /* We used these to compare the old and new screens. They are no
- * longer needed since we have a newly attached screen, so we can
- * now free the old screen's resources. */
- XFree(oldDMXScreen.beVisuals);
- XFree(oldDMXScreen.beDepths);
- XFree(oldDMXScreen.bePixmapFormats);
- /* TODO: should oldDMXScreen.name be freed?? */
-
-#ifdef PANORAMIX
- if (!noPanoramiXExtension)
- return dmxConfigureScreenWindows(1, &scrnNum, attr, NULL);
- else
-#endif
- return 0; /* Success */
-}
-
-/*
- * Resources that may have state on the BE server and need to be freed:
- *
- * RT_NONE
- * RT_WINDOW
- * RT_PIXMAP
- * RT_GC
- * RT_FONT
- * RT_CURSOR
- * RT_COLORMAP
- * RT_CMAPENTRY
- * RT_OTHERCLIENT
- * RT_PASSIVEGRAB
- * XRT_WINDOW
- * XRT_PIXMAP
- * XRT_GC
- * XRT_COLORMAP
- * XRT_PICTURE
- * PictureType
- * PictFormatType
- * GlyphSetType
- * ClientType
- * EventType
- * RT_INPUTCLIENT
- * XETrapType
- * RTCounter
- * RTAwait
- * RTAlarmClient
- * RT_XKBCLIENT
- * RTContext
- * TagResType
- * StalledResType
- * SecurityAuthorizationResType
- * RTEventClient
- * __glXContextRes
- * __glXClientRes
- * __glXPixmapRes
- * __glXWindowRes
- * __glXPbufferRes
- */
-
-#ifdef PANORAMIX
-/** Search the Xinerama XRT_PIXMAP resources for the pixmap that needs
- * to have its image saved. */
-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;
-
- dixLookupResourceByType((pointer*) &pPix, pXinPix->info[idx].id,
- RT_PIXMAP, NullClient, DixUnknownAccess);
- if (pPix != pDst) return; /* Not a match.... Next! */
-
- for (i = 0; i < PanoramiXNumScreens; i++) {
- PixmapPtr pSrc;
- dmxPixPrivPtr pSrcPriv = NULL;
-
- if (i == idx) continue; /* Self replication is bad */
-
- dixLookupResourceByType((pointer*) &pSrc, pXinPix->info[i].id,
- RT_PIXMAP, NullClient, DixUnknownAccess);
- pSrcPriv = DMX_GET_PIXMAP_PRIV(pSrc);
- if (pSrcPriv->pixmap) {
- FoundPixImage = True;
- return;
- }
- }
- }
-}
-#endif
-
-/** Save the pixmap image only when there is not another screen with
- * that pixmap from which the image can be read when the screen is
- * reattached. To do this, we first try to find a pixmap on another
- * screen corresponding to the one we are trying to save. If we find
- * one, then we do not need to save the image data since during
- * reattachment, the image data can be read from that other pixmap.
- * However, if we do not find one, then we need to save the image data.
- * The common case for these are for the default stipple and root
- * tile. */
-static void dmxBESavePixmap(PixmapPtr pPixmap)
-{
-#ifdef PANORAMIX
- int i;
-
- /* If Xinerama is not active, there's nothing we can do (see comment
- * in #else below for more info). */
- if (noPanoramiXExtension) return;
-
- FoundPixImage = False;
- for (i = currentMaxClients; --i >= 0; )
- if (clients[i])
- FindAllClientResources(clients[i], dmxBEFindPixmapImage,
- (pointer)pPixmap);
-
- /* Save the image only if there is no other screens that have a
- * pixmap that corresponds to the one we are trying to save. */
- 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
- /* NOTE: The only time there is a pixmap on another screen that
- * corresponds to the one we are trying to save is when Xinerama is
- * active. Otherwise, the pixmap image data is only stored on a
- * single screen, which means that once it is detached, that data is
- * lost. We could save the data here, but then that would require
- * us to implement the ability for Xdmx to keep the pixmap up to
- * date while the screen is detached, which is beyond the scope of
- * the current project. */
- return;
-#endif
-}
-
-/** Destroy resources on the back-end server. This function is called
- * from #dmxDetachScreen() via the dix layer's FindAllResources
- * function. It walks all resources, compares them to the screen
- * number passed in as \a n and calls the appropriate DMX function to
- * free the associated resource on the back-end server. */
-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)) {
- /* Window resources are destroyed below in dmxBEDestroyWindowTree */
- } 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);
- } else if ((type & TypeMask) == (PictureType & TypeMask)) {
- PicturePtr pPict = value;
- if (pPict->pDrawable->pScreen->myNum == scrnNum) {
- /* Free the pixmaps on the backend if needed */
- 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);
- } else {
- /* Other resource types??? */
- }
-}
-
-/** Destroy the scratch GCs that are created per depth. */
-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]);
-}
-
-/** Destroy window hierachy on back-end server. To ensure that all
- * XDestroyWindow() calls succeed, they must be performed in a bottom
- * up order so that windows are not destroyed before their children.
- * XDestroyWindow(), which is called from #dmxBEDestroyWindow(), will
- * destroy a window as well as all of it's children. */
-static void dmxBEDestroyWindowTree(int idx)
-{
- WindowPtr pWin = screenInfo.screens[idx]->root;
- WindowPtr pChild = pWin;
-
- while (1) {
- if (pChild->firstChild) {
- pChild = pChild->firstChild;
- continue;
- }
-
- /* Destroy the window */
- dmxBEDestroyWindow(pChild);
-
- /* Make sure we destroy the window's border and background
- * pixmaps if they exist */
- 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;
- }
-}
-
-/** Detach back-end screen. */
-int dmxDetachScreen(int idx)
-{
- DMXScreenInfo *dmxScreen = &dmxScreens[idx];
- int i;
-
- /* Return failure if dynamic addition/removal of screens is disabled */
- 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;
- }
-
- /* Cannot remove a screen that does not exist */
- if (idx < 0 || idx >= dmxNumScreens) return 1;
-
- /* Cannot detach from a screen that is not opened */
- 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);
-
- /* Detach input */
- dmxInputDetachAll(dmxScreen);
-
- /* Save all relevant state (TODO) */
-
- /* Free all non-window resources related to this screen */
- for (i = currentMaxClients; --i >= 0; )
- if (clients[i])
- FindAllClientResources(clients[i], dmxBEDestroyResources,
- (pointer)idx);
-
- /* Free scratch GCs */
- dmxBEDestroyScratchGCs(idx);
-
- /* Free window resources related to this screen */
- dmxBEDestroyWindowTree(idx);
-
- /* Free default stipple */
- dmxBESavePixmap(screenInfo.screens[idx]->PixmapPerDepth[0]);
- dmxBEFreePixmap(screenInfo.screens[idx]->PixmapPerDepth[0]);
-
- /* Free the remaining screen resources and close the screen */
- dmxBECloseScreen(screenInfo.screens[idx]);
-
- /* Adjust the cursor boundaries (paints detached console window) */
- dmxAdjustCursorBoundaries();
-
- return 0; /* Success */
-}
+/*
+ * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Author:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ * Kevin E. Martin <kem@redhat.com>
+ *
+ */
+
+/** \file
+ * This file provides the only interface to the X server extension support
+ * in programs/Xserver/Xext. Those programs should only include dmxext.h
+ */
+
+#ifdef HAVE_DMX_CONFIG_H
+#include <dmx-config.h>
+#endif
+
+#include <stdlib.h>
+
+#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"
+#include "dmxpict.h"
+#include "dmxinput.h"
+#include "dmxsync.h"
+#include "dmxscrinit.h"
+#include "input/dmxinputinit.h"
+
+#include "windowstr.h"
+#include "inputstr.h" /* For DeviceIntRec */
+#include <X11/extensions/dmxproto.h> /* For DMX_BAD_* */
+#include "cursorstr.h"
+
+/* The default font is declared in dix/globals.c, but is not included in
+ * _any_ header files. */
+extern FontPtr defaultFont;
+
+/** This routine provides information to the DMX protocol extension
+ * about a particular screen. */
+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;
+}
+
+/** This routine provides information to the DMX protocol extension
+ * about a particular window. */
+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;
+ }
+
+ /* Compute display-relative coordinates */
+ 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;
+ }
+
+ /* Convert to window-relative coordinates */
+ 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; /* NOTE: The upper left hand corner of */
+ attr->shiftY = 0; /* the desktop is always <0,0>. */
+}
+
+/** Return the total number of devices, not just #dmxNumInputs. The
+ * number returned should be the same as that returned by
+ * XListInputDevices. */
+int dmxGetInputCount(void)
+{
+ int i, total;
+
+ for (total = i = 0; i < dmxNumInputs; i++) total += dmxInputs[i].numDevs;
+ return total;
+}
+
+/** Return information about the device with id = \a deviceId. This
+ * information is primarily for the #ProcDMXGetInputAttributes()
+ * function, which does not have access to the appropriate data
+ * structure. */
+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; /* Success */
+ }
+ }
+ return -1; /* Failure */
+}
+
+/** Reinitialized the cursor boundaries. */
+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);
+ }
+}
+
+/** Add an input with the specified attributes. If the input is added,
+ * the physical id is returned in \a deviceId. */
+int dmxAddInput(DMXInputAttributesPtr attr, int *id)
+{
+ int retcode = BadValue;
+
+ if (attr->inputType == 1) /* console */
+ retcode = dmxInputAttachConsole(attr->name, attr->sendsCore, id);
+ else if (attr->inputType == 2) /* backend */
+ retcode = dmxInputAttachBackend(attr->physicalScreen,
+ attr->sendsCore,id);
+
+ if (retcode == Success) {
+ /* Adjust the cursor boundaries */
+ dmxAdjustCursorBoundaries();
+
+ /* Force completion of the changes */
+ dmxSync(NULL, TRUE);
+ }
+
+ return retcode;
+}
+
+/** Remove the input with physical id \a id. */
+int dmxRemoveInput(int id)
+{
+ return dmxInputDetachId(id);
+}
+
+/** Return the value of #dmxNumScreens -- the total number of backend
+ * screens in use (these are logical screens and may be larger than the
+ * number of backend displays). */
+unsigned long dmxGetNumScreens(void)
+{
+ return dmxNumScreens;
+}
+
+/** Make sure that #dmxCreateAndRealizeWindow has been called for \a
+ * pWindow. */
+void dmxForceWindowCreation(WindowPtr pWindow)
+{
+ dmxWinPrivPtr pWinPriv = DMX_GET_WINDOW_PRIV(pWindow);
+ if (!pWinPriv->window) dmxCreateAndRealizeWindow(pWindow, TRUE);
+}
+
+/** Flush pending syncs for all screens. */
+void dmxFlushPendingSyncs(void)
+{
+ dmxSync(NULL, TRUE);
+}
+
+/** Update DMX's screen resources to match those of the newly moved
+ * and/or resized "root" window. */
+void dmxUpdateScreenResources(ScreenPtr pScreen, int x, int y, int w, int h)
+{
+ DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+ WindowPtr pRoot = pScreen->root;
+ WindowPtr pChild;
+ Bool anyMarked = FALSE;
+
+ /* Handle special case where width and/or height are zero */
+ if (w == 0 || h == 0) {
+ w = 1;
+ h = 1;
+ }
+
+ /* Change screen size */
+ pScreen->width = w;
+ pScreen->height = h;
+
+ /* Reset the root window's drawable's size */
+ pRoot->drawable.width = w;
+ pRoot->drawable.height = h;
+
+ /* Set the root window's new winSize and borderSize */
+ 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;
+
+ /* Recompute this screen's mmWidth & mmHeight */
+ pScreen->mmWidth =
+ (w * 254 + dmxScreen->beXDPI * 5) / (dmxScreen->beXDPI * 10);
+ pScreen->mmHeight =
+ (h * 254 + dmxScreen->beYDPI * 5) / (dmxScreen->beYDPI * 10);
+
+ /* Recompute this screen's window's clip rects as follows: */
+ /* 1. Mark all of root's children's windows */
+ for (pChild = pRoot->firstChild; pChild; pChild = pChild->nextSib)
+ anyMarked |= pScreen->MarkOverlappedWindows(pChild, pChild,
+ (WindowPtr *)NULL);
+
+ /* 2. Set the root window's borderClip */
+ pRoot->borderClip.extents.x1 = 0;
+ pRoot->borderClip.extents.y1 = 0;
+ pRoot->borderClip.extents.x2 = w;
+ pRoot->borderClip.extents.y2 = h;
+
+ /* 3. Set the root window's clipList */
+ if (anyMarked) {
+ /* If any windows have been marked, set the root window's
+ * clipList to be broken since it will be recalculated in
+ * ValidateTree()
+ */
+ RegionBreak(&pRoot->clipList);
+ } else {
+ /* Otherwise, we just set it directly since there are no
+ * windows visible on this screen
+ */
+ pRoot->clipList.extents.x1 = 0;
+ pRoot->clipList.extents.y1 = 0;
+ pRoot->clipList.extents.x2 = w;
+ pRoot->clipList.extents.y2 = h;
+ }
+
+ /* 4. Revalidate all clip rects and generate expose events */
+ if (anyMarked) {
+ pScreen->ValidateTree(pRoot, NULL, VTBroken);
+ pScreen->HandleExposures(pRoot);
+ if (pScreen->PostValidateTree)
+ pScreen->PostValidateTree(pRoot, NULL, VTBroken);
+ }
+}
+
+#ifdef PANORAMIX
+#include "panoramiXsrv.h"
+
+/** Change the "screen" window attributes by resizing the actual window
+ * on the back-end display (if necessary). */
+static void dmxConfigureScreenWindow(int idx,
+ int x, int y, int w, int h)
+{
+ DMXScreenInfo *dmxScreen = &dmxScreens[idx];
+ ScreenPtr pScreen = screenInfo.screens[idx];
+
+ /* Resize "screen" window */
+ if (dmxScreen->scrnX != x ||
+ dmxScreen->scrnY != y ||
+ dmxScreen->scrnWidth != w ||
+ dmxScreen->scrnHeight != h) {
+ dmxResizeScreenWindow(pScreen, x, y, w, h);
+ }
+
+ /* Change "screen" window values */
+ dmxScreen->scrnX = x;
+ dmxScreen->scrnY = y;
+ dmxScreen->scrnWidth = w;
+ dmxScreen->scrnHeight = h;
+}
+
+/** Change the "root" window position and size by resizing the actual
+ * window on the back-end display (if necessary) and updating all of
+ * DMX's resources by calling #dmxUpdateScreenResources. */
+static void dmxConfigureRootWindow(int idx, int x, int y, int w, int h)
+{
+ DMXScreenInfo *dmxScreen = &dmxScreens[idx];
+ WindowPtr pRoot = screenInfo.screens[idx]->root;
+
+ /* NOTE: Either this function or the ones that it calls must handle
+ * the case where w == 0 || h == 0. Currently, the functions that
+ * this one calls handle that case. */
+
+ /* 1. Resize "root" window */
+ if (dmxScreen->rootX != x ||
+ dmxScreen->rootY != y ||
+ dmxScreen->rootWidth != w ||
+ dmxScreen->rootHeight != h) {
+ dmxResizeRootWindow(pRoot, x, y, w, h);
+ }
+
+ /* 2. Update all of the screen's resources associated with this root
+ * window */
+ if (dmxScreen->rootWidth != w ||
+ dmxScreen->rootHeight != h) {
+ dmxUpdateScreenResources(screenInfo.screens[idx], x, y, w, h);
+ }
+
+ /* Change "root" window values */
+ dmxScreen->rootX = x;
+ dmxScreen->rootY = y;
+ dmxScreen->rootWidth = w;
+ dmxScreen->rootHeight = h;
+}
+
+/** Change the "root" window's origin by updating DMX's internal data
+ * structures (dix and Xinerama) to use the new origin and adjust the
+ * positions of windows that overlap this "root" window. */
+static void dmxSetRootWindowOrigin(int idx, int x, int y)
+{
+ DMXScreenInfo *dmxScreen = &dmxScreens[idx];
+ ScreenPtr pScreen = screenInfo.screens[idx];
+ WindowPtr pRoot = pScreen->root;
+ WindowPtr pChild;
+ int xoff;
+ int yoff;
+
+ /* Change "root" window's origin */
+ dmxScreen->rootXOrigin = x;
+ dmxScreen->rootYOrigin = y;
+
+ /* Compute offsets here in case <x,y> has been changed above */
+ xoff = x - pScreen->x;
+ yoff = y - pScreen->y;
+
+ /* Adjust the root window's position */
+ pScreen->x = dmxScreen->rootXOrigin;
+ pScreen->y = dmxScreen->rootYOrigin;
+
+ /* Recalculate the Xinerama regions and data structs */
+ XineramaReinitData(pScreen);
+
+ /* Adjust each of the root window's children */
+ if (!idx) ReinitializeRootWindow(screenInfo.screens[0]->root, xoff, yoff);
+ pChild = pRoot->firstChild;
+ while (pChild) {
+ /* Adjust child window's position */
+ pScreen->MoveWindow(pChild,
+ pChild->origin.x - wBorderWidth(pChild) - xoff,
+ pChild->origin.y - wBorderWidth(pChild) - yoff,
+ pChild->nextSib,
+ VTMove);
+
+ /* Note that the call to MoveWindow will eventually call
+ * dmxPositionWindow which will automatically create a
+ * window if it is now exposed on screen (for lazy window
+ * creation optimization) and it will properly set the
+ * offscreen flag.
+ */
+
+ pChild = pChild->nextSib;
+ }
+}
+
+/** Configure the attributes of each "screen" and "root" window. */
+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;
+
+ /* Check for illegal values */
+ if (idx < 0 || idx >= dmxNumScreens) return BadValue;
+
+ /* The "screen" and "root" windows must have valid sizes */
+ if (attr->screenWindowWidth <= 0 || attr->screenWindowHeight <= 0 ||
+ attr->rootWindowWidth < 0 || attr->rootWindowHeight < 0)
+ return DMX_BAD_VALUE;
+
+ /* The "screen" window must fit entirely within the BE display */
+ 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;
+
+ /* The "root" window must fit entirely within the "screen" window */
+ if (attr->rootWindowXoffset < 0 ||
+ attr->rootWindowYoffset < 0 ||
+ attr->rootWindowXoffset
+ + attr->rootWindowWidth > attr->screenWindowWidth ||
+ attr->rootWindowYoffset
+ + attr->rootWindowHeight > attr->screenWindowHeight)
+ return DMX_BAD_VALUE;
+
+ /* The "root" window must not expose unaddressable coordinates */
+ if (attr->rootWindowXorigin < 0 ||
+ attr->rootWindowYorigin < 0 ||
+ attr->rootWindowXorigin + attr->rootWindowWidth > 32767 ||
+ attr->rootWindowYorigin + attr->rootWindowHeight > 32767)
+ return DMX_BAD_VALUE;
+
+ /* The "root" window must fit within the global bounding box */
+ if (attr->rootWindowXorigin
+ + attr->rootWindowWidth > (unsigned)dmxGlobalWidth ||
+ attr->rootWindowYorigin
+ + attr->rootWindowHeight > (unsigned)dmxGlobalHeight)
+ return DMX_BAD_VALUE;
+
+ /* FIXME: Handle the rest of the illegal value checking */
+ }
+
+ /* No illegal values found */
+ 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);
+
+ /* Configure "screen" window */
+ dmxConfigureScreenWindow(idx,
+ attr->screenWindowXoffset,
+ attr->screenWindowYoffset,
+ attr->screenWindowWidth,
+ attr->screenWindowHeight);
+
+ /* Configure "root" window */
+ dmxConfigureRootWindow(idx,
+ attr->rootWindowXoffset,
+ attr->rootWindowYoffset,
+ attr->rootWindowWidth,
+ attr->rootWindowHeight);
+
+
+ /* Set "root" window's origin */
+ dmxSetRootWindowOrigin(idx,
+ attr->rootWindowXorigin,
+ attr->rootWindowYorigin);
+ }
+
+ /* Adjust the cursor boundaries */
+ dmxAdjustCursorBoundaries();
+
+ /* Force completion of the changes */
+ dmxSync(NULL, TRUE);
+
+ return Success;
+}
+
+/** Configure the attributes of the global desktop. */
+int dmxConfigureDesktop(DMXDesktopAttributesPtr attribs)
+{
+ if (attribs->width <= 0 || attribs->width >= 32767 ||
+ attribs->height <= 0 || attribs->height >= 32767)
+ return DMX_BAD_VALUE;
+
+ /* If the desktop is shrinking, adjust the "root" windows on each
+ * "screen" window to only show the visible desktop. Also, handle
+ * the special case where the desktop shrinks such that the it no
+ * longer overlaps an portion of a "screen" window. */
+ 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);
+ }
+ }
+ }
+
+ /* Set the global width/height */
+ dmxSetWidthHeight(attribs->width, attribs->height);
+
+ /* Handle shift[XY] changes */
+ if (attribs->shiftX || attribs->shiftY) {
+ int i;
+ for (i = 0; i < dmxNumScreens; i++) {
+ ScreenPtr pScreen = screenInfo.screens[i];
+ WindowPtr pChild = pScreen->root->firstChild;
+ while (pChild) {
+ /* Adjust child window's position */
+ pScreen->MoveWindow(pChild,
+ pChild->origin.x - wBorderWidth(pChild)
+ - attribs->shiftX,
+ pChild->origin.y - wBorderWidth(pChild)
+ - attribs->shiftY,
+ pChild->nextSib,
+ VTMove);
+
+ /* Note that the call to MoveWindow will eventually call
+ * dmxPositionWindow which will automatically create a
+ * window if it is now exposed on screen (for lazy
+ * window creation optimization) and it will properly
+ * set the offscreen flag.
+ */
+
+ pChild = pChild->nextSib;
+ }
+ }
+ }
+
+ /* Update connection block, Xinerama, etc. -- these appears to
+ * already be handled in dmxConnectionBlockCallback(), which is
+ * called from dmxAdjustCursorBoundaries() [below]. */
+
+ /* Adjust the cursor boundaries */
+ dmxAdjustCursorBoundaries();
+
+ /* Force completion of the changes */
+ dmxSync(NULL, TRUE);
+
+ return Success;
+}
+#endif
+
+/** Create the scratch GCs per depth. */
+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;
+
+/** Search the Xinerama XRT_PIXMAP resources for the pixmap that needs
+ * to have its image restored. When it is found, see if there is
+ * another screen with the same image. If so, copy the pixmap image
+ * from the existing screen to the newly created pixmap. */
+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;
+
+ dixLookupResourceByType((pointer*) &pPix, pXinPix->info[idx].id,
+ RT_PIXMAP, NullClient, DixUnknownAccess);
+ if (pPix != pDst) return; /* Not a match.... Next! */
+
+ for (i = 0; i < PanoramiXNumScreens; i++) {
+ PixmapPtr pSrc;
+ dmxPixPrivPtr pSrcPriv = NULL;
+
+ if (i == idx) continue; /* Self replication is bad */
+
+ dixLookupResourceByType((pointer*) &pSrc, pXinPix->info[i].id,
+ RT_PIXMAP, NullClient, DixUnknownAccess);
+ 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;
+
+ /* This should never happen, but just in case.... */
+ if (pSrc->drawable.width != pDst->drawable.width ||
+ pSrc->drawable.height != pDst->drawable.height)
+ return;
+
+ /* Copy from src pixmap to dst pixmap */
+ 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
+
+/** Restore the pixmap image either from another screen or from an image
+ * that was saved when the screen was previously detached. */
+static void dmxBERestorePixmap(PixmapPtr pPixmap)
+{
+#ifdef PANORAMIX
+ int i;
+
+ /* If Xinerama is not active, there's nothing we can do (see comment
+ * in #else below for more info). */
+ 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);
+
+ /* No corresponding pixmap image was found on other screens, so we
+ * need to copy it from the saved image when the screen was detached
+ * (if available). */
+ 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
+ /* If Xinerama is not enabled, then there is no other copy of the
+ * pixmap image that we can restore. Saving all pixmap data is not
+ * a feasible option since there is no mechanism for updating pixmap
+ * data when a screen is detached, which means that the data that
+ * was previously saved would most likely be out of date. */
+ dmxLog(dmxWarning, "Cannot restore pixmap image\n");
+ return;
+#endif
+}
+
+/** Create resources on the back-end server. This function is called
+ * from #dmxAttachScreen() via the dix layer's FindAllResources
+ * function. It walks all resources, compares them to the screen
+ * number passed in as \a n and calls the appropriate DMX function to
+ * create the associated resource on the back-end server. */
+static void dmxBECreateResources(pointer value, XID id, RESTYPE type,
+ pointer n)
+{
+ int scrnNum = (uintptr_t)n;
+ ScreenPtr pScreen = screenInfo.screens[scrnNum];
+
+ if ((type & TypeMask) == (RT_WINDOW & TypeMask)) {
+ /* Window resources are created below in dmxBECreateWindowTree */
+ } 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) {
+ /* Create the GC on the back-end server */
+ dmxBECreateGC(pScreen, pGC);
+ /* Create any pixmaps associated with this GC */
+ 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);
+ }
+ /* Update the GC on the back-end server */
+ 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
+ /* TODO: Recreate Picture and GlyphSet resources */
+ } else if ((type & TypeMask) == (PictureType & TypeMask)) {
+ /* Picture resources are created when windows are created */
+ } else if ((type & TypeMask) == (GlyphSetType & TypeMask)) {
+ dmxBEFreeGlyphSet(pScreen, (GlyphSetPtr)value);
+#endif
+ } else {
+ /* Other resource types??? */
+ }
+}
+
+/** Create window hierachy on back-end server. The window tree is
+ * created in a special order (bottom most subwindow first) so that the
+ * #dmxCreateNonRootWindow() function does not need to recursively call
+ * itself to create each window's parents. This is required so that we
+ * have the opportunity to create each window's border and background
+ * pixmaps (where appropriate) before the window is created. */
+static void dmxBECreateWindowTree(int idx)
+{
+ DMXScreenInfo *dmxScreen = &dmxScreens[idx];
+ WindowPtr pRoot = screenInfo.screens[idx]->root;
+ dmxWinPrivPtr pWinPriv = DMX_GET_WINDOW_PRIV(pRoot);
+ WindowPtr pWin;
+
+ /* Create the pixmaps associated with the root window */
+ if (!pRoot->borderIsPixel) {
+ dmxBECreatePixmap(pRoot->border.pixmap);
+ dmxBERestorePixmap(pRoot->border.pixmap);
+ }
+ if (pRoot->backgroundState == BackgroundPixmap) {
+ dmxBECreatePixmap(pRoot->background.pixmap);
+ dmxBERestorePixmap(pRoot->background.pixmap);
+ }
+
+ /* Create root window first */
+ dmxScreen->rootWin = pWinPriv->window = dmxCreateRootWindow(pRoot);
+ XMapWindow(dmxScreen->beDisplay, dmxScreen->rootWin);
+
+ pWin = pRoot->lastChild;
+ while (pWin) {
+ pWinPriv = DMX_GET_WINDOW_PRIV(pWin);
+
+ /* Create the pixmaps regardless of whether or not the
+ * window is created or not due to lazy window creation.
+ */
+ if (!pWin->borderIsPixel) {
+ dmxBECreatePixmap(pWin->border.pixmap);
+ dmxBERestorePixmap(pWin->border.pixmap);
+ }
+ if (pWin->backgroundState == BackgroundPixmap) {
+ dmxBECreatePixmap(pWin->background.pixmap);
+ dmxBERestorePixmap(pWin->background.pixmap);
+ }
+
+ /* Reset the window attributes */
+ dmxGetDefaultWindowAttributes(pWin,
+ &pWinPriv->cmap,
+ &pWinPriv->visual);
+
+ /* Create the window */
+ if (pWinPriv->mapped && !pWinPriv->offscreen)
+ dmxCreateAndRealizeWindow(pWin, TRUE);
+
+ /* Next, create the bottom-most child */
+ if (pWin->lastChild) {
+ pWin = pWin->lastChild;
+ continue;
+ }
+
+ /* If the window has no children, move on to the next higher window */
+ while (!pWin->prevSib && (pWin != pRoot))
+ pWin = pWin->parent;
+
+ if (pWin->prevSib) {
+ pWin = pWin->prevSib;
+ continue;
+ }
+
+ /* When we reach the root window, we are finished */
+ if (pWin == pRoot)
+ break;
+ }
+}
+
+/* Refresh screen by generating exposure events for all windows */
+static void dmxForceExposures(int idx)
+{
+ ScreenPtr pScreen = screenInfo.screens[idx];
+ WindowPtr pRoot = pScreen->root;
+ Bool anyMarked = FALSE;
+ WindowPtr pChild;
+
+ for (pChild = pRoot->firstChild; pChild; pChild = pChild->nextSib)
+ anyMarked |= pScreen->MarkOverlappedWindows(pChild, pChild,
+ (WindowPtr *)NULL);
+ if (anyMarked) {
+ /* If any windows have been marked, set the root window's
+ * clipList to be broken since it will be recalculated in
+ * ValidateTree()
+ */
+ RegionBreak(&pRoot->clipList);
+ pScreen->ValidateTree(pRoot, NULL, VTBroken);
+ pScreen->HandleExposures(pRoot);
+ if (pScreen->PostValidateTree)
+ pScreen->PostValidateTree(pRoot, NULL, VTBroken);
+ }
+}
+
+/** Compare the new and old screens to see if they are compatible. */
+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;
+}
+
+/** Restore Render's picture */
+static void dmxBERestoreRenderPict(pointer value, XID id, pointer n)
+{
+ PicturePtr pPicture = value; /* The picture */
+ DrawablePtr pDraw = pPicture->pDrawable; /* The picture's drawable */
+ int scrnNum = (uintptr_t)n;
+
+ if (pDraw->pScreen->myNum != scrnNum) {
+ /* Picture not on the screen we are restoring*/
+ return;
+ }
+
+ if (pDraw->type == DRAWABLE_PIXMAP) {
+ PixmapPtr pPixmap = (PixmapPtr)pDraw;
+
+ /* Create and restore the pixmap drawable */
+ dmxBECreatePixmap(pPixmap);
+ dmxBERestorePixmap(pPixmap);
+ }
+
+ dmxBECreatePicture(pPicture);
+}
+
+/** Restore Render's glyphs */
+static void dmxBERestoreRenderGlyph(pointer value, XID id, pointer n)
+{
+ GlyphSetPtr glyphSet = value;
+ int scrnNum = (uintptr_t)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]) {
+ /* Only restore glyphs on the screen we are attaching */
+ return;
+ }
+
+ /* First we must create the glyph set on the backend. */
+ if ((beret = dmxBECreateGlyphSet(scrnNum, glyphSet)) != Success) {
+ dmxLog(dmxWarning,
+ "\tdmxBERestoreRenderGlyph failed to create glyphset!\n");
+ return;
+ }
+
+ /* Now for the complex part, restore the glyph data */
+ table = glyphSet->hash.table;
+
+ /* We need to know how much memory to allocate for this part */
+ 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);
+ }
+
+ /* Now allocate the memory we need */
+ images = calloc(len_images, sizeof(char));
+ gids = malloc(glyphSet->hash.tableEntries*sizeof(Glyph));
+ glyphs = malloc(glyphSet->hash.tableEntries*sizeof(XGlyphInfo));
+
+ pos = images;
+ ctr = 0;
+
+ /* Fill the allocated memory with the proper data */
+ for (i = 0; i < glyphSet->hash.hashSet->size; i++) {
+ GlyphRefPtr gr = &table[i];
+ GlyphPtr gl = gr->glyph;
+
+ if (!gl || gl == DeletedGlyph) continue;
+
+ /* First lets put the data into gids */
+ gids[ctr] = gr->signature;
+
+ /* Next do the glyphs data structures */
+ 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;
+
+ /* Copy the images from the DIX's data into the buffer */
+ memcpy(pos, gl+1, gl->size - sizeof(gl->info));
+ pos += gl->size - sizeof(gl->info);
+ ctr++;
+ }
+
+ /* Now restore the glyph data */
+ XRenderAddGlyphs(dmxScreen->beDisplay, glyphPriv->glyphSets[scrnNum],
+ gids,glyphs, glyphSet->hash.tableEntries, images,
+ len_images);
+
+ /* Clean up */
+ free(images);
+ free(gids);
+ free(glyphs);
+}
+
+/** Reattach previously detached back-end screen. */
+int dmxAttachScreen(int idx, DMXScreenAttributesPtr attr)
+{
+ ScreenPtr pScreen;
+ DMXScreenInfo *dmxScreen;
+ CARD32 scrnNum = idx;
+ DMXScreenInfo oldDMXScreen;
+ int i;
+
+ /* Return failure if dynamic addition/removal of screens is disabled */
+ 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;
+ }
+
+ /* Cannot add a screen that does not exist */
+ if (idx < 0 || idx >= dmxNumScreens) return 1;
+ pScreen = screenInfo.screens[idx];
+ dmxScreen = &dmxScreens[idx];
+
+ /* Cannot attach to a screen that is already opened */
+ 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);
+
+ /* Save old info */
+ oldDMXScreen = *dmxScreen;
+
+ /* Copy the name to the new screen */
+ dmxScreen->name = strdup(attr->displayName);
+
+ /* Open display and get all of the screen info */
+ if (!dmxOpenDisplay(dmxScreen)) {
+ dmxLog(dmxWarning,
+ "dmxOpenDisplay: Unable to open display %s\n",
+ dmxScreen->name);
+
+ /* Restore the old screen */
+ *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);
+
+ /* Restore the old screen */
+ *dmxScreen = oldDMXScreen;
+ return 1;
+ }
+
+ dmxGetColormaps(dmxScreen);
+ dmxGetPixmapFormats(dmxScreen);
+
+ /* Verify that the screen to be added has the same info as the
+ * previously added screen. */
+ 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);
+
+ /* Restore the old screen */
+ *dmxScreen = oldDMXScreen;
+ return 1;
+ }
+
+ /* Initialize the BE screen resources */
+ dmxBEScreenInit(idx, screenInfo.screens[idx]);
+
+ /* TODO: Handle GLX visual initialization. GLXProxy needs to be
+ * updated to handle dynamic addition/removal of screens. */
+
+ /* Create default stipple */
+ dmxBECreatePixmap(pScreen->PixmapPerDepth[0]);
+ dmxBERestorePixmap(pScreen->PixmapPerDepth[0]);
+
+ /* Create the scratch GCs */
+ dmxBECreateScratchGCs(idx);
+
+ /* Create the default font */
+ (void)dmxBELoadFont(pScreen, defaultFont);
+
+ /* Create all resources that don't depend on windows */
+ for (i = currentMaxClients; --i >= 0; )
+ if (clients[i])
+ FindAllClientResources(clients[i], dmxBECreateResources,
+ (pointer)(uintptr_t)idx);
+
+ /* Create window hierarchy (top down) */
+ dmxBECreateWindowTree(idx);
+
+ /* Restore the picture state for RENDER */
+ for (i = currentMaxClients; --i >= 0; )
+ if (clients[i])
+ FindClientResourcesByType(clients[i],PictureType,
+ dmxBERestoreRenderPict,
+ (pointer)(uintptr_t)idx);
+
+ /* Restore the glyph state for RENDER */
+ for (i = currentMaxClients; --i >= 0; )
+ if (clients[i])
+ FindClientResourcesByType(clients[i],GlyphSetType,
+ dmxBERestoreRenderGlyph,
+ (pointer)(uintptr_t)idx);
+
+ /* Refresh screen by generating exposure events for all windows */
+ dmxForceExposures(idx);
+
+ dmxSync(&dmxScreens[idx], TRUE);
+
+ /* We used these to compare the old and new screens. They are no
+ * longer needed since we have a newly attached screen, so we can
+ * now free the old screen's resources. */
+ XFree(oldDMXScreen.beVisuals);
+ XFree(oldDMXScreen.beDepths);
+ XFree(oldDMXScreen.bePixmapFormats);
+ /* TODO: should oldDMXScreen.name be freed?? */
+
+#ifdef PANORAMIX
+ if (!noPanoramiXExtension)
+ return dmxConfigureScreenWindows(1, &scrnNum, attr, NULL);
+ else
+#endif
+ return 0; /* Success */
+}
+
+/*
+ * Resources that may have state on the BE server and need to be freed:
+ *
+ * RT_NONE
+ * RT_WINDOW
+ * RT_PIXMAP
+ * RT_GC
+ * RT_FONT
+ * RT_CURSOR
+ * RT_COLORMAP
+ * RT_CMAPENTRY
+ * RT_OTHERCLIENT
+ * RT_PASSIVEGRAB
+ * XRT_WINDOW
+ * XRT_PIXMAP
+ * XRT_GC
+ * XRT_COLORMAP
+ * XRT_PICTURE
+ * PictureType
+ * PictFormatType
+ * GlyphSetType
+ * ClientType
+ * EventType
+ * RT_INPUTCLIENT
+ * XETrapType
+ * RTCounter
+ * RTAwait
+ * RTAlarmClient
+ * RT_XKBCLIENT
+ * RTContext
+ * TagResType
+ * StalledResType
+ * SecurityAuthorizationResType
+ * RTEventClient
+ * __glXContextRes
+ * __glXClientRes
+ * __glXPixmapRes
+ * __glXWindowRes
+ * __glXPbufferRes
+ */
+
+#ifdef PANORAMIX
+/** Search the Xinerama XRT_PIXMAP resources for the pixmap that needs
+ * to have its image saved. */
+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;
+
+ dixLookupResourceByType((pointer*) &pPix, pXinPix->info[idx].id,
+ RT_PIXMAP, NullClient, DixUnknownAccess);
+ if (pPix != pDst) return; /* Not a match.... Next! */
+
+ for (i = 0; i < PanoramiXNumScreens; i++) {
+ PixmapPtr pSrc;
+ dmxPixPrivPtr pSrcPriv = NULL;
+
+ if (i == idx) continue; /* Self replication is bad */
+
+ dixLookupResourceByType((pointer*) &pSrc, pXinPix->info[i].id,
+ RT_PIXMAP, NullClient, DixUnknownAccess);
+ pSrcPriv = DMX_GET_PIXMAP_PRIV(pSrc);
+ if (pSrcPriv->pixmap) {
+ FoundPixImage = True;
+ return;
+ }
+ }
+ }
+}
+#endif
+
+/** Save the pixmap image only when there is not another screen with
+ * that pixmap from which the image can be read when the screen is
+ * reattached. To do this, we first try to find a pixmap on another
+ * screen corresponding to the one we are trying to save. If we find
+ * one, then we do not need to save the image data since during
+ * reattachment, the image data can be read from that other pixmap.
+ * However, if we do not find one, then we need to save the image data.
+ * The common case for these are for the default stipple and root
+ * tile. */
+static void dmxBESavePixmap(PixmapPtr pPixmap)
+{
+#ifdef PANORAMIX
+ int i;
+
+ /* If Xinerama is not active, there's nothing we can do (see comment
+ * in #else below for more info). */
+ if (noPanoramiXExtension) return;
+
+ FoundPixImage = False;
+ for (i = currentMaxClients; --i >= 0; )
+ if (clients[i])
+ FindAllClientResources(clients[i], dmxBEFindPixmapImage,
+ (pointer)pPixmap);
+
+ /* Save the image only if there is no other screens that have a
+ * pixmap that corresponds to the one we are trying to save. */
+ 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
+ /* NOTE: The only time there is a pixmap on another screen that
+ * corresponds to the one we are trying to save is when Xinerama is
+ * active. Otherwise, the pixmap image data is only stored on a
+ * single screen, which means that once it is detached, that data is
+ * lost. We could save the data here, but then that would require
+ * us to implement the ability for Xdmx to keep the pixmap up to
+ * date while the screen is detached, which is beyond the scope of
+ * the current project. */
+ return;
+#endif
+}
+
+/** Destroy resources on the back-end server. This function is called
+ * from #dmxDetachScreen() via the dix layer's FindAllResources
+ * function. It walks all resources, compares them to the screen
+ * number passed in as \a n and calls the appropriate DMX function to
+ * free the associated resource on the back-end server. */
+static void dmxBEDestroyResources(pointer value, XID id, RESTYPE type,
+ pointer n)
+{
+ int scrnNum = (uintptr_t)n;
+ ScreenPtr pScreen = screenInfo.screens[scrnNum];
+
+ if ((type & TypeMask) == (RT_WINDOW & TypeMask)) {
+ /* Window resources are destroyed below in dmxBEDestroyWindowTree */
+ } 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);
+ } else if ((type & TypeMask) == (PictureType & TypeMask)) {
+ PicturePtr pPict = value;
+ if (pPict->pDrawable->pScreen->myNum == scrnNum) {
+ /* Free the pixmaps on the backend if needed */
+ 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);
+ } else {
+ /* Other resource types??? */
+ }
+}
+
+/** Destroy the scratch GCs that are created per depth. */
+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]);
+}
+
+/** Destroy window hierachy on back-end server. To ensure that all
+ * XDestroyWindow() calls succeed, they must be performed in a bottom
+ * up order so that windows are not destroyed before their children.
+ * XDestroyWindow(), which is called from #dmxBEDestroyWindow(), will
+ * destroy a window as well as all of it's children. */
+static void dmxBEDestroyWindowTree(int idx)
+{
+ WindowPtr pWin = screenInfo.screens[idx]->root;
+ WindowPtr pChild = pWin;
+
+ while (1) {
+ if (pChild->firstChild) {
+ pChild = pChild->firstChild;
+ continue;
+ }
+
+ /* Destroy the window */
+ dmxBEDestroyWindow(pChild);
+
+ /* Make sure we destroy the window's border and background
+ * pixmaps if they exist */
+ 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;
+ }
+}
+
+/** Detach back-end screen. */
+int dmxDetachScreen(int idx)
+{
+ DMXScreenInfo *dmxScreen = &dmxScreens[idx];
+ int i;
+
+ /* Return failure if dynamic addition/removal of screens is disabled */
+ 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;
+ }
+
+ /* Cannot remove a screen that does not exist */
+ if (idx < 0 || idx >= dmxNumScreens) return 1;
+
+ /* Cannot detach from a screen that is not opened */
+ 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);
+
+ /* Detach input */
+ dmxInputDetachAll(dmxScreen);
+
+ /* Save all relevant state (TODO) */
+
+ /* Free all non-window resources related to this screen */
+ for (i = currentMaxClients; --i >= 0; )
+ if (clients[i])
+ FindAllClientResources(clients[i], dmxBEDestroyResources,
+ (pointer)(uintptr_t)idx);
+
+ /* Free scratch GCs */
+ dmxBEDestroyScratchGCs(idx);
+
+ /* Free window resources related to this screen */
+ dmxBEDestroyWindowTree(idx);
+
+ /* Free default stipple */
+ dmxBESavePixmap(screenInfo.screens[idx]->PixmapPerDepth[0]);
+ dmxBEFreePixmap(screenInfo.screens[idx]->PixmapPerDepth[0]);
+
+ /* Free the remaining screen resources and close the screen */
+ dmxBECloseScreen(screenInfo.screens[idx]);
+
+ /* Adjust the cursor boundaries (paints detached console window) */
+ dmxAdjustCursorBoundaries();
+
+ return 0; /* Success */
+}
diff --git a/xorg-server/hw/dmx/dmxgc.c b/xorg-server/hw/dmx/dmxgc.c
index 10e93c110..f10f9a074 100644
--- a/xorg-server/hw/dmx/dmxgc.c
+++ b/xorg-server/hw/dmx/dmxgc.c
@@ -1,421 +1,416 @@
-/*
- * Copyright 2001-2004 Red Hat Inc., Durham, North Carolina.
- *
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation on the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-/*
- * Authors:
- * Kevin E. Martin <kem@redhat.com>
- *
- */
-
-/** \file
- * This file provides support for GCs. */
-
-#ifdef HAVE_DMX_CONFIG_H
-#include <dmx-config.h>
-#endif
-
-#include "dmx.h"
-#include "dmxsync.h"
-#include "dmxgc.h"
-#include "dmxgcops.h"
-#include "dmxpixmap.h"
-#include "dmxfont.h"
-
-#include "gcstruct.h"
-#include "pixmapstr.h"
-#include "migc.h"
-
-static GCFuncs dmxGCFuncs = {
- dmxValidateGC,
- dmxChangeGC,
- dmxCopyGC,
- dmxDestroyGC,
- dmxChangeClip,
- dmxDestroyClip,
- dmxCopyClip,
-};
-
-static GCOps dmxGCOps = {
- dmxFillSpans,
- dmxSetSpans,
- dmxPutImage,
- dmxCopyArea,
- dmxCopyPlane,
- dmxPolyPoint,
- dmxPolylines,
- dmxPolySegment,
- dmxPolyRectangle,
- dmxPolyArc,
- dmxFillPolygon,
- dmxPolyFillRect,
- dmxPolyFillArc,
- dmxPolyText8,
- dmxPolyText16,
- dmxImageText8,
- dmxImageText16,
- dmxImageGlyphBlt,
- dmxPolyGlyphBlt,
- dmxPushPixels
-};
-
-/** Initialize the GC on \a pScreen */
-Bool dmxInitGC(ScreenPtr pScreen)
-{
- if (!dixRegisterPrivateKey(&dmxGCPrivateKeyRec, PRIVATE_GC, sizeof(dmxGCPrivRec)))
- return FALSE;
- return TRUE;
-}
-
-/** Create the GC on the back-end server. */
-void dmxBECreateGC(ScreenPtr pScreen, GCPtr pGC)
-{
- DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
- dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
- int i;
-
- for (i = 0; i < dmxScreen->beNumPixmapFormats; i++) {
- if (pGC->depth == dmxScreen->bePixmapFormats[i].depth) {
- unsigned long mask;
- XGCValues gcvals;
-
- mask = GCGraphicsExposures;
- gcvals.graphics_exposures = FALSE;
-
- /* Create GC in the back-end servers */
- pGCPriv->gc = XCreateGC(dmxScreen->beDisplay,
- dmxScreen->scrnDefDrawables[i],
- mask, &gcvals);
- break;
- }
- }
-}
-
-/** Create a graphics context on the back-end server associated /a pGC's
- * screen. */
-Bool dmxCreateGC(GCPtr pGC)
-{
- ScreenPtr pScreen = pGC->pScreen;
- DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
- dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
- Bool ret;
-
- DMX_UNWRAP(CreateGC, dmxScreen, pScreen);
- if ((ret = pScreen->CreateGC(pGC))) {
- /* Save the old funcs */
- pGCPriv->funcs = pGC->funcs;
- pGCPriv->ops = NULL;
-
- pGC->funcs = &dmxGCFuncs;
-
- if (dmxScreen->beDisplay) {
- dmxBECreateGC(pScreen, pGC);
- } else {
- pGCPriv->gc = NULL;
- }
-
- /* Check for "magic special case"
- * 1. see CreateGC in dix/gc.c for more info
- * 2. see dmxChangeGC for more info
- */
- pGCPriv->msc = (!pGC->tileIsPixel && !pGC->tile.pixmap);
- }
- DMX_WRAP(CreateGC, dmxCreateGC, dmxScreen, pScreen);
-
- return ret;
-}
-
-/** Validate a graphics context, \a pGC, locally in the DMX server and
- * recompute the composite clip, if necessary. */
-void dmxValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
-{
- dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
-
- DMX_GC_FUNC_PROLOGUE(pGC);
-#if 0
- pGC->funcs->ValidateGC(pGC, changes, pDrawable);
-#endif
-
- if (pDrawable->type == DRAWABLE_WINDOW ||
- pDrawable->type == DRAWABLE_PIXMAP) {
- /* Save the old ops, since we're about to change the ops in the
- * epilogue.
- */
- pGCPriv->ops = pGC->ops;
- } else {
- pGCPriv->ops = NULL;
- }
-
- /* If the client clip is different or moved OR the subwindowMode has
- * changed OR the window's clip has changed since the last
- * validation, then we need to recompute the composite clip.
- */
- if ((changes & (GCClipXOrigin |
- GCClipYOrigin |
- GCClipMask |
- GCSubwindowMode)) ||
- (pDrawable->serialNumber !=
- (pGC->serialNumber & DRAWABLE_SERIAL_BITS))) {
- miComputeCompositeClip(pGC, pDrawable);
- }
-
- DMX_GC_FUNC_EPILOGUE(pGC);
-}
-
-/** Set the values in the graphics context on the back-end server
- * associated with \a pGC's screen. */
-void dmxChangeGC(GCPtr pGC, unsigned long mask)
-{
- ScreenPtr pScreen = pGC->pScreen;
- DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
- dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
- XGCValues v;
-
- DMX_GC_FUNC_PROLOGUE(pGC);
-#if 0
- pGC->funcs->ChangeGC(pGC, mask);
-#endif
-
- /* Handle "magic special case" from CreateGC */
- if (pGCPriv->msc) {
- /* The "magic special case" is used to handle the case where a
- * foreground pixel is set when the GC is created so that a
- * "pseudo default-tile" can be created and used in case the
- * fillstyle was set to FillTiled. This specific case is tested
- * in xtest (XCreateGC test #3). What has happened in dix by
- * the time it reaches here is (1) the pGC->tile.pixel has been
- * set to pGC->fgPixel and pGC->tileIsPixel is set, (2) if a
- * tile has also been set, then pGC->tileIsPixel is unset and
- * pGC->tile.pixmap is initialized; else, the default tile is
- * created and pGC->tileIsPixel is unset and pGC->tile.pixmap is
- * initialized to the "pseudo default-tile". In either case,
- * pGC->tile.pixmap is set; however, in the "magic special case"
- * the mask is not updated to allow us to detect that we should
- * initialize the GCTile in the back-end server. Thus, we catch
- * this case in dmxCreateGC and add GCTile to the mask here.
- * Are there any cases that I've missed?
- */
-
- /* Make sure that the tile.pixmap is set, just in case the user
- * set GCTile in the mask but forgot to set vals.pixmap
- */
- if (pGC->tile.pixmap) mask |= GCTile;
-
- /* This only happens once when the GC is created */
- pGCPriv->msc = FALSE;
- }
-
- /* Update back-end server's gc */
- if (mask & GCFunction) v.function = pGC->alu;
- if (mask & GCPlaneMask) v.plane_mask = pGC->planemask;
- if (mask & GCForeground) v.foreground = pGC->fgPixel;
- if (mask & GCBackground) v.background = pGC->bgPixel;
- if (mask & GCLineWidth) v.line_width = pGC->lineWidth;
- if (mask & GCLineStyle) v.line_style = pGC->lineStyle;
- if (mask & GCCapStyle) v.cap_style = pGC->capStyle;
- if (mask & GCJoinStyle) v.join_style = pGC->joinStyle;
- if (mask & GCFillStyle) v.fill_style = pGC->fillStyle;
- if (mask & GCFillRule) v.fill_rule = pGC->fillRule;
- if (mask & GCTile) {
- if (pGC->tileIsPixel) {
- mask &= ~GCTile;
- } else {
- dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pGC->tile.pixmap);
- v.tile = (Drawable)pPixPriv->pixmap;
- }
- }
- if (mask & GCStipple) {
- dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pGC->stipple);
- v.stipple = (Drawable)pPixPriv->pixmap;
- }
- if (mask & GCTileStipXOrigin) v.ts_x_origin = pGC->patOrg.x;
- if (mask & GCTileStipYOrigin) v.ts_y_origin = pGC->patOrg.y;
- if (mask & GCFont) {
- if (dmxScreen->beDisplay) {
- dmxFontPrivPtr pFontPriv;
- pFontPriv = FontGetPrivate(pGC->font, dmxFontPrivateIndex);
- v.font = pFontPriv->font[pScreen->myNum]->fid;
- } else {
- mask &= ~GCFont;
- }
- }
- if (mask & GCSubwindowMode) v.subwindow_mode = pGC->subWindowMode;
-
- /* Graphics exposures are not needed on the back-ends since they can
- be generated on the front-end thereby saving bandwidth. */
- if (mask & GCGraphicsExposures) mask &= ~GCGraphicsExposures;
-
- if (mask & GCClipXOrigin) v.clip_x_origin = pGC->clipOrg.x;
- if (mask & GCClipYOrigin) v.clip_y_origin = pGC->clipOrg.y;
- if (mask & GCClipMask) mask &= ~GCClipMask; /* See ChangeClip */
- if (mask & GCDashOffset) v.dash_offset = pGC->dashOffset;
- if (mask & GCDashList) {
- mask &= ~GCDashList;
- if (dmxScreen->beDisplay)
- XSetDashes(dmxScreen->beDisplay, pGCPriv->gc,
- pGC->dashOffset, (char *)pGC->dash,
- pGC->numInDashList);
- }
- if (mask & GCArcMode) v.arc_mode = pGC->arcMode;
-
- if (mask && dmxScreen->beDisplay) {
- XChangeGC(dmxScreen->beDisplay, pGCPriv->gc, mask, &v);
- dmxSync(dmxScreen, FALSE);
- }
-
- DMX_GC_FUNC_EPILOGUE(pGC);
-}
-
-/** Copy \a pGCSrc to \a pGCDst on the back-end server associated with
- * \a pGCSrc's screen. */
-void dmxCopyGC(GCPtr pGCSrc, unsigned long changes, GCPtr pGCDst)
-{
- ScreenPtr pScreen = pGCSrc->pScreen;
- DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
- dmxGCPrivPtr pGCSrcPriv = DMX_GET_GC_PRIV(pGCSrc);
- dmxGCPrivPtr pGCDstPriv = DMX_GET_GC_PRIV(pGCDst);
-
- DMX_GC_FUNC_PROLOGUE(pGCDst);
- pGCDst->funcs->CopyGC(pGCSrc, changes, pGCDst);
-
- /* Copy the GC on the back-end server */
- if (dmxScreen->beDisplay)
- XCopyGC(dmxScreen->beDisplay, pGCSrcPriv->gc, changes, pGCDstPriv->gc);
-
- DMX_GC_FUNC_EPILOGUE(pGCDst);
-}
-
-/** Free the \a pGC on the back-end server. */
-Bool dmxBEFreeGC(GCPtr pGC)
-{
- ScreenPtr pScreen = pGC->pScreen;
- DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
- dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
-
- if (pGCPriv->gc) {
- XFreeGC(dmxScreen->beDisplay, pGCPriv->gc);
- pGCPriv->gc = NULL;
- return TRUE;
- }
-
- return FALSE;
-}
-
-/** Destroy the graphics context, \a pGC and free the corresponding GC
- * on the back-end server. */
-void dmxDestroyGC(GCPtr pGC)
-{
- ScreenPtr pScreen = pGC->pScreen;
- DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
-
- DMX_GC_FUNC_PROLOGUE(pGC);
-
- /* Free the GC on the back-end server */
- if (dmxScreen->beDisplay)
- dmxBEFreeGC(pGC);
-
- pGC->funcs->DestroyGC(pGC);
- DMX_GC_FUNC_EPILOGUE(pGC);
-}
-
-/** Change the clip rects for a GC. */
-void dmxChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects)
-{
- ScreenPtr pScreen = pGC->pScreen;
- DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
- dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
- XRectangle *pRects;
- BoxPtr pBox;
- int i, nRects;
-
- DMX_GC_FUNC_PROLOGUE(pGC);
- pGC->funcs->ChangeClip(pGC, type, pvalue, nrects);
-
- /* Set the client clip on the back-end server */
- switch (pGC->clientClipType) {
- case CT_NONE:
- if (dmxScreen->beDisplay)
- XSetClipMask(dmxScreen->beDisplay, pGCPriv->gc, None);
- break;
-
- case CT_REGION:
- if (dmxScreen->beDisplay) {
- nRects = RegionNumRects((RegionPtr)pGC->clientClip);
- pRects = malloc(nRects * sizeof(*pRects));
- pBox = RegionRects((RegionPtr)pGC->clientClip);
-
- for (i = 0; i < nRects; i++) {
- 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(dmxScreen->beDisplay, pGCPriv->gc,
- pGC->clipOrg.x, pGC->clipOrg.y,
- pRects, nRects, Unsorted);
-
- free(pRects);
- }
- break;
-
- case CT_PIXMAP:
- case CT_UNSORTED:
- case CT_YSORTED:
- case CT_YXSORTED:
- case CT_YXBANDED:
- /* These clip types are condensed down to either NONE or REGION
- in the mi code */
- break;
- }
-
- DMX_GC_FUNC_EPILOGUE(pGC);
-}
-
-/** Destroy a GC's clip rects. */
-void dmxDestroyClip(GCPtr pGC)
-{
- ScreenPtr pScreen = pGC->pScreen;
- DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
- dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
-
- DMX_GC_FUNC_PROLOGUE(pGC);
- pGC->funcs->DestroyClip(pGC);
-
- /* Set the client clip on the back-end server to None */
- if (dmxScreen->beDisplay)
- XSetClipMask(dmxScreen->beDisplay, pGCPriv->gc, None);
-
- DMX_GC_FUNC_EPILOGUE(pGC);
-}
-
-/** Copy a GC's clip rects. */
-void dmxCopyClip(GCPtr pGCDst, GCPtr pGCSrc)
-{
- DMX_GC_FUNC_PROLOGUE(pGCDst);
- pGCDst->funcs->CopyClip(pGCDst, pGCSrc);
- DMX_GC_FUNC_EPILOGUE(pGCDst);
-}
+/*
+ * Copyright 2001-2004 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Kevin E. Martin <kem@redhat.com>
+ *
+ */
+
+/** \file
+ * This file provides support for GCs. */
+
+#ifdef HAVE_DMX_CONFIG_H
+#include <dmx-config.h>
+#endif
+
+#include "dmx.h"
+#include "dmxsync.h"
+#include "dmxgc.h"
+#include "dmxgcops.h"
+#include "dmxpixmap.h"
+#include "dmxfont.h"
+
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "migc.h"
+
+static GCFuncs dmxGCFuncs = {
+ dmxValidateGC,
+ dmxChangeGC,
+ dmxCopyGC,
+ dmxDestroyGC,
+ dmxChangeClip,
+ dmxDestroyClip,
+ dmxCopyClip,
+};
+
+static GCOps dmxGCOps = {
+ dmxFillSpans,
+ dmxSetSpans,
+ dmxPutImage,
+ dmxCopyArea,
+ dmxCopyPlane,
+ dmxPolyPoint,
+ dmxPolylines,
+ dmxPolySegment,
+ dmxPolyRectangle,
+ dmxPolyArc,
+ dmxFillPolygon,
+ dmxPolyFillRect,
+ dmxPolyFillArc,
+ dmxPolyText8,
+ dmxPolyText16,
+ dmxImageText8,
+ dmxImageText16,
+ dmxImageGlyphBlt,
+ dmxPolyGlyphBlt,
+ dmxPushPixels
+};
+
+/** Initialize the GC on \a pScreen */
+Bool dmxInitGC(ScreenPtr pScreen)
+{
+ if (!dixRegisterPrivateKey(&dmxGCPrivateKeyRec, PRIVATE_GC, sizeof(dmxGCPrivRec)))
+ return FALSE;
+ return TRUE;
+}
+
+/** Create the GC on the back-end server. */
+void dmxBECreateGC(ScreenPtr pScreen, GCPtr pGC)
+{
+ DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+ dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
+ int i;
+
+ for (i = 0; i < dmxScreen->beNumPixmapFormats; i++) {
+ if (pGC->depth == dmxScreen->bePixmapFormats[i].depth) {
+ unsigned long mask;
+ XGCValues gcvals;
+
+ mask = GCGraphicsExposures;
+ gcvals.graphics_exposures = FALSE;
+
+ /* Create GC in the back-end servers */
+ pGCPriv->gc = XCreateGC(dmxScreen->beDisplay,
+ dmxScreen->scrnDefDrawables[i],
+ mask, &gcvals);
+ break;
+ }
+ }
+}
+
+/** Create a graphics context on the back-end server associated /a pGC's
+ * screen. */
+Bool dmxCreateGC(GCPtr pGC)
+{
+ ScreenPtr pScreen = pGC->pScreen;
+ DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+ dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
+ Bool ret;
+
+ DMX_UNWRAP(CreateGC, dmxScreen, pScreen);
+ if ((ret = pScreen->CreateGC(pGC))) {
+ /* Save the old funcs */
+ pGCPriv->funcs = pGC->funcs;
+ pGCPriv->ops = NULL;
+
+ pGC->funcs = &dmxGCFuncs;
+
+ if (dmxScreen->beDisplay) {
+ dmxBECreateGC(pScreen, pGC);
+ } else {
+ pGCPriv->gc = NULL;
+ }
+
+ /* Check for "magic special case"
+ * 1. see CreateGC in dix/gc.c for more info
+ * 2. see dmxChangeGC for more info
+ */
+ pGCPriv->msc = (!pGC->tileIsPixel && !pGC->tile.pixmap);
+ }
+ DMX_WRAP(CreateGC, dmxCreateGC, dmxScreen, pScreen);
+
+ return ret;
+}
+
+/** Validate a graphics context, \a pGC, locally in the DMX server and
+ * recompute the composite clip, if necessary. */
+void dmxValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
+{
+ dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
+
+ DMX_GC_FUNC_PROLOGUE(pGC);
+#if 0
+ pGC->funcs->ValidateGC(pGC, changes, pDrawable);
+#endif
+
+ if (pDrawable->type == DRAWABLE_WINDOW ||
+ pDrawable->type == DRAWABLE_PIXMAP) {
+ /* Save the old ops, since we're about to change the ops in the
+ * epilogue.
+ */
+ pGCPriv->ops = pGC->ops;
+ } else {
+ pGCPriv->ops = NULL;
+ }
+
+ /* If the client clip is different or moved OR the subwindowMode has
+ * changed OR the window's clip has changed since the last
+ * validation, then we need to recompute the composite clip.
+ */
+ if ((changes & (GCClipXOrigin |
+ GCClipYOrigin |
+ GCClipMask |
+ GCSubwindowMode)) ||
+ (pDrawable->serialNumber !=
+ (pGC->serialNumber & DRAWABLE_SERIAL_BITS))) {
+ miComputeCompositeClip(pGC, pDrawable);
+ }
+
+ DMX_GC_FUNC_EPILOGUE(pGC);
+}
+
+/** Set the values in the graphics context on the back-end server
+ * associated with \a pGC's screen. */
+void dmxChangeGC(GCPtr pGC, unsigned long mask)
+{
+ ScreenPtr pScreen = pGC->pScreen;
+ DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+ dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
+ XGCValues v;
+
+ DMX_GC_FUNC_PROLOGUE(pGC);
+#if 0
+ pGC->funcs->ChangeGC(pGC, mask);
+#endif
+
+ /* Handle "magic special case" from CreateGC */
+ if (pGCPriv->msc) {
+ /* The "magic special case" is used to handle the case where a
+ * foreground pixel is set when the GC is created so that a
+ * "pseudo default-tile" can be created and used in case the
+ * fillstyle was set to FillTiled. This specific case is tested
+ * in xtest (XCreateGC test #3). What has happened in dix by
+ * the time it reaches here is (1) the pGC->tile.pixel has been
+ * set to pGC->fgPixel and pGC->tileIsPixel is set, (2) if a
+ * tile has also been set, then pGC->tileIsPixel is unset and
+ * pGC->tile.pixmap is initialized; else, the default tile is
+ * created and pGC->tileIsPixel is unset and pGC->tile.pixmap is
+ * initialized to the "pseudo default-tile". In either case,
+ * pGC->tile.pixmap is set; however, in the "magic special case"
+ * the mask is not updated to allow us to detect that we should
+ * initialize the GCTile in the back-end server. Thus, we catch
+ * this case in dmxCreateGC and add GCTile to the mask here.
+ * Are there any cases that I've missed?
+ */
+
+ /* Make sure that the tile.pixmap is set, just in case the user
+ * set GCTile in the mask but forgot to set vals.pixmap
+ */
+ if (pGC->tile.pixmap) mask |= GCTile;
+
+ /* This only happens once when the GC is created */
+ pGCPriv->msc = FALSE;
+ }
+
+ /* Update back-end server's gc */
+ if (mask & GCFunction) v.function = pGC->alu;
+ if (mask & GCPlaneMask) v.plane_mask = pGC->planemask;
+ if (mask & GCForeground) v.foreground = pGC->fgPixel;
+ if (mask & GCBackground) v.background = pGC->bgPixel;
+ if (mask & GCLineWidth) v.line_width = pGC->lineWidth;
+ if (mask & GCLineStyle) v.line_style = pGC->lineStyle;
+ if (mask & GCCapStyle) v.cap_style = pGC->capStyle;
+ if (mask & GCJoinStyle) v.join_style = pGC->joinStyle;
+ if (mask & GCFillStyle) v.fill_style = pGC->fillStyle;
+ if (mask & GCFillRule) v.fill_rule = pGC->fillRule;
+ if (mask & GCTile) {
+ if (pGC->tileIsPixel) {
+ mask &= ~GCTile;
+ } else {
+ dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pGC->tile.pixmap);
+ v.tile = (Drawable)pPixPriv->pixmap;
+ }
+ }
+ if (mask & GCStipple) {
+ dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pGC->stipple);
+ v.stipple = (Drawable)pPixPriv->pixmap;
+ }
+ if (mask & GCTileStipXOrigin) v.ts_x_origin = pGC->patOrg.x;
+ if (mask & GCTileStipYOrigin) v.ts_y_origin = pGC->patOrg.y;
+ if (mask & GCFont) {
+ if (dmxScreen->beDisplay) {
+ dmxFontPrivPtr pFontPriv;
+ pFontPriv = FontGetPrivate(pGC->font, dmxFontPrivateIndex);
+ v.font = pFontPriv->font[pScreen->myNum]->fid;
+ } else {
+ mask &= ~GCFont;
+ }
+ }
+ if (mask & GCSubwindowMode) v.subwindow_mode = pGC->subWindowMode;
+
+ /* Graphics exposures are not needed on the back-ends since they can
+ be generated on the front-end thereby saving bandwidth. */
+ if (mask & GCGraphicsExposures) mask &= ~GCGraphicsExposures;
+
+ if (mask & GCClipXOrigin) v.clip_x_origin = pGC->clipOrg.x;
+ if (mask & GCClipYOrigin) v.clip_y_origin = pGC->clipOrg.y;
+ if (mask & GCClipMask) mask &= ~GCClipMask; /* See ChangeClip */
+ if (mask & GCDashOffset) v.dash_offset = pGC->dashOffset;
+ if (mask & GCDashList) {
+ mask &= ~GCDashList;
+ if (dmxScreen->beDisplay)
+ XSetDashes(dmxScreen->beDisplay, pGCPriv->gc,
+ pGC->dashOffset, (char *)pGC->dash,
+ pGC->numInDashList);
+ }
+ if (mask & GCArcMode) v.arc_mode = pGC->arcMode;
+
+ if (mask && dmxScreen->beDisplay) {
+ XChangeGC(dmxScreen->beDisplay, pGCPriv->gc, mask, &v);
+ dmxSync(dmxScreen, FALSE);
+ }
+
+ DMX_GC_FUNC_EPILOGUE(pGC);
+}
+
+/** Copy \a pGCSrc to \a pGCDst on the back-end server associated with
+ * \a pGCSrc's screen. */
+void dmxCopyGC(GCPtr pGCSrc, unsigned long changes, GCPtr pGCDst)
+{
+ ScreenPtr pScreen = pGCSrc->pScreen;
+ DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+ dmxGCPrivPtr pGCSrcPriv = DMX_GET_GC_PRIV(pGCSrc);
+ dmxGCPrivPtr pGCDstPriv = DMX_GET_GC_PRIV(pGCDst);
+
+ DMX_GC_FUNC_PROLOGUE(pGCDst);
+ pGCDst->funcs->CopyGC(pGCSrc, changes, pGCDst);
+
+ /* Copy the GC on the back-end server */
+ if (dmxScreen->beDisplay)
+ XCopyGC(dmxScreen->beDisplay, pGCSrcPriv->gc, changes, pGCDstPriv->gc);
+
+ DMX_GC_FUNC_EPILOGUE(pGCDst);
+}
+
+/** Free the \a pGC on the back-end server. */
+Bool dmxBEFreeGC(GCPtr pGC)
+{
+ ScreenPtr pScreen = pGC->pScreen;
+ DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+ dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
+
+ if (pGCPriv->gc) {
+ XFreeGC(dmxScreen->beDisplay, pGCPriv->gc);
+ pGCPriv->gc = NULL;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/** Destroy the graphics context, \a pGC and free the corresponding GC
+ * on the back-end server. */
+void dmxDestroyGC(GCPtr pGC)
+{
+ ScreenPtr pScreen = pGC->pScreen;
+ DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+
+ DMX_GC_FUNC_PROLOGUE(pGC);
+
+ /* Free the GC on the back-end server */
+ if (dmxScreen->beDisplay)
+ dmxBEFreeGC(pGC);
+
+ pGC->funcs->DestroyGC(pGC);
+ DMX_GC_FUNC_EPILOGUE(pGC);
+}
+
+/** Change the clip rects for a GC. */
+void dmxChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects)
+{
+ ScreenPtr pScreen = pGC->pScreen;
+ DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+ dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
+ XRectangle *pRects;
+ BoxPtr pBox;
+ int i, nRects;
+
+ DMX_GC_FUNC_PROLOGUE(pGC);
+ pGC->funcs->ChangeClip(pGC, type, pvalue, nrects);
+
+ /* Set the client clip on the back-end server */
+ switch (pGC->clientClipType) {
+ case CT_NONE:
+ if (dmxScreen->beDisplay)
+ XSetClipMask(dmxScreen->beDisplay, pGCPriv->gc, None);
+ break;
+
+ case CT_REGION:
+ if (dmxScreen->beDisplay) {
+ nRects = RegionNumRects((RegionPtr)pGC->clientClip);
+ pRects = malloc(nRects * sizeof(*pRects));
+ pBox = RegionRects((RegionPtr)pGC->clientClip);
+
+ for (i = 0; i < nRects; i++) {
+ 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(dmxScreen->beDisplay, pGCPriv->gc,
+ pGC->clipOrg.x, pGC->clipOrg.y,
+ pRects, nRects, Unsorted);
+
+ free(pRects);
+ }
+ break;
+
+ case CT_PIXMAP:
+ /* Condensed down to REGION in the mi code */
+ break;
+ }
+
+ DMX_GC_FUNC_EPILOGUE(pGC);
+}
+
+/** Destroy a GC's clip rects. */
+void dmxDestroyClip(GCPtr pGC)
+{
+ ScreenPtr pScreen = pGC->pScreen;
+ DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+ dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
+
+ DMX_GC_FUNC_PROLOGUE(pGC);
+ pGC->funcs->DestroyClip(pGC);
+
+ /* Set the client clip on the back-end server to None */
+ if (dmxScreen->beDisplay)
+ XSetClipMask(dmxScreen->beDisplay, pGCPriv->gc, None);
+
+ DMX_GC_FUNC_EPILOGUE(pGC);
+}
+
+/** Copy a GC's clip rects. */
+void dmxCopyClip(GCPtr pGCDst, GCPtr pGCSrc)
+{
+ DMX_GC_FUNC_PROLOGUE(pGCDst);
+ pGCDst->funcs->CopyClip(pGCDst, pGCSrc);
+ DMX_GC_FUNC_EPILOGUE(pGCDst);
+}
diff --git a/xorg-server/hw/dmx/input/dmxinputinit.c b/xorg-server/hw/dmx/input/dmxinputinit.c
index 4b10ecb17..5cbd620c9 100644
--- a/xorg-server/hw/dmx/input/dmxinputinit.c
+++ b/xorg-server/hw/dmx/input/dmxinputinit.c
@@ -1,1306 +1,1274 @@
-/*
- * Copyright 2002-2003 Red Hat Inc., Durham, North Carolina.
- *
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation on the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-/*
- * Authors:
- * Rickard E. (Rik) Faith <faith@redhat.com>
- *
- */
-
-/** \file
- * This file provides generic input support. Functions here set up
- * input and lead to the calling of low-level device drivers for
- * input. */
-
-#ifdef HAVE_DMX_CONFIG_H
-#include <dmx-config.h>
-#endif
-
-#define DMX_WINDOW_DEBUG 0
-
-#include "dmxinputinit.h"
-#include "dmxextension.h" /* For dmxInputCount */
-
-#include "dmxdummy.h"
-#include "dmxbackend.h"
-#include "dmxconsole.h"
-#include "dmxcommon.h"
-#include "dmxevents.h"
-#include "dmxmotion.h"
-#include "dmxprop.h"
-#include "config/dmxconfig.h"
-#include "dmxcursor.h"
-
-#include "lnx-keyboard.h"
-#include "lnx-ms.h"
-#include "lnx-ps2.h"
-#include "usb-keyboard.h"
-#include "usb-mouse.h"
-#include "usb-other.h"
-#include "usb-common.h"
-
-#include "dmxsigio.h"
-#include "dmxarg.h"
-
-#include "inputstr.h"
-#include "input.h"
-#include "mipointer.h"
-#include "windowstr.h"
-#include "mi.h"
-#include "xkbsrv.h"
-
-#include <X11/extensions/XI.h>
-#include <X11/extensions/XIproto.h>
-#include "exevents.h"
-#include "extinit.h"
-
-DMXLocalInputInfoPtr dmxLocalCorePointer, dmxLocalCoreKeyboard;
-
-static DMXLocalInputInfoRec DMXDummyMou = {
- "dummy-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
- NULL, NULL, NULL, NULL, NULL, dmxDummyMouGetInfo
-};
-
-static DMXLocalInputInfoRec DMXDummyKbd = {
- "dummy-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_LOCAL, 1,
- NULL, NULL, NULL, NULL, NULL, dmxDummyKbdGetInfo
-};
-
-static DMXLocalInputInfoRec DMXBackendMou = {
- "backend-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_BACKEND, 2,
- dmxBackendCreatePrivate, dmxBackendDestroyPrivate,
- dmxBackendInit, NULL, dmxBackendLateReInit, dmxBackendMouGetInfo,
- dmxCommonMouOn, dmxCommonMouOff, dmxBackendUpdatePosition,
- NULL, NULL, NULL,
- dmxBackendCollectEvents, dmxBackendProcessInput, dmxBackendFunctions, NULL,
- dmxCommonMouCtrl
-};
-
-static DMXLocalInputInfoRec DMXBackendKbd = {
- "backend-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_BACKEND,
- 1, /* With backend-mou or console-mou */
- dmxCommonCopyPrivate, NULL,
- dmxBackendInit, NULL, NULL, dmxBackendKbdGetInfo,
- dmxCommonKbdOn, dmxCommonKbdOff, NULL,
- NULL, NULL, NULL,
- NULL, NULL, NULL, NULL,
- NULL, dmxCommonKbdCtrl, dmxCommonKbdBell
-};
-
-static DMXLocalInputInfoRec DMXConsoleMou = {
- "console-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_CONSOLE, 2,
- dmxConsoleCreatePrivate, dmxConsoleDestroyPrivate,
- dmxConsoleInit, dmxConsoleReInit, NULL, dmxConsoleMouGetInfo,
- dmxCommonMouOn, dmxCommonMouOff, dmxConsoleUpdatePosition,
- NULL, NULL, NULL,
- dmxConsoleCollectEvents, NULL, dmxConsoleFunctions, dmxConsoleUpdateInfo,
- dmxCommonMouCtrl
-};
-
-static DMXLocalInputInfoRec DMXConsoleKbd = {
- "console-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_CONSOLE,
- 1, /* With backend-mou or console-mou */
- dmxCommonCopyPrivate, NULL,
- dmxConsoleInit, dmxConsoleReInit, NULL, dmxConsoleKbdGetInfo,
- dmxCommonKbdOn, dmxCommonKbdOff, NULL,
- NULL, NULL, NULL,
- NULL, NULL, NULL, NULL,
- NULL, dmxCommonKbdCtrl, dmxCommonKbdBell
-};
-
-static DMXLocalInputInfoRec DMXCommonOth = {
- "common-oth", DMX_LOCAL_OTHER, DMX_LOCAL_TYPE_COMMON, 1,
- dmxCommonCopyPrivate, NULL,
- NULL, NULL, NULL, dmxCommonOthGetInfo,
- dmxCommonOthOn, dmxCommonOthOff
-};
-
-
-static DMXLocalInputInfoRec DMXLocalDevices[] = {
- /* Dummy drivers that can compile on any OS */
-#ifdef __linux__
- /* Linux-specific drivers */
- {
- "kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_LOCAL, 1,
- kbdLinuxCreatePrivate, kbdLinuxDestroyPrivate,
- kbdLinuxInit, NULL, NULL, kbdLinuxGetInfo,
- kbdLinuxOn, kbdLinuxOff, NULL,
- kbdLinuxVTPreSwitch, kbdLinuxVTPostSwitch, kbdLinuxVTSwitch,
- kbdLinuxRead, NULL, NULL, NULL,
- NULL, kbdLinuxCtrl, kbdLinuxBell
- },
- {
- "ms", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
- msLinuxCreatePrivate, msLinuxDestroyPrivate,
- msLinuxInit, NULL, NULL, msLinuxGetInfo,
- msLinuxOn, msLinuxOff, NULL,
- msLinuxVTPreSwitch, msLinuxVTPostSwitch, NULL,
- msLinuxRead
- },
- {
- "ps2", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
- ps2LinuxCreatePrivate, ps2LinuxDestroyPrivate,
- ps2LinuxInit, NULL, NULL, ps2LinuxGetInfo,
- ps2LinuxOn, ps2LinuxOff, NULL,
- ps2LinuxVTPreSwitch, ps2LinuxVTPostSwitch, NULL,
- ps2LinuxRead
- },
-#endif
-#ifdef __linux__
- /* USB drivers, currently only for
- Linux, but relatively easy to port to
- other OSs */
- {
- "usb-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_LOCAL, 1,
- usbCreatePrivate, usbDestroyPrivate,
- kbdUSBInit, NULL, NULL, kbdUSBGetInfo,
- kbdUSBOn, usbOff, NULL,
- NULL, NULL, NULL,
- kbdUSBRead, NULL, NULL, NULL,
- NULL, kbdUSBCtrl
- },
- {
- "usb-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
- usbCreatePrivate, usbDestroyPrivate,
- mouUSBInit, NULL, NULL, mouUSBGetInfo,
- mouUSBOn, usbOff, NULL,
- NULL, NULL, NULL,
- mouUSBRead
- },
- {
- "usb-oth", DMX_LOCAL_OTHER, DMX_LOCAL_TYPE_LOCAL, 1,
- usbCreatePrivate, usbDestroyPrivate,
- othUSBInit, NULL, NULL, othUSBGetInfo,
- othUSBOn, usbOff, NULL,
- NULL, NULL, NULL,
- othUSBRead
- },
-#endif
- {
- "dummy-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
- NULL, NULL, NULL, NULL, NULL, dmxDummyMouGetInfo
- },
- {
- "dummy-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_LOCAL, 1,
- NULL, NULL, NULL, NULL, NULL, dmxDummyKbdGetInfo
- },
- { NULL } /* Must be last */
-};
-
-
-#if 11 /*BP*/
-void
-DDXRingBell(int volume, int pitch, int duration)
-{
- /* NO-OP */
-}
-
-/* taken from kdrive/src/kinput.c: */
-static void
-dmxKbdCtrl (DeviceIntPtr pDevice, KeybdCtrl *ctrl)
-{
-#if 0
- KdKeyboardInfo *ki;
-
- for (ki = kdKeyboards; ki; ki = ki->next) {
- if (ki->dixdev && ki->dixdev->id == pDevice->id)
- break;
- }
-
- if (!ki || !ki->dixdev || ki->dixdev->id != pDevice->id || !ki->driver)
- return;
-
- KdSetLeds(ki, ctrl->leds);
- ki->bellPitch = ctrl->bell_pitch;
- ki->bellDuration = ctrl->bell_duration;
-#endif
-}
-
-/* taken from kdrive/src/kinput.c: */
-static void
-dmxBell(int volume, DeviceIntPtr pDev, pointer arg, int something)
-{
-#if 0
- KeybdCtrl *ctrl = arg;
- KdKeyboardInfo *ki = NULL;
-
- for (ki = kdKeyboards; ki; ki = ki->next) {
- if (ki->dixdev && ki->dixdev->id == pDev->id)
- break;
- }
-
- if (!ki || !ki->dixdev || ki->dixdev->id != pDev->id || !ki->driver)
- return;
-
- KdRingBell(ki, volume, ctrl->bell_pitch, ctrl->bell_duration);
-#endif
-}
-
-#endif /*BP*/
-
-static void _dmxChangePointerControl(DMXLocalInputInfoPtr dmxLocal,
- PtrCtrl *ctrl)
-{
- if (!dmxLocal) return;
- dmxLocal->mctrl = *ctrl;
- if (dmxLocal->mCtrl) dmxLocal->mCtrl(&dmxLocal->pDevice->public, ctrl);
-}
-
-/** Change the pointer control information for the \a pDevice. If the
- * device sends core events, then also change the control information
- * for all of the pointer devices that send core events. */
-void dmxChangePointerControl(DeviceIntPtr pDevice, PtrCtrl *ctrl)
-{
- GETDMXLOCALFROMPDEVICE;
- int i, j;
-
- if (dmxLocal->sendsCore) { /* Do for all core devices */
- for (i = 0; i < dmxNumInputs; i++) {
- DMXInputInfo *dmxInput = &dmxInputs[i];
- if (dmxInput->detached) continue;
- for (j = 0; j < dmxInput->numDevs; j++)
- if (dmxInput->devs[j]->sendsCore)
- _dmxChangePointerControl(dmxInput->devs[j], ctrl);
- }
- } else { /* Do for this device only */
- _dmxChangePointerControl(dmxLocal, ctrl);
- }
-}
-
-static void _dmxKeyboardKbdCtrlProc(DMXLocalInputInfoPtr dmxLocal,
- KeybdCtrl *ctrl)
-{
- dmxLocal->kctrl = *ctrl;
- if (dmxLocal->kCtrl) {
- dmxLocal->kCtrl(&dmxLocal->pDevice->public, ctrl);
- if (dmxLocal->pDevice->kbdfeed) {
- XkbEventCauseRec cause;
- XkbSetCauseUnknown(&cause);
- /* Generate XKB events, as necessary */
- XkbUpdateIndicators(dmxLocal->pDevice, XkbAllIndicatorsMask, False,
- NULL, &cause);
- }
- }
-}
-
-
-/** Change the keyboard control information for the \a pDevice. If the
- * device sends core events, then also change the control information
- * for all of the keyboard devices that send core events. */
-void dmxKeyboardKbdCtrlProc(DeviceIntPtr pDevice, KeybdCtrl *ctrl)
-{
- GETDMXLOCALFROMPDEVICE;
- int i, j;
-
- if (dmxLocal->sendsCore) { /* Do for all core devices */
- for (i = 0; i < dmxNumInputs; i++) {
- DMXInputInfo *dmxInput = &dmxInputs[i];
- if (dmxInput->detached) continue;
- for (j = 0; j < dmxInput->numDevs; j++)
- if (dmxInput->devs[j]->sendsCore)
- _dmxKeyboardKbdCtrlProc(dmxInput->devs[j], ctrl);
- }
- } else { /* Do for this device only */
- _dmxKeyboardKbdCtrlProc(dmxLocal, ctrl);
- }
-}
-
-static void _dmxKeyboardBellProc(DMXLocalInputInfoPtr dmxLocal, int percent)
-{
- if (dmxLocal->kBell) dmxLocal->kBell(&dmxLocal->pDevice->public,
- percent,
- dmxLocal->kctrl.bell,
- dmxLocal->kctrl.bell_pitch,
- dmxLocal->kctrl.bell_duration);
-}
-
-/** Sound the bell on the device. If the device send core events, then
- * sound the bell on all of the devices that send core events. */
-void dmxKeyboardBellProc(int percent, DeviceIntPtr pDevice,
- pointer ctrl, int unknown)
-{
- GETDMXLOCALFROMPDEVICE;
- int i, j;
-
- if (dmxLocal->sendsCore) { /* Do for all core devices */
- for (i = 0; i < dmxNumInputs; i++) {
- DMXInputInfo *dmxInput = &dmxInputs[i];
- if (dmxInput->detached) continue;
- for (j = 0; j < dmxInput->numDevs; j++)
- if (dmxInput->devs[j]->sendsCore)
- _dmxKeyboardBellProc(dmxInput->devs[j], percent);
- }
- } else { /* Do for this device only */
- _dmxKeyboardBellProc(dmxLocal, percent);
- }
-}
-
-static void dmxKeyboardFreeNames(XkbComponentNamesPtr names)
-{
- if (names->keycodes) XFree(names->keycodes);
- if (names->types) XFree(names->types);
- if (names->compat) XFree(names->compat);
- if (names->symbols) XFree(names->symbols);
- if (names->geometry) XFree(names->geometry);
-}
-
-
-static int dmxKeyboardOn(DeviceIntPtr pDevice, DMXLocalInitInfo *info)
-{
- GETDMXINPUTFROMPDEVICE;
- XkbRMLVOSet rmlvo;
-
- rmlvo.rules = dmxConfigGetXkbRules();
- rmlvo.model = dmxConfigGetXkbModel();
- rmlvo.layout = dmxConfigGetXkbLayout();
- rmlvo.variant = dmxConfigGetXkbVariant();
- rmlvo.options = dmxConfigGetXkbOptions();
-
- XkbSetRulesDflts(&rmlvo);
- if (!info->force && (dmxInput->keycodes
- || dmxInput->symbols
- || dmxInput->geometry)) {
- if (info->freenames) dmxKeyboardFreeNames(&info->names);
- info->freenames = 0;
- info->names.keycodes = dmxInput->keycodes;
- info->names.types = NULL;
- info->names.compat = NULL;
- info->names.symbols = dmxInput->symbols;
- info->names.geometry = dmxInput->geometry;
-
- dmxLogInput(dmxInput, "XKEYBOARD: From command line: %s",
- info->names.keycodes);
- if (info->names.symbols && *info->names.symbols)
- dmxLogInputCont(dmxInput, " %s", info->names.symbols);
- if (info->names.geometry && *info->names.geometry)
- dmxLogInputCont(dmxInput, " %s", info->names.geometry);
- dmxLogInputCont(dmxInput, "\n");
- } else if (info->names.keycodes) {
- dmxLogInput(dmxInput, "XKEYBOARD: From device: %s",
- info->names.keycodes);
- if (info->names.symbols && *info->names.symbols)
- dmxLogInputCont(dmxInput, " %s", info->names.symbols);
- if (info->names.geometry && *info->names.geometry)
- dmxLogInputCont(dmxInput, " %s", info->names.geometry);
- dmxLogInputCont(dmxInput, "\n");
- } else {
- dmxLogInput(dmxInput, "XKEYBOARD: Defaults: %s %s %s %s %s\n",
- dmxConfigGetXkbRules(),
- dmxConfigGetXkbLayout(),
- dmxConfigGetXkbModel(),
- dmxConfigGetXkbVariant()
- ? dmxConfigGetXkbVariant() : "",
- dmxConfigGetXkbOptions()
- ? dmxConfigGetXkbOptions() : "");
- }
- InitKeyboardDeviceStruct(pDevice, &rmlvo,
- dmxKeyboardBellProc,
- dmxKeyboardKbdCtrlProc);
-
- if (info->freenames) dmxKeyboardFreeNames(&info->names);
-
- return Success;
-}
-
-
-static int dmxDeviceOnOff(DeviceIntPtr pDevice, int what)
-{
- GETDMXINPUTFROMPDEVICE;
- int fd;
- DMXLocalInitInfo info;
- int i;
- Atom btn_labels[MAX_BUTTONS] = {0}; /* FIXME */
- Atom axis_labels[MAX_VALUATORS] = {0}; /* FIXME */
-
- if (dmxInput->detached) return Success;
-
- memset(&info, 0, sizeof(info));
- switch (what) {
- case DEVICE_INIT:
- if (dmxLocal->init)
- dmxLocal->init(pDev);
- if (dmxLocal->get_info)
- dmxLocal->get_info(pDev, &info);
- if (info.keyboard) { /* XKEYBOARD makes this a special case */
- dmxKeyboardOn(pDevice, &info);
- break;
- }
- if (info.keyClass) {
- XkbRMLVOSet rmlvo;
-
- rmlvo.rules = dmxConfigGetXkbRules();
- rmlvo.model = dmxConfigGetXkbModel();
- rmlvo.layout = dmxConfigGetXkbLayout();
- rmlvo.variant = dmxConfigGetXkbVariant();
- rmlvo.options = dmxConfigGetXkbOptions();
-
- InitKeyboardDeviceStruct(pDevice,
- &rmlvo,
- dmxBell, dmxKbdCtrl);
- }
- if (info.buttonClass) {
- InitButtonClassDeviceStruct(pDevice, info.numButtons,
- btn_labels, info.map);
- }
- if (info.valuatorClass) {
- if (info.numRelAxes && dmxLocal->sendsCore) {
- InitValuatorClassDeviceStruct(pDevice, info.numRelAxes,
- axis_labels,
- GetMaximumEventsNum(),
- Relative);
- for (i = 0; i < info.numRelAxes; i++)
- InitValuatorAxisStruct(pDevice, i, axis_labels[i],
- info.minval[i], info.maxval[i],
- info.res[i],
- info.minres[i], info.maxres[i],
- Relative);
- } else if (info.numRelAxes) {
- InitValuatorClassDeviceStruct(pDevice, info.numRelAxes,
- axis_labels,
- dmxPointerGetMotionBufferSize(),
- Relative);
- for (i = 0; i < info.numRelAxes; i++)
- InitValuatorAxisStruct(pDevice, i, axis_labels[i],
- info.minval[i],
- info.maxval[i], info.res[i],
- info.minres[i], info.maxres[i],
- Relative);
- } else if (info.numAbsAxes) {
- InitValuatorClassDeviceStruct(pDevice, info.numAbsAxes,
- axis_labels,
- dmxPointerGetMotionBufferSize(),
- Absolute);
- for (i = 0; i < info.numAbsAxes; i++)
- InitValuatorAxisStruct(pDevice, i,
- axis_labels[i],
- info.minval[i], info.maxval[i],
- info.res[i], info.minres[i],
- info.maxres[i], Absolute);
- }
- }
- if (info.focusClass) InitFocusClassDeviceStruct(pDevice);
- if (info.proximityClass) InitProximityClassDeviceStruct(pDevice);
- if (info.ptrFeedbackClass)
- InitPtrFeedbackClassDeviceStruct(pDevice, dmxChangePointerControl);
- if (info.intFeedbackClass || info.strFeedbackClass)
- dmxLog(dmxWarning,
- "Integer and string feedback not supported for %s\n",
- pDevice->name);
- if (!info.keyboard && (info.ledFeedbackClass || info.belFeedbackClass))
- dmxLog(dmxWarning,
- "Led and bel feedback not supported for non-keyboard %s\n",
- pDevice->name);
- break;
- case DEVICE_ON:
- if (!pDev->on) {
- if (dmxLocal->on && (fd = dmxLocal->on(pDev)) >= 0)
- dmxSigioRegister(dmxInput, fd);
- pDev->on = TRUE;
- }
- break;
- case DEVICE_OFF:
- case DEVICE_CLOSE:
- /* This can get called twice consecutively: once for a
- * detached screen (DEVICE_OFF), and then again at server
- * generation time (DEVICE_CLOSE). */
- if (pDev->on) {
- dmxSigioUnregister(dmxInput);
- if (dmxLocal->off) dmxLocal->off(pDev);
- pDev->on = FALSE;
- }
- break;
- }
- if (info.keySyms.map && info.freemap) {
- XFree(info.keySyms.map);
- info.keySyms.map = NULL;
- }
- if (info.xkb) XkbFreeKeyboard(info.xkb, 0, True);
- return Success;
-}
-
-static void dmxProcessInputEvents(DMXInputInfo *dmxInput)
-{
- int i;
-
- mieqProcessInputEvents();
-#if 00 /*BP*/
- miPointerUpdate();
-#endif
- if (dmxInput->detached)
- return;
- for (i = 0; i < dmxInput->numDevs; i += dmxInput->devs[i]->binding)
- if (dmxInput->devs[i]->process_input) {
-#if 11 /*BP*/
- miPointerUpdateSprite(dmxInput->devs[i]->pDevice);
-#endif
- dmxInput->devs[i]->process_input(dmxInput->devs[i]->private);
- }
-
-#if 11 /*BP*/
- mieqProcessInputEvents();
-#endif
-}
-
-static void dmxUpdateWindowInformation(DMXInputInfo *dmxInput,
- DMXUpdateType type,
- WindowPtr pWindow)
-{
- int i;
-
-#ifdef PANORAMIX
- if (!noPanoramiXExtension && pWindow && pWindow->parent != screenInfo.screens[0]->root)
- return;
-#endif
-#if DMX_WINDOW_DEBUG
- {
- const char *name = "Unknown";
- switch (type) {
- case DMX_UPDATE_REALIZE: name = "Realize"; break;
- case DMX_UPDATE_UNREALIZE: name = "Unrealize"; break;
- case DMX_UPDATE_RESTACK: name = "Restack"; break;
- case DMX_UPDATE_COPY: name = "Copy"; break;
- case DMX_UPDATE_RESIZE: name = "Resize"; break;
- case DMX_UPDATE_REPARENT: name = "Repaint"; break;
- }
- dmxLog(dmxDebug, "Window %p changed: %s\n", pWindow, name);
- }
-#endif
-
- if (dmxInput->detached)
- return;
- for (i = 0; i < dmxInput->numDevs; i += dmxInput->devs[i]->binding)
- if (dmxInput->devs[i]->update_info)
- dmxInput->devs[i]->update_info(dmxInput->devs[i]->private,
- type, pWindow);
-}
-
-static void dmxCollectAll(DMXInputInfo *dmxInput)
-{
- int i;
-
- if (dmxInput->detached)
- return;
- for (i = 0; i < dmxInput->numDevs; i += dmxInput->devs[i]->binding)
- if (dmxInput->devs[i]->collect_events)
- dmxInput->devs[i]->collect_events(&dmxInput->devs[i]->pDevice->public,
- dmxMotion,
- dmxEnqueue,
- dmxCheckSpecialKeys, DMX_BLOCK);
-}
-
-static void dmxBlockHandler(pointer blockData, OSTimePtr pTimeout,
- pointer pReadMask)
-{
- DMXInputInfo *dmxInput = &dmxInputs[(int)blockData];
- static unsigned long generation = 0;
-
- if (generation != serverGeneration) {
- generation = serverGeneration;
- dmxCollectAll(dmxInput);
- }
-}
-
-static void dmxSwitchReturn(pointer p)
-{
- DMXInputInfo *dmxInput = p;
- int i;
-
- dmxLog(dmxInfo, "Returning from VT %d\n", dmxInput->vt_switched);
-
- if (!dmxInput->vt_switched)
- dmxLog(dmxFatal, "dmxSwitchReturn called, but not switched\n");
- dmxSigioEnableInput();
- for (i = 0; i < dmxInput->numDevs; i++)
- if (dmxInput->devs[i]->vt_post_switch)
- dmxInput->devs[i]->vt_post_switch(dmxInput->devs[i]->private);
- dmxInput->vt_switched = 0;
-}
-
-static void dmxWakeupHandler(pointer blockData, int result, pointer pReadMask)
-{
- DMXInputInfo *dmxInput = &dmxInputs[(int)blockData];
- int i;
-
- if (dmxInput->vt_switch_pending) {
- dmxLog(dmxInfo, "Switching to VT %d\n", dmxInput->vt_switch_pending);
- for (i = 0; i < dmxInput->numDevs; i++)
- if (dmxInput->devs[i]->vt_pre_switch)
- dmxInput->devs[i]->vt_pre_switch(dmxInput->devs[i]->private);
- dmxInput->vt_switched = dmxInput->vt_switch_pending;
- dmxInput->vt_switch_pending = 0;
- for (i = 0; i < dmxInput->numDevs; i++) {
- if (dmxInput->devs[i]->vt_switch) {
- dmxSigioDisableInput();
- if (!dmxInput->devs[i]->vt_switch(dmxInput->devs[i]->private,
- dmxInput->vt_switched,
- dmxSwitchReturn,
- dmxInput))
- dmxSwitchReturn(dmxInput);
- break; /* Only call one vt_switch routine */
- }
- }
- }
- dmxCollectAll(dmxInput);
-}
-
-static char *dmxMakeUniqueDeviceName(DMXLocalInputInfoPtr dmxLocal)
-{
- static int k = 0;
- static int m = 0;
- static int o = 0;
- static unsigned long dmxGeneration = 0;
-#define LEN 32
- char * buf = malloc(LEN);
-
- if (dmxGeneration != serverGeneration) {
- k = m = o = 0;
- dmxGeneration = serverGeneration;
- }
-
- switch (dmxLocal->type) {
- case DMX_LOCAL_KEYBOARD: XmuSnprintf(buf, LEN, "Keyboard%d", k++); break;
- case DMX_LOCAL_MOUSE: XmuSnprintf(buf, LEN, "Mouse%d", m++); break;
- default: XmuSnprintf(buf, LEN, "Other%d", o++); break;
- }
-
- return buf;
-}
-
-static DeviceIntPtr dmxAddDevice(DMXLocalInputInfoPtr dmxLocal)
-{
- DeviceIntPtr pDevice;
- Atom atom;
- const char *name = NULL;
- char *devname;
- DMXInputInfo *dmxInput;
-
- if (!dmxLocal)
- return NULL;
- dmxInput = &dmxInputs[dmxLocal->inputIdx];
-
- if (dmxLocal->sendsCore) {
- if (dmxLocal->type == DMX_LOCAL_KEYBOARD && !dmxLocalCoreKeyboard) {
- dmxLocal->isCore = 1;
- dmxLocalCoreKeyboard = dmxLocal;
- name = "keyboard";
- }
- if (dmxLocal->type == DMX_LOCAL_MOUSE && !dmxLocalCorePointer) {
- dmxLocal->isCore = 1;
- dmxLocalCorePointer = dmxLocal;
- name = "pointer";
- }
- }
-
- if (!name) {
- name = "extension";
- }
-
- if (!name)
- dmxLog(dmxFatal, "Cannot add device %s\n", dmxLocal->name);
-
- pDevice = AddInputDevice(serverClient, dmxDeviceOnOff, TRUE);
- if (!pDevice) {
- dmxLog(dmxError, "Too many devices -- cannot add device %s\n",
- dmxLocal->name);
- return NULL;
- }
- pDevice->public.devicePrivate = dmxLocal;
- dmxLocal->pDevice = pDevice;
-
- devname = dmxMakeUniqueDeviceName(dmxLocal);
- atom = MakeAtom((char *)devname, strlen(devname), TRUE);
- pDevice->type = atom;
- pDevice->name = devname;
-
- if (dmxLocal->isCore && dmxLocal->type == DMX_LOCAL_MOUSE) {
-#if 00 /*BP*/
- miRegisterPointerDevice(screenInfo.screens[0], pDevice);
-#else
- /* Nothing? dmxDeviceOnOff() should get called to init, right? */
-#endif
- }
-
- if (dmxLocal->create_private)
- dmxLocal->private = dmxLocal->create_private(pDevice);
-
- dmxLogInput(dmxInput, "Added %s as %s device called %s%s\n",
- dmxLocal->name, name, devname,
- dmxLocal->isCore
- ? " [core]"
- : (dmxLocal->sendsCore
- ? " [sends core events]"
- : ""));
-
- return pDevice;
-}
-
-static DMXLocalInputInfoPtr dmxLookupLocal(const char *name)
-{
- DMXLocalInputInfoPtr pt;
-
- for (pt = &DMXLocalDevices[0]; pt->name; ++pt)
- if (!strcmp(pt->name, name)) return pt; /* search for device name */
- return NULL;
-}
-
-/** Copy the local input information from \a s into a new \a devs slot
- * in \a dmxInput. */
-DMXLocalInputInfoPtr dmxInputCopyLocal(DMXInputInfo *dmxInput,
- DMXLocalInputInfoPtr s)
-{
- DMXLocalInputInfoPtr dmxLocal = malloc(sizeof(*dmxLocal));
-
- if (!dmxLocal)
- dmxLog(dmxFatal, "DMXLocalInputInfoPtr: out of memory\n");
-
- memcpy(dmxLocal, s, sizeof(*dmxLocal));
- dmxLocal->inputIdx = dmxInput->inputIdx;
- dmxLocal->sendsCore = dmxInput->core;
- dmxLocal->savedSendsCore = dmxInput->core;
- dmxLocal->deviceId = -1;
-
- ++dmxInput->numDevs;
- dmxInput->devs = realloc(dmxInput->devs,
- dmxInput->numDevs * sizeof(*dmxInput->devs));
- dmxInput->devs[dmxInput->numDevs-1] = dmxLocal;
-
- return dmxLocal;
-}
-
-static void dmxPopulateLocal(DMXInputInfo *dmxInput, dmxArg a)
-{
- int i;
- int help = 0;
- DMXLocalInputInfoRec *pt;
-
- for (i = 1; i < dmxArgC(a); i++) {
- const char *name = dmxArgV(a, i);
- if ((pt = dmxLookupLocal(name))) {
- dmxInputCopyLocal(dmxInput, pt);
- } else {
- if (strlen(name))
- dmxLog(dmxWarning,
- "Could not find a driver called %s\n", name);
- ++help;
- }
- }
- if (help) {
- dmxLog(dmxInfo, "Available local device drivers:\n");
- for (pt = &DMXLocalDevices[0]; pt->name; ++pt) {
- const char *type;
- switch (pt->type) {
- case DMX_LOCAL_KEYBOARD: type = "keyboard"; break;
- case DMX_LOCAL_MOUSE: type = "pointer"; break;
- default: type = "unknown"; break;
- }
- dmxLog(dmxInfo, " %s (%s)\n", pt->name, type);
- }
- dmxLog(dmxFatal, "Must have valid local device driver\n");
- }
-}
-
-int dmxInputExtensionErrorHandler(Display *dsp, _Xconst char *name, _Xconst char *reason)
-{
- return 0;
-}
-
-static void dmxInputScanForExtensions(DMXInputInfo *dmxInput, int doXI)
-{
- XExtensionVersion *ext;
- XDeviceInfo *devices;
- Display *display;
- int num;
- int i, j;
- XextErrorHandler handler;
-
- if (!(display = XOpenDisplay(dmxInput->name))) return;
-
- /* Print out information about the XInput Extension. */
- handler = XSetExtensionErrorHandler(dmxInputExtensionErrorHandler);
- ext = XGetExtensionVersion(display, INAME);
- XSetExtensionErrorHandler(handler);
-
- if (!ext || ext == (XExtensionVersion *)NoSuchExtension) {
- dmxLogInput(dmxInput, "%s is not available\n", INAME);
- } else {
- dmxLogInput(dmxInput, "Locating devices on %s (%s version %d.%d)\n",
- dmxInput->name, INAME,
- ext->major_version, ext->minor_version);
- devices = XListInputDevices(display, &num);
-
- XFree(ext);
- ext = NULL;
-
- /* Print a list of all devices */
- for (i = 0; i < num; i++) {
- const char *use = "Unknown";
- switch (devices[i].use) {
- case IsXPointer: use = "XPointer"; break;
- case IsXKeyboard: use = "XKeyboard"; break;
- case IsXExtensionDevice: use = "XExtensionDevice"; break;
- case IsXExtensionPointer: use = "XExtensionPointer"; break;
- case IsXExtensionKeyboard: use = "XExtensionKeyboard"; break;
- }
- dmxLogInput(dmxInput, " %2d %-10.10s %-16.16s\n",
- devices[i].id,
- devices[i].name ? devices[i].name : "",
- use);
- }
-
- /* Search for extensions */
- for (i = 0; i < num; i++) {
- switch (devices[i].use) {
- case IsXKeyboard:
- for (j = 0; j < dmxInput->numDevs; j++) {
- DMXLocalInputInfoPtr dmxL = dmxInput->devs[j];
- if (dmxL->type == DMX_LOCAL_KEYBOARD
- && dmxL->deviceId < 0) {
- dmxL->deviceId = devices[i].id;
- dmxL->deviceName = (devices[i].name
- ? strdup(devices[i].name)
- : NULL);
- }
- }
- break;
- case IsXPointer:
- for (j = 0; j < dmxInput->numDevs; j++) {
- DMXLocalInputInfoPtr dmxL = dmxInput->devs[j];
- if (dmxL->type == DMX_LOCAL_MOUSE && dmxL->deviceId < 0) {
- dmxL->deviceId = devices[i].id;
- dmxL->deviceName = (devices[i].name
- ? xstrdup(devices[i].name)
- : NULL);
- }
- }
- break;
-#if 0
- case IsXExtensionDevice:
- case IsXExtensionKeyboard:
- case IsXExtensionPointer:
- if (doXI) {
- if (!dmxInput->numDevs) {
- dmxLog(dmxWarning,
- "Cannot use remote (%s) XInput devices if"
- " not also using core devices\n",
- dmxInput->name);
- } else {
- dmxLocal = dmxInputCopyLocal(dmxInput,
- &DMXCommonOth);
- dmxLocal->isCore = FALSE;
- dmxLocal->sendsCore = FALSE;
- dmxLocal->deviceId = devices[i].id;
- dmxLocal->deviceName = (devices[i].name
- ? strdup(devices[i].name)
- : NULL);
- }
- }
- break;
-#endif
- }
- }
- XFreeDeviceList(devices);
- }
- XCloseDisplay(display);
-}
-
-/** Re-initialize all the devices described in \a dmxInput. Called from
- #dmxAdjustCursorBoundaries before the cursor is redisplayed. */
-void dmxInputReInit(DMXInputInfo *dmxInput)
-{
- int i;
-
- for (i = 0; i < dmxInput->numDevs; i++) {
- DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
- if (dmxLocal->reinit)
- dmxLocal->reinit(&dmxLocal->pDevice->public);
- }
-}
-
-/** Re-initialize all the devices described in \a dmxInput. Called from
- #dmxAdjustCursorBoundaries after the cursor is redisplayed. */
-void dmxInputLateReInit(DMXInputInfo *dmxInput)
-{
- int i;
-
- for (i = 0; i < dmxInput->numDevs; i++) {
- DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
- if (dmxLocal->latereinit)
- dmxLocal->latereinit(&dmxLocal->pDevice->public);
- }
-}
-
-/** Initialize all of the devices described in \a dmxInput. */
-void dmxInputInit(DMXInputInfo *dmxInput)
-{
- DeviceIntPtr pPointer = NULL, pKeyboard = NULL;
- dmxArg a;
- const char *name;
- int i;
- int doXI = 1; /* Include by default */
- int forceConsole = 0;
- int doWindows = 1; /* On by default */
- int hasXkb = 0;
-
- a = dmxArgParse(dmxInput->name);
-
- for (i = 1; i < dmxArgC(a); i++) {
- switch (hasXkb) {
- case 1:
- dmxInput->keycodes = xstrdup(dmxArgV(a, i));
- ++hasXkb;
- break;
- case 2:
- dmxInput->symbols = xstrdup(dmxArgV(a, i));
- ++hasXkb;
- break;
- case 3:
- dmxInput->geometry = xstrdup(dmxArgV(a, i));
- hasXkb = 0;
- break;
- case 0:
- if (!strcmp(dmxArgV(a, i), "noxi")) doXI = 0;
- else if (!strcmp(dmxArgV(a, i), "xi")) doXI = 1;
- else if (!strcmp(dmxArgV(a, i), "console")) forceConsole = 1;
- else if (!strcmp(dmxArgV(a, i), "noconsole")) forceConsole = 0;
- else if (!strcmp(dmxArgV(a, i), "windows")) doWindows = 1;
- else if (!strcmp(dmxArgV(a, i), "nowindows")) doWindows = 0;
- else if (!strcmp(dmxArgV(a, i), "xkb")) hasXkb = 1;
- else {
- dmxLog(dmxFatal,
- "Unknown input argument: %s\n", dmxArgV(a, i));
- }
- }
- }
-
- name = dmxArgV(a, 0);
-
- if (!strcmp(name, "local")) {
- dmxPopulateLocal(dmxInput, a);
- } else if (!strcmp(name, "dummy")) {
- dmxInputCopyLocal(dmxInput, &DMXDummyMou);
- dmxInputCopyLocal(dmxInput, &DMXDummyKbd);
- dmxLogInput(dmxInput, "Using dummy input\n");
- } else {
- int found;
-
- for (found = 0, i = 0; i < dmxNumScreens; i++) {
- if (dmxPropertySameDisplay(&dmxScreens[i], name)) {
- if (dmxScreens[i].shared)
- dmxLog(dmxFatal,
- "Cannot take input from shared backend (%s)\n",
- name);
- if (!dmxInput->core) {
- dmxLog(dmxWarning,
- "Cannot use core devices on a backend (%s)"
- " as XInput devices\n", name);
- } else {
- char *pt;
- for (pt = (char *)dmxInput->name; pt && *pt; pt++)
- if (*pt == ',') *pt = '\0';
- dmxInputCopyLocal(dmxInput, &DMXBackendMou);
- dmxInputCopyLocal(dmxInput, &DMXBackendKbd);
- dmxInput->scrnIdx = i;
- dmxLogInput(dmxInput,
- "Using backend input from %s\n", name);
- }
- ++found;
- break;
- }
- }
- if (!found || forceConsole) {
- char *pt;
- if (found) dmxInput->console = TRUE;
- for (pt = (char *)dmxInput->name; pt && *pt; pt++)
- if (*pt == ',') *pt = '\0';
- dmxInputCopyLocal(dmxInput, &DMXConsoleMou);
- dmxInputCopyLocal(dmxInput, &DMXConsoleKbd);
- if (doWindows) {
- dmxInput->windows = TRUE;
- dmxInput->updateWindowInfo = dmxUpdateWindowInformation;
- }
- dmxLogInput(dmxInput,
- "Using console input from %s (%s windows)\n",
- name, doWindows ? "with" : "without");
- }
- }
-
- dmxArgFree(a);
-
- /* Locate extensions we may be interested in */
- dmxInputScanForExtensions(dmxInput, doXI);
-
- for (i = 0; i < dmxInput->numDevs; i++) {
- DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
- dmxLocal->pDevice = dmxAddDevice(dmxLocal);
- if (dmxLocal->isCore) {
- if (dmxLocal->type == DMX_LOCAL_MOUSE)
- pPointer = dmxLocal->pDevice;
- if (dmxLocal->type == DMX_LOCAL_KEYBOARD)
- pKeyboard = dmxLocal->pDevice;
- }
- }
-
- dmxInput->processInputEvents = dmxProcessInputEvents;
- dmxInput->detached = False;
-
- RegisterBlockAndWakeupHandlers(dmxBlockHandler,
- dmxWakeupHandler,
- (void *)dmxInput->inputIdx);
-}
-
-static void dmxInputFreeLocal(DMXLocalInputInfoRec *local)
-{
- if (!local) return;
- if (local->isCore && local->type == DMX_LOCAL_MOUSE)
- dmxLocalCorePointer = NULL;
- if (local->isCore && local->type == DMX_LOCAL_KEYBOARD)
- dmxLocalCoreKeyboard = NULL;
- if (local->destroy_private) local->destroy_private(local->private);
- free(local->history);
- free(local->valuators);
- free(local->deviceName);
- local->private = NULL;
- local->history = NULL;
- local->deviceName = NULL;
- free(local);
-}
-
-/** Free all of the memory associated with \a dmxInput */
-void dmxInputFree(DMXInputInfo *dmxInput)
-{
- int i;
-
- if (!dmxInput) return;
-
- free(dmxInput->keycodes);
- free(dmxInput->symbols);
- free(dmxInput->geometry);
-
- for (i = 0; i < dmxInput->numDevs; i++) {
- dmxInputFreeLocal(dmxInput->devs[i]);
- dmxInput->devs[i] = NULL;
- }
- free(dmxInput->devs);
- dmxInput->devs = NULL;
- dmxInput->numDevs = 0;
- if (dmxInput->freename) free(dmxInput->name);
- dmxInput->name = NULL;
-}
-
-/** Log information about all of the known devices using #dmxLog(). */
-void dmxInputLogDevices(void)
-{
- int i, j;
-
- dmxLog(dmxInfo, "%d devices:\n", dmxGetInputCount());
- dmxLog(dmxInfo, " Id Name Classes\n");
- for (j = 0; j < dmxNumInputs; j++) {
- DMXInputInfo *dmxInput = &dmxInputs[j];
- const char *pt = strchr(dmxInput->name, ',');
- int len = (pt
- ? (size_t)(pt-dmxInput->name)
- : strlen(dmxInput->name));
-
- for (i = 0; i < dmxInput->numDevs; i++) {
- DeviceIntPtr pDevice = dmxInput->devs[i]->pDevice;
- if (pDevice) {
- dmxLog(dmxInfo, " %2d%c %-20.20s",
- pDevice->id,
- dmxInput->detached ? 'D' : ' ',
- pDevice->name);
- if (pDevice->key) dmxLogCont(dmxInfo, " key");
- if (pDevice->valuator) dmxLogCont(dmxInfo, " val");
- if (pDevice->button) dmxLogCont(dmxInfo, " btn");
- if (pDevice->focus) dmxLogCont(dmxInfo, " foc");
- if (pDevice->kbdfeed) dmxLogCont(dmxInfo, " fb/kbd");
- if (pDevice->ptrfeed) dmxLogCont(dmxInfo, " fb/ptr");
- if (pDevice->intfeed) dmxLogCont(dmxInfo, " fb/int");
- if (pDevice->stringfeed) dmxLogCont(dmxInfo, " fb/str");
- if (pDevice->bell) dmxLogCont(dmxInfo, " fb/bel");
- if (pDevice->leds) dmxLogCont(dmxInfo, " fb/led");
- if (!pDevice->key && !pDevice->valuator && !pDevice->button
- && !pDevice->focus && !pDevice->kbdfeed
- && !pDevice->ptrfeed && !pDevice->intfeed
- && !pDevice->stringfeed && !pDevice->bell
- && !pDevice->leds) dmxLogCont(dmxInfo, " (none)");
-
- dmxLogCont(dmxInfo, "\t[i%d/%*.*s",
- dmxInput->inputIdx, len, len, dmxInput->name);
- if (dmxInput->devs[i]->deviceId >= 0)
- dmxLogCont(dmxInfo, "/id%d", dmxInput->devs[i]->deviceId);
- if (dmxInput->devs[i]->deviceName)
- dmxLogCont(dmxInfo, "=%s", dmxInput->devs[i]->deviceName);
- dmxLogCont(dmxInfo, "] %s\n",
- dmxInput->devs[i]->isCore
- ? "core"
- : (dmxInput->devs[i]->sendsCore
- ? "extension (sends core events)"
- : "extension"));
- }
- }
- }
-}
-
-/** Detach an input */
-int dmxInputDetach(DMXInputInfo *dmxInput)
-{
- int i;
-
- if (dmxInput->detached) return BadAccess;
-
- for (i = 0; i < dmxInput->numDevs; i++) {
- DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
- dmxLogInput(dmxInput, "Detaching device id %d: %s%s\n",
- dmxLocal->pDevice->id,
- dmxLocal->pDevice->name,
- dmxLocal->isCore
- ? " [core]"
- : (dmxLocal->sendsCore
- ? " [sends core events]"
- : ""));
- DisableDevice(dmxLocal->pDevice, TRUE);
- }
- dmxInput->detached = True;
- dmxInputLogDevices();
- return 0;
-}
-
-/** Search for input associated with \a dmxScreen, and detach. */
-void dmxInputDetachAll(DMXScreenInfo *dmxScreen)
-{
- int i;
-
- for (i = 0; i < dmxNumInputs; i++) {
- DMXInputInfo *dmxInput = &dmxInputs[i];
- if (dmxInput->scrnIdx == dmxScreen->index) dmxInputDetach(dmxInput);
- }
-}
-
-/** Search for input associated with \a deviceId, and detach. */
-int dmxInputDetachId(int id)
-{
- DMXInputInfo *dmxInput = dmxInputLocateId(id);
-
- if (!dmxInput) return BadValue;
-
- return dmxInputDetach(dmxInput);
-}
-
-DMXInputInfo *dmxInputLocateId(int id)
-{
- int i, j;
-
- for (i = 0; i < dmxNumInputs; i++) {
- DMXInputInfo *dmxInput = &dmxInputs[i];
- for (j = 0; j < dmxInput->numDevs; j++) {
- DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[j];
- if (dmxLocal->pDevice->id == id) return dmxInput;
- }
- }
- return NULL;
-}
-
-static int dmxInputAttachNew(DMXInputInfo *dmxInput, int *id)
-{
- dmxInputInit(dmxInput);
- InitAndStartDevices();
- if (id && dmxInput->devs) *id = dmxInput->devs[0]->pDevice->id;
- dmxInputLogDevices();
- return 0;
-}
-
-static int dmxInputAttachOld(DMXInputInfo *dmxInput, int *id)
-{
- int i;
-
- dmxInput->detached = False;
- for (i = 0; i < dmxInput->numDevs; i++) {
- DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
- if (id) *id = dmxLocal->pDevice->id;
- dmxLogInput(dmxInput,
- "Attaching device id %d: %s%s\n",
- dmxLocal->pDevice->id,
- dmxLocal->pDevice->name,
- dmxLocal->isCore
- ? " [core]"
- : (dmxLocal->sendsCore
- ? " [sends core events]"
- : ""));
- EnableDevice(dmxLocal->pDevice, TRUE);
- }
- dmxInputLogDevices();
- return 0;
-}
-
-int dmxInputAttachConsole(const char *name, int isCore, int *id)
-{
- DMXInputInfo *dmxInput;
- int i;
-
- for (i = 0; i < dmxNumInputs; i++) {
- dmxInput = &dmxInputs[i];
- if (dmxInput->scrnIdx == -1
- && dmxInput->detached
- && !strcmp(dmxInput->name, name)) {
- /* Found match */
- dmxLogInput(dmxInput, "Reattaching detached console input\n");
- return dmxInputAttachOld(dmxInput, id);
- }
- }
-
- /* No match found */
- dmxInput = dmxConfigAddInput(xstrdup(name), isCore);
- dmxInput->freename = TRUE;
- dmxLogInput(dmxInput, "Attaching new console input\n");
- return dmxInputAttachNew(dmxInput, id);
-}
-
-int dmxInputAttachBackend(int physicalScreen, int isCore, int *id)
-{
- DMXInputInfo *dmxInput;
- DMXScreenInfo *dmxScreen;
- int i;
-
- if (physicalScreen < 0 || physicalScreen >= dmxNumScreens) return BadValue;
- for (i = 0; i < dmxNumInputs; i++) {
- dmxInput = &dmxInputs[i];
- if (dmxInput->scrnIdx != -1 && dmxInput->scrnIdx == physicalScreen) {
- /* Found match */
- if (!dmxInput->detached) return BadAccess; /* Already attached */
- dmxScreen = &dmxScreens[physicalScreen];
- if (!dmxScreen->beDisplay) return BadAccess; /* Screen detached */
- dmxLogInput(dmxInput, "Reattaching detached backend input\n");
- return dmxInputAttachOld(dmxInput, id);
- }
- }
- /* No match found */
- dmxScreen = &dmxScreens[physicalScreen];
- if (!dmxScreen->beDisplay) return BadAccess; /* Screen detached */
- dmxInput = dmxConfigAddInput(dmxScreen->name, isCore);
- dmxLogInput(dmxInput, "Attaching new backend input\n");
- return dmxInputAttachNew(dmxInput, id);
-}
+/*
+ * Copyright 2002-2003 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+/** \file
+ * This file provides generic input support. Functions here set up
+ * input and lead to the calling of low-level device drivers for
+ * input. */
+
+#ifdef HAVE_DMX_CONFIG_H
+#include <dmx-config.h>
+#endif
+
+#define DMX_WINDOW_DEBUG 0
+
+#include "dmxinputinit.h"
+#include "dmxextension.h" /* For dmxInputCount */
+
+#include "dmxdummy.h"
+#include "dmxbackend.h"
+#include "dmxconsole.h"
+#include "dmxcommon.h"
+#include "dmxevents.h"
+#include "dmxmotion.h"
+#include "dmxprop.h"
+#include "config/dmxconfig.h"
+#include "dmxcursor.h"
+
+#include "lnx-keyboard.h"
+#include "lnx-ms.h"
+#include "lnx-ps2.h"
+#include "usb-keyboard.h"
+#include "usb-mouse.h"
+#include "usb-other.h"
+#include "usb-common.h"
+
+#include "dmxsigio.h"
+#include "dmxarg.h"
+
+#include "inputstr.h"
+#include "input.h"
+#include "mipointer.h"
+#include "windowstr.h"
+#include "mi.h"
+#include "xkbsrv.h"
+
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#include "exevents.h"
+#include "extinit.h"
+
+DMXLocalInputInfoPtr dmxLocalCorePointer, dmxLocalCoreKeyboard;
+
+static DMXLocalInputInfoRec DMXDummyMou = {
+ "dummy-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
+ NULL, NULL, NULL, NULL, NULL, dmxDummyMouGetInfo
+};
+
+static DMXLocalInputInfoRec DMXDummyKbd = {
+ "dummy-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_LOCAL, 1,
+ NULL, NULL, NULL, NULL, NULL, dmxDummyKbdGetInfo
+};
+
+static DMXLocalInputInfoRec DMXBackendMou = {
+ "backend-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_BACKEND, 2,
+ dmxBackendCreatePrivate, dmxBackendDestroyPrivate,
+ dmxBackendInit, NULL, dmxBackendLateReInit, dmxBackendMouGetInfo,
+ dmxCommonMouOn, dmxCommonMouOff, dmxBackendUpdatePosition,
+ NULL, NULL, NULL,
+ dmxBackendCollectEvents, dmxBackendProcessInput, dmxBackendFunctions, NULL,
+ dmxCommonMouCtrl
+};
+
+static DMXLocalInputInfoRec DMXBackendKbd = {
+ "backend-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_BACKEND,
+ 1, /* With backend-mou or console-mou */
+ dmxCommonCopyPrivate, NULL,
+ dmxBackendInit, NULL, NULL, dmxBackendKbdGetInfo,
+ dmxCommonKbdOn, dmxCommonKbdOff, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, dmxCommonKbdCtrl, dmxCommonKbdBell
+};
+
+static DMXLocalInputInfoRec DMXConsoleMou = {
+ "console-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_CONSOLE, 2,
+ dmxConsoleCreatePrivate, dmxConsoleDestroyPrivate,
+ dmxConsoleInit, dmxConsoleReInit, NULL, dmxConsoleMouGetInfo,
+ dmxCommonMouOn, dmxCommonMouOff, dmxConsoleUpdatePosition,
+ NULL, NULL, NULL,
+ dmxConsoleCollectEvents, NULL, dmxConsoleFunctions, dmxConsoleUpdateInfo,
+ dmxCommonMouCtrl
+};
+
+static DMXLocalInputInfoRec DMXConsoleKbd = {
+ "console-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_CONSOLE,
+ 1, /* With backend-mou or console-mou */
+ dmxCommonCopyPrivate, NULL,
+ dmxConsoleInit, dmxConsoleReInit, NULL, dmxConsoleKbdGetInfo,
+ dmxCommonKbdOn, dmxCommonKbdOff, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, dmxCommonKbdCtrl, dmxCommonKbdBell
+};
+
+static DMXLocalInputInfoRec DMXLocalDevices[] = {
+ /* Dummy drivers that can compile on any OS */
+#ifdef __linux__
+ /* Linux-specific drivers */
+ {
+ "kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_LOCAL, 1,
+ kbdLinuxCreatePrivate, kbdLinuxDestroyPrivate,
+ kbdLinuxInit, NULL, NULL, kbdLinuxGetInfo,
+ kbdLinuxOn, kbdLinuxOff, NULL,
+ kbdLinuxVTPreSwitch, kbdLinuxVTPostSwitch, kbdLinuxVTSwitch,
+ kbdLinuxRead, NULL, NULL, NULL,
+ NULL, kbdLinuxCtrl, kbdLinuxBell
+ },
+ {
+ "ms", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
+ msLinuxCreatePrivate, msLinuxDestroyPrivate,
+ msLinuxInit, NULL, NULL, msLinuxGetInfo,
+ msLinuxOn, msLinuxOff, NULL,
+ msLinuxVTPreSwitch, msLinuxVTPostSwitch, NULL,
+ msLinuxRead
+ },
+ {
+ "ps2", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
+ ps2LinuxCreatePrivate, ps2LinuxDestroyPrivate,
+ ps2LinuxInit, NULL, NULL, ps2LinuxGetInfo,
+ ps2LinuxOn, ps2LinuxOff, NULL,
+ ps2LinuxVTPreSwitch, ps2LinuxVTPostSwitch, NULL,
+ ps2LinuxRead
+ },
+#endif
+#ifdef __linux__
+ /* USB drivers, currently only for
+ Linux, but relatively easy to port to
+ other OSs */
+ {
+ "usb-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_LOCAL, 1,
+ usbCreatePrivate, usbDestroyPrivate,
+ kbdUSBInit, NULL, NULL, kbdUSBGetInfo,
+ kbdUSBOn, usbOff, NULL,
+ NULL, NULL, NULL,
+ kbdUSBRead, NULL, NULL, NULL,
+ NULL, kbdUSBCtrl
+ },
+ {
+ "usb-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
+ usbCreatePrivate, usbDestroyPrivate,
+ mouUSBInit, NULL, NULL, mouUSBGetInfo,
+ mouUSBOn, usbOff, NULL,
+ NULL, NULL, NULL,
+ mouUSBRead
+ },
+ {
+ "usb-oth", DMX_LOCAL_OTHER, DMX_LOCAL_TYPE_LOCAL, 1,
+ usbCreatePrivate, usbDestroyPrivate,
+ othUSBInit, NULL, NULL, othUSBGetInfo,
+ othUSBOn, usbOff, NULL,
+ NULL, NULL, NULL,
+ othUSBRead
+ },
+#endif
+ {
+ "dummy-mou", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
+ NULL, NULL, NULL, NULL, NULL, dmxDummyMouGetInfo
+ },
+ {
+ "dummy-kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_LOCAL, 1,
+ NULL, NULL, NULL, NULL, NULL, dmxDummyKbdGetInfo
+ },
+ { NULL } /* Must be last */
+};
+
+
+#if 11 /*BP*/
+void
+DDXRingBell(int volume, int pitch, int duration)
+{
+ /* NO-OP */
+}
+
+/* taken from kdrive/src/kinput.c: */
+static void
+dmxKbdCtrl (DeviceIntPtr pDevice, KeybdCtrl *ctrl)
+{
+#if 0
+ KdKeyboardInfo *ki;
+
+ for (ki = kdKeyboards; ki; ki = ki->next) {
+ if (ki->dixdev && ki->dixdev->id == pDevice->id)
+ break;
+ }
+
+ if (!ki || !ki->dixdev || ki->dixdev->id != pDevice->id || !ki->driver)
+ return;
+
+ KdSetLeds(ki, ctrl->leds);
+ ki->bellPitch = ctrl->bell_pitch;
+ ki->bellDuration = ctrl->bell_duration;
+#endif
+}
+
+/* taken from kdrive/src/kinput.c: */
+static void
+dmxBell(int volume, DeviceIntPtr pDev, pointer arg, int something)
+{
+#if 0
+ KeybdCtrl *ctrl = arg;
+ KdKeyboardInfo *ki = NULL;
+
+ for (ki = kdKeyboards; ki; ki = ki->next) {
+ if (ki->dixdev && ki->dixdev->id == pDev->id)
+ break;
+ }
+
+ if (!ki || !ki->dixdev || ki->dixdev->id != pDev->id || !ki->driver)
+ return;
+
+ KdRingBell(ki, volume, ctrl->bell_pitch, ctrl->bell_duration);
+#endif
+}
+
+#endif /*BP*/
+
+static void _dmxChangePointerControl(DMXLocalInputInfoPtr dmxLocal,
+ PtrCtrl *ctrl)
+{
+ if (!dmxLocal) return;
+ dmxLocal->mctrl = *ctrl;
+ if (dmxLocal->mCtrl) dmxLocal->mCtrl(&dmxLocal->pDevice->public, ctrl);
+}
+
+/** Change the pointer control information for the \a pDevice. If the
+ * device sends core events, then also change the control information
+ * for all of the pointer devices that send core events. */
+void dmxChangePointerControl(DeviceIntPtr pDevice, PtrCtrl *ctrl)
+{
+ GETDMXLOCALFROMPDEVICE;
+ int i, j;
+
+ if (dmxLocal->sendsCore) { /* Do for all core devices */
+ for (i = 0; i < dmxNumInputs; i++) {
+ DMXInputInfo *dmxInput = &dmxInputs[i];
+ if (dmxInput->detached) continue;
+ for (j = 0; j < dmxInput->numDevs; j++)
+ if (dmxInput->devs[j]->sendsCore)
+ _dmxChangePointerControl(dmxInput->devs[j], ctrl);
+ }
+ } else { /* Do for this device only */
+ _dmxChangePointerControl(dmxLocal, ctrl);
+ }
+}
+
+static void _dmxKeyboardKbdCtrlProc(DMXLocalInputInfoPtr dmxLocal,
+ KeybdCtrl *ctrl)
+{
+ dmxLocal->kctrl = *ctrl;
+ if (dmxLocal->kCtrl) {
+ dmxLocal->kCtrl(&dmxLocal->pDevice->public, ctrl);
+ if (dmxLocal->pDevice->kbdfeed) {
+ XkbEventCauseRec cause;
+ XkbSetCauseUnknown(&cause);
+ /* Generate XKB events, as necessary */
+ XkbUpdateIndicators(dmxLocal->pDevice, XkbAllIndicatorsMask, False,
+ NULL, &cause);
+ }
+ }
+}
+
+
+/** Change the keyboard control information for the \a pDevice. If the
+ * device sends core events, then also change the control information
+ * for all of the keyboard devices that send core events. */
+void dmxKeyboardKbdCtrlProc(DeviceIntPtr pDevice, KeybdCtrl *ctrl)
+{
+ GETDMXLOCALFROMPDEVICE;
+ int i, j;
+
+ if (dmxLocal->sendsCore) { /* Do for all core devices */
+ for (i = 0; i < dmxNumInputs; i++) {
+ DMXInputInfo *dmxInput = &dmxInputs[i];
+ if (dmxInput->detached) continue;
+ for (j = 0; j < dmxInput->numDevs; j++)
+ if (dmxInput->devs[j]->sendsCore)
+ _dmxKeyboardKbdCtrlProc(dmxInput->devs[j], ctrl);
+ }
+ } else { /* Do for this device only */
+ _dmxKeyboardKbdCtrlProc(dmxLocal, ctrl);
+ }
+}
+
+static void _dmxKeyboardBellProc(DMXLocalInputInfoPtr dmxLocal, int percent)
+{
+ if (dmxLocal->kBell) dmxLocal->kBell(&dmxLocal->pDevice->public,
+ percent,
+ dmxLocal->kctrl.bell,
+ dmxLocal->kctrl.bell_pitch,
+ dmxLocal->kctrl.bell_duration);
+}
+
+/** Sound the bell on the device. If the device send core events, then
+ * sound the bell on all of the devices that send core events. */
+void dmxKeyboardBellProc(int percent, DeviceIntPtr pDevice,
+ pointer ctrl, int unknown)
+{
+ GETDMXLOCALFROMPDEVICE;
+ int i, j;
+
+ if (dmxLocal->sendsCore) { /* Do for all core devices */
+ for (i = 0; i < dmxNumInputs; i++) {
+ DMXInputInfo *dmxInput = &dmxInputs[i];
+ if (dmxInput->detached) continue;
+ for (j = 0; j < dmxInput->numDevs; j++)
+ if (dmxInput->devs[j]->sendsCore)
+ _dmxKeyboardBellProc(dmxInput->devs[j], percent);
+ }
+ } else { /* Do for this device only */
+ _dmxKeyboardBellProc(dmxLocal, percent);
+ }
+}
+
+static void dmxKeyboardFreeNames(XkbComponentNamesPtr names)
+{
+ if (names->keycodes) XFree(names->keycodes);
+ if (names->types) XFree(names->types);
+ if (names->compat) XFree(names->compat);
+ if (names->symbols) XFree(names->symbols);
+ if (names->geometry) XFree(names->geometry);
+}
+
+
+static int dmxKeyboardOn(DeviceIntPtr pDevice, DMXLocalInitInfo *info)
+{
+ GETDMXINPUTFROMPDEVICE;
+ XkbRMLVOSet rmlvo;
+
+ rmlvo.rules = dmxConfigGetXkbRules();
+ rmlvo.model = dmxConfigGetXkbModel();
+ rmlvo.layout = dmxConfigGetXkbLayout();
+ rmlvo.variant = dmxConfigGetXkbVariant();
+ rmlvo.options = dmxConfigGetXkbOptions();
+
+ XkbSetRulesDflts(&rmlvo);
+ if (!info->force && (dmxInput->keycodes
+ || dmxInput->symbols
+ || dmxInput->geometry)) {
+ if (info->freenames) dmxKeyboardFreeNames(&info->names);
+ info->freenames = 0;
+ info->names.keycodes = dmxInput->keycodes;
+ info->names.types = NULL;
+ info->names.compat = NULL;
+ info->names.symbols = dmxInput->symbols;
+ info->names.geometry = dmxInput->geometry;
+
+ dmxLogInput(dmxInput, "XKEYBOARD: From command line: %s",
+ info->names.keycodes);
+ if (info->names.symbols && *info->names.symbols)
+ dmxLogInputCont(dmxInput, " %s", info->names.symbols);
+ if (info->names.geometry && *info->names.geometry)
+ dmxLogInputCont(dmxInput, " %s", info->names.geometry);
+ dmxLogInputCont(dmxInput, "\n");
+ } else if (info->names.keycodes) {
+ dmxLogInput(dmxInput, "XKEYBOARD: From device: %s",
+ info->names.keycodes);
+ if (info->names.symbols && *info->names.symbols)
+ dmxLogInputCont(dmxInput, " %s", info->names.symbols);
+ if (info->names.geometry && *info->names.geometry)
+ dmxLogInputCont(dmxInput, " %s", info->names.geometry);
+ dmxLogInputCont(dmxInput, "\n");
+ } else {
+ dmxLogInput(dmxInput, "XKEYBOARD: Defaults: %s %s %s %s %s\n",
+ dmxConfigGetXkbRules(),
+ dmxConfigGetXkbLayout(),
+ dmxConfigGetXkbModel(),
+ dmxConfigGetXkbVariant()
+ ? dmxConfigGetXkbVariant() : "",
+ dmxConfigGetXkbOptions()
+ ? dmxConfigGetXkbOptions() : "");
+ }
+ InitKeyboardDeviceStruct(pDevice, &rmlvo,
+ dmxKeyboardBellProc,
+ dmxKeyboardKbdCtrlProc);
+
+ if (info->freenames) dmxKeyboardFreeNames(&info->names);
+
+ return Success;
+}
+
+
+static int dmxDeviceOnOff(DeviceIntPtr pDevice, int what)
+{
+ GETDMXINPUTFROMPDEVICE;
+ int fd;
+ DMXLocalInitInfo info;
+ int i;
+ Atom btn_labels[MAX_BUTTONS] = {0}; /* FIXME */
+ Atom axis_labels[MAX_VALUATORS] = {0}; /* FIXME */
+
+ if (dmxInput->detached) return Success;
+
+ memset(&info, 0, sizeof(info));
+ switch (what) {
+ case DEVICE_INIT:
+ if (dmxLocal->init)
+ dmxLocal->init(pDev);
+ if (dmxLocal->get_info)
+ dmxLocal->get_info(pDev, &info);
+ if (info.keyboard) { /* XKEYBOARD makes this a special case */
+ dmxKeyboardOn(pDevice, &info);
+ break;
+ }
+ if (info.keyClass) {
+ XkbRMLVOSet rmlvo;
+
+ rmlvo.rules = dmxConfigGetXkbRules();
+ rmlvo.model = dmxConfigGetXkbModel();
+ rmlvo.layout = dmxConfigGetXkbLayout();
+ rmlvo.variant = dmxConfigGetXkbVariant();
+ rmlvo.options = dmxConfigGetXkbOptions();
+
+ InitKeyboardDeviceStruct(pDevice,
+ &rmlvo,
+ dmxBell, dmxKbdCtrl);
+ }
+ if (info.buttonClass) {
+ InitButtonClassDeviceStruct(pDevice, info.numButtons,
+ btn_labels, info.map);
+ }
+ if (info.valuatorClass) {
+ if (info.numRelAxes && dmxLocal->sendsCore) {
+ InitValuatorClassDeviceStruct(pDevice, info.numRelAxes,
+ axis_labels,
+ GetMaximumEventsNum(),
+ Relative);
+ for (i = 0; i < info.numRelAxes; i++)
+ InitValuatorAxisStruct(pDevice, i, axis_labels[i],
+ info.minval[i], info.maxval[i],
+ info.res[i],
+ info.minres[i], info.maxres[i],
+ Relative);
+ } else if (info.numRelAxes) {
+ InitValuatorClassDeviceStruct(pDevice, info.numRelAxes,
+ axis_labels,
+ dmxPointerGetMotionBufferSize(),
+ Relative);
+ for (i = 0; i < info.numRelAxes; i++)
+ InitValuatorAxisStruct(pDevice, i, axis_labels[i],
+ info.minval[i],
+ info.maxval[i], info.res[i],
+ info.minres[i], info.maxres[i],
+ Relative);
+ } else if (info.numAbsAxes) {
+ InitValuatorClassDeviceStruct(pDevice, info.numAbsAxes,
+ axis_labels,
+ dmxPointerGetMotionBufferSize(),
+ Absolute);
+ for (i = 0; i < info.numAbsAxes; i++)
+ InitValuatorAxisStruct(pDevice, i,
+ axis_labels[i],
+ info.minval[i], info.maxval[i],
+ info.res[i], info.minres[i],
+ info.maxres[i], Absolute);
+ }
+ }
+ if (info.focusClass) InitFocusClassDeviceStruct(pDevice);
+ if (info.proximityClass) InitProximityClassDeviceStruct(pDevice);
+ if (info.ptrFeedbackClass)
+ InitPtrFeedbackClassDeviceStruct(pDevice, dmxChangePointerControl);
+ if (info.intFeedbackClass || info.strFeedbackClass)
+ dmxLog(dmxWarning,
+ "Integer and string feedback not supported for %s\n",
+ pDevice->name);
+ if (!info.keyboard && (info.ledFeedbackClass || info.belFeedbackClass))
+ dmxLog(dmxWarning,
+ "Led and bel feedback not supported for non-keyboard %s\n",
+ pDevice->name);
+ break;
+ case DEVICE_ON:
+ if (!pDev->on) {
+ if (dmxLocal->on && (fd = dmxLocal->on(pDev)) >= 0)
+ dmxSigioRegister(dmxInput, fd);
+ pDev->on = TRUE;
+ }
+ break;
+ case DEVICE_OFF:
+ case DEVICE_CLOSE:
+ /* This can get called twice consecutively: once for a
+ * detached screen (DEVICE_OFF), and then again at server
+ * generation time (DEVICE_CLOSE). */
+ if (pDev->on) {
+ dmxSigioUnregister(dmxInput);
+ if (dmxLocal->off) dmxLocal->off(pDev);
+ pDev->on = FALSE;
+ }
+ break;
+ }
+ if (info.keySyms.map && info.freemap) {
+ XFree(info.keySyms.map);
+ info.keySyms.map = NULL;
+ }
+ if (info.xkb) XkbFreeKeyboard(info.xkb, 0, True);
+ return Success;
+}
+
+static void dmxProcessInputEvents(DMXInputInfo *dmxInput)
+{
+ int i;
+
+ mieqProcessInputEvents();
+#if 00 /*BP*/
+ miPointerUpdate();
+#endif
+ if (dmxInput->detached)
+ return;
+ for (i = 0; i < dmxInput->numDevs; i += dmxInput->devs[i]->binding)
+ if (dmxInput->devs[i]->process_input) {
+#if 11 /*BP*/
+ miPointerUpdateSprite(dmxInput->devs[i]->pDevice);
+#endif
+ dmxInput->devs[i]->process_input(dmxInput->devs[i]->private);
+ }
+
+#if 11 /*BP*/
+ mieqProcessInputEvents();
+#endif
+}
+
+static void dmxUpdateWindowInformation(DMXInputInfo *dmxInput,
+ DMXUpdateType type,
+ WindowPtr pWindow)
+{
+ int i;
+
+#ifdef PANORAMIX
+ if (!noPanoramiXExtension && pWindow && pWindow->parent != screenInfo.screens[0]->root)
+ return;
+#endif
+#if DMX_WINDOW_DEBUG
+ {
+ const char *name = "Unknown";
+ switch (type) {
+ case DMX_UPDATE_REALIZE: name = "Realize"; break;
+ case DMX_UPDATE_UNREALIZE: name = "Unrealize"; break;
+ case DMX_UPDATE_RESTACK: name = "Restack"; break;
+ case DMX_UPDATE_COPY: name = "Copy"; break;
+ case DMX_UPDATE_RESIZE: name = "Resize"; break;
+ case DMX_UPDATE_REPARENT: name = "Repaint"; break;
+ }
+ dmxLog(dmxDebug, "Window %p changed: %s\n", pWindow, name);
+ }
+#endif
+
+ if (dmxInput->detached)
+ return;
+ for (i = 0; i < dmxInput->numDevs; i += dmxInput->devs[i]->binding)
+ if (dmxInput->devs[i]->update_info)
+ dmxInput->devs[i]->update_info(dmxInput->devs[i]->private,
+ type, pWindow);
+}
+
+static void dmxCollectAll(DMXInputInfo *dmxInput)
+{
+ int i;
+
+ if (dmxInput->detached)
+ return;
+ for (i = 0; i < dmxInput->numDevs; i += dmxInput->devs[i]->binding)
+ if (dmxInput->devs[i]->collect_events)
+ dmxInput->devs[i]->collect_events(&dmxInput->devs[i]->pDevice->public,
+ dmxMotion,
+ dmxEnqueue,
+ dmxCheckSpecialKeys, DMX_BLOCK);
+}
+
+static void dmxBlockHandler(pointer blockData, OSTimePtr pTimeout,
+ pointer pReadMask)
+{
+ DMXInputInfo *dmxInput = &dmxInputs[(uintptr_t)blockData];
+ static unsigned long generation = 0;
+
+ if (generation != serverGeneration) {
+ generation = serverGeneration;
+ dmxCollectAll(dmxInput);
+ }
+}
+
+static void dmxSwitchReturn(pointer p)
+{
+ DMXInputInfo *dmxInput = p;
+ int i;
+
+ dmxLog(dmxInfo, "Returning from VT %d\n", dmxInput->vt_switched);
+
+ if (!dmxInput->vt_switched)
+ dmxLog(dmxFatal, "dmxSwitchReturn called, but not switched\n");
+ dmxSigioEnableInput();
+ for (i = 0; i < dmxInput->numDevs; i++)
+ if (dmxInput->devs[i]->vt_post_switch)
+ dmxInput->devs[i]->vt_post_switch(dmxInput->devs[i]->private);
+ dmxInput->vt_switched = 0;
+}
+
+static void dmxWakeupHandler(pointer blockData, int result, pointer pReadMask)
+{
+ DMXInputInfo *dmxInput = &dmxInputs[(uintptr_t)blockData];
+ int i;
+
+ if (dmxInput->vt_switch_pending) {
+ dmxLog(dmxInfo, "Switching to VT %d\n", dmxInput->vt_switch_pending);
+ for (i = 0; i < dmxInput->numDevs; i++)
+ if (dmxInput->devs[i]->vt_pre_switch)
+ dmxInput->devs[i]->vt_pre_switch(dmxInput->devs[i]->private);
+ dmxInput->vt_switched = dmxInput->vt_switch_pending;
+ dmxInput->vt_switch_pending = 0;
+ for (i = 0; i < dmxInput->numDevs; i++) {
+ if (dmxInput->devs[i]->vt_switch) {
+ dmxSigioDisableInput();
+ if (!dmxInput->devs[i]->vt_switch(dmxInput->devs[i]->private,
+ dmxInput->vt_switched,
+ dmxSwitchReturn,
+ dmxInput))
+ dmxSwitchReturn(dmxInput);
+ break; /* Only call one vt_switch routine */
+ }
+ }
+ }
+ dmxCollectAll(dmxInput);
+}
+
+static char *dmxMakeUniqueDeviceName(DMXLocalInputInfoPtr dmxLocal)
+{
+ static int k = 0;
+ static int m = 0;
+ static int o = 0;
+ static unsigned long dmxGeneration = 0;
+#define LEN 32
+ char * buf = malloc(LEN);
+
+ if (dmxGeneration != serverGeneration) {
+ k = m = o = 0;
+ dmxGeneration = serverGeneration;
+ }
+
+ switch (dmxLocal->type) {
+ case DMX_LOCAL_KEYBOARD: XmuSnprintf(buf, LEN, "Keyboard%d", k++); break;
+ case DMX_LOCAL_MOUSE: XmuSnprintf(buf, LEN, "Mouse%d", m++); break;
+ default: XmuSnprintf(buf, LEN, "Other%d", o++); break;
+ }
+
+ return buf;
+}
+
+static DeviceIntPtr dmxAddDevice(DMXLocalInputInfoPtr dmxLocal)
+{
+ DeviceIntPtr pDevice;
+ Atom atom;
+ const char *name = NULL;
+ char *devname;
+ DMXInputInfo *dmxInput;
+
+ if (!dmxLocal)
+ return NULL;
+ dmxInput = &dmxInputs[dmxLocal->inputIdx];
+
+ if (dmxLocal->sendsCore) {
+ if (dmxLocal->type == DMX_LOCAL_KEYBOARD && !dmxLocalCoreKeyboard) {
+ dmxLocal->isCore = 1;
+ dmxLocalCoreKeyboard = dmxLocal;
+ name = "keyboard";
+ }
+ if (dmxLocal->type == DMX_LOCAL_MOUSE && !dmxLocalCorePointer) {
+ dmxLocal->isCore = 1;
+ dmxLocalCorePointer = dmxLocal;
+ name = "pointer";
+ }
+ }
+
+ if (!name) {
+ name = "extension";
+ }
+
+ if (!name)
+ dmxLog(dmxFatal, "Cannot add device %s\n", dmxLocal->name);
+
+ pDevice = AddInputDevice(serverClient, dmxDeviceOnOff, TRUE);
+ if (!pDevice) {
+ dmxLog(dmxError, "Too many devices -- cannot add device %s\n",
+ dmxLocal->name);
+ return NULL;
+ }
+ pDevice->public.devicePrivate = dmxLocal;
+ dmxLocal->pDevice = pDevice;
+
+ devname = dmxMakeUniqueDeviceName(dmxLocal);
+ atom = MakeAtom((char *)devname, strlen(devname), TRUE);
+ pDevice->type = atom;
+ pDevice->name = devname;
+
+ if (dmxLocal->isCore && dmxLocal->type == DMX_LOCAL_MOUSE) {
+#if 00 /*BP*/
+ miRegisterPointerDevice(screenInfo.screens[0], pDevice);
+#else
+ /* Nothing? dmxDeviceOnOff() should get called to init, right? */
+#endif
+ }
+
+ if (dmxLocal->create_private)
+ dmxLocal->private = dmxLocal->create_private(pDevice);
+
+ dmxLogInput(dmxInput, "Added %s as %s device called %s%s\n",
+ dmxLocal->name, name, devname,
+ dmxLocal->isCore
+ ? " [core]"
+ : (dmxLocal->sendsCore
+ ? " [sends core events]"
+ : ""));
+
+ return pDevice;
+}
+
+static DMXLocalInputInfoPtr dmxLookupLocal(const char *name)
+{
+ DMXLocalInputInfoPtr pt;
+
+ for (pt = &DMXLocalDevices[0]; pt->name; ++pt)
+ if (!strcmp(pt->name, name)) return pt; /* search for device name */
+ return NULL;
+}
+
+/** Copy the local input information from \a s into a new \a devs slot
+ * in \a dmxInput. */
+DMXLocalInputInfoPtr dmxInputCopyLocal(DMXInputInfo *dmxInput,
+ DMXLocalInputInfoPtr s)
+{
+ DMXLocalInputInfoPtr dmxLocal = malloc(sizeof(*dmxLocal));
+
+ if (!dmxLocal)
+ dmxLog(dmxFatal, "DMXLocalInputInfoPtr: out of memory\n");
+
+ memcpy(dmxLocal, s, sizeof(*dmxLocal));
+ dmxLocal->inputIdx = dmxInput->inputIdx;
+ dmxLocal->sendsCore = dmxInput->core;
+ dmxLocal->savedSendsCore = dmxInput->core;
+ dmxLocal->deviceId = -1;
+
+ ++dmxInput->numDevs;
+ dmxInput->devs = realloc(dmxInput->devs,
+ dmxInput->numDevs * sizeof(*dmxInput->devs));
+ dmxInput->devs[dmxInput->numDevs-1] = dmxLocal;
+
+ return dmxLocal;
+}
+
+static void dmxPopulateLocal(DMXInputInfo *dmxInput, dmxArg a)
+{
+ int i;
+ int help = 0;
+ DMXLocalInputInfoRec *pt;
+
+ for (i = 1; i < dmxArgC(a); i++) {
+ const char *name = dmxArgV(a, i);
+ if ((pt = dmxLookupLocal(name))) {
+ dmxInputCopyLocal(dmxInput, pt);
+ } else {
+ if (strlen(name))
+ dmxLog(dmxWarning,
+ "Could not find a driver called %s\n", name);
+ ++help;
+ }
+ }
+ if (help) {
+ dmxLog(dmxInfo, "Available local device drivers:\n");
+ for (pt = &DMXLocalDevices[0]; pt->name; ++pt) {
+ const char *type;
+ switch (pt->type) {
+ case DMX_LOCAL_KEYBOARD: type = "keyboard"; break;
+ case DMX_LOCAL_MOUSE: type = "pointer"; break;
+ default: type = "unknown"; break;
+ }
+ dmxLog(dmxInfo, " %s (%s)\n", pt->name, type);
+ }
+ dmxLog(dmxFatal, "Must have valid local device driver\n");
+ }
+}
+
+int dmxInputExtensionErrorHandler(Display *dsp, _Xconst char *name, _Xconst char *reason)
+{
+ return 0;
+}
+
+static void dmxInputScanForExtensions(DMXInputInfo *dmxInput, int doXI)
+{
+ XExtensionVersion *ext;
+ XDeviceInfo *devices;
+ Display *display;
+ int num;
+ int i, j;
+ XextErrorHandler handler;
+
+ if (!(display = XOpenDisplay(dmxInput->name))) return;
+
+ /* Print out information about the XInput Extension. */
+ handler = XSetExtensionErrorHandler(dmxInputExtensionErrorHandler);
+ ext = XGetExtensionVersion(display, INAME);
+ XSetExtensionErrorHandler(handler);
+
+ if (!ext || ext == (XExtensionVersion *)NoSuchExtension) {
+ dmxLogInput(dmxInput, "%s is not available\n", INAME);
+ } else {
+ dmxLogInput(dmxInput, "Locating devices on %s (%s version %d.%d)\n",
+ dmxInput->name, INAME,
+ ext->major_version, ext->minor_version);
+ devices = XListInputDevices(display, &num);
+
+ XFree(ext);
+ ext = NULL;
+
+ /* Print a list of all devices */
+ for (i = 0; i < num; i++) {
+ const char *use = "Unknown";
+ switch (devices[i].use) {
+ case IsXPointer: use = "XPointer"; break;
+ case IsXKeyboard: use = "XKeyboard"; break;
+ case IsXExtensionDevice: use = "XExtensionDevice"; break;
+ case IsXExtensionPointer: use = "XExtensionPointer"; break;
+ case IsXExtensionKeyboard: use = "XExtensionKeyboard"; break;
+ }
+ dmxLogInput(dmxInput, " %2d %-10.10s %-16.16s\n",
+ devices[i].id,
+ devices[i].name ? devices[i].name : "",
+ use);
+ }
+
+ /* Search for extensions */
+ for (i = 0; i < num; i++) {
+ switch (devices[i].use) {
+ case IsXKeyboard:
+ for (j = 0; j < dmxInput->numDevs; j++) {
+ DMXLocalInputInfoPtr dmxL = dmxInput->devs[j];
+ if (dmxL->type == DMX_LOCAL_KEYBOARD
+ && dmxL->deviceId < 0) {
+ dmxL->deviceId = devices[i].id;
+ dmxL->deviceName = (devices[i].name
+ ? strdup(devices[i].name)
+ : NULL);
+ }
+ }
+ break;
+ case IsXPointer:
+ for (j = 0; j < dmxInput->numDevs; j++) {
+ DMXLocalInputInfoPtr dmxL = dmxInput->devs[j];
+ if (dmxL->type == DMX_LOCAL_MOUSE && dmxL->deviceId < 0) {
+ dmxL->deviceId = devices[i].id;
+ dmxL->deviceName = (devices[i].name
+ ? xstrdup(devices[i].name)
+ : NULL);
+ }
+ }
+ break;
+ }
+ }
+ XFreeDeviceList(devices);
+ }
+ XCloseDisplay(display);
+}
+
+/** Re-initialize all the devices described in \a dmxInput. Called from
+ #dmxAdjustCursorBoundaries before the cursor is redisplayed. */
+void dmxInputReInit(DMXInputInfo *dmxInput)
+{
+ int i;
+
+ for (i = 0; i < dmxInput->numDevs; i++) {
+ DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
+ if (dmxLocal->reinit)
+ dmxLocal->reinit(&dmxLocal->pDevice->public);
+ }
+}
+
+/** Re-initialize all the devices described in \a dmxInput. Called from
+ #dmxAdjustCursorBoundaries after the cursor is redisplayed. */
+void dmxInputLateReInit(DMXInputInfo *dmxInput)
+{
+ int i;
+
+ for (i = 0; i < dmxInput->numDevs; i++) {
+ DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
+ if (dmxLocal->latereinit)
+ dmxLocal->latereinit(&dmxLocal->pDevice->public);
+ }
+}
+
+/** Initialize all of the devices described in \a dmxInput. */
+void dmxInputInit(DMXInputInfo *dmxInput)
+{
+ DeviceIntPtr pPointer = NULL, pKeyboard = NULL;
+ dmxArg a;
+ const char *name;
+ int i;
+ int doXI = 1; /* Include by default */
+ int forceConsole = 0;
+ int doWindows = 1; /* On by default */
+ int hasXkb = 0;
+
+ a = dmxArgParse(dmxInput->name);
+
+ for (i = 1; i < dmxArgC(a); i++) {
+ switch (hasXkb) {
+ case 1:
+ dmxInput->keycodes = xstrdup(dmxArgV(a, i));
+ ++hasXkb;
+ break;
+ case 2:
+ dmxInput->symbols = xstrdup(dmxArgV(a, i));
+ ++hasXkb;
+ break;
+ case 3:
+ dmxInput->geometry = xstrdup(dmxArgV(a, i));
+ hasXkb = 0;
+ break;
+ case 0:
+ if (!strcmp(dmxArgV(a, i), "noxi")) doXI = 0;
+ else if (!strcmp(dmxArgV(a, i), "xi")) doXI = 1;
+ else if (!strcmp(dmxArgV(a, i), "console")) forceConsole = 1;
+ else if (!strcmp(dmxArgV(a, i), "noconsole")) forceConsole = 0;
+ else if (!strcmp(dmxArgV(a, i), "windows")) doWindows = 1;
+ else if (!strcmp(dmxArgV(a, i), "nowindows")) doWindows = 0;
+ else if (!strcmp(dmxArgV(a, i), "xkb")) hasXkb = 1;
+ else {
+ dmxLog(dmxFatal,
+ "Unknown input argument: %s\n", dmxArgV(a, i));
+ }
+ }
+ }
+
+ name = dmxArgV(a, 0);
+
+ if (!strcmp(name, "local")) {
+ dmxPopulateLocal(dmxInput, a);
+ } else if (!strcmp(name, "dummy")) {
+ dmxInputCopyLocal(dmxInput, &DMXDummyMou);
+ dmxInputCopyLocal(dmxInput, &DMXDummyKbd);
+ dmxLogInput(dmxInput, "Using dummy input\n");
+ } else {
+ int found;
+
+ for (found = 0, i = 0; i < dmxNumScreens; i++) {
+ if (dmxPropertySameDisplay(&dmxScreens[i], name)) {
+ if (dmxScreens[i].shared)
+ dmxLog(dmxFatal,
+ "Cannot take input from shared backend (%s)\n",
+ name);
+ if (!dmxInput->core) {
+ dmxLog(dmxWarning,
+ "Cannot use core devices on a backend (%s)"
+ " as XInput devices\n", name);
+ } else {
+ char *pt;
+ for (pt = (char *)dmxInput->name; pt && *pt; pt++)
+ if (*pt == ',') *pt = '\0';
+ dmxInputCopyLocal(dmxInput, &DMXBackendMou);
+ dmxInputCopyLocal(dmxInput, &DMXBackendKbd);
+ dmxInput->scrnIdx = i;
+ dmxLogInput(dmxInput,
+ "Using backend input from %s\n", name);
+ }
+ ++found;
+ break;
+ }
+ }
+ if (!found || forceConsole) {
+ char *pt;
+ if (found) dmxInput->console = TRUE;
+ for (pt = (char *)dmxInput->name; pt && *pt; pt++)
+ if (*pt == ',') *pt = '\0';
+ dmxInputCopyLocal(dmxInput, &DMXConsoleMou);
+ dmxInputCopyLocal(dmxInput, &DMXConsoleKbd);
+ if (doWindows) {
+ dmxInput->windows = TRUE;
+ dmxInput->updateWindowInfo = dmxUpdateWindowInformation;
+ }
+ dmxLogInput(dmxInput,
+ "Using console input from %s (%s windows)\n",
+ name, doWindows ? "with" : "without");
+ }
+ }
+
+ dmxArgFree(a);
+
+ /* Locate extensions we may be interested in */
+ dmxInputScanForExtensions(dmxInput, doXI);
+
+ for (i = 0; i < dmxInput->numDevs; i++) {
+ DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
+ dmxLocal->pDevice = dmxAddDevice(dmxLocal);
+ if (dmxLocal->isCore) {
+ if (dmxLocal->type == DMX_LOCAL_MOUSE)
+ pPointer = dmxLocal->pDevice;
+ if (dmxLocal->type == DMX_LOCAL_KEYBOARD)
+ pKeyboard = dmxLocal->pDevice;
+ }
+ }
+
+ dmxInput->processInputEvents = dmxProcessInputEvents;
+ dmxInput->detached = False;
+
+ RegisterBlockAndWakeupHandlers(dmxBlockHandler, dmxWakeupHandler,
+ (void *)(uintptr_t)dmxInput->inputIdx);
+}
+
+static void dmxInputFreeLocal(DMXLocalInputInfoRec *local)
+{
+ if (!local) return;
+ if (local->isCore && local->type == DMX_LOCAL_MOUSE)
+ dmxLocalCorePointer = NULL;
+ if (local->isCore && local->type == DMX_LOCAL_KEYBOARD)
+ dmxLocalCoreKeyboard = NULL;
+ if (local->destroy_private) local->destroy_private(local->private);
+ free(local->history);
+ free(local->valuators);
+ free(local->deviceName);
+ local->private = NULL;
+ local->history = NULL;
+ local->deviceName = NULL;
+ free(local);
+}
+
+/** Free all of the memory associated with \a dmxInput */
+void dmxInputFree(DMXInputInfo *dmxInput)
+{
+ int i;
+
+ if (!dmxInput) return;
+
+ free(dmxInput->keycodes);
+ free(dmxInput->symbols);
+ free(dmxInput->geometry);
+
+ for (i = 0; i < dmxInput->numDevs; i++) {
+ dmxInputFreeLocal(dmxInput->devs[i]);
+ dmxInput->devs[i] = NULL;
+ }
+ free(dmxInput->devs);
+ dmxInput->devs = NULL;
+ dmxInput->numDevs = 0;
+ if (dmxInput->freename) free(dmxInput->name);
+ dmxInput->name = NULL;
+}
+
+/** Log information about all of the known devices using #dmxLog(). */
+void dmxInputLogDevices(void)
+{
+ int i, j;
+
+ dmxLog(dmxInfo, "%d devices:\n", dmxGetInputCount());
+ dmxLog(dmxInfo, " Id Name Classes\n");
+ for (j = 0; j < dmxNumInputs; j++) {
+ DMXInputInfo *dmxInput = &dmxInputs[j];
+ const char *pt = strchr(dmxInput->name, ',');
+ int len = (pt
+ ? (size_t)(pt-dmxInput->name)
+ : strlen(dmxInput->name));
+
+ for (i = 0; i < dmxInput->numDevs; i++) {
+ DeviceIntPtr pDevice = dmxInput->devs[i]->pDevice;
+ if (pDevice) {
+ dmxLog(dmxInfo, " %2d%c %-20.20s",
+ pDevice->id,
+ dmxInput->detached ? 'D' : ' ',
+ pDevice->name);
+ if (pDevice->key) dmxLogCont(dmxInfo, " key");
+ if (pDevice->valuator) dmxLogCont(dmxInfo, " val");
+ if (pDevice->button) dmxLogCont(dmxInfo, " btn");
+ if (pDevice->focus) dmxLogCont(dmxInfo, " foc");
+ if (pDevice->kbdfeed) dmxLogCont(dmxInfo, " fb/kbd");
+ if (pDevice->ptrfeed) dmxLogCont(dmxInfo, " fb/ptr");
+ if (pDevice->intfeed) dmxLogCont(dmxInfo, " fb/int");
+ if (pDevice->stringfeed) dmxLogCont(dmxInfo, " fb/str");
+ if (pDevice->bell) dmxLogCont(dmxInfo, " fb/bel");
+ if (pDevice->leds) dmxLogCont(dmxInfo, " fb/led");
+ if (!pDevice->key && !pDevice->valuator && !pDevice->button
+ && !pDevice->focus && !pDevice->kbdfeed
+ && !pDevice->ptrfeed && !pDevice->intfeed
+ && !pDevice->stringfeed && !pDevice->bell
+ && !pDevice->leds) dmxLogCont(dmxInfo, " (none)");
+
+ dmxLogCont(dmxInfo, "\t[i%d/%*.*s",
+ dmxInput->inputIdx, len, len, dmxInput->name);
+ if (dmxInput->devs[i]->deviceId >= 0)
+ dmxLogCont(dmxInfo, "/id%d", dmxInput->devs[i]->deviceId);
+ if (dmxInput->devs[i]->deviceName)
+ dmxLogCont(dmxInfo, "=%s", dmxInput->devs[i]->deviceName);
+ dmxLogCont(dmxInfo, "] %s\n",
+ dmxInput->devs[i]->isCore
+ ? "core"
+ : (dmxInput->devs[i]->sendsCore
+ ? "extension (sends core events)"
+ : "extension"));
+ }
+ }
+ }
+}
+
+/** Detach an input */
+int dmxInputDetach(DMXInputInfo *dmxInput)
+{
+ int i;
+
+ if (dmxInput->detached) return BadAccess;
+
+ for (i = 0; i < dmxInput->numDevs; i++) {
+ DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
+ dmxLogInput(dmxInput, "Detaching device id %d: %s%s\n",
+ dmxLocal->pDevice->id,
+ dmxLocal->pDevice->name,
+ dmxLocal->isCore
+ ? " [core]"
+ : (dmxLocal->sendsCore
+ ? " [sends core events]"
+ : ""));
+ DisableDevice(dmxLocal->pDevice, TRUE);
+ }
+ dmxInput->detached = True;
+ dmxInputLogDevices();
+ return 0;
+}
+
+/** Search for input associated with \a dmxScreen, and detach. */
+void dmxInputDetachAll(DMXScreenInfo *dmxScreen)
+{
+ int i;
+
+ for (i = 0; i < dmxNumInputs; i++) {
+ DMXInputInfo *dmxInput = &dmxInputs[i];
+ if (dmxInput->scrnIdx == dmxScreen->index) dmxInputDetach(dmxInput);
+ }
+}
+
+/** Search for input associated with \a deviceId, and detach. */
+int dmxInputDetachId(int id)
+{
+ DMXInputInfo *dmxInput = dmxInputLocateId(id);
+
+ if (!dmxInput) return BadValue;
+
+ return dmxInputDetach(dmxInput);
+}
+
+DMXInputInfo *dmxInputLocateId(int id)
+{
+ int i, j;
+
+ for (i = 0; i < dmxNumInputs; i++) {
+ DMXInputInfo *dmxInput = &dmxInputs[i];
+ for (j = 0; j < dmxInput->numDevs; j++) {
+ DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[j];
+ if (dmxLocal->pDevice->id == id) return dmxInput;
+ }
+ }
+ return NULL;
+}
+
+static int dmxInputAttachNew(DMXInputInfo *dmxInput, int *id)
+{
+ dmxInputInit(dmxInput);
+ InitAndStartDevices();
+ if (id && dmxInput->devs) *id = dmxInput->devs[0]->pDevice->id;
+ dmxInputLogDevices();
+ return 0;
+}
+
+static int dmxInputAttachOld(DMXInputInfo *dmxInput, int *id)
+{
+ int i;
+
+ dmxInput->detached = False;
+ for (i = 0; i < dmxInput->numDevs; i++) {
+ DMXLocalInputInfoPtr dmxLocal = dmxInput->devs[i];
+ if (id) *id = dmxLocal->pDevice->id;
+ dmxLogInput(dmxInput,
+ "Attaching device id %d: %s%s\n",
+ dmxLocal->pDevice->id,
+ dmxLocal->pDevice->name,
+ dmxLocal->isCore
+ ? " [core]"
+ : (dmxLocal->sendsCore
+ ? " [sends core events]"
+ : ""));
+ EnableDevice(dmxLocal->pDevice, TRUE);
+ }
+ dmxInputLogDevices();
+ return 0;
+}
+
+int dmxInputAttachConsole(const char *name, int isCore, int *id)
+{
+ DMXInputInfo *dmxInput;
+ int i;
+
+ for (i = 0; i < dmxNumInputs; i++) {
+ dmxInput = &dmxInputs[i];
+ if (dmxInput->scrnIdx == -1
+ && dmxInput->detached
+ && !strcmp(dmxInput->name, name)) {
+ /* Found match */
+ dmxLogInput(dmxInput, "Reattaching detached console input\n");
+ return dmxInputAttachOld(dmxInput, id);
+ }
+ }
+
+ /* No match found */
+ dmxInput = dmxConfigAddInput(xstrdup(name), isCore);
+ dmxInput->freename = TRUE;
+ dmxLogInput(dmxInput, "Attaching new console input\n");
+ return dmxInputAttachNew(dmxInput, id);
+}
+
+int dmxInputAttachBackend(int physicalScreen, int isCore, int *id)
+{
+ DMXInputInfo *dmxInput;
+ DMXScreenInfo *dmxScreen;
+ int i;
+
+ if (physicalScreen < 0 || physicalScreen >= dmxNumScreens) return BadValue;
+ for (i = 0; i < dmxNumInputs; i++) {
+ dmxInput = &dmxInputs[i];
+ if (dmxInput->scrnIdx != -1 && dmxInput->scrnIdx == physicalScreen) {
+ /* Found match */
+ if (!dmxInput->detached) return BadAccess; /* Already attached */
+ dmxScreen = &dmxScreens[physicalScreen];
+ if (!dmxScreen->beDisplay) return BadAccess; /* Screen detached */
+ dmxLogInput(dmxInput, "Reattaching detached backend input\n");
+ return dmxInputAttachOld(dmxInput, id);
+ }
+ }
+ /* No match found */
+ dmxScreen = &dmxScreens[physicalScreen];
+ if (!dmxScreen->beDisplay) return BadAccess; /* Screen detached */
+ dmxInput = dmxConfigAddInput(dmxScreen->name, isCore);
+ dmxLogInput(dmxInput, "Attaching new backend input\n");
+ return dmxInputAttachNew(dmxInput, id);
+}