diff options
author | marha <marha@users.sourceforge.net> | 2012-03-23 10:05:55 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-03-23 10:05:55 +0100 |
commit | 0f834b91a4768673833ab4917e87d86c237bb1a6 (patch) | |
tree | 363489504ed4b2d360259b8de4c9e392918e5d02 /xorg-server/dix | |
parent | fc72edebf875378459368c5383d9023730cbca54 (diff) | |
download | vcxsrv-0f834b91a4768673833ab4917e87d86c237bb1a6.tar.gz vcxsrv-0f834b91a4768673833ab4917e87d86c237bb1a6.tar.bz2 vcxsrv-0f834b91a4768673833ab4917e87d86c237bb1a6.zip |
libX11 xserver fontconfig mesa pixman xkbcomp xkeyboard-config git update
23 Mar 2012
Diffstat (limited to 'xorg-server/dix')
35 files changed, 16690 insertions, 18176 deletions
diff --git a/xorg-server/dix/Xserver-dtrace.h.in b/xorg-server/dix/Xserver-dtrace.h.in index dc9419b0d..60ebbcdd9 100644 --- a/xorg-server/dix/Xserver-dtrace.h.in +++ b/xorg-server/dix/Xserver-dtrace.h.in @@ -1,94 +1,99 @@ -/* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS 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.
- */
-
-/*
- * Generated by dtrace(1M), and then modified for backwards compatibility
- * with older versions of dtrace. Used if dtrace -h fails.
- * (Since _ENABLED support was added after dtrace -h, this assumes if
- * dtrace -h fails, _ENABLED will too.)
- */
-
-#ifndef _XSERVER_DTRACE_H
-#define _XSERVER_DTRACE_H
-
-#include <unistd.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if _DTRACE_VERSION
-
-#define XSERVER_CLIENT_AUTH(arg0, arg1, arg2, arg3) \
- __dtrace_Xserver___client__auth(arg0, arg1, arg2, arg3)
-#define XSERVER_CLIENT_CONNECT(arg0, arg1) \
- __dtrace_Xserver___client__connect(arg0, arg1)
-#define XSERVER_CLIENT_DISCONNECT(arg0) \
- __dtrace_Xserver___client__disconnect(arg0)
-#define XSERVER_REQUEST_DONE(arg0, arg1, arg2, arg3, arg4) \
- __dtrace_Xserver___request__done(arg0, arg1, arg2, arg3, arg4)
-#define XSERVER_REQUEST_START(arg0, arg1, arg2, arg3, arg4) \
- __dtrace_Xserver___request__start(arg0, arg1, arg2, arg3, arg4)
-#define XSERVER_RESOURCE_ALLOC(arg0, arg1, arg2, arg3) \
- __dtrace_Xserver___resource__alloc(arg0, arg1, arg2, arg3)
-#define XSERVER_RESOURCE_FREE(arg0, arg1, arg2, arg3) \
- __dtrace_Xserver___resource__free(arg0, arg1, arg2, arg3)
-#define XSERVER_SEND_EVENT(arg0, arg1, arg2) \
- __dtrace_Xserver___send__event(arg0, arg1, arg2)
-
-
-extern void __dtrace_Xserver___client__auth(int, string, pid_t, zoneid_t);
-extern void __dtrace_Xserver___client__connect(int, int);
-extern void __dtrace_Xserver___client__disconnect(int);
-extern void __dtrace_Xserver___request__done(string, uint8_t, uint32_t, int, int);
-extern void __dtrace_Xserver___request__start(string, uint8_t, uint16_t, int, void *);
-extern void __dtrace_Xserver___resource__alloc(uint32_t, uint32_t, void *, string);
-extern void __dtrace_Xserver___resource__free(uint32_t, uint32_t, void *, string);
-extern void __dtrace_Xserver___send__event(int, uint8_t, void *);
-
-#else
-
-#define XSERVER_CLIENT_AUTH(arg0, arg1, arg2, arg3)
-#define XSERVER_CLIENT_CONNECT(arg0, arg1)
-#define XSERVER_CLIENT_DISCONNECT(arg0)
-#define XSERVER_REQUEST_DONE(arg0, arg1, arg2, arg3, arg4)
-#define XSERVER_REQUEST_START(arg0, arg1, arg2, arg3, arg4)
-#define XSERVER_RESOURCE_ALLOC(arg0, arg1, arg2, arg3)
-#define XSERVER_RESOURCE_FREE(arg0, arg1, arg2, arg3)
-#define XSERVER_SEND_EVENT(arg0, arg1, arg2)
-
-#endif
-
-#define XSERVER_CLIENT_AUTH_ENABLED() (1)
-#define XSERVER_CLIENT_CONNECT_ENABLED() (1)
-#define XSERVER_CLIENT_DISCONNECT_ENABLED() (1)
-#define XSERVER_REQUEST_DONE_ENABLED() (1)
-#define XSERVER_REQUEST_START_ENABLED() (1)
-#define XSERVER_RESOURCE_ALLOC_ENABLED() (1)
-#define XSERVER_RESOURCE_FREE_ENABLED() (1)
-#define XSERVER_SEND_EVENT_ENABLED() (1)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _XSERVER_DTRACE_H */
+/* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +/* + * Generated by dtrace(1M), and then modified for backwards compatibility + * with older versions of dtrace. Used if dtrace -h fails. + * (Since _ENABLED support was added after dtrace -h, this assumes if + * dtrace -h fails, _ENABLED will too.) + */ + +#ifndef _XSERVER_DTRACE_H +#define _XSERVER_DTRACE_H + +#include <unistd.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#if _DTRACE_VERSION + +#define XSERVER_CLIENT_AUTH(arg0, arg1, arg2, arg3) \ + __dtrace_Xserver___client__auth(arg0, arg1, arg2, arg3) +#define XSERVER_CLIENT_CONNECT(arg0, arg1) \ + __dtrace_Xserver___client__connect(arg0, arg1) +#define XSERVER_CLIENT_DISCONNECT(arg0) \ + __dtrace_Xserver___client__disconnect(arg0) +#define XSERVER_REQUEST_DONE(arg0, arg1, arg2, arg3, arg4) \ + __dtrace_Xserver___request__done(arg0, arg1, arg2, arg3, arg4) +#define XSERVER_REQUEST_START(arg0, arg1, arg2, arg3, arg4) \ + __dtrace_Xserver___request__start(arg0, arg1, arg2, arg3, arg4) +#define XSERVER_RESOURCE_ALLOC(arg0, arg1, arg2, arg3) \ + __dtrace_Xserver___resource__alloc(arg0, arg1, arg2, arg3) +#define XSERVER_RESOURCE_FREE(arg0, arg1, arg2, arg3) \ + __dtrace_Xserver___resource__free(arg0, arg1, arg2, arg3) +#define XSERVER_SEND_EVENT(arg0, arg1, arg2) \ + __dtrace_Xserver___send__event(arg0, arg1, arg2) +#define XSERVER_INPUT_EVENT(arg0, arg1, arg2, arg3, arg4, arg5, arg6) \ + __dtrace_Xserver___input__event(arg0, arg1, arg2, arg3, arg4, arg5, arg6) + +extern void __dtrace_Xserver___client__auth(int, string, pid_t, zoneid_t); +extern void __dtrace_Xserver___client__connect(int, int); +extern void __dtrace_Xserver___client__disconnect(int); +extern void __dtrace_Xserver___request__done(string, uint8_t, uint32_t, int, int); +extern void __dtrace_Xserver___request__start(string, uint8_t, uint16_t, int, void *); +extern void __dtrace_Xserver___resource__alloc(uint32_t, uint32_t, void *, string); +extern void __dtrace_Xserver___resource__free(uint32_t, uint32_t, void *, string); +extern void __dtrace_Xserver___send__event(int, uint8_t, void *); +extern void __dtrace_Xserver___input__event(int, uint16_t, uint32_t, uint32_t, int8_t, uint8_t *, double *); + + +#else + +#define XSERVER_CLIENT_AUTH(arg0, arg1, arg2, arg3) +#define XSERVER_CLIENT_CONNECT(arg0, arg1) +#define XSERVER_CLIENT_DISCONNECT(arg0) +#define XSERVER_REQUEST_DONE(arg0, arg1, arg2, arg3, arg4) +#define XSERVER_REQUEST_START(arg0, arg1, arg2, arg3, arg4) +#define XSERVER_RESOURCE_ALLOC(arg0, arg1, arg2, arg3) +#define XSERVER_RESOURCE_FREE(arg0, arg1, arg2, arg3) +#define XSERVER_SEND_EVENT(arg0, arg1, arg2) +#define XSERVER_INPUT_EVENT(arg0, arg1, arg2, arg3, arg4, arg5, arg6) + +#endif + +#define XSERVER_CLIENT_AUTH_ENABLED() (1) +#define XSERVER_CLIENT_CONNECT_ENABLED() (1) +#define XSERVER_CLIENT_DISCONNECT_ENABLED() (1) +#define XSERVER_REQUEST_DONE_ENABLED() (1) +#define XSERVER_REQUEST_START_ENABLED() (1) +#define XSERVER_RESOURCE_ALLOC_ENABLED() (1) +#define XSERVER_RESOURCE_FREE_ENABLED() (1) +#define XSERVER_SEND_EVENT_ENABLED() (1) +#define XSERVER_INPUT_EVENT_ENABLED() (1) + +#ifdef __cplusplus +} +#endif + +#endif /* _XSERVER_DTRACE_H */ diff --git a/xorg-server/dix/Xserver.d b/xorg-server/dix/Xserver.d index 6584ece52..248d48e24 100644 --- a/xorg-server/dix/Xserver.d +++ b/xorg-server/dix/Xserver.d @@ -1,58 +1,60 @@ -/* Copyright (c) 2005-2006, Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS 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.
- */
-
-/*
- * Xserver dtrace provider definition
- */
-#ifdef __APPLE__
-#define string char *
-#define pid_t uint32_t
-#define zoneid_t uint32_t
-#else
-#include <sys/types.h>
-#endif
-
-provider Xserver {
- /* reqType, data, length, client id, request buffer */
- probe request__start(string, uint8_t, uint16_t, int, void *);
- /* reqType, data, sequence, client id, result */
- probe request__done(string, uint8_t, uint32_t, int, int);
- /* client id, client fd */
- probe client__connect(int, int);
- /* client id, client address, client pid, client zone id */
- probe client__auth(int, string, pid_t, zoneid_t);
- /* client id */
- probe client__disconnect(int);
- /* resource id, resource type, value, resource type name */
- probe resource__alloc(uint32_t, uint32_t, void *, string);
- /* resource id, resource type, value, resource type name */
- probe resource__free(uint32_t, uint32_t, void *, string);
- /* client id, event type, event* */
- probe send__event(int, uint8_t, void *);
-};
-
-#pragma D attributes Unstable/Unstable/Common provider Xserver provider
-#pragma D attributes Private/Private/Unknown provider Xserver module
-#pragma D attributes Private/Private/Unknown provider Xserver function
-#pragma D attributes Unstable/Unstable/Common provider Xserver name
-#pragma D attributes Unstable/Unstable/Common provider Xserver args
-
+/* Copyright (c) 2005-2006, Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +/* + * Xserver dtrace provider definition + */ +#ifdef __APPLE__ +#define string char * +#define pid_t uint32_t +#define zoneid_t uint32_t +#else +#include <sys/types.h> +#endif + +provider Xserver { + /* reqType, data, length, client id, request buffer */ + probe request__start(string, uint8_t, uint16_t, int, void *); + /* reqType, data, sequence, client id, result */ + probe request__done(string, uint8_t, uint32_t, int, int); + /* client id, client fd */ + probe client__connect(int, int); + /* client id, client address, client pid, client zone id */ + probe client__auth(int, string, pid_t, zoneid_t); + /* client id */ + probe client__disconnect(int); + /* resource id, resource type, value, resource type name */ + probe resource__alloc(uint32_t, uint32_t, void *, string); + /* resource id, resource type, value, resource type name */ + probe resource__free(uint32_t, uint32_t, void *, string); + /* client id, event type, event* */ + probe send__event(int, uint8_t, void *); + /* deviceid, type, button/keycode/touchid, flags, nvalues, mask, values */ + probe input__event(int, int, uint32_t, uint32_t, int8_t, uint8_t*, double*); +}; + +#pragma D attributes Unstable/Unstable/Common provider Xserver provider +#pragma D attributes Private/Private/Unknown provider Xserver module +#pragma D attributes Private/Private/Unknown provider Xserver function +#pragma D attributes Unstable/Unstable/Common provider Xserver name +#pragma D attributes Unstable/Unstable/Common provider Xserver args + diff --git a/xorg-server/dix/atom.c b/xorg-server/dix/atom.c index 83ff71a7d..6f85968cd 100644 --- a/xorg-server/dix/atom.c +++ b/xorg-server/dix/atom.c @@ -22,7 +22,6 @@ 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 @@ -45,7 +44,6 @@ SOFTWARE. ******************************************************************/ - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #endif @@ -61,10 +59,10 @@ SOFTWARE. #define InitialTableSize 100 typedef struct _Node { - struct _Node *left, *right; + struct _Node *left, *right; Atom a; unsigned int fingerPrint; - const char *string; + const char *string; } NodeRec, *NodePtr; static Atom lastAtom = None; @@ -77,77 +75,71 @@ void FreeAtom(NodePtr patom); Atom MakeAtom(const char *string, unsigned len, Bool makeit) { - NodePtr * np; + NodePtr *np; unsigned i; int comp; unsigned int fp = 0; np = &atomRoot; - for (i = 0; i < (len+1)/2; i++) - { - fp = fp * 27 + string[i]; - fp = fp * 27 + string[len - 1 - i]; + for (i = 0; i < (len + 1) / 2; i++) { + fp = fp * 27 + string[i]; + fp = fp * 27 + string[len - 1 - i]; } - while (*np != NULL) - { - if (fp < (*np)->fingerPrint) - np = &((*np)->left); - else if (fp > (*np)->fingerPrint) - np = &((*np)->right); - else - { /* now start testing the strings */ - comp = strncmp(string, (*np)->string, (int)len); - if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string)))) - np = &((*np)->left); - else if (comp > 0) - np = &((*np)->right); - else - return(*np)->a; - } + while (*np != NULL) { + if (fp < (*np)->fingerPrint) + np = &((*np)->left); + else if (fp > (*np)->fingerPrint) + np = &((*np)->right); + else { /* now start testing the strings */ + comp = strncmp(string, (*np)->string, (int) len); + if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string)))) + np = &((*np)->left); + else if (comp > 0) + np = &((*np)->right); + else + return (*np)->a; + } } - if (makeit) - { - NodePtr nd; - - nd = malloc(sizeof(NodeRec)); - if (!nd) - return BAD_RESOURCE; - if (lastAtom < XA_LAST_PREDEFINED) - { - nd->string = string; - } - else - { - nd->string = strndup(string, len); - if (!nd->string) { - free(nd); - return BAD_RESOURCE; - } - } - if ((lastAtom + 1) >= tableLength) { - NodePtr *table; - - table = realloc(nodeTable, tableLength * (2 * sizeof(NodePtr))); - if (!table) { - if (nd->string != string) { + if (makeit) { + NodePtr nd; + + nd = malloc(sizeof(NodeRec)); + if (!nd) + return BAD_RESOURCE; + if (lastAtom < XA_LAST_PREDEFINED) { + nd->string = string; + } + else { + nd->string = strndup(string, len); + if (!nd->string) { + free(nd); + return BAD_RESOURCE; + } + } + if ((lastAtom + 1) >= tableLength) { + NodePtr *table; + + table = realloc(nodeTable, tableLength * (2 * sizeof(NodePtr))); + if (!table) { + if (nd->string != string) { /* nd->string has been strdup'ed */ - free((char *)nd->string); + free((char *) nd->string); } - free(nd); - return BAD_RESOURCE; - } - tableLength <<= 1; - nodeTable = table; - } - *np = nd; - nd->left = nd->right = NULL; - nd->fingerPrint = fp; - nd->a = ++lastAtom; - nodeTable[lastAtom] = nd; - return nd->a; + free(nd); + return BAD_RESOURCE; + } + tableLength <<= 1; + nodeTable = table; + } + *np = nd; + nd->left = nd->right = NULL; + nd->fingerPrint = fp; + nd->a = ++lastAtom; + nodeTable[lastAtom] = nd; + return nd->a; } else - return None; + return None; } Bool @@ -160,8 +152,11 @@ const char * NameForAtom(Atom atom) { NodePtr node; - if (atom > lastAtom) return 0; - if ((node = nodeTable[atom]) == NULL) return 0; + + if (atom > lastAtom) + return 0; + if ((node = nodeTable[atom]) == NULL) + return 0; return node->string; } @@ -174,16 +169,16 @@ AtomError(void) void FreeAtom(NodePtr patom) { - if(patom->left) - FreeAtom(patom->left); - if(patom->right) - FreeAtom(patom->right); + if (patom->left) + FreeAtom(patom->left); + if (patom->right) + FreeAtom(patom->right); if (patom->a > XA_LAST_PREDEFINED) { /* * All strings above XA_LAST_PREDEFINED are strdup'ed, so it's safe to * cast here */ - free((char *)patom->string); + free((char *) patom->string); } free(patom); } @@ -192,7 +187,7 @@ void FreeAllAtoms(void) { if (atomRoot == NULL) - return; + return; FreeAtom(atomRoot); atomRoot = NULL; free(nodeTable); @@ -207,9 +202,9 @@ InitAtoms(void) tableLength = InitialTableSize; nodeTable = malloc(InitialTableSize * sizeof(NodePtr)); if (!nodeTable) - AtomError(); + AtomError(); nodeTable[None] = NULL; MakePredeclaredAtoms(); if (lastAtom != XA_LAST_PREDEFINED) - AtomError(); + AtomError(); } diff --git a/xorg-server/dix/colormap.c b/xorg-server/dix/colormap.c index 038457d3d..10306285e 100644 --- a/xorg-server/dix/colormap.c +++ b/xorg-server/dix/colormap.c @@ -22,7 +22,6 @@ 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 @@ -45,7 +44,6 @@ SOFTWARE. ******************************************************************/ - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #endif @@ -66,126 +64,110 @@ SOFTWARE. #include "privates.h" #include "xace.h" -static Pixel FindBestPixel( - EntryPtr /*pentFirst*/, - int /*size*/, - xrgb * /*prgb*/, - int /*channel*/ -); - -static int AllComp( - EntryPtr /*pent*/, - xrgb * /*prgb*/ -); - -static int RedComp( - EntryPtr /*pent*/, - xrgb * /*prgb*/ -); - -static int GreenComp( - EntryPtr /*pent*/, - xrgb * /*prgb*/ -); - -static int BlueComp( - EntryPtr /*pent*/, - xrgb * /*prgb*/ -); - -static void FreePixels( - ColormapPtr /*pmap*/, - int /*client*/ -); - -static void CopyFree( - int /*channel*/, - int /*client*/, - ColormapPtr /*pmapSrc*/, - ColormapPtr /*pmapDst*/ -); - -static void FreeCell( - ColormapPtr /*pmap*/, - Pixel /*i*/, - int /*channel*/ -); - -static void UpdateColors( - ColormapPtr /*pmap*/ -); - -static int AllocDirect( - int /*client*/, - ColormapPtr /*pmap*/, - int /*c*/, - int /*r*/, - int /*g*/, - int /*b*/, - Bool /*contig*/, - Pixel * /*pixels*/, - Pixel * /*prmask*/, - Pixel * /*pgmask*/, - Pixel * /*pbmask*/ -); - -static int AllocPseudo( - int /*client*/, - ColormapPtr /*pmap*/, - int /*c*/, - int /*r*/, - Bool /*contig*/, - Pixel * /*pixels*/, - Pixel * /*pmask*/, - Pixel ** /*pppixFirst*/ -); - -static Bool AllocCP( - ColormapPtr /*pmap*/, - EntryPtr /*pentFirst*/, - int /*count*/, - int /*planes*/, - Bool /*contig*/, - Pixel * /*pixels*/, - Pixel * /*pMask*/ -); - -static Bool AllocShared( - ColormapPtr /*pmap*/, - Pixel * /*ppix*/, - int /*c*/, - int /*r*/, - int /*g*/, - int /*b*/, - Pixel /*rmask*/, - Pixel /*gmask*/, - Pixel /*bmask*/, - Pixel * /*ppixFirst*/ -); - -static int FreeCo( - ColormapPtr /*pmap*/, - int /*client*/, - int /*color*/, - int /*npixIn*/, - Pixel * /*ppixIn*/, - Pixel /*mask*/ -); - -static int TellNoMap( - WindowPtr /*pwin*/, - Colormap * /*pmid*/ -); - -static void FindColorInRootCmap ( - ColormapPtr /* pmap */, - EntryPtr /* pentFirst */, - int /* size */, - xrgb* /* prgb */, - Pixel* /* pPixel */, - int /* channel */, - ColorCompareProcPtr /* comp */ -); +static Pixel FindBestPixel(EntryPtr /*pentFirst */ , + int /*size */ , + xrgb * /*prgb */ , + int /*channel */ + ); + +static int AllComp(EntryPtr /*pent */ , + xrgb * /*prgb */ + ); + +static int RedComp(EntryPtr /*pent */ , + xrgb * /*prgb */ + ); + +static int GreenComp(EntryPtr /*pent */ , + xrgb * /*prgb */ + ); + +static int BlueComp(EntryPtr /*pent */ , + xrgb * /*prgb */ + ); + +static void FreePixels(ColormapPtr /*pmap */ , + int /*client */ + ); + +static void CopyFree(int /*channel */ , + int /*client */ , + ColormapPtr /*pmapSrc */ , + ColormapPtr /*pmapDst */ + ); + +static void FreeCell(ColormapPtr /*pmap */ , + Pixel /*i */ , + int /*channel */ + ); + +static void UpdateColors(ColormapPtr /*pmap */ + ); + +static int AllocDirect(int /*client */ , + ColormapPtr /*pmap */ , + int /*c */ , + int /*r */ , + int /*g */ , + int /*b */ , + Bool /*contig */ , + Pixel * /*pixels */ , + Pixel * /*prmask */ , + Pixel * /*pgmask */ , + Pixel * /*pbmask */ + ); + +static int AllocPseudo(int /*client */ , + ColormapPtr /*pmap */ , + int /*c */ , + int /*r */ , + Bool /*contig */ , + Pixel * /*pixels */ , + Pixel * /*pmask */ , + Pixel ** /*pppixFirst */ + ); + +static Bool AllocCP(ColormapPtr /*pmap */ , + EntryPtr /*pentFirst */ , + int /*count */ , + int /*planes */ , + Bool /*contig */ , + Pixel * /*pixels */ , + Pixel * /*pMask */ + ); + +static Bool AllocShared(ColormapPtr /*pmap */ , + Pixel * /*ppix */ , + int /*c */ , + int /*r */ , + int /*g */ , + int /*b */ , + Pixel /*rmask */ , + Pixel /*gmask */ , + Pixel /*bmask */ , + Pixel * /*ppixFirst */ + ); + +static int FreeCo(ColormapPtr /*pmap */ , + int /*client */ , + int /*color */ , + int /*npixIn */ , + Pixel * /*ppixIn */ , + Pixel /*mask */ + ); + +static int TellNoMap(WindowPtr /*pwin */ , + Colormap * /*pmid */ + ); + +static void FindColorInRootCmap(ColormapPtr /* pmap */ , + EntryPtr /* pentFirst */ , + int /* size */ , + xrgb * /* prgb */ , + Pixel * /* pPixel */ , + int /* channel */ , + ColorCompareProcPtr /* comp */ + ); #define NUMRED(vis) ((vis->redMask >> vis->offsetRed) + 1) #define NUMGREEN(vis) ((vis->greenMask >> vis->offsetGreen) + 1) @@ -227,14 +209,13 @@ static void FindColorInRootCmap ( break; \ (bits) += (base); \ while((bits) & ~(mask)) \ - (bits) += ((bits) & ~(mask)); + (bits) += ((bits) & ~(mask)); /* ID of server as client */ #define SERVER_ID 0 -typedef struct _colorResource -{ - Colormap mid; - int client; +typedef struct _colorResource { + Colormap mid; + int client; } colorResource; /* Invariants: @@ -244,7 +225,6 @@ typedef struct _colorResource * fShared should only be set if refcnt == AllocPrivate, and only in red map */ - /** * Create and initialize the color map * @@ -252,165 +232,160 @@ typedef struct _colorResource * \param alloc 1 iff all entries are allocated writable */ int -CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, - ColormapPtr *ppcmap, int alloc, int client) +CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, + ColormapPtr *ppcmap, int alloc, int client) { - int class, size; + int class, size; unsigned long sizebytes; - ColormapPtr pmap; - EntryPtr pent; - int i; - Pixel *ppix, **pptr; + ColormapPtr pmap; + EntryPtr pent; + int i; + Pixel *ppix, **pptr; class = pVisual->class; - if(!(class & DynamicClass) && (alloc != AllocNone) && (client != SERVER_ID)) - return BadMatch; + if (!(class & DynamicClass) && (alloc != AllocNone) && + (client != SERVER_ID)) + return BadMatch; size = pVisual->ColormapEntries; sizebytes = (size * sizeof(Entry)) + - (MAXCLIENTS * sizeof(Pixel *)) + - (MAXCLIENTS * sizeof(int)); + (MAXCLIENTS * sizeof(Pixel *)) + (MAXCLIENTS * sizeof(int)); if ((class | DynamicClass) == DirectColor) - sizebytes *= 3; + sizebytes *= 3; sizebytes += sizeof(ColormapRec); if (mid == pScreen->defColormap) { - pmap = malloc(sizebytes); - if (!pmap) - return BadAlloc; - if (!dixAllocatePrivates(&pmap->devPrivates, PRIVATE_COLORMAP)) { - free (pmap); - return BadAlloc; - } - } else { - pmap = _dixAllocateObjectWithPrivates(sizebytes, sizebytes, - offsetof(ColormapRec, devPrivates), PRIVATE_COLORMAP); - if (!pmap) - return BadAlloc; - } - pmap->red = (EntryPtr)((char *)pmap + sizeof(ColormapRec)); + pmap = malloc(sizebytes); + if (!pmap) + return BadAlloc; + if (!dixAllocatePrivates(&pmap->devPrivates, PRIVATE_COLORMAP)) { + free(pmap); + return BadAlloc; + } + } + else { + pmap = _dixAllocateObjectWithPrivates(sizebytes, sizebytes, + offsetof(ColormapRec, + devPrivates), + PRIVATE_COLORMAP); + if (!pmap) + return BadAlloc; + } + pmap->red = (EntryPtr) ((char *) pmap + sizeof(ColormapRec)); sizebytes = size * sizeof(Entry); - pmap->clientPixelsRed = (Pixel **)((char *)pmap->red + sizebytes); - pmap->numPixelsRed = (int *)((char *)pmap->clientPixelsRed + - (MAXCLIENTS * sizeof(Pixel *))); + pmap->clientPixelsRed = (Pixel **) ((char *) pmap->red + sizebytes); + pmap->numPixelsRed = (int *) ((char *) pmap->clientPixelsRed + + (MAXCLIENTS * sizeof(Pixel *))); pmap->mid = mid; - pmap->flags = 0; /* start out with all flags clear */ - if(mid == pScreen->defColormap) - pmap->flags |= IsDefault; + pmap->flags = 0; /* start out with all flags clear */ + if (mid == pScreen->defColormap) + pmap->flags |= IsDefault; pmap->pScreen = pScreen; pmap->pVisual = pVisual; pmap->class = class; if ((class | DynamicClass) == DirectColor) - size = NUMRED(pVisual); + size = NUMRED(pVisual); pmap->freeRed = size; - memset((char *) pmap->red, 0, (int)sizebytes); + memset((char *) pmap->red, 0, (int) sizebytes); memset((char *) pmap->numPixelsRed, 0, MAXCLIENTS * sizeof(int)); - for (pptr = &pmap->clientPixelsRed[MAXCLIENTS]; --pptr >= pmap->clientPixelsRed; ) - *pptr = (Pixel *)NULL; - if (alloc == AllocAll) - { - if (class & DynamicClass) - pmap->flags |= AllAllocated; - for (pent = &pmap->red[size - 1]; pent >= pmap->red; pent--) - pent->refcnt = AllocPrivate; - pmap->freeRed = 0; - ppix = malloc(size * sizeof(Pixel)); - if (!ppix) - { - free(pmap); - return BadAlloc; - } - pmap->clientPixelsRed[client] = ppix; - for(i = 0; i < size; i++) - ppix[i] = i; - pmap->numPixelsRed[client] = size; - } - - if ((class | DynamicClass) == DirectColor) - { - pmap->freeGreen = NUMGREEN(pVisual); - pmap->green = (EntryPtr)((char *)pmap->numPixelsRed + - (MAXCLIENTS * sizeof(int))); - pmap->clientPixelsGreen = (Pixel **)((char *)pmap->green + sizebytes); - pmap->numPixelsGreen = (int *)((char *)pmap->clientPixelsGreen + - (MAXCLIENTS * sizeof(Pixel *))); - pmap->freeBlue = NUMBLUE(pVisual); - pmap->blue = (EntryPtr)((char *)pmap->numPixelsGreen + - (MAXCLIENTS * sizeof(int))); - pmap->clientPixelsBlue = (Pixel **)((char *)pmap->blue + sizebytes); - pmap->numPixelsBlue = (int *)((char *)pmap->clientPixelsBlue + - (MAXCLIENTS * sizeof(Pixel *))); - - memset((char *) pmap->green, 0, (int)sizebytes); - memset((char *) pmap->blue, 0, (int)sizebytes); - - memmove((char *) pmap->clientPixelsGreen, - (char *) pmap->clientPixelsRed, - MAXCLIENTS * sizeof(Pixel *)); - memmove((char *) pmap->clientPixelsBlue, - (char *) pmap->clientPixelsRed, - MAXCLIENTS * sizeof(Pixel *)); - memset((char *) pmap->numPixelsGreen, 0, MAXCLIENTS * sizeof(int)); - memset((char *) pmap->numPixelsBlue, 0, MAXCLIENTS * sizeof(int)); - - /* If every cell is allocated, mark its refcnt */ - if (alloc == AllocAll) - { - size = pmap->freeGreen; - for(pent = &pmap->green[size-1]; pent >= pmap->green; pent--) - pent->refcnt = AllocPrivate; - pmap->freeGreen = 0; - ppix = malloc(size * sizeof(Pixel)); - if (!ppix) - { - free(pmap->clientPixelsRed[client]); - free(pmap); - return BadAlloc; - } - pmap->clientPixelsGreen[client] = ppix; - for(i = 0; i < size; i++) - ppix[i] = i; - pmap->numPixelsGreen[client] = size; - - size = pmap->freeBlue; - for(pent = &pmap->blue[size-1]; pent >= pmap->blue; pent--) - pent->refcnt = AllocPrivate; - pmap->freeBlue = 0; - ppix = malloc(size * sizeof(Pixel)); - if (!ppix) - { - free(pmap->clientPixelsGreen[client]); - free(pmap->clientPixelsRed[client]); - free(pmap); - return BadAlloc; - } - pmap->clientPixelsBlue[client] = ppix; - for(i = 0; i < size; i++) - ppix[i] = i; - pmap->numPixelsBlue[client] = size; - } + for (pptr = &pmap->clientPixelsRed[MAXCLIENTS]; + --pptr >= pmap->clientPixelsRed;) + *pptr = (Pixel *) NULL; + if (alloc == AllocAll) { + if (class & DynamicClass) + pmap->flags |= AllAllocated; + for (pent = &pmap->red[size - 1]; pent >= pmap->red; pent--) + pent->refcnt = AllocPrivate; + pmap->freeRed = 0; + ppix = malloc(size * sizeof(Pixel)); + if (!ppix) { + free(pmap); + return BadAlloc; + } + pmap->clientPixelsRed[client] = ppix; + for (i = 0; i < size; i++) + ppix[i] = i; + pmap->numPixelsRed[client] = size; + } + + if ((class | DynamicClass) == DirectColor) { + pmap->freeGreen = NUMGREEN(pVisual); + pmap->green = (EntryPtr) ((char *) pmap->numPixelsRed + + (MAXCLIENTS * sizeof(int))); + pmap->clientPixelsGreen = (Pixel **) ((char *) pmap->green + sizebytes); + pmap->numPixelsGreen = (int *) ((char *) pmap->clientPixelsGreen + + (MAXCLIENTS * sizeof(Pixel *))); + pmap->freeBlue = NUMBLUE(pVisual); + pmap->blue = (EntryPtr) ((char *) pmap->numPixelsGreen + + (MAXCLIENTS * sizeof(int))); + pmap->clientPixelsBlue = (Pixel **) ((char *) pmap->blue + sizebytes); + pmap->numPixelsBlue = (int *) ((char *) pmap->clientPixelsBlue + + (MAXCLIENTS * sizeof(Pixel *))); + + memset((char *) pmap->green, 0, (int) sizebytes); + memset((char *) pmap->blue, 0, (int) sizebytes); + + memmove((char *) pmap->clientPixelsGreen, + (char *) pmap->clientPixelsRed, MAXCLIENTS * sizeof(Pixel *)); + memmove((char *) pmap->clientPixelsBlue, + (char *) pmap->clientPixelsRed, MAXCLIENTS * sizeof(Pixel *)); + memset((char *) pmap->numPixelsGreen, 0, MAXCLIENTS * sizeof(int)); + memset((char *) pmap->numPixelsBlue, 0, MAXCLIENTS * sizeof(int)); + + /* If every cell is allocated, mark its refcnt */ + if (alloc == AllocAll) { + size = pmap->freeGreen; + for (pent = &pmap->green[size - 1]; pent >= pmap->green; pent--) + pent->refcnt = AllocPrivate; + pmap->freeGreen = 0; + ppix = malloc(size * sizeof(Pixel)); + if (!ppix) { + free(pmap->clientPixelsRed[client]); + free(pmap); + return BadAlloc; + } + pmap->clientPixelsGreen[client] = ppix; + for (i = 0; i < size; i++) + ppix[i] = i; + pmap->numPixelsGreen[client] = size; + + size = pmap->freeBlue; + for (pent = &pmap->blue[size - 1]; pent >= pmap->blue; pent--) + pent->refcnt = AllocPrivate; + pmap->freeBlue = 0; + ppix = malloc(size * sizeof(Pixel)); + if (!ppix) { + free(pmap->clientPixelsGreen[client]); + free(pmap->clientPixelsRed[client]); + free(pmap); + return BadAlloc; + } + pmap->clientPixelsBlue[client] = ppix; + for (i = 0; i < size; i++) + ppix[i] = i; + pmap->numPixelsBlue[client] = size; + } } pmap->flags |= BeingCreated; - if (!AddResource(mid, RT_COLORMAP, (pointer)pmap)) - return BadAlloc; + if (!AddResource(mid, RT_COLORMAP, (pointer) pmap)) + return BadAlloc; /* * Security creation/labeling check */ i = XaceHook(XACE_RESOURCE_ACCESS, clients[client], mid, RT_COLORMAP, - pmap, RT_NONE, NULL, DixCreateAccess); + pmap, RT_NONE, NULL, DixCreateAccess); if (i != Success) { - FreeResource(mid, RT_NONE); - return i; + FreeResource(mid, RT_NONE); + return i; } /* If the device wants a chance to initialize the colormap in any way, * this is it. In specific, if this is a Static colormap, this is the * time to fill in the colormap's values */ - if (!(*pScreen->CreateColormap)(pmap)) - { - FreeResource (mid, RT_NONE); - return BadAlloc; + if (!(*pScreen->CreateColormap) (pmap)) { + FreeResource(mid, RT_NONE); + return BadAlloc; } pmap->flags &= ~BeingCreated; *ppcmap = pmap; @@ -422,84 +397,76 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, * \param value must conform to DeleteType */ int -FreeColormap (pointer value, XID mid) +FreeColormap(pointer value, XID mid) { - int i; + int i; EntryPtr pent; - ColormapPtr pmap = (ColormapPtr)value; + ColormapPtr pmap = (ColormapPtr) value; - if(CLIENT_ID(mid) != SERVER_ID) - { + if (CLIENT_ID(mid) != SERVER_ID) { (*pmap->pScreen->UninstallColormap) (pmap); - WalkTree(pmap->pScreen, (VisitWindowProcPtr)TellNoMap, (pointer) &mid); + WalkTree(pmap->pScreen, (VisitWindowProcPtr) TellNoMap, (pointer) &mid); } /* This is the device's chance to undo anything it needs to, especially * to free any storage it allocated */ - (*pmap->pScreen->DestroyColormap)(pmap); - - if(pmap->clientPixelsRed) - { - for(i = 0; i < MAXCLIENTS; i++) - free(pmap->clientPixelsRed[i]); - } - - if ((pmap->class == PseudoColor) || (pmap->class == GrayScale)) - { - for(pent = &pmap->red[pmap->pVisual->ColormapEntries - 1]; - pent >= pmap->red; - pent--) - { - if(pent->fShared) - { - if (--pent->co.shco.red->refcnt == 0) - free(pent->co.shco.red); - if (--pent->co.shco.green->refcnt == 0) - free(pent->co.shco.green); - if (--pent->co.shco.blue->refcnt == 0) - free(pent->co.shco.blue); - } - } - } - if((pmap->class | DynamicClass) == DirectColor) - { - for(i = 0; i < MAXCLIENTS; i++) - { + (*pmap->pScreen->DestroyColormap) (pmap); + + if (pmap->clientPixelsRed) { + for (i = 0; i < MAXCLIENTS; i++) + free(pmap->clientPixelsRed[i]); + } + + if ((pmap->class == PseudoColor) || (pmap->class == GrayScale)) { + for (pent = &pmap->red[pmap->pVisual->ColormapEntries - 1]; + pent >= pmap->red; pent--) { + if (pent->fShared) { + if (--pent->co.shco.red->refcnt == 0) + free(pent->co.shco.red); + if (--pent->co.shco.green->refcnt == 0) + free(pent->co.shco.green); + if (--pent->co.shco.blue->refcnt == 0) + free(pent->co.shco.blue); + } + } + } + if ((pmap->class | DynamicClass) == DirectColor) { + for (i = 0; i < MAXCLIENTS; i++) { free(pmap->clientPixelsGreen[i]); free(pmap->clientPixelsBlue[i]); } } if (pmap->flags & IsDefault) { - dixFreePrivates(pmap->devPrivates, PRIVATE_COLORMAP); - free(pmap); - } else - dixFreeObjectWithPrivates(pmap, PRIVATE_COLORMAP); + dixFreePrivates(pmap->devPrivates, PRIVATE_COLORMAP); + free(pmap); + } + else + dixFreeObjectWithPrivates(pmap, PRIVATE_COLORMAP); return Success; } /* Tell window that pmid has disappeared */ static int -TellNoMap (WindowPtr pwin, Colormap *pmid) +TellNoMap(WindowPtr pwin, Colormap * pmid) { - xEvent xE; - - if (wColormap(pwin) == *pmid) - { - /* This should be call to DeliverEvent */ - xE.u.u.type = ColormapNotify; - xE.u.colormap.window = pwin->drawable.id; - xE.u.colormap.colormap = None; - xE.u.colormap.new = TRUE; - xE.u.colormap.state = ColormapUninstalled; + xEvent xE; + + if (wColormap(pwin) == *pmid) { + /* This should be call to DeliverEvent */ + xE.u.u.type = ColormapNotify; + xE.u.colormap.window = pwin->drawable.id; + xE.u.colormap.colormap = None; + xE.u.colormap.new = TRUE; + xE.u.colormap.state = ColormapUninstalled; #ifdef PANORAMIX - if(noPanoramiXExtension || !pwin->drawable.pScreen->myNum) + if (noPanoramiXExtension || !pwin->drawable.pScreen->myNum) #endif - DeliverEvents(pwin, &xE, 1, (WindowPtr)NULL); - if (pwin->optional) { - pwin->optional->colormap = None; - CheckWindowOptionalNeed (pwin); - } + DeliverEvents(pwin, &xE, 1, (WindowPtr) NULL); + if (pwin->optional) { + pwin->optional->colormap = None; + CheckWindowOptionalNeed(pwin); + } } return WT_WALKCHILDREN; @@ -507,24 +474,23 @@ TellNoMap (WindowPtr pwin, Colormap *pmid) /* Tell window that pmid got uninstalled */ int -TellLostMap (WindowPtr pwin, pointer value) +TellLostMap(WindowPtr pwin, pointer value) { - Colormap *pmid = (Colormap *)value; - xEvent xE; + Colormap *pmid = (Colormap *) value; + xEvent xE; #ifdef PANORAMIX - if(!noPanoramiXExtension && pwin->drawable.pScreen->myNum) - return WT_STOPWALKING; + if (!noPanoramiXExtension && pwin->drawable.pScreen->myNum) + return WT_STOPWALKING; #endif - if (wColormap(pwin) == *pmid) - { - /* This should be call to DeliverEvent */ - xE.u.u.type = ColormapNotify; - xE.u.colormap.window = pwin->drawable.id; - xE.u.colormap.colormap = *pmid; - xE.u.colormap.new = FALSE; - xE.u.colormap.state = ColormapUninstalled; - DeliverEvents(pwin, &xE, 1, (WindowPtr)NULL); + if (wColormap(pwin) == *pmid) { + /* This should be call to DeliverEvent */ + xE.u.u.type = ColormapNotify; + xE.u.colormap.window = pwin->drawable.id; + xE.u.colormap.colormap = *pmid; + xE.u.colormap.new = FALSE; + xE.u.colormap.state = ColormapUninstalled; + DeliverEvents(pwin, &xE, 1, (WindowPtr) NULL); } return WT_WALKCHILDREN; @@ -532,272 +498,251 @@ TellLostMap (WindowPtr pwin, pointer value) /* Tell window that pmid got installed */ int -TellGainedMap (WindowPtr pwin, pointer value) +TellGainedMap(WindowPtr pwin, pointer value) { - Colormap *pmid = (Colormap *)value; - xEvent xE; + Colormap *pmid = (Colormap *) value; + xEvent xE; #ifdef PANORAMIX - if(!noPanoramiXExtension && pwin->drawable.pScreen->myNum) - return WT_STOPWALKING; + if (!noPanoramiXExtension && pwin->drawable.pScreen->myNum) + return WT_STOPWALKING; #endif - if (wColormap (pwin) == *pmid) - { - /* This should be call to DeliverEvent */ - xE.u.u.type = ColormapNotify; - xE.u.colormap.window = pwin->drawable.id; - xE.u.colormap.colormap = *pmid; - xE.u.colormap.new = FALSE; - xE.u.colormap.state = ColormapInstalled; - DeliverEvents(pwin, &xE, 1, (WindowPtr)NULL); + if (wColormap(pwin) == *pmid) { + /* This should be call to DeliverEvent */ + xE.u.u.type = ColormapNotify; + xE.u.colormap.window = pwin->drawable.id; + xE.u.colormap.colormap = *pmid; + xE.u.colormap.new = FALSE; + xE.u.colormap.state = ColormapInstalled; + DeliverEvents(pwin, &xE, 1, (WindowPtr) NULL); } return WT_WALKCHILDREN; } - int -CopyColormapAndFree (Colormap mid, ColormapPtr pSrc, int client) +CopyColormapAndFree(Colormap mid, ColormapPtr pSrc, int client) { - ColormapPtr pmap = (ColormapPtr) NULL; - int result, alloc, size; - Colormap midSrc; - ScreenPtr pScreen; - VisualPtr pVisual; + ColormapPtr pmap = (ColormapPtr) NULL; + int result, alloc, size; + Colormap midSrc; + ScreenPtr pScreen; + VisualPtr pVisual; pScreen = pSrc->pScreen; pVisual = pSrc->pVisual; midSrc = pSrc->mid; alloc = ((pSrc->flags & AllAllocated) && CLIENT_ID(midSrc) == client) ? - AllocAll : AllocNone; + AllocAll : AllocNone; size = pVisual->ColormapEntries; /* If the create returns non-0, it failed */ - result = CreateColormap (mid, pScreen, pVisual, &pmap, alloc, client); - if(result != Success) + result = CreateColormap(mid, pScreen, pVisual, &pmap, alloc, client); + if (result != Success) return result; - if(alloc == AllocAll) - { - memmove((char *)pmap->red, (char *)pSrc->red, size * sizeof(Entry)); - if((pmap->class | DynamicClass) == DirectColor) - { - memmove((char *)pmap->green, (char *)pSrc->green, size * sizeof(Entry)); - memmove((char *)pmap->blue, (char *)pSrc->blue, size * sizeof(Entry)); - } - pSrc->flags &= ~AllAllocated; - FreePixels(pSrc, client); - UpdateColors(pmap); - return Success; + if (alloc == AllocAll) { + memmove((char *) pmap->red, (char *) pSrc->red, size * sizeof(Entry)); + if ((pmap->class | DynamicClass) == DirectColor) { + memmove((char *) pmap->green, (char *) pSrc->green, + size * sizeof(Entry)); + memmove((char *) pmap->blue, (char *) pSrc->blue, + size * sizeof(Entry)); + } + pSrc->flags &= ~AllAllocated; + FreePixels(pSrc, client); + UpdateColors(pmap); + return Success; } CopyFree(REDMAP, client, pSrc, pmap); - if ((pmap->class | DynamicClass) == DirectColor) - { - CopyFree(GREENMAP, client, pSrc, pmap); - CopyFree(BLUEMAP, client, pSrc, pmap); + if ((pmap->class | DynamicClass) == DirectColor) { + CopyFree(GREENMAP, client, pSrc, pmap); + CopyFree(BLUEMAP, client, pSrc, pmap); } if (pmap->class & DynamicClass) - UpdateColors(pmap); + UpdateColors(pmap); /* XXX should worry about removing any RT_CMAPENTRY resource */ return Success; } /* Helper routine for freeing large numbers of cells from a map */ static void -CopyFree (int channel, int client, ColormapPtr pmapSrc, ColormapPtr pmapDst) +CopyFree(int channel, int client, ColormapPtr pmapSrc, ColormapPtr pmapDst) { - int z, npix; - EntryPtr pentSrcFirst, pentDstFirst; - EntryPtr pentSrc, pentDst; - Pixel *ppix; - int nalloc; - - switch(channel) - { - default: /* so compiler can see that everything gets initialized */ - case REDMAP: - ppix = (pmapSrc->clientPixelsRed)[client]; - npix = (pmapSrc->numPixelsRed)[client]; - pentSrcFirst = pmapSrc->red; - pentDstFirst = pmapDst->red; - break; - case GREENMAP: - ppix = (pmapSrc->clientPixelsGreen)[client]; - npix = (pmapSrc->numPixelsGreen)[client]; - pentSrcFirst = pmapSrc->green; - pentDstFirst = pmapDst->green; - break; - case BLUEMAP: - ppix = (pmapSrc->clientPixelsBlue)[client]; - npix = (pmapSrc->numPixelsBlue)[client]; - pentSrcFirst = pmapSrc->blue; - pentDstFirst = pmapDst->blue; - break; + int z, npix; + EntryPtr pentSrcFirst, pentDstFirst; + EntryPtr pentSrc, pentDst; + Pixel *ppix; + int nalloc; + + switch (channel) { + default: /* so compiler can see that everything gets initialized */ + case REDMAP: + ppix = (pmapSrc->clientPixelsRed)[client]; + npix = (pmapSrc->numPixelsRed)[client]; + pentSrcFirst = pmapSrc->red; + pentDstFirst = pmapDst->red; + break; + case GREENMAP: + ppix = (pmapSrc->clientPixelsGreen)[client]; + npix = (pmapSrc->numPixelsGreen)[client]; + pentSrcFirst = pmapSrc->green; + pentDstFirst = pmapDst->green; + break; + case BLUEMAP: + ppix = (pmapSrc->clientPixelsBlue)[client]; + npix = (pmapSrc->numPixelsBlue)[client]; + pentSrcFirst = pmapSrc->blue; + pentDstFirst = pmapDst->blue; + break; } nalloc = 0; - if (pmapSrc->class & DynamicClass) - { - for(z = npix; --z >= 0; ppix++) - { - /* Copy entries */ - pentSrc = pentSrcFirst + *ppix; - pentDst = pentDstFirst + *ppix; - if (pentDst->refcnt > 0) - { - pentDst->refcnt++; - } - else - { - *pentDst = *pentSrc; - nalloc++; - if (pentSrc->refcnt > 0) - pentDst->refcnt = 1; - else - pentSrc->fShared = FALSE; - } - FreeCell(pmapSrc, *ppix, channel); - } + if (pmapSrc->class & DynamicClass) { + for (z = npix; --z >= 0; ppix++) { + /* Copy entries */ + pentSrc = pentSrcFirst + *ppix; + pentDst = pentDstFirst + *ppix; + if (pentDst->refcnt > 0) { + pentDst->refcnt++; + } + else { + *pentDst = *pentSrc; + nalloc++; + if (pentSrc->refcnt > 0) + pentDst->refcnt = 1; + else + pentSrc->fShared = FALSE; + } + FreeCell(pmapSrc, *ppix, channel); + } } /* Note that FreeCell has already fixed pmapSrc->free{Color} */ - switch(channel) - { - case REDMAP: + switch (channel) { + case REDMAP: pmapDst->freeRed -= nalloc; - (pmapDst->clientPixelsRed)[client] = - (pmapSrc->clientPixelsRed)[client]; + (pmapDst->clientPixelsRed)[client] = (pmapSrc->clientPixelsRed)[client]; (pmapSrc->clientPixelsRed)[client] = (Pixel *) NULL; (pmapDst->numPixelsRed)[client] = (pmapSrc->numPixelsRed)[client]; (pmapSrc->numPixelsRed)[client] = 0; - break; - case GREENMAP: + break; + case GREENMAP: pmapDst->freeGreen -= nalloc; (pmapDst->clientPixelsGreen)[client] = - (pmapSrc->clientPixelsGreen)[client]; + (pmapSrc->clientPixelsGreen)[client]; (pmapSrc->clientPixelsGreen)[client] = (Pixel *) NULL; (pmapDst->numPixelsGreen)[client] = (pmapSrc->numPixelsGreen)[client]; (pmapSrc->numPixelsGreen)[client] = 0; - break; - case BLUEMAP: + break; + case BLUEMAP: pmapDst->freeBlue -= nalloc; pmapDst->clientPixelsBlue[client] = pmapSrc->clientPixelsBlue[client]; pmapSrc->clientPixelsBlue[client] = (Pixel *) NULL; pmapDst->numPixelsBlue[client] = pmapSrc->numPixelsBlue[client]; pmapSrc->numPixelsBlue[client] = 0; - break; + break; } } /* Free the ith entry in a color map. Must handle freeing of * colors allocated through AllocColorPlanes */ static void -FreeCell (ColormapPtr pmap, Pixel i, int channel) +FreeCell(ColormapPtr pmap, Pixel i, int channel) { EntryPtr pent; - int *pCount; - - - switch (channel) - { - default: /* so compiler can see that everything gets initialized */ - case PSEUDOMAP: - case REDMAP: - pent = (EntryPtr) &pmap->red[i]; - pCount = &pmap->freeRed; - break; - case GREENMAP: - pent = (EntryPtr) &pmap->green[i]; - pCount = &pmap->freeGreen; - break; - case BLUEMAP: - pent = (EntryPtr) &pmap->blue[i]; - pCount = &pmap->freeBlue; - break; + int *pCount; + + switch (channel) { + default: /* so compiler can see that everything gets initialized */ + case PSEUDOMAP: + case REDMAP: + pent = (EntryPtr) & pmap->red[i]; + pCount = &pmap->freeRed; + break; + case GREENMAP: + pent = (EntryPtr) & pmap->green[i]; + pCount = &pmap->freeGreen; + break; + case BLUEMAP: + pent = (EntryPtr) & pmap->blue[i]; + pCount = &pmap->freeBlue; + break; } /* If it's not privately allocated and it's not time to free it, just * decrement the count */ if (pent->refcnt > 1) - pent->refcnt--; - else - { + pent->refcnt--; + else { /* If the color type is shared, find the sharedcolor. If decremented * refcnt is 0, free the shared cell. */ - if (pent->fShared) - { - if(--pent->co.shco.red->refcnt == 0) - free(pent->co.shco.red); - if(--pent->co.shco.green->refcnt == 0) - free(pent->co.shco.green); - if(--pent->co.shco.blue->refcnt == 0) - free(pent->co.shco.blue); - pent->fShared = FALSE; - } - pent->refcnt = 0; - *pCount += 1; + if (pent->fShared) { + if (--pent->co.shco.red->refcnt == 0) + free(pent->co.shco.red); + if (--pent->co.shco.green->refcnt == 0) + free(pent->co.shco.green); + if (--pent->co.shco.blue->refcnt == 0) + free(pent->co.shco.blue); + pent->fShared = FALSE; + } + pent->refcnt = 0; + *pCount += 1; } } static void -UpdateColors (ColormapPtr pmap) +UpdateColors(ColormapPtr pmap) { - xColorItem *defs; + xColorItem *defs; xColorItem *pdef; - EntryPtr pent; - VisualPtr pVisual; - int i, n, size; + EntryPtr pent; + VisualPtr pVisual; + int i, n, size; pVisual = pmap->pVisual; size = pVisual->ColormapEntries; defs = malloc(size * sizeof(xColorItem)); if (!defs) - return; + return; n = 0; pdef = defs; - if (pmap->class == DirectColor) - { - for (i = 0; i < size; i++) - { - if (!pmap->red[i].refcnt && - !pmap->green[i].refcnt && - !pmap->blue[i].refcnt) - continue; - pdef->pixel = ((Pixel)i << pVisual->offsetRed) | - ((Pixel)i << pVisual->offsetGreen) | - ((Pixel)i << pVisual->offsetBlue); - pdef->red = pmap->red[i].co.local.red; - pdef->green = pmap->green[i].co.local.green; - pdef->blue = pmap->blue[i].co.local.blue; - pdef->flags = DoRed|DoGreen|DoBlue; - pdef++; - n++; - } + if (pmap->class == DirectColor) { + for (i = 0; i < size; i++) { + if (!pmap->red[i].refcnt && + !pmap->green[i].refcnt && !pmap->blue[i].refcnt) + continue; + pdef->pixel = ((Pixel) i << pVisual->offsetRed) | + ((Pixel) i << pVisual->offsetGreen) | + ((Pixel) i << pVisual->offsetBlue); + pdef->red = pmap->red[i].co.local.red; + pdef->green = pmap->green[i].co.local.green; + pdef->blue = pmap->blue[i].co.local.blue; + pdef->flags = DoRed | DoGreen | DoBlue; + pdef++; + n++; + } } - else - { - for (i = 0, pent = pmap->red; i < size; i++, pent++) - { - if (!pent->refcnt) - continue; - pdef->pixel = i; - if(pent->fShared) - { - pdef->red = pent->co.shco.red->color; - pdef->green = pent->co.shco.green->color; - pdef->blue = pent->co.shco.blue->color; - } - else - { - pdef->red = pent->co.local.red; - pdef->green = pent->co.local.green; - pdef->blue = pent->co.local.blue; - } - pdef->flags = DoRed|DoGreen|DoBlue; - pdef++; - n++; - } + else { + for (i = 0, pent = pmap->red; i < size; i++, pent++) { + if (!pent->refcnt) + continue; + pdef->pixel = i; + if (pent->fShared) { + pdef->red = pent->co.shco.red->color; + pdef->green = pent->co.shco.green->color; + pdef->blue = pent->co.shco.blue->color; + } + else { + pdef->red = pent->co.local.red; + pdef->green = pent->co.local.green; + pdef->blue = pent->co.local.blue; + } + pdef->flags = DoRed | DoGreen | DoBlue; + pdef++; + n++; + } } if (n) - (*pmap->pScreen->StoreColors)(pmap, n, defs); + (*pmap->pScreen->StoreColors) (pmap, n, defs); free(defs); } @@ -805,17 +750,17 @@ UpdateColors (ColormapPtr pmap) * Returns by changing the value in pred, pgreen, pblue and pPix */ int -AllocColor (ColormapPtr pmap, - unsigned short *pred, unsigned short *pgreen, unsigned short *pblue, - Pixel *pPix, int client) +AllocColor(ColormapPtr pmap, + unsigned short *pred, unsigned short *pgreen, unsigned short *pblue, + Pixel * pPix, int client) { - Pixel pixR, pixG, pixB; - int entries; - xrgb rgb; - int class; - VisualPtr pVisual; - int npix; - Pixel *ppix; + Pixel pixR, pixG, pixB; + int entries; + xrgb rgb; + int class; + VisualPtr pVisual; + int npix; + Pixel *ppix; pVisual = pmap->pVisual; (*pmap->pScreen->ResolveColor) (pred, pgreen, pblue, pVisual); @@ -829,8 +774,8 @@ AllocColor (ColormapPtr pmap, * the colormap, even if it's a static type. Otherwise, we'd never be * able to initialize static colormaps */ - if(pmap->flags & BeingCreated) - class |= DynamicClass; + if (pmap->flags & BeingCreated) + class |= DynamicClass; /* If this is one of the static storage classes, and we're not initializing * it, the best we can do is to find the closest color entry to the @@ -839,144 +784,139 @@ AllocColor (ColormapPtr pmap, switch (class) { case StaticColor: case StaticGray: - /* Look up all three components in the same pmap */ - *pPix = pixR = FindBestPixel(pmap->red, entries, &rgb, PSEUDOMAP); - *pred = pmap->red[pixR].co.local.red; - *pgreen = pmap->red[pixR].co.local.green; - *pblue = pmap->red[pixR].co.local.blue; - npix = pmap->numPixelsRed[client]; - ppix = (Pixel *) realloc(pmap->clientPixelsRed[client], - (npix + 1) * sizeof(Pixel)); - if (!ppix) - return BadAlloc; - ppix[npix] = pixR; - pmap->clientPixelsRed[client] = ppix; - pmap->numPixelsRed[client]++; - break; + /* Look up all three components in the same pmap */ + *pPix = pixR = FindBestPixel(pmap->red, entries, &rgb, PSEUDOMAP); + *pred = pmap->red[pixR].co.local.red; + *pgreen = pmap->red[pixR].co.local.green; + *pblue = pmap->red[pixR].co.local.blue; + npix = pmap->numPixelsRed[client]; + ppix = (Pixel *) realloc(pmap->clientPixelsRed[client], + (npix + 1) * sizeof(Pixel)); + if (!ppix) + return BadAlloc; + ppix[npix] = pixR; + pmap->clientPixelsRed[client] = ppix; + pmap->numPixelsRed[client]++; + break; case TrueColor: - /* Look up each component in its own map, then OR them together */ - pixR = FindBestPixel(pmap->red, NUMRED(pVisual), &rgb, REDMAP); - pixG = FindBestPixel(pmap->green, NUMGREEN(pVisual), &rgb, GREENMAP); - pixB = FindBestPixel(pmap->blue, NUMBLUE(pVisual), &rgb, BLUEMAP); - *pPix = (pixR << pVisual->offsetRed) | - (pixG << pVisual->offsetGreen) | - (pixB << pVisual->offsetBlue) | - ALPHAMASK(pVisual); - - *pred = pmap->red[pixR].co.local.red; - *pgreen = pmap->green[pixG].co.local.green; - *pblue = pmap->blue[pixB].co.local.blue; - npix = pmap->numPixelsRed[client]; - ppix = (Pixel *) realloc(pmap->clientPixelsRed[client], - (npix + 1) * sizeof(Pixel)); - if (!ppix) - return BadAlloc; - ppix[npix] = pixR; - pmap->clientPixelsRed[client] = ppix; - npix = pmap->numPixelsGreen[client]; - ppix = (Pixel *) realloc(pmap->clientPixelsGreen[client], - (npix + 1) * sizeof(Pixel)); - if (!ppix) - return BadAlloc; - ppix[npix] = pixG; - pmap->clientPixelsGreen[client] = ppix; - npix = pmap->numPixelsBlue[client]; - ppix = (Pixel *) realloc(pmap->clientPixelsBlue[client], - (npix + 1) * sizeof(Pixel)); - if (!ppix) - return BadAlloc; - ppix[npix] = pixB; - pmap->clientPixelsBlue[client] = ppix; - pmap->numPixelsRed[client]++; - pmap->numPixelsGreen[client]++; - pmap->numPixelsBlue[client]++; - break; + /* Look up each component in its own map, then OR them together */ + pixR = FindBestPixel(pmap->red, NUMRED(pVisual), &rgb, REDMAP); + pixG = FindBestPixel(pmap->green, NUMGREEN(pVisual), &rgb, GREENMAP); + pixB = FindBestPixel(pmap->blue, NUMBLUE(pVisual), &rgb, BLUEMAP); + *pPix = (pixR << pVisual->offsetRed) | + (pixG << pVisual->offsetGreen) | + (pixB << pVisual->offsetBlue) | ALPHAMASK(pVisual); + + *pred = pmap->red[pixR].co.local.red; + *pgreen = pmap->green[pixG].co.local.green; + *pblue = pmap->blue[pixB].co.local.blue; + npix = pmap->numPixelsRed[client]; + ppix = (Pixel *) realloc(pmap->clientPixelsRed[client], + (npix + 1) * sizeof(Pixel)); + if (!ppix) + return BadAlloc; + ppix[npix] = pixR; + pmap->clientPixelsRed[client] = ppix; + npix = pmap->numPixelsGreen[client]; + ppix = (Pixel *) realloc(pmap->clientPixelsGreen[client], + (npix + 1) * sizeof(Pixel)); + if (!ppix) + return BadAlloc; + ppix[npix] = pixG; + pmap->clientPixelsGreen[client] = ppix; + npix = pmap->numPixelsBlue[client]; + ppix = (Pixel *) realloc(pmap->clientPixelsBlue[client], + (npix + 1) * sizeof(Pixel)); + if (!ppix) + return BadAlloc; + ppix[npix] = pixB; + pmap->clientPixelsBlue[client] = ppix; + pmap->numPixelsRed[client]++; + pmap->numPixelsGreen[client]++; + pmap->numPixelsBlue[client]++; + break; case GrayScale: case PseudoColor: - if (pmap->mid != pmap->pScreen->defColormap && - pmap->pVisual->vid == pmap->pScreen->rootVisual) - { - ColormapPtr prootmap; - dixLookupResourceByType((pointer *)&prootmap, pmap->pScreen->defColormap, - RT_COLORMAP, clients[client], DixReadAccess); - - if (pmap->class == prootmap->class) - FindColorInRootCmap (prootmap, prootmap->red, entries, &rgb, - pPix, PSEUDOMAP, AllComp); - } - if (FindColor(pmap, pmap->red, entries, &rgb, pPix, PSEUDOMAP, - client, AllComp) != Success) - return BadAlloc; + if (pmap->mid != pmap->pScreen->defColormap && + pmap->pVisual->vid == pmap->pScreen->rootVisual) { + ColormapPtr prootmap; + + dixLookupResourceByType((pointer *) &prootmap, + pmap->pScreen->defColormap, RT_COLORMAP, + clients[client], DixReadAccess); + + if (pmap->class == prootmap->class) + FindColorInRootCmap(prootmap, prootmap->red, entries, &rgb, + pPix, PSEUDOMAP, AllComp); + } + if (FindColor(pmap, pmap->red, entries, &rgb, pPix, PSEUDOMAP, + client, AllComp) != Success) + return BadAlloc; break; case DirectColor: - if (pmap->mid != pmap->pScreen->defColormap && - pmap->pVisual->vid == pmap->pScreen->rootVisual) - { - ColormapPtr prootmap; - dixLookupResourceByType((pointer *)&prootmap, pmap->pScreen->defColormap, - RT_COLORMAP, clients[client], DixReadAccess); - - if (pmap->class == prootmap->class) - { - pixR = (*pPix & pVisual->redMask) >> pVisual->offsetRed; - FindColorInRootCmap (prootmap, prootmap->red, entries, &rgb, - &pixR, REDMAP, RedComp); - pixG = (*pPix & pVisual->greenMask) >> pVisual->offsetGreen; - FindColorInRootCmap (prootmap, prootmap->green, entries, &rgb, - &pixG, GREENMAP, GreenComp); - pixB = (*pPix & pVisual->blueMask) >> pVisual->offsetBlue; - FindColorInRootCmap (prootmap, prootmap->blue, entries, &rgb, - &pixB, BLUEMAP, BlueComp); - *pPix = pixR | pixG | pixB; - } - } - - pixR = (*pPix & pVisual->redMask) >> pVisual->offsetRed; - if (FindColor(pmap, pmap->red, NUMRED(pVisual), &rgb, &pixR, REDMAP, - client, RedComp) != Success) - return BadAlloc; - pixG = (*pPix & pVisual->greenMask) >> pVisual->offsetGreen; - if (FindColor(pmap, pmap->green, NUMGREEN(pVisual), &rgb, &pixG, - GREENMAP, client, GreenComp) != Success) - { - (void)FreeCo(pmap, client, REDMAP, 1, &pixR, (Pixel)0); - return BadAlloc; - } - pixB = (*pPix & pVisual->blueMask) >> pVisual->offsetBlue; - if (FindColor(pmap, pmap->blue, NUMBLUE(pVisual), &rgb, &pixB, BLUEMAP, - client, BlueComp) != Success) - { - (void)FreeCo(pmap, client, GREENMAP, 1, &pixG, (Pixel)0); - (void)FreeCo(pmap, client, REDMAP, 1, &pixR, (Pixel)0); - return BadAlloc; - } - *pPix = pixR | pixG | pixB | ALPHAMASK(pVisual); - - break; + if (pmap->mid != pmap->pScreen->defColormap && + pmap->pVisual->vid == pmap->pScreen->rootVisual) { + ColormapPtr prootmap; + + dixLookupResourceByType((pointer *) &prootmap, + pmap->pScreen->defColormap, RT_COLORMAP, + clients[client], DixReadAccess); + + if (pmap->class == prootmap->class) { + pixR = (*pPix & pVisual->redMask) >> pVisual->offsetRed; + FindColorInRootCmap(prootmap, prootmap->red, entries, &rgb, + &pixR, REDMAP, RedComp); + pixG = (*pPix & pVisual->greenMask) >> pVisual->offsetGreen; + FindColorInRootCmap(prootmap, prootmap->green, entries, &rgb, + &pixG, GREENMAP, GreenComp); + pixB = (*pPix & pVisual->blueMask) >> pVisual->offsetBlue; + FindColorInRootCmap(prootmap, prootmap->blue, entries, &rgb, + &pixB, BLUEMAP, BlueComp); + *pPix = pixR | pixG | pixB; + } + } + + pixR = (*pPix & pVisual->redMask) >> pVisual->offsetRed; + if (FindColor(pmap, pmap->red, NUMRED(pVisual), &rgb, &pixR, REDMAP, + client, RedComp) != Success) + return BadAlloc; + pixG = (*pPix & pVisual->greenMask) >> pVisual->offsetGreen; + if (FindColor(pmap, pmap->green, NUMGREEN(pVisual), &rgb, &pixG, + GREENMAP, client, GreenComp) != Success) { + (void) FreeCo(pmap, client, REDMAP, 1, &pixR, (Pixel) 0); + return BadAlloc; + } + pixB = (*pPix & pVisual->blueMask) >> pVisual->offsetBlue; + if (FindColor(pmap, pmap->blue, NUMBLUE(pVisual), &rgb, &pixB, BLUEMAP, + client, BlueComp) != Success) { + (void) FreeCo(pmap, client, GREENMAP, 1, &pixG, (Pixel) 0); + (void) FreeCo(pmap, client, REDMAP, 1, &pixR, (Pixel) 0); + return BadAlloc; + } + *pPix = pixR | pixG | pixB | ALPHAMASK(pVisual); + + break; } /* if this is the client's first pixel in this colormap, tell the * resource manager that the client has pixels in this colormap which * should be freed when the client dies */ if ((pmap->numPixelsRed[client] == 1) && - (CLIENT_ID(pmap->mid) != client) && - !(pmap->flags & BeingCreated)) - { - colorResource *pcr; - - pcr = malloc(sizeof(colorResource)); - if (!pcr) - { - (void)FreeColors(pmap, client, 1, pPix, (Pixel)0); - return BadAlloc; - } - pcr->mid = pmap->mid; - pcr->client = client; - if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr)) - return BadAlloc; + (CLIENT_ID(pmap->mid) != client) && !(pmap->flags & BeingCreated)) { + colorResource *pcr; + + pcr = malloc(sizeof(colorResource)); + if (!pcr) { + (void) FreeColors(pmap, client, 1, pPix, (Pixel) 0); + return BadAlloc; + } + pcr->mid = pmap->mid; + pcr->client = client; + if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer) pcr)) + return BadAlloc; } return Success; } @@ -990,13 +930,13 @@ AllocColor (ColormapPtr pmap, */ void -FakeAllocColor (ColormapPtr pmap, xColorItem *item) +FakeAllocColor(ColormapPtr pmap, xColorItem * item) { Pixel pixR, pixG, pixB; Pixel temp; - int entries; + int entries; xrgb rgb; - int class; + int class; VisualPtr pVisual; pVisual = pmap->pVisual; @@ -1010,48 +950,47 @@ FakeAllocColor (ColormapPtr pmap, xColorItem *item) switch (class) { case GrayScale: case PseudoColor: - temp = 0; - item->pixel = 0; - if (FindColor(pmap, pmap->red, entries, &rgb, &temp, PSEUDOMAP, - -1, AllComp) == Success) { - item->pixel = temp; - break; - } - /* fall through ... */ + temp = 0; + item->pixel = 0; + if (FindColor(pmap, pmap->red, entries, &rgb, &temp, PSEUDOMAP, + -1, AllComp) == Success) { + item->pixel = temp; + break; + } + /* fall through ... */ case StaticColor: case StaticGray: - item->pixel = FindBestPixel(pmap->red, entries, &rgb, PSEUDOMAP); - break; + item->pixel = FindBestPixel(pmap->red, entries, &rgb, PSEUDOMAP); + break; case DirectColor: - /* Look up each component in its own map, then OR them together */ - pixR = (item->pixel & pVisual->redMask) >> pVisual->offsetRed; - pixG = (item->pixel & pVisual->greenMask) >> pVisual->offsetGreen; - pixB = (item->pixel & pVisual->blueMask) >> pVisual->offsetBlue; - if (FindColor(pmap, pmap->red, NUMRED(pVisual), &rgb, &pixR, REDMAP, - -1, RedComp) != Success) - pixR = FindBestPixel(pmap->red, NUMRED(pVisual), &rgb, REDMAP) - << pVisual->offsetRed; - if (FindColor(pmap, pmap->green, NUMGREEN(pVisual), &rgb, &pixG, - GREENMAP, -1, GreenComp) != Success) - pixG = FindBestPixel(pmap->green, NUMGREEN(pVisual), &rgb, - GREENMAP) << pVisual->offsetGreen; - if (FindColor(pmap, pmap->blue, NUMBLUE(pVisual), &rgb, &pixB, BLUEMAP, - -1, BlueComp) != Success) - pixB = FindBestPixel(pmap->blue, NUMBLUE(pVisual), &rgb, BLUEMAP) - << pVisual->offsetBlue; - item->pixel = pixR | pixG | pixB; - break; + /* Look up each component in its own map, then OR them together */ + pixR = (item->pixel & pVisual->redMask) >> pVisual->offsetRed; + pixG = (item->pixel & pVisual->greenMask) >> pVisual->offsetGreen; + pixB = (item->pixel & pVisual->blueMask) >> pVisual->offsetBlue; + if (FindColor(pmap, pmap->red, NUMRED(pVisual), &rgb, &pixR, REDMAP, + -1, RedComp) != Success) + pixR = FindBestPixel(pmap->red, NUMRED(pVisual), &rgb, REDMAP) + << pVisual->offsetRed; + if (FindColor(pmap, pmap->green, NUMGREEN(pVisual), &rgb, &pixG, + GREENMAP, -1, GreenComp) != Success) + pixG = FindBestPixel(pmap->green, NUMGREEN(pVisual), &rgb, + GREENMAP) << pVisual->offsetGreen; + if (FindColor(pmap, pmap->blue, NUMBLUE(pVisual), &rgb, &pixB, BLUEMAP, + -1, BlueComp) != Success) + pixB = FindBestPixel(pmap->blue, NUMBLUE(pVisual), &rgb, BLUEMAP) + << pVisual->offsetBlue; + item->pixel = pixR | pixG | pixB; + break; case TrueColor: - /* Look up each component in its own map, then OR them together */ - pixR = FindBestPixel(pmap->red, NUMRED(pVisual), &rgb, REDMAP); - pixG = FindBestPixel(pmap->green, NUMGREEN(pVisual), &rgb, GREENMAP); - pixB = FindBestPixel(pmap->blue, NUMBLUE(pVisual), &rgb, BLUEMAP); - item->pixel = (pixR << pVisual->offsetRed) | - (pixG << pVisual->offsetGreen) | - (pixB << pVisual->offsetBlue); - break; + /* Look up each component in its own map, then OR them together */ + pixR = FindBestPixel(pmap->red, NUMRED(pVisual), &rgb, REDMAP); + pixG = FindBestPixel(pmap->green, NUMGREEN(pVisual), &rgb, GREENMAP); + pixB = FindBestPixel(pmap->blue, NUMBLUE(pVisual), &rgb, BLUEMAP); + item->pixel = (pixR << pVisual->offsetRed) | + (pixG << pVisual->offsetGreen) | (pixB << pVisual->offsetBlue); + break; } } @@ -1065,26 +1004,26 @@ FakeFreeColor(ColormapPtr pmap, Pixel pixel) switch (pmap->class) { case GrayScale: case PseudoColor: - if (pmap->red[pixel].refcnt == AllocTemporary) - pmap->red[pixel].refcnt = 0; - break; + if (pmap->red[pixel].refcnt == AllocTemporary) + pmap->red[pixel].refcnt = 0; + break; case DirectColor: - pVisual = pmap->pVisual; - pixR = (pixel & pVisual->redMask) >> pVisual->offsetRed; - pixG = (pixel & pVisual->greenMask) >> pVisual->offsetGreen; - pixB = (pixel & pVisual->blueMask) >> pVisual->offsetBlue; - if (pmap->red[pixR].refcnt == AllocTemporary) - pmap->red[pixR].refcnt = 0; - if (pmap->green[pixG].refcnt == AllocTemporary) - pmap->green[pixG].refcnt = 0; - if (pmap->blue[pixB].refcnt == AllocTemporary) - pmap->blue[pixB].refcnt = 0; - break; + pVisual = pmap->pVisual; + pixR = (pixel & pVisual->redMask) >> pVisual->offsetRed; + pixG = (pixel & pVisual->greenMask) >> pVisual->offsetGreen; + pixB = (pixel & pVisual->blueMask) >> pVisual->offsetBlue; + if (pmap->red[pixR].refcnt == AllocTemporary) + pmap->red[pixR].refcnt = 0; + if (pmap->green[pixG].refcnt == AllocTemporary) + pmap->green[pixG].refcnt = 0; + if (pmap->blue[pixB].refcnt == AllocTemporary) + pmap->blue[pixB].refcnt = 0; + break; } } -typedef unsigned short BigNumUpper; -typedef unsigned long BigNumLower; +typedef unsigned short BigNumUpper; +typedef unsigned long BigNumLower; #define BIGNUMLOWERBITS 24 #define BIGNUMUPPERBITS 16 @@ -1094,8 +1033,8 @@ typedef unsigned long BigNumLower; #define LOWERPART(i) ((i) & (BIGNUMLOWER - 1)) typedef struct _bignum { - BigNumUpper upper; - BigNumLower lower; + BigNumUpper upper; + BigNumLower lower; } BigNumRec, *BigNumPtr; #define BigNumGreater(x,y) (((x)->upper > (y)->upper) ||\ @@ -1108,97 +1047,91 @@ typedef struct _bignum { ((r)->lower = BIGNUMLOWER-1)) static void -BigNumAdd (BigNumPtr x, BigNumPtr y, BigNumPtr r) +BigNumAdd(BigNumPtr x, BigNumPtr y, BigNumPtr r) { - BigNumLower lower, carry = 0; + BigNumLower lower, carry = 0; lower = x->lower + y->lower; if (lower >= BIGNUMLOWER) { - lower -= BIGNUMLOWER; - carry = 1; + lower -= BIGNUMLOWER; + carry = 1; } r->lower = lower; r->upper = x->upper + y->upper + carry; } static Pixel -FindBestPixel(EntryPtr pentFirst, int size, xrgb *prgb, int channel) +FindBestPixel(EntryPtr pentFirst, int size, xrgb * prgb, int channel) { - EntryPtr pent; - Pixel pixel, final; - long dr, dg, db; - unsigned long sq; - BigNumRec minval, sum, temp; + EntryPtr pent; + Pixel pixel, final; + long dr, dg, db; + unsigned long sq; + BigNumRec minval, sum, temp; final = 0; MaxBigNum(&minval); /* look for the minimal difference */ - for (pent = pentFirst, pixel = 0; pixel < size; pent++, pixel++) - { - dr = dg = db = 0; - switch(channel) - { - case PSEUDOMAP: - dg = (long) pent->co.local.green - prgb->green; - db = (long) pent->co.local.blue - prgb->blue; - case REDMAP: - dr = (long) pent->co.local.red - prgb->red; - break; - case GREENMAP: - dg = (long) pent->co.local.green - prgb->green; - break; - case BLUEMAP: - db = (long) pent->co.local.blue - prgb->blue; - break; - } - sq = dr * dr; - UnsignedToBigNum (sq, &sum); - sq = dg * dg; - UnsignedToBigNum (sq, &temp); - BigNumAdd (&sum, &temp, &sum); - sq = db * db; - UnsignedToBigNum (sq, &temp); - BigNumAdd (&sum, &temp, &sum); - if (BigNumGreater (&minval, &sum)) - { - final = pixel; - minval = sum; - } + for (pent = pentFirst, pixel = 0; pixel < size; pent++, pixel++) { + dr = dg = db = 0; + switch (channel) { + case PSEUDOMAP: + dg = (long) pent->co.local.green - prgb->green; + db = (long) pent->co.local.blue - prgb->blue; + case REDMAP: + dr = (long) pent->co.local.red - prgb->red; + break; + case GREENMAP: + dg = (long) pent->co.local.green - prgb->green; + break; + case BLUEMAP: + db = (long) pent->co.local.blue - prgb->blue; + break; + } + sq = dr * dr; + UnsignedToBigNum(sq, &sum); + sq = dg * dg; + UnsignedToBigNum(sq, &temp); + BigNumAdd(&sum, &temp, &sum); + sq = db * db; + UnsignedToBigNum(sq, &temp); + BigNumAdd(&sum, &temp, &sum); + if (BigNumGreater(&minval, &sum)) { + final = pixel; + minval = sum; + } } return final; } static void -FindColorInRootCmap (ColormapPtr pmap, EntryPtr pentFirst, int size, - xrgb *prgb, Pixel *pPixel, int channel, - ColorCompareProcPtr comp) +FindColorInRootCmap(ColormapPtr pmap, EntryPtr pentFirst, int size, + xrgb * prgb, Pixel * pPixel, int channel, + ColorCompareProcPtr comp) { - EntryPtr pent; - Pixel pixel; - int count; + EntryPtr pent; + Pixel pixel; + int count; if ((pixel = *pPixel) >= size) - pixel = 0; - for (pent = pentFirst + pixel, count = size; --count >= 0; pent++, pixel++) - { - if (pent->refcnt > 0 && (*comp) (pent, prgb)) - { - switch (channel) - { - case REDMAP: - pixel <<= pmap->pVisual->offsetRed; - break; - case GREENMAP: - pixel <<= pmap->pVisual->offsetGreen; - break; - case BLUEMAP: - pixel <<= pmap->pVisual->offsetBlue; - break; - default: /* PSEUDOMAP */ - break; - } - *pPixel = pixel; - } + pixel = 0; + for (pent = pentFirst + pixel, count = size; --count >= 0; pent++, pixel++) { + if (pent->refcnt > 0 && (*comp) (pent, prgb)) { + switch (channel) { + case REDMAP: + pixel <<= pmap->pVisual->offsetRed; + break; + case GREENMAP: + pixel <<= pmap->pVisual->offsetGreen; + break; + case BLUEMAP: + pixel <<= pmap->pVisual->offsetBlue; + break; + default: /* PSEUDOMAP */ + break; + } + *pPixel = pixel; + } } } @@ -1208,170 +1141,159 @@ FindColorInRootCmap (ColormapPtr pmap, EntryPtr pentFirst, int size, * load *pPixel with that value, otherwise set it to 0 */ int -FindColor (ColormapPtr pmap, EntryPtr pentFirst, int size, xrgb *prgb, - Pixel *pPixel, int channel, int client, - ColorCompareProcPtr comp) +FindColor(ColormapPtr pmap, EntryPtr pentFirst, int size, xrgb * prgb, + Pixel * pPixel, int channel, int client, ColorCompareProcPtr comp) { - EntryPtr pent; - Bool foundFree; - Pixel pixel, Free = 0; - int npix, count, *nump = NULL; - Pixel **pixp = NULL, *ppix; - xColorItem def; + EntryPtr pent; + Bool foundFree; + Pixel pixel, Free = 0; + int npix, count, *nump = NULL; + Pixel **pixp = NULL, *ppix; + xColorItem def; foundFree = FALSE; - if((pixel = *pPixel) >= size) - pixel = 0; + if ((pixel = *pPixel) >= size) + pixel = 0; /* see if there is a match, and also look for a free entry */ - for (pent = pentFirst + pixel, count = size; --count >= 0; ) - { - if (pent->refcnt > 0) - { - if ((*comp) (pent, prgb)) - { - if (client >= 0) - pent->refcnt++; - *pPixel = pixel; - switch(channel) - { - case REDMAP: - *pPixel <<= pmap->pVisual->offsetRed; - case PSEUDOMAP: - break; - case GREENMAP: - *pPixel <<= pmap->pVisual->offsetGreen; - break; - case BLUEMAP: - *pPixel <<= pmap->pVisual->offsetBlue; - break; - } - goto gotit; - } + for (pent = pentFirst + pixel, count = size; --count >= 0;) { + if (pent->refcnt > 0) { + if ((*comp) (pent, prgb)) { + if (client >= 0) + pent->refcnt++; + *pPixel = pixel; + switch (channel) { + case REDMAP: + *pPixel <<= pmap->pVisual->offsetRed; + case PSEUDOMAP: + break; + case GREENMAP: + *pPixel <<= pmap->pVisual->offsetGreen; + break; + case BLUEMAP: + *pPixel <<= pmap->pVisual->offsetBlue; + break; + } + goto gotit; + } } - else if (!foundFree && pent->refcnt == 0) - { - Free = pixel; - foundFree = TRUE; - /* If we're initializing the colormap, then we are looking for - * the first free cell we can find, not to minimize the number - * of entries we use. So don't look any further. */ - if(pmap->flags & BeingCreated) - break; - } - pixel++; - if(pixel >= size) - { - pent = pentFirst; - pixel = 0; - } - else - pent++; + else if (!foundFree && pent->refcnt == 0) { + Free = pixel; + foundFree = TRUE; + /* If we're initializing the colormap, then we are looking for + * the first free cell we can find, not to minimize the number + * of entries we use. So don't look any further. */ + if (pmap->flags & BeingCreated) + break; + } + pixel++; + if (pixel >= size) { + pent = pentFirst; + pixel = 0; + } + else + pent++; } /* If we got here, we didn't find a match. If we also didn't find * a free entry, we're out of luck. Otherwise, we'll usurp a free * entry and fill it in */ if (!foundFree) - return BadAlloc; + return BadAlloc; pent = pentFirst + Free; pent->fShared = FALSE; pent->refcnt = (client >= 0) ? 1 : AllocTemporary; - switch (channel) - { - case PSEUDOMAP: + switch (channel) { + case PSEUDOMAP: pent->co.local.red = prgb->red; pent->co.local.green = prgb->green; pent->co.local.blue = prgb->blue; def.red = prgb->red; - def.green = prgb->green; - def.blue = prgb->blue; - def.flags = (DoRed|DoGreen|DoBlue); - if (client >= 0) - pmap->freeRed--; - def.pixel = Free; - break; - - case REDMAP: + def.green = prgb->green; + def.blue = prgb->blue; + def.flags = (DoRed | DoGreen | DoBlue); + if (client >= 0) + pmap->freeRed--; + def.pixel = Free; + break; + + case REDMAP: pent->co.local.red = prgb->red; def.red = prgb->red; - def.green = pmap->green[0].co.local.green; - def.blue = pmap->blue[0].co.local.blue; - def.flags = DoRed; - if (client >= 0) - pmap->freeRed--; - def.pixel = Free << pmap->pVisual->offsetRed; - break; - - case GREENMAP: - pent->co.local.green = prgb->green; - def.red = pmap->red[0].co.local.red; + def.green = pmap->green[0].co.local.green; + def.blue = pmap->blue[0].co.local.blue; + def.flags = DoRed; + if (client >= 0) + pmap->freeRed--; + def.pixel = Free << pmap->pVisual->offsetRed; + break; + + case GREENMAP: + pent->co.local.green = prgb->green; + def.red = pmap->red[0].co.local.red; def.green = prgb->green; - def.blue = pmap->blue[0].co.local.blue; - def.flags = DoGreen; - if (client >= 0) - pmap->freeGreen--; - def.pixel = Free << pmap->pVisual->offsetGreen; - break; - - case BLUEMAP: - pent->co.local.blue = prgb->blue; - def.red = pmap->red[0].co.local.red; - def.green = pmap->green[0].co.local.green; - def.blue = prgb->blue; - def.flags = DoBlue; - if (client >= 0) - pmap->freeBlue--; - def.pixel = Free << pmap->pVisual->offsetBlue; - break; + def.blue = pmap->blue[0].co.local.blue; + def.flags = DoGreen; + if (client >= 0) + pmap->freeGreen--; + def.pixel = Free << pmap->pVisual->offsetGreen; + break; + + case BLUEMAP: + pent->co.local.blue = prgb->blue; + def.red = pmap->red[0].co.local.red; + def.green = pmap->green[0].co.local.green; + def.blue = prgb->blue; + def.flags = DoBlue; + if (client >= 0) + pmap->freeBlue--; + def.pixel = Free << pmap->pVisual->offsetBlue; + break; } (*pmap->pScreen->StoreColors) (pmap, 1, &def); - pixel = Free; + pixel = Free; *pPixel = def.pixel; -gotit: + gotit: if (pmap->flags & BeingCreated || client == -1) - return Success; + return Success; /* Now remember the pixel, for freeing later */ - switch (channel) - { - case PSEUDOMAP: - case REDMAP: - nump = pmap->numPixelsRed; - pixp = pmap->clientPixelsRed; - break; - - case GREENMAP: - nump = pmap->numPixelsGreen; - pixp = pmap->clientPixelsGreen; - break; - - case BLUEMAP: - nump = pmap->numPixelsBlue; - pixp = pmap->clientPixelsBlue; - break; + switch (channel) { + case PSEUDOMAP: + case REDMAP: + nump = pmap->numPixelsRed; + pixp = pmap->clientPixelsRed; + break; + + case GREENMAP: + nump = pmap->numPixelsGreen; + pixp = pmap->clientPixelsGreen; + break; + + case BLUEMAP: + nump = pmap->numPixelsBlue; + pixp = pmap->clientPixelsBlue; + break; } npix = nump[client]; ppix = (Pixel *) realloc(pixp[client], (npix + 1) * sizeof(Pixel)); - if (!ppix) - { - pent->refcnt--; - if (!pent->fShared) - switch (channel) - { - case PSEUDOMAP: - case REDMAP: - pmap->freeRed++; - break; - case GREENMAP: - pmap->freeGreen++; - break; - case BLUEMAP: - pmap->freeBlue++; - break; - } - return BadAlloc; + if (!ppix) { + pent->refcnt--; + if (!pent->fShared) + switch (channel) { + case PSEUDOMAP: + case REDMAP: + pmap->freeRed++; + break; + case GREENMAP: + pmap->freeGreen++; + break; + case BLUEMAP: + pmap->freeBlue++; + break; + } + return BadAlloc; } ppix[npix] = pixel; pixp[client] = ppix; @@ -1383,123 +1305,112 @@ gotit: /* Comparison functions -- passed to FindColor to determine if an * entry is already the color we're looking for or not */ static int -AllComp (EntryPtr pent, xrgb *prgb) +AllComp(EntryPtr pent, xrgb * prgb) { - if((pent->co.local.red == prgb->red) && - (pent->co.local.green == prgb->green) && - (pent->co.local.blue == prgb->blue) ) - return 1; + if ((pent->co.local.red == prgb->red) && + (pent->co.local.green == prgb->green) && + (pent->co.local.blue == prgb->blue)) + return 1; return 0; } static int -RedComp (EntryPtr pent, xrgb *prgb) +RedComp(EntryPtr pent, xrgb * prgb) { - if (pent->co.local.red == prgb->red) - return 1; + if (pent->co.local.red == prgb->red) + return 1; return 0; } static int -GreenComp (EntryPtr pent, xrgb *prgb) +GreenComp(EntryPtr pent, xrgb * prgb) { - if (pent->co.local.green == prgb->green) - return 1; + if (pent->co.local.green == prgb->green) + return 1; return 0; } static int -BlueComp (EntryPtr pent, xrgb *prgb) +BlueComp(EntryPtr pent, xrgb * prgb) { - if (pent->co.local.blue == prgb->blue) - return 1; + if (pent->co.local.blue == prgb->blue) + return 1; return 0; } - /* Read the color value of a cell */ int -QueryColors (ColormapPtr pmap, int count, Pixel *ppixIn, xrgb *prgbList, ClientPtr client) +QueryColors(ColormapPtr pmap, int count, Pixel * ppixIn, xrgb * prgbList, + ClientPtr client) { - Pixel *ppix, pixel; - xrgb *prgb; - VisualPtr pVisual; - EntryPtr pent; - Pixel i; - int errVal = Success; + Pixel *ppix, pixel; + xrgb *prgb; + VisualPtr pVisual; + EntryPtr pent; + Pixel i; + int errVal = Success; pVisual = pmap->pVisual; - if ((pmap->class | DynamicClass) == DirectColor) - { - int numred, numgreen, numblue; - Pixel rgbbad; - - numred = NUMRED(pVisual); - numgreen = NUMGREEN(pVisual); - numblue = NUMBLUE(pVisual); - rgbbad = ~RGBMASK(pVisual); - for( ppix = ppixIn, prgb = prgbList; --count >= 0; ppix++, prgb++) - { - pixel = *ppix; - if (pixel & rgbbad) { - client->errorValue = pixel; - errVal = BadValue; - continue; - } - i = (pixel & pVisual->redMask) >> pVisual->offsetRed; - if (i >= numred) - { - client->errorValue = pixel; - errVal = BadValue; - continue; - } - prgb->red = pmap->red[i].co.local.red; - i = (pixel & pVisual->greenMask) >> pVisual->offsetGreen; - if (i >= numgreen) - { - client->errorValue = pixel; - errVal = BadValue; - continue; - } - prgb->green = pmap->green[i].co.local.green; - i = (pixel & pVisual->blueMask) >> pVisual->offsetBlue; - if (i >= numblue) - { - client->errorValue = pixel; - errVal = BadValue; - continue; - } - prgb->blue = pmap->blue[i].co.local.blue; - } + if ((pmap->class | DynamicClass) == DirectColor) { + int numred, numgreen, numblue; + Pixel rgbbad; + + numred = NUMRED(pVisual); + numgreen = NUMGREEN(pVisual); + numblue = NUMBLUE(pVisual); + rgbbad = ~RGBMASK(pVisual); + for (ppix = ppixIn, prgb = prgbList; --count >= 0; ppix++, prgb++) { + pixel = *ppix; + if (pixel & rgbbad) { + client->errorValue = pixel; + errVal = BadValue; + continue; + } + i = (pixel & pVisual->redMask) >> pVisual->offsetRed; + if (i >= numred) { + client->errorValue = pixel; + errVal = BadValue; + continue; + } + prgb->red = pmap->red[i].co.local.red; + i = (pixel & pVisual->greenMask) >> pVisual->offsetGreen; + if (i >= numgreen) { + client->errorValue = pixel; + errVal = BadValue; + continue; + } + prgb->green = pmap->green[i].co.local.green; + i = (pixel & pVisual->blueMask) >> pVisual->offsetBlue; + if (i >= numblue) { + client->errorValue = pixel; + errVal = BadValue; + continue; + } + prgb->blue = pmap->blue[i].co.local.blue; + } } - else - { - for( ppix = ppixIn, prgb = prgbList; --count >= 0; ppix++, prgb++) - { - pixel = *ppix; - if (pixel >= pVisual->ColormapEntries) - { - client->errorValue = pixel; - errVal = BadValue; - } - else - { - pent = (EntryPtr)&pmap->red[pixel]; - if (pent->fShared) - { - prgb->red = pent->co.shco.red->color; - prgb->green = pent->co.shco.green->color; - prgb->blue = pent->co.shco.blue->color; - } - else - { - prgb->red = pent->co.local.red; - prgb->green = pent->co.local.green; - prgb->blue = pent->co.local.blue; - } - } - } + else { + for (ppix = ppixIn, prgb = prgbList; --count >= 0; ppix++, prgb++) { + pixel = *ppix; + if (pixel >= pVisual->ColormapEntries) { + client->errorValue = pixel; + errVal = BadValue; + } + else { + pent = (EntryPtr) & pmap->red[pixel]; + if (pent->fShared) { + prgb->red = pent->co.shco.red->color; + prgb->green = pent->co.shco.green->color; + prgb->blue = pent->co.shco.blue->color; + } + else { + prgb->red = pent->co.local.red; + prgb->green = pent->co.local.green; + prgb->blue = pent->co.local.blue; + } + } + } } return errVal; } @@ -1509,40 +1420,37 @@ FreePixels(ColormapPtr pmap, int client) { Pixel *ppix, *ppixStart; int n; - int class; + int class; class = pmap->class; ppixStart = pmap->clientPixelsRed[client]; - if (class & DynamicClass) - { - n = pmap->numPixelsRed[client]; - for (ppix = ppixStart; --n >= 0; ) - { - FreeCell(pmap, *ppix, REDMAP); - ppix++; - } + if (class & DynamicClass) { + n = pmap->numPixelsRed[client]; + for (ppix = ppixStart; --n >= 0;) { + FreeCell(pmap, *ppix, REDMAP); + ppix++; + } } free(ppixStart); pmap->clientPixelsRed[client] = (Pixel *) NULL; pmap->numPixelsRed[client] = 0; - if ((class | DynamicClass) == DirectColor) - { + if ((class | DynamicClass) == DirectColor) { ppixStart = pmap->clientPixelsGreen[client]; - if (class & DynamicClass) - for (ppix = ppixStart, n = pmap->numPixelsGreen[client]; --n >= 0;) - FreeCell(pmap, *ppix++, GREENMAP); - free(ppixStart); - pmap->clientPixelsGreen[client] = (Pixel *) NULL; - pmap->numPixelsGreen[client] = 0; + if (class & DynamicClass) + for (ppix = ppixStart, n = pmap->numPixelsGreen[client]; --n >= 0;) + FreeCell(pmap, *ppix++, GREENMAP); + free(ppixStart); + pmap->clientPixelsGreen[client] = (Pixel *) NULL; + pmap->numPixelsGreen[client] = 0; ppixStart = pmap->clientPixelsBlue[client]; - if (class & DynamicClass) - for (ppix = ppixStart, n = pmap->numPixelsBlue[client]; --n >= 0; ) - FreeCell(pmap, *ppix++, BLUEMAP); - free(ppixStart); - pmap->clientPixelsBlue[client] = (Pixel *) NULL; - pmap->numPixelsBlue[client] = 0; + if (class & DynamicClass) + for (ppix = ppixStart, n = pmap->numPixelsBlue[client]; --n >= 0;) + FreeCell(pmap, *ppix++, BLUEMAP); + free(ppixStart); + pmap->clientPixelsBlue[client] = (Pixel *) NULL; + pmap->numPixelsBlue[client] = 0; } } @@ -1553,252 +1461,236 @@ FreePixels(ColormapPtr pmap, int client) * \unused fakeid */ int -FreeClientPixels (pointer value, XID fakeid) +FreeClientPixels(pointer value, XID fakeid) { pointer pmap; colorResource *pcr = value; int rc; rc = dixLookupResourceByType(&pmap, pcr->mid, RT_COLORMAP, serverClient, - DixRemoveAccess); + DixRemoveAccess); if (rc == Success) - FreePixels((ColormapPtr)pmap, pcr->client); + FreePixels((ColormapPtr) pmap, pcr->client); free(pcr); return Success; } int -AllocColorCells (int client, ColormapPtr pmap, int colors, int planes, - Bool contig, Pixel *ppix, Pixel *masks) +AllocColorCells(int client, ColormapPtr pmap, int colors, int planes, + Bool contig, Pixel * ppix, Pixel * masks) { - Pixel rmask, gmask, bmask, *ppixFirst, r, g, b; - int n, class; - int ok; - int oldcount; - colorResource *pcr = (colorResource *)NULL; + Pixel rmask, gmask, bmask, *ppixFirst, r, g, b; + int n, class; + int ok; + int oldcount; + colorResource *pcr = (colorResource *) NULL; class = pmap->class; if (!(class & DynamicClass)) - return BadAlloc; /* Shouldn't try on this type */ + return BadAlloc; /* Shouldn't try on this type */ oldcount = pmap->numPixelsRed[client]; if (pmap->class == DirectColor) - oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; - if (!oldcount && (CLIENT_ID(pmap->mid) != client)) - { - pcr = malloc(sizeof(colorResource)); - if (!pcr) - return BadAlloc; - } - - if (pmap->class == DirectColor) - { - ok = AllocDirect (client, pmap, colors, planes, planes, planes, - contig, ppix, &rmask, &gmask, &bmask); - if(ok == Success) - { - for (r = g = b = 1, n = planes; --n >= 0; r += r, g += g, b += b) - { - while(!(rmask & r)) - r += r; - while(!(gmask & g)) - g += g; - while(!(bmask & b)) - b += b; - *masks++ = r | g | b; - } - } + oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; + if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { + pcr = malloc(sizeof(colorResource)); + if (!pcr) + return BadAlloc; + } + + if (pmap->class == DirectColor) { + ok = AllocDirect(client, pmap, colors, planes, planes, planes, + contig, ppix, &rmask, &gmask, &bmask); + if (ok == Success) { + for (r = g = b = 1, n = planes; --n >= 0; r += r, g += g, b += b) { + while (!(rmask & r)) + r += r; + while (!(gmask & g)) + g += g; + while (!(bmask & b)) + b += b; + *masks++ = r | g | b; + } + } } - else - { - ok = AllocPseudo (client, pmap, colors, planes, contig, ppix, &rmask, - &ppixFirst); - if(ok == Success) - { - for (r = 1, n = planes; --n >= 0; r += r) - { - while(!(rmask & r)) - r += r; - *masks++ = r; - } - } + else { + ok = AllocPseudo(client, pmap, colors, planes, contig, ppix, &rmask, + &ppixFirst); + if (ok == Success) { + for (r = 1, n = planes; --n >= 0; r += r) { + while (!(rmask & r)) + r += r; + *masks++ = r; + } + } } /* if this is the client's first pixels in this colormap, tell the * resource manager that the client has pixels in this colormap which * should be freed when the client dies */ - if ((ok == Success) && pcr) - { - pcr->mid = pmap->mid; - pcr->client = client; - if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr)) - ok = BadAlloc; - } else free(pcr); + if ((ok == Success) && pcr) { + pcr->mid = pmap->mid; + pcr->client = client; + if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer) pcr)) + ok = BadAlloc; + } + else + free(pcr); return ok; } - int -AllocColorPlanes (int client, ColormapPtr pmap, int colors, - int r, int g, int b, Bool contig, Pixel *pixels, - Pixel *prmask, Pixel *pgmask, Pixel *pbmask) +AllocColorPlanes(int client, ColormapPtr pmap, int colors, + int r, int g, int b, Bool contig, Pixel * pixels, + Pixel * prmask, Pixel * pgmask, Pixel * pbmask) { - int ok; - Pixel mask, *ppixFirst; + int ok; + Pixel mask, *ppixFirst; Pixel shift; int i; - int class; - int oldcount; - colorResource *pcr = (colorResource *)NULL; + int class; + int oldcount; + colorResource *pcr = (colorResource *) NULL; class = pmap->class; if (!(class & DynamicClass)) - return BadAlloc; /* Shouldn't try on this type */ + return BadAlloc; /* Shouldn't try on this type */ oldcount = pmap->numPixelsRed[client]; if (class == DirectColor) - oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; - if (!oldcount && (CLIENT_ID(pmap->mid) != client)) - { - pcr = malloc(sizeof(colorResource)); - if (!pcr) - return BadAlloc; - } - - if (class == DirectColor) - { - ok = AllocDirect (client, pmap, colors, r, g, b, contig, pixels, - prmask, pgmask, pbmask); - } - else - { - /* Allocate the proper pixels */ - /* XXX This is sort of bad, because of contig is set, we force all - * r + g + b bits to be contiguous. Should only force contiguity - * per mask - */ - ok = AllocPseudo (client, pmap, colors, r + g + b, contig, pixels, - &mask, &ppixFirst); - - if(ok == Success) - { - /* now split that mask into three */ - *prmask = *pgmask = *pbmask = 0; - shift = 1; - for (i = r; --i >= 0; shift += shift) - { - while (!(mask & shift)) - shift += shift; - *prmask |= shift; - } - for (i = g; --i >= 0; shift += shift) - { - while (!(mask & shift)) - shift += shift; - *pgmask |= shift; - } - for (i = b; --i >= 0; shift += shift) - { - while (!(mask & shift)) - shift += shift; - *pbmask |= shift; - } - - /* set up the shared color cells */ - if (!AllocShared(pmap, pixels, colors, r, g, b, - *prmask, *pgmask, *pbmask, ppixFirst)) - { - (void)FreeColors(pmap, client, colors, pixels, mask); - ok = BadAlloc; - } - } + oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; + if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { + pcr = malloc(sizeof(colorResource)); + if (!pcr) + return BadAlloc; + } + + if (class == DirectColor) { + ok = AllocDirect(client, pmap, colors, r, g, b, contig, pixels, + prmask, pgmask, pbmask); + } + else { + /* Allocate the proper pixels */ + /* XXX This is sort of bad, because of contig is set, we force all + * r + g + b bits to be contiguous. Should only force contiguity + * per mask + */ + ok = AllocPseudo(client, pmap, colors, r + g + b, contig, pixels, + &mask, &ppixFirst); + + if (ok == Success) { + /* now split that mask into three */ + *prmask = *pgmask = *pbmask = 0; + shift = 1; + for (i = r; --i >= 0; shift += shift) { + while (!(mask & shift)) + shift += shift; + *prmask |= shift; + } + for (i = g; --i >= 0; shift += shift) { + while (!(mask & shift)) + shift += shift; + *pgmask |= shift; + } + for (i = b; --i >= 0; shift += shift) { + while (!(mask & shift)) + shift += shift; + *pbmask |= shift; + } + + /* set up the shared color cells */ + if (!AllocShared(pmap, pixels, colors, r, g, b, + *prmask, *pgmask, *pbmask, ppixFirst)) { + (void) FreeColors(pmap, client, colors, pixels, mask); + ok = BadAlloc; + } + } } /* if this is the client's first pixels in this colormap, tell the * resource manager that the client has pixels in this colormap which * should be freed when the client dies */ - if ((ok == Success) && pcr) - { - pcr->mid = pmap->mid; - pcr->client = client; - if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr)) - ok = BadAlloc; - } else free(pcr); + if ((ok == Success) && pcr) { + pcr->mid = pmap->mid; + pcr->client = client; + if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer) pcr)) + ok = BadAlloc; + } + else + free(pcr); return ok; } static int -AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool contig, - Pixel *pixels, Pixel *prmask, Pixel *pgmask, Pixel *pbmask) +AllocDirect(int client, ColormapPtr pmap, int c, int r, int g, int b, + Bool contig, Pixel * pixels, Pixel * prmask, Pixel * pgmask, + Pixel * pbmask) { - Pixel *ppixRed, *ppixGreen, *ppixBlue; - Pixel *ppix, *pDst, *p; - int npix, npixR, npixG, npixB; - Bool okR, okG, okB; - Pixel *rpix = 0, *gpix = 0, *bpix = 0; + Pixel *ppixRed, *ppixGreen, *ppixBlue; + Pixel *ppix, *pDst, *p; + int npix, npixR, npixG, npixB; + Bool okR, okG, okB; + Pixel *rpix = 0, *gpix = 0, *bpix = 0; npixR = c << r; npixG = c << g; npixB = c << b; if ((r >= 32) || (g >= 32) || (b >= 32) || - (npixR > pmap->freeRed) || (npixR < c) || - (npixG > pmap->freeGreen) || (npixG < c) || - (npixB > pmap->freeBlue) || (npixB < c)) - return BadAlloc; + (npixR > pmap->freeRed) || (npixR < c) || + (npixG > pmap->freeGreen) || (npixG < c) || + (npixB > pmap->freeBlue) || (npixB < c)) + return BadAlloc; /* start out with empty pixels */ - for(p = pixels; p < pixels + c; p++) - *p = 0; + for (p = pixels; p < pixels + c; p++) + *p = 0; ppixRed = malloc(npixR * sizeof(Pixel)); ppixGreen = malloc(npixG * sizeof(Pixel)); ppixBlue = malloc(npixB * sizeof(Pixel)); - if (!ppixRed || !ppixGreen || !ppixBlue) - { - free(ppixBlue); - free(ppixGreen); - free(ppixRed); - return BadAlloc; + if (!ppixRed || !ppixGreen || !ppixBlue) { + free(ppixBlue); + free(ppixGreen); + free(ppixRed); + return BadAlloc; } okR = AllocCP(pmap, pmap->red, c, r, contig, ppixRed, prmask); okG = AllocCP(pmap, pmap->green, c, g, contig, ppixGreen, pgmask); okB = AllocCP(pmap, pmap->blue, c, b, contig, ppixBlue, pbmask); - if (okR && okG && okB) - { - rpix = (Pixel *) realloc(pmap->clientPixelsRed[client], - (pmap->numPixelsRed[client] + (c << r)) * - sizeof(Pixel)); - if (rpix) - pmap->clientPixelsRed[client] = rpix; - gpix = (Pixel *) realloc(pmap->clientPixelsGreen[client], - (pmap->numPixelsGreen[client] + (c << g)) * - sizeof(Pixel)); - if (gpix) - pmap->clientPixelsGreen[client] = gpix; - bpix = (Pixel *) realloc(pmap->clientPixelsBlue[client], - (pmap->numPixelsBlue[client] + (c << b)) * - sizeof(Pixel)); - if (bpix) - pmap->clientPixelsBlue[client] = bpix; - } - - if (!okR || !okG || !okB || !rpix || !gpix || !bpix) - { - if (okR) - for(ppix = ppixRed, npix = npixR; --npix >= 0; ppix++) - pmap->red[*ppix].refcnt = 0; - if (okG) - for(ppix = ppixGreen, npix = npixG; --npix >= 0; ppix++) - pmap->green[*ppix].refcnt = 0; - if (okB) - for(ppix = ppixBlue, npix = npixB; --npix >= 0; ppix++) - pmap->blue[*ppix].refcnt = 0; - free(ppixBlue); - free(ppixGreen); - free(ppixRed); - return BadAlloc; + if (okR && okG && okB) { + rpix = (Pixel *) realloc(pmap->clientPixelsRed[client], + (pmap->numPixelsRed[client] + (c << r)) * + sizeof(Pixel)); + if (rpix) + pmap->clientPixelsRed[client] = rpix; + gpix = (Pixel *) realloc(pmap->clientPixelsGreen[client], + (pmap->numPixelsGreen[client] + (c << g)) * + sizeof(Pixel)); + if (gpix) + pmap->clientPixelsGreen[client] = gpix; + bpix = (Pixel *) realloc(pmap->clientPixelsBlue[client], + (pmap->numPixelsBlue[client] + (c << b)) * + sizeof(Pixel)); + if (bpix) + pmap->clientPixelsBlue[client] = bpix; + } + + if (!okR || !okG || !okB || !rpix || !gpix || !bpix) { + if (okR) + for (ppix = ppixRed, npix = npixR; --npix >= 0; ppix++) + pmap->red[*ppix].refcnt = 0; + if (okG) + for (ppix = ppixGreen, npix = npixG; --npix >= 0; ppix++) + pmap->green[*ppix].refcnt = 0; + if (okB) + for (ppix = ppixBlue, npix = npixB; --npix >= 0; ppix++) + pmap->blue[*ppix].refcnt = 0; + free(ppixBlue); + free(ppixGreen); + free(ppixRed); + return BadAlloc; } *prmask <<= pmap->pVisual->offsetRed; @@ -1806,38 +1698,34 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont *pbmask <<= pmap->pVisual->offsetBlue; ppix = rpix + pmap->numPixelsRed[client]; - for (pDst = pixels, p = ppixRed; p < ppixRed + npixR; p++) - { - *ppix++ = *p; - if(p < ppixRed + c) - *pDst++ |= *p << pmap->pVisual->offsetRed; + for (pDst = pixels, p = ppixRed; p < ppixRed + npixR; p++) { + *ppix++ = *p; + if (p < ppixRed + c) + *pDst++ |= *p << pmap->pVisual->offsetRed; } pmap->numPixelsRed[client] += npixR; pmap->freeRed -= npixR; ppix = gpix + pmap->numPixelsGreen[client]; - for (pDst = pixels, p = ppixGreen; p < ppixGreen + npixG; p++) - { - *ppix++ = *p; - if(p < ppixGreen + c) - *pDst++ |= *p << pmap->pVisual->offsetGreen; + for (pDst = pixels, p = ppixGreen; p < ppixGreen + npixG; p++) { + *ppix++ = *p; + if (p < ppixGreen + c) + *pDst++ |= *p << pmap->pVisual->offsetGreen; } pmap->numPixelsGreen[client] += npixG; pmap->freeGreen -= npixG; ppix = bpix + pmap->numPixelsBlue[client]; - for (pDst = pixels, p = ppixBlue; p < ppixBlue + npixB; p++) - { - *ppix++ = *p; - if(p < ppixBlue + c) - *pDst++ |= *p << pmap->pVisual->offsetBlue; + for (pDst = pixels, p = ppixBlue; p < ppixBlue + npixB; p++) { + *ppix++ = *p; + if (p < ppixBlue + c) + *pDst++ |= *p << pmap->pVisual->offsetBlue; } pmap->numPixelsBlue[client] += npixB; pmap->freeBlue -= npixB; - for (pDst = pixels; pDst < pixels + c; pDst++) - *pDst |= ALPHAMASK(pmap->pVisual); + *pDst |= ALPHAMASK(pmap->pVisual); free(ppixBlue); free(ppixGreen); @@ -1847,46 +1735,44 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont } static int -AllocPseudo (int client, ColormapPtr pmap, int c, int r, Bool contig, - Pixel *pixels, Pixel *pmask, Pixel **pppixFirst) +AllocPseudo(int client, ColormapPtr pmap, int c, int r, Bool contig, + Pixel * pixels, Pixel * pmask, Pixel ** pppixFirst) { - Pixel *ppix, *p, *pDst, *ppixTemp; - int npix; - Bool ok; + Pixel *ppix, *p, *pDst, *ppixTemp; + int npix; + Bool ok; npix = c << r; if ((r >= 32) || (npix > pmap->freeRed) || (npix < c)) - return BadAlloc; - if(!(ppixTemp = malloc(npix * sizeof(Pixel)))) - return BadAlloc; + return BadAlloc; + if (!(ppixTemp = malloc(npix * sizeof(Pixel)))) + return BadAlloc; ok = AllocCP(pmap, pmap->red, c, r, contig, ppixTemp, pmask); - if (ok) - { - - /* all the allocated pixels are added to the client pixel list, - * but only the unique ones are returned to the client */ - ppix = (Pixel *)realloc(pmap->clientPixelsRed[client], - (pmap->numPixelsRed[client] + npix) * sizeof(Pixel)); - if (!ppix) - { - for (p = ppixTemp; p < ppixTemp + npix; p++) - pmap->red[*p].refcnt = 0; - free(ppixTemp); - return BadAlloc; - } - pmap->clientPixelsRed[client] = ppix; - ppix += pmap->numPixelsRed[client]; - *pppixFirst = ppix; - pDst = pixels; - for (p = ppixTemp; p < ppixTemp + npix; p++) - { - *ppix++ = *p; - if(p < ppixTemp + c) - *pDst++ = *p; - } - pmap->numPixelsRed[client] += npix; - pmap->freeRed -= npix; + if (ok) { + + /* all the allocated pixels are added to the client pixel list, + * but only the unique ones are returned to the client */ + ppix = (Pixel *) realloc(pmap->clientPixelsRed[client], + (pmap->numPixelsRed[client] + + npix) * sizeof(Pixel)); + if (!ppix) { + for (p = ppixTemp; p < ppixTemp + npix; p++) + pmap->red[*p].refcnt = 0; + free(ppixTemp); + return BadAlloc; + } + pmap->clientPixelsRed[client] = ppix; + ppix += pmap->numPixelsRed[client]; + *pppixFirst = ppix; + pDst = pixels; + for (p = ppixTemp; p < ppixTemp + npix; p++) { + *ppix++ = *p; + if (p < ppixTemp + c) + *pDst++ = *p; + } + pmap->numPixelsRed[client] += npix; + pmap->freeRed -= npix; } free(ppixTemp); return ok ? Success : BadAlloc; @@ -1903,43 +1789,39 @@ AllocPseudo (int client, ColormapPtr pmap, int c, int r, Bool contig, * (see AllocShared for why we care) */ static Bool -AllocCP (ColormapPtr pmap, EntryPtr pentFirst, int count, int planes, - Bool contig, Pixel *pixels, Pixel *pMask) +AllocCP(ColormapPtr pmap, EntryPtr pentFirst, int count, int planes, + Bool contig, Pixel * pixels, Pixel * pMask) { - EntryPtr ent; - Pixel pixel, base, entries, maxp, save; - int dplanes, found; - Pixel *ppix; - Pixel mask; - Pixel finalmask; + EntryPtr ent; + Pixel pixel, base, entries, maxp, save; + int dplanes, found; + Pixel *ppix; + Pixel mask; + Pixel finalmask; dplanes = pmap->pVisual->nplanes; /* Easy case. Allocate pixels only */ - if (planes == 0) - { + if (planes == 0) { /* allocate writable entries */ - ppix = pixels; + ppix = pixels; ent = pentFirst; pixel = 0; - while (--count >= 0) - { + while (--count >= 0) { /* Just find count unallocated cells */ - while (ent->refcnt) - { - ent++; - pixel++; - } - ent->refcnt = AllocPrivate; - *ppix++ = pixel; - ent->fShared = FALSE; + while (ent->refcnt) { + ent++; + pixel++; + } + ent->refcnt = AllocPrivate; + *ppix++ = pixel; + ent->fShared = FALSE; } *pMask = 0; return TRUE; } - else if (planes > dplanes) - { - return FALSE; + else if (planes > dplanes) { + return FALSE; } /* General case count pixels * 2 ^ planes cells to be allocated */ @@ -1948,56 +1830,49 @@ AllocCP (ColormapPtr pmap, EntryPtr pentFirst, int count, int planes, ent = pentFirst; /* first try for contiguous planes, since it's fastest */ - for (mask = (((Pixel)1) << planes) - 1, base = 1, dplanes -= (planes - 1); - --dplanes >= 0; - mask += mask, base += base) - { + for (mask = (((Pixel) 1) << planes) - 1, base = 1, dplanes -= (planes - 1); + --dplanes >= 0; mask += mask, base += base) { ppix = pixels; found = 0; pixel = 0; entries = pmap->pVisual->ColormapEntries - mask; - while (pixel < entries) - { - save = pixel; - maxp = pixel + mask + base; - /* check if all are free */ - while (pixel != maxp && ent[pixel].refcnt == 0) - pixel += base; - if (pixel == maxp) - { - /* this one works */ - *ppix++ = save; - found++; - if (found == count) - { - /* found enough, allocate them all */ - while (--count >= 0) - { - pixel = pixels[count]; - maxp = pixel + mask; - while (1) - { - ent[pixel].refcnt = AllocPrivate; - ent[pixel].fShared = FALSE; - if (pixel == maxp) - break; - pixel += base; - *ppix++ = pixel; - } - } - *pMask = mask; - return TRUE; - } - } - pixel = save + 1; - if (pixel & mask) - pixel += mask; + while (pixel < entries) { + save = pixel; + maxp = pixel + mask + base; + /* check if all are free */ + while (pixel != maxp && ent[pixel].refcnt == 0) + pixel += base; + if (pixel == maxp) { + /* this one works */ + *ppix++ = save; + found++; + if (found == count) { + /* found enough, allocate them all */ + while (--count >= 0) { + pixel = pixels[count]; + maxp = pixel + mask; + while (1) { + ent[pixel].refcnt = AllocPrivate; + ent[pixel].fShared = FALSE; + if (pixel == maxp) + break; + pixel += base; + *ppix++ = pixel; + } + } + *pMask = mask; + return TRUE; + } + } + pixel = save + 1; + if (pixel & mask) + pixel += mask; } } dplanes = pmap->pVisual->nplanes; if (contig || planes == 1 || dplanes < 3) - return FALSE; + return FALSE; /* this will be very slow for large maps, need a better algorithm */ @@ -2008,67 +1883,62 @@ AllocCP (ColormapPtr pmap, EntryPtr pentFirst, int count, int planes, (Non-contiguous masks need one more bit than contiguous masks). Then the smallest such mask consists of the rightmost planes-1 bits set, then a zero, then a one in position planes + 1. The formula is - (3 << (planes-1)) -1 + (3 << (planes-1)) -1 The largest such masks consists of the leftmost planes-1 bits set, then a zero, then a one bit in position dplanes-planes-1. If dplanes is smaller than 32 (the number of bits in a word) then the formula is: - (1<<dplanes) - (1<<(dplanes-planes+1) + (1<<dplanes-planes-1) + (1<<dplanes) - (1<<(dplanes-planes+1) + (1<<dplanes-planes-1) If dplanes = 32, then we can't calculate (1<<dplanes) and we have to use: - ( (1<<(planes-1)) - 1) << (dplanes-planes+1) + (1<<(dplanes-planes-1)) - - << Thank you, Loretta>>> + ( (1<<(planes-1)) - 1) << (dplanes-planes+1) + (1<<(dplanes-planes-1)) + + << Thank you, Loretta>>> - */ + */ finalmask = - (((((Pixel)1)<<(planes-1)) - 1) << (dplanes-planes+1)) + - (((Pixel)1)<<(dplanes-planes-1)); - for (mask = (((Pixel)3) << (planes -1)) - 1; mask <= finalmask; mask++) - { + (((((Pixel) 1) << (planes - 1)) - 1) << (dplanes - planes + 1)) + + (((Pixel) 1) << (dplanes - planes - 1)); + for (mask = (((Pixel) 3) << (planes - 1)) - 1; mask <= finalmask; mask++) { /* next 3 magic statements count number of ones (HAKMEM #169) */ pixel = (mask >> 1) & 033333333333; pixel = mask - pixel - ((pixel >> 1) & 033333333333); if ((((pixel + (pixel >> 3)) & 030707070707) % 077) != planes) - continue; + continue; ppix = pixels; found = 0; entries = pmap->pVisual->ColormapEntries - mask; - base = lowbit (mask); - for (pixel = 0; pixel < entries; pixel++) - { - if (pixel & mask) - continue; - maxp = 0; - /* check if all are free */ - while (ent[pixel + maxp].refcnt == 0) - { - GetNextBitsOrBreak(maxp, mask, base); - } - if ((maxp < mask) || (ent[pixel + mask].refcnt != 0)) - continue; - /* this one works */ - *ppix++ = pixel; - found++; - if (found < count) - continue; - /* found enough, allocate them all */ - while (--count >= 0) - { - pixel = (pixels)[count]; - maxp = 0; - while (1) - { - ent[pixel + maxp].refcnt = AllocPrivate; - ent[pixel + maxp].fShared = FALSE; - GetNextBitsOrBreak(maxp, mask, base); - *ppix++ = pixel + maxp; - } - } - - *pMask = mask; - return TRUE; - } + base = lowbit(mask); + for (pixel = 0; pixel < entries; pixel++) { + if (pixel & mask) + continue; + maxp = 0; + /* check if all are free */ + while (ent[pixel + maxp].refcnt == 0) { + GetNextBitsOrBreak(maxp, mask, base); + } + if ((maxp < mask) || (ent[pixel + mask].refcnt != 0)) + continue; + /* this one works */ + *ppix++ = pixel; + found++; + if (found < count) + continue; + /* found enough, allocate them all */ + while (--count >= 0) { + pixel = (pixels)[count]; + maxp = 0; + while (1) { + ent[pixel + maxp].refcnt = AllocPrivate; + ent[pixel + maxp].fShared = FALSE; + GetNextBitsOrBreak(maxp, mask, base); + *ppix++ = pixel + maxp; + } + } + + *pMask = mask; + return TRUE; + } } return FALSE; } @@ -2078,173 +1948,145 @@ AllocCP (ColormapPtr pmap, EntryPtr pentFirst, int count, int planes, * \param ppixFirst First of the client's new pixels */ static Bool -AllocShared (ColormapPtr pmap, Pixel *ppix, int c, int r, int g, int b, - Pixel rmask, Pixel gmask, Pixel bmask, Pixel *ppixFirst) +AllocShared(ColormapPtr pmap, Pixel * ppix, int c, int r, int g, int b, + Pixel rmask, Pixel gmask, Pixel bmask, Pixel * ppixFirst) { - Pixel *pptr, *cptr; - int npix, z, npixClientNew, npixShared; - Pixel basemask, base, bits, common; + Pixel *pptr, *cptr; + int npix, z, npixClientNew, npixShared; + Pixel basemask, base, bits, common; SHAREDCOLOR *pshared, **ppshared, **psharedList; npixClientNew = c << (r + g + b); npixShared = (c << r) + (c << g) + (c << b); psharedList = malloc(npixShared * sizeof(SHAREDCOLOR *)); if (!psharedList) - return FALSE; + return FALSE; ppshared = psharedList; - for (z = npixShared; --z >= 0; ) - { - if (!(ppshared[z] = malloc(sizeof(SHAREDCOLOR)))) - { - for (z++ ; z < npixShared; z++) - free(ppshared[z]); - free(psharedList); - return FALSE; - } - } - for(pptr = ppix, npix = c; --npix >= 0; pptr++) - { - basemask = ~(gmask | bmask); - common = *pptr & basemask; - if (rmask) - { - bits = 0; - base = lowbit (rmask); - while(1) - { - pshared = *ppshared++; - pshared->refcnt = 1 << (g + b); - for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) - { - if ((*cptr & basemask) == (common | bits)) - { - pmap->red[*cptr].fShared = TRUE; - pmap->red[*cptr].co.shco.red = pshared; - } - } - GetNextBitsOrBreak(bits, rmask, base); - } - } - else - { - pshared = *ppshared++; - pshared->refcnt = 1 << (g + b); - for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) - { - if ((*cptr & basemask) == common) - { - pmap->red[*cptr].fShared = TRUE; - pmap->red[*cptr].co.shco.red = pshared; - } - } - } - basemask = ~(rmask | bmask); - common = *pptr & basemask; - if (gmask) - { - bits = 0; - base = lowbit (gmask); - while(1) - { - pshared = *ppshared++; - pshared->refcnt = 1 << (r + b); - for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) - { - if ((*cptr & basemask) == (common | bits)) - { - pmap->red[*cptr].co.shco.green = pshared; - } - } - GetNextBitsOrBreak(bits, gmask, base); - } - } - else - { - pshared = *ppshared++; - pshared->refcnt = 1 << (g + b); - for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) - { - if ((*cptr & basemask) == common) - { - pmap->red[*cptr].co.shco.green = pshared; - } - } - } - basemask = ~(rmask | gmask); - common = *pptr & basemask; - if (bmask) - { - bits = 0; - base = lowbit (bmask); - while(1) - { - pshared = *ppshared++; - pshared->refcnt = 1 << (r + g); - for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) - { - if ((*cptr & basemask) == (common | bits)) - { - pmap->red[*cptr].co.shco.blue = pshared; - } - } - GetNextBitsOrBreak(bits, bmask, base); - } - } - else - { - pshared = *ppshared++; - pshared->refcnt = 1 << (g + b); - for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) - { - if ((*cptr & basemask) == common) - { - pmap->red[*cptr].co.shco.blue = pshared; - } - } - } + for (z = npixShared; --z >= 0;) { + if (!(ppshared[z] = malloc(sizeof(SHAREDCOLOR)))) { + for (z++; z < npixShared; z++) + free(ppshared[z]); + free(psharedList); + return FALSE; + } + } + for (pptr = ppix, npix = c; --npix >= 0; pptr++) { + basemask = ~(gmask | bmask); + common = *pptr & basemask; + if (rmask) { + bits = 0; + base = lowbit(rmask); + while (1) { + pshared = *ppshared++; + pshared->refcnt = 1 << (g + b); + for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) { + if ((*cptr & basemask) == (common | bits)) { + pmap->red[*cptr].fShared = TRUE; + pmap->red[*cptr].co.shco.red = pshared; + } + } + GetNextBitsOrBreak(bits, rmask, base); + } + } + else { + pshared = *ppshared++; + pshared->refcnt = 1 << (g + b); + for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) { + if ((*cptr & basemask) == common) { + pmap->red[*cptr].fShared = TRUE; + pmap->red[*cptr].co.shco.red = pshared; + } + } + } + basemask = ~(rmask | bmask); + common = *pptr & basemask; + if (gmask) { + bits = 0; + base = lowbit(gmask); + while (1) { + pshared = *ppshared++; + pshared->refcnt = 1 << (r + b); + for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) { + if ((*cptr & basemask) == (common | bits)) { + pmap->red[*cptr].co.shco.green = pshared; + } + } + GetNextBitsOrBreak(bits, gmask, base); + } + } + else { + pshared = *ppshared++; + pshared->refcnt = 1 << (g + b); + for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) { + if ((*cptr & basemask) == common) { + pmap->red[*cptr].co.shco.green = pshared; + } + } + } + basemask = ~(rmask | gmask); + common = *pptr & basemask; + if (bmask) { + bits = 0; + base = lowbit(bmask); + while (1) { + pshared = *ppshared++; + pshared->refcnt = 1 << (r + g); + for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) { + if ((*cptr & basemask) == (common | bits)) { + pmap->red[*cptr].co.shco.blue = pshared; + } + } + GetNextBitsOrBreak(bits, bmask, base); + } + } + else { + pshared = *ppshared++; + pshared->refcnt = 1 << (g + b); + for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++) { + if ((*cptr & basemask) == common) { + pmap->red[*cptr].co.shco.blue = pshared; + } + } + } } free(psharedList); return TRUE; } - /** FreeColors * Free colors and/or cells (probably slow for large numbers) */ int -FreeColors (ColormapPtr pmap, int client, int count, Pixel *pixels, Pixel mask) +FreeColors(ColormapPtr pmap, int client, int count, Pixel * pixels, Pixel mask) { - int rval, result, class; - Pixel rmask; + int rval, result, class; + Pixel rmask; class = pmap->class; if (pmap->flags & AllAllocated) - return BadAccess; - if ((class | DynamicClass) == DirectColor) - { - rmask = mask & RGBMASK(pmap->pVisual); + return BadAccess; + if ((class | DynamicClass) == DirectColor) { + rmask = mask & RGBMASK(pmap->pVisual); result = FreeCo(pmap, client, REDMAP, count, pixels, - mask & pmap->pVisual->redMask); - /* If any of the three calls fails, we must report that, if more - * than one fails, it's ok that we report the last one */ + mask & pmap->pVisual->redMask); + /* If any of the three calls fails, we must report that, if more + * than one fails, it's ok that we report the last one */ rval = FreeCo(pmap, client, GREENMAP, count, pixels, - mask & pmap->pVisual->greenMask); - if(rval != Success) - result = rval; - rval = FreeCo(pmap, client, BLUEMAP, count, pixels, - mask & pmap->pVisual->blueMask); - if(rval != Success) - result = rval; - } - else - { - rmask = mask & ((((Pixel)1) << pmap->pVisual->nplanes) - 1); + mask & pmap->pVisual->greenMask); + if (rval != Success) + result = rval; + rval = FreeCo(pmap, client, BLUEMAP, count, pixels, + mask & pmap->pVisual->blueMask); + if (rval != Success) + result = rval; + } + else { + rmask = mask & ((((Pixel) 1) << pmap->pVisual->nplanes) - 1); result = FreeCo(pmap, client, PSEUDOMAP, count, pixels, rmask); } - if ((mask != rmask) && count) - { - clients[client]->errorValue = *pixels | mask; - result = BadValue; + if ((mask != rmask) && count) { + clients[client]->errorValue = *pixels | mask; + result = BadValue; } /* XXX should worry about removing any RT_CMAPENTRY resource */ return result; @@ -2262,435 +2104,381 @@ FreeColors (ColormapPtr pmap, int client, int count, Pixel *pixels, Pixel mask) * \param mask mask client gave us */ static int -FreeCo (ColormapPtr pmap, int client, int color, int npixIn, Pixel *ppixIn, Pixel mask) +FreeCo(ColormapPtr pmap, int client, int color, int npixIn, Pixel * ppixIn, + Pixel mask) { - Pixel *ppixClient, pixTest; - int npixClient, npixNew, npix; - Pixel bits, base, cmask, rgbbad; - Pixel *pptr, *cptr; - int n, zapped; - int errVal = Success; - int offset, numents; + Pixel *ppixClient, pixTest; + int npixClient, npixNew, npix; + Pixel bits, base, cmask, rgbbad; + Pixel *pptr, *cptr; + int n, zapped; + int errVal = Success; + int offset, numents; if (npixIn == 0) return errVal; bits = 0; zapped = 0; - base = lowbit (mask); - - switch(color) - { - case REDMAP: - cmask = pmap->pVisual->redMask; - rgbbad = ~RGBMASK(pmap->pVisual); - offset = pmap->pVisual->offsetRed; - numents = (cmask >> offset) + 1; - ppixClient = pmap->clientPixelsRed[client]; - npixClient = pmap->numPixelsRed[client]; - break; - case GREENMAP: - cmask = pmap->pVisual->greenMask; - rgbbad = ~RGBMASK(pmap->pVisual); - offset = pmap->pVisual->offsetGreen; - numents = (cmask >> offset) + 1; - ppixClient = pmap->clientPixelsGreen[client]; - npixClient = pmap->numPixelsGreen[client]; - break; - case BLUEMAP: - cmask = pmap->pVisual->blueMask; - rgbbad = ~RGBMASK(pmap->pVisual); - offset = pmap->pVisual->offsetBlue; - numents = (cmask >> offset) + 1; - ppixClient = pmap->clientPixelsBlue[client]; - npixClient = pmap->numPixelsBlue[client]; - break; - default: /* so compiler can see that everything gets initialized */ - case PSEUDOMAP: - cmask = ~((Pixel)0); - rgbbad = 0; - offset = 0; - numents = pmap->pVisual->ColormapEntries; - ppixClient = pmap->clientPixelsRed[client]; - npixClient = pmap->numPixelsRed[client]; - break; + base = lowbit(mask); + + switch (color) { + case REDMAP: + cmask = pmap->pVisual->redMask; + rgbbad = ~RGBMASK(pmap->pVisual); + offset = pmap->pVisual->offsetRed; + numents = (cmask >> offset) + 1; + ppixClient = pmap->clientPixelsRed[client]; + npixClient = pmap->numPixelsRed[client]; + break; + case GREENMAP: + cmask = pmap->pVisual->greenMask; + rgbbad = ~RGBMASK(pmap->pVisual); + offset = pmap->pVisual->offsetGreen; + numents = (cmask >> offset) + 1; + ppixClient = pmap->clientPixelsGreen[client]; + npixClient = pmap->numPixelsGreen[client]; + break; + case BLUEMAP: + cmask = pmap->pVisual->blueMask; + rgbbad = ~RGBMASK(pmap->pVisual); + offset = pmap->pVisual->offsetBlue; + numents = (cmask >> offset) + 1; + ppixClient = pmap->clientPixelsBlue[client]; + npixClient = pmap->numPixelsBlue[client]; + break; + default: /* so compiler can see that everything gets initialized */ + case PSEUDOMAP: + cmask = ~((Pixel) 0); + rgbbad = 0; + offset = 0; + numents = pmap->pVisual->ColormapEntries; + ppixClient = pmap->clientPixelsRed[client]; + npixClient = pmap->numPixelsRed[client]; + break; } - /* zap all pixels which match */ - while (1) - { + while (1) { /* go through pixel list */ - for (pptr = ppixIn, n = npixIn; --n >= 0; pptr++) - { - pixTest = ((*pptr | bits) & cmask) >> offset; - if ((pixTest >= numents) || (*pptr & rgbbad)) - { - clients[client]->errorValue = *pptr | bits; - errVal = BadValue; - continue; - } - - /* find match in client list */ - for (cptr = ppixClient, npix = npixClient; - --npix >= 0 && *cptr != pixTest; - cptr++) ; - - if (npix >= 0) - { - if (pmap->class & DynamicClass) - { - FreeCell(pmap, pixTest, color); - } - *cptr = ~((Pixel)0); - zapped++; - } - else - errVal = BadAccess; - } + for (pptr = ppixIn, n = npixIn; --n >= 0; pptr++) { + pixTest = ((*pptr | bits) & cmask) >> offset; + if ((pixTest >= numents) || (*pptr & rgbbad)) { + clients[client]->errorValue = *pptr | bits; + errVal = BadValue; + continue; + } + + /* find match in client list */ + for (cptr = ppixClient, npix = npixClient; + --npix >= 0 && *cptr != pixTest; cptr++); + + if (npix >= 0) { + if (pmap->class & DynamicClass) { + FreeCell(pmap, pixTest, color); + } + *cptr = ~((Pixel) 0); + zapped++; + } + else + errVal = BadAccess; + } /* generate next bits value */ - GetNextBitsOrBreak(bits, mask, base); + GetNextBitsOrBreak(bits, mask, base); } /* delete freed pixels from client pixel list */ - if (zapped) - { + if (zapped) { npixNew = npixClient - zapped; - if (npixNew) - { - /* Since the list can only get smaller, we can do a copy in - * place and then realloc to a smaller size */ - pptr = cptr = ppixClient; - - /* If we have all the new pixels, we don't have to examine the - * rest of the old ones */ - for(npix = 0; npix < npixNew; cptr++) - { - if (*cptr != ~((Pixel)0)) - { - *pptr++ = *cptr; - npix++; - } - } - pptr = (Pixel *)realloc(ppixClient, npixNew * sizeof(Pixel)); - if (pptr) - ppixClient = pptr; - npixClient = npixNew; + if (npixNew) { + /* Since the list can only get smaller, we can do a copy in + * place and then realloc to a smaller size */ + pptr = cptr = ppixClient; + + /* If we have all the new pixels, we don't have to examine the + * rest of the old ones */ + for (npix = 0; npix < npixNew; cptr++) { + if (*cptr != ~((Pixel) 0)) { + *pptr++ = *cptr; + npix++; + } + } + pptr = (Pixel *) realloc(ppixClient, npixNew * sizeof(Pixel)); + if (pptr) + ppixClient = pptr; + npixClient = npixNew; + } + else { + npixClient = 0; + free(ppixClient); + ppixClient = (Pixel *) NULL; + } + switch (color) { + case PSEUDOMAP: + case REDMAP: + pmap->clientPixelsRed[client] = ppixClient; + pmap->numPixelsRed[client] = npixClient; + break; + case GREENMAP: + pmap->clientPixelsGreen[client] = ppixClient; + pmap->numPixelsGreen[client] = npixClient; + break; + case BLUEMAP: + pmap->clientPixelsBlue[client] = ppixClient; + pmap->numPixelsBlue[client] = npixClient; + break; } - else - { - npixClient = 0; - free(ppixClient); - ppixClient = (Pixel *)NULL; - } - switch(color) - { - case PSEUDOMAP: - case REDMAP: - pmap->clientPixelsRed[client] = ppixClient; - pmap->numPixelsRed[client] = npixClient; - break; - case GREENMAP: - pmap->clientPixelsGreen[client] = ppixClient; - pmap->numPixelsGreen[client] = npixClient; - break; - case BLUEMAP: - pmap->clientPixelsBlue[client] = ppixClient; - pmap->numPixelsBlue[client] = npixClient; - break; - } } return errVal; } - - /* Redefine color values */ int -StoreColors (ColormapPtr pmap, int count, xColorItem *defs, ClientPtr client) +StoreColors(ColormapPtr pmap, int count, xColorItem * defs, ClientPtr client) { - Pixel pix; + Pixel pix; xColorItem *pdef; - EntryPtr pent, pentT, pentLast; - VisualPtr pVisual; - SHAREDCOLOR *pred, *pgreen, *pblue; - int n, ChgRed, ChgGreen, ChgBlue, idef; - int class, errVal = Success; - int ok; - + EntryPtr pent, pentT, pentLast; + VisualPtr pVisual; + SHAREDCOLOR *pred, *pgreen, *pblue; + int n, ChgRed, ChgGreen, ChgBlue, idef; + int class, errVal = Success; + int ok; class = pmap->class; - if(!(class & DynamicClass) && !(pmap->flags & BeingCreated)) - { - return BadAccess; + if (!(class & DynamicClass) && !(pmap->flags & BeingCreated)) { + return BadAccess; } pVisual = pmap->pVisual; idef = 0; - if((class | DynamicClass) == DirectColor) - { - int numred, numgreen, numblue; - Pixel rgbbad; - - numred = NUMRED(pVisual); - numgreen = NUMGREEN(pVisual); - numblue = NUMBLUE(pVisual); - rgbbad = ~RGBMASK(pVisual); - for (pdef = defs, n = 0; n < count; pdef++, n++) - { - ok = TRUE; + if ((class | DynamicClass) == DirectColor) { + int numred, numgreen, numblue; + Pixel rgbbad; + + numred = NUMRED(pVisual); + numgreen = NUMGREEN(pVisual); + numblue = NUMBLUE(pVisual); + rgbbad = ~RGBMASK(pVisual); + for (pdef = defs, n = 0; n < count; pdef++, n++) { + ok = TRUE; (*pmap->pScreen->ResolveColor) - (&pdef->red, &pdef->green, &pdef->blue, pmap->pVisual); - - if (pdef->pixel & rgbbad) - { - errVal = BadValue; - client->errorValue = pdef->pixel; - continue; - } - pix = (pdef->pixel & pVisual->redMask) >> pVisual->offsetRed; - if (pix >= numred) - { - errVal = BadValue; - ok = FALSE; - } - else if (pmap->red[pix].refcnt != AllocPrivate) - { - errVal = BadAccess; - ok = FALSE; - } - else if (pdef->flags & DoRed) - { - pmap->red[pix].co.local.red = pdef->red; - } - else - { - pdef->red = pmap->red[pix].co.local.red; - } - - pix = (pdef->pixel & pVisual->greenMask) >> pVisual->offsetGreen; - if (pix >= numgreen) - { - errVal = BadValue; - ok = FALSE; - } - else if (pmap->green[pix].refcnt != AllocPrivate) - { - errVal = BadAccess; - ok = FALSE; - } - else if (pdef->flags & DoGreen) - { - pmap->green[pix].co.local.green = pdef->green; - } - else - { - pdef->green = pmap->green[pix].co.local.green; - } - - pix = (pdef->pixel & pVisual->blueMask) >> pVisual->offsetBlue; - if (pix >= numblue) - { - errVal = BadValue; - ok = FALSE; - } - else if (pmap->blue[pix].refcnt != AllocPrivate) - { - errVal = BadAccess; - ok = FALSE; - } - else if (pdef->flags & DoBlue) - { - pmap->blue[pix].co.local.blue = pdef->blue; - } - else - { - pdef->blue = pmap->blue[pix].co.local.blue; - } - /* If this is an o.k. entry, then it gets added to the list - * to be sent to the hardware. If not, skip it. Once we've - * skipped one, we have to copy all the others. - */ - if(ok) - { - if(idef != n) - defs[idef] = defs[n]; - idef++; - } else - client->errorValue = pdef->pixel; - } + (&pdef->red, &pdef->green, &pdef->blue, pmap->pVisual); + + if (pdef->pixel & rgbbad) { + errVal = BadValue; + client->errorValue = pdef->pixel; + continue; + } + pix = (pdef->pixel & pVisual->redMask) >> pVisual->offsetRed; + if (pix >= numred) { + errVal = BadValue; + ok = FALSE; + } + else if (pmap->red[pix].refcnt != AllocPrivate) { + errVal = BadAccess; + ok = FALSE; + } + else if (pdef->flags & DoRed) { + pmap->red[pix].co.local.red = pdef->red; + } + else { + pdef->red = pmap->red[pix].co.local.red; + } + + pix = (pdef->pixel & pVisual->greenMask) >> pVisual->offsetGreen; + if (pix >= numgreen) { + errVal = BadValue; + ok = FALSE; + } + else if (pmap->green[pix].refcnt != AllocPrivate) { + errVal = BadAccess; + ok = FALSE; + } + else if (pdef->flags & DoGreen) { + pmap->green[pix].co.local.green = pdef->green; + } + else { + pdef->green = pmap->green[pix].co.local.green; + } + + pix = (pdef->pixel & pVisual->blueMask) >> pVisual->offsetBlue; + if (pix >= numblue) { + errVal = BadValue; + ok = FALSE; + } + else if (pmap->blue[pix].refcnt != AllocPrivate) { + errVal = BadAccess; + ok = FALSE; + } + else if (pdef->flags & DoBlue) { + pmap->blue[pix].co.local.blue = pdef->blue; + } + else { + pdef->blue = pmap->blue[pix].co.local.blue; + } + /* If this is an o.k. entry, then it gets added to the list + * to be sent to the hardware. If not, skip it. Once we've + * skipped one, we have to copy all the others. + */ + if (ok) { + if (idef != n) + defs[idef] = defs[n]; + idef++; + } + else + client->errorValue = pdef->pixel; + } } - else - { - for (pdef = defs, n = 0; n < count; pdef++, n++) - { - - ok = TRUE; - if (pdef->pixel >= pVisual->ColormapEntries) - { - client->errorValue = pdef->pixel; - errVal = BadValue; - ok = FALSE; - } - else if (pmap->red[pdef->pixel].refcnt != AllocPrivate) - { - errVal = BadAccess; - ok = FALSE; - } - - /* If this is an o.k. entry, then it gets added to the list - * to be sent to the hardware. If not, skip it. Once we've - * skipped one, we have to copy all the others. - */ - if(ok) - { - if(idef != n) - defs[idef] = defs[n]; - idef++; - } - else - continue; + else { + for (pdef = defs, n = 0; n < count; pdef++, n++) { + + ok = TRUE; + if (pdef->pixel >= pVisual->ColormapEntries) { + client->errorValue = pdef->pixel; + errVal = BadValue; + ok = FALSE; + } + else if (pmap->red[pdef->pixel].refcnt != AllocPrivate) { + errVal = BadAccess; + ok = FALSE; + } + + /* If this is an o.k. entry, then it gets added to the list + * to be sent to the hardware. If not, skip it. Once we've + * skipped one, we have to copy all the others. + */ + if (ok) { + if (idef != n) + defs[idef] = defs[n]; + idef++; + } + else + continue; (*pmap->pScreen->ResolveColor) - (&pdef->red, &pdef->green, &pdef->blue, pmap->pVisual); - - pent = &pmap->red[pdef->pixel]; - - if(pdef->flags & DoRed) - { - if(pent->fShared) - { - pent->co.shco.red->color = pdef->red; - if (pent->co.shco.red->refcnt > 1) - ok = FALSE; - } - else - pent->co.local.red = pdef->red; - } - else - { - if(pent->fShared) - pdef->red = pent->co.shco.red->color; - else - pdef->red = pent->co.local.red; - } - if(pdef->flags & DoGreen) - { - if(pent->fShared) - { - pent->co.shco.green->color = pdef->green; - if (pent->co.shco.green->refcnt > 1) - ok = FALSE; - } - else - pent->co.local.green = pdef->green; - } - else - { - if(pent->fShared) - pdef->green = pent->co.shco.green->color; - else - pdef->green = pent->co.local.green; - } - if(pdef->flags & DoBlue) - { - if(pent->fShared) - { - pent->co.shco.blue->color = pdef->blue; - if (pent->co.shco.blue->refcnt > 1) - ok = FALSE; - } - else - pent->co.local.blue = pdef->blue; - } - else - { - if(pent->fShared) - pdef->blue = pent->co.shco.blue->color; - else - pdef->blue = pent->co.local.blue; - } - - if(!ok) - { + (&pdef->red, &pdef->green, &pdef->blue, pmap->pVisual); + + pent = &pmap->red[pdef->pixel]; + + if (pdef->flags & DoRed) { + if (pent->fShared) { + pent->co.shco.red->color = pdef->red; + if (pent->co.shco.red->refcnt > 1) + ok = FALSE; + } + else + pent->co.local.red = pdef->red; + } + else { + if (pent->fShared) + pdef->red = pent->co.shco.red->color; + else + pdef->red = pent->co.local.red; + } + if (pdef->flags & DoGreen) { + if (pent->fShared) { + pent->co.shco.green->color = pdef->green; + if (pent->co.shco.green->refcnt > 1) + ok = FALSE; + } + else + pent->co.local.green = pdef->green; + } + else { + if (pent->fShared) + pdef->green = pent->co.shco.green->color; + else + pdef->green = pent->co.local.green; + } + if (pdef->flags & DoBlue) { + if (pent->fShared) { + pent->co.shco.blue->color = pdef->blue; + if (pent->co.shco.blue->refcnt > 1) + ok = FALSE; + } + else + pent->co.local.blue = pdef->blue; + } + else { + if (pent->fShared) + pdef->blue = pent->co.shco.blue->color; + else + pdef->blue = pent->co.local.blue; + } + + if (!ok) { /* have to run through the colormap and change anybody who - * shares this value */ - pred = pent->co.shco.red; - pgreen = pent->co.shco.green; - pblue = pent->co.shco.blue; - ChgRed = pdef->flags & DoRed; - ChgGreen = pdef->flags & DoGreen; - ChgBlue = pdef->flags & DoBlue; - pentLast = pmap->red + pVisual->ColormapEntries; - - for(pentT = pmap->red; pentT < pentLast; pentT++) - { - if(pentT->fShared && (pentT != pent)) - { - xColorItem defChg; - - /* There are, alas, devices in this world too dumb - * to read their own hardware colormaps. Sick, but - * true. So we're going to be really nice and load - * the xColorItem with the proper value for all the - * fields. We will only set the flags for those - * fields that actually change. Smart devices can - * arrange to change only those fields. Dumb devices - * can rest assured that we have provided for them, - * and can change all three fields */ - - defChg.flags = 0; - if(ChgRed && pentT->co.shco.red == pred) - { - defChg.flags |= DoRed; - } - if(ChgGreen && pentT->co.shco.green == pgreen) - { - defChg.flags |= DoGreen; - } - if(ChgBlue && pentT->co.shco.blue == pblue) - { - defChg.flags |= DoBlue; - } - if(defChg.flags != 0) - { - defChg.pixel = pentT - pmap->red; - defChg.red = pentT->co.shco.red->color; - defChg.green = pentT->co.shco.green->color; - defChg.blue = pentT->co.shco.blue->color; - (*pmap->pScreen->StoreColors) (pmap, 1, &defChg); - } - } - } - - } - } + * shares this value */ + pred = pent->co.shco.red; + pgreen = pent->co.shco.green; + pblue = pent->co.shco.blue; + ChgRed = pdef->flags & DoRed; + ChgGreen = pdef->flags & DoGreen; + ChgBlue = pdef->flags & DoBlue; + pentLast = pmap->red + pVisual->ColormapEntries; + + for (pentT = pmap->red; pentT < pentLast; pentT++) { + if (pentT->fShared && (pentT != pent)) { + xColorItem defChg; + + /* There are, alas, devices in this world too dumb + * to read their own hardware colormaps. Sick, but + * true. So we're going to be really nice and load + * the xColorItem with the proper value for all the + * fields. We will only set the flags for those + * fields that actually change. Smart devices can + * arrange to change only those fields. Dumb devices + * can rest assured that we have provided for them, + * and can change all three fields */ + + defChg.flags = 0; + if (ChgRed && pentT->co.shco.red == pred) { + defChg.flags |= DoRed; + } + if (ChgGreen && pentT->co.shco.green == pgreen) { + defChg.flags |= DoGreen; + } + if (ChgBlue && pentT->co.shco.blue == pblue) { + defChg.flags |= DoBlue; + } + if (defChg.flags != 0) { + defChg.pixel = pentT - pmap->red; + defChg.red = pentT->co.shco.red->color; + defChg.green = pentT->co.shco.green->color; + defChg.blue = pentT->co.shco.blue->color; + (*pmap->pScreen->StoreColors) (pmap, 1, &defChg); + } + } + } + + } + } } /* Note that we use idef, the count of acceptable entries, and not * count, the count of proposed entries */ if (idef != 0) - ( *pmap->pScreen->StoreColors) (pmap, idef, defs); + (*pmap->pScreen->StoreColors) (pmap, idef, defs); return errVal; } int IsMapInstalled(Colormap map, WindowPtr pWin) { - Colormap *pmaps; - int imap, nummaps, found; + Colormap *pmaps; + int imap, nummaps, found; - pmaps = malloc(pWin->drawable.pScreen->maxInstalledCmaps*sizeof(Colormap)); - if(!pmaps) - return FALSE; + pmaps = + malloc(pWin->drawable.pScreen->maxInstalledCmaps * sizeof(Colormap)); + if (!pmaps) + return FALSE; nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps) (pWin->drawable.pScreen, pmaps); found = FALSE; - for(imap = 0; imap < nummaps; imap++) - { - if(pmaps[imap] == map) - { - found = TRUE; - break; - } + for (imap = 0; imap < nummaps; imap++) { + if (pmaps[imap] == map) { + found = TRUE; + break; + } } free(pmaps); return found; @@ -2701,8 +2489,8 @@ struct colormap_lookup_data { VisualPtr visuals; }; -static void _colormap_find_resource(pointer value, XID id, - pointer cdata) +static void +_colormap_find_resource(pointer value, XID id, pointer cdata) { struct colormap_lookup_data *cmap_data = cdata; VisualPtr visuals = cmap_data->visuals; @@ -2711,7 +2499,7 @@ static void _colormap_find_resource(pointer value, XID id, int j; if (pScreen != cmap->pScreen) - return; + return; j = cmap->pVisual - pScreen->visuals; cmap->pVisual = &visuals[j]; @@ -2720,8 +2508,7 @@ static void _colormap_find_resource(pointer value, XID id, /* something has realloced the visuals, instead of breaking ABI fix it up here - glx and compsite did this wrong */ Bool -ResizeVisualArray(ScreenPtr pScreen, int new_visual_count, - DepthPtr depth) +ResizeVisualArray(ScreenPtr pScreen, int new_visual_count, DepthPtr depth) { struct colormap_lookup_data cdata; int numVisuals; @@ -2732,7 +2519,8 @@ ResizeVisualArray(ScreenPtr pScreen, int new_visual_count, first_new_vid = depth->numVids; first_new_visual = pScreen->numVisuals; - vids = realloc(depth->vids, (depth->numVids + new_visual_count) * sizeof(XID)); + vids = + realloc(depth->vids, (depth->numVids + new_visual_count) * sizeof(XID)); if (!vids) return FALSE; @@ -2742,19 +2530,20 @@ ResizeVisualArray(ScreenPtr pScreen, int new_visual_count, numVisuals = pScreen->numVisuals + new_visual_count; visuals = realloc(pScreen->visuals, numVisuals * sizeof(VisualRec)); if (!visuals) { - return FALSE; + return FALSE; } cdata.visuals = visuals; cdata.pScreen = pScreen; - FindClientResourcesByType(serverClient, RT_COLORMAP, _colormap_find_resource, &cdata); + FindClientResourcesByType(serverClient, RT_COLORMAP, + _colormap_find_resource, &cdata); pScreen->visuals = visuals; for (i = 0; i < new_visual_count; i++) { - vid = FakeClientID(0); - pScreen->visuals[first_new_visual + i].vid = vid; - vids[first_new_vid + i] = vid; + vid = FakeClientID(0); + pScreen->visuals[first_new_visual + i].vid = vid; + vids[first_new_vid + i] = vid; } depth->numVids += new_visual_count; diff --git a/xorg-server/dix/cursor.c b/xorg-server/dix/cursor.c index 6bff44723..1ee127ac5 100644 --- a/xorg-server/dix/cursor.c +++ b/xorg-server/dix/cursor.c @@ -22,7 +22,6 @@ 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 @@ -45,8 +44,6 @@ SOFTWARE. ******************************************************************/ - - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #endif @@ -70,40 +67,36 @@ typedef struct _GlyphShare { struct _GlyphShare *next; } GlyphShare, *GlyphSharePtr; -static GlyphSharePtr sharedGlyphs = (GlyphSharePtr)NULL; +static GlyphSharePtr sharedGlyphs = (GlyphSharePtr) NULL; DevScreenPrivateKeyRec cursorScreenDevPriv; #ifdef XFIXES -static CARD32 cursorSerial; +static CARD32 cursorSerial; #endif static void FreeCursorBits(CursorBitsPtr bits) { if (--bits->refcnt > 0) - return; + return; free(bits->source); free(bits->mask); #ifdef ARGB_CURSOR free(bits->argb); #endif dixFiniPrivates(bits, PRIVATE_CURSOR_BITS); - if (bits->refcnt == 0) - { - GlyphSharePtr *prev, this; - - for (prev = &sharedGlyphs; - (this = *prev) && (this->bits != bits); - prev = &this->next) - ; - if (this) - { - *prev = this->next; - CloseFont(this->font, (Font)0); - free(this); - } - free(bits); + if (bits->refcnt == 0) { + GlyphSharePtr *prev, this; + + for (prev = &sharedGlyphs; + (this = *prev) && (this->bits != bits); prev = &this->next); + if (this) { + *prev = this->next; + CloseFont(this->font, (Font) 0); + free(this); + } + free(bits); } } @@ -115,27 +108,25 @@ FreeCursorBits(CursorBitsPtr bits) int FreeCursor(pointer value, XID cid) { - int nscr; - CursorPtr pCurs = (CursorPtr)value; + int nscr; + CursorPtr pCurs = (CursorPtr) value; - ScreenPtr pscr; - DeviceIntPtr pDev = NULL; /* unused anyway */ + ScreenPtr pscr; + DeviceIntPtr pDev = NULL; /* unused anyway */ - if ( --pCurs->refcnt != 0) - return Success; + if (--pCurs->refcnt != 0) + return Success; - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) - { - pscr = screenInfo.screens[nscr]; - (void)( *pscr->UnrealizeCursor)(pDev, pscr, pCurs); + for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { + pscr = screenInfo.screens[nscr]; + (void) (*pscr->UnrealizeCursor) (pDev, pscr, pCurs); } FreeCursorBits(pCurs->bits); dixFiniPrivates(pCurs, PRIVATE_CURSOR); - free( pCurs); + free(pCurs); return Success; } - /* * We check for empty cursors so that we won't have to display them */ @@ -146,15 +137,17 @@ CheckForEmptyMask(CursorBitsPtr bits) int n = BitmapBytePad(bits->width) * bits->height; bits->emptyMask = FALSE; - while(n--) - if(*(msk++) != 0) return; + while (n--) + if (*(msk++) != 0) + return; #ifdef ARGB_CURSOR - if (bits->argb) - { - CARD32 *argb = bits->argb; - n = bits->width * bits->height; - while (n--) - if (*argb++ & 0xff000000) return; + if (bits->argb) { + CARD32 *argb = bits->argb; + + n = bits->width * bits->height; + while (n--) + if (*argb++ & 0xff000000) + return; } #endif bits->emptyMask = TRUE; @@ -171,43 +164,37 @@ static int RealizeCursorAllScreens(CursorPtr pCurs) { DeviceIntPtr pDev; - ScreenPtr pscr; + ScreenPtr pscr; int nscr; - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) - { + for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { pscr = screenInfo.screens[nscr]; - for (pDev = inputInfo.devices; pDev; pDev = pDev->next) - { - if (DevHasCursor(pDev)) - { - if (!( *pscr->RealizeCursor)(pDev, pscr, pCurs)) - { + for (pDev = inputInfo.devices; pDev; pDev = pDev->next) { + if (DevHasCursor(pDev)) { + if (!(*pscr->RealizeCursor) (pDev, pscr, pCurs)) { /* Realize failed for device pDev on screen pscr. * We have to assume that for all devices before, realize * worked. We need to rollback all devices so far on the * current screen and then all devices on previous * screens. */ - DeviceIntPtr pDevIt = inputInfo.devices; /*dev iterator*/ - while(pDevIt && pDevIt != pDev) - { + DeviceIntPtr pDevIt = inputInfo.devices; /*dev iterator */ + + while (pDevIt && pDevIt != pDev) { if (DevHasCursor(pDevIt)) - ( *pscr->UnrealizeCursor)(pDevIt, pscr, pCurs); + (*pscr->UnrealizeCursor) (pDevIt, pscr, pCurs); pDevIt = pDevIt->next; } - while (--nscr >= 0) - { + while (--nscr >= 0) { pscr = screenInfo.screens[nscr]; /* now unrealize all devices on previous screens */ pDevIt = inputInfo.devices; - while (pDevIt) - { + while (pDevIt) { if (DevHasCursor(pDevIt)) - ( *pscr->UnrealizeCursor)(pDevIt, pscr, pCurs); + (*pscr->UnrealizeCursor) (pDevIt, pscr, pCurs); pDevIt = pDevIt->next; } - ( *pscr->UnrealizeCursor)(pDev, pscr, pCurs); + (*pscr->UnrealizeCursor) (pDev, pscr, pCurs); } return BadAlloc; } @@ -218,7 +205,6 @@ RealizeCursorAllScreens(CursorPtr pCurs) return Success; } - /** * does nothing about the resource table, just creates the data structure. * does not copy the src and mask bits @@ -229,24 +215,24 @@ RealizeCursorAllScreens(CursorPtr pCurs) */ int AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits, - CARD32 *argb, CursorMetricPtr cm, - unsigned foreRed, unsigned foreGreen, unsigned foreBlue, - unsigned backRed, unsigned backGreen, unsigned backBlue, - CursorPtr *ppCurs, ClientPtr client, XID cid) + CARD32 *argb, CursorMetricPtr cm, + unsigned foreRed, unsigned foreGreen, unsigned foreBlue, + unsigned backRed, unsigned backGreen, unsigned backBlue, + CursorPtr *ppCurs, ClientPtr client, XID cid) { - CursorBitsPtr bits; - CursorPtr pCurs; + CursorBitsPtr bits; + CursorPtr pCurs; int rc; *ppCurs = NULL; - pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1); + pCurs = (CursorPtr) calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1); if (!pCurs) - return BadAlloc; + return BadAlloc; - bits = (CursorBitsPtr)((char *)pCurs + CURSOR_REC_SIZE); + bits = (CursorBitsPtr) ((char *) pCurs + CURSOR_REC_SIZE); dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR); dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS) - bits->source = psrcbits; + bits->source = psrcbits; bits->mask = pmaskbits; #ifdef ARGB_CURSOR bits->argb = argb; @@ -255,7 +241,7 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits, bits->height = cm->height; bits->xhot = cm->xhot; bits->yhot = cm->yhot; - pCurs->refcnt = 1; + pCurs->refcnt = 1; bits->refcnt = -1; CheckForEmptyMask(bits); pCurs->bits = bits; @@ -276,7 +262,7 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits, /* security creation/labeling check */ rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, - pCurs, RT_NONE, NULL, DixCreateAccess); + pCurs, RT_NONE, NULL, DixCreateAccess); if (rc != Success) goto error; @@ -287,7 +273,7 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits, *ppCurs = pCurs; return Success; -error: + error: FreeCursorBits(bits); dixFiniPrivates(pCurs, PRIVATE_CURSOR); free(pCurs); @@ -297,142 +283,124 @@ error: int AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, - unsigned foreRed, unsigned foreGreen, unsigned foreBlue, - unsigned backRed, unsigned backGreen, unsigned backBlue, - CursorPtr *ppCurs, ClientPtr client, XID cid) + unsigned foreRed, unsigned foreGreen, unsigned foreBlue, + unsigned backRed, unsigned backGreen, unsigned backBlue, + CursorPtr *ppCurs, ClientPtr client, XID cid) { - FontPtr sourcefont, maskfont; - unsigned char *srcbits; - unsigned char *mskbits; + FontPtr sourcefont, maskfont; + unsigned char *srcbits; + unsigned char *mskbits; CursorMetricRec cm; int rc; - CursorBitsPtr bits; - CursorPtr pCurs; + CursorBitsPtr bits; + CursorPtr pCurs; GlyphSharePtr pShare; - rc = dixLookupResourceByType((pointer *)&sourcefont, source, RT_FONT, client, - DixUseAccess); - if (rc != Success) - { - client->errorValue = source; - return rc; + rc = dixLookupResourceByType((pointer *) &sourcefont, source, RT_FONT, + client, DixUseAccess); + if (rc != Success) { + client->errorValue = source; + return rc; } - rc = dixLookupResourceByType((pointer *)&maskfont, mask, RT_FONT, client, - DixUseAccess); - if (rc != Success && mask != None) - { - client->errorValue = mask; - return rc; + rc = dixLookupResourceByType((pointer *) &maskfont, mask, RT_FONT, client, + DixUseAccess); + if (rc != Success && mask != None) { + client->errorValue = mask; + return rc; } if (sourcefont != maskfont) - pShare = (GlyphSharePtr)NULL; - else - { - for (pShare = sharedGlyphs; - pShare && - ((pShare->font != sourcefont) || - (pShare->sourceChar != sourceChar) || - (pShare->maskChar != maskChar)); - pShare = pShare->next) - ; + pShare = (GlyphSharePtr) NULL; + else { + for (pShare = sharedGlyphs; + pShare && + ((pShare->font != sourcefont) || + (pShare->sourceChar != sourceChar) || + (pShare->maskChar != maskChar)); pShare = pShare->next); } - if (pShare) - { - pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE, 1); - if (!pCurs) - return BadAlloc; - dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR); - bits = pShare->bits; - bits->refcnt++; + if (pShare) { + pCurs = (CursorPtr) calloc(CURSOR_REC_SIZE, 1); + if (!pCurs) + return BadAlloc; + dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR); + bits = pShare->bits; + bits->refcnt++; } - else - { - if (!CursorMetricsFromGlyph(sourcefont, sourceChar, &cm)) - { - client->errorValue = sourceChar; - return BadValue; - } - if (!maskfont) - { - long n; - unsigned char *mskptr; - - n = BitmapBytePad(cm.width)*(long)cm.height; - mskptr = mskbits = malloc(n); - if (!mskptr) - return BadAlloc; - while (--n >= 0) - *mskptr++ = ~0; - } - else - { - if (!CursorMetricsFromGlyph(maskfont, maskChar, &cm)) - { - client->errorValue = maskChar; - return BadValue; - } - if ((rc = ServerBitsFromGlyph(maskfont, maskChar, &cm, &mskbits))) - return rc; - } - if ((rc = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits))) - { - free(mskbits); - return rc; - } - if (sourcefont != maskfont) - { - pCurs = - (CursorPtr)calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1); - if (pCurs) - bits = (CursorBitsPtr)((char *)pCurs + CURSOR_REC_SIZE); - else - bits = (CursorBitsPtr)NULL; - } - else - { - pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE, 1); - if (pCurs) - bits = (CursorBitsPtr)calloc(CURSOR_BITS_SIZE, 1); - else - bits = (CursorBitsPtr)NULL; - } - if (!bits) - { - free(pCurs); - free(mskbits); - free(srcbits); - return BadAlloc; - } - dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR); - dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS); - bits->source = srcbits; - bits->mask = mskbits; + else { + if (!CursorMetricsFromGlyph(sourcefont, sourceChar, &cm)) { + client->errorValue = sourceChar; + return BadValue; + } + if (!maskfont) { + long n; + unsigned char *mskptr; + + n = BitmapBytePad(cm.width) * (long) cm.height; + mskptr = mskbits = malloc(n); + if (!mskptr) + return BadAlloc; + while (--n >= 0) + *mskptr++ = ~0; + } + else { + if (!CursorMetricsFromGlyph(maskfont, maskChar, &cm)) { + client->errorValue = maskChar; + return BadValue; + } + if ((rc = ServerBitsFromGlyph(maskfont, maskChar, &cm, &mskbits))) + return rc; + } + if ((rc = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits))) { + free(mskbits); + return rc; + } + if (sourcefont != maskfont) { + pCurs = (CursorPtr) calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1); + if (pCurs) + bits = (CursorBitsPtr) ((char *) pCurs + CURSOR_REC_SIZE); + else + bits = (CursorBitsPtr) NULL; + } + else { + pCurs = (CursorPtr) calloc(CURSOR_REC_SIZE, 1); + if (pCurs) + bits = (CursorBitsPtr) calloc(CURSOR_BITS_SIZE, 1); + else + bits = (CursorBitsPtr) NULL; + } + if (!bits) { + free(pCurs); + free(mskbits); + free(srcbits); + return BadAlloc; + } + dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR); + dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS); + bits->source = srcbits; + bits->mask = mskbits; #ifdef ARGB_CURSOR - bits->argb = 0; + bits->argb = 0; #endif - bits->width = cm.width; - bits->height = cm.height; - bits->xhot = cm.xhot; - bits->yhot = cm.yhot; - if (sourcefont != maskfont) - bits->refcnt = -1; - else - { - bits->refcnt = 1; - pShare = malloc(sizeof(GlyphShare)); - if (!pShare) - { - FreeCursorBits(bits); - return BadAlloc; - } - pShare->font = sourcefont; - sourcefont->refcnt++; - pShare->sourceChar = sourceChar; - pShare->maskChar = maskChar; - pShare->bits = bits; - pShare->next = sharedGlyphs; - sharedGlyphs = pShare; - } + bits->width = cm.width; + bits->height = cm.height; + bits->xhot = cm.xhot; + bits->yhot = cm.yhot; + if (sourcefont != maskfont) + bits->refcnt = -1; + else { + bits->refcnt = 1; + pShare = malloc(sizeof(GlyphShare)); + if (!pShare) { + FreeCursorBits(bits); + return BadAlloc; + } + pShare->font = sourcefont; + sourcefont->refcnt++; + pShare->sourceChar = sourceChar; + pShare->maskChar = maskChar; + pShare->bits = bits; + pShare->next = sharedGlyphs; + sharedGlyphs = pShare; + } } CheckForEmptyMask(bits); @@ -455,7 +423,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, /* security creation/labeling check */ rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, - pCurs, RT_NONE, NULL, DixCreateAccess); + pCurs, RT_NONE, NULL, DixCreateAccess); if (rc != Success) goto error; @@ -466,7 +434,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, *ppCurs = pCurs; return Success; -error: + error: FreeCursorBits(bits); dixFiniPrivates(pCurs, PRIVATE_CURSOR); free(pCurs); @@ -486,27 +454,27 @@ error: CursorPtr CreateRootCursor(char *unused1, unsigned int unused2) { - CursorPtr curs; - FontPtr cursorfont; - int err; - XID fontID; + CursorPtr curs; + FontPtr cursorfont; + int err; + XID fontID; fontID = FakeClientID(0); err = OpenFont(serverClient, fontID, FontLoadAll | FontOpenSync, - (unsigned)strlen(defaultCursorFont), defaultCursorFont); + (unsigned) strlen(defaultCursorFont), defaultCursorFont); if (err != Success) - return NullCursor; + return NullCursor; - err = dixLookupResourceByType((pointer *)&cursorfont, fontID, RT_FONT, - serverClient, DixReadAccess); + err = dixLookupResourceByType((pointer *) &cursorfont, fontID, RT_FONT, + serverClient, DixReadAccess); if (err != Success) - return NullCursor; + return NullCursor; if (AllocGlyphCursor(fontID, 0, fontID, 1, 0, 0, 0, ~0, ~0, ~0, - &curs, serverClient, (XID)0) != Success) - return NullCursor; + &curs, serverClient, (XID) 0) != Success) + return NullCursor; - if (!AddResource(FakeClientID(0), RT_CURSOR, (pointer)curs)) - return NullCursor; + if (!AddResource(FakeClientID(0), RT_CURSOR, (pointer) curs)) + return NullCursor; return curs; } diff --git a/xorg-server/dix/devices.c b/xorg-server/dix/devices.c index 7478ad67a..600f8b738 100644 --- a/xorg-server/dix/devices.c +++ b/xorg-server/dix/devices.c @@ -22,7 +22,6 @@ 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 @@ -45,8 +44,6 @@ SOFTWARE. ********************************************************/ - - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #endif @@ -82,11 +79,12 @@ SOFTWARE. #include <pixman.h> #include "exglobals.h" #include "exevents.h" -#include "xiquerydevice.h" /* for SizeDeviceClasses */ +#include "xiquerydevice.h" /* for SizeDeviceClasses */ #include "xiproperty.h" -#include "enterleave.h" /* for EnterWindow() */ +#include "enterleave.h" /* for EnterWindow() */ #include "xserver-properties.h" -#include "xichangehierarchy.h" /* For XISendDeviceHierarchyEvent */ +#include "xichangehierarchy.h" /* For XISendDeviceHierarchyEvent */ +#include "syncsrv.h" /** @file * This file handles input device-related stuff. @@ -122,8 +120,8 @@ DeviceSetTransform(DeviceIntPtr dev, float *transform) scale.m[1][2] = dev->valuator->axes[1].min_value; /* transform */ - for (y=0; y<3; y++) - for (x=0; x<3; x++) + for (y = 0; y < 3; y++) + for (x = 0; x < 3; x++) dev->transform.m[y][x] = *transform++; pixman_f_transform_multiply(&dev->transform, &scale, &dev->transform); @@ -143,33 +141,31 @@ static int DeviceSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, BOOL checkonly) { - if (property == XIGetKnownProperty(XI_PROP_ENABLED)) - { + if (property == XIGetKnownProperty(XI_PROP_ENABLED)) { if (prop->format != 8 || prop->type != XA_INTEGER || prop->size != 1) return BadValue; /* Don't allow disabling of VCP/VCK */ - if ((dev == inputInfo.pointer || dev == inputInfo.keyboard) && - !(*(CARD8*)prop->data)) + if ((dev == inputInfo.pointer ||dev == + inputInfo.keyboard) &&!(*(CARD8 *) prop->data)) return BadAccess; - if (!checkonly) - { - if ((*((CARD8*)prop->data)) && !dev->enabled) + if (!checkonly) { + if ((*((CARD8 *) prop->data)) && !dev->enabled) EnableDevice(dev, TRUE); - else if (!(*((CARD8*)prop->data)) && dev->enabled) + else if (!(*((CARD8 *) prop->data)) && dev->enabled) DisableDevice(dev, TRUE); } - } else if (property == XIGetKnownProperty(XI_PROP_TRANSFORM)) - { - float *f = (float*)prop->data; + } + else if (property == XIGetKnownProperty(XI_PROP_TRANSFORM)) { + float *f = (float *) prop->data; int i; if (prop->format != 32 || prop->size != 9 || prop->type != XIGetKnownProperty(XATOM_FLOAT)) return BadValue; - for (i=0; i<9; i++) + for (i = 0; i < 9; i++) if (!isfinite(f[i])) return BadValue; @@ -199,8 +195,7 @@ PairDevices(ClientPtr client, DeviceIntPtr ptr, DeviceIntPtr kbd) if (ptr->spriteInfo->paired) return BadDevice; - if (kbd->spriteInfo->spriteOwner) - { + if (kbd->spriteInfo->spriteOwner) { free(kbd->spriteInfo->sprite); kbd->spriteInfo->sprite = NULL; kbd->spriteInfo->spriteOwner = FALSE; @@ -212,7 +207,6 @@ PairDevices(ClientPtr client, DeviceIntPtr ptr, DeviceIntPtr kbd) return Success; } - /** * Find and return the next unpaired MD pointer device. */ @@ -220,10 +214,10 @@ static DeviceIntPtr NextFreePointerDevice(void) { DeviceIntPtr dev; + for (dev = inputInfo.devices; dev; dev = dev->next) if (IsMaster(dev) && - dev->spriteInfo->spriteOwner && - !dev->spriteInfo->paired) + dev->spriteInfo->spriteOwner && !dev->spriteInfo->paired) return dev; return NULL; } @@ -238,7 +232,7 @@ NextFreePointerDevice(void) DeviceIntPtr AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart) { - DeviceIntPtr dev, *prev; /* not a typo */ + DeviceIntPtr dev, *prev; /* not a typo */ DeviceIntPtr devtmp; int devid; char devind[MAXDEVICES]; @@ -246,21 +240,24 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart) float transform[9]; /* Find next available id, 0 and 1 are reserved */ - memset(devind, 0, sizeof(char)*MAXDEVICES); + memset(devind, 0, sizeof(char) * MAXDEVICES); for (devtmp = inputInfo.devices; devtmp; devtmp = devtmp->next) - devind[devtmp->id]++; + devind[devtmp->id]++; for (devtmp = inputInfo.off_devices; devtmp; devtmp = devtmp->next) - devind[devtmp->id]++; - for (devid = 2; devid < MAXDEVICES && devind[devid]; devid++) - ; + devind[devtmp->id]++; + for (devid = 2; devid < MAXDEVICES && devind[devid]; devid++); if (devid >= MAXDEVICES) - return (DeviceIntPtr)NULL; - dev = _dixAllocateObjectWithPrivates(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec), - sizeof(DeviceIntRec) + sizeof(SpriteInfoRec), - offsetof(DeviceIntRec, devPrivates), PRIVATE_DEVICE); + return (DeviceIntPtr) NULL; + dev = + _dixAllocateObjectWithPrivates(sizeof(DeviceIntRec) + + sizeof(SpriteInfoRec), + sizeof(DeviceIntRec) + + sizeof(SpriteInfoRec), + offsetof(DeviceIntRec, devPrivates), + PRIVATE_DEVICE); if (!dev) - return (DeviceIntPtr)NULL; + return (DeviceIntPtr) NULL; dev->last.scroll = NULL; dev->last.touches = NULL; @@ -283,27 +280,26 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart) dev->coreEvents = TRUE; /* sprite defaults */ - dev->spriteInfo = (SpriteInfoPtr)&dev[1]; + dev->spriteInfo = (SpriteInfoPtr) & dev[1]; /* security creation/labeling check */ if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixCreateAccess)) { - free(dev); - return NULL; + free(dev); + return NULL; } inputInfo.numDevices++; - for (prev = &inputInfo.off_devices; *prev; prev = &(*prev)->next) - ; + for (prev = &inputInfo.off_devices; *prev; prev = &(*prev)->next); *prev = dev; dev->next = NULL; enabled = FALSE; XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_ENABLED), - XA_INTEGER, 8, PropModeReplace, 1, &enabled, - FALSE); - XISetDevicePropertyDeletable(dev, XIGetKnownProperty(XI_PROP_ENABLED), FALSE); + XA_INTEGER, 8, PropModeReplace, 1, &enabled, FALSE); + XISetDevicePropertyDeletable(dev, XIGetKnownProperty(XI_PROP_ENABLED), + FALSE); /* unity matrix */ memset(transform, 0, sizeof(transform)); @@ -333,7 +329,7 @@ SendDevicePresenceEvent(int deviceid, int type) ev.deviceid = deviceid; dummyDev.id = XIAllDevices; SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask, - (xEvent*)&ev, 1); + (xEvent *) &ev, 1); } /** @@ -356,72 +352,68 @@ EnableDevice(DeviceIntPtr dev, BOOL sendevent) int ret; DeviceIntPtr other; BOOL enabled; - int flags[MAXDEVICES] = {0}; + int flags[MAXDEVICES] = { 0 }; for (prev = &inputInfo.off_devices; - *prev && (*prev != dev); - prev = &(*prev)->next) - ; + *prev && (*prev != dev); prev = &(*prev)->next); - if (!dev->spriteInfo->sprite) - { - if (IsMaster(dev)) - { + if (!dev->spriteInfo->sprite) { + if (IsMaster(dev)) { /* Sprites appear on first root window, so we can hardcode it */ - if (dev->spriteInfo->spriteOwner) - { + if (dev->spriteInfo->spriteOwner) { InitializeSprite(dev, screenInfo.screens[0]->root); - /* mode doesn't matter */ + /* mode doesn't matter */ EnterWindow(dev, screenInfo.screens[0]->root, NotifyAncestor); } - else if ((other = NextFreePointerDevice()) == NULL) - { + else if ((other = NextFreePointerDevice()) == NULL) { ErrorF("[dix] cannot find pointer to pair with. " "This is a bug.\n"); return FALSE; - } else + } + else PairDevices(NULL, other, dev); - } else - { + } + else { if (dev->coreEvents) other = (IsPointerDevice(dev)) ? inputInfo.pointer : inputInfo.keyboard; else - other = NULL; /* auto-float non-core devices */ + other = NULL; /* auto-float non-core devices */ AttachDevice(NULL, dev, other); } } if ((*prev != dev) || !dev->inited || - ((ret = (*dev->deviceProc)(dev, DEVICE_ON)) != Success)) { + ((ret = (*dev->deviceProc) (dev, DEVICE_ON)) != Success)) { ErrorF("[dix] couldn't enable device %d\n", dev->id); - return FALSE; + return FALSE; } dev->enabled = TRUE; *prev = dev->next; - for (prev = &inputInfo.devices; *prev; prev = &(*prev)->next) - ; + for (prev = &inputInfo.devices; *prev; prev = &(*prev)->next); *prev = dev; dev->next = NULL; enabled = TRUE; XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_ENABLED), - XA_INTEGER, 8, PropModeReplace, 1, &enabled, - TRUE); + XA_INTEGER, 8, PropModeReplace, 1, &enabled, TRUE); SendDevicePresenceEvent(dev->id, DeviceEnabled); - if (sendevent) - { + if (sendevent) { flags[dev->id] |= XIDeviceEnabled; XISendDeviceHierarchyEvent(flags); } RecalculateMasterButtons(dev); + /* initialise an idle timer for this device*/ + dev->idle_counter = SyncInitDeviceIdleTime(dev); + return TRUE; } + /** * Switch a device off through the driver and push it onto the off_devices * list. A device will not send events while disabled. All clients are @@ -438,57 +430,49 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent) { DeviceIntPtr *prev, other; BOOL enabled; - int flags[MAXDEVICES] = {0}; + int flags[MAXDEVICES] = { 0 }; for (prev = &inputInfo.devices; - *prev && (*prev != dev); - prev = &(*prev)->next) - ; + *prev && (*prev != dev); prev = &(*prev)->next); if (*prev != dev) - return FALSE; + return FALSE; + + SyncRemoveDeviceIdleTime(dev->idle_counter); + dev->idle_counter = NULL; /* float attached devices */ - if (IsMaster(dev)) - { - for (other = inputInfo.devices; other; other = other->next) - { - if (!IsMaster(other) && GetMaster(other, MASTER_ATTACHED) == dev) - { + if (IsMaster(dev)) { + for (other = inputInfo.devices; other; other = other->next) { + if (!IsMaster(other) && GetMaster(other, MASTER_ATTACHED) == dev) { AttachDevice(NULL, other, NULL); flags[other->id] |= XISlaveDetached; } } } - else - { - for (other = inputInfo.devices; other; other = other->next) - { - if (IsMaster(other) && other->lastSlave == dev) - other->lastSlave = NULL; - } + else { + for (other = inputInfo.devices; other; other = other->next) { + if (IsMaster(other) && other->lastSlave == dev) + other->lastSlave = NULL; + } } - if (IsMaster(dev) && dev->spriteInfo->sprite) - { - for (other = inputInfo.devices; other; other = other->next) - { - if (other->spriteInfo->paired == dev) - { + if (IsMaster(dev) && dev->spriteInfo->sprite) { + for (other = inputInfo.devices; other; other = other->next) { + if (other->spriteInfo->paired == dev) { ErrorF("[dix] cannot disable device, still paired. " - "This is a bug. \n"); + "This is a bug. \n"); return FALSE; } } } - (void)(*dev->deviceProc)(dev, DEVICE_OFF); + (void) (*dev->deviceProc) (dev, DEVICE_OFF); dev->enabled = FALSE; /* now that the device is disabled, we can reset the signal handler's * last.slave */ OsBlockSignals(); - for (other = inputInfo.devices; other; other = other->next) - { + for (other = inputInfo.devices; other; other = other->next) { if (other->last.slave == dev) other->last.slave = NULL; } @@ -503,12 +487,10 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent) enabled = FALSE; XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_ENABLED), - XA_INTEGER, 8, PropModeReplace, 1, &enabled, - TRUE); + XA_INTEGER, 8, PropModeReplace, 1, &enabled, TRUE); SendDevicePresenceEvent(dev->id, DeviceDisabled); - if (sendevent) - { + if (sendevent) { flags[dev->id] = XIDeviceDisabled; XISendDeviceHierarchyEvent(flags); } @@ -548,9 +530,8 @@ ActivateDevice(DeviceIntPtr dev, BOOL sendevent) ret = BadAlloc; SendDevicePresenceEvent(dev->id, DeviceAdded); - if (sendevent) - { - int flags[MAXDEVICES] = {0}; + if (sendevent) { + int flags[MAXDEVICES] = { 0 }; flags[dev->id] = XISlaveAdded; XISendDeviceHierarchyEvent(flags); } @@ -570,7 +551,7 @@ CoreKeyboardBell(int volume, DeviceIntPtr pDev, pointer arg, int something) } static void -CoreKeyboardCtl(DeviceIntPtr pDev, KeybdCtrl *ctrl) +CoreKeyboardCtl(DeviceIntPtr pDev, KeybdCtrl * ctrl) { return; } @@ -585,8 +566,7 @@ CoreKeyboardProc(DeviceIntPtr pDev, int what) switch (what) { case DEVICE_INIT: if (!InitKeyboardDeviceStruct(pDev, NULL, CoreKeyboardBell, - CoreKeyboardCtl)) - { + CoreKeyboardCtl)) { ErrorF("Keyboard initialization failed. This could be a missing " "or incorrect setup of xkeyboard-config.\n"); return BadValue; @@ -614,8 +594,8 @@ CorePointerProc(DeviceIntPtr pDev, int what) #define NAXES 2 BYTE map[NBUTTONS + 1]; int i = 0; - Atom btn_labels[NBUTTONS] = {0}; - Atom axes_labels[NAXES] = {0}; + Atom btn_labels[NBUTTONS] = { 0 }; + Atom axes_labels[NAXES] = { 0 }; ScreenPtr scr = screenInfo.screens[0]; switch (what) { @@ -623,25 +603,25 @@ CorePointerProc(DeviceIntPtr pDev, int what) for (i = 1; i <= NBUTTONS; i++) map[i] = i; - btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT); - btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE); - btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT); - btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP); - btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN); - btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT); - btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT); - /* don't know about the rest */ - - axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X); - axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y); - - if (!InitPointerDeviceStruct((DevicePtr)pDev, map, NBUTTONS, btn_labels, - (PtrCtrlProcPtr)NoopDDA, - GetMotionHistorySize(), NAXES, axes_labels)) - { + btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT); + btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE); + btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT); + btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP); + btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN); + btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT); + btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT); + /* don't know about the rest */ + + axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X); + axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y); + + if (!InitPointerDeviceStruct + ((DevicePtr) pDev, map, NBUTTONS, btn_labels, + (PtrCtrlProcPtr) NoopDDA, GetMotionHistorySize(), NAXES, + axes_labels)) { ErrorF("Could not initialize device '%s'. Out of memory.\n", pDev->name); - return BadAlloc; /* IPDS only fails on allocs */ + return BadAlloc; /* IPDS only fails on allocs */ } /* axisVal is per-screen, last.valuators is desktop-wide */ pDev->valuator->axisVal[0] = scr->width / 2; @@ -676,16 +656,15 @@ InitCoreDevices(void) { if (AllocDevicePair(serverClient, "Virtual core", &inputInfo.pointer, &inputInfo.keyboard, - CorePointerProc, CoreKeyboardProc, - TRUE) != Success) - FatalError("Failed to allocate core devices"); + CorePointerProc, CoreKeyboardProc, TRUE) != Success) + FatalError("Failed to allocate core devices"); if (ActivateDevice(inputInfo.pointer, TRUE) != Success || ActivateDevice(inputInfo.keyboard, TRUE) != Success) - FatalError("Failed to activate core devices."); + FatalError("Failed to activate core devices."); if (!EnableDevice(inputInfo.pointer, TRUE) || !EnableDevice(inputInfo.keyboard, TRUE)) - FatalError("Failed to enable core devices."); + FatalError("Failed to enable core devices."); InitXTestDevices(); } @@ -714,12 +693,11 @@ InitAndStartDevices(void) } /* enable real devices */ - for (dev = inputInfo.off_devices; dev; dev = next) - { + for (dev = inputInfo.off_devices; dev; dev = next) { DebugF("(dix) enabling device %d\n", dev->id); - next = dev->next; - if (dev->inited && dev->startup) - EnableDevice(dev, TRUE); + next = dev->next; + if (dev->inited && dev->startup) + EnableDevice(dev, TRUE); } return Success; @@ -734,62 +712,63 @@ FreeDeviceClass(int type, pointer *class) if (!(*class)) return; - switch(type) + switch (type) { + case KeyClass: { - case KeyClass: - { - KeyClassPtr* k = (KeyClassPtr*)class; - if ((*k)->xkbInfo) - { - XkbFreeInfo((*k)->xkbInfo); - (*k)->xkbInfo = NULL; - } - free((*k)); - break; - } - case ButtonClass: - { - ButtonClassPtr *b = (ButtonClassPtr*)class; - free((*b)->xkb_acts); - free((*b)); - break; - } - case ValuatorClass: - { - ValuatorClassPtr *v = (ValuatorClassPtr*)class; + KeyClassPtr *k = (KeyClassPtr *) class; - free((*v)->motion); - free((*v)); - break; - } - case XITouchClass: - { - TouchClassPtr *t = (TouchClassPtr*)class; - int i; - - for (i = 0; i < (*t)->num_touches; i++) - { - free((*t)->touches[i].sprite.spriteTrace); - free((*t)->touches[i].listeners); - free((*t)->touches[i].valuators); - } - - free((*t)); - break; - } - case FocusClass: - { - FocusClassPtr *f = (FocusClassPtr*)class; - free((*f)->trace); - free((*f)); - break; - } - case ProximityClass: - { - ProximityClassPtr *p = (ProximityClassPtr*)class; - free((*p)); - break; - } + if ((*k)->xkbInfo) { + XkbFreeInfo((*k)->xkbInfo); + (*k)->xkbInfo = NULL; + } + free((*k)); + break; + } + case ButtonClass: + { + ButtonClassPtr *b = (ButtonClassPtr *) class; + + free((*b)->xkb_acts); + free((*b)); + break; + } + case ValuatorClass: + { + ValuatorClassPtr *v = (ValuatorClassPtr *) class; + + free((*v)->motion); + free((*v)); + break; + } + case XITouchClass: + { + TouchClassPtr *t = (TouchClassPtr *) class; + int i; + + for (i = 0; i < (*t)->num_touches; i++) { + free((*t)->touches[i].sprite.spriteTrace); + free((*t)->touches[i].listeners); + free((*t)->touches[i].valuators); + } + + free((*t)); + break; + } + case FocusClass: + { + FocusClassPtr *f = (FocusClassPtr *) class; + + free((*f)->trace); + free((*f)); + break; + } + case ProximityClass: + { + ProximityClassPtr *p = (ProximityClassPtr *) class; + + free((*p)); + break; + } } *class = NULL; } @@ -800,79 +779,79 @@ FreeFeedbackClass(int type, pointer *class) if (!(*class)) return; - switch(type) + switch (type) { + case KbdFeedbackClass: { - case KbdFeedbackClass: - { - KbdFeedbackPtr *kbdfeed = (KbdFeedbackPtr*)class; - KbdFeedbackPtr k, knext; - for (k = (*kbdfeed); k; k = knext) { - knext = k->next; - if (k->xkb_sli) - XkbFreeSrvLedInfo(k->xkb_sli); - free(k); - } - break; - } - case PtrFeedbackClass: - { - PtrFeedbackPtr *ptrfeed = (PtrFeedbackPtr*)class; - PtrFeedbackPtr p, pnext; - - for (p = (*ptrfeed); p; p = pnext) { - pnext = p->next; - free(p); - } - break; - } - case IntegerFeedbackClass: - { - IntegerFeedbackPtr *intfeed = (IntegerFeedbackPtr*)class; - IntegerFeedbackPtr i, inext; - - for (i = (*intfeed); i; i = inext) { - inext = i->next; - free(i); - } - break; - } - case StringFeedbackClass: - { - StringFeedbackPtr *stringfeed = (StringFeedbackPtr*)class; - StringFeedbackPtr s, snext; - - for (s = (*stringfeed); s; s = snext) { - snext = s->next; - free(s->ctrl.symbols_supported); - free(s->ctrl.symbols_displayed); - free(s); - } - break; - } - case BellFeedbackClass: - { - BellFeedbackPtr *bell = (BellFeedbackPtr*)class; - BellFeedbackPtr b, bnext; - - for (b = (*bell); b; b = bnext) { - bnext = b->next; - free(b); - } - break; - } - case LedFeedbackClass: - { - LedFeedbackPtr *leds = (LedFeedbackPtr*)class; - LedFeedbackPtr l, lnext; - - for (l = (*leds); l; l = lnext) { - lnext = l->next; - if (l->xkb_sli) - XkbFreeSrvLedInfo(l->xkb_sli); - free(l); - } - break; - } + KbdFeedbackPtr *kbdfeed = (KbdFeedbackPtr *) class; + KbdFeedbackPtr k, knext; + + for (k = (*kbdfeed); k; k = knext) { + knext = k->next; + if (k->xkb_sli) + XkbFreeSrvLedInfo(k->xkb_sli); + free(k); + } + break; + } + case PtrFeedbackClass: + { + PtrFeedbackPtr *ptrfeed = (PtrFeedbackPtr *) class; + PtrFeedbackPtr p, pnext; + + for (p = (*ptrfeed); p; p = pnext) { + pnext = p->next; + free(p); + } + break; + } + case IntegerFeedbackClass: + { + IntegerFeedbackPtr *intfeed = (IntegerFeedbackPtr *) class; + IntegerFeedbackPtr i, inext; + + for (i = (*intfeed); i; i = inext) { + inext = i->next; + free(i); + } + break; + } + case StringFeedbackClass: + { + StringFeedbackPtr *stringfeed = (StringFeedbackPtr *) class; + StringFeedbackPtr s, snext; + + for (s = (*stringfeed); s; s = snext) { + snext = s->next; + free(s->ctrl.symbols_supported); + free(s->ctrl.symbols_displayed); + free(s); + } + break; + } + case BellFeedbackClass: + { + BellFeedbackPtr *bell = (BellFeedbackPtr *) class; + BellFeedbackPtr b, bnext; + + for (b = (*bell); b; b = bnext) { + bnext = b->next; + free(b); + } + break; + } + case LedFeedbackClass: + { + LedFeedbackPtr *leds = (LedFeedbackPtr *) class; + LedFeedbackPtr l, lnext; + + for (l = (*leds); l; l = lnext) { + lnext = l->next; + if (l->xkb_sli) + XkbFreeSrvLedInfo(l->xkb_sli); + free(l); + } + break; + } } *class = NULL; } @@ -883,19 +862,19 @@ FreeAllDeviceClasses(ClassesPtr classes) if (!classes) return; - FreeDeviceClass(KeyClass, (pointer)&classes->key); - FreeDeviceClass(ValuatorClass, (pointer)&classes->valuator); - FreeDeviceClass(XITouchClass, (pointer)&classes->touch); - FreeDeviceClass(ButtonClass, (pointer)&classes->button); - FreeDeviceClass(FocusClass, (pointer)&classes->focus); - FreeDeviceClass(ProximityClass, (pointer)&classes->proximity); + FreeDeviceClass(KeyClass, (pointer) &classes->key); + FreeDeviceClass(ValuatorClass, (pointer) &classes->valuator); + FreeDeviceClass(XITouchClass, (pointer) &classes->touch); + FreeDeviceClass(ButtonClass, (pointer) &classes->button); + FreeDeviceClass(FocusClass, (pointer) &classes->focus); + FreeDeviceClass(ProximityClass, (pointer) &classes->proximity); - FreeFeedbackClass(KbdFeedbackClass, (pointer)&classes->kbdfeed); - FreeFeedbackClass(PtrFeedbackClass, (pointer)&classes->ptrfeed); - FreeFeedbackClass(IntegerFeedbackClass, (pointer)&classes->intfeed); - FreeFeedbackClass(StringFeedbackClass, (pointer)&classes->stringfeed); - FreeFeedbackClass(BellFeedbackClass, (pointer)&classes->bell); - FreeFeedbackClass(LedFeedbackClass, (pointer)&classes->leds); + FreeFeedbackClass(KbdFeedbackClass, (pointer) &classes->kbdfeed); + FreeFeedbackClass(PtrFeedbackClass, (pointer) &classes->ptrfeed); + FreeFeedbackClass(IntegerFeedbackClass, (pointer) &classes->intfeed); + FreeFeedbackClass(StringFeedbackClass, (pointer) &classes->stringfeed); + FreeFeedbackClass(BellFeedbackClass, (pointer) &classes->bell); + FreeFeedbackClass(LedFeedbackClass, (pointer) &classes->leds); } @@ -919,43 +898,40 @@ CloseDevice(DeviceIntPtr dev) XIDeleteAllDeviceProperties(dev); if (dev->inited) - (void)(*dev->deviceProc)(dev, DEVICE_CLOSE); + (void) (*dev->deviceProc) (dev, DEVICE_CLOSE); /* free sprite memory */ if (IsMaster(dev) && dev->spriteInfo->sprite) screen->DeviceCursorCleanup(dev, screen); /* free acceleration info */ - if(dev->valuator && dev->valuator->accelScheme.AccelCleanupProc) - dev->valuator->accelScheme.AccelCleanupProc(dev); + if (dev->valuator && dev->valuator->accelScheme.AccelCleanupProc) + dev->valuator->accelScheme.AccelCleanupProc(dev); while (dev->xkb_interest) - XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource); + XkbRemoveResourceClient((DevicePtr) dev, dev->xkb_interest->resource); free(dev->name); - classes = (ClassesPtr)&dev->key; + classes = (ClassesPtr) & dev->key; FreeAllDeviceClasses(classes); - if (IsMaster(dev)) - { + if (IsMaster(dev)) { classes = dev->unused_classes; FreeAllDeviceClasses(classes); - free(classes); + free(classes); } if (DevHasCursor(dev) && dev->spriteInfo->sprite) { - if (dev->spriteInfo->sprite->current) - FreeCursor(dev->spriteInfo->sprite->current, None); + if (dev->spriteInfo->sprite->current) + FreeCursor(dev->spriteInfo->sprite->current, None); free(dev->spriteInfo->sprite->spriteTrace); free(dev->spriteInfo->sprite); } /* a client may have the device set as client pointer */ - for (j = 0; j < currentMaxClients; j++) - { - if (clients[j] && clients[j]->clientPtr == dev) - { + for (j = 0; j < currentMaxClients; j++) { + if (clients[j] && clients[j]->clientPtr == dev) { clients[j]->clientPtr = NULL; clients[j]->clientPtr = PickPointer(clients[j]); } @@ -976,7 +952,7 @@ CloseDevice(DeviceIntPtr dev) * Shut down all devices of one list and free all resources. */ static -void + void CloseDeviceList(DeviceIntPtr *listHead) { /* Used to mark devices that we tried to free */ @@ -991,8 +967,7 @@ CloseDeviceList(DeviceIntPtr *listHead) freedIds[i] = FALSE; dev = *listHead; - while (dev != NULL) - { + while (dev != NULL) { freedIds[dev->id] = TRUE; DeleteInputDeviceRequest(dev); @@ -1018,8 +993,7 @@ CloseDownDevices(void) * AttachDevice(NULL, dev, NULL). Instead, we have to forcibly set master * to NULL and pretend nothing happened. */ - for (dev = inputInfo.devices; dev; dev = dev->next) - { + for (dev = inputInfo.devices; dev; dev = dev->next) { if (!IsMaster(dev) && !IsFloating(dev)) dev->master = NULL; } @@ -1028,12 +1002,14 @@ CloseDownDevices(void) CloseDeviceList(&inputInfo.off_devices); CloseDevice(inputInfo.pointer); + CloseDevice(inputInfo.keyboard); inputInfo.devices = NULL; inputInfo.off_devices = NULL; inputInfo.keyboard = NULL; inputInfo.pointer = NULL; + XkbDeleteRulesDflts(); OsReleaseSignals(); @@ -1069,12 +1045,12 @@ UndisplayDevices(void) int RemoveDevice(DeviceIntPtr dev, BOOL sendevent) { - DeviceIntPtr prev,tmp,next; + DeviceIntPtr prev, tmp, next; int ret = BadMatch; ScreenPtr screen = screenInfo.screens[0]; int deviceid; int initialized; - int flags[MAXDEVICES] = {0}; + int flags[MAXDEVICES] = { 0 }; DebugF("(dix) removing device %d\n", dev->id); @@ -1084,8 +1060,7 @@ RemoveDevice(DeviceIntPtr dev, BOOL sendevent) initialized = dev->inited; deviceid = dev->id; - if (initialized) - { + if (initialized) { if (DevHasCursor(dev)) screen->DisplayCursor(dev, screen, NullCursor); @@ -1095,34 +1070,34 @@ RemoveDevice(DeviceIntPtr dev, BOOL sendevent) prev = NULL; for (tmp = inputInfo.devices; tmp; (prev = tmp), (tmp = next)) { - next = tmp->next; - if (tmp == dev) { + next = tmp->next; + if (tmp == dev) { - if (prev==NULL) - inputInfo.devices = next; - else - prev->next = next; + if (prev == NULL) + inputInfo.devices = next; + else + prev->next = next; - flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : XISlaveRemoved; - CloseDevice(tmp); - ret = Success; - } + flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : XISlaveRemoved; + CloseDevice(tmp); + ret = Success; + } } prev = NULL; for (tmp = inputInfo.off_devices; tmp; (prev = tmp), (tmp = next)) { - next = tmp->next; - if (tmp == dev) { - flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : XISlaveRemoved; - CloseDevice(tmp); + next = tmp->next; + if (tmp == dev) { + flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : XISlaveRemoved; + CloseDevice(tmp); - if (prev == NULL) - inputInfo.off_devices = next; - else - prev->next = next; + if (prev == NULL) + inputInfo.off_devices = next; + else + prev->next = next; ret = Success; - } + } } if (ret == Success && initialized) { @@ -1148,22 +1123,23 @@ dixLookupDevice(DeviceIntPtr *pDev, int id, ClientPtr client, Mask access_mode) { DeviceIntPtr dev; int rc; + *pDev = NULL; - for (dev=inputInfo.devices; dev; dev=dev->next) { + for (dev = inputInfo.devices; dev; dev = dev->next) { if (dev->id == id) goto found; } - for (dev=inputInfo.off_devices; dev; dev=dev->next) { + for (dev = inputInfo.off_devices; dev; dev = dev->next) { if (dev->id == id) - goto found; + goto found; } return BadDevice; -found: + found: rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode); if (rc == Success) - *pDev = dev; + *pDev = dev; return rc; } @@ -1171,8 +1147,8 @@ void QueryMinMaxKeyCodes(KeyCode *minCode, KeyCode *maxCode) { if (inputInfo.keyboard) { - *minCode = inputInfo.keyboard->key->xkbInfo->desc->min_key_code; - *maxCode = inputInfo.keyboard->key->xkbInfo->desc->max_key_code; + *minCode = inputInfo.keyboard->key->xkbInfo->desc->min_key_code; + *maxCode = inputInfo.keyboard->key->xkbInfo->desc->max_key_code; } } @@ -1190,24 +1166,24 @@ SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src) for (i = src->minKeyCode; i <= src->maxKeyCode; i++) { #define SI(r, c) (((r - src->minKeyCode) * src->mapWidth) + (c)) #define DI(r, c) (((r - dst->minKeyCode) * dst->mapWidth) + (c)) - for (j = 0; j < src->mapWidth; j++) - dst->map[DI(i, j)] = src->map[SI(i, j)]; - for (j = src->mapWidth; j < dst->mapWidth; j++) - dst->map[DI(i, j)] = NoSymbol; + for (j = 0; j < src->mapWidth; j++) + dst->map[DI(i, j)] = src->map[SI(i, j)]; + for (j = src->mapWidth; j < dst->mapWidth; j++) + dst->map[DI(i, j)] = NoSymbol; #undef SI #undef DI - } - return TRUE; + } + return TRUE; } else if (src->mapWidth > dst->mapWidth) { i = sizeof(KeySym) * src->mapWidth * - (dst->maxKeyCode - dst->minKeyCode + 1); + (dst->maxKeyCode - dst->minKeyCode + 1); tmp = calloc(sizeof(KeySym), i); if (!tmp) return FALSE; if (dst->map) { - for (i = 0; i <= dst->maxKeyCode-dst->minKeyCode; i++) + for (i = 0; i <= dst->maxKeyCode - dst->minKeyCode; i++) memmove(&tmp[i * src->mapWidth], &dst->map[i * dst->mapWidth], dst->mapWidth * sizeof(KeySym)); free(dst->map); @@ -1217,7 +1193,7 @@ SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src) } else if (!dst->map) { i = sizeof(KeySym) * src->mapWidth * - (dst->maxKeyCode - dst->minKeyCode + 1); + (dst->maxKeyCode - dst->minKeyCode + 1); tmp = calloc(sizeof(KeySym), i); if (!tmp) return FALSE; @@ -1234,7 +1210,7 @@ SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src) } Bool -InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom* labels, +InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom *labels, CARD8 *map) { ButtonClassPtr butc; @@ -1242,11 +1218,11 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom* labels, butc = calloc(1, sizeof(ButtonClassRec)); if (!butc) - return FALSE; + return FALSE; butc->numButtons = numButtons; butc->sourceid = dev->id; for (i = 1; i <= numButtons; i++) - butc->map[i] = map[i]; + butc->map[i] = map[i]; for (i = numButtons + 1; i < MAP_LENGTH; i++) butc->map[i] = i; memcpy(butc->labels, labels, numButtons * sizeof(Atom)); @@ -1267,11 +1243,16 @@ ValuatorClassPtr AllocValuatorClass(ValuatorClassPtr src, int numAxes) { ValuatorClassPtr v; + /* force alignment with double */ - union align_u { ValuatorClassRec valc; double d; } *align; + union align_u { + ValuatorClassRec valc; + double d; + } *align; int size; - size = sizeof(union align_u) + numAxes * (sizeof(double) + sizeof(AxisInfo)); + size = + sizeof(union align_u) + numAxes * (sizeof(double) + sizeof(AxisInfo)); align = (union align_u *) realloc(src, size); if (!align) @@ -1282,8 +1263,8 @@ AllocValuatorClass(ValuatorClassPtr src, int numAxes) v = &align->valc; v->numAxes = numAxes; - v->axisVal = (double*)(align + 1); - v->axes = (AxisInfoPtr)(v->axisVal + numAxes); + v->axisVal = (double *) (align + 1); + v->axes = (AxisInfoPtr) (v->axisVal + numAxes); return v; } @@ -1298,8 +1279,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, if (!dev) return FALSE; - if (numAxes > MAX_VALUATORS) - { + if (numAxes > MAX_VALUATORS) { LogMessage(X_WARNING, "Device '%s' has %d axes, only using first %d.\n", dev->name, numAxes, MAX_VALUATORS); @@ -1311,8 +1291,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, return FALSE; dev->last.scroll = valuator_mask_new(numAxes); - if (!dev->last.scroll) - { + if (!dev->last.scroll) { free(valc); return FALSE; } @@ -1334,29 +1313,32 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, AllocateMotionHistory(dev); - for (i=0; i<numAxes; i++) { - InitValuatorAxisStruct(dev, i, labels[i], NO_AXIS_LIMITS, NO_AXIS_LIMITS, - 0, 0, 0, mode); - valc->axisVal[i]=0; + for (i = 0; i < numAxes; i++) { + InitValuatorAxisStruct(dev, i, labels[i], NO_AXIS_LIMITS, + NO_AXIS_LIMITS, 0, 0, 0, mode); + valc->axisVal[i] = 0; } dev->last.numValuators = numAxes; - if (IsMaster(dev) || /* do not accelerate master or xtest devices */ + if (IsMaster(dev) || /* do not accelerate master or xtest devices */ IsXTestDevice(dev, NULL)) - InitPointerAccelerationScheme(dev, PtrAccelNoOp); + InitPointerAccelerationScheme(dev, PtrAccelNoOp); else - InitPointerAccelerationScheme(dev, PtrAccelDefault); + InitPointerAccelerationScheme(dev, PtrAccelDefault); return TRUE; } /* global list of acceleration schemes */ ValuatorAccelerationRec pointerAccelerationScheme[] = { - {PtrAccelNoOp, NULL, NULL, NULL, NULL}, + {PtrAccelNoOp, NULL, NULL, NULL, NULL} + , {PtrAccelPredictable, acceleratePointerPredictable, NULL, - InitPredictableAccelerationScheme, AccelerationDefaultCleanup}, - {PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL, NULL}, - {-1, NULL, NULL, NULL, NULL} /* terminator */ + InitPredictableAccelerationScheme, AccelerationDefaultCleanup} + , + {PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL, NULL} + , + {-1, NULL, NULL, NULL, NULL} /* terminator */ }; /** @@ -1364,8 +1346,7 @@ ValuatorAccelerationRec pointerAccelerationScheme[] = { * change anything if unsuccessful. */ Bool -InitPointerAccelerationScheme(DeviceIntPtr dev, - int scheme) +InitPointerAccelerationScheme(DeviceIntPtr dev, int scheme) { int x, i = -1; ValuatorClassPtr val; @@ -1379,7 +1360,7 @@ InitPointerAccelerationScheme(DeviceIntPtr dev, return FALSE; for (x = 0; pointerAccelerationScheme[x].number >= 0; x++) { - if(pointerAccelerationScheme[x].number == scheme){ + if (pointerAccelerationScheme[x].number == scheme) { i = x; break; } @@ -1393,10 +1374,12 @@ InitPointerAccelerationScheme(DeviceIntPtr dev, if (pointerAccelerationScheme[i].AccelInitProc) { if (!pointerAccelerationScheme[i].AccelInitProc(dev, - &pointerAccelerationScheme[i])) { + &pointerAccelerationScheme + [i])) { return FALSE; } - } else { + } + else { val->accelScheme = pointerAccelerationScheme[i]; } return TRUE; @@ -1409,11 +1392,11 @@ InitFocusClassDeviceStruct(DeviceIntPtr dev) focc = malloc(sizeof(FocusClassRec)); if (!focc) - return FALSE; + return FALSE; focc->win = PointerRootWin; focc->revert = None; focc->time = currentTime; - focc->trace = (WindowPtr *)NULL; + focc->trace = (WindowPtr *) NULL; focc->traceSize = 0; focc->traceGood = 0; focc->sourceid = dev->id; @@ -1428,137 +1411,142 @@ InitPtrFeedbackClassDeviceStruct(DeviceIntPtr dev, PtrCtrlProcPtr controlProc) feedc = malloc(sizeof(PtrFeedbackClassRec)); if (!feedc) - return FALSE; + return FALSE; feedc->CtrlProc = controlProc; feedc->ctrl = defaultPointerControl; feedc->ctrl.id = 0; - if ( (feedc->next = dev->ptrfeed) ) + if ((feedc->next = dev->ptrfeed)) feedc->ctrl.id = dev->ptrfeed->ctrl.id + 1; dev->ptrfeed = feedc; - (*controlProc)(dev, &feedc->ctrl); + (*controlProc) (dev, &feedc->ctrl); return TRUE; } static LedCtrl defaultLedControl = { - DEFAULT_LEDS, DEFAULT_LEDS_MASK, 0}; + DEFAULT_LEDS, DEFAULT_LEDS_MASK, 0 +}; static BellCtrl defaultBellControl = { - DEFAULT_BELL, - DEFAULT_BELL_PITCH, - DEFAULT_BELL_DURATION, - 0}; + DEFAULT_BELL, + DEFAULT_BELL_PITCH, + DEFAULT_BELL_DURATION, + 0 +}; static IntegerCtrl defaultIntegerControl = { - DEFAULT_INT_RESOLUTION, - DEFAULT_INT_MIN_VALUE, - DEFAULT_INT_MAX_VALUE, - DEFAULT_INT_DISPLAYED, - 0}; + DEFAULT_INT_RESOLUTION, + DEFAULT_INT_MIN_VALUE, + DEFAULT_INT_MAX_VALUE, + DEFAULT_INT_DISPLAYED, + 0 +}; Bool -InitStringFeedbackClassDeviceStruct ( - DeviceIntPtr dev, StringCtrlProcPtr controlProc, - int max_symbols, int num_symbols_supported, KeySym *symbols) +InitStringFeedbackClassDeviceStruct(DeviceIntPtr dev, + StringCtrlProcPtr controlProc, + int max_symbols, int num_symbols_supported, + KeySym * symbols) { int i; StringFeedbackPtr feedc; feedc = malloc(sizeof(StringFeedbackClassRec)); if (!feedc) - return FALSE; + return FALSE; feedc->CtrlProc = controlProc; feedc->ctrl.num_symbols_supported = num_symbols_supported; feedc->ctrl.num_symbols_displayed = 0; feedc->ctrl.max_symbols = max_symbols; - feedc->ctrl.symbols_supported = malloc(sizeof (KeySym) * num_symbols_supported); - feedc->ctrl.symbols_displayed = malloc(sizeof (KeySym) * max_symbols); - if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed) - { - free(feedc->ctrl.symbols_supported); - free(feedc->ctrl.symbols_displayed); - free(feedc); - return FALSE; - } - for (i=0; i<num_symbols_supported; i++) - *(feedc->ctrl.symbols_supported+i) = *symbols++; - for (i=0; i<max_symbols; i++) - *(feedc->ctrl.symbols_displayed+i) = (KeySym) 0; + feedc->ctrl.symbols_supported = + malloc(sizeof(KeySym) * num_symbols_supported); + feedc->ctrl.symbols_displayed = malloc(sizeof(KeySym) * max_symbols); + if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed) { + free(feedc->ctrl.symbols_supported); + free(feedc->ctrl.symbols_displayed); + free(feedc); + return FALSE; + } + for (i = 0; i < num_symbols_supported; i++) + *(feedc->ctrl.symbols_supported + i) = *symbols++; + for (i = 0; i < max_symbols; i++) + *(feedc->ctrl.symbols_displayed + i) = (KeySym) 0; feedc->ctrl.id = 0; - if ( (feedc->next = dev->stringfeed) ) - feedc->ctrl.id = dev->stringfeed->ctrl.id + 1; + if ((feedc->next = dev->stringfeed)) + feedc->ctrl.id = dev->stringfeed->ctrl.id + 1; dev->stringfeed = feedc; - (*controlProc)(dev, &feedc->ctrl); + (*controlProc) (dev, &feedc->ctrl); return TRUE; } Bool -InitBellFeedbackClassDeviceStruct (DeviceIntPtr dev, BellProcPtr bellProc, - BellCtrlProcPtr controlProc) +InitBellFeedbackClassDeviceStruct(DeviceIntPtr dev, BellProcPtr bellProc, + BellCtrlProcPtr controlProc) { BellFeedbackPtr feedc; feedc = malloc(sizeof(BellFeedbackClassRec)); if (!feedc) - return FALSE; + return FALSE; feedc->CtrlProc = controlProc; feedc->BellProc = bellProc; feedc->ctrl = defaultBellControl; feedc->ctrl.id = 0; - if ( (feedc->next = dev->bell) ) - feedc->ctrl.id = dev->bell->ctrl.id + 1; + if ((feedc->next = dev->bell)) + feedc->ctrl.id = dev->bell->ctrl.id + 1; dev->bell = feedc; - (*controlProc)(dev, &feedc->ctrl); + (*controlProc) (dev, &feedc->ctrl); return TRUE; } Bool -InitLedFeedbackClassDeviceStruct (DeviceIntPtr dev, LedCtrlProcPtr controlProc) +InitLedFeedbackClassDeviceStruct(DeviceIntPtr dev, LedCtrlProcPtr controlProc) { LedFeedbackPtr feedc; feedc = malloc(sizeof(LedFeedbackClassRec)); if (!feedc) - return FALSE; + return FALSE; feedc->CtrlProc = controlProc; feedc->ctrl = defaultLedControl; feedc->ctrl.id = 0; - if ( (feedc->next = dev->leds) ) - feedc->ctrl.id = dev->leds->ctrl.id + 1; - feedc->xkb_sli= NULL; + if ((feedc->next = dev->leds)) + feedc->ctrl.id = dev->leds->ctrl.id + 1; + feedc->xkb_sli = NULL; dev->leds = feedc; - (*controlProc)(dev, &feedc->ctrl); + (*controlProc) (dev, &feedc->ctrl); return TRUE; } Bool -InitIntegerFeedbackClassDeviceStruct (DeviceIntPtr dev, IntegerCtrlProcPtr controlProc) +InitIntegerFeedbackClassDeviceStruct(DeviceIntPtr dev, + IntegerCtrlProcPtr controlProc) { IntegerFeedbackPtr feedc; feedc = malloc(sizeof(IntegerFeedbackClassRec)); if (!feedc) - return FALSE; + return FALSE; feedc->CtrlProc = controlProc; feedc->ctrl = defaultIntegerControl; feedc->ctrl.id = 0; - if ( (feedc->next = dev->intfeed) ) - feedc->ctrl.id = dev->intfeed->ctrl.id + 1; + if ((feedc->next = dev->intfeed)) + feedc->ctrl.id = dev->intfeed->ctrl.id + 1; dev->intfeed = feedc; - (*controlProc)(dev, &feedc->ctrl); + (*controlProc) (dev, &feedc->ctrl); return TRUE; } Bool -InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons, Atom* btn_labels, - PtrCtrlProcPtr controlProc, int numMotionEvents, - int numAxes, Atom *axes_labels) +InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons, + Atom *btn_labels, PtrCtrlProcPtr controlProc, + int numMotionEvents, int numAxes, Atom *axes_labels) { - DeviceIntPtr dev = (DeviceIntPtr)device; + DeviceIntPtr dev = (DeviceIntPtr) device; - return(InitButtonClassDeviceStruct(dev, numButtons, btn_labels, map) && - InitValuatorClassDeviceStruct(dev, numAxes, axes_labels, - numMotionEvents, Relative) && - InitPtrFeedbackClassDeviceStruct(dev, controlProc)); + return (InitButtonClassDeviceStruct(dev, numButtons, btn_labels, map) && + InitValuatorClassDeviceStruct(dev, numAxes, axes_labels, + numMotionEvents, Relative) && + InitPtrFeedbackClassDeviceStruct(dev, controlProc)); } /** @@ -1584,8 +1572,7 @@ InitTouchClassDeviceStruct(DeviceIntPtr device, unsigned int max_touches, if (num_axes < 2) return FALSE; - if (num_axes > MAX_VALUATORS) - { + if (num_axes > MAX_VALUATORS) { LogMessage(X_WARNING, "Device '%s' has %d touch axes, only using first %d.\n", device->name, num_axes, MAX_VALUATORS); @@ -1598,7 +1585,7 @@ InitTouchClassDeviceStruct(DeviceIntPtr device, unsigned int max_touches, touch->max_touches = max_touches; if (max_touches == 0) - max_touches = 5; /* arbitrary number plucked out of the air */ + max_touches = 5; /* arbitrary number plucked out of the air */ touch->touches = calloc(max_touches, sizeof(*touch->touches)); if (!touch->touches) goto err; @@ -1617,7 +1604,7 @@ InitTouchClassDeviceStruct(DeviceIntPtr device, unsigned int max_touches, return TRUE; -err: + err: for (i = 0; i < touch->num_touches; i++) TouchFreeTouchPoint(device, i); @@ -1634,19 +1621,17 @@ err: * @return TRUE if the device map is invalid, FALSE otherwise. */ Bool -BadDeviceMap(BYTE *buff, int length, unsigned low, unsigned high, XID *errval) +BadDeviceMap(BYTE * buff, int length, unsigned low, unsigned high, XID *errval) { int i; for (i = 0; i < length; i++) - if (buff[i]) /* only check non-zero elements */ - { - if ((low > buff[i]) || (high < buff[i])) - { - *errval = buff[i]; - return TRUE; - } - } + if (buff[i]) { /* only check non-zero elements */ + if ((low > buff[i]) || (high < buff[i])) { + *errval = buff[i]; + return TRUE; + } + } return FALSE; } @@ -1655,24 +1640,25 @@ ProcSetModifierMapping(ClientPtr client) { xSetModifierMappingReply rep; int rc; + REQUEST(xSetModifierMappingReq); REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq); if (client->req_len != ((stuff->numKeyPerModifier << 1) + - bytes_to_int32(sizeof(xSetModifierMappingReq)))) - return BadLength; + bytes_to_int32(sizeof(xSetModifierMappingReq)))) + return BadLength; rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; - rc = change_modmap(client, PickKeyboard(client), (KeyCode *)&stuff[1], + rc = change_modmap(client, PickKeyboard(client), (KeyCode *) &stuff[1], stuff->numKeyPerModifier); if (rc == MappingFailed || rc == -1) return BadValue; if (rc != Success && rc != MappingSuccess && rc != MappingFailed && rc != MappingBusy) - return rc; + return rc; rep.success = rc; @@ -1686,6 +1672,7 @@ ProcGetModifierMapping(ClientPtr client) xGetModifierMappingReply rep; int max_keys_per_mod = 0; KeyCode *modkeymap = NULL; + REQUEST_SIZE_MATCH(xReq); generate_modkeymap(client, PickKeyboard(client), &modkeymap, @@ -1699,7 +1686,7 @@ ProcGetModifierMapping(ClientPtr client) rep.length = max_keys_per_mod << 1; WriteReplyToClient(client, sizeof(xGetModifierMappingReply), &rep); - (void)WriteToClient(client, max_keys_per_mod * 8, (char *) modkeymap); + (void) WriteToClient(client, max_keys_per_mod * 8, (char *) modkeymap); free(modkeymap); @@ -1714,25 +1701,26 @@ ProcChangeKeyboardMapping(ClientPtr client) KeySymsRec keysyms; DeviceIntPtr pDev, tmp; int rc; + REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq); len = client->req_len - bytes_to_int32(sizeof(xChangeKeyboardMappingReq)); if (len != (stuff->keyCodes * stuff->keySymsPerKeyCode)) - return BadLength; + return BadLength; pDev = PickKeyboard(client); if ((stuff->firstKeyCode < pDev->key->xkbInfo->desc->min_key_code) || - (stuff->firstKeyCode > pDev->key->xkbInfo->desc->max_key_code)) { - client->errorValue = stuff->firstKeyCode; - return BadValue; + (stuff->firstKeyCode > pDev->key->xkbInfo->desc->max_key_code)) { + client->errorValue = stuff->firstKeyCode; + return BadValue; } - if (((unsigned)(stuff->firstKeyCode + stuff->keyCodes - 1) > - pDev->key->xkbInfo->desc->max_key_code) || + if (((unsigned) (stuff->firstKeyCode + stuff->keyCodes - 1) > + pDev->key->xkbInfo->desc->max_key_code) || (stuff->keySymsPerKeyCode == 0)) { - client->errorValue = stuff->keySymsPerKeyCode; - return BadValue; + client->errorValue = stuff->keySymsPerKeyCode; + return BadValue; } keysyms.minKeyCode = stuff->firstKeyCode; @@ -1772,17 +1760,18 @@ ProcSetPointerMapping(ClientPtr client) int i, j; DeviceIntPtr ptr = PickPointer(client); xSetPointerMappingReply rep; + REQUEST(xSetPointerMappingReq); REQUEST_AT_LEAST_SIZE(xSetPointerMappingReq); if (client->req_len != - bytes_to_int32(sizeof(xSetPointerMappingReq) + stuff->nElts)) - return BadLength; + bytes_to_int32(sizeof(xSetPointerMappingReq) + stuff->nElts)) + return BadLength; rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; rep.success = MappingSuccess; - map = (BYTE *)&stuff[1]; + map = (BYTE *) &stuff[1]; /* So we're bounded here by the number of core buttons. This check * probably wants disabling through XFixes. */ @@ -1791,8 +1780,8 @@ ProcSetPointerMapping(ClientPtr client) * and SetPointerMapping */ if (stuff->nElts != ptr->button->numButtons) { - client->errorValue = stuff->nElts; - return BadValue; + client->errorValue = stuff->nElts; + return BadValue; } /* Core protocol specs don't allow for duplicate mappings; this check @@ -1826,22 +1815,23 @@ ProcGetKeyboardMapping(ClientPtr client) XkbDescPtr xkb; KeySymsPtr syms; int rc; + REQUEST(xGetKeyboardMappingReq); REQUEST_SIZE_MATCH(xGetKeyboardMappingReq); rc = XaceHook(XACE_DEVICE_ACCESS, client, kbd, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; xkb = kbd->key->xkbInfo->desc; if ((stuff->firstKeyCode < xkb->min_key_code) || (stuff->firstKeyCode > xkb->max_key_code)) { - client->errorValue = stuff->firstKeyCode; - return BadValue; + client->errorValue = stuff->firstKeyCode; + return BadValue; } if (stuff->firstKeyCode + stuff->count > xkb->max_key_code + 1) { - client->errorValue = stuff->count; + client->errorValue = stuff->count; return BadValue; } @@ -1871,24 +1861,26 @@ int ProcGetPointerMapping(ClientPtr client) { xGetPointerMappingReply rep; + /* Apps may get different values each time they call GetPointerMapping as * the ClientPointer could change. */ DeviceIntPtr ptr = PickPointer(client); ButtonClassPtr butc = ptr->button; int rc; + REQUEST_SIZE_MATCH(xReq); rc = XaceHook(XACE_DEVICE_ACCESS, client, ptr, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; rep.sequenceNumber = client->sequence; rep.nElts = (butc) ? butc->numButtons : 0; - rep.length = ((unsigned)rep.nElts + (4-1))/4; + rep.length = ((unsigned) rep.nElts + (4 - 1)) / 4; WriteReplyToClient(client, sizeof(xGetPointerMappingReply), &rep); if (butc) - WriteToClient(client, (int)rep.nElts, (char *)&butc->map[1]); + WriteToClient(client, (int) rep.nElts, (char *) &butc->map[1]); return Success; } @@ -1896,25 +1888,26 @@ void NoteLedState(DeviceIntPtr keybd, int led, Bool on) { KeybdCtrl *ctrl = &keybd->kbdfeed->ctrl; + if (on) - ctrl->leds |= ((Leds)1 << (led - 1)); + ctrl->leds |= ((Leds) 1 << (led - 1)); else - ctrl->leds &= ~((Leds)1 << (led - 1)); + ctrl->leds &= ~((Leds) 1 << (led - 1)); } int -Ones(unsigned long mask) /* HACKMEM 169 */ -{ +Ones(unsigned long mask) +{ /* HACKMEM 169 */ unsigned long y; - y = (mask >> 1) &033333333333; - y = mask - y - ((y >>1) & 033333333333); + y = (mask >> 1) & 033333333333; + y = mask - y - ((y >> 1) & 033333333333); return (((y + (y >> 3)) & 030707070707) % 077); } static int -DoChangeKeyboardControl (ClientPtr client, DeviceIntPtr keybd, XID *vlist, - BITS32 vmask) +DoChangeKeyboardControl(ClientPtr client, DeviceIntPtr keybd, XID *vlist, + BITS32 vmask) { #define DO_ALL (-1) KeybdCtrl ctrl; @@ -1927,144 +1920,144 @@ DoChangeKeyboardControl (ClientPtr client, DeviceIntPtr keybd, XID *vlist, ctrl = keybd->kbdfeed->ctrl; while (vmask) { - index2 = (BITS32) lowbit (vmask); - vmask &= ~index2; - switch (index2) { - case KBKeyClickPercent: - t = (INT8)*vlist; - vlist++; - if (t == -1) { - t = defaultKeyboardControl.click; + index2 = (BITS32) lowbit(vmask); + vmask &= ~index2; + switch (index2) { + case KBKeyClickPercent: + t = (INT8) *vlist; + vlist++; + if (t == -1) { + t = defaultKeyboardControl.click; + } + else if (t < 0 || t > 100) { + client->errorValue = t; + return BadValue; + } + ctrl.click = t; + break; + case KBBellPercent: + t = (INT8) *vlist; + vlist++; + if (t == -1) { + t = defaultKeyboardControl.bell; + } + else if (t < 0 || t > 100) { + client->errorValue = t; + return BadValue; + } + ctrl.bell = t; + break; + case KBBellPitch: + t = (INT16) *vlist; + vlist++; + if (t == -1) { + t = defaultKeyboardControl.bell_pitch; + } + else if (t < 0) { + client->errorValue = t; + return BadValue; + } + ctrl.bell_pitch = t; + break; + case KBBellDuration: + t = (INT16) *vlist; + vlist++; + if (t == -1) + t = defaultKeyboardControl.bell_duration; + else if (t < 0) { + client->errorValue = t; + return BadValue; + } + ctrl.bell_duration = t; + break; + case KBLed: + led = (CARD8) *vlist; + vlist++; + if (led < 1 || led > 32) { + client->errorValue = led; + return BadValue; } - else if (t < 0 || t > 100) { - client->errorValue = t; - return BadValue; - } - ctrl.click = t; - break; - case KBBellPercent: - t = (INT8)*vlist; - vlist++; - if (t == -1) { - t = defaultKeyboardControl.bell; + if (!(mask & KBLedMode)) + return BadMatch; + break; + case KBLedMode: + t = (CARD8) *vlist; + vlist++; + if (t == LedModeOff) { + if (led == DO_ALL) + ctrl.leds = 0x0; + else + ctrl.leds &= ~(((Leds) (1)) << (led - 1)); + } + else if (t == LedModeOn) { + if (led == DO_ALL) + ctrl.leds = ~0L; + else + ctrl.leds |= (((Leds) (1)) << (led - 1)); } - else if (t < 0 || t > 100) { - client->errorValue = t; - return BadValue; - } - ctrl.bell = t; - break; - case KBBellPitch: - t = (INT16)*vlist; - vlist++; - if (t == -1) { - t = defaultKeyboardControl.bell_pitch; + else { + client->errorValue = t; + return BadValue; } - else if (t < 0) { - client->errorValue = t; - return BadValue; - } - ctrl.bell_pitch = t; - break; - case KBBellDuration: - t = (INT16)*vlist; - vlist++; - if (t == -1) - t = defaultKeyboardControl.bell_duration; - else if (t < 0) { - client->errorValue = t; - return BadValue; - } - ctrl.bell_duration = t; - break; - case KBLed: - led = (CARD8)*vlist; - vlist++; - if (led < 1 || led > 32) { - client->errorValue = led; - return BadValue; - } - if (!(mask & KBLedMode)) - return BadMatch; - break; - case KBLedMode: - t = (CARD8)*vlist; - vlist++; - if (t == LedModeOff) { - if (led == DO_ALL) - ctrl.leds = 0x0; - else - ctrl.leds &= ~(((Leds)(1)) << (led - 1)); - } - else if (t == LedModeOn) { - if (led == DO_ALL) - ctrl.leds = ~0L; - else - ctrl.leds |= (((Leds)(1)) << (led - 1)); - } - else { - client->errorValue = t; - return BadValue; - } - - XkbSetCauseCoreReq(&cause,X_ChangeKeyboardControl,client); - XkbSetIndicators(keybd,((led == DO_ALL) ? ~0L : (1L<<(led-1))), - ctrl.leds, &cause); + + XkbSetCauseCoreReq(&cause, X_ChangeKeyboardControl, client); + XkbSetIndicators(keybd, ((led == DO_ALL) ? ~0L : (1L << (led - 1))), + ctrl.leds, &cause); ctrl.leds = keybd->kbdfeed->ctrl.leds; - break; - case KBKey: - key = (KeyCode)*vlist; - vlist++; - if ((KeyCode)key < keybd->key->xkbInfo->desc->min_key_code || - (KeyCode)key > keybd->key->xkbInfo->desc->max_key_code) { - client->errorValue = key; - return BadValue; - } - if (!(mask & KBAutoRepeatMode)) - return BadMatch; - break; - case KBAutoRepeatMode: - i = (key >> 3); - mask = (1 << (key & 7)); - t = (CARD8)*vlist; - vlist++; + break; + case KBKey: + key = (KeyCode) *vlist; + vlist++; + if ((KeyCode) key < keybd->key->xkbInfo->desc->min_key_code || + (KeyCode) key > keybd->key->xkbInfo->desc->max_key_code) { + client->errorValue = key; + return BadValue; + } + if (!(mask & KBAutoRepeatMode)) + return BadMatch; + break; + case KBAutoRepeatMode: + i = (key >> 3); + mask = (1 << (key & 7)); + t = (CARD8) *vlist; + vlist++; if (key != DO_ALL) - XkbDisableComputedAutoRepeats(keybd,key); - if (t == AutoRepeatModeOff) { - if (key == DO_ALL) - ctrl.autoRepeat = FALSE; - else - ctrl.autoRepeats[i] &= ~mask; - } - else if (t == AutoRepeatModeOn) { - if (key == DO_ALL) - ctrl.autoRepeat = TRUE; - else - ctrl.autoRepeats[i] |= mask; - } - else if (t == AutoRepeatModeDefault) { - if (key == DO_ALL) - ctrl.autoRepeat = defaultKeyboardControl.autoRepeat; - else - ctrl.autoRepeats[i] = - (ctrl.autoRepeats[i] & ~mask) | - (defaultKeyboardControl.autoRepeats[i] & mask); - } - else { - client->errorValue = t; - return BadValue; - } - break; - default: - client->errorValue = mask; - return BadValue; - } + XkbDisableComputedAutoRepeats(keybd, key); + if (t == AutoRepeatModeOff) { + if (key == DO_ALL) + ctrl.autoRepeat = FALSE; + else + ctrl.autoRepeats[i] &= ~mask; + } + else if (t == AutoRepeatModeOn) { + if (key == DO_ALL) + ctrl.autoRepeat = TRUE; + else + ctrl.autoRepeats[i] |= mask; + } + else if (t == AutoRepeatModeDefault) { + if (key == DO_ALL) + ctrl.autoRepeat = defaultKeyboardControl.autoRepeat; + else + ctrl.autoRepeats[i] = + (ctrl.autoRepeats[i] & ~mask) | + (defaultKeyboardControl.autoRepeats[i] & mask); + } + else { + client->errorValue = t; + return BadValue; + } + break; + default: + client->errorValue = mask; + return BadValue; + } } keybd->kbdfeed->ctrl = ctrl; /* The XKB RepeatKeys control and core protocol global autorepeat */ - /* value are linked */ + /* value are linked */ XkbSetRepeatKeys(keybd, key, keybd->kbdfeed->ctrl.autoRepeat); return Success; @@ -2076,38 +2069,40 @@ DoChangeKeyboardControl (ClientPtr client, DeviceIntPtr keybd, XID *vlist, * Changes kbd control on the ClientPointer and all attached SDs. */ int -ProcChangeKeyboardControl (ClientPtr client) +ProcChangeKeyboardControl(ClientPtr client) { XID *vlist; BITS32 vmask; int ret = Success, error = Success; DeviceIntPtr pDev = NULL, keyboard; + REQUEST(xChangeKeyboardControlReq); REQUEST_AT_LEAST_SIZE(xChangeKeyboardControlReq); vmask = stuff->mask; - vlist = (XID *)&stuff[1]; + vlist = (XID *) &stuff[1]; - if (client->req_len != (sizeof(xChangeKeyboardControlReq)>>2)+Ones(vmask)) - return BadLength; + if (client->req_len != + (sizeof(xChangeKeyboardControlReq) >> 2) + Ones(vmask)) + return BadLength; keyboard = PickKeyboard(client); for (pDev = inputInfo.devices; pDev; pDev = pDev->next) { if ((pDev == keyboard || - (!IsMaster(pDev) && GetMaster(pDev, MASTER_KEYBOARD) == keyboard)) - && pDev->kbdfeed && pDev->kbdfeed->CtrlProc) { + (!IsMaster(pDev) && GetMaster(pDev, MASTER_KEYBOARD) == keyboard)) + && pDev->kbdfeed && pDev->kbdfeed->CtrlProc) { ret = XaceHook(XACE_DEVICE_ACCESS, client, pDev, DixManageAccess); - if (ret != Success) + if (ret != Success) return ret; } } for (pDev = inputInfo.devices; pDev; pDev = pDev->next) { if ((pDev == keyboard || - (!IsMaster(pDev) && GetMaster(pDev, MASTER_KEYBOARD) == keyboard)) - && pDev->kbdfeed && pDev->kbdfeed->CtrlProc) { + (!IsMaster(pDev) && GetMaster(pDev, MASTER_KEYBOARD) == keyboard)) + && pDev->kbdfeed && pDev->kbdfeed->CtrlProc) { ret = DoChangeKeyboardControl(client, pDev, vlist, vmask); if (ret != Success) error = ret; @@ -2118,17 +2113,18 @@ ProcChangeKeyboardControl (ClientPtr client) } int -ProcGetKeyboardControl (ClientPtr client) +ProcGetKeyboardControl(ClientPtr client) { int rc, i; DeviceIntPtr kbd = PickKeyboard(client); KeybdCtrl *ctrl = &kbd->kbdfeed->ctrl; xGetKeyboardControlReply rep; + REQUEST_SIZE_MATCH(xReq); rc = XaceHook(XACE_DEVICE_ACCESS, client, kbd, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; rep.length = 5; @@ -2140,7 +2136,7 @@ ProcGetKeyboardControl (ClientPtr client) rep.bellDuration = ctrl->bell_duration; rep.ledMask = ctrl->leds; for (i = 0; i < 32; i++) - rep.map[i] = ctrl->autoRepeats[i]; + rep.map[i] = ctrl->autoRepeats[i]; WriteReplyToClient(client, sizeof(xGetKeyboardControlReply), &rep); return Success; } @@ -2152,28 +2148,29 @@ ProcBell(ClientPtr client) int base = keybd->kbdfeed->ctrl.bell; int newpercent; int rc; + REQUEST(xBellReq); REQUEST_SIZE_MATCH(xBellReq); if (stuff->percent < -100 || stuff->percent > 100) { - client->errorValue = stuff->percent; - return BadValue; + client->errorValue = stuff->percent; + return BadValue; } newpercent = (base * stuff->percent) / 100; if (stuff->percent < 0) newpercent = base + newpercent; else - newpercent = base - newpercent + stuff->percent; + newpercent = base - newpercent + stuff->percent; for (dev = inputInfo.devices; dev; dev = dev->next) { if ((dev == keybd || - (!IsMaster(dev) && GetMaster(dev, MASTER_KEYBOARD) == keybd)) && + (!IsMaster(dev) && GetMaster(dev, MASTER_KEYBOARD) == keybd)) && dev->kbdfeed && dev->kbdfeed->BellProc) { - rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixBellAccess); - if (rc != Success) - return rc; + rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixBellAccess); + if (rc != Success) + return rc; XkbHandleBell(FALSE, FALSE, dev, newpercent, &dev->kbdfeed->ctrl, 0, None, NULL, client); } @@ -2186,69 +2183,70 @@ int ProcChangePointerControl(ClientPtr client) { DeviceIntPtr dev, mouse = PickPointer(client); - PtrCtrl ctrl; /* might get BadValue part way through */ + PtrCtrl ctrl; /* might get BadValue part way through */ int rc; + REQUEST(xChangePointerControlReq); REQUEST_SIZE_MATCH(xChangePointerControlReq); ctrl = mouse->ptrfeed->ctrl; if ((stuff->doAccel != xTrue) && (stuff->doAccel != xFalse)) { - client->errorValue = stuff->doAccel; - return BadValue; + client->errorValue = stuff->doAccel; + return BadValue; } if ((stuff->doThresh != xTrue) && (stuff->doThresh != xFalse)) { - client->errorValue = stuff->doThresh; - return BadValue; + client->errorValue = stuff->doThresh; + return BadValue; } if (stuff->doAccel) { - if (stuff->accelNum == -1) { - ctrl.num = defaultPointerControl.num; + if (stuff->accelNum == -1) { + ctrl.num = defaultPointerControl.num; } - else if (stuff->accelNum < 0) { - client->errorValue = stuff->accelNum; - return BadValue; - } - else { + else if (stuff->accelNum < 0) { + client->errorValue = stuff->accelNum; + return BadValue; + } + else { ctrl.num = stuff->accelNum; } - if (stuff->accelDenum == -1) { - ctrl.den = defaultPointerControl.den; + if (stuff->accelDenum == -1) { + ctrl.den = defaultPointerControl.den; + } + else if (stuff->accelDenum <= 0) { + client->errorValue = stuff->accelDenum; + return BadValue; } - else if (stuff->accelDenum <= 0) { - client->errorValue = stuff->accelDenum; - return BadValue; - } - else { + else { ctrl.den = stuff->accelDenum; } } if (stuff->doThresh) { - if (stuff->threshold == -1) { - ctrl.threshold = defaultPointerControl.threshold; + if (stuff->threshold == -1) { + ctrl.threshold = defaultPointerControl.threshold; + } + else if (stuff->threshold < 0) { + client->errorValue = stuff->threshold; + return BadValue; } - else if (stuff->threshold < 0) { - client->errorValue = stuff->threshold; - return BadValue; - } - else { + else { ctrl.threshold = stuff->threshold; } } for (dev = inputInfo.devices; dev; dev = dev->next) { if ((dev == mouse || - (!IsMaster(dev) && GetMaster(dev, MASTER_POINTER) == mouse)) && + (!IsMaster(dev) && GetMaster(dev, MASTER_POINTER) == mouse)) && dev->ptrfeed) { - rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixManageAccess); - if (rc != Success) - return rc; - } + rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixManageAccess); + if (rc != Success) + return rc; + } } for (dev = inputInfo.devices; dev; dev = dev->next) { if ((dev == mouse || - (!IsMaster(dev) && GetMaster(dev, MASTER_POINTER) == mouse)) && + (!IsMaster(dev) && GetMaster(dev, MASTER_POINTER) == mouse)) && dev->ptrfeed) { dev->ptrfeed->ctrl = ctrl; } @@ -2264,11 +2262,12 @@ ProcGetPointerControl(ClientPtr client) PtrCtrl *ctrl = &ptr->ptrfeed->ctrl; xGetPointerControlReply rep; int rc; + REQUEST_SIZE_MATCH(xReq); rc = XaceHook(XACE_DEVICE_ACCESS, client, ptr, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; rep.length = 0; @@ -2286,76 +2285,74 @@ MaybeStopHint(DeviceIntPtr dev, ClientPtr client) GrabPtr grab = dev->deviceGrab.grab; if ((grab && SameClient(grab, client) && - ((grab->eventMask & PointerMotionHintMask) || - (grab->ownerEvents && - (EventMaskForClient(dev->valuator->motionHintWindow, client) & - PointerMotionHintMask)))) || - (!grab && - (EventMaskForClient(dev->valuator->motionHintWindow, client) & - PointerMotionHintMask))) - dev->valuator->motionHintWindow = NullWindow; + ((grab->eventMask & PointerMotionHintMask) || + (grab->ownerEvents && + (EventMaskForClient(dev->valuator->motionHintWindow, client) & + PointerMotionHintMask)))) || + (!grab && + (EventMaskForClient(dev->valuator->motionHintWindow, client) & + PointerMotionHintMask))) + dev->valuator->motionHintWindow = NullWindow; } int ProcGetMotionEvents(ClientPtr client) { WindowPtr pWin; - xTimecoord * coords = (xTimecoord *) NULL; + xTimecoord *coords = (xTimecoord *) NULL; xGetMotionEventsReply rep; int i, count, xmin, xmax, ymin, ymax, rc; unsigned long nEvents; DeviceIntPtr mouse = PickPointer(client); TimeStamp start, stop; + REQUEST(xGetMotionEventsReq); REQUEST_SIZE_MATCH(xGetMotionEventsReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rc = XaceHook(XACE_DEVICE_ACCESS, client, mouse, DixReadAccess); if (rc != Success) - return rc; + return rc; if (mouse->valuator->motionHintWindow) - MaybeStopHint(mouse, client); + MaybeStopHint(mouse, client); rep.type = X_Reply; rep.sequenceNumber = client->sequence; nEvents = 0; start = ClientTimeToServerTime(stuff->start); stop = ClientTimeToServerTime(stuff->stop); if ((CompareTimeStamps(start, stop) != LATER) && - (CompareTimeStamps(start, currentTime) != LATER) && - mouse->valuator->numMotionEvents) - { - if (CompareTimeStamps(stop, currentTime) == LATER) - stop = currentTime; - count = GetMotionHistory(mouse, &coords, start.milliseconds, - stop.milliseconds, pWin->drawable.pScreen, + (CompareTimeStamps(start, currentTime) != LATER) && + mouse->valuator->numMotionEvents) { + if (CompareTimeStamps(stop, currentTime) == LATER) + stop = currentTime; + count = GetMotionHistory(mouse, &coords, start.milliseconds, + stop.milliseconds, pWin->drawable.pScreen, TRUE); - xmin = pWin->drawable.x - wBorderWidth (pWin); - xmax = pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth (pWin); - ymin = pWin->drawable.y - wBorderWidth (pWin); - ymax = pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin); - for (i = 0; i < count; i++) - if ((xmin <= coords[i].x) && (coords[i].x < xmax) && - (ymin <= coords[i].y) && (coords[i].y < ymax)) - { - coords[nEvents].time = coords[i].time; - coords[nEvents].x = coords[i].x - pWin->drawable.x; - coords[nEvents].y = coords[i].y - pWin->drawable.y; - nEvents++; - } + xmin = pWin->drawable.x - wBorderWidth(pWin); + xmax = pWin->drawable.x + (int) pWin->drawable.width + + wBorderWidth(pWin); + ymin = pWin->drawable.y - wBorderWidth(pWin); + ymax = pWin->drawable.y + (int) pWin->drawable.height + + wBorderWidth(pWin); + for (i = 0; i < count; i++) + if ((xmin <= coords[i].x) && (coords[i].x < xmax) && + (ymin <= coords[i].y) && (coords[i].y < ymax)) { + coords[nEvents].time = coords[i].time; + coords[nEvents].x = coords[i].x - pWin->drawable.x; + coords[nEvents].y = coords[i].y - pWin->drawable.y; + nEvents++; + } } rep.length = nEvents * bytes_to_int32(sizeof(xTimecoord)); rep.nEvents = nEvents; WriteReplyToClient(client, sizeof(xGetMotionEventsReply), &rep); - if (nEvents) - { - client->pSwapReplyFunc = (ReplySwapPtr) SwapTimeCoordWrite; - WriteSwappedDataToClient(client, nEvents * sizeof(xTimecoord), - (char *)coords); + if (nEvents) { + client->pSwapReplyFunc = (ReplySwapPtr) SwapTimeCoordWrite; + WriteSwappedDataToClient(client, nEvents * sizeof(xTimecoord), + (char *) coords); } free(coords); return Success; @@ -2376,20 +2373,19 @@ ProcQueryKeymap(ClientPtr client) rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess); if (rc != Success && rc != BadAccess) - return rc; + return rc; - for (i = 0; i<32; i++) - rep.map[i] = down[i]; + for (i = 0; i < 32; i++) + rep.map[i] = down[i]; if (rc == BadAccess) - memset(rep.map, 0, 32); + memset(rep.map, 0, 32); WriteReplyToClient(client, sizeof(xQueryKeymapReply), &rep); - return Success; + return Success; } - /** * Recalculate the number of buttons for the master device. The number of * buttons on the master device is equal to the number of buttons on the @@ -2408,18 +2404,15 @@ RecalculateMasterButtons(DeviceIntPtr slave) if (!master) return; - for (dev = inputInfo.devices; dev; dev = dev->next) - { + for (dev = inputInfo.devices; dev; dev = dev->next) { if (IsMaster(dev) || - GetMaster(dev, MASTER_ATTACHED) != master || - !dev->button) + GetMaster(dev, MASTER_ATTACHED) != master || !dev->button) continue; maxbuttons = max(maxbuttons, dev->button->numButtons); } - if (master->button && master->button->numButtons != maxbuttons) - { + if (master->button && master->button->numButtons != maxbuttons) { int i; DeviceChangedEvent event; @@ -2434,23 +2427,21 @@ RecalculateMasterButtons(DeviceIntPtr slave) event.flags = DEVCHANGE_POINTER_EVENT | DEVCHANGE_DEVICE_CHANGE; event.buttons.num_buttons = maxbuttons; memcpy(&event.buttons.names, master->button->labels, maxbuttons * - sizeof(Atom)); + sizeof(Atom)); - if (master->valuator) - { + if (master->valuator) { event.num_valuators = master->valuator->numAxes; - for (i = 0; i < event.num_valuators; i++) - { + for (i = 0; i < event.num_valuators; i++) { event.valuators[i].min = master->valuator->axes[i].min_value; event.valuators[i].max = master->valuator->axes[i].max_value; - event.valuators[i].resolution = master->valuator->axes[i].resolution; + event.valuators[i].resolution = + master->valuator->axes[i].resolution; event.valuators[i].mode = master->valuator->axes[i].mode; event.valuators[i].name = master->valuator->axes[i].label; } } - if (master->key) - { + if (master->key) { event.keys.min_keycode = master->key->xkbInfo->desc->min_key_code; event.keys.max_keycode = master->key->xkbInfo->desc->max_key_code; } @@ -2466,30 +2457,27 @@ RecalculateMasterButtons(DeviceIntPtr slave) void ReleaseButtonsAndKeys(DeviceIntPtr dev) { - InternalEvent* eventlist = InitEventList(GetMaximumEventsNum()); - ButtonClassPtr b = dev->button; - KeyClassPtr k = dev->key; - int i, j, nevents; + InternalEvent *eventlist = InitEventList(GetMaximumEventsNum()); + ButtonClassPtr b = dev->button; + KeyClassPtr k = dev->key; + int i, j, nevents; - if (!eventlist) /* no release events for you */ + if (!eventlist) /* no release events for you */ return; /* Release all buttons */ - for (i = 0; b && i < b->numButtons; i++) - { - if (BitIsOn(b->down, i)) - { - nevents = GetPointerEvents(eventlist, dev, ButtonRelease, i, 0, NULL); + for (i = 0; b && i < b->numButtons; i++) { + if (BitIsOn(b->down, i)) { + nevents = + GetPointerEvents(eventlist, dev, ButtonRelease, i, 0, NULL); for (j = 0; j < nevents; j++) mieqProcessDeviceEvent(dev, &eventlist[j], NULL); } } /* Release all keys */ - for (i = 0; k && i < MAP_LENGTH; i++) - { - if (BitIsOn(k->down, i)) - { + for (i = 0; k && i < MAP_LENGTH; i++) { + if (BitIsOn(k->down, i)) { nevents = GetKeyboardEvents(eventlist, dev, KeyRelease, i, NULL); for (j = 0; j < nevents; j++) mieqProcessDeviceEvent(dev, &eventlist[j], NULL); @@ -2513,10 +2501,11 @@ int AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master) { ScreenPtr screen; + if (!dev || IsMaster(dev)) return BadDevice; - if (master && !IsMaster(master)) /* can't attach to slaves */ + if (master && !IsMaster(master)) /* can't attach to slaves */ return BadDevice; /* set from floating to floating? */ @@ -2524,8 +2513,7 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master) return Success; /* free the existing sprite. */ - if (IsFloating(dev) && dev->spriteInfo->paired == dev) - { + if (IsFloating(dev) && dev->spriteInfo->paired == dev) { screen = miPointerGetScreen(dev); screen->DeviceCursorCleanup(dev, screen); free(dev->spriteInfo->sprite); @@ -2539,13 +2527,12 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master) * Sprite has to be forced to NULL first, otherwise InitializeSprite won't * alloc new memory but overwrite the previous one. */ - if (!master) - { + if (!master) { WindowPtr currentRoot; if (dev->spriteInfo->sprite) currentRoot = GetCurrentRootWindow(dev); - else /* new device auto-set to floating */ + else /* new device auto-set to floating */ currentRoot = screenInfo.screens[0]->root; /* we need to init a fake sprite */ @@ -2555,8 +2542,8 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master) InitializeSprite(dev, currentRoot); dev->spriteInfo->spriteOwner = FALSE; dev->spriteInfo->paired = dev; - } else - { + } + else { dev->spriteInfo->sprite = master->spriteInfo->sprite; dev->spriteInfo->paired = master; dev->spriteInfo->spriteOwner = FALSE; @@ -2587,7 +2574,6 @@ GetPairedDevice(DeviceIntPtr dev) return dev->spriteInfo->paired; } - /** * Returns the requested master for this device. * The return values are: @@ -2615,18 +2601,17 @@ GetMaster(DeviceIntPtr dev, int which) master = dev; else { master = dev->master; - if (!master && (which == POINTER_OR_FLOAT || which == KEYBOARD_OR_FLOAT)) + if (!master && + (which == POINTER_OR_FLOAT || which == KEYBOARD_OR_FLOAT)) return dev; } - if (master && which != MASTER_ATTACHED) - { - if (which == MASTER_KEYBOARD || which == KEYBOARD_OR_FLOAT) - { + if (master && which != MASTER_ATTACHED) { + if (which == MASTER_KEYBOARD || which == KEYBOARD_OR_FLOAT) { if (master->type != MASTER_KEYBOARD) master = GetPairedDevice(master); - } else - { + } + else { if (master->type != MASTER_POINTER) master = GetPairedDevice(master); } @@ -2643,24 +2628,25 @@ GetMaster(DeviceIntPtr dev, int which) * the value for master. */ int -AllocDevicePair (ClientPtr client, const char* name, - DeviceIntPtr* ptr, - DeviceIntPtr* keybd, - DeviceProc ptr_proc, - DeviceProc keybd_proc, - Bool master) +AllocDevicePair(ClientPtr client, const char *name, + DeviceIntPtr *ptr, + DeviceIntPtr *keybd, + DeviceProc ptr_proc, DeviceProc keybd_proc, Bool master) { DeviceIntPtr pointer; DeviceIntPtr keyboard; + *ptr = *keybd = NULL; pointer = AddInputDevice(client, ptr_proc, TRUE); + if (!pointer) return BadAlloc; if (asprintf(&pointer->name, "%s pointer", name) == -1) { pointer->name = NULL; RemoveDevice(pointer, FALSE); + return BadAlloc; } @@ -2677,9 +2663,9 @@ AllocDevicePair (ClientPtr client, const char* name, pointer->type = (master) ? MASTER_POINTER : SLAVE; keyboard = AddInputDevice(client, keybd_proc, TRUE); - if (!keyboard) - { + if (!keyboard) { RemoveDevice(pointer, FALSE); + return BadAlloc; } @@ -2687,6 +2673,7 @@ AllocDevicePair (ClientPtr client, const char* name, keyboard->name = NULL; RemoveDevice(keyboard, FALSE); RemoveDevice(pointer, FALSE); + return BadAlloc; } @@ -2704,9 +2691,11 @@ AllocDevicePair (ClientPtr client, const char* name, /* The ClassesRec stores the device classes currently not used. */ pointer->unused_classes = calloc(1, sizeof(ClassesRec)); + keyboard->unused_classes = calloc(1, sizeof(ClassesRec)); *ptr = pointer; + *keybd = keyboard; return Success; @@ -2715,7 +2704,8 @@ AllocDevicePair (ClientPtr client, const char* name, /** * Return Relative or Absolute for the device. */ -int valuator_get_mode(DeviceIntPtr dev, int axis) +int +valuator_get_mode(DeviceIntPtr dev, int axis) { return (dev->valuator->axes[axis].mode & DeviceMode); } @@ -2724,12 +2714,14 @@ int valuator_get_mode(DeviceIntPtr dev, int axis) * Set the given mode for the axis. If axis is VALUATOR_MODE_ALL_AXES, then * set the mode for all axes. */ -void valuator_set_mode(DeviceIntPtr dev, int axis, int mode) +void +valuator_set_mode(DeviceIntPtr dev, int axis, int mode) { if (axis != VALUATOR_MODE_ALL_AXES) dev->valuator->axes[axis].mode = mode; else { int i; + for (i = 0; i < dev->valuator->numAxes; i++) dev->valuator->axes[i].mode = mode; } diff --git a/xorg-server/dix/dispatch.c b/xorg-server/dix/dispatch.c index 44c24337a..104dcc9b3 100644 --- a/xorg-server/dix/dispatch.c +++ b/xorg-server/dix/dispatch.c @@ -22,7 +22,6 @@ 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 @@ -97,8 +96,6 @@ Equipment Corporation. * DEALINGS IN THE SOFTWARE. */ - - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #include <version-config.h> @@ -136,6 +133,7 @@ int ProcInitialConnection(); #include "registry.h" #include <sys/types.h> typedef const char *string; + #include "Xserver-dtrace.h" #endif @@ -152,6 +150,7 @@ xConnSetupPrefix connSetupPrefix; PaddingInfo PixmapWidthPaddingInfo[33]; static ClientPtr grabClient; + #define GrabNone 0 #define GrabActive 1 #define GrabKickout 2 @@ -163,9 +162,9 @@ int connBlockScreenStart; static void KillAllClients(void); -static int nextFreeClientID; /* always MIN free client ID */ +static int nextFreeClientID; /* always MIN free client ID */ -static int nClients; /* number of authorized clients */ +static int nClients; /* number of authorized clients */ CallbackListPtr ClientStateCallback; @@ -198,11 +197,11 @@ UpdateCurrentTime(void) systime.months = currentTime.months; systime.milliseconds = GetTimeInMillis(); if (systime.milliseconds < currentTime.milliseconds) - systime.months++; + systime.months++; if (*checkForInput[0] != *checkForInput[1]) - ProcessInputEvents(); + ProcessInputEvents(); if (CompareTimeStamps(systime, currentTime) == LATER) - currentTime = systime; + currentTime = systime; } /* Like UpdateCurrentTime, but can't call ProcessInputEvents */ @@ -214,16 +213,15 @@ UpdateCurrentTimeIf(void) systime.months = currentTime.months; systime.milliseconds = GetTimeInMillis(); if (systime.milliseconds < currentTime.milliseconds) - systime.months++; + systime.months++; if (*checkForInput[0] == *checkForInput[1]) - currentTime = systime; + currentTime = systime; } - #undef SMART_DEBUG -#define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */ -#define SMART_SCHEDULE_MAX_SLICE 200 /* ms */ +#define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */ +#define SMART_SCHEDULE_MAX_SLICE 200 /* ms */ Bool SmartScheduleDisable = FALSE; long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL; @@ -231,91 +229,86 @@ long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL; long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE; long SmartScheduleTime; int SmartScheduleLatencyLimited = 0; -static ClientPtr SmartLastClient; -static int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1]; +static ClientPtr SmartLastClient; +static int SmartLastIndex[SMART_MAX_PRIORITY - SMART_MIN_PRIORITY + 1]; #ifdef SMART_DEBUG -long SmartLastPrint; +long SmartLastPrint; #endif -void Dispatch(void); +void Dispatch(void); static int -SmartScheduleClient (int *clientReady, int nready) +SmartScheduleClient(int *clientReady, int nready) { - ClientPtr pClient; - int i; - int client; - int bestPrio, best = 0; - int bestRobin, robin; - long now = SmartScheduleTime; - long idle; + 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; - } + 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); + 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; + if ((now - SmartLastPrint) >= 5000) { + fprintf(stderr, " use %2d\n", best); + SmartLastPrint = now; } #endif pClient = clients[best]; - SmartLastIndex[bestPrio-SMART_MIN_PRIORITY] = pClient->index; + SmartLastIndex[bestPrio - SMART_MIN_PRIORITY] = pClient->index; /* * Set current client pointer */ - if (SmartLastClient != pClient) - { - pClient->smart_start_tick = now; - SmartLastClient = pClient; + if (SmartLastClient != pClient) { + pClient->smart_start_tick = now; + SmartLastClient = pClient; } /* * Adjust slice */ - if (nready == 1 && SmartScheduleLatencyLimited == 0) - { - /* - * 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; - } + if (nready == 1 && SmartScheduleLatencyLimited == 0) { + /* + * 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; + else { + SmartScheduleSlice = SmartScheduleInterval; } return best; } @@ -334,140 +327,132 @@ DisableLimitedSchedulingLatency(void) /* protect against bugs */ if (SmartScheduleLatencyLimited < 0) - SmartScheduleLatencyLimited = 0; + SmartScheduleLatencyLimited = 0; } void Dispatch(void) { - int *clientReady; /* array of request ready clients */ - int result; - ClientPtr client; - int nready; - HWEventQueuePtr* icheck = checkForInput; - long start_tick; + int *clientReady; /* array of request ready clients */ + int result; + ClientPtr client; + int nready; + HWEventQueuePtr *icheck = checkForInput; + long start_tick; nextFreeClientID = 1; nClients = 0; clientReady = malloc(sizeof(int) * MaxClients); if (!clientReady) - return; + return; SmartScheduleSlice = SmartScheduleInterval; - while (!dispatchException) - { - if (*icheck[0] != *icheck[1]) - { - ProcessInputEvents(); - FlushIfCriticalOutputPending(); - } - - nready = WaitForSomething(clientReady); - - if (nready && !SmartScheduleDisable) - { - clientReady[0] = SmartScheduleClient (clientReady, nready); - nready = 1; - } + while (!dispatchException) { + if (*icheck[0] != *icheck[1]) { + ProcessInputEvents(); + FlushIfCriticalOutputPending(); + } + + nready = WaitForSomething(clientReady); + + if (nready && !SmartScheduleDisable) { + clientReady[0] = SmartScheduleClient(clientReady, nready); + nready = 1; + } /***************** * 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; - - start_tick = SmartScheduleTime; - while (!isItTimeToYield) - { - if (*icheck[0] != *icheck[1]) - ProcessInputEvents(); - - FlushIfCriticalOutputPending(); - if (!SmartScheduleDisable && - (SmartScheduleTime - start_tick) >= SmartScheduleSlice) - { - /* Penalize clients which consume ticks */ - if (client->smart_priority > SMART_MIN_PRIORITY) - client->smart_priority--; - break; - } - /* now, finally, deal with client requests */ - - result = ReadRequestFromClient(client); - if (result <= 0) - { - if (result < 0) - CloseDownClient(client); - break; - } - - client->sequence++; - client->majorOp = ((xReq *)client->requestBuffer)->reqType; - client->minorOp = 0; - if (client->majorOp >= EXTENSION_BASE) { - ExtensionEntry *ext = GetExtensionEntry(client->majorOp); - if (ext) - client->minorOp = ext->MinorOpcode(client); - } + 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; + + start_tick = SmartScheduleTime; + while (!isItTimeToYield) { + if (*icheck[0] != *icheck[1]) + ProcessInputEvents(); + + FlushIfCriticalOutputPending(); + if (!SmartScheduleDisable && + (SmartScheduleTime - start_tick) >= SmartScheduleSlice) { + /* Penalize clients which consume ticks */ + if (client->smart_priority > SMART_MIN_PRIORITY) + client->smart_priority--; + break; + } + /* now, finally, deal with client requests */ + + result = ReadRequestFromClient(client); + if (result <= 0) { + if (result < 0) + CloseDownClient(client); + break; + } + + client->sequence++; + client->majorOp = ((xReq *) client->requestBuffer)->reqType; + client->minorOp = 0; + if (client->majorOp >= EXTENSION_BASE) { + ExtensionEntry *ext = GetExtensionEntry(client->majorOp); + + if (ext) + client->minorOp = ext->MinorOpcode(client); + } #ifdef XSERVER_DTRACE - if (XSERVER_REQUEST_START_ENABLED()) - XSERVER_REQUEST_START(LookupMajorName(client->majorOp), - client->majorOp, - ((xReq *)client->requestBuffer)->length, - client->index, client->requestBuffer); + if (XSERVER_REQUEST_START_ENABLED()) + XSERVER_REQUEST_START(LookupMajorName(client->majorOp), + client->majorOp, + ((xReq *) client->requestBuffer)-> + length, client->index, + client->requestBuffer); #endif - if (result > (maxBigRequestSize << 2)) - result = BadLength; - else { - result = XaceHookDispatch(client, client->majorOp); - if (result == Success) - result = (* client->requestVector[client->majorOp])(client); - XaceHookAuditEnd(client, result); - } + if (result > (maxBigRequestSize << 2)) + result = BadLength; + else { + result = XaceHookDispatch(client, client->majorOp); + if (result == Success) + result = + (*client->requestVector[client->majorOp]) (client); + XaceHookAuditEnd(client, result); + } #ifdef XSERVER_DTRACE - if (XSERVER_REQUEST_DONE_ENABLED()) - XSERVER_REQUEST_DONE(LookupMajorName(client->majorOp), - client->majorOp, client->sequence, - client->index, result); + if (XSERVER_REQUEST_DONE_ENABLED()) + XSERVER_REQUEST_DONE(LookupMajorName(client->majorOp), + client->majorOp, client->sequence, + client->index, result); #endif - if (client->noClientException != Success) - { - CloseDownClient(client); - break; - } - else if (result != Success) - { - SendErrorToClient(client, client->majorOp, - client->minorOp, - client->errorValue, result); - break; - } - } - FlushAllOutput(); - client = clients[clientReady[nready]]; - if (client) - client->smart_stop_tick = SmartScheduleTime; - } - dispatchException &= ~DE_PRIORITYCHANGE; + if (client->noClientException != Success) { + CloseDownClient(client); + break; + } + else if (result != Success) { + SendErrorToClient(client, client->majorOp, + client->minorOp, + client->errorValue, result); + break; + } + } + FlushAllOutput(); + client = clients[clientReady[nready]]; + if (client) + client->smart_stop_tick = SmartScheduleTime; + } + dispatchException &= ~DE_PRIORITYCHANGE; } #if defined(DDXBEFORERESET) - ddxBeforeReset (); + ddxBeforeReset(); #endif KillAllClients(); free(clientReady); @@ -475,10 +460,10 @@ Dispatch(void) SmartScheduleLatencyLimited = 0; } -static int VendorRelease = VENDOR_RELEASE; +static int VendorRelease = VENDOR_RELEASE; static char *VendorString = VENDOR_NAME; -static const int padlength[4] = {0, 3, 2, 1}; +static const int padlength[4] = { 0, 3, 2, 1 }; void SetVendorRelease(int release) @@ -497,16 +482,13 @@ CreateConnectionBlock(void) { xConnSetup setup; xWindowRoot root; - xDepth depth; + xDepth depth; xVisualType visual; xPixmapFormat format; unsigned long vid; - int i, j, k, - lenofblock, - sizesofar = 0; + int i, j, k, lenofblock, sizesofar = 0; char *pBuf; - memset(&setup, 0, sizeof(xConnSetup)); /* Leave off the ridBase and ridMask, these must be sent with connection */ @@ -529,112 +511,104 @@ CreateConnectionBlock(void) QueryMinMaxKeyCodes(&setup.minKeyCode, &setup.maxKeyCode); lenofblock = sizeof(xConnSetup) + - pad_to_int32(setup.nbytesVendor) + - (setup.numFormats * sizeof(xPixmapFormat)) + - (setup.numRoots * sizeof(xWindowRoot)); + pad_to_int32(setup.nbytesVendor) + + (setup.numFormats * sizeof(xPixmapFormat)) + + (setup.numRoots * sizeof(xWindowRoot)); ConnectionInfo = malloc(lenofblock); if (!ConnectionInfo) - return FALSE; + return FALSE; - memmove(ConnectionInfo, (char *)&setup, sizeof(xConnSetup)); + memmove(ConnectionInfo, (char *) &setup, sizeof(xConnSetup)); sizesofar = sizeof(xConnSetup); pBuf = ConnectionInfo + sizeof(xConnSetup); - memmove(pBuf, VendorString, (int)setup.nbytesVendor); + memmove(pBuf, VendorString, (int) setup.nbytesVendor); sizesofar += setup.nbytesVendor; pBuf += setup.nbytesVendor; i = padlength[setup.nbytesVendor & 3]; sizesofar += i; while (--i >= 0) - *pBuf++ = 0; + *pBuf++ = 0; memset(&format, 0, sizeof(xPixmapFormat)); - for (i=0; i<screenInfo.numPixmapFormats; i++) - { - format.depth = screenInfo.formats[i].depth; - format.bitsPerPixel = screenInfo.formats[i].bitsPerPixel; - format.scanLinePad = screenInfo.formats[i].scanlinePad; - memmove(pBuf, (char *)&format, sizeof(xPixmapFormat)); - pBuf += sizeof(xPixmapFormat); - sizesofar += sizeof(xPixmapFormat); + for (i = 0; i < screenInfo.numPixmapFormats; i++) { + format.depth = screenInfo.formats[i].depth; + format.bitsPerPixel = screenInfo.formats[i].bitsPerPixel; + format.scanLinePad = screenInfo.formats[i].scanlinePad; + memmove(pBuf, (char *) &format, sizeof(xPixmapFormat)); + pBuf += sizeof(xPixmapFormat); + sizesofar += sizeof(xPixmapFormat); } connBlockScreenStart = sizesofar; memset(&depth, 0, sizeof(xDepth)); memset(&visual, 0, sizeof(xVisualType)); - for (i=0; i<screenInfo.numScreens; i++) - { - ScreenPtr pScreen; - DepthPtr pDepth; - VisualPtr pVisual; - - pScreen = screenInfo.screens[i]; - root.windowId = pScreen->root->drawable.id; - root.defaultColormap = pScreen->defColormap; - root.whitePixel = pScreen->whitePixel; - root.blackPixel = pScreen->blackPixel; - root.currentInputMask = 0; /* filled in when sent */ - root.pixWidth = pScreen->width; - root.pixHeight = pScreen->height; - root.mmWidth = pScreen->mmWidth; - root.mmHeight = pScreen->mmHeight; - root.minInstalledMaps = pScreen->minInstalledCmaps; - root.maxInstalledMaps = pScreen->maxInstalledCmaps; - root.rootVisualID = pScreen->rootVisual; - root.backingStore = pScreen->backingStoreSupport; - root.saveUnders = FALSE; - root.rootDepth = pScreen->rootDepth; - root.nDepths = pScreen->numDepths; - memmove(pBuf, (char *)&root, sizeof(xWindowRoot)); - sizesofar += sizeof(xWindowRoot); - pBuf += sizeof(xWindowRoot); - - pDepth = pScreen->allowedDepths; - for(j = 0; j < pScreen->numDepths; j++, pDepth++) - { - lenofblock += sizeof(xDepth) + - (pDepth->numVids * sizeof(xVisualType)); - pBuf = (char *)realloc(ConnectionInfo, lenofblock); - if (!pBuf) - { - free(ConnectionInfo); - return FALSE; - } - ConnectionInfo = pBuf; - pBuf += sizesofar; - depth.depth = pDepth->depth; - depth.nVisuals = pDepth->numVids; - memmove(pBuf, (char *)&depth, sizeof(xDepth)); - pBuf += sizeof(xDepth); - sizesofar += sizeof(xDepth); - for(k = 0; k < pDepth->numVids; k++) - { - vid = pDepth->vids[k]; - for (pVisual = pScreen->visuals; - pVisual->vid != vid; - pVisual++) - ; - visual.visualID = vid; - visual.class = pVisual->class; - visual.bitsPerRGB = pVisual->bitsPerRGBValue; - visual.colormapEntries = pVisual->ColormapEntries; - visual.redMask = pVisual->redMask; - visual.greenMask = pVisual->greenMask; - visual.blueMask = pVisual->blueMask; - memmove(pBuf, (char *)&visual, sizeof(xVisualType)); - pBuf += sizeof(xVisualType); - sizesofar += sizeof(xVisualType); - } - } + for (i = 0; i < screenInfo.numScreens; i++) { + ScreenPtr pScreen; + DepthPtr pDepth; + VisualPtr pVisual; + + pScreen = screenInfo.screens[i]; + root.windowId = pScreen->root->drawable.id; + root.defaultColormap = pScreen->defColormap; + root.whitePixel = pScreen->whitePixel; + root.blackPixel = pScreen->blackPixel; + root.currentInputMask = 0; /* filled in when sent */ + root.pixWidth = pScreen->width; + root.pixHeight = pScreen->height; + root.mmWidth = pScreen->mmWidth; + root.mmHeight = pScreen->mmHeight; + root.minInstalledMaps = pScreen->minInstalledCmaps; + root.maxInstalledMaps = pScreen->maxInstalledCmaps; + root.rootVisualID = pScreen->rootVisual; + root.backingStore = pScreen->backingStoreSupport; + root.saveUnders = FALSE; + root.rootDepth = pScreen->rootDepth; + root.nDepths = pScreen->numDepths; + memmove(pBuf, (char *) &root, sizeof(xWindowRoot)); + sizesofar += sizeof(xWindowRoot); + pBuf += sizeof(xWindowRoot); + + pDepth = pScreen->allowedDepths; + for (j = 0; j < pScreen->numDepths; j++, pDepth++) { + lenofblock += sizeof(xDepth) + + (pDepth->numVids * sizeof(xVisualType)); + pBuf = (char *) realloc(ConnectionInfo, lenofblock); + if (!pBuf) { + free(ConnectionInfo); + return FALSE; + } + ConnectionInfo = pBuf; + pBuf += sizesofar; + depth.depth = pDepth->depth; + depth.nVisuals = pDepth->numVids; + memmove(pBuf, (char *) &depth, sizeof(xDepth)); + pBuf += sizeof(xDepth); + sizesofar += sizeof(xDepth); + for (k = 0; k < pDepth->numVids; k++) { + vid = pDepth->vids[k]; + for (pVisual = pScreen->visuals; + pVisual->vid != vid; pVisual++); + visual.visualID = vid; + visual.class = pVisual->class; + visual.bitsPerRGB = pVisual->bitsPerRGBValue; + visual.colormapEntries = pVisual->ColormapEntries; + visual.redMask = pVisual->redMask; + visual.greenMask = pVisual->greenMask; + visual.blueMask = pVisual->blueMask; + memmove(pBuf, (char *) &visual, sizeof(xVisualType)); + pBuf += sizeof(xVisualType); + sizesofar += sizeof(xVisualType); + } + } } connSetupPrefix.success = xTrue; - connSetupPrefix.length = lenofblock/4; + connSetupPrefix.length = lenofblock / 4; connSetupPrefix.majorVersion = X_PROTOCOL; connSetupPrefix.minorVersion = X_PROTOCOL_REVISION; return TRUE; } - int ProcBadRequest(ClientPtr client) { @@ -645,11 +619,12 @@ int ProcCreateWindow(ClientPtr client) { WindowPtr pParent, pWin; + REQUEST(xCreateWindowReq); int len, rc; REQUEST_AT_LEAST_SIZE(xCreateWindowReq); - + LEGAL_NEW_RESOURCE(stuff->wid, client); rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess); if (rc != Success) @@ -657,25 +632,22 @@ ProcCreateWindow(ClientPtr client) len = client->req_len - bytes_to_int32(sizeof(xCreateWindowReq)); if (Ones(stuff->mask) != len) return BadLength; - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; + 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, &rc); - 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; + stuff->y, stuff->width, stuff->height, + stuff->borderWidth, stuff->class, + stuff->mask, (XID *) &stuff[1], + (int) stuff->depth, client, stuff->visual, &rc); + 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; } return rc; } @@ -684,6 +656,7 @@ int ProcChangeWindowAttributes(ClientPtr client) { WindowPtr pWin; + REQUEST(xChangeWindowAttributesReq); int len, rc; Mask access_mode = 0; @@ -698,15 +671,14 @@ ProcChangeWindowAttributes(ClientPtr client) if (len != Ones(stuff->valueMask)) return BadLength; return ChangeWindowAttributes(pWin, - stuff->valueMask, - (XID *) &stuff[1], - client); + stuff->valueMask, (XID *) &stuff[1], client); } int ProcGetWindowAttributes(ClientPtr client) { WindowPtr pWin; + REQUEST(xResourceReq); xGetWindowAttributesReply wa; int rc; @@ -714,7 +686,7 @@ ProcGetWindowAttributes(ClientPtr client) REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; memset(&wa, 0, sizeof(xGetWindowAttributesReply)); GetWindowAttributes(pWin, client, &wa); WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa); @@ -725,19 +697,20 @@ int ProcDestroyWindow(ClientPtr client) { WindowPtr pWin; + REQUEST(xResourceReq); int rc; REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixDestroyAccess); if (rc != Success) - return rc; + return rc; if (pWin->parent) { - rc = dixLookupWindow(&pWin, pWin->parent->drawable.id, client, - DixRemoveAccess); - if (rc != Success) - return rc; - FreeResource(stuff->id, RT_NONE); + rc = dixLookupWindow(&pWin, pWin->parent->drawable.id, client, + DixRemoveAccess); + if (rc != Success) + return rc; + FreeResource(stuff->id, RT_NONE); } return Success; } @@ -746,13 +719,14 @@ int ProcDestroySubwindows(ClientPtr client) { WindowPtr pWin; + REQUEST(xResourceReq); int rc; REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixRemoveAccess); if (rc != Success) - return rc; + return rc; DestroySubwindows(pWin, client); return Success; } @@ -761,9 +735,10 @@ int ProcChangeSaveSet(ClientPtr client) { WindowPtr pWin; + REQUEST(xChangeSaveSetReq); int rc; - + REQUEST_SIZE_MATCH(xChangeSaveSetReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess); if (rc != Success) @@ -780,6 +755,7 @@ int ProcReparentWindow(ClientPtr client) { WindowPtr pWin, pParent; + REQUEST(xReparentWindowReq); int rc; @@ -791,21 +767,22 @@ ProcReparentWindow(ClientPtr client) if (rc != Success) return rc; if (!SAME_SCREENS(pWin->drawable, pParent->drawable)) - return BadMatch; + return BadMatch; if ((pWin->backgroundState == ParentRelative) && - (pParent->drawable.depth != pWin->drawable.depth)) - return BadMatch; + (pParent->drawable.depth != pWin->drawable.depth)) + return BadMatch; if ((pWin->drawable.class != InputOnly) && - (pParent->drawable.class == InputOnly)) - return BadMatch; + (pParent->drawable.class == InputOnly)) + return BadMatch; return ReparentWindow(pWin, pParent, - (short)stuff->x, (short)stuff->y, client); + (short) stuff->x, (short) stuff->y, client); } int ProcMapWindow(ClientPtr client) { WindowPtr pWin; + REQUEST(xResourceReq); int rc; @@ -814,7 +791,7 @@ ProcMapWindow(ClientPtr client) if (rc != Success) return rc; MapWindow(pWin, client); - /* update cache to say it is mapped */ + /* update cache to say it is mapped */ return Success; } @@ -822,6 +799,7 @@ int ProcMapSubwindows(ClientPtr client) { WindowPtr pWin; + REQUEST(xResourceReq); int rc; @@ -830,7 +808,7 @@ ProcMapSubwindows(ClientPtr client) if (rc != Success) return rc; MapSubwindows(pWin, client); - /* update cache to say it is mapped */ + /* update cache to say it is mapped */ return Success; } @@ -838,6 +816,7 @@ int ProcUnmapWindow(ClientPtr client) { WindowPtr pWin; + REQUEST(xResourceReq); int rc; @@ -846,7 +825,7 @@ ProcUnmapWindow(ClientPtr client) if (rc != Success) return rc; UnmapWindow(pWin, FALSE); - /* update cache to say it is mapped */ + /* update cache to say it is mapped */ return Success; } @@ -854,6 +833,7 @@ int ProcUnmapSubwindows(ClientPtr client) { WindowPtr pWin; + REQUEST(xResourceReq); int rc; @@ -869,52 +849,53 @@ int ProcConfigureWindow(ClientPtr client) { WindowPtr pWin; + REQUEST(xConfigureWindowReq); int len, rc; REQUEST_AT_LEAST_SIZE(xConfigureWindowReq); rc = dixLookupWindow(&pWin, stuff->window, client, - DixManageAccess|DixSetAttrAccess); + DixManageAccess | DixSetAttrAccess); if (rc != Success) return rc; len = client->req_len - bytes_to_int32(sizeof(xConfigureWindowReq)); - if (Ones((Mask)stuff->mask) != len) + if (Ones((Mask) stuff->mask) != len) return BadLength; - return ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1], client); + return ConfigureWindow(pWin, (Mask) stuff->mask, (XID *) &stuff[1], client); } int ProcCirculateWindow(ClientPtr client) { WindowPtr pWin; + REQUEST(xCirculateWindowReq); int rc; REQUEST_SIZE_MATCH(xCirculateWindowReq); - if ((stuff->direction != RaiseLowest) && - (stuff->direction != LowerHighest)) - { - client->errorValue = stuff->direction; + if ((stuff->direction != RaiseLowest) && (stuff->direction != LowerHighest)) { + client->errorValue = stuff->direction; return BadValue; } rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess); if (rc != Success) return rc; - CirculateWindow(pWin, (int)stuff->direction, client); + CirculateWindow(pWin, (int) stuff->direction, client); return Success; } static int -GetGeometry(ClientPtr client, xGetGeometryReply *rep) +GetGeometry(ClientPtr client, xGetGeometryReply * rep) { DrawablePtr pDraw; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupDrawable(&pDraw, stuff->id, client, M_ANY, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rep->type = X_Reply; rep->length = 0; @@ -924,22 +905,21 @@ GetGeometry(ClientPtr client, xGetGeometryReply *rep) rep->width = pDraw->width; rep->height = pDraw->height; - if (WindowDrawable(pDraw->type)) - { - WindowPtr pWin = (WindowPtr)pDraw; - rep->x = pWin->origin.x - wBorderWidth (pWin); - rep->y = pWin->origin.y - wBorderWidth (pWin); - rep->borderWidth = pWin->borderWidth; + if (WindowDrawable(pDraw->type)) { + 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 */ - { - rep->x = rep->y = rep->borderWidth = 0; + else { /* DRAWABLE_PIXMAP */ + + rep->x = rep->y = rep->borderWidth = 0; } return Success; } - int ProcGetGeometry(ClientPtr client) { @@ -948,20 +928,20 @@ ProcGetGeometry(ClientPtr client) memset(&rep, 0, sizeof(xGetGeometryReply)); if ((status = GetGeometry(client, &rep)) != Success) - return status; + return status; WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep); return Success; } - int ProcQueryTree(ClientPtr client) { xQueryTreeReply reply; int rc, numChildren = 0; WindowPtr pChild, pWin, pHead; - Window *childIDs = (Window *)NULL; + Window *childIDs = (Window *) NULL; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); @@ -973,32 +953,32 @@ ProcQueryTree(ClientPtr client) reply.root = pWin->drawable.pScreen->root->drawable.id; reply.sequenceNumber = client->sequence; if (pWin->parent) - reply.parent = pWin->parent->drawable.id; + reply.parent = pWin->parent->drawable.id; else - reply.parent = (Window)None; + reply.parent = (Window) None; pHead = RealChildHead(pWin); for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - numChildren++; - if (numChildren) - { - int curChild = 0; + numChildren++; + if (numChildren) { + int curChild = 0; - childIDs = malloc(numChildren * sizeof(Window)); - if (!childIDs) - return BadAlloc; - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - childIDs[curChild++] = pChild->drawable.id; + childIDs = malloc(numChildren * sizeof(Window)); + if (!childIDs) + return BadAlloc; + for (pChild = pWin->lastChild; pChild != pHead; + pChild = pChild->prevSib) + childIDs[curChild++] = pChild->drawable.id; } - + reply.nChildren = numChildren; reply.length = bytes_to_int32(numChildren * sizeof(Window)); - + WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply); - if (numChildren) - { - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs); - free(childIDs); + if (numChildren) { + client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; + WriteSwappedDataToClient(client, numChildren * sizeof(Window), + childIDs); + free(childIDs); } return Success; @@ -1009,29 +989,29 @@ ProcInternAtom(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; + 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; - memset(&reply, 0, sizeof(xInternAtomReply)); - reply.type = X_Reply; - reply.length = 0; - reply.sequenceNumber = client->sequence; - reply.atom = atom; - WriteReplyToClient(client, sizeof(xInternAtomReply), &reply); - return Success; + if (atom != BAD_RESOURCE) { + xInternAtomReply reply; + + memset(&reply, 0, sizeof(xInternAtomReply)); + reply.type = X_Reply; + reply.length = 0; + reply.sequenceNumber = client->sequence; + reply.atom = atom; + WriteReplyToClient(client, sizeof(xInternAtomReply), &reply); + return Success; } else - return BadAlloc; + return BadAlloc; } int @@ -1040,25 +1020,24 @@ ProcGetAtomName(ClientPtr client) const char *str; xGetAtomNameReply reply; int len; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - if ( (str = NameForAtom(stuff->id)) ) - { - len = strlen(str); - memset(&reply, 0, sizeof(xGetAtomNameReply)); - reply.type = X_Reply; - reply.length = bytes_to_int32(len); - reply.sequenceNumber = client->sequence; - reply.nameLength = len; - WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply); - (void)WriteToClient(client, len, str); - return Success; + if ((str = NameForAtom(stuff->id))) { + len = strlen(str); + memset(&reply, 0, sizeof(xGetAtomNameReply)); + reply.type = X_Reply; + reply.length = bytes_to_int32(len); + reply.sequenceNumber = client->sequence; + reply.nameLength = len; + WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply); + (void) WriteToClient(client, len, str); + return Success; } - else - { - client->errorValue = stuff->id; - return BadAtom; + else { + client->errorValue = stuff->id; + return BadAtom; } } @@ -1066,27 +1045,27 @@ int ProcGrabServer(ClientPtr client) { int rc; + REQUEST_SIZE_MATCH(xReq); - if (grabState != GrabNone && client != grabClient) - { - ResetCurrentRequest(client); - client->sequence--; - BITSET(grabWaiters, client->index); - IgnoreClient(client); - return Success; + if (grabState != GrabNone && client != grabClient) { + ResetCurrentRequest(client); + client->sequence--; + BITSET(grabWaiters, client->index); + IgnoreClient(client); + return Success; } rc = OnlyListenToOneClient(client); if (rc != Success) - return rc; + return rc; grabState = GrabKickout; grabClient = client; - if (ServerGrabCallback) - { - ServerGrabInfoRec grabinfo; - grabinfo.client = client; - grabinfo.grabstate = SERVER_GRABBED; - CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); + if (ServerGrabCallback) { + ServerGrabInfoRec grabinfo; + + grabinfo.client = client; + grabinfo.grabstate = SERVER_GRABBED; + CallCallbacks(&ServerGrabCallback, (pointer) &grabinfo); } return Success; @@ -1099,23 +1078,21 @@ UngrabServer(ClientPtr client) 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]); + 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); + if (ServerGrabCallback) { + ServerGrabInfoRec grabinfo; + + grabinfo.client = client; + grabinfo.grabstate = SERVER_UNGRABBED; + CallCallbacks(&ServerGrabCallback, (pointer) &grabinfo); } } @@ -1147,53 +1124,51 @@ ProcTranslateCoords(ClientPtr client) rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; - if (!SAME_SCREENS(pWin->drawable, pDst->drawable)) - { - rep.sameScreen = xFalse; + if (!SAME_SCREENS(pWin->drawable, pDst->drawable)) { + rep.sameScreen = xFalse; rep.child = None; - rep.dstX = rep.dstY = 0; + 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) - { - BoxRec box; - 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)) - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || - RegionContainsPoint(&pWin->borderSize, x, y, &box)) - - && (!wInputShape(pWin) || - RegionContainsPoint(wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box)) - ) - { - 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; + 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) { + BoxRec box; + + 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)) + /* When a window is shaped, a further check + * is made to see if the point is inside + * borderSize + */ + && (!wBoundingShape(pWin) || + RegionContainsPoint(&pWin->borderSize, x, y, &box)) + + && (!wInputShape(pWin) || + RegionContainsPoint(wInputShape(pWin), + x - pWin->drawable.x, + y - pWin->drawable.y, &box)) + ) { + 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 Success; @@ -1202,20 +1177,20 @@ ProcTranslateCoords(ClientPtr client) int ProcOpenFont(ClientPtr client) { - int err; + int err; + REQUEST(xOpenFontReq); REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes); client->errorValue = stuff->fid; LEGAL_NEW_RESOURCE(stuff->fid, client); err = OpenFont(client, stuff->fid, (Mask) 0, - stuff->nbytes, (char *)&stuff[1]); - if (err == Success) - { - return Success; + stuff->nbytes, (char *) &stuff[1]); + if (err == Success) { + return Success; } else - return err; + return err; } int @@ -1223,19 +1198,18 @@ ProcCloseFont(ClientPtr client) { FontPtr pFont; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - rc = dixLookupResourceByType((pointer *)&pFont, stuff->id, RT_FONT, - client, DixDestroyAccess); - if (rc == Success) - { + rc = dixLookupResourceByType((pointer *) &pFont, stuff->id, RT_FONT, + client, DixDestroyAccess); + if (rc == Success) { FreeResource(stuff->id, RT_NONE); - return Success; + return Success; } - else - { - client->errorValue = stuff->id; + else { + client->errorValue = stuff->id; return rc; } } @@ -1243,47 +1217,46 @@ ProcCloseFont(ClientPtr client) int ProcQueryFont(ClientPtr client) { - xQueryFontReply *reply; + xQueryFontReply *reply; FontPtr pFont; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupFontable(&pFont, stuff->id, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; { - 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) + - nprotoxcistructs * sizeof(xCharInfo); - reply = calloc(1, rlength); - if(!reply) - { - return BadAlloc; - } - - reply->type = X_Reply; - reply->length = bytes_to_int32(rlength - sizeof(xGenericReply)); - reply->sequenceNumber = client->sequence; - QueryFont( pFont, reply, nprotoxcistructs); + 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) + + nprotoxcistructs * sizeof(xCharInfo); + reply = calloc(1, rlength); + if (!reply) { + return BadAlloc; + } + + reply->type = X_Reply; + reply->length = bytes_to_int32(rlength - sizeof(xGenericReply)); + reply->sequenceNumber = client->sequence; + QueryFont(pFont, reply, nprotoxcistructs); WriteReplyToClient(client, rlength, reply); - free(reply); - return Success; + free(reply); + return Success; } } @@ -1295,23 +1268,23 @@ ProcQueryTextExtents(ClientPtr client) ExtentInfoRec info; unsigned long length; int rc; + REQUEST(xQueryTextExtentsReq); REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq); - + rc = dixLookupFontable(&pFont, stuff->fid, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; length = client->req_len - bytes_to_int32(sizeof(xQueryTextExtentsReq)); length = length << 1; - if (stuff->oddLength) - { - if (length == 0) - return BadLength; + if (stuff->oddLength) { + if (length == 0) + return BadLength; length--; } - if (!QueryTextExtents(pFont, length, (unsigned char *)&stuff[1], &info)) - return BadAlloc; + if (!QueryTextExtents(pFont, length, (unsigned char *) &stuff[1], &info)) + return BadAlloc; reply.type = X_Reply; reply.length = 0; reply.sequenceNumber = client->sequence; @@ -1334,8 +1307,8 @@ ProcListFonts(ClientPtr client) REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes); - return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes, - stuff->maxNames); + return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes, + stuff->maxNames); } int @@ -1346,7 +1319,7 @@ ProcListFontsWithInfo(ClientPtr client) REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes); return StartListFontsWithInfo(client, stuff->nbytes, - (unsigned char *) &stuff[1], stuff->maxNames); + (unsigned char *) &stuff[1], stuff->maxNames); } /** @@ -1356,8 +1329,9 @@ ProcListFontsWithInfo(ClientPtr client) int dixDestroyPixmap(pointer value, XID pid) { - PixmapPtr pPixmap = (PixmapPtr)value; - return (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap); + PixmapPtr pPixmap = (PixmapPtr) value; + + return (*pPixmap->drawable.pScreen->DestroyPixmap) (pPixmap); } int @@ -1365,6 +1339,7 @@ ProcCreatePixmap(ClientPtr client) { PixmapPtr pMap; DrawablePtr pDraw; + REQUEST(xCreatePixmapReq); DepthPtr pDepth; int i, rc; @@ -1372,60 +1347,55 @@ ProcCreatePixmap(ClientPtr client) REQUEST_SIZE_MATCH(xCreatePixmapReq); client->errorValue = stuff->pid; LEGAL_NEW_RESOURCE(stuff->pid, client); - + rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY, - DixGetAttrAccess); + DixGetAttrAccess); if (rc != Success) - return rc; + return rc; - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; + if (!stuff->width || !stuff->height) { + client->errorValue = 0; return BadValue; } - if (stuff->width > 32767 || stuff->height > 32767) - { - /* It is allowed to try and allocate a pixmap which is larger than - * 32767 in either dimension. However, all of the framebuffer code - * is buggy and does not reliably draw to such big pixmaps, basically - * because the Region data structure operates with signed shorts - * for the rectangles in it. - * - * Furthermore, several places in the X server computes the - * size in bytes of the pixmap and tries to store it in an - * integer. This integer can overflow and cause the allocated size - * to be much smaller. - * - * So, such big pixmaps are rejected here with a BadAlloc - */ - return BadAlloc; - } - if (stuff->depth != 1) - { + if (stuff->width > 32767 || stuff->height > 32767) { + /* It is allowed to try and allocate a pixmap which is larger than + * 32767 in either dimension. However, all of the framebuffer code + * is buggy and does not reliably draw to such big pixmaps, basically + * because the Region data structure operates with signed shorts + * for the rectangles in it. + * + * Furthermore, several places in the X server computes the + * size in bytes of the pixmap and tries to store it in an + * integer. This integer can overflow and cause the allocated size + * to be much smaller. + * + * So, such big pixmaps are rejected here with a BadAlloc + */ + return BadAlloc; + } + if (stuff->depth != 1) { pDepth = pDraw->pScreen->allowedDepths; - for (i=0; i<pDraw->pScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; + for (i = 0; i < pDraw->pScreen->numDepths; i++, pDepth++) + if (pDepth->depth == stuff->depth) + goto CreatePmap; + client->errorValue = stuff->depth; return BadValue; } -CreatePmap: - pMap = (PixmapPtr)(*pDraw->pScreen->CreatePixmap) - (pDraw->pScreen, stuff->width, - stuff->height, stuff->depth, 0); - if (pMap) - { - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - /* security creation/labeling check */ - rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP, - pMap, RT_NONE, NULL, DixCreateAccess); - if (rc != Success) { - (*pDraw->pScreen->DestroyPixmap)(pMap); - return rc; - } - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - return Success; + CreatePmap: + pMap = (PixmapPtr) (*pDraw->pScreen->CreatePixmap) + (pDraw->pScreen, stuff->width, stuff->height, stuff->depth, 0); + if (pMap) { + pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; + pMap->drawable.id = stuff->pid; + /* security creation/labeling check */ + rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP, + pMap, RT_NONE, NULL, DixCreateAccess); + if (rc != Success) { + (*pDraw->pScreen->DestroyPixmap) (pMap); + return rc; + } + if (AddResource(stuff->pid, RT_PIXMAP, (pointer) pMap)) + return Success; } return BadAlloc; } @@ -1435,20 +1405,19 @@ ProcFreePixmap(ClientPtr client) { PixmapPtr pMap; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - rc = dixLookupResourceByType((pointer *)&pMap, stuff->id, RT_PIXMAP, client, - DixDestroyAccess); - if (rc == Success) - { - FreeResource(stuff->id, RT_NONE); - return Success; + rc = dixLookupResourceByType((pointer *) &pMap, stuff->id, RT_PIXMAP, + client, DixDestroyAccess); + if (rc == Success) { + FreeResource(stuff->id, RT_NONE); + return Success; } - else - { - client->errorValue = stuff->id; - return rc; + else { + client->errorValue = stuff->id; + return rc; } } @@ -1459,25 +1428,26 @@ ProcCreateGC(ClientPtr client) GC *pGC; DrawablePtr pDraw; unsigned len; + REQUEST(xCreateGCReq); REQUEST_AT_LEAST_SIZE(xCreateGCReq); client->errorValue = stuff->gc; LEGAL_NEW_RESOURCE(stuff->gc, client); rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, - DixGetAttrAccess); + DixGetAttrAccess); if (rc != Success) - return rc; + return rc; - len = client->req_len - bytes_to_int32(sizeof(xCreateGCReq)); + len = client->req_len - bytes_to_int32(sizeof(xCreateGCReq)); if (len != Ones(stuff->mask)) return BadLength; - pGC = (GC *)CreateGC(pDraw, stuff->mask, (XID *) &stuff[1], &error, - stuff->gc, client); + pGC = (GC *) CreateGC(pDraw, stuff->mask, (XID *) &stuff[1], &error, + stuff->gc, client); if (error != Success) return error; - if (!AddResource(stuff->gc, RT_GC, (pointer)pGC)) - return BadAlloc; + if (!AddResource(stuff->gc, RT_GC, (pointer) pGC)) + return BadAlloc; return Success; } @@ -1487,14 +1457,15 @@ ProcChangeGC(ClientPtr client) GC *pGC; int result; unsigned len; + REQUEST(xChangeGCReq); REQUEST_AT_LEAST_SIZE(xChangeGCReq); result = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess); if (result != Success) - return result; + return result; - len = client->req_len - bytes_to_int32(sizeof(xChangeGCReq)); + len = client->req_len - bytes_to_int32(sizeof(xChangeGCReq)); if (len != Ones(stuff->mask)) return BadLength; @@ -1507,21 +1478,21 @@ ProcCopyGC(ClientPtr client) GC *dstGC; GC *pGC; int result; + REQUEST(xCopyGCReq); REQUEST_SIZE_MATCH(xCopyGCReq); result = dixLookupGC(&pGC, stuff->srcGC, client, DixGetAttrAccess); if (result != Success) - return result; + return result; result = dixLookupGC(&dstGC, stuff->dstGC, client, DixSetAttrAccess); if (result != Success) - return result; + return result; if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth)) return BadMatch; - if (stuff->mask & ~GCAllBits) - { - client->errorValue = stuff->mask; - return BadValue; + if (stuff->mask & ~GCAllBits) { + client->errorValue = stuff->mask; + return BadValue; } return CopyGC(pGC, dstGC, stuff->mask); } @@ -1531,50 +1502,50 @@ ProcSetDashes(ClientPtr client) { GC *pGC; int result; + REQUEST(xSetDashesReq); REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes); - if (stuff->nDashes == 0) - { - client->errorValue = 0; - return BadValue; + if (stuff->nDashes == 0) { + client->errorValue = 0; + return BadValue; } - result = dixLookupGC(&pGC,stuff->gc, client, DixSetAttrAccess); + result = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess); if (result != Success) - return result; + return result; /* If there's an error, either there's no sensible errorValue, * or there was a dash segment of 0. */ client->errorValue = 0; return SetDashes(pGC, stuff->dashOffset, stuff->nDashes, - (unsigned char *)&stuff[1]); + (unsigned char *) &stuff[1]); } int ProcSetClipRectangles(ClientPtr client) { - int nr, result; + int nr, result; GC *pGC; + REQUEST(xSetClipRectanglesReq); REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq); if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) && - (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) - { - client->errorValue = stuff->ordering; + (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) { + client->errorValue = stuff->ordering; return BadValue; } - result = dixLookupGC(&pGC,stuff->gc, client, DixSetAttrAccess); + result = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess); if (result != Success) - return result; - + return result; + nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq); if (nr & 4) - return BadLength; + return BadLength; nr >>= 3; return SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin, - nr, (xRectangle *)&stuff[1], (int)stuff->ordering); + nr, (xRectangle *) &stuff[1], (int) stuff->ordering); } int @@ -1582,12 +1553,13 @@ ProcFreeGC(ClientPtr client) { GC *pGC; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupGC(&pGC, stuff->id, client, DixDestroyAccess); if (rc != Success) - return rc; + return rc; FreeResource(stuff->id, RT_NONE); return Success; @@ -1604,19 +1576,17 @@ ProcClearToBackground(ClientPtr client) rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess); if (rc != Success) return rc; - if (pWin->drawable.class == InputOnly) - { - client->errorValue = stuff->window; - return BadMatch; - } - if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse)) - { - client->errorValue = stuff->exposures; + if (pWin->drawable.class == InputOnly) { + client->errorValue = stuff->window; + return BadMatch; + } + if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse)) { + client->errorValue = stuff->exposures; return BadValue; } - (*pWin->drawable.pScreen->ClearToBackground)(pWin, stuff->x, stuff->y, - stuff->width, stuff->height, - (Bool)stuff->exposures); + (*pWin->drawable.pScreen->ClearToBackground) (pWin, stuff->x, stuff->y, + stuff->width, stuff->height, + (Bool) stuff->exposures); return Success; } @@ -1626,37 +1596,35 @@ ProcCopyArea(ClientPtr client) DrawablePtr pDst; DrawablePtr pSrc; GC *pGC; + REQUEST(xCopyAreaReq); RegionPtr pRgn; int rc; REQUEST_SIZE_MATCH(xCopyAreaReq); - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, DixWriteAccess); - if (stuff->dstDrawable != stuff->srcDrawable) - { - rc = dixLookupDrawable(&pSrc, stuff->srcDrawable, client, 0, - DixReadAccess); - if (rc != Success) - return rc; - if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth)) - { - client->errorValue = stuff->dstDrawable; - return BadMatch; - } + VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, DixWriteAccess); + if (stuff->dstDrawable != stuff->srcDrawable) { + rc = dixLookupDrawable(&pSrc, stuff->srcDrawable, client, 0, + DixReadAccess); + if (rc != Success) + return rc; + if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth)) { + client->errorValue = stuff->dstDrawable; + return BadMatch; + } } else pSrc = pDst; - pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY); - if (pGC->graphicsExposures) - { - (*pDst->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyArea, 0); - if (pRgn) - RegionDestroy(pRgn); + pRgn = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, stuff->srcX, stuff->srcY, + stuff->width, stuff->height, + stuff->dstX, stuff->dstY); + if (pGC->graphicsExposures) { + (*pDst->pScreen->SendGraphicsExpose) + (client, pRgn, stuff->dstDrawable, X_CopyArea, 0); + if (pRgn) + RegionDestroy(pRgn); } return Success; @@ -1667,6 +1635,7 @@ ProcCopyPlane(ClientPtr client) { DrawablePtr psrcDraw, pdstDraw; GC *pGC; + REQUEST(xCopyPlaneReq); RegionPtr pRgn; int rc; @@ -1674,39 +1643,36 @@ ProcCopyPlane(ClientPtr client) REQUEST_SIZE_MATCH(xCopyPlaneReq); VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, DixWriteAccess); - if (stuff->dstDrawable != stuff->srcDrawable) - { - rc = dixLookupDrawable(&psrcDraw, stuff->srcDrawable, client, 0, - DixReadAccess); - if (rc != Success) - return rc; - - if (pdstDraw->pScreen != psrcDraw->pScreen) - { - client->errorValue = stuff->dstDrawable; - return BadMatch; - } + if (stuff->dstDrawable != stuff->srcDrawable) { + rc = dixLookupDrawable(&psrcDraw, stuff->srcDrawable, client, 0, + DixReadAccess); + if (rc != Success) + return rc; + + if (pdstDraw->pScreen != psrcDraw->pScreen) { + client->errorValue = stuff->dstDrawable; + return BadMatch; + } } else psrcDraw = pdstDraw; /* Check to see if stuff->bitPlane has exactly ONE good bit set */ - if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) || - (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) - { - client->errorValue = stuff->bitPlane; - return BadValue; + if (stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) || + (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) { + client->errorValue = stuff->bitPlane; + return BadValue; } - pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY, stuff->bitPlane); - if (pGC->graphicsExposures) - { - (*pdstDraw->pScreen->SendGraphicsExpose) - (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0); - if (pRgn) - RegionDestroy(pRgn); + pRgn = + (*pGC->ops->CopyPlane) (psrcDraw, pdstDraw, pGC, stuff->srcX, + stuff->srcY, stuff->width, stuff->height, + stuff->dstX, stuff->dstY, stuff->bitPlane); + if (pGC->graphicsExposures) { + (*pdstDraw->pScreen->SendGraphicsExpose) + (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0); + if (pRgn) + RegionDestroy(pRgn); } return Success; } @@ -1717,20 +1683,20 @@ ProcPolyPoint(ClientPtr client) int npoint; GC *pGC; DrawablePtr pDraw; + REQUEST(xPolyPointReq); REQUEST_AT_LEAST_SIZE(xPolyPointReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; + if ((stuff->coordMode != CoordModeOrigin) && + (stuff->coordMode != CoordModePrevious)) { + client->errorValue = stuff->coordMode; return BadValue; } - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); + VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq)); if (npoint) - (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint, - (xPoint *) &stuff[1]); + (*pGC->ops->PolyPoint) (pDraw, pGC, stuff->coordMode, npoint, + (xPoint *) &stuff[1]); return Success; } @@ -1740,20 +1706,20 @@ ProcPolyLine(ClientPtr client) int npoint; GC *pGC; DrawablePtr pDraw; + REQUEST(xPolyLineReq); REQUEST_AT_LEAST_SIZE(xPolyLineReq); - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; + if ((stuff->coordMode != CoordModeOrigin) && + (stuff->coordMode != CoordModePrevious)) { + client->errorValue = stuff->coordMode; return BadValue; } VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq)); if (npoint > 1) - (*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint, - (DDXPointPtr) &stuff[1]); + (*pGC->ops->Polylines) (pDraw, pGC, stuff->coordMode, npoint, + (DDXPointPtr) &stuff[1]); return Success; } @@ -1763,77 +1729,79 @@ ProcPolySegment(ClientPtr client) int nsegs; GC *pGC; DrawablePtr pDraw; + REQUEST(xPolySegmentReq); REQUEST_AT_LEAST_SIZE(xPolySegmentReq); VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq); if (nsegs & 4) - return BadLength; + return BadLength; nsegs >>= 3; if (nsegs) - (*pGC->ops->PolySegment)(pDraw, pGC, nsegs, (xSegment *) &stuff[1]); + (*pGC->ops->PolySegment) (pDraw, pGC, nsegs, (xSegment *) &stuff[1]); return Success; } int -ProcPolyRectangle (ClientPtr client) +ProcPolyRectangle(ClientPtr client) { int nrects; GC *pGC; DrawablePtr pDraw; + REQUEST(xPolyRectangleReq); REQUEST_AT_LEAST_SIZE(xPolyRectangleReq); VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq); if (nrects & 4) - return BadLength; + return BadLength; nrects >>= 3; if (nrects) - (*pGC->ops->PolyRectangle)(pDraw, pGC, - nrects, (xRectangle *) &stuff[1]); + (*pGC->ops->PolyRectangle) (pDraw, pGC, + nrects, (xRectangle *) &stuff[1]); return Success; } int ProcPolyArc(ClientPtr client) { - int narcs; + int narcs; GC *pGC; DrawablePtr pDraw; + REQUEST(xPolyArcReq); REQUEST_AT_LEAST_SIZE(xPolyArcReq); VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); narcs = (client->req_len << 2) - sizeof(xPolyArcReq); if (narcs % sizeof(xArc)) - return BadLength; + return BadLength; narcs /= sizeof(xArc); if (narcs) - (*pGC->ops->PolyArc)(pDraw, pGC, narcs, (xArc *) &stuff[1]); + (*pGC->ops->PolyArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]); return Success; } int ProcFillPoly(ClientPtr client) { - int things; + int things; GC *pGC; DrawablePtr pDraw; + REQUEST(xFillPolyReq); REQUEST_AT_LEAST_SIZE(xFillPolyReq); - if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) && - (stuff->shape != Convex)) - { - client->errorValue = stuff->shape; + if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) && + (stuff->shape != Convex)) { + client->errorValue = stuff->shape; return BadValue; } - if ((stuff->coordMode != CoordModeOrigin) && - (stuff->coordMode != CoordModePrevious)) - { - client->errorValue = stuff->coordMode; + if ((stuff->coordMode != CoordModeOrigin) && + (stuff->coordMode != CoordModePrevious)) { + client->errorValue = stuff->coordMode; return BadValue; } @@ -1841,45 +1809,47 @@ ProcFillPoly(ClientPtr client) things = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq)); if (things) (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape, - stuff->coordMode, things, - (DDXPointPtr) &stuff[1]); + stuff->coordMode, things, + (DDXPointPtr) &stuff[1]); return Success; } int ProcPolyFillRectangle(ClientPtr client) { - int things; + int things; GC *pGC; DrawablePtr pDraw; + REQUEST(xPolyFillRectangleReq); REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq); VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq); if (things & 4) - return BadLength; + return BadLength; things >>= 3; if (things) (*pGC->ops->PolyFillRect) (pDraw, pGC, things, - (xRectangle *) &stuff[1]); + (xRectangle *) &stuff[1]); return Success; } int ProcPolyFillArc(ClientPtr client) { - int narcs; + int narcs; GC *pGC; DrawablePtr pDraw; + REQUEST(xPolyFillArcReq); REQUEST_AT_LEAST_SIZE(xPolyFillArcReq); VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq); if (narcs % sizeof(xArc)) - return BadLength; + return BadLength; narcs /= sizeof(xArc); if (narcs) (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]); @@ -1889,40 +1859,40 @@ ProcPolyFillArc(ClientPtr client) #ifdef MATCH_CLIENT_ENDIAN int -ServerOrder (void) +ServerOrder(void) { - int whichbyte = 1; + int whichbyte = 1; if (*((char *) &whichbyte)) - return LSBFirst; + return LSBFirst; return MSBFirst; } #define ClientOrder(client) ((client)->swapped ? !ServerOrder() : ServerOrder()) void -ReformatImage (char *base, int nbytes, int bpp, int order) +ReformatImage(char *base, int nbytes, int bpp, int order) { switch (bpp) { - case 1: /* yuck */ - if (BITMAP_BIT_ORDER != order) - BitOrderInvert ((unsigned char *) base, nbytes); + case 1: /* yuck */ + if (BITMAP_BIT_ORDER != order) + BitOrderInvert((unsigned char *) base, nbytes); #if IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER && BITMAP_SCANLINE_UNIT != 8 - ReformatImage (base, nbytes, BITMAP_SCANLINE_UNIT, order); + ReformatImage(base, nbytes, BITMAP_SCANLINE_UNIT, order); #endif - break; + break; case 4: - break; /* yuck */ + break; /* yuck */ case 8: - break; + break; case 16: - if (IMAGE_BYTE_ORDER != order) - TwoByteSwap ((unsigned char *) base, nbytes); - break; + if (IMAGE_BYTE_ORDER != order) + TwoByteSwap((unsigned char *) base, nbytes); + break; case 32: - if (IMAGE_BYTE_ORDER != order) - FourByteSwap ((unsigned char *) base, nbytes); - break; + if (IMAGE_BYTE_ORDER != order) + FourByteSwap((unsigned char *) base, nbytes); + break; } } #else @@ -1945,128 +1915,122 @@ ProcPutImage(ClientPtr client) { GC *pGC; DrawablePtr pDraw; - long length; /* length of scanline server padded */ - long lengthProto; /* length of scanline protocol padded */ - char *tmpImage; + long length; /* length of scanline server padded */ + long lengthProto; /* length of scanline protocol padded */ + char *tmpImage; + REQUEST(xPutImageReq); REQUEST_AT_LEAST_SIZE(xPutImageReq); VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); - if (stuff->format == XYBitmap) - { + if (stuff->format == XYBitmap) { if ((stuff->depth != 1) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) + (stuff->leftPad >= (unsigned int) screenInfo.bitmapScanlinePad)) return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); + length = BitmapBytePad(stuff->width + stuff->leftPad); } - else if (stuff->format == XYPixmap) - { - if ((pDraw->depth != stuff->depth) || - (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad)) + else if (stuff->format == XYPixmap) { + if ((pDraw->depth != stuff->depth) || + (stuff->leftPad >= (unsigned int) screenInfo.bitmapScanlinePad)) return BadMatch; - length = BitmapBytePad(stuff->width + stuff->leftPad); - length *= stuff->depth; + length = BitmapBytePad(stuff->width + stuff->leftPad); + length *= stuff->depth; } - else if (stuff->format == ZPixmap) - { + else if (stuff->format == ZPixmap) { if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0)) return BadMatch; - length = PixmapBytePad(stuff->width, stuff->depth); + length = PixmapBytePad(stuff->width, stuff->depth); } - else - { - client->errorValue = stuff->format; + else { + client->errorValue = stuff->format; return BadValue; } - tmpImage = (char *)&stuff[1]; + tmpImage = (char *) &stuff[1]; lengthProto = length; - + if ((bytes_to_int32(lengthProto * stuff->height) + - bytes_to_int32(sizeof(xPutImageReq))) != client->req_len) - return BadLength; + bytes_to_int32(sizeof(xPutImageReq))) != client->req_len) + return BadLength; + + ReformatImage(tmpImage, lengthProto * stuff->height, + stuff->format == ZPixmap ? BitsPerPixel(stuff->depth) : 1, + ClientOrder(client)); - ReformatImage (tmpImage, lengthProto * stuff->height, - stuff->format == ZPixmap ? BitsPerPixel (stuff->depth) : 1, - ClientOrder(client)); - (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY, - stuff->width, stuff->height, - stuff->leftPad, stuff->format, tmpImage); + stuff->width, stuff->height, + stuff->leftPad, stuff->format, tmpImage); - return Success; + return Success; } static int -DoGetImage(ClientPtr client, int format, Drawable drawable, - int x, int y, int width, int height, - Mask planemask, xGetImageReply **im_return) +DoGetImage(ClientPtr client, int format, Drawable drawable, + int x, int y, int width, int height, + Mask planemask, xGetImageReply ** im_return) { - DrawablePtr pDraw, pBoundingDraw; - int nlines, linesPerBuf, rc; - int linesDone; + DrawablePtr pDraw, pBoundingDraw; + int nlines, linesPerBuf, rc; + int linesDone; + /* coordinates relative to the bounding drawable */ - int relx, rely; - long widthBytesLine, length; - Mask plane = 0; - char *pBuf; - xGetImageReply xgi; + int relx, rely; + long widthBytesLine, length; + Mask plane = 0; + char *pBuf; + xGetImageReply xgi; RegionPtr pVisibleRegion = NULL; - if ((format != XYPixmap) && (format != ZPixmap)) - { - client->errorValue = format; + if ((format != XYPixmap) && (format != ZPixmap)) { + client->errorValue = format; return BadValue; } rc = dixLookupDrawable(&pDraw, drawable, client, 0, DixReadAccess); if (rc != Success) - return rc; + return rc; memset(&xgi, 0, sizeof(xGetImageReply)); relx = x; rely = y; - if(pDraw->type == DRAWABLE_WINDOW) - { - WindowPtr pWin = (WindowPtr)pDraw; + if (pDraw->type == DRAWABLE_WINDOW) { + WindowPtr pWin = (WindowPtr) pDraw; - /* "If the drawable is a window, the window must be viewable ... or a - * BadMatch error results" */ - if (!pWin->viewable) - return BadMatch; + /* "If the drawable is a window, the window must be viewable ... or a + * BadMatch error results" */ + if (!pWin->viewable) + return BadMatch; - /* If the drawable is a window, the rectangle must be contained within - * its bounds (including the border). */ - if (x < -wBorderWidth(pWin) || - x + width > wBorderWidth(pWin) + (int)pDraw->width || - y < -wBorderWidth(pWin) || - y + height > wBorderWidth(pWin) + (int)pDraw->height) - return BadMatch; + /* If the drawable is a window, the rectangle must be contained within + * its bounds (including the border). */ + if (x < -wBorderWidth(pWin) || + x + width > wBorderWidth(pWin) + (int) pDraw->width || + y < -wBorderWidth(pWin) || + y + height > wBorderWidth(pWin) + (int) pDraw->height) + return BadMatch; - relx += pDraw->x; - rely += pDraw->y; + relx += pDraw->x; + rely += pDraw->y; - if (pDraw->pScreen->GetWindowPixmap) { - PixmapPtr pPix = (*pDraw->pScreen->GetWindowPixmap) (pWin); + if (pDraw->pScreen->GetWindowPixmap) { + PixmapPtr pPix = (*pDraw->pScreen->GetWindowPixmap) (pWin); - pBoundingDraw = &pPix->drawable; + pBoundingDraw = &pPix->drawable; #ifdef COMPOSITE - relx -= pPix->screen_x; - rely -= pPix->screen_y; + relx -= pPix->screen_x; + rely -= pPix->screen_y; #endif - } - else - { - pBoundingDraw = (DrawablePtr)pDraw->pScreen->root; - } + } + else { + pBoundingDraw = (DrawablePtr) pDraw->pScreen->root; + } - xgi.visual = wVisual (pWin); + xgi.visual = wVisual(pWin); } - else - { - pBoundingDraw = pDraw; - xgi.visual = None; + else { + pBoundingDraw = pDraw; + xgi.visual = None; } /* "If the drawable is a pixmap, the given rectangle must be wholly @@ -2080,171 +2044,151 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, * within the bounds of the window's backing pixmap. In particular, this * means that a GetImage request may succeed or fail with BadMatch depending * on whether any of its ancestor windows are redirected. */ - if(relx < 0 || relx + width > (int)pBoundingDraw->width || - rely < 0 || rely + height > (int)pBoundingDraw->height) - return BadMatch; + if (relx < 0 || relx + width > (int) pBoundingDraw->width || + rely < 0 || rely + height > (int) pBoundingDraw->height) + return BadMatch; xgi.type = X_Reply; xgi.sequenceNumber = client->sequence; xgi.depth = pDraw->depth; - if(format == ZPixmap) - { - widthBytesLine = PixmapBytePad(width, pDraw->depth); - length = widthBytesLine * height; + if (format == ZPixmap) { + widthBytesLine = PixmapBytePad(width, pDraw->depth); + length = widthBytesLine * height; } - else - { - widthBytesLine = BitmapBytePad(width); - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = widthBytesLine * height * - Ones(planemask & (plane | (plane - 1))); + else { + widthBytesLine = BitmapBytePad(width); + plane = ((Mask) 1) << (pDraw->depth - 1); + /* only planes asked for */ + length = widthBytesLine * height * + Ones(planemask & (plane | (plane - 1))); } xgi.length = length; if (im_return) { - pBuf = calloc(1, sz_xGetImageReply + length); - if (!pBuf) - return BadAlloc; - if (widthBytesLine == 0) - linesPerBuf = 0; - else - linesPerBuf = height; - *im_return = (xGetImageReply *)pBuf; - *(xGetImageReply *)pBuf = xgi; - pBuf += sz_xGetImageReply; - } else { - xgi.length = bytes_to_int32(xgi.length); - if (widthBytesLine == 0 || height == 0) - linesPerBuf = 0; - else if (widthBytesLine >= IMAGE_BUFSIZE) - linesPerBuf = 1; - else - { - linesPerBuf = IMAGE_BUFSIZE / widthBytesLine; - if (linesPerBuf > height) - linesPerBuf = height; - } - length = linesPerBuf * widthBytesLine; - if (linesPerBuf < height) - { - /* we have to make sure intermediate buffers don't need padding */ - while ((linesPerBuf > 1) && - (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1))) - { - linesPerBuf--; - length -= widthBytesLine; - } - while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1)) - { - linesPerBuf++; - length += widthBytesLine; - } - } - if(!(pBuf = calloc(1, length))) - return BadAlloc; - WriteReplyToClient(client, sizeof (xGetImageReply), &xgi); - } - - if (pDraw->type == DRAWABLE_WINDOW) - { - pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw); - if (pVisibleRegion) - { - RegionTranslate(pVisibleRegion, -pDraw->x, -pDraw->y); - } + pBuf = calloc(1, sz_xGetImageReply + length); + if (!pBuf) + return BadAlloc; + if (widthBytesLine == 0) + linesPerBuf = 0; + else + linesPerBuf = height; + *im_return = (xGetImageReply *) pBuf; + *(xGetImageReply *) pBuf = xgi; + pBuf += sz_xGetImageReply; + } + else { + xgi.length = bytes_to_int32(xgi.length); + if (widthBytesLine == 0 || height == 0) + linesPerBuf = 0; + else if (widthBytesLine >= IMAGE_BUFSIZE) + linesPerBuf = 1; + else { + linesPerBuf = IMAGE_BUFSIZE / widthBytesLine; + if (linesPerBuf > height) + linesPerBuf = height; + } + length = linesPerBuf * widthBytesLine; + if (linesPerBuf < height) { + /* we have to make sure intermediate buffers don't need padding */ + while ((linesPerBuf > 1) && + (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD) - 1))) { + linesPerBuf--; + length -= widthBytesLine; + } + while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD) - 1)) { + linesPerBuf++; + length += widthBytesLine; + } + } + if (!(pBuf = calloc(1, length))) + return BadAlloc; + WriteReplyToClient(client, sizeof(xGetImageReply), &xgi); } - if (linesPerBuf == 0) - { - /* nothing to do */ + if (pDraw->type == DRAWABLE_WINDOW) { + pVisibleRegion = NotClippedByChildren((WindowPtr) pDraw); + if (pVisibleRegion) { + RegionTranslate(pVisibleRegion, -pDraw->x, -pDraw->y); + } } - else if (format == ZPixmap) - { + + if (linesPerBuf == 0) { + /* nothing to do */ + } + else if (format == ZPixmap) { linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - planemask, - (pointer) pBuf); - if (pVisibleRegion) - XaceCensorImage(client, pVisibleRegion, widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); - - /* Note that this is NOT a call to WriteSwappedDataToClient, + while (height - linesDone > 0) { + nlines = min(linesPerBuf, height - linesDone); + (*pDraw->pScreen->GetImage) (pDraw, + x, + y + linesDone, + width, + nlines, + format, planemask, (pointer) pBuf); + if (pVisibleRegion) + XaceCensorImage(client, pVisibleRegion, widthBytesLine, + pDraw, x, y + linesDone, width, + nlines, format, pBuf); + + /* Note that this is NOT a call to WriteSwappedDataToClient, as we do NOT byte swap */ - if (!im_return) - { - ReformatImage (pBuf, (int)(nlines * widthBytesLine), - BitsPerPixel (pDraw->depth), - ClientOrder(client)); + if (!im_return) { + ReformatImage(pBuf, (int) (nlines * widthBytesLine), + BitsPerPixel(pDraw->depth), ClientOrder(client)); /* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; + (void) WriteToClient(client, + (int) (nlines * widthBytesLine), pBuf); + } + linesDone += nlines; } } - else /* XYPixmap */ - { - for (; plane; plane >>= 1) - { - if (planemask & plane) - { - linesDone = 0; - while (height - linesDone > 0) - { - nlines = min(linesPerBuf, height - linesDone); - (*pDraw->pScreen->GetImage) (pDraw, - x, - y + linesDone, - width, - nlines, - format, - plane, - (pointer)pBuf); - if (pVisibleRegion) - XaceCensorImage(client, pVisibleRegion, - widthBytesLine, - pDraw, x, y + linesDone, width, - nlines, format, pBuf); - - /* Note: NOT a call to WriteSwappedDataToClient, - as we do NOT byte swap */ - if (im_return) { - pBuf += nlines * widthBytesLine; - } else { - ReformatImage (pBuf, - (int)(nlines * widthBytesLine), - 1, - ClientOrder (client)); + else { /* XYPixmap */ + + for (; plane; plane >>= 1) { + if (planemask & plane) { + linesDone = 0; + while (height - linesDone > 0) { + nlines = min(linesPerBuf, height - linesDone); + (*pDraw->pScreen->GetImage) (pDraw, + x, + y + linesDone, + width, + nlines, + format, plane, (pointer) pBuf); + if (pVisibleRegion) + XaceCensorImage(client, pVisibleRegion, + widthBytesLine, + pDraw, x, y + linesDone, width, + nlines, format, pBuf); + + /* Note: NOT a call to WriteSwappedDataToClient, + as we do NOT byte swap */ + if (im_return) { + pBuf += nlines * widthBytesLine; + } + else { + ReformatImage(pBuf, + (int) (nlines * widthBytesLine), + 1, ClientOrder(client)); /* Don't split me, gcc pukes when you do */ - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - } - linesDone += nlines; - } + (void) WriteToClient(client, + (int) (nlines * widthBytesLine), + pBuf); + } + linesDone += nlines; + } } - } + } } if (pVisibleRegion) - RegionDestroy(pVisibleRegion); + RegionDestroy(pVisibleRegion); if (!im_return) - free(pBuf); + free(pBuf); return Success; } @@ -2256,15 +2200,16 @@ ProcGetImage(ClientPtr client) REQUEST_SIZE_MATCH(xGetImageReq); return DoGetImage(client, stuff->format, stuff->drawable, - stuff->x, stuff->y, - (int)stuff->width, (int)stuff->height, - stuff->planeMask, (xGetImageReply **)NULL); + stuff->x, stuff->y, + (int) stuff->width, (int) stuff->height, + stuff->planeMask, (xGetImageReply **) NULL); } int ProcPolyText(ClientPtr client) { - int err; + int err; + REQUEST(xPolyTextReq); DrawablePtr pDraw; GC *pGC; @@ -2273,27 +2218,23 @@ ProcPolyText(ClientPtr client) VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); err = PolyText(client, - pDraw, - pGC, - (unsigned char *)&stuff[1], - ((unsigned char *) stuff) + (client->req_len << 2), - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return Success; + pDraw, + pGC, + (unsigned char *) &stuff[1], + ((unsigned char *) stuff) + (client->req_len << 2), + stuff->x, stuff->y, stuff->reqType, stuff->drawable); + + if (err == Success) { + return Success; } else - return err; + return err; } int ProcImageText8(ClientPtr client) { - int err; + int err; DrawablePtr pDraw; GC *pGC; @@ -2303,27 +2244,23 @@ ProcImageText8(ClientPtr client) VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return Success; + pDraw, + pGC, + stuff->nChars, + (unsigned char *) &stuff[1], + stuff->x, stuff->y, stuff->reqType, stuff->drawable); + + if (err == Success) { + return Success; } else - return err; + return err; } int ProcImageText16(ClientPtr client) { - int err; + int err; DrawablePtr pDraw; GC *pGC; @@ -2333,40 +2270,35 @@ ProcImageText16(ClientPtr client) VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); err = ImageText(client, - pDraw, - pGC, - stuff->nChars, - (unsigned char *)&stuff[1], - stuff->x, - stuff->y, - stuff->reqType, - stuff->drawable); - - if (err == Success) - { - return Success; + pDraw, + pGC, + stuff->nChars, + (unsigned char *) &stuff[1], + stuff->x, stuff->y, stuff->reqType, stuff->drawable); + + if (err == Success) { + return Success; } else - return err; + return err; } - int ProcCreateColormap(ClientPtr client) { - VisualPtr pVisual; - ColormapPtr pmap; - Colormap mid; - WindowPtr pWin; + VisualPtr pVisual; + ColormapPtr pmap; + Colormap mid; + WindowPtr pWin; ScreenPtr pScreen; + REQUEST(xCreateColormapReq); int i, result; REQUEST_SIZE_MATCH(xCreateColormapReq); - if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll)) - { - client->errorValue = stuff->alloc; + if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll)) { + client->errorValue = stuff->alloc; return BadValue; } mid = stuff->mid; @@ -2377,13 +2309,11 @@ ProcCreateColormap(ClientPtr client) pScreen = pWin->drawable.pScreen; for (i = 0, pVisual = pScreen->visuals; - i < pScreen->numVisuals; - i++, pVisual++) - { - if (pVisual->vid != stuff->visual) - continue; - return CreateColormap(mid, pScreen, pVisual, &pmap, - (int)stuff->alloc, client->index); + i < pScreen->numVisuals; i++, pVisual++) { + if (pVisual->vid != stuff->visual) + continue; + return CreateColormap(mid, pScreen, pVisual, &pmap, + (int) stuff->alloc, client->index); } client->errorValue = stuff->visual; return BadMatch; @@ -2394,41 +2324,41 @@ ProcFreeColormap(ClientPtr client) { ColormapPtr pmap; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - rc = dixLookupResourceByType((pointer *)&pmap, stuff->id, RT_COLORMAP, client, - DixDestroyAccess); - if (rc == Success) - { - /* Freeing a default colormap is a no-op */ - if (!(pmap->flags & IsDefault)) - FreeResource(stuff->id, RT_NONE); - return Success; + rc = dixLookupResourceByType((pointer *) &pmap, stuff->id, RT_COLORMAP, + client, DixDestroyAccess); + if (rc == Success) { + /* Freeing a default colormap is a no-op */ + if (!(pmap->flags & IsDefault)) + FreeResource(stuff->id, RT_NONE); + return Success; } - else - { - client->errorValue = stuff->id; - return rc; + else { + client->errorValue = stuff->id; + return rc; } } - int ProcCopyColormapAndFree(ClientPtr client) { - Colormap mid; - ColormapPtr pSrcMap; + Colormap mid; + ColormapPtr pSrcMap; + REQUEST(xCopyColormapAndFreeReq); int rc; REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq); mid = stuff->mid; LEGAL_NEW_RESOURCE(mid, client); - rc = dixLookupResourceByType((pointer *)&pSrcMap, stuff->srcCmap, RT_COLORMAP, - client, DixReadAccess|DixRemoveAccess); + rc = dixLookupResourceByType((pointer *) &pSrcMap, stuff->srcCmap, + RT_COLORMAP, client, + DixReadAccess | DixRemoveAccess); if (rc == Success) - return CopyColormapAndFree(mid, pSrcMap, client->index); + return CopyColormapAndFree(mid, pSrcMap, client->index); client->errorValue = stuff->srcCmap; return rc; } @@ -2438,25 +2368,26 @@ ProcInstallColormap(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->id, RT_COLORMAP, client, - DixInstallAccess); + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->id, RT_COLORMAP, + client, DixInstallAccess); if (rc != Success) - goto out; + goto out; rc = XaceHook(XACE_SCREEN_ACCESS, client, pcmp->pScreen, DixSetAttrAccess); if (rc != Success) { - if (rc == BadValue) - rc = BadColor; - goto out; + if (rc == BadValue) + rc = BadColor; + goto out; } (*(pcmp->pScreen->InstallColormap)) (pcmp); return Success; -out: + out: client->errorValue = stuff->id; return rc; } @@ -2466,26 +2397,27 @@ ProcUninstallColormap(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->id, RT_COLORMAP, client, - DixUninstallAccess); + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->id, RT_COLORMAP, + client, DixUninstallAccess); if (rc != Success) - goto out; + goto out; rc = XaceHook(XACE_SCREEN_ACCESS, client, pcmp->pScreen, DixSetAttrAccess); if (rc != Success) { - if (rc == BadValue) - rc = BadColor; - goto out; + if (rc == BadValue) + rc = BadColor; + goto out; } - if(pcmp->mid != pcmp->pScreen->defColormap) - (*(pcmp->pScreen->UninstallColormap)) (pcmp); + if (pcmp->mid != pcmp->pScreen->defColormap) + (*(pcmp->pScreen->UninstallColormap)) (pcmp); return Success; -out: + out: client->errorValue = stuff->id; return rc; } @@ -2493,34 +2425,35 @@ out: int ProcListInstalledColormaps(ClientPtr client) { - xListInstalledColormapsReply *preply; + xListInstalledColormapsReply *preply; int nummaps, rc; WindowPtr pWin; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rc = XaceHook(XACE_SCREEN_ACCESS, client, pWin->drawable.pScreen, - DixGetAttrAccess); + DixGetAttrAccess); if (rc != Success) - return rc; + return rc; preply = malloc(sizeof(xListInstalledColormapsReply) + - pWin->drawable.pScreen->maxInstalledCmaps * - sizeof(Colormap)); - if(!preply) + pWin->drawable.pScreen->maxInstalledCmaps * + sizeof(Colormap)); + if (!preply) return BadAlloc; preply->type = X_Reply; preply->sequenceNumber = client->sequence; nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps) - (pWin->drawable.pScreen, (Colormap *)&preply[1]); + (pWin->drawable.pScreen, (Colormap *) & preply[1]); preply->nColormaps = nummaps; preply->length = nummaps; - WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply); + WriteReplyToClient(client, sizeof(xListInstalledColormapsReply), preply); client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]); free(preply); @@ -2528,147 +2461,142 @@ ProcListInstalledColormaps(ClientPtr client) } int -ProcAllocColor (ClientPtr client) +ProcAllocColor(ClientPtr client) { ColormapPtr pmap; int rc; xAllocColorReply acr; + REQUEST(xAllocColorReq); REQUEST_SIZE_MATCH(xAllocColorReq); - rc = dixLookupResourceByType((pointer *)&pmap, stuff->cmap, RT_COLORMAP, client, - DixAddAccess); - if (rc == Success) - { - acr.type = X_Reply; - acr.length = 0; - acr.sequenceNumber = client->sequence; - acr.red = stuff->red; - acr.green = stuff->green; - acr.blue = stuff->blue; - acr.pixel = 0; - if( (rc = AllocColor(pmap, &acr.red, &acr.green, &acr.blue, - &acr.pixel, client->index)) ) - return rc; + rc = dixLookupResourceByType((pointer *) &pmap, stuff->cmap, RT_COLORMAP, + client, DixAddAccess); + if (rc == Success) { + acr.type = X_Reply; + acr.length = 0; + acr.sequenceNumber = client->sequence; + acr.red = stuff->red; + acr.green = stuff->green; + acr.blue = stuff->blue; + acr.pixel = 0; + if ((rc = AllocColor(pmap, &acr.red, &acr.green, &acr.blue, + &acr.pixel, client->index))) + return rc; #ifdef PANORAMIX - if (noPanoramiXExtension || !pmap->pScreen->myNum) + if (noPanoramiXExtension || !pmap->pScreen->myNum) #endif - WriteReplyToClient(client, sizeof(xAllocColorReply), &acr); - return Success; + WriteReplyToClient(client, sizeof(xAllocColorReply), &acr); + return Success; } - else - { + else { client->errorValue = stuff->cmap; return rc; } } int -ProcAllocNamedColor (ClientPtr client) +ProcAllocNamedColor(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xAllocNamedColorReq); REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client, - DixAddAccess); - if (rc == Success) - { - xAllocNamedColorReply ancr; - - ancr.type = X_Reply; - ancr.length = 0; - ancr.sequenceNumber = client->sequence; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue)) - { - ancr.screenRed = ancr.exactRed; - ancr.screenGreen = ancr.exactGreen; - ancr.screenBlue = ancr.exactBlue; - ancr.pixel = 0; - if( (rc = AllocColor(pcmp, - &ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue, - &ancr.pixel, client->index)) ) - return rc; + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP, + client, DixAddAccess); + if (rc == Success) { + xAllocNamedColorReply ancr; + + ancr.type = X_Reply; + ancr.length = 0; + ancr.sequenceNumber = client->sequence; + + if (OsLookupColor + (pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes, + &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue)) { + ancr.screenRed = ancr.exactRed; + ancr.screenGreen = ancr.exactGreen; + ancr.screenBlue = ancr.exactBlue; + ancr.pixel = 0; + if ((rc = AllocColor(pcmp, + &ancr.screenRed, &ancr.screenGreen, + &ancr.screenBlue, &ancr.pixel, client->index))) + return rc; #ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) + if (noPanoramiXExtension || !pcmp->pScreen->myNum) #endif - WriteReplyToClient(client, sizeof (xAllocNamedColorReply), &ancr); - return Success; - } - else - return BadName; - + WriteReplyToClient(client, sizeof(xAllocNamedColorReply), + &ancr); + return Success; + } + else + return BadName; + } - else - { + else { client->errorValue = stuff->cmap; return rc; } } int -ProcAllocColorCells (ClientPtr client) +ProcAllocColorCells(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xAllocColorCellsReq); REQUEST_SIZE_MATCH(xAllocColorCellsReq); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client, - DixAddAccess); - if (rc == Success) - { - xAllocColorCellsReply accr; - int npixels, nmasks; - long length; - Pixel *ppixels, *pmasks; - - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return BadValue; - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return BadValue; - } - nmasks = stuff->planes; - length = ((long)npixels + (long)nmasks) * sizeof(Pixel); - ppixels = malloc(length); - if(!ppixels) + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP, + client, DixAddAccess); + if (rc == Success) { + xAllocColorCellsReply accr; + int npixels, nmasks; + long length; + Pixel *ppixels, *pmasks; + + npixels = stuff->colors; + if (!npixels) { + client->errorValue = npixels; + return BadValue; + } + if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) { + client->errorValue = stuff->contiguous; + return BadValue; + } + nmasks = stuff->planes; + length = ((long) npixels + (long) nmasks) * sizeof(Pixel); + ppixels = malloc(length); + if (!ppixels) return BadAlloc; - pmasks = ppixels + npixels; - - if( (rc = AllocColorCells(client->index, pcmp, npixels, nmasks, - (Bool)stuff->contiguous, ppixels, pmasks)) ) - { - free(ppixels); - return rc; - } + pmasks = ppixels + npixels; + + if ((rc = AllocColorCells(client->index, pcmp, npixels, nmasks, + (Bool) stuff->contiguous, ppixels, pmasks))) { + free(ppixels); + return rc; + } #ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) + if (noPanoramiXExtension || !pcmp->pScreen->myNum) #endif - { - accr.type = X_Reply; - accr.length = bytes_to_int32(length); - accr.sequenceNumber = client->sequence; - accr.nPixels = npixels; - accr.nMasks = nmasks; - WriteReplyToClient(client, sizeof (xAllocColorCellsReply), &accr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - free(ppixels); + { + accr.type = X_Reply; + accr.length = bytes_to_int32(length); + accr.sequenceNumber = client->sequence; + accr.nPixels = npixels; + accr.nMasks = nmasks; + WriteReplyToClient(client, sizeof(xAllocColorCellsReply), &accr); + client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; + WriteSwappedDataToClient(client, length, ppixels); + } + free(ppixels); return Success; } - else - { + else { client->errorValue = stuff->cmap; return rc; } @@ -2679,58 +2607,56 @@ ProcAllocColorPlanes(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xAllocColorPlanesReq); REQUEST_SIZE_MATCH(xAllocColorPlanesReq); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client, - DixAddAccess); - if (rc == Success) - { - xAllocColorPlanesReply acpr; - int npixels; - long length; - Pixel *ppixels; - - npixels = stuff->colors; - if (!npixels) - { - client->errorValue = npixels; - return BadValue; - } - if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) - { - client->errorValue = stuff->contiguous; - return BadValue; - } - acpr.type = X_Reply; - acpr.sequenceNumber = client->sequence; - acpr.nPixels = npixels; - length = (long)npixels * sizeof(Pixel); - ppixels = malloc(length); - if(!ppixels) + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP, + client, DixAddAccess); + if (rc == Success) { + xAllocColorPlanesReply acpr; + int npixels; + long length; + Pixel *ppixels; + + npixels = stuff->colors; + if (!npixels) { + client->errorValue = npixels; + return BadValue; + } + if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) { + client->errorValue = stuff->contiguous; + return BadValue; + } + acpr.type = X_Reply; + acpr.sequenceNumber = client->sequence; + acpr.nPixels = npixels; + length = (long) npixels *sizeof(Pixel); + + ppixels = malloc(length); + if (!ppixels) return BadAlloc; - if( (rc = AllocColorPlanes(client->index, pcmp, npixels, - (int)stuff->red, (int)stuff->green, (int)stuff->blue, - (Bool)stuff->contiguous, ppixels, - &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) ) - { + if ((rc = AllocColorPlanes(client->index, pcmp, npixels, + (int) stuff->red, (int) stuff->green, + (int) stuff->blue, (Bool) stuff->contiguous, + ppixels, &acpr.redMask, &acpr.greenMask, + &acpr.blueMask))) { free(ppixels); - return rc; - } - acpr.length = bytes_to_int32(length); + return rc; + } + acpr.length = bytes_to_int32(length); #ifdef PANORAMIX - if (noPanoramiXExtension || !pcmp->pScreen->myNum) + if (noPanoramiXExtension || !pcmp->pScreen->myNum) #endif - { - WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); - } - free(ppixels); + { + WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr); + client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; + WriteSwappedDataToClient(client, length, ppixels); + } + free(ppixels); return Success; } - else - { + else { client->errorValue = stuff->cmap; return rc; } @@ -2741,80 +2667,76 @@ ProcFreeColors(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xFreeColorsReq); REQUEST_AT_LEAST_SIZE(xFreeColorsReq); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client, - DixRemoveAccess); - if (rc == Success) - { - int count; + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP, + client, DixRemoveAccess); + if (rc == Success) { + int count; - if(pcmp->flags & AllAllocated) - return BadAccess; - count = bytes_to_int32((client->req_len << 2) - sizeof(xFreeColorsReq)); - return FreeColors(pcmp, client->index, count, - (Pixel *)&stuff[1], (Pixel)stuff->planeMask); + if (pcmp->flags & AllAllocated) + return BadAccess; + count = bytes_to_int32((client->req_len << 2) - sizeof(xFreeColorsReq)); + return FreeColors(pcmp, client->index, count, + (Pixel *) &stuff[1], (Pixel) stuff->planeMask); } - else - { + else { client->errorValue = stuff->cmap; return rc; } } int -ProcStoreColors (ClientPtr client) +ProcStoreColors(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xStoreColorsReq); REQUEST_AT_LEAST_SIZE(xStoreColorsReq); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client, - DixWriteAccess); - if (rc == Success) - { - int count; + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP, + client, DixWriteAccess); + if (rc == Success) { + int count; count = (client->req_len << 2) - sizeof(xStoreColorsReq); - if (count % sizeof(xColorItem)) - return BadLength; - count /= sizeof(xColorItem); - return StoreColors(pcmp, count, (xColorItem *)&stuff[1], client); + if (count % sizeof(xColorItem)) + return BadLength; + count /= sizeof(xColorItem); + return StoreColors(pcmp, count, (xColorItem *) &stuff[1], client); } - else - { + else { client->errorValue = stuff->cmap; return rc; } } int -ProcStoreNamedColor (ClientPtr client) +ProcStoreNamedColor(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xStoreNamedColorReq); REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client, - DixWriteAccess); - if (rc == Success) - { - xColorItem def; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], - stuff->nbytes, &def.red, &def.green, &def.blue)) - { - def.flags = stuff->flags; - def.pixel = stuff->pixel; - return StoreColors(pcmp, 1, &def, client); - } + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP, + client, DixWriteAccess); + if (rc == Success) { + xColorItem def; + + if (OsLookupColor(pcmp->pScreen->myNum, (char *) &stuff[1], + stuff->nbytes, &def.red, &def.green, &def.blue)) { + def.flags = stuff->flags; + def.pixel = stuff->pixel; + return StoreColors(pcmp, 1, &def, client); + } return BadName; } - else - { + else { client->errorValue = stuff->cmap; return rc; } @@ -2825,98 +2747,95 @@ ProcQueryColors(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xQueryColorsReq); REQUEST_AT_LEAST_SIZE(xQueryColorsReq); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client, - DixReadAccess); - if (rc == Success) - { - int count; - xrgb *prgbs; - xQueryColorsReply qcr; - - count = bytes_to_int32((client->req_len << 2) - sizeof(xQueryColorsReq)); - prgbs = calloc(1, count * sizeof(xrgb)); - if(!prgbs && count) + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP, + client, DixReadAccess); + if (rc == Success) { + int count; + xrgb *prgbs; + xQueryColorsReply qcr; + + count = + bytes_to_int32((client->req_len << 2) - sizeof(xQueryColorsReq)); + prgbs = calloc(1, count * sizeof(xrgb)); + if (!prgbs && count) return BadAlloc; - if( (rc = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs, client)) ) - { - free(prgbs); - return rc; - } - memset(&qcr, 0, sizeof(xQueryColorsReply)); - qcr.type = X_Reply; - qcr.length = bytes_to_int32(count * sizeof(xrgb)); - qcr.sequenceNumber = client->sequence; - qcr.nColors = count; - WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr); - if (count) - { - client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend; - WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs); - } - free(prgbs); - return Success; - + if ((rc = + QueryColors(pcmp, count, (Pixel *) &stuff[1], prgbs, client))) { + free(prgbs); + return rc; + } + memset(&qcr, 0, sizeof(xQueryColorsReply)); + qcr.type = X_Reply; + qcr.length = bytes_to_int32(count * sizeof(xrgb)); + qcr.sequenceNumber = client->sequence; + qcr.nColors = count; + WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr); + if (count) { + client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend; + WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs); + } + free(prgbs); + return Success; + } - else - { + else { client->errorValue = stuff->cmap; return rc; } -} +} int ProcLookupColor(ClientPtr client) { ColormapPtr pcmp; int rc; + REQUEST(xLookupColorReq); REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes); - rc = dixLookupResourceByType((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client, - DixReadAccess); - if (rc == Success) - { - xLookupColorReply lcr; - - if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes, - &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) - { - lcr.type = X_Reply; - lcr.length = 0; - lcr.sequenceNumber = client->sequence; - lcr.screenRed = lcr.exactRed; - lcr.screenGreen = lcr.exactGreen; - lcr.screenBlue = lcr.exactBlue; - (*pcmp->pScreen->ResolveColor)(&lcr.screenRed, - &lcr.screenGreen, - &lcr.screenBlue, - pcmp->pVisual); - WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr); - return Success; - } + rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP, + client, DixReadAccess); + if (rc == Success) { + xLookupColorReply lcr; + + if (OsLookupColor + (pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes, + &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) { + lcr.type = X_Reply; + lcr.length = 0; + lcr.sequenceNumber = client->sequence; + lcr.screenRed = lcr.exactRed; + lcr.screenGreen = lcr.exactGreen; + lcr.screenBlue = lcr.exactBlue; + (*pcmp->pScreen->ResolveColor) (&lcr.screenRed, + &lcr.screenGreen, + &lcr.screenBlue, pcmp->pVisual); + WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr); + return Success; + } return BadName; } - else - { + else { client->errorValue = stuff->cmap; return rc; } } int -ProcCreateCursor (ClientPtr client) +ProcCreateCursor(ClientPtr client) { - CursorPtr pCursor; - PixmapPtr src; - PixmapPtr msk; - unsigned char * srcbits; - unsigned char * mskbits; - unsigned short width, height; - long n; - CursorMetricRec cm; + CursorPtr pCursor; + PixmapPtr src; + PixmapPtr msk; + unsigned char *srcbits; + unsigned char *mskbits; + unsigned short width, height; + long n; + CursorMetricRec cm; int rc; REQUEST(xCreateCursorReq); @@ -2924,87 +2843,82 @@ ProcCreateCursor (ClientPtr client) REQUEST_SIZE_MATCH(xCreateCursorReq); LEGAL_NEW_RESOURCE(stuff->cid, client); - rc = dixLookupResourceByType((pointer *)&src, stuff->source, RT_PIXMAP, client, - DixReadAccess); + rc = dixLookupResourceByType((pointer *) &src, stuff->source, RT_PIXMAP, + client, DixReadAccess); if (rc != Success) { - client->errorValue = stuff->source; - return rc; + client->errorValue = stuff->source; + return rc; } - rc = dixLookupResourceByType((pointer *)&msk, stuff->mask, RT_PIXMAP, client, - DixReadAccess); - if (rc != Success) - { - if (stuff->mask != None) - { - client->errorValue = stuff->mask; - return rc; - } - } - else if ( src->drawable.width != msk->drawable.width - || src->drawable.height != msk->drawable.height - || src->drawable.depth != 1 - || msk->drawable.depth != 1) - return BadMatch; + rc = dixLookupResourceByType((pointer *) &msk, stuff->mask, RT_PIXMAP, + client, DixReadAccess); + if (rc != Success) { + if (stuff->mask != None) { + client->errorValue = stuff->mask; + return rc; + } + } + else if (src->drawable.width != msk->drawable.width + || src->drawable.height != msk->drawable.height + || src->drawable.depth != 1 || msk->drawable.depth != 1) + return BadMatch; width = src->drawable.width; height = src->drawable.height; - if ( stuff->x > width - || stuff->y > height ) - return BadMatch; + if (stuff->x > width || stuff->y > height) + return BadMatch; - n = BitmapBytePad(width)*height; + n = BitmapBytePad(width) * height; srcbits = calloc(1, n); if (!srcbits) - return BadAlloc; + return BadAlloc; mskbits = malloc(n); - if (!mskbits) - { - free(srcbits); - return BadAlloc; + if (!mskbits) { + free(srcbits); + return BadAlloc; } - (* src->drawable.pScreen->GetImage)( (DrawablePtr)src, 0, 0, width, height, - XYPixmap, 1, (pointer)srcbits); - if ( msk == (PixmapPtr)NULL) - { - unsigned char *bits = mskbits; - while (--n >= 0) - *bits++ = ~0; + (*src->drawable.pScreen->GetImage) ((DrawablePtr) src, 0, 0, width, height, + XYPixmap, 1, (pointer) srcbits); + if (msk == (PixmapPtr) NULL) { + unsigned char *bits = mskbits; + + while (--n >= 0) + *bits++ = ~0; } - else - { - /* zeroing the (pad) bits helps some ddx cursor handling */ - memset((char *)mskbits, 0, n); - (* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width, - height, XYPixmap, 1, (pointer)mskbits); + else { + /* zeroing the (pad) bits helps some ddx cursor handling */ + memset((char *) mskbits, 0, n); + (*msk->drawable.pScreen->GetImage) ((DrawablePtr) msk, 0, 0, width, + height, XYPixmap, 1, + (pointer) mskbits); } cm.width = width; cm.height = height; cm.xhot = stuff->x; cm.yhot = stuff->y; rc = AllocARGBCursor(srcbits, mskbits, NULL, &cm, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue, - &pCursor, client, stuff->cid); + stuff->foreRed, stuff->foreGreen, stuff->foreBlue, + stuff->backRed, stuff->backGreen, stuff->backBlue, + &pCursor, client, stuff->cid); if (rc != Success) - goto bail; - if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) { - rc = BadAlloc; - goto bail; + goto bail; + if (!AddResource(stuff->cid, RT_CURSOR, (pointer) pCursor)) { + rc = BadAlloc; + goto bail; } return Success; -bail: + bail: free(srcbits); free(mskbits); return rc; } int -ProcCreateGlyphCursor (ClientPtr client) +ProcCreateGlyphCursor(ClientPtr client) { CursorPtr pCursor; int res; @@ -3015,70 +2929,67 @@ ProcCreateGlyphCursor (ClientPtr client) LEGAL_NEW_RESOURCE(stuff->cid, client); res = AllocGlyphCursor(stuff->source, stuff->sourceChar, - stuff->mask, stuff->maskChar, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue, - &pCursor, client, stuff->cid); + stuff->mask, stuff->maskChar, + stuff->foreRed, stuff->foreGreen, stuff->foreBlue, + stuff->backRed, stuff->backGreen, stuff->backBlue, + &pCursor, client, stuff->cid); if (res != Success) - return res; - if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return Success; + return res; + if (AddResource(stuff->cid, RT_CURSOR, (pointer) pCursor)) + return Success; return BadAlloc; } - int -ProcFreeCursor (ClientPtr client) +ProcFreeCursor(ClientPtr client) { CursorPtr pCursor; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - rc = dixLookupResourceByType((pointer *)&pCursor, stuff->id, RT_CURSOR, client, - DixDestroyAccess); - if (rc == Success) - { - FreeResource(stuff->id, RT_NONE); - return Success; + rc = dixLookupResourceByType((pointer *) &pCursor, stuff->id, RT_CURSOR, + client, DixDestroyAccess); + if (rc == Success) { + FreeResource(stuff->id, RT_NONE); + return Success; } - else - { - client->errorValue = stuff->id; - return rc; + else { + client->errorValue = stuff->id; + return rc; } } int -ProcQueryBestSize (ClientPtr client) +ProcQueryBestSize(ClientPtr client) { - xQueryBestSizeReply reply; + xQueryBestSizeReply reply; DrawablePtr pDraw; ScreenPtr pScreen; int rc; + REQUEST(xQueryBestSizeReq); REQUEST_SIZE_MATCH(xQueryBestSizeReq); - if ((stuff->class != CursorShape) && - (stuff->class != TileShape) && - (stuff->class != StippleShape)) - { - client->errorValue = stuff->class; + if ((stuff->class != CursorShape) && + (stuff->class != TileShape) && (stuff->class != StippleShape)) { + client->errorValue = stuff->class; return BadValue; } rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY, - DixGetAttrAccess); + DixGetAttrAccess); if (rc != Success) - return rc; + return rc; if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW) - return BadMatch; + return BadMatch; pScreen = pDraw->pScreen; rc = XaceHook(XACE_SCREEN_ACCESS, client, pScreen, DixGetAttrAccess); if (rc != Success) - return rc; - (* pScreen->QueryBestSize)(stuff->class, &stuff->width, - &stuff->height, pScreen); + return rc; + (*pScreen->QueryBestSize) (stuff->class, &stuff->width, + &stuff->height, pScreen); memset(&reply, 0, sizeof(xQueryBestSizeReply)); reply.type = X_Reply; reply.length = 0; @@ -3089,65 +3000,61 @@ ProcQueryBestSize (ClientPtr client) return Success; } - int -ProcSetScreenSaver (ClientPtr client) +ProcSetScreenSaver(ClientPtr client) { int rc, i, blankingOption, exposureOption; + REQUEST(xSetScreenSaverReq); REQUEST_SIZE_MATCH(xSetScreenSaverReq); for (i = 0; i < screenInfo.numScreens; i++) { - rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i], - DixSetAttrAccess); - if (rc != Success) - return rc; + rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i], + DixSetAttrAccess); + if (rc != Success) + return rc; } blankingOption = stuff->preferBlank; if ((blankingOption != DontPreferBlanking) && (blankingOption != PreferBlanking) && - (blankingOption != DefaultBlanking)) - { - client->errorValue = blankingOption; + (blankingOption != DefaultBlanking)) { + client->errorValue = blankingOption; return BadValue; } exposureOption = stuff->allowExpose; if ((exposureOption != DontAllowExposures) && (exposureOption != AllowExposures) && - (exposureOption != DefaultExposures)) - { - client->errorValue = exposureOption; + (exposureOption != DefaultExposures)) { + client->errorValue = exposureOption; return BadValue; } - if (stuff->timeout < -1) - { - client->errorValue = stuff->timeout; + if (stuff->timeout < -1) { + client->errorValue = stuff->timeout; return BadValue; } - if (stuff->interval < -1) - { - client->errorValue = stuff->interval; + if (stuff->interval < -1) { + client->errorValue = stuff->interval; return BadValue; } if (blankingOption == DefaultBlanking) - ScreenSaverBlanking = defaultScreenSaverBlanking; + ScreenSaverBlanking = defaultScreenSaverBlanking; else - ScreenSaverBlanking = blankingOption; + ScreenSaverBlanking = blankingOption; if (exposureOption == DefaultExposures) - ScreenSaverAllowExposures = defaultScreenSaverAllowExposures; + ScreenSaverAllowExposures = defaultScreenSaverAllowExposures; else - ScreenSaverAllowExposures = exposureOption; + ScreenSaverAllowExposures = exposureOption; if (stuff->timeout >= 0) - ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND; - else - ScreenSaverTime = defaultScreenSaverTime; + ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND; + else + ScreenSaverTime = defaultScreenSaverTime; if (stuff->interval >= 0) - ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND; + ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND; else - ScreenSaverInterval = defaultScreenSaverInterval; + ScreenSaverInterval = defaultScreenSaverInterval; SetScreenSaverTimer(); return Success; @@ -3158,13 +3065,14 @@ ProcGetScreenSaver(ClientPtr client) { xGetScreenSaverReply rep; int rc, i; + REQUEST_SIZE_MATCH(xReq); for (i = 0; i < screenInfo.numScreens; i++) { - rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i], - DixGetAttrAccess); - if (rc != Success) - return rc; + rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i], + DixGetAttrAccess); + if (rc != Success) + return rc; } rep.type = X_Reply; @@ -3185,12 +3093,12 @@ ProcChangeHosts(ClientPtr client) REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength); - if(stuff->mode == HostInsert) - return AddHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); + if (stuff->mode == HostInsert) + return AddHost(client, (int) stuff->hostFamily, + stuff->hostLength, (pointer) &stuff[1]); if (stuff->mode == HostDelete) - return RemoveHost(client, (int)stuff->hostFamily, - stuff->hostLength, (pointer)&stuff[1]); + return RemoveHost(client, (int) stuff->hostFamily, + stuff->hostLength, (pointer) &stuff[1]); client->errorValue = stuff->mode; return BadValue; } @@ -3199,8 +3107,9 @@ int ProcListHosts(ClientPtr client) { xListHostsReply reply; - int len, nHosts, result; - pointer pdata; + int len, nHosts, result; + pointer pdata; + /* REQUEST(xListHostsReq); */ REQUEST_SIZE_MATCH(xListHostsReq); @@ -3208,20 +3117,19 @@ ProcListHosts(ClientPtr client) /* untrusted clients can't list hosts */ result = XaceHook(XACE_SERVER_ACCESS, client, DixReadAccess); if (result != Success) - return result; + return result; result = GetHosts(&pdata, &nHosts, &len, &reply.enabled); if (result != Success) - return result; + return result; reply.type = X_Reply; reply.sequenceNumber = client->sequence; reply.nHosts = nHosts; reply.length = bytes_to_int32(len); WriteReplyToClient(client, sizeof(xListHostsReply), &reply); - if (nHosts) - { - client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend; - WriteSwappedDataToClient(client, len, pdata); + if (nHosts) { + client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend; + WriteSwappedDataToClient(client, len, pdata); } free(pdata); return Success; @@ -3233,9 +3141,8 @@ ProcChangeAccessControl(ClientPtr client) REQUEST(xSetAccessControlReq); REQUEST_SIZE_MATCH(xSetAccessControlReq); - if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess)) - { - client->errorValue = stuff->mode; + if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess)) { + client->errorValue = stuff->mode; return BadValue; } return ChangeAccessControl(client, stuff->mode == EnableAccess); @@ -3254,12 +3161,11 @@ CloseDownRetainedResources(void) int i; ClientPtr client; - for (i=1; i<currentMaxClients; i++) - { + for (i = 1; i < currentMaxClients; i++) { client = clients[i]; if (client && (client->closeDownMode == RetainTemporary) - && (client->clientGone)) - CloseDownClient(client); + && (client->clientGone)) + CloseDownClient(client); } } @@ -3271,28 +3177,26 @@ ProcKillClient(ClientPtr client) int rc; REQUEST_SIZE_MATCH(xResourceReq); - if (stuff->id == AllTemporary) - { - CloseDownRetainedResources(); + if (stuff->id == AllTemporary) { + CloseDownRetainedResources(); return Success; } rc = dixLookupClient(&killclient, stuff->id, client, DixDestroyAccess); if (rc == Success) { - CloseDownClient(killclient); - /* if an LBX proxy gets killed, isItTimeToYield will be set */ - if (isItTimeToYield || (client == killclient)) - { - /* force yield and return Success, so that Dispatch() - * doesn't try to touch client - */ - isItTimeToYield = TRUE; - return Success; - } - return Success; + CloseDownClient(killclient); + /* if an LBX proxy gets killed, isItTimeToYield will be set */ + if (isItTimeToYield || (client == killclient)) { + /* force yield and return Success, so that Dispatch() + * doesn't try to touch client + */ + isItTimeToYield = TRUE; + return Success; + } + return Success; } else - return rc; + return rc; } int @@ -3302,24 +3206,24 @@ ProcSetFontPath(ClientPtr client) unsigned long nbytes, total; long nfonts; int n; + REQUEST(xSetFontPathReq); - + REQUEST_AT_LEAST_SIZE(xSetFontPathReq); - + nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq); total = nbytes; - ptr = (unsigned char *)&stuff[1]; + ptr = (unsigned char *) &stuff[1]; nfonts = stuff->nFonts; - while (--nfonts >= 0) - { - if ((total == 0) || (total < (n = (*ptr + 1)))) - return BadLength; - total -= n; - ptr += n; + while (--nfonts >= 0) { + if ((total == 0) || (total < (n = (*ptr + 1)))) + return BadLength; + total -= n; + ptr += n; } if (total >= 4) - return BadLength; - return SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1]); + return BadLength; + return SetFontPath(client, stuff->nFonts, (unsigned char *) &stuff[1]); } int @@ -3328,12 +3232,13 @@ ProcGetFontPath(ClientPtr client) xGetFontPathReply reply; int rc, stringLens, numpaths; unsigned char *bufferStart; + /* REQUEST (xReq); */ REQUEST_SIZE_MATCH(xReq); rc = GetFontPath(client, &numpaths, &stringLens, &bufferStart); if (rc != Success) - return rc; + return rc; reply.type = X_Reply; reply.sequenceNumber = client->sequence; @@ -3342,7 +3247,8 @@ ProcGetFontPath(ClientPtr client) WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply); if (stringLens || numpaths) - (void)WriteToClient(client, stringLens + numpaths, (char *)bufferStart); + (void) WriteToClient(client, stringLens + numpaths, + (char *) bufferStart); return Success; } @@ -3350,50 +3256,49 @@ int ProcChangeCloseDownMode(ClientPtr client) { int rc; + REQUEST(xSetCloseDownModeReq); REQUEST_SIZE_MATCH(xSetCloseDownModeReq); rc = XaceHook(XACE_CLIENT_ACCESS, client, client, DixManageAccess); if (rc != Success) - return rc; + return rc; if ((stuff->mode == AllTemporary) || - (stuff->mode == RetainPermanent) || - (stuff->mode == RetainTemporary)) - { - client->closeDownMode = stuff->mode; - return Success; + (stuff->mode == RetainPermanent) || (stuff->mode == RetainTemporary)) { + client->closeDownMode = stuff->mode; + return Success; } - else - { - client->errorValue = stuff->mode; - return BadValue; + else { + client->errorValue = stuff->mode; + return BadValue; } } -int ProcForceScreenSaver(ClientPtr client) -{ +int +ProcForceScreenSaver(ClientPtr client) +{ int rc; + REQUEST(xForceScreenSaverReq); REQUEST_SIZE_MATCH(xForceScreenSaverReq); - - if ((stuff->mode != ScreenSaverReset) && - (stuff->mode != ScreenSaverActive)) - { - client->errorValue = stuff->mode; + + if ((stuff->mode != ScreenSaverReset) && (stuff->mode != ScreenSaverActive)) { + client->errorValue = stuff->mode; return BadValue; } - rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, (int)stuff->mode); + rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, (int) stuff->mode); if (rc != Success) - return rc; + return rc; return Success; } -int ProcNoOperation(ClientPtr client) +int +ProcNoOperation(ClientPtr client) { REQUEST_AT_LEAST_SIZE(xReq); - + /* noop -- don't do anything */ return Success; } @@ -3411,88 +3316,81 @@ void CloseDownClient(ClientPtr client) { Bool really_close_down = client->clientGone || - client->closeDownMode == DestroyAll; + client->closeDownMode == DestroyAll; - if (!client->clientGone) - { - /* ungrab server if grabbing client dies */ - if (grabState != GrabNone && grabClient == client) - { - UngrabServer(client); - } - BITCLEAR(grabWaiters, client->index); - DeleteClientFromAnySelections(client); - ReleaseActiveGrabs(client); - DeleteClientFontStuff(client); - if (!really_close_down) - { - /* This frees resources that should never be retained - * no matter what the close down mode is. Actually we - * could do this unconditionally, but it's probably - * better not to traverse all the client's resources - * twice (once here, once a few lines down in - * FreeClientResources) in the common case of - * really_close_down == TRUE. - */ - FreeClientNeverRetainResources(client); - client->clientState = ClientStateRetained; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - } - client->clientGone = TRUE; /* so events aren't sent to client */ - if (ClientIsAsleep(client)) - ClientSignal (client); - ProcessWorkQueueZombies(); - CloseDownConnection(client); - - /* If the client made it to the Running stage, nClients has - * been incremented on its behalf, so we need to decrement it - * now. If it hasn't gotten to Running, nClients has *not* - * been incremented, so *don't* decrement it. - */ - if (client->clientState != ClientStateInitial) - { - --nClients; - } - } - - if (really_close_down) - { - if (client->clientState == ClientStateRunning && nClients == 0) - dispatchException |= dispatchExceptionAtReset; - - client->clientState = ClientStateGone; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; - - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; - clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } - FreeClientResources(client); - /* Disable client ID tracking. This must be done after - * ClientStateCallback. */ - ReleaseClientIds(client); + if (!client->clientGone) { + /* ungrab server if grabbing client dies */ + if (grabState != GrabNone && grabClient == client) { + UngrabServer(client); + } + BITCLEAR(grabWaiters, client->index); + DeleteClientFromAnySelections(client); + ReleaseActiveGrabs(client); + DeleteClientFontStuff(client); + if (!really_close_down) { + /* This frees resources that should never be retained + * no matter what the close down mode is. Actually we + * could do this unconditionally, but it's probably + * better not to traverse all the client's resources + * twice (once here, once a few lines down in + * FreeClientResources) in the common case of + * really_close_down == TRUE. + */ + FreeClientNeverRetainResources(client); + client->clientState = ClientStateRetained; + if (ClientStateCallback) { + NewClientInfoRec clientinfo; + + clientinfo.client = client; + clientinfo.prefix = (xConnSetupPrefix *) NULL; + clientinfo.setup = (xConnSetup *) NULL; + CallCallbacks((&ClientStateCallback), (pointer) &clientinfo); + } + } + client->clientGone = TRUE; /* so events aren't sent to client */ + if (ClientIsAsleep(client)) + ClientSignal(client); + ProcessWorkQueueZombies(); + CloseDownConnection(client); + + /* If the client made it to the Running stage, nClients has + * been incremented on its behalf, so we need to decrement it + * now. If it hasn't gotten to Running, nClients has *not* + * been incremented, so *don't* decrement it. + */ + if (client->clientState != ClientStateInitial) { + --nClients; + } + } + + if (really_close_down) { + if (client->clientState == ClientStateRunning && nClients == 0) + dispatchException |= dispatchExceptionAtReset; + + client->clientState = ClientStateGone; + if (ClientStateCallback) { + NewClientInfoRec clientinfo; + + clientinfo.client = client; + clientinfo.prefix = (xConnSetupPrefix *) NULL; + clientinfo.setup = (xConnSetup *) NULL; + CallCallbacks((&ClientStateCallback), (pointer) &clientinfo); + } + FreeClientResources(client); + /* Disable client ID tracking. This must be done after + * ClientStateCallback. */ + ReleaseClientIds(client); #ifdef XSERVER_DTRACE - XSERVER_CLIENT_DISCONNECT(client->index); -#endif - if (client->index < nextFreeClientID) - nextFreeClientID = client->index; - clients[client->index] = NullClient; - SmartLastClient = NullClient; - dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); + XSERVER_CLIENT_DISCONNECT(client->index); +#endif + if (client->index < nextFreeClientID) + nextFreeClientID = client->index; + clients[client->index] = NullClient; + SmartLastClient = NullClient; + dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); - while (!clients[currentMaxClients-1]) - currentMaxClients--; + while (!clients[currentMaxClients - 1]) + currentMaxClients--; } } @@ -3500,22 +3398,24 @@ static void KillAllClients(void) { int i; - for (i=1; i<currentMaxClients; i++) + + for (i = 1; i < currentMaxClients; i++) if (clients[i]) { /* Make sure Retained clients are released. */ clients[i]->closeDownMode = DestroyAll; - CloseDownClient(clients[i]); + CloseDownClient(clients[i]); } } -void InitClient(ClientPtr client, int i, pointer ospriv) +void +InitClient(ClientPtr client, int i, pointer ospriv) { client->index = i; - client->clientAsMask = ((Mask)i) << CLIENTOFFSET; + client->clientAsMask = ((Mask) i) << CLIENTOFFSET; client->closeDownMode = i ? DestroyAll : RetainPermanent; client->requestVector = InitialVector; client->osPrivate = ospriv; - QueryMinMaxKeyCodes(&client->minKC,&client->maxKC); + QueryMinMaxKeyCodes(&client->minKC, &client->maxKC); client->smart_start_tick = SmartScheduleTime; client->smart_stop_tick = SmartScheduleTime; client->smart_check_tick = SmartScheduleTime; @@ -3529,7 +3429,8 @@ void InitClient(ClientPtr client, int i, pointer ospriv) * Returns NULL if there are no free clients. *************************/ -ClientPtr NextAvailableClient(pointer ospriv) +ClientPtr +NextAvailableClient(pointer ospriv) { int i; ClientPtr client; @@ -3537,42 +3438,40 @@ ClientPtr NextAvailableClient(pointer ospriv) i = nextFreeClientID; if (i == MAXCLIENTS) - return (ClientPtr)NULL; - clients[i] = client = dixAllocateObjectWithPrivates(ClientRec, PRIVATE_CLIENT); + return (ClientPtr) NULL; + clients[i] = client = + dixAllocateObjectWithPrivates(ClientRec, PRIVATE_CLIENT); if (!client) - return (ClientPtr)NULL; + return (ClientPtr) NULL; InitClient(client, i, ospriv); - if (!InitClientResources(client)) - { - dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); - return (ClientPtr)NULL; + if (!InitClientResources(client)) { + dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); + return (ClientPtr) NULL; } data.reqType = 1; data.length = bytes_to_int32(sz_xReq + sz_xConnClientPrefix); - if (!InsertFakeRequest(client, (char *)&data, sz_xReq)) - { - FreeClientResources(client); - dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); - return (ClientPtr)NULL; + if (!InsertFakeRequest(client, (char *) &data, sz_xReq)) { + FreeClientResources(client); + dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); + return (ClientPtr) NULL; } if (i == currentMaxClients) - currentMaxClients++; + currentMaxClients++; while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID]) - nextFreeClientID++; + nextFreeClientID++; /* Enable client ID tracking. This must be done before * ClientStateCallback. */ ReserveClientIds(client); - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; + if (ClientStateCallback) { + NewClientInfoRec clientinfo; - clientinfo.client = client; - clientinfo.prefix = (xConnSetupPrefix *)NULL; + clientinfo.client = client; + clientinfo.prefix = (xConnSetupPrefix *) NULL; clientinfo.setup = (xConnSetup *) NULL; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } + CallCallbacks((&ClientStateCallback), (pointer) &clientinfo); + } return client; } @@ -3583,21 +3482,19 @@ ProcInitialConnection(ClientPtr client) xConnClientPrefix *prefix; int whichbyte = 1; - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); + prefix = (xConnClientPrefix *) ((char *) stuff + sz_xReq); if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B')) - return client->noClientException = -1; + return client->noClientException = -1; if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) || - (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l'))) - { - client->swapped = TRUE; - SwapConnClientPrefix(prefix); + (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l'))) { + client->swapped = TRUE; + SwapConnClientPrefix(prefix); } stuff->reqType = 2; stuff->length += bytes_to_int32(prefix->nbytesAuthProto) + - bytes_to_int32(prefix->nbytesAuthString); - if (client->swapped) - { - swaps(&stuff->length); + bytes_to_int32(prefix->nbytesAuthString); + if (client->swapped) { + swaps(&stuff->length); } ResetCurrentRequest(client); return Success; @@ -3609,24 +3506,23 @@ SendConnSetup(ClientPtr client, const char *reason) xWindowRoot *root; int i; int numScreens; - char* lConnectionInfo; - xConnSetupPrefix* lconnSetupPrefix; + char *lConnectionInfo; + xConnSetupPrefix *lconnSetupPrefix; - if (reason) - { - xConnSetupPrefix csp; + if (reason) { + xConnSetupPrefix csp; - csp.success = xFalse; - csp.lengthReason = strlen(reason); - csp.length = bytes_to_int32(csp.lengthReason); - csp.majorVersion = X_PROTOCOL; - csp.minorVersion = X_PROTOCOL_REVISION; - if (client->swapped) - WriteSConnSetupPrefix(client, &csp); - else - (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp); - (void)WriteToClient(client, (int)csp.lengthReason, reason); - return client->noClientException = -1; + csp.success = xFalse; + csp.lengthReason = strlen(reason); + csp.length = bytes_to_int32(csp.lengthReason); + csp.majorVersion = X_PROTOCOL; + csp.minorVersion = X_PROTOCOL_REVISION; + if (client->swapped) + WriteSConnSetupPrefix(client, &csp); + else + (void) WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp); + (void) WriteToClient(client, (int) csp.lengthReason, reason); + return client->noClientException = -1; } numScreens = screenInfo.numScreens; @@ -3642,61 +3538,56 @@ SendConnSetup(ClientPtr client, const char *reason) client->requestVector = client->swapped ? SwappedProcVector : ProcVector; client->sequence = 0; - ((xConnSetup *)lConnectionInfo)->ridBase = client->clientAsMask; - ((xConnSetup *)lConnectionInfo)->ridMask = RESOURCE_ID_MASK; + ((xConnSetup *) lConnectionInfo)->ridBase = client->clientAsMask; + ((xConnSetup *) lConnectionInfo)->ridMask = RESOURCE_ID_MASK; #ifdef MATCH_CLIENT_ENDIAN - ((xConnSetup *)lConnectionInfo)->imageByteOrder = ClientOrder (client); - ((xConnSetup *)lConnectionInfo)->bitmapBitOrder = ClientOrder (client); + ((xConnSetup *) lConnectionInfo)->imageByteOrder = ClientOrder(client); + ((xConnSetup *) lConnectionInfo)->bitmapBitOrder = ClientOrder(client); #endif /* fill in the "currentInputMask" */ - root = (xWindowRoot *)(lConnectionInfo + connBlockScreenStart); + root = (xWindowRoot *) (lConnectionInfo + connBlockScreenStart); #ifdef PANORAMIX if (noPanoramiXExtension) - numScreens = screenInfo.numScreens; - else - numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; + numScreens = screenInfo.numScreens; + else + numScreens = ((xConnSetup *) ConnectionInfo)->numRoots; #endif - for (i=0; i<numScreens; i++) - { - unsigned int j; - xDepth *pDepth; - WindowPtr pRoot = screenInfo.screens[i]->root; + for (i = 0; i < numScreens; i++) { + unsigned int j; + xDepth *pDepth; + WindowPtr pRoot = screenInfo.screens[i]->root; root->currentInputMask = pRoot->eventMask | wOtherEventMasks(pRoot); - pDepth = (xDepth *)(root + 1); - for (j = 0; j < root->nDepths; j++) - { - pDepth = (xDepth *)(((char *)(pDepth + 1)) + - pDepth->nVisuals * sizeof(xVisualType)); - } - root = (xWindowRoot *)pDepth; + pDepth = (xDepth *) (root + 1); + for (j = 0; j < root->nDepths; j++) { + pDepth = (xDepth *) (((char *) (pDepth + 1)) + + pDepth->nVisuals * sizeof(xVisualType)); + } + root = (xWindowRoot *) pDepth; } - if (client->swapped) - { - WriteSConnSetupPrefix(client, lconnSetupPrefix); - WriteSConnectionInfo(client, - (unsigned long)(lconnSetupPrefix->length << 2), - lConnectionInfo); + if (client->swapped) { + WriteSConnSetupPrefix(client, lconnSetupPrefix); + WriteSConnectionInfo(client, + (unsigned long) (lconnSetupPrefix->length << 2), + lConnectionInfo); } - else - { - (void)WriteToClient(client, sizeof(xConnSetupPrefix), - (char *) lconnSetupPrefix); - (void)WriteToClient(client, (int)(lconnSetupPrefix->length << 2), - lConnectionInfo); + else { + (void) WriteToClient(client, sizeof(xConnSetupPrefix), + (char *) lconnSetupPrefix); + (void) WriteToClient(client, (int) (lconnSetupPrefix->length << 2), + lConnectionInfo); } client->clientState = ClientStateRunning; - if (ClientStateCallback) - { - NewClientInfoRec clientinfo; + if (ClientStateCallback) { + NewClientInfoRec clientinfo; - clientinfo.client = client; - clientinfo.prefix = lconnSetupPrefix; - clientinfo.setup = (xConnSetup *)lConnectionInfo; - CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); - } + clientinfo.client = client; + clientinfo.prefix = lconnSetupPrefix; + clientinfo.setup = (xConnSetup *) lConnectionInfo; + CallCallbacks((&ClientStateCallback), (pointer) &clientinfo); + } return Success; } @@ -3706,26 +3597,27 @@ ProcEstablishConnection(ClientPtr client) const char *reason; char *auth_proto, *auth_string; xConnClientPrefix *prefix; + REQUEST(xReq); - prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); - auth_proto = (char *)prefix + sz_xConnClientPrefix; + prefix = (xConnClientPrefix *) ((char *) stuff + sz_xReq); + auth_proto = (char *) prefix + sz_xConnClientPrefix; auth_string = auth_proto + pad_to_int32(prefix->nbytesAuthProto); if ((prefix->majorVersion != X_PROTOCOL) || - (prefix->minorVersion != X_PROTOCOL_REVISION)) - reason = "Protocol version mismatch"; + (prefix->minorVersion != X_PROTOCOL_REVISION)) + reason = "Protocol version mismatch"; else - reason = ClientAuthorized(client, - (unsigned short)prefix->nbytesAuthProto, - auth_proto, - (unsigned short)prefix->nbytesAuthString, - auth_string); + reason = ClientAuthorized(client, + (unsigned short) prefix->nbytesAuthProto, + auth_proto, + (unsigned short) prefix->nbytesAuthString, + auth_string); - return(SendConnSetup(client, reason)); + return (SendConnSetup(client, reason)); } void -SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode, +SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode, XID resId, int errorCode) { xError rep; @@ -3737,7 +3629,7 @@ SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode, rep.minorCode = minorCode; rep.resourceID = resId; - WriteEventsToClient (client, 1, (xEvent *)&rep); + WriteEventsToClient(client, 1, (xEvent *) &rep); } void @@ -3752,15 +3644,15 @@ MarkClientException(ClientPtr client) * Note that ~0 is an invalid entry (mostly for the benefit of the reader). */ static int answer[6][4] = { - /* pad pad pad pad*/ - /* 8 16 32 64 */ - - { 3, 4, 5 , 6 }, /* 1 bit per pixel */ - { 1, 2, 3 , 4 }, /* 4 bits per pixel */ - { 0, 1, 2 , 3 }, /* 8 bits per pixel */ - { ~0, 0, 1 , 2 }, /* 16 bits per pixel */ - { ~0, ~0, 0 , 1 }, /* 24 bits per pixel */ - { ~0, ~0, 0 , 1 } /* 32 bits per pixel */ + /* pad pad pad pad */ + /* 8 16 32 64 */ + + {3, 4, 5, 6}, /* 1 bit per pixel */ + {1, 2, 3, 4}, /* 4 bits per pixel */ + {0, 1, 2, 3}, /* 8 bits per pixel */ + {~0, 0, 1, 2}, /* 16 bits per pixel */ + {~0, ~0, 0, 1}, /* 24 bits per pixel */ + {~0, ~0, 0, 1} /* 32 bits per pixel */ }; /* @@ -3768,32 +3660,32 @@ static int answer[6][4] = { * the answer array above given the number of bits per pixel?" * Note that ~0 is an invalid entry (mostly for the benefit of the reader). */ -static int indexForBitsPerPixel[ 33 ] = { - ~0, 0, ~0, ~0, /* 1 bit per pixel */ - 1, ~0, ~0, ~0, /* 4 bits per pixel */ - 2, ~0, ~0, ~0, /* 8 bits per pixel */ - ~0,~0, ~0, ~0, - 3, ~0, ~0, ~0, /* 16 bits per pixel */ - ~0,~0, ~0, ~0, - 4, ~0, ~0, ~0, /* 24 bits per pixel */ - ~0,~0, ~0, ~0, - 5 /* 32 bits per pixel */ +static int indexForBitsPerPixel[33] = { + ~0, 0, ~0, ~0, /* 1 bit per pixel */ + 1, ~0, ~0, ~0, /* 4 bits per pixel */ + 2, ~0, ~0, ~0, /* 8 bits per pixel */ + ~0, ~0, ~0, ~0, + 3, ~0, ~0, ~0, /* 16 bits per pixel */ + ~0, ~0, ~0, ~0, + 4, ~0, ~0, ~0, /* 24 bits per pixel */ + ~0, ~0, ~0, ~0, + 5 /* 32 bits per pixel */ }; /* * This array gives the bytesperPixel value for cases where the number * of bits per pixel is a multiple of 8 but not a power of 2. */ -static int answerBytesPerPixel[ 33 ] = { - ~0, 0, ~0, ~0, /* 1 bit per pixel */ - 0, ~0, ~0, ~0, /* 4 bits per pixel */ - 0, ~0, ~0, ~0, /* 8 bits per pixel */ - ~0,~0, ~0, ~0, - 0, ~0, ~0, ~0, /* 16 bits per pixel */ - ~0,~0, ~0, ~0, - 3, ~0, ~0, ~0, /* 24 bits per pixel */ - ~0,~0, ~0, ~0, - 0 /* 32 bits per pixel */ +static int answerBytesPerPixel[33] = { + ~0, 0, ~0, ~0, /* 1 bit per pixel */ + 0, ~0, ~0, ~0, /* 4 bits per pixel */ + 0, ~0, ~0, ~0, /* 8 bits per pixel */ + ~0, ~0, ~0, ~0, + 0, ~0, ~0, ~0, /* 16 bits per pixel */ + ~0, ~0, ~0, ~0, + 3, ~0, ~0, ~0, /* 24 bits per pixel */ + ~0, ~0, ~0, ~0, + 0 /* 32 bits per pixel */ }; /* @@ -3801,24 +3693,24 @@ static int answerBytesPerPixel[ 33 ] = { * the answer array above given the number of bits per scanline pad unit?" * Note that ~0 is an invalid entry (mostly for the benefit of the reader). */ -static int indexForScanlinePad[ 65 ] = { - ~0, ~0, ~0, ~0, - ~0, ~0, ~0, ~0, - 0, ~0, ~0, ~0, /* 8 bits per scanline pad unit */ - ~0, ~0, ~0, ~0, - 1, ~0, ~0, ~0, /* 16 bits per scanline pad unit */ - ~0, ~0, ~0, ~0, - ~0, ~0, ~0, ~0, - ~0, ~0, ~0, ~0, - 2, ~0, ~0, ~0, /* 32 bits per scanline pad unit */ - ~0, ~0, ~0, ~0, - ~0, ~0, ~0, ~0, - ~0, ~0, ~0, ~0, - ~0, ~0, ~0, ~0, - ~0, ~0, ~0, ~0, - ~0, ~0, ~0, ~0, - ~0, ~0, ~0, ~0, - 3 /* 64 bits per scanline pad unit */ +static int indexForScanlinePad[65] = { + ~0, ~0, ~0, ~0, + ~0, ~0, ~0, ~0, + 0, ~0, ~0, ~0, /* 8 bits per scanline pad unit */ + ~0, ~0, ~0, ~0, + 1, ~0, ~0, ~0, /* 16 bits per scanline pad unit */ + ~0, ~0, ~0, ~0, + ~0, ~0, ~0, ~0, + ~0, ~0, ~0, ~0, + 2, ~0, ~0, ~0, /* 32 bits per scanline pad unit */ + ~0, ~0, ~0, ~0, + ~0, ~0, ~0, ~0, + ~0, ~0, ~0, ~0, + ~0, ~0, ~0, ~0, + ~0, ~0, ~0, ~0, + ~0, ~0, ~0, ~0, + ~0, ~0, ~0, ~0, + 3 /* 64 bits per scanline pad unit */ }; /* @@ -3830,15 +3722,11 @@ with its screen number, a pointer to its ScreenRec, argc, and argv. */ int -AddScreen( - Bool (* pfnInit)( - int /*index*/, - ScreenPtr /*pScreen*/, - int /*argc*/, - char ** /*argv*/ - ), - int argc, - char **argv) +AddScreen(Bool (*pfnInit) (int /*index */ , + ScreenPtr /*pScreen */ , + int /*argc */ , + char ** /*argv */ + ), int argc, char **argv) { int i; @@ -3847,19 +3735,19 @@ AddScreen( i = screenInfo.numScreens; if (i == MAXSCREENS) - return -1; + return -1; pScreen = (ScreenPtr) calloc(1, sizeof(ScreenRec)); if (!pScreen) - return -1; + return -1; if (!dixAllocatePrivates(&pScreen->devPrivates, PRIVATE_SCREEN)) { - free (pScreen); - return -1; + free(pScreen); + return -1; } pScreen->myNum = i; - pScreen->totalPixmapSize = 0; /* computed in CreateScratchPixmapForScreen */ - pScreen->ClipNotify = 0; /* for R4 ddx compatibility */ + pScreen->totalPixmapSize = 0; /* computed in CreateScratchPixmapForScreen */ + pScreen->ClipNotify = 0; /* for R4 ddx compatibility */ pScreen->CreateScreenResources = 0; /* @@ -3871,29 +3759,26 @@ AddScreen( * Anyway, this must be called after InitOutput and before the * screen init routine is called. */ - for (format=0; format<screenInfo.numPixmapFormats; format++) - { - depth = screenInfo.formats[format].depth; - bitsPerPixel = screenInfo.formats[format].bitsPerPixel; - scanlinepad = screenInfo.formats[format].scanlinePad; - j = indexForBitsPerPixel[ bitsPerPixel ]; - k = indexForScanlinePad[ scanlinepad ]; - PixmapWidthPaddingInfo[ depth ].padPixelsLog2 = answer[j][k]; - PixmapWidthPaddingInfo[ depth ].padRoundUp = - (scanlinepad/bitsPerPixel) - 1; - j = indexForBitsPerPixel[ 8 ]; /* bits per byte */ - PixmapWidthPaddingInfo[ depth ].padBytesLog2 = answer[j][k]; - PixmapWidthPaddingInfo[ depth ].bitsPerPixel = bitsPerPixel; - if (answerBytesPerPixel[bitsPerPixel]) - { - PixmapWidthPaddingInfo[ depth ].notPower2 = 1; - PixmapWidthPaddingInfo[ depth ].bytesPerPixel = - answerBytesPerPixel[bitsPerPixel]; - } - else - { - PixmapWidthPaddingInfo[ depth ].notPower2 = 0; - } + for (format = 0; format < screenInfo.numPixmapFormats; format++) { + depth = screenInfo.formats[format].depth; + bitsPerPixel = screenInfo.formats[format].bitsPerPixel; + scanlinepad = screenInfo.formats[format].scanlinePad; + j = indexForBitsPerPixel[bitsPerPixel]; + k = indexForScanlinePad[scanlinepad]; + PixmapWidthPaddingInfo[depth].padPixelsLog2 = answer[j][k]; + PixmapWidthPaddingInfo[depth].padRoundUp = + (scanlinepad / bitsPerPixel) - 1; + j = indexForBitsPerPixel[8]; /* bits per byte */ + PixmapWidthPaddingInfo[depth].padBytesLog2 = answer[j][k]; + PixmapWidthPaddingInfo[depth].bitsPerPixel = bitsPerPixel; + if (answerBytesPerPixel[bitsPerPixel]) { + PixmapWidthPaddingInfo[depth].notPower2 = 1; + PixmapWidthPaddingInfo[depth].bytesPerPixel = + answerBytesPerPixel[bitsPerPixel]; + } + else { + PixmapWidthPaddingInfo[depth].notPower2 = 0; + } } /* This is where screen specific stuff gets initialized. Load the @@ -3903,20 +3788,20 @@ AddScreen( Note that InitScreen is NOT allowed to modify argc, argv, or any of the strings pointed to by argv. They may be passed to multiple screens. - */ + */ screenInfo.screens[i] = pScreen; screenInfo.numScreens++; - if (!(*pfnInit)(i, pScreen, argc, argv)) - { - dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN); - free(pScreen); - screenInfo.numScreens--; - return -1; + if (!(*pfnInit) (i, pScreen, argc, argv)) { + dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN); + free(pScreen); + screenInfo.numScreens--; + return -1; } update_desktop_dimensions(); - dixRegisterScreenPrivateKey(&cursorScreenDevPriv, pScreen, PRIVATE_CURSOR, 0); + dixRegisterScreenPrivateKey(&cursorScreenDevPriv, pScreen, PRIVATE_CURSOR, + 0); return i; } diff --git a/xorg-server/dix/dixfonts.c b/xorg-server/dix/dixfonts.c index d2bcb84ea..19fd31e3e 100644 --- a/xorg-server/dix/dixfonts.c +++ b/xorg-server/dix/dixfonts.c @@ -74,14 +74,14 @@ extern pointer fosNaturalParams; extern FontPtr defaultFont; static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0; -static int num_fpes = 0; +static int num_fpes = 0; static FPEFunctions *fpe_functions = (FPEFunctions *) 0; -static int num_fpe_types = 0; +static int num_fpe_types = 0; static unsigned char *font_path_string; -static int num_slept_fpes = 0; -static int size_slept_fpes = 0; +static int num_slept_fpes = 0; +static int size_slept_fpes = 0; static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0; static FontPatternCachePtr patternCache; @@ -90,29 +90,29 @@ FontToXError(int err) { switch (err) { case Successful: - return Success; + return Success; case AllocError: - return BadAlloc; + return BadAlloc; case BadFontName: - return BadName; + return BadName; case BadFontPath: - case BadFontFormat: /* is there something better? */ + case BadFontFormat: /* is there something better? */ case BadCharRange: - return BadValue; + return BadValue; default: - return err; + return err; } } static int LoadGlyphs(ClientPtr client, FontPtr pfont, unsigned nchars, int item_size, - unsigned char *data) + unsigned char *data) { if (fpe_functions[pfont->fpe->type].load_glyphs) - return (*fpe_functions[pfont->fpe->type].load_glyphs) - (client, pfont, 0, nchars, item_size, data); + return (*fpe_functions[pfont->fpe->type].load_glyphs) + (client, pfont, 0, nchars, item_size, data); else - return Successful; + return Successful; } /* @@ -121,19 +121,19 @@ LoadGlyphs(ClientPtr client, FontPtr pfont, unsigned nchars, int item_size, Bool SetDefaultFont(char *defaultfontname) { - int err; - FontPtr pf; - XID fid; + int err; + FontPtr pf; + XID fid; fid = FakeClientID(0); err = OpenFont(serverClient, fid, FontLoadAll | FontOpenSync, - (unsigned) strlen(defaultfontname), defaultfontname); + (unsigned) strlen(defaultfontname), defaultfontname); if (err != Success) - return FALSE; - err = dixLookupResourceByType((pointer *)&pf, fid, RT_FONT, serverClient, - DixReadAccess); + return FALSE; + err = dixLookupResourceByType((pointer *) &pf, fid, RT_FONT, serverClient, + DixReadAccess); if (err != Success) - return FALSE; + return FALSE; defaultFont = pf; return TRUE; } @@ -150,22 +150,22 @@ SetDefaultFont(char *defaultfontname) void QueueFontWakeup(FontPathElementPtr fpe) { - int i; + int i; FontPathElementPtr *new; for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - return; - } + if (slept_fpes[i] == fpe) { + return; + } } if (num_slept_fpes == size_slept_fpes) { - new = (FontPathElementPtr *) - realloc(slept_fpes, - sizeof(FontPathElementPtr) * (size_slept_fpes + 4)); - if (!new) - return; - slept_fpes = new; - size_slept_fpes += 4; + new = (FontPathElementPtr *) + realloc(slept_fpes, + sizeof(FontPathElementPtr) * (size_slept_fpes + 4)); + if (!new) + return; + slept_fpes = new; + size_slept_fpes += 4; } slept_fpes[num_slept_fpes] = fpe; num_slept_fpes++; @@ -174,32 +174,31 @@ QueueFontWakeup(FontPathElementPtr fpe) void RemoveFontWakeup(FontPathElementPtr fpe) { - int i, - j; + int i, j; for (i = 0; i < num_slept_fpes; i++) { - if (slept_fpes[i] == fpe) { - for (j = i; j < num_slept_fpes; j++) { - slept_fpes[j] = slept_fpes[j + 1]; - } - num_slept_fpes--; - return; - } + if (slept_fpes[i] == fpe) { + for (j = i; j < num_slept_fpes; j++) { + slept_fpes[j] = slept_fpes[j + 1]; + } + num_slept_fpes--; + return; + } } } void FontWakeup(pointer data, int count, pointer LastSelectMask) { - int i; + int i; FontPathElementPtr fpe; if (count < 0) - return; + return; /* wake up any fpe's that may be waiting for information */ for (i = 0; i < num_slept_fpes; i++) { - fpe = slept_fpes[i]; - (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask); + fpe = slept_fpes[i]; + (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask); } } @@ -211,166 +210,153 @@ UseFPE(FontPathElementPtr fpe) } static void -FreeFPE (FontPathElementPtr fpe) +FreeFPE(FontPathElementPtr fpe) { fpe->refcount--; if (fpe->refcount == 0) { - (*fpe_functions[fpe->type].free_fpe) (fpe); - free(fpe->name); - free(fpe); + (*fpe_functions[fpe->type].free_fpe) (fpe); + free(fpe->name); + free(fpe); } } static Bool doOpenFont(ClientPtr client, OFclosurePtr c) { - FontPtr pfont = NullFont; + FontPtr pfont = NullFont; FontPathElementPtr fpe = NULL; - ScreenPtr pScr; - int err = Successful; - int i; - char *alias, - *newname; - int newlen; - int aliascount = 20; + ScreenPtr pScr; + int err = Successful; + int i; + char *alias, *newname; + int newlen; + int aliascount = 20; + /* * Decide at runtime what FontFormat to use. */ - Mask FontFormat = - - ((screenInfo.imageByteOrder == LSBFirst) ? - BitmapFormatByteOrderLSB : BitmapFormatByteOrderMSB) | - - ((screenInfo.bitmapBitOrder == LSBFirst) ? - BitmapFormatBitOrderLSB : BitmapFormatBitOrderMSB) | - - BitmapFormatImageRectMin | - + Mask FontFormat = + ((screenInfo.imageByteOrder == LSBFirst) ? + BitmapFormatByteOrderLSB : BitmapFormatByteOrderMSB) | + ((screenInfo.bitmapBitOrder == LSBFirst) ? + BitmapFormatBitOrderLSB : BitmapFormatBitOrderMSB) | + BitmapFormatImageRectMin | #if GLYPHPADBYTES == 1 - BitmapFormatScanlinePad8 | + BitmapFormatScanlinePad8 | #endif - #if GLYPHPADBYTES == 2 - BitmapFormatScanlinePad16 | + BitmapFormatScanlinePad16 | #endif - #if GLYPHPADBYTES == 4 - BitmapFormatScanlinePad32 | + BitmapFormatScanlinePad32 | #endif - #if GLYPHPADBYTES == 8 - BitmapFormatScanlinePad64 | + BitmapFormatScanlinePad64 | #endif + BitmapFormatScanlineUnit8; - BitmapFormatScanlineUnit8; - - if (client->clientGone) - { - if (c->current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; + if (client->clientGone) { + if (c->current_fpe < c->num_fpes) { + fpe = c->fpe_list[c->current_fpe]; + (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); + } + err = Successful; + goto bail; } while (c->current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current_fpe]; - err = (*fpe_functions[fpe->type].open_font) - ((pointer) client, fpe, c->flags, - c->fontname, c->fnamelen, FontFormat, - BitmapFormatMaskByte | - BitmapFormatMaskBit | - BitmapFormatMaskImageRectangle | - BitmapFormatMaskScanLinePad | - BitmapFormatMaskScanLineUnit, - c->fontid, &pfont, &alias, - c->non_cachable_font && c->non_cachable_font->fpe == fpe ? - c->non_cachable_font : - (FontPtr)0); - - if (err == FontNameAlias && alias) { - newlen = strlen(alias); - newname = (char *) realloc(c->fontname, newlen); - if (!newname) { - err = AllocError; - break; - } - memmove(newname, alias, newlen); - c->fontname = newname; - c->fnamelen = newlen; - c->current_fpe = 0; - if (--aliascount <= 0) { - /* We've tried resolving this alias 20 times, we're - * probably stuck in an infinite loop of aliases pointing - * to each other - time to take emergency exit! - */ - err = BadImplementation; - break; - } - continue; - } - if (err == BadFontName) { - c->current_fpe++; - continue; - } - if (err == Suspended) { - if (!ClientIsAsleep(client)) - ClientSleep(client, (ClientSleepProcPtr)doOpenFont, c); - else - goto xinerama_sleep; - return TRUE; - } - break; + fpe = c->fpe_list[c->current_fpe]; + err = (*fpe_functions[fpe->type].open_font) + ((pointer) client, fpe, c->flags, + c->fontname, c->fnamelen, FontFormat, + BitmapFormatMaskByte | + BitmapFormatMaskBit | + BitmapFormatMaskImageRectangle | + BitmapFormatMaskScanLinePad | + BitmapFormatMaskScanLineUnit, + c->fontid, &pfont, &alias, + c->non_cachable_font && c->non_cachable_font->fpe == fpe ? + c->non_cachable_font : (FontPtr) 0); + + if (err == FontNameAlias && alias) { + newlen = strlen(alias); + newname = (char *) realloc(c->fontname, newlen); + if (!newname) { + err = AllocError; + break; + } + memmove(newname, alias, newlen); + c->fontname = newname; + c->fnamelen = newlen; + c->current_fpe = 0; + if (--aliascount <= 0) { + /* We've tried resolving this alias 20 times, we're + * probably stuck in an infinite loop of aliases pointing + * to each other - time to take emergency exit! + */ + err = BadImplementation; + break; + } + continue; + } + if (err == BadFontName) { + c->current_fpe++; + continue; + } + if (err == Suspended) { + if (!ClientIsAsleep(client)) + ClientSleep(client, (ClientSleepProcPtr) doOpenFont, c); + else + goto xinerama_sleep; + return TRUE; + } + break; } if (err != Successful) - goto bail; + goto bail; if (!pfont) { - err = BadFontName; - goto bail; + err = BadFontName; + goto bail; } /* check values for firstCol, lastCol, firstRow, and lastRow */ if (pfont->info.firstCol > pfont->info.lastCol || - pfont->info.firstRow > pfont->info.lastRow || - pfont->info.lastCol - pfont->info.firstCol > 255) { - err = AllocError; - goto bail; + pfont->info.firstRow > pfont->info.lastRow || + pfont->info.lastCol - pfont->info.firstCol > 255) { + err = AllocError; + goto bail; } if (!pfont->fpe) - pfont->fpe = fpe; + pfont->fpe = fpe; pfont->refcnt++; if (pfont->refcnt == 1) { - UseFPE(pfont->fpe); - for (i = 0; i < screenInfo.numScreens; i++) { - pScr = screenInfo.screens[i]; - if (pScr->RealizeFont) - { - if (!(*pScr->RealizeFont) (pScr, pfont)) - { - CloseFont (pfont, (Font) 0); - err = AllocError; - goto bail; - } - } - } + UseFPE(pfont->fpe); + for (i = 0; i < screenInfo.numScreens; i++) { + pScr = screenInfo.screens[i]; + if (pScr->RealizeFont) { + if (!(*pScr->RealizeFont) (pScr, pfont)) { + CloseFont(pfont, (Font) 0); + err = AllocError; + goto bail; + } + } + } } if (!AddResource(c->fontid, RT_FONT, (pointer) pfont)) { - err = AllocError; - goto bail; + err = AllocError; + goto bail; } if (patternCache && pfont != c->non_cachable_font) - CacheFontPattern(patternCache, c->origFontName, c->origFontNameLen, - pfont); -bail: + CacheFontPattern(patternCache, c->origFontName, c->origFontNameLen, + pfont); + bail: if (err != Successful && c->client != serverClient) { - SendErrorToClient(c->client, X_OpenFont, 0, - c->fontid, FontToXError(err)); + SendErrorToClient(c->client, X_OpenFont, 0, + c->fontid, FontToXError(err)); } ClientWakeup(c->client); -xinerama_sleep: + xinerama_sleep: for (i = 0; i < c->num_fpes; i++) { - FreeFPE(c->fpe_list[i]); + FreeFPE(c->fpe_list[i]); } free(c->fpe_list); free(c->fontname); @@ -379,52 +365,51 @@ xinerama_sleep: } int -OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontname) +OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, + char *pfontname) { OFclosurePtr c; - int i; - FontPtr cached = (FontPtr)0; + int i; + FontPtr cached = (FontPtr) 0; if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) - return BadName; - if (patternCache) - { + return BadName; + if (patternCache) { - /* - ** Check name cache. If we find a cached version of this font that - ** is cachable, immediately satisfy the request with it. If we find - ** a cached version of this font that is non-cachable, we do not - ** satisfy the request with it. Instead, we pass the FontPtr to the - ** FPE's open_font code (the fontfile FPE in turn passes the - ** information to the rasterizer; the fserve FPE ignores it). - ** - ** Presumably, the font is marked non-cachable because the FPE has - ** put some licensing restrictions on it. If the FPE, using - ** whatever logic it relies on, determines that it is willing to - ** share this existing font with the client, then it has the option - ** to return the FontPtr we passed it as the newly-opened font. - ** This allows the FPE to exercise its licensing logic without - ** having to create another instance of a font that already exists. - */ - - cached = FindCachedFontPattern(patternCache, pfontname, lenfname); - if (cached && cached->info.cachable) - { - if (!AddResource(fid, RT_FONT, (pointer) cached)) - return BadAlloc; - cached->refcnt++; - return Success; - } + /* + ** Check name cache. If we find a cached version of this font that + ** is cachable, immediately satisfy the request with it. If we find + ** a cached version of this font that is non-cachable, we do not + ** satisfy the request with it. Instead, we pass the FontPtr to the + ** FPE's open_font code (the fontfile FPE in turn passes the + ** information to the rasterizer; the fserve FPE ignores it). + ** + ** Presumably, the font is marked non-cachable because the FPE has + ** put some licensing restrictions on it. If the FPE, using + ** whatever logic it relies on, determines that it is willing to + ** share this existing font with the client, then it has the option + ** to return the FontPtr we passed it as the newly-opened font. + ** This allows the FPE to exercise its licensing logic without + ** having to create another instance of a font that already exists. + */ + + cached = FindCachedFontPattern(patternCache, pfontname, lenfname); + if (cached && cached->info.cachable) { + if (!AddResource(fid, RT_FONT, (pointer) cached)) + return BadAlloc; + cached->refcnt++; + return Success; + } } c = malloc(sizeof(OFclosureRec)); if (!c) - return BadAlloc; + return BadAlloc; c->fontname = malloc(lenfname); c->origFontName = pfontname; c->origFontNameLen = lenfname; if (!c->fontname) { - free(c); - return BadAlloc; + free(c); + return BadAlloc; } /* * copy the current FPE list, so that if it gets changed by another client @@ -432,14 +417,14 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontna */ c->fpe_list = malloc(sizeof(FontPathElementPtr) * num_fpes); if (!c->fpe_list) { - free(c->fontname); - free(c); - return BadAlloc; + free(c->fontname); + free(c); + return BadAlloc; } memmove(c->fontname, pfontname, lenfname); for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); + c->fpe_list[i] = font_path_elements[i]; + UseFPE(c->fpe_list[i]); } c->client = client; c->fontid = fid; @@ -461,38 +446,37 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontna int CloseFont(pointer value, XID fid) { - int nscr; - ScreenPtr pscr; + int nscr; + ScreenPtr pscr; FontPathElementPtr fpe; - FontPtr pfont = (FontPtr)value; + FontPtr pfont = (FontPtr) value; if (pfont == NullFont) - return Success; + return Success; if (--pfont->refcnt == 0) { - if (patternCache) - RemoveCachedFontPattern (patternCache, pfont); - /* - * since the last reference is gone, ask each screen to free any - * storage it may have allocated locally for it. - */ - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { - pscr = screenInfo.screens[nscr]; - if (pscr->UnrealizeFont) - (*pscr->UnrealizeFont) (pscr, pfont); - } - if (pfont == defaultFont) - defaultFont = NULL; + if (patternCache) + RemoveCachedFontPattern(patternCache, pfont); + /* + * since the last reference is gone, ask each screen to free any + * storage it may have allocated locally for it. + */ + for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { + pscr = screenInfo.screens[nscr]; + if (pscr->UnrealizeFont) + (*pscr->UnrealizeFont) (pscr, pfont); + } + if (pfont == defaultFont) + defaultFont = NULL; #ifdef XF86BIGFONT - XF86BigfontFreeFontShm(pfont); + XF86BigfontFreeFontShm(pfont); #endif - fpe = pfont->fpe; - (*fpe_functions[fpe->type].close_font) (fpe, pfont); - FreeFPE(fpe); + fpe = pfont->fpe; + (*fpe_functions[fpe->type].close_font) (fpe, pfont); + FreeFPE(fpe); } return Success; } - /***====================================================================***/ /** @@ -502,19 +486,17 @@ CloseFont(pointer value, XID fid) * \param pReply caller must allocate this storage */ void -QueryFont(FontPtr pFont, xQueryFontReply *pReply, int nProtoCCIStructs) +QueryFont(FontPtr pFont, xQueryFontReply * pReply, int nProtoCCIStructs) { - FontPropPtr pFP; - int r, - c, - i; - xFontProp *prFP; - xCharInfo *prCI; - xCharInfo *charInfos[256]; - unsigned char chars[512]; - int ninfos; - unsigned long ncols; - unsigned long count; + FontPropPtr pFP; + int r, c, i; + xFontProp *prFP; + xCharInfo *prCI; + xCharInfo *charInfos[256]; + unsigned char chars[512]; + int ninfos; + unsigned long ncols; + unsigned long count; /* pr->length set in dispatch */ pReply->minCharOrByte2 = pFont->info.firstCol; @@ -534,31 +516,29 @@ QueryFont(FontPtr pFont, xQueryFontReply *pReply, int nProtoCCIStructs) pReply->nCharInfos = nProtoCCIStructs; for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) (&pReply[1]); - i < pFont->info.nprops; - i++, pFP++, prFP++) { - prFP->name = pFP->name; - prFP->value = pFP->value; + i < pFont->info.nprops; i++, pFP++, prFP++) { + prFP->name = pFP->name; + prFP->value = pFP->value; } ninfos = 0; ncols = (unsigned long) (pFont->info.lastCol - pFont->info.firstCol + 1); prCI = (xCharInfo *) (prFP); for (r = pFont->info.firstRow; - ninfos < nProtoCCIStructs && r <= (int)pFont->info.lastRow; - r++) { - i = 0; - for (c = pFont->info.firstCol; c <= (int)pFont->info.lastCol; c++) { - chars[i++] = r; - chars[i++] = c; - } - (*pFont->get_metrics) (pFont, ncols, chars, - TwoD16Bit, &count, charInfos); - i = 0; - for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) { - *prCI = *charInfos[i]; - prCI++; - ninfos++; - } + ninfos < nProtoCCIStructs && r <= (int) pFont->info.lastRow; r++) { + i = 0; + for (c = pFont->info.firstCol; c <= (int) pFont->info.lastCol; c++) { + chars[i++] = r; + chars[i++] = c; + } + (*pFont->get_metrics) (pFont, ncols, chars, + TwoD16Bit, &count, charInfos); + i = 0; + for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) { + *prCI = *charInfos[i]; + prCI++; + ninfos++; + } } return; } @@ -567,211 +547,202 @@ static Bool doListFontsAndAliases(ClientPtr client, LFclosurePtr c) { FontPathElementPtr fpe; - int err = Successful; + int err = Successful; FontNamesPtr names = NULL; - char *name, *resolved=NULL; - int namelen, resolvedlen; - int nnames; - int stringLens; - int i; + char *name, *resolved = NULL; + int namelen, resolvedlen; + int nnames; + int stringLens; + int i; xListFontsReply reply; - char *bufptr; - char *bufferStart; - int aliascount = 0; - - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; + char *bufptr; + char *bufferStart; + int aliascount = 0; + + if (client->clientGone) { + if (c->current.current_fpe < c->num_fpes) { + fpe = c->fpe_list[c->current.current_fpe]; + (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); + } + err = Successful; + goto bail; } if (!c->current.patlen) - goto finish; + goto finish; while (c->current.current_fpe < c->num_fpes) { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - - if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) - { - /* This FPE doesn't support/require list_fonts_and_aliases */ - - err = (*fpe_functions[fpe->type].list_fonts) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - c->names); - - if (err == Suspended) { - if (!ClientIsAsleep(client)) - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - c); - else - goto xinerama_sleep; - return TRUE; - } - - err = BadFontName; - } - else - { - /* Start of list_fonts_and_aliases functionality. Modeled - after list_fonts_with_info in that it resolves aliases, - except that the information collected from FPEs is just - names, not font info. Each list_next_font_or_alias() - returns either a name into name/namelen or an alias into - name/namelen and its target name into resolved/resolvedlen. - The code at this level then resolves the alias by polling - the FPEs. */ - - if (!c->current.list_started) { - err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) - ((pointer) c->client, fpe, c->current.pattern, - c->current.patlen, c->current.max_names - c->names->nnames, - &c->current.private); - if (err == Suspended) { - if (!ClientIsAsleep(client)) - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - c); - else - goto xinerama_sleep; - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) { - char *tmpname; - name = 0; - err = (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &name, &namelen, &tmpname, - &resolvedlen, c->current.private); - if (err == Suspended) { - if (!ClientIsAsleep(client)) - ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - c); - else - goto xinerama_sleep; - return TRUE; - } - if (err == FontNameAlias) { - free(resolved); - resolved = malloc(resolvedlen + 1); - if (resolved) - memmove(resolved, tmpname, resolvedlen + 1); - } - } - - if (err == Successful) - { - if (c->haveSaved) - { - if (c->savedName) - (void)AddFontNamesName(c->names, c->savedName, - c->savedNameLen); - } - else - (void)AddFontNamesName(c->names, name, namelen); - } - - /* - * When we get an alias back, save our state and reset back to - * the start of the FPE looking for the specified name. As - * soon as a real font is found for the alias, pop back to the - * old state - */ - else if (err == FontNameAlias) { - char tmp_pattern[XLFDMAXFONTNAMELEN]; - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - memmove(tmp_pattern, resolved, resolvedlen); - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - - tmpname = 0; - (void) (*fpe_functions[fpe->type].list_next_font_or_alias) - ((pointer) c->client, fpe, &tmpname, &tmpnamelen, - &tmpname, &tmpnamelen, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - free(c->savedName); - c->savedName = malloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - c->savedNameLen = namelen; - aliascount = 20; - } - memmove(c->current.pattern, tmp_pattern, resolvedlen); - c->current.patlen = resolvedlen; - c->current.max_names = c->names->nnames + 1; - c->current.current_fpe = -1; - c->current.private = 0; - err = BadFontName; - } - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've collected enough - * font names, quit. - */ - if (err == BadFontName) { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->names->nnames == c->current.max_names || - c->current.current_fpe == c->num_fpes) { - c->haveSaved = FALSE; - c->current = c->saved; - /* Give the saved namelist a chance to clean itself up */ - continue; - } - } - if (c->names->nnames == c->current.max_names) - break; - } + fpe = c->fpe_list[c->current.current_fpe]; + err = Successful; + + if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) { + /* This FPE doesn't support/require list_fonts_and_aliases */ + + err = (*fpe_functions[fpe->type].list_fonts) + ((pointer) c->client, fpe, c->current.pattern, + c->current.patlen, c->current.max_names - c->names->nnames, + c->names); + + if (err == Suspended) { + if (!ClientIsAsleep(client)) + ClientSleep(client, + (ClientSleepProcPtr) doListFontsAndAliases, c); + else + goto xinerama_sleep; + return TRUE; + } + + err = BadFontName; + } + else { + /* Start of list_fonts_and_aliases functionality. Modeled + after list_fonts_with_info in that it resolves aliases, + except that the information collected from FPEs is just + names, not font info. Each list_next_font_or_alias() + returns either a name into name/namelen or an alias into + name/namelen and its target name into resolved/resolvedlen. + The code at this level then resolves the alias by polling + the FPEs. */ + + if (!c->current.list_started) { + err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases) + ((pointer) c->client, fpe, c->current.pattern, + c->current.patlen, c->current.max_names - c->names->nnames, + &c->current.private); + if (err == Suspended) { + if (!ClientIsAsleep(client)) + ClientSleep(client, + (ClientSleepProcPtr) doListFontsAndAliases, + c); + else + goto xinerama_sleep; + return TRUE; + } + if (err == Successful) + c->current.list_started = TRUE; + } + if (err == Successful) { + char *tmpname; + + name = 0; + err = (*fpe_functions[fpe->type].list_next_font_or_alias) + ((pointer) c->client, fpe, &name, &namelen, &tmpname, + &resolvedlen, c->current.private); + if (err == Suspended) { + if (!ClientIsAsleep(client)) + ClientSleep(client, + (ClientSleepProcPtr) doListFontsAndAliases, + c); + else + goto xinerama_sleep; + return TRUE; + } + if (err == FontNameAlias) { + free(resolved); + resolved = malloc(resolvedlen + 1); + if (resolved) + memmove(resolved, tmpname, resolvedlen + 1); + } + } + + if (err == Successful) { + if (c->haveSaved) { + if (c->savedName) + (void) AddFontNamesName(c->names, c->savedName, + c->savedNameLen); + } + else + (void) AddFontNamesName(c->names, name, namelen); + } + + /* + * When we get an alias back, save our state and reset back to + * the start of the FPE looking for the specified name. As + * soon as a real font is found for the alias, pop back to the + * old state + */ + else if (err == FontNameAlias) { + char tmp_pattern[XLFDMAXFONTNAMELEN]; + + /* + * when an alias recurses, we need to give + * the last FPE a chance to clean up; so we call + * it again, and assume that the error returned + * is BadFontName, indicating the alias resolution + * is complete. + */ + memmove(tmp_pattern, resolved, resolvedlen); + if (c->haveSaved) { + char *tmpname; + int tmpnamelen; + + tmpname = 0; + (void) (*fpe_functions[fpe->type].list_next_font_or_alias) + ((pointer) c->client, fpe, &tmpname, &tmpnamelen, + &tmpname, &tmpnamelen, c->current.private); + if (--aliascount <= 0) { + err = BadFontName; + goto ContBadFontName; + } + } + else { + c->saved = c->current; + c->haveSaved = TRUE; + free(c->savedName); + c->savedName = malloc(namelen + 1); + if (c->savedName) + memmove(c->savedName, name, namelen + 1); + c->savedNameLen = namelen; + aliascount = 20; + } + memmove(c->current.pattern, tmp_pattern, resolvedlen); + c->current.patlen = resolvedlen; + c->current.max_names = c->names->nnames + 1; + c->current.current_fpe = -1; + c->current.private = 0; + err = BadFontName; + } + } + /* + * At the end of this FPE, step to the next. If we've finished + * processing an alias, pop state back. If we've collected enough + * font names, quit. + */ + if (err == BadFontName) { + ContBadFontName:; + c->current.list_started = FALSE; + c->current.current_fpe++; + err = Successful; + if (c->haveSaved) { + if (c->names->nnames == c->current.max_names || + c->current.current_fpe == c->num_fpes) { + c->haveSaved = FALSE; + c->current = c->saved; + /* Give the saved namelist a chance to clean itself up */ + continue; + } + } + if (c->names->nnames == c->current.max_names) + break; + } } /* * send the reply */ if (err != Successful) { - SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err)); - goto bail; + SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err)); + goto bail; } -finish: + finish: names = c->names; nnames = names->nnames; client = c->client; stringLens = 0; for (i = 0; i < nnames; i++) - stringLens += (names->length[i] <= 255) ? names->length[i] : 0; + stringLens += (names->length[i] <= 255) ? names->length[i] : 0; memset(&reply, 0, sizeof(xListFontsReply)); reply.type = X_Reply; @@ -782,22 +753,21 @@ finish: bufptr = bufferStart = malloc(reply.length << 2); if (!bufptr && reply.length) { - SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); - goto bail; + SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); + goto bail; } /* * since WriteToClient long word aligns things, copy to temp buffer and * write all at once */ for (i = 0; i < nnames; i++) { - if (names->length[i] > 255) - reply.nFonts--; - else - { - *bufptr++ = names->length[i]; - memmove( bufptr, names->names[i], names->length[i]); - bufptr += names->length[i]; - } + if (names->length[i] > 255) + reply.nFonts--; + else { + *bufptr++ = names->length[i]; + memmove(bufptr, names->names[i], names->length[i]); + bufptr += names->length[i]; + } } nnames = reply.nFonts; reply.length = bytes_to_int32(stringLens + nnames); @@ -806,11 +776,11 @@ finish: (void) WriteToClient(client, stringLens + nnames, bufferStart); free(bufferStart); -bail: + bail: ClientWakeup(client); -xinerama_sleep: + xinerama_sleep: for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); + FreeFPE(c->fpe_list[i]); free(c->fpe_list); free(c->savedName); FreeFontNames(names); @@ -820,10 +790,10 @@ xinerama_sleep: } int -ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, +ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, unsigned max_names) { - int i; + int i; LFclosurePtr c; /* @@ -833,30 +803,29 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, * a list containing zero fontnames. */ if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; + return BadAlloc; i = XaceHook(XACE_SERVER_ACCESS, client, DixGetAttrAccess); if (i != Success) - return i; + return i; if (!(c = malloc(sizeof *c))) - return BadAlloc; + return BadAlloc; c->fpe_list = malloc(sizeof(FontPathElementPtr) * num_fpes); if (!c->fpe_list) { - free(c); - return BadAlloc; + free(c); + return BadAlloc; } c->names = MakeFontNamesRecord(max_names < 100 ? max_names : 100); - if (!c->names) - { - free(c->fpe_list); - free(c); - return BadAlloc; + if (!c->names) { + free(c->fpe_list); + free(c); + return BadAlloc; } - memmove( c->current.pattern, pattern, length); + memmove(c->current.pattern, pattern, length); for (i = 0; i < num_fpes; i++) { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); + c->fpe_list[i] = font_path_elements[i]; + UseFPE(c->fpe_list[i]); } c->client = client; c->num_fpes = num_fpes; @@ -875,215 +844,194 @@ int doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) { FontPathElementPtr fpe; - int err = Successful; - char *name; - int namelen; - int numFonts; - FontInfoRec fontInfo, - *pFontInfo; + int err = Successful; + char *name; + int namelen; + int numFonts; + FontInfoRec fontInfo, *pFontInfo; xListFontsWithInfoReply *reply; - int length; - xFontProp *pFP; - int i; - int aliascount = 0; + int length; + xFontProp *pFP; + int i; + int aliascount = 0; xListFontsWithInfoReply finalReply; - if (client->clientGone) - { - if (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - } - err = Successful; - goto bail; + if (client->clientGone) { + if (c->current.current_fpe < c->num_fpes) { + fpe = c->fpe_list[c->current.current_fpe]; + (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); + } + err = Successful; + goto bail; } client->pSwapReplyFunc = ReplySwapVector[X_ListFontsWithInfo]; if (!c->current.patlen) - goto finish; - while (c->current.current_fpe < c->num_fpes) - { - fpe = c->fpe_list[c->current.current_fpe]; - err = Successful; - if (!c->current.list_started) - { - err = (*fpe_functions[fpe->type].start_list_fonts_with_info) - (client, fpe, c->current.pattern, c->current.patlen, - c->current.max_names, &c->current.private); - if (err == Suspended) - { - if (!ClientIsAsleep(client)) - ClientSleep(client, - (ClientSleepProcPtr)doListFontsWithInfo, c); - else - goto xinerama_sleep; - return TRUE; - } - if (err == Successful) - c->current.list_started = TRUE; - } - if (err == Successful) - { - name = 0; - pFontInfo = &fontInfo; - err = (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &name, &namelen, &pFontInfo, - &numFonts, c->current.private); - if (err == Suspended) - { - if (!ClientIsAsleep(client)) - ClientSleep(client, - (ClientSleepProcPtr)doListFontsWithInfo, c); - else - goto xinerama_sleep; - return TRUE; - } - } - /* - * When we get an alias back, save our state and reset back to the - * start of the FPE looking for the specified name. As soon as a real - * font is found for the alias, pop back to the old state - */ - if (err == FontNameAlias) - { - /* - * when an alias recurses, we need to give - * the last FPE a chance to clean up; so we call - * it again, and assume that the error returned - * is BadFontName, indicating the alias resolution - * is complete. - */ - if (c->haveSaved) - { - char *tmpname; - int tmpnamelen; - FontInfoPtr tmpFontInfo; - - tmpname = 0; - tmpFontInfo = &fontInfo; - (void) (*fpe_functions[fpe->type].list_next_font_with_info) - (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo, - &numFonts, c->current.private); - if (--aliascount <= 0) - { - err = BadFontName; - goto ContBadFontName; - } - } - else - { - c->saved = c->current; - c->haveSaved = TRUE; - c->savedNumFonts = numFonts; - free(c->savedName); - c->savedName = malloc(namelen + 1); - if (c->savedName) - memmove(c->savedName, name, namelen + 1); - aliascount = 20; - } - memmove(c->current.pattern, name, namelen); - c->current.patlen = namelen; - c->current.max_names = 1; - c->current.current_fpe = 0; - c->current.private = 0; - c->current.list_started = FALSE; - } - /* - * At the end of this FPE, step to the next. If we've finished - * processing an alias, pop state back. If we've sent enough font - * names, quit. Always wait for BadFontName to let the FPE - * have a chance to clean up. - */ - else if (err == BadFontName) - { - ContBadFontName: ; - c->current.list_started = FALSE; - c->current.current_fpe++; - err = Successful; - if (c->haveSaved) - { - if (c->current.max_names == 0 || - c->current.current_fpe == c->num_fpes) - { - c->haveSaved = FALSE; - c->saved.max_names -= (1 - c->current.max_names); - c->current = c->saved; - } - } - else if (c->current.max_names == 0) - break; - } - else if (err == Successful) - { - length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp); - reply = c->reply; - if (c->length < length) - { - reply = (xListFontsWithInfoReply *) realloc(c->reply, length); - if (!reply) - { - err = AllocError; - break; - } - memset((char*)reply + c->length, 0, length - c->length); - c->reply = reply; - c->length = length; - } - if (c->haveSaved) - { - numFonts = c->savedNumFonts; - name = c->savedName; - namelen = strlen(name); - } - reply->type = X_Reply; - reply->length = bytes_to_int32(sizeof *reply - sizeof(xGenericReply) + - pFontInfo->nprops * sizeof(xFontProp) + - namelen); - reply->sequenceNumber = client->sequence; - reply->nameLength = namelen; - reply->minBounds = pFontInfo->ink_minbounds; - reply->maxBounds = pFontInfo->ink_maxbounds; - reply->minCharOrByte2 = pFontInfo->firstCol; - reply->maxCharOrByte2 = pFontInfo->lastCol; - reply->defaultChar = pFontInfo->defaultCh; - reply->nFontProps = pFontInfo->nprops; - reply->drawDirection = pFontInfo->drawDirection; - reply->minByte1 = pFontInfo->firstRow; - reply->maxByte1 = pFontInfo->lastRow; - reply->allCharsExist = pFontInfo->allExist; - reply->fontAscent = pFontInfo->fontAscent; - reply->fontDescent = pFontInfo->fontDescent; - reply->nReplies = numFonts; - pFP = (xFontProp *) (reply + 1); - for (i = 0; i < pFontInfo->nprops; i++) - { - pFP->name = pFontInfo->props[i].name; - pFP->value = pFontInfo->props[i].value; - pFP++; - } - WriteSwappedDataToClient(client, length, reply); - (void) WriteToClient(client, namelen, name); - if (pFontInfo == &fontInfo) - { - free(fontInfo.props); - free(fontInfo.isStringProp); - } - --c->current.max_names; - } - } -finish: + goto finish; + while (c->current.current_fpe < c->num_fpes) { + fpe = c->fpe_list[c->current.current_fpe]; + err = Successful; + if (!c->current.list_started) { + err = (*fpe_functions[fpe->type].start_list_fonts_with_info) + (client, fpe, c->current.pattern, c->current.patlen, + c->current.max_names, &c->current.private); + if (err == Suspended) { + if (!ClientIsAsleep(client)) + ClientSleep(client, + (ClientSleepProcPtr) doListFontsWithInfo, c); + else + goto xinerama_sleep; + return TRUE; + } + if (err == Successful) + c->current.list_started = TRUE; + } + if (err == Successful) { + name = 0; + pFontInfo = &fontInfo; + err = (*fpe_functions[fpe->type].list_next_font_with_info) + (client, fpe, &name, &namelen, &pFontInfo, + &numFonts, c->current.private); + if (err == Suspended) { + if (!ClientIsAsleep(client)) + ClientSleep(client, + (ClientSleepProcPtr) doListFontsWithInfo, c); + else + goto xinerama_sleep; + return TRUE; + } + } + /* + * When we get an alias back, save our state and reset back to the + * start of the FPE looking for the specified name. As soon as a real + * font is found for the alias, pop back to the old state + */ + if (err == FontNameAlias) { + /* + * when an alias recurses, we need to give + * the last FPE a chance to clean up; so we call + * it again, and assume that the error returned + * is BadFontName, indicating the alias resolution + * is complete. + */ + if (c->haveSaved) { + char *tmpname; + int tmpnamelen; + FontInfoPtr tmpFontInfo; + + tmpname = 0; + tmpFontInfo = &fontInfo; + (void) (*fpe_functions[fpe->type].list_next_font_with_info) + (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo, + &numFonts, c->current.private); + if (--aliascount <= 0) { + err = BadFontName; + goto ContBadFontName; + } + } + else { + c->saved = c->current; + c->haveSaved = TRUE; + c->savedNumFonts = numFonts; + free(c->savedName); + c->savedName = malloc(namelen + 1); + if (c->savedName) + memmove(c->savedName, name, namelen + 1); + aliascount = 20; + } + memmove(c->current.pattern, name, namelen); + c->current.patlen = namelen; + c->current.max_names = 1; + c->current.current_fpe = 0; + c->current.private = 0; + c->current.list_started = FALSE; + } + /* + * At the end of this FPE, step to the next. If we've finished + * processing an alias, pop state back. If we've sent enough font + * names, quit. Always wait for BadFontName to let the FPE + * have a chance to clean up. + */ + else if (err == BadFontName) { + ContBadFontName:; + c->current.list_started = FALSE; + c->current.current_fpe++; + err = Successful; + if (c->haveSaved) { + if (c->current.max_names == 0 || + c->current.current_fpe == c->num_fpes) { + c->haveSaved = FALSE; + c->saved.max_names -= (1 - c->current.max_names); + c->current = c->saved; + } + } + else if (c->current.max_names == 0) + break; + } + else if (err == Successful) { + length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp); + reply = c->reply; + if (c->length < length) { + reply = (xListFontsWithInfoReply *) realloc(c->reply, length); + if (!reply) { + err = AllocError; + break; + } + memset((char *) reply + c->length, 0, length - c->length); + c->reply = reply; + c->length = length; + } + if (c->haveSaved) { + numFonts = c->savedNumFonts; + name = c->savedName; + namelen = strlen(name); + } + reply->type = X_Reply; + reply->length = + bytes_to_int32(sizeof *reply - sizeof(xGenericReply) + + pFontInfo->nprops * sizeof(xFontProp) + namelen); + reply->sequenceNumber = client->sequence; + reply->nameLength = namelen; + reply->minBounds = pFontInfo->ink_minbounds; + reply->maxBounds = pFontInfo->ink_maxbounds; + reply->minCharOrByte2 = pFontInfo->firstCol; + reply->maxCharOrByte2 = pFontInfo->lastCol; + reply->defaultChar = pFontInfo->defaultCh; + reply->nFontProps = pFontInfo->nprops; + reply->drawDirection = pFontInfo->drawDirection; + reply->minByte1 = pFontInfo->firstRow; + reply->maxByte1 = pFontInfo->lastRow; + reply->allCharsExist = pFontInfo->allExist; + reply->fontAscent = pFontInfo->fontAscent; + reply->fontDescent = pFontInfo->fontDescent; + reply->nReplies = numFonts; + pFP = (xFontProp *) (reply + 1); + for (i = 0; i < pFontInfo->nprops; i++) { + pFP->name = pFontInfo->props[i].name; + pFP->value = pFontInfo->props[i].value; + pFP++; + } + WriteSwappedDataToClient(client, length, reply); + (void) WriteToClient(client, namelen, name); + if (pFontInfo == &fontInfo) { + free(fontInfo.props); + free(fontInfo.isStringProp); + } + --c->current.max_names; + } + } + finish: length = sizeof(xListFontsWithInfoReply); memset((char *) &finalReply, 0, sizeof(xListFontsWithInfoReply)); finalReply.type = X_Reply; finalReply.sequenceNumber = client->sequence; finalReply.length = bytes_to_int32(sizeof(xListFontsWithInfoReply) - - sizeof(xGenericReply)); + - sizeof(xGenericReply)); WriteSwappedDataToClient(client, length, &finalReply); -bail: + bail: ClientWakeup(client); -xinerama_sleep: + xinerama_sleep: for (i = 0; i < c->num_fpes; i++) - FreeFPE(c->fpe_list[i]); + FreeFPE(c->fpe_list[i]); free(c->reply); free(c->fpe_list); free(c->savedName); @@ -1092,11 +1040,11 @@ xinerama_sleep: } int -StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, +StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, int max_names) { - int i; - LFWIclosurePtr c; + int i; + LFWIclosurePtr c; /* * The right error to return here would be BadName, however the @@ -1105,25 +1053,23 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, * a list containing zero fontnames. */ if (length > XLFDMAXFONTNAMELEN) - return BadAlloc; + return BadAlloc; i = XaceHook(XACE_SERVER_ACCESS, client, DixGetAttrAccess); if (i != Success) - return i; + return i; if (!(c = malloc(sizeof *c))) - goto badAlloc; + goto badAlloc; c->fpe_list = malloc(sizeof(FontPathElementPtr) * num_fpes); - if (!c->fpe_list) - { - free(c); - goto badAlloc; + if (!c->fpe_list) { + free(c); + goto badAlloc; } memmove(c->current.pattern, pattern, length); - for (i = 0; i < num_fpes; i++) - { - c->fpe_list[i] = font_path_elements[i]; - UseFPE(c->fpe_list[i]); + for (i = 0; i < num_fpes; i++) { + c->fpe_list[i] = font_path_elements[i]; + UseFPE(c->fpe_list[i]); } c->client = client; c->num_fpes = num_fpes; @@ -1139,286 +1085,278 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, c->savedName = 0; doListFontsWithInfo(client, c); return Success; -badAlloc: + badAlloc: return BadAlloc; } #define TextEltHeader 2 #define FontShiftSize 5 -static ChangeGCVal clearGC[] = { { .ptr = NullPixmap } }; +static ChangeGCVal clearGC[] = { {.ptr = NullPixmap} }; + #define clearGCmask (GCClipMask) int doPolyText(ClientPtr client, PTclosurePtr c) { FontPtr pFont = c->pGC->font, oldpFont; - int err = Success, lgerr; /* err is in X error, not font error, space */ + int err = Success, lgerr; /* err is in X error, not font error, space */ enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT; FontPathElementPtr fpe; GC *origGC = NULL; int itemSize = c->reqType == X_PolyText8 ? 1 : 2; - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - - if (ClientIsAsleep(client)) - { - /* Client has died, but we cannot bail out right now. We - need to clean up after the work we did when going to - sleep. Setting the drawable pointer to 0 makes this - happen without any attempts to render or perform other - unnecessary activities. */ - c->pDraw = (DrawablePtr)0; - } - else - { - err = Success; - goto bail; - } + if (client->clientGone) { + fpe = c->pGC->font->fpe; + (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); + + if (ClientIsAsleep(client)) { + /* Client has died, but we cannot bail out right now. We + need to clean up after the work we did when going to + sleep. Setting the drawable pointer to 0 makes this + happen without any attempts to render or perform other + unnecessary activities. */ + c->pDraw = (DrawablePtr) 0; + } + else { + err = Success; + goto bail; + } } /* Make sure our drawable hasn't disappeared while we slept. */ - if (ClientIsAsleep(client) && c->pDraw) - { - DrawablePtr pDraw; - dixLookupDrawable(&pDraw, c->did, client, 0, DixWriteAccess); - if (c->pDraw != pDraw) { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client and avoid further - rendering while we clean up after ourself. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - c->pDraw = (DrawablePtr)0; - } + if (ClientIsAsleep(client) && c->pDraw) { + DrawablePtr pDraw; + + dixLookupDrawable(&pDraw, c->did, client, 0, DixWriteAccess); + if (c->pDraw != pDraw) { + /* Our drawable has disappeared. Treat like client died... ask + the FPE code to clean up after client and avoid further + rendering while we clean up after ourself. */ + fpe = c->pGC->font->fpe; + (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); + c->pDraw = (DrawablePtr) 0; + } } client_state = ClientIsAsleep(client) ? SLEEPING : NEVER_SLEPT; - while (c->endReq - c->pElt > TextEltHeader) - { - if (*c->pElt == FontChange) - { - Font fid; - if (c->endReq - c->pElt < FontShiftSize) - { - err = BadLength; - goto bail; - } - - oldpFont = pFont; - - fid = ((Font)*(c->pElt+4)) /* big-endian */ - | ((Font)*(c->pElt+3)) << 8 - | ((Font)*(c->pElt+2)) << 16 - | ((Font)*(c->pElt+1)) << 24; - err = dixLookupResourceByType((pointer *)&pFont, fid, RT_FONT, - client, DixUseAccess); - if (err != Success) - { - /* restore pFont for step 4 (described below) */ - pFont = oldpFont; - - /* If we're in START_SLEEP mode, the following step - shortens the request... in the unlikely event that - the fid somehow becomes valid before we come through - again to actually execute the polytext, which would - then mess up our refcounting scheme badly. */ - c->err = err; - c->endReq = c->pElt; - - goto bail; - } - - /* Step 3 (described below) on our new font */ - if (client_state == START_SLEEP) - pFont->refcnt++; - else - { - if (pFont != c->pGC->font && c->pDraw) - { - ChangeGCVal val; - val.ptr = pFont; - ChangeGC(NullClient, c->pGC, GCFont, &val); - ValidateGC(c->pDraw, c->pGC); - } - - /* Undo the refcnt++ we performed when going to sleep */ - if (client_state == SLEEPING) - (void)CloseFont(c->pGC->font, (Font)0); - } - c->pElt += FontShiftSize; - } - else /* print a string */ - { - unsigned char *pNextElt; - pNextElt = c->pElt + TextEltHeader + (*c->pElt) * itemSize; - if ( pNextElt > c->endReq) - { - err = BadLength; - goto bail; - } - if (client_state == START_SLEEP) - { - c->pElt = pNextElt; - continue; - } - if (c->pDraw) - { - lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, itemSize, - c->pElt + TextEltHeader); - } - else lgerr = Successful; - - if (lgerr == Suspended) - { - if (!ClientIsAsleep(client)) { - int len; - GC *pGC; - PTclosurePtr new_closure; - - /* We're putting the client to sleep. We need to do a few things - to ensure successful and atomic-appearing execution of the - remainder of the request. First, copy the remainder of the - request into a safe malloc'd area. Second, create a scratch GC - to use for the remainder of the request. Third, mark all fonts - referenced in the remainder of the request to prevent their - deallocation. Fourth, make the original GC look like the - request has completed... set its font to the final font value - from this request. These GC manipulations are for the unlikely - (but possible) event that some other client is using the GC. - Steps 3 and 4 are performed by running this procedure through - the remainder of the request in a special no-render mode - indicated by client_state = START_SLEEP. */ - - /* Step 1 */ - /* Allocate a malloc'd closure structure to replace - the local one we were passed */ - new_closure = malloc(sizeof(PTclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - - len = new_closure->endReq - new_closure->pElt; - new_closure->data = malloc(len); - if (!new_closure->data) - { - free(new_closure); - err = BadAlloc; - goto bail; - } - memmove(new_closure->data, new_closure->pElt, len); - new_closure->pElt = new_closure->data; - new_closure->endReq = new_closure->pElt + len; - - /* Step 2 */ - - pGC = GetScratchGC(new_closure->pGC->depth, new_closure->pGC->pScreen); - if (!pGC) - { - free(new_closure->data); - free(new_closure); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(new_closure->pGC, pGC, GCFunction | - GCPlaneMask | GCForeground | - GCBackground | GCFillStyle | - GCTile | GCStipple | - GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != - Success) - { - FreeScratchGC(pGC); - free(new_closure->data); - free(new_closure); - err = BadAlloc; - goto bail; - } - c = new_closure; - origGC = c->pGC; - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - ClientSleep(client, (ClientSleepProcPtr)doPolyText, c); - - /* Set up to perform steps 3 and 4 */ - client_state = START_SLEEP; - continue; /* on to steps 3 and 4 */ - } - else - goto xinerama_sleep; - return TRUE; - } - else if (lgerr != Successful) - { - err = FontToXError(lgerr); - goto bail; - } - if (c->pDraw) - { - c->xorg += *((INT8 *)(c->pElt + 1)); /* must be signed */ - if (c->reqType == X_PolyText8) - c->xorg = (* c->pGC->ops->PolyText8)(c->pDraw, c->pGC, c->xorg, c->yorg, - *c->pElt, (char *) (c->pElt + TextEltHeader)); - else - c->xorg = (* c->pGC->ops->PolyText16)(c->pDraw, c->pGC, c->xorg, c->yorg, - *c->pElt, (unsigned short *) (c->pElt + TextEltHeader)); - } - c->pElt = pNextElt; - } - } - -bail: - - if (client_state == START_SLEEP) - { - /* Step 4 */ - if (pFont != origGC->font) - { - ChangeGCVal val; - val.ptr = pFont; - ChangeGC(NullClient, origGC, GCFont, &val); - ValidateGC(c->pDraw, origGC); - } - - /* restore pElt pointer for execution of remainder of the request */ - c->pElt = c->data; - return TRUE; - } - - if (c->err != Success) err = c->err; + while (c->endReq - c->pElt > TextEltHeader) { + if (*c->pElt == FontChange) { + Font fid; + + if (c->endReq - c->pElt < FontShiftSize) { + err = BadLength; + goto bail; + } + + oldpFont = pFont; + + fid = ((Font) *(c->pElt + 4)) /* big-endian */ + |((Font) *(c->pElt + 3)) << 8 + | ((Font) *(c->pElt + 2)) << 16 | ((Font) *(c->pElt + 1)) << 24; + err = dixLookupResourceByType((pointer *) &pFont, fid, RT_FONT, + client, DixUseAccess); + if (err != Success) { + /* restore pFont for step 4 (described below) */ + pFont = oldpFont; + + /* If we're in START_SLEEP mode, the following step + shortens the request... in the unlikely event that + the fid somehow becomes valid before we come through + again to actually execute the polytext, which would + then mess up our refcounting scheme badly. */ + c->err = err; + c->endReq = c->pElt; + + goto bail; + } + + /* Step 3 (described below) on our new font */ + if (client_state == START_SLEEP) + pFont->refcnt++; + else { + if (pFont != c->pGC->font && c->pDraw) { + ChangeGCVal val; + + val.ptr = pFont; + ChangeGC(NullClient, c->pGC, GCFont, &val); + ValidateGC(c->pDraw, c->pGC); + } + + /* Undo the refcnt++ we performed when going to sleep */ + if (client_state == SLEEPING) + (void) CloseFont(c->pGC->font, (Font) 0); + } + c->pElt += FontShiftSize; + } + else { /* print a string */ + + unsigned char *pNextElt; + + pNextElt = c->pElt + TextEltHeader + (*c->pElt) * itemSize; + if (pNextElt > c->endReq) { + err = BadLength; + goto bail; + } + if (client_state == START_SLEEP) { + c->pElt = pNextElt; + continue; + } + if (c->pDraw) { + lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, itemSize, + c->pElt + TextEltHeader); + } + else + lgerr = Successful; + + if (lgerr == Suspended) { + if (!ClientIsAsleep(client)) { + int len; + GC *pGC; + PTclosurePtr new_closure; + + /* We're putting the client to sleep. We need to do a few things + to ensure successful and atomic-appearing execution of the + remainder of the request. First, copy the remainder of the + request into a safe malloc'd area. Second, create a scratch GC + to use for the remainder of the request. Third, mark all fonts + referenced in the remainder of the request to prevent their + deallocation. Fourth, make the original GC look like the + request has completed... set its font to the final font value + from this request. These GC manipulations are for the unlikely + (but possible) event that some other client is using the GC. + Steps 3 and 4 are performed by running this procedure through + the remainder of the request in a special no-render mode + indicated by client_state = START_SLEEP. */ + + /* Step 1 */ + /* Allocate a malloc'd closure structure to replace + the local one we were passed */ + new_closure = malloc(sizeof(PTclosureRec)); + if (!new_closure) { + err = BadAlloc; + goto bail; + } + *new_closure = *c; + + len = new_closure->endReq - new_closure->pElt; + new_closure->data = malloc(len); + if (!new_closure->data) { + free(new_closure); + err = BadAlloc; + goto bail; + } + memmove(new_closure->data, new_closure->pElt, len); + new_closure->pElt = new_closure->data; + new_closure->endReq = new_closure->pElt + len; + + /* Step 2 */ + + pGC = + GetScratchGC(new_closure->pGC->depth, + new_closure->pGC->pScreen); + if (!pGC) { + free(new_closure->data); + free(new_closure); + err = BadAlloc; + goto bail; + } + if ((err = CopyGC(new_closure->pGC, pGC, GCFunction | + GCPlaneMask | GCForeground | + GCBackground | GCFillStyle | + GCTile | GCStipple | + GCTileStipXOrigin | + GCTileStipYOrigin | GCFont | + GCSubwindowMode | GCClipXOrigin | + GCClipYOrigin | GCClipMask)) != Success) { + FreeScratchGC(pGC); + free(new_closure->data); + free(new_closure); + err = BadAlloc; + goto bail; + } + c = new_closure; + origGC = c->pGC; + c->pGC = pGC; + ValidateGC(c->pDraw, c->pGC); + + ClientSleep(client, (ClientSleepProcPtr) doPolyText, c); + + /* Set up to perform steps 3 and 4 */ + client_state = START_SLEEP; + continue; /* on to steps 3 and 4 */ + } + else + goto xinerama_sleep; + return TRUE; + } + else if (lgerr != Successful) { + err = FontToXError(lgerr); + goto bail; + } + if (c->pDraw) { + c->xorg += *((INT8 *) (c->pElt + 1)); /* must be signed */ + if (c->reqType == X_PolyText8) + c->xorg = + (*c->pGC->ops->PolyText8) (c->pDraw, c->pGC, c->xorg, + c->yorg, *c->pElt, + (char *) (c->pElt + + TextEltHeader)); + else + c->xorg = + (*c->pGC->ops->PolyText16) (c->pDraw, c->pGC, c->xorg, + c->yorg, *c->pElt, + (unsigned short *) (c-> + pElt + + TextEltHeader)); + } + c->pElt = pNextElt; + } + } + + bail: + + if (client_state == START_SLEEP) { + /* Step 4 */ + if (pFont != origGC->font) { + ChangeGCVal val; + + val.ptr = pFont; + ChangeGC(NullClient, origGC, GCFont, &val); + ValidateGC(c->pDraw, origGC); + } + + /* restore pElt pointer for execution of remainder of the request */ + c->pElt = c->data; + return TRUE; + } + + if (c->err != Success) + err = c->err; if (err != Success && c->client != serverClient) { #ifdef PANORAMIX if (noPanoramiXExtension || !c->pGC->pScreen->myNum) #endif - SendErrorToClient(c->client, c->reqType, 0, 0, err); + SendErrorToClient(c->client, c->reqType, 0, 0, err); } - if (ClientIsAsleep(client)) - { - ClientWakeup(c->client); -xinerama_sleep: - ChangeGC(NullClient, c->pGC, clearGCmask, clearGC); + if (ClientIsAsleep(client)) { + ClientWakeup(c->client); + xinerama_sleep: + ChangeGC(NullClient, c->pGC, clearGCmask, clearGC); - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; + /* Unreference the font from the scratch GC */ + CloseFont(c->pGC->font, (Font) 0); + c->pGC->font = NullFont; - FreeScratchGC(c->pGC); - free(c->data); - free(c); + FreeScratchGC(c->pGC); + free(c->data); + free(c); } return TRUE; } int -PolyText(ClientPtr client, DrawablePtr pDraw, GC *pGC, unsigned char *pElt, +PolyText(ClientPtr client, DrawablePtr pDraw, GC * pGC, unsigned char *pElt, unsigned char *endReq, int xorg, int yorg, int reqType, XID did) { PTclosureRec local_closure; @@ -1438,141 +1376,131 @@ PolyText(ClientPtr client, DrawablePtr pDraw, GC *pGC, unsigned char *pElt, return Success; } - #undef TextEltHeader #undef FontShiftSize int doImageText(ClientPtr client, ITclosurePtr c) { - int err = Success, lgerr; /* err is in X error, not font error, space */ + int err = Success, lgerr; /* err is in X error, not font error, space */ FontPathElementPtr fpe; int itemSize = c->reqType == X_ImageText8 ? 1 : 2; - if (client->clientGone) - { - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; + if (client->clientGone) { + fpe = c->pGC->font->fpe; + (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); + err = Success; + goto bail; } /* Make sure our drawable hasn't disappeared while we slept. */ - if (ClientIsAsleep(client) && c->pDraw) - { - DrawablePtr pDraw; - dixLookupDrawable(&pDraw, c->did, client, 0, DixWriteAccess); - if (c->pDraw != pDraw) { - /* Our drawable has disappeared. Treat like client died... ask - the FPE code to clean up after client. */ - fpe = c->pGC->font->fpe; - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - err = Success; - goto bail; - } + if (ClientIsAsleep(client) && c->pDraw) { + DrawablePtr pDraw; + + dixLookupDrawable(&pDraw, c->did, client, 0, DixWriteAccess); + if (c->pDraw != pDraw) { + /* Our drawable has disappeared. Treat like client died... ask + the FPE code to clean up after client. */ + fpe = c->pGC->font->fpe; + (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); + err = Success; + goto bail; + } } lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, itemSize, c->data); - if (lgerr == Suspended) - { + if (lgerr == Suspended) { if (!ClientIsAsleep(client)) { - GC *pGC; - unsigned char *data; - ITclosurePtr new_closure; - - /* We're putting the client to sleep. We need to - save some state. Similar problem to that handled - in doPolyText, but much simpler because the - request structure is much simpler. */ - - new_closure = malloc(sizeof(ITclosureRec)); - if (!new_closure) - { - err = BadAlloc; - goto bail; - } - *new_closure = *c; - c = new_closure; - - data = malloc(c->nChars * itemSize); - if (!data) - { - free(c); - err = BadAlloc; - goto bail; - } - memmove(data, c->data, c->nChars * itemSize); - c->data = data; - - pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); - if (!pGC) - { - free(c->data); - free(c); - err = BadAlloc; - goto bail; - } - if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask | - GCForeground | GCBackground | GCFillStyle | - GCTile | GCStipple | GCTileStipXOrigin | - GCTileStipYOrigin | GCFont | - GCSubwindowMode | GCClipXOrigin | - GCClipYOrigin | GCClipMask)) != Success) - { - FreeScratchGC(pGC); - free(c->data); - free(c); - err = BadAlloc; - goto bail; - } - c->pGC = pGC; - ValidateGC(c->pDraw, c->pGC); - - ClientSleep(client, (ClientSleepProcPtr)doImageText, c); + GC *pGC; + unsigned char *data; + ITclosurePtr new_closure; + + /* We're putting the client to sleep. We need to + save some state. Similar problem to that handled + in doPolyText, but much simpler because the + request structure is much simpler. */ + + new_closure = malloc(sizeof(ITclosureRec)); + if (!new_closure) { + err = BadAlloc; + goto bail; + } + *new_closure = *c; + c = new_closure; + + data = malloc(c->nChars * itemSize); + if (!data) { + free(c); + err = BadAlloc; + goto bail; + } + memmove(data, c->data, c->nChars * itemSize); + c->data = data; + + pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); + if (!pGC) { + free(c->data); + free(c); + err = BadAlloc; + goto bail; + } + if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask | + GCForeground | GCBackground | GCFillStyle | + GCTile | GCStipple | GCTileStipXOrigin | + GCTileStipYOrigin | GCFont | + GCSubwindowMode | GCClipXOrigin | + GCClipYOrigin | GCClipMask)) != Success) { + FreeScratchGC(pGC); + free(c->data); + free(c); + err = BadAlloc; + goto bail; + } + c->pGC = pGC; + ValidateGC(c->pDraw, c->pGC); + + ClientSleep(client, (ClientSleepProcPtr) doImageText, c); } - else - goto xinerama_sleep; + else + goto xinerama_sleep; return TRUE; } - else if (lgerr != Successful) - { + else if (lgerr != Successful) { err = FontToXError(lgerr); goto bail; } - if (c->pDraw) - { - if (c->reqType == X_ImageText8) - (* c->pGC->ops->ImageText8)(c->pDraw, c->pGC, c->xorg, c->yorg, - c->nChars, (char *) c->data); - else - (* c->pGC->ops->ImageText16)(c->pDraw, c->pGC, c->xorg, c->yorg, - c->nChars, (unsigned short *) c->data); + if (c->pDraw) { + if (c->reqType == X_ImageText8) + (*c->pGC->ops->ImageText8) (c->pDraw, c->pGC, c->xorg, c->yorg, + c->nChars, (char *) c->data); + else + (*c->pGC->ops->ImageText16) (c->pDraw, c->pGC, c->xorg, c->yorg, + c->nChars, (unsigned short *) c->data); } -bail: + bail: if (err != Success && c->client != serverClient) { - SendErrorToClient(c->client, c->reqType, 0, 0, err); + SendErrorToClient(c->client, c->reqType, 0, 0, err); } - if (ClientIsAsleep(client)) - { - ClientWakeup(c->client); -xinerama_sleep: - ChangeGC(NullClient, c->pGC, clearGCmask, clearGC); + if (ClientIsAsleep(client)) { + ClientWakeup(c->client); + xinerama_sleep: + ChangeGC(NullClient, c->pGC, clearGCmask, clearGC); - /* Unreference the font from the scratch GC */ - CloseFont(c->pGC->font, (Font)0); - c->pGC->font = NullFont; + /* Unreference the font from the scratch GC */ + CloseFont(c->pGC->font, (Font) 0); + c->pGC->font = NullFont; - FreeScratchGC(c->pGC); - free(c->data); - free(c); + FreeScratchGC(c->pGC); + free(c->data); + free(c); } return TRUE; } int -ImageText(ClientPtr client, DrawablePtr pDraw, GC *pGC, int nChars, +ImageText(ClientPtr client, DrawablePtr pDraw, GC * pGC, int nChars, unsigned char *data, int xorg, int yorg, int reqType, XID did) { ITclosureRec local_closure; @@ -1591,168 +1519,157 @@ ImageText(ClientPtr client, DrawablePtr pDraw, GC *pGC, int nChars, return Success; } - /* does the necessary magic to figure out the fpe type */ static int DetermineFPEType(char *pathname) { - int i; + int i; for (i = 0; i < num_fpe_types; i++) { - if ((*fpe_functions[i].name_check) (pathname)) - return i; + if ((*fpe_functions[i].name_check) (pathname)) + return i; } return -1; } - static void -FreeFontPath(FontPathElementPtr *list, int n, Bool force) +FreeFontPath(FontPathElementPtr * list, int n, Bool force) { - int i; + int i; for (i = 0; i < n; i++) { - if (force) { - /* Sanity check that all refcounts will be 0 by the time - we get to the end of the list. */ - int found = 1; /* the first reference is us */ - int j; - for (j = i+1; j < n; j++) { - if (list[j] == list[i]) - found++; - } - if (list[i]->refcount != found) { - list[i]->refcount = found; /* ensure it will get freed */ - } - } - FreeFPE(list[i]); + if (force) { + /* Sanity check that all refcounts will be 0 by the time + we get to the end of the list. */ + int found = 1; /* the first reference is us */ + int j; + + for (j = i + 1; j < n; j++) { + if (list[j] == list[i]) + found++; + } + if (list[i]->refcount != found) { + list[i]->refcount = found; /* ensure it will get freed */ + } + } + FreeFPE(list[i]); } free(list); } static FontPathElementPtr -find_existing_fpe(FontPathElementPtr *list, int num, unsigned char *name, int len) +find_existing_fpe(FontPathElementPtr * list, int num, unsigned char *name, + int len) { FontPathElementPtr fpe; - int i; + int i; for (i = 0; i < num; i++) { - fpe = list[i]; - if (fpe->name_length == len && memcmp(name, fpe->name, len) == 0) - return fpe; + fpe = list[i]; + if (fpe->name_length == len && memcmp(name, fpe->name, len) == 0) + return fpe; } return (FontPathElementPtr) 0; } - static int SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) { - int i, err = 0; - int valid_paths = 0; + int i, err = 0; + int valid_paths = 0; unsigned int len; unsigned char *cp = paths; FontPathElementPtr fpe = NULL, *fplist; fplist = malloc(sizeof(FontPathElementPtr) * npaths); if (!fplist) { - *bad = 0; - return BadAlloc; + *bad = 0; + return BadAlloc; } for (i = 0; i < num_fpe_types; i++) { - if (fpe_functions[i].set_path_hook) - (*fpe_functions[i].set_path_hook) (); - } - for (i = 0; i < npaths; i++) - { - len = (unsigned int) (*cp++); - - if (len == 0) - { - if (persist) - ErrorF("[dix] Removing empty element from the valid list of fontpaths\n"); - err = BadValue; - } - else - { - /* if it's already in our active list, just reset it */ - /* - * note that this can miss FPE's in limbo -- may be worth catching - * them, though it'd muck up refcounting - */ - fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len); - if (fpe) - { - err = (*fpe_functions[fpe->type].reset_fpe) (fpe); - if (err == Successful) - { - UseFPE(fpe);/* since it'll be decref'd later when freed - * from the old list */ - } - else - fpe = 0; - } - /* if error or can't do it, act like it's a new one */ - if (!fpe) - { - fpe = malloc(sizeof(FontPathElementRec)); - if (!fpe) - { - err = BadAlloc; - goto bail; - } - fpe->name = malloc(len + 1); - if (!fpe->name) - { - free(fpe); - err = BadAlloc; - goto bail; - } - fpe->refcount = 1; - - strncpy(fpe->name, (char *) cp, (int) len); - fpe->name[len] = '\0'; - fpe->name_length = len; - fpe->type = DetermineFPEType(fpe->name); - if (fpe->type == -1) - err = BadValue; - else - err = (*fpe_functions[fpe->type].init_fpe) (fpe); - if (err != Successful) - { - if (persist) - { - ErrorF("[dix] Could not init font path element %s, removing from list!\n", - fpe->name); - } - free(fpe->name); - free(fpe); - } - } - } - if (err != Successful) - { - if (!persist) - goto bail; - } - else - { - fplist[valid_paths++] = fpe; - } - cp += len; + if (fpe_functions[i].set_path_hook) + (*fpe_functions[i].set_path_hook) (); + } + for (i = 0; i < npaths; i++) { + len = (unsigned int) (*cp++); + + if (len == 0) { + if (persist) + ErrorF + ("[dix] Removing empty element from the valid list of fontpaths\n"); + err = BadValue; + } + else { + /* if it's already in our active list, just reset it */ + /* + * note that this can miss FPE's in limbo -- may be worth catching + * them, though it'd muck up refcounting + */ + fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len); + if (fpe) { + err = (*fpe_functions[fpe->type].reset_fpe) (fpe); + if (err == Successful) { + UseFPE(fpe); /* since it'll be decref'd later when freed + * from the old list */ + } + else + fpe = 0; + } + /* if error or can't do it, act like it's a new one */ + if (!fpe) { + fpe = malloc(sizeof(FontPathElementRec)); + if (!fpe) { + err = BadAlloc; + goto bail; + } + fpe->name = malloc(len + 1); + if (!fpe->name) { + free(fpe); + err = BadAlloc; + goto bail; + } + fpe->refcount = 1; + + strncpy(fpe->name, (char *) cp, (int) len); + fpe->name[len] = '\0'; + fpe->name_length = len; + fpe->type = DetermineFPEType(fpe->name); + if (fpe->type == -1) + err = BadValue; + else + err = (*fpe_functions[fpe->type].init_fpe) (fpe); + if (err != Successful) { + if (persist) { + ErrorF + ("[dix] Could not init font path element %s, removing from list!\n", + fpe->name); + } + free(fpe->name); + free(fpe); + } + } + } + if (err != Successful) { + if (!persist) + goto bail; + } + else { + fplist[valid_paths++] = fpe; + } + cp += len; } FreeFontPath(font_path_elements, num_fpes, FALSE); font_path_elements = fplist; if (patternCache) - EmptyFontPatternCache(patternCache); + EmptyFontPatternCache(patternCache); num_fpes = valid_paths; return Success; -bail: + bail: *bad = i; while (--valid_paths >= 0) - FreeFPE(fplist[valid_paths]); + FreeFPE(fplist[valid_paths]); free(fplist); return FontToXError(err); } @@ -1761,16 +1678,19 @@ int SetFontPath(ClientPtr client, int npaths, unsigned char *paths) { int err = XaceHook(XACE_SERVER_ACCESS, client, DixManageAccess); + if (err != Success) - return err; + return err; if (npaths == 0) { - if (SetDefaultFontPath(defaultFontPath) != Success) - return BadValue; - } else { - int bad; - err = SetFontPathElements(npaths, paths, &bad, FALSE); - client->errorValue = bad; + if (SetDefaultFontPath(defaultFontPath) != Success) + return BadValue; + } + else { + int bad; + + err = SetFontPathElements(npaths, paths, &bad, FALSE); + client->errorValue = bad; } return err; } @@ -1778,36 +1698,28 @@ SetFontPath(ClientPtr client, int npaths, unsigned char *paths) int SetDefaultFontPath(char *path) { - char *temp_path, - *start, - *end; - unsigned char *cp, - *pp, - *nump, - *newpath; - int num = 1, - len, - err, - size = 0, - bad; + char *temp_path, *start, *end; + unsigned char *cp, *pp, *nump, *newpath; + int num = 1, len, err, size = 0, bad; /* ensure temp_path contains "built-ins" */ start = path; while (1) { - start = strstr(start, "built-ins"); - if (start == NULL) - break; - end = start + strlen("built-ins"); - if ((start == path || start[-1] == ',') && (!*end || *end == ',')) - break; - start = end; + start = strstr(start, "built-ins"); + if (start == NULL) + break; + end = start + strlen("built-ins"); + if ((start == path || start[-1] == ',') && (!*end || *end == ',')) + break; + start = end; } if (!start) { - if (asprintf(&temp_path, "%s%sbuilt-ins", path, *path ? "," : "") - == -1) - temp_path = NULL; - } else { - temp_path = strdup(path); + if (asprintf(&temp_path, "%s%sbuilt-ins", path, *path ? "," : "") + == -1) + temp_path = NULL; + } + else { + temp_path = strdup(path); } if (!temp_path) return BadAlloc; @@ -1816,22 +1728,23 @@ SetDefaultFontPath(char *path) len = strlen(temp_path) + 1; nump = cp = newpath = malloc(len); if (!newpath) { - free(temp_path); - return BadAlloc; + free(temp_path); + return BadAlloc; } pp = (unsigned char *) temp_path; cp++; while (*pp) { - if (*pp == ',') { - *nump = (unsigned char) size; - nump = cp++; - pp++; - num++; - size = 0; - } else { - *cp++ = *pp++; - size++; - } + if (*pp == ',') { + *nump = (unsigned char) size; + nump = cp++; + pp++; + num++; + size = 0; + } + else { + *cp++ = *pp++; + size++; + } } *nump = (unsigned char) size; @@ -1846,32 +1759,32 @@ SetDefaultFontPath(char *path) int GetFontPath(ClientPtr client, int *count, int *length, unsigned char **result) { - int i; - unsigned char *c; - int len; - FontPathElementPtr fpe; + int i; + unsigned char *c; + int len; + FontPathElementPtr fpe; i = XaceHook(XACE_SERVER_ACCESS, client, DixGetAttrAccess); if (i != Success) - return i; + return i; len = 0; for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - len += fpe->name_length + 1; + fpe = font_path_elements[i]; + len += fpe->name_length + 1; } font_path_string = (unsigned char *) realloc(font_path_string, len); if (!font_path_string) - return BadAlloc; + return BadAlloc; c = font_path_string; *length = 0; for (i = 0; i < num_fpes; i++) { - fpe = font_path_elements[i]; - *c = fpe->name_length; - *length += *c++; - memmove(c, fpe->name, fpe->name_length); - c += fpe->name_length; + fpe = font_path_elements[i]; + *c = fpe->name_length; + *length += *c++; + memmove(c, fpe->name, fpe->name_length); + c += fpe->name_length; } *count = num_fpes; *result = font_path_string; @@ -1881,19 +1794,18 @@ GetFontPath(ClientPtr client, int *count, int *length, unsigned char **result) void DeleteClientFontStuff(ClientPtr client) { - int i; - FontPathElementPtr fpe; + int i; + FontPathElementPtr fpe; - for (i = 0; i < num_fpes; i++) - { - fpe = font_path_elements[i]; - if (fpe_functions[fpe->type].client_died) - (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); + for (i = 0; i < num_fpes; i++) { + fpe = font_path_elements[i]; + if (fpe_functions[fpe->type].client_died) + (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); } } void -InitFonts (void) +InitFonts(void) { patternCache = MakeFontPatternCache(); @@ -1901,17 +1813,16 @@ InitFonts (void) } int -GetDefaultPointSize (void) +GetDefaultPointSize(void) { return 120; } - FontResolutionPtr -GetClientResolutions (int *num) +GetClientResolutions(int *num) { static struct _FontResolution res; - ScreenPtr pScreen; + ScreenPtr pScreen; pScreen = screenInfo.screens[0]; res.x_resolution = (pScreen->width * 25.4) / pScreen->mmWidth; @@ -1920,14 +1831,14 @@ GetClientResolutions (int *num) so that we can match them from scalable fonts */ if (res.x_resolution < 88) - res.x_resolution = 75; + res.x_resolution = 75; else - res.x_resolution = 100; + res.x_resolution = 100; res.y_resolution = (pScreen->height * 25.4) / pScreen->mmHeight; if (res.y_resolution < 88) - res.y_resolution = 75; + res.y_resolution = 75; else - res.y_resolution = 100; + res.y_resolution = 100; res.point_size = 120; *num = 1; return &res; @@ -1940,29 +1851,28 @@ GetClientResolutions (int *num) */ int -RegisterFPEFunctions(NameCheckFunc name_func, - InitFpeFunc init_func, - FreeFpeFunc free_func, - ResetFpeFunc reset_func, - OpenFontFunc open_func, - CloseFontFunc close_func, - ListFontsFunc list_func, - StartLfwiFunc start_lfwi_func, - NextLfwiFunc next_lfwi_func, - WakeupFpeFunc wakeup_func, - ClientDiedFunc client_died, - LoadGlyphsFunc load_glyphs, - StartLaFunc start_list_alias_func, - NextLaFunc next_list_alias_func, - SetPathFunc set_path_func) +RegisterFPEFunctions(NameCheckFunc name_func, + InitFpeFunc init_func, + FreeFpeFunc free_func, + ResetFpeFunc reset_func, + OpenFontFunc open_func, + CloseFontFunc close_func, + ListFontsFunc list_func, + StartLfwiFunc start_lfwi_func, + NextLfwiFunc next_lfwi_func, + WakeupFpeFunc wakeup_func, + ClientDiedFunc client_died, + LoadGlyphsFunc load_glyphs, + StartLaFunc start_list_alias_func, + NextLaFunc next_list_alias_func, SetPathFunc set_path_func) { FPEFunctions *new; /* grow the list */ new = (FPEFunctions *) realloc(fpe_functions, - (num_fpe_types + 1) * sizeof(FPEFunctions)); + (num_fpe_types + 1) * sizeof(FPEFunctions)); if (!new) - return -1; + return -1; fpe_functions = new; fpe_functions[num_fpe_types].name_check = name_func; @@ -1970,19 +1880,16 @@ RegisterFPEFunctions(NameCheckFunc name_func, fpe_functions[num_fpe_types].close_font = close_func; fpe_functions[num_fpe_types].wakeup_fpe = wakeup_func; fpe_functions[num_fpe_types].list_fonts = list_func; - fpe_functions[num_fpe_types].start_list_fonts_with_info = - start_lfwi_func; - fpe_functions[num_fpe_types].list_next_font_with_info = - next_lfwi_func; + fpe_functions[num_fpe_types].start_list_fonts_with_info = start_lfwi_func; + fpe_functions[num_fpe_types].list_next_font_with_info = next_lfwi_func; fpe_functions[num_fpe_types].init_fpe = init_func; fpe_functions[num_fpe_types].free_fpe = free_func; fpe_functions[num_fpe_types].reset_fpe = reset_func; fpe_functions[num_fpe_types].client_died = client_died; fpe_functions[num_fpe_types].load_glyphs = load_glyphs; fpe_functions[num_fpe_types].start_list_fonts_and_aliases = - start_list_alias_func; - fpe_functions[num_fpe_types].list_next_font_or_alias = - next_list_alias_func; + start_list_alias_func; + fpe_functions[num_fpe_types].list_next_font_or_alias = next_list_alias_func; fpe_functions[num_fpe_types].set_path_hook = set_path_func; return num_fpe_types++; @@ -1992,8 +1899,8 @@ void FreeFonts(void) { if (patternCache) { - FreeFontPatternCache(patternCache); - patternCache = 0; + FreeFontPatternCache(patternCache); + patternCache = 0; } FreeFontPath(font_path_elements, num_fpes, TRUE); font_path_elements = 0; @@ -2009,8 +1916,9 @@ FontPtr find_old_font(XID id) { pointer pFont; + dixLookupResourceByType(&pFont, id, RT_NONE, serverClient, DixReadAccess); - return (FontPtr)pFont; + return (FontPtr) pFont; } Font @@ -2037,7 +1945,7 @@ client_auth_generation(ClientPtr client) return 0; } -static int fs_handlers_installed = 0; +static int fs_handlers_installed = 0; static unsigned int last_server_gen; int @@ -2045,28 +1953,29 @@ init_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler) { /* if server has reset, make sure the b&w handlers are reinstalled */ if (last_server_gen < serverGeneration) { - last_server_gen = serverGeneration; - fs_handlers_installed = 0; + last_server_gen = serverGeneration; + fs_handlers_installed = 0; } if (fs_handlers_installed == 0) { - if (!RegisterBlockAndWakeupHandlers(block_handler, - FontWakeup, (pointer) 0)) - return AllocError; - fs_handlers_installed++; + if (!RegisterBlockAndWakeupHandlers(block_handler, + FontWakeup, (pointer) 0)) + return AllocError; + fs_handlers_installed++; } QueueFontWakeup(fpe); return Successful; } void -remove_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler, Bool all) +remove_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler, + Bool all) { if (all) { - /* remove the handlers if no one else is using them */ - if (--fs_handlers_installed == 0) { - RemoveBlockAndWakeupHandlers(block_handler, FontWakeup, - (pointer) 0); - } + /* remove the handlers if no one else is using them */ + if (--fs_handlers_installed == 0) { + RemoveBlockAndWakeupHandlers(block_handler, FontWakeup, + (pointer) 0); + } } RemoveFontWakeup(fpe); } diff --git a/xorg-server/dix/dixutils.c b/xorg-server/dix/dixutils.c index da26dc144..9eb54893a 100644 --- a/xorg-server/dix/dixutils.c +++ b/xorg-server/dix/dixutils.c @@ -22,7 +22,6 @@ 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 @@ -81,7 +80,6 @@ Author: Adobe Systems Incorporated */ - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #endif @@ -107,13 +105,13 @@ int CompareTimeStamps(TimeStamp a, TimeStamp b) { if (a.months < b.months) - return EARLIER; + return EARLIER; if (a.months > b.months) - return LATER; + return LATER; if (a.milliseconds < b.milliseconds) - return EARLIER; + return EARLIER; if (a.milliseconds > b.milliseconds) - return LATER; + return LATER; return SAMETIME; } @@ -126,19 +124,18 @@ TimeStamp ClientTimeToServerTime(CARD32 c) { TimeStamp ts; + if (c == CurrentTime) - return currentTime; + return currentTime; ts.months = currentTime.months; ts.milliseconds = c; - if (c > currentTime.milliseconds) - { - if (((unsigned long) c - currentTime.milliseconds) > HALFMONTH) - ts.months -= 1; + if (c > currentTime.milliseconds) { + if (((unsigned long) c - currentTime.milliseconds) > HALFMONTH) + ts.months -= 1; } - else if (c < currentTime.milliseconds) - { - if (((unsigned long)currentTime.milliseconds - c) > HALFMONTH) - ts.months += 1; + else if (c < currentTime.milliseconds) { + if (((unsigned long) currentTime.milliseconds - c) > HALFMONTH) + ts.months += 1; } return ts; } @@ -151,36 +148,35 @@ ClientTimeToServerTime(CARD32 c) */ static unsigned char -ISOLatin1ToLower (unsigned char source) +ISOLatin1ToLower(unsigned char source) { - unsigned char dest; + unsigned char dest; + if ((source >= XK_A) && (source <= XK_Z)) - dest = source + (XK_a - XK_A); + dest = source + (XK_a - XK_A); else if ((source >= XK_Agrave) && (source <= XK_Odiaeresis)) - dest = source + (XK_agrave - XK_Agrave); + dest = source + (XK_agrave - XK_Agrave); else if ((source >= XK_Ooblique) && (source <= XK_Thorn)) - dest = source + (XK_oslash - XK_Ooblique); + dest = source + (XK_oslash - XK_Ooblique); else - dest = source; + dest = source; return dest; } - int 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; + 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; } return (int) c1 - (int) c2; } @@ -196,24 +192,25 @@ CompareISOLatin1Lowered(const unsigned char *s1, int s1len, */ int dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client, - Mask type, Mask access) + Mask type, Mask access) { DrawablePtr pTmp; int rc; *pDraw = NULL; - rc = dixLookupResourceByClass((pointer *)&pTmp, id, RC_DRAWABLE, client, access); + rc = dixLookupResourceByClass((pointer *) &pTmp, id, RC_DRAWABLE, client, + access); if (rc != Success) - client->errorValue = id; + client->errorValue = id; if (rc == BadValue) - return BadDrawable; + return BadDrawable; if (rc != Success) - return rc; + return rc; if (!((1 << pTmp->type) & (type ? type : M_DRAWABLE))) - return BadMatch; + return BadMatch; *pDraw = pTmp; return Success; @@ -223,22 +220,23 @@ int dixLookupWindow(WindowPtr *pWin, XID id, ClientPtr client, Mask access) { int rc; - rc = dixLookupDrawable((DrawablePtr*)pWin, id, client, M_WINDOW, access); + + 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; + rc = BadWindow; /* Similarly, users of dixLookupWindow don't want BadDrawable. */ if (rc == BadDrawable) - rc = BadWindow; + rc = BadWindow; return rc; } int dixLookupGC(GCPtr *pGC, XID id, ClientPtr client, Mask access) { - return dixLookupResourceByType((pointer *)pGC, id, RT_GC, client, access); + return dixLookupResourceByType((pointer *) pGC, id, RT_GC, client, access); } int @@ -246,15 +244,17 @@ dixLookupFontable(FontPtr *pFont, XID id, ClientPtr client, Mask access) { int rc; GC *pGC; - client->errorValue = id; /* EITHER font or gc */ - rc = dixLookupResourceByType((pointer *) pFont, id, RT_FONT, client, access); + + client->errorValue = id; /* EITHER font or gc */ + rc = dixLookupResourceByType((pointer *) pFont, id, RT_FONT, client, + access); if (rc != BadFont) - return rc; + return rc; rc = dixLookupResourceByType((pointer *) &pGC, id, RT_GC, client, access); if (rc == BadGC) - return BadFont; + return BadFont; if (rc == Success) - *pFont = pGC->font; + *pFont = pGC->font; return rc; } @@ -265,20 +265,20 @@ dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access) int rc = BadValue, clientIndex = CLIENT_ID(rid); if (!clientIndex || !clients[clientIndex] || (rid & SERVER_BIT)) - goto bad; + goto bad; rc = dixLookupResourceByClass(&pRes, rid, RC_ANY, client, DixGetAttrAccess); if (rc != Success) - goto bad; + goto bad; rc = XaceHook(XACE_CLIENT_ACCESS, client, clients[clientIndex], access); if (rc != Success) - goto bad; + goto bad; *pClient = clients[clientIndex]; return Success; -bad: - if(client) + bad: + if (client) client->errorValue = rid; *pClient = NULL; return rc; @@ -294,48 +294,43 @@ AlterSaveSetForClient(ClientPtr client, WindowPtr pWin, unsigned mode, numnow = client->numSaved; j = 0; - if (numnow) - { - pTmp = client->saveSet; - while ((j < numnow) && (SaveSetWindow(pTmp[j]) != (pointer)pWin)) - j++; + if (numnow) { + pTmp = client->saveSet; + while ((j < numnow) && (SaveSetWindow(pTmp[j]) != (pointer) pWin)) + j++; } - 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; + 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; } - 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 - { + 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 { free(client->saveSet); - client->saveSet = (SaveSetElt *)NULL; - } - client->numSaved = numnow; - return Success; + client->saveSet = (SaveSetElt *) NULL; + } + client->numSaved = numnow; + return Success; } return Success; } @@ -345,12 +340,12 @@ DeleteWindowFromAnySaveSet(WindowPtr pWin) { int i; ClientPtr client; - - for (i = 0; i< currentMaxClients; i++) - { - client = clients[i]; - if (client && client->numSaved) - (void)AlterSaveSetForClient(client, pWin, SetModeDelete, FALSE, TRUE); + + for (i = 0; i < currentMaxClients; i++) { + client = clients[i]; + if (client && client->numSaved) + (void) AlterSaveSetForClient(client, pWin, SetModeDelete, FALSE, + TRUE); } } @@ -368,14 +363,14 @@ typedef struct _BlockHandler { BlockHandlerProcPtr BlockHandler; WakeupHandlerProcPtr WakeupHandler; pointer blockData; - Bool deleted; + Bool deleted; } BlockHandlerRec, *BlockHandlerPtr; -static BlockHandlerPtr handlers; -static int numHandlers; -static int sizeHandlers; -static Bool inHandler; -static Bool handlerDeleted; +static BlockHandlerPtr handlers; +static int numHandlers; +static int sizeHandlers; +static Bool inHandler; +static Bool handlerDeleted; /** * @@ -386,28 +381,26 @@ void BlockHandler(pointer pTimeout, pointer pReadmask) { int i, j; - + ++inHandler; for (i = 0; i < screenInfo.numScreens; i++) - (* screenInfo.screens[i]->BlockHandler)(i, - screenInfo.screens[i]->blockData, - pTimeout, pReadmask); + (*screenInfo.screens[i]->BlockHandler) (i, + screenInfo.screens[i]-> + blockData, pTimeout, pReadmask); for (i = 0; i < numHandlers; i++) - if (!handlers[i].deleted) - (*handlers[i].BlockHandler) (handlers[i].blockData, - pTimeout, pReadmask); - 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; + if (!handlers[i].deleted) + (*handlers[i].BlockHandler) (handlers[i].blockData, + pTimeout, pReadmask); + 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; } --inHandler; } @@ -424,25 +417,23 @@ WakeupHandler(int result, pointer pReadmask) ++inHandler; for (i = numHandlers - 1; i >= 0; i--) - if (!handlers[i].deleted) - (*handlers[i].WakeupHandler) (handlers[i].blockData, - result, pReadmask); + if (!handlers[i].deleted) + (*handlers[i].WakeupHandler) (handlers[i].blockData, + result, pReadmask); for (i = 0; i < screenInfo.numScreens; i++) - (* screenInfo.screens[i]->WakeupHandler)(i, - screenInfo.screens[i]->wakeupData, - result, pReadmask); - 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; + (*screenInfo.screens[i]->WakeupHandler) (i, + screenInfo.screens[i]-> + wakeupData, result, pReadmask); + 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; } --inHandler; } @@ -452,20 +443,19 @@ WakeupHandler(int result, pointer pReadmask) * get called until next time */ Bool -RegisterBlockAndWakeupHandlers (BlockHandlerProcPtr blockHandler, - WakeupHandlerProcPtr wakeupHandler, - pointer blockData) +RegisterBlockAndWakeupHandlers(BlockHandlerProcPtr blockHandler, + WakeupHandlerProcPtr wakeupHandler, + pointer blockData) { BlockHandlerPtr new; - if (numHandlers >= sizeHandlers) - { + if (numHandlers >= sizeHandlers) { new = (BlockHandlerPtr) realloc(handlers, (numHandlers + 1) * - sizeof (BlockHandlerRec)); - if (!new) - return FALSE; - handlers = new; - sizeHandlers = numHandlers + 1; + sizeof(BlockHandlerRec)); + if (!new) + return FALSE; + handlers = new; + sizeHandlers = numHandlers + 1; } handlers[numHandlers].BlockHandler = blockHandler; handlers[numHandlers].WakeupHandler = wakeupHandler; @@ -476,34 +466,31 @@ RegisterBlockAndWakeupHandlers (BlockHandlerProcPtr blockHandler, } void -RemoveBlockAndWakeupHandlers (BlockHandlerProcPtr blockHandler, - WakeupHandlerProcPtr wakeupHandler, - pointer blockData) +RemoveBlockAndWakeupHandlers(BlockHandlerProcPtr blockHandler, + WakeupHandlerProcPtr wakeupHandler, + pointer blockData) { - int i; + int i; for (i = 0; i < numHandlers; i++) - 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; - } + 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; + } } void -InitBlockAndWakeupHandlers (void) +InitBlockAndWakeupHandlers(void) { free(handlers); handlers = (BlockHandlerPtr) 0; @@ -516,13 +503,13 @@ InitBlockAndWakeupHandlers (void) * sleeps for input. */ -WorkQueuePtr workQueue; -static WorkQueuePtr *workQueueLast = &workQueue; +WorkQueuePtr workQueue; +static WorkQueuePtr *workQueueLast = &workQueue; void ProcessWorkQueue(void) { - WorkQueuePtr q, *p; + WorkQueuePtr q, *p; p = &workQueue; /* @@ -531,18 +518,15 @@ ProcessWorkQueue(void) * they will be called again. This must be reentrant with * QueueWorkProc. */ - 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 */ - } + 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 */ + } } workQueueLast = p; } @@ -550,36 +534,33 @@ ProcessWorkQueue(void) void ProcessWorkQueueZombies(void) { - WorkQueuePtr q, *p; + WorkQueuePtr q, *p; p = &workQueue; - 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 */ - } + 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 */ + } } workQueueLast = p; } Bool -QueueWorkProc ( - Bool (*function)(ClientPtr /* pClient */, pointer /* closure */), - ClientPtr client, pointer closure) +QueueWorkProc(Bool (*function) + (ClientPtr /* pClient */ , pointer /* closure */ ), + ClientPtr client, pointer closure) { - WorkQueuePtr q; + WorkQueuePtr q; q = malloc(sizeof *q); if (!q) - return FALSE; + return FALSE; q->function = function; q->client = client; q->closure = closure; @@ -598,24 +579,24 @@ QueueWorkProc ( */ typedef struct _SleepQueue { - struct _SleepQueue *next; - ClientPtr client; - ClientSleepProcPtr function; - pointer closure; + struct _SleepQueue *next; + ClientPtr client; + ClientSleepProcPtr function; + pointer closure; } SleepQueueRec, *SleepQueuePtr; -static SleepQueuePtr sleepQueue = NULL; +static SleepQueuePtr sleepQueue = NULL; Bool -ClientSleep (ClientPtr client, ClientSleepProcPtr function, pointer closure) +ClientSleep(ClientPtr client, ClientSleepProcPtr function, pointer closure) { - SleepQueuePtr q; + SleepQueuePtr q; q = malloc(sizeof *q); if (!q) - return FALSE; + return FALSE; - IgnoreClient (client); + IgnoreClient(client); q->next = sleepQueue; q->client = client; q->function = function; @@ -625,52 +606,49 @@ ClientSleep (ClientPtr client, ClientSleepProcPtr function, pointer closure) } Bool -ClientSignal (ClientPtr client) +ClientSignal(ClientPtr client) { - SleepQueuePtr q; + SleepQueuePtr q; for (q = sleepQueue; q; q = q->next) - if (q->client == client) - { - return QueueWorkProc (q->function, q->client, q->closure); - } + if (q->client == client) { + return QueueWorkProc(q->function, q->client, q->closure); + } return FALSE; } void -ClientWakeup (ClientPtr client) +ClientWakeup(ClientPtr client) { - SleepQueuePtr q, *prev; + SleepQueuePtr q, *prev; prev = &sleepQueue; - 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; + 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; } } Bool -ClientIsAsleep (ClientPtr client) +ClientIsAsleep(ClientPtr client) { - SleepQueuePtr q; + SleepQueuePtr q; for (q = sleepQueue; q; q = q->next) - if (q->client == client) - return TRUE; + if (q->client == client) + return TRUE; return FALSE; } @@ -684,16 +662,13 @@ static int numCallbackListsToCleanup = 0; static CallbackListPtr **listsToCleanup = NULL; static Bool -_AddCallback( - CallbackListPtr *pcbl, - CallbackProcPtr callback, - pointer data) +_AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data) { - CallbackPtr cbr; + CallbackPtr cbr; cbr = malloc(sizeof(CallbackRec)); if (!cbr) - return FALSE; + return FALSE; cbr->proc = callback; cbr->data = data; cbr->next = (*pcbl)->list; @@ -702,126 +677,105 @@ _AddCallback( return TRUE; } -static Bool -_DeleteCallback( - CallbackListPtr *pcbl, - CallbackProcPtr callback, - pointer data) +static Bool +_DeleteCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data) { CallbackListPtr cbl = *pcbl; - CallbackPtr cbr, pcbr; - - for (pcbr = NULL, cbr = cbl->list; - cbr != NULL; - pcbr = cbr, cbr = cbr->next) - { - if ((cbr->proc == callback) && (cbr->data == data)) - break; + CallbackPtr cbr, pcbr; + + for (pcbr = NULL, cbr = cbl->list; cbr != NULL; pcbr = cbr, cbr = cbr->next) { + if ((cbr->proc == callback) && (cbr->data == data)) + break; } - 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; + 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; } return FALSE; } -void -_CallCallbacks( - CallbackListPtr *pcbl, - pointer call_data) +void +_CallCallbacks(CallbackListPtr *pcbl, pointer call_data) { CallbackListPtr cbl = *pcbl; - CallbackPtr cbr, pcbr; + CallbackPtr cbr, pcbr; ++(cbl->inCallback); - for (cbr = cbl->list; cbr != NULL; cbr = cbr->next) - { - (*(cbr->proc)) (pcbl, cbr->data, call_data); + for (cbr = cbl->list; cbr != NULL; cbr = cbr->next) { + (*(cbr->proc)) (pcbl, cbr->data, call_data); } --(cbl->inCallback); - if (cbl->inCallback) return; + if (cbl->inCallback) + return; /* Was the entire list marked for deletion? */ - if (cbl->deleted) - { - DeleteCallbackList(pcbl); - return; + if (cbl->deleted) { + DeleteCallbackList(pcbl); + return; } /* Were some individual callbacks on the list marked for deletion? * If so, do the deletions. */ - 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; - } - } + 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; + } + } } } static void -_DeleteCallbackList( - CallbackListPtr *pcbl) +_DeleteCallbackList(CallbackListPtr *pcbl) { CallbackListPtr cbl = *pcbl; - CallbackPtr cbr, nextcbr; + CallbackPtr cbr, nextcbr; int i; - if (cbl->inCallback) - { - cbl->deleted = TRUE; - return; + if (cbl->inCallback) { + cbl->deleted = TRUE; + return; } - for (i = 0; i < numCallbackListsToCleanup; i++) - { - if (listsToCleanup[i] == pcbl) - { - listsToCleanup[i] = NULL; - break; - } + for (i = 0; i < numCallbackListsToCleanup; i++) { + if (listsToCleanup[i] == pcbl) { + listsToCleanup[i] = NULL; + break; + } } - for (cbr = cbl->list; cbr != NULL; cbr = nextcbr) - { - nextcbr = cbr->next; - free(cbr); + for (cbr = cbl->list; cbr != NULL; cbr = nextcbr) { + nextcbr = cbr->next; + free(cbr); } free(cbl); *pcbl = NULL; @@ -830,29 +784,31 @@ _DeleteCallbackList( static Bool CreateCallbackList(CallbackListPtr *pcbl) { - CallbackListPtr cbl; + CallbackListPtr cbl; int i; - if (!pcbl) return FALSE; + if (!pcbl) + return FALSE; cbl = malloc(sizeof(CallbackListRec)); - if (!cbl) return FALSE; + if (!cbl) + return FALSE; cbl->inCallback = 0; cbl->deleted = FALSE; cbl->numDeleted = 0; cbl->list = NULL; *pcbl = cbl; - for (i = 0; i < numCallbackListsToCleanup; i++) - { - if (!listsToCleanup[i]) - { - listsToCleanup[i] = pcbl; - return TRUE; - } + for (i = 0; i < numCallbackListsToCleanup; i++) { + if (!listsToCleanup[i]) { + listsToCleanup[i] = pcbl; + return TRUE; + } } - listsToCleanup = (CallbackListPtr **)xnfrealloc(listsToCleanup, - sizeof(CallbackListPtr *) * (numCallbackListsToCleanup+1)); + listsToCleanup = (CallbackListPtr **) xnfrealloc(listsToCleanup, + sizeof(CallbackListPtr *) * + (numCallbackListsToCleanup + + 1)); listsToCleanup[numCallbackListsToCleanup] = pcbl; numCallbackListsToCleanup++; return TRUE; @@ -863,11 +819,11 @@ CreateCallbackList(CallbackListPtr *pcbl) Bool AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data) { - if (!pcbl) return FALSE; - if (!*pcbl) - { /* list hasn't been created yet; go create it */ - if (!CreateCallbackList(pcbl)) - return FALSE; + if (!pcbl) + return FALSE; + if (!*pcbl) { /* list hasn't been created yet; go create it */ + if (!CreateCallbackList(pcbl)) + return FALSE; } return _AddCallback(pcbl, callback, data); } @@ -875,14 +831,16 @@ AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data) Bool DeleteCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data) { - if (!pcbl || !*pcbl) return FALSE; + if (!pcbl || !*pcbl) + return FALSE; return _DeleteCallback(pcbl, callback, data); } void DeleteCallbackList(CallbackListPtr *pcbl) { - if (!pcbl || !*pcbl) return; + if (!pcbl || !*pcbl) + return; _DeleteCallbackList(pcbl); } @@ -891,9 +849,8 @@ InitCallbackManager(void) { int i; - for (i = 0; i < numCallbackListsToCleanup; i++) - { - DeleteCallbackList(listsToCleanup[i]); + for (i = 0; i < numCallbackListsToCleanup; i++) { + DeleteCallbackList(listsToCleanup[i]); } free(listsToCleanup); diff --git a/xorg-server/dix/enterleave.c b/xorg-server/dix/enterleave.c index 89a82ab99..725080a4c 100644 --- a/xorg-server/dix/enterleave.c +++ b/xorg-server/dix/enterleave.c @@ -106,6 +106,7 @@ static BOOL HasFocus(WindowPtr win) { int i; + for (i = 0; i < MAXDEVICES; i++) if (FocusWindows[i] == win) return TRUE; @@ -133,8 +134,8 @@ static WindowPtr FirstPointerChild(WindowPtr win) { int i; - for (i = 0; i < MAXDEVICES; i++) - { + + for (i = 0; i < MAXDEVICES; i++) { if (PointerWindows[i] && IsParent(win, PointerWindows[i])) return PointerWindows[i]; } @@ -153,8 +154,8 @@ static WindowPtr FirstFocusChild(WindowPtr win) { int i; - for (i = 0; i < MAXDEVICES; i++) - { + + for (i = 0; i < MAXDEVICES; i++) { if (FocusWindows[i] && FocusWindows[i] != PointerRootWin && IsParent(win, FocusWindows[i])) return FocusWindows[i]; @@ -199,9 +200,6 @@ SetFocusOut(DeviceIntPtr dev) FocusWindows[dev->id] = NULL; } - - - /** * Return the common ancestor of 'a' and 'b' (if one exists). * @param a A window with the same ancestor as b. @@ -210,16 +208,14 @@ SetFocusOut(DeviceIntPtr dev) * NullWindow if they do not have a common ancestor. */ WindowPtr -CommonAncestor( - WindowPtr a, - WindowPtr b) +CommonAncestor(WindowPtr a, WindowPtr b) { for (b = b->parent; b; b = b->parent) - if (IsParent(b, a)) return b; + if (IsParent(b, a)) + return b; return NullWindow; } - /** * Send enter notifies to all windows between 'ancestor' and 'child' (excluding * both). Events are sent running up the window hierarchy. This function @@ -227,16 +223,13 @@ CommonAncestor( */ static void DeviceEnterNotifies(DeviceIntPtr dev, - int sourceid, - WindowPtr ancestor, - WindowPtr child, - int mode, - int detail) + int sourceid, + WindowPtr ancestor, WindowPtr child, int mode, int detail) { - WindowPtr parent = child->parent; + WindowPtr parent = child->parent; if (ancestor == parent) - return; + return; DeviceEnterNotifies(dev, sourceid, ancestor, parent, mode, detail); DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, detail, parent, child->drawable.id); @@ -249,79 +242,73 @@ DeviceEnterNotifies(DeviceIntPtr dev, */ static void CoreEnterNotifies(DeviceIntPtr dev, - WindowPtr ancestor, - WindowPtr child, - int mode, - int detail) + WindowPtr ancestor, WindowPtr child, int mode, int detail) { - WindowPtr parent = child->parent; + WindowPtr parent = child->parent; + if (ancestor == parent) - return; + return; CoreEnterNotifies(dev, ancestor, parent, mode, detail); - /* Case 3: - A is above W, B is a descendant - - Classically: The move generates an EnterNotify on W with a detail of - Virtual or NonlinearVirtual - - MPX: - Case 3A: There is at least one other pointer on W itself - P(W) doesn't change, so the event should be suppressed - Case 3B: Otherwise, if there is at least one other pointer in a - descendant - P(W) stays on the same descendant, or changes to a different - descendant. The event should be suppressed. - Case 3C: Otherwise: - P(W) moves from a window above W to a descendant. The subwindow - field is set to the child containing the descendant. The detail - may need to be changed from Virtual to NonlinearVirtual depending - on the previous P(W). */ + A is above W, B is a descendant + + Classically: The move generates an EnterNotify on W with a detail of + Virtual or NonlinearVirtual + + MPX: + Case 3A: There is at least one other pointer on W itself + P(W) doesn't change, so the event should be suppressed + Case 3B: Otherwise, if there is at least one other pointer in a + descendant + P(W) stays on the same descendant, or changes to a different + descendant. The event should be suppressed. + Case 3C: Otherwise: + P(W) moves from a window above W to a descendant. The subwindow + field is set to the child containing the descendant. The detail + may need to be changed from Virtual to NonlinearVirtual depending + on the previous P(W). */ if (!HasPointer(dev, parent) && !FirstPointerChild(parent)) - CoreEnterLeaveEvent(dev, EnterNotify, mode, detail, parent, - child->drawable.id); + CoreEnterLeaveEvent(dev, EnterNotify, mode, detail, parent, + child->drawable.id); } static void CoreLeaveNotifies(DeviceIntPtr dev, - WindowPtr child, - WindowPtr ancestor, - int mode, - int detail) + WindowPtr child, WindowPtr ancestor, int mode, int detail) { - WindowPtr win; + WindowPtr win; if (ancestor == child) return; - for (win = child->parent; win != ancestor; win = win->parent) - { + for (win = child->parent; win != ancestor; win = win->parent) { /*Case 7: - A is a descendant of W, B is above W - - Classically: A LeaveNotify is generated on W with a detail of Virtual - or NonlinearVirtual. - - MPX: - Case 3A: There is at least one other pointer on W itself - P(W) doesn't change, the event should be suppressed. - Case 3B: Otherwise, if there is at least one other pointer in a - descendant - P(W) stays on the same descendant, or changes to a different - descendant. The event should be suppressed. - Case 3C: Otherwise: - P(W) changes from the descendant of W to a window above W. - The detail may need to be changed from Virtual to NonlinearVirtual - or vice-versa depending on the new P(W).*/ + A is a descendant of W, B is above W + + Classically: A LeaveNotify is generated on W with a detail of Virtual + or NonlinearVirtual. + + MPX: + Case 3A: There is at least one other pointer on W itself + P(W) doesn't change, the event should be suppressed. + Case 3B: Otherwise, if there is at least one other pointer in a + descendant + P(W) stays on the same descendant, or changes to a different + descendant. The event should be suppressed. + Case 3C: Otherwise: + P(W) changes from the descendant of W to a window above W. + The detail may need to be changed from Virtual to NonlinearVirtual + or vice-versa depending on the new P(W). */ /* If one window has a pointer or a child with a pointer, skip some * work and exit. */ if (HasPointer(dev, win) || FirstPointerChild(win)) return; - CoreEnterLeaveEvent(dev, LeaveNotify, mode, detail, win, child->drawable.id); + CoreEnterLeaveEvent(dev, LeaveNotify, mode, detail, win, + child->drawable.id); child = win; } @@ -333,20 +320,16 @@ CoreLeaveNotifies(DeviceIntPtr dev, */ static void DeviceLeaveNotifies(DeviceIntPtr dev, - int sourceid, - WindowPtr child, - WindowPtr ancestor, - int mode, - int detail) + int sourceid, + WindowPtr child, WindowPtr ancestor, int mode, int detail) { - WindowPtr win; + WindowPtr win; if (ancestor == child) - return; - for (win = child->parent; win != ancestor; win = win->parent) - { + return; + for (win = child->parent; win != ancestor; win = win->parent) { DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, detail, win, - child->drawable.id); + child->drawable.id); child = win; } } @@ -356,205 +339,198 @@ DeviceLeaveNotifies(DeviceIntPtr dev, * B a descendant of A. */ static void -CoreEnterLeaveNonLinear(DeviceIntPtr dev, - WindowPtr A, - WindowPtr B, - int mode) +CoreEnterLeaveNonLinear(DeviceIntPtr dev, WindowPtr A, WindowPtr B, int mode) { WindowPtr X = CommonAncestor(A, B); + /* Case 4: - A is W, B is above W + A is W, B is above W - Classically: The move generates a LeaveNotify on W with a detail of + Classically: The move generates a LeaveNotify on W with a detail of Ancestor or Nonlinear - MPX: - Case 3A: There is at least one other pointer on W itself - P(W) doesn't change, the event should be suppressed - Case 3B: Otherwise, if there is at least one other pointer in a - descendant of W - P(W) changes from W to a descendant of W. The subwindow field - is set to the child containing the new P(W), the detail field - is set to Inferior - Case 3C: Otherwise: - The pointer window moves from W to a window above W. - The detail may need to be changed from Ancestor to Nonlinear or - vice versa depending on the the new P(W) + MPX: + Case 3A: There is at least one other pointer on W itself + P(W) doesn't change, the event should be suppressed + Case 3B: Otherwise, if there is at least one other pointer in a + descendant of W + P(W) changes from W to a descendant of W. The subwindow field + is set to the child containing the new P(W), the detail field + is set to Inferior + Case 3C: Otherwise: + The pointer window moves from W to a window above W. + The detail may need to be changed from Ancestor to Nonlinear or + vice versa depending on the the new P(W) */ - if (!HasPointer(dev, A)) - { + if (!HasPointer(dev, A)) { WindowPtr child = FirstPointerChild(A); + if (child) - CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyInferior, A, None); + CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyInferior, A, + None); else - CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyNonlinear, A, None); + CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyNonlinear, A, + None); } - CoreLeaveNotifies(dev, A, X, mode, NotifyNonlinearVirtual); /* - Case 9: - A is a descendant of W, B is a descendant of W - - Classically: No events are generated on W - MPX: The pointer window stays the same or moves to a different - descendant of W. No events should be generated on W. + Case 9: + A is a descendant of W, B is a descendant of W + Classically: No events are generated on W + MPX: The pointer window stays the same or moves to a different + descendant of W. No events should be generated on W. Therefore, no event to X. - */ + */ CoreEnterNotifies(dev, X, B, mode, NotifyNonlinearVirtual); /* Case 2: - A is above W, B=W - - Classically: The move generates an EnterNotify on W with a detail of - Ancestor or Nonlinear - - MPX: - Case 2A: There is at least one other pointer on W itself - P(W) doesn't change, so the event should be suppressed - Case 2B: Otherwise, if there is at least one other pointer in a - descendant - P(W) moves from a descendant to W. detail is changed to Inferior, - subwindow is set to the child containing the previous P(W) - Case 2C: Otherwise: - P(W) changes from a window above W to W itself. - The detail may need to be changed from Ancestor to Nonlinear - or vice-versa depending on the previous P(W). */ - - if (!HasPointer(dev, B)) - { - WindowPtr child = FirstPointerChild(B); - if (child) - CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyInferior, B, None); - else - CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyNonlinear, B, None); - } + A is above W, B=W + + Classically: The move generates an EnterNotify on W with a detail of + Ancestor or Nonlinear + + MPX: + Case 2A: There is at least one other pointer on W itself + P(W) doesn't change, so the event should be suppressed + Case 2B: Otherwise, if there is at least one other pointer in a + descendant + P(W) moves from a descendant to W. detail is changed to Inferior, + subwindow is set to the child containing the previous P(W) + Case 2C: Otherwise: + P(W) changes from a window above W to W itself. + The detail may need to be changed from Ancestor to Nonlinear + or vice-versa depending on the previous P(W). */ + + if (!HasPointer(dev, B)) { + WindowPtr child = FirstPointerChild(B); + + if (child) + CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyInferior, B, + None); + else + CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyNonlinear, B, + None); + } } /** * Pointer dev moves from A to B and A is a descendant of B. */ static void -CoreEnterLeaveToAncestor(DeviceIntPtr dev, - WindowPtr A, - WindowPtr B, - int mode) +CoreEnterLeaveToAncestor(DeviceIntPtr dev, WindowPtr A, WindowPtr B, int mode) { /* Case 4: - A is W, B is above W + A is W, B is above W - Classically: The move generates a LeaveNotify on W with a detail of + Classically: The move generates a LeaveNotify on W with a detail of Ancestor or Nonlinear - MPX: - Case 3A: There is at least one other pointer on W itself - P(W) doesn't change, the event should be suppressed - Case 3B: Otherwise, if there is at least one other pointer in a - descendant of W - P(W) changes from W to a descendant of W. The subwindow field - is set to the child containing the new P(W), the detail field - is set to Inferior - Case 3C: Otherwise: - The pointer window moves from W to a window above W. - The detail may need to be changed from Ancestor to Nonlinear or - vice versa depending on the the new P(W) + MPX: + Case 3A: There is at least one other pointer on W itself + P(W) doesn't change, the event should be suppressed + Case 3B: Otherwise, if there is at least one other pointer in a + descendant of W + P(W) changes from W to a descendant of W. The subwindow field + is set to the child containing the new P(W), the detail field + is set to Inferior + Case 3C: Otherwise: + The pointer window moves from W to a window above W. + The detail may need to be changed from Ancestor to Nonlinear or + vice versa depending on the the new P(W) */ - if (!HasPointer(dev, A)) - { + if (!HasPointer(dev, A)) { WindowPtr child = FirstPointerChild(A); + if (child) - CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyInferior, A, None); + CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyInferior, A, + None); else - CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyAncestor, A, None); + CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyAncestor, A, + None); } CoreLeaveNotifies(dev, A, B, mode, NotifyVirtual); /* Case 8: - A is a descendant of W, B is W + A is a descendant of W, B is W - Classically: A EnterNotify is generated on W with a detail of - NotifyInferior + Classically: A EnterNotify is generated on W with a detail of + NotifyInferior - MPX: - Case 3A: There is at least one other pointer on W itself - P(W) doesn't change, the event should be suppressed - Case 3B: Otherwise: - P(W) changes from a descendant to W itself. The subwindow - field should be set to the child containing the old P(W) <<< WRONG */ + MPX: + Case 3A: There is at least one other pointer on W itself + P(W) doesn't change, the event should be suppressed + Case 3B: Otherwise: + P(W) changes from a descendant to W itself. The subwindow + field should be set to the child containing the old P(W) <<< WRONG */ if (!HasPointer(dev, B)) CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyInferior, B, None); } - /** * Pointer dev moves from A to B and B is a descendant of A. */ static void -CoreEnterLeaveToDescendant(DeviceIntPtr dev, - WindowPtr A, - WindowPtr B, - int mode) +CoreEnterLeaveToDescendant(DeviceIntPtr dev, WindowPtr A, WindowPtr B, int mode) { /* Case 6: - A is W, B is a descendant of W + A is W, B is a descendant of W - Classically: A LeaveNotify is generated on W with a detail of + Classically: A LeaveNotify is generated on W with a detail of NotifyInferior - MPX: - Case 3A: There is at least one other pointer on W itself - P(W) doesn't change, the event should be suppressed - Case 3B: Otherwise: - P(W) changes from W to a descendant of W. The subwindow field - is set to the child containing the new P(W) <<< THIS IS WRONG */ + MPX: + Case 3A: There is at least one other pointer on W itself + P(W) doesn't change, the event should be suppressed + Case 3B: Otherwise: + P(W) changes from W to a descendant of W. The subwindow field + is set to the child containing the new P(W) <<< THIS IS WRONG */ if (!HasPointer(dev, A)) CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyInferior, A, None); - CoreEnterNotifies(dev, A, B, mode, NotifyVirtual); /* Case 2: - A is above W, B=W - - Classically: The move generates an EnterNotify on W with a detail of - Ancestor or Nonlinear - - MPX: - Case 2A: There is at least one other pointer on W itself - P(W) doesn't change, so the event should be suppressed - Case 2B: Otherwise, if there is at least one other pointer in a - descendant - P(W) moves from a descendant to W. detail is changed to Inferior, - subwindow is set to the child containing the previous P(W) - Case 2C: Otherwise: - P(W) changes from a window above W to W itself. - The detail may need to be changed from Ancestor to Nonlinear - or vice-versa depending on the previous P(W). */ - - if (!HasPointer(dev, B)) - { - WindowPtr child = FirstPointerChild(B); - if (child) - CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyInferior, B, None); - else - CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyAncestor, B, None); - } + A is above W, B=W + + Classically: The move generates an EnterNotify on W with a detail of + Ancestor or Nonlinear + + MPX: + Case 2A: There is at least one other pointer on W itself + P(W) doesn't change, so the event should be suppressed + Case 2B: Otherwise, if there is at least one other pointer in a + descendant + P(W) moves from a descendant to W. detail is changed to Inferior, + subwindow is set to the child containing the previous P(W) + Case 2C: Otherwise: + P(W) changes from a window above W to W itself. + The detail may need to be changed from Ancestor to Nonlinear + or vice-versa depending on the previous P(W). */ + + if (!HasPointer(dev, B)) { + WindowPtr child = FirstPointerChild(B); + + if (child) + CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyInferior, B, + None); + else + CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyAncestor, B, + None); + } } static void -CoreEnterLeaveEvents(DeviceIntPtr dev, - WindowPtr from, - WindowPtr to, - int mode) +CoreEnterLeaveEvents(DeviceIntPtr dev, WindowPtr from, WindowPtr to, int mode) { if (!IsMaster(dev)) return; @@ -573,31 +549,34 @@ CoreEnterLeaveEvents(DeviceIntPtr dev, static void DeviceEnterLeaveEvents(DeviceIntPtr dev, - int sourceid, - WindowPtr from, - WindowPtr to, - int mode) + int sourceid, WindowPtr from, WindowPtr to, int mode) { - if (IsParent(from, to)) - { - DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, NotifyInferior, from, None); + if (IsParent(from, to)) { + DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, NotifyInferior, + from, None); DeviceEnterNotifies(dev, sourceid, from, to, mode, NotifyVirtual); - DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, NotifyAncestor, to, None); + DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, NotifyAncestor, to, + None); } - else if (IsParent(to, from)) - { - DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, NotifyAncestor, from, None); - DeviceLeaveNotifies(dev, sourceid, from, to, mode, NotifyVirtual); - DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, NotifyInferior, to, None); + else if (IsParent(to, from)) { + DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, NotifyAncestor, + from, None); + DeviceLeaveNotifies(dev, sourceid, from, to, mode, NotifyVirtual); + DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, NotifyInferior, to, + None); } - else - { /* neither from nor to is descendent of the other */ - WindowPtr common = CommonAncestor(to, from); - /* common == NullWindow ==> different screens */ - DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, NotifyNonlinear, from, None); - DeviceLeaveNotifies(dev, sourceid, from, common, mode, NotifyNonlinearVirtual); - DeviceEnterNotifies(dev, sourceid, common, to, mode, NotifyNonlinearVirtual); - DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, NotifyNonlinear, to, None); + else { /* neither from nor to is descendent of the other */ + WindowPtr common = CommonAncestor(to, from); + + /* common == NullWindow ==> different screens */ + DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, NotifyNonlinear, + from, None); + DeviceLeaveNotifies(dev, sourceid, from, common, mode, + NotifyNonlinearVirtual); + DeviceEnterNotifies(dev, sourceid, common, to, mode, + NotifyNonlinearVirtual); + DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, NotifyNonlinear, + to, None); } } @@ -610,16 +589,13 @@ DeviceEnterLeaveEvents(DeviceIntPtr dev, */ void DoEnterLeaveEvents(DeviceIntPtr pDev, - int sourceid, - WindowPtr fromWin, - WindowPtr toWin, - int mode) + int sourceid, WindowPtr fromWin, WindowPtr toWin, int mode) { if (!IsPointerDevice(pDev)) return; if (fromWin == toWin) - return; + return; if (mode != XINotifyPassiveGrab && mode != XINotifyPassiveUngrab) CoreEnterLeaveEvents(pDev, fromWin, toWin, mode); @@ -632,20 +608,16 @@ DoEnterLeaveEvents(DeviceIntPtr pDev, */ static void DeviceFocusOutEvents(DeviceIntPtr dev, - WindowPtr child, - WindowPtr ancestor, - int mode, - int detail) + WindowPtr child, WindowPtr ancestor, int mode, int detail) { - WindowPtr win; + WindowPtr win; if (ancestor == child) - return; + return; for (win = child->parent; win != ancestor; win = win->parent) DeviceFocusEvent(dev, XI_FocusOut, mode, detail, win); } - /** * Send enter notifies to all windows between 'ancestor' and 'child' (excluding * both). Events are sent running up the window hierarchy. This function @@ -653,15 +625,12 @@ DeviceFocusOutEvents(DeviceIntPtr dev, */ static void DeviceFocusInEvents(DeviceIntPtr dev, - WindowPtr ancestor, - WindowPtr child, - int mode, - int detail) + WindowPtr ancestor, WindowPtr child, int mode, int detail) { - WindowPtr parent = child->parent; + WindowPtr parent = child->parent; if (ancestor == parent || !parent) - return; + return; DeviceFocusInEvents(dev, ancestor, parent, mode, detail); DeviceFocusEvent(dev, XI_FocusIn, mode, detail, parent); } @@ -673,70 +642,63 @@ DeviceFocusInEvents(DeviceIntPtr dev, */ static void CoreFocusInEvents(DeviceIntPtr dev, - WindowPtr ancestor, - WindowPtr child, - int mode, - int detail) + WindowPtr ancestor, WindowPtr child, int mode, int detail) { - WindowPtr parent = child->parent; + WindowPtr parent = child->parent; + if (ancestor == parent) - return; + return; CoreFocusInEvents(dev, ancestor, parent, mode, detail); - /* Case 3: - A is above W, B is a descendant - - Classically: The move generates an FocusIn on W with a detail of - Virtual or NonlinearVirtual - - MPX: - Case 3A: There is at least one other focus on W itself - F(W) doesn't change, so the event should be suppressed - Case 3B: Otherwise, if there is at least one other focus in a - descendant - F(W) stays on the same descendant, or changes to a different - descendant. The event should be suppressed. - Case 3C: Otherwise: - F(W) moves from a window above W to a descendant. The detail may - need to be changed from Virtual to NonlinearVirtual depending - on the previous F(W). */ + A is above W, B is a descendant + + Classically: The move generates an FocusIn on W with a detail of + Virtual or NonlinearVirtual + + MPX: + Case 3A: There is at least one other focus on W itself + F(W) doesn't change, so the event should be suppressed + Case 3B: Otherwise, if there is at least one other focus in a + descendant + F(W) stays on the same descendant, or changes to a different + descendant. The event should be suppressed. + Case 3C: Otherwise: + F(W) moves from a window above W to a descendant. The detail may + need to be changed from Virtual to NonlinearVirtual depending + on the previous F(W). */ if (!HasFocus(parent) && !FirstFocusChild(parent)) - CoreFocusEvent(dev, FocusIn, mode, detail, parent); + CoreFocusEvent(dev, FocusIn, mode, detail, parent); } static void CoreFocusOutEvents(DeviceIntPtr dev, - WindowPtr child, - WindowPtr ancestor, - int mode, - int detail) + WindowPtr child, WindowPtr ancestor, int mode, int detail) { - WindowPtr win; + WindowPtr win; if (ancestor == child) return; - for (win = child->parent; win != ancestor; win = win->parent) - { + for (win = child->parent; win != ancestor; win = win->parent) { /*Case 7: - A is a descendant of W, B is above W - - Classically: A FocusOut is generated on W with a detail of Virtual - or NonlinearVirtual. - - MPX: - Case 3A: There is at least one other focus on W itself - F(W) doesn't change, the event should be suppressed. - Case 3B: Otherwise, if there is at least one other focus in a - descendant - F(W) stays on the same descendant, or changes to a different - descendant. The event should be suppressed. - Case 3C: Otherwise: - F(W) changes from the descendant of W to a window above W. - The detail may need to be changed from Virtual to NonlinearVirtual - or vice-versa depending on the new P(W).*/ + A is a descendant of W, B is above W + + Classically: A FocusOut is generated on W with a detail of Virtual + or NonlinearVirtual. + + MPX: + Case 3A: There is at least one other focus on W itself + F(W) doesn't change, the event should be suppressed. + Case 3B: Otherwise, if there is at least one other focus in a + descendant + F(W) stays on the same descendant, or changes to a different + descendant. The event should be suppressed. + Case 3C: Otherwise: + F(W) changes from the descendant of W to a window above W. + The detail may need to be changed from Virtual to NonlinearVirtual + or vice-versa depending on the new P(W). */ /* If one window has a focus or a child with a focuspointer, skip some * work and exit. */ @@ -760,9 +722,7 @@ CoreFocusOutEvents(DeviceIntPtr dev, static void CoreFocusOutNotifyPointerEvents(DeviceIntPtr dev, WindowPtr pwin_parent, - WindowPtr exclude, - int mode, - int inclusive) + WindowPtr exclude, int mode, int inclusive) { WindowPtr P, stopAt; @@ -790,10 +750,7 @@ CoreFocusOutNotifyPointerEvents(DeviceIntPtr dev, */ static void CoreFocusInRecurse(DeviceIntPtr dev, - WindowPtr win, - WindowPtr stopAt, - int mode, - int inclusive) + WindowPtr win, WindowPtr stopAt, int mode, int inclusive) { if ((!inclusive && win == stopAt) || !win) return; @@ -802,7 +759,6 @@ CoreFocusInRecurse(DeviceIntPtr dev, CoreFocusEvent(dev, FocusIn, mode, NotifyPointer, win); } - /** * Send FocusIn(NotifyPointer) events from pwin_parent down to * including the current pointer window (which is a descendant of pwin_parent). @@ -815,9 +771,7 @@ CoreFocusInRecurse(DeviceIntPtr dev, static void CoreFocusInNotifyPointerEvents(DeviceIntPtr dev, WindowPtr pwin_parent, - WindowPtr exclude, - int mode, - int inclusive) + WindowPtr exclude, int mode, int inclusive) { WindowPtr P; @@ -832,160 +786,148 @@ CoreFocusInNotifyPointerEvents(DeviceIntPtr dev, CoreFocusInRecurse(dev, P, pwin_parent, mode, inclusive); } - /** * Focus of dev moves from A to B and A neither a descendant of B nor is * B a descendant of A. */ static void -CoreFocusNonLinear(DeviceIntPtr dev, - WindowPtr A, - WindowPtr B, - int mode) +CoreFocusNonLinear(DeviceIntPtr dev, WindowPtr A, WindowPtr B, int mode) { WindowPtr X = CommonAncestor(A, B); /* Case 4: - A is W, B is above W + A is W, B is above W - Classically: The change generates a FocusOut on W with a detail of + Classically: The change generates a FocusOut on W with a detail of Ancestor or Nonlinear - MPX: - Case 3A: There is at least one other focus on W itself - F(W) doesn't change, the event should be suppressed - Case 3B: Otherwise, if there is at least one other focus in a - descendant of W - F(W) changes from W to a descendant of W. The detail field - is set to Inferior - Case 3C: Otherwise: - The focus window moves from W to a window above W. - The detail may need to be changed from Ancestor to Nonlinear or - vice versa depending on the the new F(W) + MPX: + Case 3A: There is at least one other focus on W itself + F(W) doesn't change, the event should be suppressed + Case 3B: Otherwise, if there is at least one other focus in a + descendant of W + F(W) changes from W to a descendant of W. The detail field + is set to Inferior + Case 3C: Otherwise: + The focus window moves from W to a window above W. + The detail may need to be changed from Ancestor to Nonlinear or + vice versa depending on the the new F(W) */ - if (!HasFocus(A)) - { + if (!HasFocus(A)) { WindowPtr child = FirstFocusChild(A); - if (child) - { - /* NotifyPointer P-A unless P is child or below*/ + + if (child) { + /* NotifyPointer P-A unless P is child or below */ CoreFocusOutNotifyPointerEvents(dev, A, child, mode, FALSE); CoreFocusEvent(dev, FocusOut, mode, NotifyInferior, A); - } else - { + } + else { /* NotifyPointer P-A */ CoreFocusOutNotifyPointerEvents(dev, A, None, mode, FALSE); CoreFocusEvent(dev, FocusOut, mode, NotifyNonlinear, A); } } - CoreFocusOutEvents(dev, A, X, mode, NotifyNonlinearVirtual); /* - Case 9: - A is a descendant of W, B is a descendant of W - - Classically: No events are generated on W - MPX: The focus window stays the same or moves to a different - descendant of W. No events should be generated on W. + Case 9: + A is a descendant of W, B is a descendant of W + Classically: No events are generated on W + MPX: The focus window stays the same or moves to a different + descendant of W. No events should be generated on W. Therefore, no event to X. - */ + */ CoreFocusInEvents(dev, X, B, mode, NotifyNonlinearVirtual); /* Case 2: - A is above W, B=W - - Classically: The move generates an EnterNotify on W with a detail of - Ancestor or Nonlinear - - MPX: - Case 2A: There is at least one other focus on W itself - F(W) doesn't change, so the event should be suppressed - Case 2B: Otherwise, if there is at least one other focus in a - descendant - F(W) moves from a descendant to W. detail is changed to Inferior. - Case 2C: Otherwise: - F(W) changes from a window above W to W itself. - The detail may need to be changed from Ancestor to Nonlinear - or vice-versa depending on the previous F(W). */ - - if (!HasFocus(B)) - { - WindowPtr child = FirstFocusChild(B); - if (child) - { - CoreFocusEvent(dev, FocusIn, mode, NotifyInferior, B); - /* NotifyPointer B-P unless P is child or below. */ - CoreFocusInNotifyPointerEvents(dev, B, child, mode, FALSE); - } else { - CoreFocusEvent(dev, FocusIn, mode, NotifyNonlinear, B); - /* NotifyPointer B-P unless P is child or below. */ - CoreFocusInNotifyPointerEvents(dev, B, None, mode, FALSE); - } - } -} + A is above W, B=W + + Classically: The move generates an EnterNotify on W with a detail of + Ancestor or Nonlinear + MPX: + Case 2A: There is at least one other focus on W itself + F(W) doesn't change, so the event should be suppressed + Case 2B: Otherwise, if there is at least one other focus in a + descendant + F(W) moves from a descendant to W. detail is changed to Inferior. + Case 2C: Otherwise: + F(W) changes from a window above W to W itself. + The detail may need to be changed from Ancestor to Nonlinear + or vice-versa depending on the previous F(W). */ + + if (!HasFocus(B)) { + WindowPtr child = FirstFocusChild(B); + + if (child) { + CoreFocusEvent(dev, FocusIn, mode, NotifyInferior, B); + /* NotifyPointer B-P unless P is child or below. */ + CoreFocusInNotifyPointerEvents(dev, B, child, mode, FALSE); + } + else { + CoreFocusEvent(dev, FocusIn, mode, NotifyNonlinear, B); + /* NotifyPointer B-P unless P is child or below. */ + CoreFocusInNotifyPointerEvents(dev, B, None, mode, FALSE); + } + } +} /** * Focus of dev moves from A to B and A is a descendant of B. */ static void -CoreFocusToAncestor(DeviceIntPtr dev, - WindowPtr A, - WindowPtr B, - int mode) +CoreFocusToAncestor(DeviceIntPtr dev, WindowPtr A, WindowPtr B, int mode) { /* Case 4: - A is W, B is above W + A is W, B is above W - Classically: The change generates a FocusOut on W with a detail of + Classically: The change generates a FocusOut on W with a detail of Ancestor or Nonlinear - MPX: - Case 3A: There is at least one other focus on W itself - F(W) doesn't change, the event should be suppressed - Case 3B: Otherwise, if there is at least one other focus in a - descendant of W - F(W) changes from W to a descendant of W. The detail field - is set to Inferior - Case 3C: Otherwise: - The focus window moves from W to a window above W. - The detail may need to be changed from Ancestor to Nonlinear or - vice versa depending on the the new F(W) + MPX: + Case 3A: There is at least one other focus on W itself + F(W) doesn't change, the event should be suppressed + Case 3B: Otherwise, if there is at least one other focus in a + descendant of W + F(W) changes from W to a descendant of W. The detail field + is set to Inferior + Case 3C: Otherwise: + The focus window moves from W to a window above W. + The detail may need to be changed from Ancestor to Nonlinear or + vice versa depending on the the new F(W) */ - if (!HasFocus(A)) - { + if (!HasFocus(A)) { WindowPtr child = FirstFocusChild(A); - if (child) - { - /* NotifyPointer P-A unless P is child or below*/ + + if (child) { + /* NotifyPointer P-A unless P is child or below */ CoreFocusOutNotifyPointerEvents(dev, A, child, mode, FALSE); CoreFocusEvent(dev, FocusOut, mode, NotifyInferior, A); - } else + } + else CoreFocusEvent(dev, FocusOut, mode, NotifyAncestor, A); } CoreFocusOutEvents(dev, A, B, mode, NotifyVirtual); /* Case 8: - A is a descendant of W, B is W + A is a descendant of W, B is W - Classically: A FocusOut is generated on W with a detail of - NotifyInferior + Classically: A FocusOut is generated on W with a detail of + NotifyInferior - MPX: - Case 3A: There is at least one other focus on W itself - F(W) doesn't change, the event should be suppressed - Case 3B: Otherwise: - F(W) changes from a descendant to W itself. */ + MPX: + Case 3A: There is at least one other focus on W itself + F(W) doesn't change, the event should be suppressed + Case 3B: Otherwise: + F(W) changes from a descendant to W itself. */ - if (!HasFocus(B)) - { + if (!HasFocus(B)) { CoreFocusEvent(dev, FocusIn, mode, NotifyInferior, B); /* NotifyPointer B-P unless P is A or below. */ CoreFocusInNotifyPointerEvents(dev, B, A, mode, FALSE); @@ -996,61 +938,56 @@ CoreFocusToAncestor(DeviceIntPtr dev, * Focus of dev moves from A to B and B is a descendant of A. */ static void -CoreFocusToDescendant(DeviceIntPtr dev, - WindowPtr A, - WindowPtr B, - int mode) +CoreFocusToDescendant(DeviceIntPtr dev, WindowPtr A, WindowPtr B, int mode) { /* Case 6: - A is W, B is a descendant of W + A is W, B is a descendant of W - Classically: A FocusOut is generated on W with a detail of + Classically: A FocusOut is generated on W with a detail of NotifyInferior - MPX: - Case 3A: There is at least one other focus on W itself - F(W) doesn't change, the event should be suppressed - Case 3B: Otherwise: - F(W) changes from W to a descendant of W. */ + MPX: + Case 3A: There is at least one other focus on W itself + F(W) doesn't change, the event should be suppressed + Case 3B: Otherwise: + F(W) changes from W to a descendant of W. */ - if (!HasFocus(A)) - { - /* NotifyPointer P-A unless P is B or below*/ + if (!HasFocus(A)) { + /* NotifyPointer P-A unless P is B or below */ CoreFocusOutNotifyPointerEvents(dev, A, B, mode, FALSE); CoreFocusEvent(dev, FocusOut, mode, NotifyInferior, A); } - CoreFocusInEvents(dev, A, B, mode, NotifyVirtual); /* Case 2: - A is above W, B=W - - Classically: The move generates an FocusIn on W with a detail of - Ancestor or Nonlinear - - MPX: - Case 2A: There is at least one other focus on W itself - F(W) doesn't change, so the event should be suppressed - Case 2B: Otherwise, if there is at least one other focus in a - descendant - F(W) moves from a descendant to W. detail is changed to Inferior. - Case 2C: Otherwise: - F(W) changes from a window above W to W itself. - The detail may need to be changed from Ancestor to Nonlinear - or vice-versa depending on the previous F(W). */ - - if (!HasFocus(B)) - { - WindowPtr child = FirstFocusChild(B); - if (child) - { - CoreFocusEvent(dev, FocusIn, mode, NotifyInferior, B); - /* NotifyPointer B-P unless P is child or below. */ - CoreFocusInNotifyPointerEvents(dev, B, child, mode, FALSE); - } else - CoreFocusEvent(dev, FocusIn, mode, NotifyAncestor, B); - } + A is above W, B=W + + Classically: The move generates an FocusIn on W with a detail of + Ancestor or Nonlinear + + MPX: + Case 2A: There is at least one other focus on W itself + F(W) doesn't change, so the event should be suppressed + Case 2B: Otherwise, if there is at least one other focus in a + descendant + F(W) moves from a descendant to W. detail is changed to Inferior. + Case 2C: Otherwise: + F(W) changes from a window above W to W itself. + The detail may need to be changed from Ancestor to Nonlinear + or vice-versa depending on the previous F(W). */ + + if (!HasFocus(B)) { + WindowPtr child = FirstFocusChild(B); + + if (child) { + CoreFocusEvent(dev, FocusIn, mode, NotifyInferior, B); + /* NotifyPointer B-P unless P is child or below. */ + CoreFocusInNotifyPointerEvents(dev, B, child, mode, FALSE); + } + else + CoreFocusEvent(dev, FocusIn, mode, NotifyAncestor, B); + } } static BOOL @@ -1070,9 +1007,8 @@ HasOtherPointer(WindowPtr win, DeviceIntPtr exclude) * Assumption: Neither A nor B are valid windows. */ static void -CoreFocusPointerRootNoneSwitch(DeviceIntPtr dev, - WindowPtr A, /* PointerRootWin or NoneWin */ - WindowPtr B, /* NoneWin or PointerRootWin */ +CoreFocusPointerRootNoneSwitch(DeviceIntPtr dev, WindowPtr A, /* PointerRootWin or NoneWin */ + WindowPtr B, /* NoneWin or PointerRootWin */ int mode) { WindowPtr root; @@ -1084,23 +1020,25 @@ CoreFocusPointerRootNoneSwitch(DeviceIntPtr dev, nscreens = 1; #endif - for (i = 0; i < nscreens; i++) - { + for (i = 0; i < nscreens; i++) { root = screenInfo.screens[i]->root; - if (!HasOtherPointer(root, GetMaster(dev, POINTER_OR_FLOAT)) && !FirstFocusChild(root)) - { + if (!HasOtherPointer(root, GetMaster(dev, POINTER_OR_FLOAT)) && + !FirstFocusChild(root)) { /* If pointer was on PointerRootWin and changes to NoneWin, and * the pointer paired with dev is below the current root window, * do a NotifyPointer run. */ if (dev->focus && dev->focus->win == PointerRootWin && - B != PointerRootWin) - { + B != PointerRootWin) { WindowPtr ptrwin = PointerWin(GetMaster(dev, POINTER_OR_FLOAT)); + if (ptrwin && IsParent(root, ptrwin)) - CoreFocusOutNotifyPointerEvents(dev, root, None, mode, TRUE); + CoreFocusOutNotifyPointerEvents(dev, root, None, mode, + TRUE); } - CoreFocusEvent(dev, FocusOut, mode, A ? NotifyPointerRoot : NotifyDetailNone, root); - CoreFocusEvent(dev, FocusIn, mode, B ? NotifyPointerRoot : NotifyDetailNone, root); + CoreFocusEvent(dev, FocusOut, mode, + A ? NotifyPointerRoot : NotifyDetailNone, root); + CoreFocusEvent(dev, FocusIn, mode, + B ? NotifyPointerRoot : NotifyDetailNone, root); if (B == PointerRootWin) CoreFocusInNotifyPointerEvents(dev, root, None, mode, TRUE); } @@ -1113,10 +1051,8 @@ CoreFocusPointerRootNoneSwitch(DeviceIntPtr dev, * Assumption: A is a valid window and not PointerRoot or None. */ static void -CoreFocusToPointerRootOrNone(DeviceIntPtr dev, - WindowPtr A, - WindowPtr B, /* PointerRootWin or NoneWin */ - int mode) +CoreFocusToPointerRootOrNone(DeviceIntPtr dev, WindowPtr A, WindowPtr B, /* PointerRootWin or NoneWin */ + int mode) { WindowPtr root; int i; @@ -1127,15 +1063,15 @@ CoreFocusToPointerRootOrNone(DeviceIntPtr dev, nscreens = 1; #endif - if (!HasFocus(A)) - { + if (!HasFocus(A)) { WindowPtr child = FirstFocusChild(A); - if (child) - { - /* NotifyPointer P-A unless P is B or below*/ + + if (child) { + /* NotifyPointer P-A unless P is B or below */ CoreFocusOutNotifyPointerEvents(dev, A, B, mode, FALSE); CoreFocusEvent(dev, FocusOut, mode, NotifyInferior, A); - } else { + } + else { /* NotifyPointer P-A */ CoreFocusOutNotifyPointerEvents(dev, A, None, mode, FALSE); CoreFocusEvent(dev, FocusOut, mode, NotifyNonlinear, A); @@ -1145,12 +1081,11 @@ CoreFocusToPointerRootOrNone(DeviceIntPtr dev, /* NullWindow means we include the root window */ CoreFocusOutEvents(dev, A, NullWindow, mode, NotifyNonlinearVirtual); - for (i = 0; i < nscreens; i++) - { + for (i = 0; i < nscreens; i++) { root = screenInfo.screens[i]->root; - if (!HasFocus(root) && !FirstFocusChild(root)) - { - CoreFocusEvent(dev, FocusIn, mode, B ? NotifyPointerRoot : NotifyDetailNone, root); + if (!HasFocus(root) && !FirstFocusChild(root)) { + CoreFocusEvent(dev, FocusIn, mode, + B ? NotifyPointerRoot : NotifyDetailNone, root); if (B == PointerRootWin) CoreFocusInNotifyPointerEvents(dev, root, None, mode, TRUE); } @@ -1162,10 +1097,8 @@ CoreFocusToPointerRootOrNone(DeviceIntPtr dev, * Assumption: B is a valid window and not PointerRoot or None. */ static void -CoreFocusFromPointerRootOrNone(DeviceIntPtr dev, - WindowPtr A, /* PointerRootWin or NoneWin */ - WindowPtr B, - int mode) +CoreFocusFromPointerRootOrNone(DeviceIntPtr dev, WindowPtr A, /* PointerRootWin or NoneWin */ + WindowPtr B, int mode) { WindowPtr root; int i; @@ -1176,45 +1109,43 @@ CoreFocusFromPointerRootOrNone(DeviceIntPtr dev, nscreens = 1; #endif - for (i = 0; i < nscreens; i++) - { + for (i = 0; i < nscreens; i++) { root = screenInfo.screens[i]->root; - if (!HasFocus(root) && !FirstFocusChild(root)) - { + if (!HasFocus(root) && !FirstFocusChild(root)) { /* If pointer was on PointerRootWin and changes to NoneWin, and * the pointer paired with dev is below the current root window, * do a NotifyPointer run. */ if (dev->focus && dev->focus->win == PointerRootWin && - B != PointerRootWin) - { + B != PointerRootWin) { WindowPtr ptrwin = PointerWin(GetMaster(dev, POINTER_OR_FLOAT)); + if (ptrwin) - CoreFocusOutNotifyPointerEvents(dev, root, None, mode, TRUE); + CoreFocusOutNotifyPointerEvents(dev, root, None, mode, + TRUE); } - CoreFocusEvent(dev, FocusOut, mode, A ? NotifyPointerRoot : NotifyDetailNone, root); + CoreFocusEvent(dev, FocusOut, mode, + A ? NotifyPointerRoot : NotifyDetailNone, root); } } - root = B; /* get B's root window */ - while(root->parent) + root = B; /* get B's root window */ + while (root->parent) root = root->parent; - if (B != root) - { + if (B != root) { CoreFocusEvent(dev, FocusIn, mode, NotifyNonlinearVirtual, root); CoreFocusInEvents(dev, root, B, mode, NotifyNonlinearVirtual); } - - if (!HasFocus(B)) - { + if (!HasFocus(B)) { WindowPtr child = FirstFocusChild(B); - if (child) - { - CoreFocusEvent(dev, FocusIn, mode, NotifyInferior, B); - /* NotifyPointer B-P unless P is child or below. */ - CoreFocusInNotifyPointerEvents(dev, B, child, mode, FALSE); - } else { + + if (child) { + CoreFocusEvent(dev, FocusIn, mode, NotifyInferior, B); + /* NotifyPointer B-P unless P is child or below. */ + CoreFocusInNotifyPointerEvents(dev, B, child, mode, FALSE); + } + else { CoreFocusEvent(dev, FocusIn, mode, NotifyNonlinear, B); /* NotifyPointer B-P unless P is child or below. */ CoreFocusInNotifyPointerEvents(dev, B, None, mode, FALSE); @@ -1224,10 +1155,7 @@ CoreFocusFromPointerRootOrNone(DeviceIntPtr dev, } static void -CoreFocusEvents(DeviceIntPtr dev, - WindowPtr from, - WindowPtr to, - int mode) +CoreFocusEvents(DeviceIntPtr dev, WindowPtr from, WindowPtr to, int mode) { if (!IsMaster(dev)) return; @@ -1252,16 +1180,13 @@ CoreFocusEvents(DeviceIntPtr dev, } static void -DeviceFocusEvents(DeviceIntPtr dev, - WindowPtr from, - WindowPtr to, - int mode) +DeviceFocusEvents(DeviceIntPtr dev, WindowPtr from, WindowPtr to, int mode) { - int out, in; /* for holding details for to/from - PointerRoot/None */ + int out, in; /* for holding details for to/from + PointerRoot/None */ int i; int nscreens = screenInfo.numScreens; - SpritePtr sprite = dev->spriteInfo->sprite; + SpritePtr sprite = dev->spriteInfo->sprite; if (from == to) return; @@ -1274,96 +1199,95 @@ DeviceFocusEvents(DeviceIntPtr dev, nscreens = 1; #endif - if ((to == NullWindow) || (to == PointerRootWin)) - { - if ((from == NullWindow) || (from == PointerRootWin)) - { + if ((to == NullWindow) || (to == PointerRootWin)) { + if ((from == NullWindow) || (from == PointerRootWin)) { if (from == PointerRootWin) - DeviceFocusOutEvents(dev, sprite->win, GetCurrentRootWindow(dev), mode, - NotifyPointer); + DeviceFocusOutEvents(dev, sprite->win, + GetCurrentRootWindow(dev), mode, + NotifyPointer); /* Notify all the roots */ for (i = 0; i < nscreens; i++) - DeviceFocusEvent(dev, XI_FocusOut, mode, out, screenInfo.screens[i]->root); + DeviceFocusEvent(dev, XI_FocusOut, mode, out, + screenInfo.screens[i]->root); } - else - { + else { if (IsParent(from, sprite->win)) DeviceFocusOutEvents(dev, sprite->win, from, mode, - NotifyPointer); + NotifyPointer); DeviceFocusEvent(dev, XI_FocusOut, mode, NotifyNonlinear, from); /* next call catches the root too, if the screen changed */ DeviceFocusOutEvents(dev, from, NullWindow, mode, - NotifyNonlinearVirtual); + NotifyNonlinearVirtual); } /* Notify all the roots */ for (i = 0; i < nscreens; i++) - DeviceFocusEvent(dev, XI_FocusIn, mode, in, screenInfo.screens[i]->root); - if (to == PointerRootWin) - { - DeviceFocusInEvents(dev, GetCurrentRootWindow(dev), sprite->win, mode, NotifyPointer); + DeviceFocusEvent(dev, XI_FocusIn, mode, in, + screenInfo.screens[i]->root); + if (to == PointerRootWin) { + DeviceFocusInEvents(dev, GetCurrentRootWindow(dev), sprite->win, + mode, NotifyPointer); DeviceFocusEvent(dev, XI_FocusIn, mode, NotifyPointer, sprite->win); } } - else - { - if ((from == NullWindow) || (from == PointerRootWin)) - { + else { + if ((from == NullWindow) || (from == PointerRootWin)) { if (from == PointerRootWin) - DeviceFocusOutEvents(dev, sprite->win, GetCurrentRootWindow(dev), mode, - NotifyPointer); + DeviceFocusOutEvents(dev, sprite->win, + GetCurrentRootWindow(dev), mode, + NotifyPointer); for (i = 0; i < nscreens; i++) - DeviceFocusEvent(dev, XI_FocusOut, mode, out, screenInfo.screens[i]->root); + DeviceFocusEvent(dev, XI_FocusOut, mode, out, + screenInfo.screens[i]->root); if (to->parent != NullWindow) - DeviceFocusInEvents(dev, GetCurrentRootWindow(dev), to, mode, NotifyNonlinearVirtual); + DeviceFocusInEvents(dev, GetCurrentRootWindow(dev), to, mode, + NotifyNonlinearVirtual); DeviceFocusEvent(dev, XI_FocusIn, mode, NotifyNonlinear, to); if (IsParent(to, sprite->win)) DeviceFocusInEvents(dev, to, sprite->win, mode, NotifyPointer); } - else - { - if (IsParent(to, from)) - { + else { + if (IsParent(to, from)) { DeviceFocusEvent(dev, XI_FocusOut, mode, NotifyAncestor, from); - DeviceFocusOutEvents(dev, from, to, mode, - NotifyVirtual); + DeviceFocusOutEvents(dev, from, to, mode, NotifyVirtual); DeviceFocusEvent(dev, XI_FocusIn, mode, NotifyInferior, to); if ((IsParent(to, sprite->win)) && - (sprite->win != from) && - (!IsParent(from, sprite->win)) && - (!IsParent(sprite->win, from))) - DeviceFocusInEvents(dev, to, sprite->win, mode, NotifyPointer); + (sprite->win != from) && + (!IsParent(from, sprite->win)) && + (!IsParent(sprite->win, from))) + DeviceFocusInEvents(dev, to, sprite->win, mode, + NotifyPointer); + } + else if (IsParent(from, to)) { + if ((IsParent(from, sprite->win)) && + (sprite->win != from) && + (!IsParent(to, sprite->win)) && + (!IsParent(sprite->win, to))) + DeviceFocusOutEvents(dev, sprite->win, from, mode, + NotifyPointer); + DeviceFocusEvent(dev, XI_FocusOut, mode, NotifyInferior, from); + DeviceFocusInEvents(dev, from, to, mode, NotifyVirtual); + DeviceFocusEvent(dev, XI_FocusIn, mode, NotifyAncestor, to); + } + else { + /* neither from or to is child of other */ + WindowPtr common = CommonAncestor(to, from); + + /* common == NullWindow ==> different screens */ + if (IsParent(from, sprite->win)) + DeviceFocusOutEvents(dev, sprite->win, from, mode, + NotifyPointer); + DeviceFocusEvent(dev, XI_FocusOut, mode, NotifyNonlinear, from); + if (from->parent != NullWindow) + DeviceFocusOutEvents(dev, from, common, mode, + NotifyNonlinearVirtual); + if (to->parent != NullWindow) + DeviceFocusInEvents(dev, common, to, mode, + NotifyNonlinearVirtual); + DeviceFocusEvent(dev, XI_FocusIn, mode, NotifyNonlinear, to); + if (IsParent(to, sprite->win)) + DeviceFocusInEvents(dev, to, sprite->win, mode, + NotifyPointer); } - else - if (IsParent(from, to)) - { - if ((IsParent(from, sprite->win)) && - (sprite->win != from) && - (!IsParent(to, sprite->win)) && - (!IsParent(sprite->win, to))) - DeviceFocusOutEvents(dev, sprite->win, from, mode, - NotifyPointer); - DeviceFocusEvent(dev, XI_FocusOut, mode, NotifyInferior, from); - DeviceFocusInEvents(dev, from, to, mode, NotifyVirtual); - DeviceFocusEvent(dev, XI_FocusIn, mode, NotifyAncestor, to); - } - else - { - /* neither from or to is child of other */ - WindowPtr common = CommonAncestor(to, from); - /* common == NullWindow ==> different screens */ - if (IsParent(from, sprite->win)) - DeviceFocusOutEvents(dev, sprite->win, from, mode, - NotifyPointer); - DeviceFocusEvent(dev, XI_FocusOut, mode, NotifyNonlinear, from); - if (from->parent != NullWindow) - DeviceFocusOutEvents(dev, from, common, mode, - NotifyNonlinearVirtual); - if (to->parent != NullWindow) - DeviceFocusInEvents(dev, common, to, mode, NotifyNonlinearVirtual); - DeviceFocusEvent(dev, XI_FocusIn, mode, NotifyNonlinear, to); - if (IsParent(to, sprite->win)) - DeviceFocusInEvents(dev, to, sprite->win, mode, NotifyPointer); - } } } } @@ -1376,16 +1300,13 @@ DeviceFocusEvents(DeviceIntPtr dev, * @param to Window the focus moved into. */ void -DoFocusEvents(DeviceIntPtr pDev, - WindowPtr from, - WindowPtr to, - int mode) +DoFocusEvents(DeviceIntPtr pDev, WindowPtr from, WindowPtr to, int mode) { if (!IsKeyboardDevice(pDev)) return; if (from == to) - return; + return; CoreFocusEvents(pDev, from, to, mode); DeviceFocusEvents(pDev, from, to, mode); diff --git a/xorg-server/dix/enterleave.h b/xorg-server/dix/enterleave.h index 471f4efaa..c1729f8da 100644 --- a/xorg-server/dix/enterleave.h +++ b/xorg-server/dix/enterleave.h @@ -31,67 +31,40 @@ #ifndef ENTERLEAVE_H #define ENTERLEAVE_H -extern void DoEnterLeaveEvents( - DeviceIntPtr pDev, - int sourceid, - WindowPtr fromWin, - WindowPtr toWin, - int mode -); +extern void DoEnterLeaveEvents(DeviceIntPtr pDev, + int sourceid, + WindowPtr fromWin, WindowPtr toWin, int mode); -extern void DoFocusEvents( - DeviceIntPtr pDev, - WindowPtr fromWin, - WindowPtr toWin, - int mode -); +extern void DoFocusEvents(DeviceIntPtr pDev, + WindowPtr fromWin, WindowPtr toWin, int mode); -extern void EnterLeaveEvent( - DeviceIntPtr mouse, - int type, - int mode, - int detail, - WindowPtr pWin, - Window child); +extern void EnterLeaveEvent(DeviceIntPtr mouse, + int type, + int mode, int detail, WindowPtr pWin, Window child); -extern WindowPtr CommonAncestor( - WindowPtr a, - WindowPtr b); +extern WindowPtr CommonAncestor(WindowPtr a, WindowPtr b); extern void CoreEnterLeaveEvent(DeviceIntPtr mouse, int type, int mode, - int detail, - WindowPtr pWin, - Window child); + int detail, WindowPtr pWin, Window child); extern void DeviceEnterLeaveEvent(DeviceIntPtr mouse, int sourceid, int type, int mode, - int detail, - WindowPtr pWin, - Window child); + int detail, WindowPtr pWin, Window child); -extern void EnterWindow(DeviceIntPtr dev, - WindowPtr win, - int mode); +extern void EnterWindow(DeviceIntPtr dev, WindowPtr win, int mode); extern void LeaveWindow(DeviceIntPtr dev); extern void CoreFocusEvent(DeviceIntPtr kbd, - int type, - int mode, - int detail, - WindowPtr pWin); + int type, int mode, int detail, WindowPtr pWin); extern void DeviceFocusEvent(DeviceIntPtr kbd, - int type, - int mode, - int detail, - WindowPtr pWin); + int type, int mode, int detail, WindowPtr pWin); -extern void SetFocusIn(DeviceIntPtr kbd, - WindowPtr win); +extern void SetFocusIn(DeviceIntPtr kbd, WindowPtr win); extern void SetFocusOut(DeviceIntPtr dev); -#endif /* _ENTERLEAVE_H_ */ +#endif /* _ENTERLEAVE_H_ */ diff --git a/xorg-server/dix/eventconvert.c b/xorg-server/dix/eventconvert.c index 60dc22fff..41a3174a6 100644 --- a/xorg-server/dix/eventconvert.c +++ b/xorg-server/dix/eventconvert.c @@ -51,9 +51,8 @@ #include "xkbsrv.h" #include "inpututils.h" - static int countValuators(DeviceEvent *ev, int *first); -static int getValuatorEvents(DeviceEvent *ev, deviceValuator *xv); +static int getValuatorEvents(DeviceEvent *ev, deviceValuator * xv); static int eventToKeyButtonPointer(DeviceEvent *ev, xEvent **xi, int *count); static int eventToDeviceChanged(DeviceChangedEvent *ev, xEvent **dcce); static int eventToDeviceEvent(DeviceEvent *ev, xEvent **xi); @@ -85,7 +84,7 @@ EventSetKeyRepeatFlag(xEvent *event, BOOL on) BOOL EventIsKeyRepeat(xEvent *event) { - return !!event->u.u.sequenceNumber; + return ! !event->u.u.sequenceNumber; } /** @@ -107,74 +106,69 @@ EventToCore(InternalEvent *event, xEvent **core_out, int *count_out) int count = 0; int ret = BadImplementation; - switch(event->any.type) + switch (event->any.type) { + case ET_Motion: { - case ET_Motion: - { - DeviceEvent *e = &event->device_event; - /* Don't create core motion event if neither x nor y are - * present */ - if (!BitIsOn(e->valuators.mask, 0) && - !BitIsOn(e->valuators.mask, 1)) - { - ret = BadMatch; - goto out; - } - } - /* fallthrough */ - case ET_ButtonPress: - case ET_ButtonRelease: - case ET_KeyPress: - case ET_KeyRelease: - { - DeviceEvent *e = &event->device_event; - - if (e->detail.key > 0xFF) - { - ret = BadMatch; - goto out; - } - - core = calloc(1, sizeof(*core)); - if (!core) - return BadAlloc; - count = 1; - core->u.u.type = e->type - ET_KeyPress + KeyPress; - core->u.u.detail = e->detail.key & 0xFF; - core->u.keyButtonPointer.time = e->time; - core->u.keyButtonPointer.rootX = e->root_x; - core->u.keyButtonPointer.rootY = e->root_y; - core->u.keyButtonPointer.state = e->corestate; - core->u.keyButtonPointer.root = e->root; - EventSetKeyRepeatFlag(core, - (e->type == ET_KeyPress && - e->key_repeat)); - ret = Success; - } - break; - case ET_ProximityIn: - case ET_ProximityOut: - case ET_RawKeyPress: - case ET_RawKeyRelease: - case ET_RawButtonPress: - case ET_RawButtonRelease: - case ET_RawMotion: - case ET_RawTouchBegin: - case ET_RawTouchUpdate: - case ET_RawTouchEnd: - case ET_TouchBegin: - case ET_TouchUpdate: - case ET_TouchEnd: - case ET_TouchOwnership: + DeviceEvent *e = &event->device_event; + + /* Don't create core motion event if neither x nor y are + * present */ + if (!BitIsOn(e->valuators.mask, 0) && !BitIsOn(e->valuators.mask, 1)) { ret = BadMatch; - break; - default: - /* XXX: */ - ErrorF("[dix] EventToCore: Not implemented yet \n"); - ret = BadImplementation; + goto out; + } } + /* fallthrough */ + case ET_ButtonPress: + case ET_ButtonRelease: + case ET_KeyPress: + case ET_KeyRelease: + { + DeviceEvent *e = &event->device_event; -out: + if (e->detail.key > 0xFF) { + ret = BadMatch; + goto out; + } + + core = calloc(1, sizeof(*core)); + if (!core) + return BadAlloc; + count = 1; + core->u.u.type = e->type - ET_KeyPress + KeyPress; + core->u.u.detail = e->detail.key & 0xFF; + core->u.keyButtonPointer.time = e->time; + core->u.keyButtonPointer.rootX = e->root_x; + core->u.keyButtonPointer.rootY = e->root_y; + core->u.keyButtonPointer.state = e->corestate; + core->u.keyButtonPointer.root = e->root; + EventSetKeyRepeatFlag(core, (e->type == ET_KeyPress && e->key_repeat)); + ret = Success; + } + break; + case ET_ProximityIn: + case ET_ProximityOut: + case ET_RawKeyPress: + case ET_RawKeyRelease: + case ET_RawButtonPress: + case ET_RawButtonRelease: + case ET_RawMotion: + case ET_RawTouchBegin: + case ET_RawTouchUpdate: + case ET_RawTouchEnd: + case ET_TouchBegin: + case ET_TouchUpdate: + case ET_TouchEnd: + case ET_TouchOwnership: + ret = BadMatch; + break; + default: + /* XXX: */ + ErrorF("[dix] EventToCore: Not implemented yet \n"); + ret = BadImplementation; + } + + out: *core_out = core; *count_out = count; return ret; @@ -200,34 +194,33 @@ out: int EventToXI(InternalEvent *ev, xEvent **xi, int *count) { - switch (ev->any.type) - { - case ET_Motion: - case ET_ButtonPress: - case ET_ButtonRelease: - case ET_KeyPress: - case ET_KeyRelease: - case ET_ProximityIn: - case ET_ProximityOut: - return eventToKeyButtonPointer(&ev->device_event, xi, count); - case ET_DeviceChanged: - case ET_RawKeyPress: - case ET_RawKeyRelease: - case ET_RawButtonPress: - case ET_RawButtonRelease: - case ET_RawMotion: - case ET_RawTouchBegin: - case ET_RawTouchUpdate: - case ET_RawTouchEnd: - case ET_TouchBegin: - case ET_TouchUpdate: - case ET_TouchEnd: - case ET_TouchOwnership: - *count = 0; - *xi = NULL; - return BadMatch; - default: - break; + switch (ev->any.type) { + case ET_Motion: + case ET_ButtonPress: + case ET_ButtonRelease: + case ET_KeyPress: + case ET_KeyRelease: + case ET_ProximityIn: + case ET_ProximityOut: + return eventToKeyButtonPointer(&ev->device_event, xi, count); + case ET_DeviceChanged: + case ET_RawKeyPress: + case ET_RawKeyRelease: + case ET_RawButtonPress: + case ET_RawButtonRelease: + case ET_RawMotion: + case ET_RawTouchBegin: + case ET_RawTouchUpdate: + case ET_RawTouchEnd: + case ET_TouchBegin: + case ET_TouchUpdate: + case ET_TouchEnd: + case ET_TouchOwnership: + *count = 0; + *xi = NULL; + return BadMatch; + default: + break; } ErrorF("[dix] EventToXI: Not implemented for %d \n", ev->any.type); @@ -251,42 +244,41 @@ EventToXI(InternalEvent *ev, xEvent **xi, int *count) int EventToXI2(InternalEvent *ev, xEvent **xi) { - switch (ev->any.type) - { + switch (ev->any.type) { /* Enter/FocusIn are for grabs. We don't need an actual event, since * the real events delivered are triggered elsewhere */ - case ET_Enter: - case ET_FocusIn: - *xi = NULL; - return Success; - case ET_Motion: - case ET_ButtonPress: - case ET_ButtonRelease: - case ET_KeyPress: - case ET_KeyRelease: - case ET_TouchBegin: - case ET_TouchUpdate: - case ET_TouchEnd: - return eventToDeviceEvent(&ev->device_event, xi); - case ET_TouchOwnership: - return eventToTouchOwnershipEvent(&ev->touch_ownership_event, xi); - case ET_ProximityIn: - case ET_ProximityOut: - *xi = NULL; - return BadMatch; - case ET_DeviceChanged: - return eventToDeviceChanged(&ev->changed_event, xi); - case ET_RawKeyPress: - case ET_RawKeyRelease: - case ET_RawButtonPress: - case ET_RawButtonRelease: - case ET_RawMotion: - case ET_RawTouchBegin: - case ET_RawTouchUpdate: - case ET_RawTouchEnd: - return eventToRawEvent(&ev->raw_event, xi); - default: - break; + case ET_Enter: + case ET_FocusIn: + *xi = NULL; + return Success; + case ET_Motion: + case ET_ButtonPress: + case ET_ButtonRelease: + case ET_KeyPress: + case ET_KeyRelease: + case ET_TouchBegin: + case ET_TouchUpdate: + case ET_TouchEnd: + return eventToDeviceEvent(&ev->device_event, xi); + case ET_TouchOwnership: + return eventToTouchOwnershipEvent(&ev->touch_ownership_event, xi); + case ET_ProximityIn: + case ET_ProximityOut: + *xi = NULL; + return BadMatch; + case ET_DeviceChanged: + return eventToDeviceChanged(&ev->changed_event, xi); + case ET_RawKeyPress: + case ET_RawKeyRelease: + case ET_RawButtonPress: + case ET_RawButtonRelease: + case ET_RawMotion: + case ET_RawTouchBegin: + case ET_RawTouchUpdate: + case ET_RawTouchEnd: + return eventToRawEvent(&ev->raw_event, xi); + default: + break; } ErrorF("[dix] EventToXI2: Not implemented for %d \n", ev->any.type); @@ -297,83 +289,90 @@ static int eventToKeyButtonPointer(DeviceEvent *ev, xEvent **xi, int *count) { int num_events; - int first; /* dummy */ + int first; /* dummy */ deviceKeyButtonPointer *kbp; /* Sorry, XI 1.x protocol restrictions. */ - if (ev->detail.button > 0xFF || ev->deviceid >= 0x80) - { + if (ev->detail.button > 0xFF || ev->deviceid >= 0x80) { *count = 0; return Success; } - num_events = (countValuators(ev, &first) + 5)/6; /* valuator ev */ - if (num_events <= 0) - { - switch (ev->type) - { - case ET_KeyPress: - case ET_KeyRelease: - case ET_ButtonPress: - case ET_ButtonRelease: - /* no axes is ok */ - break; - case ET_Motion: - case ET_ProximityIn: - case ET_ProximityOut: - *count = 0; - return BadMatch; - default: - *count = 0; - return BadImplementation; + num_events = (countValuators(ev, &first) + 5) / 6; /* valuator ev */ + if (num_events <= 0) { + switch (ev->type) { + case ET_KeyPress: + case ET_KeyRelease: + case ET_ButtonPress: + case ET_ButtonRelease: + /* no axes is ok */ + break; + case ET_Motion: + case ET_ProximityIn: + case ET_ProximityOut: + *count = 0; + return BadMatch; + default: + *count = 0; + return BadImplementation; } } - num_events++; /* the actual event event */ + num_events++; /* the actual event event */ *xi = calloc(num_events, sizeof(xEvent)); - if (!(*xi)) - { + if (!(*xi)) { return BadAlloc; } - kbp = (deviceKeyButtonPointer*)(*xi); - kbp->detail = ev->detail.button; - kbp->time = ev->time; - kbp->root = ev->root; - kbp->root_x = ev->root_x; - kbp->root_y = ev->root_y; + kbp = (deviceKeyButtonPointer *) (*xi); + kbp->detail = ev->detail.button; + kbp->time = ev->time; + kbp->root = ev->root; + kbp->root_x = ev->root_x; + kbp->root_y = ev->root_y; kbp->deviceid = ev->deviceid; - kbp->state = ev->corestate; - EventSetKeyRepeatFlag((xEvent*)kbp, + kbp->state = ev->corestate; + EventSetKeyRepeatFlag((xEvent *) kbp, (ev->type == ET_KeyPress && ev->key_repeat)); if (num_events > 1) kbp->deviceid |= MORE_EVENTS; - switch(ev->type) - { - case ET_Motion: kbp->type = DeviceMotionNotify; break; - case ET_ButtonPress: kbp->type = DeviceButtonPress; break; - case ET_ButtonRelease: kbp->type = DeviceButtonRelease; break; - case ET_KeyPress: kbp->type = DeviceKeyPress; break; - case ET_KeyRelease: kbp->type = DeviceKeyRelease; break; - case ET_ProximityIn: kbp->type = ProximityIn; break; - case ET_ProximityOut: kbp->type = ProximityOut; break; - default: - break; + switch (ev->type) { + case ET_Motion: + kbp->type = DeviceMotionNotify; + break; + case ET_ButtonPress: + kbp->type = DeviceButtonPress; + break; + case ET_ButtonRelease: + kbp->type = DeviceButtonRelease; + break; + case ET_KeyPress: + kbp->type = DeviceKeyPress; + break; + case ET_KeyRelease: + kbp->type = DeviceKeyRelease; + break; + case ET_ProximityIn: + kbp->type = ProximityIn; + break; + case ET_ProximityOut: + kbp->type = ProximityOut; + break; + default: + break; } - if (num_events > 1) - { - getValuatorEvents(ev, (deviceValuator*)(kbp + 1)); + if (num_events > 1) { + getValuatorEvents(ev, (deviceValuator *) (kbp + 1)); } *count = num_events; return Success; } - /** * Set first to the first valuator in the event ev and return the number of * valuators from first to the last set valuator. @@ -384,18 +383,15 @@ countValuators(DeviceEvent *ev, int *first) int first_valuator = -1, last_valuator = -1, num_valuators = 0; int i; - for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++) - { - if (BitIsOn(ev->valuators.mask, i)) - { + for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++) { + if (BitIsOn(ev->valuators.mask, i)) { if (first_valuator == -1) first_valuator = i; last_valuator = i; } } - if (first_valuator != -1) - { + if (first_valuator != -1) { num_valuators = last_valuator - first_valuator + 1; *first = first_valuator; } @@ -404,25 +400,26 @@ countValuators(DeviceEvent *ev, int *first) } static int -getValuatorEvents(DeviceEvent *ev, deviceValuator *xv) +getValuatorEvents(DeviceEvent *ev, deviceValuator * xv) { int i; int state = 0; int first_valuator, num_valuators; - num_valuators = countValuators(ev, &first_valuator); - if (num_valuators > 0) - { + if (num_valuators > 0) { DeviceIntPtr dev = NULL; + dixLookupDevice(&dev, ev->deviceid, serverClient, DixUseAccess); /* State needs to be assembled BEFORE the device is updated. */ - state = (dev && dev->key) ? XkbStateFieldFromRec(&dev->key->xkbInfo->state) : 0; + state = (dev && + dev->key) ? XkbStateFieldFromRec(&dev->key->xkbInfo-> + state) : 0; state |= (dev && dev->button) ? (dev->button->state) : 0; } for (i = 0; i < num_valuators; i += 6, xv++) { - INT32 *valuators = &xv->valuator0; // Treat all 6 vals as an array + INT32 *valuators = &xv->valuator0; // Treat all 6 vals as an array int j; xv->type = DeviceValuator; @@ -443,19 +440,18 @@ getValuatorEvents(DeviceEvent *ev, deviceValuator *xv) return (num_valuators + 5) / 6; } - static int -appendKeyInfo(DeviceChangedEvent *dce, xXIKeyInfo* info) +appendKeyInfo(DeviceChangedEvent *dce, xXIKeyInfo * info) { uint32_t *kc; int i; info->type = XIKeyClass; info->num_keycodes = dce->keys.max_keycode - dce->keys.min_keycode + 1; - info->length = sizeof(xXIKeyInfo)/4 + info->num_keycodes; + info->length = sizeof(xXIKeyInfo) / 4 + info->num_keycodes; info->sourceid = dce->sourceid; - kc = (uint32_t*)&info[1]; + kc = (uint32_t *) & info[1]; for (i = 0; i < info->num_keycodes; i++) *kc++ = i + dce->keys.min_keycode; @@ -463,7 +459,7 @@ appendKeyInfo(DeviceChangedEvent *dce, xXIKeyInfo* info) } static int -appendButtonInfo(DeviceChangedEvent *dce, xXIButtonInfo *info) +appendButtonInfo(DeviceChangedEvent *dce, xXIButtonInfo * info) { unsigned char *bits; int mask_len; @@ -473,10 +469,10 @@ appendButtonInfo(DeviceChangedEvent *dce, xXIButtonInfo *info) info->type = XIButtonClass; info->num_buttons = dce->buttons.num_buttons; info->length = bytes_to_int32(sizeof(xXIButtonInfo)) + - info->num_buttons + mask_len; + info->num_buttons + mask_len; info->sourceid = dce->sourceid; - bits = (unsigned char*)&info[1]; + bits = (unsigned char *) &info[1]; memset(bits, 0, mask_len * 4); /* FIXME: is_down? */ @@ -487,10 +483,11 @@ appendButtonInfo(DeviceChangedEvent *dce, xXIButtonInfo *info) } static int -appendValuatorInfo(DeviceChangedEvent *dce, xXIValuatorInfo *info, int axisnumber) +appendValuatorInfo(DeviceChangedEvent *dce, xXIValuatorInfo * info, + int axisnumber) { info->type = XIValuatorClass; - info->length = sizeof(xXIValuatorInfo)/4; + info->length = sizeof(xXIValuatorInfo) / 4; info->label = dce->valuators[axisnumber].name; info->min.integral = dce->valuators[axisnumber].min; info->min.frac = 0; @@ -508,27 +505,28 @@ appendValuatorInfo(DeviceChangedEvent *dce, xXIValuatorInfo *info, int axisnumbe } static int -appendScrollInfo(DeviceChangedEvent *dce, xXIScrollInfo *info, int axisnumber) +appendScrollInfo(DeviceChangedEvent *dce, xXIScrollInfo * info, int axisnumber) { if (dce->valuators[axisnumber].scroll.type == SCROLL_TYPE_NONE) return 0; info->type = XIScrollClass; - info->length = sizeof(xXIScrollInfo)/4; + info->length = sizeof(xXIScrollInfo) / 4; info->number = axisnumber; - switch(dce->valuators[axisnumber].scroll.type) - { - case SCROLL_TYPE_VERTICAL: - info->scroll_type = XIScrollTypeVertical; - break; - case SCROLL_TYPE_HORIZONTAL: - info->scroll_type = XIScrollTypeHorizontal; - break; - default: - ErrorF("[Xi] Unknown scroll type %d. This is a bug.\n", dce->valuators[axisnumber].scroll.type); - break; + switch (dce->valuators[axisnumber].scroll.type) { + case SCROLL_TYPE_VERTICAL: + info->scroll_type = XIScrollTypeVertical; + break; + case SCROLL_TYPE_HORIZONTAL: + info->scroll_type = XIScrollTypeHorizontal; + break; + default: + ErrorF("[Xi] Unknown scroll type %d. This is a bug.\n", + dce->valuators[axisnumber].scroll.type); + break; } - info->increment = double_to_fp3232(dce->valuators[axisnumber].scroll.increment); + info->increment = + double_to_fp3232(dce->valuators[axisnumber].scroll.increment); info->sourceid = dce->sourceid; info->flags = 0; @@ -549,14 +547,12 @@ eventToDeviceChanged(DeviceChangedEvent *dce, xEvent **xi) int nkeys; char *ptr; - if (dce->buttons.num_buttons) - { + if (dce->buttons.num_buttons) { len += sizeof(xXIButtonInfo); len += dce->buttons.num_buttons * sizeof(Atom); /* button names */ len += pad_to_int32(bits_to_bytes(dce->buttons.num_buttons)); } - if (dce->num_valuators) - { + if (dce->num_valuators) { int i; len += sizeof(xXIValuatorInfo) * dce->num_valuators; @@ -567,77 +563,70 @@ eventToDeviceChanged(DeviceChangedEvent *dce, xEvent **xi) } nkeys = (dce->keys.max_keycode > 0) ? - dce->keys.max_keycode - dce->keys.min_keycode + 1 : 0; - if (nkeys > 0) - { + dce->keys.max_keycode - dce->keys.min_keycode + 1 : 0; + if (nkeys > 0) { len += sizeof(xXIKeyInfo); - len += sizeof(CARD32) * nkeys; /* keycodes */ + len += sizeof(CARD32) * nkeys; /* keycodes */ } dcce = calloc(1, len); - if (!dcce) - { + if (!dcce) { ErrorF("[Xi] BadAlloc in SendDeviceChangedEvent.\n"); return BadAlloc; } - dcce->type = GenericEvent; - dcce->extension = IReqCode; - dcce->evtype = XI_DeviceChanged; - dcce->time = dce->time; - dcce->deviceid = dce->deviceid; - dcce->sourceid = dce->sourceid; - dcce->reason = (dce->flags & DEVCHANGE_DEVICE_CHANGE) ? XIDeviceChange : XISlaveSwitch; - dcce->num_classes = 0; + dcce->type = GenericEvent; + dcce->extension = IReqCode; + dcce->evtype = XI_DeviceChanged; + dcce->time = dce->time; + dcce->deviceid = dce->deviceid; + dcce->sourceid = dce->sourceid; + dcce->reason = + (dce->flags & DEVCHANGE_DEVICE_CHANGE) ? XIDeviceChange : XISlaveSwitch; + dcce->num_classes = 0; dcce->length = bytes_to_int32(len - sizeof(xEvent)); - ptr = (char*)&dcce[1]; - if (dce->buttons.num_buttons) - { + ptr = (char *) &dcce[1]; + if (dce->buttons.num_buttons) { dcce->num_classes++; - ptr += appendButtonInfo(dce, (xXIButtonInfo*)ptr); + ptr += appendButtonInfo(dce, (xXIButtonInfo *) ptr); } - if (nkeys) - { + if (nkeys) { dcce->num_classes++; - ptr += appendKeyInfo(dce, (xXIKeyInfo*)ptr); + ptr += appendKeyInfo(dce, (xXIKeyInfo *) ptr); } - if (dce->num_valuators) - { + if (dce->num_valuators) { int i; dcce->num_classes += dce->num_valuators; for (i = 0; i < dce->num_valuators; i++) - ptr += appendValuatorInfo(dce, (xXIValuatorInfo*)ptr, i); + ptr += appendValuatorInfo(dce, (xXIValuatorInfo *) ptr, i); - for (i = 0; i < dce->num_valuators; i++) - { - if (dce->valuators[i].scroll.type != SCROLL_TYPE_NONE) - { + for (i = 0; i < dce->num_valuators; i++) { + if (dce->valuators[i].scroll.type != SCROLL_TYPE_NONE) { dcce->num_classes++; - ptr += appendScrollInfo(dce, (xXIScrollInfo*)ptr, i); + ptr += appendScrollInfo(dce, (xXIScrollInfo *) ptr, i); } } } - *xi = (xEvent*)dcce; + *xi = (xEvent *) dcce; return Success; } -static int count_bits(unsigned char* ptr, int len) +static int +count_bits(unsigned char *ptr, int len) { int bits = 0; unsigned int i; unsigned char x; - for (i = 0; i < len; i++) - { + for (i = 0; i < len; i++) { x = ptr[i]; - while(x > 0) - { + while (x > 0) { bits += (x & 0x1); x >>= 1; } @@ -658,69 +647,67 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi) * with MAX_VALUATORS below */ /* btlen is in 4 byte units */ btlen = bytes_to_int32(bits_to_bytes(MAX_BUTTONS)); - len += btlen * 4; /* buttonmask len */ + len += btlen * 4; /* buttonmask len */ - - vallen = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)/sizeof(ev->valuators.mask[0])); - len += vallen * 2 * sizeof(uint32_t); /* axisvalues */ + vallen = + count_bits(ev->valuators.mask, + sizeof(ev->valuators.mask) / sizeof(ev->valuators.mask[0])); + len += vallen * 2 * sizeof(uint32_t); /* axisvalues */ vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS)); - len += vallen * 4; /* valuators mask */ + len += vallen * 4; /* valuators mask */ *xi = calloc(1, len); - xde = (xXIDeviceEvent*)*xi; - xde->type = GenericEvent; - xde->extension = IReqCode; - xde->evtype = GetXI2Type(ev->type); - xde->time = ev->time; - xde->length = bytes_to_int32(len - sizeof(xEvent)); - if (IsTouchEvent((InternalEvent*)ev)) - xde->detail = ev->touchid; + xde = (xXIDeviceEvent *) * xi; + xde->type = GenericEvent; + xde->extension = IReqCode; + xde->evtype = GetXI2Type(ev->type); + xde->time = ev->time; + xde->length = bytes_to_int32(len - sizeof(xEvent)); + if (IsTouchEvent((InternalEvent *) ev)) + xde->detail = ev->touchid; else - xde->detail = ev->detail.button; + xde->detail = ev->detail.button; - xde->root = ev->root; - xde->buttons_len = btlen; - xde->valuators_len = vallen; - xde->deviceid = ev->deviceid; - xde->sourceid = ev->sourceid; - xde->root_x = FP1616(ev->root_x, ev->root_x_frac); - xde->root_y = FP1616(ev->root_y, ev->root_y_frac); + xde->root = ev->root; + xde->buttons_len = btlen; + xde->valuators_len = vallen; + xde->deviceid = ev->deviceid; + xde->sourceid = ev->sourceid; + xde->root_x = FP1616(ev->root_x, ev->root_x_frac); + xde->root_y = FP1616(ev->root_y, ev->root_y_frac); if (ev->type == ET_TouchUpdate) xde->flags |= (ev->flags & TOUCH_PENDING_END) ? XITouchPendingEnd : 0; else xde->flags = ev->flags; - if (IsTouchEvent((InternalEvent*)ev) && + if (IsTouchEvent((InternalEvent *) ev) && ev->flags & TOUCH_POINTER_EMULATED) xde->flags |= XITouchEmulatingPointer; if (ev->key_repeat) - xde->flags |= XIKeyRepeat; + xde->flags |= XIKeyRepeat; - xde->mods.base_mods = ev->mods.base; - xde->mods.latched_mods = ev->mods.latched; - xde->mods.locked_mods = ev->mods.locked; - xde->mods.effective_mods = ev->mods.effective; + xde->mods.base_mods = ev->mods.base; + xde->mods.latched_mods = ev->mods.latched; + xde->mods.locked_mods = ev->mods.locked; + xde->mods.effective_mods = ev->mods.effective; - xde->group.base_group = ev->group.base; - xde->group.latched_group = ev->group.latched; - xde->group.locked_group = ev->group.locked; - xde->group.effective_group = ev->group.effective; + xde->group.base_group = ev->group.base; + xde->group.latched_group = ev->group.latched; + xde->group.locked_group = ev->group.locked; + xde->group.effective_group = ev->group.effective; - ptr = (char*)&xde[1]; - for (i = 0; i < sizeof(ev->buttons) * 8; i++) - { + ptr = (char *) &xde[1]; + for (i = 0; i < sizeof(ev->buttons) * 8; i++) { if (BitIsOn(ev->buttons, i)) SetBit(ptr, i); } ptr += xde->buttons_len * 4; - axisval = (FP3232*)(ptr + xde->valuators_len * 4); - for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++) - { - if (BitIsOn(ev->valuators.mask, i)) - { + axisval = (FP3232 *) (ptr + xde->valuators_len * 4); + for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++) { + if (BitIsOn(ev->valuators.mask, i)) { SetBit(ptr, i); *axisval = double_to_fp3232(ev->valuators.data[i]); axisval++; @@ -737,16 +724,16 @@ eventToTouchOwnershipEvent(TouchOwnershipEvent *ev, xEvent **xi) xXITouchOwnershipEvent *xtoe; *xi = calloc(1, len); - xtoe = (xXITouchOwnershipEvent*)*xi; - xtoe->type = GenericEvent; - xtoe->extension = IReqCode; - xtoe->length = bytes_to_int32(len - sizeof(xEvent)); - xtoe->evtype = GetXI2Type(ev->type); - xtoe->deviceid = ev->deviceid; - xtoe->time = ev->time; - xtoe->sourceid = ev->sourceid; - xtoe->touchid = ev->touchid; - xtoe->flags = 0; /* we don't have wire flags for ownership yet */ + xtoe = (xXITouchOwnershipEvent *) * xi; + xtoe->type = GenericEvent; + xtoe->extension = IReqCode; + xtoe->length = bytes_to_int32(len - sizeof(xEvent)); + xtoe->evtype = GetXI2Type(ev->type); + xtoe->deviceid = ev->deviceid; + xtoe->time = ev->time; + xtoe->sourceid = ev->sourceid; + xtoe->touchid = ev->touchid; + xtoe->flags = 0; /* we don't have wire flags for ownership yet */ return Success; } @@ -754,40 +741,38 @@ eventToTouchOwnershipEvent(TouchOwnershipEvent *ev, xEvent **xi) static int eventToRawEvent(RawDeviceEvent *ev, xEvent **xi) { - xXIRawEvent* raw; + xXIRawEvent *raw; int vallen, nvals; int i, len = sizeof(xXIRawEvent); char *ptr; FP3232 *axisval, *axisval_raw; nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)); - len += nvals * sizeof(FP3232) * 2; /* 8 byte per valuator, once - raw, once processed */ + len += nvals * sizeof(FP3232) * 2; /* 8 byte per valuator, once + raw, once processed */ vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS)); - len += vallen * 4; /* valuators mask */ + len += vallen * 4; /* valuators mask */ *xi = calloc(1, len); - raw = (xXIRawEvent*)*xi; - raw->type = GenericEvent; - raw->extension = IReqCode; - raw->evtype = GetXI2Type(ev->type); - raw->time = ev->time; - raw->length = bytes_to_int32(len - sizeof(xEvent)); - raw->detail = ev->detail.button; - raw->deviceid = ev->deviceid; - raw->sourceid = ev->sourceid; - raw->valuators_len = vallen; - raw->flags = ev->flags; - - ptr = (char*)&raw[1]; - axisval = (FP3232*)(ptr + raw->valuators_len * 4); + raw = (xXIRawEvent *) * xi; + raw->type = GenericEvent; + raw->extension = IReqCode; + raw->evtype = GetXI2Type(ev->type); + raw->time = ev->time; + raw->length = bytes_to_int32(len - sizeof(xEvent)); + raw->detail = ev->detail.button; + raw->deviceid = ev->deviceid; + raw->sourceid = ev->sourceid; + raw->valuators_len = vallen; + raw->flags = ev->flags; + + ptr = (char *) &raw[1]; + axisval = (FP3232 *) (ptr + raw->valuators_len * 4); axisval_raw = axisval + nvals; - for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++) - { - if (BitIsOn(ev->valuators.mask, i)) - { + for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++) { + if (BitIsOn(ev->valuators.mask, i)) { SetBit(ptr, i); - *axisval = double_to_fp3232(ev->valuators.data[i]); + *axisval = double_to_fp3232(ev->valuators.data[i]); *axisval_raw = double_to_fp3232(ev->valuators.data_raw[i]); axisval++; axisval_raw++; @@ -805,15 +790,25 @@ int GetCoreType(enum EventType type) { int coretype = 0; - switch(type) - { - case ET_Motion: coretype = MotionNotify; break; - case ET_ButtonPress: coretype = ButtonPress; break; - case ET_ButtonRelease: coretype = ButtonRelease; break; - case ET_KeyPress: coretype = KeyPress; break; - case ET_KeyRelease: coretype = KeyRelease; break; - default: - break; + + switch (type) { + case ET_Motion: + coretype = MotionNotify; + break; + case ET_ButtonPress: + coretype = ButtonPress; + break; + case ET_ButtonRelease: + coretype = ButtonRelease; + break; + case ET_KeyPress: + coretype = KeyPress; + break; + case ET_KeyRelease: + coretype = KeyRelease; + break; + default: + break; } return coretype; } @@ -826,17 +821,31 @@ int GetXIType(enum EventType type) { int xitype = 0; - switch(type) - { - case ET_Motion: xitype = DeviceMotionNotify; break; - case ET_ButtonPress: xitype = DeviceButtonPress; break; - case ET_ButtonRelease: xitype = DeviceButtonRelease; break; - case ET_KeyPress: xitype = DeviceKeyPress; break; - case ET_KeyRelease: xitype = DeviceKeyRelease; break; - case ET_ProximityIn: xitype = ProximityIn; break; - case ET_ProximityOut: xitype = ProximityOut; break; - default: - break; + + switch (type) { + case ET_Motion: + xitype = DeviceMotionNotify; + break; + case ET_ButtonPress: + xitype = DeviceButtonPress; + break; + case ET_ButtonRelease: + xitype = DeviceButtonRelease; + break; + case ET_KeyPress: + xitype = DeviceKeyPress; + break; + case ET_KeyRelease: + xitype = DeviceKeyRelease; + break; + case ET_ProximityIn: + xitype = ProximityIn; + break; + case ET_ProximityOut: + xitype = ProximityOut; + break; + default: + break; } return xitype; } @@ -850,33 +859,78 @@ GetXI2Type(enum EventType type) { int xi2type = 0; - switch(type) - { - case ET_Motion: xi2type = XI_Motion; break; - case ET_ButtonPress: xi2type = XI_ButtonPress; break; - case ET_ButtonRelease: xi2type = XI_ButtonRelease; break; - case ET_KeyPress: xi2type = XI_KeyPress; break; - case ET_KeyRelease: xi2type = XI_KeyRelease; break; - case ET_Enter: xi2type = XI_Enter; break; - case ET_Leave: xi2type = XI_Leave; break; - case ET_Hierarchy: xi2type = XI_HierarchyChanged; break; - case ET_DeviceChanged: xi2type = XI_DeviceChanged; break; - case ET_RawKeyPress: xi2type = XI_RawKeyPress; break; - case ET_RawKeyRelease: xi2type = XI_RawKeyRelease; break; - case ET_RawButtonPress: xi2type = XI_RawButtonPress; break; - case ET_RawButtonRelease: xi2type = XI_RawButtonRelease; break; - case ET_RawMotion: xi2type = XI_RawMotion; break; - case ET_RawTouchBegin: xi2type = XI_RawTouchBegin; break; - case ET_RawTouchUpdate: xi2type = XI_RawTouchUpdate; break; - case ET_RawTouchEnd: xi2type = XI_RawTouchEnd; break; - case ET_FocusIn: xi2type = XI_FocusIn; break; - case ET_FocusOut: xi2type = XI_FocusOut; break; - case ET_TouchBegin: xi2type = XI_TouchBegin; break; - case ET_TouchEnd: xi2type = XI_TouchEnd; break; - case ET_TouchUpdate: xi2type = XI_TouchUpdate; break; - case ET_TouchOwnership: xi2type = XI_TouchOwnership; break; - default: - break; + switch (type) { + case ET_Motion: + xi2type = XI_Motion; + break; + case ET_ButtonPress: + xi2type = XI_ButtonPress; + break; + case ET_ButtonRelease: + xi2type = XI_ButtonRelease; + break; + case ET_KeyPress: + xi2type = XI_KeyPress; + break; + case ET_KeyRelease: + xi2type = XI_KeyRelease; + break; + case ET_Enter: + xi2type = XI_Enter; + break; + case ET_Leave: + xi2type = XI_Leave; + break; + case ET_Hierarchy: + xi2type = XI_HierarchyChanged; + break; + case ET_DeviceChanged: + xi2type = XI_DeviceChanged; + break; + case ET_RawKeyPress: + xi2type = XI_RawKeyPress; + break; + case ET_RawKeyRelease: + xi2type = XI_RawKeyRelease; + break; + case ET_RawButtonPress: + xi2type = XI_RawButtonPress; + break; + case ET_RawButtonRelease: + xi2type = XI_RawButtonRelease; + break; + case ET_RawMotion: + xi2type = XI_RawMotion; + break; + case ET_RawTouchBegin: + xi2type = XI_RawTouchBegin; + break; + case ET_RawTouchUpdate: + xi2type = XI_RawTouchUpdate; + break; + case ET_RawTouchEnd: + xi2type = XI_RawTouchEnd; + break; + case ET_FocusIn: + xi2type = XI_FocusIn; + break; + case ET_FocusOut: + xi2type = XI_FocusOut; + break; + case ET_TouchBegin: + xi2type = XI_TouchBegin; + break; + case ET_TouchEnd: + xi2type = XI_TouchEnd; + break; + case ET_TouchUpdate: + xi2type = XI_TouchUpdate; + break; + case ET_TouchOwnership: + xi2type = XI_TouchOwnership; + break; + default: + break; } return xi2type; } diff --git a/xorg-server/dix/events.c b/xorg-server/dix/events.c index 924479582..447094757 100644 --- a/xorg-server/dix/events.c +++ b/xorg-server/dix/events.c @@ -22,7 +22,6 @@ 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 @@ -130,6 +129,7 @@ Equipment Corporation. #ifdef XSERVER_DTRACE #include <sys/types.h> typedef const char *string; + #include "Xserver-dtrace.h" #endif @@ -155,7 +155,7 @@ typedef const char *string; #include "mi.h" /* Extension events type numbering starts at EXTENSION_EVENT_BASE. */ -#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ +#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ #define StructureAndSubMask ( StructureNotifyMask | SubstructureNotifyMask ) #define AllButtonsMask ( \ Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) @@ -177,7 +177,6 @@ typedef const char *string; #define LastEventMask OwnerGrabButtonMask #define AllEventMasks (LastEventMask|(LastEventMask-1)) - /* @return the core event type or 0 if the event is not a core event */ static inline int core_get_type(const xEvent *event) @@ -191,9 +190,10 @@ core_get_type(const xEvent *event) static inline int xi2_get_type(const xEvent *event) { - const xGenericEvent* e = (const xGenericEvent*)event; + const xGenericEvent *e = (const xGenericEvent *) event; - return (e->type != GenericEvent || e->extension != IReqCode) ? 0 : e->evtype; + return (e->type != GenericEvent || + e->extension != IReqCode) ? 0 : e->evtype; } /** @@ -206,7 +206,6 @@ xi2_get_type(const xEvent *event) #define XE_KBPTR (xE->u.keyButtonPointer) - CallbackListPtr EventCallback; CallbackListPtr DeviceEventCallback; @@ -215,11 +214,10 @@ CallbackListPtr DeviceEventCallback; Mask DontPropagateMasks[DNPMCOUNT]; static int DontPropagateRefCnts[DNPMCOUNT]; -static void CheckVirtualMotion( DeviceIntPtr pDev, QdEventPtr qe, WindowPtr pWin); -static void CheckPhysLimits(DeviceIntPtr pDev, - CursorPtr cursor, - Bool generateEvents, - Bool confineToScreen, +static void CheckVirtualMotion(DeviceIntPtr pDev, QdEventPtr qe, + WindowPtr pWin); +static void CheckPhysLimits(DeviceIntPtr pDev, CursorPtr cursor, + Bool generateEvents, Bool confineToScreen, ScreenPtr pScreen); /** Key repeat hack. Do not use but in TryClientEvents */ @@ -266,7 +264,7 @@ EventSyncInfoRec syncEvents; */ #define RootWindow(sprite) sprite->spriteTrace[0] -static xEvent* swapEvent = NULL; +static xEvent *swapEvent = NULL; static int swapEventLen = 0; void @@ -284,6 +282,7 @@ int XItoCoreType(int xitype) { int coretype = 0; + if (xitype == DeviceMotionNotify) coretype = MotionNotify; else if (xitype == DeviceButtonPress) @@ -316,8 +315,7 @@ Bool IsPointerDevice(DeviceIntPtr dev) { return (dev->type == MASTER_POINTER) || - (dev->valuator && dev->button) || - (dev->valuator && !dev->key); + (dev->valuator && dev->button) || (dev->valuator && !dev->key); } /* @@ -331,7 +329,7 @@ Bool IsKeyboardDevice(DeviceIntPtr dev) { return (dev->type == MASTER_KEYBOARD) || - ((dev->key && dev->kbdfeed) && !IsPointerDevice(dev)); + ((dev->key && dev->kbdfeed) && !IsPointerDevice(dev)); } Bool @@ -343,10 +341,9 @@ IsMaster(DeviceIntPtr dev) Bool IsFloating(DeviceIntPtr dev) { - return GetMaster(dev, MASTER_KEYBOARD) == NULL; + return !IsMaster(dev) && GetMaster(dev, MASTER_KEYBOARD) == NULL; } - /** * Max event opcode. */ @@ -370,43 +367,42 @@ extern int DeviceMotionNotify; */ Mask event_filters[MAXDEVICES][MAXEVENTS]; -static const Mask default_filter[MAXEVENTS] = -{ - NoSuchEvent, /* 0 */ - NoSuchEvent, /* 1 */ - KeyPressMask, /* KeyPress */ - KeyReleaseMask, /* KeyRelease */ - ButtonPressMask, /* ButtonPress */ - ButtonReleaseMask, /* ButtonRelease */ - PointerMotionMask, /* MotionNotify (initial state) */ - EnterWindowMask, /* EnterNotify */ - LeaveWindowMask, /* LeaveNotify */ - FocusChangeMask, /* FocusIn */ - FocusChangeMask, /* FocusOut */ - KeymapStateMask, /* KeymapNotify */ - ExposureMask, /* Expose */ - CantBeFiltered, /* GraphicsExpose */ - CantBeFiltered, /* NoExpose */ - VisibilityChangeMask, /* VisibilityNotify */ - SubstructureNotifyMask, /* CreateNotify */ - StructureAndSubMask, /* DestroyNotify */ - StructureAndSubMask, /* UnmapNotify */ - StructureAndSubMask, /* MapNotify */ - SubstructureRedirectMask, /* MapRequest */ - StructureAndSubMask, /* ReparentNotify */ - StructureAndSubMask, /* ConfigureNotify */ - SubstructureRedirectMask, /* ConfigureRequest */ - StructureAndSubMask, /* GravityNotify */ - ResizeRedirectMask, /* ResizeRequest */ - StructureAndSubMask, /* CirculateNotify */ - SubstructureRedirectMask, /* CirculateRequest */ - PropertyChangeMask, /* PropertyNotify */ - CantBeFiltered, /* SelectionClear */ - CantBeFiltered, /* SelectionRequest */ - CantBeFiltered, /* SelectionNotify */ - ColormapChangeMask, /* ColormapNotify */ - CantBeFiltered, /* ClientMessage */ - CantBeFiltered /* MappingNotify */ +static const Mask default_filter[MAXEVENTS] = { + NoSuchEvent, /* 0 */ + NoSuchEvent, /* 1 */ + KeyPressMask, /* KeyPress */ + KeyReleaseMask, /* KeyRelease */ + ButtonPressMask, /* ButtonPress */ + ButtonReleaseMask, /* ButtonRelease */ + PointerMotionMask, /* MotionNotify (initial state) */ + EnterWindowMask, /* EnterNotify */ + LeaveWindowMask, /* LeaveNotify */ + FocusChangeMask, /* FocusIn */ + FocusChangeMask, /* FocusOut */ + KeymapStateMask, /* KeymapNotify */ + ExposureMask, /* Expose */ + CantBeFiltered, /* GraphicsExpose */ + CantBeFiltered, /* NoExpose */ + VisibilityChangeMask, /* VisibilityNotify */ + SubstructureNotifyMask, /* CreateNotify */ + StructureAndSubMask, /* DestroyNotify */ + StructureAndSubMask, /* UnmapNotify */ + StructureAndSubMask, /* MapNotify */ + SubstructureRedirectMask, /* MapRequest */ + StructureAndSubMask, /* ReparentNotify */ + StructureAndSubMask, /* ConfigureNotify */ + SubstructureRedirectMask, /* ConfigureRequest */ + StructureAndSubMask, /* GravityNotify */ + ResizeRedirectMask, /* ResizeRequest */ + StructureAndSubMask, /* CirculateNotify */ + SubstructureRedirectMask, /* CirculateRequest */ + PropertyChangeMask, /* PropertyNotify */ + CantBeFiltered, /* SelectionClear */ + CantBeFiltered, /* SelectionRequest */ + CantBeFiltered, /* SelectionNotify */ + ColormapChangeMask, /* ColormapNotify */ + CantBeFiltered, /* ClientMessage */ + CantBeFiltered /* MappingNotify */ }; /** @@ -453,13 +449,12 @@ GetXI2MaskByte(XI2Mask *mask, DeviceIntPtr dev, int event_type) return 0; } - /** * @return TRUE if the mask is set for this event from this device on the * window, or FALSE otherwise. */ Bool -WindowXI2MaskIsset(DeviceIntPtr dev, WindowPtr win, xEvent* ev) +WindowXI2MaskIsset(DeviceIntPtr dev, WindowPtr win, xEvent *ev) { OtherInputMasks *inputMasks = wOtherInputMasks(win); int evtype; @@ -467,34 +462,33 @@ WindowXI2MaskIsset(DeviceIntPtr dev, WindowPtr win, xEvent* ev) if (!inputMasks || xi2_get_type(ev) == 0) return 0; - evtype = ((xGenericEvent*)ev)->evtype; + evtype = ((xGenericEvent *) ev)->evtype; return xi2mask_isset(inputMasks->xi2mask, dev, evtype); } Mask -GetEventMask(DeviceIntPtr dev, xEvent *event, InputClients* other) +GetEventMask(DeviceIntPtr dev, xEvent *event, InputClients * other) { int evtype; /* XI2 filters are only ever 8 bit, so let's return a 8 bit mask */ - if ((evtype = xi2_get_type(event))) - { + if ((evtype = xi2_get_type(event))) { return GetXI2MaskByte(other->xi2mask, dev, evtype); - } else if (core_get_type(event) != 0) + } + else if (core_get_type(event) != 0) return other->mask[XIAllDevices]; else return other->mask[dev->id]; } - -static CARD8 criticalEvents[32] = -{ - 0x7c, 0x30, 0x40 /* key, button, expose, and configure events */ +static CARD8 criticalEvents[32] = { + 0x7c, 0x30, 0x40 /* key, button, expose, and configure events */ }; static void -SyntheticMotion(DeviceIntPtr dev, int x, int y) { +SyntheticMotion(DeviceIntPtr dev, int x, int y) +{ int screenno = 0; #ifdef PANORAMIX @@ -502,7 +496,8 @@ SyntheticMotion(DeviceIntPtr dev, int x, int y) { screenno = dev->spriteInfo->sprite->screen->myNum; #endif PostSyntheticMotion(dev, x, y, screenno, - (syncEvents.playingEvents) ? syncEvents.time.milliseconds : currentTime.milliseconds); + (syncEvents.playingEvents) ? syncEvents.time. + milliseconds : currentTime.milliseconds); } @@ -510,12 +505,8 @@ SyntheticMotion(DeviceIntPtr dev, int x, int y) { static void PostNewCursor(DeviceIntPtr pDev); static Bool -XineramaSetCursorPosition( - DeviceIntPtr pDev, - int x, - int y, - Bool generateEvent -){ +XineramaSetCursorPosition(DeviceIntPtr pDev, int x, int y, Bool generateEvent) +{ ScreenPtr pScreen; int i; SpritePtr pSprite = pDev->spriteInfo->sprite; @@ -528,18 +519,15 @@ XineramaSetCursorPosition( x += screenInfo.screens[0]->x; y += screenInfo.screens[0]->y; - if(!point_on_screen(pScreen, x, y)) - { - FOR_NSCREENS(i) - { - if(i == pScreen->myNum) - continue; - if(point_on_screen(screenInfo.screens[i], x, y)) - { - pScreen = screenInfo.screens[i]; - break; - } - } + if (!point_on_screen(pScreen, x, y)) { + FOR_NSCREENS(i) { + if (i == pScreen->myNum) + continue; + if (point_on_screen(screenInfo.screens[i], x, y)) { + pScreen = screenInfo.screens[i]; + break; + } + } } pSprite->screen = pScreen; @@ -548,10 +536,9 @@ XineramaSetCursorPosition( x -= pScreen->x; y -= pScreen->y; - return (*pScreen->SetCursorPosition)(pDev, pScreen, x, y, generateEvent); + return (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent); } - static void XineramaConstrainCursor(DeviceIntPtr pDev) { @@ -569,66 +556,65 @@ XineramaConstrainCursor(DeviceIntPtr pDev) newBox.y1 += screenInfo.screens[0]->y - pScreen->y; newBox.y2 += screenInfo.screens[0]->y - pScreen->y; - (* pScreen->ConstrainCursor)(pDev, pScreen, &newBox); + (*pScreen->ConstrainCursor) (pDev, pScreen, &newBox); } - static Bool XineramaSetWindowPntrs(DeviceIntPtr pDev, WindowPtr pWin) { SpritePtr pSprite = pDev->spriteInfo->sprite; - if(pWin == screenInfo.screens[0]->root) { - int i; - FOR_NSCREENS(i) - pSprite->windows[i] = screenInfo.screens[i]->root; - } else { - PanoramiXRes *win; - int rc, i; - - rc = dixLookupResourceByType((pointer *)&win, pWin->drawable.id, - XRT_WINDOW, serverClient, DixReadAccess); - if (rc != Success) - return FALSE; - - FOR_NSCREENS(i) { - rc = dixLookupWindow(pSprite->windows + i, win->info[i].id, - serverClient, DixReadAccess); - if (rc != Success) /* window is being unmapped */ - return FALSE; - } + if (pWin == screenInfo.screens[0]->root) { + int i; + + FOR_NSCREENS(i) + pSprite->windows[i] = screenInfo.screens[i]->root; + } + else { + PanoramiXRes *win; + int rc, i; + + rc = dixLookupResourceByType((pointer *) &win, pWin->drawable.id, + XRT_WINDOW, serverClient, DixReadAccess); + if (rc != Success) + return FALSE; + + FOR_NSCREENS(i) { + rc = dixLookupWindow(pSprite->windows + i, win->info[i].id, + serverClient, DixReadAccess); + if (rc != Success) /* window is being unmapped */ + return FALSE; + } } return TRUE; } static void XineramaConfineCursorToWindow(DeviceIntPtr pDev, - WindowPtr pWin, - Bool generateEvents) + WindowPtr pWin, Bool generateEvents) { SpritePtr pSprite = pDev->spriteInfo->sprite; int x, y, off_x, off_y, i; - if(!XineramaSetWindowPntrs(pDev, pWin)) + if (!XineramaSetWindowPntrs(pDev, pWin)) return; i = PanoramiXNumScreens - 1; - RegionCopy(&pSprite->Reg1, - &pSprite->windows[i]->borderSize); + RegionCopy(&pSprite->Reg1, &pSprite->windows[i]->borderSize); off_x = screenInfo.screens[i]->x; off_y = screenInfo.screens[i]->y; - while(i--) { + while (i--) { x = off_x - screenInfo.screens[i]->x; y = off_y - screenInfo.screens[i]->y; - if(x || y) + if (x || y) RegionTranslate(&pSprite->Reg1, x, y); RegionUnion(&pSprite->Reg1, &pSprite->Reg1, - &pSprite->windows[i]->borderSize); + &pSprite->windows[i]->borderSize); off_x = screenInfo.screens[i]->x; off_y = screenInfo.screens[i]->y; @@ -636,18 +622,19 @@ XineramaConfineCursorToWindow(DeviceIntPtr pDev, pSprite->hotLimits = *RegionExtents(&pSprite->Reg1); - if(RegionNumRects(&pSprite->Reg1) > 1) + if (RegionNumRects(&pSprite->Reg1) > 1) pSprite->hotShape = &pSprite->Reg1; else pSprite->hotShape = NullRegion; pSprite->confined = FALSE; - pSprite->confineWin = (pWin == screenInfo.screens[0]->root) ? NullWindow : pWin; + pSprite->confineWin = + (pWin == screenInfo.screens[0]->root) ? NullWindow : pWin; CheckPhysLimits(pDev, pSprite->current, generateEvents, FALSE, NULL); } -#endif /* PANORAMIX */ +#endif /* PANORAMIX */ /** * Modifies the filter for the given protocol event type to the given masks. @@ -675,7 +662,7 @@ void SetCriticalEvent(int event) { if (event >= MAXEVENTS) - FatalError("SetCriticalEvent: bogus event number"); + FatalError("SetCriticalEvent: bogus event number"); criticalEvents[event >> 3] |= 1 << (event & 7); } @@ -687,47 +674,40 @@ ConfineToShape(DeviceIntPtr pDev, RegionPtr shape, int *px, int *py) int incx = 1, incy = 1; if (RegionContainsPoint(shape, x, y, &box)) - return; + return; box = *RegionExtents(shape); /* this is rather crude */ do { - x += incx; - if (x >= box.x2) - { - incx = -1; - x = *px - 1; - } - else if (x < box.x1) - { - incx = 1; - x = *px; - y += incy; - if (y >= box.y2) - { - incy = -1; - y = *py - 1; - } - else if (y < box.y1) - return; /* should never get here! */ - } + x += incx; + if (x >= box.x2) { + incx = -1; + x = *px - 1; + } + else if (x < box.x1) { + incx = 1; + x = *px; + y += incy; + if (y >= box.y2) { + incy = -1; + y = *py - 1; + } + else if (y < box.y1) + return; /* should never get here! */ + } } while (!RegionContainsPoint(shape, x, y, &box)); *px = x; *py = y; } static void -CheckPhysLimits( - DeviceIntPtr pDev, - CursorPtr cursor, - Bool generateEvents, - Bool confineToScreen, /* unused if PanoramiX on */ - ScreenPtr pScreen) /* unused if PanoramiX on */ -{ +CheckPhysLimits(DeviceIntPtr pDev, CursorPtr cursor, Bool generateEvents, Bool confineToScreen, /* unused if PanoramiX on */ + ScreenPtr pScreen) +{ /* unused if PanoramiX on */ HotSpot new; SpritePtr pSprite = pDev->spriteInfo->sprite; if (!cursor) - return; + return; new = pSprite->hotPhys; #ifdef PANORAMIX if (!noPanoramiXExtension) @@ -741,34 +721,31 @@ CheckPhysLimits( else pScreen = new.pScreen; (*pScreen->CursorLimits) (pDev, pScreen, cursor, &pSprite->hotLimits, - &pSprite->physLimits); + &pSprite->physLimits); pSprite->confined = confineToScreen; - (* pScreen->ConstrainCursor)(pDev, pScreen, &pSprite->physLimits); + (*pScreen->ConstrainCursor) (pDev, pScreen, &pSprite->physLimits); } /* constrain the pointer to those limits */ if (new.x < pSprite->physLimits.x1) - new.x = pSprite->physLimits.x1; - else - if (new.x >= pSprite->physLimits.x2) - new.x = pSprite->physLimits.x2 - 1; + new.x = pSprite->physLimits.x1; + else if (new.x >= pSprite->physLimits.x2) + new.x = pSprite->physLimits.x2 - 1; if (new.y < pSprite->physLimits.y1) - new.y = pSprite->physLimits.y1; - else - if (new.y >= pSprite->physLimits.y2) - new.y = pSprite->physLimits.y2 - 1; + new.y = pSprite->physLimits.y1; + else if (new.y >= pSprite->physLimits.y2) + new.y = pSprite->physLimits.y2 - 1; if (pSprite->hotShape) - ConfineToShape(pDev, pSprite->hotShape, &new.x, &new.y); + ConfineToShape(pDev, pSprite->hotShape, &new.x, &new.y); if (( #ifdef PANORAMIX noPanoramiXExtension && #endif (pScreen != pSprite->hotPhys.pScreen)) || - (new.x != pSprite->hotPhys.x) || (new.y != pSprite->hotPhys.y)) - { + (new.x != pSprite->hotPhys.x) || (new.y != pSprite->hotPhys.y)) { #ifdef PANORAMIX if (!noPanoramiXExtension) - XineramaSetCursorPosition (pDev, new.x, new.y, generateEvents); + XineramaSetCursorPosition(pDev, new.x, new.y, generateEvents); else #endif { @@ -789,94 +766,89 @@ CheckPhysLimits( } static void -CheckVirtualMotion( - DeviceIntPtr pDev, - QdEventPtr qe, - WindowPtr pWin) +CheckVirtualMotion(DeviceIntPtr pDev, QdEventPtr qe, WindowPtr pWin) { SpritePtr pSprite = pDev->spriteInfo->sprite; RegionPtr reg = NULL; DeviceEvent *ev = NULL; - if (qe) - { + if (qe) { ev = &qe->event->device_event; - switch(ev->type) - { - case ET_Motion: - case ET_ButtonPress: - case ET_ButtonRelease: - case ET_KeyPress: - case ET_KeyRelease: - case ET_ProximityIn: - case ET_ProximityOut: - pSprite->hot.pScreen = qe->pScreen; - pSprite->hot.x = ev->root_x; - pSprite->hot.y = ev->root_y; - pWin = pDev->deviceGrab.grab ? pDev->deviceGrab.grab->confineTo : NullWindow; - break; - default: - break; + switch (ev->type) { + case ET_Motion: + case ET_ButtonPress: + case ET_ButtonRelease: + case ET_KeyPress: + case ET_KeyRelease: + case ET_ProximityIn: + case ET_ProximityOut: + pSprite->hot.pScreen = qe->pScreen; + pSprite->hot.x = ev->root_x; + pSprite->hot.y = ev->root_y; + pWin = + pDev->deviceGrab.grab ? pDev->deviceGrab.grab-> + confineTo : NullWindow; + break; + default: + break; } } - if (pWin) - { - BoxRec lims; + if (pWin) { + BoxRec lims; #ifdef PANORAMIX if (!noPanoramiXExtension) { int x, y, off_x, off_y, i; - if(!XineramaSetWindowPntrs(pDev, pWin)) + if (!XineramaSetWindowPntrs(pDev, pWin)) return; i = PanoramiXNumScreens - 1; - RegionCopy(&pSprite->Reg2, - &pSprite->windows[i]->borderSize); + RegionCopy(&pSprite->Reg2, &pSprite->windows[i]->borderSize); off_x = screenInfo.screens[i]->x; off_y = screenInfo.screens[i]->y; - while(i--) { + while (i--) { x = off_x - screenInfo.screens[i]->x; y = off_y - screenInfo.screens[i]->y; - if(x || y) + if (x || y) RegionTranslate(&pSprite->Reg2, x, y); RegionUnion(&pSprite->Reg2, &pSprite->Reg2, - &pSprite->windows[i]->borderSize); + &pSprite->windows[i]->borderSize); off_x = screenInfo.screens[i]->x; off_y = screenInfo.screens[i]->y; } - } else + } + else #endif { - if (pSprite->hot.pScreen != pWin->drawable.pScreen) - { + if (pSprite->hot.pScreen != pWin->drawable.pScreen) { pSprite->hot.pScreen = pWin->drawable.pScreen; pSprite->hot.x = pSprite->hot.y = 0; } } - lims = *RegionExtents(&pWin->borderSize); - if (pSprite->hot.x < lims.x1) - pSprite->hot.x = lims.x1; - else if (pSprite->hot.x >= lims.x2) - pSprite->hot.x = lims.x2 - 1; - if (pSprite->hot.y < lims.y1) - pSprite->hot.y = lims.y1; - else if (pSprite->hot.y >= lims.y2) - pSprite->hot.y = lims.y2 - 1; + lims = *RegionExtents(&pWin->borderSize); + if (pSprite->hot.x < lims.x1) + pSprite->hot.x = lims.x1; + else if (pSprite->hot.x >= lims.x2) + pSprite->hot.x = lims.x2 - 1; + if (pSprite->hot.y < lims.y1) + pSprite->hot.y = lims.y1; + else if (pSprite->hot.y >= lims.y2) + pSprite->hot.y = lims.y2 - 1; #ifdef PANORAMIX - if (!noPanoramiXExtension) - { + if (!noPanoramiXExtension) { if (RegionNumRects(&pSprite->Reg2) > 1) reg = &pSprite->Reg2; - } else + } + else #endif { if (wBoundingShape(pWin)) @@ -886,40 +858,38 @@ CheckVirtualMotion( if (reg) ConfineToShape(pDev, reg, &pSprite->hot.x, &pSprite->hot.y); - if (qe && ev) - { - qe->pScreen = pSprite->hot.pScreen; - ev->root_x = pSprite->hot.x; - ev->root_y = pSprite->hot.y; - } + if (qe && ev) { + qe->pScreen = pSprite->hot.pScreen; + ev->root_x = pSprite->hot.x; + ev->root_y = pSprite->hot.y; + } } #ifdef PANORAMIX - if (noPanoramiXExtension) /* No typo. Only set the root win if disabled */ + if (noPanoramiXExtension) /* No typo. Only set the root win if disabled */ #endif RootWindow(pDev->spriteInfo->sprite) = pSprite->hot.pScreen->root; } static void -ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents, Bool confineToScreen) +ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents, + Bool confineToScreen) { SpritePtr pSprite = pDev->spriteInfo->sprite; - if (syncEvents.playingEvents) - { - CheckVirtualMotion(pDev, (QdEventPtr)NULL, pWin); - SyntheticMotion(pDev, pSprite->hot.x, pSprite->hot.y); + if (syncEvents.playingEvents) { + CheckVirtualMotion(pDev, (QdEventPtr) NULL, pWin); + SyntheticMotion(pDev, pSprite->hot.x, pSprite->hot.y); } - else - { + else { #ifdef PANORAMIX - if(!noPanoramiXExtension) { + if (!noPanoramiXExtension) { XineramaConfineCursorToWindow(pDev, pWin, generateEvents); return; } #endif - pSprite->hotLimits = *RegionExtents(&pWin->borderSize); - pSprite->hotShape = wBoundingShape(pWin) ? &pWin->borderSize - : NullRegion; + pSprite->hotLimits = *RegionExtents(&pWin->borderSize); + pSprite->hotShape = wBoundingShape(pWin) ? &pWin->borderSize + : NullRegion; CheckPhysLimits(pDev, pSprite->current, generateEvents, confineToScreen, pWin->drawable.pScreen); } @@ -944,12 +914,11 @@ ChangeToCursor(DeviceIntPtr pDev, CursorPtr cursor) SpritePtr pSprite = pDev->spriteInfo->sprite; ScreenPtr pScreen; - if (cursor != pSprite->current) - { - if ((pSprite->current->bits->xhot != cursor->bits->xhot) || - (pSprite->current->bits->yhot != cursor->bits->yhot)) - CheckPhysLimits(pDev, cursor, FALSE, pSprite->confined, - (ScreenPtr)NULL); + if (cursor != pSprite->current) { + if ((pSprite->current->bits->xhot != cursor->bits->xhot) || + (pSprite->current->bits->yhot != cursor->bits->yhot)) + CheckPhysLimits(pDev, cursor, FALSE, pSprite->confined, + (ScreenPtr) NULL); #ifdef PANORAMIX /* XXX: is this really necessary?? (whot) */ if (!noPanoramiXExtension) @@ -958,10 +927,10 @@ ChangeToCursor(DeviceIntPtr pDev, CursorPtr cursor) #endif pScreen = pSprite->hotPhys.pScreen; - (*pScreen->DisplayCursor)(pDev, pScreen, cursor); - FreeCursor(pSprite->current, (Cursor)0); - pSprite->current = cursor; - pSprite->current->refcnt++; + (*pScreen->DisplayCursor) (pDev, pScreen, cursor); + FreeCursor(pSprite->current, (Cursor) 0); + pSprite->current = cursor; + pSprite->current->refcnt++; } } @@ -972,7 +941,8 @@ Bool IsParent(WindowPtr a, WindowPtr b) { for (b = b->parent; b; b = b->parent) - if (b == a) return TRUE; + if (b == a) + return TRUE; return FALSE; } @@ -986,42 +956,36 @@ PostNewCursor(DeviceIntPtr pDev) { WindowPtr win; GrabPtr grab = pDev->deviceGrab.grab; - SpritePtr pSprite = pDev->spriteInfo->sprite; - CursorPtr pCursor; + SpritePtr pSprite = pDev->spriteInfo->sprite; + CursorPtr pCursor; if (syncEvents.playingEvents) - return; - if (grab) - { - if (grab->cursor) - { - ChangeToCursor(pDev, grab->cursor); - return; - } - if (IsParent(grab->window, pSprite->win)) - win = pSprite->win; - else - win = grab->window; + return; + if (grab) { + if (grab->cursor) { + ChangeToCursor(pDev, grab->cursor); + return; + } + if (IsParent(grab->window, pSprite->win)) + win = pSprite->win; + else + win = grab->window; } else - win = pSprite->win; - for (; win; win = win->parent) - { - if (win->optional) - { + win = pSprite->win; + for (; win; win = win->parent) { + if (win->optional) { pCursor = WindowGetDeviceCursor(win, pDev); if (!pCursor && win->optional->cursor != NullCursor) pCursor = win->optional->cursor; - if (pCursor) - { + if (pCursor) { ChangeToCursor(pDev, pCursor); return; } - } + } } } - /** * @param dev device which you want to know its current root window * @return root window where dev's sprite is located @@ -1057,6 +1021,7 @@ void GetSpritePosition(DeviceIntPtr pDev, int *px, int *py) { SpritePtr pSprite = pDev->spriteInfo->sprite; + *px = pSprite->hotPhys.x; *py = pSprite->hotPhys.y; } @@ -1065,15 +1030,16 @@ GetSpritePosition(DeviceIntPtr pDev, int *px, int *py) int XineramaGetCursorScreen(DeviceIntPtr pDev) { - if(!noPanoramiXExtension) { - return pDev->spriteInfo->sprite->screen->myNum; - } else { - return 0; + if (!noPanoramiXExtension) { + return pDev->spriteInfo->sprite->screen->myNum; + } + else { + return 0; } } -#endif /* PANORAMIX */ +#endif /* PANORAMIX */ -#define TIMESLOP (5 * 60 * 1000) /* 5 minutes */ +#define TIMESLOP (5 * 60 * 1000) /* 5 minutes */ static void MonthChangedOrBadTime(InternalEvent *ev) @@ -1083,25 +1049,26 @@ MonthChangedOrBadTime(InternalEvent *ev) * backwards when it should not. Here we ensure a decent time. */ if ((currentTime.milliseconds - ev->any.time) > TIMESLOP) - currentTime.months++; + currentTime.months++; else ev->any.time = currentTime.milliseconds; } static void -NoticeTime(InternalEvent *ev) +NoticeTime(InternalEvent *ev, DeviceIntPtr dev) { if (ev->any.time < currentTime.milliseconds) MonthChangedOrBadTime(ev); currentTime.milliseconds = ev->any.time; - lastDeviceEventTime = currentTime; + lastDeviceEventTime[XIAllDevices] = currentTime; + lastDeviceEventTime[dev->id] = currentTime; } void -NoticeEventTime(InternalEvent *ev) +NoticeEventTime(InternalEvent *ev, DeviceIntPtr dev) { if (!syncEvents.playingEvents) - NoticeTime(ev); + NoticeTime(ev, dev); } /************************************************************************** @@ -1116,78 +1083,76 @@ NoticeEventTime(InternalEvent *ev) void EnqueueEvent(InternalEvent *ev, DeviceIntPtr device) { - QdEventPtr tail = NULL; - QdEventPtr qe; - SpritePtr pSprite = device->spriteInfo->sprite; - int eventlen; + QdEventPtr tail = NULL; + QdEventPtr qe; + SpritePtr pSprite = device->spriteInfo->sprite; + int eventlen; DeviceEvent *event = &ev->device_event; if (!xorg_list_is_empty(&syncEvents.pending)) tail = xorg_list_last_entry(&syncEvents.pending, QdEventRec, next); - NoticeTime((InternalEvent*)event); + NoticeTime((InternalEvent *)event, device); /* Fix for key repeating bug. */ if (device->key != NULL && device->key->xkbInfo != NULL && event->type == ET_KeyRelease) - AccessXCancelRepeatKey(device->key->xkbInfo, event->detail.key); + AccessXCancelRepeatKey(device->key->xkbInfo, event->detail.key); + + if (DeviceEventCallback) { + DeviceEventInfoRec eventinfo; + + /* The RECORD spec says that the root window field of motion events + * must be valid. At this point, it hasn't been filled in yet, so + * we do it here. The long expression below is necessary to get + * the current root window; the apparently reasonable alternative + * GetCurrentRootWindow()->drawable.id doesn't give you the right + * answer on the first motion event after a screen change because + * the data that GetCurrentRootWindow relies on hasn't been + * updated yet. + */ + if (ev->any.type == ET_Motion) + ev->device_event.root = pSprite->hotPhys.pScreen->root->drawable.id; - if (DeviceEventCallback) - { - DeviceEventInfoRec eventinfo; - - /* The RECORD spec says that the root window field of motion events - * must be valid. At this point, it hasn't been filled in yet, so - * we do it here. The long expression below is necessary to get - * the current root window; the apparently reasonable alternative - * GetCurrentRootWindow()->drawable.id doesn't give you the right - * answer on the first motion event after a screen change because - * the data that GetCurrentRootWindow relies on hasn't been - * updated yet. - */ - if (ev->any.type == ET_Motion) - ev->device_event.root = pSprite->hotPhys.pScreen->root->drawable.id; - - eventinfo.event = ev; - eventinfo.device = device; - CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo); - } - - if (event->type == ET_Motion) - { + eventinfo.event = ev; + eventinfo.device = device; + CallCallbacks(&DeviceEventCallback, (pointer) &eventinfo); + } + + if (event->type == ET_Motion) { #ifdef PANORAMIX - if(!noPanoramiXExtension) { - event->root_x += pSprite->screen->x - screenInfo.screens[0]->x; - event->root_y += pSprite->screen->y - screenInfo.screens[0]->y; - } + if (!noPanoramiXExtension) { + event->root_x += pSprite->screen->x - screenInfo.screens[0]->x; + event->root_y += pSprite->screen->y - screenInfo.screens[0]->y; + } #endif - pSprite->hotPhys.x = event->root_x; - pSprite->hotPhys.y = event->root_y; - /* do motion compression, but not if from different devices */ - if (tail && - (tail->event->any.type == ET_Motion) && + pSprite->hotPhys.x = event->root_x; + pSprite->hotPhys.y = event->root_y; + /* do motion compression, but not if from different devices */ + if (tail && + (tail->event->any.type == ET_Motion) && (tail->device == device) && - (tail->pScreen == pSprite->hotPhys.pScreen)) - { + (tail->pScreen == pSprite->hotPhys.pScreen)) { DeviceEvent *tailev = &tail->event->device_event; - tailev->root_x = pSprite->hotPhys.x; - tailev->root_y = pSprite->hotPhys.y; - tailev->time = event->time; - tail->months = currentTime.months; - return; - } + + tailev->root_x = pSprite->hotPhys.x; + tailev->root_y = pSprite->hotPhys.y; + tailev->time = event->time; + tail->months = currentTime.months; + return; + } } eventlen = event->length; qe = malloc(sizeof(QdEventRec) + eventlen); if (!qe) - return; + return; xorg_list_init(&qe->next); qe->device = device; qe->pScreen = pSprite->hotPhys.pScreen; qe->months = currentTime.months; - qe->event = (InternalEvent *)(qe + 1); + qe->event = (InternalEvent *) (qe + 1); memcpy(qe->event, event, eventlen); xorg_list_append(&qe->next, &syncEvents.pending); } @@ -1209,53 +1174,52 @@ PlayReleasedEvents(void) DeviceIntPtr dev; DeviceIntPtr pDev; -restart: + restart: xorg_list_for_each_entry_safe(qe, tmp, &syncEvents.pending, next) { - if (!qe->device->deviceGrab.sync.frozen) - { - xorg_list_del(&qe->next); - pDev = qe->device; - if (qe->event->any.type == ET_Motion) - CheckVirtualMotion(pDev, qe, NullWindow); - syncEvents.time.months = qe->months; + if (!qe->device->deviceGrab.sync.frozen) { + xorg_list_del(&qe->next); + pDev = qe->device; + if (qe->event->any.type == ET_Motion) + CheckVirtualMotion(pDev, qe, NullWindow); + syncEvents.time.months = qe->months; syncEvents.time.milliseconds = qe->event->any.time; #ifdef PANORAMIX - /* Translate back to the sprite screen since processInputProc - will translate from sprite screen to screen 0 upon reentry - to the DIX layer */ - if(!noPanoramiXExtension) { + /* Translate back to the sprite screen since processInputProc + will translate from sprite screen to screen 0 upon reentry + to the DIX layer */ + if (!noPanoramiXExtension) { DeviceEvent *ev = &qe->event->device_event; - switch(ev->type) - { - case ET_Motion: - case ET_ButtonPress: - case ET_ButtonRelease: - case ET_KeyPress: - case ET_KeyRelease: - case ET_ProximityIn: - case ET_ProximityOut: - ev->root_x += screenInfo.screens[0]->x - - pDev->spriteInfo->sprite->screen->x; - ev->root_y += screenInfo.screens[0]->y - - pDev->spriteInfo->sprite->screen->y; - break; - default: - break; + + switch (ev->type) { + case ET_Motion: + case ET_ButtonPress: + case ET_ButtonRelease: + case ET_KeyPress: + case ET_KeyRelease: + case ET_ProximityIn: + case ET_ProximityOut: + ev->root_x += screenInfo.screens[0]->x - + pDev->spriteInfo->sprite->screen->x; + ev->root_y += screenInfo.screens[0]->y - + pDev->spriteInfo->sprite->screen->y; + break; + default: + break; } - } + } #endif - (*qe->device->public.processInputProc)(qe->event, qe->device); - free(qe); - for (dev = inputInfo.devices; dev && dev->deviceGrab.sync.frozen; dev = dev->next) - ; - if (!dev) - break; - - /* Playing the event may have unfrozen another device. */ - /* So to play it safe, restart at the head of the queue */ - goto restart; - } + (*qe->device->public.processInputProc) (qe->event, qe->device); + free(qe); + for (dev = inputInfo.devices; dev && dev->deviceGrab.sync.frozen; + dev = dev->next); + if (!dev) + break; + + /* Playing the event may have unfrozen another device. */ + /* So to play it safe, restart at the head of the queue */ + goto restart; + } } } @@ -1272,9 +1236,9 @@ FreezeThaw(DeviceIntPtr dev, Bool frozen) { dev->deviceGrab.sync.frozen = frozen; if (frozen) - dev->public.processInputProc = dev->public.enqueueInputProc; + dev->public.processInputProc = dev->public.enqueueInputProc; else - dev->public.processInputProc = dev->public.realInputProc; + dev->public.processInputProc = dev->public.realInputProc; } /** @@ -1294,66 +1258,64 @@ ComputeFreezes(void) DeviceIntPtr dev; for (dev = inputInfo.devices; dev; dev = dev->next) - FreezeThaw(dev, dev->deviceGrab.sync.other || - (dev->deviceGrab.sync.state >= FROZEN)); + FreezeThaw(dev, dev->deviceGrab.sync.other || + (dev->deviceGrab.sync.state >= FROZEN)); if (syncEvents.playingEvents || (!replayDev && xorg_list_is_empty(&syncEvents.pending))) - return; + return; syncEvents.playingEvents = TRUE; - if (replayDev) - { - DeviceEvent* event = replayDev->deviceGrab.sync.event; + if (replayDev) { + DeviceEvent *event = replayDev->deviceGrab.sync.event; - syncEvents.replayDev = (DeviceIntPtr)NULL; + syncEvents.replayDev = (DeviceIntPtr) NULL; w = XYToWindow(replayDev->spriteInfo->sprite, event->root_x, event->root_y); - if (!CheckDeviceGrabs(replayDev, event, syncEvents.replayWin)) - { - if (IsTouchEvent((InternalEvent*)event)) - { + if (!CheckDeviceGrabs(replayDev, event, syncEvents.replayWin)) { + if (IsTouchEvent((InternalEvent *) event)) { InternalEvent *events = InitEventList(GetMaximumEventsNum()); int i, nev; - TouchPointInfoPtr ti = TouchFindByClientID(replayDev, event->touchid); + TouchPointInfoPtr ti = + TouchFindByClientID(replayDev, event->touchid); BUG_WARN(!ti); - nev = GetTouchOwnershipEvents(events, replayDev, ti, XIRejectTouch, ti->listeners[0].listener, 0); + nev = + GetTouchOwnershipEvents(events, replayDev, ti, + XIRejectTouch, + ti->listeners[0].listener, 0); for (i = 0; i < nev; i++) mieqProcessDeviceEvent(replayDev, events + i, NULL); ProcessInputEvents(); - } else if (replayDev->focus && !IsPointerEvent((InternalEvent*)event)) - DeliverFocusedEvent(replayDev, (InternalEvent*)event, w); + } + else if (replayDev->focus && + !IsPointerEvent((InternalEvent *) event)) + DeliverFocusedEvent(replayDev, (InternalEvent *) event, w); else - DeliverDeviceEvents(w, (InternalEvent*)event, NullGrab, + DeliverDeviceEvents(w, (InternalEvent *) event, NullGrab, NullWindow, replayDev); } } - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (!dev->deviceGrab.sync.frozen) - { - PlayReleasedEvents(); - break; - } + for (dev = inputInfo.devices; dev; dev = dev->next) { + if (!dev->deviceGrab.sync.frozen) { + PlayReleasedEvents(); + break; + } } syncEvents.playingEvents = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (DevHasCursor(dev)) - { + for (dev = inputInfo.devices; dev; dev = dev->next) { + if (DevHasCursor(dev)) { /* the following may have been skipped during replay, - so do it now */ - if ((grab = dev->deviceGrab.grab) && grab->confineTo) - { + so do it now */ + if ((grab = dev->deviceGrab.grab) && grab->confineTo) { if (grab->confineTo->drawable.pScreen != - dev->spriteInfo->sprite->hotPhys.pScreen) + dev->spriteInfo->sprite->hotPhys.pScreen) dev->spriteInfo->sprite->hotPhys.x = dev->spriteInfo->sprite->hotPhys.y = 0; ConfineCursorToWindow(dev, grab->confineTo, TRUE, TRUE); } else ConfineCursorToWindow(dev, - dev->spriteInfo->sprite->hotPhys.pScreen->root, - TRUE, FALSE); + dev->spriteInfo->sprite->hotPhys.pScreen-> + root, TRUE, FALSE); PostNewCursor(dev); } } @@ -1361,29 +1323,28 @@ ComputeFreezes(void) #ifdef RANDR void -ScreenRestructured (ScreenPtr pScreen) +ScreenRestructured(ScreenPtr pScreen) { GrabPtr grab; DeviceIntPtr pDev; - for (pDev = inputInfo.devices; pDev; pDev = pDev->next) - { + for (pDev = inputInfo.devices; pDev; pDev = pDev->next) { if (!IsFloating(pDev) && !DevHasCursor(pDev)) continue; /* GrabDevice doesn't have a confineTo field, so we don't need to * worry about it. */ - if ((grab = pDev->deviceGrab.grab) && grab->confineTo) - { + if ((grab = pDev->deviceGrab.grab) && grab->confineTo) { if (grab->confineTo->drawable.pScreen - != pDev->spriteInfo->sprite->hotPhys.pScreen) - pDev->spriteInfo->sprite->hotPhys.x = pDev->spriteInfo->sprite->hotPhys.y = 0; + != pDev->spriteInfo->sprite->hotPhys.pScreen) + pDev->spriteInfo->sprite->hotPhys.x = + pDev->spriteInfo->sprite->hotPhys.y = 0; ConfineCursorToWindow(pDev, grab->confineTo, TRUE, TRUE); } else ConfineCursorToWindow(pDev, - pDev->spriteInfo->sprite->hotPhys.pScreen->root, - TRUE, FALSE); + pDev->spriteInfo->sprite->hotPhys.pScreen-> + root, TRUE, FALSE); } } #endif @@ -1395,26 +1356,23 @@ CheckGrabForSyncs(DeviceIntPtr thisDev, Bool thisMode, Bool otherMode) DeviceIntPtr dev; if (thisMode == GrabModeSync) - thisDev->deviceGrab.sync.state = FROZEN_NO_EVENT; - else - { /* free both if same client owns both */ - thisDev->deviceGrab.sync.state = THAWED; - if (thisDev->deviceGrab.sync.other && - (CLIENT_BITS(thisDev->deviceGrab.sync.other->resource) == - CLIENT_BITS(grab->resource))) - thisDev->deviceGrab.sync.other = NullGrab; + thisDev->deviceGrab.sync.state = FROZEN_NO_EVENT; + else { /* free both if same client owns both */ + thisDev->deviceGrab.sync.state = THAWED; + if (thisDev->deviceGrab.sync.other && + (CLIENT_BITS(thisDev->deviceGrab.sync.other->resource) == + CLIENT_BITS(grab->resource))) + thisDev->deviceGrab.sync.other = NullGrab; } - if (IsMaster(thisDev)) - { + if (IsMaster(thisDev)) { dev = GetPairedDevice(thisDev); if (otherMode == GrabModeSync) dev->deviceGrab.sync.other = grab; - else - { /* free both if same client owns both */ + else { /* free both if same client owns both */ if (dev->deviceGrab.sync.other && - (CLIENT_BITS(dev->deviceGrab.sync.other->resource) == - CLIENT_BITS(grab->resource))) + (CLIENT_BITS(dev->deviceGrab.sync.other->resource) == + CLIENT_BITS(grab->resource))) dev->deviceGrab.sync.other = NullGrab; } } @@ -1451,10 +1409,9 @@ ReattachToOldMaster(DeviceIntPtr dev) dixLookupDevice(&master, dev->saved_master_id, serverClient, DixUseAccess); - if (master) - { + if (master) { AttachDevice(serverClient, dev, master); - dev->saved_master_id = 0; + dev->saved_master_id = 0; } } @@ -1479,8 +1436,7 @@ ActivatePointerGrab(DeviceIntPtr mouse, GrabPtr grab, { GrabInfoPtr grabinfo = &mouse->deviceGrab; WindowPtr oldWin = (grabinfo->grab) ? - grabinfo->grab->window - : mouse->spriteInfo->sprite->win; + grabinfo->grab->window : mouse->spriteInfo->sprite->win; Bool isPassive = autoGrab & ~ImplicitGrabMask; /* slave devices need to float for the duration of the grab. */ @@ -1488,28 +1444,28 @@ ActivatePointerGrab(DeviceIntPtr mouse, GrabPtr grab, !(autoGrab & ImplicitGrabMask) && !IsMaster(mouse)) DetachFromMaster(mouse); - if (grab->confineTo) - { - if (grab->confineTo->drawable.pScreen - != mouse->spriteInfo->sprite->hotPhys.pScreen) - mouse->spriteInfo->sprite->hotPhys.x = + if (grab->confineTo) { + if (grab->confineTo->drawable.pScreen + != mouse->spriteInfo->sprite->hotPhys.pScreen) + mouse->spriteInfo->sprite->hotPhys.x = mouse->spriteInfo->sprite->hotPhys.y = 0; - ConfineCursorToWindow(mouse, grab->confineTo, FALSE, TRUE); + ConfineCursorToWindow(mouse, grab->confineTo, FALSE, TRUE); } DoEnterLeaveEvents(mouse, mouse->id, oldWin, grab->window, NotifyGrab); mouse->valuator->motionHintWindow = NullWindow; if (syncEvents.playingEvents) grabinfo->grabTime = syncEvents.time; else - grabinfo->grabTime = time; + grabinfo->grabTime = time; if (grab->cursor) - grab->cursor->refcnt++; + grab->cursor->refcnt++; CopyGrab(grabinfo->activeGrab, grab); grabinfo->grab = grabinfo->activeGrab; grabinfo->fromPassiveGrab = isPassive; grabinfo->implicitGrab = autoGrab & ImplicitGrabMask; PostNewCursor(mouse); - CheckGrabForSyncs(mouse,(Bool)grab->pointerMode, (Bool)grab->keyboardMode); + CheckGrabForSyncs(mouse, (Bool) grab->pointerMode, + (Bool) grab->keyboardMode); } /** @@ -1532,18 +1488,17 @@ DeactivatePointerGrab(DeviceIntPtr mouse) mouse->deviceGrab.sync.state = NOT_GRABBED; mouse->deviceGrab.fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->deviceGrab.sync.other == grab) - dev->deviceGrab.sync.other = NullGrab; + for (dev = inputInfo.devices; dev; dev = dev->next) { + if (dev->deviceGrab.sync.other == grab) + dev->deviceGrab.sync.other = NullGrab; } DoEnterLeaveEvents(mouse, mouse->id, grab->window, mouse->spriteInfo->sprite->win, NotifyUngrab); if (grab->confineTo) - ConfineCursorToWindow(mouse, GetCurrentRootWindow(mouse), FALSE, FALSE); + ConfineCursorToWindow(mouse, GetCurrentRootWindow(mouse), FALSE, FALSE); PostNewCursor(mouse); if (grab->cursor) - FreeCursor(grab->cursor, (Cursor)0); + FreeCursor(grab->cursor, (Cursor) 0); if (!wasImplicit && grab->grabtype == XI2) ReattachToOldMaster(mouse); @@ -1557,37 +1512,38 @@ DeactivatePointerGrab(DeviceIntPtr mouse) * Extension devices have ActivateKeyboardGrab() set as their grabbing proc. */ void -ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, Bool passive) +ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, + Bool passive) { GrabInfoPtr grabinfo = &keybd->deviceGrab; WindowPtr oldWin; /* slave devices need to float for the duration of the grab. */ if (grab->grabtype == XI2 && - !(passive & ImplicitGrabMask) && - !IsMaster(keybd)) + !(passive & ImplicitGrabMask) && !IsMaster(keybd)) DetachFromMaster(keybd); if (grabinfo->grab) - oldWin = grabinfo->grab->window; + oldWin = grabinfo->grab->window; else if (keybd->focus) - oldWin = keybd->focus->win; + oldWin = keybd->focus->win; else - oldWin = keybd->spriteInfo->sprite->win; + oldWin = keybd->spriteInfo->sprite->win; if (oldWin == FollowKeyboardWin) - oldWin = keybd->focus->win; + oldWin = keybd->focus->win; if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; + keybd->valuator->motionHintWindow = NullWindow; DoFocusEvents(keybd, oldWin, grab->window, NotifyGrab); if (syncEvents.playingEvents) - grabinfo->grabTime = syncEvents.time; + grabinfo->grabTime = syncEvents.time; else - grabinfo->grabTime = time; + grabinfo->grabTime = time; CopyGrab(grabinfo->activeGrab, grab); grabinfo->grab = grabinfo->activeGrab; grabinfo->fromPassiveGrab = passive; grabinfo->implicitGrab = passive & ImplicitGrabMask; - CheckGrabForSyncs(keybd, (Bool)grab->keyboardMode, (Bool)grab->pointerMode); + CheckGrabForSyncs(keybd, (Bool) grab->keyboardMode, + (Bool) grab->pointerMode); } /** @@ -1599,22 +1555,21 @@ DeactivateKeyboardGrab(DeviceIntPtr keybd) GrabPtr grab = keybd->deviceGrab.grab; DeviceIntPtr dev; WindowPtr focusWin = keybd->focus ? keybd->focus->win - : keybd->spriteInfo->sprite->win; + : keybd->spriteInfo->sprite->win; Bool wasImplicit = (keybd->deviceGrab.fromPassiveGrab && keybd->deviceGrab.implicitGrab); if (focusWin == FollowKeyboardWin) - focusWin = inputInfo.keyboard->focus->win; + focusWin = inputInfo.keyboard->focus->win; if (keybd->valuator) - keybd->valuator->motionHintWindow = NullWindow; + keybd->valuator->motionHintWindow = NullWindow; keybd->deviceGrab.grab = NullGrab; keybd->deviceGrab.sync.state = NOT_GRABBED; keybd->deviceGrab.fromPassiveGrab = FALSE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->deviceGrab.sync.other == grab) - dev->deviceGrab.sync.other = NullGrab; + for (dev = inputInfo.devices; dev; dev = dev->next) { + if (dev->deviceGrab.sync.other == grab) + dev->deviceGrab.sync.other = NullGrab; } DoFocusEvents(keybd, grab->window, focusWin, NotifyUngrab); @@ -1625,124 +1580,106 @@ DeactivateKeyboardGrab(DeviceIntPtr keybd) } void -AllowSome(ClientPtr client, - TimeStamp time, - DeviceIntPtr thisDev, - int newState) +AllowSome(ClientPtr client, TimeStamp time, DeviceIntPtr thisDev, int newState) { Bool thisGrabbed, otherGrabbed, othersFrozen, thisSynced; TimeStamp grabTime; DeviceIntPtr dev; - GrabInfoPtr devgrabinfo, - grabinfo = &thisDev->deviceGrab; + GrabInfoPtr devgrabinfo, grabinfo = &thisDev->deviceGrab; thisGrabbed = grabinfo->grab && SameClient(grabinfo->grab, client); thisSynced = FALSE; otherGrabbed = FALSE; othersFrozen = FALSE; grabTime = grabinfo->grabTime; - for (dev = inputInfo.devices; dev; dev = dev->next) - { + for (dev = inputInfo.devices; dev; dev = dev->next) { devgrabinfo = &dev->deviceGrab; - if (dev == thisDev) - continue; - if (devgrabinfo->grab && SameClient(devgrabinfo->grab, client)) - { - if (!(thisGrabbed || otherGrabbed) || - (CompareTimeStamps(devgrabinfo->grabTime, grabTime) == LATER)) - grabTime = devgrabinfo->grabTime; - otherGrabbed = TRUE; - if (grabinfo->sync.other == devgrabinfo->grab) - thisSynced = TRUE; - if (devgrabinfo->sync.state >= FROZEN) - othersFrozen = TRUE; - } + if (dev == thisDev) + continue; + if (devgrabinfo->grab && SameClient(devgrabinfo->grab, client)) { + if (!(thisGrabbed || otherGrabbed) || + (CompareTimeStamps(devgrabinfo->grabTime, grabTime) == LATER)) + grabTime = devgrabinfo->grabTime; + otherGrabbed = TRUE; + if (grabinfo->sync.other == devgrabinfo->grab) + thisSynced = TRUE; + if (devgrabinfo->sync.state >= FROZEN) + othersFrozen = TRUE; + } } if (!((thisGrabbed && grabinfo->sync.state >= FROZEN) || thisSynced)) - return; + return; if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, grabTime) == EARLIER)) - return; - switch (newState) - { - case THAWED: /* Async */ - if (thisGrabbed) - grabinfo->sync.state = THAWED; - if (thisSynced) - grabinfo->sync.other = NullGrab; - ComputeFreezes(); - break; - case FREEZE_NEXT_EVENT: /* Sync */ - if (thisGrabbed) - { - grabinfo->sync.state = FREEZE_NEXT_EVENT; - if (thisSynced) - grabinfo->sync.other = NullGrab; - ComputeFreezes(); - } - break; - case THAWED_BOTH: /* AsyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - devgrabinfo = &dev->deviceGrab; - if (devgrabinfo->grab - && SameClient(devgrabinfo->grab, client)) - devgrabinfo->sync.state = THAWED; - if (devgrabinfo->sync.other && - SameClient(devgrabinfo->sync.other, client)) - devgrabinfo->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case FREEZE_BOTH_NEXT_EVENT: /* SyncBoth */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - devgrabinfo = &dev->deviceGrab; - if (devgrabinfo->grab - && SameClient(devgrabinfo->grab, client)) - devgrabinfo->sync.state = FREEZE_BOTH_NEXT_EVENT; - if (devgrabinfo->sync.other - && SameClient(devgrabinfo->sync.other, client)) - devgrabinfo->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; - case NOT_GRABBED: /* Replay */ - if (thisGrabbed && grabinfo->sync.state == FROZEN_WITH_EVENT) - { - if (thisSynced) - grabinfo->sync.other = NullGrab; - syncEvents.replayDev = thisDev; - syncEvents.replayWin = grabinfo->grab->window; - (*grabinfo->DeactivateGrab)(thisDev); - syncEvents.replayDev = (DeviceIntPtr)NULL; - } - break; - case THAW_OTHERS: /* AsyncOthers */ - if (othersFrozen) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev == thisDev) - continue; - devgrabinfo = &dev->deviceGrab; - if (devgrabinfo->grab - && SameClient(devgrabinfo->grab, client)) - devgrabinfo->sync.state = THAWED; - if (devgrabinfo->sync.other - && SameClient(devgrabinfo->sync.other, client)) - devgrabinfo->sync.other = NullGrab; - } - ComputeFreezes(); - } - break; + (CompareTimeStamps(time, grabTime) == EARLIER)) + return; + switch (newState) { + case THAWED: /* Async */ + if (thisGrabbed) + grabinfo->sync.state = THAWED; + if (thisSynced) + grabinfo->sync.other = NullGrab; + ComputeFreezes(); + break; + case FREEZE_NEXT_EVENT: /* Sync */ + if (thisGrabbed) { + grabinfo->sync.state = FREEZE_NEXT_EVENT; + if (thisSynced) + grabinfo->sync.other = NullGrab; + ComputeFreezes(); + } + break; + case THAWED_BOTH: /* AsyncBoth */ + if (othersFrozen) { + for (dev = inputInfo.devices; dev; dev = dev->next) { + devgrabinfo = &dev->deviceGrab; + if (devgrabinfo->grab && SameClient(devgrabinfo->grab, client)) + devgrabinfo->sync.state = THAWED; + if (devgrabinfo->sync.other && + SameClient(devgrabinfo->sync.other, client)) + devgrabinfo->sync.other = NullGrab; + } + ComputeFreezes(); + } + break; + case FREEZE_BOTH_NEXT_EVENT: /* SyncBoth */ + if (othersFrozen) { + for (dev = inputInfo.devices; dev; dev = dev->next) { + devgrabinfo = &dev->deviceGrab; + if (devgrabinfo->grab && SameClient(devgrabinfo->grab, client)) + devgrabinfo->sync.state = FREEZE_BOTH_NEXT_EVENT; + if (devgrabinfo->sync.other + && SameClient(devgrabinfo->sync.other, client)) + devgrabinfo->sync.other = NullGrab; + } + ComputeFreezes(); + } + break; + case NOT_GRABBED: /* Replay */ + if (thisGrabbed && grabinfo->sync.state == FROZEN_WITH_EVENT) { + if (thisSynced) + grabinfo->sync.other = NullGrab; + syncEvents.replayDev = thisDev; + syncEvents.replayWin = grabinfo->grab->window; + (*grabinfo->DeactivateGrab) (thisDev); + syncEvents.replayDev = (DeviceIntPtr) NULL; + } + break; + case THAW_OTHERS: /* AsyncOthers */ + if (othersFrozen) { + for (dev = inputInfo.devices; dev; dev = dev->next) { + if (dev == thisDev) + continue; + devgrabinfo = &dev->deviceGrab; + if (devgrabinfo->grab && SameClient(devgrabinfo->grab, client)) + devgrabinfo->sync.state = THAWED; + if (devgrabinfo->sync.other + && SameClient(devgrabinfo->sync.other, client)) + devgrabinfo->sync.other = NullGrab; + } + ComputeFreezes(); + } + break; } } @@ -1754,9 +1691,10 @@ AllowSome(ClientPtr client, int ProcAllowEvents(ClientPtr client) { - TimeStamp time; - DeviceIntPtr mouse = NULL; - DeviceIntPtr keybd = NULL; + TimeStamp time; + DeviceIntPtr mouse = NULL; + DeviceIntPtr keybd = NULL; + REQUEST(xAllowEventsReq); REQUEST_SIZE_MATCH(xAllowEventsReq); @@ -1765,35 +1703,34 @@ ProcAllowEvents(ClientPtr client) mouse = PickPointer(client); keybd = PickKeyboard(client); - switch (stuff->mode) - { - case ReplayPointer: - AllowSome(client, time, mouse, NOT_GRABBED); - break; - case SyncPointer: - AllowSome(client, time, mouse, FREEZE_NEXT_EVENT); - break; - case AsyncPointer: - AllowSome(client, time, mouse, THAWED); - break; - case ReplayKeyboard: - AllowSome(client, time, keybd, NOT_GRABBED); - break; - case SyncKeyboard: - AllowSome(client, time, keybd, FREEZE_NEXT_EVENT); - break; - case AsyncKeyboard: - AllowSome(client, time, keybd, THAWED); - break; - case SyncBoth: - AllowSome(client, time, keybd, FREEZE_BOTH_NEXT_EVENT); - break; - case AsyncBoth: - AllowSome(client, time, keybd, THAWED_BOTH); - break; - default: - client->errorValue = stuff->mode; - return BadValue; + switch (stuff->mode) { + case ReplayPointer: + AllowSome(client, time, mouse, NOT_GRABBED); + break; + case SyncPointer: + AllowSome(client, time, mouse, FREEZE_NEXT_EVENT); + break; + case AsyncPointer: + AllowSome(client, time, mouse, THAWED); + break; + case ReplayKeyboard: + AllowSome(client, time, keybd, NOT_GRABBED); + break; + case SyncKeyboard: + AllowSome(client, time, keybd, FREEZE_NEXT_EVENT); + break; + case AsyncKeyboard: + AllowSome(client, time, keybd, THAWED); + break; + case SyncBoth: + AllowSome(client, time, keybd, FREEZE_BOTH_NEXT_EVENT); + break; + case AsyncBoth: + AllowSome(client, time, keybd, THAWED_BOTH); + break; + default: + client->errorValue = stuff->mode; + return BadValue; } return Success; } @@ -1805,21 +1742,20 @@ void ReleaseActiveGrabs(ClientPtr client) { DeviceIntPtr dev; - Bool done; + Bool done; /* XXX CloseDownClient should remove passive grabs before * releasing active grabs. */ do { - done = TRUE; - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (dev->deviceGrab.grab && SameClient(dev->deviceGrab.grab, client)) - { - (*dev->deviceGrab.DeactivateGrab)(dev); - done = FALSE; - } - } + done = TRUE; + for (dev = inputInfo.devices; dev; dev = dev->next) { + if (dev->deviceGrab.grab && + SameClient(dev->deviceGrab.grab, client)) { + (*dev->deviceGrab.DeactivateGrab) (dev); + done = FALSE; + } + } } while (!done); } @@ -1853,8 +1789,8 @@ ReleaseActiveGrabs(ClientPtr client) * client. */ int -TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents, - int count, Mask mask, Mask filter, GrabPtr grab) +TryClientEvents(ClientPtr client, DeviceIntPtr dev, xEvent *pEvents, + int count, Mask mask, Mask filter, GrabPtr grab) { int type; @@ -1872,75 +1808,66 @@ TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents, return 0; } - if (filter != CantBeFiltered && !(mask & filter)) - { - #ifdef DEBUG_EVENTS + if (filter != CantBeFiltered && !(mask & filter)) { +#ifdef DEBUG_EVENTS ErrorF(" filtered\n"); - #endif +#endif return 0; } - if (grab && !SameClient(grab, client)) - { + if (grab && !SameClient(grab, client)) { #ifdef DEBUG_EVENTS ErrorF(" not delivered due to grab\n"); #endif - return -1; /* don't send, but notify caller */ + return -1; /* don't send, but notify caller */ } type = pEvents->u.u.type; - if (type == MotionNotify) - { - if (mask & PointerMotionHintMask) - { + if (type == MotionNotify) { + if (mask & PointerMotionHintMask) { if (WID(dev->valuator->motionHintWindow) == - pEvents->u.keyButtonPointer.event) - { + pEvents->u.keyButtonPointer.event) { #ifdef DEBUG_EVENTS ErrorF("[dix] \n"); ErrorF("[dix] motionHintWindow == keyButtonPointer.event\n"); #endif - return 1; /* don't send, but pretend we did */ + return 1; /* don't send, but pretend we did */ } pEvents->u.u.detail = NotifyHint; } - else - { + else { pEvents->u.u.detail = NotifyNormal; } } - else if (type == DeviceMotionNotify) - { - if (MaybeSendDeviceMotionNotifyHint((deviceKeyButtonPointer*)pEvents, + else if (type == DeviceMotionNotify) { + if (MaybeSendDeviceMotionNotifyHint((deviceKeyButtonPointer *) pEvents, mask) != 0) return 1; - } else if (type == KeyPress) - { - if (EventIsKeyRepeat(pEvents)) - { - if (!_XkbWantsDetectableAutoRepeat(client)) - { + } + else if (type == KeyPress) { + if (EventIsKeyRepeat(pEvents)) { + if (!_XkbWantsDetectableAutoRepeat(client)) { xEvent release = *pEvents; + release.u.u.type = KeyRelease; WriteEventsToClient(client, 1, &release); #ifdef DEBUG_EVENTS ErrorF(" (plus fake core release for repeat)"); #endif - } else - { + } + else { #ifdef DEBUG_EVENTS ErrorF(" (detectable autorepeat for core)"); #endif } } - } else if (type == DeviceKeyPress) - { - if (EventIsKeyRepeat(pEvents)) - { - if (!_XkbWantsDetectableAutoRepeat(client)) - { - deviceKeyButtonPointer release = *(deviceKeyButtonPointer *)pEvents; + } + else if (type == DeviceKeyPress) { + if (EventIsKeyRepeat(pEvents)) { + if (!_XkbWantsDetectableAutoRepeat(client)) { + deviceKeyButtonPointer release = + *(deviceKeyButtonPointer *) pEvents; release.type = DeviceKeyRelease; #ifdef DEBUG_EVENTS ErrorF(" (plus fake xi1 release for repeat)"); @@ -1955,8 +1882,7 @@ TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents, } } - if (BitIsOn(criticalEvents, type)) - { + if (BitIsOn(criticalEvents, type)) { if (client->smart_priority < SMART_MAX_PRIORITY) client->smart_priority++; SetCriticalOutputPending(); @@ -2005,13 +1931,13 @@ ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win, /* get the XI and XI2 device mask */ inputMasks = wOtherInputMasks(win); - tempGrab->deviceMask = (inputMasks) ? inputMasks->inputEvents[dev->id]: 0; + tempGrab->deviceMask = (inputMasks) ? inputMasks->inputEvents[dev->id] : 0; if (inputMasks) xi2mask_merge(tempGrab->xi2mask, inputMasks->xi2mask); - (*dev->deviceGrab.ActivateGrab)(dev, tempGrab, - currentTime, TRUE | ImplicitGrabMask); + (*dev->deviceGrab.ActivateGrab) (dev, tempGrab, + currentTime, TRUE | ImplicitGrabMask); FreeGrab(tempGrab); return TRUE; } @@ -2021,22 +1947,21 @@ ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win, */ static enum EventDeliveryState DeliverToWindowOwner(DeviceIntPtr dev, WindowPtr win, - xEvent *events, int count, Mask filter, - GrabPtr grab) + xEvent *events, int count, Mask filter, GrabPtr grab) { /* if nobody ever wants to see this event, skip some work */ if (filter != CantBeFiltered && - !((wOtherEventMasks(win)|win->eventMask) & filter)) + !((wOtherEventMasks(win) | win->eventMask) & filter)) return EVENT_SKIP; if (IsInterferingGrab(wClient(win), dev, events)) return EVENT_SKIP; - if (!XaceHook(XACE_RECEIVE_ACCESS, wClient(win), win, events, count)) - { + if (!XaceHook(XACE_RECEIVE_ACCESS, wClient(win), win, events, count)) { int attempt = TryClientEvents(wClient(win), dev, events, count, win->eventMask, filter, grab); + if (attempt > 0) return EVENT_DELIVERED; if (attempt < 0) @@ -2046,7 +1971,6 @@ DeliverToWindowOwner(DeviceIntPtr dev, WindowPtr win, return EVENT_NOT_DELIVERED; } - /** * Get the list of clients that should be tried for event delivery on the * given window. @@ -2056,31 +1980,32 @@ DeliverToWindowOwner(DeviceIntPtr dev, WindowPtr win, */ static Bool GetClientsForDelivery(DeviceIntPtr dev, WindowPtr win, - xEvent *events, Mask filter, InputClients **clients) + xEvent *events, Mask filter, InputClients ** clients) { int rc = 0; if (core_get_type(events) != 0) - *clients = (InputClients *)wOtherClients(win); - else if (xi2_get_type(events) != 0) - { + *clients = (InputClients *) wOtherClients(win); + else if (xi2_get_type(events) != 0) { OtherInputMasks *inputMasks = wOtherInputMasks(win); + /* Has any client selected for the event? */ if (!WindowXI2MaskIsset(dev, win, events)) goto out; *clients = inputMasks->inputClients; - } else { + } + else { OtherInputMasks *inputMasks = wOtherInputMasks(win); + /* Has any client selected for the event? */ - if (!inputMasks || - !(inputMasks->inputEvents[dev->id] & filter)) + if (!inputMasks || !(inputMasks->inputEvents[dev->id] & filter)) goto out; *clients = inputMasks->inputClients; } rc = 1; -out: + out: return rc; } @@ -2089,7 +2014,7 @@ out: * accepts it and there is no interfering core grab.. */ static enum EventDeliveryState -DeliverEventToInputClients(DeviceIntPtr dev, InputClients *inputclients, +DeliverEventToInputClients(DeviceIntPtr dev, InputClients * inputclients, WindowPtr win, xEvent *events, int count, Mask filter, GrabPtr grab, ClientPtr *client_return, Mask *mask_return) @@ -2097,8 +2022,7 @@ DeliverEventToInputClients(DeviceIntPtr dev, InputClients *inputclients, int attempt; enum EventDeliveryState rc = EVENT_NOT_DELIVERED; - for (; inputclients; inputclients = inputclients->next) - { + for (; inputclients; inputclients = inputclients->next) { Mask mask; ClientPtr client = rClient(inputclients); @@ -2107,21 +2031,19 @@ DeliverEventToInputClients(DeviceIntPtr dev, InputClients *inputclients, mask = GetEventMask(dev, events, inputclients); - if (XaceHook(XACE_RECEIVE_ACCESS, client, win, - events, count)) - /* do nothing */; - else if ( (attempt = TryClientEvents(client, dev, - events, count, - mask, filter, grab)) ) - { - if (attempt > 0) - { + if (XaceHook(XACE_RECEIVE_ACCESS, client, win, events, count)) + /* do nothing */ ; + else if ((attempt = TryClientEvents(client, dev, + events, count, + mask, filter, grab))) { + if (attempt > 0) { rc = EVENT_DELIVERED; *client_return = client; *mask_return = mask; /* Success overrides non-success, so if we've been * successful on one client, return that */ - } else if (rc == EVENT_NOT_DELIVERED) + } + else if (rc == EVENT_NOT_DELIVERED) rc = EVENT_REJECTED; } } @@ -2129,7 +2051,6 @@ DeliverEventToInputClients(DeviceIntPtr dev, InputClients *inputclients, return rc; } - /** * Deliver events to clients registered on the window. * @@ -2152,7 +2073,6 @@ DeliverEventToWindowMask(DeviceIntPtr dev, WindowPtr win, xEvent *events, } - /** * Deliver events to a window. At this point, we do not yet know if the event * actually needs to be delivered. May activate a grab if the event is a @@ -2177,77 +2097,73 @@ DeliverEventToWindowMask(DeviceIntPtr dev, WindowPtr win, xEvent *events, */ int DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent - *pEvents, int count, Mask filter, GrabPtr grab) + *pEvents, int count, Mask filter, GrabPtr grab) { int deliveries = 0, nondeliveries = 0; ClientPtr client = NullClient; - Mask deliveryMask = 0; /* If a grab occurs due to a button press, then - this mask is the mask of the grab. */ + Mask deliveryMask = 0; /* If a grab occurs due to a button press, then + this mask is the mask of the grab. */ int type = pEvents->u.u.type; /* Deliver to window owner */ - if ((filter == CantBeFiltered) || core_get_type(pEvents) != 0) - { + if ((filter == CantBeFiltered) || core_get_type(pEvents) != 0) { enum EventDeliveryState rc; rc = DeliverToWindowOwner(pDev, pWin, pEvents, count, filter, grab); - switch(rc) - { - case EVENT_SKIP: - return 0; - case EVENT_REJECTED: - nondeliveries--; - break; - case EVENT_DELIVERED: - /* We delivered to the owner, with our event mask */ - deliveries++; - client = wClient(pWin); - deliveryMask = pWin->eventMask; - break; - case EVENT_NOT_DELIVERED: - break; + switch (rc) { + case EVENT_SKIP: + return 0; + case EVENT_REJECTED: + nondeliveries--; + break; + case EVENT_DELIVERED: + /* We delivered to the owner, with our event mask */ + deliveries++; + client = wClient(pWin); + deliveryMask = pWin->eventMask; + break; + case EVENT_NOT_DELIVERED: + break; } } /* CantBeFiltered means only window owner gets the event */ - if (filter != CantBeFiltered) - { + if (filter != CantBeFiltered) { enum EventDeliveryState rc; rc = DeliverEventToWindowMask(pDev, pWin, pEvents, count, filter, grab, &client, &deliveryMask); - switch(rc) - { - case EVENT_SKIP: - return 0; - case EVENT_REJECTED: - nondeliveries--; - break; - case EVENT_DELIVERED: - deliveries++; - break; - case EVENT_NOT_DELIVERED: - break; + switch (rc) { + case EVENT_SKIP: + return 0; + case EVENT_REJECTED: + nondeliveries--; + break; + case EVENT_DELIVERED: + deliveries++; + break; + case EVENT_NOT_DELIVERED: + break; } } - if (deliveries) - { + if (deliveries) { /* * Note that since core events are delivered first, an implicit grab may * be activated on a core grab, stopping the XI events. */ - if (!grab && ActivateImplicitGrab(pDev, client, pWin, pEvents, deliveryMask)) - /* grab activated */; + if (!grab && + ActivateImplicitGrab(pDev, client, pWin, pEvents, deliveryMask)) + /* grab activated */ ; else if (type == MotionNotify) pDev->valuator->motionHintWindow = pWin; else if (type == DeviceMotionNotify || type == DeviceButtonPress) - CheckDeviceGrabAndHintWindow (pWin, type, - (deviceKeyButtonPointer*) pEvents, - grab, client, deliveryMask); - return deliveries; + CheckDeviceGrabAndHintWindow(pWin, type, + (deviceKeyButtonPointer *) pEvents, + grab, client, deliveryMask); + return deliveries; } return nondeliveries; } @@ -2270,7 +2186,8 @@ FilterRawEvents(const ClientPtr client, const GrabPtr grab) if (!grab) return FALSE; - client_xi_version = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey); + client_xi_version = + dixLookupPrivate(&client->devPrivates, XIClientPrivateKey); cmp = version_compare(client_xi_version->major_version, client_xi_version->minor_version, 2, 0); @@ -2296,21 +2213,19 @@ DeliverRawEvent(RawDeviceEvent *ev, DeviceIntPtr device) int i, rc; int filter; - rc = EventToXI2((InternalEvent*)ev, (xEvent**)&xi); - if (rc != Success) - { + rc = EventToXI2((InternalEvent *) ev, (xEvent **) &xi); + if (rc != Success) { ErrorF("[Xi] %s: XI2 conversion failed in %s (%d)\n", - __func__, device->name, rc); + __func__, device->name, rc); return; } if (grab) - DeliverGrabbedEvent((InternalEvent*)ev, device, FALSE); + DeliverGrabbedEvent((InternalEvent *) ev, device, FALSE); filter = GetEventFilter(device, xi); - for (i = 0; i < screenInfo.numScreens; i++) - { + for (i = 0; i < screenInfo.numScreens; i++) { WindowPtr root; InputClients *inputclients; @@ -2318,10 +2233,9 @@ DeliverRawEvent(RawDeviceEvent *ev, DeviceIntPtr device) if (!GetClientsForDelivery(device, root, xi, filter, &inputclients)) continue; - for (; inputclients; inputclients = inputclients->next) - { - ClientPtr c; /* unused */ - Mask m; /* unused */ + for (; inputclients; inputclients = inputclients->next) { + ClientPtr c; /* unused */ + Mask m; /* unused */ InputClients ic = *inputclients; /* Because we run through the list manually, copy the actual @@ -2348,17 +2262,15 @@ DeliverRawEvent(RawDeviceEvent *ev, DeviceIntPtr device) #ifdef PANORAMIX static int -XineramaTryClientEventsResult( - ClientPtr client, - GrabPtr grab, - Mask mask, - Mask filter -){ +XineramaTryClientEventsResult(ClientPtr client, + GrabPtr grab, Mask mask, Mask filter) +{ if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) return -1; - else return 1; + ((filter == CantBeFiltered) || (mask & filter))) { + if (grab && !SameClient(grab, client)) + return -1; + else + return 1; } return 0; } @@ -2379,43 +2291,40 @@ MaybeDeliverEventsToClient(WindowPtr pWin, xEvent *pEvents, { OtherClients *other; - - if (pWin->eventMask & filter) - { + if (pWin->eventMask & filter) { if (wClient(pWin) == dontClient) - return 0; + return 0; #ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - wClient(pWin), NullGrab, pWin->eventMask, filter); + if (!noPanoramiXExtension && pWin->drawable.pScreen->myNum) + return XineramaTryClientEventsResult(wClient(pWin), NullGrab, + pWin->eventMask, filter); #endif - if (XaceHook(XACE_RECEIVE_ACCESS, wClient(pWin), pWin, pEvents, count)) - return 1; /* don't send, but pretend we did */ - return TryClientEvents(wClient(pWin), NULL, pEvents, count, - pWin->eventMask, filter, NullGrab); + if (XaceHook(XACE_RECEIVE_ACCESS, wClient(pWin), pWin, pEvents, count)) + return 1; /* don't send, but pretend we did */ + return TryClientEvents(wClient(pWin), NULL, pEvents, count, + pWin->eventMask, filter, NullGrab); } - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->mask & filter) - { + for (other = wOtherClients(pWin); other; other = other->next) { + if (other->mask & filter) { if (SameClient(other, dontClient)) - return 0; + return 0; #ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult( - rClient(other), NullGrab, other->mask, filter); + if (!noPanoramiXExtension && pWin->drawable.pScreen->myNum) + return XineramaTryClientEventsResult(rClient(other), NullGrab, + other->mask, filter); #endif - if (XaceHook(XACE_RECEIVE_ACCESS, rClient(other), pWin, pEvents, - count)) - return 1; /* don't send, but pretend we did */ - return TryClientEvents(rClient(other), NULL, pEvents, count, - other->mask, filter, NullGrab); - } + if (XaceHook(XACE_RECEIVE_ACCESS, rClient(other), pWin, pEvents, + count)) + return 1; /* don't send, but pretend we did */ + return TryClientEvents(rClient(other), NULL, pEvents, count, + other->mask, filter, NullGrab); + } } return 2; } -static Window FindChildForEvent(SpritePtr pSprite, WindowPtr event) +static Window +FindChildForEvent(SpritePtr pSprite, WindowPtr event) { WindowPtr w = DeepestSpriteWin(pSprite); Window child = None; @@ -2424,19 +2333,16 @@ static Window FindChildForEvent(SpritePtr pSprite, WindowPtr event) set to none or should the value in the argument be passed through. It probably doesn't matter since everyone calls this function with child == None anyway. */ - while (w) - { + while (w) { /* If the source window is same as event window, child should be none. Don't bother going all all the way back to the root. */ - if (w == event) - { + if (w == event) { child = None; break; } - if (w->parent == event) - { + if (w->parent == event) { child = w->drawable.id; break; } @@ -2454,56 +2360,48 @@ static Window FindChildForEvent(SpritePtr pSprite, WindowPtr event) * @param calcChild If True, calculate the child window. */ void -FixUpEventFromWindow( - SpritePtr pSprite, - xEvent *xE, - WindowPtr pWin, - Window child, - Bool calcChild) +FixUpEventFromWindow(SpritePtr pSprite, + xEvent *xE, WindowPtr pWin, Window child, Bool calcChild) { int evtype; if (calcChild) child = FindChildForEvent(pSprite, pWin); - if ((evtype = xi2_get_type(xE))) - { - xXIDeviceEvent* event = (xXIDeviceEvent*)xE; - - switch (evtype) - { - case XI_RawKeyPress: - case XI_RawKeyRelease: - case XI_RawButtonPress: - case XI_RawButtonRelease: - case XI_RawMotion: - case XI_RawTouchBegin: - case XI_RawTouchUpdate: - case XI_RawTouchEnd: - case XI_DeviceChanged: - case XI_HierarchyChanged: - case XI_PropertyEvent: - return; - default: - break; + if ((evtype = xi2_get_type(xE))) { + xXIDeviceEvent *event = (xXIDeviceEvent *) xE; + + switch (evtype) { + case XI_RawKeyPress: + case XI_RawKeyRelease: + case XI_RawButtonPress: + case XI_RawButtonRelease: + case XI_RawMotion: + case XI_RawTouchBegin: + case XI_RawTouchUpdate: + case XI_RawTouchEnd: + case XI_DeviceChanged: + case XI_HierarchyChanged: + case XI_PropertyEvent: + return; + default: + break; } event->root = RootWindow(pSprite)->drawable.id; event->event = pWin->drawable.id; - if (evtype == XI_TouchOwnership) - { + if (evtype == XI_TouchOwnership) { event->child = child; return; } - if (pSprite->hot.pScreen == pWin->drawable.pScreen) - { + if (pSprite->hot.pScreen == pWin->drawable.pScreen) { event->event_x = event->root_x - FP1616(pWin->drawable.x, 0); event->event_y = event->root_y - FP1616(pWin->drawable.y, 0); event->child = child; - } else - { + } + else { event->event_x = 0; event->event_y = 0; event->child = None; @@ -2511,24 +2409,20 @@ FixUpEventFromWindow( if (event->evtype == XI_Enter || event->evtype == XI_Leave || event->evtype == XI_FocusIn || event->evtype == XI_FocusOut) - ((xXIEnterEvent*)event)->same_screen = + ((xXIEnterEvent *) event)->same_screen = (pSprite->hot.pScreen == pWin->drawable.pScreen); - } else - { + } + else { XE_KBPTR.root = RootWindow(pSprite)->drawable.id; XE_KBPTR.event = pWin->drawable.id; - if (pSprite->hot.pScreen == pWin->drawable.pScreen) - { + if (pSprite->hot.pScreen == pWin->drawable.pScreen) { XE_KBPTR.sameScreen = xTrue; XE_KBPTR.child = child; - XE_KBPTR.eventX = - XE_KBPTR.rootX - pWin->drawable.x; - XE_KBPTR.eventY = - XE_KBPTR.rootY - pWin->drawable.y; + XE_KBPTR.eventX = XE_KBPTR.rootX - pWin->drawable.x; + XE_KBPTR.eventY = XE_KBPTR.rootY - pWin->drawable.y; } - else - { + else { XE_KBPTR.sameScreen = xFalse; XE_KBPTR.child = None; XE_KBPTR.eventX = 0; @@ -2558,14 +2452,12 @@ EventIsDeliverable(DeviceIntPtr dev, int evtype, WindowPtr win) int type; OtherInputMasks *inputMasks = wOtherInputMasks(win); - if ((type = GetXI2Type(evtype)) != 0) - { + if ((type = GetXI2Type(evtype)) != 0) { if (inputMasks && xi2mask_isset(inputMasks->xi2mask, dev, type)) rc |= EVENT_XI2_MASK; } - if ((type = GetXIType(evtype)) != 0) - { + if ((type = GetXIType(evtype)) != 0) { filter = event_get_filter_from_type(dev, type); /* Check for XI mask */ @@ -2580,8 +2472,7 @@ EventIsDeliverable(DeviceIntPtr dev, int evtype, WindowPtr win) } - if ((type = GetCoreType(evtype)) != 0) - { + if ((type = GetCoreType(evtype)) != 0) { filter = event_get_filter_from_type(dev, type); /* Check for core mask */ @@ -2608,8 +2499,7 @@ DeliverEvent(DeviceIntPtr dev, xEvent *xE, int count, if (XaceHook(XACE_SEND_ACCESS, NULL, dev, win, xE, count) == Success) { filter = GetEventFilter(dev, xE); FixUpEventFromWindow(pSprite, xE, win, child, FALSE); - deliveries = DeliverEventsToWindow(dev, win, xE, count, - filter, grab); + deliveries = DeliverEventsToWindow(dev, win, xE, count, filter, grab); } return deliveries; @@ -2624,26 +2514,26 @@ DeliverOneEvent(InternalEvent *event, DeviceIntPtr dev, enum InputLevel level, int deliveries = 0; int rc; - switch(level) - { - case XI2: - rc = EventToXI2(event, &xE); - count = 1; - break; - case XI: - rc = EventToXI(event, &xE, &count); - break; - case CORE: - rc = EventToCore(event, &xE, &count); - break; + switch (level) { + case XI2: + rc = EventToXI2(event, &xE); + count = 1; + break; + case XI: + rc = EventToXI(event, &xE, &count); + break; + case CORE: + rc = EventToCore(event, &xE, &count); + break; } - if (rc == Success) - { + if (rc == Success) { deliveries = DeliverEvent(dev, xE, count, win, child, grab); free(xE); - } else - BUG_WARN_MSG(rc != BadMatch, "%s: conversion to level %d failed with rc %d\n", + } + else + BUG_WARN_MSG(rc != BadMatch, + "%s: conversion to level %d failed with rc %d\n", dev->name, level, rc); return deliveries; } @@ -2677,30 +2567,27 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab, verify_internal_event(event); - while (pWin) - { - if ((mask = EventIsDeliverable(dev, event->any.type, pWin))) - { + while (pWin) { + if ((mask = EventIsDeliverable(dev, event->any.type, pWin))) { /* XI2 events first */ - if (mask & EVENT_XI2_MASK) - { - deliveries = DeliverOneEvent(event, dev, XI2, pWin, child, grab); + if (mask & EVENT_XI2_MASK) { + deliveries = + DeliverOneEvent(event, dev, XI2, pWin, child, grab); if (deliveries > 0) break; } /* XI events */ - if (mask & EVENT_XI1_MASK) - { + if (mask & EVENT_XI1_MASK) { deliveries = DeliverOneEvent(event, dev, XI, pWin, child, grab); if (deliveries > 0) break; } /* Core event */ - if ((mask & EVENT_CORE_MASK) && IsMaster(dev) && dev->coreEvents) - { - deliveries = DeliverOneEvent(event, dev, CORE, pWin, child, grab); + if ((mask & EVENT_CORE_MASK) && IsMaster(dev) && dev->coreEvents) { + deliveries = + DeliverOneEvent(event, dev, CORE, pWin, child, grab); if (deliveries > 0) break; } @@ -2708,8 +2595,7 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab, } if ((deliveries < 0) || (pWin == stopAt) || - (mask & EVENT_DONT_PROPAGATE_MASK)) - { + (mask & EVENT_DONT_PROPAGATE_MASK)) { deliveries = 0; break; } @@ -2735,97 +2621,93 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab, * @param otherParent Used for ReparentNotify events. */ int -DeliverEvents(WindowPtr pWin, xEvent *xE, int count, - WindowPtr otherParent) +DeliverEvents(WindowPtr pWin, xEvent *xE, int count, WindowPtr otherParent) { DeviceIntRec dummy; - int deliveries; + int deliveries; #ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return count; + if (!noPanoramiXExtension && pWin->drawable.pScreen->myNum) + return count; #endif if (!count) - return 0; + return 0; dummy.id = XIAllDevices; - switch (xE->u.u.type) - { - case DestroyNotify: - case UnmapNotify: - case MapNotify: - case MapRequest: - case ReparentNotify: - case ConfigureNotify: - case ConfigureRequest: - case GravityNotify: - case CirculateNotify: - case CirculateRequest: - xE->u.destroyNotify.event = pWin->drawable.id; - break; + switch (xE->u.u.type) { + case DestroyNotify: + case UnmapNotify: + case MapNotify: + case MapRequest: + case ReparentNotify: + case ConfigureNotify: + case ConfigureRequest: + case GravityNotify: + case CirculateNotify: + case CirculateRequest: + xE->u.destroyNotify.event = pWin->drawable.id; + break; } - switch (xE->u.u.type) + switch (xE->u.u.type) { + case DestroyNotify: + case UnmapNotify: + case MapNotify: + case ReparentNotify: + case ConfigureNotify: + case GravityNotify: + case CirculateNotify: + break; + default: { - case DestroyNotify: - case UnmapNotify: - case MapNotify: - case ReparentNotify: - case ConfigureNotify: - case GravityNotify: - case CirculateNotify: - break; - default: - { - Mask filter; - filter = GetEventFilter(&dummy, xE); - return DeliverEventsToWindow(&dummy, pWin, xE, count, filter, - NullGrab); - } + Mask filter; + + filter = GetEventFilter(&dummy, xE); + return DeliverEventsToWindow(&dummy, pWin, xE, count, filter, NullGrab); + } } deliveries = DeliverEventsToWindow(&dummy, pWin, xE, count, StructureNotifyMask, NullGrab); - if (pWin->parent) - { - xE->u.destroyNotify.event = pWin->parent->drawable.id; - deliveries += DeliverEventsToWindow(&dummy, pWin->parent, xE, count, - SubstructureNotifyMask, NullGrab); - if (xE->u.u.type == ReparentNotify) - { - xE->u.destroyNotify.event = otherParent->drawable.id; + if (pWin->parent) { + xE->u.destroyNotify.event = pWin->parent->drawable.id; + deliveries += DeliverEventsToWindow(&dummy, pWin->parent, xE, count, + SubstructureNotifyMask, NullGrab); + if (xE->u.u.type == ReparentNotify) { + xE->u.destroyNotify.event = otherParent->drawable.id; deliveries += DeliverEventsToWindow(&dummy, - otherParent, xE, count, SubstructureNotifyMask, - NullGrab); - } + otherParent, xE, count, + SubstructureNotifyMask, + NullGrab); + } } return deliveries; } - static Bool PointInBorderSize(WindowPtr pWin, int x, int y) { BoxRec box; - if(RegionContainsPoint(&pWin->borderSize, x, y, &box)) - return TRUE; + if (RegionContainsPoint(&pWin->borderSize, x, y, &box)) + return TRUE; #ifdef PANORAMIX - if(!noPanoramiXExtension && - XineramaSetWindowPntrs(inputInfo.pointer, pWin)) { - SpritePtr pSprite = inputInfo.pointer->spriteInfo->sprite; - int i; - - FOR_NSCREENS_FORWARD_SKIP(i) { - if(RegionContainsPoint(&pSprite->windows[i]->borderSize, - x + screenInfo.screens[0]->x - screenInfo.screens[i]->x, - y + screenInfo.screens[0]->y - screenInfo.screens[i]->y, - &box)) - return TRUE; - } + if (!noPanoramiXExtension && + XineramaSetWindowPntrs(inputInfo.pointer, pWin)) { + SpritePtr pSprite = inputInfo.pointer->spriteInfo->sprite; + int i; + + FOR_NSCREENS_FORWARD_SKIP(i) { + if (RegionContainsPoint(&pSprite->windows[i]->borderSize, + x + screenInfo.screens[0]->x - + screenInfo.screens[i]->x, + y + screenInfo.screens[0]->y - + screenInfo.screens[i]->y, &box)) + return TRUE; + } } #endif return FALSE; @@ -2845,49 +2727,47 @@ PointInBorderSize(WindowPtr pWin, int x, int y) WindowPtr XYToWindow(SpritePtr pSprite, int x, int y) { - WindowPtr pWin; - BoxRec box; + WindowPtr pWin; + BoxRec box; - pSprite->spriteTraceGood = 1; /* root window still there */ + pSprite->spriteTraceGood = 1; /* root window still there */ pWin = RootWindow(pSprite)->firstChild; - while (pWin) - { - 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)) - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y)) - && (!wInputShape(pWin) || - RegionContainsPoint(wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box)) + while (pWin) { + 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)) + /* When a window is shaped, a further check + * is made to see if the point is inside + * borderSize + */ + && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y)) + && (!wInputShape(pWin) || + RegionContainsPoint(wInputShape(pWin), + x - pWin->drawable.x, + y - pWin->drawable.y, &box)) #ifdef ROOTLESS - /* In rootless mode windows may be offscreen, even when - * they're in X's stack. (E.g. if the native window system - * implements some form of virtual desktop system). - */ - && !pWin->rootlessUnhittable + /* In rootless mode windows may be offscreen, even when + * they're in X's stack. (E.g. if the native window system + * implements some form of virtual desktop system). + */ + && !pWin->rootlessUnhittable #endif - ) - { - if (pSprite->spriteTraceGood >= pSprite->spriteTraceSize) - { - pSprite->spriteTraceSize += 10; - pSprite->spriteTrace = realloc(pSprite->spriteTrace, - pSprite->spriteTraceSize*sizeof(WindowPtr)); - } - pSprite->spriteTrace[pSprite->spriteTraceGood++] = pWin; - pWin = pWin->firstChild; - } - else - pWin = pWin->nextSib; + ) { + if (pSprite->spriteTraceGood >= pSprite->spriteTraceSize) { + pSprite->spriteTraceSize += 10; + pSprite->spriteTrace = realloc(pSprite->spriteTrace, + pSprite->spriteTraceSize * + sizeof(WindowPtr)); + } + pSprite->spriteTrace[pSprite->spriteTraceGood++] = pWin; + pWin = pWin->firstChild; + } + else + pWin = pWin->nextSib; } return DeepestSpriteWin(pSprite); } @@ -2905,15 +2785,14 @@ ActivateFocusInGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win) BOOL rc = FALSE; DeviceEvent event; - if (dev->deviceGrab.grab) - { + if (dev->deviceGrab.grab) { if (!dev->deviceGrab.fromPassiveGrab || dev->deviceGrab.grab->type != XI_Enter || dev->deviceGrab.grab->window == win || IsParent(dev->deviceGrab.grab->window, win)) return FALSE; DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveUngrab); - (*dev->deviceGrab.DeactivateGrab)(dev); + (*dev->deviceGrab.DeactivateGrab) (dev); } if (win == NoneWin || win == PointerRootWin) @@ -2946,15 +2825,14 @@ ActivateEnterGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win) BOOL rc = FALSE; DeviceEvent event; - if (dev->deviceGrab.grab) - { + if (dev->deviceGrab.grab) { if (!dev->deviceGrab.fromPassiveGrab || dev->deviceGrab.grab->type != XI_Enter || dev->deviceGrab.grab->window == win || IsParent(dev->deviceGrab.grab->window, win)) return FALSE; DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveUngrab); - (*dev->deviceGrab.DeactivateGrab)(dev); + (*dev->deviceGrab.DeactivateGrab) (dev); } memset(&event, 0, sizeof(DeviceEvent)); @@ -2989,42 +2867,38 @@ CheckMotion(DeviceEvent *ev, DeviceIntPtr pDev) WindowPtr prevSpriteWin, newSpriteWin; SpritePtr pSprite = pDev->spriteInfo->sprite; - verify_internal_event((InternalEvent *)ev); + verify_internal_event((InternalEvent *) ev); prevSpriteWin = pSprite->win; - if (ev && !syncEvents.playingEvents) - { + if (ev && !syncEvents.playingEvents) { /* GetPointerEvents() guarantees that pointer events have the correct rootX/Y set already. */ - switch (ev->type) - { - case ET_ButtonPress: - case ET_ButtonRelease: - case ET_Motion: - case ET_TouchBegin: - case ET_TouchUpdate: - case ET_TouchEnd: - break; - default: - /* all other events return FALSE */ - return FALSE; + switch (ev->type) { + case ET_ButtonPress: + case ET_ButtonRelease: + case ET_Motion: + case ET_TouchBegin: + case ET_TouchUpdate: + case ET_TouchEnd: + break; + default: + /* all other events return FALSE */ + return FALSE; } - #ifdef PANORAMIX - if (!noPanoramiXExtension) - { + if (!noPanoramiXExtension) { /* Motion events entering DIX get translated to Screen 0 coordinates. Replayed events have already been translated since they've entered DIX before */ ev->root_x += pSprite->screen->x - screenInfo.screens[0]->x; ev->root_y += pSprite->screen->y - screenInfo.screens[0]->y; - } else + } + else #endif { - if (pSprite->hot.pScreen != pSprite->hotPhys.pScreen) - { + if (pSprite->hot.pScreen != pSprite->hotPhys.pScreen) { pSprite->hot.pScreen = pSprite->hotPhys.pScreen; RootWindow(pDev->spriteInfo->sprite) = pSprite->hot.pScreen->root; @@ -3041,43 +2915,49 @@ CheckMotion(DeviceEvent *ev, DeviceIntPtr pDev) pSprite->hot.y = pSprite->physLimits.y1; else if (pSprite->hot.y >= pSprite->physLimits.y2) pSprite->hot.y = pSprite->physLimits.y2 - 1; - if (pSprite->hotShape) - ConfineToShape(pDev, pSprite->hotShape, &pSprite->hot.x, &pSprite->hot.y); - pSprite->hotPhys = pSprite->hot; + if (pSprite->hotShape) + ConfineToShape(pDev, pSprite->hotShape, &pSprite->hot.x, + &pSprite->hot.y); + pSprite->hotPhys = pSprite->hot; - if ((pSprite->hotPhys.x != ev->root_x) || - (pSprite->hotPhys.y != ev->root_y)) - { + if ((pSprite->hotPhys.x != ev->root_x) || + (pSprite->hotPhys.y != ev->root_y)) { #ifdef PANORAMIX - if (!noPanoramiXExtension) - { - XineramaSetCursorPosition( - pDev, pSprite->hotPhys.x, pSprite->hotPhys.y, FALSE); - } else + if (!noPanoramiXExtension) { + XineramaSetCursorPosition(pDev, pSprite->hotPhys.x, + pSprite->hotPhys.y, FALSE); + } + else #endif { - (*pSprite->hotPhys.pScreen->SetCursorPosition)( - pDev, pSprite->hotPhys.pScreen, - pSprite->hotPhys.x, pSprite->hotPhys.y, FALSE); + (*pSprite->hotPhys.pScreen->SetCursorPosition) (pDev, + pSprite-> + hotPhys.pScreen, + pSprite-> + hotPhys.x, + pSprite-> + hotPhys.y, + FALSE); } - } + } - ev->root_x = pSprite->hot.x; - ev->root_y = pSprite->hot.y; + ev->root_x = pSprite->hot.x; + ev->root_y = pSprite->hot.y; } newSpriteWin = XYToWindow(pSprite, pSprite->hot.x, pSprite->hot.y); - if (newSpriteWin != prevSpriteWin) - { + if (newSpriteWin != prevSpriteWin) { int sourceid; + if (!ev) { UpdateCurrentTimeIf(); - sourceid = pDev->id; /* when from WindowsRestructured */ - } else + sourceid = pDev->id; /* when from WindowsRestructured */ + } + else sourceid = ev->sourceid; - if (prevSpriteWin != NullWindow) { + if (prevSpriteWin != NullWindow) { if (!ActivateEnterGrab(pDev, prevSpriteWin, newSpriteWin)) DoEnterLeaveEvents(pDev, sourceid, prevSpriteWin, newSpriteWin, NotifyNormal); @@ -3100,8 +2980,8 @@ void WindowsRestructured(void) { DeviceIntPtr pDev = inputInfo.devices; - while(pDev) - { + + while (pDev) { if (IsMaster(pDev) || IsFloating(pDev)) CheckMotion(NULL, pDev); pDev = pDev->next; @@ -3114,25 +2994,25 @@ WindowsRestructured(void) * other than 0,0, the information in the private sprite structure must * be updated accordingly, or XYToWindow (and other routines) will not * compute correctly. */ -void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff) +void +ReinitializeRootWindow(WindowPtr win, int xoff, int yoff) { - GrabPtr grab; + GrabPtr grab; DeviceIntPtr pDev; SpritePtr pSprite; - if (noPanoramiXExtension) return; + if (noPanoramiXExtension) + return; pDev = inputInfo.devices; - while(pDev) - { - if (DevHasCursor(pDev)) - { + while (pDev) { + if (DevHasCursor(pDev)) { pSprite = pDev->spriteInfo->sprite; - pSprite->hot.x -= xoff; - pSprite->hot.y -= yoff; + pSprite->hot.x -= xoff; + pSprite->hot.y -= yoff; - pSprite->hotPhys.x -= xoff; - pSprite->hotPhys.y -= yoff; + pSprite->hotPhys.x -= xoff; + pSprite->hotPhys.y -= yoff; pSprite->hotLimits.x1 -= xoff; pSprite->hotLimits.y1 -= yoff; @@ -3147,14 +3027,14 @@ void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff) /* FIXME: if we call ConfineCursorToWindow, must we do anything else? */ if ((grab = pDev->deviceGrab.grab) && grab->confineTo) { if (grab->confineTo->drawable.pScreen - != pSprite->hotPhys.pScreen) + != pSprite->hotPhys.pScreen) pSprite->hotPhys.x = pSprite->hotPhys.y = 0; ConfineCursorToWindow(pDev, grab->confineTo, TRUE, TRUE); - } else - ConfineCursorToWindow( - pDev, - pSprite->hotPhys.pScreen->root, - TRUE, FALSE); + } + else + ConfineCursorToWindow(pDev, + pSprite->hotPhys.pScreen->root, + TRUE, FALSE); } pDev = pDev->next; @@ -3184,11 +3064,10 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin) ScreenPtr pScreen; CursorPtr pCursor; - if (!pDev->spriteInfo->sprite) - { + if (!pDev->spriteInfo->sprite) { DeviceIntPtr it; - pDev->spriteInfo->sprite = (SpritePtr)calloc(1, sizeof(SpriteRec)); + pDev->spriteInfo->sprite = (SpritePtr) calloc(1, sizeof(SpriteRec)); if (!pDev->spriteInfo->sprite) FatalError("InitializeSprite: failed to allocate sprite struct"); @@ -3198,8 +3077,7 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin) * * The VCK is always paired with the VCP before the VCP has a sprite. */ - for (it = inputInfo.devices; it; it = it->next) - { + for (it = inputInfo.devices; it; it = it->next) { if (it->spriteInfo->paired == pDev) it->spriteInfo->sprite = pDev->spriteInfo->sprite; } @@ -3210,11 +3088,10 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin) pSprite = pDev->spriteInfo->sprite; pDev->spriteInfo->spriteOwner = TRUE; - pScreen = (pWin) ? pWin->drawable.pScreen : (ScreenPtr)NULL; + pScreen = (pWin) ? pWin->drawable.pScreen : (ScreenPtr) NULL; pSprite->hot.pScreen = pScreen; pSprite->hotPhys.pScreen = pScreen; - if (pScreen) - { + if (pScreen) { pSprite->hotPhys.x = pScreen->width / 2; pSprite->hotPhys.y = pScreen->height / 2; pSprite->hotLimits.x2 = pScreen->width; @@ -3224,53 +3101,50 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin) pSprite->hot = pSprite->hotPhys; pSprite->win = pWin; - if (pWin) - { - pCursor = wCursor(pWin); - pSprite->spriteTrace = (WindowPtr *)calloc(1, 32*sizeof(WindowPtr)); - if (!pSprite->spriteTrace) - FatalError("Failed to allocate spriteTrace"); - pSprite->spriteTraceSize = 32; + if (pWin) { + pCursor = wCursor(pWin); + pSprite->spriteTrace = (WindowPtr *) calloc(1, 32 * sizeof(WindowPtr)); + if (!pSprite->spriteTrace) + FatalError("Failed to allocate spriteTrace"); + pSprite->spriteTraceSize = 32; - RootWindow(pDev->spriteInfo->sprite) = pWin; - pSprite->spriteTraceGood = 1; + RootWindow(pDev->spriteInfo->sprite) = pWin; + pSprite->spriteTraceGood = 1; - pSprite->pEnqueueScreen = pScreen; - pSprite->pDequeueScreen = pSprite->pEnqueueScreen; + pSprite->pEnqueueScreen = pScreen; + pSprite->pDequeueScreen = pSprite->pEnqueueScreen; - } else { + } + else { pCursor = NullCursor; - pSprite->spriteTrace = NULL; - pSprite->spriteTraceSize = 0; - pSprite->spriteTraceGood = 0; - pSprite->pEnqueueScreen = screenInfo.screens[0]; - pSprite->pDequeueScreen = pSprite->pEnqueueScreen; + pSprite->spriteTrace = NULL; + pSprite->spriteTraceSize = 0; + pSprite->spriteTraceGood = 0; + pSprite->pEnqueueScreen = screenInfo.screens[0]; + pSprite->pDequeueScreen = pSprite->pEnqueueScreen; } if (pCursor) - pCursor->refcnt++; + pCursor->refcnt++; if (pSprite->current) - FreeCursor(pSprite->current, None); + FreeCursor(pSprite->current, None); pSprite->current = pCursor; - if (pScreen) - { - (*pScreen->RealizeCursor) ( pDev, pScreen, pSprite->current); - (*pScreen->CursorLimits) ( pDev, pScreen, pSprite->current, - &pSprite->hotLimits, &pSprite->physLimits); + if (pScreen) { + (*pScreen->RealizeCursor) (pDev, pScreen, pSprite->current); + (*pScreen->CursorLimits) (pDev, pScreen, pSprite->current, + &pSprite->hotLimits, &pSprite->physLimits); pSprite->confined = FALSE; - (*pScreen->ConstrainCursor) (pDev, pScreen, - &pSprite->physLimits); + (*pScreen->ConstrainCursor) (pDev, pScreen, &pSprite->physLimits); (*pScreen->SetCursorPosition) (pDev, pScreen, pSprite->hot.x, - pSprite->hot.y, - FALSE); + pSprite->hot.y, FALSE); (*pScreen->DisplayCursor) (pDev, pScreen, pSprite->current); } #ifdef PANORAMIX - if(!noPanoramiXExtension) { + if (!noPanoramiXExtension) { pSprite->hotLimits.x1 = -screenInfo.screens[0]->x; pSprite->hotLimits.y1 = -screenInfo.screens[0]->y; - pSprite->hotLimits.x2 = PanoramiXPixWidth - screenInfo.screens[0]->x; + pSprite->hotLimits.x2 = PanoramiXPixWidth - screenInfo.screens[0]->x; pSprite->hotLimits.y2 = PanoramiXPixHeight - screenInfo.screens[0]->y; pSprite->physLimits = pSprite->hotLimits; pSprite->confineWin = NullWindow; @@ -3304,8 +3178,9 @@ UpdateSpriteForScreen(DeviceIntPtr pDev, ScreenPtr pScreen) SpritePtr pSprite = NULL; WindowPtr win = NULL; CursorPtr pCursor; + if (!pScreen) - return ; + return; if (!pDev->spriteInfo->sprite) return; @@ -3321,26 +3196,25 @@ UpdateSpriteForScreen(DeviceIntPtr pDev, ScreenPtr pScreen) pSprite->win = win; pCursor = wCursor(win); if (pCursor) - pCursor->refcnt++; + pCursor->refcnt++; if (pSprite->current) - FreeCursor(pSprite->current, 0); + FreeCursor(pSprite->current, 0); pSprite->current = pCursor; pSprite->spriteTraceGood = 1; pSprite->spriteTrace[0] = win; (*pScreen->CursorLimits) (pDev, pScreen, pSprite->current, - &pSprite->hotLimits, - &pSprite->physLimits); + &pSprite->hotLimits, &pSprite->physLimits); pSprite->confined = FALSE; (*pScreen->ConstrainCursor) (pDev, pScreen, &pSprite->physLimits); (*pScreen->DisplayCursor) (pDev, pScreen, pSprite->current); #ifdef PANORAMIX - if(!noPanoramiXExtension) { + if (!noPanoramiXExtension) { pSprite->hotLimits.x1 = -screenInfo.screens[0]->x; pSprite->hotLimits.y1 = -screenInfo.screens[0]->y; - pSprite->hotLimits.x2 = PanoramiXPixWidth - screenInfo.screens[0]->x; + pSprite->hotLimits.x2 = PanoramiXPixWidth - screenInfo.screens[0]->x; pSprite->hotLimits.y2 = PanoramiXPixHeight - screenInfo.screens[0]->y; pSprite->physLimits = pSprite->hotLimits; pSprite->screen = pScreen; @@ -3360,7 +3234,7 @@ WindowHasNewCursor(WindowPtr pWin) { DeviceIntPtr pDev; - for(pDev = inputInfo.devices; pDev; pDev = pDev->next) + for (pDev = inputInfo.devices; pDev; pDev = pDev->next) if (DevHasCursor(pDev)) PostNewCursor(pDev); } @@ -3371,72 +3245,76 @@ NewCurrentScreen(DeviceIntPtr pDev, ScreenPtr newScreen, int x, int y) DeviceIntPtr ptr; SpritePtr pSprite; - ptr = IsFloating(pDev) ? pDev : GetXTestDevice(GetMaster(pDev, MASTER_POINTER)); + ptr = + IsFloating(pDev) ? pDev : + GetXTestDevice(GetMaster(pDev, MASTER_POINTER)); pSprite = ptr->spriteInfo->sprite; pSprite->hotPhys.x = x; pSprite->hotPhys.y = y; #ifdef PANORAMIX - if(!noPanoramiXExtension) { - pSprite->hotPhys.x += newScreen->x - screenInfo.screens[0]->x; - pSprite->hotPhys.y += newScreen->y - screenInfo.screens[0]->y; - if (newScreen != pSprite->screen) { - pSprite->screen = newScreen; - /* Make sure we tell the DDX to update its copy of the screen */ - if(pSprite->confineWin) - XineramaConfineCursorToWindow(ptr, - pSprite->confineWin, TRUE); - else - XineramaConfineCursorToWindow(ptr, screenInfo.screens[0]->root, TRUE); - /* if the pointer wasn't confined, the DDX won't get - told of the pointer warp so we reposition it here */ - if(!syncEvents.playingEvents) - (*pSprite->screen->SetCursorPosition)( - ptr, - pSprite->screen, - pSprite->hotPhys.x + screenInfo.screens[0]->x - - pSprite->screen->x, - pSprite->hotPhys.y + screenInfo.screens[0]->y - - pSprite->screen->y, FALSE); - } - } else + if (!noPanoramiXExtension) { + pSprite->hotPhys.x += newScreen->x - screenInfo.screens[0]->x; + pSprite->hotPhys.y += newScreen->y - screenInfo.screens[0]->y; + if (newScreen != pSprite->screen) { + pSprite->screen = newScreen; + /* Make sure we tell the DDX to update its copy of the screen */ + if (pSprite->confineWin) + XineramaConfineCursorToWindow(ptr, pSprite->confineWin, TRUE); + else + XineramaConfineCursorToWindow(ptr, screenInfo.screens[0]->root, + TRUE); + /* if the pointer wasn't confined, the DDX won't get + told of the pointer warp so we reposition it here */ + if (!syncEvents.playingEvents) + (*pSprite->screen->SetCursorPosition) (ptr, + pSprite->screen, + pSprite->hotPhys.x + + screenInfo.screens[0]-> + x - pSprite->screen->x, + pSprite->hotPhys.y + + screenInfo.screens[0]-> + y - pSprite->screen->y, + FALSE); + } + } + else #endif if (newScreen != pSprite->hotPhys.pScreen) - ConfineCursorToWindow(ptr, newScreen->root, TRUE, FALSE); + ConfineCursorToWindow(ptr, newScreen->root, TRUE, FALSE); } #ifdef PANORAMIX static Bool -XineramaPointInWindowIsVisible( - WindowPtr pWin, - int x, - int y -) +XineramaPointInWindowIsVisible(WindowPtr pWin, int x, int y) { BoxRec box; int i, xoff, yoff; - if (!pWin->realized) return FALSE; + if (!pWin->realized) + return FALSE; if (RegionContainsPoint(&pWin->borderClip, x, y, &box)) return TRUE; - if(!XineramaSetWindowPntrs(inputInfo.pointer, pWin)) return FALSE; + if (!XineramaSetWindowPntrs(inputInfo.pointer, pWin)) + return FALSE; xoff = x + screenInfo.screens[0]->x; yoff = y + screenInfo.screens[0]->y; FOR_NSCREENS_FORWARD_SKIP(i) { - pWin = inputInfo.pointer->spriteInfo->sprite->windows[i]; - x = xoff - screenInfo.screens[i]->x; - y = yoff - screenInfo.screens[i]->y; - - if(RegionContainsPoint(&pWin->borderClip, x, y, &box) - && (!wInputShape(pWin) || - RegionContainsPoint(wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box))) + pWin = inputInfo.pointer->spriteInfo->sprite->windows[i]; + + x = xoff - screenInfo.screens[i]->x; + y = yoff - screenInfo.screens[i]->y; + + if (RegionContainsPoint(&pWin->borderClip, x, y, &box) + && (!wInputShape(pWin) || + RegionContainsPoint(wInputShape(pWin), + x - pWin->drawable.x, + y - pWin->drawable.y, &box))) return TRUE; } @@ -3447,68 +3325,66 @@ XineramaPointInWindowIsVisible( static int XineramaWarpPointer(ClientPtr client) { - WindowPtr dest = NULL; - int x, y, rc; - SpritePtr pSprite = PickPointer(client)->spriteInfo->sprite; + WindowPtr dest = NULL; + int x, y, rc; + SpritePtr pSprite = PickPointer(client)->spriteInfo->sprite; REQUEST(xWarpPointerReq); - if (stuff->dstWid != None) { - rc = dixLookupWindow(&dest, stuff->dstWid, client, DixReadAccess); - if (rc != Success) - return rc; + rc = dixLookupWindow(&dest, stuff->dstWid, client, DixReadAccess); + if (rc != Success) + return rc; } x = pSprite->hotPhys.x; y = pSprite->hotPhys.y; - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; + if (stuff->srcWid != None) { + int winX, winY; + XID winID = stuff->srcWid; WindowPtr source; - rc = dixLookupWindow(&source, winID, client, DixReadAccess); - if (rc != Success) - return rc; - - winX = source->drawable.x; - winY = source->drawable.y; - if(source == screenInfo.screens[0]->root) { - winX -= screenInfo.screens[0]->x; - winY -= screenInfo.screens[0]->y; - } - if (x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !XineramaPointInWindowIsVisible(source, x, y)) - return Success; + rc = dixLookupWindow(&source, winID, client, DixReadAccess); + if (rc != Success) + return rc; + + winX = source->drawable.x; + winY = source->drawable.y; + if (source == screenInfo.screens[0]->root) { + winX -= screenInfo.screens[0]->x; + winY -= screenInfo.screens[0]->y; + } + if (x < winX + stuff->srcX || + y < winY + stuff->srcY || + (stuff->srcWidth != 0 && + winX + stuff->srcX + (int) stuff->srcWidth < x) || + (stuff->srcHeight != 0 && + winY + stuff->srcY + (int) stuff->srcHeight < y) || + !XineramaPointInWindowIsVisible(source, x, y)) + return Success; } if (dest) { - x = dest->drawable.x; - y = dest->drawable.y; - if(dest == screenInfo.screens[0]->root) { - x -= screenInfo.screens[0]->x; - y -= screenInfo.screens[0]->y; - } + x = dest->drawable.x; + y = dest->drawable.y; + if (dest == screenInfo.screens[0]->root) { + x -= screenInfo.screens[0]->x; + y -= screenInfo.screens[0]->y; + } } x += stuff->dstX; y += stuff->dstY; if (x < pSprite->physLimits.x1) - x = pSprite->physLimits.x1; + x = pSprite->physLimits.x1; else if (x >= pSprite->physLimits.x2) - x = pSprite->physLimits.x2 - 1; + x = pSprite->physLimits.x2 - 1; if (y < pSprite->physLimits.y1) - y = pSprite->physLimits.y1; + y = pSprite->physLimits.y1; else if (y >= pSprite->physLimits.y2) - y = pSprite->physLimits.y2 - 1; + y = pSprite->physLimits.y2 - 1; if (pSprite->hotShape) - ConfineToShape(PickPointer(client), pSprite->hotShape, &x, &y); + ConfineToShape(PickPointer(client), pSprite->hotShape, &x, &y); XineramaSetCursorPosition(PickPointer(client), x, y, TRUE); @@ -3517,7 +3393,6 @@ XineramaWarpPointer(ClientPtr client) #endif - /** * Server-side protocol handling for WarpPointer request. * Warps the cursor position to the coordinates given in the request. @@ -3525,11 +3400,11 @@ XineramaWarpPointer(ClientPtr client) int ProcWarpPointer(ClientPtr client) { - WindowPtr dest = NULL; - int x, y, rc; - ScreenPtr newScreen; + WindowPtr dest = NULL; + int x, y, rc; + ScreenPtr newScreen; DeviceIntPtr dev, tmp; - SpritePtr pSprite; + SpritePtr pSprite; REQUEST(xWarpPointerReq); REQUEST_SIZE_MATCH(xWarpPointerReq); @@ -3538,10 +3413,10 @@ ProcWarpPointer(ClientPtr client) for (tmp = inputInfo.devices; tmp; tmp = tmp->next) { if (GetMaster(tmp, MASTER_ATTACHED) == dev) { - rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixWriteAccess); - if (rc != Success) - return rc; - } + rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixWriteAccess); + if (rc != Success) + return rc; + } } if (dev->lastSlave) @@ -3549,77 +3424,74 @@ ProcWarpPointer(ClientPtr client) pSprite = dev->spriteInfo->sprite; #ifdef PANORAMIX - if(!noPanoramiXExtension) - return XineramaWarpPointer(client); + if (!noPanoramiXExtension) + return XineramaWarpPointer(client); #endif if (stuff->dstWid != None) { - rc = dixLookupWindow(&dest, stuff->dstWid, client, DixGetAttrAccess); - if (rc != Success) - return rc; + rc = dixLookupWindow(&dest, stuff->dstWid, client, DixGetAttrAccess); + if (rc != Success) + return rc; } x = pSprite->hotPhys.x; y = pSprite->hotPhys.y; - if (stuff->srcWid != None) - { - int winX, winY; - XID winID = stuff->srcWid; + if (stuff->srcWid != None) { + int winX, winY; + XID winID = stuff->srcWid; WindowPtr source; - rc = dixLookupWindow(&source, winID, client, DixGetAttrAccess); - if (rc != Success) - return rc; - - winX = source->drawable.x; - winY = source->drawable.y; - if (source->drawable.pScreen != pSprite->hotPhys.pScreen || - x < winX + stuff->srcX || - y < winY + stuff->srcY || - (stuff->srcWidth != 0 && - winX + stuff->srcX + (int)stuff->srcWidth < x) || - (stuff->srcHeight != 0 && - winY + stuff->srcY + (int)stuff->srcHeight < y) || - !PointInWindowIsVisible(source, x, y)) - return Success; - } - if (dest) - { - x = dest->drawable.x; - y = dest->drawable.y; - newScreen = dest->drawable.pScreen; - } else - newScreen = pSprite->hotPhys.pScreen; + rc = dixLookupWindow(&source, winID, client, DixGetAttrAccess); + if (rc != Success) + return rc; + + winX = source->drawable.x; + winY = source->drawable.y; + if (source->drawable.pScreen != pSprite->hotPhys.pScreen || + x < winX + stuff->srcX || + y < winY + stuff->srcY || + (stuff->srcWidth != 0 && + winX + stuff->srcX + (int) stuff->srcWidth < x) || + (stuff->srcHeight != 0 && + winY + stuff->srcY + (int) stuff->srcHeight < y) || + !PointInWindowIsVisible(source, x, y)) + return Success; + } + if (dest) { + x = dest->drawable.x; + y = dest->drawable.y; + newScreen = dest->drawable.pScreen; + } + else + newScreen = pSprite->hotPhys.pScreen; x += stuff->dstX; y += stuff->dstY; if (x < 0) - x = 0; + x = 0; else if (x >= newScreen->width) - x = newScreen->width - 1; + x = newScreen->width - 1; if (y < 0) - y = 0; + y = 0; else if (y >= newScreen->height) - y = newScreen->height - 1; - - if (newScreen == pSprite->hotPhys.pScreen) - { - if (x < pSprite->physLimits.x1) - x = pSprite->physLimits.x1; - else if (x >= pSprite->physLimits.x2) - x = pSprite->physLimits.x2 - 1; - if (y < pSprite->physLimits.y1) - y = pSprite->physLimits.y1; - else if (y >= pSprite->physLimits.y2) - y = pSprite->physLimits.y2 - 1; - if (pSprite->hotShape) - ConfineToShape(dev, pSprite->hotShape, &x, &y); - (*newScreen->SetCursorPosition)(dev, newScreen, x, y, TRUE); - } - else if (!PointerConfinedToScreen(dev)) - { - NewCurrentScreen(dev, newScreen, x, y); + y = newScreen->height - 1; + + if (newScreen == pSprite->hotPhys.pScreen) { + if (x < pSprite->physLimits.x1) + x = pSprite->physLimits.x1; + else if (x >= pSprite->physLimits.x2) + x = pSprite->physLimits.x2 - 1; + if (y < pSprite->physLimits.y1) + y = pSprite->physLimits.y1; + else if (y >= pSprite->physLimits.y2) + y = pSprite->physLimits.y2 - 1; + if (pSprite->hotShape) + ConfineToShape(dev, pSprite->hotShape, &x, &y); + (*newScreen->SetCursorPosition) (dev, newScreen, x, y, TRUE); + } + else if (!PointerConfinedToScreen(dev)) { + NewCurrentScreen(dev, newScreen, x, y); } return Success; } @@ -3627,20 +3499,21 @@ ProcWarpPointer(ClientPtr client) static Bool BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin) { - if(RegionNotEmpty(&pWin->borderSize)) - return TRUE; + if (RegionNotEmpty(&pWin->borderSize)) + return TRUE; #ifdef PANORAMIX - if(!noPanoramiXExtension && XineramaSetWindowPntrs(pDev, pWin)) { - int i; - - FOR_NSCREENS_FORWARD_SKIP(i) { - if(RegionNotEmpty(&pDev->spriteInfo->sprite->windows[i]->borderSize)) - return TRUE; - } - } + if (!noPanoramiXExtension && XineramaSetWindowPntrs(pDev, pWin)) { + int i; + + FOR_NSCREENS_FORWARD_SKIP(i) { + if (RegionNotEmpty + (&pDev->spriteInfo->sprite->windows[i]->borderSize)) + return TRUE; + } + } #endif - return FALSE; + return FALSE; } /** @@ -3658,7 +3531,6 @@ BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin) Bool ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event, InternalEvent *real_event) - { SpritePtr pSprite = device->spriteInfo->sprite; GrabInfoPtr grabinfo = &device->deviceGrab; @@ -3668,8 +3540,7 @@ ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event, /* The only consumers of corestate are Xi 1.x and core events, which * are guaranteed to come from DeviceEvents. */ - if (grab->grabtype == XI || grab->grabtype == CORE) - { + if (grab->grabtype == XI || grab->grabtype == CORE) { DeviceIntPtr gdev; event->device_event.corestate &= 0x1f00; @@ -3684,43 +3555,38 @@ ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event, gdev->key->xkbInfo->state.grab_mods & (~0x1f00); } - if (grab->grabtype == CORE) - { + if (grab->grabtype == CORE) { rc = EventToCore(event, &xE, &count); - if (rc != Success) - { - BUG_WARN_MSG(rc != BadMatch,"[dix] %s: core conversion failed" + if (rc != Success) { + BUG_WARN_MSG(rc != BadMatch, "[dix] %s: core conversion failed" "(%d, %d).\n", device->name, event->any.type, rc); return FALSE; } - } else if (grab->grabtype == XI2) - { + } + else if (grab->grabtype == XI2) { rc = EventToXI2(event, &xE); - if (rc != Success) - { + if (rc != Success) { if (rc != BadMatch) - BUG_WARN_MSG(rc != BadMatch,"[dix] %s: XI2 conversion failed" + BUG_WARN_MSG(rc != BadMatch, "[dix] %s: XI2 conversion failed" "(%d, %d).\n", device->name, event->any.type, rc); return FALSE; } count = 1; - } else - { + } + else { rc = EventToXI(event, &xE, &count); - if (rc != Success) - { + if (rc != Success) { if (rc != BadMatch) - BUG_WARN_MSG(rc != BadMatch,"[dix] %s: XI conversion failed" + BUG_WARN_MSG(rc != BadMatch, "[dix] %s: XI conversion failed" "(%d, %d).\n", device->name, event->any.type, rc); return FALSE; } } - (*grabinfo->ActivateGrab)(device, grab, - ClientTimeToServerTime(event->any.time), TRUE); + (*grabinfo->ActivateGrab) (device, grab, + ClientTimeToServerTime(event->any.time), TRUE); - if (xE) - { + if (xE) { FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE); /* XXX: XACE? */ @@ -3743,16 +3609,15 @@ CoreGrabInterferes(DeviceIntPtr device, GrabPtr grab) DeviceIntPtr other; BOOL interfering = FALSE; - for (other = inputInfo.devices; other; other = other->next) - { + for (other = inputInfo.devices; other; other = other->next) { GrabPtr othergrab = other->deviceGrab.grab; + if (othergrab && othergrab->grabtype == CORE && - SameClient(grab, rClient(othergrab)) && - ((IsPointerDevice(grab->device) && - IsPointerDevice(othergrab->device)) || - (IsKeyboardDevice(grab->device) && - IsKeyboardDevice(othergrab->device)))) - { + SameClient(grab, rClient(othergrab)) && + ((IsPointerDevice(grab->device) && + IsPointerDevice(othergrab->device)) || + (IsKeyboardDevice(grab->device) && + IsKeyboardDevice(othergrab->device)))) { interfering = TRUE; break; } @@ -3762,10 +3627,10 @@ CoreGrabInterferes(DeviceIntPtr device, GrabPtr grab) } enum MatchFlags { - NO_MATCH = 0x0, - CORE_MATCH = 0x1, - XI_MATCH = 0x2, - XI2_MATCH = 0x4, + NO_MATCH = 0x0, + CORE_MATCH = 0x1, + XI_MATCH = 0x2, + XI2_MATCH = 0x4, }; /** @@ -3780,32 +3645,32 @@ enum MatchFlags { * @return The respective matched flag or 0 for no match */ static enum MatchFlags -MatchForType(const GrabPtr grab, GrabPtr tmp, enum InputLevel level, int event_type) +MatchForType(const GrabPtr grab, GrabPtr tmp, enum InputLevel level, + int event_type) { enum MatchFlags match; BOOL ignore_device = FALSE; int grabtype; int evtype; - switch(level) - { - case XI2: - grabtype = XI2; - evtype = GetXI2Type(event_type); - BUG_WARN(!evtype); - match = XI2_MATCH; - break; - case XI: - grabtype = XI; - evtype = GetXIType(event_type); - match = XI_MATCH; - break; - case CORE: - grabtype = CORE; - evtype = GetCoreType(event_type); - match = CORE_MATCH; - ignore_device = TRUE; - break; + switch (level) { + case XI2: + grabtype = XI2; + evtype = GetXI2Type(event_type); + BUG_WARN(!evtype); + match = XI2_MATCH; + break; + case XI: + grabtype = XI; + evtype = GetXIType(event_type); + match = XI_MATCH; + break; + case CORE: + grabtype = CORE; + evtype = GetCoreType(event_type); + match = CORE_MATCH; + ignore_device = TRUE; + break; } tmp->grabtype = grabtype; @@ -3840,11 +3705,10 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event, int emulated_type = 0; gdev = grab->modifierDevice; - if (grab->grabtype == CORE) - { + if (grab->grabtype == CORE) { gdev = GetMaster(device, KEYBOARD_OR_FLOAT); - } else if (grab->grabtype == XI2) - { + } + else if (grab->grabtype == XI2) { /* if the device is an attached slave device, gdev must be the * attached master keyboard. Since the slave may have been * reattached after the grab, the modifier device may not be the @@ -3854,15 +3718,15 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event, } if (gdev && gdev->key) - xkbi= gdev->key->xkbInfo; + xkbi = gdev->key->xkbInfo; tempGrab->modifierDevice = grab->modifierDevice; tempGrab->modifiersDetail.exact = xkbi ? xkbi->state.grab_mods : 0; /* Check for XI2 and XI grabs first */ match = MatchForType(grab, tempGrab, XI2, event->any.type); - if (!match && IsTouchEvent(event) && (event->device_event.flags & TOUCH_POINTER_EMULATED)) - { + if (!match && IsTouchEvent(event) && + (event->device_event.flags & TOUCH_POINTER_EMULATED)) { emulated_type = TouchGetPointerEventType(event); match = MatchForType(grab, tempGrab, XI2, emulated_type); } @@ -3873,8 +3737,7 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event, if (!match && emulated_type) match = MatchForType(grab, tempGrab, XI, emulated_type); - if (!match && checkCore) - { + if (!match && checkCore) { match = MatchForType(grab, tempGrab, CORE, event->any.type); if (!match && emulated_type) match = MatchForType(grab, tempGrab, CORE, emulated_type); @@ -3891,8 +3754,7 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event, * device. */ - if (grab->grabtype == CORE) - { + if (grab->grabtype == CORE) { /* A passive grab may have been created for a different device than it is assigned to at this point in time. Update the grab's device and modifier device to reflect the @@ -3900,8 +3762,7 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event, Since XGrabDeviceButton requires to specify the modifierDevice explicitly, we don't override this choice. */ - if (grab->type < GenericEvent) - { + if (grab->type < GenericEvent) { grab->device = device; grab->modifierDevice = GetMaster(device, MASTER_KEYBOARD); } @@ -3927,38 +3788,34 @@ CheckPassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event, */ GrabPtr -CheckPassiveGrabsOnWindow( - WindowPtr pWin, - DeviceIntPtr device, - InternalEvent *event, - BOOL checkCore, - BOOL activate) +CheckPassiveGrabsOnWindow(WindowPtr pWin, + DeviceIntPtr device, + InternalEvent *event, BOOL checkCore, BOOL activate) { GrabPtr grab = wPassiveGrabs(pWin); GrabPtr tempGrab; if (!grab) - return NULL; + return NULL; tempGrab = AllocGrab(); /* Fill out the grab details, but leave the type for later before * comparing */ - switch (event->any.type) - { - case ET_KeyPress: - case ET_KeyRelease: - tempGrab->detail.exact = event->device_event.detail.key; - break; - case ET_ButtonPress: - case ET_ButtonRelease: - case ET_TouchBegin: - case ET_TouchEnd: - tempGrab->detail.exact = event->device_event.detail.button; - break; - default: - tempGrab->detail.exact = 0; - break; + switch (event->any.type) { + case ET_KeyPress: + case ET_KeyRelease: + tempGrab->detail.exact = event->device_event.detail.key; + break; + case ET_ButtonPress: + case ET_ButtonRelease: + case ET_TouchBegin: + case ET_TouchEnd: + tempGrab->detail.exact = event->device_event.detail.button; + break; + default: + tempGrab->detail.exact = 0; + break; } tempGrab->window = pWin; tempGrab->device = device; @@ -3966,8 +3823,7 @@ CheckPassiveGrabsOnWindow( tempGrab->modifiersDetail.pMask = NULL; tempGrab->next = NULL; - for (; grab; grab = grab->next) - { + for (; grab; grab = grab->next) { if (!CheckPassiveGrab(device, grab, event, checkCore, tempGrab)) continue; @@ -4012,24 +3868,22 @@ CheckDeviceGrabs(DeviceIntPtr device, DeviceEvent *event, WindowPtr ancestor) { int i; WindowPtr pWin = NULL; - FocusClassPtr focus = IsPointerEvent((InternalEvent*)event) ? NULL : device->focus; + FocusClassPtr focus = + IsPointerEvent((InternalEvent *) event) ? NULL : device->focus; BOOL sendCore = (IsMaster(device) && device->coreEvents); Bool ret = FALSE; - if (event->type != ET_ButtonPress && - event->type != ET_KeyPress) + if (event->type != ET_ButtonPress && event->type != ET_KeyPress) return FALSE; - if (event->type == ET_ButtonPress - && (device->button->buttonsDown != 1)) - return FALSE; + if (event->type == ET_ButtonPress && (device->button->buttonsDown != 1)) + return FALSE; if (device->deviceGrab.grab) return FALSE; i = 0; - if (ancestor) - { + if (ancestor) { while (i < device->spriteInfo->sprite->spriteTraceGood) if (device->spriteInfo->sprite->spriteTrace[i++] == ancestor) break; @@ -4037,37 +3891,32 @@ CheckDeviceGrabs(DeviceIntPtr device, DeviceEvent *event, WindowPtr ancestor) goto out; } - if (focus) - { - for (; i < focus->traceGood; i++) - { - pWin = focus->trace[i]; - if (CheckPassiveGrabsOnWindow(pWin, device, (InternalEvent *) event, - sendCore, TRUE)) - { - ret = TRUE; - goto out; - } - } - - if ((focus->win == NoneWin) || - (i >= device->spriteInfo->sprite->spriteTraceGood) || - (pWin && pWin != device->spriteInfo->sprite->spriteTrace[i-1])) - goto out; - } - - for (; i < device->spriteInfo->sprite->spriteTraceGood; i++) - { - pWin = device->spriteInfo->sprite->spriteTrace[i]; - if (CheckPassiveGrabsOnWindow(pWin, device, (InternalEvent *) event, - sendCore, TRUE)) - { - ret = TRUE; - goto out; - } + if (focus) { + for (; i < focus->traceGood; i++) { + pWin = focus->trace[i]; + if (CheckPassiveGrabsOnWindow(pWin, device, (InternalEvent *) event, + sendCore, TRUE)) { + ret = TRUE; + goto out; + } + } + + if ((focus->win == NoneWin) || + (i >= device->spriteInfo->sprite->spriteTraceGood) || + (pWin && pWin != device->spriteInfo->sprite->spriteTrace[i - 1])) + goto out; + } + + for (; i < device->spriteInfo->sprite->spriteTraceGood; i++) { + pWin = device->spriteInfo->sprite->spriteTrace[i]; + if (CheckPassiveGrabsOnWindow(pWin, device, (InternalEvent *) event, + sendCore, TRUE)) { + ret = TRUE; + goto out; + } } -out: + out: if (ret == TRUE && event->type == ET_KeyPress) device->deviceGrab.activatingKey = event->detail.key; return ret; @@ -4095,78 +3944,81 @@ DeliverFocusedEvent(DeviceIntPtr keybd, InternalEvent *event, WindowPtr window) int deliveries = 0; if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; + focus = inputInfo.keyboard->focus->win; if (!focus) - return; - if (focus == PointerRootWin) - { - DeliverDeviceEvents(window, event, NullGrab, NullWindow, keybd); - return; + return; + if (focus == PointerRootWin) { + DeliverDeviceEvents(window, event, NullGrab, NullWindow, keybd); + return; } - if ((focus == window) || IsParent(focus, window)) - { - if (DeliverDeviceEvents(window, event, NullGrab, focus, keybd)) - return; + if ((focus == window) || IsParent(focus, window)) { + if (DeliverDeviceEvents(window, event, NullGrab, focus, keybd)) + return; } /* just deliver it to the focus window */ ptr = GetMaster(keybd, POINTER_OR_FLOAT); rc = EventToXI2(event, &xi2); - if (rc == Success) - { + if (rc == Success) { /* XXX: XACE */ int filter = GetEventFilter(keybd, xi2); + FixUpEventFromWindow(ptr->spriteInfo->sprite, xi2, focus, None, FALSE); deliveries = DeliverEventsToWindow(keybd, focus, xi2, 1, filter, NullGrab); if (deliveries > 0) goto unwind; - } else if (rc != BadMatch) - ErrorF("[dix] %s: XI2 conversion failed in DFE (%d, %d). Skipping delivery.\n", - keybd->name, event->any.type, rc); + } + else if (rc != BadMatch) + ErrorF + ("[dix] %s: XI2 conversion failed in DFE (%d, %d). Skipping delivery.\n", + keybd->name, event->any.type, rc); rc = EventToXI(event, &xE, &count); if (rc == Success && - XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, xE, count) == Success) - { + XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, xE, count) == Success) { FixUpEventFromWindow(ptr->spriteInfo->sprite, xE, focus, None, FALSE); deliveries = DeliverEventsToWindow(keybd, focus, xE, count, - GetEventFilter(keybd, xE), - NullGrab); + GetEventFilter(keybd, xE), NullGrab); if (deliveries > 0) goto unwind; - } else if (rc != BadMatch) - ErrorF("[dix] %s: XI conversion failed in DFE (%d, %d). Skipping delivery.\n", - keybd->name, event->any.type, rc); + } + else if (rc != BadMatch) + ErrorF + ("[dix] %s: XI conversion failed in DFE (%d, %d). Skipping delivery.\n", + keybd->name, event->any.type, rc); - if (sendCore) - { + if (sendCore) { rc = EventToCore(event, &core, &count); if (rc == Success) { - if (XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, core, count) == Success) { + if (XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, core, count) == + Success) { FixUpEventFromWindow(keybd->spriteInfo->sprite, core, focus, None, FALSE); - deliveries = DeliverEventsToWindow(keybd, focus, core, count, - GetEventFilter(keybd, core), - NullGrab); + deliveries = + DeliverEventsToWindow(keybd, focus, core, count, + GetEventFilter(keybd, core), + NullGrab); } - } else if (rc != BadMatch) - ErrorF("[dix] %s: core conversion failed DFE (%d, %d). Skipping delivery.\n", - keybd->name, event->any.type, rc); + } + else if (rc != BadMatch) + ErrorF + ("[dix] %s: core conversion failed DFE (%d, %d). Skipping delivery.\n", + keybd->name, event->any.type, rc); } -unwind: + unwind: free(core); free(xE); free(xi2); return; } - int -DeliverOneGrabbedEvent(InternalEvent *event, DeviceIntPtr dev, enum InputLevel level) +DeliverOneGrabbedEvent(InternalEvent *event, DeviceIntPtr dev, + enum InputLevel level) { SpritePtr pSprite = dev->spriteInfo->sprite; int rc; @@ -4178,61 +4030,58 @@ DeliverOneGrabbedEvent(InternalEvent *event, DeviceIntPtr dev, enum InputLevel l GrabPtr grab = grabinfo->grab; Mask filter; - switch(level) - { - case XI2: - rc = EventToXI2(event, &xE); - count = 1; - if (rc == Success) - { - int evtype = xi2_get_type(xE); - mask = GetXI2MaskByte(grab->xi2mask, dev, evtype); - filter = GetEventFilter(dev, xE); - } - break; - case XI: - if (grabinfo->fromPassiveGrab && grabinfo->implicitGrab) - mask = grab->deviceMask; - else - mask = grab->eventMask; - rc = EventToXI(event, &xE, &count); - if (rc == Success) - filter = GetEventFilter(dev, xE); - break; - case CORE: - rc = EventToCore(event, &xE, &count); + switch (level) { + case XI2: + rc = EventToXI2(event, &xE); + count = 1; + if (rc == Success) { + int evtype = xi2_get_type(xE); + + mask = GetXI2MaskByte(grab->xi2mask, dev, evtype); + filter = GetEventFilter(dev, xE); + } + break; + case XI: + if (grabinfo->fromPassiveGrab && grabinfo->implicitGrab) + mask = grab->deviceMask; + else mask = grab->eventMask; - if (rc == Success) - filter = GetEventFilter(dev, xE); - break; - default: - BUG_WARN_MSG(1, "Invalid input level %d\n", level); - return 0; + rc = EventToXI(event, &xE, &count); + if (rc == Success) + filter = GetEventFilter(dev, xE); + break; + case CORE: + rc = EventToCore(event, &xE, &count); + mask = grab->eventMask; + if (rc == Success) + filter = GetEventFilter(dev, xE); + break; + default: + BUG_WARN_MSG(1, "Invalid input level %d\n", level); + return 0; } - if (rc == Success) - { + if (rc == Success) { FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE); if (XaceHook(XACE_SEND_ACCESS, 0, dev, - grab->window, xE, count) || - XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), - grab->window, xE, count)) - deliveries = 1; /* don't send, but pretend we did */ - else if (level != CORE || !IsInterferingGrab(rClient(grab), dev, xE)) - { + grab->window, xE, count) || + XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), + grab->window, xE, count)) + deliveries = 1; /* don't send, but pretend we did */ + else if (level != CORE || !IsInterferingGrab(rClient(grab), dev, xE)) { deliveries = TryClientEvents(rClient(grab), dev, - xE, count, mask, filter, - grab); + xE, count, mask, filter, grab); } - } else - BUG_WARN_MSG(rc != BadMatch, "%s: conversion to mode %d failed on %d with %d\n", - dev->name, level, event->any.type, rc); + } + else + BUG_WARN_MSG(rc != BadMatch, + "%s: conversion to mode %d failed on %d with %d\n", + dev->name, level, event->any.type, rc); free(xE); return deliveries; } - /** * Deliver an event from a device that is currently grabbed. Uses * DeliverDeviceEvents() for further delivery if a ownerEvents is set on the @@ -4256,9 +4105,8 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev, grabinfo = &thisDev->deviceGrab; grab = grabinfo->grab; - if (grab->ownerEvents) - { - WindowPtr focus; + if (grab->ownerEvents) { + WindowPtr focus; /* Hack: Some pointer device have a focus class. So we need to check * for the type of event, to see if we really want to deliver it to @@ -4266,27 +4114,25 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev, */ if (IsPointerEvent(event)) focus = PointerRootWin; - else if (thisDev->focus) - { - focus = thisDev->focus->win; - if (focus == FollowKeyboardWin) - focus = inputInfo.keyboard->focus->win; - } - else - focus = PointerRootWin; - if (focus == PointerRootWin) - deliveries = DeliverDeviceEvents(pSprite->win, event, grab, + else if (thisDev->focus) { + focus = thisDev->focus->win; + if (focus == FollowKeyboardWin) + focus = inputInfo.keyboard->focus->win; + } + else + focus = PointerRootWin; + if (focus == PointerRootWin) + deliveries = DeliverDeviceEvents(pSprite->win, event, grab, NullWindow, thisDev); - else if (focus && (focus == pSprite->win || - IsParent(focus, pSprite->win))) - deliveries = DeliverDeviceEvents(pSprite->win, event, grab, focus, - thisDev); - else if (focus) - deliveries = DeliverDeviceEvents(focus, event, grab, focus, - thisDev); - } - if (!deliveries) - { + else if (focus && (focus == pSprite->win || + IsParent(focus, pSprite->win))) + deliveries = DeliverDeviceEvents(pSprite->win, event, grab, focus, + thisDev); + else if (focus) + deliveries = DeliverDeviceEvents(focus, event, grab, focus, + thisDev); + } + if (!deliveries) { /* XXX: In theory, we could pass the internal events through to * everything and only convert just before hitting the wire. We can't * do that yet, so DGE is the last stop for internal events. From here @@ -4295,47 +4141,41 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev, sendCore = (IsMaster(thisDev) && thisDev->coreEvents); /* try core event */ - if (sendCore && grab->grabtype == CORE) - { + if (sendCore && grab->grabtype == CORE) { deliveries = DeliverOneGrabbedEvent(event, thisDev, CORE); } - if (!deliveries) - { + if (!deliveries) { deliveries = DeliverOneGrabbedEvent(event, thisDev, XI2); } - if (!deliveries) - { + if (!deliveries) { deliveries = DeliverOneGrabbedEvent(event, thisDev, XI); } if (deliveries && (event->any.type == ET_Motion)) thisDev->valuator->motionHintWindow = grab->window; } - if (deliveries && !deactivateGrab && event->any.type != ET_Motion) - { - switch (grabinfo->sync.state) - { - case FREEZE_BOTH_NEXT_EVENT: - dev = GetPairedDevice(thisDev); - if (dev) - { - FreezeThaw(dev, TRUE); - if ((dev->deviceGrab.sync.state == FREEZE_BOTH_NEXT_EVENT) && - (CLIENT_BITS(grab->resource) == - CLIENT_BITS(dev->deviceGrab.grab->resource))) - dev->deviceGrab.sync.state = FROZEN_NO_EVENT; - else + if (deliveries && !deactivateGrab && event->any.type != ET_Motion) { + switch (grabinfo->sync.state) { + case FREEZE_BOTH_NEXT_EVENT: + dev = GetPairedDevice(thisDev); + if (dev) { + FreezeThaw(dev, TRUE); + if ((dev->deviceGrab.sync.state == FREEZE_BOTH_NEXT_EVENT) && + (CLIENT_BITS(grab->resource) == + CLIENT_BITS(dev->deviceGrab.grab->resource))) + dev->deviceGrab.sync.state = FROZEN_NO_EVENT; + else dev->deviceGrab.sync.other = grab; - } - /* fall through */ - case FREEZE_NEXT_EVENT: - grabinfo->sync.state = FROZEN_WITH_EVENT; - FreezeThaw(thisDev, TRUE); - *grabinfo->sync.event = event->device_event; - break; - } + } + /* fall through */ + case FREEZE_NEXT_EVENT: + grabinfo->sync.state = FROZEN_WITH_EVENT; + FreezeThaw(thisDev, TRUE); + *grabinfo->sync.event = event->device_event; + break; + } } return deliveries; @@ -4346,12 +4186,12 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev, the device's processInputProc to be called, as in for example Mouse Keys. */ void -FixKeyState (DeviceEvent *event, DeviceIntPtr keybd) +FixKeyState(DeviceEvent *event, DeviceIntPtr keybd) { int key = event->detail.key; if (event->type == ET_KeyPress) { - DebugF("FixKeyState: Key %d %s\n",key, + DebugF("FixKeyState: Key %d %s\n", key, ((event->type == ET_KeyPress) ? "down" : "up")); } @@ -4387,32 +4227,28 @@ RecalculateDeliverableEvents(WindowPtr pWin) WindowPtr pChild; pChild = pWin; - while (1) - { - if (pChild->optional) - { - pChild->optional->otherEventMasks = 0; - for (others = wOtherClients(pChild); others; others = others->next) - { - pChild->optional->otherEventMasks |= others->mask; - } - } - pChild->deliverableEvents = pChild->eventMask| - wOtherEventMasks(pChild); - if (pChild->parent) - pChild->deliverableEvents |= - (pChild->parent->deliverableEvents & - ~wDontPropagateMask(pChild) & PropagateMask); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; + while (1) { + if (pChild->optional) { + pChild->optional->otherEventMasks = 0; + for (others = wOtherClients(pChild); others; others = others->next) { + pChild->optional->otherEventMasks |= others->mask; + } + } + pChild->deliverableEvents = pChild->eventMask | + wOtherEventMasks(pChild); + if (pChild->parent) + pChild->deliverableEvents |= + (pChild->parent->deliverableEvents & + ~wDontPropagateMask(pChild) & PropagateMask); + if (pChild->firstChild) { + pChild = pChild->firstChild; + continue; + } + while (!pChild->nextSib && (pChild != pWin)) + pChild = pChild->parent; + if (pChild == pWin) + break; + pChild = pChild->nextSib; } } @@ -4424,107 +4260,93 @@ int OtherClientGone(pointer value, XID id) { OtherClientsPtr other, prev; - WindowPtr pWin = (WindowPtr)value; + WindowPtr pWin = (WindowPtr) value; prev = 0; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (other->resource == id) - { - if (prev) - prev->next = other->next; - else - { - if (!(pWin->optional->otherClients = other->next)) - CheckWindowOptionalNeed (pWin); - } - free(other); - RecalculateDeliverableEvents(pWin); - return Success; - } - prev = other; + for (other = wOtherClients(pWin); other; other = other->next) { + if (other->resource == id) { + if (prev) + prev->next = other->next; + else { + if (!(pWin->optional->otherClients = other->next)) + CheckWindowOptionalNeed(pWin); + } + free(other); + RecalculateDeliverableEvents(pWin); + return Success; + } + prev = other; } FatalError("client not on event list"); - /*NOTREACHED*/ - return -1; /* make compiler happy */ + /*NOTREACHED*/ return -1; /* make compiler happy */ } int EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask) { Mask check; - OtherClients * others; + OtherClients *others; DeviceIntPtr dev; int rc; - if (mask & ~AllEventMasks) - { - client->errorValue = mask; - return BadValue; + if (mask & ~AllEventMasks) { + client->errorValue = mask; + return BadValue; } check = (mask & ManagerMask); if (check) { - rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, - RT_WINDOW, pWin, RT_NONE, NULL, DixManageAccess); - if (rc != Success) - return rc; + rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, + RT_WINDOW, pWin, RT_NONE, NULL, DixManageAccess); + if (rc != Success) + return rc; } check = (mask & AtMostOneClient); - if (check & (pWin->eventMask|wOtherEventMasks(pWin))) - { /* It is illegal for two different - clients to select on any of the - events for AtMostOneClient. However, - it is OK, for some client to - continue selecting on one of those - events. */ - if ((wClient(pWin) != client) && (check & pWin->eventMask)) - return BadAccess; - for (others = wOtherClients (pWin); others; others = others->next) - { - if (!SameClient(others, client) && (check & others->mask)) - return BadAccess; - } - } - if (wClient (pWin) == client) - { - check = pWin->eventMask; - pWin->eventMask = mask; + if (check & (pWin->eventMask | wOtherEventMasks(pWin))) { /* It is illegal for two different + clients to select on any of the + events for AtMostOneClient. However, + it is OK, for some client to + continue selecting on one of those + events. */ + if ((wClient(pWin) != client) && (check & pWin->eventMask)) + return BadAccess; + for (others = wOtherClients(pWin); others; others = others->next) { + if (!SameClient(others, client) && (check & others->mask)) + return BadAccess; + } } - else - { - for (others = wOtherClients (pWin); others; others = others->next) - { - if (SameClient(others, client)) - { - check = others->mask; - if (mask == 0) - { - FreeResource(others->resource, RT_NONE); - return Success; - } - else - others->mask = mask; - goto maskSet; - } - } - check = 0; - if (!pWin->optional && !MakeWindowOptional (pWin)) - return BadAlloc; - others = malloc(sizeof(OtherClients)); - if (!others) - return BadAlloc; - others->mask = mask; - others->resource = FakeClientID(client->index); - others->next = pWin->optional->otherClients; - pWin->optional->otherClients = others; - if (!AddResource(others->resource, RT_OTHERCLIENT, (pointer)pWin)) - return BadAlloc; - } -maskSet: - if ((mask & PointerMotionHintMask) && !(check & PointerMotionHintMask)) - { - for (dev = inputInfo.devices; dev; dev = dev->next) - { + if (wClient(pWin) == client) { + check = pWin->eventMask; + pWin->eventMask = mask; + } + else { + for (others = wOtherClients(pWin); others; others = others->next) { + if (SameClient(others, client)) { + check = others->mask; + if (mask == 0) { + FreeResource(others->resource, RT_NONE); + return Success; + } + else + others->mask = mask; + goto maskSet; + } + } + check = 0; + if (!pWin->optional && !MakeWindowOptional(pWin)) + return BadAlloc; + others = malloc(sizeof(OtherClients)); + if (!others) + return BadAlloc; + others->mask = mask; + others->resource = FakeClientID(client->index); + others->next = pWin->optional->otherClients; + pWin->optional->otherClients = others; + if (!AddResource(others->resource, RT_OTHERCLIENT, (pointer) pWin)) + return BadAlloc; + } + maskSet: + if ((mask & PointerMotionHintMask) && !(check & PointerMotionHintMask)) { + for (dev = inputInfo.devices; dev; dev = dev->next) { if (dev->valuator && dev->valuator->motionHintWindow == pWin) dev->valuator->motionHintWindow = NullWindow; } @@ -4539,50 +4361,42 @@ EventSuppressForWindow(WindowPtr pWin, ClientPtr client, { int i, free; - if (mask & ~PropagateMask) - { - client->errorValue = mask; - return BadValue; + if (mask & ~PropagateMask) { + client->errorValue = mask; + return BadValue; } if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; + DontPropagateRefCnts[pWin->dontPropagate]--; if (!mask) - i = 0; - else - { - for (i = DNPMCOUNT, free = 0; --i > 0; ) - { - if (!DontPropagateRefCnts[i]) - free = i; - else if (mask == DontPropagateMasks[i]) - break; - } - if (!i && free) - { - i = free; - DontPropagateMasks[i] = mask; - } - } - if (i || !mask) - { - pWin->dontPropagate = i; - if (i) - DontPropagateRefCnts[i]++; - if (pWin->optional) - { - pWin->optional->dontPropagateMask = mask; - *checkOptional = TRUE; - } + i = 0; + else { + for (i = DNPMCOUNT, free = 0; --i > 0;) { + if (!DontPropagateRefCnts[i]) + free = i; + else if (mask == DontPropagateMasks[i]) + break; + } + if (!i && free) { + i = free; + DontPropagateMasks[i] = mask; + } } - else - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]++; - return BadAlloc; - } - pWin->dontPropagate = 0; + if (i || !mask) { + pWin->dontPropagate = i; + if (i) + DontPropagateRefCnts[i]++; + if (pWin->optional) { + pWin->optional->dontPropagateMask = mask; + *checkOptional = TRUE; + } + } + else { + if (!pWin->optional && !MakeWindowOptional(pWin)) { + if (pWin->dontPropagate) + DontPropagateRefCnts[pWin->dontPropagate]++; + return BadAlloc; + } + pWin->dontPropagate = 0; pWin->optional->dontPropagateMask = mask; } RecalculateDeliverableEvents(pWin); @@ -4594,34 +4408,28 @@ EventSuppressForWindow(WindowPtr pWin, ClientPtr client, * Uses the paired keyboard to get some additional information. */ void -CoreEnterLeaveEvent( - DeviceIntPtr mouse, - int type, - int mode, - int detail, - WindowPtr pWin, - Window child) +CoreEnterLeaveEvent(DeviceIntPtr mouse, + int type, + int mode, int detail, WindowPtr pWin, Window child) { - xEvent event; - WindowPtr focus; - DeviceIntPtr keybd; - GrabPtr grab = mouse->deviceGrab.grab; - Mask mask; + xEvent event; + WindowPtr focus; + DeviceIntPtr keybd; + GrabPtr grab = mouse->deviceGrab.grab; + Mask mask; keybd = GetMaster(mouse, KEYBOARD_OR_FLOAT); if ((pWin == mouse->valuator->motionHintWindow) && - (detail != NotifyInferior)) - mouse->valuator->motionHintWindow = NullWindow; - if (grab) - { - mask = (pWin == grab->window) ? grab->eventMask : 0; - if (grab->ownerEvents) - mask |= EventMaskForClient(pWin, rClient(grab)); + (detail != NotifyInferior)) + mouse->valuator->motionHintWindow = NullWindow; + if (grab) { + mask = (pWin == grab->window) ? grab->eventMask : 0; + if (grab->ownerEvents) + mask |= EventMaskForClient(pWin, rClient(grab)); } - else - { - mask = pWin->eventMask | wOtherEventMasks(pWin); + else { + mask = pWin->eventMask | wOtherEventMasks(pWin); } memset(&event, 0, sizeof(xEvent)); @@ -4636,62 +4444,56 @@ CoreEnterLeaveEvent( event.u.enterLeave.child = child; event.u.enterLeave.flags = event.u.keyButtonPointer.sameScreen ? ELFlagSameScreen : 0; - event.u.enterLeave.state = mouse->button ? (mouse->button->state & 0x1f00) : 0; + event.u.enterLeave.state = + mouse->button ? (mouse->button->state & 0x1f00) : 0; if (keybd) event.u.enterLeave.state |= - XkbGrabStateFromRec(&keybd->key->xkbInfo->state); + XkbGrabStateFromRec(&keybd->key->xkbInfo->state); event.u.enterLeave.mode = mode; focus = (keybd) ? keybd->focus->win : None; if ((focus != NoneWin) && - ((pWin == focus) || (focus == PointerRootWin) || - IsParent(focus, pWin))) + ((pWin == focus) || (focus == PointerRootWin) || IsParent(focus, pWin))) event.u.enterLeave.flags |= ELFlagFocus; - if ((mask & GetEventFilter(mouse, &event))) - { + if ((mask & GetEventFilter(mouse, &event))) { if (grab) TryClientEvents(rClient(grab), mouse, &event, 1, mask, GetEventFilter(mouse, &event), grab); else DeliverEventsToWindow(mouse, pWin, &event, 1, - GetEventFilter(mouse, &event), - NullGrab); + GetEventFilter(mouse, &event), NullGrab); } - if ((type == EnterNotify) && (mask & KeymapStateMask)) - { + if ((type == EnterNotify) && (mask & KeymapStateMask)) { xKeymapEvent ke; ClientPtr client = grab ? rClient(grab) : wClient(pWin); + if (XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess)) - memset((char *)&ke.map[0], 0, 31); + memset((char *) &ke.map[0], 0, 31); else - memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31); + memmove((char *) &ke.map[0], (char *) &keybd->key->down[1], 31); ke.type = KeymapNotify; if (grab) - TryClientEvents(rClient(grab), keybd, (xEvent *)&ke, 1, + TryClientEvents(rClient(grab), keybd, (xEvent *) &ke, 1, mask, KeymapStateMask, grab); else - DeliverEventsToWindow(mouse, pWin, (xEvent *)&ke, 1, + DeliverEventsToWindow(mouse, pWin, (xEvent *) &ke, 1, KeymapStateMask, NullGrab); } } void -DeviceEnterLeaveEvent( - DeviceIntPtr mouse, - int sourceid, - int type, - int mode, - int detail, - WindowPtr pWin, - Window child) +DeviceEnterLeaveEvent(DeviceIntPtr mouse, + int sourceid, + int type, + int mode, int detail, WindowPtr pWin, Window child) { - GrabPtr grab = mouse->deviceGrab.grab; - xXIEnterEvent *event; - int filter; - int btlen, len, i; - DeviceIntPtr kbd; + GrabPtr grab = mouse->deviceGrab.grab; + xXIEnterEvent *event; + int filter; + int btlen, len, i; + DeviceIntPtr kbd; if ((mode == XINotifyPassiveGrab && type == XI_Leave) || (mode == XINotifyPassiveUngrab && type == XI_Enter)) @@ -4702,26 +4504,25 @@ DeviceEnterLeaveEvent( len = sizeof(xXIEnterEvent) + btlen * 4; event = calloc(1, len); - event->type = GenericEvent; - event->extension = IReqCode; - event->evtype = type; - event->length = (len - sizeof(xEvent))/4; - event->buttons_len = btlen; - event->detail = detail; - event->time = currentTime.milliseconds; - event->deviceid = mouse->id; - event->sourceid = sourceid; - event->mode = mode; - event->root_x = FP1616(mouse->spriteInfo->sprite->hot.x, 0); - event->root_y = FP1616(mouse->spriteInfo->sprite->hot.y, 0); + event->type = GenericEvent; + event->extension = IReqCode; + event->evtype = type; + event->length = (len - sizeof(xEvent)) / 4; + event->buttons_len = btlen; + event->detail = detail; + event->time = currentTime.milliseconds; + event->deviceid = mouse->id; + event->sourceid = sourceid; + event->mode = mode; + event->root_x = FP1616(mouse->spriteInfo->sprite->hot.x, 0); + event->root_y = FP1616(mouse->spriteInfo->sprite->hot.y, 0); for (i = 0; mouse && mouse->button && i < mouse->button->numButtons; i++) if (BitIsOn(mouse->button->down, i)) SetBit(&event[1], i); kbd = GetMaster(mouse, MASTER_KEYBOARD); - if (kbd && kbd->key) - { + if (kbd && kbd->key) { event->mods.base_mods = kbd->key->xkbInfo->state.base_mods; event->mods.latched_mods = kbd->key->xkbInfo->state.latched_mods; event->mods.locked_mods = kbd->key->xkbInfo->state.locked_mods; @@ -4731,24 +4532,26 @@ DeviceEnterLeaveEvent( event->group.locked_group = kbd->key->xkbInfo->state.locked_group; } - FixUpEventFromWindow(mouse->spriteInfo->sprite, (xEvent*)event, pWin, + FixUpEventFromWindow(mouse->spriteInfo->sprite, (xEvent *) event, pWin, None, FALSE); - filter = GetEventFilter(mouse, (xEvent*)event); + filter = GetEventFilter(mouse, (xEvent *) event); - if (grab) - { + if (grab) { Mask mask; + mask = xi2mask_isset(grab->xi2mask, mouse, type); - TryClientEvents(rClient(grab), mouse, (xEvent*)event, 1, mask, 1, grab); - } else { - if (!WindowXI2MaskIsset(mouse, pWin, (xEvent*)event)) + TryClientEvents(rClient(grab), mouse, (xEvent *) event, 1, mask, 1, + grab); + } + else { + if (!WindowXI2MaskIsset(mouse, pWin, (xEvent *) event)) goto out; - DeliverEventsToWindow(mouse, pWin, (xEvent*)event, 1, filter, + DeliverEventsToWindow(mouse, pWin, (xEvent *) event, 1, filter, NullGrab); } -out: + out: free(event); } @@ -4766,18 +4569,18 @@ CoreFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin) DeliverEventsToWindow(dev, pWin, &event, 1, GetEventFilter(dev, &event), NullGrab); if ((type == FocusIn) && - ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask)) - { + ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask)) { xKeymapEvent ke; ClientPtr client = wClient(pWin); + if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess)) - memset((char *)&ke.map[0], 0, 31); + memset((char *) &ke.map[0], 0, 31); else - memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31); + memmove((char *) &ke.map[0], (char *) &dev->key->down[1], 31); ke.type = KeymapNotify; - DeliverEventsToWindow(dev, pWin, (xEvent *)&ke, 1, - KeymapStateMask, NullGrab); + DeliverEventsToWindow(dev, pWin, (xEvent *) &ke, 1, + KeymapStateMask, NullGrab); } } @@ -4799,90 +4602,81 @@ CoreFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin) * @param followOK True if pointer is allowed to follow the keyboard. */ int -SetInputFocus( - ClientPtr client, - DeviceIntPtr dev, - Window focusID, - CARD8 revertTo, - Time ctime, - Bool followOK) +SetInputFocus(ClientPtr client, + DeviceIntPtr dev, + Window focusID, CARD8 revertTo, Time ctime, Bool followOK) { FocusClassPtr focus; WindowPtr focusWin; int mode, rc; TimeStamp time; - DeviceIntPtr keybd; /* used for FollowKeyboard or FollowKeyboardWin */ - + DeviceIntPtr keybd; /* used for FollowKeyboard or FollowKeyboardWin */ UpdateCurrentTime(); if ((revertTo != RevertToParent) && - (revertTo != RevertToPointerRoot) && - (revertTo != RevertToNone) && - ((revertTo != RevertToFollowKeyboard) || !followOK)) - { - client->errorValue = revertTo; - return BadValue; + (revertTo != RevertToPointerRoot) && + (revertTo != RevertToNone) && + ((revertTo != RevertToFollowKeyboard) || !followOK)) { + client->errorValue = revertTo; + return BadValue; } time = ClientTimeToServerTime(ctime); keybd = GetMaster(dev, KEYBOARD_OR_FLOAT); if ((focusID == None) || (focusID == PointerRoot)) - focusWin = (WindowPtr)(long)focusID; - else if ((focusID == FollowKeyboard) && followOK) - { - focusWin = keybd->focus->win; + focusWin = (WindowPtr) (long) focusID; + else if ((focusID == FollowKeyboard) && followOK) { + focusWin = keybd->focus->win; } else { - rc = dixLookupWindow(&focusWin, focusID, client, DixSetAttrAccess); - if (rc != Success) - return rc; - /* It is a match error to try to set the input focus to an - unviewable window. */ - if(!focusWin->realized) - return BadMatch; + rc = dixLookupWindow(&focusWin, focusID, client, DixSetAttrAccess); + if (rc != Success) + return rc; + /* It is a match error to try to set the input focus to an + unviewable window. */ + if (!focusWin->realized) + return BadMatch; } rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixSetFocusAccess); if (rc != Success) - return Success; + return Success; focus = dev->focus; if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, focus->time) == EARLIER)) - return Success; + (CompareTimeStamps(time, focus->time) == EARLIER)) + return Success; mode = (dev->deviceGrab.grab) ? NotifyWhileGrabbed : NotifyNormal; - if (focus->win == FollowKeyboardWin) - { + if (focus->win == FollowKeyboardWin) { if (!ActivateFocusInGrab(dev, keybd->focus->win, focusWin)) DoFocusEvents(dev, keybd->focus->win, focusWin, mode); - } else - { + } + else { if (!ActivateFocusInGrab(dev, focus->win, focusWin)) DoFocusEvents(dev, focus->win, focusWin, mode); } focus->time = time; focus->revert = revertTo; if (focusID == FollowKeyboard) - focus->win = FollowKeyboardWin; + focus->win = FollowKeyboardWin; else - focus->win = focusWin; + focus->win = focusWin; if ((focusWin == NoneWin) || (focusWin == PointerRootWin)) - focus->traceGood = 0; - else - { + focus->traceGood = 0; + else { int depth = 0; - WindowPtr pWin; - - for (pWin = focusWin; pWin; pWin = pWin->parent) depth++; - if (depth > focus->traceSize) - { - focus->traceSize = depth+1; - focus->trace = realloc(focus->trace, - focus->traceSize * sizeof(WindowPtr)); - } - focus->traceGood = depth; + WindowPtr pWin; + + for (pWin = focusWin; pWin; pWin = pWin->parent) + depth++; + if (depth > focus->traceSize) { + focus->traceSize = depth + 1; + focus->trace = realloc(focus->trace, + focus->traceSize * sizeof(WindowPtr)); + } + focus->traceGood = depth; for (pWin = focusWin, depth--; pWin; pWin = pWin->parent, depth--) - focus->trace[depth] = pWin; + focus->trace[depth] = pWin; } return Success; } @@ -4896,12 +4690,13 @@ int ProcSetInputFocus(ClientPtr client) { DeviceIntPtr kbd = PickKeyboard(client); + REQUEST(xSetInputFocusReq); REQUEST_SIZE_MATCH(xSetInputFocusReq); return SetInputFocus(client, kbd, stuff->focus, - stuff->revertTo, stuff->time, FALSE); + stuff->revertTo, stuff->time, FALSE); } /** @@ -4917,22 +4712,24 @@ ProcGetInputFocus(ClientPtr client) xGetInputFocusReply rep; FocusClassPtr focus = kbd->focus; int rc; + /* REQUEST(xReq); */ REQUEST_SIZE_MATCH(xReq); rc = XaceHook(XACE_DEVICE_ACCESS, client, kbd, DixGetFocusAccess); if (rc != Success) - return rc; + return rc; memset(&rep, 0, sizeof(xGetInputFocusReply)); rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; if (focus->win == NoneWin) - rep.focus = None; + rep.focus = None; else if (focus->win == PointerRootWin) - rep.focus = PointerRoot; - else rep.focus = focus->win->drawable.id; + rep.focus = PointerRoot; + else + rep.focus = focus->win->drawable.id; rep.revertTo = focus->revert; WriteReplyToClient(client, sizeof(xGetInputFocusReply), &rep); return Success; @@ -4953,34 +4750,32 @@ ProcGrabPointer(ClientPtr client) GrabMask mask; WindowPtr confineTo; CursorPtr oldCursor; + REQUEST(xGrabPointerReq); int rc; REQUEST_SIZE_MATCH(xGrabPointerReq); UpdateCurrentTime(); - if (stuff->eventMask & ~PointerGrabMask) - { - client->errorValue = stuff->eventMask; + if (stuff->eventMask & ~PointerGrabMask) { + client->errorValue = stuff->eventMask; return BadValue; } if (stuff->confineTo == None) - confineTo = NullWindow; - else - { - rc = dixLookupWindow(&confineTo, stuff->confineTo, client, - DixSetAttrAccess); - if (rc != Success) - return rc; + confineTo = NullWindow; + else { + rc = dixLookupWindow(&confineTo, stuff->confineTo, client, + DixSetAttrAccess); + if (rc != Success) + return rc; } memset(&rep, 0, sizeof(xGrabPointerReply)); oldCursor = NullCursor; grab = device->deviceGrab.grab; - if (grab) - { + if (grab) { if (grab->confineTo && !confineTo) ConfineCursorToWindow(device, GetCurrentRootWindow(device), FALSE, FALSE); @@ -4991,13 +4786,12 @@ ProcGrabPointer(ClientPtr client) rc = GrabDevice(client, device, stuff->pointerMode, stuff->keyboardMode, stuff->grabWindow, stuff->ownerEvents, stuff->time, - &mask, CORE, stuff->cursor, - stuff->confineTo, &rep.status); + &mask, CORE, stuff->cursor, stuff->confineTo, &rep.status); if (rc != Success) return rc; if (oldCursor && rep.status == GrabSuccess) - FreeCursor (oldCursor, (Cursor)0); + FreeCursor(oldCursor, (Cursor) 0); rep.type = X_Reply; rep.sequenceNumber = client->sequence; @@ -5016,48 +4810,47 @@ int ProcChangeActivePointerGrab(ClientPtr client) { DeviceIntPtr device; - GrabPtr grab; + GrabPtr grab; CursorPtr newCursor, oldCursor; + REQUEST(xChangeActivePointerGrabReq); TimeStamp time; REQUEST_SIZE_MATCH(xChangeActivePointerGrabReq); - if (stuff->eventMask & ~PointerGrabMask) - { - client->errorValue = stuff->eventMask; + if (stuff->eventMask & ~PointerGrabMask) { + client->errorValue = stuff->eventMask; return BadValue; } if (stuff->cursor == None) - newCursor = NullCursor; - else - { - int rc = dixLookupResourceByType((pointer *)&newCursor, stuff->cursor, - RT_CURSOR, client, DixUseAccess); - if (rc != Success) - { - client->errorValue = stuff->cursor; - return rc; - } + newCursor = NullCursor; + else { + int rc = dixLookupResourceByType((pointer *) &newCursor, stuff->cursor, + RT_CURSOR, client, DixUseAccess); + + if (rc != Success) { + client->errorValue = stuff->cursor; + return rc; + } } device = PickPointer(client); grab = device->deviceGrab.grab; if (!grab) - return Success; + return Success; if (!SameClient(grab, client)) - return Success; + return Success; time = ClientTimeToServerTime(stuff->time); if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, device->deviceGrab.grabTime) == EARLIER)) - return Success; + (CompareTimeStamps(time, device->deviceGrab.grabTime) == EARLIER)) + return Success; oldCursor = grab->cursor; grab->cursor = newCursor; if (newCursor) - newCursor->refcnt++; + newCursor->refcnt++; PostNewCursor(device); if (oldCursor) - FreeCursor(oldCursor, (Cursor)0); + FreeCursor(oldCursor, (Cursor) 0); grab->eventMask = stuff->eventMask; return Success; } @@ -5073,6 +4866,7 @@ ProcUngrabPointer(ClientPtr client) DeviceIntPtr device = PickPointer(client); GrabPtr grab; TimeStamp time; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); @@ -5081,9 +4875,9 @@ ProcUngrabPointer(ClientPtr client) time = ClientTimeToServerTime(stuff->id); if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->deviceGrab.grabTime) != EARLIER) && - (grab) && SameClient(grab, client)) - (*device->deviceGrab.DeactivateGrab)(device); + (CompareTimeStamps(time, device->deviceGrab.grabTime) != EARLIER) && + (grab) && SameClient(grab, client)) + (*device->deviceGrab.DeactivateGrab) (device); return Success; } @@ -5120,99 +4914,91 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev, CursorPtr cursor; UpdateCurrentTime(); - if ((keyboard_mode != GrabModeSync) && (keyboard_mode != GrabModeAsync)) - { - client->errorValue = keyboard_mode; + if ((keyboard_mode != GrabModeSync) && (keyboard_mode != GrabModeAsync)) { + client->errorValue = keyboard_mode; return BadValue; } - if ((pointer_mode != GrabModeSync) && (pointer_mode != GrabModeAsync)) - { - client->errorValue = pointer_mode; + if ((pointer_mode != GrabModeSync) && (pointer_mode != GrabModeAsync)) { + client->errorValue = pointer_mode; return BadValue; } - if ((ownerEvents != xFalse) && (ownerEvents != xTrue)) - { - client->errorValue = ownerEvents; + if ((ownerEvents != xFalse) && (ownerEvents != xTrue)) { + client->errorValue = ownerEvents; return BadValue; } rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess); if (rc != Success) - return rc; + return rc; if (confineToWin == None) - confineTo = NullWindow; - else - { - rc = dixLookupWindow(&confineTo, confineToWin, client, - DixSetAttrAccess); - if (rc != Success) - return rc; + confineTo = NullWindow; + else { + rc = dixLookupWindow(&confineTo, confineToWin, client, + DixSetAttrAccess); + if (rc != Success) + return rc; } if (curs == None) - cursor = NullCursor; - else - { - rc = dixLookupResourceByType((pointer *)&cursor, curs, RT_CURSOR, - client, DixUseAccess); - if (rc != Success) - { - client->errorValue = curs; - return rc; - } - access_mode |= DixForceAccess; + cursor = NullCursor; + else { + rc = dixLookupResourceByType((pointer *) &cursor, curs, RT_CURSOR, + client, DixUseAccess); + if (rc != Success) { + client->errorValue = curs; + return rc; + } + access_mode |= DixForceAccess; } if (keyboard_mode == GrabModeSync || pointer_mode == GrabModeSync) - access_mode |= DixFreezeAccess; + access_mode |= DixFreezeAccess; rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode); if (rc != Success) - return rc; + return rc; time = ClientTimeToServerTime(ctime); grab = grabInfo->grab; if (grab && grab->grabtype != grabtype) *status = AlreadyGrabbed; if (grab && !SameClient(grab, client)) - *status = AlreadyGrabbed; + *status = AlreadyGrabbed; else if ((!pWin->realized) || (confineTo && - !(confineTo->realized - && BorderSizeNotEmpty(dev, confineTo)))) - *status = GrabNotViewable; + !(confineTo->realized && BorderSizeNotEmpty(dev, confineTo)))) + *status = GrabNotViewable; else if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, grabInfo->grabTime) == EARLIER)) - *status = GrabInvalidTime; + (CompareTimeStamps(time, grabInfo->grabTime) == EARLIER)) + *status = GrabInvalidTime; else if (grabInfo->sync.frozen && - grabInfo->sync.other && !SameClient(grabInfo->sync.other, client)) - *status = GrabFrozen; - else - { - GrabPtr tempGrab; - - tempGrab = AllocGrab(); - - tempGrab->next = NULL; - tempGrab->window = pWin; - tempGrab->resource = client->clientAsMask; - tempGrab->ownerEvents = ownerEvents; - tempGrab->keyboardMode = keyboard_mode; - tempGrab->pointerMode = pointer_mode; - if (grabtype == CORE) - tempGrab->eventMask = mask->core; - else if (grabtype == XI) - tempGrab->eventMask = mask->xi; - else + grabInfo->sync.other && !SameClient(grabInfo->sync.other, client)) + *status = GrabFrozen; + else { + GrabPtr tempGrab; + + tempGrab = AllocGrab(); + + tempGrab->next = NULL; + tempGrab->window = pWin; + tempGrab->resource = client->clientAsMask; + tempGrab->ownerEvents = ownerEvents; + tempGrab->keyboardMode = keyboard_mode; + tempGrab->pointerMode = pointer_mode; + if (grabtype == CORE) + tempGrab->eventMask = mask->core; + else if (grabtype == XI) + tempGrab->eventMask = mask->xi; + else xi2mask_merge(tempGrab->xi2mask, mask->xi2mask); - tempGrab->device = dev; - tempGrab->cursor = cursor; - tempGrab->confineTo = confineTo; - tempGrab->grabtype = grabtype; - (*grabInfo->ActivateGrab)(dev, tempGrab, time, FALSE); - *status = GrabSuccess; + tempGrab->device = dev; + tempGrab->cursor = cursor; + tempGrab->confineTo = confineTo; + tempGrab->grabtype = grabtype; + (*grabInfo->ActivateGrab) (dev, tempGrab, time, FALSE); + *status = GrabSuccess; - FreeGrab(tempGrab); + FreeGrab(tempGrab); } return Success; } @@ -5226,6 +5012,7 @@ int ProcGrabKeyboard(ClientPtr client) { xGrabKeyboardReply rep; + REQUEST(xGrabKeyboardReq); int result; DeviceIntPtr keyboard = PickKeyboard(client); @@ -5237,12 +5024,12 @@ ProcGrabKeyboard(ClientPtr client) mask.core = KeyPressMask | KeyReleaseMask; result = GrabDevice(client, keyboard, stuff->pointerMode, - stuff->keyboardMode, stuff->grabWindow, stuff->ownerEvents, - stuff->time, &mask, CORE, None, None, - &rep.status); + stuff->keyboardMode, stuff->grabWindow, + stuff->ownerEvents, stuff->time, &mask, CORE, None, + None, &rep.status); if (result != Success) - return result; + return result; rep.type = X_Reply; rep.sequenceNumber = client->sequence; rep.length = 0; @@ -5261,6 +5048,7 @@ ProcUngrabKeyboard(ClientPtr client) DeviceIntPtr device = PickKeyboard(client); GrabPtr grab; TimeStamp time; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); @@ -5270,9 +5058,9 @@ ProcUngrabKeyboard(ClientPtr client) time = ClientTimeToServerTime(stuff->id); if ((CompareTimeStamps(time, currentTime) != LATER) && - (CompareTimeStamps(time, device->deviceGrab.grabTime) != EARLIER) && - (grab) && SameClient(grab, client) && grab->grabtype == CORE) - (*device->deviceGrab.DeactivateGrab)(device); + (CompareTimeStamps(time, device->deviceGrab.grabTime) != EARLIER) && + (grab) && SameClient(grab, client) && grab->grabtype == CORE) + (*device->deviceGrab.DeactivateGrab) (device); return Success; } @@ -5291,21 +5079,22 @@ ProcQueryPointer(ClientPtr client) DeviceIntPtr keyboard; SpritePtr pSprite; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rc = XaceHook(XACE_DEVICE_ACCESS, client, mouse, DixReadAccess); if (rc != Success && rc != BadAccess) - return rc; + return rc; keyboard = GetMaster(mouse, MASTER_KEYBOARD); pSprite = mouse->spriteInfo->sprite; if (mouse->valuator->motionHintWindow) - MaybeStopHint(mouse, client); + MaybeStopHint(mouse, client); memset(&rep, 0, sizeof(xQueryPointerReply)); rep.type = X_Reply; rep.sequenceNumber = client->sequence; @@ -5316,43 +5105,40 @@ ProcQueryPointer(ClientPtr client) rep.rootX = pSprite->hot.x; rep.rootY = pSprite->hot.y; rep.child = None; - if (pSprite->hot.pScreen == pWin->drawable.pScreen) - { - rep.sameScreen = xTrue; - rep.winX = pSprite->hot.x - pWin->drawable.x; - rep.winY = pSprite->hot.y - pWin->drawable.y; - for (t = pSprite->win; t; t = t->parent) - if (t->parent == pWin) - { - rep.child = t->drawable.id; - break; - } + if (pSprite->hot.pScreen == pWin->drawable.pScreen) { + rep.sameScreen = xTrue; + rep.winX = pSprite->hot.x - pWin->drawable.x; + rep.winY = pSprite->hot.y - pWin->drawable.y; + for (t = pSprite->win; t; t = t->parent) + if (t->parent == pWin) { + rep.child = t->drawable.id; + break; + } } - else - { - rep.sameScreen = xFalse; - rep.winX = 0; - rep.winY = 0; + else { + rep.sameScreen = xFalse; + rep.winX = 0; + rep.winY = 0; } #ifdef PANORAMIX - if(!noPanoramiXExtension) { - rep.rootX += screenInfo.screens[0]->x; - rep.rootY += screenInfo.screens[0]->y; - if(stuff->id == rep.root) { - rep.winX += screenInfo.screens[0]->x; - rep.winY += screenInfo.screens[0]->y; - } + if (!noPanoramiXExtension) { + rep.rootX += screenInfo.screens[0]->x; + rep.rootY += screenInfo.screens[0]->y; + if (stuff->id == rep.root) { + rep.winX += screenInfo.screens[0]->x; + rep.winY += screenInfo.screens[0]->y; + } } #endif if (rc == BadAccess) { - rep.mask = 0; - rep.child = None; - rep.rootX = 0; - rep.rootY = 0; - rep.winX = 0; - rep.winY = 0; + rep.mask = 0; + rep.child = None; + rep.rootX = 0; + rep.rootY = 0; + rep.winX = 0; + rep.winY = 0; } WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep); @@ -5371,16 +5157,17 @@ InitEvents(void) QdEventPtr qe, tmp; inputInfo.numDevices = 0; - inputInfo.devices = (DeviceIntPtr)NULL; - inputInfo.off_devices = (DeviceIntPtr)NULL; - inputInfo.keyboard = (DeviceIntPtr)NULL; - inputInfo.pointer = (DeviceIntPtr)NULL; - for (i = 0; i < MAXDEVICES; i++) - { + inputInfo.devices = (DeviceIntPtr) NULL; + inputInfo.off_devices = (DeviceIntPtr) NULL; + inputInfo.keyboard = (DeviceIntPtr) NULL; + inputInfo.pointer = (DeviceIntPtr) NULL; + + for (i = 0; i < MAXDEVICES; i++) { memcpy(&event_filters[i], default_filter, sizeof(default_filter)); + lastDeviceEventTime[i] = currentTime; } - syncEvents.replayDev = (DeviceIntPtr)NULL; + syncEvents.replayDev = (DeviceIntPtr) NULL; syncEvents.replayWin = NullWindow; if (syncEvents.pending.next) xorg_list_for_each_entry_safe(qe, tmp, &syncEvents.pending, next) @@ -5388,14 +5175,12 @@ InitEvents(void) xorg_list_init(&syncEvents.pending); syncEvents.playingEvents = FALSE; syncEvents.time.months = 0; - syncEvents.time.milliseconds = 0; /* hardly matters */ + syncEvents.time.milliseconds = 0; /* hardly matters */ currentTime.months = 0; currentTime.milliseconds = GetTimeInMillis(); - lastDeviceEventTime = currentTime; - for (i = 0; i < DNPMCOUNT; i++) - { - DontPropagateMasks[i] = 0; - DontPropagateRefCnts[i] = 0; + for (i = 0; i < DNPMCOUNT; i++) { + DontPropagateMasks[i] = 0; + DontPropagateRefCnts[i] = 0; } InputEventList = InitEventList(GetMaximumEventsNum()); @@ -5421,10 +5206,11 @@ int ProcSendEvent(ClientPtr client) { WindowPtr pWin; - WindowPtr effectiveFocus = NullWindow; /* only set if dest==InputFocus */ + WindowPtr effectiveFocus = NullWindow; /* only set if dest==InputFocus */ DeviceIntPtr dev = PickPointer(client); DeviceIntPtr keybd = GetMaster(dev, MASTER_KEYBOARD); SpritePtr pSprite = dev->spriteInfo->sprite; + REQUEST(xSendEventReq); REQUEST_SIZE_MATCH(xSendEventReq); @@ -5440,83 +5226,75 @@ ProcSendEvent(ClientPtr client) stuff->event.u.u.type &= ~(SEND_EVENT_BIT); /* The client's event type must be a core event type or one defined by an - extension. */ + extension. */ - if ( ! ((stuff->event.u.u.type > X_Reply && - stuff->event.u.u.type < LASTEvent) || - (stuff->event.u.u.type >= EXTENSION_EVENT_BASE && - stuff->event.u.u.type < (unsigned)lastEvent))) - { - client->errorValue = stuff->event.u.u.type; - return BadValue; + if (!((stuff->event.u.u.type > X_Reply && + stuff->event.u.u.type < LASTEvent) || + (stuff->event.u.u.type >= EXTENSION_EVENT_BASE && + stuff->event.u.u.type < (unsigned) lastEvent))) { + client->errorValue = stuff->event.u.u.type; + return BadValue; } if (stuff->event.u.u.type == ClientMessage && - stuff->event.u.u.detail != 8 && - stuff->event.u.u.detail != 16 && - stuff->event.u.u.detail != 32) - { - client->errorValue = stuff->event.u.u.detail; - return BadValue; + stuff->event.u.u.detail != 8 && + stuff->event.u.u.detail != 16 && stuff->event.u.u.detail != 32) { + client->errorValue = stuff->event.u.u.detail; + return BadValue; } - if (stuff->eventMask & ~AllEventMasks) - { - client->errorValue = stuff->eventMask; - return BadValue; + if (stuff->eventMask & ~AllEventMasks) { + client->errorValue = stuff->eventMask; + return BadValue; } if (stuff->destination == PointerWindow) - pWin = pSprite->win; - else if (stuff->destination == InputFocus) - { - WindowPtr inputFocus = (keybd) ? keybd->focus->win : NoneWin; + pWin = pSprite->win; + else if (stuff->destination == InputFocus) { + WindowPtr inputFocus = (keybd) ? keybd->focus->win : NoneWin; - if (inputFocus == NoneWin) - return Success; + if (inputFocus == NoneWin) + return Success; - /* If the input focus is PointerRootWin, send the event to where - the pointer is if possible, then perhaps propogate up to root. */ - if (inputFocus == PointerRootWin) - inputFocus = GetCurrentRootWindow(dev); + /* If the input focus is PointerRootWin, send the event to where + the pointer is if possible, then perhaps propogate up to root. */ + if (inputFocus == PointerRootWin) + inputFocus = GetCurrentRootWindow(dev); - if (IsParent(inputFocus, pSprite->win)) - { - effectiveFocus = inputFocus; - pWin = pSprite->win; - } - else - effectiveFocus = pWin = inputFocus; + if (IsParent(inputFocus, pSprite->win)) { + effectiveFocus = inputFocus; + pWin = pSprite->win; + } + else + effectiveFocus = pWin = inputFocus; } else - dixLookupWindow(&pWin, stuff->destination, client, DixSendAccess); + dixLookupWindow(&pWin, stuff->destination, client, DixSendAccess); if (!pWin) - return BadWindow; - if ((stuff->propagate != xFalse) && (stuff->propagate != xTrue)) - { - client->errorValue = stuff->propagate; - return BadValue; + return BadWindow; + if ((stuff->propagate != xFalse) && (stuff->propagate != xTrue)) { + client->errorValue = stuff->propagate; + return BadValue; } stuff->event.u.u.type |= SEND_EVENT_BIT; - if (stuff->propagate) - { - for (;pWin; pWin = pWin->parent) - { - if (XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, - &stuff->event, 1)) - return Success; + if (stuff->propagate) { + for (; pWin; pWin = pWin->parent) { + if (XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, + &stuff->event, 1)) + return Success; if (DeliverEventsToWindow(dev, pWin, - &stuff->event, 1, stuff->eventMask, NullGrab)) - return Success; - if (pWin == effectiveFocus) - return Success; - stuff->eventMask &= ~wDontPropagateMask(pWin); - if (!stuff->eventMask) - break; - } + &stuff->event, 1, stuff->eventMask, + NullGrab)) + return Success; + if (pWin == effectiveFocus) + return Success; + stuff->eventMask &= ~wDontPropagateMask(pWin); + if (!stuff->eventMask) + break; + } } else if (!XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, &stuff->event, 1)) DeliverEventsToWindow(dev, pWin, &stuff->event, - 1, stuff->eventMask, NullGrab); + 1, stuff->eventMask, NullGrab); return Success; } @@ -5538,20 +5316,18 @@ ProcUngrabKey(ClientPtr client) REQUEST_SIZE_MATCH(xUngrabKeyReq); rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; if (((stuff->key > keybd->key->xkbInfo->desc->max_key_code) || - (stuff->key < keybd->key->xkbInfo->desc->min_key_code)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; + (stuff->key < keybd->key->xkbInfo->desc->min_key_code)) + && (stuff->key != AnyKey)) { + client->errorValue = stuff->key; return BadValue; } if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; + (stuff->modifiers & ~AllModifiersMask)) { + client->errorValue = stuff->modifiers; + return BadValue; } tempGrab = AllocGrab(); if (!tempGrab) @@ -5586,6 +5362,7 @@ int ProcGrabKey(ClientPtr client) { WindowPtr pWin; + REQUEST(xGrabKeyReq); GrabPtr grab; DeviceIntPtr keybd = PickKeyboard(client); @@ -5607,27 +5384,24 @@ ProcGrabKey(ClientPtr client) return rc; if (((stuff->key > keybd->key->xkbInfo->desc->max_key_code) || - (stuff->key < keybd->key->xkbInfo->desc->min_key_code)) - && (stuff->key != AnyKey)) - { - client->errorValue = stuff->key; + (stuff->key < keybd->key->xkbInfo->desc->min_key_code)) + && (stuff->key != AnyKey)) { + client->errorValue = stuff->key; return BadValue; } rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess); if (rc != Success) - return rc; - + return rc; mask.core = (KeyPressMask | KeyReleaseMask); grab = CreateGrab(client->index, keybd, keybd, pWin, CORE, &mask, ¶m, KeyPress, stuff->key, NullWindow, NullCursor); if (!grab) - return BadAlloc; + return BadAlloc; return AddPassiveGrabToList(client, grab); } - /** * Server-side protocol handling for GrabButton request. * @@ -5638,6 +5412,7 @@ int ProcGrabButton(ClientPtr client) { WindowPtr pWin, confineTo; + REQUEST(xGrabButtonReq); CursorPtr cursor; GrabPtr grab; @@ -5649,66 +5424,59 @@ ProcGrabButton(ClientPtr client) REQUEST_SIZE_MATCH(xGrabButtonReq); if ((stuff->pointerMode != GrabModeSync) && - (stuff->pointerMode != GrabModeAsync)) - { - client->errorValue = stuff->pointerMode; + (stuff->pointerMode != GrabModeAsync)) { + client->errorValue = stuff->pointerMode; return BadValue; } if ((stuff->keyboardMode != GrabModeSync) && - (stuff->keyboardMode != GrabModeAsync)) - { - client->errorValue = stuff->keyboardMode; + (stuff->keyboardMode != GrabModeAsync)) { + client->errorValue = stuff->keyboardMode; return BadValue; } if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; + (stuff->modifiers & ~AllModifiersMask)) { + client->errorValue = stuff->modifiers; + return BadValue; } - if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) - { - client->errorValue = stuff->ownerEvents; - return BadValue; + if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue)) { + client->errorValue = stuff->ownerEvents; + return BadValue; } - if (stuff->eventMask & ~PointerGrabMask) - { - client->errorValue = stuff->eventMask; + if (stuff->eventMask & ~PointerGrabMask) { + client->errorValue = stuff->eventMask; return BadValue; } rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess); if (rc != Success) - return rc; + return rc; if (stuff->confineTo == None) - confineTo = NullWindow; + confineTo = NullWindow; else { - rc = dixLookupWindow(&confineTo, stuff->confineTo, client, - DixSetAttrAccess); - if (rc != Success) - return rc; + rc = dixLookupWindow(&confineTo, stuff->confineTo, client, + DixSetAttrAccess); + if (rc != Success) + return rc; } if (stuff->cursor == None) - cursor = NullCursor; - else - { - rc = dixLookupResourceByType((pointer *)&cursor, stuff->cursor, RT_CURSOR, - client, DixUseAccess); - if (rc != Success) - { - client->errorValue = stuff->cursor; - return rc; - } - access_mode |= DixForceAccess; + cursor = NullCursor; + else { + rc = dixLookupResourceByType((pointer *) &cursor, stuff->cursor, + RT_CURSOR, client, DixUseAccess); + if (rc != Success) { + client->errorValue = stuff->cursor; + return rc; + } + access_mode |= DixForceAccess; } ptr = PickPointer(client); modifierDevice = GetMaster(ptr, MASTER_KEYBOARD); if (stuff->pointerMode == GrabModeSync || - stuff->keyboardMode == GrabModeSync) - access_mode |= DixFreezeAccess; + stuff->keyboardMode == GrabModeSync) + access_mode |= DixFreezeAccess; rc = XaceHook(XACE_DEVICE_ACCESS, client, ptr, access_mode); if (rc != Success) - return rc; + return rc; memset(¶m, 0, sizeof(param)); param.grabtype = CORE; @@ -5723,7 +5491,7 @@ ProcGrabButton(ClientPtr client) CORE, &mask, ¶m, ButtonPress, stuff->button, confineTo, cursor); if (!grab) - return BadAlloc; + return BadAlloc; return AddPassiveGrabToList(client, grab); } @@ -5743,14 +5511,13 @@ ProcUngrabButton(ClientPtr client) REQUEST_SIZE_MATCH(xUngrabButtonReq); if ((stuff->modifiers != AnyModifier) && - (stuff->modifiers & ~AllModifiersMask)) - { - client->errorValue = stuff->modifiers; - return BadValue; + (stuff->modifiers & ~AllModifiersMask)) { + client->errorValue = stuff->modifiers; + return BadValue; } rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixReadAccess); if (rc != Success) - return rc; + return rc; ptr = PickPointer(client); @@ -5790,48 +5557,40 @@ ProcUngrabButton(ClientPtr client) void DeleteWindowFromAnyEvents(WindowPtr pWin, Bool freeResources) { - WindowPtr parent; - DeviceIntPtr mouse = inputInfo.pointer; - DeviceIntPtr keybd = inputInfo.keyboard; - FocusClassPtr focus; - OtherClientsPtr oc; - GrabPtr passive; - GrabPtr grab; - + WindowPtr parent; + DeviceIntPtr mouse = inputInfo.pointer; + DeviceIntPtr keybd = inputInfo.keyboard; + FocusClassPtr focus; + OtherClientsPtr oc; + GrabPtr passive; + GrabPtr grab; /* Deactivate any grabs performed on this window, before making any - input focus changes. */ + input focus changes. */ grab = mouse->deviceGrab.grab; - if (grab && - ((grab->window == pWin) || (grab->confineTo == pWin))) - (*mouse->deviceGrab.DeactivateGrab)(mouse); - + if (grab && ((grab->window == pWin) || (grab->confineTo == pWin))) + (*mouse->deviceGrab.DeactivateGrab) (mouse); /* Deactivating a keyboard grab should cause focus events. */ grab = keybd->deviceGrab.grab; if (grab && (grab->window == pWin)) - (*keybd->deviceGrab.DeactivateGrab)(keybd); + (*keybd->deviceGrab.DeactivateGrab) (keybd); /* And now the real devices */ - for (mouse = inputInfo.devices; mouse; mouse = mouse->next) - { + for (mouse = inputInfo.devices; mouse; mouse = mouse->next) { grab = mouse->deviceGrab.grab; if (grab && ((grab->window == pWin) || (grab->confineTo == pWin))) - (*mouse->deviceGrab.DeactivateGrab)(mouse); + (*mouse->deviceGrab.DeactivateGrab) (mouse); } - - for (keybd = inputInfo.devices; keybd; keybd = keybd->next) - { - if (IsKeyboardDevice(keybd)) - { + for (keybd = inputInfo.devices; keybd; keybd = keybd->next) { + if (IsKeyboardDevice(keybd)) { focus = keybd->focus; /* If the focus window is a root window (ie. has no parent) then don't delete the focus from it. */ - if ((pWin == focus->win) && (pWin->parent != NullWindow)) - { + if ((pWin == focus->win) && (pWin->parent != NullWindow)) { int focusEventMode = NotifyNormal; /* If a grab is in progress, then alter the mode of focus events. */ @@ -5839,61 +5598,58 @@ DeleteWindowFromAnyEvents(WindowPtr pWin, Bool freeResources) if (keybd->deviceGrab.grab) focusEventMode = NotifyWhileGrabbed; - switch (focus->revert) - { - case RevertToNone: - DoFocusEvents(keybd, pWin, NoneWin, focusEventMode); - focus->win = NoneWin; - focus->traceGood = 0; - break; - case RevertToParent: - parent = pWin; - do - { - parent = parent->parent; - focus->traceGood--; - } while (!parent->realized - /* This would be a good protocol change -- windows being reparented - during SaveSet processing would cause the focus to revert to the - nearest enclosing window which will survive the death of the exiting - client, instead of ending up reverting to a dying window and thence - to None - */ + switch (focus->revert) { + case RevertToNone: + DoFocusEvents(keybd, pWin, NoneWin, focusEventMode); + focus->win = NoneWin; + focus->traceGood = 0; + break; + case RevertToParent: + parent = pWin; + do { + parent = parent->parent; + focus->traceGood--; + } while (!parent->realized + /* This would be a good protocol change -- windows being reparented + during SaveSet processing would cause the focus to revert to the + nearest enclosing window which will survive the death of the exiting + client, instead of ending up reverting to a dying window and thence + to None + */ #ifdef NOTDEF - || wClient(parent)->clientGone + || wClient(parent)->clientGone #endif - ); - if (!ActivateFocusInGrab(keybd, pWin, parent)) - DoFocusEvents(keybd, pWin, parent, focusEventMode); - focus->win = parent; - focus->revert = RevertToNone; - break; - case RevertToPointerRoot: - if (!ActivateFocusInGrab(keybd, pWin, PointerRootWin)) - DoFocusEvents(keybd, pWin, PointerRootWin, focusEventMode); - focus->win = PointerRootWin; - focus->traceGood = 0; - break; + ); + if (!ActivateFocusInGrab(keybd, pWin, parent)) + DoFocusEvents(keybd, pWin, parent, focusEventMode); + focus->win = parent; + focus->revert = RevertToNone; + break; + case RevertToPointerRoot: + if (!ActivateFocusInGrab(keybd, pWin, PointerRootWin)) + DoFocusEvents(keybd, pWin, PointerRootWin, + focusEventMode); + focus->win = PointerRootWin; + focus->traceGood = 0; + break; } } } - if (IsPointerDevice(keybd)) - { + if (IsPointerDevice(keybd)) { if (keybd->valuator->motionHintWindow == pWin) keybd->valuator->motionHintWindow = NullWindow; } } - if (freeResources) - { - if (pWin->dontPropagate) - DontPropagateRefCnts[pWin->dontPropagate]--; - while ( (oc = wOtherClients(pWin)) ) - FreeResource(oc->resource, RT_NONE); - while ( (passive = wPassiveGrabs(pWin)) ) - FreeResource(passive->resource, RT_NONE); - } + if (freeResources) { + if (pWin->dontPropagate) + DontPropagateRefCnts[pWin->dontPropagate]--; + while ((oc = wOtherClients(pWin))) + FreeResource(oc->resource, RT_NONE); + while ((passive = wPassiveGrabs(pWin))) + FreeResource(passive->resource, RT_NONE); + } DeleteWindowFromAnyExtEvents(pWin, freeResources); } @@ -5911,18 +5667,16 @@ CheckCursorConfinement(WindowPtr pWin) DeviceIntPtr pDev; #ifdef PANORAMIX - if(!noPanoramiXExtension && pWin->drawable.pScreen->myNum) return; + if (!noPanoramiXExtension && pWin->drawable.pScreen->myNum) + return; #endif - for (pDev = inputInfo.devices; pDev; pDev = pDev->next) - { - if (DevHasCursor(pDev)) - { + for (pDev = inputInfo.devices; pDev; pDev = pDev->next) { + if (DevHasCursor(pDev)) { grab = pDev->deviceGrab.grab; - if (grab && (confineTo = grab->confineTo)) - { + if (grab && (confineTo = grab->confineTo)) { if (!BorderSizeNotEmpty(pDev, confineTo)) - (*pDev->deviceGrab.DeactivateGrab)(pDev); + (*pDev->deviceGrab.DeactivateGrab) (pDev); else if ((pWin == confineTo) || IsParent(pWin, confineTo)) ConfineCursorToWindow(pDev, confineTo, TRUE, TRUE); } @@ -5933,14 +5687,13 @@ CheckCursorConfinement(WindowPtr pWin) Mask EventMaskForClient(WindowPtr pWin, ClientPtr client) { - OtherClientsPtr other; + OtherClientsPtr other; - if (wClient (pWin) == client) - return pWin->eventMask; - for (other = wOtherClients(pWin); other; other = other->next) - { - if (SameClient(other, client)) - return other->mask; + if (wClient(pWin) == client) + return pWin->eventMask; + for (other = wOtherClients(pWin); other; other = other->next) { + if (SameClient(other, client)) + return other->mask; } return 0; } @@ -5952,19 +5705,19 @@ int ProcRecolorCursor(ClientPtr client) { CursorPtr pCursor; - int rc, nscr; - ScreenPtr pscr; - Bool displayed; - SpritePtr pSprite = PickPointer(client)->spriteInfo->sprite; + int rc, nscr; + ScreenPtr pscr; + Bool displayed; + SpritePtr pSprite = PickPointer(client)->spriteInfo->sprite; + REQUEST(xRecolorCursorReq); REQUEST_SIZE_MATCH(xRecolorCursorReq); - rc = dixLookupResourceByType((pointer *)&pCursor, stuff->cursor, RT_CURSOR, - client, DixWriteAccess); - if (rc != Success) - { - client->errorValue = stuff->cursor; - return rc; + rc = dixLookupResourceByType((pointer *) &pCursor, stuff->cursor, RT_CURSOR, + client, DixWriteAccess); + if (rc != Success) { + client->errorValue = stuff->cursor; + return rc; } pCursor->foreRed = stuff->foreRed; @@ -5975,17 +5728,16 @@ ProcRecolorCursor(ClientPtr client) pCursor->backGreen = stuff->backGreen; pCursor->backBlue = stuff->backBlue; - for (nscr = 0; nscr < screenInfo.numScreens; nscr++) - { - pscr = screenInfo.screens[nscr]; + for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { + pscr = screenInfo.screens[nscr]; #ifdef PANORAMIX - if(!noPanoramiXExtension) - displayed = (pscr == pSprite->screen); - else + if (!noPanoramiXExtension) + displayed = (pscr == pSprite->screen); + else #endif - displayed = (pscr == pSprite->hotPhys.pScreen); - ( *pscr->RecolorCursor)(PickPointer(client), pscr, pCursor, - (pCursor == pSprite->current) && displayed); + displayed = (pscr == pSprite->hotPhys.pScreen); + (*pscr->RecolorCursor) (PickPointer(client), pscr, pCursor, + (pCursor == pSprite->current) && displayed); } return Success; } @@ -6008,120 +5760,109 @@ void WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) { #ifdef PANORAMIX - xEvent eventCopy; + xEvent eventCopy; #endif - xEvent *eventTo, *eventFrom; - int i, - eventlength = sizeof(xEvent); + xEvent *eventTo, *eventFrom; + int i, eventlength = sizeof(xEvent); if (!pClient || pClient == serverClient || pClient->clientGone) - return; + return; for (i = 0; i < count; i++) - if ((events[i].u.u.type & 0x7f) != KeymapNotify) - events[i].u.u.sequenceNumber = pClient->sequence; + if ((events[i].u.u.type & 0x7f) != KeymapNotify) + events[i].u.u.sequenceNumber = pClient->sequence; /* Let XKB rewrite the state, as it depends on client preferences. */ XkbFilterEvents(pClient, count, events); #ifdef PANORAMIX - if(!noPanoramiXExtension && - (screenInfo.screens[0]->x || screenInfo.screens[0]->y)) - { - switch(events->u.u.type) { - case MotionNotify: - case ButtonPress: - case ButtonRelease: - case KeyPress: - case KeyRelease: - case EnterNotify: - case LeaveNotify: - /* - When multiple clients want the same event DeliverEventsToWindow - passes the same event structure multiple times so we can't - modify the one passed to us - */ - count = 1; /* should always be 1 */ - memcpy(&eventCopy, events, sizeof(xEvent)); - eventCopy.u.keyButtonPointer.rootX += screenInfo.screens[0]->x; - eventCopy.u.keyButtonPointer.rootY += screenInfo.screens[0]->y; - if(eventCopy.u.keyButtonPointer.event == - eventCopy.u.keyButtonPointer.root) - { - eventCopy.u.keyButtonPointer.eventX += screenInfo.screens[0]->x; - eventCopy.u.keyButtonPointer.eventY += screenInfo.screens[0]->y; - } - events = &eventCopy; - break; - default: break; - } + if (!noPanoramiXExtension && + (screenInfo.screens[0]->x || screenInfo.screens[0]->y)) { + switch (events->u.u.type) { + case MotionNotify: + case ButtonPress: + case ButtonRelease: + case KeyPress: + case KeyRelease: + case EnterNotify: + case LeaveNotify: + /* + When multiple clients want the same event DeliverEventsToWindow + passes the same event structure multiple times so we can't + modify the one passed to us + */ + count = 1; /* should always be 1 */ + memcpy(&eventCopy, events, sizeof(xEvent)); + eventCopy.u.keyButtonPointer.rootX += screenInfo.screens[0]->x; + eventCopy.u.keyButtonPointer.rootY += screenInfo.screens[0]->y; + if (eventCopy.u.keyButtonPointer.event == + eventCopy.u.keyButtonPointer.root) { + eventCopy.u.keyButtonPointer.eventX += screenInfo.screens[0]->x; + eventCopy.u.keyButtonPointer.eventY += screenInfo.screens[0]->y; + } + events = &eventCopy; + break; + default: + break; + } } #endif - if (EventCallback) - { - EventInfoRec eventinfo; - eventinfo.client = pClient; - eventinfo.events = events; - eventinfo.count = count; - CallCallbacks(&EventCallback, (pointer)&eventinfo); + if (EventCallback) { + EventInfoRec eventinfo; + + eventinfo.client = pClient; + eventinfo.events = events; + eventinfo.count = count; + CallCallbacks(&EventCallback, (pointer) &eventinfo); } #ifdef XSERVER_DTRACE if (XSERVER_SEND_EVENT_ENABLED()) { - for (i = 0; i < count; i++) - { - XSERVER_SEND_EVENT(pClient->index, events[i].u.u.type, &events[i]); - } + for (i = 0; i < count; i++) { + XSERVER_SEND_EVENT(pClient->index, events[i].u.u.type, &events[i]); + } } #endif /* Just a safety check to make sure we only have one GenericEvent, it just * makes things easier for me right now. (whot) */ - for (i = 1; i < count; i++) - { - if (events[i].u.u.type == GenericEvent) - { + for (i = 1; i < count; i++) { + if (events[i].u.u.type == GenericEvent) { ErrorF("[dix] TryClientEvents: Only one GenericEvent at a time.\n"); return; } } - if (events->u.u.type == GenericEvent) - { - eventlength += ((xGenericEvent*)events)->length * 4; + if (events->u.u.type == GenericEvent) { + eventlength += ((xGenericEvent *) events)->length * 4; } - if(pClient->swapped) - { - if (eventlength > swapEventLen) - { + if (pClient->swapped) { + if (eventlength > swapEventLen) { swapEventLen = eventlength; swapEvent = realloc(swapEvent, swapEventLen); - if (!swapEvent) - { + if (!swapEvent) { FatalError("WriteEventsToClient: Out of memory.\n"); return; } } - for(i = 0; i < count; i++) - { - eventFrom = &events[i]; + for (i = 0; i < count; i++) { + eventFrom = &events[i]; eventTo = swapEvent; - /* Remember to strip off the leading bit of type in case - this event was sent with "SendEvent." */ - (*EventSwapVector[eventFrom->u.u.type & 0177]) - (eventFrom, eventTo); + /* Remember to strip off the leading bit of type in case + this event was sent with "SendEvent." */ + (*EventSwapVector[eventFrom->u.u.type & 0177]) + (eventFrom, eventTo); - WriteToClient(pClient, eventlength, (char *)eventTo); - } + WriteToClient(pClient, eventlength, (char *) eventTo); + } } - else - { + else { /* only one GenericEvent, remember? that means either count is 1 and * eventlength is arbitrary or eventlength is 32 and count doesn't * matter. And we're all set. Woohoo. */ - WriteToClient(pClient, count * eventlength, (char *) events); + WriteToClient(pClient, count * eventlength, (char *) events); } } @@ -6138,17 +5879,17 @@ int SetClientPointer(ClientPtr client, DeviceIntPtr device) { int rc = XaceHook(XACE_DEVICE_ACCESS, client, device, DixUseAccess); + if (rc != Success) - return rc; + return rc; - if (!IsMaster(device)) - { + if (!IsMaster(device)) { ErrorF("[dix] Need master device for ClientPointer. This is a bug.\n"); return BadDevice; - } else if (!device->spriteInfo->spriteOwner) - { + } + else if (!device->spriteInfo->spriteOwner) { ErrorF("[dix] Device %d does not have a sprite. " - "Cannot be ClientPointer\n", device->id); + "Cannot be ClientPointer\n", device->id); return BadDevice; } client->clientPtr = device; @@ -6169,23 +5910,19 @@ PickPointer(ClientPtr client) /* First, check if the client currently has a grab on a device. Even * keyboards count. */ - for(it = inputInfo.devices; it; it = it->next) - { + for (it = inputInfo.devices; it; it = it->next) { GrabPtr grab = it->deviceGrab.grab; - if (grab && grab->grabtype == CORE && SameClient(grab, client)) - { + + if (grab && grab->grabtype == CORE && SameClient(grab, client)) { it = GetMaster(it, MASTER_POINTER); - return it; /* Always return a core grabbed device */ + return it; /* Always return a core grabbed device */ } } - if (!client->clientPtr) - { + if (!client->clientPtr) { it = inputInfo.devices; - while (it) - { - if (IsMaster(it) && it->spriteInfo->spriteOwner) - { + while (it) { + if (IsMaster(it) && it->spriteInfo->spriteOwner) { client->clientPtr = it; break; } @@ -6205,10 +5942,9 @@ PickKeyboard(ClientPtr client) DeviceIntPtr ptr = PickPointer(client); DeviceIntPtr kbd = GetMaster(ptr, MASTER_KEYBOARD); - if (!kbd) - { + if (!kbd) { ErrorF("[dix] ClientPointer not paired with a keyboard. This " - "is a bug.\n"); + "is a bug.\n"); } return kbd; @@ -6223,36 +5959,32 @@ PickKeyboard(ClientPtr client) * be delivered. */ Bool -IsInterferingGrab(ClientPtr client, DeviceIntPtr dev, xEvent* event) +IsInterferingGrab(ClientPtr client, DeviceIntPtr dev, xEvent *event) { DeviceIntPtr it = inputInfo.devices; - switch(event->u.u.type) - { - case KeyPress: - case KeyRelease: - case ButtonPress: - case ButtonRelease: - case MotionNotify: - case EnterNotify: - case LeaveNotify: - break; - default: - return FALSE; + switch (event->u.u.type) { + case KeyPress: + case KeyRelease: + case ButtonPress: + case ButtonRelease: + case MotionNotify: + case EnterNotify: + case LeaveNotify: + break; + default: + return FALSE; } if (dev->deviceGrab.grab && SameClient(dev->deviceGrab.grab, client)) return FALSE; - while(it) - { - if (it != dev) - { + while (it) { + if (it != dev) { if (it->deviceGrab.grab && SameClient(it->deviceGrab.grab, client) - && !it->deviceGrab.fromPassiveGrab) - { + && !it->deviceGrab.fromPassiveGrab) { if ((IsPointerDevice(it) && IsPointerDevice(dev)) || - (IsKeyboardDevice(it) && IsKeyboardDevice(dev))) + (IsKeyboardDevice(it) && IsKeyboardDevice(dev))) return TRUE; } } @@ -6261,4 +5993,3 @@ IsInterferingGrab(ClientPtr client, DeviceIntPtr dev, xEvent* event) return FALSE; } - diff --git a/xorg-server/dix/extension.c b/xorg-server/dix/extension.c index af9ba312d..3cdfb5152 100644 --- a/xorg-server/dix/extension.c +++ b/xorg-server/dix/extension.c @@ -22,7 +22,6 @@ 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 @@ -63,7 +62,7 @@ SOFTWARE. #define LAST_ERROR 255 -static ExtensionEntry **extensions = (ExtensionEntry **)NULL; +static ExtensionEntry **extensions = (ExtensionEntry **) NULL; int lastEvent = EXTENSION_EVENT_BASE; static int lastError = FirstExtensionError; @@ -71,48 +70,46 @@ static unsigned int NumExtensions = 0; ExtensionEntry * AddExtension(const char *name, int NumEvents, int NumErrors, - int (*MainProc)(ClientPtr c1), - int (*SwappedMainProc)(ClientPtr c2), - void (*CloseDownProc)(ExtensionEntry *e), - unsigned short (*MinorOpcodeProc)(ClientPtr c3)) + int (*MainProc) (ClientPtr c1), + int (*SwappedMainProc) (ClientPtr c2), + void (*CloseDownProc) (ExtensionEntry * e), + unsigned short (*MinorOpcodeProc) (ClientPtr c3)) { int i; ExtensionEntry *ext, **newexts; if (!MainProc || !SwappedMainProc || !MinorOpcodeProc) - return((ExtensionEntry *) NULL); - if ((lastEvent + NumEvents > MAXEVENTS) || - (unsigned)(lastError + NumErrors > LAST_ERROR)) { + return ((ExtensionEntry *) NULL); + if ((lastEvent + NumEvents > MAXEVENTS) || + (unsigned) (lastError + NumErrors > LAST_ERROR)) { LogMessage(X_ERROR, "Not enabling extension %s: maximum number of " "events or errors exceeded.\n", name); - return((ExtensionEntry *) NULL); + return ((ExtensionEntry *) NULL); } - ext = calloc(sizeof (ExtensionEntry), 1); + ext = calloc(sizeof(ExtensionEntry), 1); if (!ext) - return NULL; + return NULL; if (!dixAllocatePrivates(&ext->devPrivates, PRIVATE_EXTENSION)) { - free(ext); - return NULL; + free(ext); + return NULL; } ext->name = strdup(name); ext->num_aliases = 0; - ext->aliases = (char **)NULL; - if (!ext->name) - { - dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION); - free(ext); - return((ExtensionEntry *) NULL); + ext->aliases = (char **) NULL; + if (!ext->name) { + dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION); + free(ext); + return ((ExtensionEntry *) NULL); } i = NumExtensions; newexts = (ExtensionEntry **) realloc(extensions, - (i + 1) * sizeof(ExtensionEntry *)); - if (!newexts) - { - free(ext->name); - dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION); - free(ext); - return((ExtensionEntry *) NULL); + (i + 1) * sizeof(ExtensionEntry *)); + if (!newexts) { + free(ext->name); + dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION); + free(ext); + return ((ExtensionEntry *) NULL); } NumExtensions++; extensions = newexts; @@ -123,25 +120,21 @@ AddExtension(const char *name, int NumEvents, int NumErrors, ext->MinorOpcode = MinorOpcodeProc; ProcVector[i + EXTENSION_BASE] = MainProc; SwappedProcVector[i + EXTENSION_BASE] = SwappedMainProc; - if (NumEvents) - { + if (NumEvents) { ext->eventBase = lastEvent; - ext->eventLast = lastEvent + NumEvents; - lastEvent += NumEvents; + ext->eventLast = lastEvent + NumEvents; + lastEvent += NumEvents; } - else - { + else { ext->eventBase = 0; ext->eventLast = 0; } - if (NumErrors) - { + if (NumErrors) { ext->errorBase = lastError; - ext->errorLast = lastError + NumErrors; - lastError += NumErrors; + ext->errorLast = lastError + NumErrors; + lastError += NumErrors; } - else - { + else { ext->errorBase = 0; ext->errorLast = 0; } @@ -150,21 +143,22 @@ AddExtension(const char *name, int NumEvents, int NumErrors, return ext; } -Bool AddExtensionAlias(const char *alias, ExtensionEntry *ext) +Bool +AddExtensionAlias(const char *alias, ExtensionEntry * ext) { char *name; char **aliases; if (!ext) - return FALSE ; - aliases = (char **)realloc(ext->aliases, - (ext->num_aliases + 1) * sizeof(char *)); + return FALSE; + aliases = (char **) realloc(ext->aliases, + (ext->num_aliases + 1) * sizeof(char *)); if (!aliases) - return FALSE; + return FALSE; ext->aliases = aliases; name = strdup(alias); if (!name) - return FALSE; + return FALSE; ext->aliases[ext->num_aliases] = name; ext->num_aliases++; return TRUE; @@ -175,18 +169,17 @@ FindExtension(const char *extname, int len) { int i, j; - for (i=0; i<NumExtensions; i++) - { - if ((strlen(extensions[i]->name) == len) && - !strncmp(extname, extensions[i]->name, len)) - break; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - if ((strlen(extensions[i]->aliases[j]) == len) && - !strncmp(extname, extensions[i]->aliases[j], len)) - break; - } - if (j >= 0) break; + for (i = 0; i < NumExtensions; i++) { + if ((strlen(extensions[i]->name) == len) && + !strncmp(extname, extensions[i]->name, len)) + break; + for (j = extensions[i]->num_aliases; --j >= 0;) { + if ((strlen(extensions[i]->aliases[j]) == len) && + !strncmp(extname, extensions[i]->aliases[j], len)) + break; + } + if (j >= 0) + break; } return ((i == NumExtensions) ? -1 : i); } @@ -202,9 +195,9 @@ CheckExtension(const char *extname) n = FindExtension(extname, strlen(extname)); if (n != -1) - return extensions[n]; + return extensions[n]; else - return NULL; + return NULL; } /* @@ -212,40 +205,39 @@ CheckExtension(const char *extname) */ ExtensionEntry * GetExtensionEntry(int major) -{ +{ if (major < EXTENSION_BASE) - return NULL; + return NULL; major -= EXTENSION_BASE; if (major >= NumExtensions) - return NULL; + return NULL; return extensions[major]; } unsigned short StandardMinorOpcode(ClientPtr client) { - return ((xReq *)client->requestBuffer)->data; + return ((xReq *) client->requestBuffer)->data; } void CloseDownExtensions(void) { - int i,j; - - for (i = NumExtensions - 1; i >= 0; i--) - { - if (extensions[i]->CloseDown) - extensions[i]->CloseDown(extensions[i]); - NumExtensions = i; - free(extensions[i]->name); - for (j = extensions[i]->num_aliases; --j >= 0;) - free(extensions[i]->aliases[j]); - free(extensions[i]->aliases); - dixFreePrivates(extensions[i]->devPrivates, PRIVATE_EXTENSION); - free(extensions[i]); + int i, j; + + for (i = NumExtensions - 1; i >= 0; i--) { + if (extensions[i]->CloseDown) + extensions[i]->CloseDown(extensions[i]); + NumExtensions = i; + free(extensions[i]->name); + for (j = extensions[i]->num_aliases; --j >= 0;) + free(extensions[i]->aliases[j]); + free(extensions[i]->aliases); + dixFreePrivates(extensions[i]->devPrivates, PRIVATE_EXTENSION); + free(extensions[i]); } free(extensions); - extensions = (ExtensionEntry **)NULL; + extensions = (ExtensionEntry **) NULL; lastEvent = EXTENSION_EVENT_BASE; lastError = FirstExtensionError; } @@ -255,6 +247,7 @@ ProcQueryExtension(ClientPtr client) { xQueryExtensionReply reply; int i; + REQUEST(xQueryExtensionReq); REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes); @@ -265,20 +258,18 @@ ProcQueryExtension(ClientPtr client) reply.major_opcode = 0; reply.sequenceNumber = client->sequence; - if ( ! NumExtensions ) + if (!NumExtensions) reply.present = xFalse; - else - { - i = FindExtension((char *)&stuff[1], stuff->nbytes); + else { + i = FindExtension((char *) &stuff[1], stuff->nbytes); if (i < 0 || XaceHook(XACE_EXT_ACCESS, client, extensions[i])) reply.present = xFalse; - else - { + else { reply.present = xTrue; - reply.major_opcode = extensions[i]->base; - reply.first_event = extensions[i]->eventBase; - reply.first_error = extensions[i]->errorBase; - } + reply.major_opcode = extensions[i]->base; + reply.first_event = extensions[i]->eventBase; + reply.first_error = extensions[i]->errorBase; + } } WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply); return Success; @@ -300,41 +291,38 @@ ProcListExtensions(ClientPtr client) reply.sequenceNumber = client->sequence; buffer = NULL; - if ( NumExtensions ) - { + if (NumExtensions) { int i, j; - for (i=0; i<NumExtensions; i++) - { - /* call callbacks to find out whether to show extension */ - if (XaceHook(XACE_EXT_ACCESS, client, extensions[i]) != Success) - continue; - - total_length += strlen(extensions[i]->name) + 1; - reply.nExtensions += 1 + extensions[i]->num_aliases; - for (j = extensions[i]->num_aliases; --j >= 0;) - total_length += strlen(extensions[i]->aliases[j]) + 1; - } + for (i = 0; i < NumExtensions; i++) { + /* call callbacks to find out whether to show extension */ + if (XaceHook(XACE_EXT_ACCESS, client, extensions[i]) != Success) + continue; + + total_length += strlen(extensions[i]->name) + 1; + reply.nExtensions += 1 + extensions[i]->num_aliases; + for (j = extensions[i]->num_aliases; --j >= 0;) + total_length += strlen(extensions[i]->aliases[j]) + 1; + } reply.length = bytes_to_int32(total_length); - buffer = bufptr = malloc(total_length); - if (!buffer) - return BadAlloc; - for (i=0; i<NumExtensions; i++) - { - int len; - if (XaceHook(XACE_EXT_ACCESS, client, extensions[i]) != Success) - continue; + buffer = bufptr = malloc(total_length); + if (!buffer) + return BadAlloc; + for (i = 0; i < NumExtensions; i++) { + int len; + + if (XaceHook(XACE_EXT_ACCESS, client, extensions[i]) != Success) + continue; *bufptr++ = len = strlen(extensions[i]->name); - memmove(bufptr, extensions[i]->name, len); - bufptr += len; - for (j = extensions[i]->num_aliases; --j >= 0;) - { - *bufptr++ = len = strlen(extensions[i]->aliases[j]); - memmove(bufptr, extensions[i]->aliases[j], len); - bufptr += len; - } - } + memmove(bufptr, extensions[i]->name, len); + bufptr += len; + for (j = extensions[i]->num_aliases; --j >= 0;) { + *bufptr++ = len = strlen(extensions[i]->aliases[j]); + memmove(bufptr, extensions[i]->aliases[j], len); + bufptr += len; + } + } } WriteReplyToClient(client, sizeof(xListExtensionsReply), &reply); if (reply.length) diff --git a/xorg-server/dix/gc.c b/xorg-server/dix/gc.c index e7bcc66f1..7be050221 100644 --- a/xorg-server/dix/gc.c +++ b/xorg-server/dix/gc.c @@ -1,1149 +1,1111 @@ -/***********************************************************
-
-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
-
-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.
-
-******************************************************************/
-
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>
-#include <X11/Xmd.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "resource.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-#include "dixfontstr.h"
-#include "scrnintstr.h"
-#include "region.h"
-#include "dixstruct.h"
-
-#include "privates.h"
-#include "dix.h"
-#include "xace.h"
-#include <assert.h>
-
-extern FontPtr defaultFont;
-
-static Bool CreateDefaultTile(GCPtr pGC);
-
-static unsigned char DefaultDash[2] = {4, 4};
-
-void
-ValidateGC(DrawablePtr pDraw, GC *pGC)
-{
- (*pGC->funcs->ValidateGC) (pGC, pGC->stateChanges, pDraw);
- pGC->stateChanges = 0;
- pGC->serialNumber = pDraw->serialNumber;
-}
-
-
-/*
- * ChangeGC/ChangeGCXIDs:
- *
- * The client performing the gc change must be passed so that access
- * checks can be performed on any tiles, stipples, or fonts that are
- * specified. ddxen can call this too; they should normally pass
- * NullClient for the client since any access checking should have
- * already been done at a higher level.
- *
- * If you have any XIDs, you must use ChangeGCXIDs:
- *
- * CARD32 v[2];
- * v[0] = FillTiled;
- * v[1] = pid;
- * ChangeGCXIDs(client, pGC, GCFillStyle|GCTile, v);
- *
- * However, if you need to pass a pointer to a pixmap or font, you must
- * use ChangeGC:
- *
- * ChangeGCVal v[2];
- * v[0].val = FillTiled;
- * v[1].ptr = pPixmap;
- * ChangeGC(client, pGC, GCFillStyle|GCTile, v);
- *
- * If you have neither XIDs nor pointers, you can use either function,
- * but ChangeGC will do less work.
- *
- * ChangeGCVal v[2];
- * v[0].val = foreground;
- * v[1].val = background;
- * ChangeGC(client, pGC, GCForeground|GCBackground, v);
- */
-
-#define NEXTVAL(_type, _var) { \
- _var = (_type)(pUnion->val); pUnion++; \
- }
-
-#define NEXT_PTR(_type, _var) { \
- _var = (_type)pUnion->ptr; pUnion++; }
-
-int
-ChangeGC(ClientPtr client, GC *pGC, BITS32 mask, ChangeGCValPtr pUnion)
-{
- BITS32 index2;
- int error = 0;
- PixmapPtr pPixmap;
- BITS32 maskQ;
-
- assert(pUnion);
- pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;
-
- maskQ = mask; /* save these for when we walk the GCque */
- while (mask && !error)
- {
- index2 = (BITS32) lowbit (mask);
- mask &= ~index2;
- pGC->stateChanges |= index2;
- switch (index2)
- {
- case GCFunction:
- {
- CARD8 newalu;
- NEXTVAL(CARD8, newalu);
- if (newalu <= GXset)
- pGC->alu = newalu;
- else
- {
- if (client)
- client->errorValue = newalu;
- error = BadValue;
- }
- break;
- }
- case GCPlaneMask:
- NEXTVAL(unsigned long, pGC->planemask);
- break;
- case GCForeground:
- NEXTVAL(unsigned long, pGC->fgPixel);
- /*
- * this is for CreateGC
- */
- if (!pGC->tileIsPixel && !pGC->tile.pixmap)
- {
- pGC->tileIsPixel = TRUE;
- pGC->tile.pixel = pGC->fgPixel;
- }
- break;
- case GCBackground:
- NEXTVAL(unsigned long, pGC->bgPixel);
- break;
- case GCLineWidth: /* ??? line width is a CARD16 */
- NEXTVAL(CARD16, pGC->lineWidth);
- break;
- case GCLineStyle:
- {
- unsigned int newlinestyle;
- NEXTVAL(unsigned int, newlinestyle);
- if (newlinestyle <= LineDoubleDash)
- pGC->lineStyle = newlinestyle;
- else
- {
- if (client)
- client->errorValue = newlinestyle;
- error = BadValue;
- }
- break;
- }
- case GCCapStyle:
- {
- unsigned int newcapstyle;
- NEXTVAL(unsigned int, newcapstyle);
- if (newcapstyle <= CapProjecting)
- pGC->capStyle = newcapstyle;
- else
- {
- if (client)
- client->errorValue = newcapstyle;
- error = BadValue;
- }
- break;
- }
- case GCJoinStyle:
- {
- unsigned int newjoinstyle;
- NEXTVAL(unsigned int, newjoinstyle);
- if (newjoinstyle <= JoinBevel)
- pGC->joinStyle = newjoinstyle;
- else
- {
- if (client)
- client->errorValue = newjoinstyle;
- error = BadValue;
- }
- break;
- }
- case GCFillStyle:
- {
- unsigned int newfillstyle;
- NEXTVAL(unsigned int, newfillstyle);
- if (newfillstyle <= FillOpaqueStippled)
- pGC->fillStyle = newfillstyle;
- else
- {
- if (client)
- client->errorValue = newfillstyle;
- error = BadValue;
- }
- break;
- }
- case GCFillRule:
- {
- unsigned int newfillrule;
- NEXTVAL(unsigned int, newfillrule);
- if (newfillrule <= WindingRule)
- pGC->fillRule = newfillrule;
- else
- {
- if (client)
- client->errorValue = newfillrule;
- error = BadValue;
- }
- break;
- }
- case GCTile:
- NEXT_PTR(PixmapPtr, pPixmap);
- if ((pPixmap->drawable.depth != pGC->depth) ||
- (pPixmap->drawable.pScreen != pGC->pScreen))
- {
- error = BadMatch;
- }
- else
- {
- pPixmap->refcnt++;
- if (!pGC->tileIsPixel)
- (* pGC->pScreen->DestroyPixmap)(pGC->tile.pixmap);
- pGC->tileIsPixel = FALSE;
- pGC->tile.pixmap = pPixmap;
- }
- break;
- case GCStipple:
- NEXT_PTR(PixmapPtr, pPixmap);
- if ((pPixmap->drawable.depth != 1) ||
- (pPixmap->drawable.pScreen != pGC->pScreen))
- {
- error = BadMatch;
- }
- else
- {
- pPixmap->refcnt++;
- if (pGC->stipple)
- (* pGC->pScreen->DestroyPixmap)(pGC->stipple);
- pGC->stipple = pPixmap;
- }
- break;
- case GCTileStipXOrigin:
- NEXTVAL(INT16, pGC->patOrg.x);
- break;
- case GCTileStipYOrigin:
- NEXTVAL(INT16, pGC->patOrg.y);
- break;
- case GCFont:
- {
- FontPtr pFont;
- NEXT_PTR(FontPtr, pFont);
- pFont->refcnt++;
- if (pGC->font)
- CloseFont(pGC->font, (Font)0);
- pGC->font = pFont;
- break;
- }
- case GCSubwindowMode:
- {
- unsigned int newclipmode;
- NEXTVAL(unsigned int, newclipmode);
- if (newclipmode <= IncludeInferiors)
- pGC->subWindowMode = newclipmode;
- else
- {
- if (client)
- client->errorValue = newclipmode;
- error = BadValue;
- }
- break;
- }
- case GCGraphicsExposures:
- {
- unsigned int newge;
- NEXTVAL(unsigned int, newge);
- if (newge <= xTrue)
- pGC->graphicsExposures = newge;
- else
- {
- if (client)
- client->errorValue = newge;
- error = BadValue;
- }
- break;
- }
- case GCClipXOrigin:
- NEXTVAL(INT16, pGC->clipOrg.x);
- break;
- case GCClipYOrigin:
- NEXTVAL(INT16, pGC->clipOrg.y);
- break;
- case GCClipMask:
- NEXT_PTR(PixmapPtr, pPixmap);
- if (pPixmap)
- {
- if ((pPixmap->drawable.depth != 1) ||
- (pPixmap->drawable.pScreen != pGC->pScreen))
- {
- error = BadMatch;
- break;
- }
- pPixmap->refcnt++;
- }
- (*pGC->funcs->ChangeClip)(pGC, pPixmap ? CT_PIXMAP : CT_NONE,
- (pointer)pPixmap, 0);
- break;
- case GCDashOffset:
- NEXTVAL(INT16, pGC->dashOffset);
- break;
- case GCDashList:
- {
- CARD8 newdash;
- NEXTVAL(CARD8, newdash);
- if (newdash == 4)
- {
- if (pGC->dash != DefaultDash)
- {
- free(pGC->dash);
- pGC->numInDashList = 2;
- pGC->dash = DefaultDash;
- }
- }
- else if (newdash != 0)
- {
- unsigned char *dash;
-
- dash = malloc(2 * sizeof(unsigned char));
- if (dash)
- {
- if (pGC->dash != DefaultDash)
- free(pGC->dash);
- pGC->numInDashList = 2;
- pGC->dash = dash;
- dash[0] = newdash;
- dash[1] = newdash;
- }
- else
- error = BadAlloc;
- }
- else
- {
- if (client)
- client->errorValue = newdash;
- error = BadValue;
- }
- break;
- }
- case GCArcMode:
- {
- unsigned int newarcmode;
- NEXTVAL(unsigned int, newarcmode);
- if (newarcmode <= ArcPieSlice)
- pGC->arcMode = newarcmode;
- else
- {
- if (client)
- client->errorValue = newarcmode;
- error = BadValue;
- }
- break;
- }
- default:
- if (client)
- client->errorValue = maskQ;
- error = BadValue;
- break;
- }
- } /* end while mask && !error */
-
- if (pGC->fillStyle == FillTiled && pGC->tileIsPixel)
- {
- if (!CreateDefaultTile (pGC))
- {
- pGC->fillStyle = FillSolid;
- error = BadAlloc;
- }
- }
- (*pGC->funcs->ChangeGC)(pGC, maskQ);
- return error;
-}
-
-#undef NEXTVAL
-#undef NEXT_PTR
-
-static const struct {
- BITS32 mask;
- RESTYPE type;
- Mask access_mode;
-} xidfields[] = {
- { GCTile, RT_PIXMAP, DixReadAccess },
- { GCStipple, RT_PIXMAP, DixReadAccess },
- { GCFont, RT_FONT, DixUseAccess },
- { GCClipMask, RT_PIXMAP, DixReadAccess },
-};
-
-int
-ChangeGCXIDs(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32)
-{
- ChangeGCVal vals[GCLastBit + 1];
- int i;
- if (mask & ~GCAllBits)
- {
- client->errorValue = mask;
- return BadValue;
- }
- for (i = Ones(mask); i--; )
- vals[i].val = pC32[i];
- for (i = 0; i < sizeof(xidfields) / sizeof(*xidfields); ++i)
- {
- int offset, rc;
- if (!(mask & xidfields[i].mask))
- continue;
- offset = Ones(mask & (xidfields[i].mask - 1));
- if (xidfields[i].mask == GCClipMask && vals[offset].val == None)
- {
- vals[offset].ptr = NullPixmap;
- continue;
- }
- rc = dixLookupResourceByType(&vals[offset].ptr, vals[offset].val,
- xidfields[i].type, client, xidfields[i].access_mode);
- if (rc != Success)
- {
- client->errorValue = vals[offset].val;
- return rc;
- }
- }
- return ChangeGC(client, pGC, mask, vals);
-}
-
-/* CreateGC(pDrawable, mask, pval, pStatus)
- creates a default GC for the given drawable, using mask to fill
- in any non-default values.
- Returns a pointer to the new GC on success, NULL otherwise.
- returns status of non-default fields in pStatus
-BUG:
- should check for failure to create default tile
-
-*/
-GCPtr
-CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
- XID gcid, ClientPtr client)
-{
- GCPtr pGC;
-
- pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
- if (!pGC)
- {
- *pStatus = BadAlloc;
- return (GCPtr)NULL;
- }
-
- pGC->pScreen = pDrawable->pScreen;
- pGC->depth = pDrawable->depth;
- pGC->alu = GXcopy; /* dst <- src */
- pGC->planemask = ~0;
- pGC->serialNumber = GC_CHANGE_SERIAL_BIT;
- pGC->funcs = 0;
- pGC->fgPixel = 0;
- pGC->bgPixel = 1;
- pGC->lineWidth = 0;
- pGC->lineStyle = LineSolid;
- pGC->capStyle = CapButt;
- pGC->joinStyle = JoinMiter;
- pGC->fillStyle = FillSolid;
- pGC->fillRule = EvenOddRule;
- pGC->arcMode = ArcPieSlice;
- pGC->tile.pixel = 0;
- pGC->tile.pixmap = NullPixmap;
- if (mask & GCForeground)
- {
- /*
- * magic special case -- ChangeGC checks for this condition
- * and snags the Foreground value to create a pseudo default-tile
- */
- pGC->tileIsPixel = FALSE;
- }
- else
- {
- pGC->tileIsPixel = TRUE;
- }
-
- pGC->patOrg.x = 0;
- pGC->patOrg.y = 0;
- pGC->subWindowMode = ClipByChildren;
- pGC->graphicsExposures = TRUE;
- pGC->clipOrg.x = 0;
- pGC->clipOrg.y = 0;
- pGC->clientClipType = CT_NONE;
- pGC->clientClip = (pointer)NULL;
- pGC->numInDashList = 2;
- pGC->dash = DefaultDash;
- pGC->dashOffset = 0;
-
- /* use the default font and stipple */
- pGC->font = defaultFont;
- defaultFont->refcnt++;
- pGC->stipple = pGC->pScreen->PixmapPerDepth[0];
- pGC->stipple->refcnt++;
-
- /* this is not a scratch GC */
- pGC->scratch_inuse = FALSE;
-
- /* security creation/labeling check */
- *pStatus = XaceHook(XACE_RESOURCE_ACCESS, client, gcid, RT_GC, pGC,
- RT_NONE, NULL, DixCreateAccess|DixSetAttrAccess);
- if (*pStatus != Success)
- goto out;
-
- pGC->stateChanges = GCAllBits;
- if (!(*pGC->pScreen->CreateGC)(pGC))
- *pStatus = BadAlloc;
- else if (mask)
- *pStatus = ChangeGCXIDs(client, pGC, mask, pval);
- else
- *pStatus = Success;
-
-out:
- if (*pStatus != Success)
- {
- if (!pGC->tileIsPixel && !pGC->tile.pixmap)
- pGC->tileIsPixel = TRUE; /* undo special case */
- FreeGC(pGC, (XID)0);
- pGC = (GCPtr)NULL;
- }
-
- return pGC;
-}
-
-static Bool
-CreateDefaultTile (GCPtr pGC)
-{
- ChangeGCVal tmpval[3];
- PixmapPtr pTile;
- GCPtr pgcScratch;
- xRectangle rect;
- CARD16 w, h;
-
- w = 1;
- h = 1;
- (*pGC->pScreen->QueryBestSize)(TileShape, &w, &h, pGC->pScreen);
- pTile = (PixmapPtr)
- (*pGC->pScreen->CreatePixmap)(pGC->pScreen,
- w, h, pGC->depth, 0);
- pgcScratch = GetScratchGC(pGC->depth, pGC->pScreen);
- if (!pTile || !pgcScratch)
- {
- if (pTile)
- (*pTile->drawable.pScreen->DestroyPixmap)(pTile);
- if (pgcScratch)
- FreeScratchGC(pgcScratch);
- return FALSE;
- }
- tmpval[0].val = GXcopy;
- tmpval[1].val = pGC->tile.pixel;
- tmpval[2].val = FillSolid;
- (void)ChangeGC(NullClient, pgcScratch, GCFunction | GCForeground | GCFillStyle, tmpval);
- ValidateGC((DrawablePtr)pTile, pgcScratch);
- rect.x = 0;
- rect.y = 0;
- rect.width = w;
- rect.height = h;
- (*pgcScratch->ops->PolyFillRect)((DrawablePtr)pTile, pgcScratch, 1, &rect);
- /* Always remember to free the scratch graphics context after use. */
- FreeScratchGC(pgcScratch);
-
- pGC->tileIsPixel = FALSE;
- pGC->tile.pixmap = pTile;
- return TRUE;
-}
-
-int
-CopyGC(GC *pgcSrc, GC *pgcDst, BITS32 mask)
-{
- BITS32 index2;
- BITS32 maskQ;
- int error = 0;
-
- if (pgcSrc == pgcDst)
- return Success;
- pgcDst->serialNumber |= GC_CHANGE_SERIAL_BIT;
- pgcDst->stateChanges |= mask;
- maskQ = mask;
- while (mask)
- {
- index2 = (BITS32) lowbit (mask);
- mask &= ~index2;
- switch (index2)
- {
- case GCFunction:
- pgcDst->alu = pgcSrc->alu;
- break;
- case GCPlaneMask:
- pgcDst->planemask = pgcSrc->planemask;
- break;
- case GCForeground:
- pgcDst->fgPixel = pgcSrc->fgPixel;
- break;
- case GCBackground:
- pgcDst->bgPixel = pgcSrc->bgPixel;
- break;
- case GCLineWidth:
- pgcDst->lineWidth = pgcSrc->lineWidth;
- break;
- case GCLineStyle:
- pgcDst->lineStyle = pgcSrc->lineStyle;
- break;
- case GCCapStyle:
- pgcDst->capStyle = pgcSrc->capStyle;
- break;
- case GCJoinStyle:
- pgcDst->joinStyle = pgcSrc->joinStyle;
- break;
- case GCFillStyle:
- pgcDst->fillStyle = pgcSrc->fillStyle;
- break;
- case GCFillRule:
- pgcDst->fillRule = pgcSrc->fillRule;
- break;
- case GCTile:
- {
- if (EqualPixUnion(pgcDst->tileIsPixel,
- pgcDst->tile,
- pgcSrc->tileIsPixel,
- pgcSrc->tile))
- {
- break;
- }
- if (!pgcDst->tileIsPixel)
- (* pgcDst->pScreen->DestroyPixmap)(pgcDst->tile.pixmap);
- pgcDst->tileIsPixel = pgcSrc->tileIsPixel;
- pgcDst->tile = pgcSrc->tile;
- if (!pgcDst->tileIsPixel)
- pgcDst->tile.pixmap->refcnt++;
- break;
- }
- case GCStipple:
- {
- if (pgcDst->stipple == pgcSrc->stipple)
- break;
- if (pgcDst->stipple)
- (* pgcDst->pScreen->DestroyPixmap)(pgcDst->stipple);
- pgcDst->stipple = pgcSrc->stipple;
- if (pgcDst->stipple)
- pgcDst->stipple->refcnt ++;
- break;
- }
- case GCTileStipXOrigin:
- pgcDst->patOrg.x = pgcSrc->patOrg.x;
- break;
- case GCTileStipYOrigin:
- pgcDst->patOrg.y = pgcSrc->patOrg.y;
- break;
- case GCFont:
- if (pgcDst->font == pgcSrc->font)
- break;
- if (pgcDst->font)
- CloseFont(pgcDst->font, (Font)0);
- if ((pgcDst->font = pgcSrc->font) != NullFont)
- (pgcDst->font)->refcnt++;
- break;
- case GCSubwindowMode:
- pgcDst->subWindowMode = pgcSrc->subWindowMode;
- break;
- case GCGraphicsExposures:
- pgcDst->graphicsExposures = pgcSrc->graphicsExposures;
- break;
- case GCClipXOrigin:
- pgcDst->clipOrg.x = pgcSrc->clipOrg.x;
- break;
- case GCClipYOrigin:
- pgcDst->clipOrg.y = pgcSrc->clipOrg.y;
- break;
- case GCClipMask:
- (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
- break;
- case GCDashOffset:
- pgcDst->dashOffset = pgcSrc->dashOffset;
- break;
- case GCDashList:
- if (pgcSrc->dash == DefaultDash)
- {
- if (pgcDst->dash != DefaultDash)
- {
- free(pgcDst->dash);
- pgcDst->numInDashList = pgcSrc->numInDashList;
- pgcDst->dash = pgcSrc->dash;
- }
- }
- else
- {
- unsigned char *dash;
- unsigned int i;
-
- dash = malloc(pgcSrc->numInDashList * sizeof(unsigned char));
- if (dash)
- {
- if (pgcDst->dash != DefaultDash)
- free(pgcDst->dash);
- pgcDst->numInDashList = pgcSrc->numInDashList;
- pgcDst->dash = dash;
- for (i=0; i<pgcSrc->numInDashList; i++)
- dash[i] = pgcSrc->dash[i];
- }
- else
- error = BadAlloc;
- }
- break;
- case GCArcMode:
- pgcDst->arcMode = pgcSrc->arcMode;
- break;
- default:
- FatalError ("CopyGC: Unhandled mask!\n");
- }
- }
- if (pgcDst->fillStyle == FillTiled && pgcDst->tileIsPixel)
- {
- if (!CreateDefaultTile (pgcDst))
- {
- pgcDst->fillStyle = FillSolid;
- error = BadAlloc;
- }
- }
- (*pgcDst->funcs->CopyGC) (pgcSrc, maskQ, pgcDst);
- return error;
-}
-
-/**
- * does the diX part of freeing the characteristics in the GC.
- *
- * \param value must conform to DeleteType
- */
-int
-FreeGC(pointer value, XID gid)
-{
- GCPtr pGC = (GCPtr)value;
-
- CloseFont(pGC->font, (Font)0);
- (* pGC->funcs->DestroyClip)(pGC);
-
- if (!pGC->tileIsPixel)
- (* pGC->pScreen->DestroyPixmap)(pGC->tile.pixmap);
- if (pGC->stipple)
- (* pGC->pScreen->DestroyPixmap)(pGC->stipple);
-
- (*pGC->funcs->DestroyGC) (pGC);
- if (pGC->dash != DefaultDash)
- free(pGC->dash);
- dixFreeObjectWithPrivates(pGC, PRIVATE_GC);
- return Success;
-}
-
-/* CreateScratchGC(pScreen, depth)
- like CreateGC, but doesn't do the default tile or stipple,
-since we can't create them without already having a GC. any code
-using the tile or stipple has to set them explicitly anyway,
-since the state of the scratch gc is unknown. This is OK
-because ChangeGC() has to be able to deal with NULL tiles and
-stipples anyway (in case the CreateGC() call has provided a
-value for them -- we can't set the default tile until the
-client-supplied attributes are installed, since the fgPixel
-is what fills the default tile. (maybe this comment should
-go with CreateGC() or ChangeGC().)
-*/
-
-static GCPtr
-CreateScratchGC(ScreenPtr pScreen, unsigned depth)
-{
- GCPtr pGC;
-
- pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
- if (!pGC)
- return (GCPtr)NULL;
-
- pGC->pScreen = pScreen;
- pGC->depth = depth;
- pGC->alu = GXcopy; /* dst <- src */
- pGC->planemask = ~0;
- pGC->serialNumber = 0;
- pGC->fgPixel = 0;
- pGC->bgPixel = 1;
- pGC->lineWidth = 0;
- pGC->lineStyle = LineSolid;
- pGC->capStyle = CapButt;
- pGC->joinStyle = JoinMiter;
- pGC->fillStyle = FillSolid;
- pGC->fillRule = EvenOddRule;
- pGC->arcMode = ArcPieSlice;
- pGC->font = defaultFont;
- if ( pGC->font) /* necessary, because open of default font could fail */
- pGC->font->refcnt++;
- pGC->tileIsPixel = TRUE;
- pGC->tile.pixel = 0;
- pGC->tile.pixmap = NullPixmap;
- pGC->stipple = NullPixmap;
- pGC->patOrg.x = 0;
- pGC->patOrg.y = 0;
- pGC->subWindowMode = ClipByChildren;
- pGC->graphicsExposures = TRUE;
- pGC->clipOrg.x = 0;
- pGC->clipOrg.y = 0;
- pGC->clientClipType = CT_NONE;
- pGC->dashOffset = 0;
- pGC->numInDashList = 2;
- pGC->dash = DefaultDash;
-
- /* scratch GCs in the GCperDepth pool start off unused */
- pGC->scratch_inuse = FALSE;
-
- pGC->stateChanges = GCAllBits;
- if (!(*pScreen->CreateGC)(pGC))
- {
- FreeGC(pGC, (XID)0);
- pGC = (GCPtr)NULL;
- }
- return pGC;
-}
-
-void
-FreeGCperDepth(int screenNum)
-{
- int i;
- ScreenPtr pScreen;
- GCPtr *ppGC;
-
- pScreen = screenInfo.screens[screenNum];
- ppGC = pScreen->GCperDepth;
-
- for (i = 0; i <= pScreen->numDepths; i++)
- {
- (void)FreeGC(ppGC[i], (XID)0);
- ppGC[i] = NULL;
- }
-}
-
-
-Bool
-CreateGCperDepth(int screenNum)
-{
- int i;
- ScreenPtr pScreen;
- DepthPtr pDepth;
- GCPtr *ppGC;
-
- pScreen = screenInfo.screens[screenNum];
- ppGC = pScreen->GCperDepth;
- /* do depth 1 separately because it's not included in list */
- if (!(ppGC[0] = CreateScratchGC(pScreen, 1)))
- return FALSE;
- ppGC[0]->graphicsExposures = FALSE;
- /* Make sure we don't overflow GCperDepth[] */
- if( pScreen->numDepths > MAXFORMATS )
- return FALSE;
-
- pDepth = pScreen->allowedDepths;
- for (i=0; i<pScreen->numDepths; i++, pDepth++)
- {
- if (!(ppGC[i+1] = CreateScratchGC(pScreen, pDepth->depth)))
- {
- for (; i >= 0; i--)
- (void)FreeGC(ppGC[i], (XID)0);
- return FALSE;
- }
- ppGC[i+1]->graphicsExposures = FALSE;
- }
- return TRUE;
-}
-
-Bool
-CreateDefaultStipple(int screenNum)
-{
- ScreenPtr pScreen;
- ChangeGCVal tmpval[3];
- xRectangle rect;
- CARD16 w, h;
- GCPtr pgcScratch;
-
- pScreen = screenInfo.screens[screenNum];
-
- w = 16;
- h = 16;
- (* pScreen->QueryBestSize)(StippleShape, &w, &h, pScreen);
- if (!(pScreen->PixmapPerDepth[0] =
- (*pScreen->CreatePixmap)(pScreen, w, h, 1, 0)))
- return FALSE;
- /* fill stipple with 1 */
- tmpval[0].val = GXcopy;
- tmpval[1].val = 1;
- tmpval[2].val = FillSolid;
- pgcScratch = GetScratchGC(1, pScreen);
- if (!pgcScratch)
- {
- (*pScreen->DestroyPixmap)(pScreen->PixmapPerDepth[0]);
- return FALSE;
- }
- (void)ChangeGC(NullClient, pgcScratch, GCFunction|GCForeground|GCFillStyle, tmpval);
- ValidateGC((DrawablePtr)pScreen->PixmapPerDepth[0], pgcScratch);
- rect.x = 0;
- rect.y = 0;
- rect.width = w;
- rect.height = h;
- (*pgcScratch->ops->PolyFillRect)((DrawablePtr)pScreen->PixmapPerDepth[0],
- pgcScratch, 1, &rect);
- FreeScratchGC(pgcScratch);
- return TRUE;
-}
-
-void
-FreeDefaultStipple(int screenNum)
-{
- ScreenPtr pScreen = screenInfo.screens[screenNum];
- (*pScreen->DestroyPixmap)(pScreen->PixmapPerDepth[0]);
-}
-
-int
-SetDashes(GCPtr pGC, unsigned offset, unsigned ndash, unsigned char *pdash)
-{
- long i;
- unsigned char *p, *indash;
- BITS32 maskQ = 0;
-
- i = ndash;
- p = pdash;
- while (i--)
- {
- if (!*p++)
- {
- /* dash segment must be > 0 */
- return BadValue;
- }
- }
-
- if (ndash & 1)
- p = malloc(2 * ndash * sizeof(unsigned char));
- else
- p = malloc(ndash * sizeof(unsigned char));
- if (!p)
- return BadAlloc;
-
- pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;
- if (offset != pGC->dashOffset)
- {
- pGC->dashOffset = offset;
- pGC->stateChanges |= GCDashOffset;
- maskQ |= GCDashOffset;
- }
-
- if (pGC->dash != DefaultDash)
- free(pGC->dash);
- pGC->numInDashList = ndash;
- pGC->dash = p;
- if (ndash & 1)
- {
- pGC->numInDashList += ndash;
- indash = pdash;
- i = ndash;
- while (i--)
- *p++ = *indash++;
- }
- while(ndash--)
- *p++ = *pdash++;
- pGC->stateChanges |= GCDashList;
- maskQ |= GCDashList;
-
- if (pGC->funcs->ChangeGC)
- (*pGC->funcs->ChangeGC) (pGC, maskQ);
- return Success;
-}
-
-int
-VerifyRectOrder(int nrects, xRectangle *prects, int ordering)
-{
- xRectangle *prectP, *prectN;
- int i;
-
- switch(ordering)
- {
- case Unsorted:
- return CT_UNSORTED;
- case YSorted:
- if(nrects > 1)
- {
- for(i = 1, prectP = prects, prectN = prects + 1;
- i < nrects;
- i++, prectP++, prectN++)
- if(prectN->y < prectP->y)
- return -1;
- }
- return CT_YSORTED;
- case YXSorted:
- if(nrects > 1)
- {
- for(i = 1, prectP = prects, prectN = prects + 1;
- i < nrects;
- i++, prectP++, prectN++)
- if((prectN->y < prectP->y) ||
- ( (prectN->y == prectP->y) &&
- (prectN->x < prectP->x) ) )
- return -1;
- }
- return CT_YXSORTED;
- case YXBanded:
- if(nrects > 1)
- {
- for(i = 1, prectP = prects, prectN = prects + 1;
- i < nrects;
- i++, prectP++, prectN++)
- if((prectN->y != prectP->y &&
- prectN->y < prectP->y + (int) prectP->height) ||
- ((prectN->y == prectP->y) &&
- (prectN->height != prectP->height ||
- prectN->x < prectP->x + (int) prectP->width)))
- return -1;
- }
- return CT_YXBANDED;
- }
- return -1;
-}
-
-int
-SetClipRects(GCPtr pGC, int xOrigin, int yOrigin, int nrects,
- xRectangle *prects, int ordering)
-{
- int newct, size;
- xRectangle *prectsNew;
-
- newct = VerifyRectOrder(nrects, prects, ordering);
- if (newct < 0)
- return BadMatch;
- size = nrects * sizeof(xRectangle);
- prectsNew = malloc(size);
- if (!prectsNew && size)
- return BadAlloc;
-
- pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;
- pGC->clipOrg.x = xOrigin;
- pGC->stateChanges |= GCClipXOrigin;
-
- pGC->clipOrg.y = yOrigin;
- pGC->stateChanges |= GCClipYOrigin;
-
- if (size)
- memmove((char *)prectsNew, (char *)prects, size);
- (*pGC->funcs->ChangeClip)(pGC, newct, (pointer)prectsNew, nrects);
- if (pGC->funcs->ChangeGC)
- (*pGC->funcs->ChangeGC) (pGC, GCClipXOrigin|GCClipYOrigin|GCClipMask);
- return Success;
-}
-
-
-/*
- sets reasonable defaults
- if we can get a pre-allocated one, use it and mark it as used.
- if we can't, create one out of whole cloth (The Velveteen GC -- if
- you use it often enough it will become real.)
-*/
-GCPtr
-GetScratchGC(unsigned depth, ScreenPtr pScreen)
-{
- int i;
- GCPtr pGC;
-
- for (i=0; i<=pScreen->numDepths; i++)
- {
- pGC = pScreen->GCperDepth[i];
- if (pGC && pGC->depth == depth && !pGC->scratch_inuse)
- {
- pGC->scratch_inuse = TRUE;
-
- pGC->alu = GXcopy;
- pGC->planemask = ~0;
- pGC->serialNumber = 0;
- pGC->fgPixel = 0;
- pGC->bgPixel = 1;
- pGC->lineWidth = 0;
- pGC->lineStyle = LineSolid;
- pGC->capStyle = CapButt;
- pGC->joinStyle = JoinMiter;
- pGC->fillStyle = FillSolid;
- pGC->fillRule = EvenOddRule;
- pGC->arcMode = ArcChord;
- pGC->patOrg.x = 0;
- pGC->patOrg.y = 0;
- pGC->subWindowMode = ClipByChildren;
- pGC->graphicsExposures = FALSE;
- pGC->clipOrg.x = 0;
- pGC->clipOrg.y = 0;
- if (pGC->clientClipType != CT_NONE)
- (*pGC->funcs->ChangeClip) (pGC, CT_NONE, NULL, 0);
- pGC->stateChanges = GCAllBits;
- return pGC;
- }
- }
- /* if we make it this far, need to roll our own */
- pGC = CreateScratchGC(pScreen, depth);
- if (pGC)
- pGC->graphicsExposures = FALSE;
- return pGC;
-}
-
-/*
- if the gc to free is in the table of pre-existing ones,
-mark it as available.
- if not, free it for real
-*/
-void
-FreeScratchGC(GCPtr pGC)
-{
- if (pGC->scratch_inuse)
- pGC->scratch_inuse = FALSE;
- else
- FreeGC(pGC, (GContext)0);
-}
+/*********************************************************** + +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 + +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. + +******************************************************************/ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <X11/X.h> +#include <X11/Xmd.h> +#include <X11/Xproto.h> +#include "misc.h" +#include "resource.h" +#include "gcstruct.h" +#include "pixmapstr.h" +#include "dixfontstr.h" +#include "scrnintstr.h" +#include "region.h" +#include "dixstruct.h" + +#include "privates.h" +#include "dix.h" +#include "xace.h" +#include <assert.h> + +extern FontPtr defaultFont; + +static Bool CreateDefaultTile(GCPtr pGC); + +static unsigned char DefaultDash[2] = { 4, 4 }; + +void +ValidateGC(DrawablePtr pDraw, GC * pGC) +{ + (*pGC->funcs->ValidateGC) (pGC, pGC->stateChanges, pDraw); + pGC->stateChanges = 0; + pGC->serialNumber = pDraw->serialNumber; +} + +/* + * ChangeGC/ChangeGCXIDs: + * + * The client performing the gc change must be passed so that access + * checks can be performed on any tiles, stipples, or fonts that are + * specified. ddxen can call this too; they should normally pass + * NullClient for the client since any access checking should have + * already been done at a higher level. + * + * If you have any XIDs, you must use ChangeGCXIDs: + * + * CARD32 v[2]; + * v[0] = FillTiled; + * v[1] = pid; + * ChangeGCXIDs(client, pGC, GCFillStyle|GCTile, v); + * + * However, if you need to pass a pointer to a pixmap or font, you must + * use ChangeGC: + * + * ChangeGCVal v[2]; + * v[0].val = FillTiled; + * v[1].ptr = pPixmap; + * ChangeGC(client, pGC, GCFillStyle|GCTile, v); + * + * If you have neither XIDs nor pointers, you can use either function, + * but ChangeGC will do less work. + * + * ChangeGCVal v[2]; + * v[0].val = foreground; + * v[1].val = background; + * ChangeGC(client, pGC, GCForeground|GCBackground, v); + */ + +#define NEXTVAL(_type, _var) { \ + _var = (_type)(pUnion->val); pUnion++; \ + } + +#define NEXT_PTR(_type, _var) { \ + _var = (_type)pUnion->ptr; pUnion++; } + +int +ChangeGC(ClientPtr client, GC * pGC, BITS32 mask, ChangeGCValPtr pUnion) +{ + BITS32 index2; + int error = 0; + PixmapPtr pPixmap; + BITS32 maskQ; + + assert(pUnion); + pGC->serialNumber |= GC_CHANGE_SERIAL_BIT; + + maskQ = mask; /* save these for when we walk the GCque */ + while (mask && !error) { + index2 = (BITS32) lowbit(mask); + mask &= ~index2; + pGC->stateChanges |= index2; + switch (index2) { + case GCFunction: + { + CARD8 newalu; + NEXTVAL(CARD8, newalu); + + if (newalu <= GXset) + pGC->alu = newalu; + else { + if (client) + client->errorValue = newalu; + error = BadValue; + } + break; + } + case GCPlaneMask: + NEXTVAL(unsigned long, pGC->planemask); + + break; + case GCForeground: + NEXTVAL(unsigned long, pGC->fgPixel); + + /* + * this is for CreateGC + */ + if (!pGC->tileIsPixel && !pGC->tile.pixmap) { + pGC->tileIsPixel = TRUE; + pGC->tile.pixel = pGC->fgPixel; + } + break; + case GCBackground: + NEXTVAL(unsigned long, pGC->bgPixel); + + break; + case GCLineWidth: /* ??? line width is a CARD16 */ + NEXTVAL(CARD16, pGC->lineWidth); + + break; + case GCLineStyle: + { + unsigned int newlinestyle; + NEXTVAL(unsigned int, newlinestyle); + + if (newlinestyle <= LineDoubleDash) + pGC->lineStyle = newlinestyle; + else { + if (client) + client->errorValue = newlinestyle; + error = BadValue; + } + break; + } + case GCCapStyle: + { + unsigned int newcapstyle; + NEXTVAL(unsigned int, newcapstyle); + + if (newcapstyle <= CapProjecting) + pGC->capStyle = newcapstyle; + else { + if (client) + client->errorValue = newcapstyle; + error = BadValue; + } + break; + } + case GCJoinStyle: + { + unsigned int newjoinstyle; + NEXTVAL(unsigned int, newjoinstyle); + + if (newjoinstyle <= JoinBevel) + pGC->joinStyle = newjoinstyle; + else { + if (client) + client->errorValue = newjoinstyle; + error = BadValue; + } + break; + } + case GCFillStyle: + { + unsigned int newfillstyle; + NEXTVAL(unsigned int, newfillstyle); + + if (newfillstyle <= FillOpaqueStippled) + pGC->fillStyle = newfillstyle; + else { + if (client) + client->errorValue = newfillstyle; + error = BadValue; + } + break; + } + case GCFillRule: + { + unsigned int newfillrule; + NEXTVAL(unsigned int, newfillrule); + + if (newfillrule <= WindingRule) + pGC->fillRule = newfillrule; + else { + if (client) + client->errorValue = newfillrule; + error = BadValue; + } + break; + } + case GCTile: + NEXT_PTR(PixmapPtr, pPixmap); + + if ((pPixmap->drawable.depth != pGC->depth) || + (pPixmap->drawable.pScreen != pGC->pScreen)) { + error = BadMatch; + } + else { + pPixmap->refcnt++; + if (!pGC->tileIsPixel) + (*pGC->pScreen->DestroyPixmap) (pGC->tile.pixmap); + pGC->tileIsPixel = FALSE; + pGC->tile.pixmap = pPixmap; + } + break; + case GCStipple: + NEXT_PTR(PixmapPtr, pPixmap); + + if ((pPixmap->drawable.depth != 1) || + (pPixmap->drawable.pScreen != pGC->pScreen)) { + error = BadMatch; + } + else { + pPixmap->refcnt++; + if (pGC->stipple) + (*pGC->pScreen->DestroyPixmap) (pGC->stipple); + pGC->stipple = pPixmap; + } + break; + case GCTileStipXOrigin: + NEXTVAL(INT16, pGC->patOrg.x); + + break; + case GCTileStipYOrigin: + NEXTVAL(INT16, pGC->patOrg.y); + + break; + case GCFont: + { + FontPtr pFont; + NEXT_PTR(FontPtr, pFont); + + pFont->refcnt++; + if (pGC->font) + CloseFont(pGC->font, (Font) 0); + pGC->font = pFont; + break; + } + case GCSubwindowMode: + { + unsigned int newclipmode; + NEXTVAL(unsigned int, newclipmode); + + if (newclipmode <= IncludeInferiors) + pGC->subWindowMode = newclipmode; + else { + if (client) + client->errorValue = newclipmode; + error = BadValue; + } + break; + } + case GCGraphicsExposures: + { + unsigned int newge; + NEXTVAL(unsigned int, newge); + + if (newge <= xTrue) + pGC->graphicsExposures = newge; + else { + if (client) + client->errorValue = newge; + error = BadValue; + } + break; + } + case GCClipXOrigin: + NEXTVAL(INT16, pGC->clipOrg.x); + + break; + case GCClipYOrigin: + NEXTVAL(INT16, pGC->clipOrg.y); + + break; + case GCClipMask: + NEXT_PTR(PixmapPtr, pPixmap); + + if (pPixmap) { + if ((pPixmap->drawable.depth != 1) || + (pPixmap->drawable.pScreen != pGC->pScreen)) { + error = BadMatch; + break; + } + pPixmap->refcnt++; + } + (*pGC->funcs->ChangeClip) (pGC, pPixmap ? CT_PIXMAP : CT_NONE, + (pointer) pPixmap, 0); + break; + case GCDashOffset: + NEXTVAL(INT16, pGC->dashOffset); + + break; + case GCDashList: + { + CARD8 newdash; + NEXTVAL(CARD8, newdash); + + if (newdash == 4) { + if (pGC->dash != DefaultDash) { + free(pGC->dash); + pGC->numInDashList = 2; + pGC->dash = DefaultDash; + } + } + else if (newdash != 0) { + unsigned char *dash; + + dash = malloc(2 * sizeof(unsigned char)); + if (dash) { + if (pGC->dash != DefaultDash) + free(pGC->dash); + pGC->numInDashList = 2; + pGC->dash = dash; + dash[0] = newdash; + dash[1] = newdash; + } + else + error = BadAlloc; + } + else { + if (client) + client->errorValue = newdash; + error = BadValue; + } + break; + } + case GCArcMode: + { + unsigned int newarcmode; + NEXTVAL(unsigned int, newarcmode); + + if (newarcmode <= ArcPieSlice) + pGC->arcMode = newarcmode; + else { + if (client) + client->errorValue = newarcmode; + error = BadValue; + } + break; + } + default: + if (client) + client->errorValue = maskQ; + error = BadValue; + break; + } + } /* end while mask && !error */ + + if (pGC->fillStyle == FillTiled && pGC->tileIsPixel) { + if (!CreateDefaultTile(pGC)) { + pGC->fillStyle = FillSolid; + error = BadAlloc; + } + } + (*pGC->funcs->ChangeGC) (pGC, maskQ); + return error; +} + +#undef NEXTVAL +#undef NEXT_PTR + +static const struct { + BITS32 mask; + RESTYPE type; + Mask access_mode; +} xidfields[] = { + { + GCTile, RT_PIXMAP, DixReadAccess}, { + GCStipple, RT_PIXMAP, DixReadAccess}, { + GCFont, RT_FONT, DixUseAccess}, { +GCClipMask, RT_PIXMAP, DixReadAccess},}; + +int +ChangeGCXIDs(ClientPtr client, GC * pGC, BITS32 mask, CARD32 *pC32) +{ + ChangeGCVal vals[GCLastBit + 1]; + int i; + + if (mask & ~GCAllBits) { + client->errorValue = mask; + return BadValue; + } + for (i = Ones(mask); i--;) + vals[i].val = pC32[i]; + for (i = 0; i < sizeof(xidfields) / sizeof(*xidfields); ++i) { + int offset, rc; + + if (!(mask & xidfields[i].mask)) + continue; + offset = Ones(mask & (xidfields[i].mask - 1)); + if (xidfields[i].mask == GCClipMask && vals[offset].val == None) { + vals[offset].ptr = NullPixmap; + continue; + } + rc = dixLookupResourceByType(&vals[offset].ptr, vals[offset].val, + xidfields[i].type, client, + xidfields[i].access_mode); + if (rc != Success) { + client->errorValue = vals[offset].val; + return rc; + } + } + return ChangeGC(client, pGC, mask, vals); +} + +/* CreateGC(pDrawable, mask, pval, pStatus) + creates a default GC for the given drawable, using mask to fill + in any non-default values. + Returns a pointer to the new GC on success, NULL otherwise. + returns status of non-default fields in pStatus +BUG: + should check for failure to create default tile + +*/ +GCPtr +CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus, + XID gcid, ClientPtr client) +{ + GCPtr pGC; + + pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC); + if (!pGC) { + *pStatus = BadAlloc; + return (GCPtr) NULL; + } + + pGC->pScreen = pDrawable->pScreen; + pGC->depth = pDrawable->depth; + pGC->alu = GXcopy; /* dst <- src */ + pGC->planemask = ~0; + pGC->serialNumber = GC_CHANGE_SERIAL_BIT; + pGC->funcs = 0; + pGC->fgPixel = 0; + pGC->bgPixel = 1; + pGC->lineWidth = 0; + pGC->lineStyle = LineSolid; + pGC->capStyle = CapButt; + pGC->joinStyle = JoinMiter; + pGC->fillStyle = FillSolid; + pGC->fillRule = EvenOddRule; + pGC->arcMode = ArcPieSlice; + pGC->tile.pixel = 0; + pGC->tile.pixmap = NullPixmap; + if (mask & GCForeground) { + /* + * magic special case -- ChangeGC checks for this condition + * and snags the Foreground value to create a pseudo default-tile + */ + pGC->tileIsPixel = FALSE; + } + else { + pGC->tileIsPixel = TRUE; + } + + pGC->patOrg.x = 0; + pGC->patOrg.y = 0; + pGC->subWindowMode = ClipByChildren; + pGC->graphicsExposures = TRUE; + pGC->clipOrg.x = 0; + pGC->clipOrg.y = 0; + pGC->clientClipType = CT_NONE; + pGC->clientClip = (pointer) NULL; + pGC->numInDashList = 2; + pGC->dash = DefaultDash; + pGC->dashOffset = 0; + + /* use the default font and stipple */ + pGC->font = defaultFont; + defaultFont->refcnt++; + pGC->stipple = pGC->pScreen->PixmapPerDepth[0]; + pGC->stipple->refcnt++; + + /* this is not a scratch GC */ + pGC->scratch_inuse = FALSE; + + /* security creation/labeling check */ + *pStatus = XaceHook(XACE_RESOURCE_ACCESS, client, gcid, RT_GC, pGC, + RT_NONE, NULL, DixCreateAccess | DixSetAttrAccess); + if (*pStatus != Success) + goto out; + + pGC->stateChanges = GCAllBits; + if (!(*pGC->pScreen->CreateGC) (pGC)) + *pStatus = BadAlloc; + else if (mask) + *pStatus = ChangeGCXIDs(client, pGC, mask, pval); + else + *pStatus = Success; + + out: + if (*pStatus != Success) { + if (!pGC->tileIsPixel && !pGC->tile.pixmap) + pGC->tileIsPixel = TRUE; /* undo special case */ + FreeGC(pGC, (XID) 0); + pGC = (GCPtr) NULL; + } + + return pGC; +} + +static Bool +CreateDefaultTile(GCPtr pGC) +{ + ChangeGCVal tmpval[3]; + PixmapPtr pTile; + GCPtr pgcScratch; + xRectangle rect; + CARD16 w, h; + + w = 1; + h = 1; + (*pGC->pScreen->QueryBestSize) (TileShape, &w, &h, pGC->pScreen); + pTile = (PixmapPtr) + (*pGC->pScreen->CreatePixmap) (pGC->pScreen, w, h, pGC->depth, 0); + pgcScratch = GetScratchGC(pGC->depth, pGC->pScreen); + if (!pTile || !pgcScratch) { + if (pTile) + (*pTile->drawable.pScreen->DestroyPixmap) (pTile); + if (pgcScratch) + FreeScratchGC(pgcScratch); + return FALSE; + } + tmpval[0].val = GXcopy; + tmpval[1].val = pGC->tile.pixel; + tmpval[2].val = FillSolid; + (void) ChangeGC(NullClient, pgcScratch, + GCFunction | GCForeground | GCFillStyle, tmpval); + ValidateGC((DrawablePtr) pTile, pgcScratch); + rect.x = 0; + rect.y = 0; + rect.width = w; + rect.height = h; + (*pgcScratch->ops->PolyFillRect) ((DrawablePtr) pTile, pgcScratch, 1, + &rect); + /* Always remember to free the scratch graphics context after use. */ + FreeScratchGC(pgcScratch); + + pGC->tileIsPixel = FALSE; + pGC->tile.pixmap = pTile; + return TRUE; +} + +int +CopyGC(GC * pgcSrc, GC * pgcDst, BITS32 mask) +{ + BITS32 index2; + BITS32 maskQ; + int error = 0; + + if (pgcSrc == pgcDst) + return Success; + pgcDst->serialNumber |= GC_CHANGE_SERIAL_BIT; + pgcDst->stateChanges |= mask; + maskQ = mask; + while (mask) { + index2 = (BITS32) lowbit(mask); + mask &= ~index2; + switch (index2) { + case GCFunction: + pgcDst->alu = pgcSrc->alu; + break; + case GCPlaneMask: + pgcDst->planemask = pgcSrc->planemask; + break; + case GCForeground: + pgcDst->fgPixel = pgcSrc->fgPixel; + break; + case GCBackground: + pgcDst->bgPixel = pgcSrc->bgPixel; + break; + case GCLineWidth: + pgcDst->lineWidth = pgcSrc->lineWidth; + break; + case GCLineStyle: + pgcDst->lineStyle = pgcSrc->lineStyle; + break; + case GCCapStyle: + pgcDst->capStyle = pgcSrc->capStyle; + break; + case GCJoinStyle: + pgcDst->joinStyle = pgcSrc->joinStyle; + break; + case GCFillStyle: + pgcDst->fillStyle = pgcSrc->fillStyle; + break; + case GCFillRule: + pgcDst->fillRule = pgcSrc->fillRule; + break; + case GCTile: + { + if (EqualPixUnion(pgcDst->tileIsPixel, + pgcDst->tile, + pgcSrc->tileIsPixel, pgcSrc->tile)) { + break; + } + if (!pgcDst->tileIsPixel) + (*pgcDst->pScreen->DestroyPixmap) (pgcDst->tile.pixmap); + pgcDst->tileIsPixel = pgcSrc->tileIsPixel; + pgcDst->tile = pgcSrc->tile; + if (!pgcDst->tileIsPixel) + pgcDst->tile.pixmap->refcnt++; + break; + } + case GCStipple: + { + if (pgcDst->stipple == pgcSrc->stipple) + break; + if (pgcDst->stipple) + (*pgcDst->pScreen->DestroyPixmap) (pgcDst->stipple); + pgcDst->stipple = pgcSrc->stipple; + if (pgcDst->stipple) + pgcDst->stipple->refcnt++; + break; + } + case GCTileStipXOrigin: + pgcDst->patOrg.x = pgcSrc->patOrg.x; + break; + case GCTileStipYOrigin: + pgcDst->patOrg.y = pgcSrc->patOrg.y; + break; + case GCFont: + if (pgcDst->font == pgcSrc->font) + break; + if (pgcDst->font) + CloseFont(pgcDst->font, (Font) 0); + if ((pgcDst->font = pgcSrc->font) != NullFont) + (pgcDst->font)->refcnt++; + break; + case GCSubwindowMode: + pgcDst->subWindowMode = pgcSrc->subWindowMode; + break; + case GCGraphicsExposures: + pgcDst->graphicsExposures = pgcSrc->graphicsExposures; + break; + case GCClipXOrigin: + pgcDst->clipOrg.x = pgcSrc->clipOrg.x; + break; + case GCClipYOrigin: + pgcDst->clipOrg.y = pgcSrc->clipOrg.y; + break; + case GCClipMask: + (*pgcDst->funcs->CopyClip) (pgcDst, pgcSrc); + break; + case GCDashOffset: + pgcDst->dashOffset = pgcSrc->dashOffset; + break; + case GCDashList: + if (pgcSrc->dash == DefaultDash) { + if (pgcDst->dash != DefaultDash) { + free(pgcDst->dash); + pgcDst->numInDashList = pgcSrc->numInDashList; + pgcDst->dash = pgcSrc->dash; + } + } + else { + unsigned char *dash; + unsigned int i; + + dash = malloc(pgcSrc->numInDashList * sizeof(unsigned char)); + if (dash) { + if (pgcDst->dash != DefaultDash) + free(pgcDst->dash); + pgcDst->numInDashList = pgcSrc->numInDashList; + pgcDst->dash = dash; + for (i = 0; i < pgcSrc->numInDashList; i++) + dash[i] = pgcSrc->dash[i]; + } + else + error = BadAlloc; + } + break; + case GCArcMode: + pgcDst->arcMode = pgcSrc->arcMode; + break; + default: + FatalError("CopyGC: Unhandled mask!\n"); + } + } + if (pgcDst->fillStyle == FillTiled && pgcDst->tileIsPixel) { + if (!CreateDefaultTile(pgcDst)) { + pgcDst->fillStyle = FillSolid; + error = BadAlloc; + } + } + (*pgcDst->funcs->CopyGC) (pgcSrc, maskQ, pgcDst); + return error; +} + +/** + * does the diX part of freeing the characteristics in the GC. + * + * \param value must conform to DeleteType + */ +int +FreeGC(pointer value, XID gid) +{ + GCPtr pGC = (GCPtr) value; + + CloseFont(pGC->font, (Font) 0); + (*pGC->funcs->DestroyClip) (pGC); + + if (!pGC->tileIsPixel) + (*pGC->pScreen->DestroyPixmap) (pGC->tile.pixmap); + if (pGC->stipple) + (*pGC->pScreen->DestroyPixmap) (pGC->stipple); + + (*pGC->funcs->DestroyGC) (pGC); + if (pGC->dash != DefaultDash) + free(pGC->dash); + dixFreeObjectWithPrivates(pGC, PRIVATE_GC); + return Success; +} + +/* CreateScratchGC(pScreen, depth) + like CreateGC, but doesn't do the default tile or stipple, +since we can't create them without already having a GC. any code +using the tile or stipple has to set them explicitly anyway, +since the state of the scratch gc is unknown. This is OK +because ChangeGC() has to be able to deal with NULL tiles and +stipples anyway (in case the CreateGC() call has provided a +value for them -- we can't set the default tile until the +client-supplied attributes are installed, since the fgPixel +is what fills the default tile. (maybe this comment should +go with CreateGC() or ChangeGC().) +*/ + +static GCPtr +CreateScratchGC(ScreenPtr pScreen, unsigned depth) +{ + GCPtr pGC; + + pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC); + if (!pGC) + return (GCPtr) NULL; + + pGC->pScreen = pScreen; + pGC->depth = depth; + pGC->alu = GXcopy; /* dst <- src */ + pGC->planemask = ~0; + pGC->serialNumber = 0; + pGC->fgPixel = 0; + pGC->bgPixel = 1; + pGC->lineWidth = 0; + pGC->lineStyle = LineSolid; + pGC->capStyle = CapButt; + pGC->joinStyle = JoinMiter; + pGC->fillStyle = FillSolid; + pGC->fillRule = EvenOddRule; + pGC->arcMode = ArcPieSlice; + pGC->font = defaultFont; + if (pGC->font) /* necessary, because open of default font could fail */ + pGC->font->refcnt++; + pGC->tileIsPixel = TRUE; + pGC->tile.pixel = 0; + pGC->tile.pixmap = NullPixmap; + pGC->stipple = NullPixmap; + pGC->patOrg.x = 0; + pGC->patOrg.y = 0; + pGC->subWindowMode = ClipByChildren; + pGC->graphicsExposures = TRUE; + pGC->clipOrg.x = 0; + pGC->clipOrg.y = 0; + pGC->clientClipType = CT_NONE; + pGC->dashOffset = 0; + pGC->numInDashList = 2; + pGC->dash = DefaultDash; + + /* scratch GCs in the GCperDepth pool start off unused */ + pGC->scratch_inuse = FALSE; + + pGC->stateChanges = GCAllBits; + if (!(*pScreen->CreateGC) (pGC)) { + FreeGC(pGC, (XID) 0); + pGC = (GCPtr) NULL; + } + return pGC; +} + +void +FreeGCperDepth(int screenNum) +{ + int i; + ScreenPtr pScreen; + GCPtr *ppGC; + + pScreen = screenInfo.screens[screenNum]; + ppGC = pScreen->GCperDepth; + + for (i = 0; i <= pScreen->numDepths; i++) { + (void) FreeGC(ppGC[i], (XID) 0); + ppGC[i] = NULL; + } +} + +Bool +CreateGCperDepth(int screenNum) +{ + int i; + ScreenPtr pScreen; + DepthPtr pDepth; + GCPtr *ppGC; + + pScreen = screenInfo.screens[screenNum]; + ppGC = pScreen->GCperDepth; + /* do depth 1 separately because it's not included in list */ + if (!(ppGC[0] = CreateScratchGC(pScreen, 1))) + return FALSE; + ppGC[0]->graphicsExposures = FALSE; + /* Make sure we don't overflow GCperDepth[] */ + if (pScreen->numDepths > MAXFORMATS) + return FALSE; + + pDepth = pScreen->allowedDepths; + for (i = 0; i < pScreen->numDepths; i++, pDepth++) { + if (!(ppGC[i + 1] = CreateScratchGC(pScreen, pDepth->depth))) { + for (; i >= 0; i--) + (void) FreeGC(ppGC[i], (XID) 0); + return FALSE; + } + ppGC[i + 1]->graphicsExposures = FALSE; + } + return TRUE; +} + +Bool +CreateDefaultStipple(int screenNum) +{ + ScreenPtr pScreen; + ChangeGCVal tmpval[3]; + xRectangle rect; + CARD16 w, h; + GCPtr pgcScratch; + + pScreen = screenInfo.screens[screenNum]; + + w = 16; + h = 16; + (*pScreen->QueryBestSize) (StippleShape, &w, &h, pScreen); + if (!(pScreen->PixmapPerDepth[0] = + (*pScreen->CreatePixmap) (pScreen, w, h, 1, 0))) + return FALSE; + /* fill stipple with 1 */ + tmpval[0].val = GXcopy; + tmpval[1].val = 1; + tmpval[2].val = FillSolid; + pgcScratch = GetScratchGC(1, pScreen); + if (!pgcScratch) { + (*pScreen->DestroyPixmap) (pScreen->PixmapPerDepth[0]); + return FALSE; + } + (void) ChangeGC(NullClient, pgcScratch, + GCFunction | GCForeground | GCFillStyle, tmpval); + ValidateGC((DrawablePtr) pScreen->PixmapPerDepth[0], pgcScratch); + rect.x = 0; + rect.y = 0; + rect.width = w; + rect.height = h; + (*pgcScratch->ops->PolyFillRect) ((DrawablePtr) pScreen->PixmapPerDepth[0], + pgcScratch, 1, &rect); + FreeScratchGC(pgcScratch); + return TRUE; +} + +void +FreeDefaultStipple(int screenNum) +{ + ScreenPtr pScreen = screenInfo.screens[screenNum]; + + (*pScreen->DestroyPixmap) (pScreen->PixmapPerDepth[0]); +} + +int +SetDashes(GCPtr pGC, unsigned offset, unsigned ndash, unsigned char *pdash) +{ + long i; + unsigned char *p, *indash; + BITS32 maskQ = 0; + + i = ndash; + p = pdash; + while (i--) { + if (!*p++) { + /* dash segment must be > 0 */ + return BadValue; + } + } + + if (ndash & 1) + p = malloc(2 * ndash * sizeof(unsigned char)); + else + p = malloc(ndash * sizeof(unsigned char)); + if (!p) + return BadAlloc; + + pGC->serialNumber |= GC_CHANGE_SERIAL_BIT; + if (offset != pGC->dashOffset) { + pGC->dashOffset = offset; + pGC->stateChanges |= GCDashOffset; + maskQ |= GCDashOffset; + } + + if (pGC->dash != DefaultDash) + free(pGC->dash); + pGC->numInDashList = ndash; + pGC->dash = p; + if (ndash & 1) { + pGC->numInDashList += ndash; + indash = pdash; + i = ndash; + while (i--) + *p++ = *indash++; + } + while (ndash--) + *p++ = *pdash++; + pGC->stateChanges |= GCDashList; + maskQ |= GCDashList; + + if (pGC->funcs->ChangeGC) + (*pGC->funcs->ChangeGC) (pGC, maskQ); + return Success; +} + +int +VerifyRectOrder(int nrects, xRectangle *prects, int ordering) +{ + xRectangle *prectP, *prectN; + int i; + + switch (ordering) { + case Unsorted: + return CT_UNSORTED; + case YSorted: + if (nrects > 1) { + for (i = 1, prectP = prects, prectN = prects + 1; + i < nrects; i++, prectP++, prectN++) + if (prectN->y < prectP->y) + return -1; + } + return CT_YSORTED; + case YXSorted: + if (nrects > 1) { + for (i = 1, prectP = prects, prectN = prects + 1; + i < nrects; i++, prectP++, prectN++) + if ((prectN->y < prectP->y) || + ((prectN->y == prectP->y) && (prectN->x < prectP->x))) + return -1; + } + return CT_YXSORTED; + case YXBanded: + if (nrects > 1) { + for (i = 1, prectP = prects, prectN = prects + 1; + i < nrects; i++, prectP++, prectN++) + if ((prectN->y != prectP->y && + prectN->y < prectP->y + (int) prectP->height) || + ((prectN->y == prectP->y) && + (prectN->height != prectP->height || + prectN->x < prectP->x + (int) prectP->width))) + return -1; + } + return CT_YXBANDED; + } + return -1; +} + +int +SetClipRects(GCPtr pGC, int xOrigin, int yOrigin, int nrects, + xRectangle *prects, int ordering) +{ + int newct, size; + xRectangle *prectsNew; + + newct = VerifyRectOrder(nrects, prects, ordering); + if (newct < 0) + return BadMatch; + size = nrects * sizeof(xRectangle); + prectsNew = malloc(size); + if (!prectsNew && size) + return BadAlloc; + + pGC->serialNumber |= GC_CHANGE_SERIAL_BIT; + pGC->clipOrg.x = xOrigin; + pGC->stateChanges |= GCClipXOrigin; + + pGC->clipOrg.y = yOrigin; + pGC->stateChanges |= GCClipYOrigin; + + if (size) + memmove((char *) prectsNew, (char *) prects, size); + (*pGC->funcs->ChangeClip) (pGC, newct, (pointer) prectsNew, nrects); + if (pGC->funcs->ChangeGC) + (*pGC->funcs->ChangeGC) (pGC, + GCClipXOrigin | GCClipYOrigin | GCClipMask); + return Success; +} + +/* + sets reasonable defaults + if we can get a pre-allocated one, use it and mark it as used. + if we can't, create one out of whole cloth (The Velveteen GC -- if + you use it often enough it will become real.) +*/ +GCPtr +GetScratchGC(unsigned depth, ScreenPtr pScreen) +{ + int i; + GCPtr pGC; + + for (i = 0; i <= pScreen->numDepths; i++) { + pGC = pScreen->GCperDepth[i]; + if (pGC && pGC->depth == depth && !pGC->scratch_inuse) { + pGC->scratch_inuse = TRUE; + + pGC->alu = GXcopy; + pGC->planemask = ~0; + pGC->serialNumber = 0; + pGC->fgPixel = 0; + pGC->bgPixel = 1; + pGC->lineWidth = 0; + pGC->lineStyle = LineSolid; + pGC->capStyle = CapButt; + pGC->joinStyle = JoinMiter; + pGC->fillStyle = FillSolid; + pGC->fillRule = EvenOddRule; + pGC->arcMode = ArcChord; + pGC->patOrg.x = 0; + pGC->patOrg.y = 0; + pGC->subWindowMode = ClipByChildren; + pGC->graphicsExposures = FALSE; + pGC->clipOrg.x = 0; + pGC->clipOrg.y = 0; + if (pGC->clientClipType != CT_NONE) + (*pGC->funcs->ChangeClip) (pGC, CT_NONE, NULL, 0); + pGC->stateChanges = GCAllBits; + return pGC; + } + } + /* if we make it this far, need to roll our own */ + pGC = CreateScratchGC(pScreen, depth); + if (pGC) + pGC->graphicsExposures = FALSE; + return pGC; +} + +/* + if the gc to free is in the table of pre-existing ones, +mark it as available. + if not, free it for real +*/ +void +FreeScratchGC(GCPtr pGC) +{ + if (pGC->scratch_inuse) + pGC->scratch_inuse = FALSE; + else + FreeGC(pGC, (GContext) 0); +} diff --git a/xorg-server/dix/getevents.c b/xorg-server/dix/getevents.c index 306d0ff09..3093786c3 100644 --- a/xorg-server/dix/getevents.c +++ b/xorg-server/dix/getevents.c @@ -66,7 +66,13 @@ #include "exglobals.h" #include "exevents.h" #include "extnsionst.h" -#include "listdev.h" /* for sizing up DeviceClassesChangedEvent */ +#include "listdev.h" /* for sizing up DeviceClassesChangedEvent */ + +#if XSERVER_DTRACE +#include <sys/types.h> +typedef const char *string; +#include <Xserver-dtrace.h> +#endif /* Number of motion history events to store. */ #define MOTION_HISTORY_SIZE 256 @@ -76,7 +82,7 @@ * QueuePointerEvents, QueueKeyboardEvents, and QueueProximityEvents. * This list is allocated on startup by the DIX. */ -InternalEvent* InputEventList = NULL; +InternalEvent *InputEventList = NULL; /** * Pick some arbitrary size for Xi motion history. @@ -152,12 +158,12 @@ key_is_down(DeviceIntPtr pDev, int key_code, int type) static Bool key_autorepeats(DeviceIntPtr pDev, int key_code) { - return !!(pDev->kbdfeed->ctrl.autoRepeats[key_code >> 3] & - (1 << (key_code & 7))); + return ! !(pDev->kbdfeed->ctrl.autoRepeats[key_code >> 3] & + (1 << (key_code & 7))); } static void -init_event(DeviceIntPtr dev, DeviceEvent* event, Time ms) +init_event(DeviceIntPtr dev, DeviceEvent *event, Time ms) { memset(event, 0, sizeof(DeviceEvent)); event->header = ET_Internal; @@ -184,15 +190,31 @@ init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail) memset(event, 0, sizeof(RawDeviceEvent)); event->header = ET_Internal; event->length = sizeof(RawDeviceEvent); - switch(type) { - case MotionNotify: event->type = ET_RawMotion; break; - case ButtonPress: event->type = ET_RawButtonPress; break; - case ButtonRelease: event->type = ET_RawButtonRelease; break; - case KeyPress: event->type = ET_RawKeyPress; break; - case KeyRelease: event->type = ET_RawKeyRelease; break; - case XI_TouchBegin: event->type = ET_RawTouchBegin; break; - case XI_TouchUpdate: event->type = ET_RawTouchUpdate; break; - case XI_TouchEnd: event->type = ET_RawTouchEnd; break; + switch (type) { + case MotionNotify: + event->type = ET_RawMotion; + break; + case ButtonPress: + event->type = ET_RawButtonPress; + break; + case ButtonRelease: + event->type = ET_RawButtonRelease; + break; + case KeyPress: + event->type = ET_RawKeyPress; + break; + case KeyRelease: + event->type = ET_RawKeyRelease; + break; + case XI_TouchBegin: + event->type = ET_RawTouchBegin; + break; + case XI_TouchUpdate: + event->type = ET_RawTouchUpdate; + break; + case XI_TouchEnd: + event->type = ET_RawTouchEnd; + break; } event->time = ms; event->deviceid = dev->id; @@ -201,32 +223,27 @@ init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail) } static void -set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, double* data) +set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, double *data) { int i; - for (i = 0; i < valuator_mask_size(mask); i++) - { - if (valuator_mask_isset(mask, i)) - { + for (i = 0; i < valuator_mask_size(mask); i++) { + if (valuator_mask_isset(mask, i)) { SetBit(event->valuators.mask, i); data[i] = valuator_mask_get_double(mask, i); } } } - static void -set_valuators(DeviceIntPtr dev, DeviceEvent* event, ValuatorMask *mask) +set_valuators(DeviceIntPtr dev, DeviceEvent *event, ValuatorMask *mask) { int i; /* Set the data to the previous value for unset absolute axes. The values * may be used when sent as part of an XI 1.x valuator event. */ - for (i = 0; i < valuator_mask_size(mask); i++) - { - if (valuator_mask_isset(mask, i)) - { + for (i = 0; i < valuator_mask_size(mask); i++) { + if (valuator_mask_isset(mask, i)) { SetBit(event->valuators.mask, i); if (valuator_get_mode(dev, i) == Absolute) SetBit(event->valuators.mode, i); @@ -238,10 +255,8 @@ set_valuators(DeviceIntPtr dev, DeviceEvent* event, ValuatorMask *mask) } void -CreateClassesChangedEvent(InternalEvent* event, - DeviceIntPtr master, - DeviceIntPtr slave, - int flags) +CreateClassesChangedEvent(InternalEvent *event, + DeviceIntPtr master, DeviceIntPtr slave, int flags) { int i; DeviceChangedEvent *dce; @@ -258,17 +273,14 @@ CreateClassesChangedEvent(InternalEvent* event, dce->flags = flags; dce->sourceid = slave->id; - if (slave->button) - { + if (slave->button) { dce->buttons.num_buttons = slave->button->numButtons; for (i = 0; i < dce->buttons.num_buttons; i++) dce->buttons.names[i] = slave->button->labels[i]; } - if (slave->valuator) - { + if (slave->valuator) { dce->num_valuators = slave->valuator->numAxes; - for (i = 0; i < dce->num_valuators; i++) - { + for (i = 0; i < dce->num_valuators; i++) { dce->valuators[i].min = slave->valuator->axes[i].min_value; dce->valuators[i].max = slave->valuator->axes[i].max_value; dce->valuators[i].resolution = slave->valuator->axes[i].resolution; @@ -277,8 +289,7 @@ CreateClassesChangedEvent(InternalEvent* event, dce->valuators[i].scroll = slave->valuator->axes[i].scroll; } } - if (slave->key) - { + if (slave->key) { dce->keys.min_keycode = slave->key->xkbInfo->desc->min_key_code; dce->keys.max_keycode = slave->key->xkbInfo->desc->max_key_code; } @@ -306,7 +317,7 @@ rescaleValuatorAxis(double coord, AxisInfoPtr from, AxisInfoPtr to, if (fmin == tmin && fmax == tmax) return coord; - if (fmax == fmin) /* avoid division by 0 */ + if (fmax == fmin) /* avoid division by 0 */ return 0.0; return (coord - fmin) * (tmax - tmin) / (fmax - fmin) + tmin; @@ -323,7 +334,6 @@ rescaleValuatorAxis(double coord, AxisInfoPtr from, AxisInfoPtr to, static void updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev) { - ScreenPtr scr = miPointerGetScreen(pDev); int i; DeviceIntPtr lastSlave; @@ -336,19 +346,19 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev) return; /* scale back to device coordinates */ - if(pDev->valuator->numAxes > 0) - { + if (pDev->valuator->numAxes > 0) { pDev->last.valuators[0] = rescaleValuatorAxis(pDev->last.valuators[0], NULL, pDev->valuator->axes + 0, - 0, scr->width); + screenInfo.x, + screenInfo.width); } - if(pDev->valuator->numAxes > 1) - { + if (pDev->valuator->numAxes > 1) { pDev->last.valuators[1] = rescaleValuatorAxis(pDev->last.valuators[1], NULL, pDev->valuator->axes + 1, - 0, scr->height); + screenInfo.y, + screenInfo.height); } /* calculate the other axis as well based on info from the old @@ -357,14 +367,13 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev) */ if ((lastSlave = master->last.slave) && lastSlave->valuator) { for (i = 2; i < pDev->valuator->numAxes; i++) { - if (i >= lastSlave->valuator->numAxes) - { + if (i >= lastSlave->valuator->numAxes) { pDev->last.valuators[i] = 0; valuator_mask_set_double(pDev->last.scroll, i, 0); } - else - { + else { double val = pDev->last.valuators[i]; + val = rescaleValuatorAxis(val, lastSlave->valuator->axes + i, pDev->valuator->axes + i, 0, 0); pDev->last.valuators[i] = val; @@ -382,6 +391,7 @@ void AllocateMotionHistory(DeviceIntPtr pDev) { int size; + free(pDev->valuator->motion); if (pDev->valuator->numMotionEvents < 1) @@ -396,6 +406,7 @@ AllocateMotionHistory(DeviceIntPtr pDev) else { ValuatorClassPtr v = pDev->valuator; int numAxes; + /* XI1 doesn't understand mixed mode devices */ for (numAxes = 0; numAxes < v->numAxes; numAxes++) if (valuator_get_mode(pDev, numAxes) != valuator_get_mode(pDev, 0)) @@ -410,7 +421,7 @@ AllocateMotionHistory(DeviceIntPtr pDev) pDev->valuator->last_motion = 0; if (!pDev->valuator->motion) ErrorF("[dix] %s: Failed to alloc motion history (%d bytes).\n", - pDev->name, size * pDev->valuator->numMotionEvents); + pDev->name, size * pDev->valuator->numMotionEvents); } /** @@ -421,19 +432,20 @@ AllocateMotionHistory(DeviceIntPtr pDev) * If core is set, we only generate x/y, in INT16, scaled to screen coords. */ int -GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, +GetMotionHistory(DeviceIntPtr pDev, xTimecoord ** buff, unsigned long start, unsigned long stop, ScreenPtr pScreen, BOOL core) { char *ibuff = NULL, *obuff; int i = 0, ret = 0; int j, coord; Time current; + /* The size of a single motion event. */ int size; - AxisInfo from, *to; /* for scaling */ - INT32 *ocbuf, *icbuf; /* pointer to coordinates for copying */ + AxisInfo from, *to; /* for scaling */ + INT32 *ocbuf, *icbuf; /* pointer to coordinates for copying */ INT16 *corebuf; - AxisInfo core_axis = {0}; + AxisInfo core_axis = { 0 }; if (!pDev->valuator || !pDev->valuator->numMotionEvents) return 0; @@ -449,7 +461,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, *buff = malloc(size * pDev->valuator->numMotionEvents); if (!(*buff)) return 0; - obuff = (char *)*buff; + obuff = (char *) *buff; for (i = pDev->valuator->first_motion; i != pDev->valuator->last_motion; @@ -464,12 +476,11 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, return ret; } else if (current >= start) { - if (core) - { - memcpy(obuff, ibuff, sizeof(Time)); /* copy timestamp */ + if (core) { + memcpy(obuff, ibuff, sizeof(Time)); /* copy timestamp */ - icbuf = (INT32*)(ibuff + sizeof(Time)); - corebuf = (INT16*)(obuff + sizeof(Time)); + icbuf = (INT32 *) (ibuff + sizeof(Time)); + corebuf = (INT16 *) (obuff + sizeof(Time)); /* fetch x coordinate + range */ memcpy(&from.min_value, icbuf++, sizeof(INT32)); @@ -479,7 +490,8 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, /* scale to screen coords */ to = &core_axis; to->max_value = pScreen->width; - coord = rescaleValuatorAxis(coord, &from, to, 0, pScreen->width); + coord = + rescaleValuatorAxis(coord, &from, to, 0, pScreen->width); memcpy(corebuf, &coord, sizeof(INT16)); corebuf++; @@ -490,17 +502,17 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, memcpy(&coord, icbuf++, sizeof(INT32)); to->max_value = pScreen->height; - coord = rescaleValuatorAxis(coord, &from, to, 0, pScreen->height); + coord = + rescaleValuatorAxis(coord, &from, to, 0, pScreen->height); memcpy(corebuf, &coord, sizeof(INT16)); - } else if (IsMaster(pDev)) - { - memcpy(obuff, ibuff, sizeof(Time)); /* copy timestamp */ + } + else if (IsMaster(pDev)) { + memcpy(obuff, ibuff, sizeof(Time)); /* copy timestamp */ - ocbuf = (INT32*)(obuff + sizeof(Time)); - icbuf = (INT32*)(ibuff + sizeof(Time)); - for (j = 0; j < MAX_VALUATORS; j++) - { + ocbuf = (INT32 *) (obuff + sizeof(Time)); + icbuf = (INT32 *) (ibuff + sizeof(Time)); + for (j = 0; j < MAX_VALUATORS; j++) { if (j >= pDev->valuator->numAxes) break; @@ -509,7 +521,9 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, memcpy(&from.max_value, icbuf++, sizeof(INT32)); memcpy(&coord, icbuf++, sizeof(INT32)); - to = (j < pDev->valuator->numAxes) ? &pDev->valuator->axes[j] : NULL; + to = (j < + pDev->valuator->numAxes) ? &pDev->valuator-> + axes[j] : NULL; /* x/y scaled to screen if no range is present */ if (j == 0 && (from.max_value < from.min_value)) @@ -522,7 +536,8 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, memcpy(ocbuf, &coord, sizeof(INT32)); ocbuf++; } - } else + } + else memcpy(obuff, ibuff, size); /* don't advance by size here. size may be different to the @@ -530,7 +545,8 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, if (core) obuff += sizeof(INT32) + sizeof(Time); else - obuff += (sizeof(INT32) * pDev->valuator->numAxes) + sizeof(Time); + obuff += + (sizeof(INT32) * pDev->valuator->numAxes) + sizeof(Time); ret++; } } @@ -538,7 +554,6 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, return ret; } - /** * Update the motion history for a specific device, with the list of * valuators. @@ -562,24 +577,22 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask, return; v = pDev->valuator; - if (IsMaster(pDev)) - { + if (IsMaster(pDev)) { buff += ((sizeof(INT32) * 3 * MAX_VALUATORS) + sizeof(CARD32)) * - v->last_motion; + v->last_motion; memcpy(buff, &ms, sizeof(Time)); buff += sizeof(Time); memset(buff, 0, sizeof(INT32) * 3 * MAX_VALUATORS); - for (i = 0; i < v->numAxes; i++) - { + for (i = 0; i < v->numAxes; i++) { int val; + /* XI1 doesn't support mixed mode devices */ if (valuator_get_mode(pDev, i) != valuator_get_mode(pDev, 0)) break; - if (valuator_mask_size(mask) <= i || !valuator_mask_isset(mask, i)) - { + if (valuator_mask_size(mask) <= i || !valuator_mask_isset(mask, i)) { buff += 3 * sizeof(INT32); continue; } @@ -591,8 +604,8 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask, memcpy(buff, &val, sizeof(INT32)); buff += sizeof(INT32); } - } else - { + } + else { buff += ((sizeof(INT32) * pDev->valuator->numAxes) + sizeof(CARD32)) * pDev->valuator->last_motion; @@ -602,11 +615,10 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask, memset(buff, 0, sizeof(INT32) * pDev->valuator->numAxes); - for (i = 0; i < MAX_VALUATORS; i++) - { + for (i = 0; i < MAX_VALUATORS; i++) { int val; - if (valuator_mask_size(mask) <= i || !valuator_mask_isset(mask, i)) - { + + if (valuator_mask_size(mask) <= i || !valuator_mask_isset(mask, i)) { buff += sizeof(INT32); continue; } @@ -621,12 +633,11 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask, /* If we're wrapping around, just keep the circular buffer going. */ if (pDev->valuator->first_motion == pDev->valuator->last_motion) pDev->valuator->first_motion = (pDev->valuator->first_motion + 1) % - pDev->valuator->numMotionEvents; + pDev->valuator->numMotionEvents; return; } - /** * Returns the maximum number of events GetKeyboardEvents * and GetPointerEvents will ever return. @@ -634,7 +645,8 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask, * This MUST be absolutely constant, from init until exit. */ int -GetMaximumEventsNum(void) { +GetMaximumEventsNum(void) +{ /* One raw event * One device event * One possible device changed event @@ -644,7 +656,6 @@ GetMaximumEventsNum(void) { return 100; } - /** * Clip an axis to its bounds, which are declared in the call to * InitValuatorAxisClassStruct. @@ -678,9 +689,9 @@ clipValuators(DeviceIntPtr pDev, ValuatorMask *mask) int i; for (i = 0; i < valuator_mask_size(mask); i++) - if (valuator_mask_isset(mask, i)) - { + if (valuator_mask_isset(mask, i)) { double val = valuator_mask_get_double(mask, i); + clipAxis(pDev, i, &val); valuator_mask_set_double(mask, i, val); } @@ -698,18 +709,21 @@ clipValuators(DeviceIntPtr pDev, ValuatorMask *mask) * events if a DCCE was generated. * @return The updated @events pointer. */ -InternalEvent* -UpdateFromMaster(InternalEvent* events, DeviceIntPtr dev, int type, int *num_events) +InternalEvent * +UpdateFromMaster(InternalEvent *events, DeviceIntPtr dev, int type, + int *num_events) { DeviceIntPtr master; - master = GetMaster(dev, (type & DEVCHANGE_POINTER_EVENT) ? MASTER_POINTER : MASTER_KEYBOARD); + master = + GetMaster(dev, + (type & DEVCHANGE_POINTER_EVENT) ? MASTER_POINTER : + MASTER_KEYBOARD); - if (master && master->last.slave != dev) - { - CreateClassesChangedEvent(events, master, dev, type | DEVCHANGE_SLAVE_SWITCH); - if (IsPointerDevice(master)) - { + if (master && master->last.slave != dev) { + CreateClassesChangedEvent(events, master, dev, + type | DEVCHANGE_SLAVE_SWITCH); + if (IsPointerDevice(master)) { updateSlaveDeviceCoords(master, dev); master->last.numValuators = dev->last.numValuators; } @@ -731,8 +745,7 @@ clipAbsolute(DeviceIntPtr dev, ValuatorMask *mask) { int i; - for (i = 0; i < valuator_mask_size(mask); i++) - { + for (i = 0; i < valuator_mask_size(mask); i++) { double val; if (!valuator_mask_isset(mask, i)) @@ -756,8 +769,7 @@ moveRelative(DeviceIntPtr dev, ValuatorMask *mask) Bool clip_xy = IsMaster(dev) || !IsFloating(dev); /* calc other axes, clip, drop back into valuators */ - for (i = 0; i < valuator_mask_size(mask); i++) - { + for (i = 0; i < valuator_mask_size(mask); i++) { double val = dev->last.valuators[i]; if (!valuator_mask_isset(mask, i)) @@ -780,7 +792,7 @@ moveRelative(DeviceIntPtr dev, ValuatorMask *mask) * @param ms Current time. */ static void -accelPointer(DeviceIntPtr dev, ValuatorMask* valuators, CARD32 ms) +accelPointer(DeviceIntPtr dev, ValuatorMask *valuators, CARD32 ms) { if (dev->valuator->accelScheme.AccelSchemeProc) dev->valuator->accelScheme.AccelSchemeProc(dev, valuators, ms); @@ -800,16 +812,14 @@ scale_from_screen(DeviceIntPtr dev, ValuatorMask *mask) double scaled; ScreenPtr scr = miPointerGetScreen(dev); - if (valuator_mask_isset(mask, 0)) - { + if (valuator_mask_isset(mask, 0)) { scaled = valuator_mask_get_double(mask, 0) + scr->x; scaled = rescaleValuatorAxis(scaled, NULL, dev->valuator->axes + 0, 0, scr->width); valuator_mask_set_double(mask, 0, scaled); } - if (valuator_mask_isset(mask, 1)) - { + if (valuator_mask_isset(mask, 1)) { scaled = valuator_mask_get_double(mask, 1) + scr->y; scaled = rescaleValuatorAxis(scaled, NULL, dev->valuator->axes + 1, @@ -818,7 +828,6 @@ scale_from_screen(DeviceIntPtr dev, ValuatorMask *mask) } } - /** * Scale from (absolute) device to screen coordinates here, * @@ -834,15 +843,13 @@ scale_from_screen(DeviceIntPtr dev, ValuatorMask *mask) */ static ScreenPtr scale_to_desktop(DeviceIntPtr dev, ValuatorMask *mask, - double *devx, double *devy, - double *screenx, double *screeny) + double *devx, double *devy, double *screenx, double *screeny) { ScreenPtr scr = miPointerGetScreen(dev); double x, y; BUG_WARN(!dev->valuator || dev->valuator->numAxes < 2); - if (!dev->valuator || dev->valuator->numAxes < 2) - { + if (!dev->valuator || dev->valuator->numAxes < 2) { /* if we have no axes, last.valuators must be in screen coords * anyway */ *devx = *screenx = dev->last.valuators[0]; @@ -895,8 +902,7 @@ scale_to_desktop(DeviceIntPtr dev, ValuatorMask *mask, */ static ScreenPtr positionSprite(DeviceIntPtr dev, int mode, ValuatorMask *mask, - double *devx, double *devy, - double *screenx, double *screeny) + double *devx, double *devy, double *screenx, double *screeny) { ScreenPtr scr = miPointerGetScreen(dev); double tmpx, tmpy; @@ -927,14 +933,16 @@ positionSprite(DeviceIntPtr dev, int mode, ValuatorMask *mask, /* Recalculate the per-screen device coordinates */ if (valuator_mask_isset(mask, 0)) { double x; - x = rescaleValuatorAxis(*screenx - scr->x, NULL, dev->valuator->axes + 0, - 0, scr->width); + + x = rescaleValuatorAxis(*screenx - scr->x, NULL, + dev->valuator->axes + 0, 0, scr->width); valuator_mask_set_double(mask, 0, x); } if (valuator_mask_isset(mask, 1)) { double y; - y = rescaleValuatorAxis(*screeny - scr->y, NULL, dev->valuator->axes + 1, - 0, scr->height); + + y = rescaleValuatorAxis(*screeny - scr->y, NULL, + dev->valuator->axes + 1, 0, scr->height); valuator_mask_set_double(mask, 1, y); } @@ -956,9 +964,9 @@ updateHistory(DeviceIntPtr dev, ValuatorMask *mask, CARD32 ms) return; updateMotionHistory(dev, ms, mask, dev->last.valuators); - if(!IsMaster(dev) && !IsFloating(dev)) - { + if (!IsMaster(dev) && !IsFloating(dev)) { DeviceIntPtr master = GetMaster(dev, MASTER_POINTER); + updateMotionHistory(master, ms, mask, dev->last.valuators); } } @@ -967,12 +975,13 @@ static void queueEventList(DeviceIntPtr device, InternalEvent *events, int nevents) { int i; + for (i = 0; i < nevents; i++) mieqEnqueue(device, &events[i]); } static void -event_set_root_coordinates(DeviceEvent* event, double x, double y) +event_set_root_coordinates(DeviceEvent *event, double x, double y) { event->root_x = trunc(x); event->root_y = trunc(y); @@ -1015,30 +1024,41 @@ QueueKeyboardEvents(DeviceIntPtr device, int type, */ int GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type, - int key_code, const ValuatorMask *mask_in) { + int key_code, const ValuatorMask *mask_in) +{ int num_events = 0; CARD32 ms = 0; DeviceEvent *event; RawDeviceEvent *raw; ValuatorMask mask; +#if XSERVER_DTRACE + if (XSERVER_INPUT_EVENT_ENABLED()) { + XSERVER_INPUT_EVENT(pDev->id, type, key_code, 0, + mask_in ? mask_in->last_bit + 1 : 0, + mask_in ? mask_in->mask : NULL, + mask_in ? mask_in->valuators : NULL); + } +#endif + /* refuse events from disabled devices */ if (!pDev->enabled) return 0; - if (!events ||!pDev->key || !pDev->focus || !pDev->kbdfeed || - (type != KeyPress && type != KeyRelease) || - (key_code < 8 || key_code > 255)) + if (!events || !pDev->key || !pDev->focus || !pDev->kbdfeed || + (type != KeyPress && type != KeyRelease) || + (key_code < 8 || key_code > 255)) return 0; if (mask_in && valuator_mask_size(mask_in) > 1) { ErrorF("[dix] the server does not handle valuator masks with " - "keyboard events. This is a bug. You may fix it.\n"); + "keyboard events. This is a bug. You may fix it.\n"); } num_events = 1; - events = UpdateFromMaster(events, pDev, DEVCHANGE_KEYBOARD_EVENT, &num_events); + events = + UpdateFromMaster(events, pDev, DEVCHANGE_KEYBOARD_EVENT, &num_events); /* Handle core repeating, via press/release/press/release. */ if (type == KeyPress && key_is_down(pDev, key_code, KEY_POSTED)) { @@ -1071,11 +1091,11 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type, if (type == KeyPress) { event->type = ET_KeyPress; - set_key_down(pDev, key_code, KEY_POSTED); + set_key_down(pDev, key_code, KEY_POSTED); } else if (type == KeyRelease) { event->type = ET_KeyRelease; - set_key_up(pDev, key_code, KEY_POSTED); + set_key_up(pDev, key_code, KEY_POSTED); } clipValuators(pDev, &mask); @@ -1083,10 +1103,11 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type, set_valuators(pDev, event, &mask); if (!IsFloating(pDev)) { - DeviceIntPtr master = GetMaster(pDev, MASTER_POINTER); - event_set_root_coordinates(event, - master->last.valuators[0], - master->last.valuators[1]); + DeviceIntPtr master = GetMaster(pDev, MASTER_POINTER); + + event_set_root_coordinates(event, + master->last.valuators[0], + master->last.valuators[1]); } return num_events; @@ -1099,10 +1120,11 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type, * * @param num_events Number of elements in list. */ -InternalEvent* +InternalEvent * InitEventList(int num_events) { InternalEvent *events = calloc(num_events, sizeof(InternalEvent)); + return events; } @@ -1125,7 +1147,7 @@ FreeEventList(InternalEvent *list, int num_events) static void transform(struct pixman_f_transform *m, double *x, double *y) { - struct pixman_f_vector p = {.v = {*x, *y, 1}}; + struct pixman_f_vector p = {.v = {*x, *y, 1} }; pixman_f_transform_point(m, &p); *x = p.v[0]; @@ -1166,8 +1188,7 @@ transformAbsolute(DeviceIntPtr dev, ValuatorMask *mask) static void storeLastValuators(DeviceIntPtr dev, ValuatorMask *mask, - int xaxis, int yaxis, - double devx, double devy) + int xaxis, int yaxis, double devx, double devy) { int i; @@ -1177,8 +1198,7 @@ storeLastValuators(DeviceIntPtr dev, ValuatorMask *mask, if (valuator_mask_isset(mask, yaxis)) dev->last.valuators[1] = devy; - for (i = 0; i < valuator_mask_size(mask); i++) - { + for (i = 0; i < valuator_mask_size(mask); i++) { if (i == xaxis || i == yaxis) continue; @@ -1207,7 +1227,8 @@ QueuePointerEvents(DeviceIntPtr device, int type, { int nevents; - nevents = GetPointerEvents(InputEventList, device, type, buttons, flags, mask); + nevents = + GetPointerEvents(InputEventList, device, type, buttons, flags, mask); queueEventList(device, InputEventList, nevents); } @@ -1259,68 +1280,68 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type, int num_events = 1; DeviceEvent *event; RawDeviceEvent *raw; - double screenx = 0.0, screeny = 0.0; /* desktop coordinate system */ - double devx = 0.0, devy = 0.0; /* desktop-wide in device coords */ + double screenx = 0.0, screeny = 0.0; /* desktop coordinate system */ + double devx = 0.0, devy = 0.0; /* desktop-wide in device coords */ ValuatorMask mask; ScreenPtr scr; - switch (type) - { - case MotionNotify: - if (!pDev->valuator) - { - ErrorF("[dix] motion events from device %d without valuators\n", pDev->id); - return 0; - } - if (!mask_in || valuator_mask_num_valuators(mask_in) <= 0) - return 0; - break; - case ButtonPress: - case ButtonRelease: - if (!pDev->button || !buttons) - return 0; - if (mask_in && valuator_mask_size(mask_in) > 0 && !pDev->valuator) - { - ErrorF("[dix] button event with valuator from device %d without valuators\n", pDev->id); - return 0; - } - break; - default: + switch (type) { + case MotionNotify: + if (!pDev->valuator) { + ErrorF("[dix] motion events from device %d without valuators\n", + pDev->id); return 0; + } + if (!mask_in || valuator_mask_num_valuators(mask_in) <= 0) + return 0; + break; + case ButtonPress: + case ButtonRelease: + if (!pDev->button || !buttons) + return 0; + if (mask_in && valuator_mask_size(mask_in) > 0 && !pDev->valuator) { + ErrorF + ("[dix] button event with valuator from device %d without valuators\n", + pDev->id); + return 0; + } + break; + default: + return 0; } valuator_mask_copy(&mask, mask_in); - if ((flags & POINTER_NORAW) == 0) - { - raw = &events->raw_event; - events++; - num_events++; + if ((flags & POINTER_NORAW) == 0) { + raw = &events->raw_event; + events++; + num_events++; - init_raw(pDev, raw, ms, type, buttons); + init_raw(pDev, raw, ms, type, buttons); set_raw_valuators(raw, &mask, raw->valuators.data_raw); } /* valuators are in driver-native format (rel or abs) */ - if (flags & POINTER_ABSOLUTE) - { - if (flags & POINTER_SCREEN) /* valuators are in screen coords */ + if (flags & POINTER_ABSOLUTE) { + if (flags & POINTER_SCREEN) /* valuators are in screen coords */ scale_from_screen(pDev, &mask); transformAbsolute(pDev, &mask); clipAbsolute(pDev, &mask); - } else { + if ((flags & POINTER_NORAW) == 0) + set_raw_valuators(raw, &mask, raw->valuators.data); + } + else { if (flags & POINTER_ACCELERATE) accelPointer(pDev, &mask, ms); + if ((flags & POINTER_NORAW) == 0) + set_raw_valuators(raw, &mask, raw->valuators.data); + moveRelative(pDev, &mask); } /* valuators are in device coordinate system in absolute coordinates */ - - if ((flags & POINTER_NORAW) == 0) - set_raw_valuators(raw, &mask, raw->valuators.data); - scale_to_desktop(pDev, &mask, &devx, &devy, &screenx, &screeny); scr = positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative, &mask, &devx, &devy, &screenx, &screeny); @@ -1337,6 +1358,7 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type, /* Update the MD's co-ordinates, which are always in desktop space. */ if (!IsMaster(pDev) && !IsFloating(pDev)) { DeviceIntPtr master = GetMaster(pDev, MASTER_POINTER); + master->last.valuators[0] = screenx; master->last.valuators[1] = screeny; } @@ -1394,9 +1416,7 @@ emulate_scroll_button_events(InternalEvent *events, int type, int axis, const ValuatorMask *mask, - ValuatorMask *last, - CARD32 ms, - int max_events) + ValuatorMask *last, CARD32 ms, int max_events) { AxisInfoPtr ax; double delta; @@ -1421,16 +1441,16 @@ emulate_scroll_button_events(InternalEvent *events, if (!valuator_mask_isset(last, axis)) valuator_mask_set_double(last, axis, 0); - delta = valuator_mask_get_double(mask, axis) - valuator_mask_get_double(last, axis); + delta = + valuator_mask_get_double(mask, axis) - valuator_mask_get_double(last, + axis); total = delta; b = (ax->scroll.type == SCROLL_TYPE_VERTICAL) ? 5 : 7; - if ((incr > 0 && delta < 0) || - (incr < 0 && delta > 0)) - b--; /* we're scrolling up or left → button 4 or 6 */ + if ((incr > 0 && delta < 0) || (incr < 0 && delta > 0)) + b--; /* we're scrolling up or left → button 4 or 6 */ - while (fabs(delta) >= fabs(incr)) - { + while (fabs(delta) >= fabs(incr)) { int nev_tmp; if (delta > 0) @@ -1443,17 +1463,14 @@ emulate_scroll_button_events(InternalEvent *events, * We may get a bigger scroll delta than we can generate events * for. In that case, we keep decreasing delta, but skip events. */ - if (num_events + 4 < max_events) - { - if (type != ButtonRelease) - { + if (num_events + 4 < max_events) { + if (type != ButtonRelease) { nev_tmp = fill_pointer_events(events, dev, ButtonPress, b, ms, flags, NULL); events += nev_tmp; num_events += nev_tmp; } - if (type != ButtonPress) - { + if (type != ButtonPress) { nev_tmp = fill_pointer_events(events, dev, ButtonRelease, b, ms, flags, NULL); events += nev_tmp; @@ -1463,8 +1480,7 @@ emulate_scroll_button_events(InternalEvent *events, } /* We emulated, update last.scroll */ - if (total != delta) - { + if (total != delta) { total -= delta; valuator_mask_set_double(last, axis, valuator_mask_get_double(last, axis) + total); @@ -1473,7 +1489,6 @@ emulate_scroll_button_events(InternalEvent *events, return num_events; } - /** * Generate a complete series of InternalEvents (filled into the EventList) * representing pointer motion, or button presses. If the device is a slave @@ -1503,6 +1518,15 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int i; int realtype = type; +#if XSERVER_DTRACE + if (XSERVER_INPUT_EVENT_ENABLED()) { + XSERVER_INPUT_EVENT(pDev->id, type, buttons, flags, + mask_in ? mask_in->last_bit + 1 : 0, + mask_in ? mask_in->mask : NULL, + mask_in ? mask_in->valuators : NULL); + } +#endif + /* refuse events from disabled devices */ if (!pDev->enabled) return 0; @@ -1518,15 +1542,13 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, /* Turn a scroll button press into a smooth-scrolling event if * necessary. This only needs to cater for the XIScrollFlagPreferred * axis (if more than one scrolling axis is present) */ - if (type == ButtonPress) - { + if (type == ButtonPress) { double val, adj; int axis; int h_scroll_axis = -1; int v_scroll_axis = -1; - if (pDev->valuator) - { + if (pDev->valuator) { h_scroll_axis = pDev->valuator->h_scroll_axis; v_scroll_axis = pDev->valuator->v_scroll_axis; } @@ -1555,8 +1577,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, break; } - if (adj != 0.0 && axis != -1) - { + if (adj != 0.0 && axis != -1) { adj *= pDev->valuator->axes[axis].scroll.increment; val = valuator_mask_get_double(&mask, axis) + adj; valuator_mask_set_double(&mask, axis, val); @@ -1582,9 +1603,10 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, valuator_mask_set_double(&scroll, i, pDev->last.valuators[i]); - nev_tmp = emulate_scroll_button_events(events, pDev, realtype, i, &scroll, - pDev->last.scroll, ms, - GetMaximumEventsNum() - num_events); + nev_tmp = + emulate_scroll_button_events(events, pDev, realtype, i, &scroll, + pDev->last.scroll, ms, + GetMaximumEventsNum() - num_events); events += nev_tmp; num_events += nev_tmp; } @@ -1605,8 +1627,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, * */ void -QueueProximityEvents(DeviceIntPtr device, int type, - const ValuatorMask *mask) +QueueProximityEvents(DeviceIntPtr device, int type, const ValuatorMask *mask) { int nevents; @@ -1624,12 +1645,22 @@ QueueProximityEvents(DeviceIntPtr device, int type, * @return the number of events written into events. */ int -GetProximityEvents(InternalEvent *events, DeviceIntPtr pDev, int type, const ValuatorMask *mask_in) +GetProximityEvents(InternalEvent *events, DeviceIntPtr pDev, int type, + const ValuatorMask *mask_in) { int num_events = 1, i; DeviceEvent *event; ValuatorMask mask; +#if XSERVER_DTRACE + if (XSERVER_INPUT_EVENT_ENABLED()) { + XSERVER_INPUT_EVENT(pDev->id, type, 0, 0, + mask_in ? mask_in->last_bit + 1 : 0, + mask_in ? mask_in->mask : NULL, + mask_in ? mask_in->valuators : NULL); + } +#endif + /* refuse events from disabled devices */ if (!pDev->enabled) return 0; @@ -1643,8 +1674,7 @@ GetProximityEvents(InternalEvent *events, DeviceIntPtr pDev, int type, const Val valuator_mask_copy(&mask, mask_in); /* ignore relative axes for proximity. */ - for (i = 0; i < valuator_mask_size(&mask); i++) - { + for (i = 0; i < valuator_mask_size(&mask); i++) { if (valuator_mask_isset(&mask, i) && valuator_get_mode(pDev, i) == Relative) valuator_mask_unset(&mask, i); @@ -1654,7 +1684,8 @@ GetProximityEvents(InternalEvent *events, DeviceIntPtr pDev, int type, const Val * in an empty event, EventToXI() will fail to convert → no event sent * to client. */ - events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events); + events = + UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events); event = &events->device_event; init_device_event(event, pDev, GetTimeInMillis()); @@ -1709,7 +1740,8 @@ QueueTouchEvents(DeviceIntPtr device, int type, { int nevents; - nevents = GetTouchEvents(InputEventList, device, ddx_touchid, type, flags, mask); + nevents = + GetTouchEvents(InputEventList, device, ddx_touchid, type, flags, mask); queueEventList(device, InputEventList, nevents); } @@ -1740,8 +1772,8 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, DeviceEvent *event; CARD32 ms = GetTimeInMillis(); ValuatorMask mask; - double screenx = 0.0, screeny = 0.0; /* desktop coordinate system */ - double devx = 0.0, devy = 0.0; /* desktop-wide in device coords */ + double screenx = 0.0, screeny = 0.0; /* desktop coordinate system */ + double devx = 0.0, devy = 0.0; /* desktop-wide in device coords */ int i; int num_events = 0; RawDeviceEvent *raw; @@ -1753,13 +1785,21 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, Bool emulate_pointer = FALSE; int client_id = 0; +#if XSERVER_DTRACE + if (XSERVER_INPUT_EVENT_ENABLED()) { + XSERVER_INPUT_EVENT(dev->id, type, ddx_touchid, flags, + mask_in ? mask_in->last_bit + 1 : 0, + mask_in ? mask_in->mask : NULL, + mask_in ? mask_in->valuators : NULL); + } +#endif + if (!dev->enabled || !t || !v) return 0; /* Find and/or create the DDX touch info */ - if (flags & TOUCH_CLIENT_ID) /* A DIX-submitted TouchEnd */ - { + if (flags & TOUCH_CLIENT_ID) { /* A DIX-submitted TouchEnd */ touchpoint.dix_ti = TouchFindByClientID(dev, ddx_touchid); BUG_WARN(!touchpoint.dix_ti); @@ -1768,38 +1808,39 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, if (!mask_in || !valuator_mask_isset(mask_in, 0) || - !valuator_mask_isset(mask_in, 1)) - { - ErrorF("[dix] dix-submitted events must have x/y valuator information.\n"); + !valuator_mask_isset(mask_in, 1)) { + ErrorF + ("[dix] dix-submitted events must have x/y valuator information.\n"); return 0; } need_rawevent = FALSE; client_id = touchpoint.dix_ti->client_id; - } else /* a DDX-submitted touch */ - { - touchpoint.ti = TouchFindByDDXID(dev, ddx_touchid, (type == XI_TouchBegin)); - if (!touchpoint.ti) - { + } + else { /* a DDX-submitted touch */ + + touchpoint.ti = + TouchFindByDDXID(dev, ddx_touchid, (type == XI_TouchBegin)); + if (!touchpoint.ti) { ErrorF("[dix] %s: unable to %s touch point %x\n", dev->name, - type == XI_TouchBegin ? "begin" : "find", ddx_touchid); + type == XI_TouchBegin ? "begin" : "find", ddx_touchid); return 0; } client_id = touchpoint.ti->client_id; } if (!(flags & TOUCH_CLIENT_ID)) - emulate_pointer = touchpoint.ti->emulate_pointer; + emulate_pointer = touchpoint.ti->emulate_pointer; else - emulate_pointer = !!(flags & TOUCH_POINTER_EMULATED); + emulate_pointer = ! !(flags & TOUCH_POINTER_EMULATED); if (!IsMaster(dev)) - events = UpdateFromMaster(events, dev, DEVCHANGE_POINTER_EVENT, &num_events); + events = + UpdateFromMaster(events, dev, DEVCHANGE_POINTER_EVENT, &num_events); valuator_mask_copy(&mask, mask_in); - if (need_rawevent) - { + if (need_rawevent) { raw = &events->raw_event; events++; num_events++; @@ -1812,8 +1853,7 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, init_event(dev, event, ms); /* if submitted for master device, get the sourceid from there */ - if (flags & TOUCH_CLIENT_ID) - { + if (flags & TOUCH_CLIENT_ID) { event->sourceid = touchpoint.dix_ti->sourceid; /* TOUCH_CLIENT_ID implies norawevent */ } @@ -1824,8 +1864,7 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, /* If we're starting a touch, we must have x & y co-ordinates. */ if (!mask_in || !valuator_mask_isset(mask_in, 0) || - !valuator_mask_isset(mask_in, 1)) - { + !valuator_mask_isset(mask_in, 1)) { ErrorF("%s: Attempted to start touch without x/y (driver bug)\n", dev->name); return 0; @@ -1833,10 +1872,9 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, break; case XI_TouchUpdate: event->type = ET_TouchUpdate; - if (!mask_in || valuator_mask_num_valuators(mask_in) <= 0) - { + if (!mask_in || valuator_mask_num_valuators(mask_in) <= 0) { ErrorF("%s: TouchUpdate with no valuators? Driver bug\n", - dev->name); + dev->name); } break; case XI_TouchEnd: @@ -1849,12 +1887,15 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, default: return 0; } - if (t->mode == XIDirectTouch && !(flags & TOUCH_CLIENT_ID)) - { + if (t->mode == XIDirectTouch && !(flags & TOUCH_CLIENT_ID)) { if (!valuator_mask_isset(&mask, 0)) - valuator_mask_set_double(&mask, 0, valuator_mask_get_double(touchpoint.ti->valuators, 0)); + valuator_mask_set_double(&mask, 0, + valuator_mask_get_double(touchpoint.ti-> + valuators, 0)); if (!valuator_mask_isset(&mask, 1)) - valuator_mask_set_double(&mask, 1, valuator_mask_get_double(touchpoint.ti->valuators, 1)); + valuator_mask_set_double(&mask, 1, + valuator_mask_get_double(touchpoint.ti-> + valuators, 1)); } /* Get our screen event co-ordinates (root_x/root_y/event_x/event_y): @@ -1866,6 +1907,7 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, if (!(flags & TOUCH_CLIENT_ID)) { for (i = 0; i < valuator_mask_size(&mask); i++) { double val; + if (valuator_mask_fetch_double(&mask, i, &val)) valuator_mask_set_double(touchpoint.ti->valuators, i, val); } @@ -1905,15 +1947,13 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, event->touchid = client_id; event->flags = flags; - if (emulate_pointer) - { + if (emulate_pointer) { event->flags |= TOUCH_POINTER_EMULATED; event->detail.button = 1; } set_valuators(dev, event, &mask); - for (i = 0; i < v->numAxes; i++) - { + for (i = 0; i < v->numAxes; i++) { if (valuator_mask_isset(&mask, i)) v->axisVal[i] = valuator_mask_get(&mask, i); } @@ -1921,7 +1961,6 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, return num_events; } - /** * Synthesize a single motion event for the core pointer. * @@ -1930,10 +1969,7 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid, */ void PostSyntheticMotion(DeviceIntPtr pDev, - int x, - int y, - int screen, - unsigned long time) + int x, int y, int screen, unsigned long time) { DeviceEvent ev; @@ -1955,5 +1991,5 @@ PostSyntheticMotion(DeviceIntPtr pDev, ev.time = time; /* FIXME: MD/SD considerations? */ - (*pDev->public.processInputProc)((InternalEvent*)&ev, pDev); + (*pDev->public.processInputProc) ((InternalEvent *) &ev, pDev); } diff --git a/xorg-server/dix/globals.c b/xorg-server/dix/globals.c index d7e919e50..a564575f3 100644 --- a/xorg-server/dix/globals.c +++ b/xorg-server/dix/globals.c @@ -1,131 +1,133 @@ -/************************************************************
-
-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
-
-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.
-
-********************************************************/
-
-
-#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 "scrnintstr.h"
-#include "input.h"
-#include "dixfont.h"
-#include "site.h"
-#include "dixstruct.h"
-#include "os.h"
-
-ScreenInfo screenInfo;
-KeybdCtrl defaultKeyboardControl = {
- DEFAULT_KEYBOARD_CLICK,
- DEFAULT_BELL,
- DEFAULT_BELL_PITCH,
- DEFAULT_BELL_DURATION,
- DEFAULT_AUTOREPEAT,
- DEFAULT_AUTOREPEATS,
- DEFAULT_LEDS,
- 0};
-
-PtrCtrl defaultPointerControl = {
- DEFAULT_PTR_NUMERATOR,
- DEFAULT_PTR_DENOMINATOR,
- DEFAULT_PTR_THRESHOLD,
- 0};
-
-ClientPtr clients[MAXCLIENTS];
-ClientPtr serverClient;
-int currentMaxClients; /* current size of clients array */
-long maxBigRequestSize = MAX_BIG_REQUEST_SIZE;
-
-unsigned long globalSerialNumber = 0;
-unsigned long serverGeneration = 0;
-
-/* these next four are initialized in main.c */
-CARD32 ScreenSaverTime;
-CARD32 ScreenSaverInterval;
-int ScreenSaverBlanking;
-int ScreenSaverAllowExposures;
-
-#ifdef DPMSExtension
-CARD16 DPMSPowerLevel = 0;
-Bool DPMSDisabledSwitch = FALSE;
-Bool DPMSCapableFlag = FALSE;
-CARD32 DPMSStandbyTime;
-CARD32 DPMSSuspendTime;
-CARD32 DPMSOffTime;
-Bool DPMSEnabled;
-#endif
-
-CARD32 defaultScreenSaverTime = DEFAULT_SCREEN_SAVER_TIME;
-CARD32 defaultScreenSaverInterval = DEFAULT_SCREEN_SAVER_INTERVAL;
-int defaultScreenSaverBlanking = DEFAULT_SCREEN_SAVER_BLANKING;
-int defaultScreenSaverAllowExposures = DEFAULT_SCREEN_SAVER_EXPOSURES;
-#ifdef SCREENSAVER
-Bool screenSaverSuspended = FALSE;
-#endif
-
-char *defaultFontPath = COMPILEDDEFAULTFONTPATH;
-char *defaultTextFont = COMPILEDDEFAULTFONT;
-char *defaultCursorFont = COMPILEDCURSORFONT;
-FontPtr defaultFont; /* not declared in dix.h to avoid including font.h in
- every compilation of dix code */
-CursorPtr rootCursor;
-Bool party_like_its_1989 = FALSE;
-Bool whiteRoot = FALSE;
-
-TimeStamp currentTime;
-TimeStamp lastDeviceEventTime;
-
-int defaultColorVisualClass = -1;
-int monitorResolution = 0;
-
-char *display;
-char *ConnectionInfo;
-
-CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND;
+/************************************************************ + +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 + +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. + +********************************************************/ + +#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 "scrnintstr.h" +#include "input.h" +#include "dixfont.h" +#include "site.h" +#include "dixstruct.h" +#include "os.h" + +ScreenInfo screenInfo; + +KeybdCtrl defaultKeyboardControl = { + DEFAULT_KEYBOARD_CLICK, + DEFAULT_BELL, + DEFAULT_BELL_PITCH, + DEFAULT_BELL_DURATION, + DEFAULT_AUTOREPEAT, + DEFAULT_AUTOREPEATS, + DEFAULT_LEDS, + 0 +}; + +PtrCtrl defaultPointerControl = { + DEFAULT_PTR_NUMERATOR, + DEFAULT_PTR_DENOMINATOR, + DEFAULT_PTR_THRESHOLD, + 0 +}; + +ClientPtr clients[MAXCLIENTS]; +ClientPtr serverClient; +int currentMaxClients; /* current size of clients array */ +long maxBigRequestSize = MAX_BIG_REQUEST_SIZE; + +unsigned long globalSerialNumber = 0; +unsigned long serverGeneration = 0; + +/* these next four are initialized in main.c */ +CARD32 ScreenSaverTime; +CARD32 ScreenSaverInterval; +int ScreenSaverBlanking; +int ScreenSaverAllowExposures; + +#ifdef DPMSExtension +CARD16 DPMSPowerLevel = 0; +Bool DPMSDisabledSwitch = FALSE; +Bool DPMSCapableFlag = FALSE; +CARD32 DPMSStandbyTime; +CARD32 DPMSSuspendTime; +CARD32 DPMSOffTime; +Bool DPMSEnabled; +#endif + +CARD32 defaultScreenSaverTime = DEFAULT_SCREEN_SAVER_TIME; +CARD32 defaultScreenSaverInterval = DEFAULT_SCREEN_SAVER_INTERVAL; +int defaultScreenSaverBlanking = DEFAULT_SCREEN_SAVER_BLANKING; +int defaultScreenSaverAllowExposures = DEFAULT_SCREEN_SAVER_EXPOSURES; + +#ifdef SCREENSAVER +Bool screenSaverSuspended = FALSE; +#endif + +char *defaultFontPath = COMPILEDDEFAULTFONTPATH; +char *defaultTextFont = COMPILEDDEFAULTFONT; +char *defaultCursorFont = COMPILEDCURSORFONT; +FontPtr defaultFont; /* not declared in dix.h to avoid including font.h in + every compilation of dix code */ +CursorPtr rootCursor; +Bool party_like_its_1989 = FALSE; +Bool whiteRoot = FALSE; + +TimeStamp currentTime; +TimeStamp lastDeviceEventTime[MAXDEVICES]; + +int defaultColorVisualClass = -1; +int monitorResolution = 0; + +char *display; +char *ConnectionInfo; + +CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND; diff --git a/xorg-server/dix/glyphcurs.c b/xorg-server/dix/glyphcurs.c index 946f447b2..9004cb152 100644 --- a/xorg-server/dix/glyphcurs.c +++ b/xorg-server/dix/glyphcurs.c @@ -1,191 +1,181 @@ -/************************************************************************
-
-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
-
-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.
-
-************************************************************************/
-
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "misc.h"
-#include <X11/fonts/fontstruct.h>
-#include "dixfontstr.h"
-#include "scrnintstr.h"
-#include "gcstruct.h"
-#include "resource.h"
-#include "dix.h"
-#include "cursorstr.h"
-#include "opaque.h"
-#include "servermd.h"
-
-
-/*
- get the bits out of the font in a portable way. to avoid
-dealing with padding and such-like, we draw the glyph into
-a bitmap, then read the bits out with GetImage, which
-uses server-natural format.
- since all screens return the same bitmap format, we'll just use
-the first one we find.
- the character origin lines up with the hotspot in the
-cursor metrics.
-*/
-
-int
-ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, unsigned char **ppbits)
-{
- ScreenPtr pScreen;
- GCPtr pGC;
- xRectangle rect;
- PixmapPtr ppix;
- long nby;
- char *pbits;
- ChangeGCVal gcval[3];
- unsigned char char2b[2];
-
- /* turn glyph index into a protocol-format char2b */
- char2b[0] = (unsigned char)(ch >> 8);
- char2b[1] = (unsigned char)(ch & 0xff);
-
- pScreen = screenInfo.screens[0];
- nby = BitmapBytePad(cm->width) * (long)cm->height;
- pbits = calloc(1, nby);
- if (!pbits)
- return BadAlloc;
-
- ppix = (PixmapPtr)(*pScreen->CreatePixmap)(pScreen, cm->width,
- cm->height, 1,
- CREATE_PIXMAP_USAGE_SCRATCH);
- pGC = GetScratchGC(1, pScreen);
- if (!ppix || !pGC)
- {
- if (ppix)
- (*pScreen->DestroyPixmap)(ppix);
- if (pGC)
- FreeScratchGC(pGC);
- free(pbits);
- return BadAlloc;
- }
-
- rect.x = 0;
- rect.y = 0;
- rect.width = cm->width;
- rect.height = cm->height;
-
- /* fill the pixmap with 0 */
- gcval[0].val = GXcopy;
- gcval[1].val = 0;
- gcval[2].ptr = (pointer)pfont;
- ChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFont, gcval);
- ValidateGC((DrawablePtr)ppix, pGC);
- (*pGC->ops->PolyFillRect)((DrawablePtr)ppix, pGC, 1, &rect);
-
- /* draw the glyph */
- gcval[0].val = 1;
- ChangeGC(NullClient, pGC, GCForeground, gcval);
- ValidateGC((DrawablePtr)ppix, pGC);
- (*pGC->ops->PolyText16)((DrawablePtr)ppix, pGC, cm->xhot, cm->yhot,
- 1, (unsigned short *)char2b);
- (*pScreen->GetImage)((DrawablePtr)ppix, 0, 0, cm->width, cm->height,
- XYPixmap, 1, pbits);
- *ppbits = (unsigned char *)pbits;
- FreeScratchGC(pGC);
- (*pScreen->DestroyPixmap)(ppix);
- return Success;
-}
-
-
-Bool
-CursorMetricsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm)
-{
- CharInfoPtr pci;
- unsigned long nglyphs;
- CARD8 chs[2];
- FontEncoding encoding;
-
- chs[0] = ch >> 8;
- chs[1] = ch;
- encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit;
- if (encoding == Linear16Bit)
- {
- if (ch < pfont->info.firstCol || pfont->info.lastCol < ch)
- return FALSE;
- }
- else
- {
- if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0])
- return FALSE;
- if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1])
- return FALSE;
- }
- (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci);
- if (nglyphs == 0)
- return FALSE;
- cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
- cm->height = pci->metrics.descent + pci->metrics.ascent;
- if (pci->metrics.leftSideBearing > 0)
- {
- cm->width += pci->metrics.leftSideBearing;
- cm->xhot = 0;
- }
- else
- {
- cm->xhot = -pci->metrics.leftSideBearing;
- if (pci->metrics.rightSideBearing < 0)
- cm->width -= pci->metrics.rightSideBearing;
- }
- if (pci->metrics.ascent < 0)
- {
- cm->height -= pci->metrics.ascent;
- cm->yhot = 0;
- }
- else
- {
- cm->yhot = pci->metrics.ascent;
- if (pci->metrics.descent < 0)
- cm->height -= pci->metrics.descent;
- }
- return TRUE;
-}
+/************************************************************************ + +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 + +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. + +************************************************************************/ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "misc.h" +#include <X11/fonts/fontstruct.h> +#include "dixfontstr.h" +#include "scrnintstr.h" +#include "gcstruct.h" +#include "resource.h" +#include "dix.h" +#include "cursorstr.h" +#include "opaque.h" +#include "servermd.h" + +/* + get the bits out of the font in a portable way. to avoid +dealing with padding and such-like, we draw the glyph into +a bitmap, then read the bits out with GetImage, which +uses server-natural format. + since all screens return the same bitmap format, we'll just use +the first one we find. + the character origin lines up with the hotspot in the +cursor metrics. +*/ + +int +ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, + unsigned char **ppbits) +{ + ScreenPtr pScreen; + GCPtr pGC; + xRectangle rect; + PixmapPtr ppix; + long nby; + char *pbits; + ChangeGCVal gcval[3]; + unsigned char char2b[2]; + + /* turn glyph index into a protocol-format char2b */ + char2b[0] = (unsigned char) (ch >> 8); + char2b[1] = (unsigned char) (ch & 0xff); + + pScreen = screenInfo.screens[0]; + nby = BitmapBytePad(cm->width) * (long) cm->height; + pbits = calloc(1, nby); + if (!pbits) + return BadAlloc; + + ppix = (PixmapPtr) (*pScreen->CreatePixmap) (pScreen, cm->width, + cm->height, 1, + CREATE_PIXMAP_USAGE_SCRATCH); + pGC = GetScratchGC(1, pScreen); + if (!ppix || !pGC) { + if (ppix) + (*pScreen->DestroyPixmap) (ppix); + if (pGC) + FreeScratchGC(pGC); + free(pbits); + return BadAlloc; + } + + rect.x = 0; + rect.y = 0; + rect.width = cm->width; + rect.height = cm->height; + + /* fill the pixmap with 0 */ + gcval[0].val = GXcopy; + gcval[1].val = 0; + gcval[2].ptr = (pointer) pfont; + ChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFont, gcval); + ValidateGC((DrawablePtr) ppix, pGC); + (*pGC->ops->PolyFillRect) ((DrawablePtr) ppix, pGC, 1, &rect); + + /* draw the glyph */ + gcval[0].val = 1; + ChangeGC(NullClient, pGC, GCForeground, gcval); + ValidateGC((DrawablePtr) ppix, pGC); + (*pGC->ops->PolyText16) ((DrawablePtr) ppix, pGC, cm->xhot, cm->yhot, + 1, (unsigned short *) char2b); + (*pScreen->GetImage) ((DrawablePtr) ppix, 0, 0, cm->width, cm->height, + XYPixmap, 1, pbits); + *ppbits = (unsigned char *) pbits; + FreeScratchGC(pGC); + (*pScreen->DestroyPixmap) (ppix); + return Success; +} + +Bool +CursorMetricsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm) +{ + CharInfoPtr pci; + unsigned long nglyphs; + CARD8 chs[2]; + FontEncoding encoding; + + chs[0] = ch >> 8; + chs[1] = ch; + encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit; + if (encoding == Linear16Bit) { + if (ch < pfont->info.firstCol || pfont->info.lastCol < ch) + return FALSE; + } + else { + if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0]) + return FALSE; + if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1]) + return FALSE; + } + (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci); + if (nglyphs == 0) + return FALSE; + cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing; + cm->height = pci->metrics.descent + pci->metrics.ascent; + if (pci->metrics.leftSideBearing > 0) { + cm->width += pci->metrics.leftSideBearing; + cm->xhot = 0; + } + else { + cm->xhot = -pci->metrics.leftSideBearing; + if (pci->metrics.rightSideBearing < 0) + cm->width -= pci->metrics.rightSideBearing; + } + if (pci->metrics.ascent < 0) { + cm->height -= pci->metrics.ascent; + cm->yhot = 0; + } + else { + cm->yhot = pci->metrics.ascent; + if (pci->metrics.descent < 0) + cm->height -= pci->metrics.descent; + } + return TRUE; +} diff --git a/xorg-server/dix/grabs.c b/xorg-server/dix/grabs.c index cc2c946d0..2f05f5733 100644 --- a/xorg-server/dix/grabs.c +++ b/xorg-server/dix/grabs.c @@ -24,7 +24,6 @@ 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 @@ -84,24 +83,20 @@ PrintDeviceGrabInfo(DeviceIntPtr dev) ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):\n", (unsigned long) grab->resource, (grab->grabtype == XI2) ? "xi2" : - ((grab->grabtype == CORE) ? "core" : "xi1"), - dev->name, dev->id); + ((grab->grabtype == CORE) ? "core" : "xi1"), dev->name, dev->id); client = clients[CLIENT_ID(grab->resource)]; - if (client) - { + if (client) { pid_t clientpid = GetClientPid(client); const char *cmdname = GetClientCmdName(client); const char *cmdargs = GetClientCmdArgs(client); - if ((clientpid > 0) && (cmdname != NULL)) - { + if ((clientpid > 0) && (cmdname != NULL)) { ErrorF(" client pid %ld %s %s\n", (long) clientpid, cmdname, cmdargs ? cmdargs : ""); clientIdPrinted = TRUE; } - else if (GetLocalClientCreds(client, &lcc) != -1) - { + else if (GetLocalClientCreds(client, &lcc) != -1) { ErrorF(" client pid %ld uid %ld gid %ld\n", (lcc->fieldsSet & LCC_PID_SET) ? (long) lcc->pid : 0, (lcc->fieldsSet & LCC_UID_SET) ? (long) lcc->euid : 0, @@ -110,8 +105,7 @@ PrintDeviceGrabInfo(DeviceIntPtr dev) clientIdPrinted = TRUE; } } - if (!clientIdPrinted) - { + if (!clientIdPrinted) { ErrorF(" (no client information available for client %d)\n", CLIENT_ID(grab->resource)); } @@ -125,32 +119,26 @@ PrintDeviceGrabInfo(DeviceIntPtr dev) (unsigned long) devGrab->grabTime.milliseconds, devGrab->fromPassiveGrab ? "passive" : "active", devGrab->implicitGrab ? " (implicit)" : "", - devGrab->sync.frozen ? "frozen" : "thawed", - devGrab->sync.state); + devGrab->sync.frozen ? "frozen" : "thawed", devGrab->sync.state); - if (grab->grabtype == CORE) - { + if (grab->grabtype == CORE) { ErrorF(" core event mask 0x%lx\n", (unsigned long) grab->eventMask); } - else if (grab->grabtype == XI) - { + else if (grab->grabtype == XI) { ErrorF(" xi1 event mask 0x%lx\n", devGrab->implicitGrab ? (unsigned long) grab->deviceMask : - (unsigned long) grab->eventMask); + (unsigned long) grab->eventMask); } - else if (grab->grabtype == XI2) - { - for (i = 0; i < xi2mask_num_masks(grab->xi2mask); i++) - { + else if (grab->grabtype == XI2) { + for (i = 0; i < xi2mask_num_masks(grab->xi2mask); i++) { const unsigned char *mask; int print; + print = 0; - for (j = 0; j < XI2MASKSIZE; j++) - { + for (j = 0; j < XI2MASKSIZE; j++) { mask = xi2mask_get_one_mask(grab->xi2mask, i); - if (mask[j]) - { + if (mask[j]) { print = 1; break; } @@ -164,8 +152,7 @@ PrintDeviceGrabInfo(DeviceIntPtr dev) } } - if (devGrab->fromPassiveGrab) - { + if (devGrab->fromPassiveGrab) { ErrorF(" passive grab type %d, detail 0x%x, " "activating key %d\n", grab->type, grab->detail.exact, devGrab->activatingKey); @@ -187,8 +174,7 @@ UngrabAllDevices(Bool kill_client) ErrorF("Ungrabbing all devices%s; grabs listed below:\n", kill_client ? " and killing their owners" : ""); - for (dev = inputInfo.devices; dev; dev = dev->next) - { + for (dev = inputInfo.devices; dev; dev = dev->next) { if (!dev->deviceGrab.grab) continue; PrintDeviceGrabInfo(dev); @@ -219,28 +205,18 @@ AllocGrab(void) } GrabPtr -CreateGrab( - int client, - DeviceIntPtr device, - DeviceIntPtr modDevice, - WindowPtr window, - enum InputLevel grabtype, - GrabMask *mask, - GrabParameters *param, - int type, - KeyCode keybut, /* key or button */ - WindowPtr confineTo, - CursorPtr cursor) +CreateGrab(int client, DeviceIntPtr device, DeviceIntPtr modDevice, WindowPtr window, enum InputLevel grabtype, GrabMask *mask, GrabParameters *param, int type, KeyCode keybut, /* key or button */ + WindowPtr confineTo, CursorPtr cursor) { GrabPtr grab; grab = AllocGrab(); if (!grab) - return (GrabPtr)NULL; + return (GrabPtr) NULL; grab->resource = FakeClientID(client); grab->device = device; grab->window = window; - grab->eventMask = mask->core; /* same for XI */ + grab->eventMask = mask->core; /* same for XI */ grab->deviceMask = 0; grab->ownerEvents = param->ownerEvents; grab->keyboardMode = param->this_device_mode; @@ -259,7 +235,7 @@ CreateGrab( if (grabtype == XI2) xi2mask_merge(grab->xi2mask, mask->xi2mask); if (cursor) - cursor->refcnt++; + cursor->refcnt++; return grab; } @@ -274,7 +250,7 @@ FreeGrab(GrabPtr pGrab) free(pGrab->detail.pMask); if (pGrab->cursor) - FreeCursor(pGrab->cursor, (Cursor)0); + FreeCursor(pGrab->cursor, (Cursor) 0); xi2mask_free(&pGrab->xi2mask); free(pGrab); @@ -292,6 +268,7 @@ CopyGrab(GrabPtr dst, const GrabPtr src) if (src->modifiersDetail.pMask) { int len = MasksPerDetailMask * sizeof(Mask); + mdetails_mask = malloc(len); if (!mdetails_mask) return FALSE; @@ -300,6 +277,7 @@ CopyGrab(GrabPtr dst, const GrabPtr src) if (src->detail.pMask) { int len = MasksPerDetailMask * sizeof(Mask); + details_mask = malloc(len); if (!details_mask) { free(mdetails_mask); @@ -315,7 +293,8 @@ CopyGrab(GrabPtr dst, const GrabPtr src) free(details_mask); return FALSE; } - } else { + } + else { xi2mask = dst->xi2mask; xi2mask_zero(xi2mask, -1); } @@ -334,22 +313,19 @@ int DeletePassiveGrab(pointer value, XID id) { GrabPtr g, prev; - GrabPtr pGrab = (GrabPtr)value; + GrabPtr pGrab = (GrabPtr) value; /* it is OK if the grab isn't found */ prev = 0; - for (g = (wPassiveGrabs (pGrab->window)); g; g = g->next) - { - if (pGrab == g) - { - if (prev) - prev->next = g->next; - else - if (!(pGrab->window->optional->passiveGrabs = g->next)) - CheckWindowOptionalNeed (pGrab->window); - break; - } - prev = g; + for (g = (wPassiveGrabs(pGrab->window)); g; g = g->next) { + if (pGrab == g) { + if (prev) + prev->next = g->next; + else if (!(pGrab->window->optional->passiveGrabs = g->next)) + CheckWindowOptionalNeed(pGrab->window); + break; + } + prev = g; } FreeGrab(pGrab); return Success; @@ -362,69 +338,60 @@ DeleteDetailFromMask(Mask *pDetailMask, unsigned int detail) int i; mask = malloc(sizeof(Mask) * MasksPerDetailMask); - if (mask) - { - if (pDetailMask) - for (i = 0; i < MasksPerDetailMask; i++) - mask[i]= pDetailMask[i]; - else - for (i = 0; i < MasksPerDetailMask; i++) - mask[i]= ~0L; - BITCLEAR(mask, detail); + if (mask) { + if (pDetailMask) + for (i = 0; i < MasksPerDetailMask; i++) + mask[i] = pDetailMask[i]; + else + for (i = 0; i < MasksPerDetailMask; i++) + mask[i] = ~0L; + BITCLEAR(mask, detail); } - return mask; + return mask; } static Bool -IsInGrabMask( - DetailRec firstDetail, - DetailRec secondDetail, - unsigned int exception) +IsInGrabMask(DetailRec firstDetail, + DetailRec secondDetail, unsigned int exception) { - if (firstDetail.exact == exception) - { - if (firstDetail.pMask == NULL) - return TRUE; - - /* (at present) never called with two non-null pMasks */ - if (secondDetail.exact == exception) - return FALSE; - - if (GETBIT(firstDetail.pMask, secondDetail.exact)) - return TRUE; + if (firstDetail.exact == exception) { + if (firstDetail.pMask == NULL) + return TRUE; + + /* (at present) never called with two non-null pMasks */ + if (secondDetail.exact == exception) + return FALSE; + + if (GETBIT(firstDetail.pMask, secondDetail.exact)) + return TRUE; } - + return FALSE; } -static Bool -IdenticalExactDetails( - unsigned int firstExact, - unsigned int secondExact, - unsigned int exception) +static Bool +IdenticalExactDetails(unsigned int firstExact, + unsigned int secondExact, unsigned int exception) { if ((firstExact == exception) || (secondExact == exception)) - return FALSE; - + return FALSE; + if (firstExact == secondExact) - return TRUE; + return TRUE; return FALSE; } -static Bool -DetailSupersedesSecond( - DetailRec firstDetail, - DetailRec secondDetail, - unsigned int exception) +static Bool +DetailSupersedesSecond(DetailRec firstDetail, + DetailRec secondDetail, unsigned int exception) { if (IsInGrabMask(firstDetail, secondDetail, exception)) - return TRUE; + return TRUE; + + if (IdenticalExactDetails(firstDetail.exact, secondDetail.exact, exception)) + return TRUE; - if (IdenticalExactDetails(firstDetail.exact, secondDetail.exact, - exception)) - return TRUE; - return FALSE; } @@ -432,17 +399,15 @@ static Bool GrabSupersedesSecond(GrabPtr pFirstGrab, GrabPtr pSecondGrab) { unsigned int any_modifier = (pFirstGrab->grabtype == XI2) ? - (unsigned int)XIAnyModifier : - (unsigned int)AnyModifier; + (unsigned int) XIAnyModifier : (unsigned int) AnyModifier; if (!DetailSupersedesSecond(pFirstGrab->modifiersDetail, - pSecondGrab->modifiersDetail, - any_modifier)) - return FALSE; + pSecondGrab->modifiersDetail, any_modifier)) + return FALSE; if (DetailSupersedesSecond(pFirstGrab->detail, - pSecondGrab->detail, (unsigned int)AnyKey)) - return TRUE; - + pSecondGrab->detail, (unsigned int) AnyKey)) + return TRUE; + return FALSE; } @@ -463,57 +428,54 @@ Bool GrabMatchesSecond(GrabPtr pFirstGrab, GrabPtr pSecondGrab, Bool ignoreDevice) { unsigned int any_modifier = (pFirstGrab->grabtype == XI2) ? - (unsigned int)XIAnyModifier : - (unsigned int)AnyModifier; + (unsigned int) XIAnyModifier : (unsigned int) AnyModifier; if (pFirstGrab->grabtype != pSecondGrab->grabtype) return FALSE; - if (pFirstGrab->grabtype == XI2) - { + if (pFirstGrab->grabtype == XI2) { if (pFirstGrab->device == inputInfo.all_devices || - pSecondGrab->device == inputInfo.all_devices) - { + pSecondGrab->device == inputInfo.all_devices) { /* do nothing */ - } else if (pFirstGrab->device == inputInfo.all_master_devices) - { + } + else if (pFirstGrab->device == inputInfo.all_master_devices) { if (pSecondGrab->device != inputInfo.all_master_devices && !IsMaster(pSecondGrab->device)) return FALSE; - } else if (pSecondGrab->device == inputInfo.all_master_devices) - { + } + else if (pSecondGrab->device == inputInfo.all_master_devices) { if (pFirstGrab->device != inputInfo.all_master_devices && !IsMaster(pFirstGrab->device)) return FALSE; - } else if (pSecondGrab->device != pFirstGrab->device) - return FALSE; - } else if (!ignoreDevice && - ((pFirstGrab->device != pSecondGrab->device) || - (pFirstGrab->modifierDevice != pSecondGrab->modifierDevice))) + } + else if (pSecondGrab->device != pFirstGrab->device) return FALSE; + } + else if (!ignoreDevice && + ((pFirstGrab->device != pSecondGrab->device) || + (pFirstGrab->modifierDevice != pSecondGrab->modifierDevice))) + return FALSE; if (pFirstGrab->type != pSecondGrab->type) - return FALSE; + return FALSE; if (GrabSupersedesSecond(pFirstGrab, pSecondGrab) || - GrabSupersedesSecond(pSecondGrab, pFirstGrab)) - return TRUE; - + GrabSupersedesSecond(pSecondGrab, pFirstGrab)) + return TRUE; + if (DetailSupersedesSecond(pSecondGrab->detail, pFirstGrab->detail, - (unsigned int)AnyKey) - && - DetailSupersedesSecond(pFirstGrab->modifiersDetail, - pSecondGrab->modifiersDetail, - any_modifier)) - return TRUE; + (unsigned int) AnyKey) + && + DetailSupersedesSecond(pFirstGrab->modifiersDetail, + pSecondGrab->modifiersDetail, any_modifier)) + return TRUE; if (DetailSupersedesSecond(pFirstGrab->detail, pSecondGrab->detail, - (unsigned int)AnyKey) - && - DetailSupersedesSecond(pSecondGrab->modifiersDetail, - pFirstGrab->modifiersDetail, - any_modifier)) - return TRUE; + (unsigned int) AnyKey) + && + DetailSupersedesSecond(pSecondGrab->modifiersDetail, + pFirstGrab->modifiersDetail, any_modifier)) + return TRUE; return FALSE; } @@ -522,38 +484,33 @@ static Bool GrabsAreIdentical(GrabPtr pFirstGrab, GrabPtr pSecondGrab) { unsigned int any_modifier = (pFirstGrab->grabtype == XI2) ? - (unsigned int)XIAnyModifier : - (unsigned int)AnyModifier; + (unsigned int) XIAnyModifier : (unsigned int) AnyModifier; if (pFirstGrab->grabtype != pSecondGrab->grabtype) return FALSE; - if (pFirstGrab->device != pSecondGrab->device || - (pFirstGrab->modifierDevice != pSecondGrab->modifierDevice) || - (pFirstGrab->type != pSecondGrab->type)) - return FALSE; - - if (!(DetailSupersedesSecond(pFirstGrab->detail, - pSecondGrab->detail, - (unsigned int)AnyKey) && - DetailSupersedesSecond(pSecondGrab->detail, - pFirstGrab->detail, - (unsigned int)AnyKey))) + if (pFirstGrab->device != pSecondGrab->device || + (pFirstGrab->modifierDevice != pSecondGrab->modifierDevice) || + (pFirstGrab->type != pSecondGrab->type)) return FALSE; + if (!(DetailSupersedesSecond(pFirstGrab->detail, + pSecondGrab->detail, + (unsigned int) AnyKey) && + DetailSupersedesSecond(pSecondGrab->detail, + pFirstGrab->detail, (unsigned int) AnyKey))) + return FALSE; - if (!(DetailSupersedesSecond(pFirstGrab->modifiersDetail, - pSecondGrab->modifiersDetail, - any_modifier) && - DetailSupersedesSecond(pSecondGrab->modifiersDetail, - pFirstGrab->modifiersDetail, - any_modifier))) + if (!(DetailSupersedesSecond(pFirstGrab->modifiersDetail, + pSecondGrab->modifiersDetail, + any_modifier) && + DetailSupersedesSecond(pSecondGrab->modifiersDetail, + pFirstGrab->modifiersDetail, any_modifier))) return FALSE; return TRUE; } - /** * Prepend the new grab to the list of passive grabs on the window. * Any previously existing grab that matches the new grab will be removed. @@ -569,44 +526,39 @@ AddPassiveGrabToList(ClientPtr client, GrabPtr pGrab) Mask access_mode = DixGrabAccess; int rc; - for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next) - { - if (GrabMatchesSecond(pGrab, grab, (pGrab->grabtype == CORE))) - { - if (CLIENT_BITS(pGrab->resource) != CLIENT_BITS(grab->resource)) - { - FreeGrab(pGrab); - return BadAccess; - } - } + for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next) { + if (GrabMatchesSecond(pGrab, grab, (pGrab->grabtype == CORE))) { + if (CLIENT_BITS(pGrab->resource) != CLIENT_BITS(grab->resource)) { + FreeGrab(pGrab); + return BadAccess; + } + } } - if (pGrab->keyboardMode == GrabModeSync||pGrab->pointerMode == GrabModeSync) - access_mode |= DixFreezeAccess; + if (pGrab->keyboardMode == GrabModeSync || + pGrab->pointerMode == GrabModeSync) + access_mode |= DixFreezeAccess; rc = XaceHook(XACE_DEVICE_ACCESS, client, pGrab->device, access_mode); if (rc != Success) - return rc; + return rc; /* Remove all grabs that match the new one exactly */ - for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next) - { - if (GrabsAreIdentical(pGrab, grab)) - { + for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next) { + if (GrabsAreIdentical(pGrab, grab)) { DeletePassiveGrabFromList(grab); break; - } + } } - if (!pGrab->window->optional && !MakeWindowOptional (pGrab->window)) - { - FreeGrab(pGrab); - return BadAlloc; + if (!pGrab->window->optional && !MakeWindowOptional(pGrab->window)) { + FreeGrab(pGrab); + return BadAlloc; } pGrab->next = pGrab->window->optional->passiveGrabs; pGrab->window->optional->passiveGrabs = pGrab; - if (AddResource(pGrab->resource, RT_PASSIVEGRAB, (pointer)pGrab)) - return Success; + if (AddResource(pGrab->resource, RT_PASSIVEGRAB, (pointer) pGrab)) + return Success; return BadAlloc; } @@ -633,58 +585,50 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab) i = 0; for (grab = wPassiveGrabs(pMinuendGrab->window); grab; grab = grab->next) - i++; + i++; if (!i) - return TRUE; + return TRUE; deletes = malloc(i * sizeof(GrabPtr)); adds = malloc(i * sizeof(GrabPtr)); updates = malloc(i * sizeof(Mask **)); details = malloc(i * sizeof(Mask *)); - if (!deletes || !adds || !updates || !details) - { - free(details); - free(updates); - free(adds); - free(deletes); - return FALSE; + if (!deletes || !adds || !updates || !details) { + free(details); + free(updates); + free(adds); + free(deletes); + return FALSE; } any_modifier = (pMinuendGrab->grabtype == XI2) ? - (unsigned int)XIAnyModifier : (unsigned int)AnyModifier; + (unsigned int) XIAnyModifier : (unsigned int) AnyModifier; any_key = (pMinuendGrab->grabtype == XI2) ? - (unsigned int)XIAnyKeycode : (unsigned int)AnyKey; + (unsigned int) XIAnyKeycode : (unsigned int) AnyKey; ndels = nadds = nups = 0; ok = TRUE; for (grab = wPassiveGrabs(pMinuendGrab->window); - grab && ok; - grab = grab->next) - { - if ((CLIENT_BITS(grab->resource) != CLIENT_BITS(pMinuendGrab->resource)) || - !GrabMatchesSecond(grab, pMinuendGrab, - (grab->grabtype == CORE))) - continue; - if (GrabSupersedesSecond(pMinuendGrab, grab)) - { - deletes[ndels++] = grab; - } - else if ((grab->detail.exact == any_key) - && (grab->modifiersDetail.exact != any_modifier)) - { - UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact); - } - else if ((grab->modifiersDetail.exact == any_modifier) - && (grab->detail.exact != any_key)) - { - UPDATE(grab->modifiersDetail.pMask, - pMinuendGrab->modifiersDetail.exact); - } - else if ((pMinuendGrab->detail.exact != any_key) - && (pMinuendGrab->modifiersDetail.exact != any_modifier)) - { - GrabPtr pNewGrab; + grab && ok; grab = grab->next) { + if ((CLIENT_BITS(grab->resource) != CLIENT_BITS(pMinuendGrab->resource)) + || !GrabMatchesSecond(grab, pMinuendGrab, (grab->grabtype == CORE))) + continue; + if (GrabSupersedesSecond(pMinuendGrab, grab)) { + deletes[ndels++] = grab; + } + else if ((grab->detail.exact == any_key) + && (grab->modifiersDetail.exact != any_modifier)) { + UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact); + } + else if ((grab->modifiersDetail.exact == any_modifier) + && (grab->detail.exact != any_key)) { + UPDATE(grab->modifiersDetail.pMask, + pMinuendGrab->modifiersDetail.exact); + } + else if ((pMinuendGrab->detail.exact != any_key) + && (pMinuendGrab->modifiersDetail.exact != any_modifier)) { + GrabPtr pNewGrab; GrabParameters param; - UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact); + UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact); memset(¶m, 0, sizeof(param)); param.ownerEvents = grab->ownerEvents; @@ -692,64 +636,57 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab) param.other_devices_mode = grab->pointerMode; param.modifiers = any_modifier; - pNewGrab = CreateGrab(CLIENT_ID(grab->resource), grab->device, - grab->modifierDevice, grab->window, + pNewGrab = CreateGrab(CLIENT_ID(grab->resource), grab->device, + grab->modifierDevice, grab->window, grab->grabtype, - (GrabMask*)&grab->eventMask, - ¶m, (int)grab->type, - pMinuendGrab->detail.exact, - grab->confineTo, grab->cursor); - if (!pNewGrab) - ok = FALSE; - else if (!(pNewGrab->modifiersDetail.pMask = - DeleteDetailFromMask(grab->modifiersDetail.pMask, - pMinuendGrab->modifiersDetail.exact)) - || - (!pNewGrab->window->optional && - !MakeWindowOptional(pNewGrab->window))) - { - FreeGrab(pNewGrab); - ok = FALSE; - } - else if (!AddResource(pNewGrab->resource, RT_PASSIVEGRAB, - (pointer)pNewGrab)) - ok = FALSE; - else - adds[nadds++] = pNewGrab; - } - else if (pMinuendGrab->detail.exact == any_key) - { - UPDATE(grab->modifiersDetail.pMask, - pMinuendGrab->modifiersDetail.exact); - } - else - { - UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact); - } + (GrabMask *) &grab->eventMask, + ¶m, (int) grab->type, + pMinuendGrab->detail.exact, + grab->confineTo, grab->cursor); + if (!pNewGrab) + ok = FALSE; + else if (!(pNewGrab->modifiersDetail.pMask = + DeleteDetailFromMask(grab->modifiersDetail.pMask, + pMinuendGrab->modifiersDetail. + exact)) + || (!pNewGrab->window->optional && + !MakeWindowOptional(pNewGrab->window))) { + FreeGrab(pNewGrab); + ok = FALSE; + } + else if (!AddResource(pNewGrab->resource, RT_PASSIVEGRAB, + (pointer) pNewGrab)) + ok = FALSE; + else + adds[nadds++] = pNewGrab; + } + else if (pMinuendGrab->detail.exact == any_key) { + UPDATE(grab->modifiersDetail.pMask, + pMinuendGrab->modifiersDetail.exact); + } + else { + UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact); + } } - if (!ok) - { - for (i = 0; i < nadds; i++) - FreeResource(adds[i]->resource, RT_NONE); - for (i = 0; i < nups; i++) - free(details[i]); + if (!ok) { + for (i = 0; i < nadds; i++) + FreeResource(adds[i]->resource, RT_NONE); + for (i = 0; i < nups; i++) + free(details[i]); } - else - { - for (i = 0; i < ndels; i++) - FreeResource(deletes[i]->resource, RT_NONE); - for (i = 0; i < nadds; i++) - { - grab = adds[i]; - grab->next = grab->window->optional->passiveGrabs; - grab->window->optional->passiveGrabs = grab; - } - for (i = 0; i < nups; i++) - { - free(*updates[i]); - *updates[i] = details[i]; - } + else { + for (i = 0; i < ndels; i++) + FreeResource(deletes[i]->resource, RT_NONE); + for (i = 0; i < nadds; i++) { + grab = adds[i]; + grab->next = grab->window->optional->passiveGrabs; + grab->window->optional->passiveGrabs = grab; + } + for (i = 0; i < nups; i++) { + free(*updates[i]); + *updates[i] = details[i]; + } } free(details); free(updates); @@ -764,14 +701,12 @@ Bool GrabIsPointerGrab(GrabPtr grab) { return (grab->type == ButtonPress || - grab->type == DeviceButtonPress || - grab->type == XI_ButtonPress); + grab->type == DeviceButtonPress || grab->type == XI_ButtonPress); } Bool GrabIsKeyboardGrab(GrabPtr grab) { - return (grab->type == KeyPress || - grab->type == DeviceKeyPress || - grab->type == XI_KeyPress); + return (grab->type == KeyPress || + grab->type == DeviceKeyPress || grab->type == XI_KeyPress); } diff --git a/xorg-server/dix/initatoms.c b/xorg-server/dix/initatoms.c index de101bd0f..bcc38a0f1 100644 --- a/xorg-server/dix/initatoms.c +++ b/xorg-server/dix/initatoms.c @@ -11,74 +11,143 @@ #include <X11/Xatom.h> #include "misc.h" #include "dix.h" -void MakePredeclaredAtoms(void) +void +MakePredeclaredAtoms(void) { - if (MakeAtom("PRIMARY", 7, 1) != XA_PRIMARY) AtomError(); - if (MakeAtom("SECONDARY", 9, 1) != XA_SECONDARY) AtomError(); - if (MakeAtom("ARC", 3, 1) != XA_ARC) AtomError(); - if (MakeAtom("ATOM", 4, 1) != XA_ATOM) AtomError(); - if (MakeAtom("BITMAP", 6, 1) != XA_BITMAP) AtomError(); - if (MakeAtom("CARDINAL", 8, 1) != XA_CARDINAL) AtomError(); - if (MakeAtom("COLORMAP", 8, 1) != XA_COLORMAP) AtomError(); - if (MakeAtom("CURSOR", 6, 1) != XA_CURSOR) AtomError(); - if (MakeAtom("CUT_BUFFER0", 11, 1) != XA_CUT_BUFFER0) AtomError(); - if (MakeAtom("CUT_BUFFER1", 11, 1) != XA_CUT_BUFFER1) AtomError(); - if (MakeAtom("CUT_BUFFER2", 11, 1) != XA_CUT_BUFFER2) AtomError(); - if (MakeAtom("CUT_BUFFER3", 11, 1) != XA_CUT_BUFFER3) AtomError(); - if (MakeAtom("CUT_BUFFER4", 11, 1) != XA_CUT_BUFFER4) AtomError(); - if (MakeAtom("CUT_BUFFER5", 11, 1) != XA_CUT_BUFFER5) AtomError(); - if (MakeAtom("CUT_BUFFER6", 11, 1) != XA_CUT_BUFFER6) AtomError(); - if (MakeAtom("CUT_BUFFER7", 11, 1) != XA_CUT_BUFFER7) AtomError(); - if (MakeAtom("DRAWABLE", 8, 1) != XA_DRAWABLE) AtomError(); - if (MakeAtom("FONT", 4, 1) != XA_FONT) AtomError(); - if (MakeAtom("INTEGER", 7, 1) != XA_INTEGER) AtomError(); - if (MakeAtom("PIXMAP", 6, 1) != XA_PIXMAP) AtomError(); - if (MakeAtom("POINT", 5, 1) != XA_POINT) AtomError(); - if (MakeAtom("RECTANGLE", 9, 1) != XA_RECTANGLE) AtomError(); - if (MakeAtom("RESOURCE_MANAGER", 16, 1) != XA_RESOURCE_MANAGER) AtomError(); - if (MakeAtom("RGB_COLOR_MAP", 13, 1) != XA_RGB_COLOR_MAP) AtomError(); - if (MakeAtom("RGB_BEST_MAP", 12, 1) != XA_RGB_BEST_MAP) AtomError(); - if (MakeAtom("RGB_BLUE_MAP", 12, 1) != XA_RGB_BLUE_MAP) AtomError(); - if (MakeAtom("RGB_DEFAULT_MAP", 15, 1) != XA_RGB_DEFAULT_MAP) AtomError(); - if (MakeAtom("RGB_GRAY_MAP", 12, 1) != XA_RGB_GRAY_MAP) AtomError(); - if (MakeAtom("RGB_GREEN_MAP", 13, 1) != XA_RGB_GREEN_MAP) AtomError(); - if (MakeAtom("RGB_RED_MAP", 11, 1) != XA_RGB_RED_MAP) AtomError(); - if (MakeAtom("STRING", 6, 1) != XA_STRING) AtomError(); - if (MakeAtom("VISUALID", 8, 1) != XA_VISUALID) AtomError(); - if (MakeAtom("WINDOW", 6, 1) != XA_WINDOW) AtomError(); - if (MakeAtom("WM_COMMAND", 10, 1) != XA_WM_COMMAND) AtomError(); - if (MakeAtom("WM_HINTS", 8, 1) != XA_WM_HINTS) AtomError(); - if (MakeAtom("WM_CLIENT_MACHINE", 17, 1) != XA_WM_CLIENT_MACHINE) AtomError(); - if (MakeAtom("WM_ICON_NAME", 12, 1) != XA_WM_ICON_NAME) AtomError(); - if (MakeAtom("WM_ICON_SIZE", 12, 1) != XA_WM_ICON_SIZE) AtomError(); - if (MakeAtom("WM_NAME", 7, 1) != XA_WM_NAME) AtomError(); - if (MakeAtom("WM_NORMAL_HINTS", 15, 1) != XA_WM_NORMAL_HINTS) AtomError(); - if (MakeAtom("WM_SIZE_HINTS", 13, 1) != XA_WM_SIZE_HINTS) AtomError(); - if (MakeAtom("WM_ZOOM_HINTS", 13, 1) != XA_WM_ZOOM_HINTS) AtomError(); - if (MakeAtom("MIN_SPACE", 9, 1) != XA_MIN_SPACE) AtomError(); - if (MakeAtom("NORM_SPACE", 10, 1) != XA_NORM_SPACE) AtomError(); - if (MakeAtom("MAX_SPACE", 9, 1) != XA_MAX_SPACE) AtomError(); - if (MakeAtom("END_SPACE", 9, 1) != XA_END_SPACE) AtomError(); - if (MakeAtom("SUPERSCRIPT_X", 13, 1) != XA_SUPERSCRIPT_X) AtomError(); - if (MakeAtom("SUPERSCRIPT_Y", 13, 1) != XA_SUPERSCRIPT_Y) AtomError(); - if (MakeAtom("SUBSCRIPT_X", 11, 1) != XA_SUBSCRIPT_X) AtomError(); - if (MakeAtom("SUBSCRIPT_Y", 11, 1) != XA_SUBSCRIPT_Y) AtomError(); - if (MakeAtom("UNDERLINE_POSITION", 18, 1) != XA_UNDERLINE_POSITION) AtomError(); - if (MakeAtom("UNDERLINE_THICKNESS", 19, 1) != XA_UNDERLINE_THICKNESS) AtomError(); - if (MakeAtom("STRIKEOUT_ASCENT", 16, 1) != XA_STRIKEOUT_ASCENT) AtomError(); - if (MakeAtom("STRIKEOUT_DESCENT", 17, 1) != XA_STRIKEOUT_DESCENT) AtomError(); - if (MakeAtom("ITALIC_ANGLE", 12, 1) != XA_ITALIC_ANGLE) AtomError(); - if (MakeAtom("X_HEIGHT", 8, 1) != XA_X_HEIGHT) AtomError(); - if (MakeAtom("QUAD_WIDTH", 10, 1) != XA_QUAD_WIDTH) AtomError(); - if (MakeAtom("WEIGHT", 6, 1) != XA_WEIGHT) AtomError(); - if (MakeAtom("POINT_SIZE", 10, 1) != XA_POINT_SIZE) AtomError(); - if (MakeAtom("RESOLUTION", 10, 1) != XA_RESOLUTION) AtomError(); - if (MakeAtom("COPYRIGHT", 9, 1) != XA_COPYRIGHT) AtomError(); - if (MakeAtom("NOTICE", 6, 1) != XA_NOTICE) AtomError(); - if (MakeAtom("FONT_NAME", 9, 1) != XA_FONT_NAME) AtomError(); - if (MakeAtom("FAMILY_NAME", 11, 1) != XA_FAMILY_NAME) AtomError(); - if (MakeAtom("FULL_NAME", 9, 1) != XA_FULL_NAME) AtomError(); - if (MakeAtom("CAP_HEIGHT", 10, 1) != XA_CAP_HEIGHT) AtomError(); - if (MakeAtom("WM_CLASS", 8, 1) != XA_WM_CLASS) AtomError(); - if (MakeAtom("WM_TRANSIENT_FOR", 16, 1) != XA_WM_TRANSIENT_FOR) AtomError(); + if (MakeAtom("PRIMARY", 7, 1) != XA_PRIMARY) + AtomError(); + if (MakeAtom("SECONDARY", 9, 1) != XA_SECONDARY) + AtomError(); + if (MakeAtom("ARC", 3, 1) != XA_ARC) + AtomError(); + if (MakeAtom("ATOM", 4, 1) != XA_ATOM) + AtomError(); + if (MakeAtom("BITMAP", 6, 1) != XA_BITMAP) + AtomError(); + if (MakeAtom("CARDINAL", 8, 1) != XA_CARDINAL) + AtomError(); + if (MakeAtom("COLORMAP", 8, 1) != XA_COLORMAP) + AtomError(); + if (MakeAtom("CURSOR", 6, 1) != XA_CURSOR) + AtomError(); + if (MakeAtom("CUT_BUFFER0", 11, 1) != XA_CUT_BUFFER0) + AtomError(); + if (MakeAtom("CUT_BUFFER1", 11, 1) != XA_CUT_BUFFER1) + AtomError(); + if (MakeAtom("CUT_BUFFER2", 11, 1) != XA_CUT_BUFFER2) + AtomError(); + if (MakeAtom("CUT_BUFFER3", 11, 1) != XA_CUT_BUFFER3) + AtomError(); + if (MakeAtom("CUT_BUFFER4", 11, 1) != XA_CUT_BUFFER4) + AtomError(); + if (MakeAtom("CUT_BUFFER5", 11, 1) != XA_CUT_BUFFER5) + AtomError(); + if (MakeAtom("CUT_BUFFER6", 11, 1) != XA_CUT_BUFFER6) + AtomError(); + if (MakeAtom("CUT_BUFFER7", 11, 1) != XA_CUT_BUFFER7) + AtomError(); + if (MakeAtom("DRAWABLE", 8, 1) != XA_DRAWABLE) + AtomError(); + if (MakeAtom("FONT", 4, 1) != XA_FONT) + AtomError(); + if (MakeAtom("INTEGER", 7, 1) != XA_INTEGER) + AtomError(); + if (MakeAtom("PIXMAP", 6, 1) != XA_PIXMAP) + AtomError(); + if (MakeAtom("POINT", 5, 1) != XA_POINT) + AtomError(); + if (MakeAtom("RECTANGLE", 9, 1) != XA_RECTANGLE) + AtomError(); + if (MakeAtom("RESOURCE_MANAGER", 16, 1) != XA_RESOURCE_MANAGER) + AtomError(); + if (MakeAtom("RGB_COLOR_MAP", 13, 1) != XA_RGB_COLOR_MAP) + AtomError(); + if (MakeAtom("RGB_BEST_MAP", 12, 1) != XA_RGB_BEST_MAP) + AtomError(); + if (MakeAtom("RGB_BLUE_MAP", 12, 1) != XA_RGB_BLUE_MAP) + AtomError(); + if (MakeAtom("RGB_DEFAULT_MAP", 15, 1) != XA_RGB_DEFAULT_MAP) + AtomError(); + if (MakeAtom("RGB_GRAY_MAP", 12, 1) != XA_RGB_GRAY_MAP) + AtomError(); + if (MakeAtom("RGB_GREEN_MAP", 13, 1) != XA_RGB_GREEN_MAP) + AtomError(); + if (MakeAtom("RGB_RED_MAP", 11, 1) != XA_RGB_RED_MAP) + AtomError(); + if (MakeAtom("STRING", 6, 1) != XA_STRING) + AtomError(); + if (MakeAtom("VISUALID", 8, 1) != XA_VISUALID) + AtomError(); + if (MakeAtom("WINDOW", 6, 1) != XA_WINDOW) + AtomError(); + if (MakeAtom("WM_COMMAND", 10, 1) != XA_WM_COMMAND) + AtomError(); + if (MakeAtom("WM_HINTS", 8, 1) != XA_WM_HINTS) + AtomError(); + if (MakeAtom("WM_CLIENT_MACHINE", 17, 1) != XA_WM_CLIENT_MACHINE) + AtomError(); + if (MakeAtom("WM_ICON_NAME", 12, 1) != XA_WM_ICON_NAME) + AtomError(); + if (MakeAtom("WM_ICON_SIZE", 12, 1) != XA_WM_ICON_SIZE) + AtomError(); + if (MakeAtom("WM_NAME", 7, 1) != XA_WM_NAME) + AtomError(); + if (MakeAtom("WM_NORMAL_HINTS", 15, 1) != XA_WM_NORMAL_HINTS) + AtomError(); + if (MakeAtom("WM_SIZE_HINTS", 13, 1) != XA_WM_SIZE_HINTS) + AtomError(); + if (MakeAtom("WM_ZOOM_HINTS", 13, 1) != XA_WM_ZOOM_HINTS) + AtomError(); + if (MakeAtom("MIN_SPACE", 9, 1) != XA_MIN_SPACE) + AtomError(); + if (MakeAtom("NORM_SPACE", 10, 1) != XA_NORM_SPACE) + AtomError(); + if (MakeAtom("MAX_SPACE", 9, 1) != XA_MAX_SPACE) + AtomError(); + if (MakeAtom("END_SPACE", 9, 1) != XA_END_SPACE) + AtomError(); + if (MakeAtom("SUPERSCRIPT_X", 13, 1) != XA_SUPERSCRIPT_X) + AtomError(); + if (MakeAtom("SUPERSCRIPT_Y", 13, 1) != XA_SUPERSCRIPT_Y) + AtomError(); + if (MakeAtom("SUBSCRIPT_X", 11, 1) != XA_SUBSCRIPT_X) + AtomError(); + if (MakeAtom("SUBSCRIPT_Y", 11, 1) != XA_SUBSCRIPT_Y) + AtomError(); + if (MakeAtom("UNDERLINE_POSITION", 18, 1) != XA_UNDERLINE_POSITION) + AtomError(); + if (MakeAtom("UNDERLINE_THICKNESS", 19, 1) != XA_UNDERLINE_THICKNESS) + AtomError(); + if (MakeAtom("STRIKEOUT_ASCENT", 16, 1) != XA_STRIKEOUT_ASCENT) + AtomError(); + if (MakeAtom("STRIKEOUT_DESCENT", 17, 1) != XA_STRIKEOUT_DESCENT) + AtomError(); + if (MakeAtom("ITALIC_ANGLE", 12, 1) != XA_ITALIC_ANGLE) + AtomError(); + if (MakeAtom("X_HEIGHT", 8, 1) != XA_X_HEIGHT) + AtomError(); + if (MakeAtom("QUAD_WIDTH", 10, 1) != XA_QUAD_WIDTH) + AtomError(); + if (MakeAtom("WEIGHT", 6, 1) != XA_WEIGHT) + AtomError(); + if (MakeAtom("POINT_SIZE", 10, 1) != XA_POINT_SIZE) + AtomError(); + if (MakeAtom("RESOLUTION", 10, 1) != XA_RESOLUTION) + AtomError(); + if (MakeAtom("COPYRIGHT", 9, 1) != XA_COPYRIGHT) + AtomError(); + if (MakeAtom("NOTICE", 6, 1) != XA_NOTICE) + AtomError(); + if (MakeAtom("FONT_NAME", 9, 1) != XA_FONT_NAME) + AtomError(); + if (MakeAtom("FAMILY_NAME", 11, 1) != XA_FAMILY_NAME) + AtomError(); + if (MakeAtom("FULL_NAME", 9, 1) != XA_FULL_NAME) + AtomError(); + if (MakeAtom("CAP_HEIGHT", 10, 1) != XA_CAP_HEIGHT) + AtomError(); + if (MakeAtom("WM_CLASS", 8, 1) != XA_WM_CLASS) + AtomError(); + if (MakeAtom("WM_TRANSIENT_FOR", 16, 1) != XA_WM_TRANSIENT_FOR) + AtomError(); } diff --git a/xorg-server/dix/inpututils.c b/xorg-server/dix/inpututils.c index 9e0c5518c..223d547c5 100644 --- a/xorg-server/dix/inpututils.c +++ b/xorg-server/dix/inpututils.c @@ -48,15 +48,13 @@ check_butmap_change(DeviceIntPtr dev, CARD8 *map, int len, CARD32 *errval_out, { int i, ret; - if (!dev || !dev->button) - { + if (!dev || !dev->button) { client->errorValue = (dev) ? dev->id : 0; return BadDevice; } ret = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixManageAccess); - if (ret != Success) - { + if (ret != Success) { client->errorValue = dev->id; return ret; } @@ -207,9 +205,9 @@ check_modmap_change_slave(ClientPtr client, DeviceIntPtr master, * extended keyboard, ignore the whole remap request. */ for (j = 0; j < XkbKeyNumSyms(slave_xkb, i) && - j < XkbKeyNumSyms(master_xkb, i); - j++) - if (XkbKeySymsPtr(slave_xkb, i)[j] != XkbKeySymsPtr(master_xkb, i)[j]) + j < XkbKeyNumSyms(master_xkb, i); j++) + if (XkbKeySymsPtr(slave_xkb, i)[j] != + XkbKeySymsPtr(master_xkb, i)[j]) return 0; } @@ -227,8 +225,9 @@ do_modmap_change(ClientPtr client, DeviceIntPtr dev, CARD8 *modmap) } /* Rebuild modmap (key -> mod) from map (mod -> key). */ -static int build_modmap_from_modkeymap(CARD8 *modmap, KeyCode *modkeymap, - int max_keys_per_mod) +static int +build_modmap_from_modkeymap(CARD8 *modmap, KeyCode *modkeymap, + int max_keys_per_mod) { int i, len = max_keys_per_mod * 8; @@ -276,7 +275,8 @@ change_modmap(ClientPtr client, DeviceIntPtr dev, KeyCode *modkeymap, do_modmap_change(client, tmp, modmap); } } - else if (!IsFloating(dev) && GetMaster(dev, MASTER_KEYBOARD)->lastSlave == dev) { + else if (!IsFloating(dev) && + GetMaster(dev, MASTER_KEYBOARD)->lastSlave == dev) { /* If this fails, expect the results to be weird. */ if (check_modmap_change(client, dev->master, modmap)) do_modmap_change(client, dev->master, modmap); @@ -285,8 +285,9 @@ change_modmap(ClientPtr client, DeviceIntPtr dev, KeyCode *modkeymap, return Success; } -int generate_modkeymap(ClientPtr client, DeviceIntPtr dev, - KeyCode **modkeymap_out, int *max_keys_per_mod_out) +int +generate_modkeymap(ClientPtr client, DeviceIntPtr dev, + KeyCode **modkeymap_out, int *max_keys_per_mod_out) { CARD8 keys_per_mod[8]; int max_keys_per_mod; @@ -344,8 +345,8 @@ int generate_modkeymap(ClientPtr client, DeviceIntPtr dev, * flexibility with the data. Drivers should be able to call realloc on the * product string if needed and perform similar operations. */ -InputAttributes* -DuplicateInputAttributes(InputAttributes *attrs) +InputAttributes * +DuplicateInputAttributes(InputAttributes * attrs) { InputAttributes *new_attr; int ntags = 0; @@ -370,20 +371,18 @@ DuplicateInputAttributes(InputAttributes *attrs) new_attr->flags = attrs->flags; - if ((tags = attrs->tags)) - { - while(*tags++) + if ((tags = attrs->tags)) { + while (*tags++) ntags++; - new_attr->tags = calloc(ntags + 1, sizeof(char*)); + new_attr->tags = calloc(ntags + 1, sizeof(char *)); if (!new_attr->tags) goto unwind; tags = attrs->tags; new_tags = new_attr->tags; - while(*tags) - { + while (*tags) { *new_tags = strdup(*tags); if (!*new_tags) goto unwind; @@ -395,13 +394,13 @@ DuplicateInputAttributes(InputAttributes *attrs) return new_attr; -unwind: + unwind: FreeInputAttributes(new_attr); return NULL; } void -FreeInputAttributes(InputAttributes *attrs) +FreeInputAttributes(InputAttributes * attrs) { char **tags; @@ -415,7 +414,7 @@ FreeInputAttributes(InputAttributes *attrs) free(attrs->usb_id); if ((tags = attrs->tags)) - while(*tags) + while (*tags) free(*tags++); free(attrs->tags); @@ -425,13 +424,14 @@ FreeInputAttributes(InputAttributes *attrs) /** * Alloc a valuator mask large enough for num_valuators. */ -ValuatorMask* +ValuatorMask * valuator_mask_new(int num_valuators) { /* alloc a fixed size mask for now and ignore num_valuators. in the * flying-car future, when we can dynamically alloc the masks and are * not constrained by signals, we can start using num_valuators */ ValuatorMask *mask = calloc(1, sizeof(ValuatorMask)); + if (mask == NULL) return NULL; @@ -446,20 +446,20 @@ valuator_mask_free(ValuatorMask **mask) *mask = NULL; } - /** * Sets a range of valuators between first_valuator and num_valuators with * the data in the valuators array. All other values are set to 0. */ void -valuator_mask_set_range(ValuatorMask *mask, int first_valuator, int num_valuators, - const int* valuators) +valuator_mask_set_range(ValuatorMask *mask, int first_valuator, + int num_valuators, const int *valuators) { int i; valuator_mask_zero(mask); - for (i = first_valuator; i < min(first_valuator + num_valuators, MAX_VALUATORS); i++) + for (i = first_valuator; + i < min(first_valuator + num_valuators, MAX_VALUATORS); i++) valuator_mask_set(mask, i, valuators[i - first_valuator]); } @@ -550,13 +550,14 @@ valuator_mask_get(const ValuatorMask *mask, int valuator) * FALSE is returned. */ Bool -valuator_mask_fetch_double(const ValuatorMask *mask, int valuator, double *value) +valuator_mask_fetch_double(const ValuatorMask *mask, int valuator, + double *value) { - if (valuator_mask_isset(mask, valuator)) - { + if (valuator_mask_isset(mask, valuator)) { *value = valuator_mask_get_double(mask, valuator); return TRUE; - } else + } + else return FALSE; } @@ -570,11 +571,11 @@ valuator_mask_fetch_double(const ValuatorMask *mask, int valuator, double *value Bool valuator_mask_fetch(const ValuatorMask *mask, int valuator, int *value) { - if (valuator_mask_isset(mask, valuator)) - { + if (valuator_mask_isset(mask, valuator)) { *value = valuator_mask_get(mask, valuator); return TRUE; - } else + } + else return FALSE; } @@ -607,7 +608,7 @@ valuator_mask_copy(ValuatorMask *dest, const ValuatorMask *src) } int -CountBits(const uint8_t *mask, int len) +CountBits(const uint8_t * mask, int len) { int i; int ret = 0; @@ -624,17 +625,16 @@ CountBits(const uint8_t *mask, int len) * memdumps the first 32 bytes of event to the log, a backtrace, then kill * the server. */ -void verify_internal_event(const InternalEvent *ev) +void +verify_internal_event(const InternalEvent *ev) { - if (ev && ev->any.header != ET_Internal) - { + if (ev && ev->any.header != ET_Internal) { int i; - const unsigned char *data = (const unsigned char*)ev; + const unsigned char *data = (const unsigned char *) ev; ErrorF("dix: invalid event type %d\n", ev->any.header); - for (i = 0; i < sizeof(xEvent); i++, data++) - { + for (i = 0; i < sizeof(xEvent); i++, data++) { ErrorF("%02hhx ", *data); if ((i % 8) == 7) @@ -650,7 +650,8 @@ void verify_internal_event(const InternalEvent *ev) * Initializes the given event to zero (or default values), for the given * device. */ -void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms) +void +init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms) { memset(event, 0, sizeof(DeviceEvent)); event->header = ET_Internal; @@ -660,18 +661,23 @@ void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms) event->sourceid = dev->id; } -int event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd) +int +event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd) { int corestate; + /* core state needs to be assembled BEFORE the device is updated. */ - corestate = (kbd && kbd->key) ? XkbStateFieldFromRec(&kbd->key->xkbInfo->state) : 0; + corestate = (kbd && + kbd->key) ? XkbStateFieldFromRec(&kbd->key->xkbInfo-> + state) : 0; corestate |= (mouse && mouse->button) ? (mouse->button->state) : 0; corestate |= (mouse && mouse->touch) ? (mouse->touch->state) : 0; return corestate; } -void event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event) +void +event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event) { int i; @@ -682,9 +688,9 @@ void event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event) if (mouse && mouse->touch && mouse->touch->buttonsDown > 0) SetBit(event->buttons, mouse->button->map[1]); - if (kbd && kbd->key) - { + if (kbd && kbd->key) { XkbStatePtr state; + /* we need the state before the event happens */ if (event->type == ET_KeyPress || event->type == ET_KeyRelease) state = &kbd->key->xkbInfo->prev_state; @@ -727,7 +733,7 @@ Bool point_on_screen(ScreenPtr pScreen, int x, int y) { return x >= pScreen->x && x < pScreen->x + pScreen->width && - y >= pScreen->y && y < pScreen->y + pScreen->height; + y >= pScreen->y && y < pScreen->y + pScreen->height; } /** @@ -737,11 +743,12 @@ void update_desktop_dimensions(void) { int i; - int x1 = INT_MAX, y1 = INT_MAX; /* top-left */ - int x2 = INT_MIN, y2 = INT_MIN; /* bottom-right */ + int x1 = INT_MAX, y1 = INT_MAX; /* top-left */ + int x2 = INT_MIN, y2 = INT_MIN; /* bottom-right */ for (i = 0; i < screenInfo.numScreens; i++) { ScreenPtr screen = screenInfo.screens[i]; + x1 = min(x1, screen->x); y1 = min(y1, screen->y); x2 = max(x2, screen->x + screen->width); @@ -783,20 +790,17 @@ input_option_free(InputOption *o) * is NULL, a new option list with one element. On failure, NULL is * returned. */ -InputOption* -input_option_new(InputOption* list, const char *key, const char *value) +InputOption * +input_option_new(InputOption *list, const char *key, const char *value) { InputOption *opt = NULL; if (!key) return NULL; - if (list) - { - nt_list_for_each_entry(opt, list, list.next) - { - if (strcmp(input_option_get_key(opt), key) == 0) - { + if (list) { + nt_list_for_each_entry(opt, list, list.next) { + if (strcmp(input_option_get_key(opt), key) == 0) { input_option_set_value(opt, value); return list; } @@ -811,15 +815,16 @@ input_option_new(InputOption* list, const char *key, const char *value) input_option_set_key(opt, key); input_option_set_value(opt, value); - if (list) - { + if (list) { nt_list_append(opt, list, InputOption, list.next); + return list; - } else + } + else return opt; } -InputOption* +InputOption * input_option_free_element(InputOption *list, const char *key) { InputOption *element; @@ -827,6 +832,7 @@ input_option_free_element(InputOption *list, const char *key) nt_list_for_each_entry(element, list, list.next) { if (strcmp(input_option_get_key(element), key) == 0) { nt_list_del(element, list, InputOption, list.next); + input_option_free(element); break; } @@ -844,18 +850,18 @@ input_option_free_list(InputOption **opt) nt_list_for_each_entry_safe(element, tmp, *opt, list.next) { nt_list_del(element, *opt, InputOption, list.next); + input_option_free(element); } *opt = NULL; } - /** * Find the InputOption with the given option name. * * @return The InputOption or NULL if not present. */ -InputOption* +InputOption * input_option_find(InputOption *list, const char *key) { InputOption *element; @@ -868,13 +874,13 @@ input_option_find(InputOption *list, const char *key) return NULL; } -const char* +const char * input_option_get_key(const InputOption *opt) { return opt->opt_name; } -const char* +const char * input_option_get_value(const InputOption *opt) { return opt->opt_val; @@ -896,7 +902,6 @@ input_option_set_value(InputOption *opt, const char *value) opt->opt_val = strdup(value); } - /* FP1616/FP3232 conversion functions. * Fixed point types are encoded as signed integral and unsigned frac. So any * negative number -n.m is encoded as floor(n) + (1 - 0.m). @@ -906,8 +911,8 @@ fp1616_to_double(FP1616 in) { double ret; - ret = (double)(in >> 16); - ret += (double)(in & 0xffff) * (1.0 / (1UL << 16)); /* Optimized: ldexp((double)(in & 0xffff), -16); */ + ret = (double) (in >> 16); + ret += (double) (in & 0xffff) * (1.0 / (1UL << 16)); /* Optimized: ldexp((double)(in & 0xffff), -16); */ return ret; } @@ -915,12 +920,12 @@ double fp3232_to_double(FP3232 in) { double ret; - ret = (double)in.integral; - ret += (double)in.frac * (1.0 / (1ULL << 32)); /* Optimized: ldexp((double)in.frac, -32); */ + + ret = (double) in.integral; + ret += (double) in.frac * (1.0 / (1ULL << 32)); /* Optimized: ldexp((double)in.frac, -32); */ return ret; } - FP1616 double_to_fp1616(double in) { @@ -930,10 +935,10 @@ double_to_fp1616(double in) uint32_t frac_d; tmp = floor(in); - integral = (int32_t)tmp; + integral = (int32_t) tmp; - tmp = (in - integral) * (1UL << 16); /* Optimized: ldexp(in - integral, 16) */ - frac_d = (uint16_t)tmp; + tmp = (in - integral) * (1UL << 16); /* Optimized: ldexp(in - integral, 16) */ + frac_d = (uint16_t) tmp; ret = integral << 16; ret |= frac_d & 0xffff; @@ -949,10 +954,10 @@ double_to_fp3232(double in) uint32_t frac_d; tmp = floor(in); - integral = (int32_t)tmp; + integral = (int32_t) tmp; - tmp = (in - integral) * (1ULL << 32); /* Optimized: ldexp(in - integral, 32) */ - frac_d = (uint32_t)tmp; + tmp = (in - integral) * (1ULL << 32); /* Optimized: ldexp(in - integral, 32) */ + frac_d = (uint32_t) tmp; ret.integral = integral; ret.frac = frac_d; @@ -967,16 +972,16 @@ double_to_fp3232(double in) * @param size The size of the masks in bytes * @return The new mask or NULL on allocation error. */ -XI2Mask* +XI2Mask * xi2mask_new_with_size(size_t nmasks, size_t size) { int i; XI2Mask *mask = calloc(1, sizeof(*mask)); + if (!mask) return NULL; - mask->nmasks = nmasks; mask->mask_size = size; @@ -991,19 +996,18 @@ xi2mask_new_with_size(size_t nmasks, size_t size) } return mask; -unwind: + unwind: xi2mask_free(&mask); return NULL; } - /** * Create a new XI2 mask of the standard size, i.e. for all devices + fake * devices and for the highest supported XI2 event type. * * @return The new mask or NULL on allocation error. */ -XI2Mask* +XI2Mask * xi2mask_new(void) { return xi2mask_new_with_size(EMASKSIZE, XI2MASKSIZE); @@ -1013,7 +1017,7 @@ xi2mask_new(void) * Frees memory associated with mask and resets mask to NULL. */ void -xi2mask_free(XI2Mask** mask) +xi2mask_free(XI2Mask **mask) { int i; @@ -1034,7 +1038,7 @@ xi2mask_free(XI2Mask** mask) * @return TRUE if the bit is set, FALSE otherwise */ Bool -xi2mask_isset(XI2Mask* mask, const DeviceIntPtr dev, int event_type) +xi2mask_isset(XI2Mask *mask, const DeviceIntPtr dev, int event_type) { int set = 0; @@ -1042,11 +1046,11 @@ xi2mask_isset(XI2Mask* mask, const DeviceIntPtr dev, int event_type) BUG_WARN(dev->id >= mask->nmasks); BUG_WARN(bits_to_bytes(event_type + 1) > mask->mask_size); - set = !!BitIsOn(mask->masks[XIAllDevices], event_type); + set = ! !BitIsOn(mask->masks[XIAllDevices], event_type); if (!set) - set = !!BitIsOn(mask->masks[dev->id], event_type); + set = ! !BitIsOn(mask->masks[dev->id], event_type); if (!set && IsMaster(dev)) - set = !!BitIsOn(mask->masks[XIAllMasterDevices], event_type); + set = ! !BitIsOn(mask->masks[XIAllMasterDevices], event_type); return set; } @@ -1120,7 +1124,8 @@ xi2mask_mask_size(const XI2Mask *mask) * parts are copied. */ void -xi2mask_set_one_mask(XI2Mask *xi2mask, int deviceid, const unsigned char *mask, size_t mask_size) +xi2mask_set_one_mask(XI2Mask *xi2mask, int deviceid, const unsigned char *mask, + size_t mask_size) { BUG_WARN(deviceid < 0); BUG_WARN(deviceid >= xi2mask->nmasks); @@ -1131,7 +1136,7 @@ xi2mask_set_one_mask(XI2Mask *xi2mask, int deviceid, const unsigned char *mask, /** * Get a reference to the XI2mask for this particular device. */ -const unsigned char* +const unsigned char * xi2mask_get_one_mask(const XI2Mask *mask, int deviceid) { BUG_WARN(deviceid < 0); diff --git a/xorg-server/dix/main.c b/xorg-server/dix/main.c index 16575ceba..70dcc946e 100644 --- a/xorg-server/dix/main.c +++ b/xorg-server/dix/main.c @@ -22,7 +22,6 @@ 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 @@ -80,7 +79,7 @@ Equipment Corporation. #endif #include <X11/X.h> -#include <X11/Xos.h> /* for unistd.h */ +#include <X11/Xos.h> /* for unistd.h */ #include <X11/Xproto.h> #include <pixman.h> #include "scrnintstr.h" @@ -108,7 +107,7 @@ Equipment Corporation. #ifdef PANORAMIX #include "panoramiXsrv.h" #else -#include "dixevents.h" /* InitEvents() */ +#include "dixevents.h" /* InitEvents() */ #endif #ifdef DPMSExtension @@ -127,13 +126,15 @@ pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER; int dix_main(int argc, char *argv[], char *envp[]); -int dix_main(int argc, char *argv[], char *envp[]) +int +dix_main(int argc, char *argv[], char *envp[]) #else -int main(int argc, char *argv[], char *envp[]) +int +main(int argc, char *argv[], char *envp[]) #endif { - int i; - HWEventQueueType alwaysCheckForInput[2]; + int i; + HWEventQueueType alwaysCheckForInput[2]; display = "0"; @@ -149,211 +150,208 @@ int main(int argc, char *argv[], char *envp[]) alwaysCheckForInput[0] = 0; alwaysCheckForInput[1] = 1; - while(1) - { - serverGeneration++; - ScreenSaverTime = defaultScreenSaverTime; - ScreenSaverInterval = defaultScreenSaverInterval; - ScreenSaverBlanking = defaultScreenSaverBlanking; - ScreenSaverAllowExposures = defaultScreenSaverAllowExposures; + while (1) { + serverGeneration++; + ScreenSaverTime = defaultScreenSaverTime; + ScreenSaverInterval = defaultScreenSaverInterval; + ScreenSaverBlanking = defaultScreenSaverBlanking; + ScreenSaverAllowExposures = defaultScreenSaverAllowExposures; #ifdef DPMSExtension - DPMSStandbyTime = DPMSSuspendTime = DPMSOffTime = ScreenSaverTime; - DPMSEnabled = TRUE; - DPMSPowerLevel = 0; + DPMSStandbyTime = DPMSSuspendTime = DPMSOffTime = ScreenSaverTime; + DPMSEnabled = TRUE; + DPMSPowerLevel = 0; #endif - InitBlockAndWakeupHandlers(); - /* Perform any operating system dependent initializations you'd like */ - OsInit(); - if(serverGeneration == 1) - { - CreateWellKnownSockets(); - for (i=1; i<MAXCLIENTS; i++) - clients[i] = NullClient; - serverClient = calloc(sizeof(ClientRec), 1); - if (!serverClient) - FatalError("couldn't create server client"); - InitClient(serverClient, 0, (pointer)NULL); - } - else - ResetWellKnownSockets (); - clients[0] = serverClient; - currentMaxClients = 1; - - /* Initialize privates before first allocation */ - dixResetPrivates(); - - /* Initialize server client devPrivates, to be reallocated as - * more client privates are registered - */ - if (!dixAllocatePrivates(&serverClient->devPrivates, PRIVATE_CLIENT)) - FatalError("failed to create server client privates"); - - if (!InitClientResources(serverClient)) /* for root resources */ - FatalError("couldn't init server resources"); - - SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]); - screenInfo.numScreens = 0; - - InitAtoms(); - InitEvents(); - InitSelections(); - InitGlyphCaching(); - dixResetRegistry(); - ResetFontPrivateIndex(); - InitCallbackManager(); - InitOutput(&screenInfo, argc, argv); - - if (screenInfo.numScreens < 1) - FatalError("no screens found"); - InitExtensions(argc, argv); - - for (i = 0; i < screenInfo.numScreens; i++) - { - ScreenPtr pScreen = screenInfo.screens[i]; - if (!CreateScratchPixmapsForScreen(i)) - FatalError("failed to create scratch pixmaps"); - if (pScreen->CreateScreenResources && - !(*pScreen->CreateScreenResources)(pScreen)) - FatalError("failed to create screen resources"); - if (!CreateGCperDepth(i)) - FatalError("failed to create scratch GCs"); - if (!CreateDefaultStipple(i)) - FatalError("failed to create default stipple"); - if (!CreateRootWindow(pScreen)) - FatalError("failed to create root window"); - } - - InitFonts(); - if (SetDefaultFontPath(defaultFontPath) != Success) { - ErrorF("[dix] failed to set default font path '%s'", defaultFontPath); - } - if (!SetDefaultFont(defaultTextFont)) { - FatalError("could not open default font '%s'", defaultTextFont); - } - - if (!(rootCursor = CreateRootCursor(NULL, 0))) { - FatalError("could not open default cursor font '%s'", - defaultCursorFont); - } + InitBlockAndWakeupHandlers(); + /* Perform any operating system dependent initializations you'd like */ + OsInit(); + if (serverGeneration == 1) { + CreateWellKnownSockets(); + for (i = 1; i < MAXCLIENTS; i++) + clients[i] = NullClient; + serverClient = calloc(sizeof(ClientRec), 1); + if (!serverClient) + FatalError("couldn't create server client"); + InitClient(serverClient, 0, (pointer) NULL); + } + else + ResetWellKnownSockets(); + clients[0] = serverClient; + currentMaxClients = 1; + + /* Initialize privates before first allocation */ + dixResetPrivates(); + + /* Initialize server client devPrivates, to be reallocated as + * more client privates are registered + */ + if (!dixAllocatePrivates(&serverClient->devPrivates, PRIVATE_CLIENT)) + FatalError("failed to create server client privates"); + + if (!InitClientResources(serverClient)) /* for root resources */ + FatalError("couldn't init server resources"); + + SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]); + screenInfo.numScreens = 0; + + InitAtoms(); + InitEvents(); + InitSelections(); + InitGlyphCaching(); + dixResetRegistry(); + ResetFontPrivateIndex(); + InitCallbackManager(); + InitOutput(&screenInfo, argc, argv); + + if (screenInfo.numScreens < 1) + FatalError("no screens found"); + InitExtensions(argc, argv); + + for (i = 0; i < screenInfo.numScreens; i++) { + ScreenPtr pScreen = screenInfo.screens[i]; + + if (!CreateScratchPixmapsForScreen(i)) + FatalError("failed to create scratch pixmaps"); + if (pScreen->CreateScreenResources && + !(*pScreen->CreateScreenResources) (pScreen)) + FatalError("failed to create screen resources"); + if (!CreateGCperDepth(i)) + FatalError("failed to create scratch GCs"); + if (!CreateDefaultStipple(i)) + FatalError("failed to create default stipple"); + if (!CreateRootWindow(pScreen)) + FatalError("failed to create root window"); + } + + InitFonts(); + if (SetDefaultFontPath(defaultFontPath) != Success) { + ErrorF("[dix] failed to set default font path '%s'", + defaultFontPath); + } + if (!SetDefaultFont(defaultTextFont)) { + FatalError("could not open default font '%s'", defaultTextFont); + } + + if (!(rootCursor = CreateRootCursor(NULL, 0))) { + FatalError("could not open default cursor font '%s'", + defaultCursorFont); + } #ifdef DPMSExtension - /* check all screens, looking for DPMS Capabilities */ - DPMSCapableFlag = DPMSSupported(); - if (!DPMSCapableFlag) - DPMSEnabled = FALSE; + /* check all screens, looking for DPMS Capabilities */ + DPMSCapableFlag = DPMSSupported(); + if (!DPMSCapableFlag) + DPMSEnabled = FALSE; #endif #ifdef PANORAMIX - /* - * Consolidate window and colourmap information for each screen - */ - if (!noPanoramiXExtension) - PanoramiXConsolidate(); + /* + * Consolidate window and colourmap information for each screen + */ + if (!noPanoramiXExtension) + PanoramiXConsolidate(); #endif - for (i = 0; i < screenInfo.numScreens; i++) - InitRootWindow(screenInfo.screens[i]->root); + for (i = 0; i < screenInfo.numScreens; i++) + InitRootWindow(screenInfo.screens[i]->root); InitCoreDevices(); - InitInput(argc, argv); - InitAndStartDevices(); - ReserveClientIds(serverClient); + InitInput(argc, argv); + InitAndStartDevices(); + ReserveClientIds(serverClient); - dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); + dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); #ifdef PANORAMIX - if (!noPanoramiXExtension) { - if (!PanoramiXCreateConnectionBlock()) { - FatalError("could not create connection block info"); - } - } else + if (!noPanoramiXExtension) { + if (!PanoramiXCreateConnectionBlock()) { + FatalError("could not create connection block info"); + } + } + else #endif - { - if (!CreateConnectionBlock()) { - FatalError("could not create connection block info"); - } - } + { + if (!CreateConnectionBlock()) { + FatalError("could not create connection block info"); + } + } #ifdef XQUARTZ - /* Let the other threads know the server is done with its init */ - pthread_mutex_lock(&serverRunningMutex); - serverRunning = TRUE; - pthread_cond_broadcast(&serverRunningCond); - pthread_mutex_unlock(&serverRunningMutex); + /* Let the other threads know the server is done with its init */ + pthread_mutex_lock(&serverRunningMutex); + serverRunning = TRUE; + pthread_cond_broadcast(&serverRunningCond); + pthread_mutex_unlock(&serverRunningMutex); #endif - - NotifyParentProcess(); - Dispatch(); + NotifyParentProcess(); + + Dispatch(); #ifdef XQUARTZ - /* Let the other threads know the server is no longer running */ - pthread_mutex_lock(&serverRunningMutex); - serverRunning = FALSE; - pthread_mutex_unlock(&serverRunningMutex); + /* Let the other threads know the server is no longer running */ + pthread_mutex_lock(&serverRunningMutex); + serverRunning = FALSE; + pthread_mutex_unlock(&serverRunningMutex); #endif - UndisplayDevices(); + UndisplayDevices(); - /* Now free up whatever must be freed */ - if (screenIsSaved == SCREEN_SAVER_ON) - dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset); - FreeScreenSaverTimer(); - CloseDownExtensions(); + /* Now free up whatever must be freed */ + if (screenIsSaved == SCREEN_SAVER_ON) + dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset); + FreeScreenSaverTimer(); + CloseDownExtensions(); #ifdef PANORAMIX - { - Bool remember_it = noPanoramiXExtension; - noPanoramiXExtension = TRUE; - FreeAllResources(); - noPanoramiXExtension = remember_it; - } + { + Bool remember_it = noPanoramiXExtension; + + noPanoramiXExtension = TRUE; + FreeAllResources(); + noPanoramiXExtension = remember_it; + } #else - FreeAllResources(); + FreeAllResources(); #endif CloseInput(); - for (i = 0; i < screenInfo.numScreens; i++) - screenInfo.screens[i]->root = NullWindow; - CloseDownDevices(); - CloseDownEvents(); - - for (i = screenInfo.numScreens - 1; i >= 0; i--) - { - FreeScratchPixmapsForScreen(i); - FreeGCperDepth(i); - FreeDefaultStipple(i); - (* screenInfo.screens[i]->CloseScreen)(i, screenInfo.screens[i]); - dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN); - free(screenInfo.screens[i]); - screenInfo.numScreens = i; - } - - ReleaseClientIds(serverClient); - dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT); - serverClient->devPrivates = NULL; - - FreeFonts(); - - FreeAuditTimer(); - - if (dispatchException & DE_TERMINATE) - { - CloseWellKnownConnections(); - } - - OsCleanup((dispatchException & DE_TERMINATE) != 0); - - if (dispatchException & DE_TERMINATE) - { - ddxGiveUp(EXIT_NO_ERROR); - break; - } - - free(ConnectionInfo); - ConnectionInfo = NULL; + for (i = 0; i < screenInfo.numScreens; i++) + screenInfo.screens[i]->root = NullWindow; + CloseDownDevices(); + CloseDownEvents(); + + for (i = screenInfo.numScreens - 1; i >= 0; i--) { + FreeScratchPixmapsForScreen(i); + FreeGCperDepth(i); + FreeDefaultStipple(i); + (*screenInfo.screens[i]->CloseScreen) (i, screenInfo.screens[i]); + dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN); + free(screenInfo.screens[i]); + screenInfo.numScreens = i; + } + + ReleaseClientIds(serverClient); + dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT); + serverClient->devPrivates = NULL; + + FreeFonts(); + + FreeAuditTimer(); + + if (dispatchException & DE_TERMINATE) { + CloseWellKnownConnections(); + } + + OsCleanup((dispatchException & DE_TERMINATE) != 0); + + if (dispatchException & DE_TERMINATE) { + ddxGiveUp(EXIT_NO_ERROR); + break; + } + + free(ConnectionInfo); + ConnectionInfo = NULL; } return 0; } - diff --git a/xorg-server/dix/pixmap.c b/xorg-server/dix/pixmap.c index 3943f5582..47b220b58 100644 --- a/xorg-server/dix/pixmap.c +++ b/xorg-server/dix/pixmap.c @@ -1,137 +1,131 @@ -/*
-
-Copyright 1993, 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.
-
-*/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "misc.h"
-#include "os.h"
-#include "windowstr.h"
-#include "resource.h"
-#include "dixstruct.h"
-#include "gcstruct.h"
-#include "servermd.h"
-#include "site.h"
-
-
-/*
- * Scratch pixmap management and device independent pixmap allocation
- * function.
- */
-
-
-/* callable by ddx */
-PixmapPtr
-GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth,
- int bitsPerPixel, int devKind, pointer pPixData)
-{
- PixmapPtr pPixmap = pScreen->pScratchPixmap;
-
- if (pPixmap)
- pScreen->pScratchPixmap = NULL;
- else
- /* width and height of 0 means don't allocate any pixmap data */
- pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth, 0);
-
- if (pPixmap) {
- if ((*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth,
- bitsPerPixel, devKind, pPixData))
- return pPixmap;
- (*pScreen->DestroyPixmap)(pPixmap);
- }
- return NullPixmap;
-}
-
-
-/* callable by ddx */
-void
-FreeScratchPixmapHeader(PixmapPtr pPixmap)
-{
- if (pPixmap)
- {
- ScreenPtr pScreen = pPixmap->drawable.pScreen;
-
- pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */
- if (pScreen->pScratchPixmap)
- (*pScreen->DestroyPixmap)(pPixmap);
- else
- pScreen->pScratchPixmap = pPixmap;
- }
-}
-
-
-Bool
-CreateScratchPixmapsForScreen(int scrnum)
-{
- unsigned int pixmap_size;
-
- pixmap_size = sizeof(PixmapRec) + dixPrivatesSize(PRIVATE_PIXMAP);
- screenInfo.screens[scrnum]->totalPixmapSize = BitmapBytePad(pixmap_size * 8);
-
- /* let it be created on first use */
- screenInfo.screens[scrnum]->pScratchPixmap = NULL;
- return TRUE;
-}
-
-
-void
-FreeScratchPixmapsForScreen(int scrnum)
-{
- FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap);
-}
-
-
-/* callable by ddx */
-PixmapPtr
-AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
-{
- PixmapPtr pPixmap;
-
- assert(pScreen->totalPixmapSize > 0);
-
- if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize)
- return NullPixmap;
-
- pPixmap = malloc(pScreen->totalPixmapSize + pixDataSize);
- if (!pPixmap)
- return NullPixmap;
-
- dixInitPrivates(pPixmap, pPixmap + 1, PRIVATE_PIXMAP);
- return pPixmap;
-}
-
-/* callable by ddx */
-void
-FreePixmap(PixmapPtr pPixmap)
-{
- dixFiniPrivates(pPixmap, PRIVATE_PIXMAP);
- free(pPixmap);
-}
+/* + +Copyright 1993, 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. + +*/ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <X11/X.h> +#include "scrnintstr.h" +#include "misc.h" +#include "os.h" +#include "windowstr.h" +#include "resource.h" +#include "dixstruct.h" +#include "gcstruct.h" +#include "servermd.h" +#include "site.h" + +/* + * Scratch pixmap management and device independent pixmap allocation + * function. + */ + +/* callable by ddx */ +PixmapPtr +GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth, + int bitsPerPixel, int devKind, pointer pPixData) +{ + PixmapPtr pPixmap = pScreen->pScratchPixmap; + + if (pPixmap) + pScreen->pScratchPixmap = NULL; + else + /* width and height of 0 means don't allocate any pixmap data */ + pPixmap = (*pScreen->CreatePixmap) (pScreen, 0, 0, depth, 0); + + if (pPixmap) { + if ((*pScreen->ModifyPixmapHeader) (pPixmap, width, height, depth, + bitsPerPixel, devKind, pPixData)) + return pPixmap; + (*pScreen->DestroyPixmap) (pPixmap); + } + return NullPixmap; +} + +/* callable by ddx */ +void +FreeScratchPixmapHeader(PixmapPtr pPixmap) +{ + if (pPixmap) { + ScreenPtr pScreen = pPixmap->drawable.pScreen; + + pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */ + if (pScreen->pScratchPixmap) + (*pScreen->DestroyPixmap) (pPixmap); + else + pScreen->pScratchPixmap = pPixmap; + } +} + +Bool +CreateScratchPixmapsForScreen(int scrnum) +{ + unsigned int pixmap_size; + + pixmap_size = sizeof(PixmapRec) + dixPrivatesSize(PRIVATE_PIXMAP); + screenInfo.screens[scrnum]->totalPixmapSize = + BitmapBytePad(pixmap_size * 8); + + /* let it be created on first use */ + screenInfo.screens[scrnum]->pScratchPixmap = NULL; + return TRUE; +} + +void +FreeScratchPixmapsForScreen(int scrnum) +{ + FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap); +} + +/* callable by ddx */ +PixmapPtr +AllocatePixmap(ScreenPtr pScreen, int pixDataSize) +{ + PixmapPtr pPixmap; + + assert(pScreen->totalPixmapSize > 0); + + if (pScreen->totalPixmapSize > ((size_t) - 1) - pixDataSize) + return NullPixmap; + + pPixmap = malloc(pScreen->totalPixmapSize + pixDataSize); + if (!pPixmap) + return NullPixmap; + + dixInitPrivates(pPixmap, pPixmap + 1, PRIVATE_PIXMAP); + return pPixmap; +} + +/* callable by ddx */ +void +FreePixmap(PixmapPtr pPixmap) +{ + dixFiniPrivates(pPixmap, PRIVATE_PIXMAP); + free(pPixmap); +} diff --git a/xorg-server/dix/privates.c b/xorg-server/dix/privates.c index 583b9f1f5..15fbf7590 100644 --- a/xorg-server/dix/privates.c +++ b/xorg-server/dix/privates.c @@ -1,502 +1,517 @@ -/*
-
-Copyright 1993, 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 © 2010, Keith Packard
- * Copyright © 2010, Jamey Sharp
- *
- * 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, and
- * that the name of the copyright holders not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no representations
- * about the suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THE COPYRIGHT HOLDERS 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.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <stddef.h>
-#include "windowstr.h"
-#include "resource.h"
-#include "privates.h"
-#include "gcstruct.h"
-#include "cursorstr.h"
-#include "colormapst.h"
-#include "inputstr.h"
-#include "scrnintstr.h"
-#include "extnsionst.h"
-
-static struct {
- DevPrivateKey key;
- unsigned offset;
- int created;
- int allocated;
-} keys[PRIVATE_LAST];
-
-static const Bool xselinux_private[PRIVATE_LAST] = {
- [PRIVATE_SCREEN] = TRUE,
- [PRIVATE_CLIENT] = TRUE,
- [PRIVATE_WINDOW] = TRUE,
- [PRIVATE_PIXMAP] = TRUE,
- [PRIVATE_GC] = TRUE,
- [PRIVATE_CURSOR] = TRUE,
- [PRIVATE_COLORMAP] = TRUE,
- [PRIVATE_DEVICE] = TRUE,
- [PRIVATE_EXTENSION] = TRUE,
- [PRIVATE_SELECTION] = TRUE,
- [PRIVATE_PROPERTY] = TRUE,
- [PRIVATE_PICTURE] = TRUE,
- [PRIVATE_GLYPHSET] = TRUE,
-};
-
-typedef Bool (*FixupFunc)(PrivatePtr *privates, int offset, unsigned bytes);
-
-static Bool
-dixReallocPrivates(PrivatePtr *privates, int old_offset, unsigned bytes)
-{
- void *new_privates;
-
- new_privates = realloc(*privates, old_offset + bytes);
- if (!new_privates)
- return FALSE;
- memset((char *) new_privates + old_offset, '\0', bytes);
- *privates = new_privates;
- return TRUE;
-}
-
-static Bool
-dixMovePrivates(PrivatePtr *privates, int new_offset, unsigned bytes)
-{
- memmove((char *) *privates + bytes, *privates, new_offset - bytes);
- memset(*privates, '\0', bytes);
- return TRUE;
-}
-
-static Bool
-fixupScreens(FixupFunc fixup, unsigned bytes)
-{
- int s;
- for (s = 0; s < screenInfo.numScreens; s++)
- if (!fixup(&screenInfo.screens[s]->devPrivates, keys[PRIVATE_SCREEN].offset, bytes))
- return FALSE;
- return TRUE;
-}
-
-static Bool
-fixupServerClient(FixupFunc fixup, unsigned bytes)
-{
- if (serverClient)
- return fixup(&serverClient->devPrivates, keys[PRIVATE_CLIENT].offset, bytes);
- return TRUE;
-}
-
-static Bool
-fixupExtensions(FixupFunc fixup, unsigned bytes)
-{
- unsigned char major;
- ExtensionEntry *extension;
- for (major = EXTENSION_BASE; (extension = GetExtensionEntry(major)); major++)
- if (!fixup(&extension->devPrivates, keys[PRIVATE_EXTENSION].offset, bytes))
- return FALSE;
- return TRUE;
-}
-
-static Bool
-fixupDefaultColormaps(FixupFunc fixup, unsigned bytes)
-{
- int s;
- for (s = 0; s < screenInfo.numScreens; s++) {
- ColormapPtr cmap;
- dixLookupResourceByType((pointer *) &cmap, screenInfo.screens[s]->defColormap,
- RT_COLORMAP, serverClient, DixCreateAccess);
- if (cmap && !fixup(&cmap->devPrivates, keys[PRIVATE_COLORMAP].offset, bytes))
- return FALSE;
- }
- return TRUE;
-}
-
-static Bool (* const allocated_early[PRIVATE_LAST])(FixupFunc, unsigned) = {
- [PRIVATE_SCREEN] = fixupScreens,
- [PRIVATE_CLIENT] = fixupServerClient,
- [PRIVATE_EXTENSION] = fixupExtensions,
- [PRIVATE_COLORMAP] = fixupDefaultColormaps,
-};
-
-/*
- * Register a private key. This takes the type of object the key will
- * be used with, which may be PRIVATE_ALL indicating that this key
- * will be used with all of the private objects. If 'size' is
- * non-zero, then the specified amount of space will be allocated in
- * the private storage. Otherwise, space for a single pointer will
- * be allocated which can be set with dixSetPrivate
- */
-Bool
-dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
-{
- DevPrivateType t;
- int offset;
- unsigned bytes;
-
- if (key->initialized) {
- assert (size == key->size);
- return TRUE;
- }
-
- /* Compute required space */
- bytes = size;
- if (size == 0)
- bytes = sizeof (void *);
-
- /* align to void * size */
- bytes = (bytes + sizeof (void *) - 1) & ~(sizeof (void *) - 1);
-
- /* Update offsets for all affected keys */
- if (type == PRIVATE_XSELINUX) {
- DevPrivateKey k;
-
- /* Resize if we can, or make sure nothing's allocated if we can't
- */
- for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++)
- if (xselinux_private[t]) {
- if (!allocated_early[t])
- assert (!keys[t].created);
- else if (!allocated_early[t](dixReallocPrivates, bytes))
- return FALSE;
- }
-
- /* Move all existing keys up in the privates space to make
- * room for this new global key
- */
- for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
- if (xselinux_private[t]) {
- for (k = keys[t].key; k; k = k->next)
- k->offset += bytes;
- keys[t].offset += bytes;
- if (allocated_early[t])
- allocated_early[t](dixMovePrivates, bytes);
- }
- }
-
- offset = 0;
- } else {
- /* Resize if we can, or make sure nothing's allocated if we can't */
- if (!allocated_early[type])
- assert(!keys[type].created);
- else if (!allocated_early[type](dixReallocPrivates, bytes))
- return FALSE;
- offset = keys[type].offset;
- keys[type].offset += bytes;
- }
-
- /* Setup this key */
- key->offset = offset;
- key->size = size;
- key->initialized = TRUE;
- key->type = type;
- key->allocated = FALSE;
- key->next = keys[type].key;
- keys[type].key = key;
-
- return TRUE;
-}
-
-Bool
-dixRegisterScreenPrivateKey(DevScreenPrivateKey screenKey, ScreenPtr pScreen, DevPrivateType type, unsigned size)
-{
- DevPrivateKey key;
-
- if (!dixRegisterPrivateKey(&screenKey->screenKey, PRIVATE_SCREEN, 0))
- return FALSE;
- key = dixGetPrivate(&pScreen->devPrivates, &screenKey->screenKey);
- if (key != NULL) {
- assert(key->size == size);
- assert(key->type == type);
- return TRUE;
- }
- key = calloc(sizeof (DevPrivateKeyRec), 1);
- if (!key)
- return FALSE;
- if (!dixRegisterPrivateKey(key, type, size)) {
- free(key);
- return FALSE;
- }
- key->allocated = TRUE;
- dixSetPrivate(&pScreen->devPrivates, &screenKey->screenKey, key);
- return TRUE;
-}
-
-DevPrivateKey
-_dixGetScreenPrivateKey(const DevScreenPrivateKey key, ScreenPtr pScreen)
-{
- return dixGetPrivate(&pScreen->devPrivates, &key->screenKey);
-}
-
-/*
- * Initialize privates by zeroing them
- */
-void
-_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type)
-{
- keys[type].created++;
- if (xselinux_private[type])
- keys[PRIVATE_XSELINUX].created++;
- if (keys[type].offset == 0)
- addr = 0;
- *privates = addr;
- memset(addr, '\0', keys[type].offset);
-}
-
-/*
- * Clean up privates
- */
-void
-_dixFiniPrivates(PrivatePtr privates, DevPrivateType type)
-{
- keys[type].created--;
- if (xselinux_private[type])
- keys[PRIVATE_XSELINUX].created--;
-}
-
-/*
- * Allocate new object with privates.
- *
- * This is expected to be invoked from the
- * dixAllocateObjectWithPrivates macro
- */
-void *
-_dixAllocateObjectWithPrivates(unsigned baseSize, unsigned clear, unsigned offset, DevPrivateType type)
-{
- unsigned totalSize;
- void *object;
- PrivatePtr privates;
- PrivatePtr *devPrivates;
-
- assert (type > PRIVATE_SCREEN && type < PRIVATE_LAST);
-
- /* round up so that void * is aligned */
- baseSize = (baseSize + sizeof (void *) - 1) & ~(sizeof (void *) - 1);
- totalSize = baseSize + keys[type].offset;
- object = malloc(totalSize);
- if (!object)
- return NULL;
-
- memset(object, '\0', clear);
- privates = (PrivatePtr) (((char *) object) + baseSize);
- devPrivates = (PrivatePtr *) ((char *) object + offset);
-
- _dixInitPrivates(devPrivates, privates, type);
-
- return object;
-}
-
-/*
- * Allocate privates separately from containing object.
- * Used for clients and screens.
- */
-Bool
-dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type)
-{
- unsigned size;
- PrivatePtr p;
-
- assert (type > PRIVATE_XSELINUX && type < PRIVATE_LAST);
-
- size = keys[type].offset;
- if (!size) {
- p = NULL;
- } else {
- if (!(p = malloc(size)))
- return FALSE;
- }
-
- _dixInitPrivates(privates, p, type);
- ++keys[type].allocated;
-
- return TRUE;
-}
-
-/*
- * Free an object that has privates
- *
- * This is expected to be invoked from the
- * dixFreeObjectWithPrivates macro
- */
-void
-_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type)
-{
- _dixFiniPrivates(privates, type);
- free(object);
-}
-
-/*
- * Called to free screen or client privates
- */
-void
-dixFreePrivates(PrivatePtr privates, DevPrivateType type)
-{
- _dixFiniPrivates(privates, type);
- --keys[type].allocated;
- free(privates);
-}
-
-/*
- * Return size of privates for the specified type
- */
-extern _X_EXPORT int
-dixPrivatesSize(DevPrivateType type)
-{
- assert (type >= PRIVATE_SCREEN && type < PRIVATE_LAST);
-
- return keys[type].offset;
-}
-
-/* Table of devPrivates offsets */
-static const int offsets[] = {
- -1, /* RT_NONE */
- offsetof(WindowRec, devPrivates), /* RT_WINDOW */
- offsetof(PixmapRec, devPrivates), /* RT_PIXMAP */
- offsetof(GC, devPrivates), /* RT_GC */
- -1, /* RT_FONT */
- offsetof(CursorRec, devPrivates), /* RT_CURSOR */
- offsetof(ColormapRec, devPrivates), /* RT_COLORMAP */
-};
-
-#define NUM_OFFSETS (sizeof (offsets) / sizeof (offsets[0]))
-
-int
-dixLookupPrivateOffset(RESTYPE type)
-{
- /*
- * Special kludge for DBE which registers a new resource type that
- * points at pixmaps (thanks, DBE)
- */
- if (type & RC_DRAWABLE) {
- if (type == RT_WINDOW)
- return offsets[RT_WINDOW & TypeMask];
- else
- return offsets[RT_PIXMAP & TypeMask];
- }
- type = type & TypeMask;
- if (type < NUM_OFFSETS)
- return offsets[type];
- return -1;
-}
-
-static const char *key_names[PRIVATE_LAST] = {
- /* XSELinux uses the same private keys for numerous objects */
- [PRIVATE_XSELINUX] = "XSELINUX",
-
- /* Otherwise, you get a private in just the requested structure
- */
- /* These can have objects created before all of the keys are registered */
- [PRIVATE_SCREEN] = "SCREEN",
- [PRIVATE_EXTENSION] = "EXTENSION",
- [PRIVATE_COLORMAP] = "COLORMAP",
-
- /* These cannot have any objects before all relevant keys are registered */
- [PRIVATE_DEVICE] = "DEVICE",
- [PRIVATE_CLIENT] = "CLIENT",
- [PRIVATE_PROPERTY] = "PROPERTY",
- [PRIVATE_SELECTION] = "SELECTION",
- [PRIVATE_WINDOW] = "WINDOW",
- [PRIVATE_PIXMAP] = "PIXMAP",
- [PRIVATE_GC] = "GC",
- [PRIVATE_CURSOR] = "CURSOR",
- [PRIVATE_CURSOR_BITS] = "CURSOR_BITS",
-
- /* extension privates */
- [PRIVATE_DBE_WINDOW] = "DBE_WINDOW",
- [PRIVATE_DAMAGE] = "DAMAGE",
- [PRIVATE_GLYPH] = "GLYPH",
- [PRIVATE_GLYPHSET] = "GLYPHSET",
- [PRIVATE_PICTURE] = "PICTURE",
- [PRIVATE_SYNC_FENCE] = "SYNC_FENCE",
-};
-
-void
-dixPrivateUsage(void)
-{
- int objects = 0;
- int bytes = 0;
- int alloc = 0;
- DevPrivateType t;
-
- for (t = PRIVATE_XSELINUX + 1; t < PRIVATE_LAST; t++) {
- if (keys[t].offset) {
- ErrorF("%s: %d objects of %d bytes = %d total bytes %d private allocs\n",
- key_names[t], keys[t].created, keys[t].offset, keys[t].created * keys[t].offset,
- keys[t].allocated);
- bytes += keys[t].created * keys[t].offset;
- objects += keys[t].created;
- alloc += keys[t].allocated;
- }
- }
- ErrorF("TOTAL: %d objects, %d bytes, %d allocs\n",
- objects, bytes, alloc);
-}
-
-void
-dixResetPrivates(void)
-{
- DevPrivateType t;
-
- for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
- DevPrivateKey key, next;
-
- for (key = keys[t].key; key; key = next) {
- next = key->next;
- key->offset = 0;
- key->initialized = FALSE;
- key->size = 0;
- key->type = 0;
- if (key->allocated)
- free(key);
- }
- if (keys[t].created) {
- ErrorF("%d %ss still allocated at reset\n",
- keys[t].created, key_names[t]);
- dixPrivateUsage();
- }
- keys[t].key = NULL;
- keys[t].offset = 0;
- keys[t].created = 0;
- keys[t].allocated = 0;
- }
-}
+/* + +Copyright 1993, 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 © 2010, Keith Packard + * Copyright © 2010, Jamey Sharp + * + * 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, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS 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. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <stddef.h> +#include "windowstr.h" +#include "resource.h" +#include "privates.h" +#include "gcstruct.h" +#include "cursorstr.h" +#include "colormapst.h" +#include "inputstr.h" +#include "scrnintstr.h" +#include "extnsionst.h" + +static struct { + DevPrivateKey key; + unsigned offset; + int created; + int allocated; +} keys[PRIVATE_LAST]; + +static const Bool xselinux_private[PRIVATE_LAST] = { + [PRIVATE_SCREEN] = TRUE, + [PRIVATE_CLIENT] = TRUE, + [PRIVATE_WINDOW] = TRUE, + [PRIVATE_PIXMAP] = TRUE, + [PRIVATE_GC] = TRUE, + [PRIVATE_CURSOR] = TRUE, + [PRIVATE_COLORMAP] = TRUE, + [PRIVATE_DEVICE] = TRUE, + [PRIVATE_EXTENSION] = TRUE, + [PRIVATE_SELECTION] = TRUE, + [PRIVATE_PROPERTY] = TRUE, + [PRIVATE_PICTURE] = TRUE, + [PRIVATE_GLYPHSET] = TRUE, +}; + +typedef Bool (*FixupFunc) (PrivatePtr *privates, int offset, unsigned bytes); + +static Bool +dixReallocPrivates(PrivatePtr *privates, int old_offset, unsigned bytes) +{ + void *new_privates; + + new_privates = realloc(*privates, old_offset + bytes); + if (!new_privates) + return FALSE; + memset((char *) new_privates + old_offset, '\0', bytes); + *privates = new_privates; + return TRUE; +} + +static Bool +dixMovePrivates(PrivatePtr *privates, int new_offset, unsigned bytes) +{ + memmove((char *) *privates + bytes, *privates, new_offset - bytes); + memset(*privates, '\0', bytes); + return TRUE; +} + +static Bool +fixupScreens(FixupFunc fixup, unsigned bytes) +{ + int s; + + for (s = 0; s < screenInfo.numScreens; s++) + if (!fixup + (&screenInfo.screens[s]->devPrivates, keys[PRIVATE_SCREEN].offset, + bytes)) + return FALSE; + return TRUE; +} + +static Bool +fixupServerClient(FixupFunc fixup, unsigned bytes) +{ + if (serverClient) + return fixup(&serverClient->devPrivates, keys[PRIVATE_CLIENT].offset, + bytes); + return TRUE; +} + +static Bool +fixupExtensions(FixupFunc fixup, unsigned bytes) +{ + unsigned char major; + ExtensionEntry *extension; + + for (major = EXTENSION_BASE; (extension = GetExtensionEntry(major)); + major++) + if (!fixup + (&extension->devPrivates, keys[PRIVATE_EXTENSION].offset, bytes)) + return FALSE; + return TRUE; +} + +static Bool +fixupDefaultColormaps(FixupFunc fixup, unsigned bytes) +{ + int s; + + for (s = 0; s < screenInfo.numScreens; s++) { + ColormapPtr cmap; + + dixLookupResourceByType((pointer *) &cmap, + screenInfo.screens[s]->defColormap, RT_COLORMAP, + serverClient, DixCreateAccess); + if (cmap && + !fixup(&cmap->devPrivates, keys[PRIVATE_COLORMAP].offset, bytes)) + return FALSE; + } + return TRUE; +} + +static Bool (*const allocated_early[PRIVATE_LAST]) (FixupFunc, unsigned) = { +[PRIVATE_SCREEN] = fixupScreens, + [PRIVATE_CLIENT] = fixupServerClient, + [PRIVATE_EXTENSION] = fixupExtensions, + [PRIVATE_COLORMAP] = fixupDefaultColormaps,}; + +/* + * Register a private key. This takes the type of object the key will + * be used with, which may be PRIVATE_ALL indicating that this key + * will be used with all of the private objects. If 'size' is + * non-zero, then the specified amount of space will be allocated in + * the private storage. Otherwise, space for a single pointer will + * be allocated which can be set with dixSetPrivate + */ +Bool +dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size) +{ + DevPrivateType t; + int offset; + unsigned bytes; + + if (key->initialized) { + assert(size == key->size); + return TRUE; + } + + /* Compute required space */ + bytes = size; + if (size == 0) + bytes = sizeof(void *); + + /* align to void * size */ + bytes = (bytes + sizeof(void *) - 1) & ~(sizeof(void *) - 1); + + /* Update offsets for all affected keys */ + if (type == PRIVATE_XSELINUX) { + DevPrivateKey k; + + /* Resize if we can, or make sure nothing's allocated if we can't + */ + for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) + if (xselinux_private[t]) { + if (!allocated_early[t]) + assert(!keys[t].created); + else if (!allocated_early[t] (dixReallocPrivates, bytes)) + return FALSE; + } + + /* Move all existing keys up in the privates space to make + * room for this new global key + */ + for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) { + if (xselinux_private[t]) { + for (k = keys[t].key; k; k = k->next) + k->offset += bytes; + keys[t].offset += bytes; + if (allocated_early[t]) + allocated_early[t] (dixMovePrivates, bytes); + } + } + + offset = 0; + } + else { + /* Resize if we can, or make sure nothing's allocated if we can't */ + if (!allocated_early[type]) + assert(!keys[type].created); + else if (!allocated_early[type] (dixReallocPrivates, bytes)) + return FALSE; + offset = keys[type].offset; + keys[type].offset += bytes; + } + + /* Setup this key */ + key->offset = offset; + key->size = size; + key->initialized = TRUE; + key->type = type; + key->allocated = FALSE; + key->next = keys[type].key; + keys[type].key = key; + + return TRUE; +} + +Bool +dixRegisterScreenPrivateKey(DevScreenPrivateKey screenKey, ScreenPtr pScreen, + DevPrivateType type, unsigned size) +{ + DevPrivateKey key; + + if (!dixRegisterPrivateKey(&screenKey->screenKey, PRIVATE_SCREEN, 0)) + return FALSE; + key = dixGetPrivate(&pScreen->devPrivates, &screenKey->screenKey); + if (key != NULL) { + assert(key->size == size); + assert(key->type == type); + return TRUE; + } + key = calloc(sizeof(DevPrivateKeyRec), 1); + if (!key) + return FALSE; + if (!dixRegisterPrivateKey(key, type, size)) { + free(key); + return FALSE; + } + key->allocated = TRUE; + dixSetPrivate(&pScreen->devPrivates, &screenKey->screenKey, key); + return TRUE; +} + +DevPrivateKey +_dixGetScreenPrivateKey(const DevScreenPrivateKey key, ScreenPtr pScreen) +{ + return dixGetPrivate(&pScreen->devPrivates, &key->screenKey); +} + +/* + * Initialize privates by zeroing them + */ +void +_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type) +{ + keys[type].created++; + if (xselinux_private[type]) + keys[PRIVATE_XSELINUX].created++; + if (keys[type].offset == 0) + addr = 0; + *privates = addr; + memset(addr, '\0', keys[type].offset); +} + +/* + * Clean up privates + */ +void +_dixFiniPrivates(PrivatePtr privates, DevPrivateType type) +{ + keys[type].created--; + if (xselinux_private[type]) + keys[PRIVATE_XSELINUX].created--; +} + +/* + * Allocate new object with privates. + * + * This is expected to be invoked from the + * dixAllocateObjectWithPrivates macro + */ +void * +_dixAllocateObjectWithPrivates(unsigned baseSize, unsigned clear, + unsigned offset, DevPrivateType type) +{ + unsigned totalSize; + void *object; + PrivatePtr privates; + PrivatePtr *devPrivates; + + assert(type > PRIVATE_SCREEN && type < PRIVATE_LAST); + + /* round up so that void * is aligned */ + baseSize = (baseSize + sizeof(void *) - 1) & ~(sizeof(void *) - 1); + totalSize = baseSize + keys[type].offset; + object = malloc(totalSize); + if (!object) + return NULL; + + memset(object, '\0', clear); + privates = (PrivatePtr) (((char *) object) + baseSize); + devPrivates = (PrivatePtr *) ((char *) object + offset); + + _dixInitPrivates(devPrivates, privates, type); + + return object; +} + +/* + * Allocate privates separately from containing object. + * Used for clients and screens. + */ +Bool +dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type) +{ + unsigned size; + PrivatePtr p; + + assert(type > PRIVATE_XSELINUX && type < PRIVATE_LAST); + + size = keys[type].offset; + if (!size) { + p = NULL; + } + else { + if (!(p = malloc(size))) + return FALSE; + } + + _dixInitPrivates(privates, p, type); + ++keys[type].allocated; + + return TRUE; +} + +/* + * Free an object that has privates + * + * This is expected to be invoked from the + * dixFreeObjectWithPrivates macro + */ +void +_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, + DevPrivateType type) +{ + _dixFiniPrivates(privates, type); + free(object); +} + +/* + * Called to free screen or client privates + */ +void +dixFreePrivates(PrivatePtr privates, DevPrivateType type) +{ + _dixFiniPrivates(privates, type); + --keys[type].allocated; + free(privates); +} + +/* + * Return size of privates for the specified type + */ +extern _X_EXPORT int +dixPrivatesSize(DevPrivateType type) +{ + assert(type >= PRIVATE_SCREEN && type < PRIVATE_LAST); + + return keys[type].offset; +} + +/* Table of devPrivates offsets */ +static const int offsets[] = { + -1, /* RT_NONE */ + offsetof(WindowRec, devPrivates), /* RT_WINDOW */ + offsetof(PixmapRec, devPrivates), /* RT_PIXMAP */ + offsetof(GC, devPrivates), /* RT_GC */ + -1, /* RT_FONT */ + offsetof(CursorRec, devPrivates), /* RT_CURSOR */ + offsetof(ColormapRec, devPrivates), /* RT_COLORMAP */ +}; + +#define NUM_OFFSETS (sizeof (offsets) / sizeof (offsets[0])) + +int +dixLookupPrivateOffset(RESTYPE type) +{ + /* + * Special kludge for DBE which registers a new resource type that + * points at pixmaps (thanks, DBE) + */ + if (type & RC_DRAWABLE) { + if (type == RT_WINDOW) + return offsets[RT_WINDOW & TypeMask]; + else + return offsets[RT_PIXMAP & TypeMask]; + } + type = type & TypeMask; + if (type < NUM_OFFSETS) + return offsets[type]; + return -1; +} + +static const char *key_names[PRIVATE_LAST] = { + /* XSELinux uses the same private keys for numerous objects */ + [PRIVATE_XSELINUX] = "XSELINUX", + + /* Otherwise, you get a private in just the requested structure + */ + /* These can have objects created before all of the keys are registered */ + [PRIVATE_SCREEN] = "SCREEN", + [PRIVATE_EXTENSION] = "EXTENSION", + [PRIVATE_COLORMAP] = "COLORMAP", + + /* These cannot have any objects before all relevant keys are registered */ + [PRIVATE_DEVICE] = "DEVICE", + [PRIVATE_CLIENT] = "CLIENT", + [PRIVATE_PROPERTY] = "PROPERTY", + [PRIVATE_SELECTION] = "SELECTION", + [PRIVATE_WINDOW] = "WINDOW", + [PRIVATE_PIXMAP] = "PIXMAP", + [PRIVATE_GC] = "GC", + [PRIVATE_CURSOR] = "CURSOR", + [PRIVATE_CURSOR_BITS] = "CURSOR_BITS", + + /* extension privates */ + [PRIVATE_DBE_WINDOW] = "DBE_WINDOW", + [PRIVATE_DAMAGE] = "DAMAGE", + [PRIVATE_GLYPH] = "GLYPH", + [PRIVATE_GLYPHSET] = "GLYPHSET", + [PRIVATE_PICTURE] = "PICTURE", + [PRIVATE_SYNC_FENCE] = "SYNC_FENCE", +}; + +void +dixPrivateUsage(void) +{ + int objects = 0; + int bytes = 0; + int alloc = 0; + DevPrivateType t; + + for (t = PRIVATE_XSELINUX + 1; t < PRIVATE_LAST; t++) { + if (keys[t].offset) { + ErrorF + ("%s: %d objects of %d bytes = %d total bytes %d private allocs\n", + key_names[t], keys[t].created, keys[t].offset, + keys[t].created * keys[t].offset, keys[t].allocated); + bytes += keys[t].created * keys[t].offset; + objects += keys[t].created; + alloc += keys[t].allocated; + } + } + ErrorF("TOTAL: %d objects, %d bytes, %d allocs\n", objects, bytes, alloc); +} + +void +dixResetPrivates(void) +{ + DevPrivateType t; + + for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) { + DevPrivateKey key, next; + + for (key = keys[t].key; key; key = next) { + next = key->next; + key->offset = 0; + key->initialized = FALSE; + key->size = 0; + key->type = 0; + if (key->allocated) + free(key); + } + if (keys[t].created) { + ErrorF("%d %ss still allocated at reset\n", + keys[t].created, key_names[t]); + dixPrivateUsage(); + } + keys[t].key = NULL; + keys[t].offset = 0; + keys[t].created = 0; + keys[t].allocated = 0; + } +} diff --git a/xorg-server/dix/property.c b/xorg-server/dix/property.c index d933d5cec..b1b83124f 100644 --- a/xorg-server/dix/property.c +++ b/xorg-server/dix/property.c @@ -22,7 +22,6 @@ 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 @@ -76,13 +75,12 @@ PrintPropertys(WindowPtr pWin) int j; pProp = pWin->userProps; - while (pProp) - { + while (pProp) { ErrorF("[dix] %x %x\n", pProp->propertyName, pProp->type); ErrorF("[dix] property format: %d\n", pProp->format); ErrorF("[dix] property data: \n"); - for (j=0; j<(pProp->format/8)*pProp->size; j++) - ErrorF("[dix] %c\n", pProp->data[j]); + for (j = 0; j < (pProp->format / 8) * pProp->size; j++) + ErrorF("[dix] %c\n", pProp->data[j]); pProp = pProp->next; } } @@ -90,18 +88,19 @@ PrintPropertys(WindowPtr pWin) int dixLookupProperty(PropertyPtr *result, WindowPtr pWin, Atom propertyName, - ClientPtr client, Mask access_mode) + ClientPtr client, Mask access_mode) { PropertyPtr pProp; int rc = BadMatch; + client->errorValue = propertyName; for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) - if (pProp->propertyName == propertyName) - break; + if (pProp->propertyName == propertyName) + break; if (pProp) - rc = XaceHookPropertyAccess(client, pWin, &pProp, access_mode); + rc = XaceHookPropertyAccess(client, pWin, &pProp, access_mode); *result = pProp; return rc; } @@ -117,17 +116,18 @@ deliverPropertyNotifyEvent(WindowPtr pWin, int state, Atom atom) event.u.property.state = state; event.u.property.atom = atom; event.u.property.time = currentTime.milliseconds; - DeliverEvents(pWin, &event, 1, (WindowPtr)NULL); + DeliverEvents(pWin, &event, 1, (WindowPtr) NULL); } int ProcRotateProperties(ClientPtr client) { - int i, j, delta, rc; + int i, j, delta, rc; + REQUEST(xRotatePropertiesReq); WindowPtr pWin; - Atom * atoms; - PropertyPtr * props; /* array of pointer */ + Atom *atoms; + PropertyPtr *props; /* array of pointer */ PropertyPtr pProp, saved; REQUEST_FIXED_SIZE(xRotatePropertiesReq, stuff->nAtoms << 2); @@ -136,70 +136,67 @@ ProcRotateProperties(ClientPtr client) if (rc != Success || stuff->nAtoms <= 0) return rc; - atoms = (Atom *) & stuff[1]; + atoms = (Atom *) &stuff[1]; props = malloc(stuff->nAtoms * sizeof(PropertyPtr)); saved = malloc(stuff->nAtoms * sizeof(PropertyRec)); if (!props || !saved) { - rc = BadAlloc; - goto out; + rc = BadAlloc; + goto out; } - for (i = 0; i < stuff->nAtoms; i++) - { + for (i = 0; i < stuff->nAtoms; i++) { if (!ValidAtom(atoms[i])) { - rc = BadAtom; - client->errorValue = atoms[i]; - goto out; + rc = BadAtom; + client->errorValue = atoms[i]; + goto out; } for (j = i + 1; j < stuff->nAtoms; j++) - if (atoms[j] == atoms[i]) - { - rc = BadMatch; - goto out; + if (atoms[j] == atoms[i]) { + rc = BadMatch; + goto out; } - rc = dixLookupProperty(&pProp, pWin, atoms[i], client, - DixReadAccess|DixWriteAccess); - if (rc != Success) - goto out; + rc = dixLookupProperty(&pProp, pWin, atoms[i], client, + DixReadAccess | DixWriteAccess); + if (rc != Success) + goto out; props[i] = pProp; - saved[i] = *pProp; + saved[i] = *pProp; } delta = stuff->nPositions; /* If the rotation is a complete 360 degrees, then moving the properties - around and generating PropertyNotify events should be skipped. */ + around and generating PropertyNotify events should be skipped. */ - if (abs(delta) % stuff->nAtoms) - { - while (delta < 0) /* faster if abs value is small */ + if (abs(delta) % stuff->nAtoms) { + while (delta < 0) /* faster if abs value is small */ delta += stuff->nAtoms; - for (i = 0; i < stuff->nAtoms; i++) - { - j = (i + delta) % stuff->nAtoms; - deliverPropertyNotifyEvent(pWin, PropertyNewValue, atoms[i]); - - /* Preserve name and devPrivates */ - props[j]->type = saved[i].type; - props[j]->format = saved[i].format; - props[j]->size = saved[i].size; - props[j]->data = saved[i].data; - } + for (i = 0; i < stuff->nAtoms; i++) { + j = (i + delta) % stuff->nAtoms; + deliverPropertyNotifyEvent(pWin, PropertyNewValue, atoms[i]); + + /* Preserve name and devPrivates */ + props[j]->type = saved[i].type; + props[j]->format = saved[i].format; + props[j]->size = saved[i].size; + props[j]->data = saved[i].data; + } } -out: + out: free(saved); free(props); return rc; } -int +int ProcChangeProperty(ClientPtr client) -{ +{ WindowPtr pWin; char format, mode; unsigned long len; int sizeInBytes, totalSize, err; + REQUEST(xChangePropertyReq); REQUEST_AT_LEAST_SIZE(xChangePropertyReq); @@ -207,50 +204,46 @@ ProcChangeProperty(ClientPtr client) format = stuff->format; mode = stuff->mode; if ((mode != PropModeReplace) && (mode != PropModeAppend) && - (mode != PropModePrepend)) - { - client->errorValue = mode; - return BadValue; + (mode != PropModePrepend)) { + client->errorValue = mode; + return BadValue; } - if ((format != 8) && (format != 16) && (format != 32)) - { - client->errorValue = format; + if ((format != 8) && (format != 16) && (format != 32)) { + client->errorValue = format; return BadValue; } len = stuff->nUnits; if (len > bytes_to_int32(0xffffffff - sizeof(xChangePropertyReq))) - return BadLength; - sizeInBytes = format>>3; + return BadLength; + sizeInBytes = format >> 3; totalSize = len * sizeInBytes; REQUEST_FIXED_SIZE(xChangePropertyReq, totalSize); err = dixLookupWindow(&pWin, stuff->window, client, DixSetPropAccess); if (err != Success) - return err; - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return BadAtom; + return err; + if (!ValidAtom(stuff->property)) { + client->errorValue = stuff->property; + return BadAtom; } - if (!ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return BadAtom; + if (!ValidAtom(stuff->type)) { + client->errorValue = stuff->type; + return BadAtom; } err = dixChangeWindowProperty(client, pWin, stuff->property, stuff->type, - (int)format, (int)mode, len, &stuff[1], - TRUE); + (int) format, (int) mode, len, &stuff[1], + TRUE); if (err != Success) - return err; + return err; else - return Success; + return Success; } int dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, - Atom type, int format, int mode, unsigned long len, - pointer value, Bool sendevent) + Atom type, int format, int mode, unsigned long len, + pointer value, Bool sendevent) { PropertyPtr pProp; PropertyRec savedProp; @@ -258,126 +251,116 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, unsigned char *data; Mask access_mode; - sizeInBytes = format>>3; + sizeInBytes = format >> 3; totalSize = len * sizeInBytes; access_mode = (mode == PropModeReplace) ? DixWriteAccess : DixBlendAccess; /* first see if property already exists */ rc = dixLookupProperty(&pProp, pWin, property, pClient, access_mode); - if (rc == BadMatch) /* just add to list */ - { - if (!pWin->optional && !MakeWindowOptional (pWin)) - return BadAlloc; - pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY); - if (!pProp) - return BadAlloc; + if (rc == BadMatch) { /* just add to list */ + if (!pWin->optional && !MakeWindowOptional(pWin)) + return BadAlloc; + pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY); + if (!pProp) + return BadAlloc; data = malloc(totalSize); - if (!data && len) - { - dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); - return BadAlloc; - } + if (!data && len) { + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); + return BadAlloc; + } memcpy(data, value, totalSize); pProp->propertyName = property; pProp->type = type; pProp->format = format; pProp->data = data; - pProp->size = len; - rc = XaceHookPropertyAccess(pClient, pWin, &pProp, - DixCreateAccess|DixWriteAccess); - if (rc != Success) { - free(data); - dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); - pClient->errorValue = property; - return rc; - } + pProp->size = len; + rc = XaceHookPropertyAccess(pClient, pWin, &pProp, + DixCreateAccess | DixWriteAccess); + if (rc != Success) { + free(data); + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); + pClient->errorValue = property; + return rc; + } pProp->next = pWin->optional->userProps; pWin->optional->userProps = pProp; } - else if (rc == Success) - { - /* To append or prepend to a property the request format and type - must match those of the already defined property. The - existing format and type are irrelevant when using the mode - "PropModeReplace" since they will be written over. */ + else if (rc == Success) { + /* To append or prepend to a property the request format and type + must match those of the already defined property. The + existing format and type are irrelevant when using the mode + "PropModeReplace" since they will be written over. */ if ((format != pProp->format) && (mode != PropModeReplace)) - return BadMatch; + return BadMatch; if ((pProp->type != type) && (mode != PropModeReplace)) return BadMatch; - /* save the old values for later */ - savedProp = *pProp; - - if (mode == PropModeReplace) - { - data = malloc(totalSize); - if (!data && len) - return BadAlloc; - memcpy(data, value, totalSize); - pProp->data = data; - pProp->size = len; - pProp->type = type; - pProp->format = format; - } - else if (len == 0) - { - /* do nothing */ - } - else if (mode == PropModeAppend) - { - data = malloc((pProp->size + len) * sizeInBytes); - if (!data) - return BadAlloc; - memcpy(data, pProp->data, pProp->size * sizeInBytes); - memcpy(data + pProp->size * sizeInBytes, value, totalSize); + /* save the old values for later */ + savedProp = *pProp; + + if (mode == PropModeReplace) { + data = malloc(totalSize); + if (!data && len) + return BadAlloc; + memcpy(data, value, totalSize); + pProp->data = data; + pProp->size = len; + pProp->type = type; + pProp->format = format; + } + else if (len == 0) { + /* do nothing */ + } + else if (mode == PropModeAppend) { + data = malloc((pProp->size + len) * sizeInBytes); + if (!data) + return BadAlloc; + memcpy(data, pProp->data, pProp->size * sizeInBytes); + memcpy(data + pProp->size * sizeInBytes, value, totalSize); pProp->data = data; pProp->size += len; - } - else if (mode == PropModePrepend) - { + } + else if (mode == PropModePrepend) { data = malloc(sizeInBytes * (len + pProp->size)); - if (!data) - return BadAlloc; + if (!data) + return BadAlloc; memcpy(data + totalSize, pProp->data, pProp->size * sizeInBytes); memcpy(data, value, totalSize); pProp->data = data; pProp->size += len; - } - - /* Allow security modules to check the new content */ - access_mode |= DixPostAccess; - rc = XaceHookPropertyAccess(pClient, pWin, &pProp, access_mode); - if (rc == Success) - { - if (savedProp.data != pProp->data) - free(savedProp.data); - } - else - { - if (savedProp.data != pProp->data) - free(pProp->data); - *pProp = savedProp; - return rc; - } + } + + /* Allow security modules to check the new content */ + access_mode |= DixPostAccess; + rc = XaceHookPropertyAccess(pClient, pWin, &pProp, access_mode); + if (rc == Success) { + if (savedProp.data != pProp->data) + free(savedProp.data); + } + else { + if (savedProp.data != pProp->data) + free(pProp->data); + *pProp = savedProp; + return rc; + } } else - return rc; + return rc; if (sendevent) - deliverPropertyNotifyEvent(pWin, PropertyNewValue, pProp->propertyName); + deliverPropertyNotifyEvent(pWin, PropertyNewValue, pProp->propertyName); return Success; } int -ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format, - int mode, unsigned long len, pointer value, - Bool sendevent) +ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format, + int mode, unsigned long len, pointer value, Bool sendevent) { return dixChangeWindowProperty(serverClient, pWin, property, type, format, - mode, len, value, sendevent); + mode, len, value, sendevent); } int @@ -388,24 +371,25 @@ DeleteProperty(ClientPtr client, WindowPtr pWin, Atom propName) rc = dixLookupProperty(&pProp, pWin, propName, client, DixDestroyAccess); if (rc == BadMatch) - return Success; /* Succeed if property does not exist */ + return Success; /* Succeed if property does not exist */ if (rc == Success) { - if (pWin->optional->userProps == pProp) { - /* Takes care of head */ + if (pWin->optional->userProps == pProp) { + /* Takes care of head */ if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } else { - /* Need to traverse to find the previous element */ - prevProp = pWin->optional->userProps; - while (prevProp->next != pProp) - prevProp = prevProp->next; - prevProp->next = pProp->next; - } - - deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName); - free(pProp->data); - dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); + CheckWindowOptionalNeed(pWin); + } + else { + /* Need to traverse to find the previous element */ + prevProp = pWin->optional->userProps; + while (prevProp->next != pProp) + prevProp = prevProp->next; + prevProp->next = pProp->next; + } + + deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName); + free(pProp->data); + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); } return rc; } @@ -415,14 +399,13 @@ DeleteAllWindowProperties(WindowPtr pWin) { PropertyPtr pProp, pNextProp; - pProp = wUserProps (pWin); - while (pProp) - { - deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName); - pNextProp = pProp->next; + pProp = wUserProps(pWin); + while (pProp) { + deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName); + pNextProp = pProp->next; free(pProp->data); - dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); - pProp = pNextProp; + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); + pProp = pNextProp; } if (pWin->optional) @@ -430,11 +413,8 @@ DeleteAllWindowProperties(WindowPtr pWin) } static int -NullPropertyReply( - ClientPtr client, - ATOM propertyType, - int format, - xGetPropertyReply *reply) +NullPropertyReply(ClientPtr client, + ATOM propertyType, int format, xGetPropertyReply * reply) { reply->nItems = 0; reply->length = 0; @@ -464,32 +444,30 @@ ProcGetProperty(ClientPtr client) WindowPtr pWin; xGetPropertyReply reply; Mask win_mode = DixGetPropAccess, prop_mode = DixReadAccess; + REQUEST(xGetPropertyReq); REQUEST_SIZE_MATCH(xGetPropertyReq); if (stuff->delete) { - UpdateCurrentTime(); - win_mode |= DixSetPropAccess; - prop_mode |= DixDestroyAccess; + UpdateCurrentTime(); + win_mode |= DixSetPropAccess; + prop_mode |= DixDestroyAccess; } rc = dixLookupWindow(&pWin, stuff->window, client, win_mode); if (rc != Success) - return rc; + return rc; - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return BadAtom; + if (!ValidAtom(stuff->property)) { + client->errorValue = stuff->property; + return BadAtom; } - if ((stuff->delete != xTrue) && (stuff->delete != xFalse)) - { - client->errorValue = stuff->delete; - return BadValue; + if ((stuff->delete != xTrue) && (stuff->delete != xFalse)) { + client->errorValue = stuff->delete; + return BadValue; } - if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type)) - { - client->errorValue = stuff->type; - return BadAtom; + if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type)) { + client->errorValue = stuff->type; + return BadAtom; } memset(&reply, 0, sizeof(xGetPropertyReply)); @@ -498,39 +476,36 @@ ProcGetProperty(ClientPtr client) rc = dixLookupProperty(&pProp, pWin, stuff->property, client, prop_mode); if (rc == BadMatch) - return NullPropertyReply(client, None, 0, &reply); + return NullPropertyReply(client, None, 0, &reply); else if (rc != Success) - return rc; + return rc; /* If the request type and actual type don't match. Return the - property information, but not the data. */ - - if (((stuff->type != pProp->type) && - (stuff->type != AnyPropertyType)) - ) - { - reply.bytesAfter = pProp->size; - reply.format = pProp->format; - reply.length = 0; - reply.nItems = 0; - reply.propertyType = pProp->type; - WriteReplyToClient(client, sizeof(xGenericReply), &reply); - return Success; + property information, but not the data. */ + + if (((stuff->type != pProp->type) && (stuff->type != AnyPropertyType)) + ) { + reply.bytesAfter = pProp->size; + reply.format = pProp->format; + reply.length = 0; + reply.nItems = 0; + reply.propertyType = pProp->type; + WriteReplyToClient(client, sizeof(xGenericReply), &reply); + return Success; } /* * Return type, format, value to client */ - n = (pProp->format/8) * pProp->size; /* size (bytes) of prop */ - ind = stuff->longOffset << 2; + n = (pProp->format / 8) * pProp->size; /* size (bytes) of prop */ + ind = stuff->longOffset << 2; - /* If longOffset is invalid such that it causes "len" to - be negative, it's a value error. */ + /* If longOffset is invalid such that it causes "len" to + be negative, it's a value error. */ - if (n < ind) - { - client->errorValue = stuff->longOffset; - return BadValue; + if (n < ind) { + client->errorValue = stuff->longOffset; + return BadValue; } len = min(n - ind, 4 * stuff->longLength); @@ -538,40 +513,45 @@ ProcGetProperty(ClientPtr client) reply.bytesAfter = n - (ind + len); reply.format = pProp->format; reply.length = bytes_to_int32(len); - reply.nItems = len / (pProp->format / 8 ); + reply.nItems = len / (pProp->format / 8); reply.propertyType = pProp->type; if (stuff->delete && (reply.bytesAfter == 0)) - deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName); + deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName); WriteReplyToClient(client, sizeof(xGenericReply), &reply); - if (len) - { - switch (reply.format) { - case 32: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap32Write; break; - case 16: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap16Write; break; - default: client->pSwapReplyFunc = (ReplySwapPtr)WriteToClient; break; - } - WriteSwappedDataToClient(client, len, - (char *)pProp->data + ind); + if (len) { + switch (reply.format) { + case 32: + client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write; + break; + case 16: + client->pSwapReplyFunc = (ReplySwapPtr) CopySwap16Write; + break; + default: + client->pSwapReplyFunc = (ReplySwapPtr) WriteToClient; + break; + } + WriteSwappedDataToClient(client, len, (char *) pProp->data + ind); } if (stuff->delete && (reply.bytesAfter == 0)) { - /* Delete the Property */ - if (pWin->optional->userProps == pProp) { - /* Takes care of head */ + /* Delete the Property */ + if (pWin->optional->userProps == pProp) { + /* Takes care of head */ if (!(pWin->optional->userProps = pProp->next)) - CheckWindowOptionalNeed (pWin); - } else { - /* Need to traverse to find the previous element */ - prevProp = pWin->optional->userProps; - while (prevProp->next != pProp) - prevProp = prevProp->next; - prevProp->next = pProp->next; - } - - free(pProp->data); - dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); + CheckWindowOptionalNeed(pWin); + } + else { + /* Need to traverse to find the previous element */ + prevProp = pWin->optional->userProps; + while (prevProp->next != pProp) + prevProp = prevProp->next; + prevProp->next = pProp->next; + } + + free(pProp->data); + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); } return Success; } @@ -581,9 +561,10 @@ ProcListProperties(ClientPtr client) { Atom *pAtoms = NULL, *temppAtoms; xListPropertiesReply xlpr; - int rc, numProps = 0; + int rc, numProps = 0; WindowPtr pWin; PropertyPtr pProp, realProp; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); @@ -592,20 +573,20 @@ ProcListProperties(ClientPtr client) return rc; for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) - numProps++; + numProps++; if (numProps && !(pAtoms = malloc(numProps * sizeof(Atom)))) - return BadAlloc; + return BadAlloc; numProps = 0; temppAtoms = pAtoms; for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) { - realProp = pProp; - rc = XaceHookPropertyAccess(client, pWin, &realProp, DixGetAttrAccess); - if (rc == Success && realProp == pProp) { - *temppAtoms++ = pProp->propertyName; - numProps++; - } + realProp = pProp; + rc = XaceHookPropertyAccess(client, pWin, &realProp, DixGetAttrAccess); + if (rc == Success && realProp == pProp) { + *temppAtoms++ = pProp->propertyName; + numProps++; + } } xlpr.type = X_Reply; @@ -613,31 +594,30 @@ ProcListProperties(ClientPtr client) xlpr.length = bytes_to_int32(numProps * sizeof(Atom)); xlpr.sequenceNumber = client->sequence; WriteReplyToClient(client, sizeof(xGenericReply), &xlpr); - if (numProps) - { - client->pSwapReplyFunc = (ReplySwapPtr)Swap32Write; + if (numProps) { + client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms); } free(pAtoms); return Success; } -int +int ProcDeleteProperty(ClientPtr client) { WindowPtr pWin; + REQUEST(xDeletePropertyReq); int result; - + REQUEST_SIZE_MATCH(xDeletePropertyReq); UpdateCurrentTime(); result = dixLookupWindow(&pWin, stuff->window, client, DixSetPropAccess); if (result != Success) return result; - if (!ValidAtom(stuff->property)) - { - client->errorValue = stuff->property; - return BadAtom; + if (!ValidAtom(stuff->property)) { + client->errorValue = stuff->property; + return BadAtom; } return DeleteProperty(client, pWin, stuff->property); diff --git a/xorg-server/dix/ptrveloc.c b/xorg-server/dix/ptrveloc.c index 7b6f56049..acbb479c1 100644 --- a/xorg-server/dix/ptrveloc.c +++ b/xorg-server/dix/ptrveloc.c @@ -62,8 +62,9 @@ /* fwds */ int -SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num); + SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num); static double + SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, double velocity, double threshold, double acc); static PointerAccelerationProfileFunc @@ -81,7 +82,7 @@ DeletePredictableAccelerationProperties(DeviceIntPtr, #ifdef PTRACCEL_DEBUGGING #define DebugAccelF ErrorF #else -#define DebugAccelF(...) /* */ +#define DebugAccelF(...) /* */ #endif /******************************** @@ -99,11 +100,11 @@ InitVelocityData(DeviceVelocityPtr vel) { memset(vel, 0, sizeof(DeviceVelocityRec)); - vel->corr_mul = 10.0; /* dots per 10 milisecond should be usable */ - vel->const_acceleration = 1.0; /* no acceleration/deceleration */ + vel->corr_mul = 10.0; /* dots per 10 milisecond should be usable */ + vel->const_acceleration = 1.0; /* no acceleration/deceleration */ vel->reset_time = 300; vel->use_softening = 1; - vel->min_acceleration = 1.0; /* don't decelerate */ + vel->min_acceleration = 1.0; /* don't decelerate */ vel->max_rel_diff = 0.2; vel->max_diff = 1.0; vel->initial_range = 2; @@ -112,26 +113,27 @@ InitVelocityData(DeviceVelocityPtr vel) InitTrackers(vel, 16); } - /** * Clean up DeviceVelocityRec */ void -FreeVelocityData(DeviceVelocityPtr vel){ +FreeVelocityData(DeviceVelocityPtr vel) +{ free(vel->tracker); SetAccelerationProfile(vel, PROFILE_UNINITIALIZE); } - /** * Init predictable scheme */ Bool InitPredictableAccelerationScheme(DeviceIntPtr dev, - ValuatorAccelerationPtr protoScheme) { + ValuatorAccelerationPtr protoScheme) +{ DeviceVelocityPtr vel; ValuatorAccelerationRec scheme; PredictableAccelSchemePtr schemeData; + scheme = *protoScheme; vel = calloc(1, sizeof(DeviceVelocityRec)); schemeData = calloc(1, sizeof(PredictableAccelSchemeRec)); @@ -147,7 +149,6 @@ InitPredictableAccelerationScheme(DeviceIntPtr dev, return TRUE; } - /** * Uninit scheme */ @@ -155,6 +156,7 @@ void AccelerationDefaultCleanup(DeviceIntPtr dev) { DeviceVelocityPtr vel = GetDevicePredictableAccelData(dev); + if (vel) { /* the proper guarantee would be that we're not inside of * AccelSchemeProc(), but that seems impossible. Schemes don't get @@ -165,14 +167,15 @@ AccelerationDefaultCleanup(DeviceIntPtr dev) FreeVelocityData(vel); free(vel); DeletePredictableAccelerationProperties(dev, - (PredictableAccelSchemePtr) dev->valuator->accelScheme.accelData); + (PredictableAccelSchemePtr) + dev->valuator->accelScheme. + accelData); free(dev->valuator->accelScheme.accelData); dev->valuator->accelScheme.accelData = NULL; OsReleaseSignals(); } } - /************************* * Input property support ************************/ @@ -197,15 +200,15 @@ AccelSetProfileProperty(DeviceIntPtr dev, Atom atom, return BadValue; rc = XIPropToInt(val, &nelem, &ptr); - if(checkOnly) - { + if (checkOnly) { if (rc) return rc; if (GetAccelerationProfile(vel, profile) == NULL) return BadValue; - } else - SetAccelerationProfile(vel, profile); + } + else + SetAccelerationProfile(vel, profile); return Success; } @@ -242,15 +245,14 @@ AccelSetDecelProperty(DeviceIntPtr dev, Atom atom, return BadValue; rc = XIPropToFloat(val, &nelem, &ptr); - if(checkOnly) - { + if (checkOnly) { if (rc) return rc; - return (v >= 1.0f) ? Success : BadValue; + return (v >= 1.0f) ? Success : BadValue; } - if(v >= 1.0f) - vel->const_acceleration = 1/v; + if (v >= 1.0f) + vel->const_acceleration = 1 / v; return Success; } @@ -258,16 +260,16 @@ AccelSetDecelProperty(DeviceIntPtr dev, Atom atom, static long AccelInitDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr vel) { - float fval = 1.0/vel->const_acceleration; - Atom prop_const_decel = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION); + float fval = 1.0 / vel->const_acceleration; + Atom prop_const_decel = + XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION); XIChangeDeviceProperty(dev, prop_const_decel, - XIGetKnownProperty(XATOM_FLOAT), 32, - PropModeReplace, 1, &fval, FALSE); + XIGetKnownProperty(XATOM_FLOAT), 32, PropModeReplace, + 1, &fval, FALSE); XISetDevicePropertyDeletable(dev, prop_const_decel, FALSE); return XIRegisterPropertyHandler(dev, AccelSetDecelProperty, NULL, NULL); } - /** * adaptive deceleration */ @@ -288,15 +290,14 @@ AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom, return BadValue; rc = XIPropToFloat(val, &nelem, &ptr); - if(checkOnly) - { + if (checkOnly) { if (rc) return rc; - return (v >= 1.0f) ? Success : BadValue; + return (v >= 1.0f) ? Success : BadValue; } - if(v >= 1.0f) - veloc->min_acceleration = 1/v; + if (v >= 1.0f) + veloc->min_acceleration = 1 / v; return Success; } @@ -304,16 +305,18 @@ AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom, static long AccelInitAdaptDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr vel) { - float fval = 1.0/vel->min_acceleration; - Atom prop_adapt_decel = XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION); + float fval = 1.0 / vel->min_acceleration; + Atom prop_adapt_decel = + XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION); - XIChangeDeviceProperty(dev, prop_adapt_decel, XIGetKnownProperty(XATOM_FLOAT), 32, - PropModeReplace, 1, &fval, FALSE); + XIChangeDeviceProperty(dev, prop_adapt_decel, + XIGetKnownProperty(XATOM_FLOAT), 32, PropModeReplace, + 1, &fval, FALSE); XISetDevicePropertyDeletable(dev, prop_adapt_decel, FALSE); - return XIRegisterPropertyHandler(dev, AccelSetAdaptDecelProperty, NULL, NULL); + return XIRegisterPropertyHandler(dev, AccelSetAdaptDecelProperty, NULL, + NULL); } - /** * velocity scaling */ @@ -334,16 +337,15 @@ AccelSetScaleProperty(DeviceIntPtr dev, Atom atom, return BadValue; rc = XIPropToFloat(val, &nelem, &ptr); - if (checkOnly) - { + if (checkOnly) { if (rc) return rc; return (v > 0) ? Success : BadValue; } - if(v > 0) - vel->corr_mul = v; + if (v > 0) + vel->corr_mul = v; return Success; } @@ -354,20 +356,22 @@ AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr vel) float fval = vel->corr_mul; Atom prop_velo_scale = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING); - XIChangeDeviceProperty(dev, prop_velo_scale, XIGetKnownProperty(XATOM_FLOAT), 32, - PropModeReplace, 1, &fval, FALSE); + XIChangeDeviceProperty(dev, prop_velo_scale, + XIGetKnownProperty(XATOM_FLOAT), 32, PropModeReplace, + 1, &fval, FALSE); XISetDevicePropertyDeletable(dev, prop_velo_scale, FALSE); return XIRegisterPropertyHandler(dev, AccelSetScaleProperty, NULL, NULL); } static BOOL -InitializePredictableAccelerationProperties( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - PredictableAccelSchemePtr schemeData) +InitializePredictableAccelerationProperties(DeviceIntPtr dev, + DeviceVelocityPtr vel, + PredictableAccelSchemePtr + schemeData) { int num_handlers = 4; - if(!vel) + + if (!vel) return FALSE; schemeData->prop_handlers = calloc(num_handlers, sizeof(long)); @@ -383,9 +387,8 @@ InitializePredictableAccelerationProperties( } BOOL -DeletePredictableAccelerationProperties( - DeviceIntPtr dev, - PredictableAccelSchemePtr scheme) +DeletePredictableAccelerationProperties(DeviceIntPtr dev, + PredictableAccelSchemePtr scheme) { DeviceVelocityPtr vel; Atom prop; @@ -420,26 +423,27 @@ DeletePredictableAccelerationProperties( void InitTrackers(DeviceVelocityPtr vel, int ntracker) { - if(ntracker < 1){ - ErrorF("(dix ptracc) invalid number of trackers\n"); - return; + if (ntracker < 1) { + ErrorF("(dix ptracc) invalid number of trackers\n"); + return; } free(vel->tracker); - vel->tracker = (MotionTrackerPtr)calloc(ntracker, sizeof(MotionTracker)); + vel->tracker = (MotionTrackerPtr) calloc(ntracker, sizeof(MotionTracker)); vel->num_tracker = ntracker; } enum directions { - N = (1 << 0), - NE = (1 << 1), - E = (1 << 2), - SE = (1 << 3), - S = (1 << 4), - SW = (1 << 5), - W = (1 << 6), - NW = (1 << 7), + N = (1 << 0), + NE = (1 << 1), + E = (1 << 2), + SE = (1 << 3), + S = (1 << 4), + SW = (1 << 5), + W = (1 << 6), + NW = (1 << 7), UNDEFINED = 0xFF }; + /** * return a bit field of possible directions. * There's no reason against widening to more precise directions (<45 degrees), @@ -452,32 +456,34 @@ enum directions { * this movement. */ static int -DoGetDirection(int dx, int dy){ +DoGetDirection(int dx, int dy) +{ int dir = 0; /* on insignificant mickeys, flag 135 degrees */ - if(abs(dx) < 2 && abs(dy) < 2){ + if (abs(dx) < 2 && abs(dy) < 2) { /* first check diagonal cases */ - if(dx > 0 && dy > 0) + if (dx > 0 && dy > 0) dir = E | SE | S; - else if(dx > 0 && dy < 0) - dir = N | NE | E; - else if(dx < 0 && dy < 0) - dir = W | NW | N; - else if(dx < 0 && dy > 0) - dir = W | SW | S; + else if (dx > 0 && dy < 0) + dir = N | NE | E; + else if (dx < 0 && dy < 0) + dir = W | NW | N; + else if (dx < 0 && dy > 0) + dir = W | SW | S; /* check axis-aligned directions */ - else if(dx > 0) - dir = NE | E | SE; - else if(dx < 0) - dir = NW | W | SW; - else if(dy > 0) - dir = SE | S | SW; - else if(dy < 0) - dir = NE | N | NW; + else if (dx > 0) + dir = NE | E | SE; + else if (dx < 0) + dir = NW | W | SW; + else if (dy > 0) + dir = SE | S | SW; + else if (dy < 0) + dir = NE | N | NW; else - dir = UNDEFINED; /* shouldn't happen */ - } else { /* compute angle and set appropriate flags */ + dir = UNDEFINED; /* shouldn't happen */ + } + else { /* compute angle and set appropriate flags */ double r; int i1, i2; @@ -493,13 +499,13 @@ DoGetDirection(int dx, int dy){ * But we add extra 90° to match up with our N, S, etc. defines up * there, rest stays the same. */ - r = (r+(M_PI*2.5))/(M_PI/4); + r = (r + (M_PI * 2.5)) / (M_PI / 4); /* this intends to flag 2 directions (45 degrees), * except on very well-aligned mickeys. */ - i1 = (int)(r+0.1) % 8; - i2 = (int)(r+0.9) % 8; - if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7) - dir = UNDEFINED; /* shouldn't happen */ + i1 = (int) (r + 0.1) % 8; + i2 = (int) (r + 0.9) % 8; + if (i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7) + dir = UNDEFINED; /* shouldn't happen */ else dir = (1 << i1 | 1 << i2); } @@ -517,19 +523,22 @@ DoGetDirection(int dx, int dy){ * this movement. */ static int -GetDirection(int dx, int dy){ +GetDirection(int dx, int dy) +{ static int cache[DIRECTION_CACHE_SIZE][DIRECTION_CACHE_SIZE]; int dir; + if (abs(dx) <= DIRECTION_CACHE_RANGE && abs(dy) <= DIRECTION_CACHE_RANGE) { - /* cacheable */ - dir = cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy]; - if(dir == 0) { - dir = DoGetDirection(dx, dy); - cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy] = dir; - } - }else{ - /* non-cacheable */ - dir = DoGetDirection(dx, dy); + /* cacheable */ + dir = cache[DIRECTION_CACHE_RANGE + dx][DIRECTION_CACHE_RANGE + dy]; + if (dir == 0) { + dir = DoGetDirection(dx, dy); + cache[DIRECTION_CACHE_RANGE + dx][DIRECTION_CACHE_RANGE + dy] = dir; + } + } + else { + /* non-cacheable */ + dir = DoGetDirection(dx, dy); } return dir; @@ -538,7 +547,6 @@ GetDirection(int dx, int dy){ #undef DIRECTION_CACHE_RANGE #undef DIRECTION_CACHE_SIZE - /* convert offset (age) to array index */ #define TRACKER_INDEX(s, d) (((s)->num_tracker + (s)->cur_tracker - (d)) % (s)->num_tracker) #define TRACKER(s, d) &(s)->tracker[TRACKER_INDEX(s,d)] @@ -551,9 +559,10 @@ static inline void FeedTrackers(DeviceVelocityPtr vel, double dx, double dy, int cur_t) { int n; - for(n = 0; n < vel->num_tracker; n++){ - vel->tracker[n].dx += dx; - vel->tracker[n].dy += dy; + + for (n = 0; n < vel->num_tracker; n++) { + vel->tracker[n].dx += dx; + vel->tracker[n].dy += dy; } n = (vel->cur_tracker + 1) % vel->num_tracker; vel->tracker[n].dx = 0.0; @@ -572,13 +581,15 @@ FeedTrackers(DeviceVelocityPtr vel, double dx, double dy, int cur_t) * This assumes linear motion. */ static double -CalcTracker(const MotionTracker *tracker, int cur_t){ +CalcTracker(const MotionTracker * tracker, int cur_t) +{ double dist = sqrt(tracker->dx * tracker->dx + tracker->dy * tracker->dy); int dtime = cur_t - tracker->time; - if(dtime > 0) - return dist / dtime; + + if (dtime > 0) + return dist / dtime; else - return 0;/* synonymous for NaN, since we're not C99 */ + return 0; /* synonymous for NaN, since we're not C99 */ } /* find the most plausible velocity. That is, the most distant @@ -589,71 +600,79 @@ CalcTracker(const MotionTracker *tracker, int cur_t){ * @return The tracker's velocity or 0 if the above conditions are unmet */ static double -QueryTrackers(DeviceVelocityPtr vel, int cur_t){ +QueryTrackers(DeviceVelocityPtr vel, int cur_t) +{ int offset, dir = UNDEFINED, used_offset = -1, age_ms; + /* initial velocity: a low-offset, valid velocity */ double initial_velocity = 0, result = 0, velocity_diff; - double velocity_factor = vel->corr_mul * vel->const_acceleration; /* premultiply */ + double velocity_factor = vel->corr_mul * vel->const_acceleration; /* premultiply */ + /* loop from current to older data */ - for(offset = 1; offset < vel->num_tracker; offset++){ - MotionTracker *tracker = TRACKER(vel, offset); - double tracker_velocity; - - age_ms = cur_t - tracker->time; - - /* bail out if data is too old and protect from overrun */ - if (age_ms >= vel->reset_time || age_ms < 0) { - DebugAccelF("(dix prtacc) query: tracker too old\n"); - break; - } - - /* - * this heuristic avoids using the linear-motion velocity formula - * in CalcTracker() on motion that isn't exactly linear. So to get - * even more precision we could subdivide as a final step, so possible - * non-linearities are accounted for. - */ - dir &= tracker->dir; - if(dir == 0){ /* we've changed octant of movement (e.g. NE → NW) */ - DebugAccelF("(dix prtacc) query: no longer linear\n"); - /* instead of breaking it we might also inspect the partition after, - * but actual improvement with this is probably rare. */ - break; - } - - tracker_velocity = CalcTracker(tracker, cur_t) * velocity_factor; - - if ((initial_velocity == 0 || offset <= vel->initial_range) && tracker_velocity != 0) { - /* set initial velocity and result */ - result = initial_velocity = tracker_velocity; - used_offset = offset; - } else if (initial_velocity != 0 && tracker_velocity != 0) { - velocity_diff = fabs(initial_velocity - tracker_velocity); - - if (velocity_diff > vel->max_diff && - velocity_diff/(initial_velocity + tracker_velocity) >= vel->max_rel_diff) { - /* we're not in range, quit - it won't get better. */ - DebugAccelF("(dix prtacc) query: tracker too different:" - " old %2.2f initial %2.2f diff: %2.2f\n", - tracker_velocity, initial_velocity, velocity_diff); - break; - } - /* we're in range with the initial velocity, - * so this result is likely better - * (it contains more information). */ - result = tracker_velocity; - used_offset = offset; - } + for (offset = 1; offset < vel->num_tracker; offset++) { + MotionTracker *tracker = TRACKER(vel, offset); + double tracker_velocity; + + age_ms = cur_t - tracker->time; + + /* bail out if data is too old and protect from overrun */ + if (age_ms >= vel->reset_time || age_ms < 0) { + DebugAccelF("(dix prtacc) query: tracker too old\n"); + break; + } + + /* + * this heuristic avoids using the linear-motion velocity formula + * in CalcTracker() on motion that isn't exactly linear. So to get + * even more precision we could subdivide as a final step, so possible + * non-linearities are accounted for. + */ + dir &= tracker->dir; + if (dir == 0) { /* we've changed octant of movement (e.g. NE → NW) */ + DebugAccelF("(dix prtacc) query: no longer linear\n"); + /* instead of breaking it we might also inspect the partition after, + * but actual improvement with this is probably rare. */ + break; + } + + tracker_velocity = CalcTracker(tracker, cur_t) * velocity_factor; + + if ((initial_velocity == 0 || offset <= vel->initial_range) && + tracker_velocity != 0) { + /* set initial velocity and result */ + result = initial_velocity = tracker_velocity; + used_offset = offset; + } + else if (initial_velocity != 0 && tracker_velocity != 0) { + velocity_diff = fabs(initial_velocity - tracker_velocity); + + if (velocity_diff > vel->max_diff && + velocity_diff / (initial_velocity + tracker_velocity) >= + vel->max_rel_diff) { + /* we're not in range, quit - it won't get better. */ + DebugAccelF("(dix prtacc) query: tracker too different:" + " old %2.2f initial %2.2f diff: %2.2f\n", + tracker_velocity, initial_velocity, velocity_diff); + break; + } + /* we're in range with the initial velocity, + * so this result is likely better + * (it contains more information). */ + result = tracker_velocity; + used_offset = offset; + } } - if(offset == vel->num_tracker){ - DebugAccelF("(dix prtacc) query: last tracker in effect\n"); - used_offset = vel->num_tracker-1; + if (offset == vel->num_tracker) { + DebugAccelF("(dix prtacc) query: last tracker in effect\n"); + used_offset = vel->num_tracker - 1; } - if(used_offset >= 0){ + if (used_offset >= 0) { #ifdef PTRACCEL_DEBUGGING - MotionTracker *tracker = TRACKER(vel, used_offset); - DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n", - used_offset, tracker->dx, tracker->dy, cur_t - tracker->time); + MotionTracker *tracker = TRACKER(vel, used_offset); + + DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n", + used_offset, tracker->dx, tracker->dy, + cur_t - tracker->time); #endif } return result; @@ -667,11 +686,7 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){ * return true if non-visible state reset is suggested */ BOOL -ProcessVelocityData2D( - DeviceVelocityPtr vel, - double dx, - double dy, - int time) +ProcessVelocityData2D(DeviceVelocityPtr vel, double dx, double dy, int time) { double velocity; @@ -695,15 +710,14 @@ ApplySimpleSoftening(double prev_delta, double delta) double result = delta; if (delta < -1.0 || delta > 1.0) { - if (delta > prev_delta) - result -= 0.5; - else if (delta < prev_delta) - result += 0.5; + if (delta > prev_delta) + result -= 0.5; + else if (delta < prev_delta) + result += 0.5; } return result; } - /** * Soften the delta based on previous deltas stored in vel. * @@ -711,10 +725,7 @@ ApplySimpleSoftening(double prev_delta, double delta) * @param[in,out] fdx Delta Y, modified in-place. */ static void -ApplySoftening( - DeviceVelocityPtr vel, - double* fdx, - double* fdy) +ApplySoftening(DeviceVelocityPtr vel, double *fdx, double *fdy) { if (vel->use_softening) { *fdx = ApplySimpleSoftening(vel->last_dx, *fdx); @@ -733,19 +744,18 @@ ApplyConstantDeceleration(DeviceVelocityPtr vel, double *fdx, double *fdy) * compute the acceleration for given velocity and enforce min_acceleartion */ double -BasicComputeAcceleration( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double velocity, - double threshold, - double acc){ +BasicComputeAcceleration(DeviceIntPtr dev, + DeviceVelocityPtr vel, + double velocity, double threshold, double acc) +{ double result; + result = vel->Profile(dev, vel, velocity, threshold, acc); /* enforce min_acceleration */ if (result < vel->min_acceleration) - result = vel->min_acceleration; + result = vel->min_acceleration; return result; } @@ -755,47 +765,48 @@ BasicComputeAcceleration( * current velocity, last velocity and 4 times the average between the two. */ static double -ComputeAcceleration( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double threshold, - double acc){ +ComputeAcceleration(DeviceIntPtr dev, + DeviceVelocityPtr vel, double threshold, double acc) +{ double result; - if(vel->velocity <= 0){ - DebugAccelF("(dix ptracc) profile skipped\n"); + if (vel->velocity <= 0) { + DebugAccelF("(dix ptracc) profile skipped\n"); /* * If we have no idea about device velocity, don't pretend it. */ - return 1; + return 1; } - if(vel->average_accel && vel->velocity != vel->last_velocity){ - /* use simpson's rule to average acceleration between - * current and previous velocity. - * Though being the more natural choice, it causes a minor delay - * in comparison, so it can be disabled. */ - result = BasicComputeAcceleration( - dev, vel, vel->velocity, threshold, acc); - result += BasicComputeAcceleration( - dev, vel, vel->last_velocity, threshold, acc); - result += 4.0f * BasicComputeAcceleration(dev, vel, - (vel->last_velocity + vel->velocity) / 2, - threshold, acc); - result /= 6.0f; - DebugAccelF("(dix ptracc) profile average [%.2f ... %.2f] is %.3f\n", - vel->velocity, vel->last_velocity, result); - }else{ - result = BasicComputeAcceleration(dev, vel, - vel->velocity, threshold, acc); - DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n", - vel->velocity, res); + if (vel->average_accel && vel->velocity != vel->last_velocity) { + /* use simpson's rule to average acceleration between + * current and previous velocity. + * Though being the more natural choice, it causes a minor delay + * in comparison, so it can be disabled. */ + result = + BasicComputeAcceleration(dev, vel, vel->velocity, threshold, acc); + result += + BasicComputeAcceleration(dev, vel, vel->last_velocity, threshold, + acc); + result += + 4.0f * BasicComputeAcceleration(dev, vel, + (vel->last_velocity + + vel->velocity) / 2, threshold, + acc); + result /= 6.0f; + DebugAccelF("(dix ptracc) profile average [%.2f ... %.2f] is %.3f\n", + vel->velocity, vel->last_velocity, result); + } + else { + result = BasicComputeAcceleration(dev, vel, + vel->velocity, threshold, acc); + DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n", + vel->velocity, res); } return result; } - /***************************************** * Acceleration functions and profiles ****************************************/ @@ -804,45 +815,30 @@ ComputeAcceleration( * Polynomial function similar previous one, but with f(1) = 1 */ static double -PolynomialAccelerationProfile( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double velocity, - double ignored, - double acc) +PolynomialAccelerationProfile(DeviceIntPtr dev, + DeviceVelocityPtr vel, + double velocity, double ignored, double acc) { - return pow(velocity, (acc - 1.0) * 0.5); + return pow(velocity, (acc - 1.0) * 0.5); } - /** * returns acceleration for velocity. * This profile selects the two functions like the old scheme did */ static double -ClassicProfile( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double velocity, - double threshold, - double acc) +ClassicProfile(DeviceIntPtr dev, + DeviceVelocityPtr vel, + double velocity, double threshold, double acc) { if (threshold > 0) { - return SimpleSmoothProfile (dev, - vel, - velocity, - threshold, - acc); - } else { - return PolynomialAccelerationProfile (dev, - vel, - velocity, - 0, - acc); + return SimpleSmoothProfile(dev, vel, velocity, threshold, acc); + } + else { + return PolynomialAccelerationProfile(dev, vel, velocity, 0, acc); } } - /** * Power profile * This has a completely smooth transition curve, i.e. no jumps in the @@ -852,16 +848,13 @@ ClassicProfile( * In effect, min_acceleration mimics const_acceleration in this profile. */ static double -PowerProfile( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double velocity, - double threshold, - double acc) +PowerProfile(DeviceIntPtr dev, + DeviceVelocityPtr vel, + double velocity, double threshold, double acc) { double vel_dist; - acc = (acc-1.0) * 0.1f + 1.0; /* without this, acc of 2 is unuseable */ + acc = (acc - 1.0) * 0.1f + 1.0; /* without this, acc of 2 is unuseable */ if (velocity <= threshold) return vel->min_acceleration; @@ -869,7 +862,6 @@ PowerProfile( return (pow(acc, vel_dist)) * vel->min_acceleration; } - /** * just a smooth function in [0..1] -> [0..1] * - point symmetry at 0.5 @@ -878,28 +870,25 @@ PowerProfile( * - smoothness C1 (Cinf if you dare to ignore endpoints) */ static inline double -CalcPenumbralGradient(double x){ +CalcPenumbralGradient(double x) +{ x *= 2.0f; x -= 1.0f; - return 0.5f + (x * sqrt(1.0 - x*x) + asin(x))/M_PI; + return 0.5f + (x * sqrt(1.0 - x * x) + asin(x)) / M_PI; } - /** * acceleration function similar to classic accelerated/unaccelerated, * but with smooth transition in between (and towards zero for adaptive dec.). */ static double -SimpleSmoothProfile( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double velocity, - double threshold, - double acc) +SimpleSmoothProfile(DeviceIntPtr dev, + DeviceVelocityPtr vel, + double velocity, double threshold, double acc) { - if(velocity < 1.0f) - return CalcPenumbralGradient(0.5 + velocity*0.5) * 2.0f - 1.0f; - if(threshold < 1.0f) + if (velocity < 1.0f) + return CalcPenumbralGradient(0.5 + velocity * 0.5) * 2.0f - 1.0f; + if (threshold < 1.0f) threshold = 1.0f; if (velocity <= threshold) return 1; @@ -907,118 +896,102 @@ SimpleSmoothProfile( if (velocity >= acc) return acc; else - return 1.0f + (CalcPenumbralGradient(velocity/acc) * (acc - 1.0f)); + return 1.0f + (CalcPenumbralGradient(velocity / acc) * (acc - 1.0f)); } - /** * This profile uses the first half of the penumbral gradient as a start * and then scales linearly. */ static double -SmoothLinearProfile( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double velocity, - double threshold, - double acc) +SmoothLinearProfile(DeviceIntPtr dev, + DeviceVelocityPtr vel, + double velocity, double threshold, double acc) { double res, nv; - if(acc > 1.0f) - acc -= 1.0f; /*this is so acc = 1 is no acceleration */ + if (acc > 1.0f) + acc -= 1.0f; /*this is so acc = 1 is no acceleration */ else return 1.0f; nv = (velocity - threshold) * acc * 0.5f; - if(nv < 0){ + if (nv < 0) { res = 0; - }else if(nv < 2){ - res = CalcPenumbralGradient(nv*0.25f)*2.0f; - }else{ + } + else if (nv < 2) { + res = CalcPenumbralGradient(nv * 0.25f) * 2.0f; + } + else { nv -= 2.0f; res = nv * 2.0f / M_PI /* steepness of gradient at 0.5 */ - + 1.0f; /* gradient crosses 2|1 */ + + 1.0f; /* gradient crosses 2|1 */ } res += vel->min_acceleration; return res; } - /** * From 0 to threshold, the response graduates smoothly from min_accel to * acceleration. Beyond threshold it is exactly the specified acceleration. */ static double -SmoothLimitedProfile( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double velocity, - double threshold, - double acc) +SmoothLimitedProfile(DeviceIntPtr dev, + DeviceVelocityPtr vel, + double velocity, double threshold, double acc) { double res; - if(velocity >= threshold || threshold == 0.0f) - return acc; + if (velocity >= threshold || threshold == 0.0f) + return acc; - velocity /= threshold; /* should be [0..1[ now */ + velocity /= threshold; /* should be [0..1[ now */ res = CalcPenumbralGradient(velocity) * (acc - vel->min_acceleration); return vel->min_acceleration + res; } - static double -LinearProfile( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double velocity, - double threshold, - double acc) +LinearProfile(DeviceIntPtr dev, + DeviceVelocityPtr vel, + double velocity, double threshold, double acc) { return acc * velocity; } static double -NoProfile( - DeviceIntPtr dev, - DeviceVelocityPtr vel, - double velocity, - double threshold, - double acc) +NoProfile(DeviceIntPtr dev, + DeviceVelocityPtr vel, double velocity, double threshold, double acc) { return 1.0f; } static PointerAccelerationProfileFunc -GetAccelerationProfile( - DeviceVelocityPtr vel, - int profile_num) +GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num) { - switch(profile_num){ - case AccelProfileClassic: - return ClassicProfile; - case AccelProfileDeviceSpecific: - return vel->deviceSpecificProfile; - case AccelProfilePolynomial: - return PolynomialAccelerationProfile; - case AccelProfileSmoothLinear: - return SmoothLinearProfile; - case AccelProfileSimple: - return SimpleSmoothProfile; - case AccelProfilePower: - return PowerProfile; - case AccelProfileLinear: - return LinearProfile; - case AccelProfileSmoothLimited: - return SmoothLimitedProfile; - case AccelProfileNone: - return NoProfile; - default: - return NULL; + switch (profile_num) { + case AccelProfileClassic: + return ClassicProfile; + case AccelProfileDeviceSpecific: + return vel->deviceSpecificProfile; + case AccelProfilePolynomial: + return PolynomialAccelerationProfile; + case AccelProfileSmoothLinear: + return SmoothLinearProfile; + case AccelProfileSimple: + return SimpleSmoothProfile; + case AccelProfilePower: + return PowerProfile; + case AccelProfileLinear: + return LinearProfile; + case AccelProfileSmoothLimited: + return SmoothLimitedProfile; + case AccelProfileNone: + return NoProfile; + default: + return NULL; } } @@ -1033,15 +1006,14 @@ GetAccelerationProfile( * returns FALSE if profile number is unavailable, TRUE otherwise. */ int -SetAccelerationProfile( - DeviceVelocityPtr vel, - int profile_num) +SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num) { PointerAccelerationProfileFunc profile; + profile = GetAccelerationProfile(vel, profile_num); - if(profile == NULL && profile_num != PROFILE_UNINITIALIZE) - return FALSE; + if (profile == NULL && profile_num != PROFILE_UNINITIALIZE) + return FALSE; /* Here one could free old profile-private data */ free(vel->profile_private); @@ -1056,7 +1028,6 @@ SetAccelerationProfile( * driver interaction **********************************************/ - /** * device-specific profile * @@ -1067,12 +1038,11 @@ SetAccelerationProfile( * Users may override or choose it. */ void -SetDeviceSpecificAccelerationProfile( - DeviceVelocityPtr vel, - PointerAccelerationProfileFunc profile) +SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel, + PointerAccelerationProfileFunc profile) { - if(vel) - vel->deviceSpecificProfile = profile; + if (vel) + vel->deviceSpecificProfile = profile; } /** @@ -1080,21 +1050,20 @@ SetDeviceSpecificAccelerationProfile( * the predictable acceleration scheme is not in effect. */ DeviceVelocityPtr -GetDevicePredictableAccelData( - DeviceIntPtr dev) +GetDevicePredictableAccelData(DeviceIntPtr dev) { - /*sanity check*/ - if(!dev){ - ErrorF("[dix] accel: DeviceIntPtr was NULL"); - return NULL; + /*sanity check */ + if (!dev) { + ErrorF("[dix] accel: DeviceIntPtr was NULL"); + return NULL; } - if( dev->valuator && - dev->valuator->accelScheme.AccelSchemeProc == - acceleratePointerPredictable && - dev->valuator->accelScheme.accelData != NULL){ + if (dev->valuator && + dev->valuator->accelScheme.AccelSchemeProc == + acceleratePointerPredictable && + dev->valuator->accelScheme.accelData != NULL) { - return ((PredictableAccelSchemePtr) - dev->valuator->accelScheme.accelData)->vel; + return ((PredictableAccelSchemePtr) + dev->valuator->accelScheme.accelData)->vel; } return NULL; } @@ -1109,10 +1078,7 @@ GetDevicePredictableAccelData( * enable fine-grained predictable acceleration profiles. */ void -acceleratePointerPredictable( - DeviceIntPtr dev, - ValuatorMask* val, - CARD32 evtime) +acceleratePointerPredictable(DeviceIntPtr dev, ValuatorMask *val, CARD32 evtime) { double dx = 0, dy = 0; DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev); @@ -1123,7 +1089,7 @@ acceleratePointerPredictable( if (velocitydata->statistics.profile_number == AccelProfileNone && velocitydata->const_acceleration == 1.0f) { - return; /*we're inactive anyway, so skip the whole thing.*/ + return; /*we're inactive anyway, so skip the whole thing. */ } if (valuator_mask_isset(val, 0)) { @@ -1136,7 +1102,7 @@ acceleratePointerPredictable( if (dx != 0.0 || dy != 0.0) { /* reset non-visible state? */ - if (ProcessVelocityData2D(velocitydata, dx , dy, evtime)) { + if (ProcessVelocityData2D(velocitydata, dx, dy, evtime)) { soften = FALSE; } @@ -1144,12 +1110,12 @@ acceleratePointerPredictable( double mult; /* invoke acceleration profile to determine acceleration */ - mult = ComputeAcceleration (dev, velocitydata, - dev->ptrfeed->ctrl.threshold, - (double)dev->ptrfeed->ctrl.num / - (double)dev->ptrfeed->ctrl.den); + mult = ComputeAcceleration(dev, velocitydata, + dev->ptrfeed->ctrl.threshold, + (double) dev->ptrfeed->ctrl.num / + (double) dev->ptrfeed->ctrl.den); - if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) { + if (mult != 1.0f || velocitydata->const_acceleration != 1.0f) { if (mult > 1.0f && soften) ApplySoftening(velocitydata, &dx, &dy); ApplyConstantDeceleration(velocitydata, &dx, &dy); @@ -1168,17 +1134,13 @@ acceleratePointerPredictable( velocitydata->last_dy = dy; } - - /** * Originally a part of xf86PostMotionEvent; modifies valuators * in-place. Retained mostly for embedded scenarios. */ void -acceleratePointerLightweight( - DeviceIntPtr dev, - ValuatorMask* val, - CARD32 ignored) +acceleratePointerLightweight(DeviceIntPtr dev, + ValuatorMask *val, CARD32 ignored) { double mult = 0.0, tmpf; double dx = 0.0, dy = 0.0; @@ -1199,23 +1161,22 @@ acceleratePointerLightweight( if (dev->ptrfeed->ctrl.threshold) { if ((fabs(dx) + fabs(dy)) >= dev->ptrfeed->ctrl.threshold) { if (dx != 0.0) { - tmpf = (dx * (double)(dev->ptrfeed->ctrl.num)) / - (double)(dev->ptrfeed->ctrl.den); + tmpf = (dx * (double) (dev->ptrfeed->ctrl.num)) / + (double) (dev->ptrfeed->ctrl.den); valuator_mask_set_double(val, 0, tmpf); } if (dy != 0.0) { - tmpf = (dy * (double)(dev->ptrfeed->ctrl.num)) / - (double)(dev->ptrfeed->ctrl.den); + tmpf = (dy * (double) (dev->ptrfeed->ctrl.num)) / + (double) (dev->ptrfeed->ctrl.den); valuator_mask_set_double(val, 1, tmpf); } } } else { - mult = pow(dx * dx + dy * dy, - ((double)(dev->ptrfeed->ctrl.num) / - (double)(dev->ptrfeed->ctrl.den) - 1.0) / - 2.0) / 2.0; + mult = pow(dx * dx + dy * dy, + ((double) (dev->ptrfeed->ctrl.num) / + (double) (dev->ptrfeed->ctrl.den) - 1.0) / 2.0) / 2.0; if (dx != 0.0) valuator_mask_set_double(val, 0, mult * dx); if (dy != 0.0) diff --git a/xorg-server/dix/region.c b/xorg-server/dix/region.c index 6820c1eac..737d2a861 100644 --- a/xorg-server/dix/region.c +++ b/xorg-server/dix/region.c @@ -202,7 +202,6 @@ if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \ assert(pReg->data->numRects<=pReg->data->size); \ } - #define DOWNSIZE(reg,numRects) \ if (((numRects) < ((reg)->data->size >> 1)) && ((reg)->data->size > 50)) \ { \ @@ -215,17 +214,17 @@ if (((numRects) < ((reg)->data->size >> 1)) && ((reg)->data->size > 50)) \ } \ } +BoxRec RegionEmptyBox = { 0, 0, 0, 0 }; +RegDataRec RegionEmptyData = { 0, 0 }; -BoxRec RegionEmptyBox = {0, 0, 0, 0}; -RegDataRec RegionEmptyData = {0, 0}; - -RegDataRec RegionBrokenData = {0, 0}; -static RegionRec RegionBrokenRegion = { { 0, 0, 0, 0 }, &RegionBrokenData }; +RegDataRec RegionBrokenData = { 0, 0 }; +static RegionRec RegionBrokenRegion = { {0, 0, 0, 0}, &RegionBrokenData }; void -InitRegions (void) +InitRegions(void) { - pixman_region_set_static_pointers (&RegionEmptyBox, &RegionEmptyData, &RegionBrokenData); + pixman_region_set_static_pointers(&RegionEmptyBox, &RegionEmptyData, + &RegionBrokenData); } /***************************************************************** @@ -238,22 +237,22 @@ RegionPtr RegionCreate(BoxPtr rect, int size) { RegionPtr pReg; - - pReg = (RegionPtr)malloc(sizeof(RegionRec)); + + pReg = (RegionPtr) malloc(sizeof(RegionRec)); if (!pReg) - return &RegionBrokenRegion; + return &RegionBrokenRegion; + + RegionInit(pReg, rect, size); - RegionInit (pReg, rect, size); - return pReg; } void RegionDestroy(RegionPtr pReg) { - pixman_region_fini (pReg); + pixman_region_fini(pReg); if (pReg != &RegionBrokenRegion) - free(pReg); + free(pReg); } void @@ -268,10 +267,10 @@ RegionPrint(RegionPtr rgn) rects = RegionRects(rgn); ErrorF("[mi] num: %d size: %d\n", num, size); ErrorF("[mi] extents: %d %d %d %d\n", - rgn->extents.x1, rgn->extents.y1, rgn->extents.x2, rgn->extents.y2); + rgn->extents.x1, rgn->extents.y1, rgn->extents.x2, rgn->extents.y2); for (i = 0; i < num; i++) - ErrorF("[mi] %d %d %d %d \n", - rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2); + ErrorF("[mi] %d %d %d %d \n", + rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2); ErrorF("[mi] \n"); } @@ -280,52 +279,48 @@ Bool RegionIsValid(RegionPtr reg) { int i, numRects; - + if ((reg->extents.x1 > reg->extents.x2) || - (reg->extents.y1 > reg->extents.y2)) - return FALSE; + (reg->extents.y1 > reg->extents.y2)) + return FALSE; numRects = RegionNumRects(reg); if (!numRects) - return ((reg->extents.x1 == reg->extents.x2) && - (reg->extents.y1 == reg->extents.y2) && - (reg->data->size || (reg->data == &RegionEmptyData))); + return ((reg->extents.x1 == reg->extents.x2) && + (reg->extents.y1 == reg->extents.y2) && + (reg->data->size || (reg->data == &RegionEmptyData))); else if (numRects == 1) - return !reg->data; - else - { - BoxPtr pboxP, pboxN; - BoxRec box; - - pboxP = RegionRects(reg); - box = *pboxP; - box.y2 = pboxP[numRects-1].y2; - pboxN = pboxP + 1; - for (i = numRects; --i > 0; pboxP++, pboxN++) - { - if ((pboxN->x1 >= pboxN->x2) || - (pboxN->y1 >= pboxN->y2)) - return FALSE; - if (pboxN->x1 < box.x1) - box.x1 = pboxN->x1; - if (pboxN->x2 > box.x2) - box.x2 = pboxN->x2; - if ((pboxN->y1 < pboxP->y1) || - ((pboxN->y1 == pboxP->y1) && - ((pboxN->x1 < pboxP->x2) || (pboxN->y2 != pboxP->y2)))) - return FALSE; - } - return ((box.x1 == reg->extents.x1) && - (box.x2 == reg->extents.x2) && - (box.y1 == reg->extents.y1) && - (box.y2 == reg->extents.y2)); + return !reg->data; + else { + BoxPtr pboxP, pboxN; + BoxRec box; + + pboxP = RegionRects(reg); + box = *pboxP; + box.y2 = pboxP[numRects - 1].y2; + pboxN = pboxP + 1; + for (i = numRects; --i > 0; pboxP++, pboxN++) { + if ((pboxN->x1 >= pboxN->x2) || (pboxN->y1 >= pboxN->y2)) + return FALSE; + if (pboxN->x1 < box.x1) + box.x1 = pboxN->x1; + if (pboxN->x2 > box.x2) + box.x2 = pboxN->x2; + if ((pboxN->y1 < pboxP->y1) || + ((pboxN->y1 == pboxP->y1) && + ((pboxN->x1 < pboxP->x2) || (pboxN->y2 != pboxP->y2)))) + return FALSE; + } + return ((box.x1 == reg->extents.x1) && + (box.x2 == reg->extents.x2) && + (box.y1 == reg->extents.y1) && (box.y2 == reg->extents.y2)); } } -#endif /* DEBUG */ +#endif /* DEBUG */ Bool -RegionBreak (RegionPtr pReg) +RegionBreak(RegionPtr pReg) { - xfreeData (pReg); + xfreeData(pReg); pReg->extents = RegionEmptyBox; pReg->data = &RegionBrokenData; return FALSE; @@ -334,37 +329,33 @@ RegionBreak (RegionPtr pReg) Bool RegionRectAlloc(RegionPtr pRgn, int n) { - RegDataPtr data; - - if (!pRgn->data) - { - n++; - pRgn->data = xallocData(n); - if (!pRgn->data) - return RegionBreak (pRgn); - pRgn->data->numRects = 1; - *RegionBoxptr(pRgn) = pRgn->extents; + RegDataPtr data; + + if (!pRgn->data) { + n++; + pRgn->data = xallocData(n); + if (!pRgn->data) + return RegionBreak(pRgn); + pRgn->data->numRects = 1; + *RegionBoxptr(pRgn) = pRgn->extents; } - else if (!pRgn->data->size) - { - pRgn->data = xallocData(n); - if (!pRgn->data) - return RegionBreak (pRgn); - pRgn->data->numRects = 0; + else if (!pRgn->data->size) { + pRgn->data = xallocData(n); + if (!pRgn->data) + return RegionBreak(pRgn); + pRgn->data->numRects = 0; } - else - { - if (n == 1) - { - n = pRgn->data->numRects; - if (n > 500) /* XXX pick numbers out of a hat */ - n = 250; - } - n += pRgn->data->numRects; - data = (RegDataPtr)realloc(pRgn->data, RegionSizeof(n)); - if (!data) - return RegionBreak (pRgn); - pRgn->data = data; + else { + if (n == 1) { + n = pRgn->data->numRects; + if (n > 500) /* XXX pick numbers out of a hat */ + n = 250; + } + n += pRgn->data->numRects; + data = (RegDataPtr) realloc(pRgn->data, RegionSizeof(n)); + if (!data) + return RegionBreak(pRgn); + pRgn->data = data; } pRgn->data->size = n; return TRUE; @@ -393,22 +384,23 @@ RegionRectAlloc(RegionPtr pRgn, int n) *----------------------------------------------------------------------- */ _X_INLINE static int -RegionCoalesce ( - RegionPtr pReg, /* Region to coalesce */ - int prevStart, /* Index of start of previous band */ - int curStart) /* Index of start of current band */ -{ - BoxPtr pPrevBox; /* Current box in previous band */ - BoxPtr pCurBox; /* Current box in current band */ - int numRects; /* Number rectangles in both bands */ - int y2; /* Bottom of current band */ +RegionCoalesce(RegionPtr pReg, /* Region to coalesce */ + int prevStart, /* Index of start of previous band */ + int curStart) +{ /* Index of start of current band */ + BoxPtr pPrevBox; /* Current box in previous band */ + BoxPtr pCurBox; /* Current box in current band */ + int numRects; /* Number rectangles in both bands */ + int y2; /* Bottom of current band */ + /* * Figure out how many rectangles are in the band. */ numRects = curStart - prevStart; assert(numRects == pReg->data->numRects - curStart); - if (!numRects) return curStart; + if (!numRects) + return curStart; /* * The bands may only be coalesced if the bottom of the previous @@ -416,7 +408,8 @@ RegionCoalesce ( */ pPrevBox = RegionBox(pReg, prevStart); pCurBox = RegionBox(pReg, curStart); - if (pPrevBox->y2 != pCurBox->y1) return curStart; + if (pPrevBox->y2 != pCurBox->y1) + return curStart; /* * Make sure the bands have boxes in the same places. This @@ -427,12 +420,12 @@ RegionCoalesce ( y2 = pCurBox->y2; do { - if ((pPrevBox->x1 != pCurBox->x1) || (pPrevBox->x2 != pCurBox->x2)) { - return curStart; - } - pPrevBox++; - pCurBox++; - numRects--; + if ((pPrevBox->x1 != pCurBox->x1) || (pPrevBox->x2 != pCurBox->x2)) { + return curStart; + } + pPrevBox++; + pCurBox++; + numRects--; } while (numRects); /* @@ -442,14 +435,13 @@ RegionCoalesce ( numRects = curStart - prevStart; pReg->data->numRects -= numRects; do { - pPrevBox--; - pPrevBox->y2 = y2; - numRects--; + pPrevBox--; + pPrevBox->y2 = y2; + numRects--; } while (numRects); return prevStart; } - /* Quicky macro to avoid trivial reject procedure calls to RegionCoalesce */ #define Coalesce(newReg, prevBand, curBand) \ @@ -477,15 +469,10 @@ RegionCoalesce ( */ _X_INLINE static Bool -RegionAppendNonO ( - RegionPtr pReg, - BoxPtr r, - BoxPtr rEnd, - int y1, - int y2) +RegionAppendNonO(RegionPtr pReg, BoxPtr r, BoxPtr rEnd, int y1, int y2) { - BoxPtr pNextRect; - int newRects; + BoxPtr pNextRect; + int newRects; newRects = rEnd - r; @@ -497,9 +484,9 @@ RegionAppendNonO ( pNextRect = RegionTop(pReg); pReg->data->numRects += newRects; do { - assert(r->x1 < r->x2); - ADDRECT(pNextRect, r->x1, y1, r->x2, y2); - r++; + assert(r->x1 < r->x2); + ADDRECT(pNextRect, r->x1, y1, r->x2, y2); + r++; } while (r != rEnd); return TRUE; @@ -554,58 +541,54 @@ RegionAppendNonO ( *----------------------------------------------------------------------- */ -typedef Bool (*OverlapProcPtr)( - RegionPtr pReg, - BoxPtr r1, - BoxPtr r1End, - BoxPtr r2, - BoxPtr r2End, - short y1, - short y2, - Bool *pOverlap); +typedef Bool (*OverlapProcPtr) (RegionPtr pReg, + BoxPtr r1, + BoxPtr r1End, + BoxPtr r2, + BoxPtr r2End, + short y1, short y2, Bool *pOverlap); static Bool -RegionOp( - RegionPtr newReg, /* Place to store result */ - RegionPtr reg1, /* First region in operation */ - RegionPtr reg2, /* 2d region in operation */ - OverlapProcPtr overlapFunc, /* Function to call for over- - * lapping bands */ - Bool appendNon1, /* Append non-overlapping bands */ - /* in region 1 ? */ - Bool appendNon2, /* Append non-overlapping bands */ - /* in region 2 ? */ - Bool *pOverlap) +RegionOp(RegionPtr newReg, /* Place to store result */ + RegionPtr reg1, /* First region in operation */ + RegionPtr reg2, /* 2d region in operation */ + OverlapProcPtr overlapFunc, /* Function to call for over- + * lapping bands */ + Bool appendNon1, /* Append non-overlapping bands */ + /* in region 1 ? */ + Bool appendNon2, /* Append non-overlapping bands */ + /* in region 2 ? */ + Bool *pOverlap) { - BoxPtr r1; /* Pointer into first region */ - BoxPtr r2; /* Pointer into 2d region */ - BoxPtr r1End; /* End of 1st region */ - BoxPtr r2End; /* End of 2d region */ - short ybot; /* Bottom of intersection */ - short ytop; /* Top of intersection */ - RegDataPtr oldData; /* Old data for newReg */ - int prevBand; /* Index of start of - * previous band in newReg */ - int curBand; /* Index of start of current - * band in newReg */ - BoxPtr r1BandEnd; /* End of current band in r1 */ - BoxPtr r2BandEnd; /* End of current band in r2 */ - short top; /* Top of non-overlapping band */ - short bot; /* Bottom of non-overlapping band*/ - int r1y1; /* Temps for r1->y1 and r2->y1 */ - int r2y1; - int newSize; - int numRects; + BoxPtr r1; /* Pointer into first region */ + BoxPtr r2; /* Pointer into 2d region */ + BoxPtr r1End; /* End of 1st region */ + BoxPtr r2End; /* End of 2d region */ + short ybot; /* Bottom of intersection */ + short ytop; /* Top of intersection */ + RegDataPtr oldData; /* Old data for newReg */ + int prevBand; /* Index of start of + * previous band in newReg */ + int curBand; /* Index of start of current + * band in newReg */ + BoxPtr r1BandEnd; /* End of current band in r1 */ + BoxPtr r2BandEnd; /* End of current band in r2 */ + short top; /* Top of non-overlapping band */ + short bot; /* Bottom of non-overlapping band */ + int r1y1; /* Temps for r1->y1 and r2->y1 */ + int r2y1; + int newSize; + int numRects; /* * Break any region computed from a broken region */ - if (RegionNar (reg1) || RegionNar(reg2)) - return RegionBreak (newReg); - + if (RegionNar(reg1) || RegionNar(reg2)) + return RegionBreak(newReg); + /* * Initialization: - * set r1, r2, r1End and r2End appropriately, save the rectangles + * set r1, r2, r1End and r2End appropriately, save the rectangles * of the destination region until the end in case it's one of * the two source regions, then mark the "new" region empty, allocating * another array of rectangles for it to use. @@ -622,39 +605,38 @@ RegionOp( oldData = NULL; if (((newReg == reg1) && (newSize > 1)) || - ((newReg == reg2) && (numRects > 1))) - { - oldData = newReg->data; - newReg->data = &RegionEmptyData; + ((newReg == reg2) && (numRects > 1))) { + oldData = newReg->data; + newReg->data = &RegionEmptyData; } /* guess at new size */ if (numRects > newSize) - newSize = numRects; + newSize = numRects; newSize <<= 1; if (!newReg->data) - newReg->data = &RegionEmptyData; + newReg->data = &RegionEmptyData; else if (newReg->data->size) - newReg->data->numRects = 0; + newReg->data->numRects = 0; if (newSize > newReg->data->size) - if (!RegionRectAlloc(newReg, newSize)) - return FALSE; + if (!RegionRectAlloc(newReg, newSize)) + return FALSE; /* * Initialize ybot. * In the upcoming loop, ybot and ytop serve different functions depending * on whether the band being handled is an overlapping or non-overlapping * band. - * In the case of a non-overlapping band (only one of the regions + * In the case of a non-overlapping band (only one of the regions * has points in the band), ybot is the bottom of the most recent * intersection and thus clips the top of the rectangles in that band. * ytop is the top of the next intersection between the two regions and * serves to clip the bottom of the rectangles in the current band. - * For an overlapping band (where the two regions intersect), ytop clips + * For an overlapping band (where the two regions intersect), ytop clips * the top of the rectangles of both regions and ybot clips the bottoms. */ ybot = min(r1->y1, r2->y1); - + /* * prevBand serves to mark the start of the previous band so rectangles * can be coalesced into larger rectangles. qv. RegionCoalesce, above. @@ -665,73 +647,77 @@ RegionOp( * array of rectangles. */ prevBand = 0; - + do { - /* - * This algorithm proceeds one source-band (as opposed to a - * destination band, which is determined by where the two regions - * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the - * rectangle after the last one in the current band for their - * respective regions. - */ - assert(r1 != r1End); - assert(r2 != r2End); - - FindBand(r1, r1BandEnd, r1End, r1y1); - FindBand(r2, r2BandEnd, r2End, r2y1); - - /* - * First handle the band that doesn't intersect, if any. - * - * Note that attention is restricted to one band in the - * non-intersecting region at once, so if a region has n - * bands between the current position and the next place it overlaps - * the other, this entire loop will be passed through n times. - */ - if (r1y1 < r2y1) { - if (appendNon1) { - top = max(r1y1, ybot); - bot = min(r1->y2, r2y1); - if (top != bot) { - curBand = newReg->data->numRects; - RegionAppendNonO(newReg, r1, r1BandEnd, top, bot); - Coalesce(newReg, prevBand, curBand); - } - } - ytop = r2y1; - } else if (r2y1 < r1y1) { - if (appendNon2) { - top = max(r2y1, ybot); - bot = min(r2->y2, r1y1); - if (top != bot) { - curBand = newReg->data->numRects; - RegionAppendNonO(newReg, r2, r2BandEnd, top, bot); - Coalesce(newReg, prevBand, curBand); - } - } - ytop = r1y1; - } else { - ytop = r1y1; - } - - /* - * Now see if we've hit an intersecting band. The two bands only - * intersect if ybot > ytop - */ - ybot = min(r1->y2, r2->y2); - if (ybot > ytop) { - curBand = newReg->data->numRects; - (* overlapFunc)(newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot, - pOverlap); - Coalesce(newReg, prevBand, curBand); - } - - /* - * If we've finished with a band (y2 == ybot) we skip forward - * in the region to the next band. - */ - if (r1->y2 == ybot) r1 = r1BandEnd; - if (r2->y2 == ybot) r2 = r2BandEnd; + /* + * This algorithm proceeds one source-band (as opposed to a + * destination band, which is determined by where the two regions + * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the + * rectangle after the last one in the current band for their + * respective regions. + */ + assert(r1 != r1End); + assert(r2 != r2End); + + FindBand(r1, r1BandEnd, r1End, r1y1); + FindBand(r2, r2BandEnd, r2End, r2y1); + + /* + * First handle the band that doesn't intersect, if any. + * + * Note that attention is restricted to one band in the + * non-intersecting region at once, so if a region has n + * bands between the current position and the next place it overlaps + * the other, this entire loop will be passed through n times. + */ + if (r1y1 < r2y1) { + if (appendNon1) { + top = max(r1y1, ybot); + bot = min(r1->y2, r2y1); + if (top != bot) { + curBand = newReg->data->numRects; + RegionAppendNonO(newReg, r1, r1BandEnd, top, bot); + Coalesce(newReg, prevBand, curBand); + } + } + ytop = r2y1; + } + else if (r2y1 < r1y1) { + if (appendNon2) { + top = max(r2y1, ybot); + bot = min(r2->y2, r1y1); + if (top != bot) { + curBand = newReg->data->numRects; + RegionAppendNonO(newReg, r2, r2BandEnd, top, bot); + Coalesce(newReg, prevBand, curBand); + } + } + ytop = r1y1; + } + else { + ytop = r1y1; + } + + /* + * Now see if we've hit an intersecting band. The two bands only + * intersect if ybot > ytop + */ + ybot = min(r1->y2, r2->y2); + if (ybot > ytop) { + curBand = newReg->data->numRects; + (*overlapFunc) (newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot, + pOverlap); + Coalesce(newReg, prevBand, curBand); + } + + /* + * If we've finished with a band (y2 == ybot) we skip forward + * in the region to the next band. + */ + if (r1->y2 == ybot) + r1 = r1BandEnd; + if (r2->y2 == ybot) + r2 = r2BandEnd; } while (r1 != r1End && r2 != r2End); @@ -744,40 +730,38 @@ RegionOp( */ if ((r1 != r1End) && appendNon1) { - /* Do first nonOverlap1Func call, which may be able to coalesce */ - FindBand(r1, r1BandEnd, r1End, r1y1); - curBand = newReg->data->numRects; - RegionAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2); - Coalesce(newReg, prevBand, curBand); - /* Just append the rest of the boxes */ - AppendRegions(newReg, r1BandEnd, r1End); - - } else if ((r2 != r2End) && appendNon2) { - /* Do first nonOverlap2Func call, which may be able to coalesce */ - FindBand(r2, r2BandEnd, r2End, r2y1); - curBand = newReg->data->numRects; - RegionAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2); - Coalesce(newReg, prevBand, curBand); - /* Append rest of boxes */ - AppendRegions(newReg, r2BandEnd, r2End); + /* Do first nonOverlap1Func call, which may be able to coalesce */ + FindBand(r1, r1BandEnd, r1End, r1y1); + curBand = newReg->data->numRects; + RegionAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2); + Coalesce(newReg, prevBand, curBand); + /* Just append the rest of the boxes */ + AppendRegions(newReg, r1BandEnd, r1End); + + } + else if ((r2 != r2End) && appendNon2) { + /* Do first nonOverlap2Func call, which may be able to coalesce */ + FindBand(r2, r2BandEnd, r2End, r2y1); + curBand = newReg->data->numRects; + RegionAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2); + Coalesce(newReg, prevBand, curBand); + /* Append rest of boxes */ + AppendRegions(newReg, r2BandEnd, r2End); } free(oldData); - if (!(numRects = newReg->data->numRects)) - { - xfreeData(newReg); - newReg->data = &RegionEmptyData; + if (!(numRects = newReg->data->numRects)) { + xfreeData(newReg); + newReg->data = &RegionEmptyData; } - else if (numRects == 1) - { - newReg->extents = *RegionBoxptr(newReg); - xfreeData(newReg); - newReg->data = NULL; + else if (numRects == 1) { + newReg->extents = *RegionBoxptr(newReg); + xfreeData(newReg); + newReg->data = NULL; } - else - { - DOWNSIZE(newReg, numRects); + else { + DOWNSIZE(newReg, numRects); } return TRUE; @@ -799,17 +783,16 @@ RegionOp( *----------------------------------------------------------------------- */ static void -RegionSetExtents (RegionPtr pReg) +RegionSetExtents(RegionPtr pReg) { BoxPtr pBox, pBoxEnd; if (!pReg->data) - return; - if (!pReg->data->size) - { - pReg->extents.x2 = pReg->extents.x1; - pReg->extents.y2 = pReg->extents.y1; - return; + return; + if (!pReg->data->size) { + pReg->extents.x2 = pReg->extents.x1; + pReg->extents.y2 = pReg->extents.y1; + return; } pBox = RegionBoxptr(pReg); @@ -829,11 +812,11 @@ RegionSetExtents (RegionPtr pReg) assert(pReg->extents.y1 < pReg->extents.y2); while (pBox <= pBoxEnd) { - if (pBox->x1 < pReg->extents.x1) - pReg->extents.x1 = pBox->x1; - if (pBox->x2 > pReg->extents.x2) - pReg->extents.x2 = pBox->x2; - pBox++; + if (pBox->x1 < pReg->extents.x1) + pReg->extents.x1 = pBox->x1; + if (pBox->x2 > pReg->extents.x2) + pReg->extents.x2 = pBox->x2; + pBox++; }; assert(pReg->extents.x1 < pReg->extents.x2); @@ -855,8 +838,7 @@ RegionSetExtents (RegionPtr pReg) * *----------------------------------------------------------------------- */ -/*ARGSUSED*/ - + /*ARGSUSED*/ #define MERGERECT(r) \ { \ if (r->x1 <= x2) { \ @@ -871,11 +853,9 @@ RegionSetExtents (RegionPtr pReg) } \ r++; \ } - /*====================================================================== * Region Union *====================================================================*/ - /*- *----------------------------------------------------------------------- * RegionUnionO -- @@ -891,60 +871,51 @@ RegionSetExtents (RegionPtr pReg) * *----------------------------------------------------------------------- */ -static Bool -RegionUnionO ( - RegionPtr pReg, - BoxPtr r1, - BoxPtr r1End, - BoxPtr r2, - BoxPtr r2End, - short y1, - short y2, - Bool *pOverlap) + static Bool +RegionUnionO(RegionPtr pReg, + BoxPtr r1, + BoxPtr r1End, + BoxPtr r2, BoxPtr r2End, short y1, short y2, Bool *pOverlap) { - BoxPtr pNextRect; - int x1; /* left and right side of current union */ - int x2; + BoxPtr pNextRect; + int x1; /* left and right side of current union */ + int x2; - assert (y1 < y2); + assert(y1 < y2); assert(r1 != r1End && r2 != r2End); pNextRect = RegionTop(pReg); /* Start off current rectangle */ - if (r1->x1 < r2->x1) - { - x1 = r1->x1; - x2 = r1->x2; - r1++; + if (r1->x1 < r2->x1) { + x1 = r1->x1; + x2 = r1->x2; + r1++; } - else - { - x1 = r2->x1; - x2 = r2->x2; - r2++; + else { + x1 = r2->x1; + x2 = r2->x2; + r2++; } - while (r1 != r1End && r2 != r2End) - { - if (r1->x1 < r2->x1) MERGERECT(r1) else MERGERECT(r2); + while (r1 != r1End && r2 != r2End) { + if (r1->x1 < r2->x1) + MERGERECT(r1) + else + MERGERECT(r2); } /* Finish off whoever (if any) is left */ - if (r1 != r1End) - { - do - { - MERGERECT(r1); - } while (r1 != r1End); + if (r1 != r1End) { + do { + MERGERECT(r1); + } while (r1 != r1End); } - else if (r2 != r2End) - { - do - { - MERGERECT(r2); - } while (r2 != r2End); + else if (r2 != r2End) { + do { + MERGERECT(r2); + } while (r2 != r2End); } - + /* Add current rectangle */ NEWRECT(pReg, pNextRect, x1, y1, x2, y2); @@ -980,83 +951,76 @@ RegionAppend(RegionPtr dstrgn, RegionPtr rgn) Bool prepend; if (RegionNar(rgn)) - return RegionBreak (dstrgn); - - if (!rgn->data && (dstrgn->data == &RegionEmptyData)) - { - dstrgn->extents = rgn->extents; - dstrgn->data = NULL; - return TRUE; + return RegionBreak(dstrgn); + + if (!rgn->data && (dstrgn->data == &RegionEmptyData)) { + dstrgn->extents = rgn->extents; + dstrgn->data = NULL; + return TRUE; } numRects = RegionNumRects(rgn); if (!numRects) - return TRUE; + return TRUE; prepend = FALSE; size = numRects; dnumRects = RegionNumRects(dstrgn); if (!dnumRects && (size < 200)) - size = 200; /* XXX pick numbers out of a hat */ + size = 200; /* XXX pick numbers out of a hat */ RECTALLOC(dstrgn, size); old = RegionRects(rgn); if (!dnumRects) - dstrgn->extents = rgn->extents; - else if (dstrgn->extents.x2 > dstrgn->extents.x1) - { - BoxPtr first, last; - - first = old; - last = RegionBoxptr(dstrgn) + (dnumRects - 1); - if ((first->y1 > last->y2) || - ((first->y1 == last->y1) && (first->y2 == last->y2) && - (first->x1 > last->x2))) - { - if (rgn->extents.x1 < dstrgn->extents.x1) - dstrgn->extents.x1 = rgn->extents.x1; - if (rgn->extents.x2 > dstrgn->extents.x2) - dstrgn->extents.x2 = rgn->extents.x2; - dstrgn->extents.y2 = rgn->extents.y2; - } - else - { - first = RegionBoxptr(dstrgn); - last = old + (numRects - 1); - if ((first->y1 > last->y2) || - ((first->y1 == last->y1) && (first->y2 == last->y2) && - (first->x1 > last->x2))) - { - prepend = TRUE; - if (rgn->extents.x1 < dstrgn->extents.x1) - dstrgn->extents.x1 = rgn->extents.x1; - if (rgn->extents.x2 > dstrgn->extents.x2) - dstrgn->extents.x2 = rgn->extents.x2; - dstrgn->extents.y1 = rgn->extents.y1; - } - else - dstrgn->extents.x2 = dstrgn->extents.x1; - } + dstrgn->extents = rgn->extents; + else if (dstrgn->extents.x2 > dstrgn->extents.x1) { + BoxPtr first, last; + + first = old; + last = RegionBoxptr(dstrgn) + (dnumRects - 1); + if ((first->y1 > last->y2) || + ((first->y1 == last->y1) && (first->y2 == last->y2) && + (first->x1 > last->x2))) { + if (rgn->extents.x1 < dstrgn->extents.x1) + dstrgn->extents.x1 = rgn->extents.x1; + if (rgn->extents.x2 > dstrgn->extents.x2) + dstrgn->extents.x2 = rgn->extents.x2; + dstrgn->extents.y2 = rgn->extents.y2; + } + else { + first = RegionBoxptr(dstrgn); + last = old + (numRects - 1); + if ((first->y1 > last->y2) || + ((first->y1 == last->y1) && (first->y2 == last->y2) && + (first->x1 > last->x2))) { + prepend = TRUE; + if (rgn->extents.x1 < dstrgn->extents.x1) + dstrgn->extents.x1 = rgn->extents.x1; + if (rgn->extents.x2 > dstrgn->extents.x2) + dstrgn->extents.x2 = rgn->extents.x2; + dstrgn->extents.y1 = rgn->extents.y1; + } + else + dstrgn->extents.x2 = dstrgn->extents.x1; + } } - if (prepend) - { - new = RegionBox(dstrgn, numRects); - if (dnumRects == 1) - *new = *RegionBoxptr(dstrgn); - else - memmove((char *)new,(char *)RegionBoxptr(dstrgn), - dnumRects * sizeof(BoxRec)); - new = RegionBoxptr(dstrgn); + if (prepend) { + new = RegionBox(dstrgn, numRects); + if (dnumRects == 1) + *new = *RegionBoxptr(dstrgn); + else + memmove((char *) new, (char *) RegionBoxptr(dstrgn), + dnumRects * sizeof(BoxRec)); + new = RegionBoxptr(dstrgn); } else - new = RegionBoxptr(dstrgn) + dnumRects; + new = RegionBoxptr(dstrgn) + dnumRects; if (numRects == 1) - *new = *old; + *new = *old; else - memmove((char *)new, (char *)old, numRects * sizeof(BoxRec)); + memmove((char *) new, (char *) old, numRects * sizeof(BoxRec)); dstrgn->data->numRects += numRects; return TRUE; } - #define ExchangeRects(a, b) \ { \ BoxRec t; \ @@ -1066,60 +1030,53 @@ RegionAppend(RegionPtr dstrgn, RegionPtr rgn) } static void -QuickSortRects( - BoxRec rects[], - int numRects) +QuickSortRects(BoxRec rects[], int numRects) { - int y1; - int x1; - int i, j; - BoxPtr r; + int y1; + int x1; + int i, j; + BoxPtr r; /* Always called with numRects > 1 */ - do - { - if (numRects == 2) - { - if (rects[0].y1 > rects[1].y1 || - (rects[0].y1 == rects[1].y1 && rects[0].x1 > rects[1].x1)) - ExchangeRects(0, 1); - return; - } - - /* Choose partition element, stick in location 0 */ + do { + if (numRects == 2) { + if (rects[0].y1 > rects[1].y1 || + (rects[0].y1 == rects[1].y1 && rects[0].x1 > rects[1].x1)) + ExchangeRects(0, 1); + return; + } + + /* Choose partition element, stick in location 0 */ ExchangeRects(0, numRects >> 1); - y1 = rects[0].y1; - x1 = rects[0].x1; + y1 = rects[0].y1; + x1 = rects[0].x1; /* Partition array */ i = 0; j = numRects; - do - { - r = &(rects[i]); - do - { - r++; - i++; + do { + r = &(rects[i]); + do { + r++; + i++; } while (i != numRects && - (r->y1 < y1 || (r->y1 == y1 && r->x1 < x1))); - r = &(rects[j]); - do - { - r--; - j--; + (r->y1 < y1 || (r->y1 == y1 && r->x1 < x1))); + r = &(rects[j]); + do { + r--; + j--; } while (y1 < r->y1 || (y1 == r->y1 && x1 < r->x1)); if (i < j) - ExchangeRects(i, j); + ExchangeRects(i, j); } while (i < j); /* Move partition element back to middle */ ExchangeRects(0, j); - /* Recurse */ - if (numRects-j-1 > 1) - QuickSortRects(&rects[j+1], numRects-j-1); + /* Recurse */ + if (numRects - j - 1 > 1) + QuickSortRects(&rects[j + 1], numRects - j - 1); numRects = j; } while (numRects > 1); } @@ -1161,51 +1118,46 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap) { /* Descriptor for regions under construction in Step 2. */ typedef struct { - RegionRec reg; - int prevBand; - int curBand; + RegionRec reg; + int prevBand; + int curBand; } RegionInfo; - int numRects; /* Original numRects for badreg */ - RegionInfo *ri; /* Array of current regions */ - int numRI; /* Number of entries used in ri */ - int sizeRI; /* Number of entries available in ri */ - int i; /* Index into rects */ - int j; /* Index into ri */ - RegionInfo *rit; /* &ri[j] */ - RegionPtr reg; /* ri[j].reg */ - BoxPtr box; /* Current box in rects */ - BoxPtr riBox; /* Last box in ri[j].reg */ - RegionPtr hreg; /* ri[j_half].reg */ - Bool ret = TRUE; + int numRects; /* Original numRects for badreg */ + RegionInfo *ri; /* Array of current regions */ + int numRI; /* Number of entries used in ri */ + int sizeRI; /* Number of entries available in ri */ + int i; /* Index into rects */ + int j; /* Index into ri */ + RegionInfo *rit; /* &ri[j] */ + RegionPtr reg; /* ri[j].reg */ + BoxPtr box; /* Current box in rects */ + BoxPtr riBox; /* Last box in ri[j].reg */ + RegionPtr hreg; /* ri[j_half].reg */ + Bool ret = TRUE; *pOverlap = FALSE; - if (!badreg->data) - { - good(badreg); - return TRUE; + if (!badreg->data) { + good(badreg); + return TRUE; } numRects = badreg->data->numRects; - if (!numRects) - { - if (RegionNar(badreg)) - return FALSE; - good(badreg); - return TRUE; + if (!numRects) { + if (RegionNar(badreg)) + return FALSE; + good(badreg); + return TRUE; } - if (badreg->extents.x1 < badreg->extents.x2) - { - if ((numRects) == 1) - { - xfreeData(badreg); - badreg->data = (RegDataPtr) NULL; - } - else - { - DOWNSIZE(badreg, numRects); - } - good(badreg); - return TRUE; + if (badreg->extents.x1 < badreg->extents.x2) { + if ((numRects) == 1) { + xfreeData(badreg); + badreg->data = (RegDataPtr) NULL; + } + else { + DOWNSIZE(badreg, numRects); + } + good(badreg); + return TRUE; } /* Step 1: Sort the rects array into ascending (y1, x1) order */ @@ -1217,7 +1169,7 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap) /* Note that step 2 code will never overflow the ri[0].reg rects array */ ri = (RegionInfo *) malloc(4 * sizeof(RegionInfo)); if (!ri) - return RegionBreak (badreg); + return RegionBreak(badreg); sizeRI = 4; numRI = 1; ri[0].prevBand = 0; @@ -1233,193 +1185,181 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap) forget it. Try the next region. If it doesn't fit cleanly into any region, make a new one. */ - for (i = numRects; --i > 0;) - { - box++; - /* Look for a region to append box to */ - for (j = numRI, rit = ri; --j >= 0; rit++) - { - reg = &rit->reg; - riBox = RegionEnd(reg); - - if (box->y1 == riBox->y1 && box->y2 == riBox->y2) - { - /* box is in same band as riBox. Merge or append it */ - if (box->x1 <= riBox->x2) - { - /* Merge it with riBox */ - if (box->x1 < riBox->x2) *pOverlap = TRUE; - if (box->x2 > riBox->x2) riBox->x2 = box->x2; - } - else - { - RECTALLOC_BAIL(reg, 1, bail); - *RegionTop(reg) = *box; - reg->data->numRects++; - } - goto NextRect; /* So sue me */ - } - else if (box->y1 >= riBox->y2) - { - /* Put box into new band */ - if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2; - if (reg->extents.x1 > box->x1) reg->extents.x1 = box->x1; - Coalesce(reg, rit->prevBand, rit->curBand); - rit->curBand = reg->data->numRects; - RECTALLOC_BAIL(reg, 1, bail); - *RegionTop(reg) = *box; - reg->data->numRects++; - goto NextRect; - } - /* Well, this region was inappropriate. Try the next one. */ - } /* for j */ - - /* Uh-oh. No regions were appropriate. Create a new one. */ - if (sizeRI == numRI) - { - /* Oops, allocate space for new region information */ - sizeRI <<= 1; - rit = (RegionInfo *) realloc(ri, sizeRI * sizeof(RegionInfo)); - if (!rit) - goto bail; - ri = rit; - rit = &ri[numRI]; - } - numRI++; - rit->prevBand = 0; - rit->curBand = 0; - rit->reg.extents = *box; - rit->reg.data = NULL; - if (!RegionRectAlloc(&rit->reg, (i+numRI) / numRI)) /* MUST force allocation */ - goto bail; -NextRect: ; - } /* for i */ + for (i = numRects; --i > 0;) { + box++; + /* Look for a region to append box to */ + for (j = numRI, rit = ri; --j >= 0; rit++) { + reg = &rit->reg; + riBox = RegionEnd(reg); + + if (box->y1 == riBox->y1 && box->y2 == riBox->y2) { + /* box is in same band as riBox. Merge or append it */ + if (box->x1 <= riBox->x2) { + /* Merge it with riBox */ + if (box->x1 < riBox->x2) + *pOverlap = TRUE; + if (box->x2 > riBox->x2) + riBox->x2 = box->x2; + } + else { + RECTALLOC_BAIL(reg, 1, bail); + *RegionTop(reg) = *box; + reg->data->numRects++; + } + goto NextRect; /* So sue me */ + } + else if (box->y1 >= riBox->y2) { + /* Put box into new band */ + if (reg->extents.x2 < riBox->x2) + reg->extents.x2 = riBox->x2; + if (reg->extents.x1 > box->x1) + reg->extents.x1 = box->x1; + Coalesce(reg, rit->prevBand, rit->curBand); + rit->curBand = reg->data->numRects; + RECTALLOC_BAIL(reg, 1, bail); + *RegionTop(reg) = *box; + reg->data->numRects++; + goto NextRect; + } + /* Well, this region was inappropriate. Try the next one. */ + } /* for j */ + + /* Uh-oh. No regions were appropriate. Create a new one. */ + if (sizeRI == numRI) { + /* Oops, allocate space for new region information */ + sizeRI <<= 1; + rit = (RegionInfo *) realloc(ri, sizeRI * sizeof(RegionInfo)); + if (!rit) + goto bail; + ri = rit; + rit = &ri[numRI]; + } + numRI++; + rit->prevBand = 0; + rit->curBand = 0; + rit->reg.extents = *box; + rit->reg.data = NULL; + if (!RegionRectAlloc(&rit->reg, (i + numRI) / numRI)) /* MUST force allocation */ + goto bail; + NextRect:; + } /* for i */ /* Make a final pass over each region in order to Coalesce and set extents.x2 and extents.y2 */ - for (j = numRI, rit = ri; --j >= 0; rit++) - { - reg = &rit->reg; - riBox = RegionEnd(reg); - reg->extents.y2 = riBox->y2; - if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2; - Coalesce(reg, rit->prevBand, rit->curBand); - if (reg->data->numRects == 1) /* keep unions happy below */ - { - xfreeData(reg); - reg->data = NULL; - } + for (j = numRI, rit = ri; --j >= 0; rit++) { + reg = &rit->reg; + riBox = RegionEnd(reg); + reg->extents.y2 = riBox->y2; + if (reg->extents.x2 < riBox->x2) + reg->extents.x2 = riBox->x2; + Coalesce(reg, rit->prevBand, rit->curBand); + if (reg->data->numRects == 1) { /* keep unions happy below */ + xfreeData(reg); + reg->data = NULL; + } } /* Step 3: Union all regions into a single region */ - while (numRI > 1) - { - int half = numRI/2; - for (j = numRI & 1; j < (half + (numRI & 1)); j++) - { - reg = &ri[j].reg; - hreg = &ri[j+half].reg; - if (!RegionOp(reg, reg, hreg, RegionUnionO, TRUE, TRUE, pOverlap)) - ret = FALSE; - if (hreg->extents.x1 < reg->extents.x1) - reg->extents.x1 = hreg->extents.x1; - if (hreg->extents.y1 < reg->extents.y1) - reg->extents.y1 = hreg->extents.y1; - if (hreg->extents.x2 > reg->extents.x2) - reg->extents.x2 = hreg->extents.x2; - if (hreg->extents.y2 > reg->extents.y2) - reg->extents.y2 = hreg->extents.y2; - xfreeData(hreg); - } - numRI -= half; + while (numRI > 1) { + int half = numRI / 2; + + for (j = numRI & 1; j < (half + (numRI & 1)); j++) { + reg = &ri[j].reg; + hreg = &ri[j + half].reg; + if (!RegionOp(reg, reg, hreg, RegionUnionO, TRUE, TRUE, pOverlap)) + ret = FALSE; + if (hreg->extents.x1 < reg->extents.x1) + reg->extents.x1 = hreg->extents.x1; + if (hreg->extents.y1 < reg->extents.y1) + reg->extents.y1 = hreg->extents.y1; + if (hreg->extents.x2 > reg->extents.x2) + reg->extents.x2 = hreg->extents.x2; + if (hreg->extents.y2 > reg->extents.y2) + reg->extents.y2 = hreg->extents.y2; + xfreeData(hreg); + } + numRI -= half; } *badreg = ri[0].reg; free(ri); good(badreg); return ret; -bail: + bail: for (i = 0; i < numRI; i++) - xfreeData(&ri[i].reg); + xfreeData(&ri[i].reg); free(ri); - return RegionBreak (badreg); + return RegionBreak(badreg); } RegionPtr RegionFromRects(int nrects, xRectangle *prect, int ctype) { - - RegionPtr pRgn; - RegDataPtr pData; - BoxPtr pBox; - int i; - int x1, y1, x2, y2; + + RegionPtr pRgn; + RegDataPtr pData; + BoxPtr pBox; + int i; + int x1, y1, x2, y2; pRgn = RegionCreate(NullBox, 0); - if (RegionNar (pRgn)) - return pRgn; + if (RegionNar(pRgn)) + return pRgn; if (!nrects) - return pRgn; - if (nrects == 1) - { - x1 = prect->x; - y1 = prect->y; - if ((x2 = x1 + (int) prect->width) > MAXSHORT) - x2 = MAXSHORT; - if ((y2 = y1 + (int) prect->height) > MAXSHORT) - y2 = MAXSHORT; - if (x1 != x2 && y1 != y2) - { - pRgn->extents.x1 = x1; - pRgn->extents.y1 = y1; - pRgn->extents.x2 = x2; - pRgn->extents.y2 = y2; - pRgn->data = NULL; - } - return pRgn; + return pRgn; + if (nrects == 1) { + x1 = prect->x; + y1 = prect->y; + if ((x2 = x1 + (int) prect->width) > MAXSHORT) + x2 = MAXSHORT; + if ((y2 = y1 + (int) prect->height) > MAXSHORT) + y2 = MAXSHORT; + if (x1 != x2 && y1 != y2) { + pRgn->extents.x1 = x1; + pRgn->extents.y1 = y1; + pRgn->extents.x2 = x2; + pRgn->extents.y2 = y2; + pRgn->data = NULL; + } + return pRgn; } pData = xallocData(nrects); - if (!pData) - { - RegionBreak (pRgn); - return pRgn; + if (!pData) { + RegionBreak(pRgn); + return pRgn; } pBox = (BoxPtr) (pData + 1); - for (i = nrects; --i >= 0; prect++) - { - x1 = prect->x; - y1 = prect->y; - if ((x2 = x1 + (int) prect->width) > MAXSHORT) - x2 = MAXSHORT; - if ((y2 = y1 + (int) prect->height) > MAXSHORT) - y2 = MAXSHORT; - if (x1 != x2 && y1 != y2) - { - pBox->x1 = x1; - pBox->y1 = y1; - pBox->x2 = x2; - pBox->y2 = y2; - pBox++; - } + for (i = nrects; --i >= 0; prect++) { + x1 = prect->x; + y1 = prect->y; + if ((x2 = x1 + (int) prect->width) > MAXSHORT) + x2 = MAXSHORT; + if ((y2 = y1 + (int) prect->height) > MAXSHORT) + y2 = MAXSHORT; + if (x1 != x2 && y1 != y2) { + pBox->x1 = x1; + pBox->y1 = y1; + pBox->x2 = x2; + pBox->y2 = y2; + pBox++; + } } - if (pBox != (BoxPtr) (pData + 1)) - { - pData->size = nrects; - pData->numRects = pBox - (BoxPtr) (pData + 1); - pRgn->data = pData; - if (ctype != CT_YXBANDED) - { - Bool overlap; /* result ignored */ - pRgn->extents.x1 = pRgn->extents.x2 = 0; - RegionValidate(pRgn, &overlap); - } - else - RegionSetExtents(pRgn); - good(pRgn); + if (pBox != (BoxPtr) (pData + 1)) { + pData->size = nrects; + pData->numRects = pBox - (BoxPtr) (pData + 1); + pRgn->data = pData; + if (ctype != CT_YXBANDED) { + Bool overlap; /* result ignored */ + + pRgn->extents.x1 = pRgn->extents.x2 = 0; + RegionValidate(pRgn, &overlap); + } + else + RegionSetExtents(pRgn); + good(pRgn); } - else - { - free(pData); + else { + free(pData); } return pRgn; } diff --git a/xorg-server/dix/registry.c b/xorg-server/dix/registry.c index 5ab25ad70..e9c19b092 100644 --- a/xorg-server/dix/registry.c +++ b/xorg-server/dix/registry.c @@ -48,43 +48,45 @@ static unsigned nmajor, *nminor, nevent, nerror, nresource; /* * File parsing routines */ -static int double_size(void *p, unsigned n, unsigned size) +static int +double_size(void *p, unsigned n, unsigned size) { - char **ptr = (char **)p; + char **ptr = (char **) p; unsigned s, f; if (n) { - s = n * size; - n *= 2 * size; - f = n; - } else { - s = 0; - n = f = BASE_SIZE * size; + s = n * size; + n *= 2 * size; + f = n; + } + else { + s = 0; + n = f = BASE_SIZE * size; } *ptr = realloc(*ptr, n); if (!*ptr) { - dixResetRegistry(); - return FALSE; + dixResetRegistry(); + return FALSE; } memset(*ptr + s, 0, f - s); return TRUE; -} +} static void RegisterRequestName(unsigned major, unsigned minor, char *name) { while (major >= nmajor) { - if (!double_size(&requests, nmajor, sizeof(char **))) - return; - if (!double_size(&nminor, nmajor, sizeof(unsigned))) - return; - nmajor = nmajor ? nmajor * 2 : BASE_SIZE; + if (!double_size(&requests, nmajor, sizeof(char **))) + return; + if (!double_size(&nminor, nmajor, sizeof(unsigned))) + return; + nmajor = nmajor ? nmajor * 2 : BASE_SIZE; } while (minor >= nminor[major]) { - if (!double_size(requests+major, nminor[major], sizeof(char *))) - return; - nminor[major] = nminor[major] ? nminor[major] * 2 : BASE_SIZE; + if (!double_size(requests + major, nminor[major], sizeof(char *))) + return; + nminor[major] = nminor[major] ? nminor[major] * 2 : BASE_SIZE; } free(requests[major][minor]); @@ -92,11 +94,12 @@ RegisterRequestName(unsigned major, unsigned minor, char *name) } static void -RegisterEventName(unsigned event, char *name) { +RegisterEventName(unsigned event, char *name) +{ while (event >= nevent) { - if (!double_size(&events, nevent, sizeof(char *))) - return; - nevent = nevent ? nevent * 2 : BASE_SIZE; + if (!double_size(&events, nevent, sizeof(char *))) + return; + nevent = nevent ? nevent * 2 : BASE_SIZE; } free(events[event]); @@ -104,11 +107,12 @@ RegisterEventName(unsigned event, char *name) { } static void -RegisterErrorName(unsigned error, char *name) { +RegisterErrorName(unsigned error, char *name) +{ while (error >= nerror) { - if (!double_size(&errors, nerror, sizeof(char *))) - return; - nerror = nerror ? nerror * 2 : BASE_SIZE; + if (!double_size(&errors, nerror, sizeof(char *))) + return; + nerror = nerror ? nerror * 2 : BASE_SIZE; } free(errors[error]); @@ -116,80 +120,80 @@ RegisterErrorName(unsigned error, char *name) { } void -RegisterExtensionNames(ExtensionEntry *extEntry) +RegisterExtensionNames(ExtensionEntry * extEntry) { char buf[256], *lineobj, *ptr; unsigned offset; if (fh == NULL) - return; + return; rewind(fh); while (fgets(buf, sizeof(buf), fh)) { - lineobj = NULL; - ptr = strchr(buf, '\n'); - if (ptr) - *ptr = 0; - - /* Check for comments or empty lines */ - switch (buf[0]) { - case PROT_REQUEST: - case PROT_EVENT: - case PROT_ERROR: - break; - case PROT_COMMENT: - case '\0': - continue; - default: - goto invalid; - } - - /* Check for space character in the fifth position */ - ptr = strchr(buf, ' '); - if (!ptr || ptr != buf + 4) - goto invalid; - - /* Duplicate the string after the space */ - lineobj = strdup(ptr + 1); - if (!lineobj) - continue; - - /* Check for a colon somewhere on the line */ - ptr = strchr(buf, ':'); - if (!ptr) - goto invalid; - - /* Compare the part before colon with the target extension name */ - *ptr = 0; - if (strcmp(buf + 5, extEntry->name)) - goto skip; - - /* Get the opcode for the request, event, or error */ - offset = strtol(buf + 1, &ptr, 10); - if (offset == 0 && ptr == buf + 1) - goto invalid; - - /* Save the strdup result in the registry */ - switch(buf[0]) { - case PROT_REQUEST: - if (extEntry->base) - RegisterRequestName(extEntry->base, offset, lineobj); - else - RegisterRequestName(offset, 0, lineobj); - continue; - case PROT_EVENT: - RegisterEventName(extEntry->eventBase + offset, lineobj); - continue; - case PROT_ERROR: - RegisterErrorName(extEntry->errorBase + offset, lineobj); - continue; - } - - invalid: - LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n"); - skip: - free(lineobj); + lineobj = NULL; + ptr = strchr(buf, '\n'); + if (ptr) + *ptr = 0; + + /* Check for comments or empty lines */ + switch (buf[0]) { + case PROT_REQUEST: + case PROT_EVENT: + case PROT_ERROR: + break; + case PROT_COMMENT: + case '\0': + continue; + default: + goto invalid; + } + + /* Check for space character in the fifth position */ + ptr = strchr(buf, ' '); + if (!ptr || ptr != buf + 4) + goto invalid; + + /* Duplicate the string after the space */ + lineobj = strdup(ptr + 1); + if (!lineobj) + continue; + + /* Check for a colon somewhere on the line */ + ptr = strchr(buf, ':'); + if (!ptr) + goto invalid; + + /* Compare the part before colon with the target extension name */ + *ptr = 0; + if (strcmp(buf + 5, extEntry->name)) + goto skip; + + /* Get the opcode for the request, event, or error */ + offset = strtol(buf + 1, &ptr, 10); + if (offset == 0 && ptr == buf + 1) + goto invalid; + + /* Save the strdup result in the registry */ + switch (buf[0]) { + case PROT_REQUEST: + if (extEntry->base) + RegisterRequestName(extEntry->base, offset, lineobj); + else + RegisterRequestName(offset, 0, lineobj); + continue; + case PROT_EVENT: + RegisterEventName(extEntry->eventBase + offset, lineobj); + continue; + case PROT_ERROR: + RegisterErrorName(extEntry->errorBase + offset, lineobj); + continue; + } + + invalid: + LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n"); + skip: + free(lineobj); } } @@ -203,9 +207,9 @@ RegisterResourceName(RESTYPE resource, const char *name) resource &= TypeMask; while (resource >= nresource) { - if (!double_size(&resources, nresource, sizeof(char *))) - return; - nresource = nresource ? nresource * 2 : BASE_SIZE; + if (!double_size(&resources, nresource, sizeof(char *))) + return; + nresource = nresource ? nresource * 2 : BASE_SIZE; } resources[resource] = name; @@ -219,9 +223,9 @@ const char * LookupRequestName(int major, int minor) { if (major >= nmajor) - return XREGISTRY_UNKNOWN; + return XREGISTRY_UNKNOWN; if (minor >= nminor[major]) - return XREGISTRY_UNKNOWN; + return XREGISTRY_UNKNOWN; return requests[major][minor] ? requests[major][minor] : XREGISTRY_UNKNOWN; } @@ -230,18 +234,20 @@ const char * LookupMajorName(int major) { if (major < 128) { - const char *retval; - - if (major >= nmajor) - return XREGISTRY_UNKNOWN; - if (0 >= nminor[major]) - return XREGISTRY_UNKNOWN; - - retval = requests[major][0]; - return retval ? retval + sizeof(CORE) : XREGISTRY_UNKNOWN; - } else { - ExtensionEntry *extEntry = GetExtensionEntry(major); - return extEntry ? extEntry->name : XREGISTRY_UNKNOWN; + const char *retval; + + if (major >= nmajor) + return XREGISTRY_UNKNOWN; + if (0 >= nminor[major]) + return XREGISTRY_UNKNOWN; + + retval = requests[major][0]; + return retval ? retval + sizeof(CORE) : XREGISTRY_UNKNOWN; + } + else { + ExtensionEntry *extEntry = GetExtensionEntry(major); + + return extEntry ? extEntry->name : XREGISTRY_UNKNOWN; } } @@ -250,7 +256,7 @@ LookupEventName(int event) { event &= 127; if (event >= nevent) - return XREGISTRY_UNKNOWN; + return XREGISTRY_UNKNOWN; return events[event] ? events[event] : XREGISTRY_UNKNOWN; } @@ -259,7 +265,7 @@ const char * LookupErrorName(int error) { if (error >= nerror) - return XREGISTRY_UNKNOWN; + return XREGISTRY_UNKNOWN; return errors[error] ? errors[error] : XREGISTRY_UNKNOWN; } @@ -269,7 +275,7 @@ LookupResourceName(RESTYPE resource) { resource &= TypeMask; if (resource >= nresource) - return XREGISTRY_UNKNOWN; + return XREGISTRY_UNKNOWN; return resources[resource] ? resources[resource] : XREGISTRY_UNKNOWN; } @@ -284,19 +290,19 @@ dixResetRegistry(void) /* Free all memory */ while (nmajor--) { - while (nminor[nmajor]) - free(requests[nmajor][--nminor[nmajor]]); - free(requests[nmajor]); + while (nminor[nmajor]) + free(requests[nmajor][--nminor[nmajor]]); + free(requests[nmajor]); } free(requests); free(nminor); while (nevent--) - free(events[nevent]); + free(events[nevent]); free(events); while (nerror--) - free(errors[nerror]); + free(errors[nerror]); free(errors); free(resources); @@ -311,10 +317,11 @@ dixResetRegistry(void) /* Open the protocol file */ if (fh) - fclose(fh); + fclose(fh); fh = fopen(FILENAME, "r"); if (!fh) - LogMessage(X_WARNING, "Failed to open protocol names file " FILENAME "\n"); + LogMessage(X_WARNING, + "Failed to open protocol names file " FILENAME "\n"); /* Add built-in resources */ RegisterResourceName(RT_NONE, "NONE"); @@ -334,4 +341,4 @@ dixResetRegistry(void) RegisterExtensionNames(&extEntry); } -#endif /* XREGISTRY */ +#endif /* XREGISTRY */ diff --git a/xorg-server/dix/resource.c b/xorg-server/dix/resource.c index be8a8f81b..89d077642 100644 --- a/xorg-server/dix/resource.c +++ b/xorg-server/dix/resource.c @@ -22,7 +22,6 @@ 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 @@ -126,7 +125,7 @@ Equipment Corporation. #include "misc.h" #include "os.h" #include "resource.h" -#include "dixstruct.h" +#include "dixstruct.h" #include "opaque.h" #include "windowstr.h" #include "dixfont.h" @@ -146,14 +145,14 @@ Equipment Corporation. #ifdef XSERVER_DTRACE #include <sys/types.h> typedef const char *string; + #include "Xserver-dtrace.h" #define TypeNameString(t) LookupResourceName(t) #endif -static void RebuildTable( - int /*client*/ -); +static void RebuildTable(int /*client */ + ); #define SERVER_MINID 32 @@ -162,19 +161,19 @@ static void RebuildTable( #define MAXHASHSIZE 11 typedef struct _Resource { - struct _Resource *next; - XID id; - RESTYPE type; - pointer value; + struct _Resource *next; + XID id; + RESTYPE type; + pointer value; } ResourceRec, *ResourcePtr; typedef struct _ClientResource { ResourcePtr *resources; - int elements; - int buckets; - int hashsize; /* log(2)(buckets) */ - XID fakeID; - XID endFakeID; + int elements; + int buckets; + int hashsize; /* log(2)(buckets) */ + XID fakeID; + XID endFakeID; } ClientResourceRec; RESTYPE lastResourceType; @@ -187,57 +186,58 @@ struct ResourceType { }; static struct ResourceType *resourceTypes; + static const struct ResourceType predefTypes[] = { [RT_NONE & (RC_LASTPREDEF - 1)] = { - .deleteFunc = (DeleteType)NoopDDA, - .errorValue = BadValue, - }, + .deleteFunc = (DeleteType) NoopDDA, + .errorValue = BadValue, + }, [RT_WINDOW & (RC_LASTPREDEF - 1)] = { - .deleteFunc = DeleteWindow, - .errorValue = BadWindow, - }, + .deleteFunc = DeleteWindow, + .errorValue = BadWindow, + }, [RT_PIXMAP & (RC_LASTPREDEF - 1)] = { - .deleteFunc = dixDestroyPixmap, - .errorValue = BadPixmap, - }, + .deleteFunc = dixDestroyPixmap, + .errorValue = BadPixmap, + }, [RT_GC & (RC_LASTPREDEF - 1)] = { - .deleteFunc = FreeGC, - .errorValue = BadGC, - }, + .deleteFunc = FreeGC, + .errorValue = BadGC, + }, [RT_FONT & (RC_LASTPREDEF - 1)] = { - .deleteFunc = CloseFont, - .errorValue = BadFont, - }, + .deleteFunc = CloseFont, + .errorValue = BadFont, + }, [RT_CURSOR & (RC_LASTPREDEF - 1)] = { - .deleteFunc = FreeCursor, - .errorValue = BadCursor, - }, + .deleteFunc = FreeCursor, + .errorValue = BadCursor, + }, [RT_COLORMAP & (RC_LASTPREDEF - 1)] = { - .deleteFunc = FreeColormap, - .errorValue = BadColor, - }, + .deleteFunc = FreeColormap, + .errorValue = BadColor, + }, [RT_CMAPENTRY & (RC_LASTPREDEF - 1)] = { - .deleteFunc = FreeClientPixels, - .errorValue = BadColor, - }, + .deleteFunc = FreeClientPixels, + .errorValue = BadColor, + }, [RT_OTHERCLIENT & (RC_LASTPREDEF - 1)] = { - .deleteFunc = OtherClientGone, - .errorValue = BadValue, - }, + .deleteFunc = OtherClientGone, + .errorValue = BadValue, + }, [RT_PASSIVEGRAB & (RC_LASTPREDEF - 1)] = { - .deleteFunc = DeletePassiveGrab, - .errorValue = BadValue, - }, + .deleteFunc = DeletePassiveGrab, + .errorValue = BadValue, + }, }; CallbackListPtr ResourceStateCallback; static _X_INLINE void -CallResourceStateCallback(ResourceState state, ResourceRec *res) +CallResourceStateCallback(ResourceState state, ResourceRec * res) { if (ResourceStateCallback) { - ResourceStateInfoRec rsi = { state, res->id, res->type, res->value }; - CallCallbacks(&ResourceStateCallback, &rsi); + ResourceStateInfoRec rsi = { state, res->id, res->type, res->value }; + CallCallbacks(&ResourceStateCallback, &rsi); } } @@ -248,10 +248,10 @@ CreateNewResourceType(DeleteType deleteFunc, const char *name) struct ResourceType *types; if (next & lastResourceClass) - return 0; + return 0; types = realloc(resourceTypes, (next + 1) * sizeof(*resourceTypes)); if (!types) - return 0; + return 0; lastResourceType = next; resourceTypes = types; @@ -276,7 +276,7 @@ CreateNewResourceClass(void) RESTYPE next = lastResourceClass >> 1; if (next & lastResourceType) - return 0; + return 0; lastResourceClass = next; TypeMask = next - 1; return next; @@ -294,22 +294,21 @@ Bool InitClientResources(ClientPtr client) { int i, j; - - if (client == serverClient) - { - lastResourceType = RT_LASTPREDEF; - lastResourceClass = RC_LASTPREDEF; - TypeMask = RC_LASTPREDEF - 1; - free(resourceTypes); - resourceTypes = malloc(sizeof(predefTypes)); - if (!resourceTypes) - return FALSE; - memcpy(resourceTypes, predefTypes, sizeof(predefTypes)); + + if (client == serverClient) { + lastResourceType = RT_LASTPREDEF; + lastResourceClass = RC_LASTPREDEF; + TypeMask = RC_LASTPREDEF - 1; + free(resourceTypes); + resourceTypes = malloc(sizeof(predefTypes)); + if (!resourceTypes) + return FALSE; + memcpy(resourceTypes, predefTypes, sizeof(predefTypes)); } clientTable[i = client->index].resources = - malloc(INITBUCKETS*sizeof(ResourcePtr)); + malloc(INITBUCKETS * sizeof(ResourcePtr)); if (!clientTable[i].resources) - return FALSE; + return FALSE; clientTable[i].buckets = INITBUCKETS; clientTable[i].elements = 0; clientTable[i].hashsize = INITHASHSIZE; @@ -319,56 +318,48 @@ InitClientResources(ClientPtr client) * clients, we can start from zero, with SERVER_BIT set. */ clientTable[i].fakeID = client->clientAsMask | - (client->index ? SERVER_BIT : SERVER_MINID); + (client->index ? SERVER_BIT : SERVER_MINID); clientTable[i].endFakeID = (clientTable[i].fakeID | RESOURCE_ID_MASK) + 1; - for (j=0; j<INITBUCKETS; j++) - { + for (j = 0; j < INITBUCKETS; j++) { clientTable[i].resources[j] = NULL; } return TRUE; } - static int Hash(int client, XID id) { id &= RESOURCE_ID_MASK; - switch (clientTable[client].hashsize) - { - case 6: - return ((int)(0x03F & (id ^ (id>>6) ^ (id>>12)))); - case 7: - return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13)))); - case 8: - return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16)))); - case 9: - return ((int)(0x1FF & (id ^ (id>>9)))); - case 10: - return ((int)(0x3FF & (id ^ (id>>10)))); - case 11: - return ((int)(0x7FF & (id ^ (id>>11)))); + switch (clientTable[client].hashsize) { + case 6: + return ((int) (0x03F & (id ^ (id >> 6) ^ (id >> 12)))); + case 7: + return ((int) (0x07F & (id ^ (id >> 7) ^ (id >> 13)))); + case 8: + return ((int) (0x0FF & (id ^ (id >> 8) ^ (id >> 16)))); + case 9: + return ((int) (0x1FF & (id ^ (id >> 9)))); + case 10: + return ((int) (0x3FF & (id ^ (id >> 10)))); + case 11: + return ((int) (0x7FF & (id ^ (id >> 11)))); } return -1; } static XID -AvailableID( - int client, - XID id, - XID maxid, - XID goodid) +AvailableID(int client, XID id, XID maxid, XID goodid) { ResourcePtr res; if ((goodid >= id) && (goodid <= maxid)) - return goodid; - for (; id <= maxid; id++) - { - res = clientTable[client].resources[Hash(client, id)]; - while (res && (res->id != id)) - res = res->next; - if (!res) - return id; + return goodid; + for (; id <= maxid; id++) { + res = clientTable[client].resources[Hash(client, id)]; + while (res && (res->id != id)) + res = res->next; + if (!res) + return id; } return 0; } @@ -382,28 +373,26 @@ GetXIDRange(int client, Bool server, XID *minp, XID *maxp) int i; XID goodid; - id = (Mask)client << CLIENTOFFSET; + id = (Mask) client << CLIENTOFFSET; if (server) - id |= client ? SERVER_BIT : SERVER_MINID; + id |= client ? SERVER_BIT : SERVER_MINID; maxid = id | RESOURCE_ID_MASK; goodid = 0; for (resp = clientTable[client].resources, i = clientTable[client].buckets; - --i >= 0;) - { - for (res = *resp++; res; res = res->next) - { - if ((res->id < id) || (res->id > maxid)) - continue; - if (((res->id - id) >= (maxid - res->id)) ? - (goodid = AvailableID(client, id, res->id - 1, goodid)) : - !(goodid = AvailableID(client, res->id + 1, maxid, goodid))) - maxid = res->id - 1; - else - id = res->id + 1; - } + --i >= 0;) { + for (res = *resp++; res; res = res->next) { + if ((res->id < id) || (res->id > maxid)) + continue; + if (((res->id - id) >= (maxid - res->id)) ? + (goodid = AvailableID(client, id, res->id - 1, goodid)) : + !(goodid = AvailableID(client, res->id + 1, maxid, goodid))) + maxid = res->id - 1; + else + id = res->id + 1; + } } if (id > maxid) - id = maxid = 0; + id = maxid = 0; *minp = id; *maxp = maxid; } @@ -433,15 +422,13 @@ GetXIDList(ClientPtr pClient, unsigned count, XID *pids) pointer val; maxid = id | RESOURCE_ID_MASK; - while ( (found < count) && (id <= maxid) ) - { - rc = dixLookupResourceByClass(&val, id, RC_ANY, serverClient, - DixGetAttrAccess); - if (rc == BadValue) - { - pids[found++] = id; - } - id++; + while ((found < count) && (id <= maxid)) { + rc = dixLookupResourceByClass(&val, id, RC_ANY, serverClient, + DixGetAttrAccess); + if (rc == BadValue) { + pids[found++] = id; + } + id++; } return found; } @@ -461,14 +448,14 @@ FakeClientID(int client) id = clientTable[client].fakeID++; if (id != clientTable[client].endFakeID) - return id; + return id; GetXIDRange(client, TRUE, &id, &maxid); if (!id) { - if (!client) - FatalError("FakeClientID: server internal ids exhausted\n"); - MarkClientException(clients[client]); - id = ((Mask)client << CLIENTOFFSET) | (SERVER_BIT * 3); - maxid = id | RESOURCE_ID_MASK; + if (!client) + FatalError("FakeClientID: server internal ids exhausted\n"); + MarkClientException(clients[client]); + id = ((Mask) client << CLIENTOFFSET) | (SERVER_BIT * 3); + maxid = id | RESOURCE_ID_MASK; } clientTable[client].fakeID = id + 1; clientTable[client].endFakeID = maxid + 1; @@ -481,27 +468,24 @@ AddResource(XID id, RESTYPE type, pointer value) int client; ClientResourceRec *rrec; ResourcePtr res, *head; - + #ifdef XSERVER_DTRACE XSERVER_RESOURCE_ALLOC(id, type, value, TypeNameString(type)); #endif client = CLIENT_ID(id); rrec = &clientTable[client]; - if (!rrec->buckets) - { - ErrorF("[dix] AddResource(%lx, %x, %lx), client=%d \n", - (unsigned long)id, type, (unsigned long)value, client); + if (!rrec->buckets) { + ErrorF("[dix] AddResource(%lx, %x, %lx), client=%d \n", + (unsigned long) id, type, (unsigned long) value, client); FatalError("client not in use\n"); } - if ((rrec->elements >= 4*rrec->buckets) && - (rrec->hashsize < MAXHASHSIZE)) - RebuildTable(client); + if ((rrec->elements >= 4 * rrec->buckets) && (rrec->hashsize < MAXHASHSIZE)) + RebuildTable(client); head = &rrec->resources[Hash(client, id)]; res = malloc(sizeof(ResourceRec)); - if (!res) - { - (*resourceTypes[type & TypeMask].deleteFunc)(value, id); - return FALSE; + if (!res) { + (*resourceTypes[type & TypeMask].deleteFunc) (value, id); + return FALSE; } res->next = *head; res->id = id; @@ -529,32 +513,26 @@ RebuildTable(int client) j = 2 * clientTable[client].buckets; tails = malloc(j * sizeof(ResourcePtr *)); if (!tails) - return; + return; resources = malloc(j * sizeof(ResourcePtr)); - if (!resources) - { - free(tails); - return; + if (!resources) { + free(tails); + return; } - for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++) - { - *rptr = NULL; - *tptr = rptr; + for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++) { + *rptr = NULL; + *tptr = rptr; } clientTable[client].hashsize++; for (j = clientTable[client].buckets, - rptr = clientTable[client].resources; - --j >= 0; - rptr++) - { - for (res = *rptr; res; res = next) - { - next = res->next; - res->next = NULL; - tptr = &tails[Hash(client, res->id)]; - **tptr = res; - *tptr = &res->next; - } + rptr = clientTable[client].resources; --j >= 0; rptr++) { + for (res = *rptr; res; res = next) { + next = res->next; + res->next = NULL; + tptr = &tails[Hash(client, res->id)]; + **tptr = res; + *tptr = &res->next; + } } free(tails); clientTable[client].buckets *= 2; @@ -568,7 +546,7 @@ doFreeResource(ResourcePtr res, Bool skip) CallResourceStateCallback(ResourceStateFreeing, res); if (!skip) - resourceTypes[res->type & TypeMask].deleteFunc(res->value, res->id); + resourceTypes[res->type & TypeMask].deleteFunc(res->value, res->id); free(res); } @@ -576,38 +554,35 @@ doFreeResource(ResourcePtr res, Bool skip) void FreeResource(XID id, RESTYPE skipDeleteFuncType) { - int cid; + int cid; ResourcePtr res; ResourcePtr *prev, *head; int *eltptr; - int elements; + int elements; - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - eltptr = &clientTable[cid].elements; + if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) { + head = &clientTable[cid].resources[Hash(cid, id)]; + eltptr = &clientTable[cid].elements; - prev = head; - while ( (res = *prev) ) - { - if (res->id == id) - { - RESTYPE rtype = res->type; + prev = head; + while ((res = *prev)) { + if (res->id == id) { + RESTYPE rtype = res->type; #ifdef XSERVER_DTRACE - XSERVER_RESOURCE_FREE(res->id, res->type, - res->value, TypeNameString(res->type)); -#endif - *prev = res->next; - elements = --*eltptr; - - doFreeResource(res, rtype == skipDeleteFuncType); - - if (*eltptr != elements) - prev = head; /* prev may no longer be valid */ - } - else - prev = &res->next; + XSERVER_RESOURCE_FREE(res->id, res->type, + res->value, TypeNameString(res->type)); +#endif + *prev = res->next; + elements = --*eltptr; + + doFreeResource(res, rtype == skipDeleteFuncType); + + if (*eltptr != elements) + prev = head; /* prev may no longer be valid */ + } + else + prev = &res->next; } } } @@ -615,31 +590,29 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType) void FreeResourceByType(XID id, RESTYPE type, Bool skipFree) { - int cid; + int cid; ResourcePtr res; ResourcePtr *prev, *head; - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - head = &clientTable[cid].resources[Hash(cid, id)]; - - prev = head; - while ( (res = *prev) ) - { - if (res->id == id && res->type == type) - { + + if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) { + head = &clientTable[cid].resources[Hash(cid, id)]; + + prev = head; + while ((res = *prev)) { + if (res->id == id && res->type == type) { #ifdef XSERVER_DTRACE - XSERVER_RESOURCE_FREE(res->id, res->type, - res->value, TypeNameString(res->type)); -#endif - *prev = res->next; - clientTable[cid].elements--; - - doFreeResource(res, skipFree); - - break; - } - else - prev = &res->next; + XSERVER_RESOURCE_FREE(res->id, res->type, + res->value, TypeNameString(res->type)); +#endif + *prev = res->next; + clientTable[cid].elements--; + + doFreeResource(res, skipFree); + + break; + } + else + prev = &res->next; } } } @@ -651,21 +624,19 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree) */ Bool -ChangeResourceValue (XID id, RESTYPE rtype, pointer value) +ChangeResourceValue(XID id, RESTYPE rtype, pointer value) { - int cid; + int cid; ResourcePtr res; - if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) - { - res = clientTable[cid].resources[Hash(cid, id)]; + if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) { + res = clientTable[cid].resources[Hash(cid, id)]; - for (; res; res = res->next) - if ((res->id == id) && (res->type == rtype)) - { - res->value = value; - return TRUE; - } + for (; res; res = res->next) + if ((res->id == id) && (res->type == rtype)) { + res->value = value; + return TRUE; + } } return FALSE; } @@ -677,43 +648,35 @@ ChangeResourceValue (XID id, RESTYPE rtype, pointer value) */ void -FindClientResourcesByType( - ClientPtr client, - RESTYPE type, - FindResType func, - pointer cdata -){ +FindClientResourcesByType(ClientPtr client, + RESTYPE type, FindResType func, pointer cdata) +{ ResourcePtr *resources; ResourcePtr this, next; int i, elements; int *eltptr; if (!client) - client = serverClient; + client = serverClient; resources = clientTable[client->index].resources; eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { - next = this->next; - if (!type || this->type == type) { - elements = *eltptr; - (*func)(this->value, this->id, cdata); - if (*eltptr != elements) - next = resources[i]; /* start over */ - } - } + for (i = 0; i < clientTable[client->index].buckets; i++) { + for (this = resources[i]; this; this = next) { + next = this->next; + if (!type || this->type == type) { + elements = *eltptr; + (*func) (this->value, this->id, cdata); + if (*eltptr != elements) + next = resources[i]; /* start over */ + } + } } } void -FindAllClientResources( - ClientPtr client, - FindAllRes func, - pointer cdata -){ +FindAllClientResources(ClientPtr client, FindAllRes func, pointer cdata) +{ ResourcePtr *resources; ResourcePtr this, next; int i, elements; @@ -724,51 +687,45 @@ FindAllClientResources( resources = clientTable[client->index].resources; eltptr = &clientTable[client->index].elements; - for (i = 0; i < clientTable[client->index].buckets; i++) - { - for (this = resources[i]; this; this = next) - { + for (i = 0; i < clientTable[client->index].buckets; i++) { + for (this = resources[i]; this; this = next) { next = this->next; elements = *eltptr; - (*func)(this->value, this->id, this->type, cdata); + (*func) (this->value, this->id, this->type, cdata); if (*eltptr != elements) - next = resources[i]; /* start over */ + next = resources[i]; /* start over */ } } } - pointer -LookupClientResourceComplex( - ClientPtr client, - RESTYPE type, - FindComplexResType func, - pointer cdata -){ +LookupClientResourceComplex(ClientPtr client, + RESTYPE type, + FindComplexResType func, pointer cdata) +{ ResourcePtr *resources; ResourcePtr this, next; pointer value; int i; if (!client) - client = serverClient; + client = serverClient; resources = clientTable[client->index].resources; for (i = 0; i < clientTable[client->index].buckets; i++) { for (this = resources[i]; this; this = next) { - next = this->next; - if (!type || this->type == type) { - /* workaround func freeing the type as DRI1 does */ - value = this->value; - if((*func)(value, this->id, cdata)) - return value; - } - } + next = this->next; + if (!type || this->type == type) { + /* workaround func freeing the type as DRI1 does */ + value = this->value; + if ((*func) (value, this->id, cdata)) + return value; + } + } } return NULL; } - void FreeClientNeverRetainResources(ClientPtr client) { @@ -779,34 +736,32 @@ FreeClientNeverRetainResources(ClientPtr client) int *eltptr; if (!client) - return; + return; resources = clientTable[client->index].resources; eltptr = &clientTable[client->index].elements; - for (j=0; j < clientTable[client->index].buckets; j++) - { - prev = &resources[j]; - while ( (this = *prev) ) - { - RESTYPE rtype = this->type; - if (rtype & RC_NEVERRETAIN) - { + for (j = 0; j < clientTable[client->index].buckets; j++) { + prev = &resources[j]; + while ((this = *prev)) { + RESTYPE rtype = this->type; + + if (rtype & RC_NEVERRETAIN) { #ifdef XSERVER_DTRACE - XSERVER_RESOURCE_FREE(this->id, this->type, - this->value, TypeNameString(this->type)); -#endif - *prev = this->next; - clientTable[client->index].elements--; - elements = *eltptr; - - doFreeResource(this, FALSE); - - if (*eltptr != elements) - prev = &resources[j]; /* prev may no longer be valid */ - } - else - prev = &this->next; - } + XSERVER_RESOURCE_FREE(this->id, this->type, + this->value, TypeNameString(this->type)); +#endif + *prev = this->next; + clientTable[client->index].elements--; + elements = *eltptr; + + doFreeResource(this, FALSE); + + if (*eltptr != elements) + prev = &resources[j]; /* prev may no longer be valid */ + } + else + prev = &this->next; + } } } @@ -818,40 +773,38 @@ FreeClientResources(ClientPtr client) int j; /* This routine shouldn't be called with a null client, but just in - case ... */ + case ... */ if (!client) - return; + return; HandleSaveSet(client); resources = clientTable[client->index].resources; - for (j=0; j < clientTable[client->index].buckets; j++) - { + for (j = 0; j < clientTable[client->index].buckets; j++) { /* It may seem silly to update the head of this resource list as - we delete the members, since the entire list will be deleted any way, - but there are some resource deletion functions "FreeClientPixels" for - one which do a LookupID on another resource id (a Colormap id in this - case), so the resource list must be kept valid up to the point that - it is deleted, so every time we delete a resource, we must update the - head, just like in FreeResource. I hope that this doesn't slow down - mass deletion appreciably. PRH */ + we delete the members, since the entire list will be deleted any way, + but there are some resource deletion functions "FreeClientPixels" for + one which do a LookupID on another resource id (a Colormap id in this + case), so the resource list must be kept valid up to the point that + it is deleted, so every time we delete a resource, we must update the + head, just like in FreeResource. I hope that this doesn't slow down + mass deletion appreciably. PRH */ - ResourcePtr *head; + ResourcePtr *head; - head = &resources[j]; + head = &resources[j]; - for (this = *head; this; this = *head) - { + for (this = *head; this; this = *head) { #ifdef XSERVER_DTRACE - XSERVER_RESOURCE_FREE(this->id, this->type, - this->value, TypeNameString(this->type)); -#endif - *head = this->next; - clientTable[client->index].elements--; - - doFreeResource(this, FALSE); - } + XSERVER_RESOURCE_FREE(this->id, this->type, + this->value, TypeNameString(this->type)); +#endif + *head = this->next; + clientTable[client->index].elements--; + + doFreeResource(this, FALSE); + } } free(clientTable[client->index].resources); clientTable[client->index].resources = NULL; @@ -861,12 +814,11 @@ FreeClientResources(ClientPtr client) void FreeAllResources(void) { - int i; + int i; - for (i = currentMaxClients; --i >= 0; ) - { - if (clientTable[i].buckets) - FreeClientResources(clients[i]); + for (i = currentMaxClients; --i >= 0;) { + if (clientTable[i].buckets) + FreeClientResources(clients[i]); } } @@ -877,7 +829,7 @@ LegalNewID(XID id, ClientPtr client) int rc; #ifdef PANORAMIX - XID minid, maxid; + XID minid, maxid; if (!noPanoramiXExtension) { minid = client->clientAsMask | (client->index ? @@ -886,9 +838,8 @@ LegalNewID(XID id, ClientPtr client) if ((id >= minid) && (id <= maxid)) return TRUE; } -#endif /* PANORAMIX */ - if (client->clientAsMask == (id & ~RESOURCE_ID_MASK)) - { +#endif /* PANORAMIX */ + if (client->clientAsMask == (id & ~RESOURCE_ID_MASK)) { rc = dixLookupResourceByClass(&val, id, RC_ANY, serverClient, DixGetAttrAccess); return rc == BadValue; @@ -898,33 +849,33 @@ LegalNewID(XID id, ClientPtr client) int dixLookupResourceByType(pointer *result, XID id, RESTYPE rtype, - ClientPtr client, Mask mode) + ClientPtr client, Mask mode) { int cid = CLIENT_ID(id); ResourcePtr res = NULL; *result = NULL; if ((rtype & TypeMask) > lastResourceType) - return BadImplementation; + return BadImplementation; if ((cid < MAXCLIENTS) && clientTable[cid].buckets) { - res = clientTable[cid].resources[Hash(cid, id)]; + res = clientTable[cid].resources[Hash(cid, id)]; - for (; res; res = res->next) - if (res->id == id && res->type == rtype) - break; + for (; res; res = res->next) + if (res->id == id && res->type == rtype) + break; } if (!res) - return resourceTypes[rtype & TypeMask].errorValue; + return resourceTypes[rtype & TypeMask].errorValue; if (client) { - client->errorValue = id; - cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, - res->value, RT_NONE, NULL, mode); - if (cid == BadValue) - return resourceTypes[rtype & TypeMask].errorValue; - if (cid != Success) - return cid; + client->errorValue = id; + cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, + res->value, RT_NONE, NULL, mode); + if (cid == BadValue) + return resourceTypes[rtype & TypeMask].errorValue; + if (cid != Success) + return cid; } *result = res->value; @@ -933,7 +884,7 @@ dixLookupResourceByType(pointer *result, XID id, RESTYPE rtype, int dixLookupResourceByClass(pointer *result, XID id, RESTYPE rclass, - ClientPtr client, Mask mode) + ClientPtr client, Mask mode) { int cid = CLIENT_ID(id); ResourcePtr res = NULL; @@ -941,21 +892,21 @@ dixLookupResourceByClass(pointer *result, XID id, RESTYPE rclass, *result = NULL; if ((cid < MAXCLIENTS) && clientTable[cid].buckets) { - res = clientTable[cid].resources[Hash(cid, id)]; + res = clientTable[cid].resources[Hash(cid, id)]; - for (; res; res = res->next) - if (res->id == id && (res->type & rclass)) - break; + for (; res; res = res->next) + if (res->id == id && (res->type & rclass)) + break; } if (!res) - return BadValue; + return BadValue; if (client) { - client->errorValue = id; - cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, - res->value, RT_NONE, NULL, mode); - if (cid != Success) - return cid; + client->errorValue = id; + cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, + res->value, RT_NONE, NULL, mode); + if (cid != Success) + return cid; } *result = res->value; diff --git a/xorg-server/dix/selection.c b/xorg-server/dix/selection.c index 732ba34e5..dfdcfdc64 100644 --- a/xorg-server/dix/selection.c +++ b/xorg-server/dix/selection.c @@ -1,311 +1,309 @@ -/************************************************************
-
-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.
-
-********************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "windowstr.h"
-#include "dixstruct.h"
-#include "dispatch.h"
-#include "selection.h"
-#include "xace.h"
-
-/*****************************************************************
- * Selection Stuff
- *
- * dixLookupSelection
- *
- * Selections are global to the server. The list of selections should
- * not be traversed directly. Instead, use the functions listed above.
- *
- *****************************************************************/
-
-Selection *CurrentSelections;
-CallbackListPtr SelectionCallback;
-
-int
-dixLookupSelection(Selection **result, Atom selectionName,
- ClientPtr client, Mask access_mode)
-{
- Selection *pSel;
- int rc = BadMatch;
- client->errorValue = selectionName;
-
- for (pSel = CurrentSelections; pSel; pSel = pSel->next)
- if (pSel->selection == selectionName)
- break;
-
- if (pSel)
- rc = XaceHookSelectionAccess(client, &pSel, access_mode);
- *result = pSel;
- return rc;
-}
-
-void
-InitSelections(void)
-{
- Selection *pSel, *pNextSel;
-
- pSel = CurrentSelections;
- while (pSel) {
- pNextSel = pSel->next;
- dixFreeObjectWithPrivates(pSel, PRIVATE_SELECTION);
- pSel = pNextSel;
- }
-
- CurrentSelections = NULL;
-}
-
-static _X_INLINE void
-CallSelectionCallback(Selection *pSel, ClientPtr client,
- SelectionCallbackKind kind)
-{
- SelectionInfoRec info = { pSel, client, kind };
- CallCallbacks(&SelectionCallback, &info);
-}
-
-void
-DeleteWindowFromAnySelections(WindowPtr pWin)
-{
- Selection *pSel;
-
- for (pSel = CurrentSelections; pSel; pSel = pSel->next)
- if (pSel->pWin == pWin) {
- CallSelectionCallback(pSel, NULL, SelectionWindowDestroy);
-
- pSel->pWin = (WindowPtr)NULL;
- pSel->window = None;
- pSel->client = NullClient;
- }
-}
-
-void
-DeleteClientFromAnySelections(ClientPtr client)
-{
- Selection *pSel;
-
- for (pSel = CurrentSelections; pSel; pSel = pSel->next)
- if (pSel->client == client) {
- CallSelectionCallback(pSel, NULL, SelectionClientClose);
-
- pSel->pWin = (WindowPtr)NULL;
- pSel->window = None;
- pSel->client = NullClient;
- }
-}
-
-int
-ProcSetSelectionOwner(ClientPtr client)
-{
- WindowPtr pWin = NULL;
- TimeStamp time;
- Selection *pSel;
- int rc;
-
- 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) {
- rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
- if (rc != Success)
- return rc;
- }
- if (!ValidAtom(stuff->selection)) {
- client->errorValue = stuff->selection;
- return BadAtom;
- }
-
- /*
- * First, see if the selection is already set...
- */
- rc = dixLookupSelection(&pSel, stuff->selection, client, DixSetAttrAccess);
-
- if (rc == Success) {
- 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, pSel->lastTimeChanged) == EARLIER)
- return Success;
- if (pSel->client && (!pWin || (pSel->client != client)))
- {
- event.u.u.type = SelectionClear;
- event.u.selectionClear.time = time.milliseconds;
- event.u.selectionClear.window = pSel->window;
- event.u.selectionClear.atom = pSel->selection;
- WriteEventsToClient(pSel->client, 1, &event);
- }
- }
- else if (rc == BadMatch)
- {
- /*
- * It doesn't exist, so add it...
- */
- pSel = dixAllocateObjectWithPrivates(Selection, PRIVATE_SELECTION);
- if (!pSel)
- return BadAlloc;
-
- pSel->selection = stuff->selection;
-
- /* security creation/labeling check */
- rc = XaceHookSelectionAccess(client, &pSel,
- DixCreateAccess|DixSetAttrAccess);
- if (rc != Success) {
- free(pSel);
- return rc;
- }
-
- pSel->next = CurrentSelections;
- CurrentSelections = pSel;
- }
- else
- return rc;
-
- pSel->lastTimeChanged = time;
- pSel->window = stuff->window;
- pSel->pWin = pWin;
- pSel->client = (pWin ? client : NullClient);
-
- CallSelectionCallback(pSel, client, SelectionSetOwner);
- return Success;
-}
-
-int
-ProcGetSelectionOwner(ClientPtr client)
-{
- int rc;
- Selection *pSel;
- xGetSelectionOwnerReply reply;
-
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
-
- if (!ValidAtom(stuff->id)) {
- client->errorValue = stuff->id;
- return BadAtom;
- }
-
- memset(&reply, 0, sizeof(xGetSelectionOwnerReply));
- reply.type = X_Reply;
- reply.length = 0;
- reply.sequenceNumber = client->sequence;
-
- rc = dixLookupSelection(&pSel, stuff->id, client, DixGetAttrAccess);
- if (rc == Success)
- reply.owner = pSel->window;
- else if (rc == BadMatch)
- reply.owner = None;
- else
- return rc;
-
- WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
- return Success;
-}
-
-int
-ProcConvertSelection(ClientPtr client)
-{
- Bool paramsOkay;
- xEvent event;
- WindowPtr pWin;
- Selection *pSel;
- int rc;
-
- REQUEST(xConvertSelectionReq);
- REQUEST_SIZE_MATCH(xConvertSelectionReq);
-
- rc = dixLookupWindow(&pWin, stuff->requestor, client, DixSetAttrAccess);
- if (rc != Success)
- return rc;
-
- paramsOkay = ValidAtom(stuff->selection) && ValidAtom(stuff->target);
- paramsOkay &= (stuff->property == None) || ValidAtom(stuff->property);
- if (!paramsOkay) {
- client->errorValue = stuff->property;
- return BadAtom;
- }
-
- rc = dixLookupSelection(&pSel, stuff->selection, client, DixReadAccess);
-
- memset(&event, 0, sizeof(xEvent));
- if (rc != Success && rc != BadMatch)
- return rc;
- else if (rc == Success && pSel->window != None) {
- event.u.u.type = SelectionRequest;
- event.u.selectionRequest.owner = pSel->window;
- event.u.selectionRequest.time = stuff->time;
- 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 (pSel->client && pSel->client != serverClient && !pSel->client->clientGone)
- {
- WriteEventsToClient(pSel->client, 1, &event);
- return Success;
- }
- }
-
- 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;
- WriteEventsToClient(client, 1, &event);
- return Success;
-}
+/************************************************************ + +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. + +********************************************************/ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "windowstr.h" +#include "dixstruct.h" +#include "dispatch.h" +#include "selection.h" +#include "xace.h" + +/***************************************************************** + * Selection Stuff + * + * dixLookupSelection + * + * Selections are global to the server. The list of selections should + * not be traversed directly. Instead, use the functions listed above. + * + *****************************************************************/ + +Selection *CurrentSelections; +CallbackListPtr SelectionCallback; + +int +dixLookupSelection(Selection ** result, Atom selectionName, + ClientPtr client, Mask access_mode) +{ + Selection *pSel; + int rc = BadMatch; + + client->errorValue = selectionName; + + for (pSel = CurrentSelections; pSel; pSel = pSel->next) + if (pSel->selection == selectionName) + break; + + if (pSel) + rc = XaceHookSelectionAccess(client, &pSel, access_mode); + *result = pSel; + return rc; +} + +void +InitSelections(void) +{ + Selection *pSel, *pNextSel; + + pSel = CurrentSelections; + while (pSel) { + pNextSel = pSel->next; + dixFreeObjectWithPrivates(pSel, PRIVATE_SELECTION); + pSel = pNextSel; + } + + CurrentSelections = NULL; +} + +static _X_INLINE void +CallSelectionCallback(Selection * pSel, ClientPtr client, + SelectionCallbackKind kind) +{ + SelectionInfoRec info = { pSel, client, kind }; + CallCallbacks(&SelectionCallback, &info); +} + +void +DeleteWindowFromAnySelections(WindowPtr pWin) +{ + Selection *pSel; + + for (pSel = CurrentSelections; pSel; pSel = pSel->next) + if (pSel->pWin == pWin) { + CallSelectionCallback(pSel, NULL, SelectionWindowDestroy); + + pSel->pWin = (WindowPtr) NULL; + pSel->window = None; + pSel->client = NullClient; + } +} + +void +DeleteClientFromAnySelections(ClientPtr client) +{ + Selection *pSel; + + for (pSel = CurrentSelections; pSel; pSel = pSel->next) + if (pSel->client == client) { + CallSelectionCallback(pSel, NULL, SelectionClientClose); + + pSel->pWin = (WindowPtr) NULL; + pSel->window = None; + pSel->client = NullClient; + } +} + +int +ProcSetSelectionOwner(ClientPtr client) +{ + WindowPtr pWin = NULL; + TimeStamp time; + Selection *pSel; + int rc; + + 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) { + rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess); + if (rc != Success) + return rc; + } + if (!ValidAtom(stuff->selection)) { + client->errorValue = stuff->selection; + return BadAtom; + } + + /* + * First, see if the selection is already set... + */ + rc = dixLookupSelection(&pSel, stuff->selection, client, DixSetAttrAccess); + + if (rc == Success) { + 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, pSel->lastTimeChanged) == EARLIER) + return Success; + if (pSel->client && (!pWin || (pSel->client != client))) { + event.u.u.type = SelectionClear; + event.u.selectionClear.time = time.milliseconds; + event.u.selectionClear.window = pSel->window; + event.u.selectionClear.atom = pSel->selection; + WriteEventsToClient(pSel->client, 1, &event); + } + } + else if (rc == BadMatch) { + /* + * It doesn't exist, so add it... + */ + pSel = dixAllocateObjectWithPrivates(Selection, PRIVATE_SELECTION); + if (!pSel) + return BadAlloc; + + pSel->selection = stuff->selection; + + /* security creation/labeling check */ + rc = XaceHookSelectionAccess(client, &pSel, + DixCreateAccess | DixSetAttrAccess); + if (rc != Success) { + free(pSel); + return rc; + } + + pSel->next = CurrentSelections; + CurrentSelections = pSel; + } + else + return rc; + + pSel->lastTimeChanged = time; + pSel->window = stuff->window; + pSel->pWin = pWin; + pSel->client = (pWin ? client : NullClient); + + CallSelectionCallback(pSel, client, SelectionSetOwner); + return Success; +} + +int +ProcGetSelectionOwner(ClientPtr client) +{ + int rc; + Selection *pSel; + xGetSelectionOwnerReply reply; + + REQUEST(xResourceReq); + REQUEST_SIZE_MATCH(xResourceReq); + + if (!ValidAtom(stuff->id)) { + client->errorValue = stuff->id; + return BadAtom; + } + + memset(&reply, 0, sizeof(xGetSelectionOwnerReply)); + reply.type = X_Reply; + reply.length = 0; + reply.sequenceNumber = client->sequence; + + rc = dixLookupSelection(&pSel, stuff->id, client, DixGetAttrAccess); + if (rc == Success) + reply.owner = pSel->window; + else if (rc == BadMatch) + reply.owner = None; + else + return rc; + + WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply); + return Success; +} + +int +ProcConvertSelection(ClientPtr client) +{ + Bool paramsOkay; + xEvent event; + WindowPtr pWin; + Selection *pSel; + int rc; + + REQUEST(xConvertSelectionReq); + REQUEST_SIZE_MATCH(xConvertSelectionReq); + + rc = dixLookupWindow(&pWin, stuff->requestor, client, DixSetAttrAccess); + if (rc != Success) + return rc; + + paramsOkay = ValidAtom(stuff->selection) && ValidAtom(stuff->target); + paramsOkay &= (stuff->property == None) || ValidAtom(stuff->property); + if (!paramsOkay) { + client->errorValue = stuff->property; + return BadAtom; + } + + rc = dixLookupSelection(&pSel, stuff->selection, client, DixReadAccess); + + memset(&event, 0, sizeof(xEvent)); + if (rc != Success && rc != BadMatch) + return rc; + else if (rc == Success && pSel->window != None) { + event.u.u.type = SelectionRequest; + event.u.selectionRequest.owner = pSel->window; + event.u.selectionRequest.time = stuff->time; + 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 (pSel->client && pSel->client != serverClient && + !pSel->client->clientGone) { + WriteEventsToClient(pSel->client, 1, &event); + return Success; + } + } + + 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; + WriteEventsToClient(client, 1, &event); + return Success; +} diff --git a/xorg-server/dix/swaprep.c b/xorg-server/dix/swaprep.c index 28c354cd9..9440c4ee3 100644 --- a/xorg-server/dix/swaprep.c +++ b/xorg-server/dix/swaprep.c @@ -22,7 +22,6 @@ 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 @@ -45,7 +44,6 @@ SOFTWARE. ********************************************************/ - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #endif @@ -59,11 +57,11 @@ SOFTWARE. #include "swaprep.h" #include "globals.h" -static void SwapFontInfo(xQueryFontReply *pr); +static void SwapFontInfo(xQueryFontReply * pr); -static void SwapCharInfo(xCharInfo *pInfo); +static void SwapCharInfo(xCharInfo * pInfo); -static void SwapFont(xQueryFontReply *pr, Bool hasGlyphs); +static void SwapFont(xQueryFontReply * pr, Bool hasGlyphs); /** * Thanks to Jack Palevich for testing and subsequently rewriting all this @@ -76,13 +74,13 @@ Swap32Write(ClientPtr pClient, int size, CARD32 *pbuf) int i; size >>= 2; - for(i = 0; i < size; i++) - /* brackets are mandatory here, because "swapl" macro expands - to several statements */ - { - swapl(&pbuf[i]); + for (i = 0; i < size; i++) + /* brackets are mandatory here, because "swapl" macro expands + to several statements */ + { + swapl(&pbuf[i]); } - (void)WriteToClient(pClient, size << 2, (char *) pbuf); + (void) WriteToClient(pClient, size << 2, (char *) pbuf); } /** @@ -96,18 +94,16 @@ CopySwap32Write(ClientPtr pClient, int size, CARD32 *pbuf) CARD32 *pbufT; CARD32 *from, *to, *fromLast, *toLast; CARD32 tmpbuf[1]; - + /* Allocate as big a buffer as we can... */ - while (!(pbufT = malloc(bufsize))) - { + while (!(pbufT = malloc(bufsize))) { bufsize >>= 1; - if (bufsize == 4) - { - pbufT = tmpbuf; - break; - } + if (bufsize == 4) { + pbufT = tmpbuf; + break; + } } - + /* convert lengths from # of bytes to # of longs */ size >>= 2; bufsize >>= 2; @@ -115,22 +111,23 @@ CopySwap32Write(ClientPtr pClient, int size, CARD32 *pbuf) from = pbuf; fromLast = from + size; while (from < fromLast) { - int nbytes; + int nbytes; + to = pbufT; - toLast = to + min (bufsize, fromLast - from); + toLast = to + min(bufsize, fromLast - from); nbytes = (toLast - to) << 2; while (to < toLast) { /* can't write "cpswapl(*from++, *to++)" because cpswapl is a macro - that evaulates its args more than once */ - cpswapl(*from, *to); + that evaulates its args more than once */ + cpswapl(*from, *to); from++; to++; - } - (void)WriteToClient (pClient, nbytes, (char *) pbufT); - } + } + (void) WriteToClient(pClient, nbytes, (char *) pbufT); + } if (pbufT != tmpbuf) - free(pbufT); + free(pbufT); } /** @@ -144,18 +141,16 @@ CopySwap16Write(ClientPtr pClient, int size, short *pbuf) short *pbufT; short *from, *to, *fromLast, *toLast; short tmpbuf[2]; - + /* Allocate as big a buffer as we can... */ - while (!(pbufT = malloc(bufsize))) - { + while (!(pbufT = malloc(bufsize))) { bufsize >>= 1; - if (bufsize == 4) - { - pbufT = tmpbuf; - break; - } + if (bufsize == 4) { + pbufT = tmpbuf; + break; + } } - + /* convert lengths from # of bytes to # of shorts */ size >>= 1; bufsize >>= 1; @@ -163,37 +158,37 @@ CopySwap16Write(ClientPtr pClient, int size, short *pbuf) from = pbuf; fromLast = from + size; while (from < fromLast) { - int nbytes; + int nbytes; + to = pbufT; - toLast = to + min (bufsize, fromLast - from); + toLast = to + min(bufsize, fromLast - from); nbytes = (toLast - to) << 1; while (to < toLast) { /* can't write "cpswaps(*from++, *to++)" because cpswaps is a macro - that evaulates its args more than once */ - cpswaps(*from, *to); + that evaulates its args more than once */ + cpswaps(*from, *to); from++; to++; - } - (void)WriteToClient (pClient, nbytes, (char *) pbufT); - } + } + (void) WriteToClient(pClient, nbytes, (char *) pbufT); + } if (pbufT != tmpbuf) - free(pbufT); + free(pbufT); } - /* Extra-small reply */ void -SGenericReply(ClientPtr pClient, int size, xGenericReply *pRep) +SGenericReply(ClientPtr pClient, int size, xGenericReply * pRep) { swaps(&pRep->sequenceNumber); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } /* Extra-large reply */ void SGetWindowAttributesReply(ClientPtr pClient, int size, - xGetWindowAttributesReply *pRep) + xGetWindowAttributesReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); @@ -205,11 +200,11 @@ SGetWindowAttributesReply(ClientPtr pClient, int size, swapl(&pRep->allEventMasks); swapl(&pRep->yourEventMask); swaps(&pRep->doNotPropagateMask); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SGetGeometryReply(ClientPtr pClient, int size, xGetGeometryReply *pRep) +SGetGeometryReply(ClientPtr pClient, int size, xGetGeometryReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->root); @@ -218,70 +213,68 @@ SGetGeometryReply(ClientPtr pClient, int size, xGetGeometryReply *pRep) swaps(&pRep->width); swaps(&pRep->height); swaps(&pRep->borderWidth); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SQueryTreeReply(ClientPtr pClient, int size, xQueryTreeReply *pRep) +SQueryTreeReply(ClientPtr pClient, int size, xQueryTreeReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swapl(&pRep->root); swapl(&pRep->parent); swaps(&pRep->nChildren); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SInternAtomReply(ClientPtr pClient, int size, xInternAtomReply *pRep) +SInternAtomReply(ClientPtr pClient, int size, xInternAtomReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->atom); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SGetAtomNameReply(ClientPtr pClient, int size, xGetAtomNameReply *pRep) +SGetAtomNameReply(ClientPtr pClient, int size, xGetAtomNameReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swaps(&pRep->nameLength); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } - void -SGetPropertyReply(ClientPtr pClient, int size, xGetPropertyReply *pRep) +SGetPropertyReply(ClientPtr pClient, int size, xGetPropertyReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swapl(&pRep->propertyType); swapl(&pRep->bytesAfter); swapl(&pRep->nItems); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SListPropertiesReply(ClientPtr pClient, int size, xListPropertiesReply *pRep) +SListPropertiesReply(ClientPtr pClient, int size, xListPropertiesReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swaps(&pRep->nProperties); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void SGetSelectionOwnerReply(ClientPtr pClient, int size, - xGetSelectionOwnerReply *pRep) + xGetSelectionOwnerReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->owner); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } - void -SQueryPointerReply(ClientPtr pClient, int size, xQueryPointerReply *pRep) +SQueryPointerReply(ClientPtr pClient, int size, xQueryPointerReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->root); @@ -291,11 +284,11 @@ SQueryPointerReply(ClientPtr pClient, int size, xQueryPointerReply *pRep) swaps(&pRep->winX); swaps(&pRep->winY); swaps(&pRep->mask); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } static void -SwapTimecoord(xTimecoord* pCoord) +SwapTimecoord(xTimecoord * pCoord) { swapl(&pCoord->time); swaps(&pCoord->x); @@ -303,59 +296,59 @@ SwapTimecoord(xTimecoord* pCoord) } void -SwapTimeCoordWrite(ClientPtr pClient, int size, xTimecoord *pRep) +SwapTimeCoordWrite(ClientPtr pClient, int size, xTimecoord * pRep) { - int i, n; - xTimecoord *pRepT; + int i, n; + xTimecoord *pRepT; n = size / sizeof(xTimecoord); pRepT = pRep; - for(i = 0; i < n; i++) - { - SwapTimecoord(pRepT); - pRepT++; + for (i = 0; i < n; i++) { + SwapTimecoord(pRepT); + pRepT++; } - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } + void -SGetMotionEventsReply(ClientPtr pClient, int size, xGetMotionEventsReply *pRep) +SGetMotionEventsReply(ClientPtr pClient, int size, xGetMotionEventsReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swapl(&pRep->nEvents); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -STranslateCoordsReply(ClientPtr pClient, int size, xTranslateCoordsReply *pRep) +STranslateCoordsReply(ClientPtr pClient, int size, xTranslateCoordsReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->child); swaps(&pRep->dstX); swaps(&pRep->dstY); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SGetInputFocusReply(ClientPtr pClient, int size, xGetInputFocusReply *pRep) +SGetInputFocusReply(ClientPtr pClient, int size, xGetInputFocusReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->focus); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } /* extra long reply */ void -SQueryKeymapReply(ClientPtr pClient, int size, xQueryKeymapReply *pRep) +SQueryKeymapReply(ClientPtr pClient, int size, xQueryKeymapReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } static void -SwapCharInfo(xCharInfo *pInfo) +SwapCharInfo(xCharInfo * pInfo) { swaps(&pInfo->leftSideBearing); swaps(&pInfo->rightSideBearing); @@ -366,7 +359,7 @@ SwapCharInfo(xCharInfo *pInfo) } static void -SwapFontInfo(xQueryFontReply *pr) +SwapFontInfo(xQueryFontReply * pr) { swaps(&pr->minCharOrByte2); swaps(&pr->maxCharOrByte2); @@ -374,18 +367,18 @@ SwapFontInfo(xQueryFontReply *pr) swaps(&pr->nFontProps); swaps(&pr->fontAscent); swaps(&pr->fontDescent); - SwapCharInfo( &pr->minBounds); - SwapCharInfo( &pr->maxBounds); + SwapCharInfo(&pr->minBounds); + SwapCharInfo(&pr->maxBounds); swapl(&pr->nCharInfos); } static void -SwapFont(xQueryFontReply *pr, Bool hasGlyphs) +SwapFont(xQueryFontReply * pr, Bool hasGlyphs) { - unsigned i; - xCharInfo * pxci; - unsigned nchars, nprops; - char *pby; + unsigned i; + xCharInfo *pxci; + unsigned nchars, nprops; + char *pby; swaps(&pr->sequenceNumber); swapl(&pr->length); @@ -395,30 +388,29 @@ SwapFont(xQueryFontReply *pr, Bool hasGlyphs) pby = (char *) &pr[1]; /* Font properties are an atom and either an int32 or a CARD32, so * they are always 2 4 byte values */ - for(i = 0; i < nprops; i++) - { - swapl((int *)pby); - pby += 4; - swapl((int *)pby); - pby += 4; + for (i = 0; i < nprops; i++) { + swapl((int *) pby); + pby += 4; + swapl((int *) pby); + pby += 4; } - if (hasGlyphs) - { - pxci = (xCharInfo *)pby; - for(i = 0; i< nchars; i++, pxci++) - SwapCharInfo(pxci); + if (hasGlyphs) { + pxci = (xCharInfo *) pby; + for (i = 0; i < nchars; i++, pxci++) + SwapCharInfo(pxci); } } void -SQueryFontReply(ClientPtr pClient, int size, xQueryFontReply *pRep) +SQueryFontReply(ClientPtr pClient, int size, xQueryFontReply * pRep) { SwapFont(pRep, TRUE); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SQueryTextExtentsReply(ClientPtr pClient, int size, xQueryTextExtentsReply *pRep) +SQueryTextExtentsReply(ClientPtr pClient, int size, + xQueryTextExtentsReply * pRep) { swaps(&pRep->sequenceNumber); swaps(&pRep->fontAscent); @@ -428,68 +420,68 @@ SQueryTextExtentsReply(ClientPtr pClient, int size, xQueryTextExtentsReply *pRep swapl(&pRep->overallWidth); swapl(&pRep->overallLeft); swapl(&pRep->overallRight); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SListFontsReply(ClientPtr pClient, int size, xListFontsReply *pRep) +SListFontsReply(ClientPtr pClient, int size, xListFontsReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swaps(&pRep->nFonts); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void SListFontsWithInfoReply(ClientPtr pClient, int size, - xListFontsWithInfoReply *pRep) + xListFontsWithInfoReply * pRep) { - SwapFont((xQueryFontReply *)pRep, FALSE); - (void)WriteToClient(pClient, size, (char *) pRep); + SwapFont((xQueryFontReply *) pRep, FALSE); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SGetFontPathReply(ClientPtr pClient, int size, xGetFontPathReply *pRep) +SGetFontPathReply(ClientPtr pClient, int size, xGetFontPathReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swaps(&pRep->nPaths); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SGetImageReply(ClientPtr pClient, int size, xGetImageReply *pRep) +SGetImageReply(ClientPtr pClient, int size, xGetImageReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swapl(&pRep->visual); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); /* Fortunately, image doesn't need swapping */ } void SListInstalledColormapsReply(ClientPtr pClient, int size, - xListInstalledColormapsReply *pRep) + xListInstalledColormapsReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swaps(&pRep->nColormaps); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SAllocColorReply(ClientPtr pClient, int size, xAllocColorReply *pRep) +SAllocColorReply(ClientPtr pClient, int size, xAllocColorReply * pRep) { swaps(&pRep->sequenceNumber); swaps(&pRep->red); swaps(&pRep->green); swaps(&pRep->blue); swapl(&pRep->pixel); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SAllocNamedColorReply(ClientPtr pClient, int size, xAllocNamedColorReply *pRep) +SAllocNamedColorReply(ClientPtr pClient, int size, xAllocNamedColorReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->pixel); @@ -499,22 +491,22 @@ SAllocNamedColorReply(ClientPtr pClient, int size, xAllocNamedColorReply *pRep) swaps(&pRep->screenRed); swaps(&pRep->screenGreen); swaps(&pRep->screenBlue); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SAllocColorCellsReply(ClientPtr pClient, int size, xAllocColorCellsReply *pRep) +SAllocColorCellsReply(ClientPtr pClient, int size, xAllocColorCellsReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swaps(&pRep->nPixels); swaps(&pRep->nMasks); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } - void -SAllocColorPlanesReply(ClientPtr pClient, int size, xAllocColorPlanesReply *pRep) +SAllocColorPlanesReply(ClientPtr pClient, int size, + xAllocColorPlanesReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); @@ -522,11 +514,11 @@ SAllocColorPlanesReply(ClientPtr pClient, int size, xAllocColorPlanesReply *pRep swapl(&pRep->redMask); swapl(&pRep->greenMask); swapl(&pRep->blueMask); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } static void -SwapRGB(xrgb *prgb) +SwapRGB(xrgb * prgb) { swaps(&prgb->red); swaps(&prgb->green); @@ -534,32 +526,31 @@ SwapRGB(xrgb *prgb) } void -SQColorsExtend(ClientPtr pClient, int size, xrgb *prgb) +SQColorsExtend(ClientPtr pClient, int size, xrgb * prgb) { - int i, n; - xrgb *prgbT; + int i, n; + xrgb *prgbT; n = size / sizeof(xrgb); prgbT = prgb; - for(i = 0; i < n; i++) - { - SwapRGB(prgbT); - prgbT++; + for (i = 0; i < n; i++) { + SwapRGB(prgbT); + prgbT++; } - (void)WriteToClient(pClient, size, (char *) prgb); + (void) WriteToClient(pClient, size, (char *) prgb); } void -SQueryColorsReply(ClientPtr pClient, int size, xQueryColorsReply* pRep) +SQueryColorsReply(ClientPtr pClient, int size, xQueryColorsReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swaps(&pRep->nColors); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SLookupColorReply(ClientPtr pClient, int size, xLookupColorReply *pRep) +SLookupColorReply(ClientPtr pClient, int size, xLookupColorReply * pRep) { swaps(&pRep->sequenceNumber); swaps(&pRep->exactRed); @@ -568,81 +559,83 @@ SLookupColorReply(ClientPtr pClient, int size, xLookupColorReply *pRep) swaps(&pRep->screenRed); swaps(&pRep->screenGreen); swaps(&pRep->screenBlue); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SQueryBestSizeReply(ClientPtr pClient, int size, xQueryBestSizeReply *pRep) +SQueryBestSizeReply(ClientPtr pClient, int size, xQueryBestSizeReply * pRep) { swaps(&pRep->sequenceNumber); swaps(&pRep->width); swaps(&pRep->height); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SListExtensionsReply(ClientPtr pClient, int size, xListExtensionsReply *pRep) +SListExtensionsReply(ClientPtr pClient, int size, xListExtensionsReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void SGetKeyboardMappingReply(ClientPtr pClient, int size, - xGetKeyboardMappingReply *pRep) + xGetKeyboardMappingReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void SGetPointerMappingReply(ClientPtr pClient, int size, - xGetPointerMappingReply *pRep) + xGetPointerMappingReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void SGetModifierMappingReply(ClientPtr pClient, int size, - xGetModifierMappingReply *pRep) + xGetModifierMappingReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SGetKeyboardControlReply(ClientPtr pClient, int size, xGetKeyboardControlReply *pRep) +SGetKeyboardControlReply(ClientPtr pClient, int size, + xGetKeyboardControlReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swapl(&pRep->ledMask); swaps(&pRep->bellPitch); swaps(&pRep->bellDuration); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SGetPointerControlReply(ClientPtr pClient, int size, xGetPointerControlReply *pRep) +SGetPointerControlReply(ClientPtr pClient, int size, + xGetPointerControlReply * pRep) { swaps(&pRep->sequenceNumber); swaps(&pRep->accelNumerator); swaps(&pRep->accelDenominator); swaps(&pRep->threshold); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void -SGetScreenSaverReply(ClientPtr pClient, int size, xGetScreenSaverReply *pRep) +SGetScreenSaverReply(ClientPtr pClient, int size, xGetScreenSaverReply * pRep) { swaps(&pRep->sequenceNumber); swaps(&pRep->timeout); swaps(&pRep->interval); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } void @@ -650,28 +643,28 @@ SLHostsExtend(ClientPtr pClient, int size, char *buf) { char *bufT = buf; char *endbuf = buf + size; + while (bufT < endbuf) { - xHostEntry *host = (xHostEntry *) bufT; - int len = host->length; - swaps(&host->length); - bufT += sizeof (xHostEntry) + pad_to_int32(len); - } - (void)WriteToClient (pClient, size, buf); + xHostEntry *host = (xHostEntry *) bufT; + int len = host->length; + + swaps(&host->length); + bufT += sizeof(xHostEntry) + pad_to_int32(len); + } + (void) WriteToClient(pClient, size, buf); } void -SListHostsReply(ClientPtr pClient, int size, xListHostsReply *pRep) +SListHostsReply(ClientPtr pClient, int size, xListHostsReply * pRep) { swaps(&pRep->sequenceNumber); swapl(&pRep->length); swaps(&pRep->nHosts); - (void)WriteToClient(pClient, size, (char *) pRep); + (void) WriteToClient(pClient, size, (char *) pRep); } - - void -SErrorEvent(xError *from, xError *to) +SErrorEvent(xError * from, xError * to) { to->type = X_Error; to->errorCode = from->errorCode; @@ -687,26 +680,16 @@ SKeyButtonPtrEvent(xEvent *from, xEvent *to) to->u.u.type = from->u.u.type; to->u.u.detail = from->u.u.detail; cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber); - cpswapl(from->u.keyButtonPointer.time, - to->u.keyButtonPointer.time); - cpswapl(from->u.keyButtonPointer.root, - to->u.keyButtonPointer.root); - cpswapl(from->u.keyButtonPointer.event, - to->u.keyButtonPointer.event); - cpswapl(from->u.keyButtonPointer.child, - to->u.keyButtonPointer.child); - cpswaps(from->u.keyButtonPointer.rootX, - to->u.keyButtonPointer.rootX); - cpswaps(from->u.keyButtonPointer.rootY, - to->u.keyButtonPointer.rootY); - cpswaps(from->u.keyButtonPointer.eventX, - to->u.keyButtonPointer.eventX); - cpswaps(from->u.keyButtonPointer.eventY, - to->u.keyButtonPointer.eventY); - cpswaps(from->u.keyButtonPointer.state, - to->u.keyButtonPointer.state); - to->u.keyButtonPointer.sameScreen = - from->u.keyButtonPointer.sameScreen; + cpswapl(from->u.keyButtonPointer.time, to->u.keyButtonPointer.time); + cpswapl(from->u.keyButtonPointer.root, to->u.keyButtonPointer.root); + cpswapl(from->u.keyButtonPointer.event, to->u.keyButtonPointer.event); + cpswapl(from->u.keyButtonPointer.child, to->u.keyButtonPointer.child); + cpswaps(from->u.keyButtonPointer.rootX, to->u.keyButtonPointer.rootX); + cpswaps(from->u.keyButtonPointer.rootY, to->u.keyButtonPointer.rootY); + cpswaps(from->u.keyButtonPointer.eventX, to->u.keyButtonPointer.eventX); + cpswaps(from->u.keyButtonPointer.eventY, to->u.keyButtonPointer.eventY); + cpswaps(from->u.keyButtonPointer.state, to->u.keyButtonPointer.state); + to->u.keyButtonPointer.sameScreen = from->u.keyButtonPointer.sameScreen; } void @@ -756,22 +739,15 @@ SGraphicsExposureEvent(xEvent *from, xEvent *to) { to->u.u.type = from->u.u.type; cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber); - cpswapl(from->u.graphicsExposure.drawable, - to->u.graphicsExposure.drawable); - cpswaps(from->u.graphicsExposure.x, - to->u.graphicsExposure.x); - cpswaps(from->u.graphicsExposure.y, - to->u.graphicsExposure.y); - cpswaps(from->u.graphicsExposure.width, - to->u.graphicsExposure.width); - cpswaps(from->u.graphicsExposure.height, - to->u.graphicsExposure.height); + cpswapl(from->u.graphicsExposure.drawable, to->u.graphicsExposure.drawable); + cpswaps(from->u.graphicsExposure.x, to->u.graphicsExposure.x); + cpswaps(from->u.graphicsExposure.y, to->u.graphicsExposure.y); + cpswaps(from->u.graphicsExposure.width, to->u.graphicsExposure.width); + cpswaps(from->u.graphicsExposure.height, to->u.graphicsExposure.height); cpswaps(from->u.graphicsExposure.minorEvent, - to->u.graphicsExposure.minorEvent); - cpswaps(from->u.graphicsExposure.count, - to->u.graphicsExposure.count); - to->u.graphicsExposure.majorEvent = - from->u.graphicsExposure.majorEvent; + to->u.graphicsExposure.minorEvent); + cpswaps(from->u.graphicsExposure.count, to->u.graphicsExposure.count); + to->u.graphicsExposure.majorEvent = from->u.graphicsExposure.majorEvent; } void @@ -804,8 +780,7 @@ SCreateNotifyEvent(xEvent *from, xEvent *to) cpswaps(from->u.createNotify.y, to->u.createNotify.y); cpswaps(from->u.createNotify.width, to->u.createNotify.width); cpswaps(from->u.createNotify.height, to->u.createNotify.height); - cpswaps(from->u.createNotify.borderWidth, - to->u.createNotify.borderWidth); + cpswaps(from->u.createNotify.borderWidth, to->u.createNotify.borderWidth); to->u.createNotify.override = from->u.createNotify.override; } @@ -865,19 +840,16 @@ SConfigureNotifyEvent(xEvent *from, xEvent *to) { to->u.u.type = from->u.u.type; cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber); - cpswapl(from->u.configureNotify.event, - to->u.configureNotify.event); - cpswapl(from->u.configureNotify.window, - to->u.configureNotify.window); + cpswapl(from->u.configureNotify.event, to->u.configureNotify.event); + cpswapl(from->u.configureNotify.window, to->u.configureNotify.window); cpswapl(from->u.configureNotify.aboveSibling, - to->u.configureNotify.aboveSibling); + to->u.configureNotify.aboveSibling); cpswaps(from->u.configureNotify.x, to->u.configureNotify.x); cpswaps(from->u.configureNotify.y, to->u.configureNotify.y); cpswaps(from->u.configureNotify.width, to->u.configureNotify.width); - cpswaps(from->u.configureNotify.height, - to->u.configureNotify.height); + cpswaps(from->u.configureNotify.height, to->u.configureNotify.height); cpswaps(from->u.configureNotify.borderWidth, - to->u.configureNotify.borderWidth); + to->u.configureNotify.borderWidth); to->u.configureNotify.override = from->u.configureNotify.override; } @@ -887,25 +859,19 @@ SConfigureRequestEvent(xEvent *from, xEvent *to) to->u.u.type = from->u.u.type; to->u.u.detail = from->u.u.detail; /* actually stack-mode */ cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber); - cpswapl(from->u.configureRequest.parent, - to->u.configureRequest.parent); - cpswapl(from->u.configureRequest.window, - to->u.configureRequest.window); - cpswapl(from->u.configureRequest.sibling, - to->u.configureRequest.sibling); + cpswapl(from->u.configureRequest.parent, to->u.configureRequest.parent); + cpswapl(from->u.configureRequest.window, to->u.configureRequest.window); + cpswapl(from->u.configureRequest.sibling, to->u.configureRequest.sibling); cpswaps(from->u.configureRequest.x, to->u.configureRequest.x); cpswaps(from->u.configureRequest.y, to->u.configureRequest.y); - cpswaps(from->u.configureRequest.width, - to->u.configureRequest.width); - cpswaps(from->u.configureRequest.height, - to->u.configureRequest.height); + cpswaps(from->u.configureRequest.width, to->u.configureRequest.width); + cpswaps(from->u.configureRequest.height, to->u.configureRequest.height); cpswaps(from->u.configureRequest.borderWidth, - to->u.configureRequest.borderWidth); + to->u.configureRequest.borderWidth); cpswaps(from->u.configureRequest.valueMask, - to->u.configureRequest.valueMask); + to->u.configureRequest.valueMask); } - void SGravityEvent(xEvent *from, xEvent *to) { @@ -966,16 +932,13 @@ SSelectionRequestEvent(xEvent *from, xEvent *to) to->u.u.type = from->u.u.type; cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber); cpswapl(from->u.selectionRequest.time, to->u.selectionRequest.time); - cpswapl(from->u.selectionRequest.owner, - to->u.selectionRequest.owner); + cpswapl(from->u.selectionRequest.owner, to->u.selectionRequest.owner); cpswapl(from->u.selectionRequest.requestor, - to->u.selectionRequest.requestor); + to->u.selectionRequest.requestor); cpswapl(from->u.selectionRequest.selection, - to->u.selectionRequest.selection); - cpswapl(from->u.selectionRequest.target, - to->u.selectionRequest.target); - cpswapl(from->u.selectionRequest.property, - to->u.selectionRequest.property); + to->u.selectionRequest.selection); + cpswapl(from->u.selectionRequest.target, to->u.selectionRequest.target); + cpswapl(from->u.selectionRequest.property, to->u.selectionRequest.property); } void @@ -984,14 +947,10 @@ SSelectionNotifyEvent(xEvent *from, xEvent *to) to->u.u.type = from->u.u.type; cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber); cpswapl(from->u.selectionNotify.time, to->u.selectionNotify.time); - cpswapl(from->u.selectionNotify.requestor, - to->u.selectionNotify.requestor); - cpswapl(from->u.selectionNotify.selection, - to->u.selectionNotify.selection); - cpswapl(from->u.selectionNotify.target, - to->u.selectionNotify.target); - cpswapl(from->u.selectionNotify.property, - to->u.selectionNotify.property); + cpswapl(from->u.selectionNotify.requestor, to->u.selectionNotify.requestor); + cpswapl(from->u.selectionNotify.selection, to->u.selectionNotify.selection); + cpswapl(from->u.selectionNotify.target, to->u.selectionNotify.target); + cpswapl(from->u.selectionNotify.property, to->u.selectionNotify.property); } void @@ -1011,8 +970,7 @@ SMappingEvent(xEvent *from, xEvent *to) to->u.u.type = from->u.u.type; cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber); to->u.mappingNotify.request = from->u.mappingNotify.request; - to->u.mappingNotify.firstKeyCode = - from->u.mappingNotify.firstKeyCode; + to->u.mappingNotify.firstKeyCode = from->u.mappingNotify.firstKeyCode; to->u.mappingNotify.count = from->u.mappingNotify.count; } @@ -1023,48 +981,47 @@ SClientMessageEvent(xEvent *from, xEvent *to) to->u.u.detail = from->u.u.detail; /* actually format */ cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber); cpswapl(from->u.clientMessage.window, to->u.clientMessage.window); - cpswapl(from->u.clientMessage.u.l.type, - to->u.clientMessage.u.l.type); + cpswapl(from->u.clientMessage.u.l.type, to->u.clientMessage.u.l.type); switch (from->u.u.detail) { - case 8: - memmove(to->u.clientMessage.u.b.bytes, - from->u.clientMessage.u.b.bytes,20); - break; - case 16: - cpswaps(from->u.clientMessage.u.s.shorts0, - to->u.clientMessage.u.s.shorts0); - cpswaps(from->u.clientMessage.u.s.shorts1, - to->u.clientMessage.u.s.shorts1); - cpswaps(from->u.clientMessage.u.s.shorts2, - to->u.clientMessage.u.s.shorts2); - cpswaps(from->u.clientMessage.u.s.shorts3, - to->u.clientMessage.u.s.shorts3); - cpswaps(from->u.clientMessage.u.s.shorts4, - to->u.clientMessage.u.s.shorts4); - cpswaps(from->u.clientMessage.u.s.shorts5, - to->u.clientMessage.u.s.shorts5); - cpswaps(from->u.clientMessage.u.s.shorts6, - to->u.clientMessage.u.s.shorts6); - cpswaps(from->u.clientMessage.u.s.shorts7, - to->u.clientMessage.u.s.shorts7); - cpswaps(from->u.clientMessage.u.s.shorts8, - to->u.clientMessage.u.s.shorts8); - cpswaps(from->u.clientMessage.u.s.shorts9, - to->u.clientMessage.u.s.shorts9); - break; - case 32: - cpswapl(from->u.clientMessage.u.l.longs0, - to->u.clientMessage.u.l.longs0); - cpswapl(from->u.clientMessage.u.l.longs1, - to->u.clientMessage.u.l.longs1); - cpswapl(from->u.clientMessage.u.l.longs2, - to->u.clientMessage.u.l.longs2); - cpswapl(from->u.clientMessage.u.l.longs3, - to->u.clientMessage.u.l.longs3); - cpswapl(from->u.clientMessage.u.l.longs4, - to->u.clientMessage.u.l.longs4); - break; - } + case 8: + memmove(to->u.clientMessage.u.b.bytes, + from->u.clientMessage.u.b.bytes, 20); + break; + case 16: + cpswaps(from->u.clientMessage.u.s.shorts0, + to->u.clientMessage.u.s.shorts0); + cpswaps(from->u.clientMessage.u.s.shorts1, + to->u.clientMessage.u.s.shorts1); + cpswaps(from->u.clientMessage.u.s.shorts2, + to->u.clientMessage.u.s.shorts2); + cpswaps(from->u.clientMessage.u.s.shorts3, + to->u.clientMessage.u.s.shorts3); + cpswaps(from->u.clientMessage.u.s.shorts4, + to->u.clientMessage.u.s.shorts4); + cpswaps(from->u.clientMessage.u.s.shorts5, + to->u.clientMessage.u.s.shorts5); + cpswaps(from->u.clientMessage.u.s.shorts6, + to->u.clientMessage.u.s.shorts6); + cpswaps(from->u.clientMessage.u.s.shorts7, + to->u.clientMessage.u.s.shorts7); + cpswaps(from->u.clientMessage.u.s.shorts8, + to->u.clientMessage.u.s.shorts8); + cpswaps(from->u.clientMessage.u.s.shorts9, + to->u.clientMessage.u.s.shorts9); + break; + case 32: + cpswapl(from->u.clientMessage.u.l.longs0, + to->u.clientMessage.u.l.longs0); + cpswapl(from->u.clientMessage.u.l.longs1, + to->u.clientMessage.u.l.longs1); + cpswapl(from->u.clientMessage.u.l.longs2, + to->u.clientMessage.u.l.longs2); + cpswapl(from->u.clientMessage.u.l.longs3, + to->u.clientMessage.u.l.longs3); + cpswapl(from->u.clientMessage.u.l.longs4, + to->u.clientMessage.u.l.longs4); + break; + } } void @@ -1076,7 +1033,7 @@ SKeymapNotifyEvent(xEvent *from, xEvent *to) } static void -SwapConnSetup(xConnSetup *pConnSetup, xConnSetup *pConnSetupT) +SwapConnSetup(xConnSetup * pConnSetup, xConnSetup * pConnSetupT) { cpswapl(pConnSetup->release, pConnSetupT->release); cpswapl(pConnSetup->ridBase, pConnSetupT->ridBase); @@ -1095,7 +1052,7 @@ SwapConnSetup(xConnSetup *pConnSetup, xConnSetup *pConnSetupT) } static void -SwapWinRoot(xWindowRoot *pRoot, xWindowRoot *pRootT) +SwapWinRoot(xWindowRoot * pRoot, xWindowRoot * pRootT) { cpswapl(pRoot->windowId, pRootT->windowId); cpswapl(pRoot->defaultColormap, pRootT->defaultColormap); @@ -1116,7 +1073,7 @@ SwapWinRoot(xWindowRoot *pRoot, xWindowRoot *pRootT) } static void -SwapVisual(xVisualType *pVis, xVisualType *pVisT) +SwapVisual(xVisualType * pVis, xVisualType * pVisT) { cpswapl(pVis->visualID, pVisT->visualID); pVisT->class = pVis->class; @@ -1128,17 +1085,14 @@ SwapVisual(xVisualType *pVis, xVisualType *pVisT) } void -SwapConnSetupInfo( - char *pInfo, - char *pInfoT -) +SwapConnSetupInfo(char *pInfo, char *pInfoT) { - int i, j, k; - xConnSetup *pConnSetup = (xConnSetup *)pInfo; - xDepth *depth; + int i, j, k; + xConnSetup *pConnSetup = (xConnSetup *) pInfo; + xDepth *depth; xWindowRoot *root; - SwapConnSetup(pConnSetup, (xConnSetup *)pInfoT); + SwapConnSetup(pConnSetup, (xConnSetup *) pInfoT); pInfo += sizeof(xConnSetup); pInfoT += sizeof(xConnSetup); @@ -1154,48 +1108,44 @@ SwapConnSetupInfo( pInfo += i; pInfoT += i; - for(i = 0; i < pConnSetup->numRoots; i++) - { - root = (xWindowRoot*)pInfo; - SwapWinRoot(root, (xWindowRoot *)pInfoT); - pInfo += sizeof(xWindowRoot); - pInfoT += sizeof(xWindowRoot); - - for(j = 0; j < root->nDepths; j++) - { - depth = (xDepth*)pInfo; - ((xDepth *)pInfoT)->depth = depth->depth; - cpswaps(depth->nVisuals, ((xDepth *)pInfoT)->nVisuals); - pInfo += sizeof(xDepth); - pInfoT += sizeof(xDepth); - for(k = 0; k < depth->nVisuals; k++) - { - SwapVisual((xVisualType *)pInfo, (xVisualType *)pInfoT); - pInfo += sizeof(xVisualType); - pInfoT += sizeof(xVisualType); - } - } + for (i = 0; i < pConnSetup->numRoots; i++) { + root = (xWindowRoot *) pInfo; + SwapWinRoot(root, (xWindowRoot *) pInfoT); + pInfo += sizeof(xWindowRoot); + pInfoT += sizeof(xWindowRoot); + + for (j = 0; j < root->nDepths; j++) { + depth = (xDepth *) pInfo; + ((xDepth *) pInfoT)->depth = depth->depth; + cpswaps(depth->nVisuals, ((xDepth *) pInfoT)->nVisuals); + pInfo += sizeof(xDepth); + pInfoT += sizeof(xDepth); + for (k = 0; k < depth->nVisuals; k++) { + SwapVisual((xVisualType *) pInfo, (xVisualType *) pInfoT); + pInfo += sizeof(xVisualType); + pInfoT += sizeof(xVisualType); + } + } } } void WriteSConnectionInfo(ClientPtr pClient, unsigned long size, char *pInfo) { - char *pInfoTBase; + char *pInfoTBase; pInfoTBase = malloc(size); - if (!pInfoTBase) - { - pClient->noClientException = -1; - return; + if (!pInfoTBase) { + pClient->noClientException = -1; + return; } SwapConnSetupInfo(pInfo, pInfoTBase); - (void)WriteToClient(pClient, (int)size, (char *) pInfoTBase); + (void) WriteToClient(pClient, (int) size, (char *) pInfoTBase); free(pInfoTBase); } void -SwapConnSetupPrefix(xConnSetupPrefix *pcspFrom, xConnSetupPrefix *pcspTo) +SwapConnSetupPrefix(xConnSetupPrefix * pcspFrom, xConnSetupPrefix * pcspTo) { pcspTo->success = pcspFrom->success; pcspTo->lengthReason = pcspFrom->lengthReason; @@ -1205,12 +1155,12 @@ SwapConnSetupPrefix(xConnSetupPrefix *pcspFrom, xConnSetupPrefix *pcspTo) } void -WriteSConnSetupPrefix(ClientPtr pClient, xConnSetupPrefix *pcsp) +WriteSConnSetupPrefix(ClientPtr pClient, xConnSetupPrefix * pcsp) { - xConnSetupPrefix cspT; + xConnSetupPrefix cspT; SwapConnSetupPrefix(pcsp, &cspT); - (void)WriteToClient(pClient, sizeof(cspT), (char *) &cspT); + (void) WriteToClient(pClient, sizeof(cspT), (char *) &cspT); } /* @@ -1218,12 +1168,7 @@ WriteSConnSetupPrefix(ClientPtr pClient, xConnSetupPrefix *pcsp) */ void -ReplyNotSwappd( - ClientPtr pClient , - int size , - void * pbuf - ) +ReplyNotSwappd(ClientPtr pClient, int size, void *pbuf) { FatalError("Not implemented"); } - diff --git a/xorg-server/dix/swapreq.c b/xorg-server/dix/swapreq.c index d07cd10d3..a896b4b29 100644 --- a/xorg-server/dix/swapreq.c +++ b/xorg-server/dix/swapreq.c @@ -22,7 +22,6 @@ 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 @@ -45,7 +44,6 @@ SOFTWARE. ********************************************************/ - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #endif @@ -55,65 +53,65 @@ SOFTWARE. #include <X11/Xprotostr.h> #include "misc.h" #include "dixstruct.h" -#include "extnsionst.h" /* for SendEvent */ +#include "extnsionst.h" /* for SendEvent */ #include "swapreq.h" /* Thanks to Jack Palevich for testing and subsequently rewriting all this */ /* Byte swap a list of longs */ void -SwapLongs (CARD32 *list, unsigned long count) -{ - while (count >= 8) { - swapl(list + 0); - swapl(list + 1); - swapl(list + 2); - swapl(list + 3); - swapl(list + 4); - swapl(list + 5); - swapl(list + 6); - swapl(list + 7); - list += 8; - count -= 8; - } - if (count != 0) { - do { - swapl(list); - list++; - } while (--count != 0); - } +SwapLongs(CARD32 *list, unsigned long count) +{ + while (count >= 8) { + swapl(list + 0); + swapl(list + 1); + swapl(list + 2); + swapl(list + 3); + swapl(list + 4); + swapl(list + 5); + swapl(list + 6); + swapl(list + 7); + list += 8; + count -= 8; + } + if (count != 0) { + do { + swapl(list); + list++; + } while (--count != 0); + } } /* Byte swap a list of shorts */ void -SwapShorts (short *list, unsigned long count) -{ - while (count >= 16) { - swaps(list + 0); - swaps(list + 1); - swaps(list + 2); - swaps(list + 3); - swaps(list + 4); - swaps(list + 5); - swaps(list + 6); - swaps(list + 7); - swaps(list + 8); - swaps(list + 9); - swaps(list + 10); - swaps(list + 11); - swaps(list + 12); - swaps(list + 13); - swaps(list + 14); - swaps(list + 15); - list += 16; - count -= 16; - } - if (count != 0) { - do { - swaps(list); - list++; - } while (--count != 0); - } +SwapShorts(short *list, unsigned long count) +{ + while (count >= 16) { + swaps(list + 0); + swaps(list + 1); + swaps(list + 2); + swaps(list + 3); + swaps(list + 4); + swaps(list + 5); + swaps(list + 6); + swaps(list + 7); + swaps(list + 8); + swaps(list + 9); + swaps(list + 10); + swaps(list + 11); + swaps(list + 12); + swaps(list + 13); + swaps(list + 14); + swaps(list + 15); + list += 16; + count -= 16; + } + if (count != 0) { + do { + swaps(list); + list++; + } while (--count != 0); + } } /* The following is used for all requests that have @@ -123,7 +121,7 @@ SProcSimpleReq(ClientPtr client) { REQUEST(xReq); swaps(&stuff->length); - return(*ProcVector[stuff->reqType])(client); + return (*ProcVector[stuff->reqType]) (client); } /* The following is used for all requests that have @@ -134,9 +132,9 @@ SProcResourceReq(ClientPtr client) { REQUEST(xResourceReq); swaps(&stuff->length); - REQUEST_AT_LEAST_SIZE(xResourceReq); /* not EXACT */ + REQUEST_AT_LEAST_SIZE(xResourceReq); /* not EXACT */ swapl(&stuff->id); - return(*ProcVector[stuff->reqType])(client); + return (*ProcVector[stuff->reqType]) (client); } int @@ -156,7 +154,7 @@ SProcCreateWindow(ClientPtr client) swapl(&stuff->visual); swapl(&stuff->mask); SwapRestL(stuff); - return((* ProcVector[X_CreateWindow])(client)); + return ((*ProcVector[X_CreateWindow]) (client)); } int @@ -168,7 +166,7 @@ SProcChangeWindowAttributes(ClientPtr client) swapl(&stuff->window); swapl(&stuff->valueMask); SwapRestL(stuff); - return((* ProcVector[X_ChangeWindowAttributes])(client)); + return ((*ProcVector[X_ChangeWindowAttributes]) (client)); } int @@ -181,7 +179,7 @@ SProcReparentWindow(ClientPtr client) swapl(&stuff->parent); swaps(&stuff->x); swaps(&stuff->y); - return((* ProcVector[X_ReparentWindow])(client)); + return ((*ProcVector[X_ReparentWindow]) (client)); } int @@ -193,11 +191,10 @@ SProcConfigureWindow(ClientPtr client) swapl(&stuff->window); swaps(&stuff->mask); SwapRestL(stuff); - return((* ProcVector[X_ConfigureWindow])(client)); + return ((*ProcVector[X_ConfigureWindow]) (client)); } - int SProcInternAtom(ClientPtr client) { @@ -205,7 +202,7 @@ SProcInternAtom(ClientPtr client) swaps(&stuff->length); REQUEST_AT_LEAST_SIZE(xInternAtomReq); swaps(&stuff->nbytes); - return((* ProcVector[X_InternAtom])(client)); + return ((*ProcVector[X_InternAtom]) (client)); } int @@ -218,17 +215,17 @@ SProcChangeProperty(ClientPtr client) swapl(&stuff->property); swapl(&stuff->type); swapl(&stuff->nUnits); - switch ( stuff->format ) { - case 8 : - break; - case 16: - SwapRestS(stuff); - break; - case 32: - SwapRestL(stuff); - break; - } - return((* ProcVector[X_ChangeProperty])(client)); + switch (stuff->format) { + case 8: + break; + case 16: + SwapRestS(stuff); + break; + case 32: + SwapRestL(stuff); + break; + } + return ((*ProcVector[X_ChangeProperty]) (client)); } int @@ -239,8 +236,8 @@ SProcDeleteProperty(ClientPtr client) REQUEST_SIZE_MATCH(xDeletePropertyReq); swapl(&stuff->window); swapl(&stuff->property); - return((* ProcVector[X_DeleteProperty])(client)); - + return ((*ProcVector[X_DeleteProperty]) (client)); + } int @@ -254,7 +251,7 @@ SProcGetProperty(ClientPtr client) swapl(&stuff->type); swapl(&stuff->longOffset); swapl(&stuff->longLength); - return((* ProcVector[X_GetProperty])(client)); + return ((*ProcVector[X_GetProperty]) (client)); } int @@ -266,7 +263,7 @@ SProcSetSelectionOwner(ClientPtr client) swapl(&stuff->window); swapl(&stuff->selection); swapl(&stuff->time); - return((* ProcVector[X_SetSelectionOwner])(client)); + return ((*ProcVector[X_SetSelectionOwner]) (client)); } int @@ -280,7 +277,7 @@ SProcConvertSelection(ClientPtr client) swapl(&stuff->target); swapl(&stuff->property); swapl(&stuff->time); - return((* ProcVector[X_ConvertSelection])(client)); + return ((*ProcVector[X_ConvertSelection]) (client)); } int @@ -288,6 +285,7 @@ SProcSendEvent(ClientPtr client) { xEvent eventT; EventSwapPtr proc; + REQUEST(xSendEventReq); swaps(&stuff->length); REQUEST_SIZE_MATCH(xSendEventReq); @@ -296,12 +294,12 @@ SProcSendEvent(ClientPtr client) /* Swap event */ proc = EventSwapVector[stuff->event.u.u.type & 0177]; - if (!proc || proc == NotImplemented) /* no swapping proc; invalid event type? */ - return BadValue; - (*proc)(&stuff->event, &eventT); + if (!proc || proc == NotImplemented) /* no swapping proc; invalid event type? */ + return BadValue; + (*proc) (&stuff->event, &eventT); stuff->event = eventT; - return((* ProcVector[X_SendEvent])(client)); + return ((*ProcVector[X_SendEvent]) (client)); } int @@ -315,7 +313,7 @@ SProcGrabPointer(ClientPtr client) swapl(&stuff->confineTo); swapl(&stuff->cursor); swapl(&stuff->time); - return((* ProcVector[X_GrabPointer])(client)); + return ((*ProcVector[X_GrabPointer]) (client)); } int @@ -329,7 +327,7 @@ SProcGrabButton(ClientPtr client) swapl(&stuff->confineTo); swapl(&stuff->cursor); swaps(&stuff->modifiers); - return((* ProcVector[X_GrabButton])(client)); + return ((*ProcVector[X_GrabButton]) (client)); } int @@ -340,7 +338,7 @@ SProcUngrabButton(ClientPtr client) REQUEST_SIZE_MATCH(xUngrabButtonReq); swapl(&stuff->grabWindow); swaps(&stuff->modifiers); - return((* ProcVector[X_UngrabButton])(client)); + return ((*ProcVector[X_UngrabButton]) (client)); } int @@ -352,7 +350,7 @@ SProcChangeActivePointerGrab(ClientPtr client) swapl(&stuff->cursor); swapl(&stuff->time); swaps(&stuff->eventMask); - return((* ProcVector[X_ChangeActivePointerGrab])(client)); + return ((*ProcVector[X_ChangeActivePointerGrab]) (client)); } int @@ -363,7 +361,7 @@ SProcGrabKeyboard(ClientPtr client) REQUEST_SIZE_MATCH(xGrabKeyboardReq); swapl(&stuff->grabWindow); swapl(&stuff->time); - return((* ProcVector[X_GrabKeyboard])(client)); + return ((*ProcVector[X_GrabKeyboard]) (client)); } int @@ -374,7 +372,7 @@ SProcGrabKey(ClientPtr client) REQUEST_SIZE_MATCH(xGrabKeyReq); swapl(&stuff->grabWindow); swaps(&stuff->modifiers); - return((* ProcVector[X_GrabKey])(client)); + return ((*ProcVector[X_GrabKey]) (client)); } int @@ -385,7 +383,7 @@ SProcUngrabKey(ClientPtr client) REQUEST_SIZE_MATCH(xUngrabKeyReq); swapl(&stuff->grabWindow); swaps(&stuff->modifiers); - return((* ProcVector[X_UngrabKey])(client)); + return ((*ProcVector[X_UngrabKey]) (client)); } int @@ -397,7 +395,7 @@ SProcGetMotionEvents(ClientPtr client) swapl(&stuff->window); swapl(&stuff->start); swapl(&stuff->stop); - return((* ProcVector[X_GetMotionEvents])(client)); + return ((*ProcVector[X_GetMotionEvents]) (client)); } int @@ -410,7 +408,7 @@ SProcTranslateCoords(ClientPtr client) swapl(&stuff->dstWid); swaps(&stuff->srcX); swaps(&stuff->srcY); - return((* ProcVector[X_TranslateCoords])(client)); + return ((*ProcVector[X_TranslateCoords]) (client)); } int @@ -427,7 +425,7 @@ SProcWarpPointer(ClientPtr client) swaps(&stuff->srcHeight); swaps(&stuff->dstX); swaps(&stuff->dstY); - return((* ProcVector[X_WarpPointer])(client)); + return ((*ProcVector[X_WarpPointer]) (client)); } int @@ -438,7 +436,7 @@ SProcSetInputFocus(ClientPtr client) REQUEST_SIZE_MATCH(xSetInputFocusReq); swapl(&stuff->focus); swapl(&stuff->time); - return((* ProcVector[X_SetInputFocus])(client)); + return ((*ProcVector[X_SetInputFocus]) (client)); } int @@ -449,7 +447,7 @@ SProcOpenFont(ClientPtr client) REQUEST_AT_LEAST_SIZE(xOpenFontReq); swapl(&stuff->fid); swaps(&stuff->nbytes); - return((* ProcVector[X_OpenFont])(client)); + return ((*ProcVector[X_OpenFont]) (client)); } int @@ -460,7 +458,7 @@ SProcListFonts(ClientPtr client) REQUEST_AT_LEAST_SIZE(xListFontsReq); swaps(&stuff->maxNames); swaps(&stuff->nbytes); - return((* ProcVector[X_ListFonts])(client)); + return ((*ProcVector[X_ListFonts]) (client)); } int @@ -471,7 +469,7 @@ SProcListFontsWithInfo(ClientPtr client) REQUEST_AT_LEAST_SIZE(xListFontsWithInfoReq); swaps(&stuff->maxNames); swaps(&stuff->nbytes); - return((* ProcVector[X_ListFontsWithInfo])(client)); + return ((*ProcVector[X_ListFontsWithInfo]) (client)); } int @@ -481,7 +479,7 @@ SProcSetFontPath(ClientPtr client) swaps(&stuff->length); REQUEST_AT_LEAST_SIZE(xSetFontPathReq); swaps(&stuff->nFonts); - return((* ProcVector[X_SetFontPath])(client)); + return ((*ProcVector[X_SetFontPath]) (client)); } int @@ -495,7 +493,7 @@ SProcCreatePixmap(ClientPtr client) swapl(&stuff->drawable); swaps(&stuff->width); swaps(&stuff->height); - return((* ProcVector[X_CreatePixmap])(client)); + return ((*ProcVector[X_CreatePixmap]) (client)); } int @@ -508,7 +506,7 @@ SProcCreateGC(ClientPtr client) swapl(&stuff->drawable); swapl(&stuff->mask); SwapRestL(stuff); - return((* ProcVector[X_CreateGC])(client)); + return ((*ProcVector[X_CreateGC]) (client)); } int @@ -520,7 +518,7 @@ SProcChangeGC(ClientPtr client) swapl(&stuff->gc); swapl(&stuff->mask); SwapRestL(stuff); - return((* ProcVector[X_ChangeGC])(client)); + return ((*ProcVector[X_ChangeGC]) (client)); } int @@ -532,7 +530,7 @@ SProcCopyGC(ClientPtr client) swapl(&stuff->srcGC); swapl(&stuff->dstGC); swapl(&stuff->mask); - return((* ProcVector[X_CopyGC])(client)); + return ((*ProcVector[X_CopyGC]) (client)); } int @@ -544,7 +542,7 @@ SProcSetDashes(ClientPtr client) swapl(&stuff->gc); swaps(&stuff->dashOffset); swaps(&stuff->nDashes); - return((* ProcVector[X_SetDashes])(client)); + return ((*ProcVector[X_SetDashes]) (client)); } @@ -558,7 +556,7 @@ SProcSetClipRectangles(ClientPtr client) swaps(&stuff->xOrigin); swaps(&stuff->yOrigin); SwapRestS(stuff); - return((* ProcVector[X_SetClipRectangles])(client)); + return ((*ProcVector[X_SetClipRectangles]) (client)); } int @@ -572,7 +570,7 @@ SProcClearToBackground(ClientPtr client) swaps(&stuff->y); swaps(&stuff->width); swaps(&stuff->height); - return((* ProcVector[X_ClearArea])(client)); + return ((*ProcVector[X_ClearArea]) (client)); } int @@ -590,7 +588,7 @@ SProcCopyArea(ClientPtr client) swaps(&stuff->dstY); swaps(&stuff->width); swaps(&stuff->height); - return((* ProcVector[X_CopyArea])(client)); + return ((*ProcVector[X_CopyArea]) (client)); } int @@ -609,7 +607,7 @@ SProcCopyPlane(ClientPtr client) swaps(&stuff->width); swaps(&stuff->height); swapl(&stuff->bitPlane); - return((* ProcVector[X_CopyPlane])(client)); + return ((*ProcVector[X_CopyPlane]) (client)); } /* The following routine is used for all Poly drawing requests @@ -623,7 +621,7 @@ SProcPoly(ClientPtr client) swapl(&stuff->drawable); swapl(&stuff->gc); SwapRestS(stuff); - return((* ProcVector[stuff->reqType])(client)); + return ((*ProcVector[stuff->reqType]) (client)); } /* cannot use SProcPoly for this one, because xFillPolyReq @@ -638,7 +636,7 @@ SProcFillPoly(ClientPtr client) swapl(&stuff->drawable); swapl(&stuff->gc); SwapRestS(stuff); - return((* ProcVector[X_FillPoly])(client)); + return ((*ProcVector[X_FillPoly]) (client)); } int @@ -654,7 +652,7 @@ SProcPutImage(ClientPtr client) swaps(&stuff->dstX); swaps(&stuff->dstY); /* Image should already be swapped */ - return((* ProcVector[X_PutImage])(client)); + return ((*ProcVector[X_PutImage]) (client)); } @@ -670,7 +668,7 @@ SProcGetImage(ClientPtr client) swaps(&stuff->width); swaps(&stuff->height); swapl(&stuff->planeMask); - return((* ProcVector[X_GetImage])(client)); + return ((*ProcVector[X_GetImage]) (client)); } /* ProcPolyText used for both PolyText8 and PolyText16 */ @@ -685,7 +683,7 @@ SProcPolyText(ClientPtr client) swapl(&stuff->gc); swaps(&stuff->x); swaps(&stuff->y); - return((* ProcVector[stuff->reqType])(client)); + return ((*ProcVector[stuff->reqType]) (client)); } /* ProcImageText used for both ImageText8 and ImageText16 */ @@ -700,7 +698,7 @@ SProcImageText(ClientPtr client) swapl(&stuff->gc); swaps(&stuff->x); swaps(&stuff->y); - return((* ProcVector[stuff->reqType])(client)); + return ((*ProcVector[stuff->reqType]) (client)); } int @@ -712,10 +710,9 @@ SProcCreateColormap(ClientPtr client) swapl(&stuff->mid); swapl(&stuff->window); swapl(&stuff->visual); - return((* ProcVector[X_CreateColormap])(client)); + return ((*ProcVector[X_CreateColormap]) (client)); } - int SProcCopyColormapAndFree(ClientPtr client) { @@ -724,7 +721,7 @@ SProcCopyColormapAndFree(ClientPtr client) REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq); swapl(&stuff->mid); swapl(&stuff->srcCmap); - return((* ProcVector[X_CopyColormapAndFree])(client)); + return ((*ProcVector[X_CopyColormapAndFree]) (client)); } @@ -738,7 +735,7 @@ SProcAllocColor(ClientPtr client) swaps(&stuff->red); swaps(&stuff->green); swaps(&stuff->blue); - return((* ProcVector[X_AllocColor])(client)); + return ((*ProcVector[X_AllocColor]) (client)); } int @@ -749,7 +746,7 @@ SProcAllocNamedColor(ClientPtr client) REQUEST_AT_LEAST_SIZE(xAllocNamedColorReq); swapl(&stuff->cmap); swaps(&stuff->nbytes); - return((* ProcVector[X_AllocNamedColor])(client)); + return ((*ProcVector[X_AllocNamedColor]) (client)); } int @@ -761,7 +758,7 @@ SProcAllocColorCells(ClientPtr client) swapl(&stuff->cmap); swaps(&stuff->colors); swaps(&stuff->planes); - return((* ProcVector[X_AllocColorCells])(client)); + return ((*ProcVector[X_AllocColorCells]) (client)); } int @@ -775,7 +772,7 @@ SProcAllocColorPlanes(ClientPtr client) swaps(&stuff->red); swaps(&stuff->green); swaps(&stuff->blue); - return((* ProcVector[X_AllocColorPlanes])(client)); + return ((*ProcVector[X_AllocColorPlanes]) (client)); } int @@ -787,12 +784,12 @@ SProcFreeColors(ClientPtr client) swapl(&stuff->cmap); swapl(&stuff->planeMask); SwapRestL(stuff); - return((* ProcVector[X_FreeColors])(client)); + return ((*ProcVector[X_FreeColors]) (client)); } void -SwapColorItem(xColorItem *pItem) +SwapColorItem(xColorItem * pItem) { swapl(&pItem->pixel); swaps(&pItem->red); @@ -804,20 +801,20 @@ int SProcStoreColors(ClientPtr client) { long count; - xColorItem *pItem; + xColorItem *pItem; REQUEST(xStoreColorsReq); swaps(&stuff->length); REQUEST_AT_LEAST_SIZE(xStoreColorsReq); swapl(&stuff->cmap); pItem = (xColorItem *) &stuff[1]; - for(count = LengthRestB(stuff)/sizeof(xColorItem); --count >= 0; ) - SwapColorItem(pItem++); - return((* ProcVector[X_StoreColors])(client)); + for (count = LengthRestB(stuff) / sizeof(xColorItem); --count >= 0;) + SwapColorItem(pItem++); + return ((*ProcVector[X_StoreColors]) (client)); } int -SProcStoreNamedColor (ClientPtr client) +SProcStoreNamedColor(ClientPtr client) { REQUEST(xStoreNamedColorReq); swaps(&stuff->length); @@ -825,33 +822,33 @@ SProcStoreNamedColor (ClientPtr client) swapl(&stuff->cmap); swapl(&stuff->pixel); swaps(&stuff->nbytes); - return((* ProcVector[X_StoreNamedColor])(client)); + return ((*ProcVector[X_StoreNamedColor]) (client)); } int -SProcQueryColors (ClientPtr client) +SProcQueryColors(ClientPtr client) { REQUEST(xQueryColorsReq); swaps(&stuff->length); REQUEST_AT_LEAST_SIZE(xQueryColorsReq); swapl(&stuff->cmap); SwapRestL(stuff); - return((* ProcVector[X_QueryColors])(client)); -} + return ((*ProcVector[X_QueryColors]) (client)); +} int -SProcLookupColor (ClientPtr client) +SProcLookupColor(ClientPtr client) { REQUEST(xLookupColorReq); swaps(&stuff->length); REQUEST_AT_LEAST_SIZE(xLookupColorReq); swapl(&stuff->cmap); swaps(&stuff->nbytes); - return((* ProcVector[X_LookupColor])(client)); + return ((*ProcVector[X_LookupColor]) (client)); } int -SProcCreateCursor (ClientPtr client) +SProcCreateCursor(ClientPtr client) { REQUEST(xCreateCursorReq); swaps(&stuff->length); @@ -867,11 +864,11 @@ SProcCreateCursor (ClientPtr client) swaps(&stuff->backBlue); swaps(&stuff->x); swaps(&stuff->y); - return((* ProcVector[X_CreateCursor])(client)); + return ((*ProcVector[X_CreateCursor]) (client)); } int -SProcCreateGlyphCursor (ClientPtr client) +SProcCreateGlyphCursor(ClientPtr client) { REQUEST(xCreateGlyphCursorReq); swaps(&stuff->length); @@ -887,12 +884,11 @@ SProcCreateGlyphCursor (ClientPtr client) swaps(&stuff->backRed); swaps(&stuff->backGreen); swaps(&stuff->backBlue); - return((* ProcVector[X_CreateGlyphCursor])(client)); + return ((*ProcVector[X_CreateGlyphCursor]) (client)); } - int -SProcRecolorCursor (ClientPtr client) +SProcRecolorCursor(ClientPtr client) { REQUEST(xRecolorCursorReq); swaps(&stuff->length); @@ -904,11 +900,11 @@ SProcRecolorCursor (ClientPtr client) swaps(&stuff->backRed); swaps(&stuff->backGreen); swaps(&stuff->backBlue); - return((* ProcVector[X_RecolorCursor])(client)); + return ((*ProcVector[X_RecolorCursor]) (client)); } int -SProcQueryBestSize (ClientPtr client) +SProcQueryBestSize(ClientPtr client) { REQUEST(xQueryBestSizeReq); swaps(&stuff->length); @@ -916,44 +912,43 @@ SProcQueryBestSize (ClientPtr client) swapl(&stuff->drawable); swaps(&stuff->width); swaps(&stuff->height); - return((* ProcVector[X_QueryBestSize])(client)); + return ((*ProcVector[X_QueryBestSize]) (client)); } int -SProcQueryExtension (ClientPtr client) +SProcQueryExtension(ClientPtr client) { REQUEST(xQueryExtensionReq); swaps(&stuff->length); REQUEST_AT_LEAST_SIZE(xQueryExtensionReq); swaps(&stuff->nbytes); - return((* ProcVector[X_QueryExtension])(client)); + return ((*ProcVector[X_QueryExtension]) (client)); } int -SProcChangeKeyboardMapping (ClientPtr client) +SProcChangeKeyboardMapping(ClientPtr client) { REQUEST(xChangeKeyboardMappingReq); swaps(&stuff->length); REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq); SwapRestL(stuff); - return((* ProcVector[X_ChangeKeyboardMapping])(client)); + return ((*ProcVector[X_ChangeKeyboardMapping]) (client)); } - int -SProcChangeKeyboardControl (ClientPtr client) +SProcChangeKeyboardControl(ClientPtr client) { REQUEST(xChangeKeyboardControlReq); swaps(&stuff->length); REQUEST_AT_LEAST_SIZE(xChangeKeyboardControlReq); swapl(&stuff->mask); SwapRestL(stuff); - return((* ProcVector[X_ChangeKeyboardControl])(client)); + return ((*ProcVector[X_ChangeKeyboardControl]) (client)); } int -SProcChangePointerControl (ClientPtr client) +SProcChangePointerControl(ClientPtr client) { REQUEST(xChangePointerControlReq); swaps(&stuff->length); @@ -961,33 +956,33 @@ SProcChangePointerControl (ClientPtr client) swaps(&stuff->accelNum); swaps(&stuff->accelDenum); swaps(&stuff->threshold); - return((* ProcVector[X_ChangePointerControl])(client)); + return ((*ProcVector[X_ChangePointerControl]) (client)); } - int -SProcSetScreenSaver (ClientPtr client) +SProcSetScreenSaver(ClientPtr client) { REQUEST(xSetScreenSaverReq); swaps(&stuff->length); REQUEST_SIZE_MATCH(xSetScreenSaverReq); swaps(&stuff->timeout); swaps(&stuff->interval); - return((* ProcVector[X_SetScreenSaver])(client)); + return ((*ProcVector[X_SetScreenSaver]) (client)); } int -SProcChangeHosts (ClientPtr client) +SProcChangeHosts(ClientPtr client) { REQUEST(xChangeHostsReq); swaps(&stuff->length); REQUEST_AT_LEAST_SIZE(xChangeHostsReq); swaps(&stuff->hostLength); - return((* ProcVector[X_ChangeHosts])(client)); + return ((*ProcVector[X_ChangeHosts]) (client)); } -int SProcRotateProperties (ClientPtr client) +int +SProcRotateProperties(ClientPtr client) { REQUEST(xRotatePropertiesReq); swaps(&stuff->length); @@ -996,7 +991,7 @@ int SProcRotateProperties (ClientPtr client) swaps(&stuff->nAtoms); swaps(&stuff->nPositions); SwapRestL(stuff); - return ((* ProcVector[X_RotateProperties])(client)); + return ((*ProcVector[X_RotateProperties]) (client)); } int @@ -1004,11 +999,11 @@ SProcNoOperation(ClientPtr client) { REQUEST(xReq); swaps(&stuff->length); - return ((* ProcVector[X_NoOperation])(client)); + return ((*ProcVector[X_NoOperation]) (client)); } void -SwapConnClientPrefix(xConnClientPrefix *pCCP) +SwapConnClientPrefix(xConnClientPrefix * pCCP) { swaps(&pCCP->majorVersion); swaps(&pCCP->minorVersion); diff --git a/xorg-server/dix/tables.c b/xorg-server/dix/tables.c index 45ae2a9d1..705ef0d4d 100644 --- a/xorg-server/dix/tables.c +++ b/xorg-server/dix/tables.c @@ -22,7 +22,6 @@ 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 @@ -59,572 +58,397 @@ SOFTWARE. #include "swaprep.h" #include "swapreq.h" -int (* InitialVector[3]) ( - ClientPtr /* client */ - ) = -{ - 0, - ProcInitialConnection, - ProcEstablishConnection -}; +int (*InitialVector[3]) (ClientPtr /* client */ + ) = { +0, ProcInitialConnection, ProcEstablishConnection}; -int (* ProcVector[256]) ( - ClientPtr /* client */ - ) = -{ - ProcBadRequest, - ProcCreateWindow, - ProcChangeWindowAttributes, - ProcGetWindowAttributes, - ProcDestroyWindow, - ProcDestroySubwindows, /* 5 */ - ProcChangeSaveSet, - ProcReparentWindow, - ProcMapWindow, - ProcMapSubwindows, - ProcUnmapWindow, /* 10 */ - ProcUnmapSubwindows, - ProcConfigureWindow, - ProcCirculateWindow, - ProcGetGeometry, - ProcQueryTree, /* 15 */ - ProcInternAtom, - ProcGetAtomName, - ProcChangeProperty, - ProcDeleteProperty, - ProcGetProperty, /* 20 */ - ProcListProperties, - ProcSetSelectionOwner, - ProcGetSelectionOwner, - ProcConvertSelection, - ProcSendEvent, /* 25 */ - ProcGrabPointer, - ProcUngrabPointer, - ProcGrabButton, - ProcUngrabButton, - ProcChangeActivePointerGrab, /* 30 */ - ProcGrabKeyboard, - ProcUngrabKeyboard, - ProcGrabKey, - ProcUngrabKey, - ProcAllowEvents, /* 35 */ - ProcGrabServer, - ProcUngrabServer, - ProcQueryPointer, - ProcGetMotionEvents, - ProcTranslateCoords, /* 40 */ - ProcWarpPointer, - ProcSetInputFocus, - ProcGetInputFocus, - ProcQueryKeymap, - ProcOpenFont, /* 45 */ - ProcCloseFont, - ProcQueryFont, - ProcQueryTextExtents, - ProcListFonts, - ProcListFontsWithInfo, /* 50 */ - ProcSetFontPath, - ProcGetFontPath, - ProcCreatePixmap, - ProcFreePixmap, - ProcCreateGC, /* 55 */ - ProcChangeGC, - ProcCopyGC, - ProcSetDashes, - ProcSetClipRectangles, - ProcFreeGC, /* 60 */ - ProcClearToBackground, - ProcCopyArea, - ProcCopyPlane, - ProcPolyPoint, - ProcPolyLine, /* 65 */ - ProcPolySegment, - ProcPolyRectangle, - ProcPolyArc, - ProcFillPoly, - ProcPolyFillRectangle, /* 70 */ - ProcPolyFillArc, - ProcPutImage, - ProcGetImage, - ProcPolyText, - ProcPolyText, /* 75 */ - ProcImageText8, - ProcImageText16, - ProcCreateColormap, - ProcFreeColormap, - ProcCopyColormapAndFree, /* 80 */ - ProcInstallColormap, - ProcUninstallColormap, - ProcListInstalledColormaps, - ProcAllocColor, - ProcAllocNamedColor, /* 85 */ - ProcAllocColorCells, - ProcAllocColorPlanes, - ProcFreeColors, - ProcStoreColors, - ProcStoreNamedColor, /* 90 */ - ProcQueryColors, - ProcLookupColor, - ProcCreateCursor, - ProcCreateGlyphCursor, - ProcFreeCursor, /* 95 */ - ProcRecolorCursor, - ProcQueryBestSize, - ProcQueryExtension, - ProcListExtensions, - ProcChangeKeyboardMapping, /* 100 */ - ProcGetKeyboardMapping, - ProcChangeKeyboardControl, - ProcGetKeyboardControl, - ProcBell, - ProcChangePointerControl, /* 105 */ - ProcGetPointerControl, - ProcSetScreenSaver, - ProcGetScreenSaver, - ProcChangeHosts, - ProcListHosts, /* 110 */ - ProcChangeAccessControl, - ProcChangeCloseDownMode, - ProcKillClient, - ProcRotateProperties, - ProcForceScreenSaver, /* 115 */ - ProcSetPointerMapping, - ProcGetPointerMapping, - ProcSetModifierMapping, - ProcGetModifierMapping, - ProcBadRequest, /* 120 */ - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, /* 125 */ - ProcBadRequest, - ProcNoOperation, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest -}; +int (*ProcVector[256]) (ClientPtr /* client */ + ) = { + ProcBadRequest, ProcCreateWindow, ProcChangeWindowAttributes, ProcGetWindowAttributes, ProcDestroyWindow, ProcDestroySubwindows, /* 5 */ + ProcChangeSaveSet, ProcReparentWindow, ProcMapWindow, ProcMapSubwindows, ProcUnmapWindow, /* 10 */ + ProcUnmapSubwindows, ProcConfigureWindow, ProcCirculateWindow, ProcGetGeometry, ProcQueryTree, /* 15 */ + ProcInternAtom, ProcGetAtomName, ProcChangeProperty, ProcDeleteProperty, ProcGetProperty, /* 20 */ + ProcListProperties, ProcSetSelectionOwner, ProcGetSelectionOwner, ProcConvertSelection, ProcSendEvent, /* 25 */ + ProcGrabPointer, ProcUngrabPointer, ProcGrabButton, ProcUngrabButton, ProcChangeActivePointerGrab, /* 30 */ + ProcGrabKeyboard, ProcUngrabKeyboard, ProcGrabKey, ProcUngrabKey, ProcAllowEvents, /* 35 */ + ProcGrabServer, ProcUngrabServer, ProcQueryPointer, ProcGetMotionEvents, ProcTranslateCoords, /* 40 */ + ProcWarpPointer, ProcSetInputFocus, ProcGetInputFocus, ProcQueryKeymap, ProcOpenFont, /* 45 */ + ProcCloseFont, ProcQueryFont, ProcQueryTextExtents, ProcListFonts, ProcListFontsWithInfo, /* 50 */ + ProcSetFontPath, ProcGetFontPath, ProcCreatePixmap, ProcFreePixmap, ProcCreateGC, /* 55 */ + ProcChangeGC, ProcCopyGC, ProcSetDashes, ProcSetClipRectangles, ProcFreeGC, /* 60 */ + ProcClearToBackground, ProcCopyArea, ProcCopyPlane, ProcPolyPoint, ProcPolyLine, /* 65 */ + ProcPolySegment, ProcPolyRectangle, ProcPolyArc, ProcFillPoly, ProcPolyFillRectangle, /* 70 */ + ProcPolyFillArc, ProcPutImage, ProcGetImage, ProcPolyText, ProcPolyText, /* 75 */ + ProcImageText8, ProcImageText16, ProcCreateColormap, ProcFreeColormap, ProcCopyColormapAndFree, /* 80 */ + ProcInstallColormap, ProcUninstallColormap, ProcListInstalledColormaps, ProcAllocColor, ProcAllocNamedColor, /* 85 */ + ProcAllocColorCells, ProcAllocColorPlanes, ProcFreeColors, ProcStoreColors, ProcStoreNamedColor, /* 90 */ + ProcQueryColors, ProcLookupColor, ProcCreateCursor, ProcCreateGlyphCursor, ProcFreeCursor, /* 95 */ + ProcRecolorCursor, ProcQueryBestSize, ProcQueryExtension, ProcListExtensions, ProcChangeKeyboardMapping, /* 100 */ + ProcGetKeyboardMapping, ProcChangeKeyboardControl, ProcGetKeyboardControl, ProcBell, ProcChangePointerControl, /* 105 */ + ProcGetPointerControl, ProcSetScreenSaver, ProcGetScreenSaver, ProcChangeHosts, ProcListHosts, /* 110 */ + ProcChangeAccessControl, ProcChangeCloseDownMode, ProcKillClient, ProcRotateProperties, ProcForceScreenSaver, /* 115 */ + ProcSetPointerMapping, ProcGetPointerMapping, ProcSetModifierMapping, ProcGetModifierMapping, ProcBadRequest, /* 120 */ + ProcBadRequest, ProcBadRequest, ProcBadRequest, ProcBadRequest, ProcBadRequest, /* 125 */ +ProcBadRequest, + ProcNoOperation, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, ProcBadRequest, ProcBadRequest, ProcBadRequest}; -int (* SwappedProcVector[256]) ( - ClientPtr /* client */ - ) = -{ - ProcBadRequest, - SProcCreateWindow, - SProcChangeWindowAttributes, - SProcResourceReq, /* GetWindowAttributes */ - SProcResourceReq, /* DestroyWindow */ - SProcResourceReq, /* 5 DestroySubwindows */ - SProcResourceReq, /* SProcChangeSaveSet, */ - SProcReparentWindow, - SProcResourceReq, /* MapWindow */ - SProcResourceReq, /* MapSubwindows */ - SProcResourceReq, /* 10 UnmapWindow */ - SProcResourceReq, /* UnmapSubwindows */ - SProcConfigureWindow, - SProcResourceReq, /* SProcCirculateWindow, */ - SProcResourceReq, /* GetGeometry */ - SProcResourceReq, /* 15 QueryTree */ - SProcInternAtom, - SProcResourceReq, /* SProcGetAtomName, */ - SProcChangeProperty, - SProcDeleteProperty, - SProcGetProperty, /* 20 */ - SProcResourceReq, /* SProcListProperties, */ - SProcSetSelectionOwner, - SProcResourceReq, /* SProcGetSelectionOwner, */ - SProcConvertSelection, - SProcSendEvent, /* 25 */ - SProcGrabPointer, - SProcResourceReq, /* SProcUngrabPointer, */ - SProcGrabButton, - SProcUngrabButton, - SProcChangeActivePointerGrab, /* 30 */ - SProcGrabKeyboard, - SProcResourceReq, /* SProcUngrabKeyboard, */ - SProcGrabKey, - SProcUngrabKey, - SProcResourceReq, /* 35 SProcAllowEvents, */ - SProcSimpleReq, /* SProcGrabServer, */ - SProcSimpleReq, /* SProcUngrabServer, */ - SProcResourceReq, /* SProcQueryPointer, */ - SProcGetMotionEvents, - SProcTranslateCoords, /*40 */ - SProcWarpPointer, - SProcSetInputFocus, - SProcSimpleReq, /* SProcGetInputFocus, */ - SProcSimpleReq, /* QueryKeymap, */ - SProcOpenFont, /* 45 */ - SProcResourceReq, /* SProcCloseFont, */ - SProcResourceReq, /* SProcQueryFont, */ - SProcResourceReq, /* SProcQueryTextExtents, */ - SProcListFonts, - SProcListFontsWithInfo, /* 50 */ - SProcSetFontPath, - SProcSimpleReq, /* GetFontPath, */ - SProcCreatePixmap, - SProcResourceReq, /* SProcFreePixmap, */ - SProcCreateGC, /* 55 */ - SProcChangeGC, - SProcCopyGC, - SProcSetDashes, - SProcSetClipRectangles, - SProcResourceReq, /* 60 SProcFreeGC, */ - SProcClearToBackground, - SProcCopyArea, - SProcCopyPlane, - SProcPoly, /* PolyPoint, */ - SProcPoly, /* 65 PolyLine */ - SProcPoly, /* PolySegment, */ - SProcPoly, /* PolyRectangle, */ - SProcPoly, /* PolyArc, */ - SProcFillPoly, - SProcPoly, /* 70 PolyFillRectangle */ - SProcPoly, /* PolyFillArc, */ - SProcPutImage, - SProcGetImage, - SProcPolyText, - SProcPolyText, /* 75 */ - SProcImageText, - SProcImageText, - SProcCreateColormap, - SProcResourceReq, /* SProcFreeColormap, */ - SProcCopyColormapAndFree, /* 80 */ - SProcResourceReq, /* SProcInstallColormap, */ - SProcResourceReq, /* SProcUninstallColormap, */ - SProcResourceReq, /* SProcListInstalledColormaps, */ - SProcAllocColor, - SProcAllocNamedColor, /* 85 */ - SProcAllocColorCells, - SProcAllocColorPlanes, - SProcFreeColors, - SProcStoreColors, - SProcStoreNamedColor, /* 90 */ - SProcQueryColors, - SProcLookupColor, - SProcCreateCursor, - SProcCreateGlyphCursor, - SProcResourceReq, /* 95 SProcFreeCursor, */ - SProcRecolorCursor, - SProcQueryBestSize, - SProcQueryExtension, - SProcSimpleReq, /* ListExtensions, */ - SProcChangeKeyboardMapping, /* 100 */ - SProcSimpleReq, /* GetKeyboardMapping, */ - SProcChangeKeyboardControl, - SProcSimpleReq, /* GetKeyboardControl, */ - SProcSimpleReq, /* Bell, */ - SProcChangePointerControl, /* 105 */ - SProcSimpleReq, /* GetPointerControl, */ - SProcSetScreenSaver, - SProcSimpleReq, /* GetScreenSaver, */ - SProcChangeHosts, - SProcSimpleReq, /* 110 ListHosts, */ - SProcSimpleReq, /* SProcChangeAccessControl, */ - SProcSimpleReq, /* SProcChangeCloseDownMode, */ - SProcResourceReq, /* SProcKillClient, */ - SProcRotateProperties, - SProcSimpleReq, /* 115 ForceScreenSaver */ - SProcSimpleReq, /* SetPointerMapping, */ - SProcSimpleReq, /* GetPointerMapping, */ - SProcSimpleReq, /* SetModifierMapping, */ - SProcSimpleReq, /* GetModifierMapping, */ - ProcBadRequest, /* 120 */ - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, /* 125 */ - ProcBadRequest, - SProcNoOperation, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest, - ProcBadRequest -}; +int (*SwappedProcVector[256]) (ClientPtr /* client */ + ) = { + ProcBadRequest, SProcCreateWindow, SProcChangeWindowAttributes, SProcResourceReq, /* GetWindowAttributes */ + SProcResourceReq, /* DestroyWindow */ + SProcResourceReq, /* 5 DestroySubwindows */ + SProcResourceReq, /* SProcChangeSaveSet, */ + SProcReparentWindow, SProcResourceReq, /* MapWindow */ + SProcResourceReq, /* MapSubwindows */ + SProcResourceReq, /* 10 UnmapWindow */ + SProcResourceReq, /* UnmapSubwindows */ + SProcConfigureWindow, SProcResourceReq, /* SProcCirculateWindow, */ + SProcResourceReq, /* GetGeometry */ + SProcResourceReq, /* 15 QueryTree */ + SProcInternAtom, SProcResourceReq, /* SProcGetAtomName, */ + SProcChangeProperty, SProcDeleteProperty, SProcGetProperty, /* 20 */ + SProcResourceReq, /* SProcListProperties, */ + SProcSetSelectionOwner, SProcResourceReq, /* SProcGetSelectionOwner, */ + SProcConvertSelection, SProcSendEvent, /* 25 */ + SProcGrabPointer, SProcResourceReq, /* SProcUngrabPointer, */ + SProcGrabButton, SProcUngrabButton, SProcChangeActivePointerGrab, /* 30 */ + SProcGrabKeyboard, SProcResourceReq, /* SProcUngrabKeyboard, */ + SProcGrabKey, SProcUngrabKey, SProcResourceReq, /* 35 SProcAllowEvents, */ + SProcSimpleReq, /* SProcGrabServer, */ + SProcSimpleReq, /* SProcUngrabServer, */ + SProcResourceReq, /* SProcQueryPointer, */ + SProcGetMotionEvents, SProcTranslateCoords, /*40 */ + SProcWarpPointer, SProcSetInputFocus, SProcSimpleReq, /* SProcGetInputFocus, */ + SProcSimpleReq, /* QueryKeymap, */ + SProcOpenFont, /* 45 */ + SProcResourceReq, /* SProcCloseFont, */ + SProcResourceReq, /* SProcQueryFont, */ + SProcResourceReq, /* SProcQueryTextExtents, */ + SProcListFonts, SProcListFontsWithInfo, /* 50 */ + SProcSetFontPath, SProcSimpleReq, /* GetFontPath, */ + SProcCreatePixmap, SProcResourceReq, /* SProcFreePixmap, */ + SProcCreateGC, /* 55 */ + SProcChangeGC, SProcCopyGC, SProcSetDashes, SProcSetClipRectangles, SProcResourceReq, /* 60 SProcFreeGC, */ + SProcClearToBackground, SProcCopyArea, SProcCopyPlane, SProcPoly, /* PolyPoint, */ + SProcPoly, /* 65 PolyLine */ + SProcPoly, /* PolySegment, */ + SProcPoly, /* PolyRectangle, */ + SProcPoly, /* PolyArc, */ + SProcFillPoly, SProcPoly, /* 70 PolyFillRectangle */ + SProcPoly, /* PolyFillArc, */ + SProcPutImage, SProcGetImage, SProcPolyText, SProcPolyText, /* 75 */ + SProcImageText, SProcImageText, SProcCreateColormap, SProcResourceReq, /* SProcFreeColormap, */ + SProcCopyColormapAndFree, /* 80 */ + SProcResourceReq, /* SProcInstallColormap, */ + SProcResourceReq, /* SProcUninstallColormap, */ + SProcResourceReq, /* SProcListInstalledColormaps, */ + SProcAllocColor, SProcAllocNamedColor, /* 85 */ + SProcAllocColorCells, SProcAllocColorPlanes, SProcFreeColors, SProcStoreColors, SProcStoreNamedColor, /* 90 */ + SProcQueryColors, SProcLookupColor, SProcCreateCursor, SProcCreateGlyphCursor, SProcResourceReq, /* 95 SProcFreeCursor, */ + SProcRecolorCursor, SProcQueryBestSize, SProcQueryExtension, SProcSimpleReq, /* ListExtensions, */ + SProcChangeKeyboardMapping, /* 100 */ + SProcSimpleReq, /* GetKeyboardMapping, */ + SProcChangeKeyboardControl, SProcSimpleReq, /* GetKeyboardControl, */ + SProcSimpleReq, /* Bell, */ + SProcChangePointerControl, /* 105 */ + SProcSimpleReq, /* GetPointerControl, */ + SProcSetScreenSaver, SProcSimpleReq, /* GetScreenSaver, */ + SProcChangeHosts, SProcSimpleReq, /* 110 ListHosts, */ + SProcSimpleReq, /* SProcChangeAccessControl, */ + SProcSimpleReq, /* SProcChangeCloseDownMode, */ + SProcResourceReq, /* SProcKillClient, */ + SProcRotateProperties, SProcSimpleReq, /* 115 ForceScreenSaver */ + SProcSimpleReq, /* SetPointerMapping, */ + SProcSimpleReq, /* GetPointerMapping, */ + SProcSimpleReq, /* SetModifierMapping, */ + SProcSimpleReq, /* GetModifierMapping, */ + ProcBadRequest, /* 120 */ + ProcBadRequest, ProcBadRequest, ProcBadRequest, ProcBadRequest, ProcBadRequest, /* 125 */ +ProcBadRequest, + SProcNoOperation, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, + ProcBadRequest, ProcBadRequest, ProcBadRequest, ProcBadRequest}; -EventSwapPtr EventSwapVector[MAXEVENTS] = -{ - (EventSwapPtr)SErrorEvent, +EventSwapPtr EventSwapVector[MAXEVENTS] = { + (EventSwapPtr) SErrorEvent, NotImplemented, SKeyButtonPtrEvent, SKeyButtonPtrEvent, SKeyButtonPtrEvent, - SKeyButtonPtrEvent, /* 5 */ + SKeyButtonPtrEvent, /* 5 */ SKeyButtonPtrEvent, SEnterLeaveEvent, SEnterLeaveEvent, SFocusEvent, - SFocusEvent, /* 10 */ + SFocusEvent, /* 10 */ SKeymapNotifyEvent, SExposeEvent, SGraphicsExposureEvent, SNoExposureEvent, - SVisibilityEvent, /* 15 */ + SVisibilityEvent, /* 15 */ SCreateNotifyEvent, SDestroyNotifyEvent, SUnmapNotifyEvent, SMapNotifyEvent, - SMapRequestEvent, /* 20 */ + SMapRequestEvent, /* 20 */ SReparentEvent, SConfigureNotifyEvent, SConfigureRequestEvent, SGravityEvent, - SResizeRequestEvent, /* 25 */ + SResizeRequestEvent, /* 25 */ SCirculateEvent, SCirculateEvent, SPropertyEvent, SSelectionClearEvent, - SSelectionRequestEvent, /* 30 */ + SSelectionRequestEvent, /* 30 */ SSelectionNotifyEvent, SColormapEvent, SClientMessageEvent, @@ -724,137 +548,135 @@ EventSwapPtr EventSwapVector[MAXEVENTS] = NotImplemented }; - -ReplySwapPtr ReplySwapVector[256] = -{ +ReplySwapPtr ReplySwapVector[256] = { ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr)SGetWindowAttributesReply, + (ReplySwapPtr) SGetWindowAttributesReply, ReplyNotSwappd, - ReplyNotSwappd, /* 5 */ + ReplyNotSwappd, /* 5 */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 10 */ + ReplyNotSwappd, /* 10 */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr)SGetGeometryReply, - (ReplySwapPtr)SQueryTreeReply, /* 15 */ - (ReplySwapPtr)SInternAtomReply, - (ReplySwapPtr)SGetAtomNameReply, + (ReplySwapPtr) SGetGeometryReply, + (ReplySwapPtr) SQueryTreeReply, /* 15 */ + (ReplySwapPtr) SInternAtomReply, + (ReplySwapPtr) SGetAtomNameReply, ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr)SGetPropertyReply, /* 20 */ - (ReplySwapPtr)SListPropertiesReply, + (ReplySwapPtr) SGetPropertyReply, /* 20 */ + (ReplySwapPtr) SListPropertiesReply, ReplyNotSwappd, - (ReplySwapPtr)SGetSelectionOwnerReply, + (ReplySwapPtr) SGetSelectionOwnerReply, ReplyNotSwappd, - ReplyNotSwappd, /* 25 */ - (ReplySwapPtr)SGenericReply, /* SGrabPointerReply, */ + ReplyNotSwappd, /* 25 */ + (ReplySwapPtr) SGenericReply, /* SGrabPointerReply, */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 30 */ - (ReplySwapPtr)SGenericReply, /* SGrabKeyboardReply, */ + ReplyNotSwappd, /* 30 */ + (ReplySwapPtr) SGenericReply, /* SGrabKeyboardReply, */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 35 */ + ReplyNotSwappd, /* 35 */ ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr)SQueryPointerReply, - (ReplySwapPtr)SGetMotionEventsReply, - (ReplySwapPtr)STranslateCoordsReply, /* 40 */ + (ReplySwapPtr) SQueryPointerReply, + (ReplySwapPtr) SGetMotionEventsReply, + (ReplySwapPtr) STranslateCoordsReply, /* 40 */ ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr)SGetInputFocusReply, - (ReplySwapPtr)SQueryKeymapReply, - ReplyNotSwappd, /* 45 */ + (ReplySwapPtr) SGetInputFocusReply, + (ReplySwapPtr) SQueryKeymapReply, + ReplyNotSwappd, /* 45 */ ReplyNotSwappd, - (ReplySwapPtr)SQueryFontReply, - (ReplySwapPtr)SQueryTextExtentsReply, - (ReplySwapPtr)SListFontsReply, - (ReplySwapPtr)SListFontsWithInfoReply, /* 50 */ + (ReplySwapPtr) SQueryFontReply, + (ReplySwapPtr) SQueryTextExtentsReply, + (ReplySwapPtr) SListFontsReply, + (ReplySwapPtr) SListFontsWithInfoReply, /* 50 */ ReplyNotSwappd, - (ReplySwapPtr)SGetFontPathReply, + (ReplySwapPtr) SGetFontPathReply, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 55 */ + ReplyNotSwappd, /* 55 */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 60 */ + ReplyNotSwappd, /* 60 */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 65 */ + ReplyNotSwappd, /* 65 */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 70 */ + ReplyNotSwappd, /* 70 */ ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr)SGetImageReply, + (ReplySwapPtr) SGetImageReply, ReplyNotSwappd, - ReplyNotSwappd, /* 75 */ + ReplyNotSwappd, /* 75 */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 80 */ + ReplyNotSwappd, /* 80 */ ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr)SListInstalledColormapsReply, - (ReplySwapPtr)SAllocColorReply, - (ReplySwapPtr)SAllocNamedColorReply, /* 85 */ - (ReplySwapPtr)SAllocColorCellsReply, - (ReplySwapPtr)SAllocColorPlanesReply, + (ReplySwapPtr) SListInstalledColormapsReply, + (ReplySwapPtr) SAllocColorReply, + (ReplySwapPtr) SAllocNamedColorReply, /* 85 */ + (ReplySwapPtr) SAllocColorCellsReply, + (ReplySwapPtr) SAllocColorPlanesReply, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 90 */ - (ReplySwapPtr)SQueryColorsReply, - (ReplySwapPtr)SLookupColorReply, + ReplyNotSwappd, /* 90 */ + (ReplySwapPtr) SQueryColorsReply, + (ReplySwapPtr) SLookupColorReply, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 95 */ + ReplyNotSwappd, /* 95 */ ReplyNotSwappd, - (ReplySwapPtr)SQueryBestSizeReply, - (ReplySwapPtr)SGenericReply, /* SQueryExtensionReply, */ - (ReplySwapPtr)SListExtensionsReply, - ReplyNotSwappd, /* 100 */ - (ReplySwapPtr)SGetKeyboardMappingReply, + (ReplySwapPtr) SQueryBestSizeReply, + (ReplySwapPtr) SGenericReply, /* SQueryExtensionReply, */ + (ReplySwapPtr) SListExtensionsReply, + ReplyNotSwappd, /* 100 */ + (ReplySwapPtr) SGetKeyboardMappingReply, ReplyNotSwappd, - (ReplySwapPtr)SGetKeyboardControlReply, + (ReplySwapPtr) SGetKeyboardControlReply, ReplyNotSwappd, - ReplyNotSwappd, /* 105 */ - (ReplySwapPtr)SGetPointerControlReply, + ReplyNotSwappd, /* 105 */ + (ReplySwapPtr) SGetPointerControlReply, ReplyNotSwappd, - (ReplySwapPtr)SGetScreenSaverReply, + (ReplySwapPtr) SGetScreenSaverReply, ReplyNotSwappd, - (ReplySwapPtr)SListHostsReply, /* 110 */ + (ReplySwapPtr) SListHostsReply, /* 110 */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - ReplyNotSwappd, /* 115 */ - (ReplySwapPtr)SGenericReply, /* SetPointerMapping */ - (ReplySwapPtr)SGetPointerMappingReply, - (ReplySwapPtr)SGenericReply, /* SetModifierMapping */ - (ReplySwapPtr)SGetModifierMappingReply, /* 119 */ - ReplyNotSwappd, /* 120 */ - ReplyNotSwappd, /* 121 */ - ReplyNotSwappd, /* 122 */ - ReplyNotSwappd, /* 123 */ - ReplyNotSwappd, /* 124 */ - ReplyNotSwappd, /* 125 */ - ReplyNotSwappd, /* 126 */ - ReplyNotSwappd, /* NoOperation */ + ReplyNotSwappd, /* 115 */ + (ReplySwapPtr) SGenericReply, /* SetPointerMapping */ + (ReplySwapPtr) SGetPointerMappingReply, + (ReplySwapPtr) SGenericReply, /* SetModifierMapping */ + (ReplySwapPtr) SGetModifierMappingReply, /* 119 */ + ReplyNotSwappd, /* 120 */ + ReplyNotSwappd, /* 121 */ + ReplyNotSwappd, /* 122 */ + ReplyNotSwappd, /* 123 */ + ReplyNotSwappd, /* 124 */ + ReplyNotSwappd, /* 125 */ + ReplyNotSwappd, /* 126 */ + ReplyNotSwappd, /* NoOperation */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, diff --git a/xorg-server/dix/touch.c b/xorg-server/dix/touch.c index d04801c86..0829b6545 100644 --- a/xorg-server/dix/touch.c +++ b/xorg-server/dix/touch.c @@ -42,9 +42,8 @@ #define TOUCH_HISTORY_SIZE 100 - /* If a touch queue resize is needed, the device id's bit is set. */ -static unsigned char resize_waiting[(MAXDEVICES + 7)/8]; +static unsigned char resize_waiting[(MAXDEVICES + 7) / 8]; /** * Some documentation about touch points: @@ -83,8 +82,7 @@ TouchResizeQueue(ClientPtr client, pointer closure) OsBlockSignals(); /* first two ids are reserved */ - for (i = 2; i < MAXDEVICES; i++) - { + for (i = 2; i < MAXDEVICES; i++) { DeviceIntPtr dev; DDXTouchPointInfoPtr tmp; size_t size; @@ -101,12 +99,12 @@ TouchResizeQueue(ClientPtr client, pointer closure) /* Need to grow the queue means dropping events. Grow sufficiently so we * don't need to do it often */ - size = dev->last.num_touches + dev->last.num_touches/2 + 1; + size = dev->last.num_touches + dev->last.num_touches / 2 + 1; - tmp = realloc(dev->last.touches, size * sizeof(*dev->last.touches)); - if (tmp) - { + tmp = realloc(dev->last.touches, size * sizeof(*dev->last.touches)); + if (tmp) { int i; + dev->last.touches = tmp; for (i = dev->last.num_touches; i < size; i++) TouchInitDDXTouchPoint(dev, &dev->last.touches[i]); @@ -136,8 +134,7 @@ TouchFindByDDXID(DeviceIntPtr dev, uint32_t ddx_id, Bool create) if (!dev->touch) return NULL; - for (i = 0; i < dev->last.num_touches; i++) - { + for (i = 0; i < dev->last.num_touches; i++) { ti = &dev->last.touches[i]; if (ti->active && ti->ddx_id == ddx_id) return ti; @@ -173,21 +170,20 @@ TouchBeginDDXTouch(DeviceIntPtr dev, uint32_t ddx_id) if (TouchFindByDDXID(dev, ddx_id, FALSE)) return NULL; - for (i = 0; i < dev->last.num_touches; i++) - { + for (i = 0; i < dev->last.num_touches; i++) { /* Only emulate pointer events on the first touch */ if (dev->last.touches[i].active) emulate_pointer = FALSE; - else if (!ti) /* ti is now first non-active touch rec */ + else if (!ti) /* ti is now first non-active touch rec */ ti = &dev->last.touches[i]; if (!emulate_pointer && ti) break; } - if (ti) - { + if (ti) { int client_id; + ti->active = TRUE; ti->ddx_id = ddx_id; client_id = next_client_id; @@ -230,7 +226,6 @@ TouchInitDDXTouchPoint(DeviceIntPtr dev, DDXTouchPointInfoPtr ddxtouch) ddxtouch->valuators = valuator_mask_new(dev->valuator->numAxes); } - Bool TouchInitTouchPoint(TouchClassPtr t, ValuatorClassPtr v, int index) { @@ -247,8 +242,7 @@ TouchInitTouchPoint(TouchClassPtr t, ValuatorClassPtr v, int index) return FALSE; ti->sprite.spriteTrace = calloc(32, sizeof(*ti->sprite.spriteTrace)); - if (!ti->sprite.spriteTrace) - { + if (!ti->sprite.spriteTrace) { valuator_mask_free(&ti->valuators); return FALSE; } @@ -299,8 +293,7 @@ TouchFindByClientID(DeviceIntPtr dev, uint32_t client_id) if (!t) return NULL; - for (i = 0; i < t->num_touches; i++) - { + for (i = 0; i < t->num_touches; i++) { ti = &t->touches[i]; if (ti->active && ti->client_id == client_id) return ti; @@ -309,7 +302,6 @@ TouchFindByClientID(DeviceIntPtr dev, uint32_t client_id) return NULL; } - /** * Given a unique ID for a touchpoint, create a touchpoint record in the * server. @@ -337,9 +329,8 @@ TouchBeginTouch(DeviceIntPtr dev, int sourceid, uint32_t touchid, if (TouchFindByClientID(dev, touchid)) return NULL; -try_find_touch: - for (i = 0; i < t->num_touches; i++) - { + try_find_touch: + for (i = 0; i < t->num_touches; i++) { ti = &t->touches[i]; if (!ti->active) { ti->active = TRUE; @@ -353,8 +344,7 @@ try_find_touch: /* If we get here, then we've run out of touches: enlarge dev->touch and * try again. */ tmp = realloc(t->touches, (t->num_touches + 1) * sizeof(*ti)); - if (tmp) - { + if (tmp) { t->touches = tmp; t->num_touches++; if (TouchInitTouchPoint(t, dev->valuator, t->num_touches - 1)) @@ -372,24 +362,22 @@ try_find_touch: void TouchEndTouch(DeviceIntPtr dev, TouchPointInfoPtr ti) { - if (ti->emulate_pointer) - { + if (ti->emulate_pointer) { GrabPtr grab; DeviceEvent ev; + memset(&ev, 0, sizeof(ev)); ev.type = ET_TouchEnd; ev.detail.button = 1; ev.touchid = ti->client_id; - ev.flags = TOUCH_POINTER_EMULATED|TOUCH_END; + ev.flags = TOUCH_POINTER_EMULATED | TOUCH_END; UpdateDeviceState(dev, &ev); - if ((grab = dev->deviceGrab.grab)) - { + if ((grab = dev->deviceGrab.grab)) { if (dev->deviceGrab.fromPassiveGrab && !dev->button->buttonsDown && - !dev->touch->buttonsDown && - GrabIsPointerGrab(grab)) - (*dev->deviceGrab.DeactivateGrab)(dev); + !dev->touch->buttonsDown && GrabIsPointerGrab(grab)) + (*dev->deviceGrab.DeactivateGrab) (dev); } } @@ -450,32 +438,30 @@ TouchEventHistoryPush(TouchPointInfoPtr ti, const DeviceEvent *ev) if (!ti->history) return; - switch(ev->type) - { - case ET_TouchBegin: - /* don't store the same touchbegin twice */ - if (ti->history_elements > 0) - return; - break; - case ET_TouchUpdate: - break; - case ET_TouchEnd: - return; /* no TouchEnd events in the history */ - default: + switch (ev->type) { + case ET_TouchBegin: + /* don't store the same touchbegin twice */ + if (ti->history_elements > 0) return; + break; + case ET_TouchUpdate: + break; + case ET_TouchEnd: + return; /* no TouchEnd events in the history */ + default: + return; } /* We only store real events in the history */ - if (ev->flags & (TOUCH_CLIENT_ID|TOUCH_REPLAYING)) + if (ev->flags & (TOUCH_CLIENT_ID | TOUCH_REPLAYING)) return; ti->history[ti->history_elements++] = *ev; /* FIXME: proper overflow fixes */ - if (ti->history_elements > ti->history_size - 1) - { + if (ti->history_elements > ti->history_size - 1) { ti->history_elements = ti->history_size - 1; DebugF("source device %d: history size %d overflowing for touch %u\n", - ti->sourceid, ti->history_size, ti->client_id); + ti->sourceid, ti->history_size, ti->client_id); } } @@ -493,7 +479,7 @@ TouchEventHistoryReplay(TouchPointInfoPtr ti, DeviceIntPtr dev, XID resource) valuator_mask_set_double(mask, 0, ti->history[0].valuators.data[0]); valuator_mask_set_double(mask, 1, ti->history[0].valuators.data[1]); - flags = TOUCH_CLIENT_ID|TOUCH_REPLAYING; + flags = TOUCH_CLIENT_ID | TOUCH_REPLAYING; if (ti->emulate_pointer) flags |= TOUCH_POINTER_EMULATED; /* send fake begin event to next owner */ @@ -505,11 +491,11 @@ TouchEventHistoryReplay(TouchPointInfoPtr ti, DeviceIntPtr dev, XID resource) FreeEventList(tel, GetMaximumEventsNum()); /* First event was TouchBegin, already replayed that one */ - for (i = 1; i < ti->history_elements; i++) - { + for (i = 1; i < ti->history_elements; i++) { DeviceEvent *ev = &ti->history[i]; + ev->flags |= TOUCH_REPLAYING; - DeliverTouchEvents(dev, ti, (InternalEvent*)ev, resource); + DeliverTouchEvents(dev, ti, (InternalEvent *) ev, resource); } } @@ -524,7 +510,8 @@ TouchBuildDependentSpriteTrace(DeviceIntPtr dev, SpritePtr sprite) /* All touches should have the same sprite trace, so find and reuse an * existing touch's sprite if possible, else use the device's sprite. */ for (i = 0; i < t->num_touches; i++) - if (t->touches[i].sprite.spriteTraceGood > 0) + if (!t->touches[i].pending_finish && + t->touches[i].sprite.spriteTraceGood > 0) break; if (i < t->num_touches) srcsprite = &t->touches[i].sprite; @@ -533,12 +520,10 @@ TouchBuildDependentSpriteTrace(DeviceIntPtr dev, SpritePtr sprite) else return FALSE; - if (srcsprite->spriteTraceGood > sprite->spriteTraceSize) - { + if (srcsprite->spriteTraceGood > sprite->spriteTraceSize) { trace = realloc(sprite->spriteTrace, - srcsprite->spriteTraceSize * sizeof(*trace)); - if (!trace) - { + srcsprite->spriteTraceSize * sizeof(*trace)); + if (!trace) { sprite->spriteTraceGood = 0; return FALSE; } @@ -546,7 +531,7 @@ TouchBuildDependentSpriteTrace(DeviceIntPtr dev, SpritePtr sprite) sprite->spriteTraceSize = srcsprite->spriteTraceGood; } memcpy(sprite->spriteTrace, srcsprite->spriteTrace, - srcsprite->spriteTraceGood * sizeof(*trace)); + srcsprite->spriteTraceGood * sizeof(*trace)); sprite->spriteTraceGood = srcsprite->spriteTraceGood; return TRUE; @@ -573,8 +558,7 @@ TouchEnsureSprite(DeviceIntPtr sourcedev, TouchPointInfoPtr ti, else if (ev->any.type != ET_TouchBegin) return (sprite->spriteTraceGood > 0); - if (t->mode == XIDirectTouch) - { + if (t->mode == XIDirectTouch) { /* Focus immediately under the touchpoint in direct touch mode. * XXX: Do we need to handle crossing screens here? */ sprite->spriteTrace[0] = @@ -590,8 +574,7 @@ TouchEnsureSprite(DeviceIntPtr sourcedev, TouchPointInfoPtr ti, /* Mark which grabs/event selections we're delivering to: max one grab per * window plus the bottom-most event selection. */ ti->listeners = calloc(sprite->spriteTraceGood + 1, sizeof(*ti->listeners)); - if (!ti->listeners) - { + if (!ti->listeners) { sprite->spriteTraceGood = 0; return FALSE; } @@ -624,22 +607,21 @@ TouchConvertToPointerEvent(const InternalEvent *event, BUG_WARN(!event); BUG_WARN(!motion_event); - switch(event->any.type) - { - case ET_TouchUpdate: - nevents = 1; - break; - case ET_TouchBegin: - nevents = 2; /* motion + press */ - ptrtype = ET_ButtonPress; - break; - case ET_TouchEnd: - nevents = 2; /* motion + release */ - ptrtype = ET_ButtonRelease; - break; - default: - BUG_WARN_MSG(1,"Invalid event type %d\n", event->any.type); - return 0; + switch (event->any.type) { + case ET_TouchUpdate: + nevents = 1; + break; + case ET_TouchBegin: + nevents = 2; /* motion + press */ + ptrtype = ET_ButtonPress; + break; + case ET_TouchEnd: + nevents = 2; /* motion + release */ + ptrtype = ET_ButtonRelease; + break; + default: + BUG_WARN_MSG(1, "Invalid event type %d\n", event->any.type); + return 0; } BUG_WARN_MSG(!(event->device_event.flags & TOUCH_POINTER_EMULATED), @@ -650,8 +632,7 @@ TouchConvertToPointerEvent(const InternalEvent *event, motion_event->device_event.detail.button = 0; motion_event->device_event.flags = XIPointerEmulated; - if (nevents > 1) - { + if (nevents > 1) { BUG_WARN(!button_event); *button_event = *event; button_event->any.type = ptrtype; @@ -671,18 +652,22 @@ TouchGetPointerEventType(const InternalEvent *event) { int type = 0; - switch(event->any.type) - { - case ET_TouchBegin: type = ET_ButtonPress; break; - case ET_TouchUpdate: type = ET_Motion; break; - case ET_TouchEnd: type = ET_ButtonRelease; break; - default: - break; + switch (event->any.type) { + case ET_TouchBegin: + type = ET_ButtonPress; + break; + case ET_TouchUpdate: + type = ET_Motion; + break; + case ET_TouchEnd: + type = ET_ButtonRelease; + break; + default: + break; } return type; } - /** * @returns TRUE if the specified grab or selection is the current owner of * the touch sequence. @@ -719,12 +704,12 @@ Bool TouchRemoveListener(TouchPointInfoPtr ti, XID resource) { int i; - for (i = 0; i < ti->num_listeners; i++) - { - if (ti->listeners[i].listener == resource) - { + + for (i = 0; i < ti->num_listeners; i++) { + if (ti->listeners[i].listener == resource) { int j; - for (j = i; j< ti->num_listeners - 1; j++) + + for (j = i; j < ti->num_listeners - 1; j++) ti->listeners[j] = ti->listeners[j + 1]; ti->num_listeners--; ti->listeners[ti->num_listeners].listener = 0; @@ -743,14 +728,13 @@ TouchAddGrabListener(DeviceIntPtr dev, TouchPointInfoPtr ti, /* FIXME: owner_events */ - if (grab->grabtype == XI2) - { + if (grab->grabtype == XI2) { if (!xi2mask_isset(grab->xi2mask, dev, XI_TouchOwnership)) TouchEventHistoryAllocate(ti); if (!xi2mask_isset(grab->xi2mask, dev, XI_TouchBegin)) type = LISTENER_POINTER_GRAB; - } else if (grab->grabtype == XI || grab->grabtype == CORE) - { + } + else if (grab->grabtype == XI || grab->grabtype == CORE) { TouchEventHistoryAllocate(ti); type = LISTENER_POINTER_GRAB; } @@ -784,7 +768,7 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti, { InputClients *iclients = NULL; OtherInputMasks *inputMasks = NULL; - uint16_t evtype = 0; /* may be event type or emulated event type */ + uint16_t evtype = 0; /* may be event type or emulated event type */ enum TouchListenerType type = LISTENER_REGULAR; int mask; @@ -792,11 +776,9 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti, mask = EventIsDeliverable(dev, ev->any.type, win); if (!mask && !ti->emulate_pointer) return FALSE; - else if (!mask)/* now try for pointer event */ - { + else if (!mask) { /* now try for pointer event */ mask = EventIsDeliverable(dev, TouchGetPointerEventType(ev), win); - if (mask) - { + if (mask) { evtype = GetXI2Type(TouchGetPointerEventType(ev)); type = LISTENER_POINTER_REGULAR; } @@ -806,10 +788,8 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti, inputMasks = wOtherInputMasks(win); - if (mask & EVENT_XI2_MASK) - { - nt_list_for_each_entry(iclients, inputMasks->inputClients, next) - { + if (mask & EVENT_XI2_MASK) { + nt_list_for_each_entry(iclients, inputMasks->inputClients, next) { if (!xi2mask_isset(iclients->xi2mask, dev, evtype)) continue; @@ -822,12 +802,11 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti, } } - if (mask & EVENT_XI1_MASK) - { + if (mask & EVENT_XI1_MASK) { int xitype = GetXIType(TouchGetPointerEventType(ev)); Mask xi_filter = event_get_filter_from_type(dev, xitype); - nt_list_for_each_entry(iclients, inputMasks->inputClients, next) - { + + nt_list_for_each_entry(iclients, inputMasks->inputClients, next) { if (!(iclients->mask[dev->id] & xi_filter)) continue; @@ -839,14 +818,12 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti, } } - if (mask & EVENT_CORE_MASK) - { + if (mask & EVENT_CORE_MASK) { int coretype = GetCoreType(TouchGetPointerEventType(ev)); Mask core_filter = event_get_filter_from_type(dev, coretype); /* window owner */ - if (IsMaster(dev) && (win->eventMask & core_filter)) - { + if (IsMaster(dev) && (win->eventMask & core_filter)) { TouchEventHistoryAllocate(ti); TouchAddListener(ti, win->drawable.id, CORE, LISTENER_POINTER_REGULAR, LISTENER_AWAITING_BEGIN, @@ -855,8 +832,8 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti, } /* all others */ - nt_list_for_each_entry(iclients, (InputClients*)wOtherClients(win), next) - { + nt_list_for_each_entry(iclients, (InputClients *) wOtherClients(win), + next) { if (!(iclients->mask[XIAllDevices] & core_filter)) continue; @@ -880,7 +857,8 @@ TouchAddActiveGrabListener(DeviceIntPtr dev, TouchPointInfoPtr ti, if (!ti->emulate_pointer && grab->grabtype == XI2 && - (grab->type != XI_TouchBegin && grab->type != XI_TouchEnd && grab->type != XI_TouchUpdate)) + (grab->type != XI_TouchBegin && grab->type != XI_TouchEnd && + grab->type != XI_TouchUpdate)) return; TouchAddGrabListener(dev, ti, ev, grab); @@ -898,16 +876,14 @@ TouchSetupListeners(DeviceIntPtr dev, TouchPointInfoPtr ti, InternalEvent *ev) /* First, find all grabbing clients from the root window down * to the deepest child window. */ - for (i = 0; i < sprite->spriteTraceGood; i++) - { + for (i = 0; i < sprite->spriteTraceGood; i++) { win = sprite->spriteTrace[i]; TouchAddPassiveGrabListener(dev, ti, win, ev); } /* Find the first client with an applicable event selection, * going from deepest child window back up to the root window. */ - for (i = sprite->spriteTraceGood - 1; i >= 0; i--) - { + for (i = sprite->spriteTraceGood - 1; i >= 0; i--) { Bool delivered; win = sprite->spriteTrace[i]; @@ -935,7 +911,7 @@ TouchRemovePointerGrab(DeviceIntPtr dev) return; ev = dev->deviceGrab.sync.event; - if (!IsTouchEvent((InternalEvent*)ev)) + if (!IsTouchEvent((InternalEvent *) ev)) return; ti = TouchFindByClientID(dev, ev->touchid); @@ -957,19 +933,16 @@ TouchListenerGone(XID resource) if (!events) FatalError("TouchListenerGone: couldn't allocate events\n"); - for (dev = inputInfo.devices; dev; dev = dev->next) - { + for (dev = inputInfo.devices; dev; dev = dev->next) { if (!dev->touch) continue; - for (i = 0; i < dev->touch->num_touches; i++) - { + for (i = 0; i < dev->touch->num_touches; i++) { ti = &dev->touch->touches[i]; if (!ti->active) continue; - for (j = 0; j < ti->num_listeners; j++) - { + for (j = 0; j < ti->num_listeners; j++) { if (ti->listeners[j].listener != resource) continue; @@ -997,21 +970,18 @@ TouchAcceptReject(ClientPtr client, DeviceIntPtr dev, int mode, if (!events) return BadAlloc; - if (!dev->touch) - { + if (!dev->touch) { *error = dev->id; return BadDevice; } ti = TouchFindByClientID(dev, touchid); - if (!ti) - { + if (!ti) { *error = touchid; return BadValue; } - for (i = 0; i < ti->num_listeners; i++) - { + for (i = 0; i < ti->num_listeners; i++) { if (CLIENT_ID(ti->listeners[i].listener) == client->index && ti->listeners[i].window->drawable.id == grab_window) break; @@ -1019,8 +989,7 @@ TouchAcceptReject(ClientPtr client, DeviceIntPtr dev, int mode, if (i == ti->num_listeners) return BadAccess; - if (i > 0) - { + if (i > 0) { if (mode == XIRejectTouch) TouchRejected(dev, ti, ti->listeners[i].listener, NULL); else diff --git a/xorg-server/dix/window.c b/xorg-server/dix/window.c index 823294b9a..98f5604c9 100644 --- a/xorg-server/dix/window.c +++ b/xorg-server/dix/window.c @@ -45,7 +45,6 @@ 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 @@ -97,7 +96,6 @@ Equipment Corporation. ******************************************************************/ - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #endif @@ -124,7 +122,7 @@ Equipment Corporation. #endif #include "dixevents.h" #include "globals.h" -#include "mi.h" /* miPaintWindow */ +#include "mi.h" /* miPaintWindow */ #ifdef COMPOSITE #include "compint.h" #endif @@ -133,7 +131,7 @@ Equipment Corporation. #include "xace.h" #include "exevents.h" -#include <X11/Xatom.h> /* must come after server includes */ +#include <X11/Xatom.h> /* must come after server includes */ /****** * Window stuff for server @@ -147,17 +145,16 @@ Equipment Corporation. Bool bgNoneRoot = FALSE; -static unsigned char _back_lsb[4] = {0x88, 0x22, 0x44, 0x11}; -static unsigned char _back_msb[4] = {0x11, 0x44, 0x22, 0x88}; +static unsigned char _back_lsb[4] = { 0x88, 0x22, 0x44, 0x11 }; +static unsigned char _back_msb[4] = { 0x11, 0x44, 0x22, 0x88 }; + +static Bool WindowParentHasDeviceCursor(WindowPtr pWin, + DeviceIntPtr pDev, CursorPtr pCurs); +static Bool -static Bool WindowParentHasDeviceCursor(WindowPtr pWin, - DeviceIntPtr pDev, - CursorPtr pCurs); -static Bool -WindowSeekDeviceCursor(WindowPtr pWin, - DeviceIntPtr pDev, - DevCursNodePtr* pNode, - DevCursNodePtr* pPrev); +WindowSeekDeviceCursor(WindowPtr pWin, + DeviceIntPtr pDev, + DevCursNodePtr * pNode, DevCursNodePtr * pPrev); int screenIsSaved = SCREEN_SAVER_OFF; @@ -194,6 +191,7 @@ get_window_name(WindowPtr pWin) PropertyPtr prop; static char buf[WINDOW_NAME_BUF_LEN]; int len; + #ifdef COMPOSITE CompScreenPtr comp_screen = GetCompScreen(pWin->drawable.pScreen); @@ -201,11 +199,9 @@ get_window_name(WindowPtr pWin) return overlay_win_name; #endif - for (prop = wUserProps(pWin); prop; prop = prop->next) - { + for (prop = wUserProps(pWin); prop; prop = prop->next) { if (prop->propertyName == XA_WM_NAME && prop->type == XA_STRING && - prop->data) - { + prop->data) { len = min(prop->size, WINDOW_NAME_BUF_LEN - 1); memcpy(buf, prop->data, len); buf[len] = '\0'; @@ -217,7 +213,8 @@ get_window_name(WindowPtr pWin) #undef WINDOW_NAME_BUF_LEN } -static void log_window_info(WindowPtr pWin, int depth) +static void +log_window_info(WindowPtr pWin, int depth) { int i; const char *win_name, *visibility; @@ -241,35 +238,32 @@ static void log_window_info(WindowPtr pWin, int depth) if (pWin->redirectDraw) ErrorF(" (%s compositing: pixmap %x)", (pWin->redirectDraw == RedirectDrawAutomatic) ? - "automatic" : "manual", + "automatic" : "manual", pScreen->GetWindowPixmap(pWin)->drawable.id); #endif - switch (pWin->visibility) - { + switch (pWin->visibility) { case VisibilityUnobscured: - visibility = "unobscured"; - break; + visibility = "unobscured"; + break; case VisibilityPartiallyObscured: - visibility = "partially obscured"; - break; + visibility = "partially obscured"; + break; case VisibilityFullyObscured: - visibility = "fully obscured"; - break; + visibility = "fully obscured"; + break; case VisibilityNotViewable: - visibility = "unviewable"; - break; + visibility = "unviewable"; + break; } ErrorF(", %s", visibility); - if (REGION_NOTEMPTY(pScreen, &pWin->clipList)) - { + if (REGION_NOTEMPTY(pScreen, &pWin->clipList)) { ErrorF(", clip list:"); rects = REGION_RECTS(&pWin->clipList); for (i = 0; i < REGION_NUM_RECTS(&pWin->clipList); i++) ErrorF(" [(%d, %d) to (%d, %d)]", - rects[i].x1, rects[i].y1, - rects[i].x2, rects[i].y2); + rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2); ErrorF("; extents [(%d, %d) to (%d, %d)]", pWin->clipList.extents.x1, pWin->clipList.extents.y1, pWin->clipList.extents.x2, pWin->clipList.extents.y2); @@ -285,31 +279,27 @@ PrintWindowTree(void) ScreenPtr pScreen; WindowPtr pWin; - for (scrnum = 0; scrnum < screenInfo.numScreens; scrnum++) - { + for (scrnum = 0; scrnum < screenInfo.numScreens; scrnum++) { pScreen = screenInfo.screens[scrnum]; ErrorF("[dix] Dumping windows for screen %d (pixmap %x):\n", scrnum, pScreen->GetScreenPixmap(pScreen)->drawable.id); pWin = pScreen->root; depth = 1; - while (pWin) - { + while (pWin) { log_window_info(pWin, depth); - if (pWin->firstChild) - { + if (pWin->firstChild) { pWin = pWin->firstChild; depth++; continue; } - while (pWin && !pWin->nextSib) - { + while (pWin && !pWin->nextSib) { pWin = pWin->parent; depth--; } if (!pWin) break; pWin = pWin->nextSib; - } + } } } @@ -320,22 +310,20 @@ TraverseTree(WindowPtr pWin, VisitWindowProcPtr func, pointer data) WindowPtr pChild; if (!(pChild = pWin)) - return WT_NOMATCH; - while (1) - { - result = (* func)(pChild, data); - if (result == WT_STOPWALKING) - return WT_STOPWALKING; - if ((result == WT_WALKCHILDREN) && pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - break; - pChild = pChild->nextSib; + return WT_NOMATCH; + while (1) { + result = (*func) (pChild, data); + if (result == WT_STOPWALKING) + return WT_STOPWALKING; + if ((result == WT_WALKCHILDREN) && pChild->firstChild) { + pChild = pChild->firstChild; + continue; + } + while (!pChild->nextSib && (pChild != pWin)) + pChild = pChild->parent; + if (pChild == pWin) + break; + pChild = pChild->nextSib; } return WT_NOMATCH; } @@ -351,14 +339,15 @@ TraverseTree(WindowPtr pWin, VisitWindowProcPtr func, pointer data) int WalkTree(ScreenPtr pScreen, VisitWindowProcPtr func, pointer data) { - return(TraverseTree(pScreen->root, func, data)); + return (TraverseTree(pScreen->root, func, data)); } /* hack for forcing backing store on all windows */ -int defaultBackingStore = NotUseful; +int defaultBackingStore = NotUseful; + /* hack to force no backing store */ -Bool disableBackingStore = FALSE; -Bool enableBackingStore = FALSE; +Bool disableBackingStore = FALSE; +Bool enableBackingStore = FALSE; static void SetWindowToDefaults(WindowPtr pWin) @@ -367,16 +356,16 @@ SetWindowToDefaults(WindowPtr pWin) pWin->firstChild = NullWindow; pWin->lastChild = NullWindow; - pWin->valdata = (ValidatePtr)NULL; - pWin->optional = (WindowOptPtr)NULL; + pWin->valdata = (ValidatePtr) NULL; + pWin->optional = (WindowOptPtr) NULL; pWin->cursorIsNone = TRUE; pWin->backingStore = NotUseful; pWin->DIXsaveUnder = FALSE; pWin->backStorage = (pointer) NULL; - pWin->mapped = FALSE; /* off */ - pWin->realized = FALSE; /* off */ + pWin->mapped = FALSE; /* off */ + pWin->realized = FALSE; /* off */ pWin->viewable = FALSE; pWin->visibility = VisibilityNotViewable; pWin->overrideRedirect = FALSE; @@ -411,36 +400,37 @@ MakeRootTile(WindowPtr pWin) unsigned char *from, *to; int i, j; - pWin->background.pixmap = (*pScreen->CreatePixmap)(pScreen, 4, 4, - pScreen->rootDepth, 0); + pWin->background.pixmap = (*pScreen->CreatePixmap) (pScreen, 4, 4, + pScreen->rootDepth, 0); pWin->backgroundState = BackgroundPixmap; pGC = GetScratchGC(pScreen->rootDepth, pScreen); if (!pWin->background.pixmap || !pGC) - FatalError("could not create root tile"); + FatalError("could not create root tile"); { - ChangeGCVal attributes[2]; + ChangeGCVal attributes[2]; - attributes[0].val = pScreen->whitePixel; - attributes[1].val = pScreen->blackPixel; + attributes[0].val = pScreen->whitePixel; + attributes[1].val = pScreen->blackPixel; - (void)ChangeGC(NullClient, pGC, GCForeground | GCBackground, attributes); + (void) ChangeGC(NullClient, pGC, GCForeground | GCBackground, + attributes); } - ValidateGC((DrawablePtr)pWin->background.pixmap, pGC); + ValidateGC((DrawablePtr) pWin->background.pixmap, pGC); - from = (screenInfo.bitmapBitOrder == LSBFirst) ? _back_lsb : _back_msb; - to = back; + from = (screenInfo.bitmapBitOrder == LSBFirst) ? _back_lsb : _back_msb; + to = back; - for (i = 4; i > 0; i--, from++) - for (j = len; j > 0; j--) - *to++ = *from; + for (i = 4; i > 0; i--, from++) + for (j = len; j > 0; j--) + *to++ = *from; - (*pGC->ops->PutImage)((DrawablePtr)pWin->background.pixmap, pGC, 1, - 0, 0, len, 4, 0, XYBitmap, (char *)back); + (*pGC->ops->PutImage) ((DrawablePtr) pWin->background.pixmap, pGC, 1, + 0, 0, len, 4, 0, XYBitmap, (char *) back); - FreeScratchGC(pGC); + FreeScratchGC(pGC); } @@ -452,13 +442,13 @@ MakeRootTile(WindowPtr pWin) Bool CreateRootWindow(ScreenPtr pScreen) { - WindowPtr pWin; - BoxRec box; + WindowPtr pWin; + BoxRec box; PixmapFormatRec *format; pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW); if (!pWin) - return FALSE; + return FALSE; pScreen->screensaver.pWindow = NULL; pScreen->screensaver.wid = FakeClientID(0); @@ -472,9 +462,7 @@ CreateRootWindow(ScreenPtr pScreen) pWin->drawable.depth = pScreen->rootDepth; for (format = screenInfo.formats; - format->depth != pScreen->rootDepth; - format++) - ; + format->depth != pScreen->rootDepth; format++); pWin->drawable.bitsPerPixel = format->bitsPerPixel; pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; @@ -482,7 +470,7 @@ CreateRootWindow(ScreenPtr pScreen) pWin->parent = NullWindow; SetWindowToDefaults(pWin); - pWin->optional = malloc(sizeof (WindowOptRec)); + pWin->optional = malloc(sizeof(WindowOptRec)); if (!pWin->optional) return FALSE; @@ -532,16 +520,16 @@ CreateRootWindow(ScreenPtr pScreen) /* security creation/labeling check */ if (XaceHook(XACE_RESOURCE_ACCESS, serverClient, pWin->drawable.id, - RT_WINDOW, pWin, RT_NONE, NULL, DixCreateAccess)) - return FALSE; + RT_WINDOW, pWin, RT_NONE, NULL, DixCreateAccess)) + return FALSE; - if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin)) - return FALSE; + if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer) pWin)) + return FALSE; if (disableBackingStore) - pScreen->backingStoreSupport = NotUseful; + pScreen->backingStoreSupport = NotUseful; if (enableBackingStore) - pScreen->backingStoreSupport = Always; + pScreen->backingStoreSupport = Always; pScreen->saveUnderSupport = NotUseful; @@ -554,35 +542,36 @@ InitRootWindow(WindowPtr pWin) ScreenPtr pScreen = pWin->drawable.pScreen; int backFlag = CWBorderPixel | CWCursor | CWBackingStore; - if (!(*pScreen->CreateWindow)(pWin)) - return; /* XXX */ - (*pScreen->PositionWindow)(pWin, 0, 0); + if (!(*pScreen->CreateWindow) (pWin)) + return; /* XXX */ + (*pScreen->PositionWindow) (pWin, 0, 0); pWin->cursorIsNone = FALSE; pWin->optional->cursor = rootCursor; rootCursor->refcnt++; - if (party_like_its_1989) { MakeRootTile(pWin); backFlag |= CWBackPixmap; - } else if (pScreen->canDoBGNoneRoot && bgNoneRoot) { + } + else if (pScreen->canDoBGNoneRoot && bgNoneRoot) { pWin->backgroundState = XaceBackgroundNoneState(pWin); pWin->background.pixel = pScreen->whitePixel; backFlag |= CWBackPixmap; - } else { + } + else { pWin->backgroundState = BackgroundPixel; - if (whiteRoot) + if (whiteRoot) pWin->background.pixel = pScreen->whitePixel; else pWin->background.pixel = pScreen->blackPixel; backFlag |= CWBackPixel; - } + } pWin->backingStore = defaultBackingStore; pWin->forcedBS = (defaultBackingStore != NotUseful); /* We SHOULD check for an error value here XXX */ - (*pScreen->ChangeWindowAttributes)(pWin, backFlag); + (*pScreen->ChangeWindowAttributes) (pWin, backFlag); MapWindow(pWin, serverClient); } @@ -593,27 +582,25 @@ InitRootWindow(WindowPtr pWin) */ static void -ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn, - int x, int y, - int w, int h) +ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn, int x, int y, int w, int h) { BoxRec box = *RegionExtents(&pWin->winSize); /* we do these calculations to avoid overflows */ if (x > box.x1) - box.x1 = x; + box.x1 = x; if (y > box.y1) - box.y1 = y; + box.y1 = y; x += w; if (x < box.x2) - box.x2 = x; + box.x2 = x; y += h; if (y < box.y2) - box.y2 = y; + box.y2 = y; if (box.x1 > box.x2) - box.x2 = box.x1; + box.x2 = box.x1; if (box.y1 > box.y2) - box.y2 = box.y1; + box.y2 = box.y1; RegionReset(Rgn, &box); RegionIntersect(Rgn, Rgn, &pWin->winSize); } @@ -621,25 +608,24 @@ ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn, static RealChildHeadProc realChildHeadProc = NULL; void -RegisterRealChildHeadProc (RealChildHeadProc proc) +RegisterRealChildHeadProc(RealChildHeadProc proc) { realChildHeadProc = proc; } - WindowPtr RealChildHead(WindowPtr pWin) { if (realChildHeadProc) { - return realChildHeadProc (pWin); + return realChildHeadProc(pWin); } if (!pWin->parent && - (screenIsSaved == SCREEN_SAVER_ON) && - (HasSaverWindow (pWin->drawable.pScreen))) - return pWin->firstChild; + (screenIsSaved == SCREEN_SAVER_ON) && + (HasSaverWindow(pWin->drawable.pScreen))) + return pWin->firstChild; else - return NullWindow; + return NullWindow; } /***** @@ -663,97 +649,82 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w, WindowOptPtr ancwopt; if (class == CopyFromParent) - class = pParent->drawable.class; + class = pParent->drawable.class; - if ((class != InputOutput) && (class != InputOnly)) - { - *error = BadValue; - client->errorValue = class; - return NullWindow; + if ((class != InputOutput) && (class != InputOnly)) { + *error = BadValue; + client->errorValue = class; + return NullWindow; } - if ((class != InputOnly) && (pParent->drawable.class == InputOnly)) - { - *error = BadMatch; - return NullWindow; + if ((class != InputOnly) && (pParent->drawable.class == InputOnly)) { + *error = BadMatch; + return NullWindow; } - if ((class == InputOnly) && ((bw != 0) || (depth != 0))) - { - *error = BadMatch; - return NullWindow; + if ((class == InputOnly) && ((bw != 0) || (depth != 0))) { + *error = BadMatch; + return NullWindow; } pScreen = pParent->drawable.pScreen; if ((class == InputOutput) && (depth == 0)) - depth = pParent->drawable.depth; + depth = pParent->drawable.depth; ancwopt = pParent->optional; if (!ancwopt) - ancwopt = FindWindowWithOptional(pParent)->optional; + ancwopt = FindWindowWithOptional(pParent)->optional; if (visual == CopyFromParent) { - visual = ancwopt->visual; + visual = ancwopt->visual; } /* Find out if the depth and visual are acceptable for this Screen */ - if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) - { - fOK = FALSE; - for(idepth = 0; idepth < pScreen->numDepths; idepth++) - { - pDepth = (DepthPtr) &pScreen->allowedDepths[idepth]; - if ((depth == pDepth->depth) || (depth == 0)) - { - for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) - { - if (visual == pDepth->vids[ivisual]) - { - fOK = TRUE; - break; - } - } - } - } - if (fOK == FALSE) - { - *error = BadMatch; - return NullWindow; - } + if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) { + fOK = FALSE; + for (idepth = 0; idepth < pScreen->numDepths; idepth++) { + pDepth = (DepthPtr) & pScreen->allowedDepths[idepth]; + if ((depth == pDepth->depth) || (depth == 0)) { + for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) { + if (visual == pDepth->vids[ivisual]) { + fOK = TRUE; + break; + } + } + } + } + if (fOK == FALSE) { + *error = BadMatch; + return NullWindow; + } } if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) && - (class != InputOnly) && - (depth != pParent->drawable.depth)) - { - *error = BadMatch; - return NullWindow; + (class != InputOnly) && (depth != pParent->drawable.depth)) { + *error = BadMatch; + return NullWindow; } if (((vmask & CWColormap) == 0) && - (class != InputOnly) && - ((visual != ancwopt->visual) || (ancwopt->colormap == None))) - { - *error = BadMatch; - return NullWindow; + (class != InputOnly) && + ((visual != ancwopt->visual) || (ancwopt->colormap == None))) { + *error = BadMatch; + return NullWindow; } pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW); - if (!pWin) - { - *error = BadAlloc; - return NullWindow; + if (!pWin) { + *error = BadAlloc; + return NullWindow; } pWin->drawable = pParent->drawable; pWin->drawable.depth = depth; if (depth == pParent->drawable.depth) - pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel; - else - { - for (format = screenInfo.formats; format->depth != depth; format++) - ; - pWin->drawable.bitsPerPixel = format->bitsPerPixel; + pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel; + else { + for (format = screenInfo.formats; format->depth != depth; format++); + pWin->drawable.bitsPerPixel = format->bitsPerPixel; } if (class == InputOnly) - pWin->drawable.type = (short) UNDRAWABLE_WINDOW; + pWin->drawable.type = (short) UNDRAWABLE_WINDOW; pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; pWin->drawable.id = wid; @@ -762,16 +733,14 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w, pWin->parent = pParent; SetWindowToDefaults(pWin); - if (visual != ancwopt->visual) - { - if (!MakeWindowOptional (pWin)) - { - dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW); - *error = BadAlloc; - return NullWindow; - } - pWin->optional->visual = visual; - pWin->optional->colormap = None; + if (visual != ancwopt->visual) { + if (!MakeWindowOptional(pWin)) { + dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW); + *error = BadAlloc; + return NullWindow; + } + pWin->optional->visual = visual; + pWin->optional->colormap = None; } pWin->borderWidth = bw; @@ -779,10 +748,11 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w, /* security creation/labeling check */ *error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW, pWin, - RT_WINDOW, pWin->parent, DixCreateAccess|DixSetAttrAccess); + RT_WINDOW, pWin->parent, + DixCreateAccess | DixSetAttrAccess); if (*error != Success) { - dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW); - return NullWindow; + dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW); + return NullWindow; } pWin->backgroundState = XaceBackgroundNoneState(pWin); @@ -791,118 +761,112 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w, pWin->borderIsPixel = pParent->borderIsPixel; pWin->border = pParent->border; if (pWin->borderIsPixel == FALSE) - pWin->border.pixmap->refcnt++; - - pWin->origin.x = x + (int)bw; - pWin->origin.y = y + (int)bw; + pWin->border.pixmap->refcnt++; + + pWin->origin.x = x + (int) bw; + pWin->origin.y = y + (int) bw; pWin->drawable.width = w; pWin->drawable.height = h; - pWin->drawable.x = pParent->drawable.x + x + (int)bw; - pWin->drawable.y = pParent->drawable.y + y + (int)bw; + pWin->drawable.x = pParent->drawable.x + x + (int) bw; + pWin->drawable.y = pParent->drawable.y + y + (int) bw; - /* set up clip list correctly for unobscured WindowPtr */ + /* set up clip list correctly for unobscured WindowPtr */ RegionNull(&pWin->clipList); RegionNull(&pWin->borderClip); RegionNull(&pWin->winSize); RegionNull(&pWin->borderSize); pHead = RealChildHead(pParent); - if (pHead) - { - pWin->nextSib = pHead->nextSib; - if (pHead->nextSib) - pHead->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pHead->nextSib = pWin; - pWin->prevSib = pHead; + if (pHead) { + pWin->nextSib = pHead->nextSib; + if (pHead->nextSib) + pHead->nextSib->prevSib = pWin; + else + pParent->lastChild = pWin; + pHead->nextSib = pWin; + pWin->prevSib = pHead; } - else - { - pWin->nextSib = pParent->firstChild; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; + else { + pWin->nextSib = pParent->firstChild; + if (pParent->firstChild) + pParent->firstChild->prevSib = pWin; + else + pParent->lastChild = pWin; + pParent->firstChild = pWin; } - SetWinSize (pWin); - SetBorderSize (pWin); + SetWinSize(pWin); + SetBorderSize(pWin); /* We SHOULD check for an error value here XXX */ - if (!(*pScreen->CreateWindow)(pWin)) - { - *error = BadAlloc; - DeleteWindow(pWin, None); - return NullWindow; + if (!(*pScreen->CreateWindow) (pWin)) { + *error = BadAlloc; + DeleteWindow(pWin, None); + return NullWindow; } /* We SHOULD check for an error value here XXX */ - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); + (*pScreen->PositionWindow) (pWin, pWin->drawable.x, pWin->drawable.y); if (!(vmask & CWEventMask)) - RecalculateDeliverableEvents(pWin); + RecalculateDeliverableEvents(pWin); if (vmask) - *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient (pWin)); + *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient(pWin)); else - *error = Success; + *error = Success; - if (*error != Success) - { - DeleteWindow(pWin, None); - return NullWindow; - } - if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful)) - { - XID value = defaultBackingStore; - (void)ChangeWindowAttributes(pWin, CWBackingStore, &value, wClient (pWin)); - pWin->forcedBS = TRUE; - } - - if (SubSend(pParent)) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = CreateNotify; - event.u.createNotify.window = wid; - event.u.createNotify.parent = pParent->drawable.id; - event.u.createNotify.x = x; - event.u.createNotify.y = y; - event.u.createNotify.width = w; - event.u.createNotify.height = h; - event.u.createNotify.borderWidth = bw; - event.u.createNotify.override = pWin->overrideRedirect; - DeliverEvents(pParent, &event, 1, NullWindow); + if (*error != Success) { + DeleteWindow(pWin, None); + return NullWindow; + } + if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful)) { + XID value = defaultBackingStore; + + (void) ChangeWindowAttributes(pWin, CWBackingStore, &value, + wClient(pWin)); + pWin->forcedBS = TRUE; + } + + if (SubSend(pParent)) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = CreateNotify; + event.u.createNotify.window = wid; + event.u.createNotify.parent = pParent->drawable.id; + event.u.createNotify.x = x; + event.u.createNotify.y = y; + event.u.createNotify.width = w; + event.u.createNotify.height = h; + event.u.createNotify.borderWidth = bw; + event.u.createNotify.override = pWin->overrideRedirect; + DeliverEvents(pParent, &event, 1, NullWindow); } return pWin; } static void -DisposeWindowOptional (WindowPtr pWin) +DisposeWindowOptional(WindowPtr pWin) { if (!pWin->optional) - return; + return; /* * everything is peachy. Delete the optional record * and clean up */ - if (pWin->optional->cursor) - { - FreeCursor (pWin->optional->cursor, (Cursor)0); - pWin->cursorIsNone = FALSE; + if (pWin->optional->cursor) { + FreeCursor(pWin->optional->cursor, (Cursor) 0); + pWin->cursorIsNone = FALSE; } else - pWin->cursorIsNone = TRUE; + pWin->cursorIsNone = TRUE; - if (pWin->optional->deviceCursors) - { + if (pWin->optional->deviceCursors) { DevCursorList pList; DevCursorList pPrev; + pList = pWin->optional->deviceCursors; - while(pList) - { + while (pList) { if (pList->cursor) - FreeCursor(pList->cursor, (XID)0); + FreeCursor(pList->cursor, (XID) 0); pPrev = pList; pList = pList->next; free(pPrev); @@ -926,21 +890,21 @@ FreeWindowResources(WindowPtr pWin) RegionUninit(&pWin->winSize); RegionUninit(&pWin->borderClip); RegionUninit(&pWin->borderSize); - if (wBoundingShape (pWin)) - RegionDestroy(wBoundingShape (pWin)); - if (wClipShape (pWin)) - RegionDestroy(wClipShape (pWin)); - if (wInputShape (pWin)) - RegionDestroy(wInputShape (pWin)); + if (wBoundingShape(pWin)) + RegionDestroy(wBoundingShape(pWin)); + if (wClipShape(pWin)) + RegionDestroy(wClipShape(pWin)); + if (wInputShape(pWin)) + RegionDestroy(wInputShape(pWin)); if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); + (*pScreen->DestroyPixmap) (pWin->border.pixmap); if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); + (*pScreen->DestroyPixmap) (pWin->background.pixmap); DeleteAllWindowProperties(pWin); /* We SHOULD check for an error value here XXX */ - (*pScreen->DestroyWindow)(pWin); - DisposeWindowOptional (pWin); + (*pScreen->DestroyWindow) (pWin); + DisposeWindowOptional(pWin); } static void @@ -951,46 +915,41 @@ CrushTree(WindowPtr pWin) xEvent event; if (!(pChild = pWin->firstChild)) - return; + return; UnrealizeWindow = pWin->drawable.pScreen->UnrealizeWindow; - while (1) - { - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (1) - { - pParent = pChild->parent; - if (SubStrSend(pChild, pParent)) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pChild->drawable.id; - DeliverEvents(pChild, &event, 1, NullWindow); - } - FreeResource(pChild->drawable.id, RT_WINDOW); - pSib = pChild->nextSib; - pChild->viewable = FALSE; - if (pChild->realized) - { - pChild->realized = FALSE; - (*UnrealizeWindow)(pChild); - } - FreeWindowResources(pChild); - dixFreeObjectWithPrivates(pChild, PRIVATE_WINDOW); - if ( (pChild = pSib) ) - break; - pChild = pParent; - pChild->firstChild = NullWindow; - pChild->lastChild = NullWindow; - if (pChild == pWin) - return; - } + while (1) { + if (pChild->firstChild) { + pChild = pChild->firstChild; + continue; + } + while (1) { + pParent = pChild->parent; + if (SubStrSend(pChild, pParent)) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = DestroyNotify; + event.u.destroyNotify.window = pChild->drawable.id; + DeliverEvents(pChild, &event, 1, NullWindow); + } + FreeResource(pChild->drawable.id, RT_WINDOW); + pSib = pChild->nextSib; + pChild->viewable = FALSE; + if (pChild->realized) { + pChild->realized = FALSE; + (*UnrealizeWindow) (pChild); + } + FreeWindowResources(pChild); + dixFreeObjectWithPrivates(pChild, PRIVATE_WINDOW); + if ((pChild = pSib)) + break; + pChild = pParent; + pChild->firstChild = NullWindow; + pChild->lastChild = NullWindow; + if (pChild == pWin) + return; + } } } - + /***** * DeleteWindow * Deletes child of window then window itself @@ -999,9 +958,9 @@ CrushTree(WindowPtr pWin) int DeleteWindow(pointer value, XID wid) - { +{ WindowPtr pParent; - WindowPtr pWin = (WindowPtr)value; + WindowPtr pWin = (WindowPtr) value; xEvent event; UnmapWindow(pWin, FALSE); @@ -1009,28 +968,26 @@ DeleteWindow(pointer value, XID wid) CrushTree(pWin); pParent = pWin->parent; - if (wid && pParent && SubStrSend(pWin, pParent)) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = DestroyNotify; - event.u.destroyNotify.window = pWin->drawable.id; - DeliverEvents(pWin, &event, 1, NullWindow); + if (wid && pParent && SubStrSend(pWin, pParent)) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = DestroyNotify; + event.u.destroyNotify.window = pWin->drawable.id; + DeliverEvents(pWin, &event, 1, NullWindow); } FreeWindowResources(pWin); - if (pParent) - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; + if (pParent) { + if (pParent->firstChild == pWin) + pParent->firstChild = pWin->nextSib; + if (pParent->lastChild == pWin) + pParent->lastChild = pWin->prevSib; + if (pWin->nextSib) + pWin->nextSib->prevSib = pWin->prevSib; + if (pWin->prevSib) + pWin->prevSib->nextSib = pWin->nextSib; } else - pWin->drawable.pScreen->root = NULL; + pWin->drawable.pScreen->root = NULL; dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW); return Success; } @@ -1048,12 +1005,13 @@ DestroySubwindows(WindowPtr pWin, ClientPtr client) */ UnmapSubwindows(pWin); while (pWin->lastChild) { - int rc = XaceHook(XACE_RESOURCE_ACCESS, client, - pWin->lastChild->drawable.id, RT_WINDOW, - pWin->lastChild, RT_NONE, NULL, DixDestroyAccess); - if (rc != Success) - return rc; - FreeResource(pWin->lastChild->drawable.id, RT_NONE); + int rc = XaceHook(XACE_RESOURCE_ACCESS, client, + pWin->lastChild->drawable.id, RT_WINDOW, + pWin->lastChild, RT_NONE, NULL, DixDestroyAccess); + + if (rc != Success) + return rc; + FreeResource(pWin->lastChild->drawable.id, RT_NONE); } return Success; } @@ -1064,18 +1022,18 @@ SetRootWindowBackground(WindowPtr pWin, ScreenPtr pScreen, Mask *index2) /* following the protocol: "Changing the background of a root window to * None or ParentRelative restores the default background pixmap" */ if (bgNoneRoot) { - pWin->backgroundState = XaceBackgroundNoneState(pWin); - pWin->background.pixel = pScreen->whitePixel; + pWin->backgroundState = XaceBackgroundNoneState(pWin); + pWin->background.pixel = pScreen->whitePixel; } else if (party_like_its_1989) - MakeRootTile(pWin); + MakeRootTile(pWin); else { pWin->backgroundState = BackgroundPixel; - if (whiteRoot) - pWin->background.pixel = pScreen->whitePixel; - else - pWin->background.pixel = pScreen->blackPixel; - *index2 = CWBackPixel; + if (whiteRoot) + pWin->background.pixel = pScreen->whitePixel; + else + pWin->background.pixel = pScreen->blackPixel; + *index2 = CWBackPixel; } } @@ -1086,7 +1044,7 @@ SetRootWindowBackground(WindowPtr pWin, ScreenPtr pScreen, Mask *index2) * value-list contains one value for each one bit in the mask, from least * to most significant bit in the mask. *****/ - + int ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) { @@ -1097,7 +1055,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) Cursor cursorID; WindowPtr pChild; Colormap cmap; - ColormapPtr pCmap; + ColormapPtr pCmap; xEvent xE; int error, rc; ScreenPtr pScreen; @@ -1105,568 +1063,523 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) unsigned int val; Bool checkOptional = FALSE, borderRelative = FALSE; - if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK))) - return BadMatch; + if ((pWin->drawable.class == InputOnly) && + (vmask & (~INPUTONLY_LEGAL_MASK))) + return BadMatch; error = Success; pScreen = pWin->drawable.pScreen; pVlist = vlist; tmask = vmask; - while (tmask) - { - index2 = (Mask) lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBackPixmap: - pixID = (Pixmap )*pVlist; - pVlist++; - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pixID == None) - { - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - SetRootWindowBackground(pWin, pScreen, &index2); - else { - pWin->backgroundState = XaceBackgroundNoneState(pWin); - pWin->background.pixel = pScreen->whitePixel; - } - } - else if (pixID == ParentRelative) - { - if (pWin->parent && - pWin->drawable.depth != pWin->parent->drawable.depth) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - if (!pWin->parent) - SetRootWindowBackground(pWin, pScreen, &index2); - else - pWin->backgroundState = ParentRelative; - borderRelative = TRUE; - /* Note that the parent's backgroundTile's refcnt is NOT - * incremented. */ - } - else - { - rc = dixLookupResourceByType((pointer *)&pPixmap, pixID, RT_PIXMAP, - client, DixReadAccess); - if (rc == Success) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixmap; - pWin->background.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = rc; - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBackPixel: - if (pWin->backgroundState == ParentRelative) - borderRelative = TRUE; - if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap)(pWin->background.pixmap); - pWin->backgroundState = BackgroundPixel; - pWin->background.pixel = (CARD32 ) *pVlist; - /* background pixel overrides background pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBackPixmap; - pVlist++; - break; - case CWBorderPixmap: - pixID = (Pixmap ) *pVlist; - pVlist++; - if (pixID == CopyFromParent) - { - if (!pWin->parent || - (pWin->drawable.depth != pWin->parent->drawable.depth)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->parent->borderIsPixel == TRUE) { - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->border = pWin->parent->border; - pWin->borderIsPixel = TRUE; - index2 = CWBorderPixel; - break; - } - else - { - pixID = pWin->parent->border.pixmap->drawable.id; - } - } - rc = dixLookupResourceByType((pointer *)&pPixmap, pixID, RT_PIXMAP, - client, DixReadAccess); - if (rc == Success) - { - if ((pPixmap->drawable.depth != pWin->drawable.depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - error = BadMatch; - goto PatchUp; - } - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = FALSE; - pWin->border.pixmap = pPixmap; - pPixmap->refcnt++; - } - else - { - error = rc; - client->errorValue = pixID; - goto PatchUp; - } - break; - case CWBorderPixel: - if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap)(pWin->border.pixmap); - pWin->borderIsPixel = TRUE; - pWin->border.pixel = (CARD32) *pVlist; - /* border pixel overrides border pixmap, - so don't let the ddx layer see both bits */ - vmaskCopy &= ~CWBorderPixmap; - pVlist++; - break; - case CWBitGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->bitGravity = val; - break; - case CWWinGravity: - val = (CARD8 )*pVlist; - pVlist++; - if (val > StaticGravity) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->winGravity = val; - break; - case CWBackingStore: - val = (CARD8 )*pVlist; - pVlist++; - if ((val != NotUseful) && (val != WhenMapped) && (val != Always)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->backingStore = val; - pWin->forcedBS = FALSE; - break; - case CWBackingPlanes: - if (pWin->optional || ((CARD32)*pVlist != (CARD32)~0L)) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingBitPlanes = (CARD32) *pVlist; - if ((CARD32)*pVlist == (CARD32)~0L) - checkOptional = TRUE; - } - pVlist++; - break; - case CWBackingPixel: - if (pWin->optional || (CARD32) *pVlist) { - if (!pWin->optional && !MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - pWin->optional->backingPixel = (CARD32) *pVlist; - if (!*pVlist) - checkOptional = TRUE; - } - pVlist++; - break; - case CWSaveUnder: - val = (BOOL) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - pWin->saveUnder = val; - break; - case CWEventMask: - rc = EventSelectForWindow(pWin, client, (Mask )*pVlist); - if (rc) - { - error = rc; - goto PatchUp; - } - pVlist++; - break; - case CWDontPropagate: - rc = EventSuppressForWindow(pWin, client, (Mask )*pVlist, - &checkOptional); - if (rc) - { - error = rc; - goto PatchUp; - } - pVlist++; - break; - case CWOverrideRedirect: - val = (BOOL ) *pVlist; - pVlist++; - if ((val != xTrue) && (val != xFalse)) - { - error = BadValue; - client->errorValue = val; - goto PatchUp; - } - if (val == xTrue) { - rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, - RT_WINDOW, pWin, RT_NONE, NULL, DixGrabAccess); - if (rc != Success) { - error = rc; - client->errorValue = pWin->drawable.id; - goto PatchUp; - } - } - pWin->overrideRedirect = val; - break; - case CWColormap: - cmap = (Colormap) *pVlist; - pVlist++; - if (cmap == CopyFromParent) - { - if (pWin->parent && - (!pWin->optional || - pWin->optional->visual == wVisual (pWin->parent))) - { - cmap = wColormap (pWin->parent); - } - else - cmap = None; - } - if (cmap == None) - { - error = BadMatch; - goto PatchUp; - } - rc = dixLookupResourceByType((pointer *)&pCmap, cmap, RT_COLORMAP, - client, DixUseAccess); - if (rc != Success) - { - error = rc; - client->errorValue = cmap; - goto PatchUp; - } - if (pCmap->pVisual->vid != wVisual (pWin) || - pCmap->pScreen != pScreen) - { - error = BadMatch; - goto PatchUp; - } - if (cmap != wColormap (pWin)) - { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && cmap == wColormap (pWin->parent)) - checkOptional = TRUE; - - /* - * propagate the original colormap to any children - * inheriting it - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pWin->optional->colormap = cmap; - - /* - * check on any children now matching the new colormap - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional->colormap == cmap) - CheckWindowOptionalNeed (pChild); - } - - xE.u.u.type = ColormapNotify; - xE.u.colormap.window = pWin->drawable.id; - xE.u.colormap.colormap = cmap; - xE.u.colormap.new = xTrue; - xE.u.colormap.state = IsMapInstalled(cmap, pWin); - DeliverEvents(pWin, &xE, 1, NullWindow); - } - break; - case CWCursor: - cursorID = (Cursor ) *pVlist; - pVlist++; - /* - * install the new - */ - if ( cursorID == None) - { - if (pWin == pWin->drawable.pScreen->root) - pCursor = rootCursor; - else - pCursor = (CursorPtr) None; - } - else - { - rc = dixLookupResourceByType((pointer *)&pCursor, cursorID, - RT_CURSOR, client, DixUseAccess); - if (rc != Success) - { - error = rc; - client->errorValue = cursorID; - goto PatchUp; - } - } - - if (pCursor != wCursor (pWin)) - { - /* - * patch up child windows so they don't lose cursors. - */ - - for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (!pChild->optional && !pChild->cursorIsNone && - !MakeWindowOptional (pChild)) - { - error = BadAlloc; - goto PatchUp; - } - } - - pOldCursor = 0; - if (pCursor == (CursorPtr) None) - { - pWin->cursorIsNone = TRUE; - if (pWin->optional) - { - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = (CursorPtr) None; - checkOptional = TRUE; - } - } else { - if (!pWin->optional) - { - if (!MakeWindowOptional (pWin)) - { - error = BadAlloc; - goto PatchUp; - } - } - else if (pWin->parent && pCursor == wCursor (pWin->parent)) - checkOptional = TRUE; - pOldCursor = pWin->optional->cursor; - pWin->optional->cursor = pCursor; - pCursor->refcnt++; - pWin->cursorIsNone = FALSE; - /* - * check on any children now matching the new cursor - */ - - for (pChild=pWin->firstChild; pChild; pChild=pChild->nextSib) - { - if (pChild->optional && - (pChild->optional->cursor == pCursor)) - CheckWindowOptionalNeed (pChild); - } - } - - if (pWin->realized) - WindowHasNewCursor( pWin); - - /* Can't free cursor until here - old cursor - * is needed in WindowHasNewCursor - */ - if (pOldCursor) - FreeCursor (pOldCursor, (Cursor)0); - } - break; - default: - error = BadValue; - client->errorValue = vmask; - goto PatchUp; - } - vmaskCopy |= index2; - } -PatchUp: + while (tmask) { + index2 = (Mask) lowbit(tmask); + tmask &= ~index2; + switch (index2) { + case CWBackPixmap: + pixID = (Pixmap) * pVlist; + pVlist++; + if (pWin->backgroundState == ParentRelative) + borderRelative = TRUE; + if (pixID == None) { + if (pWin->backgroundState == BackgroundPixmap) + (*pScreen->DestroyPixmap) (pWin->background.pixmap); + if (!pWin->parent) + SetRootWindowBackground(pWin, pScreen, &index2); + else { + pWin->backgroundState = XaceBackgroundNoneState(pWin); + pWin->background.pixel = pScreen->whitePixel; + } + } + else if (pixID == ParentRelative) { + if (pWin->parent && + pWin->drawable.depth != pWin->parent->drawable.depth) { + error = BadMatch; + goto PatchUp; + } + if (pWin->backgroundState == BackgroundPixmap) + (*pScreen->DestroyPixmap) (pWin->background.pixmap); + if (!pWin->parent) + SetRootWindowBackground(pWin, pScreen, &index2); + else + pWin->backgroundState = ParentRelative; + borderRelative = TRUE; + /* Note that the parent's backgroundTile's refcnt is NOT + * incremented. */ + } + else { + rc = dixLookupResourceByType((pointer *) &pPixmap, pixID, + RT_PIXMAP, client, DixReadAccess); + if (rc == Success) { + if ((pPixmap->drawable.depth != pWin->drawable.depth) || + (pPixmap->drawable.pScreen != pScreen)) { + error = BadMatch; + goto PatchUp; + } + if (pWin->backgroundState == BackgroundPixmap) + (*pScreen->DestroyPixmap) (pWin->background.pixmap); + pWin->backgroundState = BackgroundPixmap; + pWin->background.pixmap = pPixmap; + pPixmap->refcnt++; + } + else { + error = rc; + client->errorValue = pixID; + goto PatchUp; + } + } + break; + case CWBackPixel: + if (pWin->backgroundState == ParentRelative) + borderRelative = TRUE; + if (pWin->backgroundState == BackgroundPixmap) + (*pScreen->DestroyPixmap) (pWin->background.pixmap); + pWin->backgroundState = BackgroundPixel; + pWin->background.pixel = (CARD32) *pVlist; + /* background pixel overrides background pixmap, + so don't let the ddx layer see both bits */ + vmaskCopy &= ~CWBackPixmap; + pVlist++; + break; + case CWBorderPixmap: + pixID = (Pixmap) * pVlist; + pVlist++; + if (pixID == CopyFromParent) { + if (!pWin->parent || + (pWin->drawable.depth != pWin->parent->drawable.depth)) { + error = BadMatch; + goto PatchUp; + } + if (pWin->parent->borderIsPixel == TRUE) { + if (pWin->borderIsPixel == FALSE) + (*pScreen->DestroyPixmap) (pWin->border.pixmap); + pWin->border = pWin->parent->border; + pWin->borderIsPixel = TRUE; + index2 = CWBorderPixel; + break; + } + else { + pixID = pWin->parent->border.pixmap->drawable.id; + } + } + rc = dixLookupResourceByType((pointer *) &pPixmap, pixID, RT_PIXMAP, + client, DixReadAccess); + if (rc == Success) { + if ((pPixmap->drawable.depth != pWin->drawable.depth) || + (pPixmap->drawable.pScreen != pScreen)) { + error = BadMatch; + goto PatchUp; + } + if (pWin->borderIsPixel == FALSE) + (*pScreen->DestroyPixmap) (pWin->border.pixmap); + pWin->borderIsPixel = FALSE; + pWin->border.pixmap = pPixmap; + pPixmap->refcnt++; + } + else { + error = rc; + client->errorValue = pixID; + goto PatchUp; + } + break; + case CWBorderPixel: + if (pWin->borderIsPixel == FALSE) + (*pScreen->DestroyPixmap) (pWin->border.pixmap); + pWin->borderIsPixel = TRUE; + pWin->border.pixel = (CARD32) *pVlist; + /* border pixel overrides border pixmap, + so don't let the ddx layer see both bits */ + vmaskCopy &= ~CWBorderPixmap; + pVlist++; + break; + case CWBitGravity: + val = (CARD8) *pVlist; + pVlist++; + if (val > StaticGravity) { + error = BadValue; + client->errorValue = val; + goto PatchUp; + } + pWin->bitGravity = val; + break; + case CWWinGravity: + val = (CARD8) *pVlist; + pVlist++; + if (val > StaticGravity) { + error = BadValue; + client->errorValue = val; + goto PatchUp; + } + pWin->winGravity = val; + break; + case CWBackingStore: + val = (CARD8) *pVlist; + pVlist++; + if ((val != NotUseful) && (val != WhenMapped) && (val != Always)) { + error = BadValue; + client->errorValue = val; + goto PatchUp; + } + pWin->backingStore = val; + pWin->forcedBS = FALSE; + break; + case CWBackingPlanes: + if (pWin->optional || ((CARD32) *pVlist != (CARD32) ~0L)) { + if (!pWin->optional && !MakeWindowOptional(pWin)) { + error = BadAlloc; + goto PatchUp; + } + pWin->optional->backingBitPlanes = (CARD32) *pVlist; + if ((CARD32) *pVlist == (CARD32) ~0L) + checkOptional = TRUE; + } + pVlist++; + break; + case CWBackingPixel: + if (pWin->optional || (CARD32) *pVlist) { + if (!pWin->optional && !MakeWindowOptional(pWin)) { + error = BadAlloc; + goto PatchUp; + } + pWin->optional->backingPixel = (CARD32) *pVlist; + if (!*pVlist) + checkOptional = TRUE; + } + pVlist++; + break; + case CWSaveUnder: + val = (BOOL) * pVlist; + pVlist++; + if ((val != xTrue) && (val != xFalse)) { + error = BadValue; + client->errorValue = val; + goto PatchUp; + } + pWin->saveUnder = val; + break; + case CWEventMask: + rc = EventSelectForWindow(pWin, client, (Mask) *pVlist); + if (rc) { + error = rc; + goto PatchUp; + } + pVlist++; + break; + case CWDontPropagate: + rc = EventSuppressForWindow(pWin, client, (Mask) *pVlist, + &checkOptional); + if (rc) { + error = rc; + goto PatchUp; + } + pVlist++; + break; + case CWOverrideRedirect: + val = (BOOL) * pVlist; + pVlist++; + if ((val != xTrue) && (val != xFalse)) { + error = BadValue; + client->errorValue = val; + goto PatchUp; + } + if (val == xTrue) { + rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, + RT_WINDOW, pWin, RT_NONE, NULL, DixGrabAccess); + if (rc != Success) { + error = rc; + client->errorValue = pWin->drawable.id; + goto PatchUp; + } + } + pWin->overrideRedirect = val; + break; + case CWColormap: + cmap = (Colormap) * pVlist; + pVlist++; + if (cmap == CopyFromParent) { + if (pWin->parent && + (!pWin->optional || + pWin->optional->visual == wVisual(pWin->parent))) { + cmap = wColormap(pWin->parent); + } + else + cmap = None; + } + if (cmap == None) { + error = BadMatch; + goto PatchUp; + } + rc = dixLookupResourceByType((pointer *) &pCmap, cmap, RT_COLORMAP, + client, DixUseAccess); + if (rc != Success) { + error = rc; + client->errorValue = cmap; + goto PatchUp; + } + if (pCmap->pVisual->vid != wVisual(pWin) || + pCmap->pScreen != pScreen) { + error = BadMatch; + goto PatchUp; + } + if (cmap != wColormap(pWin)) { + if (!pWin->optional) { + if (!MakeWindowOptional(pWin)) { + error = BadAlloc; + goto PatchUp; + } + } + else if (pWin->parent && cmap == wColormap(pWin->parent)) + checkOptional = TRUE; + + /* + * propagate the original colormap to any children + * inheriting it + */ + + for (pChild = pWin->firstChild; pChild; + pChild = pChild->nextSib) { + if (!pChild->optional && !MakeWindowOptional(pChild)) { + error = BadAlloc; + goto PatchUp; + } + } + + pWin->optional->colormap = cmap; + + /* + * check on any children now matching the new colormap + */ + + for (pChild = pWin->firstChild; pChild; + pChild = pChild->nextSib) { + if (pChild->optional->colormap == cmap) + CheckWindowOptionalNeed(pChild); + } + + xE.u.u.type = ColormapNotify; + xE.u.colormap.window = pWin->drawable.id; + xE.u.colormap.colormap = cmap; + xE.u.colormap.new = xTrue; + xE.u.colormap.state = IsMapInstalled(cmap, pWin); + DeliverEvents(pWin, &xE, 1, NullWindow); + } + break; + case CWCursor: + cursorID = (Cursor) * pVlist; + pVlist++; + /* + * install the new + */ + if (cursorID == None) { + if (pWin == pWin->drawable.pScreen->root) + pCursor = rootCursor; + else + pCursor = (CursorPtr) None; + } + else { + rc = dixLookupResourceByType((pointer *) &pCursor, cursorID, + RT_CURSOR, client, DixUseAccess); + if (rc != Success) { + error = rc; + client->errorValue = cursorID; + goto PatchUp; + } + } + + if (pCursor != wCursor(pWin)) { + /* + * patch up child windows so they don't lose cursors. + */ + + for (pChild = pWin->firstChild; pChild; + pChild = pChild->nextSib) { + if (!pChild->optional && !pChild->cursorIsNone && + !MakeWindowOptional(pChild)) { + error = BadAlloc; + goto PatchUp; + } + } + + pOldCursor = 0; + if (pCursor == (CursorPtr) None) { + pWin->cursorIsNone = TRUE; + if (pWin->optional) { + pOldCursor = pWin->optional->cursor; + pWin->optional->cursor = (CursorPtr) None; + checkOptional = TRUE; + } + } + else { + if (!pWin->optional) { + if (!MakeWindowOptional(pWin)) { + error = BadAlloc; + goto PatchUp; + } + } + else if (pWin->parent && pCursor == wCursor(pWin->parent)) + checkOptional = TRUE; + pOldCursor = pWin->optional->cursor; + pWin->optional->cursor = pCursor; + pCursor->refcnt++; + pWin->cursorIsNone = FALSE; + /* + * check on any children now matching the new cursor + */ + + for (pChild = pWin->firstChild; pChild; + pChild = pChild->nextSib) { + if (pChild->optional && + (pChild->optional->cursor == pCursor)) + CheckWindowOptionalNeed(pChild); + } + } + + if (pWin->realized) + WindowHasNewCursor(pWin); + + /* Can't free cursor until here - old cursor + * is needed in WindowHasNewCursor + */ + if (pOldCursor) + FreeCursor(pOldCursor, (Cursor) 0); + } + break; + default: + error = BadValue; + client->errorValue = vmask; + goto PatchUp; + } + vmaskCopy |= index2; + } + PatchUp: if (checkOptional) - CheckWindowOptionalNeed (pWin); + CheckWindowOptionalNeed(pWin); - /* We SHOULD check for an error value here XXX */ - (*pScreen->ChangeWindowAttributes)(pWin, vmaskCopy); + /* We SHOULD check for an error value here XXX */ + (*pScreen->ChangeWindowAttributes) (pWin, vmaskCopy); /* - If the border contents have changed, redraw the border. - Note that this has to be done AFTER pScreen->ChangeWindowAttributes - for the tile to be rotated, and the correct function selected. - */ + If the border contents have changed, redraw the border. + Note that this has to be done AFTER pScreen->ChangeWindowAttributes + for the tile to be rotated, and the correct function selected. + */ if (((vmaskCopy & (CWBorderPixel | CWBorderPixmap)) || borderRelative) - && pWin->viewable && HasBorder (pWin)) - { - RegionRec exposed; + && pWin->viewable && HasBorder(pWin)) { + RegionRec exposed; - RegionNull(&exposed); - RegionSubtract(&exposed, &pWin->borderClip, &pWin->winSize); - miPaintWindow(pWin, &exposed, PW_BORDER); - RegionUninit(&exposed); + RegionNull(&exposed); + RegionSubtract(&exposed, &pWin->borderClip, &pWin->winSize); + miPaintWindow(pWin, &exposed, PW_BORDER); + RegionUninit(&exposed); } return error; } - /***** * GetWindowAttributes * Notice that this is different than ChangeWindowAttributes *****/ void -GetWindowAttributes(WindowPtr pWin, ClientPtr client, xGetWindowAttributesReply *wa) +GetWindowAttributes(WindowPtr pWin, ClientPtr client, + xGetWindowAttributesReply * wa) { wa->type = X_Reply; wa->bitGravity = pWin->bitGravity; wa->winGravity = pWin->winGravity; if (pWin->forcedBS && pWin->backingStore != Always) - wa->backingStore = NotUseful; + wa->backingStore = NotUseful; else - wa->backingStore = pWin->backingStore; + wa->backingStore = pWin->backingStore; wa->length = bytes_to_int32(sizeof(xGetWindowAttributesReply) - - sizeof(xGenericReply)); + sizeof(xGenericReply)); wa->sequenceNumber = client->sequence; - wa->backingBitPlanes = wBackingBitPlanes (pWin); - wa->backingPixel = wBackingPixel (pWin); - wa->saveUnder = (BOOL)pWin->saveUnder; + wa->backingBitPlanes = wBackingBitPlanes(pWin); + wa->backingPixel = wBackingPixel(pWin); + wa->saveUnder = (BOOL) pWin->saveUnder; wa->override = pWin->overrideRedirect; if (!pWin->mapped) - wa->mapState = IsUnmapped; + wa->mapState = IsUnmapped; else if (pWin->realized) - wa->mapState = IsViewable; + wa->mapState = IsViewable; else - wa->mapState = IsUnviewable; + wa->mapState = IsUnviewable; - wa->colormap = wColormap (pWin); + wa->colormap = wColormap(pWin); wa->mapInstalled = (wa->colormap == None) ? xFalse - : IsMapInstalled(wa->colormap, pWin); + : IsMapInstalled(wa->colormap, pWin); wa->yourEventMask = EventMaskForClient(pWin, client); - wa->allEventMasks = pWin->eventMask | wOtherEventMasks (pWin); - wa->doNotPropagateMask = wDontPropagateMask (pWin); + wa->allEventMasks = pWin->eventMask | wOtherEventMasks(pWin); + wa->doNotPropagateMask = wDontPropagateMask(pWin); wa->class = pWin->drawable.class; - wa->visualID = wVisual (pWin); + wa->visualID = wVisual(pWin); } - WindowPtr MoveWindowInStack(WindowPtr pWin, WindowPtr pNextSib) { WindowPtr pParent = pWin->parent; - WindowPtr pFirstChange = pWin; /* highest window where list changes */ + WindowPtr pFirstChange = pWin; /* highest window where list changes */ + + if (pWin->nextSib != pNextSib) { + WindowPtr pOldNextSib = pWin->nextSib; + + if (!pNextSib) { /* move to bottom */ + if (pParent->firstChild == pWin) + pParent->firstChild = pWin->nextSib; + /* if (pWin->nextSib) *//* is always True: pNextSib == NULL + * and pWin->nextSib != pNextSib + * therefore pWin->nextSib != NULL */ + pFirstChange = pWin->nextSib; + pWin->nextSib->prevSib = pWin->prevSib; + if (pWin->prevSib) + pWin->prevSib->nextSib = pWin->nextSib; + pParent->lastChild->nextSib = pWin; + pWin->prevSib = pParent->lastChild; + pWin->nextSib = NullWindow; + pParent->lastChild = pWin; + } + else if (pParent->firstChild == pNextSib) { /* move to top */ + pFirstChange = pWin; + if (pParent->lastChild == pWin) + pParent->lastChild = pWin->prevSib; + if (pWin->nextSib) + pWin->nextSib->prevSib = pWin->prevSib; + if (pWin->prevSib) + pWin->prevSib->nextSib = pWin->nextSib; + pWin->nextSib = pParent->firstChild; + pWin->prevSib = (WindowPtr) NULL; + pNextSib->prevSib = pWin; + pParent->firstChild = pWin; + } + else { /* move in middle of list */ - if (pWin->nextSib != pNextSib) - { - WindowPtr pOldNextSib = pWin->nextSib; - - if (!pNextSib) /* move to bottom */ - { - if (pParent->firstChild == pWin) - pParent->firstChild = pWin->nextSib; - /* if (pWin->nextSib) */ /* is always True: pNextSib == NULL - * and pWin->nextSib != pNextSib - * therefore pWin->nextSib != NULL */ - pFirstChange = pWin->nextSib; - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pParent->lastChild->nextSib = pWin; - pWin->prevSib = pParent->lastChild; - pWin->nextSib = NullWindow; - pParent->lastChild = pWin; - } - else if (pParent->firstChild == pNextSib) /* move to top */ - { - pFirstChange = pWin; - if (pParent->lastChild == pWin) - pParent->lastChild = pWin->prevSib; - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pParent->firstChild; - pWin->prevSib = (WindowPtr ) NULL; - pNextSib->prevSib = pWin; - pParent->firstChild = pWin; - } - else /* move in middle of list */ - { - WindowPtr pOldNext = pWin->nextSib; - - pFirstChange = NullWindow; - if (pParent->firstChild == pWin) - pFirstChange = pParent->firstChild = pWin->nextSib; - if (pParent->lastChild == pWin) { - pFirstChange = pWin; - pParent->lastChild = pWin->prevSib; - } - if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; - if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; - pWin->nextSib = pNextSib; - pWin->prevSib = pNextSib->prevSib; - if (pNextSib->prevSib) - pNextSib->prevSib->nextSib = pWin; - pNextSib->prevSib = pWin; - if (!pFirstChange) { /* do we know it yet? */ - pFirstChange = pParent->firstChild; /* no, search from top */ - while ((pFirstChange != pWin) && (pFirstChange != pOldNext)) - pFirstChange = pFirstChange->nextSib; - } - } - if(pWin->drawable.pScreen->RestackWindow) - (*pWin->drawable.pScreen->RestackWindow)(pWin, pOldNextSib); + WindowPtr pOldNext = pWin->nextSib; + + pFirstChange = NullWindow; + if (pParent->firstChild == pWin) + pFirstChange = pParent->firstChild = pWin->nextSib; + if (pParent->lastChild == pWin) { + pFirstChange = pWin; + pParent->lastChild = pWin->prevSib; + } + if (pWin->nextSib) + pWin->nextSib->prevSib = pWin->prevSib; + if (pWin->prevSib) + pWin->prevSib->nextSib = pWin->nextSib; + pWin->nextSib = pNextSib; + pWin->prevSib = pNextSib->prevSib; + if (pNextSib->prevSib) + pNextSib->prevSib->nextSib = pWin; + pNextSib->prevSib = pWin; + if (!pFirstChange) { /* do we know it yet? */ + pFirstChange = pParent->firstChild; /* no, search from top */ + while ((pFirstChange != pWin) && (pFirstChange != pOldNext)) + pFirstChange = pFirstChange->nextSib; + } + } + if (pWin->drawable.pScreen->RestackWindow) + (*pWin->drawable.pScreen->RestackWindow) (pWin, pOldNextSib); } #ifdef ROOTLESS @@ -1677,90 +1590,85 @@ MoveWindowInStack(WindowPtr pWin, WindowPtr pNextSib) * the underlying window system may want to reorder it. */ else if (pWin->drawable.pScreen->RestackWindow) - (*pWin->drawable.pScreen->RestackWindow)(pWin, pWin->nextSib); + (*pWin->drawable.pScreen->RestackWindow) (pWin, pWin->nextSib); #endif return pFirstChange; } void -SetWinSize (WindowPtr pWin) +SetWinSize(WindowPtr pWin) { #ifdef COMPOSITE - if (pWin->redirectDraw != RedirectDrawNone) - { - BoxRec box; - - /* - * Redirected clients get clip list equal to their - * own geometry, not clipped to their parent - */ - box.x1 = pWin->drawable.x; - box.y1 = pWin->drawable.y; - box.x2 = pWin->drawable.x + pWin->drawable.width; - box.y2 = pWin->drawable.y + pWin->drawable.height; - RegionReset(&pWin->winSize, &box); + if (pWin->redirectDraw != RedirectDrawNone) { + BoxRec box; + + /* + * Redirected clients get clip list equal to their + * own geometry, not clipped to their parent + */ + box.x1 = pWin->drawable.x; + box.y1 = pWin->drawable.y; + box.x2 = pWin->drawable.x + pWin->drawable.width; + box.y2 = pWin->drawable.y + pWin->drawable.height; + RegionReset(&pWin->winSize, &box); } else #endif - ClippedRegionFromBox(pWin->parent, &pWin->winSize, - pWin->drawable.x, pWin->drawable.y, - (int)pWin->drawable.width, - (int)pWin->drawable.height); - if (wBoundingShape (pWin) || wClipShape (pWin)) { - RegionTranslate(&pWin->winSize, - pWin->drawable.x, - - pWin->drawable.y); - if (wBoundingShape (pWin)) - RegionIntersect(&pWin->winSize, &pWin->winSize, - wBoundingShape (pWin)); - if (wClipShape (pWin)) - RegionIntersect(&pWin->winSize, &pWin->winSize, - wClipShape (pWin)); - RegionTranslate(&pWin->winSize, pWin->drawable.x, - pWin->drawable.y); + ClippedRegionFromBox(pWin->parent, &pWin->winSize, + pWin->drawable.x, pWin->drawable.y, + (int) pWin->drawable.width, + (int) pWin->drawable.height); + if (wBoundingShape(pWin) || wClipShape(pWin)) { + RegionTranslate(&pWin->winSize, -pWin->drawable.x, -pWin->drawable.y); + if (wBoundingShape(pWin)) + RegionIntersect(&pWin->winSize, &pWin->winSize, + wBoundingShape(pWin)); + if (wClipShape(pWin)) + RegionIntersect(&pWin->winSize, &pWin->winSize, wClipShape(pWin)); + RegionTranslate(&pWin->winSize, pWin->drawable.x, pWin->drawable.y); } } void -SetBorderSize (WindowPtr pWin) +SetBorderSize(WindowPtr pWin) { - int bw; + int bw; - if (HasBorder (pWin)) { - bw = wBorderWidth (pWin); + if (HasBorder(pWin)) { + bw = wBorderWidth(pWin); #ifdef COMPOSITE - if (pWin->redirectDraw != RedirectDrawNone) - { - BoxRec box; - - /* - * Redirected clients get clip list equal to their - * own geometry, not clipped to their parent - */ - box.x1 = pWin->drawable.x - bw; - box.y1 = pWin->drawable.y - bw; - box.x2 = pWin->drawable.x + pWin->drawable.width + bw; - box.y2 = pWin->drawable.y + pWin->drawable.height + bw; - RegionReset(&pWin->borderSize, &box); - } - else + if (pWin->redirectDraw != RedirectDrawNone) { + BoxRec box; + + /* + * Redirected clients get clip list equal to their + * own geometry, not clipped to their parent + */ + box.x1 = pWin->drawable.x - bw; + box.y1 = pWin->drawable.y - bw; + box.x2 = pWin->drawable.x + pWin->drawable.width + bw; + box.y2 = pWin->drawable.y + pWin->drawable.height + bw; + RegionReset(&pWin->borderSize, &box); + } + else #endif - ClippedRegionFromBox(pWin->parent, &pWin->borderSize, - pWin->drawable.x - bw, pWin->drawable.y - bw, - (int)(pWin->drawable.width + (bw<<1)), - (int)(pWin->drawable.height + (bw<<1))); - if (wBoundingShape (pWin)) { - RegionTranslate(&pWin->borderSize, - pWin->drawable.x, - - pWin->drawable.y); - RegionIntersect(&pWin->borderSize, &pWin->borderSize, - wBoundingShape (pWin)); - RegionTranslate(&pWin->borderSize, pWin->drawable.x, - pWin->drawable.y); - RegionUnion(&pWin->borderSize, &pWin->borderSize, - &pWin->winSize); - } - } else { - RegionCopy(&pWin->borderSize, &pWin->winSize); + ClippedRegionFromBox(pWin->parent, &pWin->borderSize, + pWin->drawable.x - bw, pWin->drawable.y - bw, + (int) (pWin->drawable.width + (bw << 1)), + (int) (pWin->drawable.height + (bw << 1))); + if (wBoundingShape(pWin)) { + RegionTranslate(&pWin->borderSize, -pWin->drawable.x, + -pWin->drawable.y); + RegionIntersect(&pWin->borderSize, &pWin->borderSize, + wBoundingShape(pWin)); + RegionTranslate(&pWin->borderSize, pWin->drawable.x, + pWin->drawable.y); + RegionUnion(&pWin->borderSize, &pWin->borderSize, &pWin->winSize); + } + } + else { + RegionCopy(&pWin->borderSize, &pWin->winSize); } } @@ -1772,51 +1680,50 @@ SetBorderSize (WindowPtr pWin) */ void -GravityTranslate (int x, int y, int oldx, int oldy, - int dw, int dh, unsigned gravity, - int *destx, int *desty) +GravityTranslate(int x, int y, int oldx, int oldy, + int dw, int dh, unsigned gravity, int *destx, int *desty) { switch (gravity) { case NorthGravity: - *destx = x + dw / 2; - *desty = y; - break; + *destx = x + dw / 2; + *desty = y; + break; case NorthEastGravity: - *destx = x + dw; - *desty = y; - break; + *destx = x + dw; + *desty = y; + break; case WestGravity: - *destx = x; - *desty = y + dh / 2; - break; + *destx = x; + *desty = y + dh / 2; + break; case CenterGravity: - *destx = x + dw / 2; - *desty = y + dh / 2; - break; + *destx = x + dw / 2; + *desty = y + dh / 2; + break; case EastGravity: - *destx = x + dw; - *desty = y + dh / 2; - break; + *destx = x + dw; + *desty = y + dh / 2; + break; case SouthWestGravity: - *destx = x; - *desty = y + dh; - break; + *destx = x; + *desty = y + dh; + break; case SouthGravity: - *destx = x + dw / 2; - *desty = y + dh; - break; + *destx = x + dw / 2; + *desty = y + dh; + break; case SouthEastGravity: - *destx = x + dw; - *desty = y + dh; - break; + *destx = x + dw; + *desty = y + dh; + break; case StaticGravity: - *destx = oldx; - *desty = oldy; - break; + *destx = oldx; + *desty = oldy; + break; default: - *destx = x; - *desty = y; - break; + *destx = x; + *desty = y; + break; } } @@ -1830,59 +1737,54 @@ ResizeChildrenWinSize(WindowPtr pWin, int dx, int dy, int dw, int dh) pScreen = pWin->drawable.pScreen; - for (pSib = pWin->firstChild; pSib; pSib = pSib->nextSib) - { - if (resized && (pSib->winGravity > NorthWestGravity)) - { - int cwsx, cwsy; - - cwsx = pSib->origin.x; - cwsy = pSib->origin.y; - GravityTranslate (cwsx, cwsy, cwsx - dx, cwsy - dy, dw, dh, - pSib->winGravity, &cwsx, &cwsy); - if (cwsx != pSib->origin.x || cwsy != pSib->origin.y) - { - xEvent event; - - event.u.u.type = GravityNotify; - event.u.gravity.window = pSib->drawable.id; - event.u.gravity.x = cwsx - wBorderWidth (pSib); - event.u.gravity.y = cwsy - wBorderWidth (pSib); - DeliverEvents (pSib, &event, 1, NullWindow); - pSib->origin.x = cwsx; - pSib->origin.y = cwsy; - } - } - pSib->drawable.x = pWin->drawable.x + pSib->origin.x; - pSib->drawable.y = pWin->drawable.y + pSib->origin.y; - SetWinSize (pSib); - SetBorderSize (pSib); - (*pScreen->PositionWindow)(pSib, pSib->drawable.x, pSib->drawable.y); - - if ( (pChild = pSib->firstChild) ) - { - while (1) - { - pChild->drawable.x = pChild->parent->drawable.x + - pChild->origin.x; - pChild->drawable.y = pChild->parent->drawable.y + - pChild->origin.y; - SetWinSize (pChild); - SetBorderSize (pChild); - (*pScreen->PositionWindow)(pChild, - pChild->drawable.x, pChild->drawable.y); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - while (!pChild->nextSib && (pChild != pSib)) - pChild = pChild->parent; - if (pChild == pSib) - break; - pChild = pChild->nextSib; - } - } + for (pSib = pWin->firstChild; pSib; pSib = pSib->nextSib) { + if (resized && (pSib->winGravity > NorthWestGravity)) { + int cwsx, cwsy; + + cwsx = pSib->origin.x; + cwsy = pSib->origin.y; + GravityTranslate(cwsx, cwsy, cwsx - dx, cwsy - dy, dw, dh, + pSib->winGravity, &cwsx, &cwsy); + if (cwsx != pSib->origin.x || cwsy != pSib->origin.y) { + xEvent event; + + event.u.u.type = GravityNotify; + event.u.gravity.window = pSib->drawable.id; + event.u.gravity.x = cwsx - wBorderWidth(pSib); + event.u.gravity.y = cwsy - wBorderWidth(pSib); + DeliverEvents(pSib, &event, 1, NullWindow); + pSib->origin.x = cwsx; + pSib->origin.y = cwsy; + } + } + pSib->drawable.x = pWin->drawable.x + pSib->origin.x; + pSib->drawable.y = pWin->drawable.y + pSib->origin.y; + SetWinSize(pSib); + SetBorderSize(pSib); + (*pScreen->PositionWindow) (pSib, pSib->drawable.x, pSib->drawable.y); + + if ((pChild = pSib->firstChild)) { + while (1) { + pChild->drawable.x = pChild->parent->drawable.x + + pChild->origin.x; + pChild->drawable.y = pChild->parent->drawable.y + + pChild->origin.y; + SetWinSize(pChild); + SetBorderSize(pChild); + (*pScreen->PositionWindow) (pChild, + pChild->drawable.x, + pChild->drawable.y); + if (pChild->firstChild) { + pChild = pChild->firstChild; + continue; + } + while (!pChild->nextSib && (pChild != pSib)) + pChild = pChild->parent; + if (pChild == pSib) + break; + pChild = pChild->nextSib; + } + } } } @@ -1916,68 +1818,58 @@ ResizeChildrenWinSize(WindowPtr pWin, int dx, int dy, int dw, int dh) */ static int -IsSiblingAboveMe( - WindowPtr pMe, - WindowPtr pSib) +IsSiblingAboveMe(WindowPtr pMe, WindowPtr pSib) { WindowPtr pWin; pWin = pMe->parent->firstChild; - while (pWin) - { - if (pWin == pSib) - return Above; - else if (pWin == pMe) - return Below; - pWin = pWin->nextSib; + while (pWin) { + if (pWin == pSib) + return Above; + else if (pWin == pMe) + return Below; + pWin = pWin->nextSib; } return Below; } static BoxPtr -WindowExtents( - WindowPtr pWin, - BoxPtr pBox) +WindowExtents(WindowPtr pWin, BoxPtr pBox) { - pBox->x1 = pWin->drawable.x - wBorderWidth (pWin); - pBox->y1 = pWin->drawable.y - wBorderWidth (pWin); - pBox->x2 = pWin->drawable.x + (int)pWin->drawable.width - + wBorderWidth (pWin); - pBox->y2 = pWin->drawable.y + (int)pWin->drawable.height - + wBorderWidth (pWin); + pBox->x1 = pWin->drawable.x - wBorderWidth(pWin); + pBox->y1 = pWin->drawable.y - wBorderWidth(pWin); + pBox->x2 = pWin->drawable.x + (int) pWin->drawable.width + + wBorderWidth(pWin); + pBox->y2 = pWin->drawable.y + (int) pWin->drawable.height + + wBorderWidth(pWin); return pBox; } #define IS_SHAPED(pWin) (wBoundingShape (pWin) != (RegionPtr) NULL) static RegionPtr -MakeBoundingRegion ( - WindowPtr pWin, - BoxPtr pBox) +MakeBoundingRegion(WindowPtr pWin, BoxPtr pBox) { - RegionPtr pRgn = RegionCreate(pBox, 1); - if (wBoundingShape (pWin)) { - RegionTranslate(pRgn, -pWin->origin.x, -pWin->origin.y); - RegionIntersect(pRgn, pRgn, wBoundingShape (pWin)); - RegionTranslate(pRgn, pWin->origin.x, pWin->origin.y); + RegionPtr pRgn = RegionCreate(pBox, 1); + + if (wBoundingShape(pWin)) { + RegionTranslate(pRgn, -pWin->origin.x, -pWin->origin.y); + RegionIntersect(pRgn, pRgn, wBoundingShape(pWin)); + RegionTranslate(pRgn, pWin->origin.x, pWin->origin.y); } return pRgn; } static Bool -ShapeOverlap ( - WindowPtr pWin, - BoxPtr pWinBox, - WindowPtr pSib, - BoxPtr pSibBox) +ShapeOverlap(WindowPtr pWin, BoxPtr pWinBox, WindowPtr pSib, BoxPtr pSibBox) { - RegionPtr pWinRgn, pSibRgn; - Bool ret; + RegionPtr pWinRgn, pSibRgn; + Bool ret; if (!IS_SHAPED(pWin) && !IS_SHAPED(pSib)) - return TRUE; - pWinRgn = MakeBoundingRegion (pWin, pWinBox); - pSibRgn = MakeBoundingRegion (pSib, pSibBox); + return TRUE; + pWinRgn = MakeBoundingRegion(pWin, pWinBox); + pSibRgn = MakeBoundingRegion(pSib, pSibBox); RegionIntersect(pWinRgn, pWinRgn, pSibRgn); ret = RegionNotEmpty(pWinRgn); RegionDestroy(pWinRgn); @@ -1986,48 +1878,39 @@ ShapeOverlap ( } static Bool -AnyWindowOverlapsMe( - WindowPtr pWin, - WindowPtr pHead, - BoxPtr box) +AnyWindowOverlapsMe(WindowPtr pWin, WindowPtr pHead, BoxPtr box) { WindowPtr pSib; BoxRec sboxrec; BoxPtr sbox; - for (pSib = pWin->prevSib; pSib != pHead; pSib = pSib->prevSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) - && ShapeOverlap (pWin, box, pSib, sbox) - ) - return TRUE; - } + for (pSib = pWin->prevSib; pSib != pHead; pSib = pSib->prevSib) { + if (pSib->mapped) { + sbox = WindowExtents(pSib, &sboxrec); + if (BOXES_OVERLAP(sbox, box) + && ShapeOverlap(pWin, box, pSib, sbox) + ) + return TRUE; + } } return FALSE; } static Bool -IOverlapAnyWindow( - WindowPtr pWin, - BoxPtr box) +IOverlapAnyWindow(WindowPtr pWin, BoxPtr box) { WindowPtr pSib; BoxRec sboxrec; BoxPtr sbox; - for (pSib = pWin->nextSib; pSib; pSib = pSib->nextSib) - { - if (pSib->mapped) - { - sbox = WindowExtents(pSib, &sboxrec); - if (BOXES_OVERLAP(sbox, box) - && ShapeOverlap (pWin, box, pSib, sbox) - ) - return TRUE; - } + for (pSib = pWin->nextSib; pSib; pSib = pSib->nextSib) { + if (pSib->mapped) { + sbox = WindowExtents(pSib, &sboxrec); + if (BOXES_OVERLAP(sbox, box) + && ShapeOverlap(pWin, box, pSib, sbox) + ) + return TRUE; + } } return FALSE; } @@ -2061,144 +1944,130 @@ IOverlapAnyWindow( */ static WindowPtr -WhereDoIGoInTheStack( - WindowPtr pWin, - WindowPtr pSib, - short x, - short y, - unsigned short w, - unsigned short h, - int smode) +WhereDoIGoInTheStack(WindowPtr pWin, + WindowPtr pSib, + short x, + short y, unsigned short w, unsigned short h, int smode) { BoxRec box; WindowPtr pHead, pFirst; - if ((pWin == pWin->parent->firstChild) && - (pWin == pWin->parent->lastChild)) - return((WindowPtr ) NULL); + if ((pWin == pWin->parent->firstChild) && (pWin == pWin->parent->lastChild)) + return ((WindowPtr) NULL); pHead = RealChildHead(pWin->parent); pFirst = pHead ? pHead->nextSib : pWin->parent->firstChild; box.x1 = x; box.y1 = y; - box.x2 = x + (int)w; - box.y2 = y + (int)h; - switch (smode) + box.x2 = x + (int) w; + box.y2 = y + (int) h; + switch (smode) { + case Above: + if (pSib) + return pSib; + else if (pWin == pFirst) + return pWin->nextSib; + else + return pFirst; + case Below: + if (pSib) + if (pSib->nextSib != pWin) + return pSib->nextSib; + else + return pWin->nextSib; + else + return NullWindow; + case TopIf: + if ((!pWin->mapped || (pSib && !pSib->mapped))) + return pWin->nextSib; + else if (pSib) { + if ((IsSiblingAboveMe(pWin, pSib) == Above) && + (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT)) + return pFirst; + else + return pWin->nextSib; + } + else if (AnyWindowOverlapsMe(pWin, pHead, &box)) + return pFirst; + else + return pWin->nextSib; + case BottomIf: + if ((!pWin->mapped || (pSib && !pSib->mapped))) + return pWin->nextSib; + else if (pSib) { + if ((IsSiblingAboveMe(pWin, pSib) == Below) && + (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT)) + return NullWindow; + else + return pWin->nextSib; + } + else if (IOverlapAnyWindow(pWin, &box)) + return NullWindow; + else + return pWin->nextSib; + case Opposite: + if ((!pWin->mapped || (pSib && !pSib->mapped))) + return pWin->nextSib; + else if (pSib) { + if (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT) { + if (IsSiblingAboveMe(pWin, pSib) == Above) + return pFirst; + else + return NullWindow; + } + else + return pWin->nextSib; + } + else if (AnyWindowOverlapsMe(pWin, pHead, &box)) { + /* If I'm occluded, I can't possibly be the first child + * if (pWin == pWin->parent->firstChild) + * return pWin->nextSib; + */ + return pFirst; + } + else if (IOverlapAnyWindow(pWin, &box)) + return NullWindow; + else + return pWin->nextSib; + default: { - case Above: - if (pSib) - return pSib; - else if (pWin == pFirst) - return pWin->nextSib; - else - return pFirst; - case Below: - if (pSib) - if (pSib->nextSib != pWin) - return pSib->nextSib; - else - return pWin->nextSib; - else - return NullWindow; - case TopIf: - if ((!pWin->mapped || (pSib && !pSib->mapped))) - return pWin->nextSib; - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Above) && - (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT)) - return pFirst; - else - return pWin->nextSib; - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - return pFirst; - else - return pWin->nextSib; - case BottomIf: - if ((!pWin->mapped || (pSib && !pSib->mapped))) - return pWin->nextSib; - else if (pSib) - { - if ((IsSiblingAboveMe(pWin, pSib) == Below) && - (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT)) - return NullWindow; - else - return pWin->nextSib; - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return pWin->nextSib; - case Opposite: - if ((!pWin->mapped || (pSib && !pSib->mapped))) - return pWin->nextSib; - else if (pSib) - { - if (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT) - { - if (IsSiblingAboveMe(pWin, pSib) == Above) - return pFirst; - else - return NullWindow; - } - else - return pWin->nextSib; - } - else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - { - /* If I'm occluded, I can't possibly be the first child - * if (pWin == pWin->parent->firstChild) - * return pWin->nextSib; - */ - return pFirst; - } - else if (IOverlapAnyWindow(pWin, &box)) - return NullWindow; - else - return pWin->nextSib; - default: - { - /* should never happen; make something up. */ - return pWin->nextSib; - } + /* should never happen; make something up. */ + return pWin->nextSib; + } } } static void -ReflectStackChange( - WindowPtr pWin, - WindowPtr pSib, - VTKind kind) +ReflectStackChange(WindowPtr pWin, WindowPtr pSib, VTKind kind) { /* Note that pSib might be NULL */ - Bool WasViewable = (Bool)pWin->viewable; + Bool WasViewable = (Bool) pWin->viewable; Bool anyMarked; WindowPtr pFirstChange; - WindowPtr pLayerWin; + WindowPtr pLayerWin; ScreenPtr pScreen = pWin->drawable.pScreen; /* if this is a root window, can't be restacked */ if (!pWin->parent) - return; + return; pFirstChange = MoveWindowInStack(pWin, pSib); - if (WasViewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, - &pLayerWin); - if (pLayerWin != pWin) pFirstChange = pLayerWin; - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, kind); - (*pScreen->HandleExposures)(pLayerWin->parent); - } - if (anyMarked && pWin->drawable.pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, kind); + if (WasViewable) { + anyMarked = (*pScreen->MarkOverlappedWindows) (pWin, pFirstChange, + &pLayerWin); + if (pLayerWin != pWin) + pFirstChange = pLayerWin; + if (anyMarked) { + (*pScreen->ValidateTree) (pLayerWin->parent, pFirstChange, kind); + (*pScreen->HandleExposures) (pLayerWin->parent); + } + if (anyMarked && pWin->drawable.pScreen->PostValidateTree) + (*pScreen->PostValidateTree) (pLayerWin->parent, pFirstChange, + kind); } if (pWin->realized) - WindowsRestructured (); + WindowsRestructured(); } /***** @@ -2217,251 +2086,236 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client) Window sibwid = 0; Mask index2, tmask; XID *pVlist; - short x, y, beforeX, beforeY; + short x, y, beforeX, beforeY; unsigned short w = pWin->drawable.width, - h = pWin->drawable.height, - bw = pWin->borderWidth; + h = pWin->drawable.height, bw = pWin->borderWidth; int rc, action, smode = Above; xEvent event; - if ((pWin->drawable.class == InputOnly) && (mask & IllegalInputOnlyConfigureMask)) - return BadMatch; + if ((pWin->drawable.class == InputOnly) && + (mask & IllegalInputOnlyConfigureMask)) + return BadMatch; if ((mask & CWSibling) && !(mask & CWStackMode)) - return BadMatch; + return BadMatch; pVlist = vlist; - if (pParent) - { - x = pWin->drawable.x - pParent->drawable.x - (int)bw; - y = pWin->drawable.y - pParent->drawable.y - (int)bw; + if (pParent) { + x = pWin->drawable.x - pParent->drawable.x - (int) bw; + y = pWin->drawable.y - pParent->drawable.y - (int) bw; } - else - { - x = pWin->drawable.x; - y = pWin->drawable.y; + else { + x = pWin->drawable.x; + y = pWin->drawable.y; } beforeX = x; beforeY = y; - action = RESTACK_WIN; - if ((mask & (CWX | CWY)) && (!(mask & (CWHeight | CWWidth)))) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - action = MOVE_WIN; - } - /* or should be resized */ - else if (mask & (CWX | CWY | CWWidth | CWHeight)) - { - GET_INT16(CWX, x); - GET_INT16(CWY, y); - GET_CARD16(CWWidth, w); - GET_CARD16 (CWHeight, h); - if (!w || !h) - { - client->errorValue = 0; - return BadValue; - } - action = RESIZE_WIN; + action = RESTACK_WIN; + if ((mask & (CWX | CWY)) && (!(mask & (CWHeight | CWWidth)))) { + GET_INT16(CWX, x); + GET_INT16(CWY, y); + action = MOVE_WIN; + } + /* or should be resized */ + else if (mask & (CWX | CWY | CWWidth | CWHeight)) { + GET_INT16(CWX, x); + GET_INT16(CWY, y); + GET_CARD16(CWWidth, w); + GET_CARD16(CWHeight, h); + if (!w || !h) { + client->errorValue = 0; + return BadValue; + } + action = RESIZE_WIN; } tmask = mask & ~ChangeMask; - while (tmask) - { - index2 = (Mask)lowbit (tmask); - tmask &= ~index2; - switch (index2) - { - case CWBorderWidth: - GET_CARD16(CWBorderWidth, bw); - break; - case CWSibling: - sibwid = (Window ) *pVlist; - pVlist++; - rc = dixLookupWindow(&pSib, sibwid, client, DixGetAttrAccess); - if (rc != Success) - { - client->errorValue = sibwid; - return rc; - } - if (pSib->parent != pParent) - return BadMatch; - if (pSib == pWin) - return BadMatch; - break; - case CWStackMode: - GET_CARD8(CWStackMode, smode); - if ((smode != TopIf) && (smode != BottomIf) && - (smode != Opposite) && (smode != Above) && (smode != Below)) - { - client->errorValue = smode; - return BadValue; - } - break; - default: - client->errorValue = mask; - return BadValue; - } - } - /* root really can't be reconfigured, so just return */ + while (tmask) { + index2 = (Mask) lowbit(tmask); + tmask &= ~index2; + switch (index2) { + case CWBorderWidth: + GET_CARD16(CWBorderWidth, bw); + break; + case CWSibling: + sibwid = (Window) *pVlist; + pVlist++; + rc = dixLookupWindow(&pSib, sibwid, client, DixGetAttrAccess); + if (rc != Success) { + client->errorValue = sibwid; + return rc; + } + if (pSib->parent != pParent) + return BadMatch; + if (pSib == pWin) + return BadMatch; + break; + case CWStackMode: + GET_CARD8(CWStackMode, smode); + if ((smode != TopIf) && (smode != BottomIf) && + (smode != Opposite) && (smode != Above) && (smode != Below)) { + client->errorValue = smode; + return BadValue; + } + break; + default: + client->errorValue = mask; + return BadValue; + } + } + /* root really can't be reconfigured, so just return */ if (!pParent) - return Success; + return Success; - /* Figure out if the window should be moved. Doesnt - make the changes to the window if event sent */ + /* Figure out if the window should be moved. Doesnt + make the changes to the window if event sent */ if (mask & CWStackMode) - pSib = WhereDoIGoInTheStack(pWin, pSib, pParent->drawable.x + x, - pParent->drawable.y + y, - w + (bw << 1), h + (bw << 1), smode); + pSib = WhereDoIGoInTheStack(pWin, pSib, pParent->drawable.x + x, + pParent->drawable.y + y, + w + (bw << 1), h + (bw << 1), smode); else - pSib = pWin->nextSib; - - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) - )) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = ConfigureRequest; - event.u.configureRequest.window = pWin->drawable.id; - if (mask & CWSibling) - event.u.configureRequest.sibling = sibwid; - else - event.u.configureRequest.sibling = None; - if (mask & CWStackMode) - event.u.u.detail = smode; - else - event.u.u.detail = Above; - event.u.configureRequest.x = x; - event.u.configureRequest.y = y; + pSib = pWin->nextSib; + + if ((!pWin->overrideRedirect) && (RedirectSend(pParent) + )) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = ConfigureRequest; + event.u.configureRequest.window = pWin->drawable.id; + if (mask & CWSibling) + event.u.configureRequest.sibling = sibwid; + else + event.u.configureRequest.sibling = None; + if (mask & CWStackMode) + event.u.u.detail = smode; + else + event.u.u.detail = Above; + event.u.configureRequest.x = x; + event.u.configureRequest.y = y; #ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { + if (!noPanoramiXExtension && (!pParent || !pParent->parent)) { event.u.configureRequest.x += screenInfo.screens[0]->x; event.u.configureRequest.y += screenInfo.screens[0]->y; - } + } #endif - event.u.configureRequest.width = w; - event.u.configureRequest.height = h; - event.u.configureRequest.borderWidth = bw; - event.u.configureRequest.valueMask = mask; - event.u.configureRequest.parent = pParent->drawable.id; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return Success; + event.u.configureRequest.width = w; + event.u.configureRequest.height = h; + event.u.configureRequest.borderWidth = bw; + event.u.configureRequest.valueMask = mask; + event.u.configureRequest.parent = pParent->drawable.id; + if (MaybeDeliverEventsToClient(pParent, &event, 1, + SubstructureRedirectMask, client) == 1) + return Success; } - if (action == RESIZE_WIN) - { - Bool size_change = (w != pWin->drawable.width) - || (h != pWin->drawable.height); - if (size_change && ((pWin->eventMask|wOtherEventMasks(pWin)) & ResizeRedirectMask)) - { - xEvent eventT; - memset(&eventT, 0, sizeof(xEvent)); - eventT.u.u.type = ResizeRequest; - eventT.u.resizeRequest.window = pWin->drawable.id; - eventT.u.resizeRequest.width = w; - eventT.u.resizeRequest.height = h; - if (MaybeDeliverEventsToClient(pWin, &eventT, 1, - ResizeRedirectMask, client) == 1) - { - /* if event is delivered, leave the actual size alone. */ - w = pWin->drawable.width; - h = pWin->drawable.height; - size_change = FALSE; - } - } - if (!size_change) - { - if (mask & (CWX | CWY)) - action = MOVE_WIN; - else if (mask & (CWStackMode | CWBorderWidth)) - action = RESTACK_WIN; - else /* really nothing to do */ - return(Success) ; - } + if (action == RESIZE_WIN) { + Bool size_change = (w != pWin->drawable.width) + || (h != pWin->drawable.height); + + if (size_change && + ((pWin->eventMask | wOtherEventMasks(pWin)) & ResizeRedirectMask)) { + xEvent eventT; + + memset(&eventT, 0, sizeof(xEvent)); + eventT.u.u.type = ResizeRequest; + eventT.u.resizeRequest.window = pWin->drawable.id; + eventT.u.resizeRequest.width = w; + eventT.u.resizeRequest.height = h; + if (MaybeDeliverEventsToClient(pWin, &eventT, 1, + ResizeRedirectMask, client) == 1) { + /* if event is delivered, leave the actual size alone. */ + w = pWin->drawable.width; + h = pWin->drawable.height; + size_change = FALSE; + } + } + if (!size_change) { + if (mask & (CWX | CWY)) + action = MOVE_WIN; + else if (mask & (CWStackMode | CWBorderWidth)) + action = RESTACK_WIN; + else /* really nothing to do */ + return (Success); + } } if (action == RESIZE_WIN) - /* we've already checked whether there's really a size change */ - goto ActuallyDoSomething; + /* we've already checked whether there's really a size change */ + goto ActuallyDoSomething; if ((mask & CWX) && (x != beforeX)) - goto ActuallyDoSomething; + goto ActuallyDoSomething; if ((mask & CWY) && (y != beforeY)) - goto ActuallyDoSomething; - if ((mask & CWBorderWidth) && (bw != wBorderWidth (pWin))) - goto ActuallyDoSomething; - if (mask & CWStackMode) - { + goto ActuallyDoSomething; + if ((mask & CWBorderWidth) && (bw != wBorderWidth(pWin))) + goto ActuallyDoSomething; + if (mask & CWStackMode) { #ifndef ROOTLESS /* See above for why we always reorder in rootless mode. */ - if (pWin->nextSib != pSib) + if (pWin->nextSib != pSib) #endif - goto ActuallyDoSomething; + goto ActuallyDoSomething; } return Success; -ActuallyDoSomething: - if (pWin->drawable.pScreen->ConfigNotify) - { - int ret; - ret = (*pWin->drawable.pScreen->ConfigNotify)(pWin, x, y, w, h, bw, pSib); - if (ret) { - client->errorValue = 0; - return ret; - } + ActuallyDoSomething: + if (pWin->drawable.pScreen->ConfigNotify) { + int ret; + + ret = + (*pWin->drawable.pScreen->ConfigNotify) (pWin, x, y, w, h, bw, + pSib); + if (ret) { + client->errorValue = 0; + return ret; + } } - if (SubStrSend(pWin, pParent)) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; - if (pSib) - event.u.configureNotify.aboveSibling = pSib->drawable.id; - else - event.u.configureNotify.aboveSibling = None; - event.u.configureNotify.x = x; - event.u.configureNotify.y = y; + if (SubStrSend(pWin, pParent)) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = ConfigureNotify; + event.u.configureNotify.window = pWin->drawable.id; + if (pSib) + event.u.configureNotify.aboveSibling = pSib->drawable.id; + else + event.u.configureNotify.aboveSibling = None; + event.u.configureNotify.x = x; + event.u.configureNotify.y = y; #ifdef PANORAMIX - if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureNotify.x += screenInfo.screens[0]->x; - event.u.configureNotify.y += screenInfo.screens[0]->y; - } + if (!noPanoramiXExtension && (!pParent || !pParent->parent)) { + event.u.configureNotify.x += screenInfo.screens[0]->x; + event.u.configureNotify.y += screenInfo.screens[0]->y; + } #endif - event.u.configureNotify.width = w; - event.u.configureNotify.height = h; - event.u.configureNotify.borderWidth = bw; - event.u.configureNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (mask & CWBorderWidth) - { - if (action == RESTACK_WIN) - { - action = MOVE_WIN; - pWin->borderWidth = bw; - } - else if ((action == MOVE_WIN) && - (beforeX + wBorderWidth (pWin) == x + (int)bw) && - (beforeY + wBorderWidth (pWin) == y + (int)bw)) - { - action = REBORDER_WIN; - (*pWin->drawable.pScreen->ChangeBorderWidth)(pWin, bw); - } - else - pWin->borderWidth = bw; + event.u.configureNotify.width = w; + event.u.configureNotify.height = h; + event.u.configureNotify.borderWidth = bw; + event.u.configureNotify.override = pWin->overrideRedirect; + DeliverEvents(pWin, &event, 1, NullWindow); + } + if (mask & CWBorderWidth) { + if (action == RESTACK_WIN) { + action = MOVE_WIN; + pWin->borderWidth = bw; + } + else if ((action == MOVE_WIN) && + (beforeX + wBorderWidth(pWin) == x + (int) bw) && + (beforeY + wBorderWidth(pWin) == y + (int) bw)) { + action = REBORDER_WIN; + (*pWin->drawable.pScreen->ChangeBorderWidth) (pWin, bw); + } + else + pWin->borderWidth = bw; } if (action == MOVE_WIN) - (*pWin->drawable.pScreen->MoveWindow)(pWin, x, y, pSib, - (mask & CWBorderWidth) ? VTOther : VTMove); + (*pWin->drawable.pScreen->MoveWindow) (pWin, x, y, pSib, + (mask & CWBorderWidth) ? VTOther + : VTMove); else if (action == RESIZE_WIN) - (*pWin->drawable.pScreen->ResizeWindow)(pWin, x, y, w, h, pSib); + (*pWin->drawable.pScreen->ResizeWindow) (pWin, x, y, w, h, pSib); else if (mask & CWStackMode) - ReflectStackChange(pWin, pSib, VTOther); + ReflectStackChange(pWin, pSib, VTOther); if (action != RESTACK_WIN) - CheckCursorConfinement(pWin); + CheckCursorConfinement(pWin); return Success; #undef RESTACK_WIN #undef MOVE_WIN @@ -2469,7 +2323,6 @@ ActuallyDoSomething: #undef REBORDER_WIN } - /****** * * CirculateWindow @@ -2489,63 +2342,58 @@ CirculateWindow(WindowPtr pParent, int direction, ClientPtr client) pHead = RealChildHead(pParent); pFirst = pHead ? pHead->nextSib : pParent->firstChild; - if (direction == RaiseLowest) - { - for (pWin = pParent->lastChild; - (pWin != pHead) && - !(pWin->mapped && - AnyWindowOverlapsMe(pWin, pHead, WindowExtents(pWin, &box))); - pWin = pWin->prevSib) ; - if (pWin == pHead) - return Success; + if (direction == RaiseLowest) { + for (pWin = pParent->lastChild; + (pWin != pHead) && + !(pWin->mapped && + AnyWindowOverlapsMe(pWin, pHead, WindowExtents(pWin, &box))); + pWin = pWin->prevSib); + if (pWin == pHead) + return Success; } - else - { - for (pWin = pFirst; - pWin && - !(pWin->mapped && - IOverlapAnyWindow(pWin, WindowExtents(pWin, &box))); - pWin = pWin->nextSib) ; - if (!pWin) - return Success; + else { + for (pWin = pFirst; + pWin && + !(pWin->mapped && + IOverlapAnyWindow(pWin, WindowExtents(pWin, &box))); + pWin = pWin->nextSib); + if (!pWin) + return Success; } event.u.circulate.window = pWin->drawable.id; event.u.circulate.parent = pParent->drawable.id; event.u.circulate.event = pParent->drawable.id; if (direction == RaiseLowest) - event.u.circulate.place = PlaceOnTop; + event.u.circulate.place = PlaceOnTop; else - event.u.circulate.place = PlaceOnBottom; + event.u.circulate.place = PlaceOnBottom; - if (RedirectSend(pParent)) - { - event.u.u.type = CirculateRequest; - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return Success; + if (RedirectSend(pParent)) { + event.u.u.type = CirculateRequest; + if (MaybeDeliverEventsToClient(pParent, &event, 1, + SubstructureRedirectMask, client) == 1) + return Success; } event.u.u.type = CirculateNotify; DeliverEvents(pWin, &event, 1, NullWindow); ReflectStackChange(pWin, - (direction == RaiseLowest) ? pFirst : NullWindow, - VTStack); + (direction == RaiseLowest) ? pFirst : NullWindow, + VTStack); return Success; } static int -CompareWIDs( - WindowPtr pWin, - pointer value) /* must conform to VisitWindowProcPtr */ -{ - Window *wid = (Window *)value; +CompareWIDs(WindowPtr pWin, pointer value) +{ /* must conform to VisitWindowProcPtr */ + Window *wid = (Window *) value; if (pWin->drawable.id == *wid) - return WT_STOPWALKING; + return WT_STOPWALKING; else - return WT_WALKCHILDREN; + return WT_WALKCHILDREN; } /***** @@ -2557,19 +2405,20 @@ ReparentWindow(WindowPtr pWin, WindowPtr pParent, int x, int y, ClientPtr client) { WindowPtr pPrev, pPriorParent; - Bool WasMapped = (Bool)(pWin->mapped); + Bool WasMapped = (Bool) (pWin->mapped); xEvent event; - int bw = wBorderWidth (pWin); + int bw = wBorderWidth(pWin); ScreenPtr pScreen; pScreen = pWin->drawable.pScreen; - if (TraverseTree(pWin, CompareWIDs, (pointer)&pParent->drawable.id) == WT_STOPWALKING) - return BadMatch; + if (TraverseTree(pWin, CompareWIDs, (pointer) &pParent->drawable.id) == + WT_STOPWALKING) + return BadMatch; if (!MakeWindowOptional(pWin)) - return BadAlloc; + return BadAlloc; if (WasMapped) - UnmapWindow(pWin, FALSE); + UnmapWindow(pWin, FALSE); memset(&event, 0, sizeof(xEvent)); event.u.u.type = ReparentNotify; @@ -2578,9 +2427,9 @@ ReparentWindow(WindowPtr pWin, WindowPtr pParent, event.u.reparent.x = x; event.u.reparent.y = y; #ifdef PANORAMIX - if(!noPanoramiXExtension && !pParent->parent) { - event.u.reparent.x += screenInfo.screens[0]->x; - event.u.reparent.y += screenInfo.screens[0]->y; + if (!noPanoramiXExtension && !pParent->parent) { + event.u.reparent.x += screenInfo.screens[0]->x; + event.u.reparent.y += screenInfo.screens[0]->y; } #endif event.u.reparent.override = pWin->overrideRedirect; @@ -2590,37 +2439,35 @@ ReparentWindow(WindowPtr pWin, WindowPtr pParent, pPriorParent = pPrev = pWin->parent; if (pPrev->firstChild == pWin) - pPrev->firstChild = pWin->nextSib; + pPrev->firstChild = pWin->nextSib; if (pPrev->lastChild == pWin) - pPrev->lastChild = pWin->prevSib; + pPrev->lastChild = pWin->prevSib; if (pWin->nextSib) - pWin->nextSib->prevSib = pWin->prevSib; + pWin->nextSib->prevSib = pWin->prevSib; if (pWin->prevSib) - pWin->prevSib->nextSib = pWin->nextSib; + pWin->prevSib->nextSib = pWin->nextSib; /* insert at begining of pParent */ pWin->parent = pParent; pPrev = RealChildHead(pParent); - if (pPrev) - { - pWin->nextSib = pPrev->nextSib; - if (pPrev->nextSib) - pPrev->nextSib->prevSib = pWin; - else - pParent->lastChild = pWin; - pPrev->nextSib = pWin; - pWin->prevSib = pPrev; + if (pPrev) { + pWin->nextSib = pPrev->nextSib; + if (pPrev->nextSib) + pPrev->nextSib->prevSib = pWin; + else + pParent->lastChild = pWin; + pPrev->nextSib = pWin; + pWin->prevSib = pPrev; } - else - { - pWin->nextSib = pParent->firstChild; - pWin->prevSib = NullWindow; - if (pParent->firstChild) - pParent->firstChild->prevSib = pWin; - else - pParent->lastChild = pWin; - pParent->firstChild = pWin; + else { + pWin->nextSib = pParent->firstChild; + pWin->prevSib = NullWindow; + if (pParent->firstChild) + pParent->firstChild->prevSib = pWin; + else + pParent->lastChild = pWin; + pParent->firstChild = pWin; } pWin->origin.x = x + bw; @@ -2629,18 +2476,18 @@ ReparentWindow(WindowPtr pWin, WindowPtr pParent, pWin->drawable.y = y + bw + pParent->drawable.y; /* clip to parent */ - SetWinSize (pWin); - SetBorderSize (pWin); + SetWinSize(pWin); + SetBorderSize(pWin); if (pScreen->ReparentWindow) - (*pScreen->ReparentWindow)(pWin, pPriorParent); - (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y); + (*pScreen->ReparentWindow) (pWin, pPriorParent); + (*pScreen->PositionWindow) (pWin, pWin->drawable.x, pWin->drawable.y); ResizeChildrenWinSize(pWin, 0, 0, 0, 0); CheckWindowOptionalNeed(pWin); if (WasMapped) - MapWindow(pWin, client); + MapWindow(pWin, client); RecalculateDeliverableEvents(pWin); return Success; } @@ -2653,24 +2500,21 @@ RealizeTree(WindowPtr pWin) Realize = pWin->drawable.pScreen->RealizeWindow; pChild = pWin; - while (1) - { - if (pChild->mapped) - { - pChild->realized = TRUE; - pChild->viewable = (pChild->drawable.class == InputOutput); - (* Realize)(pChild); - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; + while (1) { + if (pChild->mapped) { + pChild->realized = TRUE; + pChild->viewable = (pChild->drawable.class == InputOutput); + (*Realize) (pChild); + if (pChild->firstChild) { + pChild = pChild->firstChild; + continue; + } + } + while (!pChild->nextSib && (pChild != pWin)) + pChild = pChild->parent; + if (pChild == pWin) + return; + pChild = pChild->nextSib; } } @@ -2679,15 +2523,15 @@ static WindowPtr windowDisableMapUnmapEvents; void DisableMapUnmapEvents(WindowPtr pWin) { - assert (windowDisableMapUnmapEvents == NULL); - + assert(windowDisableMapUnmapEvents == NULL); + windowDisableMapUnmapEvents = pWin; } void EnableMapUnmapEvents(WindowPtr pWin) { - assert (windowDisableMapUnmapEvents != NULL); + assert(windowDisableMapUnmapEvents != NULL); windowDisableMapUnmapEvents = NULL; } @@ -2712,86 +2556,80 @@ MapWindow(WindowPtr pWin, ClientPtr client) ScreenPtr pScreen; WindowPtr pParent; - WindowPtr pLayerWin; + WindowPtr pLayerWin; if (pWin->mapped) - return Success; + return Success; /* general check for permission to map window */ if (XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, RT_WINDOW, - pWin, RT_NONE, NULL, DixShowAccess) != Success) - return Success; + pWin, RT_NONE, NULL, DixShowAccess) != Success) + return Success; pScreen = pWin->drawable.pScreen; - if ( (pParent = pWin->parent) ) - { - xEvent event; - Bool anyMarked; - - if ((!pWin->overrideRedirect) && - (RedirectSend(pParent) - )) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - return Success; - } - - pWin->mapped = TRUE; - if (SubStrSend(pWin, pParent) && MapUnmapEventsEnabled(pWin)) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pParent->realized) - return Success; - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, - &pLayerWin); - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, VTMap); - } - WindowsRestructured (); + if ((pParent = pWin->parent)) { + xEvent event; + Bool anyMarked; + + if ((!pWin->overrideRedirect) && (RedirectSend(pParent) + )) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = MapRequest; + event.u.mapRequest.window = pWin->drawable.id; + event.u.mapRequest.parent = pParent->drawable.id; + + if (MaybeDeliverEventsToClient(pParent, &event, 1, + SubstructureRedirectMask, + client) == 1) + return Success; + } + + pWin->mapped = TRUE; + if (SubStrSend(pWin, pParent) && MapUnmapEventsEnabled(pWin)) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = MapNotify; + event.u.mapNotify.window = pWin->drawable.id; + event.u.mapNotify.override = pWin->overrideRedirect; + DeliverEvents(pWin, &event, 1, NullWindow); + } + + if (!pParent->realized) + return Success; + RealizeTree(pWin); + if (pWin->viewable) { + anyMarked = (*pScreen->MarkOverlappedWindows) (pWin, pWin, + &pLayerWin); + if (anyMarked) { + (*pScreen->ValidateTree) (pLayerWin->parent, pLayerWin, VTMap); + (*pScreen->HandleExposures) (pLayerWin->parent); + } + if (anyMarked && pScreen->PostValidateTree) + (*pScreen->PostValidateTree) (pLayerWin->parent, pLayerWin, + VTMap); + } + WindowsRestructured(); } - else - { - RegionRec temp; - - pWin->mapped = TRUE; - pWin->realized = TRUE; /* for roots */ - pWin->viewable = pWin->drawable.class == InputOutput; - /* We SHOULD check for an error value here XXX */ - (*pScreen->RealizeWindow)(pWin); - if (pScreen->ClipNotify) - (*pScreen->ClipNotify) (pWin, 0, 0); - if (pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(NullWindow, pWin, VTMap); - RegionNull(&temp); - RegionCopy(&temp, &pWin->clipList); - (*pScreen->WindowExposures) (pWin, &temp, NullRegion); - RegionUninit(&temp); + else { + RegionRec temp; + + pWin->mapped = TRUE; + pWin->realized = TRUE; /* for roots */ + pWin->viewable = pWin->drawable.class == InputOutput; + /* We SHOULD check for an error value here XXX */ + (*pScreen->RealizeWindow) (pWin); + if (pScreen->ClipNotify) + (*pScreen->ClipNotify) (pWin, 0, 0); + if (pScreen->PostValidateTree) + (*pScreen->PostValidateTree) (NullWindow, pWin, VTMap); + RegionNull(&temp); + RegionCopy(&temp, &pWin->clipList); + (*pScreen->WindowExposures) (pWin, &temp, NullRegion); + RegionUninit(&temp); } return Success; } - /***** * MapSubwindows * Performs a MapWindow all unmapped children of the window, in top @@ -2801,84 +2639,76 @@ MapWindow(WindowPtr pWin, ClientPtr client) void MapSubwindows(WindowPtr pParent, ClientPtr client) { - WindowPtr pWin; - WindowPtr pFirstMapped = NullWindow; - ScreenPtr pScreen; - Mask parentRedirect; - Mask parentNotify; - xEvent event; - Bool anyMarked; - WindowPtr pLayerWin; + WindowPtr pWin; + WindowPtr pFirstMapped = NullWindow; + ScreenPtr pScreen; + Mask parentRedirect; + Mask parentNotify; + xEvent event; + Bool anyMarked; + WindowPtr pLayerWin; pScreen = pParent->drawable.pScreen; parentRedirect = RedirectSend(pParent); parentNotify = SubSend(pParent); anyMarked = FALSE; - for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) - { - if (!pWin->mapped) - { - if (parentRedirect && !pWin->overrideRedirect) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = MapRequest; - event.u.mapRequest.window = pWin->drawable.id; - event.u.mapRequest.parent = pParent->drawable.id; - - if (MaybeDeliverEventsToClient(pParent, &event, 1, - SubstructureRedirectMask, client) == 1) - continue; - } - - pWin->mapped = TRUE; - if (parentNotify || StrSend(pWin)) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = MapNotify; - event.u.mapNotify.window = pWin->drawable.id; - event.u.mapNotify.override = pWin->overrideRedirect; - DeliverEvents(pWin, &event, 1, NullWindow); - } - - if (!pFirstMapped) - pFirstMapped = pWin; - if (pParent->realized) - { - RealizeTree(pWin); - if (pWin->viewable) - { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, - (WindowPtr *)NULL); - } - } - } - } - - if (pFirstMapped) - { - pLayerWin = (*pScreen->GetLayerWindow)(pParent); - if (pLayerWin->parent != pParent) { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pLayerWin, - pLayerWin, - (WindowPtr *)NULL); - pFirstMapped = pLayerWin; - } - if (anyMarked) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pFirstMapped, VTMap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } + for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) { + if (!pWin->mapped) { + if (parentRedirect && !pWin->overrideRedirect) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = MapRequest; + event.u.mapRequest.window = pWin->drawable.id; + event.u.mapRequest.parent = pParent->drawable.id; + + if (MaybeDeliverEventsToClient(pParent, &event, 1, + SubstructureRedirectMask, + client) == 1) + continue; + } + + pWin->mapped = TRUE; + if (parentNotify || StrSend(pWin)) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = MapNotify; + event.u.mapNotify.window = pWin->drawable.id; + event.u.mapNotify.override = pWin->overrideRedirect; + DeliverEvents(pWin, &event, 1, NullWindow); + } + + if (!pFirstMapped) + pFirstMapped = pWin; + if (pParent->realized) { + RealizeTree(pWin); + if (pWin->viewable) { + anyMarked |= (*pScreen->MarkOverlappedWindows) (pWin, pWin, + (WindowPtr + *) NULL); + } + } + } + } + + if (pFirstMapped) { + pLayerWin = (*pScreen->GetLayerWindow) (pParent); + if (pLayerWin->parent != pParent) { + anyMarked |= (*pScreen->MarkOverlappedWindows) (pLayerWin, + pLayerWin, + (WindowPtr *) NULL); + pFirstMapped = pLayerWin; + } + if (anyMarked) { + (*pScreen->ValidateTree) (pLayerWin->parent, pFirstMapped, VTMap); + (*pScreen->HandleExposures) (pLayerWin->parent); + } if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstMapped, - VTMap); - WindowsRestructured (); + (*pScreen->PostValidateTree) (pLayerWin->parent, pFirstMapped, + VTMap); + WindowsRestructured(); } } static void -UnrealizeTree( - WindowPtr pWin, - Bool fromConfigure) +UnrealizeTree(WindowPtr pWin, Bool fromConfigure) { WindowPtr pChild; UnrealizeWindowProcPtr Unrealize; @@ -2887,42 +2717,40 @@ UnrealizeTree( Unrealize = pWin->drawable.pScreen->UnrealizeWindow; MarkUnrealizedWindow = pWin->drawable.pScreen->MarkUnrealizedWindow; pChild = pWin; - while (1) - { - if (pChild->realized) - { - pChild->realized = FALSE; - pChild->visibility = VisibilityNotViewable; + while (1) { + if (pChild->realized) { + pChild->realized = FALSE; + pChild->visibility = VisibilityNotViewable; #ifdef PANORAMIX - if(!noPanoramiXExtension && !pChild->drawable.pScreen->myNum) { - PanoramiXRes *win; - int rc = dixLookupResourceByType((pointer *)&win, - pChild->drawable.id, XRT_WINDOW, - serverClient, DixWriteAccess); - if (rc == Success) - win->u.win.visibility = VisibilityNotViewable; - } + if (!noPanoramiXExtension && !pChild->drawable.pScreen->myNum) { + PanoramiXRes *win; + int rc = dixLookupResourceByType((pointer *) &win, + pChild->drawable.id, + XRT_WINDOW, + serverClient, DixWriteAccess); + + if (rc == Success) + win->u.win.visibility = VisibilityNotViewable; + } #endif - (* Unrealize)(pChild); - if (MapUnmapEventsEnabled(pWin)) - DeleteWindowFromAnyEvents(pChild, FALSE); - if (pChild->viewable) - { - pChild->viewable = FALSE; - (* MarkUnrealizedWindow)(pChild, pWin, fromConfigure); - pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER; - } - if (pChild->firstChild) - { - pChild = pChild->firstChild; - continue; - } - } - while (!pChild->nextSib && (pChild != pWin)) - pChild = pChild->parent; - if (pChild == pWin) - return; - pChild = pChild->nextSib; + (*Unrealize) (pChild); + if (MapUnmapEventsEnabled(pWin)) + DeleteWindowFromAnyEvents(pChild, FALSE); + if (pChild->viewable) { + pChild->viewable = FALSE; + (*MarkUnrealizedWindow) (pChild, pWin, fromConfigure); + pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER; + } + if (pChild->firstChild) { + pChild = pChild->firstChild; + continue; + } + } + while (!pChild->nextSib && (pChild != pWin)) + pChild = pChild->parent; + if (pChild == pWin) + return; + pChild = pChild->nextSib; } } @@ -2938,43 +2766,39 @@ UnmapWindow(WindowPtr pWin, Bool fromConfigure) { WindowPtr pParent; xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; + Bool wasRealized = (Bool) pWin->realized; + Bool wasViewable = (Bool) pWin->viewable; ScreenPtr pScreen = pWin->drawable.pScreen; WindowPtr pLayerWin = pWin; if ((!pWin->mapped) || (!(pParent = pWin->parent))) - return Success; - if (SubStrSend(pWin, pParent) && MapUnmapEventsEnabled(pWin)) - { - memset(&event, 0, sizeof(xEvent)); - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pWin->drawable.id; - event.u.unmapNotify.fromConfigure = fromConfigure; - DeliverEvents(pWin, &event, 1, NullWindow); - } - if (wasViewable && !fromConfigure) - { - pWin->valdata = UnmapValData; - (*pScreen->MarkOverlappedWindows)(pWin, pWin->nextSib, &pLayerWin); - (*pScreen->MarkWindow)(pLayerWin->parent); + return Success; + if (SubStrSend(pWin, pParent) && MapUnmapEventsEnabled(pWin)) { + memset(&event, 0, sizeof(xEvent)); + event.u.u.type = UnmapNotify; + event.u.unmapNotify.window = pWin->drawable.id; + event.u.unmapNotify.fromConfigure = fromConfigure; + DeliverEvents(pWin, &event, 1, NullWindow); + } + if (wasViewable && !fromConfigure) { + pWin->valdata = UnmapValData; + (*pScreen->MarkOverlappedWindows) (pWin, pWin->nextSib, &pLayerWin); + (*pScreen->MarkWindow) (pLayerWin->parent); } pWin->mapped = FALSE; if (wasRealized) - UnrealizeTree(pWin, fromConfigure); - if (wasViewable) - { - if (!fromConfigure) - { - (*pScreen->ValidateTree)(pLayerWin->parent, pWin, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } - if (!fromConfigure && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pWin, VTUnmap); + UnrealizeTree(pWin, fromConfigure); + if (wasViewable) { + if (!fromConfigure) { + (*pScreen->ValidateTree) (pLayerWin->parent, pWin, VTUnmap); + (*pScreen->HandleExposures) (pLayerWin->parent); + } + if (!fromConfigure && pScreen->PostValidateTree) + (*pScreen->PostValidateTree) (pLayerWin->parent, pWin, VTUnmap); } if (wasRealized && !fromConfigure) { - WindowsRestructured (); - WindowGone(pWin); + WindowsRestructured(); + WindowGone(pWin); } return Success; } @@ -2990,125 +2814,114 @@ UnmapSubwindows(WindowPtr pWin) { WindowPtr pChild, pHead; xEvent event; - Bool wasRealized = (Bool)pWin->realized; - Bool wasViewable = (Bool)pWin->viewable; + Bool wasRealized = (Bool) pWin->realized; + Bool wasViewable = (Bool) pWin->viewable; Bool anyMarked = FALSE; Mask parentNotify; WindowPtr pLayerWin = NULL; ScreenPtr pScreen = pWin->drawable.pScreen; if (!pWin->firstChild) - return; + return; parentNotify = SubSend(pWin); pHead = RealChildHead(pWin); if (wasViewable) - pLayerWin = (*pScreen->GetLayerWindow)(pWin); - - for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) - { - if (pChild->mapped) - { - if (parentNotify || StrSend(pChild)) - { - event.u.u.type = UnmapNotify; - event.u.unmapNotify.window = pChild->drawable.id; - event.u.unmapNotify.fromConfigure = xFalse; - DeliverEvents(pChild, &event, 1, NullWindow); - } - if (pChild->viewable) - { - pChild->valdata = UnmapValData; - anyMarked = TRUE; - } - pChild->mapped = FALSE; - if (pChild->realized) - UnrealizeTree(pChild, FALSE); - if (wasViewable) - { - } - } + pLayerWin = (*pScreen->GetLayerWindow) (pWin); + + for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) { + if (pChild->mapped) { + if (parentNotify || StrSend(pChild)) { + event.u.u.type = UnmapNotify; + event.u.unmapNotify.window = pChild->drawable.id; + event.u.unmapNotify.fromConfigure = xFalse; + DeliverEvents(pChild, &event, 1, NullWindow); + } + if (pChild->viewable) { + pChild->valdata = UnmapValData; + anyMarked = TRUE; + } + pChild->mapped = FALSE; + if (pChild->realized) + UnrealizeTree(pChild, FALSE); + if (wasViewable) { + } + } } - if (wasViewable) - { - if (anyMarked) - { - if (pLayerWin->parent == pWin) - (*pScreen->MarkWindow)(pWin); - else - { - WindowPtr ptmp; - (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin, - (WindowPtr *)NULL); - (*pScreen->MarkWindow)(pLayerWin->parent); - - /* Windows between pWin and pLayerWin may not have been marked */ - ptmp = pWin; - - while (ptmp != pLayerWin->parent) - { - (*pScreen->MarkWindow)(ptmp); - ptmp = ptmp->parent; - } + if (wasViewable) { + if (anyMarked) { + if (pLayerWin->parent == pWin) + (*pScreen->MarkWindow) (pWin); + else { + WindowPtr ptmp; + + (*pScreen->MarkOverlappedWindows) (pWin, pLayerWin, + (WindowPtr *) NULL); + (*pScreen->MarkWindow) (pLayerWin->parent); + + /* Windows between pWin and pLayerWin may not have been marked */ + ptmp = pWin; + + while (ptmp != pLayerWin->parent) { + (*pScreen->MarkWindow) (ptmp); + ptmp = ptmp->parent; + } pHead = pWin->firstChild; - } - (*pScreen->ValidateTree)(pLayerWin->parent, pHead, VTUnmap); - (*pScreen->HandleExposures)(pLayerWin->parent); - } - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pLayerWin->parent, pHead, VTUnmap); + } + (*pScreen->ValidateTree) (pLayerWin->parent, pHead, VTUnmap); + (*pScreen->HandleExposures) (pLayerWin->parent); + } + if (anyMarked && pScreen->PostValidateTree) + (*pScreen->PostValidateTree) (pLayerWin->parent, pHead, VTUnmap); } if (wasRealized) { - WindowsRestructured (); - WindowGone(pWin); + WindowsRestructured(); + WindowGone(pWin); } } - void HandleSaveSet(ClientPtr client) { WindowPtr pParent, pWin; int j; - for (j=0; j<client->numSaved; j++) - { - pWin = SaveSetWindow(client->saveSet[j]); + for (j = 0; j < client->numSaved; j++) { + pWin = SaveSetWindow(client->saveSet[j]); #ifdef XFIXES - if (SaveSetToRoot(client->saveSet[j])) - pParent = pWin->drawable.pScreen->root; - else + if (SaveSetToRoot(client->saveSet[j])) + pParent = pWin->drawable.pScreen->root; + else #endif - { - pParent = pWin->parent; - while (pParent && (wClient (pParent) == client)) - pParent = pParent->parent; - } - if (pParent) - { - if (pParent != pWin->parent) - { + { + pParent = pWin->parent; + while (pParent && (wClient(pParent) == client)) + pParent = pParent->parent; + } + if (pParent) { + if (pParent != pWin->parent) { #ifdef XFIXES - /* unmap first so that ReparentWindow doesn't remap */ - if (!SaveSetShouldMap (client->saveSet[j])) - UnmapWindow(pWin, FALSE); + /* unmap first so that ReparentWindow doesn't remap */ + if (!SaveSetShouldMap(client->saveSet[j])) + UnmapWindow(pWin, FALSE); #endif - ReparentWindow(pWin, pParent, - pWin->drawable.x - wBorderWidth (pWin) - pParent->drawable.x, - pWin->drawable.y - wBorderWidth (pWin) - pParent->drawable.y, - client); - if(!pWin->realized && pWin->mapped) - pWin->mapped = FALSE; - } + ReparentWindow(pWin, pParent, + pWin->drawable.x - wBorderWidth(pWin) - + pParent->drawable.x, + pWin->drawable.y - wBorderWidth(pWin) - + pParent->drawable.y, client); + if (!pWin->realized && pWin->mapped) + pWin->mapped = FALSE; + } #ifdef XFIXES - if (SaveSetShouldMap (client->saveSet[j])) + if (SaveSetShouldMap(client->saveSet[j])) #endif - MapWindow(pWin, client); - } + MapWindow(pWin, client); + } } free(client->saveSet); client->numSaved = 0; - client->saveSet = (SaveSetElt *)NULL; + client->saveSet = (SaveSetElt *) NULL; } /** @@ -3121,27 +2934,25 @@ PointInWindowIsVisible(WindowPtr pWin, int x, int y) BoxRec box; if (!pWin->realized) - return FALSE; - if (RegionContainsPoint(&pWin->borderClip, - x, y, &box) - && (!wInputShape(pWin) || - RegionContainsPoint(wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box))) - return TRUE; + return FALSE; + if (RegionContainsPoint(&pWin->borderClip, x, y, &box) + && (!wInputShape(pWin) || + RegionContainsPoint(wInputShape(pWin), + x - pWin->drawable.x, + y - pWin->drawable.y, &box))) + return TRUE; return FALSE; } - RegionPtr NotClippedByChildren(WindowPtr pWin) { RegionPtr pReg = RegionCreate(NullBox, 1); + if (pWin->parent || - screenIsSaved != SCREEN_SAVER_ON || - !HasSaverWindow (pWin->drawable.pScreen)) - { - RegionIntersect(pReg, &pWin->borderClip, &pWin->winSize); + screenIsSaved != SCREEN_SAVER_ON || + !HasSaverWindow(pWin->drawable.pScreen)) { + RegionIntersect(pReg, &pWin->borderClip, &pWin->winSize); } return pReg; } @@ -3156,59 +2967,64 @@ SendVisibilityNotify(WindowPtr pWin) return; #ifdef PANORAMIX /* This is not quite correct yet, but it's close */ - if(!noPanoramiXExtension) { - PanoramiXRes *win; - WindowPtr pWin2; - int rc, i, Scrnum; - - Scrnum = pWin->drawable.pScreen->myNum; - - win = PanoramiXFindIDByScrnum(XRT_WINDOW, pWin->drawable.id, Scrnum); - - if(!win || (win->u.win.visibility == visibility)) - return; - - switch(visibility) { - case VisibilityUnobscured: - FOR_NSCREENS(i) { - if(i == Scrnum) continue; - - rc = dixLookupWindow(&pWin2, win->info[i].id, serverClient, - DixWriteAccess); - - if (rc == Success) { - if(pWin2->visibility == VisibilityPartiallyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - case VisibilityPartiallyObscured: - if(Scrnum) { - rc = dixLookupWindow(&pWin2, win->info[0].id, serverClient, - DixWriteAccess); - if (rc == Success) pWin = pWin2; - } - break; - case VisibilityFullyObscured: - FOR_NSCREENS(i) { - if(i == Scrnum) continue; - - rc = dixLookupWindow(&pWin2, win->info[i].id, serverClient, - DixWriteAccess); - - if (rc == Success) { - if(pWin2->visibility != VisibilityFullyObscured) - return; - - if(!i) pWin = pWin2; - } - } - break; - } - - win->u.win.visibility = visibility; + if (!noPanoramiXExtension) { + PanoramiXRes *win; + WindowPtr pWin2; + int rc, i, Scrnum; + + Scrnum = pWin->drawable.pScreen->myNum; + + win = PanoramiXFindIDByScrnum(XRT_WINDOW, pWin->drawable.id, Scrnum); + + if (!win || (win->u.win.visibility == visibility)) + return; + + switch (visibility) { + case VisibilityUnobscured: + FOR_NSCREENS(i) { + if (i == Scrnum) + continue; + + rc = dixLookupWindow(&pWin2, win->info[i].id, serverClient, + DixWriteAccess); + + if (rc == Success) { + if (pWin2->visibility == VisibilityPartiallyObscured) + return; + + if (!i) + pWin = pWin2; + } + } + break; + case VisibilityPartiallyObscured: + if (Scrnum) { + rc = dixLookupWindow(&pWin2, win->info[0].id, serverClient, + DixWriteAccess); + if (rc == Success) + pWin = pWin2; + } + break; + case VisibilityFullyObscured: + FOR_NSCREENS(i) { + if (i == Scrnum) + continue; + + rc = dixLookupWindow(&pWin2, win->info[i].id, serverClient, + DixWriteAccess); + + if (rc == Success) { + if (pWin2->visibility != VisibilityFullyObscured) + return; + + if (!i) + pWin = pWin2; + } + } + break; + } + + win->u.win.visibility = visibility; } #endif @@ -3225,109 +3041,105 @@ dixSaveScreens(ClientPtr client, int on, int mode) { int rc, i, what, type; - if (on == SCREEN_SAVER_FORCER) - { - if (mode == ScreenSaverReset) - what = SCREEN_SAVER_OFF; - else - what = SCREEN_SAVER_ON; - type = what; + if (on == SCREEN_SAVER_FORCER) { + if (mode == ScreenSaverReset) + what = SCREEN_SAVER_OFF; + else + what = SCREEN_SAVER_ON; + type = what; } - else - { - what = on; - type = what; - if (what == screenIsSaved) - type = SCREEN_SAVER_CYCLE; + else { + what = on; + type = what; + if (what == screenIsSaved) + type = SCREEN_SAVER_CYCLE; } for (i = 0; i < screenInfo.numScreens; i++) { - rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i], - DixShowAccess | DixHideAccess); - if (rc != Success) - return rc; + rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i], + DixShowAccess | DixHideAccess); + if (rc != Success) + return rc; } - for (i = 0; i < screenInfo.numScreens; i++) - { - ScreenPtr pScreen = screenInfo.screens[i]; - if (on == SCREEN_SAVER_FORCER) - (* pScreen->SaveScreen) (pScreen, on); - if (pScreen->screensaver.ExternalScreenSaver) - { - if ((*pScreen->screensaver.ExternalScreenSaver) - (pScreen, type, on == SCREEN_SAVER_FORCER)) - continue; - } - if (type == screenIsSaved) - continue; - switch (type) { - case SCREEN_SAVER_OFF: - if (pScreen->screensaver.blanked == SCREEN_IS_BLANKED) - { - (* pScreen->SaveScreen) (pScreen, what); - } - else if (HasSaverWindow (pScreen)) - { - pScreen->screensaver.pWindow = NullWindow; - FreeResource(pScreen->screensaver.wid, RT_NONE); - } - break; - case SCREEN_SAVER_CYCLE: - if (pScreen->screensaver.blanked == SCREEN_IS_TILED) - { - WindowPtr pWin = pScreen->screensaver.pWindow; - /* make it look like screen saver is off, so that - * NotClippedByChildren will compute a clip list - * for the root window, so miPaintWindow works - */ - screenIsSaved = SCREEN_SAVER_OFF; - (*pWin->drawable.pScreen->MoveWindow)(pWin, - (short)(-(rand() % RANDOM_WIDTH)), - (short)(-(rand() % RANDOM_WIDTH)), - pWin->nextSib, VTMove); - screenIsSaved = SCREEN_SAVER_ON; - } - /* - * Call the DDX saver in case it wants to do something - * at cycle time - */ - else if (pScreen->screensaver.blanked == SCREEN_IS_BLANKED) - { - (* pScreen->SaveScreen) (pScreen, type); - } - break; - case SCREEN_SAVER_ON: - if (ScreenSaverBlanking != DontPreferBlanking) - { - if ((* pScreen->SaveScreen) (pScreen, what)) - { - pScreen->screensaver.blanked = SCREEN_IS_BLANKED; - continue; - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(pScreen, SCREEN_IS_BLACK)) - { - pScreen->screensaver.blanked = SCREEN_IS_BLACK; - continue; - } - } - if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(pScreen, SCREEN_IS_TILED)) - { - pScreen->screensaver.blanked = SCREEN_IS_TILED; - } - else - pScreen->screensaver.blanked = SCREEN_ISNT_SAVED; - break; - } + for (i = 0; i < screenInfo.numScreens; i++) { + ScreenPtr pScreen = screenInfo.screens[i]; + + if (on == SCREEN_SAVER_FORCER) + (*pScreen->SaveScreen) (pScreen, on); + if (pScreen->screensaver.ExternalScreenSaver) { + if ((*pScreen->screensaver.ExternalScreenSaver) + (pScreen, type, on == SCREEN_SAVER_FORCER)) + continue; + } + if (type == screenIsSaved) + continue; + switch (type) { + case SCREEN_SAVER_OFF: + if (pScreen->screensaver.blanked == SCREEN_IS_BLANKED) { + (*pScreen->SaveScreen) (pScreen, what); + } + else if (HasSaverWindow(pScreen)) { + pScreen->screensaver.pWindow = NullWindow; + FreeResource(pScreen->screensaver.wid, RT_NONE); + } + break; + case SCREEN_SAVER_CYCLE: + if (pScreen->screensaver.blanked == SCREEN_IS_TILED) { + WindowPtr pWin = pScreen->screensaver.pWindow; + + /* make it look like screen saver is off, so that + * NotClippedByChildren will compute a clip list + * for the root window, so miPaintWindow works + */ + screenIsSaved = SCREEN_SAVER_OFF; + (*pWin->drawable.pScreen->MoveWindow) (pWin, + (short) (- + (rand() % + RANDOM_WIDTH)), + (short) (- + (rand() % + RANDOM_WIDTH)), + pWin->nextSib, VTMove); + screenIsSaved = SCREEN_SAVER_ON; + } + /* + * Call the DDX saver in case it wants to do something + * at cycle time + */ + else if (pScreen->screensaver.blanked == SCREEN_IS_BLANKED) { + (*pScreen->SaveScreen) (pScreen, type); + } + break; + case SCREEN_SAVER_ON: + if (ScreenSaverBlanking != DontPreferBlanking) { + if ((*pScreen->SaveScreen) (pScreen, what)) { + pScreen->screensaver.blanked = SCREEN_IS_BLANKED; + continue; + } + if ((ScreenSaverAllowExposures != DontAllowExposures) && + TileScreenSaver(pScreen, SCREEN_IS_BLACK)) { + pScreen->screensaver.blanked = SCREEN_IS_BLACK; + continue; + } + } + if ((ScreenSaverAllowExposures != DontAllowExposures) && + TileScreenSaver(pScreen, SCREEN_IS_TILED)) { + pScreen->screensaver.blanked = SCREEN_IS_TILED; + } + else + pScreen->screensaver.blanked = SCREEN_ISNT_SAVED; + break; + } } screenIsSaved = what; if (mode == ScreenSaverReset) { - if (on == SCREEN_SAVER_FORCER) { - UpdateCurrentTimeIf(); - lastDeviceEventTime = currentTime; - } - SetScreenSaverTimer(); + if (on == SCREEN_SAVER_FORCER) { + DeviceIntPtr dev; + UpdateCurrentTimeIf(); + nt_list_for_each_entry(dev, inputInfo.devices, next) + lastDeviceEventTime[dev->id] = currentTime; + } + SetScreenSaverTimer(); } return Success; } @@ -3345,34 +3157,34 @@ TileScreenSaver(ScreenPtr pScreen, int kind) int result; XID attributes[3]; Mask mask; - WindowPtr pWin; + WindowPtr pWin; CursorMetricRec cm; unsigned char *srcbits, *mskbits; CursorPtr cursor; - XID cursorID = 0; - int attri; + XID cursorID = 0; + int attri; mask = 0; attri = 0; switch (kind) { case SCREEN_IS_TILED: - switch (pScreen->root->backgroundState) { - case BackgroundPixel: - attributes[attri++] = pScreen->root->background.pixel; - mask |= CWBackPixel; - break; - case BackgroundPixmap: - attributes[attri++] = None; - mask |= CWBackPixmap; - break; - default: - break; - } - break; + switch (pScreen->root->backgroundState) { + case BackgroundPixel: + attributes[attri++] = pScreen->root->background.pixel; + mask |= CWBackPixel; + break; + case BackgroundPixmap: + attributes[attri++] = None; + mask |= CWBackPixmap; + break; + default: + break; + } + break; case SCREEN_IS_BLACK: - attributes[attri++] = pScreen->root->drawable.pScreen->blackPixel; - mask |= CWBackPixel; - break; + attributes[attri++] = pScreen->root->drawable.pScreen->blackPixel; + mask |= CWBackPixel; + break; } mask |= CWOverrideRedirect; attributes[attri++] = xTrue; @@ -3381,65 +3193,59 @@ TileScreenSaver(ScreenPtr pScreen, int kind) * create a blank cursor */ - cm.width=16; - cm.height=16; - cm.xhot=8; - cm.yhot=8; - srcbits = malloc( BitmapBytePad(32)*16); - mskbits = malloc( BitmapBytePad(32)*16); - if (!srcbits || !mskbits) - { - free(srcbits); - free(mskbits); - cursor = 0; + cm.width = 16; + cm.height = 16; + cm.xhot = 8; + cm.yhot = 8; + srcbits = malloc(BitmapBytePad(32) * 16); + mskbits = malloc(BitmapBytePad(32) * 16); + if (!srcbits || !mskbits) { + free(srcbits); + free(mskbits); + cursor = 0; } - else - { - for (j=0; j<BitmapBytePad(32)*16; j++) - srcbits[j] = mskbits[j] = 0x0; - result = AllocARGBCursor(srcbits, mskbits, NULL, &cm, 0, 0, 0, 0, 0, 0, - &cursor, serverClient, (XID)0); - if (cursor) - { - cursorID = FakeClientID(0); - if (AddResource (cursorID, RT_CURSOR, (pointer) cursor)) - { - attributes[attri] = cursorID; - mask |= CWCursor; - } - else - cursor = 0; - } - else - { - free(srcbits); - free(mskbits); - } + else { + for (j = 0; j < BitmapBytePad(32) * 16; j++) + srcbits[j] = mskbits[j] = 0x0; + result = AllocARGBCursor(srcbits, mskbits, NULL, &cm, 0, 0, 0, 0, 0, 0, + &cursor, serverClient, (XID) 0); + if (cursor) { + cursorID = FakeClientID(0); + if (AddResource(cursorID, RT_CURSOR, (pointer) cursor)) { + attributes[attri] = cursorID; + mask |= CWCursor; + } + else + cursor = 0; + } + else { + free(srcbits); + free(mskbits); + } } pWin = pScreen->screensaver.pWindow = - CreateWindow(pScreen->screensaver.wid, - pScreen->root, - -RANDOM_WIDTH, -RANDOM_WIDTH, - (unsigned short)pScreen->width + RANDOM_WIDTH, - (unsigned short)pScreen->height + RANDOM_WIDTH, - 0, InputOutput, mask, attributes, 0, serverClient, - wVisual (pScreen->root), &result); + CreateWindow(pScreen->screensaver.wid, + pScreen->root, + -RANDOM_WIDTH, -RANDOM_WIDTH, + (unsigned short) pScreen->width + RANDOM_WIDTH, + (unsigned short) pScreen->height + RANDOM_WIDTH, + 0, InputOutput, mask, attributes, 0, serverClient, + wVisual(pScreen->root), &result); if (cursor) - FreeResource (cursorID, RT_NONE); + FreeResource(cursorID, RT_NONE); if (!pWin) - return FALSE; + return FALSE; if (!AddResource(pWin->drawable.id, RT_WINDOW, - (pointer)pScreen->screensaver.pWindow)) - return FALSE; + (pointer) pScreen->screensaver.pWindow)) + return FALSE; - if (mask & CWBackPixmap) - { - MakeRootTile (pWin); - (*pWin->drawable.pScreen->ChangeWindowAttributes)(pWin, CWBackPixmap); + if (mask & CWBackPixmap) { + MakeRootTile(pWin); + (*pWin->drawable.pScreen->ChangeWindowAttributes) (pWin, CWBackPixmap); } MapWindow(pWin, serverClient); return TRUE; @@ -3454,10 +3260,10 @@ TileScreenSaver(ScreenPtr pScreen, int kind) */ WindowPtr -FindWindowWithOptional (WindowPtr w) +FindWindowWithOptional(WindowPtr w) { do - w = w->parent; + w = w->parent; while (!w->optional); return w; } @@ -3471,41 +3277,40 @@ FindWindowWithOptional (WindowPtr w) */ void -CheckWindowOptionalNeed (WindowPtr w) +CheckWindowOptionalNeed(WindowPtr w) { WindowOptPtr optional; WindowOptPtr parentOptional; if (!w->parent || !w->optional) - return; + return; optional = w->optional; if (optional->dontPropagateMask != DontPropagateMasks[w->dontPropagate]) - return; + return; if (optional->otherEventMasks != 0) - return; + return; if (optional->otherClients != NULL) - return; + return; if (optional->passiveGrabs != NULL) - return; + return; if (optional->userProps != NULL) - return; + return; if (optional->backingBitPlanes != ~0L) - return; + return; if (optional->backingPixel != 0) - return; + return; if (optional->boundingShape != NULL) - return; + return; if (optional->clipShape != NULL) - return; + return; if (optional->inputShape != NULL) - return; + return; if (optional->inputMasks != NULL) - return; - if (optional->deviceCursors != NULL) - { + return; + if (optional->deviceCursors != NULL) { DevCursNodePtr pNode = optional->deviceCursors; - while(pNode) - { + + while (pNode) { if (pNode->cursor != None) return; pNode = pNode->next; @@ -3514,14 +3319,13 @@ CheckWindowOptionalNeed (WindowPtr w) parentOptional = FindWindowWithOptional(w)->optional; if (optional->visual != parentOptional->visual) - return; + return; if (optional->cursor != None && - (optional->cursor != parentOptional->cursor || - w->parent->cursorIsNone)) - return; + (optional->cursor != parentOptional->cursor || w->parent->cursorIsNone)) + return; if (optional->colormap != parentOptional->colormap) - return; - DisposeWindowOptional (w); + return; + DisposeWindowOptional(w); } /* @@ -3532,16 +3336,16 @@ CheckWindowOptionalNeed (WindowPtr w) */ Bool -MakeWindowOptional (WindowPtr pWin) +MakeWindowOptional(WindowPtr pWin) { WindowOptPtr optional; WindowOptPtr parentOptional; if (pWin->optional) - return TRUE; - optional = malloc(sizeof (WindowOptRec)); + return TRUE; + optional = malloc(sizeof(WindowOptRec)); if (!optional) - return FALSE; + return FALSE; optional->dontPropagateMask = DontPropagateMasks[pWin->dontPropagate]; optional->otherEventMasks = 0; optional->otherClients = NULL; @@ -3557,14 +3361,12 @@ MakeWindowOptional (WindowPtr pWin) parentOptional = FindWindowWithOptional(pWin)->optional; optional->visual = parentOptional->visual; - if (!pWin->cursorIsNone) - { - optional->cursor = parentOptional->cursor; - optional->cursor->refcnt++; + if (!pWin->cursorIsNone) { + optional->cursor = parentOptional->cursor; + optional->cursor->refcnt++; } - else - { - optional->cursor = None; + else { + optional->cursor = None; } optional->colormap = parentOptional->colormap; pWin->optional = optional; @@ -3586,9 +3388,7 @@ MakeWindowOptional (WindowPtr pWin) * cursor. If the cursor is set to None, it is inherited by the parent. */ int -ChangeWindowDeviceCursor(WindowPtr pWin, - DeviceIntPtr pDev, - CursorPtr pCursor) +ChangeWindowDeviceCursor(WindowPtr pWin, DeviceIntPtr pDev, CursorPtr pCursor) { DevCursNodePtr pNode, pPrev; CursorPtr pOldCursor = NULL; @@ -3613,8 +3413,7 @@ ChangeWindowDeviceCursor(WindowPtr pWin, pScreen = pWin->drawable.pScreen; - if (WindowSeekDeviceCursor(pWin, pDev, &pNode, &pPrev)) - { + if (WindowSeekDeviceCursor(pWin, pDev, &pNode, &pPrev)) { /* has device cursor */ if (pNode->cursor == pCursor) @@ -3622,20 +3421,19 @@ ChangeWindowDeviceCursor(WindowPtr pWin, pOldCursor = pNode->cursor; - if (!pCursor) /* remove from list */ - { - if(pPrev) - pPrev->next = pNode->next; - else - /* first item in list */ - pWin->optional->deviceCursors = pNode->next; + if (!pCursor) { /* remove from list */ + if (pPrev) + pPrev->next = pNode->next; + else + /* first item in list */ + pWin->optional->deviceCursors = pNode->next; free(pNode); goto out; } - } else - { + } + else { /* no device cursor yet */ DevCursNodePtr pNewNode; @@ -3652,40 +3450,36 @@ ChangeWindowDeviceCursor(WindowPtr pWin, if (pCursor && WindowParentHasDeviceCursor(pWin, pDev, pCursor)) pNode->cursor = None; - else - { + else { pNode->cursor = pCursor; pCursor->refcnt++; } pNode = pPrev = NULL; /* fix up children */ - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - if (WindowSeekDeviceCursor(pChild, pDev, &pNode, &pPrev)) - { - if (pNode->cursor == None) /* inherited from parent */ - { + for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) { + if (WindowSeekDeviceCursor(pChild, pDev, &pNode, &pPrev)) { + if (pNode->cursor == None) { /* inherited from parent */ pNode->cursor = pOldCursor; pOldCursor->refcnt++; - } else if (pNode->cursor == pCursor) - { + } + else if (pNode->cursor == pCursor) { pNode->cursor = None; - FreeCursor(pCursor, (Cursor)0); /* fix up refcnt */ + FreeCursor(pCursor, (Cursor) 0); /* fix up refcnt */ } } } -out: + out: if (pWin->realized) WindowHasNewCursor(pWin); if (pOldCursor) - FreeCursor(pOldCursor, (Cursor)0); + FreeCursor(pOldCursor, (Cursor) 0); /* FIXME: We SHOULD check for an error value here XXX (comment taken from ChangeWindowAttributes) */ - (*pScreen->ChangeWindowAttributes)(pWin, CWCursor); + (*pScreen->ChangeWindowAttributes) (pWin, CWCursor); return Success; } @@ -3701,11 +3495,9 @@ WindowGetDeviceCursor(WindowPtr pWin, DeviceIntPtr pDev) pList = pWin->optional->deviceCursors; - while(pList) - { - if (pList->dev == pDev) - { - if (pList->cursor == None) /* inherited from parent */ + while (pList) { + if (pList->dev == pDev) { + if (pList->cursor == None) /* inherited from parent */ return WindowGetDeviceCursor(pWin->parent, pDev); else return pList->cursor; @@ -3720,11 +3512,10 @@ WindowGetDeviceCursor(WindowPtr pWin, DeviceIntPtr pDev) * before the node respectively. Otherwise return False. * If the device is the first in list, pPrev is set to NULL. */ -static Bool -WindowSeekDeviceCursor(WindowPtr pWin, - DeviceIntPtr pDev, - DevCursNodePtr* pNode, - DevCursNodePtr* pPrev) +static Bool +WindowSeekDeviceCursor(WindowPtr pWin, + DeviceIntPtr pDev, + DevCursNodePtr * pNode, DevCursNodePtr * pPrev) { DevCursorList pList; @@ -3733,19 +3524,15 @@ WindowSeekDeviceCursor(WindowPtr pWin, pList = pWin->optional->deviceCursors; - if (pList && pList->dev == pDev) - { + if (pList && pList->dev == pDev) { *pNode = pList; *pPrev = NULL; return TRUE; } - while(pList) - { - if (pList->next) - { - if (pList->next->dev == pDev) - { + while (pList) { + if (pList->next) { + if (pList->next->dev == pDev) { *pNode = pList->next; *pPrev = pList; return TRUE; @@ -3758,30 +3545,26 @@ WindowSeekDeviceCursor(WindowPtr pWin, /* Return True if a parent has the same device cursor set or False if * otherwise - */ -static Bool -WindowParentHasDeviceCursor(WindowPtr pWin, - DeviceIntPtr pDev, - CursorPtr pCursor) + */ +static Bool +WindowParentHasDeviceCursor(WindowPtr pWin, + DeviceIntPtr pDev, CursorPtr pCursor) { WindowPtr pParent; DevCursNodePtr pParentNode, pParentPrev; pParent = pWin->parent; - while(pParent) - { - if (WindowSeekDeviceCursor(pParent, pDev, - &pParentNode, &pParentPrev)) - { + while (pParent) { + if (WindowSeekDeviceCursor(pParent, pDev, &pParentNode, &pParentPrev)) { /* if there is a node in the list, the win has a dev cursor */ - if (!pParentNode->cursor) /* inherited. */ + if (!pParentNode->cursor) /* inherited. */ pParent = pParent->parent; - else if (pParentNode->cursor == pCursor) /* inherit */ + else if (pParentNode->cursor == pCursor) /* inherit */ return TRUE; - else /* different cursor */ + else /* different cursor */ return FALSE; - } - else + } + else /* parent does not have a device cursor for our device */ return FALSE; } @@ -3797,39 +3580,34 @@ WindowParentHasDeviceCursor(WindowPtr pWin, void SetRootClip(ScreenPtr pScreen, Bool enable) { - WindowPtr pWin = pScreen->root; - WindowPtr pChild; - Bool WasViewable; - Bool anyMarked = FALSE; - WindowPtr pLayerWin; - BoxRec box; + WindowPtr pWin = pScreen->root; + WindowPtr pChild; + Bool WasViewable; + Bool anyMarked = FALSE; + WindowPtr pLayerWin; + BoxRec box; if (!pWin) - return; - WasViewable = (Bool)(pWin->viewable); - if (WasViewable) - { - for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) - { - (void) (*pScreen->MarkOverlappedWindows)(pChild, - pChild, - &pLayerWin); - } - (*pScreen->MarkWindow) (pWin); - anyMarked = TRUE; - if (pWin->valdata) - { - if (HasBorder (pWin)) - { - RegionPtr borderVisible; - - borderVisible = RegionCreate(NullBox, 1); - RegionSubtract(borderVisible, - &pWin->borderClip, &pWin->winSize); - pWin->valdata->before.borderVisible = borderVisible; - } - pWin->valdata->before.resized = TRUE; - } + return; + WasViewable = (Bool) (pWin->viewable); + if (WasViewable) { + for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) { + (void) (*pScreen->MarkOverlappedWindows) (pChild, + pChild, &pLayerWin); + } + (*pScreen->MarkWindow) (pWin); + anyMarked = TRUE; + if (pWin->valdata) { + if (HasBorder(pWin)) { + RegionPtr borderVisible; + + borderVisible = RegionCreate(NullBox, 1); + RegionSubtract(borderVisible, + &pWin->borderClip, &pWin->winSize); + pWin->valdata->before.borderVisible = borderVisible; + } + pWin->valdata->before.resized = TRUE; + } } /* @@ -3837,55 +3615,48 @@ SetRootClip(ScreenPtr pScreen, Bool enable) * that assume the root borderClip can't change well, normally * it doesn't...) */ - if (enable) - { - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - RegionInit(&pWin->winSize, &box, 1); - RegionInit(&pWin->borderSize, &box, 1); - if (WasViewable) - RegionReset(&pWin->borderClip, &box); - pWin->drawable.width = pScreen->width; - pWin->drawable.height = pScreen->height; - RegionBreak(&pWin->clipList); + if (enable) { + box.x1 = 0; + box.y1 = 0; + box.x2 = pScreen->width; + box.y2 = pScreen->height; + RegionInit(&pWin->winSize, &box, 1); + RegionInit(&pWin->borderSize, &box, 1); + if (WasViewable) + RegionReset(&pWin->borderClip, &box); + pWin->drawable.width = pScreen->width; + pWin->drawable.height = pScreen->height; + RegionBreak(&pWin->clipList); } - else - { - RegionEmpty(&pWin->borderClip); - RegionBreak(&pWin->clipList); + else { + RegionEmpty(&pWin->borderClip); + RegionBreak(&pWin->clipList); } - ResizeChildrenWinSize (pWin, 0, 0, 0, 0); - - if (WasViewable) - { - if (pWin->firstChild) - { - anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin->firstChild, - pWin->firstChild, - (WindowPtr *)NULL); - } - else - { - (*pScreen->MarkWindow) (pWin); - anyMarked = TRUE; - } + ResizeChildrenWinSize(pWin, 0, 0, 0, 0); + if (WasViewable) { + if (pWin->firstChild) { + anyMarked |= (*pScreen->MarkOverlappedWindows) (pWin->firstChild, + pWin->firstChild, + (WindowPtr *) NULL); + } + else { + (*pScreen->MarkWindow) (pWin); + anyMarked = TRUE; + } - if (anyMarked) - (*pScreen->ValidateTree)(pWin, NullWindow, VTOther); + if (anyMarked) + (*pScreen->ValidateTree) (pWin, NullWindow, VTOther); } - if (WasViewable) - { - if (anyMarked) - (*pScreen->HandleExposures)(pWin); - if (anyMarked && pScreen->PostValidateTree) - (*pScreen->PostValidateTree)(pWin, NullWindow, VTOther); + if (WasViewable) { + if (anyMarked) + (*pScreen->HandleExposures) (pWin); + if (anyMarked && pScreen->PostValidateTree) + (*pScreen->PostValidateTree) (pWin, NullWindow, VTOther); } if (pWin->realized) - WindowsRestructured (); + WindowsRestructured(); FlushAllOutput(); } |