📄 dispatch.c
字号:
/* $XConsortium: dispatch.c /main/195 1996/12/15 21:24:40 rws $ *//* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.7 1996/12/23 06:29:38 dawes Exp $ *//************************************************************Copyright (c) 1987, 1989 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. All Rights ReservedPermission 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 thatboth that copyright notice and this permission notice appear in supporting documentation, and that the name of Digital not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY 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 THISSOFTWARE.********************************************************/#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 "dispatch.h"#include "swaprep.h"#include "swapreq.h"#include "dixevents.h"#ifdef XCSECURITY#define _SECURITY_SERVER#include "extensions/security.h"#endif#ifdef XAPPGROUP#include "extensions/Xagsrv.h"#endif#define mskcnt ((MAXCLIENTS + 31) / 32)#define BITMASK(i) (1 << ((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 WindowPtr *WindowTable;extern xConnSetupPrefix connSetupPrefix;extern char *ConnectionInfo;Selection *CurrentSelections;int NumCurrentSelections;extern CARD32 defaultScreenSaverTime;extern CARD32 defaultScreenSaverInterval;extern int defaultScreenSaverBlanking;extern int defaultScreenSaverAllowExposures;static ClientPtr grabClient;#define GrabNone 0#define GrabActive 1#define GrabKickout 2static int grabState = GrabNone;static long grabWaiters[mskcnt];CallbackListPtr ServerGrabCallback = NULL;HWEventQueuePtr checkForInput[2];extern int connBlockScreenStart;#ifdef XKBextern Bool noXkbExtension;#endifstatic void KillAllClients(#if NeedFunctionPrototypes void#endif);static void DeleteClientFromAnySelections(#if NeedFunctionPrototypes ClientPtr /*client*/#endif);#ifdef LBXextern unsigned long StandardRequestLength();#endifstatic 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))voidSetInputCheck(c0, c1) HWEventQueuePtr c0, c1;{ checkForInput[0] = c0; checkForInput[1] = c1;}voidUpdateCurrentTime(){ 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 */voidUpdateCurrentTimeIf(){ TimeStamp systime; systime.months = currentTime.months; systime.milliseconds = GetTimeInMillis(); if (systime.milliseconds < currentTime.milliseconds) systime.months++; if (*checkForInput[0] == *checkForInput[1]) currentTime = systime;}voidInitSelections(){ if (CurrentSelections) xfree(CurrentSelections); CurrentSelections = (Selection *)NULL; NumCurrentSelections = 0;}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; } } }}#define MAJOROP ((xReq *)client->requestBuffer)->reqTypevoidDispatch(){ register int *clientReady; /* array of request ready clients */ register int result; register ClientPtr client; register int nready; register HWEventQueuePtr* icheck = checkForInput; nextFreeClientID = 1; InitSelections(); nClients = 0; clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients); if (!clientReady) return; while (!dispatchException) { if (*icheck[0] != *icheck[1]) { ProcessInputEvents(); FlushIfCriticalOutputPending(); } nready = WaitForSomething(clientReady); /***************** * 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; while (!isItTimeToYield) { if (*icheck[0] != *icheck[1]) { ProcessInputEvents(); FlushIfCriticalOutputPending(); } /* now, finally, deal with client requests */ result = ReadRequestFromClient(client); if (result <= 0) { if (result < 0) CloseDownClient(client); break; } 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 result = (* client->requestVector[MAJOROP])(client); if (result != Success) { if (client->noClientException != Success) CloseDownClient(client); else SendErrorToClient(client, MAJOROP, MinorOpcodeOfRequest(client), client->errorValue, result); break; } } FlushAllOutput(); requestingClient = NULL; } dispatchException &= ~DE_PRIORITYCHANGE; } KillAllClients(); DEALLOCATE_LOCAL(clientReady); dispatchException &= ~DE_RESET;}#undef MAJOROP/*ARGSUSED*/intProcBadRequest(client) ClientPtr client;{ return (BadRequest);}intProcCreateWindow(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);}intProcChangeWindowAttributes(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);}intProcGetWindowAttributes(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);}intProcDestroyWindow(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);}intProcDestroySubwindows(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);}intProcChangeSaveSet(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 ); }}intProcReparentWindow(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); pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -