2006-11-26 11:13:41 -07:00
|
|
|
/***********************************************************
|
|
|
|
|
|
|
|
Copyright 1987, 1998 The Open Group
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice 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 NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
OPEN GROUP 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.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of The Open Group shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings
|
|
|
|
in this Software without prior written authorization from The Open Group.
|
|
|
|
|
|
|
|
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
2006-11-26 11:13:41 -07:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
2015-09-16 13:10:19 -06:00
|
|
|
both that copyright notice and this permission notice appear in
|
2006-11-26 11:13:41 -07:00
|
|
|
supporting documentation, and that the name of Digital not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
2015-09-16 13:10:19 -06:00
|
|
|
software without specific, written prior permission.
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
(c)Copyright 1988,1991 Adobe Systems Incorporated. All rights reserved.
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sublicense this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted, provided that
|
|
|
|
the above copyright notices appear in all copies and that both those copyright
|
|
|
|
notices and this permission notice appear in supporting documentation and that
|
|
|
|
the name of Adobe Systems Incorporated not be used in advertising or publicity
|
|
|
|
pertaining to distribution of the software without specific, written prior
|
|
|
|
permission. No trademark license to use the Adobe trademarks is hereby
|
|
|
|
granted. If the Adobe trademark "Display PostScript"(tm) is used to describe
|
|
|
|
this software, its functionality or for any other purpose, such use shall be
|
|
|
|
limited to a statement that this software works in conjunction with the Display
|
|
|
|
PostScript system. Proper trademark attribution to reflect Adobe's ownership
|
|
|
|
of the trademark shall be given whenever any such reference to the Display
|
|
|
|
PostScript system is made.
|
|
|
|
|
|
|
|
ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY
|
|
|
|
PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ADOBE
|
|
|
|
DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-
|
|
|
|
INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE TO YOU
|
|
|
|
OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
|
|
|
|
DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,NEGLIGENCE, STRICT
|
|
|
|
LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT PROVIDE ANY TRAINING OR OTHER
|
|
|
|
SUPPORT FOR THE SOFTWARE.
|
|
|
|
|
|
|
|
Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
|
|
|
|
Incorporated which may be registered in certain jurisdictions.
|
|
|
|
|
|
|
|
Author: Adobe Systems Incorporated
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xmd.h>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "windowstr.h"
|
|
|
|
#include "dixstruct.h"
|
|
|
|
#include "pixmapstr.h"
|
2010-12-05 08:36:02 -07:00
|
|
|
#include "gcstruct.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "scrnintstr.h"
|
|
|
|
#define XK_LATIN1
|
|
|
|
#include <X11/keysymdef.h>
|
|
|
|
#include "xace.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CompareTimeStamps returns -1, 0, or +1 depending on if the first
|
|
|
|
* argument is less than, equal to or greater than the second argument.
|
|
|
|
*/
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2006-11-26 11:13:41 -07:00
|
|
|
CompareTimeStamps(TimeStamp a, TimeStamp b)
|
|
|
|
{
|
|
|
|
if (a.months < b.months)
|
2012-06-10 07:21:05 -06:00
|
|
|
return EARLIER;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (a.months > b.months)
|
2012-06-10 07:21:05 -06:00
|
|
|
return LATER;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (a.milliseconds < b.milliseconds)
|
2012-06-10 07:21:05 -06:00
|
|
|
return EARLIER;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (a.milliseconds > b.milliseconds)
|
2012-06-10 07:21:05 -06:00
|
|
|
return LATER;
|
2006-11-26 11:13:41 -07:00
|
|
|
return SAMETIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* convert client times to server TimeStamps
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define HALFMONTH ((unsigned long) 1<<31)
|
2010-07-27 13:02:24 -06:00
|
|
|
TimeStamp
|
2006-11-26 11:13:41 -07:00
|
|
|
ClientTimeToServerTime(CARD32 c)
|
|
|
|
{
|
|
|
|
TimeStamp ts;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (c == CurrentTime)
|
2012-06-10 07:21:05 -06:00
|
|
|
return currentTime;
|
2006-11-26 11:13:41 -07:00
|
|
|
ts.months = currentTime.months;
|
|
|
|
ts.milliseconds = c;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (c > currentTime.milliseconds) {
|
|
|
|
if (((unsigned long) c - currentTime.milliseconds) > HALFMONTH)
|
|
|
|
ts.months -= 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (c < currentTime.milliseconds) {
|
|
|
|
if (((unsigned long) currentTime.milliseconds - c) > HALFMONTH)
|
|
|
|
ts.months += 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ISO Latin-1 case conversion routine
|
|
|
|
*
|
|
|
|
* this routine always null-terminates the result, so
|
|
|
|
* beware of too-small buffers
|
|
|
|
*/
|
|
|
|
|
|
|
|
static unsigned char
|
2012-06-10 07:21:05 -06:00
|
|
|
ISOLatin1ToLower(unsigned char source)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
unsigned char dest;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if ((source >= XK_A) && (source <= XK_Z))
|
2012-06-10 07:21:05 -06:00
|
|
|
dest = source + (XK_a - XK_A);
|
2006-11-26 11:13:41 -07:00
|
|
|
else if ((source >= XK_Agrave) && (source <= XK_Odiaeresis))
|
2012-06-10 07:21:05 -06:00
|
|
|
dest = source + (XK_agrave - XK_Agrave);
|
2006-11-26 11:13:41 -07:00
|
|
|
else if ((source >= XK_Ooblique) && (source <= XK_Thorn))
|
2012-06-10 07:21:05 -06:00
|
|
|
dest = source + (XK_oslash - XK_Ooblique);
|
2006-11-26 11:13:41 -07:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
dest = source;
|
2006-11-26 11:13:41 -07:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
CompareISOLatin1Lowered(const unsigned char *s1, int s1len,
|
|
|
|
const unsigned char *s2, int s2len)
|
|
|
|
{
|
|
|
|
unsigned char c1, c2;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* note -- compare against zero so that -1 ignores len */
|
|
|
|
c1 = s1len-- ? *s1++ : '\0';
|
|
|
|
c2 = s2len-- ? *s2++ : '\0';
|
|
|
|
if (!c1 ||
|
|
|
|
(c1 != c2 &&
|
|
|
|
(c1 = ISOLatin1ToLower(c1)) != (c2 = ISOLatin1ToLower(c2))))
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return (int) c1 - (int) c2;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
/*
|
|
|
|
* dixLookupWindow and dixLookupDrawable:
|
|
|
|
* Look up the window/drawable taking into account the client doing the
|
|
|
|
* lookup, the type of drawable desired, and the type of access desired.
|
|
|
|
* Return Success with *pDraw set if the window/drawable exists and the client
|
|
|
|
* is allowed access, else return an error code with *pDraw set to NULL. The
|
|
|
|
* access mask values are defined in resource.h. The type mask values are
|
|
|
|
* defined in pixmap.h, with zero equivalent to M_DRAWABLE.
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2007-11-24 10:55:21 -07:00
|
|
|
dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client,
|
2012-06-10 07:21:05 -06:00
|
|
|
Mask type, Mask access)
|
2007-11-24 10:55:21 -07:00
|
|
|
{
|
|
|
|
DrawablePtr pTmp;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
*pDraw = NULL;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
rc = dixLookupResourceByClass((void **) &pTmp, id, RC_DRAWABLE, client,
|
2012-06-10 07:21:05 -06:00
|
|
|
access);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-01-31 00:52:35 -07:00
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
client->errorValue = id;
|
2012-01-31 00:52:35 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc == BadValue)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadDrawable;
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2007-11-24 10:55:21 -07:00
|
|
|
if (!((1 << pTmp->type) & (type ? type : M_DRAWABLE)))
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadMatch;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
*pDraw = pTmp;
|
|
|
|
return Success;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2007-11-24 10:55:21 -07:00
|
|
|
dixLookupWindow(WindowPtr *pWin, XID id, ClientPtr client, Mask access)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 10:55:21 -07:00
|
|
|
int rc;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
rc = dixLookupDrawable((DrawablePtr *) pWin, id, client, M_WINDOW, access);
|
|
|
|
/* dixLookupDrawable returns BadMatch iff id is a valid Drawable
|
|
|
|
but is not a Window. Users of dixLookupWindow expect a BadWindow
|
|
|
|
error in this case; they don't care that it's a valid non-Window XID */
|
|
|
|
if (rc == BadMatch)
|
|
|
|
rc = BadWindow;
|
|
|
|
/* Similarly, users of dixLookupWindow don't want BadDrawable. */
|
|
|
|
if (rc == BadDrawable)
|
|
|
|
rc = BadWindow;
|
|
|
|
return rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2007-11-24 10:55:21 -07:00
|
|
|
dixLookupGC(GCPtr *pGC, XID id, ClientPtr client, Mask access)
|
2010-12-05 08:36:02 -07:00
|
|
|
{
|
2014-09-27 11:52:59 -06:00
|
|
|
return dixLookupResourceByType((void **) pGC, id, RT_GC, client, access);
|
2010-12-05 08:36:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dixLookupFontable(FontPtr *pFont, XID id, ClientPtr client, Mask access)
|
2007-11-24 10:55:21 -07:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
int rc;
|
2010-12-05 08:36:02 -07:00
|
|
|
GC *pGC;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
client->errorValue = id; /* EITHER font or gc */
|
2014-09-27 11:52:59 -06:00
|
|
|
rc = dixLookupResourceByType((void **) pFont, id, RT_FONT, client,
|
2012-06-10 07:21:05 -06:00
|
|
|
access);
|
2010-12-05 08:36:02 -07:00
|
|
|
if (rc != BadFont)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2014-09-27 11:52:59 -06:00
|
|
|
rc = dixLookupResourceByType((void **) &pGC, id, RT_GC, client, access);
|
2010-12-05 08:36:02 -07:00
|
|
|
if (rc == BadGC)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadFont;
|
2010-12-05 08:36:02 -07:00
|
|
|
if (rc == Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
*pFont = pGC->font;
|
2010-12-05 08:36:02 -07:00
|
|
|
return rc;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2007-11-24 10:55:21 -07:00
|
|
|
dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2014-09-27 11:52:59 -06:00
|
|
|
void *pRes;
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc = BadValue, clientIndex = CLIENT_ID(rid);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!clientIndex || !clients[clientIndex] || (rid & SERVER_BIT))
|
2012-06-10 07:21:05 -06:00
|
|
|
goto bad;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
rc = dixLookupResourceByClass(&pRes, rid, RC_ANY, client, DixGetAttrAccess);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
goto bad;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
rc = XaceHook(XACE_CLIENT_ACCESS, client, clients[clientIndex], access);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
goto bad;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
*pClient = clients[clientIndex];
|
|
|
|
return Success;
|
2012-06-10 07:21:05 -06:00
|
|
|
bad:
|
|
|
|
if (client)
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = rid;
|
2008-11-02 08:26:08 -07:00
|
|
|
*pClient = NULL;
|
|
|
|
return rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
AlterSaveSetForClient(ClientPtr client, WindowPtr pWin, unsigned mode,
|
2009-09-06 13:44:18 -06:00
|
|
|
Bool toRoot, Bool map)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
int numnow;
|
|
|
|
SaveSetElt *pTmp = NULL;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
numnow = client->numSaved;
|
|
|
|
j = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (numnow) {
|
|
|
|
pTmp = client->saveSet;
|
2014-09-27 11:52:59 -06:00
|
|
|
while ((j < numnow) && (SaveSetWindow(pTmp[j]) != (void *) pWin))
|
2012-06-10 07:21:05 -06:00
|
|
|
j++;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (mode == SetModeInsert) {
|
|
|
|
if (j < numnow) /* duplicate */
|
|
|
|
return Success;
|
|
|
|
numnow++;
|
|
|
|
pTmp = (SaveSetElt *) realloc(client->saveSet, sizeof(*pTmp) * numnow);
|
|
|
|
if (!pTmp)
|
|
|
|
return BadAlloc;
|
|
|
|
client->saveSet = pTmp;
|
|
|
|
client->numSaved = numnow;
|
|
|
|
SaveSetAssignWindow(client->saveSet[numnow - 1], pWin);
|
|
|
|
SaveSetAssignToRoot(client->saveSet[numnow - 1], toRoot);
|
|
|
|
SaveSetAssignMap(client->saveSet[numnow - 1], map);
|
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else if ((mode == SetModeDelete) && (j < numnow)) {
|
|
|
|
while (j < numnow - 1) {
|
|
|
|
pTmp[j] = pTmp[j + 1];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
numnow--;
|
|
|
|
if (numnow) {
|
|
|
|
pTmp =
|
|
|
|
(SaveSetElt *) realloc(client->saveSet, sizeof(*pTmp) * numnow);
|
|
|
|
if (pTmp)
|
|
|
|
client->saveSet = pTmp;
|
|
|
|
}
|
|
|
|
else {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(client->saveSet);
|
2012-06-10 07:21:05 -06:00
|
|
|
client->saveSet = (SaveSetElt *) NULL;
|
|
|
|
}
|
|
|
|
client->numSaved = numnow;
|
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeleteWindowFromAnySaveSet(WindowPtr pWin)
|
|
|
|
{
|
2007-11-24 10:55:21 -07:00
|
|
|
int i;
|
|
|
|
ClientPtr client;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
for (i = 0; i < currentMaxClients; i++) {
|
|
|
|
client = clients[i];
|
|
|
|
if (client && client->numSaved)
|
|
|
|
(void) AlterSaveSetForClient(client, pWin, SetModeDelete, FALSE,
|
|
|
|
TRUE);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No-op Don't Do Anything : sometimes we need to be able to call a procedure
|
|
|
|
* that doesn't do anything. For example, on screen with only static
|
|
|
|
* colormaps, if someone calls install colormap, it's easier to have a dummy
|
2015-09-16 13:10:19 -06:00
|
|
|
* procedure to call than to check if there's a procedure
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2006-11-26 11:13:41 -07:00
|
|
|
NoopDDA(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _BlockHandler {
|
2017-12-08 08:01:59 -07:00
|
|
|
ServerBlockHandlerProcPtr BlockHandler;
|
|
|
|
ServerWakeupHandlerProcPtr WakeupHandler;
|
2014-09-27 11:52:59 -06:00
|
|
|
void *blockData;
|
2012-06-10 07:21:05 -06:00
|
|
|
Bool deleted;
|
2006-11-26 11:13:41 -07:00
|
|
|
} BlockHandlerRec, *BlockHandlerPtr;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static BlockHandlerPtr handlers;
|
|
|
|
static int numHandlers;
|
|
|
|
static int sizeHandlers;
|
|
|
|
static Bool inHandler;
|
|
|
|
static Bool handlerDeleted;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/**
|
2015-09-16 13:10:19 -06:00
|
|
|
*
|
2006-11-26 11:13:41 -07:00
|
|
|
* \param pTimeout DIX doesn't want to know how OS represents time
|
|
|
|
* \param pReadMask nor how it represents the det of descriptors
|
|
|
|
*/
|
|
|
|
void
|
2017-12-08 08:01:59 -07:00
|
|
|
BlockHandler(void *pTimeout)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 10:55:21 -07:00
|
|
|
int i, j;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
++inHandler;
|
|
|
|
for (i = 0; i < numHandlers; i++)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!handlers[i].deleted)
|
2017-12-08 08:01:59 -07:00
|
|
|
(*handlers[i].BlockHandler) (handlers[i].blockData, pTimeout);
|
|
|
|
|
|
|
|
for (i = 0; i < screenInfo.numGPUScreens; i++)
|
|
|
|
(*screenInfo.gpuscreens[i]->BlockHandler) (screenInfo.gpuscreens[i], pTimeout);
|
|
|
|
|
|
|
|
for (i = 0; i < screenInfo.numScreens; i++)
|
|
|
|
(*screenInfo.screens[i]->BlockHandler) (screenInfo.screens[i], pTimeout);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (handlerDeleted) {
|
|
|
|
for (i = 0; i < numHandlers;)
|
|
|
|
if (handlers[i].deleted) {
|
|
|
|
for (j = i; j < numHandlers - 1; j++)
|
|
|
|
handlers[j] = handlers[j + 1];
|
|
|
|
numHandlers--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
handlerDeleted = FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
--inHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \param result 32 bits of undefined result from the wait
|
|
|
|
* \param pReadmask the resulting descriptor mask
|
|
|
|
*/
|
|
|
|
void
|
2017-12-08 08:01:59 -07:00
|
|
|
WakeupHandler(int result)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 10:55:21 -07:00
|
|
|
int i, j;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
++inHandler;
|
|
|
|
for (i = 0; i < screenInfo.numScreens; i++)
|
2017-12-08 08:01:59 -07:00
|
|
|
(*screenInfo.screens[i]->WakeupHandler) (screenInfo.screens[i], result);
|
2013-06-07 11:28:45 -06:00
|
|
|
for (i = 0; i < screenInfo.numGPUScreens; i++)
|
2017-12-08 08:01:59 -07:00
|
|
|
(*screenInfo.gpuscreens[i]->WakeupHandler) (screenInfo.gpuscreens[i], result);
|
|
|
|
for (i = numHandlers - 1; i >= 0; i--)
|
|
|
|
if (!handlers[i].deleted)
|
|
|
|
(*handlers[i].WakeupHandler) (handlers[i].blockData, result);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (handlerDeleted) {
|
|
|
|
for (i = 0; i < numHandlers;)
|
|
|
|
if (handlers[i].deleted) {
|
|
|
|
for (j = i; j < numHandlers - 1; j++)
|
|
|
|
handlers[j] = handlers[j + 1];
|
|
|
|
numHandlers--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
handlerDeleted = FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
--inHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reentrant with BlockHandler and WakeupHandler, except wakeup won't
|
|
|
|
* get called until next time
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2017-12-08 08:01:59 -07:00
|
|
|
RegisterBlockAndWakeupHandlers(ServerBlockHandlerProcPtr blockHandler,
|
|
|
|
ServerWakeupHandlerProcPtr wakeupHandler,
|
2014-09-27 11:52:59 -06:00
|
|
|
void *blockData)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
BlockHandlerPtr new;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (numHandlers >= sizeHandlers) {
|
2010-12-05 08:36:02 -07:00
|
|
|
new = (BlockHandlerPtr) realloc(handlers, (numHandlers + 1) *
|
2012-06-10 07:21:05 -06:00
|
|
|
sizeof(BlockHandlerRec));
|
|
|
|
if (!new)
|
|
|
|
return FALSE;
|
|
|
|
handlers = new;
|
|
|
|
sizeHandlers = numHandlers + 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
handlers[numHandlers].BlockHandler = blockHandler;
|
|
|
|
handlers[numHandlers].WakeupHandler = wakeupHandler;
|
|
|
|
handlers[numHandlers].blockData = blockData;
|
|
|
|
handlers[numHandlers].deleted = FALSE;
|
|
|
|
numHandlers = numHandlers + 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2017-12-08 08:01:59 -07:00
|
|
|
RemoveBlockAndWakeupHandlers(ServerBlockHandlerProcPtr blockHandler,
|
|
|
|
ServerWakeupHandlerProcPtr wakeupHandler,
|
2014-09-27 11:52:59 -06:00
|
|
|
void *blockData)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (i = 0; i < numHandlers; i++)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (handlers[i].BlockHandler == blockHandler &&
|
|
|
|
handlers[i].WakeupHandler == wakeupHandler &&
|
|
|
|
handlers[i].blockData == blockData) {
|
|
|
|
if (inHandler) {
|
|
|
|
handlerDeleted = TRUE;
|
|
|
|
handlers[i].deleted = TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (; i < numHandlers - 1; i++)
|
|
|
|
handlers[i] = handlers[i + 1];
|
|
|
|
numHandlers--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
InitBlockAndWakeupHandlers(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
free(handlers);
|
2006-11-26 11:13:41 -07:00
|
|
|
handlers = (BlockHandlerPtr) 0;
|
|
|
|
numHandlers = 0;
|
|
|
|
sizeHandlers = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A general work queue. Perform some task before the server
|
|
|
|
* sleeps for input.
|
|
|
|
*/
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
WorkQueuePtr workQueue;
|
|
|
|
static WorkQueuePtr *workQueueLast = &workQueue;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
ProcessWorkQueue(void)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
WorkQueuePtr q, *p;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
p = &workQueue;
|
|
|
|
/*
|
|
|
|
* Scan the work queue once, calling each function. Those
|
|
|
|
* which return TRUE are removed from the queue, otherwise
|
|
|
|
* they will be called again. This must be reentrant with
|
|
|
|
* QueueWorkProc.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
while ((q = *p)) {
|
|
|
|
if ((*q->function) (q->client, q->closure)) {
|
|
|
|
/* remove q from the list */
|
|
|
|
*p = q->next; /* don't fetch until after func called */
|
|
|
|
free(q);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p = &q->next; /* don't fetch until after func called */
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
workQueueLast = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ProcessWorkQueueZombies(void)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
WorkQueuePtr q, *p;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
p = &workQueue;
|
2012-06-10 07:21:05 -06:00
|
|
|
while ((q = *p)) {
|
|
|
|
if (q->client && q->client->clientGone) {
|
|
|
|
(void) (*q->function) (q->client, q->closure);
|
|
|
|
/* remove q from the list */
|
|
|
|
*p = q->next; /* don't fetch until after func called */
|
|
|
|
free(q);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p = &q->next; /* don't fetch until after func called */
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
workQueueLast = p;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
QueueWorkProc(Bool (*function) (ClientPtr pClient, void *closure),
|
|
|
|
ClientPtr client, void *closure)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
WorkQueuePtr q;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
q = malloc(sizeof *q);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!q)
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
q->function = function;
|
|
|
|
q->client = client;
|
|
|
|
q->closure = closure;
|
|
|
|
q->next = NULL;
|
|
|
|
*workQueueLast = q;
|
|
|
|
workQueueLast = &q->next;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manage a queue of sleeping clients, awakening them
|
|
|
|
* when requested, by using the OS functions IgnoreClient
|
|
|
|
* and AttendClient. Note that this *ignores* the troubles
|
|
|
|
* with request data interleaving itself with events, but
|
|
|
|
* we'll leave that until a later time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _SleepQueue {
|
2012-06-10 07:21:05 -06:00
|
|
|
struct _SleepQueue *next;
|
|
|
|
ClientPtr client;
|
|
|
|
ClientSleepProcPtr function;
|
2014-09-27 11:52:59 -06:00
|
|
|
void *closure;
|
2006-11-26 11:13:41 -07:00
|
|
|
} SleepQueueRec, *SleepQueuePtr;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static SleepQueuePtr sleepQueue = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
ClientSleep(ClientPtr client, ClientSleepProcPtr function, void *closure)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
SleepQueuePtr q;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
q = malloc(sizeof *q);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!q)
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
IgnoreClient(client);
|
2006-11-26 11:13:41 -07:00
|
|
|
q->next = sleepQueue;
|
|
|
|
q->client = client;
|
|
|
|
q->function = function;
|
|
|
|
q->closure = closure;
|
|
|
|
sleepQueue = q;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
ClientSignal(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
SleepQueuePtr q;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (q = sleepQueue; q; q = q->next)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (q->client == client) {
|
|
|
|
return QueueWorkProc(q->function, q->client, q->closure);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-05-29 06:02:34 -06:00
|
|
|
int
|
|
|
|
ClientSignalAll(ClientPtr client, ClientSleepProcPtr function, void *closure)
|
|
|
|
{
|
|
|
|
SleepQueuePtr q;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (q = sleepQueue; q; q = q->next) {
|
|
|
|
if (!(client == CLIENT_SIGNAL_ANY || q->client == client))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(function == CLIENT_SIGNAL_ANY || q->function == function))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(closure == CLIENT_SIGNAL_ANY || q->closure == closure))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
count += QueueWorkProc(q->function, q->client, q->closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
ClientWakeup(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
SleepQueuePtr q, *prev;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
prev = &sleepQueue;
|
2012-06-10 07:21:05 -06:00
|
|
|
while ((q = *prev)) {
|
|
|
|
if (q->client == client) {
|
|
|
|
*prev = q->next;
|
|
|
|
free(q);
|
|
|
|
if (client->clientGone)
|
|
|
|
/* Oops -- new zombie cleanup code ensures this only
|
|
|
|
* happens from inside CloseDownClient; don't want to
|
|
|
|
* recurse here...
|
|
|
|
*/
|
|
|
|
/* CloseDownClient(client) */ ;
|
|
|
|
else
|
|
|
|
AttendClient(client);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = &q->next;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
ClientIsAsleep(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
SleepQueuePtr q;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (q = sleepQueue; q; q = q->next)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (q->client == client)
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic Callback Manager
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ===== Private Procedures ===== */
|
|
|
|
|
|
|
|
static int numCallbackListsToCleanup = 0;
|
|
|
|
static CallbackListPtr **listsToCleanup = NULL;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
_AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, void *data)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
CallbackPtr cbr;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
cbr = malloc(sizeof(CallbackRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!cbr)
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
cbr->proc = callback;
|
|
|
|
cbr->data = data;
|
|
|
|
cbr->next = (*pcbl)->list;
|
|
|
|
cbr->deleted = FALSE;
|
|
|
|
(*pcbl)->list = cbr;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
_DeleteCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, void *data)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
CallbackListPtr cbl = *pcbl;
|
2012-06-10 07:21:05 -06:00
|
|
|
CallbackPtr cbr, pcbr;
|
|
|
|
|
|
|
|
for (pcbr = NULL, cbr = cbl->list; cbr != NULL; pcbr = cbr, cbr = cbr->next) {
|
|
|
|
if ((cbr->proc == callback) && (cbr->data == data))
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (cbr != NULL) {
|
|
|
|
if (cbl->inCallback) {
|
|
|
|
++(cbl->numDeleted);
|
|
|
|
cbr->deleted = TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (pcbr == NULL)
|
|
|
|
cbl->list = cbr->next;
|
|
|
|
else
|
|
|
|
pcbr->next = cbr->next;
|
|
|
|
free(cbr);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
2014-09-27 11:52:59 -06:00
|
|
|
_CallCallbacks(CallbackListPtr *pcbl, void *call_data)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
CallbackListPtr cbl = *pcbl;
|
2012-06-10 07:21:05 -06:00
|
|
|
CallbackPtr cbr, pcbr;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
++(cbl->inCallback);
|
2012-06-10 07:21:05 -06:00
|
|
|
for (cbr = cbl->list; cbr != NULL; cbr = cbr->next) {
|
|
|
|
(*(cbr->proc)) (pcbl, cbr->data, call_data);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
--(cbl->inCallback);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (cbl->inCallback)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* Was the entire list marked for deletion? */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (cbl->deleted) {
|
|
|
|
DeleteCallbackList(pcbl);
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Were some individual callbacks on the list marked for deletion?
|
|
|
|
* If so, do the deletions.
|
|
|
|
*/
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (cbl->numDeleted) {
|
|
|
|
for (pcbr = NULL, cbr = cbl->list; (cbr != NULL) && cbl->numDeleted;) {
|
|
|
|
if (cbr->deleted) {
|
|
|
|
if (pcbr) {
|
|
|
|
cbr = cbr->next;
|
|
|
|
free(pcbr->next);
|
|
|
|
pcbr->next = cbr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cbr = cbr->next;
|
|
|
|
free(cbl->list);
|
|
|
|
cbl->list = cbr;
|
|
|
|
}
|
|
|
|
cbl->numDeleted--;
|
|
|
|
}
|
|
|
|
else { /* this one wasn't deleted */
|
|
|
|
|
|
|
|
pcbr = cbr;
|
|
|
|
cbr = cbr->next;
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
_DeleteCallbackList(CallbackListPtr *pcbl)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
CallbackListPtr cbl = *pcbl;
|
2012-06-10 07:21:05 -06:00
|
|
|
CallbackPtr cbr, nextcbr;
|
2006-11-26 11:13:41 -07:00
|
|
|
int i;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (cbl->inCallback) {
|
|
|
|
cbl->deleted = TRUE;
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < numCallbackListsToCleanup; i++) {
|
|
|
|
if (listsToCleanup[i] == pcbl) {
|
|
|
|
listsToCleanup[i] = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (cbr = cbl->list; cbr != NULL; cbr = nextcbr) {
|
|
|
|
nextcbr = cbr->next;
|
|
|
|
free(cbr);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(cbl);
|
2006-11-26 11:13:41 -07:00
|
|
|
*pcbl = NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
static Bool
|
2008-11-02 08:26:08 -07:00
|
|
|
CreateCallbackList(CallbackListPtr *pcbl)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
CallbackListPtr cbl;
|
2006-11-26 11:13:41 -07:00
|
|
|
int i;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pcbl)
|
|
|
|
return FALSE;
|
2010-12-05 08:36:02 -07:00
|
|
|
cbl = malloc(sizeof(CallbackListRec));
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!cbl)
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
cbl->inCallback = 0;
|
|
|
|
cbl->deleted = FALSE;
|
|
|
|
cbl->numDeleted = 0;
|
|
|
|
cbl->list = NULL;
|
|
|
|
*pcbl = cbl;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < numCallbackListsToCleanup; i++) {
|
|
|
|
if (!listsToCleanup[i]) {
|
|
|
|
listsToCleanup[i] = pcbl;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
listsToCleanup = (CallbackListPtr **) xnfrealloc(listsToCleanup,
|
|
|
|
sizeof(CallbackListPtr *) *
|
|
|
|
(numCallbackListsToCleanup
|
|
|
|
+ 1));
|
2006-11-26 11:13:41 -07:00
|
|
|
listsToCleanup[numCallbackListsToCleanup] = pcbl;
|
|
|
|
numCallbackListsToCleanup++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
/* ===== Public Procedures ===== */
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, void *data)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pcbl)
|
|
|
|
return FALSE;
|
|
|
|
if (!*pcbl) { /* list hasn't been created yet; go create it */
|
|
|
|
if (!CreateCallbackList(pcbl))
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
return _AddCallback(pcbl, callback, data);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
DeleteCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, void *data)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pcbl || !*pcbl)
|
|
|
|
return FALSE;
|
2008-11-02 08:26:08 -07:00
|
|
|
return _DeleteCallback(pcbl, callback, data);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeleteCallbackList(CallbackListPtr *pcbl)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pcbl || !*pcbl)
|
|
|
|
return;
|
2008-11-02 08:26:08 -07:00
|
|
|
_DeleteCallbackList(pcbl);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2014-05-02 13:27:46 -06:00
|
|
|
DeleteCallbackManager(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < numCallbackListsToCleanup; i++) {
|
|
|
|
DeleteCallbackList(listsToCleanup[i]);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(listsToCleanup);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
numCallbackListsToCleanup = 0;
|
|
|
|
listsToCleanup = NULL;
|
|
|
|
}
|
2014-05-02 13:27:46 -06:00
|
|
|
|
|
|
|
void
|
|
|
|
InitCallbackManager(void)
|
|
|
|
{
|
|
|
|
DeleteCallbackManager();
|
|
|
|
}
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Coordinates the global GL context used by modules in the X Server
|
|
|
|
* doing rendering with OpenGL.
|
|
|
|
*
|
|
|
|
* When setting a GL context (glXMakeCurrent() or eglMakeCurrent()),
|
|
|
|
* there is an expensive implied glFlush() required by the GLX and EGL
|
|
|
|
* APIs, so modules don't want to have to do it on every request. But
|
|
|
|
* the individual modules using GL also don't know about each other,
|
|
|
|
* so they have to coordinate who owns the current context.
|
|
|
|
*
|
|
|
|
* When you're about to do a MakeCurrent, you should set this variable
|
|
|
|
* to your context's address, and you can skip MakeCurrent if it's
|
|
|
|
* already set to yours.
|
|
|
|
*
|
|
|
|
* When you're about to do a DestroyContext, you should set this to
|
|
|
|
* NULL if it's set to your context.
|
|
|
|
*
|
|
|
|
* When you're about to do an unbindContext on a DRI driver, you
|
|
|
|
* should set this to NULL. Despite the unbindContext interface
|
|
|
|
* sounding like it only unbinds the passed in context, it actually
|
|
|
|
* unconditionally clears the dispatch table even if the given
|
|
|
|
* context wasn't current.
|
|
|
|
*/
|
|
|
|
void *lastGLContext = NULL;
|