/nx-3.5.0/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c
C | 4716 lines | 3825 code | 517 blank | 374 comment | 710 complexity | cf05a9dd59d7903f2fb8c4e7f7ac2411 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
Large files files are truncated, but you can click here to view the full file
- #ifdef NXAGENT_UPGRADE
- #include "X/NXdispatch.c"
- #else
- /**************************************************************************/
- /* */
- /* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */
- /* */
- /* NXAGENT, NX protocol compression and NX extensions to this software */
- /* are copyright of NoMachine. Redistribution and use of the present */
- /* software is allowed according to terms specified in the file LICENSE */
- /* which comes in the source distribution. */
- /* */
- /* Check http://www.nomachine.com/licensing.html for applicability. */
- /* */
- /* NX and NoMachine are trademarks of Medialogic S.p.A. */
- /* */
- /* All rights reserved. */
- /* */
- /**************************************************************************/
- /* $Xorg: dispatch.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */
- /************************************************************
- Copyright 1987, 1989, 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, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
- All Rights Reserved
- Permission to use, copy, modify, and distribute this software and its
- documentation for any purpose and without fee is hereby granted,
- provided that the above copyright notice appear in all copies and that
- both that copyright notice and this permission notice appear in
- supporting documentation, and that the name of Digital not be
- used in advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
- 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.
- ********************************************************/
- /* The panoramix components contained the following notice */
- /****************************************************************
- * *
- * Copyright (c) Digital Equipment Corporation, 1991, 1997 *
- * *
- * All Rights Reserved. Unpublished rights reserved under *
- * the copyright laws of the United States. *
- * *
- * The software contained on this media is proprietary to *
- * and embodies the confidential technology of Digital *
- * Equipment Corporation. Possession, use, duplication or *
- * dissemination of the software and media is authorized only *
- * pursuant to a valid written license from Digital Equipment *
- * Corporation. *
- * *
- * RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure *
- * by the U.S. Government is subject to restrictions as set *
- * forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, *
- * or in FAR 52.227-19, as applicable. *
- * *
- *****************************************************************/
- /* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.29 2003/01/12 02:44:26 dawes Exp $ */
- #ifdef PANORAMIX_DEBUG
- #include <stdio.h>
- int ProcInitialConnection();
- #endif
- #ifdef __sun
- #define False 0
- #define True 1
- #endif
- #define GC XlibGC
- #include <X11/Xlib.h>
- #undef GC
- #include "windowstr.h"
- #include "fontstruct.h"
- #include "dixfontstr.h"
- #include "gcstruct.h"
- #include "selection.h"
- #include "colormapst.h"
- #include "cursorstr.h"
- #include "scrnintstr.h"
- #include "opaque.h"
- #include "input.h"
- #include "servermd.h"
- #include "extnsionst.h"
- #include "dixfont.h"
- #include "../../dix/dispatch.h"
- #include "swaprep.h"
- #include "swapreq.h"
- #ifdef PANORAMIX
- #include "panoramiX.h"
- #include "panoramiXsrv.h"
- #endif
- #ifdef XCSECURITY
- #define _SECURITY_SERVER
- #include "security.h"
- #endif
- #ifdef XAPPGROUP
- #include "Xagsrv.h"
- #endif
- #ifdef XKB
- #define XKB_IN_SERVER
- #include "inputstr.h"
- #include "XKBsrv.h"
- #endif
- #include "Atoms.h"
- #include "Splash.h"
- #include "Client.h"
- #include "Clipboard.h"
- #include "Reconnect.h"
- #include "Millis.h"
- #include "Font.h"
- #include "Shadow.h"
- #include "Handlers.h"
- const int nxagentMaxFontNames = 10000;
- char dispatchExceptionAtReset = DE_RESET;
- /*
- * This allows the agent to exit if no
- * client is connected within a timeout.
- */
- int nxagentClients = 0;
- void nxagentWaitDisplay(void);
- void nxagentListRemoteFonts(const char *, int);
- unsigned int nxagentWMtimeout = 0;
- Bool nxagentWMPassed = 0;
- /*
- * Timeouts based on screen saver time.
- */
- int nxagentAutoDisconnectTimeout = 0;
- #ifdef LBX
- #include "../../lbx/lbxserve.h"
- #endif
- #include "Xatom.h"
- /*
- * Set here the required log level.
- */
- #define PANIC
- #define WARNING
- #undef TEST
- #undef WATCH
- /*
- * Log begin and end of the important handlers.
- */
- #undef BLOCKS
- #ifdef WATCH
- #include "unistd.h"
- #endif
- #ifdef TEST
- #include "Literals.h"
- #endif
- #define mskcnt ((MAXCLIENTS + 31) / 32)
- #define BITMASK(i) (1U << ((i) & 31))
- #define MASKIDX(i) ((i) >> 5)
- #define MASKWORD(buf, i) buf[MASKIDX(i)]
- #define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
- #define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
- #define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
- extern xConnSetupPrefix connSetupPrefix;
- extern char *ConnectionInfo;
- Selection *CurrentSelections;
- int NumCurrentSelections;
- extern WindowPtr nxagentViewportFrameLeft;
- extern WindowPtr nxagentViewportFrameRight;
- extern WindowPtr nxagentViewportFrameAbove;
- extern WindowPtr nxagentViewportFrameBelow;
- #define IsViewportFrame(pWin) ((pWin) == nxagentViewportFrameLeft || \
- (pWin) == nxagentViewportFrameRight || \
- (pWin) == nxagentViewportFrameAbove || \
- (pWin) == nxagentViewportFrameBelow)
- extern int nxagentMaxAllowedResets;
- extern int nxagentFindClientResource(int, RESTYPE, pointer);
- static ClientPtr grabClient;
- #define GrabNone 0
- #define GrabActive 1
- #define GrabKickout 2
- static int grabState = GrabNone;
- static long grabWaiters[mskcnt];
- CallbackListPtr ServerGrabCallback = NULL;
- HWEventQueuePtr checkForInput[2];
- extern int connBlockScreenStart;
- static void KillAllClients(
- #if NeedFunctionPrototypes
- void
- #endif
- );
- static void DeleteClientFromAnySelections(
- #if NeedFunctionPrototypes
- ClientPtr /*client*/
- #endif
- );
- static int nextFreeClientID; /* always MIN free client ID */
- static int nClients; /* number of authorized clients */
- CallbackListPtr ClientStateCallback;
- char dispatchException = 0;
- char isItTimeToYield;
- /* Various of the DIX function interfaces were not designed to allow
- * the client->errorValue to be set on BadValue and other errors.
- * Rather than changing interfaces and breaking untold code we introduce
- * a new global that dispatch can use.
- */
- XID clientErrorValue; /* XXX this is a kludge */
- #define SAME_SCREENS(a, b) (\
- (a.pScreen == b.pScreen))
- void
- SetInputCheck(c0, c1)
- HWEventQueuePtr c0, c1;
- {
- checkForInput[0] = c0;
- checkForInput[1] = c1;
- }
- void
- UpdateCurrentTime()
- {
- TimeStamp systime;
- /* To avoid time running backwards, we must call GetTimeInMillis before
- * calling ProcessInputEvents.
- */
- systime.months = currentTime.months;
- systime.milliseconds = GetTimeInMillis();
- if (systime.milliseconds < currentTime.milliseconds)
- systime.months++;
- if (*checkForInput[0] != *checkForInput[1])
- ProcessInputEvents();
- if (CompareTimeStamps(systime, currentTime) == LATER)
- currentTime = systime;
- }
- /* Like UpdateCurrentTime, but can't call ProcessInputEvents */
- void
- UpdateCurrentTimeIf()
- {
- TimeStamp systime;
- systime.months = currentTime.months;
- systime.milliseconds = GetTimeInMillis();
- if (systime.milliseconds < currentTime.milliseconds)
- systime.months++;
- if (*checkForInput[0] == *checkForInput[1])
- currentTime = systime;
- }
- void
- InitSelections()
- {
- if (CurrentSelections)
- xfree(CurrentSelections);
- CurrentSelections = (Selection *)NULL;
- NumCurrentSelections = 0;
- #ifdef NXAGENT_CLIPBOARD
- {
- Selection *newsels;
- newsels = (Selection *)xalloc(2 * sizeof(Selection));
- if (!newsels)
- return;
- NumCurrentSelections += 2;
- CurrentSelections = newsels;
- CurrentSelections[0].selection = XA_PRIMARY;
- CurrentSelections[0].lastTimeChanged = ClientTimeToServerTime(0);
- CurrentSelections[0].window = WindowTable[0]->drawable.id;
- CurrentSelections[0].pWin = NULL;
- CurrentSelections[0].client = NullClient;
- CurrentSelections[1].selection = MakeAtom("CLIPBOARD", 9, 1);
- CurrentSelections[1].lastTimeChanged = ClientTimeToServerTime(0);
- CurrentSelections[1].window = WindowTable[0]->drawable.id;
- CurrentSelections[1].pWin = NULL;
- CurrentSelections[1].client = NullClient;
- }
- #endif
- }
- void
- FlushClientCaches(id)
- XID id;
- {
- int i;
- register ClientPtr client;
- client = clients[CLIENT_ID(id)];
- if (client == NullClient)
- return ;
- for (i=0; i<currentMaxClients; i++)
- {
- client = clients[i];
- if (client != NullClient)
- {
- if (client->lastDrawableID == id)
- {
- client->lastDrawableID = WindowTable[0]->drawable.id;
- client->lastDrawable = (DrawablePtr)WindowTable[0];
- }
- else if (client->lastGCID == id)
- {
- client->lastGCID = INVALID;
- client->lastGC = (GCPtr)NULL;
- }
- }
- }
- }
- #ifdef SMART_SCHEDULE
- #undef SMART_DEBUG
- #define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */
- #define SMART_SCHEDULE_MAX_SLICE 200 /* ms */
- /*
- * Disable the SmartScheduler as it doesn't
- * seem to work for us.
- */
- Bool SmartScheduleDisable = True;
- long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL;
- long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL;
- long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE;
- long SmartScheduleTime;
- ClientPtr SmartLastClient;
- int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1];
- int SmartScheduleClient(int *clientReady, int nready);
- #ifdef SMART_DEBUG
- long SmartLastPrint;
- #endif
- void Dispatch(void);
- void InitProcVectors(void);
- int
- SmartScheduleClient (int *clientReady, int nready)
- {
- ClientPtr pClient;
- int i;
- int client;
- int bestPrio, best = 0;
- int bestRobin, robin;
- long now = SmartScheduleTime;
- long idle;
- bestPrio = -0x7fffffff;
- bestRobin = 0;
- idle = 2 * SmartScheduleSlice;
- for (i = 0; i < nready; i++)
- {
- client = clientReady[i];
- pClient = clients[client];
- /* Praise clients which are idle */
- if ((now - pClient->smart_check_tick) >= idle)
- {
- if (pClient->smart_priority < 0)
- pClient->smart_priority++;
- }
- pClient->smart_check_tick = now;
-
- /* check priority to select best client */
- robin = (pClient->index - SmartLastIndex[pClient->smart_priority-SMART_MIN_PRIORITY]) & 0xff;
- if (pClient->smart_priority > bestPrio ||
- (pClient->smart_priority == bestPrio && robin > bestRobin))
- {
- bestPrio = pClient->smart_priority;
- bestRobin = robin;
- best = client;
- }
- #ifdef SMART_DEBUG
- if ((now - SmartLastPrint) >= 5000)
- fprintf (stderr, " %2d: %3d", client, pClient->smart_priority);
- #endif
- }
- #ifdef SMART_DEBUG
- if ((now - SmartLastPrint) >= 5000)
- {
- fprintf (stderr, " use %2d\n", best);
- SmartLastPrint = now;
- }
- #endif
- pClient = clients[best];
- SmartLastIndex[bestPrio-SMART_MIN_PRIORITY] = pClient->index;
- /*
- * Set current client pointer
- */
- if (SmartLastClient != pClient)
- {
- pClient->smart_start_tick = now;
- SmartLastClient = pClient;
- }
- /*
- * Adjust slice
- */
- if (nready == 1)
- {
- /*
- * If it's been a long time since another client
- * has run, bump the slice up to get maximal
- * performance from a single client
- */
- if ((now - pClient->smart_start_tick) > 1000 &&
- SmartScheduleSlice < SmartScheduleMaxSlice)
- {
- SmartScheduleSlice += SmartScheduleInterval;
- }
- }
- else
- {
- SmartScheduleSlice = SmartScheduleInterval;
- }
- return best;
- }
- #endif
- #define MAJOROP ((xReq *)client->requestBuffer)->reqType
- void
- Dispatch(void)
- {
- register int *clientReady; /* array of request ready clients */
- register int result;
- register ClientPtr client;
- register int nready;
- register HWEventQueuePtr* icheck = checkForInput;
- #ifdef SMART_SCHEDULE
- int start_tick;
- #endif
- unsigned long currentDispatch = 0;
- nextFreeClientID = 1;
- InitSelections();
- nClients = 0;
- /*
- * The agent initialization was successfully
- * completed. We can now handle our clients.
- */
- if (serverGeneration > nxagentMaxAllowedResets)
- {
- fprintf(stderr, "Session: Session started at '%s'.\n", GetTimeAsString());
- nxagentSessionState = SESSION_UP;
- }
- #ifdef NXAGENT_ONSTART
- /*
- * Set NX_WM property (used by NX client to identify
- * the agent's window) three seconds since the first
- * client connects.
- */
- nxagentWMtimeout = GetTimeInMillis() + 3000;
- #endif
- clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients);
- if (!clientReady)
- return;
- #ifdef WATCH
- fprintf(stderr, "Dispatch: Watchpoint 12.\n");
- /*
- Reply Total Cached Bits In Bits Out Bits/Reply Ratio
- ------- ----- ------ ------- -------- ---------- -----
- #3 1 352 bits (0 KB) -> 236 bits (0 KB) -> 352/1 -> 236/1 = 1.492:1
- #14 1 256 bits (0 KB) -> 101 bits (0 KB) -> 256/1 -> 101/1 = 2.535:1
- #16 1 256 bits (0 KB) -> 26 bits (0 KB) -> 256/1 -> 26/1 = 9.846:1
- #20 2 2 12256 bits (1 KB) -> 56 bits (0 KB) -> 6128/1 -> 28/1 = 218.857:1
- #43 1 256 bits (0 KB) -> 45 bits (0 KB) -> 256/1 -> 45/1 = 5.689:1
- #47 2 2 42304 bits (5 KB) -> 49 bits (0 KB) -> 21152/1 -> 24/1 = 863.347:1
- #98 1 256 bits (0 KB) -> 34 bits (0 KB) -> 256/1 -> 34/1 = 7.529:1
- */
- sleep(30);
- #endif
- #ifdef TEST
- fprintf(stderr, "Dispatch: Value of dispatchException is [%x].\n",
- dispatchException);
- fprintf(stderr, "Dispatch: Value of dispatchExceptionAtReset is [%x].\n",
- dispatchExceptionAtReset);
- #endif
- if (!(dispatchException & DE_TERMINATE))
- dispatchException = 0;
- while (!dispatchException)
- {
- if (*icheck[0] != *icheck[1])
- {
- ProcessInputEvents();
- FlushIfCriticalOutputPending();
- }
- /*
- * Ensure we remove the splash after the timeout.
- * Initializing clientReady[0] to -1 will tell
- * WaitForSomething() to yield control after the
- * timeout set in clientReady[1].
- */
- clientReady[0] = 0;
- if (nxagentSplashWindow != None || (nxagentOption(Xdmcp) == 1 && nxagentXdmcpUp == 0))
- {
- #ifdef TEST
- fprintf(stderr, "******Dispatch: Requesting a timeout of [%d] Ms.\n",
- NXAGENT_WAKEUP);
- #endif
- clientReady[0] = -1;
- clientReady[1] = NXAGENT_WAKEUP;
- }
- #ifdef BLOCKS
- fprintf(stderr, "[End dispatch]\n");
- #endif
- nready = WaitForSomething(clientReady);
- #ifdef BLOCKS
- fprintf(stderr, "[Begin dispatch]\n");
- #endif
- #ifdef TEST
- fprintf(stderr, "******Dispatch: Running with [%d] clients ready.\n",
- nready);
- #endif
-
- #ifdef NXAGENT_ONSTART
- currentDispatch = GetTimeInMillis();
- /*
- * If the timeout is expired set the
- * selection informing the NX client
- * that the agent is ready.
- */
- if (!nxagentWMPassed && (nxagentWMtimeout < currentDispatch))
- {
- nxagentRemoveSplashWindow(NULL);
- }
- nxagentClients = nClients;
- #endif
- #ifdef SMART_SCHEDULE
- if (nready && !SmartScheduleDisable)
- {
- clientReady[0] = SmartScheduleClient (clientReady, nready);
- nready = 1;
- }
- #endif
- /*****************
- * Handle events in round robin fashion, doing input between
- * each round
- *****************/
- while (!dispatchException && (--nready >= 0))
- {
- client = clients[clientReady[nready]];
- if (! client)
- {
- /* KillClient can cause this to happen */
- continue;
- }
- /* GrabServer activation can cause this to be true */
- if (grabState == GrabKickout)
- {
- grabState = GrabActive;
- break;
- }
- isItTimeToYield = FALSE;
-
- requestingClient = client;
- #ifdef SMART_SCHEDULE
- start_tick = SmartScheduleTime;
- #endif
- while (!isItTimeToYield)
- {
- if (*icheck[0] != *icheck[1])
- {
- ProcessInputEvents();
- FlushIfCriticalOutputPending();
- }
- #ifdef SMART_SCHEDULE
- if (!SmartScheduleDisable &&
- (SmartScheduleTime - start_tick) >= SmartScheduleSlice)
- {
- /* Penalize clients which consume ticks */
- if (client->smart_priority > SMART_MIN_PRIORITY)
- client->smart_priority--;
- break;
- }
- #endif
- /* now, finally, deal with client requests */
- #ifdef TEST
- fprintf(stderr, "******Dispatch: Reading request from client [%d].\n",
- client->index);
- #endif
- result = ReadRequestFromClient(client);
- if (result <= 0)
- {
- if (result < 0)
- CloseDownClient(client);
- break;
- }
- #ifdef NXAGENT_SERVER
- #ifdef TEST
- else
- {
- if (MAJOROP > 127)
- {
- fprintf(stderr, "******Dispatch: Read [Extension] request OPCODE#%d MINOR#%d "
- "size [%d] client [%d].\n", MAJOROP, *((char *) client->requestBuffer + 1),
- client->req_len << 2, client->index);
- }
- else
- {
- fprintf(stderr, "******Dispatch: Read [%s] request OPCODE#%d size [%d] client [%d].\n",
- nxagentRequestLiteral[MAJOROP], MAJOROP, client->req_len << 2,
- client->index);
- }
- }
- #endif
- #endif
- client->sequence++;
- #ifdef DEBUG
- if (client->requestLogIndex == MAX_REQUEST_LOG)
- client->requestLogIndex = 0;
- client->requestLog[client->requestLogIndex] = MAJOROP;
- client->requestLogIndex++;
- #endif
- if (result > (MAX_BIG_REQUEST_SIZE << 2))
- result = BadLength;
- else
- #ifdef NXAGENT_SERVER
- {
- result = (* client->requestVector[MAJOROP])(client);
- #ifdef TEST
- if (MAJOROP > 127)
- {
- fprintf(stderr, "******Dispatch: Handled [Extension] request OPCODE#%d MINOR#%d "
- "size [%d] client [%d] result [%d].\n", MAJOROP,
- *((char *) client->requestBuffer + 1), client->req_len << 2,
- client->index, result);
- }
- else
- {
- fprintf(stderr, "******Dispatch: Handled [%s] request OPCODE#%d size [%d] client [%d] "
- "result [%d].\n", nxagentRequestLiteral[MAJOROP], MAJOROP,
- client->req_len << 2, client->index, result);
- }
- #endif
- /*
- * Can set isItTimeToYield to force
- * the dispatcher to pay attention
- * to another client.
- */
- nxagentDispatchHandler(client, client->req_len << 2, 0);
- }
- #else
- result = (* client->requestVector[MAJOROP])(client);
- #endif
- if (result != Success)
- {
- if (client->noClientException != Success)
- CloseDownClient(client);
- else
- SendErrorToClient(client, MAJOROP,
- MinorOpcodeOfRequest(client),
- client->errorValue, result);
- break;
- }
- }
- FlushAllOutput();
- #ifdef SMART_SCHEDULE
- client = clients[clientReady[nready]];
- if (client)
- client->smart_stop_tick = SmartScheduleTime;
- #endif
- requestingClient = NULL;
- }
- dispatchException &= ~DE_PRIORITYCHANGE;
- }
- if ((dispatchException & DE_RESET) &&
- (serverGeneration > nxagentMaxAllowedResets))
- {
- dispatchException &= ~DE_RESET;
- dispatchException |= DE_TERMINATE;
- fprintf(stderr, "Info: Reached threshold of maximum allowed resets.\n");
- }
- nxagentResetAtomMap();
- if (serverGeneration > nxagentMaxAllowedResets)
- {
- /*
- * The session is terminating. Force an I/O
- * error on the display and wait until the
- * NX transport is gone.
- */
- fprintf(stderr, "Session: Terminating session at '%s'.\n", GetTimeAsString());
- nxagentWaitDisplay();
- fprintf(stderr, "Session: Session terminated at '%s'.\n", GetTimeAsString());
- }
- if (nxagentOption(Shadow))
- {
- NXShadowDestroy();
- }
- KillAllClients();
- DEALLOCATE_LOCAL(clientReady);
- dispatchException &= ~DE_RESET;
- }
- #undef MAJOROP
- /*ARGSUSED*/
- int
- ProcBadRequest(client)
- ClientPtr client;
- {
- return (BadRequest);
- }
- int
- ProcCreateWindow(client)
- register ClientPtr client;
- {
- register WindowPtr pParent, pWin;
- REQUEST(xCreateWindowReq);
- int result;
- int len;
- REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
-
- LEGAL_NEW_RESOURCE(stuff->wid, client);
- if (!(pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
- SecurityWriteAccess)))
- return BadWindow;
- len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
- if (Ones(stuff->mask) != len)
- return BadLength;
- if (!stuff->width || !stuff->height)
- {
- client->errorValue = 0;
- return BadValue;
- }
- pWin = CreateWindow(stuff->wid, pParent, stuff->x,
- stuff->y, stuff->width, stuff->height,
- stuff->borderWidth, stuff->class,
- stuff->mask, (XID *) &stuff[1],
- (int)stuff->depth,
- client, stuff->visual, &result);
- if (pWin)
- {
- Mask mask = pWin->eventMask;
- pWin->eventMask = 0; /* subterfuge in case AddResource fails */
- if (!AddResource(stuff->wid, RT_WINDOW, (pointer)pWin))
- return BadAlloc;
- pWin->eventMask = mask;
- }
- if (client->noClientException != Success)
- return(client->noClientException);
- else
- return(result);
- }
- int
- ProcChangeWindowAttributes(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xChangeWindowAttributesReq);
- register int result;
- int len;
- REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
- SecurityWriteAccess);
- if (!pWin)
- return(BadWindow);
- len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
- if (len != Ones(stuff->valueMask))
- return BadLength;
- result = ChangeWindowAttributes(pWin,
- stuff->valueMask,
- (XID *) &stuff[1],
- client);
- if (client->noClientException != Success)
- return(client->noClientException);
- else
- return(result);
- }
- int
- ProcGetWindowAttributes(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xResourceReq);
- xGetWindowAttributesReply wa;
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- GetWindowAttributes(pWin, client, &wa);
- WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa);
- return(client->noClientException);
- }
- int
- ProcDestroyWindow(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
- SecurityDestroyAccess);
- if (!pWin)
- return(BadWindow);
- if (pWin->parent)
- FreeResource(stuff->id, RT_NONE);
- return(client->noClientException);
- }
- int
- ProcDestroySubwindows(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
- SecurityDestroyAccess);
- if (!pWin)
- return(BadWindow);
- DestroySubwindows(pWin, client);
- return(client->noClientException);
- }
- int
- ProcChangeSaveSet(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xChangeSaveSetReq);
- register int result;
-
- REQUEST_SIZE_MATCH(xChangeSaveSetReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)))
- return BadMatch;
- if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete))
- {
- result = AlterSaveSetForClient(client, pWin, stuff->mode);
- if (client->noClientException != Success)
- return(client->noClientException);
- else
- return(result);
- }
- else
- {
- client->errorValue = stuff->mode;
- return( BadValue );
- }
- }
- int
- ProcReparentWindow(client)
- register ClientPtr client;
- {
- register WindowPtr pWin, pParent;
- REQUEST(xReparentWindowReq);
- register int result;
- REQUEST_SIZE_MATCH(xReparentWindowReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
- SecurityWriteAccess);
- if (!pWin)
- return(BadWindow);
- if (!nxagentWMPassed)
- {
- nxagentRemoveSplashWindow(pWin);
- }
- pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
- SecurityWriteAccess);
- if (!pParent)
- return(BadWindow);
- if (SAME_SCREENS(pWin->drawable, pParent->drawable))
- {
- if ((pWin->backgroundState == ParentRelative) &&
- (pParent->drawable.depth != pWin->drawable.depth))
- return BadMatch;
- if ((pWin->drawable.class != InputOnly) &&
- (pParent->drawable.class == InputOnly))
- return BadMatch;
- result = ReparentWindow(pWin, pParent,
- (short)stuff->x, (short)stuff->y, client);
- if (client->noClientException != Success)
- return(client->noClientException);
- else
- return(result);
- }
- else
- return (BadMatch);
- }
- int
- ProcMapWindow(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- MapWindow(pWin, client);
- /* update cache to say it is mapped */
- return(client->noClientException);
- }
- int
- ProcMapSubwindows(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- MapSubwindows(pWin, client);
- /* update cache to say it is mapped */
- return(client->noClientException);
- }
- int
- ProcUnmapWindow(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- UnmapWindow(pWin, FALSE);
- /* update cache to say it is mapped */
- return(client->noClientException);
- }
- int
- ProcUnmapSubwindows(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- UnmapSubwindows(pWin);
- return(client->noClientException);
- }
- int
- ProcConfigureWindow(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xConfigureWindowReq);
- register int result;
- int len;
- REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
- pWin = (WindowPtr)SecurityLookupWindow( stuff->window, client,
- SecurityWriteAccess);
- if (!pWin)
- return(BadWindow);
- len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
- if (Ones((Mask)stuff->mask) != len)
- return BadLength;
- result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1],
- client);
- if (client->noClientException != Success)
- return(client->noClientException);
- else
- return(result);
- }
- int
- ProcCirculateWindow(client)
- register ClientPtr client;
- {
- register WindowPtr pWin;
- REQUEST(xCirculateWindowReq);
- REQUEST_SIZE_MATCH(xCirculateWindowReq);
- if ((stuff->direction != RaiseLowest) &&
- (stuff->direction != LowerHighest))
- {
- client->errorValue = stuff->direction;
- return BadValue;
- }
- pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
- SecurityWriteAccess);
- if (!pWin)
- return(BadWindow);
- CirculateWindow(pWin, (int)stuff->direction, client);
- return(client->noClientException);
- }
- int
- GetGeometry(client, rep)
- register ClientPtr client;
- xGetGeometryReply *rep;
- {
- register DrawablePtr pDraw;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->id, client, SecurityReadAccess);
- rep->type = X_Reply;
- rep->length = 0;
- rep->sequenceNumber = client->sequence;
- rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id;
- rep->depth = pDraw->depth;
- rep->width = pDraw->width;
- rep->height = pDraw->height;
- /* XXX - Because the pixmap-implementation of the multibuffer extension
- * may have the buffer-id's drawable resource value be a pointer
- * to the buffer's window instead of the buffer itself
- * (this happens if the buffer is the displayed buffer),
- * we also have to check that the id matches before we can
- * truly say that it is a DRAWABLE_WINDOW.
- */
- if ((pDraw->type == UNDRAWABLE_WINDOW) ||
- ((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id)))
- {
- register WindowPtr pWin = (WindowPtr)pDraw;
- rep->x = pWin->origin.x - wBorderWidth (pWin);
- rep->y = pWin->origin.y - wBorderWidth (pWin);
- rep->borderWidth = pWin->borderWidth;
- }
- else /* DRAWABLE_PIXMAP or DRAWABLE_BUFFER */
- {
- rep->x = rep->y = rep->borderWidth = 0;
- }
- return Success;
- }
- int
- ProcGetGeometry(client)
- register ClientPtr client;
- {
- xGetGeometryReply rep;
- int status;
- if ((status = GetGeometry(client, &rep)) != Success)
- return status;
- WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep);
- return(client->noClientException);
- }
- int
- ProcQueryTree(client)
- register ClientPtr client;
- {
- xQueryTreeReply reply;
- int numChildren = 0;
- register WindowPtr pChild, pWin, pHead;
- Window *childIDs = (Window *)NULL;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- reply.type = X_Reply;
- reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id;
- reply.sequenceNumber = client->sequence;
- if (pWin->parent)
- reply.parent = pWin->parent->drawable.id;
- else
- reply.parent = (Window)None;
- pHead = RealChildHead(pWin);
- for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
- {
- if (!IsViewportFrame(pChild))
- {
- numChildren++;
- }
- }
- if (numChildren)
- {
- int curChild = 0;
- childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window));
- if (!childIDs)
- return BadAlloc;
- for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
- {
- if (!IsViewportFrame(pChild))
- {
- childIDs[curChild++] = pChild->drawable.id;
- }
- }
- }
-
- reply.nChildren = numChildren;
- reply.length = (numChildren * sizeof(Window)) >> 2;
-
- WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply);
- if (numChildren)
- {
- client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
- WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs);
- DEALLOCATE_LOCAL(childIDs);
- }
- return(client->noClientException);
- }
- int
- ProcInternAtom(client)
- register ClientPtr client;
- {
- Atom atom;
- char *tchar;
- REQUEST(xInternAtomReq);
- REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes);
- if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse))
- {
- client->errorValue = stuff->onlyIfExists;
- return(BadValue);
- }
- tchar = (char *) &stuff[1];
- atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists);
- if (atom != BAD_RESOURCE)
- {
- xInternAtomReply reply;
- reply.type = X_Reply;
- reply.length = 0;
- reply.sequenceNumber = client->sequence;
- reply.atom = atom;
- WriteReplyToClient(client, sizeof(xInternAtomReply), &reply);
- return(client->noClientException);
- }
- else
- return (BadAlloc);
- }
- int
- ProcGetAtomName(client)
- register ClientPtr client;
- {
- char *str;
- xGetAtomNameReply reply;
- int len;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- if ( (str = NameForAtom(stuff->id)) )
- {
- len = strlen(str);
- reply.type = X_Reply;
- reply.length = (len + 3) >> 2;
- reply.sequenceNumber = client->sequence;
- reply.nameLength = len;
- WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
- (void)WriteToClient(client, len, str);
- return(client->noClientException);
- }
- else
- {
- client->errorValue = stuff->id;
- return (BadAtom);
- }
- }
- #ifdef K5AUTH
- extern int k5_bad();
- #endif
- int
- ProcSetSelectionOwner(client)
- register ClientPtr client;
- {
- WindowPtr pWin;
- TimeStamp time;
- REQUEST(xSetSelectionOwnerReq);
- REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
- UpdateCurrentTime();
- time = ClientTimeToServerTime(stuff->time);
- /* If the client's time stamp is in the future relative to the server's
- time stamp, do not set the selection, just return success. */
- if (CompareTimeStamps(time, currentTime) == LATER)
- return Success;
- if (stuff->window != None)
- {
- pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- }
- else
- pWin = (WindowPtr)None;
- if (ValidAtom(stuff->selection))
- {
- int i = 0;
- /*
- * First, see if the selection is already set...
- */
- while ((i < NumCurrentSelections) &&
- CurrentSelections[i].selection != stuff->selection)
- i++;
- if (i < NumCurrentSelections)
- {
- xEvent event;
- /* If the timestamp in client's request is in the past relative
- to the time stamp indicating the last time the owner of the
- selection was set, do not set the selection, just return
- success. */
- if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged)
- == EARLIER)
- return Success;
- if (CurrentSelections[i].client &&
- (!pWin || (CurrentSelections[i].client != client)))
- {
- event.u.u.type = SelectionClear;
- event.u.selectionClear.time = time.milliseconds;
- event.u.selectionClear.window = CurrentSelections[i].window;
- event.u.selectionClear.atom = CurrentSelections[i].selection;
- (void) TryClientEvents (CurrentSelections[i].client, &event, 1,
- NoEventMask, NoEventMask /* CantBeFiltered */,
- NullGrab);
- }
- }
- else
- {
- /*
- * It doesn't exist, so add it...
- */
- Selection *newsels;
- if (i == 0)
- newsels = (Selection *)xalloc(sizeof(Selection));
- else
- newsels = (Selection *)xrealloc(CurrentSelections,
- (NumCurrentSelections + 1) * sizeof(Selection));
- if (!newsels)
- return BadAlloc;
- NumCurrentSelections++;
- CurrentSelections = newsels;
- CurrentSelections[i].selection = stuff->selection;
- }
- CurrentSelections[i].lastTimeChanged = time;
- CurrentSelections[i].window = stuff->window;
- CurrentSelections[i].pWin = pWin;
- CurrentSelections[i].client = (pWin ? client : NullClient);
- #ifdef NXAGENT_CLIPBOARD
- if ((CurrentSelections[i].pWin != NULL) &&
- (nxagentOption(Clipboard) != ClipboardNone) &&
- ((CurrentSelections[i].selection == XA_PRIMARY) ||
- (CurrentSelections[i].selection == MakeAtom("CLIPBOARD", 9, 0))))
- {
- nxagentSetSelectionOwner(&CurrentSelections[i]);
- }
- #endif
- return (client->noClientException);
- }
- else
- {
- client->errorValue = stuff->selection;
- return (BadAtom);
- }
- }
- int
- ProcGetSelectionOwner(client)
- register ClientPtr client;
- {
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- if (ValidAtom(stuff->id))
- {
- int i;
- xGetSelectionOwnerReply reply;
- i = 0;
- while ((i < NumCurrentSelections) &&
- CurrentSelections[i].selection != stuff->id) i++;
- reply.type = X_Reply;
- reply.length = 0;
- reply.sequenceNumber = client->sequence;
- if (i < NumCurrentSelections)
- reply.owner = CurrentSelections[i].window;
- else
- reply.owner = None;
- WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
- return(client->noClientException);
- }
- else
- {
- client->errorValue = stuff->id;
- return (BadAtom);
- }
- }
- int
- ProcConvertSelection(client)
- register ClientPtr client;
- {
- Bool paramsOkay;
- xEvent event;
- WindowPtr pWin;
- REQUEST(xConvertSelectionReq);
- REQUEST_SIZE_MATCH(xConvertSelectionReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->requestor, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- #ifdef NXAGENT_CLIPBOARD
- if (((stuff->selection == XA_PRIMARY) ||
- (stuff->selection == MakeAtom("CLIPBOARD", 9, 0))) &&
- nxagentOption(Clipboard) != ClipboardNone)
- {
- int i = 0;
- while ((i < NumCurrentSelections) &&
- CurrentSelections[i].selection != stuff->selection) i++;
- if ((i < NumCurrentSelections) && (CurrentSelections[i].window != None))
- {
- if (nxagentConvertSelection(client, pWin, stuff->selection, stuff->requestor,
- stuff->property, stuff->target, stuff->time))
- {
- return (client->noClientException);
- }
- }
- }
- #endif
- paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target));
- if (stuff->property != None)
- paramsOkay &= ValidAtom(stuff->property);
- if (paramsOkay)
- {
- int i;
- i = 0;
- while ((i < NumCurrentSelections) &&
- CurrentSelections[i].selection != stuff->selection) i++;
- if ((i < NumCurrentSelections) &&
- (CurrentSelections[i].window != None) && (CurrentSelections[i].client != NullClient)
- #ifdef XCSECURITY
- && (!client->CheckAccess ||
- (* client->CheckAccess)(client, CurrentSelections[i].window,
- RT_WINDOW, SecurityReadAccess,
- CurrentSelections[i].pWin))
- #endif
- )
- {
- event.u.u.type = SelectionRequest;
- event.u.selectionRequest.time = stuff->time;
- event.u.selectionRequest.owner =
- CurrentSelections[i].window;
- event.u.selectionRequest.requestor = stuff->requestor;
- event.u.selectionRequest.selection = stuff->selection;
- event.u.selectionRequest.target = stuff->target;
- event.u.selectionRequest.property = stuff->property;
- if (TryClientEvents(
- CurrentSelections[i].client, &event, 1, NoEventMask,
- NoEventMask /* CantBeFiltered */, NullGrab))
- return (client->noClientException);
- }
- event.u.u.type = SelectionNotify;
- event.u.selectionNotify.time = stuff->time;
- event.u.selectionNotify.requestor = stuff->requestor;
- event.u.selectionNotify.selection = stuff->selection;
- event.u.selectionNotify.target = stuff->target;
- event.u.selectionNotify.property = None;
- (void) TryClientEvents(client, &event, 1, NoEventMask,
- NoEventMask /* CantBeFiltered */, NullGrab);
- return (client->noClientException);
- }
- else
- {
- client->errorValue = stuff->property;
- return (BadAtom);
- }
- }
- int
- ProcGrabServer(client)
- register ClientPtr client;
- {
- REQUEST_SIZE_MATCH(xReq);
- if (grabState != GrabNone && client != grabClient)
- {
- ResetCurrentRequest(client);
- client->sequence--;
- BITSET(grabWaiters, client->index);
- IgnoreClient(client);
- return(client->noClientException);
- }
- OnlyListenToOneClient(client);
- grabState = GrabKickout;
- grabClient = client;
- if (ServerGrabCallback)
- {
- ServerGrabInfoRec grabinfo;
- grabinfo.client = client;
- grabinfo.grabstate = SERVER_GRABBED;
- CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
- }
- return(client->noClientException);
- }
- static void
- #if NeedFunctionPrototypes
- UngrabServer(ClientPtr client)
- #else
- UngrabServer(client)
- ClientPtr client;
- #endif
- {
- int i;
- grabState = GrabNone;
- ListenToAllClients();
- for (i = mskcnt; --i >= 0 && !grabWaiters[i]; )
- ;
- if (i >= 0)
- {
- i <<= 5;
- while (!GETBIT(grabWaiters, i))
- i++;
- BITCLEAR(grabWaiters, i);
- AttendClient(clients[i]);
- }
- if (ServerGrabCallback)
- {
- ServerGrabInfoRec grabinfo;
- grabinfo.client = client;
- grabinfo.grabstate = SERVER_UNGRABBED;
- CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
- }
- }
- int
- ProcUngrabServer(client)
- register ClientPtr client;
- {
- REQUEST_SIZE_MATCH(xReq);
- UngrabServer(client);
- return(client->noClientException);
- }
- int
- ProcTranslateCoords(client)
- register ClientPtr client;
- {
- REQUEST(xTranslateCoordsReq);
- register WindowPtr pWin, pDst;
- xTranslateCoordsReply rep;
- REQUEST_SIZE_MATCH(xTranslateCoordsReq);
- pWin = (WindowPtr)SecurityLookupWindow(stuff->srcWid, client,
- SecurityReadAccess);
- if (!pWin)
- return(BadWindow);
- pDst = (WindowPtr)SecurityLookupWindow(stuff->dstWid, client,
- SecurityReadAccess);
- if (!pDst)
- return(BadWindow);
- rep.type = X_Reply;
- rep.length = 0;
- rep.sequenceNumber = client->sequence;
- if (!SAME_SCREENS(pWin->drawable, pDst->drawable))
- {
- rep.sameScreen = xFalse;
- rep.child = None;
- rep.dstX = rep.dstY = 0;
- }
- else
- {
- INT16 x, y;
- rep.sameScreen = xTrue;
- rep.child = None;
- /* computing absolute coordinates -- adjust to destination later */
- x = pWin->drawable.x + stuff->srcX;
- y = pWin->drawable.y + stuff->srcY;
- pWin = pDst->firstChild;
- while (pWin)
- {
- #ifdef SHAPE
- BoxRec box;
- #endif
- if ((pWin->mapped) &&
- (x >= pWin->drawable.x - wBorderWidth (pWin)) &&
- (x < pWin->drawable.x + (int)pWin->drawable.width +
- wBorderWidth (pWin)) &&
- (y >= pWin->drawable.y - wBorderWidth (pWin)) &&
- (y < pWin->drawable.y + (int)pWin->drawable.height +
- wBorderWidth (pWin))
- #ifdef SHAPE
- /* When a window is shaped, a further check
- * is made to see if the point is inside
- * borderSize
- */
- && (!wBoundingShape(pWin) ||
- POINT_IN_REGION(pWin->drawable.pScreen,
- &pWin->borderSize, x, y, &box))
- #endif
- )
- {
- rep.child = pWin->drawable.id;
- pWin = (WindowPtr) NULL;
- }
- else
- pWin = pWin->nextSib;
- }
- /* adjust to destination coordinates */
- rep.dstX = x - pDst->drawable.x;
- rep.dstY = y - pDst->drawable.y;
- }
- WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep);
- return(client->noClientException);
- }
- int
- ProcOpenFont(client)
- register ClientPtr client;
- {
- int err;
- char fontReq[256];
- REQUEST(xOpenFontReq);
- REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes);
- client->errorValue = stuff->fid;
- LEGAL_NEW_RESOURCE(stuff->fid, client);
- memcpy(fontReq,(char *)&stuff[1],(stuff->nbytes<256)?stuff->nbytes:255);
- fontReq[stuff->nbytes]=0;
- if (strchr(fontReq,'*') || strchr(fontReq,'?'))
- {
- extern int nxOpenFont(ClientPtr, XID, Mask, unsigned, char*);
- #ifdef NXAGENT_FONTMATCH_DEBUG
- fprintf(stderr, "Dispatch: ProcOpenFont try to find a common font with font pattern=%s\n",fontReq);
- #endif
- nxagentListRemoteFonts(fontReq, nxagentMaxFontNames);
- err = nxOpenFont(client, stuff->fid, (Mask) 0,
- stuff->nbytes, (char *)&stuff[1]);
- }
- else
- err = OpenFont(client, stuff->fid, (Mask) 0,
- stuff->nbytes, (char *)&stuff[1]);
- if (err == Success)
- {
- return(client->noClientException);
- }
- else
- return err;
- }
- int
- ProcCloseFont(client)
- register ClientPtr client;
- {
- FontPtr pFont;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
- SecurityDestroyAccess);
- if (pFont != (FontPtr)NULL)
- {
- #ifdef NXAGENT_SERVER
- /*
- * When a client closes a font the resource
- * should not be lost if the reference counter
- * is not 0, otherwise the server will not be
- * able to find this font looping through the
- * resources.
- */
- if (pFont -> refcnt > 0)
- {
- if (nxagentFindClientResource(serverClient -> index, RT_NX_FONT, pFont) == 0)
- {
- #ifdef TEST
- fprintf(stderr, "ProcCloseFont: Switching resource for font at [%p].\n",
- (void *) pFont);
- #endif
- nxagentFontPriv(pFont) -> mirrorID = FakeClientID(serverClient -> index);
- AddResource(nxagentFontPriv(pFont) -> mirrorID, RT_NX_FONT, pFont);
- }
- #ifdef TEST
- else
- {
- fprintf(stderr, "ProcCloseFont: Found duplicated font at [%p], "
- "resource switching skipped.\n", (void *) pFont);
- }
- #endif
- }
- #endif
- FreeResource(stuff->id, RT_NONE);
- return(client->noClientException);
- }
- else
- {
- client->errorValue = stuff->id;
- return (BadFont);
- }
- }
- int
- ProcQueryFont(client)
- register ClientPtr client;
- {
- xQueryFontReply *reply;
- FontPtr pFont;
- register GC *pGC;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- client->errorValue = stuff->id; /* EITHER font or gc */
- pFont = NULL;
- pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
- SecurityReadAccess);
- if (!pFont)
- {
- /* can't use VERIFY_GC because it might return BadGC */
- pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC,
- SecurityReadAccess);
- if (!pGC)
- {
- client->errorValue = stuff->id;
- return(BadFont); /* procotol spec says only error is BadFont */
- }
- pFont = pGC->font;
- }
- /* test
- {
- Atom name_atom, value_atom;
- int nprops;
- FontPropPtr props;
- int i;
- char *name;
- name_atom = MakeAtom("FONT", 4, True);
- value_atom = 0L;
- nprops = pFont->info.nprops;
- props = pFont->info.props;
- for (i = 0; i < nprops; i++)
- if (props[i].name == name_atom) {
- value_atom = props[i].value;
- break;
- }
- if (!value_atom) return (BadFont);
- name = (char *)NameForAtom(value_atom);
- fprintf(stderr, "QueryFont: font name [%s]\n",name);
- }
- end test */
- {
- xCharInfo *pmax = FONTINKMAX(pFont);
- xCharInfo *pmin = FONTINKMIN(pFont);
- int nprotoxcistructs;
- int rlength;
- nprotoxcistructs = (
- pmax->rightSideBearing == pmin->rightSideBearing &&
- pmax->leftSideBearing == pmin->leftSideBearing &&
- pmax->descent == pmin->descent &&
- pmax->ascent == pmin->ascent &&
- pmax->characterWidth == pmin->characterWidth) ?
- 0 : N2dChars(pFont);
- rlength = sizeof(xQueryFontReply) +
- FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp) +
- …
Large files files are truncated, but you can click here to view the full file