diff options
Diffstat (limited to 'xorg-server/hw/xquartz')
51 files changed, 9363 insertions, 8599 deletions
diff --git a/xorg-server/hw/xquartz/GL/capabilities.c b/xorg-server/hw/xquartz/GL/capabilities.c index b718a4156..4624fd4db 100644 --- a/xorg-server/hw/xquartz/GL/capabilities.c +++ b/xorg-server/hw/xquartz/GL/capabilities.c @@ -38,313 +38,326 @@ #include "os.h" -static void handleBufferModes(struct glCapabilitiesConfig *c, GLint bufferModes) { - if(bufferModes & kCGLStereoscopicBit) { - c->stereo = true; +static void +handleBufferModes(struct glCapabilitiesConfig *c, GLint bufferModes) +{ + if (bufferModes & kCGLStereoscopicBit) { + c->stereo = true; } - if(bufferModes & kCGLDoubleBufferBit) { - c->buffers = 2; - } else { - c->buffers = 1; + if (bufferModes & kCGLDoubleBufferBit) { + c->buffers = 2; + } + else { + c->buffers = 1; } } -static void handleStencilModes(struct glCapabilitiesConfig *c, GLint smodes) { +static void +handleStencilModes(struct glCapabilitiesConfig *c, GLint smodes) +{ int offset = 0; - - if(kCGL0Bit & smodes) - c->stencil_bit_depths[offset++] = 0; - - if(kCGL1Bit & smodes) - c->stencil_bit_depths[offset++] = 1; - - if(kCGL2Bit & smodes) - c->stencil_bit_depths[offset++] = 2; - - if(kCGL3Bit & smodes) - c->stencil_bit_depths[offset++] = 3; - - if(kCGL4Bit & smodes) - c->stencil_bit_depths[offset++] = 4; - - if(kCGL5Bit & smodes) - c->stencil_bit_depths[offset++] = 5; - - if(kCGL6Bit & smodes) - c->stencil_bit_depths[offset++] = 6; - - if(kCGL8Bit & smodes) - c->stencil_bit_depths[offset++] = 8; - - if(kCGL10Bit & smodes) - c->stencil_bit_depths[offset++] = 10; - - if(kCGL12Bit & smodes) - c->stencil_bit_depths[offset++] = 12; - - if(kCGL16Bit & smodes) - c->stencil_bit_depths[offset++] = 16; - - if(kCGL24Bit & smodes) - c->stencil_bit_depths[offset++] = 24; - - if(kCGL32Bit & smodes) - c->stencil_bit_depths[offset++] = 32; - - if(kCGL48Bit & smodes) - c->stencil_bit_depths[offset++] = 48; - - if(kCGL64Bit & smodes) - c->stencil_bit_depths[offset++] = 64; - - if(kCGL96Bit & smodes) - c->stencil_bit_depths[offset++] = 96; - - if(kCGL128Bit & smodes) - c->stencil_bit_depths[offset++] = 128; + + if (kCGL0Bit & smodes) + c->stencil_bit_depths[offset++] = 0; + + if (kCGL1Bit & smodes) + c->stencil_bit_depths[offset++] = 1; + + if (kCGL2Bit & smodes) + c->stencil_bit_depths[offset++] = 2; + + if (kCGL3Bit & smodes) + c->stencil_bit_depths[offset++] = 3; + + if (kCGL4Bit & smodes) + c->stencil_bit_depths[offset++] = 4; + + if (kCGL5Bit & smodes) + c->stencil_bit_depths[offset++] = 5; + + if (kCGL6Bit & smodes) + c->stencil_bit_depths[offset++] = 6; + + if (kCGL8Bit & smodes) + c->stencil_bit_depths[offset++] = 8; + + if (kCGL10Bit & smodes) + c->stencil_bit_depths[offset++] = 10; + + if (kCGL12Bit & smodes) + c->stencil_bit_depths[offset++] = 12; + + if (kCGL16Bit & smodes) + c->stencil_bit_depths[offset++] = 16; + + if (kCGL24Bit & smodes) + c->stencil_bit_depths[offset++] = 24; + + if (kCGL32Bit & smodes) + c->stencil_bit_depths[offset++] = 32; + + if (kCGL48Bit & smodes) + c->stencil_bit_depths[offset++] = 48; + + if (kCGL64Bit & smodes) + c->stencil_bit_depths[offset++] = 64; + + if (kCGL96Bit & smodes) + c->stencil_bit_depths[offset++] = 96; + + if (kCGL128Bit & smodes) + c->stencil_bit_depths[offset++] = 128; assert(offset < GLCAPS_STENCIL_BIT_DEPTH_BUFFERS); c->total_stencil_bit_depths = offset; } -static int handleColorAndAccumulation(struct glColorBufCapabilities *c, - GLint cmodes, int forAccum) { +static int +handleColorAndAccumulation(struct glColorBufCapabilities *c, + GLint cmodes, int forAccum) +{ int offset = 0; - - /*1*/ - if(kCGLRGB444Bit & cmodes) { - c[offset].r = 4; - c[offset].g = 4; - c[offset].b = 4; - ++offset; - } - - /*2*/ - if(kCGLARGB4444Bit & cmodes) { - c[offset].a = 4; - c[offset].r = 4; - c[offset].g = 4; - c[offset].b = 4; - c[offset].is_argb = true; - ++offset; - } - - /*3*/ - if(kCGLRGB444A8Bit & cmodes) { - c[offset].r = 4; - c[offset].g = 4; - c[offset].b = 4; - c[offset].a = 8; - ++offset; - } - /*4*/ - if(kCGLRGB555Bit & cmodes) { - c[offset].r = 5; - c[offset].g = 5; - c[offset].b = 5; - ++offset; + /*1 */ + if (kCGLRGB444Bit & cmodes) { + c[offset].r = 4; + c[offset].g = 4; + c[offset].b = 4; + ++offset; } - /*5*/ - if(kCGLARGB1555Bit & cmodes) { - c[offset].a = 1; - c[offset].r = 5; - c[offset].g = 5; - c[offset].b = 5; - c[offset].is_argb = true; - ++offset; + /*2 */ + if (kCGLARGB4444Bit & cmodes) { + c[offset].a = 4; + c[offset].r = 4; + c[offset].g = 4; + c[offset].b = 4; + c[offset].is_argb = true; + ++offset; } - /*6*/ - if(kCGLRGB555A8Bit & cmodes) { - c[offset].r = 5; - c[offset].g = 5; - c[offset].b = 5; - c[offset].a = 8; - ++offset; + /*3 */ + if (kCGLRGB444A8Bit & cmodes) { + c[offset].r = 4; + c[offset].g = 4; + c[offset].b = 4; + c[offset].a = 8; + ++offset; } - /*7*/ - if(kCGLRGB565Bit & cmodes) { - c[offset].r = 5; - c[offset].g = 6; - c[offset].b = 5; - ++offset; + /*4 */ + if (kCGLRGB555Bit & cmodes) { + c[offset].r = 5; + c[offset].g = 5; + c[offset].b = 5; + ++offset; } - /*8*/ - if(kCGLRGB565A8Bit & cmodes) { - c[offset].r = 5; - c[offset].g = 6; - c[offset].b = 5; - c[offset].a = 8; - ++offset; + /*5 */ + if (kCGLARGB1555Bit & cmodes) { + c[offset].a = 1; + c[offset].r = 5; + c[offset].g = 5; + c[offset].b = 5; + c[offset].is_argb = true; + ++offset; } - /*9*/ - if(kCGLRGB888Bit & cmodes) { - c[offset].r = 8; - c[offset].g = 8; - c[offset].b = 8; - ++offset; + /*6 */ + if (kCGLRGB555A8Bit & cmodes) { + c[offset].r = 5; + c[offset].g = 5; + c[offset].b = 5; + c[offset].a = 8; + ++offset; } - /*10*/ - if(kCGLARGB8888Bit & cmodes) { - c[offset].a = 8; - c[offset].r = 8; - c[offset].g = 8; - c[offset].b = 8; - c[offset].is_argb = true; - ++offset; + /*7 */ + if (kCGLRGB565Bit & cmodes) { + c[offset].r = 5; + c[offset].g = 6; + c[offset].b = 5; + ++offset; } - /*11*/ - if(kCGLRGB888A8Bit & cmodes) { - c[offset].r = 8; - c[offset].g = 8; - c[offset].b = 8; - c[offset].a = 8; - ++offset; + /*8 */ + if (kCGLRGB565A8Bit & cmodes) { + c[offset].r = 5; + c[offset].g = 6; + c[offset].b = 5; + c[offset].a = 8; + ++offset; } - if(forAccum) { -//#if 0 - /* FIXME - * Disable this path, because some part of libGL, X, or Xplugin - * doesn't work with sizes greater than 8. - * When this is enabled and visuals are chosen using depths - * such as 16, the result is that the windows don't redraw - * and are often white, until a resize. - */ - - /*12*/ - if(kCGLRGB101010Bit & cmodes) { - c[offset].r = 10; - c[offset].g = 10; - c[offset].b = 10; - ++offset; + /*9 */ + if (kCGLRGB888Bit & cmodes) { + c[offset].r = 8; + c[offset].g = 8; + c[offset].b = 8; + ++offset; } - /*13*/ - if(kCGLARGB2101010Bit & cmodes) { - c[offset].a = 2; - c[offset].r = 10; - c[offset].g = 10; - c[offset].b = 10; - c[offset].is_argb = true; - ++offset; + /*10 */ + if (kCGLARGB8888Bit & cmodes) { + c[offset].a = 8; + c[offset].r = 8; + c[offset].g = 8; + c[offset].b = 8; + c[offset].is_argb = true; + ++offset; } - /*14*/ - if(kCGLRGB101010_A8Bit & cmodes) { - c[offset].r = 10; - c[offset].g = 10; - c[offset].b = 10; - c[offset].a = 8; - ++offset; + /*11 */ + if (kCGLRGB888A8Bit & cmodes) { + c[offset].r = 8; + c[offset].g = 8; + c[offset].b = 8; + c[offset].a = 8; + ++offset; } - /*15*/ - if(kCGLRGB121212Bit & cmodes) { - c[offset].r = 12; - c[offset].g = 12; - c[offset].b = 12; - ++offset; - } - - /*16*/ - if(kCGLARGB12121212Bit & cmodes) { - c[offset].a = 12; - c[offset].r = 12; - c[offset].g = 12; - c[offset].b = 12; - c[offset].is_argb = true; - ++offset; - } - - /*17*/ - if(kCGLRGB161616Bit & cmodes) { - c[offset].r = 16; - c[offset].g = 16; - c[offset].b = 16; - ++offset; - } - - /*18*/ - if(kCGLRGBA16161616Bit & cmodes) { - c[offset].r = 16; - c[offset].g = 16; - c[offset].b = 16; - c[offset].a = 16; - ++offset; - } + if (forAccum) { +//#if 0 + /* FIXME + * Disable this path, because some part of libGL, X, or Xplugin + * doesn't work with sizes greater than 8. + * When this is enabled and visuals are chosen using depths + * such as 16, the result is that the windows don't redraw + * and are often white, until a resize. + */ + + /*12 */ + if (kCGLRGB101010Bit & cmodes) { + c[offset].r = 10; + c[offset].g = 10; + c[offset].b = 10; + ++offset; + } + + /*13 */ + if (kCGLARGB2101010Bit & cmodes) { + c[offset].a = 2; + c[offset].r = 10; + c[offset].g = 10; + c[offset].b = 10; + c[offset].is_argb = true; + ++offset; + } + + /*14 */ + if (kCGLRGB101010_A8Bit & cmodes) { + c[offset].r = 10; + c[offset].g = 10; + c[offset].b = 10; + c[offset].a = 8; + ++offset; + } + + /*15 */ + if (kCGLRGB121212Bit & cmodes) { + c[offset].r = 12; + c[offset].g = 12; + c[offset].b = 12; + ++offset; + } + + /*16 */ + if (kCGLARGB12121212Bit & cmodes) { + c[offset].a = 12; + c[offset].r = 12; + c[offset].g = 12; + c[offset].b = 12; + c[offset].is_argb = true; + ++offset; + } + + /*17 */ + if (kCGLRGB161616Bit & cmodes) { + c[offset].r = 16; + c[offset].g = 16; + c[offset].b = 16; + ++offset; + } + + /*18 */ + if (kCGLRGBA16161616Bit & cmodes) { + c[offset].r = 16; + c[offset].g = 16; + c[offset].b = 16; + c[offset].a = 16; + ++offset; + } } //#endif /* FIXME should we handle the floating point color modes, and if so, how? */ - + return offset; } - -static void handleColorModes(struct glCapabilitiesConfig *c, GLint cmodes) { +static void +handleColorModes(struct glCapabilitiesConfig *c, GLint cmodes) +{ c->total_color_buffers = handleColorAndAccumulation(c->color_buffers, - cmodes, 0); - + cmodes, 0); + assert(c->total_color_buffers < GLCAPS_COLOR_BUFFERS); } -static void handleAccumulationModes(struct glCapabilitiesConfig *c, GLint cmodes) { +static void +handleAccumulationModes(struct glCapabilitiesConfig *c, GLint cmodes) +{ c->total_accum_buffers = handleColorAndAccumulation(c->accum_buffers, - cmodes, 1); + cmodes, 1); assert(c->total_accum_buffers < GLCAPS_COLOR_BUFFERS); } -static void handleDepthModes(struct glCapabilitiesConfig *c, GLint dmodes) { +static void +handleDepthModes(struct glCapabilitiesConfig *c, GLint dmodes) +{ int offset = 0; + #define DEPTH(flag,value) do { \ if(dmodes & flag) { \ c->depth_buffers[offset++] = value; \ } \ } while(0) - /*1*/ + /*1 */ DEPTH(kCGL0Bit, 0); - /*2*/ + /*2 */ DEPTH(kCGL1Bit, 1); - /*3*/ + /*3 */ DEPTH(kCGL2Bit, 2); - /*4*/ + /*4 */ DEPTH(kCGL3Bit, 3); - /*5*/ + /*5 */ DEPTH(kCGL4Bit, 4); - /*6*/ + /*6 */ DEPTH(kCGL5Bit, 5); - /*7*/ + /*7 */ DEPTH(kCGL6Bit, 6); - /*8*/ + /*8 */ DEPTH(kCGL8Bit, 8); - /*9*/ + /*9 */ DEPTH(kCGL10Bit, 10); - /*10*/ + /*10 */ DEPTH(kCGL12Bit, 12); - /*11*/ + /*11 */ DEPTH(kCGL16Bit, 16); - /*12*/ + /*12 */ DEPTH(kCGL24Bit, 24); - /*13*/ + /*13 */ DEPTH(kCGL32Bit, 32); - /*14*/ + /*14 */ DEPTH(kCGL48Bit, 48); - /*15*/ + /*15 */ DEPTH(kCGL64Bit, 64); - /*16*/ + /*16 */ DEPTH(kCGL96Bit, 96); - /*17*/ + /*17 */ DEPTH(kCGL128Bit, 128); #undef DEPTH @@ -354,95 +367,96 @@ static void handleDepthModes(struct glCapabilitiesConfig *c, GLint dmodes) { } /* Return non-zero if an error occured. */ -static CGLError handleRendererDescriptions(CGLRendererInfoObj info, GLint r, - struct glCapabilitiesConfig *c) { +static CGLError +handleRendererDescriptions(CGLRendererInfoObj info, GLint r, + struct glCapabilitiesConfig *c) +{ CGLError err; GLint accelerated = 0, flags = 0, aux = 0, samplebufs = 0, samples = 0; - err = CGLDescribeRenderer (info, r, kCGLRPAccelerated, &accelerated); + err = CGLDescribeRenderer(info, r, kCGLRPAccelerated, &accelerated); + + if (err) + return err; - if(err) - return err; - c->accelerated = accelerated; /* Buffering modes: single/double, stereo */ err = CGLDescribeRenderer(info, r, kCGLRPBufferModes, &flags); - if(err) - return err; - + if (err) + return err; + handleBufferModes(c, flags); - + /* AUX buffers */ err = CGLDescribeRenderer(info, r, kCGLRPMaxAuxBuffers, &aux); - if(err) - return err; - + if (err) + return err; + c->aux_buffers = aux; - /* Depth buffer size */ err = CGLDescribeRenderer(info, r, kCGLRPDepthModes, &flags); - - if(err) - return err; - handleDepthModes(c, flags); + if (err) + return err; + handleDepthModes(c, flags); /* Multisample buffers */ err = CGLDescribeRenderer(info, r, kCGLRPMaxSampleBuffers, &samplebufs); - if(err) - return err; + if (err) + return err; c->multisample_buffers = samplebufs; - /* Multisample samples per multisample buffer */ err = CGLDescribeRenderer(info, r, kCGLRPMaxSamples, &samples); - if(err) - return err; + if (err) + return err; c->multisample_samples = samples; - /* Stencil bit depths */ err = CGLDescribeRenderer(info, r, kCGLRPStencilModes, &flags); - if(err) - return err; - - handleStencilModes(c, flags); + if (err) + return err; + handleStencilModes(c, flags); /* Color modes (RGB/RGBA depths supported */ err = CGLDescribeRenderer(info, r, kCGLRPColorModes, &flags); - if(err) - return err; - + if (err) + return err; + handleColorModes(c, flags); err = CGLDescribeRenderer(info, r, kCGLRPAccumModes, &flags); - if(err) - return err; + if (err) + return err; handleAccumulationModes(c, flags); - + return kCGLNoError; } -static void initCapabilities(struct glCapabilities *cap) { +static void +initCapabilities(struct glCapabilities *cap) +{ cap->configurations = NULL; cap->total_configurations = 0; } -static void initConfig(struct glCapabilitiesConfig *c) { +static void +initConfig(struct glCapabilitiesConfig *c) +{ int i; c->accelerated = false; @@ -452,8 +466,8 @@ static void initConfig(struct glCapabilitiesConfig *c) { c->total_depth_buffer_depths = 0; - for(i = 0; i < GLCAPS_DEPTH_BUFFERS; ++i) { - c->depth_buffers[i] = GLCAPS_INVALID_DEPTH_VALUE; + for (i = 0; i < GLCAPS_DEPTH_BUFFERS; ++i) { + c->depth_buffers[i] = GLCAPS_INVALID_DEPTH_VALUE; } c->multisample_buffers = 0; @@ -461,83 +475,88 @@ static void initConfig(struct glCapabilitiesConfig *c) { c->total_stencil_bit_depths = 0; - for(i = 0; i < GLCAPS_STENCIL_BIT_DEPTH_BUFFERS; ++i) { - c->stencil_bit_depths[i] = GLCAPS_INVALID_STENCIL_DEPTH; + for (i = 0; i < GLCAPS_STENCIL_BIT_DEPTH_BUFFERS; ++i) { + c->stencil_bit_depths[i] = GLCAPS_INVALID_STENCIL_DEPTH; } - + c->total_color_buffers = 0; - for(i = 0; i < GLCAPS_COLOR_BUFFERS; ++i) { - c->color_buffers[i].r = c->color_buffers[i].g = - c->color_buffers[i].b = c->color_buffers[i].a = - GLCAPS_COLOR_BUF_INVALID_VALUE; - c->color_buffers[i].is_argb = false; - } + for (i = 0; i < GLCAPS_COLOR_BUFFERS; ++i) { + c->color_buffers[i].r = c->color_buffers[i].g = + c->color_buffers[i].b = c->color_buffers[i].a = + GLCAPS_COLOR_BUF_INVALID_VALUE; + c->color_buffers[i].is_argb = false; + } c->total_accum_buffers = 0; - for(i = 0; i < GLCAPS_COLOR_BUFFERS; ++i) { - c->accum_buffers[i].r = c->accum_buffers[i].g = - c->accum_buffers[i].b = c->accum_buffers[i].a = - GLCAPS_COLOR_BUF_INVALID_VALUE; - c->accum_buffers[i].is_argb = false; + for (i = 0; i < GLCAPS_COLOR_BUFFERS; ++i) { + c->accum_buffers[i].r = c->accum_buffers[i].g = + c->accum_buffers[i].b = c->accum_buffers[i].a = + GLCAPS_COLOR_BUF_INVALID_VALUE; + c->accum_buffers[i].is_argb = false; } c->next = NULL; } -void freeGlCapabilities(struct glCapabilities *cap) { +void +freeGlCapabilities(struct glCapabilities *cap) +{ struct glCapabilitiesConfig *conf, *next; - + conf = cap->configurations; - while(conf) { - next = conf->next; - free(conf); - conf = next; + while (conf) { + next = conf->next; + free(conf); + conf = next; } - cap->configurations = NULL; + cap->configurations = NULL; } /*Return true if an error occured. */ -bool getGlCapabilities(struct glCapabilities *cap) { - CGLRendererInfoObj info; +bool +getGlCapabilities(struct glCapabilities *cap) +{ + CGLRendererInfoObj info; CGLError err; - GLint numRenderers = 0, r; + GLint numRenderers = 0, r; initCapabilities(cap); - err = CGLQueryRendererInfo((GLuint)-1, &info, &numRenderers); - if(err) { - ErrorF("CGLQueryRendererInfo error: %s\n", CGLErrorString(err)); + err = CGLQueryRendererInfo((GLuint) - 1, &info, &numRenderers); + if (err) { + ErrorF("CGLQueryRendererInfo error: %s\n", CGLErrorString(err)); return err; - } + } - for(r = 0; r < numRenderers; r++) { - struct glCapabilitiesConfig tmpconf, *conf; + for (r = 0; r < numRenderers; r++) { + struct glCapabilitiesConfig tmpconf, *conf; - initConfig(&tmpconf); + initConfig(&tmpconf); - err = handleRendererDescriptions(info, r, &tmpconf); - if(err) { - ErrorF("handleRendererDescriptions returned error: %s\n", CGLErrorString(err)); + err = handleRendererDescriptions(info, r, &tmpconf); + if (err) { + ErrorF("handleRendererDescriptions returned error: %s\n", + CGLErrorString(err)); ErrorF("trying to continue...\n"); continue; - } + } - conf = malloc(sizeof(*conf)); - if(NULL == conf) { - FatalError("Unable to allocate memory for OpenGL capabilities\n"); - } + conf = malloc(sizeof(*conf)); + if (NULL == conf) { + FatalError("Unable to allocate memory for OpenGL capabilities\n"); + } - /* Copy the struct. */ - *conf = tmpconf; + /* Copy the struct. */ + *conf = tmpconf; - /* Now link the configuration into the list. */ - conf->next = cap->configurations; - cap->configurations = conf; - } + /* Now link the configuration into the list. */ + conf->next = cap->configurations; + cap->configurations = conf; + } CGLDestroyRendererInfo(info); diff --git a/xorg-server/hw/xquartz/GL/glcontextmodes.c b/xorg-server/hw/xquartz/GL/glcontextmodes.c index 52a9ca440..79fadf876 100644 --- a/xorg-server/hw/xquartz/GL/glcontextmodes.c +++ b/xorg-server/hw/xquartz/GL/glcontextmodes.c @@ -1,550 +1,538 @@ -/*
- * (C) Copyright IBM Corporation 2003
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * on the rights to use, copy, modify, merge, publish, distribute, sub
- * license, and/or sell copies of the Software, and to permit persons to whom
- * the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file glcontextmodes.c
- * Utility routines for working with \c __GLcontextModes structures. At
- * some point most or all of these functions will be moved to the Mesa
- * code base.
- *
- * \author Ian Romanick <idr@us.ibm.com>
- */
-
-#if defined(IN_MINI_GLX)
-#include <GL/gl.h>
-#else
-#if defined(HAVE_DIX_CONFIG_H)
-# include <dix-config.h>
-#endif
-#include <X11/X.h>
-#include <GL/glx.h>
-#include "GL/glxint.h"
-#endif
-
-/* Memory macros */
-#if defined(IN_MINI_GLX)
-# include <stdlib.h>
-# include <string.h>
-# define _mesa_malloc(b) malloc(b)
-# define _mesa_free(m) free(m)
-# define _mesa_memset memset
-#else
-# ifdef XFree86Server
-# include <os.h>
-# include <string.h>
-# define _mesa_malloc(b) malloc(b)
-# define _mesa_free(m) free(m)
-# define _mesa_memset memset
-# else
-# include <X11/Xlibint.h>
-# define _mesa_memset memset
-# define _mesa_malloc(b) Xmalloc(b)
-# define _mesa_free(m) free(m)
-# endif /* XFree86Server */
-#endif /* !defined(IN_MINI_GLX) */
-
-#include "glcontextmodes.h"
-
-#if !defined(IN_MINI_GLX)
-#define NUM_VISUAL_TYPES 6
-
-/**
- * Convert an X visual type to a GLX visual type.
- *
- * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.)
- * to be converted.
- * \return If \c visualType is a valid X visual type, a GLX visual type will
- * be returned. Otherwise \c GLX_NONE will be returned.
- */
-GLint
-_gl_convert_from_x_visual_type( int visualType )
-{
- static const int glx_visual_types[ NUM_VISUAL_TYPES ] = {
- GLX_STATIC_GRAY, GLX_GRAY_SCALE,
- GLX_STATIC_COLOR, GLX_PSEUDO_COLOR,
- GLX_TRUE_COLOR, GLX_DIRECT_COLOR
- };
-
- return ( (unsigned) visualType < NUM_VISUAL_TYPES )
- ? glx_visual_types[ visualType ] : GLX_NONE;
-}
-
-
-/**
- * Convert a GLX visual type to an X visual type.
- *
- * \param visualType GLX visual type (i.e., \c GLX_TRUE_COLOR,
- * \c GLX_STATIC_GRAY, etc.) to be converted.
- * \return If \c visualType is a valid GLX visual type, an X visual type will
- * be returned. Otherwise -1 will be returned.
- */
-GLint
-_gl_convert_to_x_visual_type( int visualType )
-{
- static const int x_visual_types[ NUM_VISUAL_TYPES ] = {
- TrueColor, DirectColor,
- PseudoColor, StaticColor,
- GrayScale, StaticGray
- };
-
- return ( (unsigned) (visualType - GLX_TRUE_COLOR) < NUM_VISUAL_TYPES )
- ? x_visual_types[ visualType - GLX_TRUE_COLOR ] : -1;
-}
-
-
-/**
- * Copy a GLX visual config structure to a GL context mode structure. All
- * of the fields in \c config are copied to \c mode. Additional fields in
- * \c mode that can be derrived from the fields of \c config (i.e.,
- * \c haveDepthBuffer) are also filled in. The remaining fields in \c mode
- * that cannot be derived are set to default values.
- *
- * \param mode Destination GL context mode.
- * \param config Source GLX visual config.
- *
- * \note
- * The \c fbconfigID and \c visualID fields of the \c __GLcontextModes
- * structure will be set to the \c vid of the \c __GLXvisualConfig structure.
- */
-void
-_gl_copy_visual_to_context_mode( __GLcontextModes * mode,
- const __GLXvisualConfig * config )
-{
- __GLcontextModes * const next = mode->next;
-
- (void) _mesa_memset( mode, 0, sizeof( __GLcontextModes ) );
- mode->next = next;
-
- mode->visualID = config->vid;
- mode->visualType = _gl_convert_from_x_visual_type( config->class );
- mode->xRenderable = GL_TRUE;
- mode->fbconfigID = config->vid;
- mode->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT;
-
- mode->rgbMode = (config->rgba != 0);
- mode->renderType = (mode->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
-
- mode->colorIndexMode = !(mode->rgbMode);
- mode->doubleBufferMode = (config->doubleBuffer != 0);
- mode->stereoMode = (config->stereo != 0);
-
- mode->haveAccumBuffer = ((config->accumRedSize +
- config->accumGreenSize +
- config->accumBlueSize +
- config->accumAlphaSize) > 0);
- mode->haveDepthBuffer = (config->depthSize > 0);
- mode->haveStencilBuffer = (config->stencilSize > 0);
-
- mode->redBits = config->redSize;
- mode->greenBits = config->greenSize;
- mode->blueBits = config->blueSize;
- mode->alphaBits = config->alphaSize;
- mode->redMask = config->redMask;
- mode->greenMask = config->greenMask;
- mode->blueMask = config->blueMask;
- mode->alphaMask = config->alphaMask;
- mode->rgbBits = mode->rgbMode ? config->bufferSize : 0;
- mode->indexBits = mode->colorIndexMode ? config->bufferSize : 0;
-
- mode->accumRedBits = config->accumRedSize;
- mode->accumGreenBits = config->accumGreenSize;
- mode->accumBlueBits = config->accumBlueSize;
- mode->accumAlphaBits = config->accumAlphaSize;
- mode->depthBits = config->depthSize;
- mode->stencilBits = config->stencilSize;
-
- mode->numAuxBuffers = config->auxBuffers;
- mode->level = config->level;
-
- mode->visualRating = config->visualRating;
- mode->transparentPixel = config->transparentPixel;
- mode->transparentRed = config->transparentRed;
- mode->transparentGreen = config->transparentGreen;
- mode->transparentBlue = config->transparentBlue;
- mode->transparentAlpha = config->transparentAlpha;
- mode->transparentIndex = config->transparentIndex;
- mode->samples = config->multiSampleSize;
- mode->sampleBuffers = config->nMultiSampleBuffers;
- /* mode->visualSelectGroup = config->visualSelectGroup; ? */
-
- mode->swapMethod = GLX_SWAP_UNDEFINED_OML;
-
- mode->bindToTextureRgb = (mode->rgbMode) ? GL_TRUE : GL_FALSE;
- mode->bindToTextureRgba = (mode->rgbMode && mode->alphaBits) ?
- GL_TRUE : GL_FALSE;
- mode->bindToMipmapTexture = mode->rgbMode ? GL_TRUE : GL_FALSE;
- mode->bindToTextureTargets = mode->rgbMode ?
- GLX_TEXTURE_1D_BIT_EXT | GLX_TEXTURE_2D_BIT_EXT |
- GLX_TEXTURE_RECTANGLE_BIT_EXT : 0;
- mode->yInverted = GL_FALSE;
-}
-
-
-/**
- * Get data from a GL context mode.
- *
- * \param mode GL context mode whose data is to be returned.
- * \param attribute Attribute of \c mode that is to be returned.
- * \param value_return Location to store the data member of \c mode.
- * \return If \c attribute is a valid attribute of \c mode, zero is
- * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned.
- */
-int
-_gl_get_context_mode_data(const __GLcontextModes *mode, int attribute,
- int *value_return)
-{
- switch (attribute) {
- case GLX_USE_GL:
- *value_return = GL_TRUE;
- return 0;
- case GLX_BUFFER_SIZE:
- *value_return = mode->rgbBits;
- return 0;
- case GLX_RGBA:
- *value_return = mode->rgbMode;
- return 0;
- case GLX_RED_SIZE:
- *value_return = mode->redBits;
- return 0;
- case GLX_GREEN_SIZE:
- *value_return = mode->greenBits;
- return 0;
- case GLX_BLUE_SIZE:
- *value_return = mode->blueBits;
- return 0;
- case GLX_ALPHA_SIZE:
- *value_return = mode->alphaBits;
- return 0;
- case GLX_DOUBLEBUFFER:
- *value_return = mode->doubleBufferMode;
- return 0;
- case GLX_STEREO:
- *value_return = mode->stereoMode;
- return 0;
- case GLX_AUX_BUFFERS:
- *value_return = mode->numAuxBuffers;
- return 0;
- case GLX_DEPTH_SIZE:
- *value_return = mode->depthBits;
- return 0;
- case GLX_STENCIL_SIZE:
- *value_return = mode->stencilBits;
- return 0;
- case GLX_ACCUM_RED_SIZE:
- *value_return = mode->accumRedBits;
- return 0;
- case GLX_ACCUM_GREEN_SIZE:
- *value_return = mode->accumGreenBits;
- return 0;
- case GLX_ACCUM_BLUE_SIZE:
- *value_return = mode->accumBlueBits;
- return 0;
- case GLX_ACCUM_ALPHA_SIZE:
- *value_return = mode->accumAlphaBits;
- return 0;
- case GLX_LEVEL:
- *value_return = mode->level;
- return 0;
- case GLX_TRANSPARENT_TYPE_EXT:
- *value_return = mode->transparentPixel;
- return 0;
- case GLX_TRANSPARENT_RED_VALUE:
- *value_return = mode->transparentRed;
- return 0;
- case GLX_TRANSPARENT_GREEN_VALUE:
- *value_return = mode->transparentGreen;
- return 0;
- case GLX_TRANSPARENT_BLUE_VALUE:
- *value_return = mode->transparentBlue;
- return 0;
- case GLX_TRANSPARENT_ALPHA_VALUE:
- *value_return = mode->transparentAlpha;
- return 0;
- case GLX_TRANSPARENT_INDEX_VALUE:
- *value_return = mode->transparentIndex;
- return 0;
- case GLX_X_VISUAL_TYPE:
- *value_return = mode->visualType;
- return 0;
- case GLX_CONFIG_CAVEAT:
- *value_return = mode->visualRating;
- return 0;
- case GLX_VISUAL_ID:
- *value_return = mode->visualID;
- return 0;
- case GLX_DRAWABLE_TYPE:
- *value_return = mode->drawableType;
- return 0;
- case GLX_RENDER_TYPE:
- *value_return = mode->renderType;
- return 0;
- case GLX_X_RENDERABLE:
- *value_return = mode->xRenderable;
- return 0;
- case GLX_FBCONFIG_ID:
- *value_return = mode->fbconfigID;
- return 0;
- case GLX_MAX_PBUFFER_WIDTH:
- *value_return = mode->maxPbufferWidth;
- return 0;
- case GLX_MAX_PBUFFER_HEIGHT:
- *value_return = mode->maxPbufferHeight;
- return 0;
- case GLX_MAX_PBUFFER_PIXELS:
- *value_return = mode->maxPbufferPixels;
- return 0;
- case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX:
- *value_return = mode->optimalPbufferWidth;
- return 0;
- case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX:
- *value_return = mode->optimalPbufferHeight;
- return 0;
- case GLX_SWAP_METHOD_OML:
- *value_return = mode->swapMethod;
- return 0;
- case GLX_SAMPLE_BUFFERS_SGIS:
- *value_return = mode->sampleBuffers;
- return 0;
- case GLX_SAMPLES_SGIS:
- *value_return = mode->samples;
- return 0;
- case GLX_BIND_TO_TEXTURE_RGB_EXT:
- *value_return = mode->bindToTextureRgb;
- return 0;
- case GLX_BIND_TO_TEXTURE_RGBA_EXT:
- *value_return = mode->bindToTextureRgba;
- return 0;
- case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
- *value_return = mode->bindToMipmapTexture == GL_TRUE ? GL_TRUE :
- GL_FALSE;
- return 0;
- case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
- *value_return = mode->bindToTextureTargets;
- return 0;
- case GLX_Y_INVERTED_EXT:
- *value_return = mode->yInverted;
- return 0;
-
- /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
- * It is ONLY for communication between the GLX client and the GLX
- * server.
- */
- case GLX_VISUAL_SELECT_GROUP_SGIX:
- default:
- return GLX_BAD_ATTRIBUTE;
- }
-}
-#endif /* !defined(IN_MINI_GLX) */
-
-
-/**
- * Allocate a linked list of \c __GLcontextModes structures. The fields of
- * each structure will be initialized to "reasonable" default values. In
- * most cases this is the default value defined by table 3.4 of the GLX
- * 1.3 specification. This means that most values are either initialized to
- * zero or \c GLX_DONT_CARE (which is -1). As support for additional
- * extensions is added, the new values will be initialized to appropriate
- * values from the extension specification.
- *
- * \param count Number of structures to allocate.
- * \param minimum_size Minimum size of a structure to allocate. This allows
- * for differences in the version of the
- * \c __GLcontextModes stucture used in libGL and in a
- * DRI-based driver.
- * \returns A pointer to the first element in a linked list of \c count
- * stuctures on success, or \c NULL on failure.
- *
- * \warning Use of \c minimum_size does \b not guarantee binary compatibility.
- * The fundamental assumption is that if the \c minimum_size
- * specified by the driver and the size of the \c __GLcontextModes
- * structure in libGL is the same, then the meaning of each byte in
- * the structure is the same in both places. \b Be \b careful!
- * Basically this means that fields have to be added in libGL and
- * then propagated to drivers. Drivers should \b never arbitrarilly
- * extend the \c __GLcontextModes data-structure.
- */
-__GLcontextModes *
-_gl_context_modes_create( unsigned count, size_t minimum_size )
-{
- const size_t size = (minimum_size > sizeof( __GLcontextModes ))
- ? minimum_size : sizeof( __GLcontextModes );
- __GLcontextModes * base = NULL;
- __GLcontextModes ** next;
- unsigned i;
-
- next = & base;
- for ( i = 0 ; i < count ; i++ ) {
- *next = (__GLcontextModes *) _mesa_malloc( size );
- if ( *next == NULL ) {
- _gl_context_modes_destroy( base );
- base = NULL;
- break;
- }
-
- (void) _mesa_memset( *next, 0, size );
- (*next)->visualID = GLX_DONT_CARE;
- (*next)->visualType = GLX_DONT_CARE;
- (*next)->visualRating = GLX_NONE;
- (*next)->transparentPixel = GLX_NONE;
- (*next)->transparentRed = GLX_DONT_CARE;
- (*next)->transparentGreen = GLX_DONT_CARE;
- (*next)->transparentBlue = GLX_DONT_CARE;
- (*next)->transparentAlpha = GLX_DONT_CARE;
- (*next)->transparentIndex = GLX_DONT_CARE;
- (*next)->xRenderable = GLX_DONT_CARE;
- (*next)->fbconfigID = GLX_DONT_CARE;
- (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML;
- (*next)->bindToTextureRgb = GLX_DONT_CARE;
- (*next)->bindToTextureRgba = GLX_DONT_CARE;
- (*next)->bindToMipmapTexture = GLX_DONT_CARE;
- (*next)->bindToTextureTargets = GLX_DONT_CARE;
- (*next)->yInverted = GLX_DONT_CARE;
-
- next = & ((*next)->next);
- }
-
- return base;
-}
-
-
-/**
- * Destroy a linked list of \c __GLcontextModes structures created by
- * \c _gl_context_modes_create.
- *
- * \param modes Linked list of structures to be destroyed. All structres
- * in the list will be freed.
- */
-void
-_gl_context_modes_destroy( __GLcontextModes * modes )
-{
- while ( modes != NULL ) {
- __GLcontextModes * const next = modes->next;
-
- _mesa_free( modes );
- modes = next;
- }
-}
-
-
-/**
- * Find a context mode matching a Visual ID.
- *
- * \param modes List list of context-mode structures to be searched.
- * \param vid Visual ID to be found.
- * \returns A pointer to a context-mode in \c modes if \c vid was found in
- * the list, or \c NULL if it was not.
- */
-
-__GLcontextModes *
-_gl_context_modes_find_visual(__GLcontextModes *modes, int vid)
-{
- __GLcontextModes *m;
-
- for (m = modes; m != NULL; m = m->next)
- if (m->visualID == vid)
- return m;
-
- return NULL;
-}
-
-__GLcontextModes *
-_gl_context_modes_find_fbconfig(__GLcontextModes *modes, int fbid)
-{
- __GLcontextModes *m;
-
- for (m = modes; m != NULL; m = m->next)
- if (m->fbconfigID == fbid)
- return m;
-
- return NULL;
-}
-
-/**
- * Determine if two context-modes are the same. This is intended to be used
- * by libGL implementations to compare to sets of driver generated FBconfigs.
- *
- * \param a Context-mode to be compared.
- * \param b Context-mode to be compared.
- * \returns \c GL_TRUE if the two context-modes are the same. \c GL_FALSE is
- * returned otherwise.
- */
-GLboolean
-_gl_context_modes_are_same( const __GLcontextModes * a,
- const __GLcontextModes * b )
-{
- return( (a->rgbMode == b->rgbMode) &&
- (a->floatMode == b->floatMode) &&
- (a->colorIndexMode == b->colorIndexMode) &&
- (a->doubleBufferMode == b->doubleBufferMode) &&
- (a->stereoMode == b->stereoMode) &&
- (a->redBits == b->redBits) &&
- (a->greenBits == b->greenBits) &&
- (a->blueBits == b->blueBits) &&
- (a->alphaBits == b->alphaBits) &&
-#if 0 /* For some reason these don't get set on the client-side in libGL. */
- (a->redMask == b->redMask) &&
- (a->greenMask == b->greenMask) &&
- (a->blueMask == b->blueMask) &&
- (a->alphaMask == b->alphaMask) &&
-#endif
- (a->rgbBits == b->rgbBits) &&
- (a->indexBits == b->indexBits) &&
- (a->accumRedBits == b->accumRedBits) &&
- (a->accumGreenBits == b->accumGreenBits) &&
- (a->accumBlueBits == b->accumBlueBits) &&
- (a->accumAlphaBits == b->accumAlphaBits) &&
- (a->depthBits == b->depthBits) &&
- (a->stencilBits == b->stencilBits) &&
- (a->numAuxBuffers == b->numAuxBuffers) &&
- (a->level == b->level) &&
- (a->pixmapMode == b->pixmapMode) &&
- (a->visualRating == b->visualRating) &&
-
- (a->transparentPixel == b->transparentPixel) &&
-
- ((a->transparentPixel != GLX_TRANSPARENT_RGB) ||
- ((a->transparentRed == b->transparentRed) &&
- (a->transparentGreen == b->transparentGreen) &&
- (a->transparentBlue == b->transparentBlue) &&
- (a->transparentAlpha == b->transparentAlpha))) &&
-
- ((a->transparentPixel != GLX_TRANSPARENT_INDEX) ||
- (a->transparentIndex == b->transparentIndex)) &&
-
- (a->sampleBuffers == b->sampleBuffers) &&
- (a->samples == b->samples) &&
- ((a->drawableType & b->drawableType) != 0) &&
- (a->renderType == b->renderType) &&
- (a->maxPbufferWidth == b->maxPbufferWidth) &&
- (a->maxPbufferHeight == b->maxPbufferHeight) &&
- (a->maxPbufferPixels == b->maxPbufferPixels) &&
- (a->optimalPbufferWidth == b->optimalPbufferWidth) &&
- (a->optimalPbufferHeight == b->optimalPbufferHeight) &&
- (a->swapMethod == b->swapMethod) &&
- (a->bindToTextureRgb == b->bindToTextureRgb) &&
- (a->bindToTextureRgba == b->bindToTextureRgba) &&
- (a->bindToMipmapTexture == b->bindToMipmapTexture) &&
- (a->bindToTextureTargets == b->bindToTextureTargets) &&
- (a->yInverted == b->yInverted) );
-}
+/* + * (C) Copyright IBM Corporation 2003 + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file glcontextmodes.c + * Utility routines for working with \c __GLcontextModes structures. At + * some point most or all of these functions will be moved to the Mesa + * code base. + * + * \author Ian Romanick <idr@us.ibm.com> + */ + +#if defined(IN_MINI_GLX) +#include <GL/gl.h> +#else +#if defined(HAVE_DIX_CONFIG_H) +#include <dix-config.h> +#endif +#include <X11/X.h> +#include <GL/glx.h> +#include "GL/glxint.h" +#endif + +/* Memory macros */ +#if defined(IN_MINI_GLX) +#include <stdlib.h> +#include <string.h> +#define _mesa_malloc(b) malloc(b) +#define _mesa_free(m) free(m) +#define _mesa_memset memset +#else +#ifdef XFree86Server +#include <os.h> +#include <string.h> +#define _mesa_malloc(b) malloc(b) +#define _mesa_free(m) free(m) +#define _mesa_memset memset +#else +#include <X11/Xlibint.h> +#define _mesa_memset memset +#define _mesa_malloc(b) Xmalloc(b) +#define _mesa_free(m) free(m) +#endif /* XFree86Server */ +#endif /* !defined(IN_MINI_GLX) */ + +#include "glcontextmodes.h" + +#if !defined(IN_MINI_GLX) +#define NUM_VISUAL_TYPES 6 + +/** + * Convert an X visual type to a GLX visual type. + * + * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.) + * to be converted. + * \return If \c visualType is a valid X visual type, a GLX visual type will + * be returned. Otherwise \c GLX_NONE will be returned. + */ +GLint +_gl_convert_from_x_visual_type(int visualType) +{ + static const int glx_visual_types[NUM_VISUAL_TYPES] = { + GLX_STATIC_GRAY, GLX_GRAY_SCALE, + GLX_STATIC_COLOR, GLX_PSEUDO_COLOR, + GLX_TRUE_COLOR, GLX_DIRECT_COLOR + }; + + return ((unsigned) visualType < NUM_VISUAL_TYPES) + ? glx_visual_types[visualType] : GLX_NONE; +} + +/** + * Convert a GLX visual type to an X visual type. + * + * \param visualType GLX visual type (i.e., \c GLX_TRUE_COLOR, + * \c GLX_STATIC_GRAY, etc.) to be converted. + * \return If \c visualType is a valid GLX visual type, an X visual type will + * be returned. Otherwise -1 will be returned. + */ +GLint +_gl_convert_to_x_visual_type(int visualType) +{ + static const int x_visual_types[NUM_VISUAL_TYPES] = { + TrueColor, DirectColor, + PseudoColor, StaticColor, + GrayScale, StaticGray + }; + + return ((unsigned) (visualType - GLX_TRUE_COLOR) < NUM_VISUAL_TYPES) + ? x_visual_types[visualType - GLX_TRUE_COLOR] : -1; +} + +/** + * Copy a GLX visual config structure to a GL context mode structure. All + * of the fields in \c config are copied to \c mode. Additional fields in + * \c mode that can be derrived from the fields of \c config (i.e., + * \c haveDepthBuffer) are also filled in. The remaining fields in \c mode + * that cannot be derived are set to default values. + * + * \param mode Destination GL context mode. + * \param config Source GLX visual config. + * + * \note + * The \c fbconfigID and \c visualID fields of the \c __GLcontextModes + * structure will be set to the \c vid of the \c __GLXvisualConfig structure. + */ +void +_gl_copy_visual_to_context_mode(__GLcontextModes * mode, + const __GLXvisualConfig * config) +{ + __GLcontextModes *const next = mode->next; + + (void) _mesa_memset(mode, 0, sizeof(__GLcontextModes)); + mode->next = next; + + mode->visualID = config->vid; + mode->visualType = _gl_convert_from_x_visual_type(config->class); + mode->xRenderable = GL_TRUE; + mode->fbconfigID = config->vid; + mode->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT; + + mode->rgbMode = (config->rgba != 0); + mode->renderType = (mode->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT; + + mode->colorIndexMode = !(mode->rgbMode); + mode->doubleBufferMode = (config->doubleBuffer != 0); + mode->stereoMode = (config->stereo != 0); + + mode->haveAccumBuffer = ((config->accumRedSize + + config->accumGreenSize + + config->accumBlueSize + + config->accumAlphaSize) > 0); + mode->haveDepthBuffer = (config->depthSize > 0); + mode->haveStencilBuffer = (config->stencilSize > 0); + + mode->redBits = config->redSize; + mode->greenBits = config->greenSize; + mode->blueBits = config->blueSize; + mode->alphaBits = config->alphaSize; + mode->redMask = config->redMask; + mode->greenMask = config->greenMask; + mode->blueMask = config->blueMask; + mode->alphaMask = config->alphaMask; + mode->rgbBits = mode->rgbMode ? config->bufferSize : 0; + mode->indexBits = mode->colorIndexMode ? config->bufferSize : 0; + + mode->accumRedBits = config->accumRedSize; + mode->accumGreenBits = config->accumGreenSize; + mode->accumBlueBits = config->accumBlueSize; + mode->accumAlphaBits = config->accumAlphaSize; + mode->depthBits = config->depthSize; + mode->stencilBits = config->stencilSize; + + mode->numAuxBuffers = config->auxBuffers; + mode->level = config->level; + + mode->visualRating = config->visualRating; + mode->transparentPixel = config->transparentPixel; + mode->transparentRed = config->transparentRed; + mode->transparentGreen = config->transparentGreen; + mode->transparentBlue = config->transparentBlue; + mode->transparentAlpha = config->transparentAlpha; + mode->transparentIndex = config->transparentIndex; + mode->samples = config->multiSampleSize; + mode->sampleBuffers = config->nMultiSampleBuffers; + /* mode->visualSelectGroup = config->visualSelectGroup; ? */ + + mode->swapMethod = GLX_SWAP_UNDEFINED_OML; + + mode->bindToTextureRgb = (mode->rgbMode) ? GL_TRUE : GL_FALSE; + mode->bindToTextureRgba = (mode->rgbMode && mode->alphaBits) ? + GL_TRUE : GL_FALSE; + mode->bindToMipmapTexture = mode->rgbMode ? GL_TRUE : GL_FALSE; + mode->bindToTextureTargets = mode->rgbMode ? + GLX_TEXTURE_1D_BIT_EXT | GLX_TEXTURE_2D_BIT_EXT | + GLX_TEXTURE_RECTANGLE_BIT_EXT : 0; + mode->yInverted = GL_FALSE; +} + +/** + * Get data from a GL context mode. + * + * \param mode GL context mode whose data is to be returned. + * \param attribute Attribute of \c mode that is to be returned. + * \param value_return Location to store the data member of \c mode. + * \return If \c attribute is a valid attribute of \c mode, zero is + * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned. + */ +int +_gl_get_context_mode_data(const __GLcontextModes * mode, int attribute, + int *value_return) +{ + switch (attribute) { + case GLX_USE_GL: + *value_return = GL_TRUE; + return 0; + case GLX_BUFFER_SIZE: + *value_return = mode->rgbBits; + return 0; + case GLX_RGBA: + *value_return = mode->rgbMode; + return 0; + case GLX_RED_SIZE: + *value_return = mode->redBits; + return 0; + case GLX_GREEN_SIZE: + *value_return = mode->greenBits; + return 0; + case GLX_BLUE_SIZE: + *value_return = mode->blueBits; + return 0; + case GLX_ALPHA_SIZE: + *value_return = mode->alphaBits; + return 0; + case GLX_DOUBLEBUFFER: + *value_return = mode->doubleBufferMode; + return 0; + case GLX_STEREO: + *value_return = mode->stereoMode; + return 0; + case GLX_AUX_BUFFERS: + *value_return = mode->numAuxBuffers; + return 0; + case GLX_DEPTH_SIZE: + *value_return = mode->depthBits; + return 0; + case GLX_STENCIL_SIZE: + *value_return = mode->stencilBits; + return 0; + case GLX_ACCUM_RED_SIZE: + *value_return = mode->accumRedBits; + return 0; + case GLX_ACCUM_GREEN_SIZE: + *value_return = mode->accumGreenBits; + return 0; + case GLX_ACCUM_BLUE_SIZE: + *value_return = mode->accumBlueBits; + return 0; + case GLX_ACCUM_ALPHA_SIZE: + *value_return = mode->accumAlphaBits; + return 0; + case GLX_LEVEL: + *value_return = mode->level; + return 0; + case GLX_TRANSPARENT_TYPE_EXT: + *value_return = mode->transparentPixel; + return 0; + case GLX_TRANSPARENT_RED_VALUE: + *value_return = mode->transparentRed; + return 0; + case GLX_TRANSPARENT_GREEN_VALUE: + *value_return = mode->transparentGreen; + return 0; + case GLX_TRANSPARENT_BLUE_VALUE: + *value_return = mode->transparentBlue; + return 0; + case GLX_TRANSPARENT_ALPHA_VALUE: + *value_return = mode->transparentAlpha; + return 0; + case GLX_TRANSPARENT_INDEX_VALUE: + *value_return = mode->transparentIndex; + return 0; + case GLX_X_VISUAL_TYPE: + *value_return = mode->visualType; + return 0; + case GLX_CONFIG_CAVEAT: + *value_return = mode->visualRating; + return 0; + case GLX_VISUAL_ID: + *value_return = mode->visualID; + return 0; + case GLX_DRAWABLE_TYPE: + *value_return = mode->drawableType; + return 0; + case GLX_RENDER_TYPE: + *value_return = mode->renderType; + return 0; + case GLX_X_RENDERABLE: + *value_return = mode->xRenderable; + return 0; + case GLX_FBCONFIG_ID: + *value_return = mode->fbconfigID; + return 0; + case GLX_MAX_PBUFFER_WIDTH: + *value_return = mode->maxPbufferWidth; + return 0; + case GLX_MAX_PBUFFER_HEIGHT: + *value_return = mode->maxPbufferHeight; + return 0; + case GLX_MAX_PBUFFER_PIXELS: + *value_return = mode->maxPbufferPixels; + return 0; + case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX: + *value_return = mode->optimalPbufferWidth; + return 0; + case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX: + *value_return = mode->optimalPbufferHeight; + return 0; + case GLX_SWAP_METHOD_OML: + *value_return = mode->swapMethod; + return 0; + case GLX_SAMPLE_BUFFERS_SGIS: + *value_return = mode->sampleBuffers; + return 0; + case GLX_SAMPLES_SGIS: + *value_return = mode->samples; + return 0; + case GLX_BIND_TO_TEXTURE_RGB_EXT: + *value_return = mode->bindToTextureRgb; + return 0; + case GLX_BIND_TO_TEXTURE_RGBA_EXT: + *value_return = mode->bindToTextureRgba; + return 0; + case GLX_BIND_TO_MIPMAP_TEXTURE_EXT: + *value_return = mode->bindToMipmapTexture == GL_TRUE ? GL_TRUE : + GL_FALSE; + return 0; + case GLX_BIND_TO_TEXTURE_TARGETS_EXT: + *value_return = mode->bindToTextureTargets; + return 0; + case GLX_Y_INVERTED_EXT: + *value_return = mode->yInverted; + return 0; + + /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX. + * It is ONLY for communication between the GLX client and the GLX + * server. + */ + case GLX_VISUAL_SELECT_GROUP_SGIX: + default: + return GLX_BAD_ATTRIBUTE; + } +} +#endif /* !defined(IN_MINI_GLX) */ + +/** + * Allocate a linked list of \c __GLcontextModes structures. The fields of + * each structure will be initialized to "reasonable" default values. In + * most cases this is the default value defined by table 3.4 of the GLX + * 1.3 specification. This means that most values are either initialized to + * zero or \c GLX_DONT_CARE (which is -1). As support for additional + * extensions is added, the new values will be initialized to appropriate + * values from the extension specification. + * + * \param count Number of structures to allocate. + * \param minimum_size Minimum size of a structure to allocate. This allows + * for differences in the version of the + * \c __GLcontextModes stucture used in libGL and in a + * DRI-based driver. + * \returns A pointer to the first element in a linked list of \c count + * stuctures on success, or \c NULL on failure. + * + * \warning Use of \c minimum_size does \b not guarantee binary compatibility. + * The fundamental assumption is that if the \c minimum_size + * specified by the driver and the size of the \c __GLcontextModes + * structure in libGL is the same, then the meaning of each byte in + * the structure is the same in both places. \b Be \b careful! + * Basically this means that fields have to be added in libGL and + * then propagated to drivers. Drivers should \b never arbitrarilly + * extend the \c __GLcontextModes data-structure. + */ +__GLcontextModes * +_gl_context_modes_create(unsigned count, size_t minimum_size) +{ + const size_t size = (minimum_size > sizeof(__GLcontextModes)) + ? minimum_size : sizeof(__GLcontextModes); + __GLcontextModes *base = NULL; + __GLcontextModes **next; + unsigned i; + + next = &base; + for (i = 0; i < count; i++) { + *next = (__GLcontextModes *) _mesa_malloc(size); + if (*next == NULL) { + _gl_context_modes_destroy(base); + base = NULL; + break; + } + + (void) _mesa_memset(*next, 0, size); + (*next)->visualID = GLX_DONT_CARE; + (*next)->visualType = GLX_DONT_CARE; + (*next)->visualRating = GLX_NONE; + (*next)->transparentPixel = GLX_NONE; + (*next)->transparentRed = GLX_DONT_CARE; + (*next)->transparentGreen = GLX_DONT_CARE; + (*next)->transparentBlue = GLX_DONT_CARE; + (*next)->transparentAlpha = GLX_DONT_CARE; + (*next)->transparentIndex = GLX_DONT_CARE; + (*next)->xRenderable = GLX_DONT_CARE; + (*next)->fbconfigID = GLX_DONT_CARE; + (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML; + (*next)->bindToTextureRgb = GLX_DONT_CARE; + (*next)->bindToTextureRgba = GLX_DONT_CARE; + (*next)->bindToMipmapTexture = GLX_DONT_CARE; + (*next)->bindToTextureTargets = GLX_DONT_CARE; + (*next)->yInverted = GLX_DONT_CARE; + + next = &((*next)->next); + } + + return base; +} + +/** + * Destroy a linked list of \c __GLcontextModes structures created by + * \c _gl_context_modes_create. + * + * \param modes Linked list of structures to be destroyed. All structres + * in the list will be freed. + */ +void +_gl_context_modes_destroy(__GLcontextModes * modes) +{ + while (modes != NULL) { + __GLcontextModes *const next = modes->next; + + _mesa_free(modes); + modes = next; + } +} + +/** + * Find a context mode matching a Visual ID. + * + * \param modes List list of context-mode structures to be searched. + * \param vid Visual ID to be found. + * \returns A pointer to a context-mode in \c modes if \c vid was found in + * the list, or \c NULL if it was not. + */ + +__GLcontextModes * +_gl_context_modes_find_visual(__GLcontextModes * modes, int vid) +{ + __GLcontextModes *m; + + for (m = modes; m != NULL; m = m->next) + if (m->visualID == vid) + return m; + + return NULL; +} + +__GLcontextModes * +_gl_context_modes_find_fbconfig(__GLcontextModes * modes, int fbid) +{ + __GLcontextModes *m; + + for (m = modes; m != NULL; m = m->next) + if (m->fbconfigID == fbid) + return m; + + return NULL; +} + +/** + * Determine if two context-modes are the same. This is intended to be used + * by libGL implementations to compare to sets of driver generated FBconfigs. + * + * \param a Context-mode to be compared. + * \param b Context-mode to be compared. + * \returns \c GL_TRUE if the two context-modes are the same. \c GL_FALSE is + * returned otherwise. + */ +GLboolean +_gl_context_modes_are_same(const __GLcontextModes * a, + const __GLcontextModes * b) +{ + return ((a->rgbMode == b->rgbMode) && + (a->floatMode == b->floatMode) && + (a->colorIndexMode == b->colorIndexMode) && + (a->doubleBufferMode == b->doubleBufferMode) && + (a->stereoMode == b->stereoMode) && + (a->redBits == b->redBits) && + (a->greenBits == b->greenBits) && + (a->blueBits == b->blueBits) && (a->alphaBits == b->alphaBits) && +#if 0 /* For some reason these don't get set on the client-side in libGL. */ + (a->redMask == b->redMask) && + (a->greenMask == b->greenMask) && + (a->blueMask == b->blueMask) && (a->alphaMask == b->alphaMask) && +#endif + (a->rgbBits == b->rgbBits) && + (a->indexBits == b->indexBits) && + (a->accumRedBits == b->accumRedBits) && + (a->accumGreenBits == b->accumGreenBits) && + (a->accumBlueBits == b->accumBlueBits) && + (a->accumAlphaBits == b->accumAlphaBits) && + (a->depthBits == b->depthBits) && + (a->stencilBits == b->stencilBits) && + (a->numAuxBuffers == b->numAuxBuffers) && + (a->level == b->level) && + (a->pixmapMode == b->pixmapMode) && + (a->visualRating == b->visualRating) && + (a->transparentPixel == b->transparentPixel) && + ((a->transparentPixel != GLX_TRANSPARENT_RGB) || + ((a->transparentRed == b->transparentRed) && + (a->transparentGreen == b->transparentGreen) && + (a->transparentBlue == b->transparentBlue) && + (a->transparentAlpha == b->transparentAlpha))) && + ((a->transparentPixel != GLX_TRANSPARENT_INDEX) || + (a->transparentIndex == b->transparentIndex)) && + (a->sampleBuffers == b->sampleBuffers) && + (a->samples == b->samples) && + ((a->drawableType & b->drawableType) != 0) && + (a->renderType == b->renderType) && + (a->maxPbufferWidth == b->maxPbufferWidth) && + (a->maxPbufferHeight == b->maxPbufferHeight) && + (a->maxPbufferPixels == b->maxPbufferPixels) && + (a->optimalPbufferWidth == b->optimalPbufferWidth) && + (a->optimalPbufferHeight == b->optimalPbufferHeight) && + (a->swapMethod == b->swapMethod) && + (a->bindToTextureRgb == b->bindToTextureRgb) && + (a->bindToTextureRgba == b->bindToTextureRgba) && + (a->bindToMipmapTexture == b->bindToMipmapTexture) && + (a->bindToTextureTargets == b->bindToTextureTargets) && + (a->yInverted == b->yInverted)); +} diff --git a/xorg-server/hw/xquartz/GL/glcontextmodes.h b/xorg-server/hw/xquartz/GL/glcontextmodes.h index afd09cd7f..871c2e1b3 100644 --- a/xorg-server/hw/xquartz/GL/glcontextmodes.h +++ b/xorg-server/hw/xquartz/GL/glcontextmodes.h @@ -33,22 +33,22 @@ #include "GL/internal/glcore.h" #if !defined(IN_MINI_GLX) -extern GLint _gl_convert_from_x_visual_type( int visualType ); -extern GLint _gl_convert_to_x_visual_type( int visualType ); -extern void _gl_copy_visual_to_context_mode( __GLcontextModes * mode, - const __GLXvisualConfig * config ); -extern int _gl_get_context_mode_data( const __GLcontextModes *mode, - int attribute, int *value_return ); -#endif /* !defined(IN_MINI_GLX) */ +extern GLint _gl_convert_from_x_visual_type(int visualType); +extern GLint _gl_convert_to_x_visual_type(int visualType); +extern void _gl_copy_visual_to_context_mode(__GLcontextModes * mode, + const __GLXvisualConfig * config); +extern int _gl_get_context_mode_data(const __GLcontextModes * mode, + int attribute, int *value_return); +#endif /* !defined(IN_MINI_GLX) */ -extern __GLcontextModes * _gl_context_modes_create( unsigned count, - size_t minimum_size ); -extern void _gl_context_modes_destroy( __GLcontextModes * modes ); -extern __GLcontextModes * - _gl_context_modes_find_visual(__GLcontextModes *modes, int vid); -extern __GLcontextModes * - _gl_context_modes_find_fbconfig(__GLcontextModes *modes, int fbid); -extern GLboolean _gl_context_modes_are_same( const __GLcontextModes * a, - const __GLcontextModes * b ); +extern __GLcontextModes *_gl_context_modes_create(unsigned count, + size_t minimum_size); +extern void _gl_context_modes_destroy(__GLcontextModes * modes); +extern __GLcontextModes *_gl_context_modes_find_visual(__GLcontextModes * modes, + int vid); +extern __GLcontextModes *_gl_context_modes_find_fbconfig(__GLcontextModes * + modes, int fbid); +extern GLboolean _gl_context_modes_are_same(const __GLcontextModes * a, + const __GLcontextModes * b); -#endif /* GLCONTEXTMODES_H */ +#endif /* GLCONTEXTMODES_H */ diff --git a/xorg-server/hw/xquartz/GL/indirect.c b/xorg-server/hw/xquartz/GL/indirect.c index e6ff37668..1f4f79c4b 100644 --- a/xorg-server/hw/xquartz/GL/indirect.c +++ b/xorg-server/hw/xquartz/GL/indirect.c @@ -40,7 +40,7 @@ #include <dlfcn.h> #include <OpenGL/OpenGL.h> -#include <OpenGL/gl.h> /* Just to prevent glxserver.h from loading mesa's and colliding with OpenGL.h */ +#include <OpenGL/gl.h> /* Just to prevent glxserver.h from loading mesa's and colliding with OpenGL.h */ #include <X11/Xproto.h> #include <GL/glxproto.h> @@ -58,22 +58,28 @@ #include "darwin.h" #define GLAQUA_DEBUG_MSG(msg, args...) ASL_LOG(ASL_LEVEL_DEBUG, "GLXAqua", msg, ##args) -__GLXprovider * GlxGetDRISWrastProvider (void); +__GLXprovider *GlxGetDRISWrastProvider(void); static void setup_dispatch_table(void); GLuint __glFloorLog2(GLuint val); -void warn_func(void * p1, char *format, ...); +void warn_func(void *p1, char *format, ...); // some prototypes -static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen); -static __GLXdrawable * __glXAquaScreenCreateDrawable(ClientPtr client, __GLXscreen *screen, DrawablePtr pDraw, XID drawId, int type, XID glxDrawId, __GLXconfig *conf); - -static void __glXAquaContextDestroy(__GLXcontext *baseContext); -static int __glXAquaContextMakeCurrent(__GLXcontext *baseContext); -static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext); -static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask); - -static CGLPixelFormatObj makeFormat(__GLXconfig *conf); +static __GLXscreen *__glXAquaScreenProbe(ScreenPtr pScreen); +static __GLXdrawable *__glXAquaScreenCreateDrawable(ClientPtr client, + __GLXscreen * screen, + DrawablePtr pDraw, + XID drawId, int type, + XID glxDrawId, + __GLXconfig * conf); + +static void __glXAquaContextDestroy(__GLXcontext * baseContext); +static int __glXAquaContextMakeCurrent(__GLXcontext * baseContext); +static int __glXAquaContextLoseCurrent(__GLXcontext * baseContext); +static int __glXAquaContextCopy(__GLXcontext * baseDst, __GLXcontext * baseSrc, + unsigned long mask); + +static CGLPixelFormatObj makeFormat(__GLXconfig * conf); __GLXprovider __glXDRISWRastProvider = { __glXAquaScreenProbe, @@ -81,8 +87,8 @@ __GLXprovider __glXDRISWRastProvider = { NULL }; -typedef struct __GLXAquaScreen __GLXAquaScreen; -typedef struct __GLXAquaContext __GLXAquaContext; +typedef struct __GLXAquaScreen __GLXAquaScreen; +typedef struct __GLXAquaContext __GLXAquaContext; typedef struct __GLXAquaDrawable __GLXAquaDrawable; /* @@ -105,7 +111,7 @@ struct __GLXAquaContext { CGLContextObj ctx; CGLPixelFormatObj pixelFormat; xp_surface_id sid; - unsigned isAttached :1; + unsigned isAttached:1; }; struct __GLXAquaDrawable { @@ -115,35 +121,34 @@ struct __GLXAquaDrawable { __GLXAquaContext *context; }; - static __GLXcontext * -__glXAquaScreenCreateContext(__GLXscreen *screen, - __GLXconfig *conf, - __GLXcontext *baseShareContext) +__glXAquaScreenCreateContext(__GLXscreen * screen, + __GLXconfig * conf, + __GLXcontext * baseShareContext) { __GLXAquaContext *context; __GLXAquaContext *shareContext = (__GLXAquaContext *) baseShareContext; CGLError gl_err; - + GLAQUA_DEBUG_MSG("glXAquaScreenCreateContext\n"); - - context = calloc(1, sizeof (__GLXAquaContext)); - + + context = calloc(1, sizeof(__GLXAquaContext)); + if (context == NULL) - return NULL; + return NULL; memset(context, 0, sizeof *context); - + context->base.pGlxScreen = screen; - - context->base.destroy = __glXAquaContextDestroy; - context->base.makeCurrent = __glXAquaContextMakeCurrent; - context->base.loseCurrent = __glXAquaContextLoseCurrent; - context->base.copy = __glXAquaContextCopy; + + context->base.destroy = __glXAquaContextDestroy; + context->base.makeCurrent = __glXAquaContextMakeCurrent; + context->base.loseCurrent = __glXAquaContextLoseCurrent; + context->base.copy = __glXAquaContextCopy; /*FIXME verify that the context->base is fully initialized. */ - + context->pixelFormat = makeFormat(conf); - + if (!context->pixelFormat) { free(context); return NULL; @@ -151,56 +156,63 @@ __glXAquaScreenCreateContext(__GLXscreen *screen, context->ctx = NULL; gl_err = CGLCreateContext(context->pixelFormat, - shareContext ? shareContext->ctx : NULL, - &context->ctx); - + shareContext ? shareContext->ctx : NULL, + &context->ctx); + if (gl_err != 0) { - ErrorF("CGLCreateContext error: %s\n", CGLErrorString(gl_err)); - CGLDestroyPixelFormat(context->pixelFormat); - free(context); - return NULL; + ErrorF("CGLCreateContext error: %s\n", CGLErrorString(gl_err)); + CGLDestroyPixelFormat(context->pixelFormat); + free(context); + return NULL; } - + setup_dispatch_table(); GLAQUA_DEBUG_MSG("glAquaCreateContext done\n"); - + return &context->base; } /* maps from surface id -> list of __GLcontext */ static x_hash_table *surface_hash; -static void __glXAquaContextDestroy(__GLXcontext *baseContext) { +static void +__glXAquaContextDestroy(__GLXcontext * baseContext) +{ x_list *lst; __GLXAquaContext *context = (__GLXAquaContext *) baseContext; - + GLAQUA_DEBUG_MSG("glAquaContextDestroy (ctx %p)\n", baseContext); if (context != NULL) { - if (context->sid != 0 && surface_hash != NULL) { - lst = x_hash_table_lookup(surface_hash, x_cvt_uint_to_vptr(context->sid), NULL); - lst = x_list_remove(lst, context); - x_hash_table_insert(surface_hash, x_cvt_uint_to_vptr(context->sid), lst); - } - - if (context->ctx != NULL) - CGLDestroyContext(context->ctx); - - if (context->pixelFormat != NULL) - CGLDestroyPixelFormat(context->pixelFormat); - - free(context); + if (context->sid != 0 && surface_hash != NULL) { + lst = + x_hash_table_lookup(surface_hash, + x_cvt_uint_to_vptr(context->sid), NULL); + lst = x_list_remove(lst, context); + x_hash_table_insert(surface_hash, x_cvt_uint_to_vptr(context->sid), + lst); + } + + if (context->ctx != NULL) + CGLDestroyContext(context->ctx); + + if (context->pixelFormat != NULL) + CGLDestroyPixelFormat(context->pixelFormat); + + free(context); } } -static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext) { +static int +__glXAquaContextLoseCurrent(__GLXcontext * baseContext) +{ CGLError gl_err; GLAQUA_DEBUG_MSG("glAquaLoseCurrent (ctx 0x%p)\n", baseContext); gl_err = CGLSetCurrentContext(NULL); if (gl_err != 0) - ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err)); + ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err)); /* * There should be no need to set __glXLastContext to NULL here, because @@ -213,115 +225,126 @@ static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext) { /* Called when a surface is destroyed as a side effect of destroying the window it's attached to. */ -static void surface_notify(void *_arg, void *data) { - DRISurfaceNotifyArg *arg = (DRISurfaceNotifyArg *)_arg; - __GLXAquaDrawable *draw = (__GLXAquaDrawable *)data; +static void +surface_notify(void *_arg, void *data) +{ + DRISurfaceNotifyArg *arg = (DRISurfaceNotifyArg *) _arg; + __GLXAquaDrawable *draw = (__GLXAquaDrawable *) data; __GLXAquaContext *context; x_list *lst; - if(_arg == NULL || data == NULL) { - ErrorF("surface_notify called with bad params"); - return; + + if (_arg == NULL || data == NULL) { + ErrorF("surface_notify called with bad params"); + return; } - + GLAQUA_DEBUG_MSG("surface_notify(%p, %p)\n", _arg, data); switch (arg->kind) { case AppleDRISurfaceNotifyDestroyed: if (surface_hash != NULL) x_hash_table_remove(surface_hash, x_cvt_uint_to_vptr(arg->id)); - draw->pDraw = NULL; - draw->sid = 0; + draw->pDraw = NULL; + draw->sid = 0; break; case AppleDRISurfaceNotifyChanged: if (surface_hash != NULL) { - lst = x_hash_table_lookup(surface_hash, x_cvt_uint_to_vptr(arg->id), NULL); - for (; lst != NULL; lst = lst->next) - { + lst = + x_hash_table_lookup(surface_hash, x_cvt_uint_to_vptr(arg->id), + NULL); + for (; lst != NULL; lst = lst->next) { context = lst->data; xp_update_gl_context(context->ctx); } } break; default: - ErrorF("surface_notify: unknown kind %d\n", arg->kind); - break; + ErrorF("surface_notify: unknown kind %d\n", arg->kind); + break; } } -static BOOL attach(__GLXAquaContext *context, __GLXAquaDrawable *draw) { +static BOOL +attach(__GLXAquaContext * context, __GLXAquaDrawable * draw) +{ DrawablePtr pDraw; - + GLAQUA_DEBUG_MSG("attach(%p, %p)\n", context, draw); - - if(NULL == context || NULL == draw) - return TRUE; + + if (NULL == context || NULL == draw) + return TRUE; pDraw = draw->base.pDraw; - if(NULL == pDraw) { - ErrorF("%s:%s() pDraw is NULL!\n", __FILE__, __func__); - return TRUE; + if (NULL == pDraw) { + ErrorF("%s:%s() pDraw is NULL!\n", __FILE__, __func__); + return TRUE; } if (draw->sid == 0) { - //if (!quartzProcs->CreateSurface(pDraw->pScreen, pDraw->id, pDraw, + //if (!quartzProcs->CreateSurface(pDraw->pScreen, pDraw->id, pDraw, if (!DRICreateSurface(pDraw->pScreen, pDraw->id, pDraw, - 0, &draw->sid, NULL, - surface_notify, draw)) + 0, &draw->sid, NULL, surface_notify, draw)) return TRUE; draw->pDraw = pDraw; - } - + } + if (!context->isAttached || context->sid != draw->sid) { x_list *lst; - + if (xp_attach_gl_context(context->ctx, draw->sid) != Success) { - //quartzProcs->DestroySurface(pDraw->pScreen, pDraw->id, pDraw, + //quartzProcs->DestroySurface(pDraw->pScreen, pDraw->id, pDraw, DRIDestroySurface(pDraw->pScreen, pDraw->id, pDraw, - surface_notify, draw); + surface_notify, draw); if (surface_hash != NULL) - x_hash_table_remove(surface_hash, x_cvt_uint_to_vptr(draw->sid)); - + x_hash_table_remove(surface_hash, + x_cvt_uint_to_vptr(draw->sid)); + draw->sid = 0; return TRUE; } - + context->isAttached = TRUE; context->sid = draw->sid; - + if (surface_hash == NULL) surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL); - - lst = x_hash_table_lookup(surface_hash, x_cvt_uint_to_vptr(context->sid), NULL); + + lst = + x_hash_table_lookup(surface_hash, x_cvt_uint_to_vptr(context->sid), + NULL); if (x_list_find(lst, context) == NULL) { lst = x_list_prepend(lst, context); - x_hash_table_insert(surface_hash, x_cvt_uint_to_vptr(context->sid), lst); + x_hash_table_insert(surface_hash, x_cvt_uint_to_vptr(context->sid), + lst); } - - GLAQUA_DEBUG_MSG("attached 0x%x to 0x%x\n", (unsigned int) pDraw->id, (unsigned int) draw->sid); - } + } draw->context = context; return FALSE; } -#if 0 // unused -static void unattach(__GLXAquaContext *context) { - x_list *lst; - GLAQUA_DEBUG_MSG("unattach\n"); - if (context == NULL) { - ErrorF("Tried to unattach a null context\n"); - return; - } +#if 0 // unused +static void +unattach(__GLXAquaContext * context) +{ + x_list *lst; + + GLAQUA_DEBUG_MSG("unattach\n"); + if (context == NULL) { + ErrorF("Tried to unattach a null context\n"); + return; + } if (context->isAttached) { GLAQUA_DEBUG_MSG("unattaching\n"); if (surface_hash != NULL) { - lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL); + lst = + x_hash_table_lookup(surface_hash, (void *) context->sid, NULL); lst = x_list_remove(lst, context); x_hash_table_insert(surface_hash, (void *) context->sid, lst); } @@ -333,24 +356,28 @@ static void unattach(__GLXAquaContext *context) { } #endif -static int __glXAquaContextMakeCurrent(__GLXcontext *baseContext) { +static int +__glXAquaContextMakeCurrent(__GLXcontext * baseContext) +{ CGLError gl_err; __GLXAquaContext *context = (__GLXAquaContext *) baseContext; __GLXAquaDrawable *drawPriv = (__GLXAquaDrawable *) context->base.drawPriv; - + GLAQUA_DEBUG_MSG("glAquaMakeCurrent (ctx 0x%p)\n", baseContext); - - if(attach(context, drawPriv)) - return /*error*/ 0; + + if (attach(context, drawPriv)) + return /*error */ 0; gl_err = CGLSetCurrentContext(context->ctx); if (gl_err != 0) ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err)); - + return gl_err == 0; } -static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask) +static int +__glXAquaContextCopy(__GLXcontext * baseDst, __GLXcontext * baseSrc, + unsigned long mask) { CGLError gl_err; @@ -367,95 +394,100 @@ static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, un } /* Drawing surface notification callbacks */ -static GLboolean __glXAquaDrawableSwapBuffers(ClientPtr client, __GLXdrawable *base) { +static GLboolean +__glXAquaDrawableSwapBuffers(ClientPtr client, __GLXdrawable * base) +{ CGLError err; __GLXAquaDrawable *drawable; - + // GLAQUA_DEBUG_MSG("glAquaDrawableSwapBuffers(%p)\n",base); - - if(!base) { - ErrorF("%s passed NULL\n", __func__); - return GL_FALSE; + + if (!base) { + ErrorF("%s passed NULL\n", __func__); + return GL_FALSE; } - drawable = (__GLXAquaDrawable *)base; + drawable = (__GLXAquaDrawable *) base; - if(NULL == drawable->context) { - ErrorF("%s called with a NULL->context for drawable %p!\n", - __func__, (void *)drawable); - return GL_FALSE; + if (NULL == drawable->context) { + ErrorF("%s called with a NULL->context for drawable %p!\n", + __func__, (void *) drawable); + return GL_FALSE; } err = CGLFlushDrawable(drawable->context->ctx); - if(kCGLNoError != err) { - ErrorF("CGLFlushDrawable error: %s in %s\n", CGLErrorString(err), - __func__); - return GL_FALSE; + if (kCGLNoError != err) { + ErrorF("CGLFlushDrawable error: %s in %s\n", CGLErrorString(err), + __func__); + return GL_FALSE; } return GL_TRUE; } - -static CGLPixelFormatObj makeFormat(__GLXconfig *conf) { +static CGLPixelFormatObj +makeFormat(__GLXconfig * conf) +{ CGLPixelFormatAttribute attr[64]; CGLPixelFormatObj fobj; GLint formats; CGLError error; int i = 0; - - if(conf->doubleBufferMode) - attr[i++] = kCGLPFADoubleBuffer; - if(conf->stereoMode) - attr[i++] = kCGLPFAStereo; + if (conf->doubleBufferMode) + attr[i++] = kCGLPFADoubleBuffer; + + if (conf->stereoMode) + attr[i++] = kCGLPFAStereo; attr[i++] = kCGLPFAColorSize; attr[i++] = conf->redBits + conf->greenBits + conf->blueBits; attr[i++] = kCGLPFAAlphaSize; attr[i++] = conf->alphaBits; - if((conf->accumRedBits + conf->accumGreenBits + conf->accumBlueBits + - conf->accumAlphaBits) > 0) { + if ((conf->accumRedBits + conf->accumGreenBits + conf->accumBlueBits + + conf->accumAlphaBits) > 0) { - attr[i++] = kCGLPFAAccumSize; + attr[i++] = kCGLPFAAccumSize; attr[i++] = conf->accumRedBits + conf->accumGreenBits - + conf->accumBlueBits + conf->accumAlphaBits; + + conf->accumBlueBits + conf->accumAlphaBits; } - + attr[i++] = kCGLPFADepthSize; attr[i++] = conf->depthBits; - if(conf->stencilBits) { - attr[i++] = kCGLPFAStencilSize; - attr[i++] = conf->stencilBits; + if (conf->stencilBits) { + attr[i++] = kCGLPFAStencilSize; + attr[i++] = conf->stencilBits; } - - if(conf->numAuxBuffers > 0) { - attr[i++] = kCGLPFAAuxBuffers; - attr[i++] = conf->numAuxBuffers; + + if (conf->numAuxBuffers > 0) { + attr[i++] = kCGLPFAAuxBuffers; + attr[i++] = conf->numAuxBuffers; } - if(conf->sampleBuffers > 0) { - attr[i++] = kCGLPFASampleBuffers; - attr[i++] = conf->sampleBuffers; - attr[i++] = kCGLPFASamples; - attr[i++] = conf->samples; + if (conf->sampleBuffers > 0) { + attr[i++] = kCGLPFASampleBuffers; + attr[i++] = conf->sampleBuffers; + attr[i++] = kCGLPFASamples; + attr[i++] = conf->samples; } - + attr[i] = 0; error = CGLChoosePixelFormat(attr, &fobj, &formats); - if(error) { - ErrorF("error: creating pixel format %s\n", CGLErrorString(error)); - return NULL; + if (error) { + ErrorF("error: creating pixel format %s\n", CGLErrorString(error)); + return NULL; } return fobj; } -static void __glXAquaScreenDestroy(__GLXscreen *screen) { +static void +__glXAquaScreenDestroy(__GLXscreen * screen) +{ GLAQUA_DEBUG_MSG("glXAquaScreenDestroy(%p)\n", screen); __glXScreenDestroy(screen); @@ -464,26 +496,30 @@ static void __glXAquaScreenDestroy(__GLXscreen *screen) { } /* This is called by __glXInitScreens(). */ -static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen) { +static __GLXscreen * +__glXAquaScreenProbe(ScreenPtr pScreen) +{ __GLXAquaScreen *screen; GLAQUA_DEBUG_MSG("glXAquaScreenProbe\n"); - if (pScreen == NULL) - return NULL; + if (pScreen == NULL) + return NULL; screen = calloc(1, sizeof *screen); - if(NULL == screen) - return NULL; - - screen->base.destroy = __glXAquaScreenDestroy; - screen->base.createContext = __glXAquaScreenCreateContext; + if (NULL == screen) + return NULL; + + screen->base.destroy = __glXAquaScreenDestroy; + screen->base.createContext = __glXAquaScreenCreateContext; screen->base.createDrawable = __glXAquaScreenCreateDrawable; screen->base.swapInterval = /*FIXME*/ NULL; - screen->base.pScreen = pScreen; - - screen->base.fbconfigs = __glXAquaCreateVisualConfigs(&screen->base.numFBConfigs, pScreen->myNum); + screen->base.pScreen = pScreen; + + screen->base.fbconfigs = + __glXAquaCreateVisualConfigs(&screen->base.numFBConfigs, + pScreen->myNum); __glXScreenInit(&screen->base, pScreen); @@ -494,29 +530,33 @@ static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen) { "GLX_ARB_multisample " "GLX_EXT_visual_info " "GLX_EXT_import_context "); - + /*We may be able to add more GLXextensions at a later time. */ - + return &screen->base; } -#if 0 // unused -static void __glXAquaDrawableCopySubBuffer (__GLXdrawable *drawable, - int x, int y, int w, int h) { - /*TODO finish me*/ +#if 0 // unused +static void +__glXAquaDrawableCopySubBuffer(__GLXdrawable * drawable, + int x, int y, int w, int h) +{ + /*TODO finish me */ } #endif -static void __glXAquaDrawableDestroy(__GLXdrawable *base) { +static void +__glXAquaDrawableDestroy(__GLXdrawable * base) +{ /* gstaplin: base is the head of the structure, so it's at the same * offset in memory. * Is this safe with strict aliasing? I noticed that the other dri code * does this too... */ - __GLXAquaDrawable *glxPriv = (__GLXAquaDrawable *)base; + __GLXAquaDrawable *glxPriv = (__GLXAquaDrawable *) base; GLAQUA_DEBUG_MSG("TRACE"); - + /* It doesn't work to call DRIDestroySurface here, the drawable's already gone.. But dri.c notices the window destruction and frees the surface itself. */ @@ -533,40 +573,41 @@ static void __glXAquaDrawableDestroy(__GLXdrawable *base) { static __GLXdrawable * __glXAquaScreenCreateDrawable(ClientPtr client, - __GLXscreen *screen, - DrawablePtr pDraw, - XID drawId, - int type, - XID glxDrawId, - __GLXconfig *conf) { - __GLXAquaDrawable *glxPriv; + __GLXscreen * screen, + DrawablePtr pDraw, + XID drawId, + int type, XID glxDrawId, __GLXconfig * conf) +{ + __GLXAquaDrawable *glxPriv; - glxPriv = malloc(sizeof *glxPriv); + glxPriv = malloc(sizeof *glxPriv); - if(glxPriv == NULL) - return NULL; + if (glxPriv == NULL) + return NULL; - memset(glxPriv, 0, sizeof *glxPriv); + memset(glxPriv, 0, sizeof *glxPriv); - if(!__glXDrawableInit(&glxPriv->base, screen, pDraw, type, glxDrawId, conf)) { - free(glxPriv); - return NULL; - } - - glxPriv->base.destroy = __glXAquaDrawableDestroy; - glxPriv->base.swapBuffers = __glXAquaDrawableSwapBuffers; - glxPriv->base.copySubBuffer = NULL; /* __glXAquaDrawableCopySubBuffer; */ - - glxPriv->pDraw = pDraw; - glxPriv->sid = 0; - glxPriv->context = NULL; - - return &glxPriv->base; + if (!__glXDrawableInit + (&glxPriv->base, screen, pDraw, type, glxDrawId, conf)) { + free(glxPriv); + return NULL; + } + + glxPriv->base.destroy = __glXAquaDrawableDestroy; + glxPriv->base.swapBuffers = __glXAquaDrawableSwapBuffers; + glxPriv->base.copySubBuffer = NULL; /* __glXAquaDrawableCopySubBuffer; */ + + glxPriv->pDraw = pDraw; + glxPriv->sid = 0; + glxPriv->context = NULL; + + return &glxPriv->base; } // Extra goodies for glx -GLuint __glFloorLog2(GLuint val) +GLuint +__glFloorLog2(GLuint val) { int c = 0; @@ -581,12 +622,14 @@ GLuint __glFloorLog2(GLuint val) #define OPENGL_FRAMEWORK_PATH "/System/Library/Frameworks/OpenGL.framework/OpenGL" #endif -static void setup_dispatch_table(void) { +static void +setup_dispatch_table(void) +{ static struct _glapi_table *disp = NULL; static void *handle; const char *opengl_framework_path; - if(disp) { + if (disp) { _glapi_set_dispatch(disp); return; } @@ -596,12 +639,12 @@ static void setup_dispatch_table(void) { opengl_framework_path = OPENGL_FRAMEWORK_PATH; } - (void) dlerror(); /*drain dlerror */ + (void) dlerror(); /*drain dlerror */ handle = dlopen(opengl_framework_path, RTLD_LOCAL); if (!handle) { ErrorF("unable to dlopen %s : %s, using RTLD_DEFAULT\n", - opengl_framework_path, dlerror()); + opengl_framework_path, dlerror()); handle = RTLD_DEFAULT; } diff --git a/xorg-server/hw/xquartz/GL/visualConfigs.c b/xorg-server/hw/xquartz/GL/visualConfigs.c index 2c2a9a29e..c02427c99 100644 --- a/xorg-server/hw/xquartz/GL/visualConfigs.c +++ b/xorg-server/hw/xquartz/GL/visualConfigs.c @@ -58,83 +58,98 @@ #include "darwinfb.h" /* Based originally on code from indirect.c which was based on code from i830_dri.c. */ -__GLXconfig *__glXAquaCreateVisualConfigs(int *numConfigsPtr, int screenNumber) { +__GLXconfig * +__glXAquaCreateVisualConfigs(int *numConfigsPtr, int screenNumber) +{ int numConfigs = 0; __GLXconfig *visualConfigs, *c; struct glCapabilities caps; struct glCapabilitiesConfig *conf; int stereo, depth, aux, buffers, stencil, accum, color, msample; - - if(getGlCapabilities(&caps)) { + + if (getGlCapabilities(&caps)) { ErrorF("error from getGlCapabilities()!\n"); return NULL; } - + /* - conf->stereo is 0 or 1, but we need at least 1 iteration of the loop, - so we treat a true conf->stereo as 2. - - The depth size is 0 or 24. Thus we do 2 iterations for that. - - conf->aux_buffers (when available/non-zero) result in 2 iterations instead of 1. - - conf->buffers indicates whether we have single or double buffering. - - conf->total_stencil_bit_depths - - conf->total_color_buffers indicates the RGB/RGBA color depths. - - conf->total_accum_buffers iterations for accum (with at least 1 if equal to 0) - - conf->total_depth_buffer_depths - - conf->multisample_buffers iterations (with at least 1 if equal to 0). We add 1 - for the 0 multisampling config. - + conf->stereo is 0 or 1, but we need at least 1 iteration of the loop, + so we treat a true conf->stereo as 2. + + The depth size is 0 or 24. Thus we do 2 iterations for that. + + conf->aux_buffers (when available/non-zero) result in 2 iterations instead of 1. + + conf->buffers indicates whether we have single or double buffering. + + conf->total_stencil_bit_depths + + conf->total_color_buffers indicates the RGB/RGBA color depths. + + conf->total_accum_buffers iterations for accum (with at least 1 if equal to 0) + + conf->total_depth_buffer_depths + + conf->multisample_buffers iterations (with at least 1 if equal to 0). We add 1 + for the 0 multisampling config. + */ - + assert(NULL != caps.configurations); - + numConfigs = 0; - - for(conf = caps.configurations; conf; conf = conf->next) { - if(conf->total_color_buffers <= 0) + + for (conf = caps.configurations; conf; conf = conf->next) { + if (conf->total_color_buffers <= 0) continue; - - numConfigs += (conf->stereo ? 2 : 1) - * (conf->aux_buffers ? 2 : 1) - * conf->buffers - * ((conf->total_stencil_bit_depths > 0) ? conf->total_stencil_bit_depths : 1) - * conf->total_color_buffers - * ((conf->total_accum_buffers > 0) ? conf->total_accum_buffers : 1) - * conf->total_depth_buffer_depths - * (conf->multisample_buffers + 1); + + numConfigs += (conf->stereo ? 2 : 1) + * (conf->aux_buffers ? 2 : 1) + * conf->buffers + * + ((conf->total_stencil_bit_depths > + 0) ? conf->total_stencil_bit_depths : 1) + * conf->total_color_buffers * + ((conf->total_accum_buffers > 0) ? conf->total_accum_buffers : 1) + * conf->total_depth_buffer_depths * (conf->multisample_buffers + 1); } - - if(numConfigsPtr) - *numConfigsPtr = numConfigs; - + + if (numConfigsPtr) + *numConfigsPtr = numConfigs; + visualConfigs = calloc(sizeof(*visualConfigs), numConfigs); - - if(NULL == visualConfigs) { + + if (NULL == visualConfigs) { ErrorF("xcalloc failure when allocating visualConfigs\n"); freeGlCapabilities(&caps); return NULL; } - - c = visualConfigs; /* current buffer */ - for(conf = caps.configurations; conf; conf = conf->next) { - for(stereo = 0; stereo < (conf->stereo ? 2 : 1); ++stereo) { - for(aux = 0; aux < (conf->aux_buffers ? 2 : 1); ++aux) { - for(buffers = 0; buffers < conf->buffers; ++buffers) { - for(stencil = 0; stencil < ((conf->total_stencil_bit_depths > 0) ? - conf->total_stencil_bit_depths : 1); ++stencil) { - for(color = 0; color < conf->total_color_buffers; ++color) { - for(accum = 0; accum < ((conf->total_accum_buffers > 0) ? - conf->total_accum_buffers : 1); ++accum) { - for(depth = 0; depth < conf->total_depth_buffer_depths; ++depth) { - for(msample = 0; msample < (conf->multisample_buffers + 1); ++msample) { - + + c = visualConfigs; /* current buffer */ + for (conf = caps.configurations; conf; conf = conf->next) { + for (stereo = 0; stereo < (conf->stereo ? 2 : 1); ++stereo) { + for (aux = 0; aux < (conf->aux_buffers ? 2 : 1); ++aux) { + for (buffers = 0; buffers < conf->buffers; ++buffers) { + for (stencil = 0; + stencil < + ((conf->total_stencil_bit_depths > + 0) ? conf->total_stencil_bit_depths : 1); + ++stencil) { + for (color = 0; color < conf->total_color_buffers; + ++color) { + for (accum = 0; + accum < + ((conf->total_accum_buffers > + 0) ? conf->total_accum_buffers : 1); + ++accum) { + for (depth = 0; + depth < conf->total_depth_buffer_depths; + ++depth) { + for (msample = 0; + msample < + (conf->multisample_buffers + 1); + ++msample) { + // Global c->visualID = -1; c->visualType = GLX_TRUE_COLOR; @@ -144,99 +159,137 @@ __GLXconfig *__glXAquaCreateVisualConfigs(int *numConfigsPtr, int screenNumber) c->level = 0; c->indexBits = 0; - c->pixmapMode = 0; // TODO: What should this be? - - if(conf->accelerated) { + c->pixmapMode = 0; // TODO: What should this be? + + if (conf->accelerated) { c->visualRating = GLX_NONE; - } else { - c->visualRating = GLX_SLOW_VISUAL_EXT; } - + else { + c->visualRating = + GLX_SLOW_VISUAL_EXT; + } + c->transparentPixel = GLX_NONE; c->transparentRed = GLX_NONE; c->transparentGreen = GLX_NONE; c->transparentBlue = GLX_NONE; c->transparentAlpha = GLX_NONE; c->transparentIndex = GLX_NONE; - + c->visualSelectGroup = 0; - + c->swapMethod = GLX_SWAP_UNDEFINED_OML; - + // Stereo c->stereoMode = stereo ? TRUE : FALSE; // Aux buffers - c->numAuxBuffers = aux ? conf->aux_buffers : 0; - + c->numAuxBuffers = + aux ? conf->aux_buffers : 0; + // Double Buffered - c->doubleBufferMode = buffers ? TRUE : FALSE; + c->doubleBufferMode = + buffers ? TRUE : FALSE; // Stencil Buffer - if(conf->total_stencil_bit_depths > 0) { - c->stencilBits = conf->stencil_bit_depths[stencil]; - } else { + if (conf->total_stencil_bit_depths > 0) { + c->stencilBits = + conf-> + stencil_bit_depths[stencil]; + } + else { c->stencilBits = 0; } - + // Color - if(GLCAPS_COLOR_BUF_INVALID_VALUE != conf->color_buffers[color].a) { - c->alphaBits = conf->color_buffers[color].a; - } else { + if (GLCAPS_COLOR_BUF_INVALID_VALUE != + conf->color_buffers[color].a) { + c->alphaBits = + conf->color_buffers[color].a; + } + else { c->alphaBits = 0; } - c->redBits = conf->color_buffers[color].r; - c->greenBits = conf->color_buffers[color].g; - c->blueBits = conf->color_buffers[color].b; - - c->rgbBits = c->alphaBits + c->redBits + c->greenBits + c->blueBits; - - c->alphaMask = AM_ARGB(c->alphaBits, c->redBits, c->greenBits, c->blueBits); - c->redMask = RM_ARGB(c->alphaBits, c->redBits, c->greenBits, c->blueBits); - c->greenMask = GM_ARGB(c->alphaBits, c->redBits, c->greenBits, c->blueBits); - c->blueMask = BM_ARGB(c->alphaBits, c->redBits, c->greenBits, c->blueBits); - + c->redBits = + conf->color_buffers[color].r; + c->greenBits = + conf->color_buffers[color].g; + c->blueBits = + conf->color_buffers[color].b; + + c->rgbBits = + c->alphaBits + c->redBits + + c->greenBits + c->blueBits; + + c->alphaMask = + AM_ARGB(c->alphaBits, c->redBits, + c->greenBits, c->blueBits); + c->redMask = + RM_ARGB(c->alphaBits, c->redBits, + c->greenBits, c->blueBits); + c->greenMask = + GM_ARGB(c->alphaBits, c->redBits, + c->greenBits, c->blueBits); + c->blueMask = + BM_ARGB(c->alphaBits, c->redBits, + c->greenBits, c->blueBits); + // Accumulation Buffers - if(conf->total_accum_buffers > 0) { - c->accumRedBits = conf->accum_buffers[accum].r; - c->accumGreenBits = conf->accum_buffers[accum].g; - c->accumBlueBits = conf->accum_buffers[accum].b; - if(GLCAPS_COLOR_BUF_INVALID_VALUE != conf->accum_buffers[accum].a) { - c->accumAlphaBits = conf->accum_buffers[accum].a; - } else { + if (conf->total_accum_buffers > 0) { + c->accumRedBits = + conf->accum_buffers[accum].r; + c->accumGreenBits = + conf->accum_buffers[accum].g; + c->accumBlueBits = + conf->accum_buffers[accum].b; + if (GLCAPS_COLOR_BUF_INVALID_VALUE + != + conf->accum_buffers[accum].a) { + c->accumAlphaBits = + conf->accum_buffers[accum]. + a; + } + else { c->accumAlphaBits = 0; } - } else { + } + else { c->accumRedBits = 0; c->accumGreenBits = 0; c->accumBlueBits = 0; c->accumAlphaBits = 0; - } + } // Depth - c->depthBits = conf->depth_buffers[depth]; - + c->depthBits = + conf->depth_buffers[depth]; + // MultiSample - if(msample > 0) { - c->samples = conf->multisample_samples; - c->sampleBuffers = conf->multisample_buffers; - } else { + if (msample > 0) { + c->samples = + conf->multisample_samples; + c->sampleBuffers = + conf->multisample_buffers; + } + else { c->samples = 0; c->sampleBuffers = 0; } - + /* * The Apple libGL supports GLXPixmaps and * GLXPbuffers in direct mode. */ /* SGIX_fbconfig / GLX 1.3 */ - c->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT; + c->drawableType = + GLX_WINDOW_BIT | GLX_PIXMAP_BIT | + GLX_PBUFFER_BIT; c->renderType = GLX_RGBA_BIT; c->xRenderable = GL_TRUE; c->fbconfigID = -1; - + /* SGIX_pbuffer / GLX 1.3 */ - + /* * The CGL layer provides a way of retrieving * the maximum pbuffer width/height, but only @@ -247,21 +300,22 @@ __GLXconfig *__glXAquaCreateVisualConfigs(int *numConfigsPtr, int screenNumber) */ c->maxPbufferWidth = 8192; c->maxPbufferHeight = 8192; - c->maxPbufferPixels = /*Do we need this?*/ 0; + c->maxPbufferPixels = + /*Do we need this? */ 0; /* * There is no introspection for this sort of thing * with CGL. What should we do realistically? */ c->optimalPbufferWidth = 0; c->optimalPbufferHeight = 0; - + /* EXT_texture_from_pixmap */ c->bindToTextureRgb = 0; c->bindToTextureRgba = 0; c->bindToMipmapTexture = 0; c->bindToTextureTargets = 0; c->yInverted = 0; - + c = c->next; } } @@ -273,12 +327,14 @@ __GLXconfig *__glXAquaCreateVisualConfigs(int *numConfigsPtr, int screenNumber) } } - (c-1)->next = NULL; + (c - 1)->next = NULL; if (c - visualConfigs != numConfigs) { - FatalError("numConfigs calculation error in setVisualConfigs! numConfigs is %d i is %d\n", numConfigs, (int)(c - visualConfigs)); + FatalError + ("numConfigs calculation error in setVisualConfigs! numConfigs is %d i is %d\n", + numConfigs, (int) (c - visualConfigs)); } - + freeGlCapabilities(&caps); return visualConfigs; } diff --git a/xorg-server/hw/xquartz/X11Application.h b/xorg-server/hw/xquartz/X11Application.h index baee29d4c..bdbe6ac1f 100644 --- a/xorg-server/hw/xquartz/X11Application.h +++ b/xorg-server/hw/xquartz/X11Application.h @@ -34,49 +34,79 @@ #import "X11Controller.h" -@interface X11Application : NSApplication { + @ interface X11Application:NSApplication { X11Controller *_controller; - unsigned int _x_active :1; + unsigned int _x_active:1; } -- (void) set_controller:controller; -- (void) set_window_menu:(NSArray *)list; + -(void) set_controller:controller; + -(void) set_window_menu:(NSArray *) list; -- (CFPropertyListRef) prefs_get_copy:(NSString *)key CF_RETURNS_RETAINED; -- (int) prefs_get_integer:(NSString *)key default:(int)def; -- (const char *) prefs_get_string:(NSString *)key default:(const char *)def; -- (float) prefs_get_float:(NSString *)key default:(float)def; -- (int) prefs_get_boolean:(NSString *)key default:(int)def; -- (NSURL *) prefs_copy_url:(NSString *)key default:(NSURL *)def NS_RETURNS_RETAINED; -- (NSArray *) prefs_get_array:(NSString *)key; -- (void) prefs_set_integer:(NSString *)key value:(int)value; -- (void) prefs_set_float:(NSString *)key value:(float)value; -- (void) prefs_set_boolean:(NSString *)key value:(int)value; -- (void) prefs_set_array:(NSString *)key value:(NSArray *)value; -- (void) prefs_set_string:(NSString *)key value:(NSString *)value; -- (void) prefs_synchronize; + -(CFPropertyListRef) prefs_get_copy:(NSString *) +key CF_RETURNS_RETAINED; -- (X11Controller *) controller; -- (OSX_BOOL) x_active; -@end + -(int) prefs_get_integer:(NSString *) +key default:(int) def; -extern X11Application *X11App; + -(const char *) prefs_get_string:(NSString *) +key default:(const char *) def; -#endif /* __OBJC__ */ + -(float) prefs_get_float:(NSString *) +key default:(float) def; -void X11ApplicationSetWindowMenu (int nitems, const char **items, - const char *shortcuts); -void X11ApplicationSetWindowMenuCheck (int idx); -void X11ApplicationSetFrontProcess (void); -void X11ApplicationSetCanQuit (int state); -void X11ApplicationServerReady (void); -void X11ApplicationShowHideMenubar (int state); -void X11ApplicationLaunchClient (const char *cmd); + -(int) prefs_get_boolean:(NSString *) +key default:(int) def; -Bool X11ApplicationCanEnterRandR (void); + -(NSURL *) prefs_copy_url:(NSString *) +key default:(NSURL *) +def NS_RETURNS_RETAINED; -void X11ApplicationMain(int argc, char **argv, char **envp); + -(NSArray *) prefs_get_array:(NSString *) key; + -(void) prefs_set_integer:(NSString *) +key value:(int) value; + + -(void) prefs_set_float:(NSString *) +key value:(float) value; + + -(void) prefs_set_boolean:(NSString *) +key value:(int) value; + + -(void) prefs_set_array:(NSString *) +key value:(NSArray *) value; + + -(void) prefs_set_string:(NSString *) +key value:(NSString *) value; + +-(void) prefs_synchronize; + +-(X11Controller *) controller; +-(OSX_BOOL) x_active; +@end extern X11Application *X11App; + +#endif /* __OBJC__ */ + +void +X11ApplicationSetWindowMenu(int nitems, const char **items, + const char *shortcuts); +void +X11ApplicationSetWindowMenuCheck(int idx); +void +X11ApplicationSetFrontProcess(void); +void +X11ApplicationSetCanQuit(int state); +void +X11ApplicationServerReady(void); +void +X11ApplicationShowHideMenubar(int state); +void +X11ApplicationLaunchClient(const char *cmd); + +Bool +X11ApplicationCanEnterRandR(void); + +void +X11ApplicationMain(int argc, char **argv, char **envp); #define PREFS_APPSMENU "apps_menu" #define PREFS_FAKEBUTTONS "enable_fake_buttons" @@ -113,4 +143,4 @@ extern Bool XQuartzScrollInDeviceDirection; #define PREFS_SYNC_CLIPBOARD_TO_PB "sync_clipboard_to_pasteboard" #define PREFS_SYNC_PRIMARY_ON_SELECT "sync_primary_on_select" -#endif /* X11APPLICATION_H */ +#endif /* X11APPLICATION_H */ diff --git a/xorg-server/hw/xquartz/X11Application.m b/xorg-server/hw/xquartz/X11Application.m index 048e7875b..e091fbb3d 100644 --- a/xorg-server/hw/xquartz/X11Application.m +++ b/xorg-server/hw/xquartz/X11Application.m @@ -54,7 +54,7 @@ #include <Xplugin.h> // pbproxy/pbproxy.h -extern int xpbproxy_run (void); +extern int xpbproxy_run(void); #define DEFAULTS_FILE X11LIBDIR"/X11/xserver/Xquartz.plist" @@ -95,115 +95,129 @@ CFStringRef app_prefs_domain_cfstr = NULL; #define ALL_KEY_MASKS (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask) -@interface X11Application (Private) -- (void) sendX11NSEvent:(NSEvent *)e; -@end - -@implementation X11Application - -typedef struct message_struct message; +@interface X11Application(Private) + - (void) sendX11NSEvent:(NSEvent *) e; +@end @ implementation X11Application typedef struct message_struct + message; struct message_struct { - mach_msg_header_t hdr; - SEL selector; - NSObject *arg; + mach_msg_header_t + hdr; + SEL + selector; + NSObject * + arg; }; -static mach_port_t _port; +static mach_port_t + _port; /* Quartz mode initialization routine. This is often dynamically loaded but is statically linked into this X server. */ -Bool QuartzModeBundleInit(void); +Bool +QuartzModeBundleInit(void); -static void init_ports (void) { +static void +init_ports(void) +{ kern_return_t r; NSPort *p; - - if (_port != MACH_PORT_NULL) return; - - r = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &_port); - if (r != KERN_SUCCESS) return; - - p = [NSMachPort portWithMachPort:_port]; - [p setDelegate:NSApp]; - [p scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + + if (_port != MACH_PORT_NULL) + return; + + r = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &_port); + if (r != KERN_SUCCESS) + return; + + p =[NSMachPort portWithMachPort:_port]; + [p setDelegate:NSApp]; + [p scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } -static void message_kit_thread (SEL selector, NSObject *arg) { +static void +message_kit_thread(SEL selector, NSObject * arg) +{ message msg; kern_return_t r; - - msg.hdr.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MAKE_SEND, 0); - msg.hdr.msgh_size = sizeof (msg); + + msg.hdr.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND, 0); + msg.hdr.msgh_size = sizeof(msg); msg.hdr.msgh_remote_port = _port; msg.hdr.msgh_local_port = MACH_PORT_NULL; msg.hdr.msgh_reserved = 0; msg.hdr.msgh_id = 0; - + msg.selector = selector; - msg.arg = [arg retain]; - - r = mach_msg (&msg.hdr, MACH_SEND_MSG, msg.hdr.msgh_size, - 0, MACH_PORT_NULL, 0, MACH_PORT_NULL); + msg.arg =[arg retain]; + + r = mach_msg(&msg.hdr, MACH_SEND_MSG, msg.hdr.msgh_size, + 0, MACH_PORT_NULL, 0, MACH_PORT_NULL); if (r != KERN_SUCCESS) - ErrorF("%s: mach_msg failed: %x\n", __FUNCTION__, r); + ErrorF("%s: mach_msg failed: %x\n", __FUNCTION__, r); } -- (void) handleMachMessage:(void *)_msg { + -(void) handleMachMessage:(void *) _msg { message *msg = _msg; - - [self performSelector:msg->selector withObject:msg->arg]; + + [self performSelector: msg->selector withObject:msg->arg]; [msg->arg release]; } -- (void) set_controller:obj { - if (_controller == nil) _controller = [obj retain]; + -(void) set_controller:obj { + if (_controller == nil) + _controller =[obj retain]; } -- (void) dealloc { - if (_controller != nil) [_controller release]; - +-(void) dealloc { + if (_controller != nil) + [_controller release]; + if (_port != MACH_PORT_NULL) - mach_port_deallocate (mach_task_self (), _port); - + mach_port_deallocate(mach_task_self(), _port); + [super dealloc]; } -- (void) orderFrontStandardAboutPanel: (id) sender { + -(void) orderFrontStandardAboutPanel:(id) sender { NSMutableDictionary *dict; NSDictionary *infoDict; NSString *tem; - - dict = [NSMutableDictionary dictionaryWithCapacity:3]; - infoDict = [[NSBundle mainBundle] infoDictionary]; - - [dict setObject: NSLocalizedString (@"The X Window System", @"About panel") - forKey:@"ApplicationName"]; - - tem = [infoDict objectForKey:@"CFBundleShortVersionString"]; - - [dict setObject:[NSString stringWithFormat:@"XQuartz %@", tem] - forKey:@"ApplicationVersion"]; - - [dict setObject:[NSString stringWithFormat:@"xorg-server %s", XSERVER_VERSION] - forKey:@"Version"]; - - [self orderFrontStandardAboutPanelWithOptions: dict]; + + dict =[NSMutableDictionary dictionaryWithCapacity:3]; + infoDict =[[NSBundle mainBundle] infoDictionary]; + + [dict setObject:NSLocalizedString(@"The X Window System", @"About panel") + forKey:@"ApplicationName"]; + + tem =[infoDict objectForKey:@"CFBundleShortVersionString"]; + + [dict setObject: [NSString stringWithFormat:@"XQuartz %@", tem] + forKey:@"ApplicationVersion"]; + + [dict setObject: [NSString stringWithFormat:@"xorg-server %s", + XSERVER_VERSION] + forKey:@"Version"]; + + [self orderFrontStandardAboutPanelWithOptions:dict]; } -- (void) activateX:(OSX_BOOL)state { + -(void) activateX:(OSX_BOOL) state { if (_x_active == state) return; DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active); if (state) { - if(bgMouseLocationUpdated) { - DarwinSendPointerEvents(darwinPointer, MotionNotify, 0, bgMouseLocation.x, bgMouseLocation.y, 0.0, 0.0, 0.0); + if (bgMouseLocationUpdated) { + DarwinSendPointerEvents(darwinPointer, MotionNotify, 0, + bgMouseLocation.x, bgMouseLocation.y, 0.0, + 0.0, 0.0); bgMouseLocationUpdated = FALSE; } DarwinSendDDXEvent(kXquartzActivate, 0); - } else { + } + else { - if(darwin_all_modifier_flags) + if (darwin_all_modifier_flags) DarwinUpdateModKeys(0); DarwinInputReleaseButtonsAndKeys(darwinKeyboard); @@ -218,238 +232,270 @@ static void message_kit_thread (SEL selector, NSObject *arg) { _x_active = state; } -- (void) became_key:(NSWindow *)win { - [self activateX:NO]; + -(void) became_key:(NSWindow *) win { + [self activateX:NO]; } -- (void) sendEvent:(NSEvent *)e { + -(void) sendEvent:(NSEvent *) e { OSX_BOOL for_appkit, for_x; - + /* By default pass down the responder chain and to X. */ for_appkit = YES; for_x = YES; - + switch ([e type]) { - case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown: - case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: - if ([e window] != nil) { - /* Pointer event has an (AppKit) window. Probably something for the kit. */ - for_x = NO; - if (_x_active) [self activateX:NO]; - } else if ([self modalWindow] == nil) { - /* Must be an X window. Tell appkit it doesn't have focus. */ - for_appkit = NO; - - if ([self isActive]) { - [self deactivate]; - if (!_x_active && quartzProcs->IsX11Window([e windowNumber])) - [self activateX:YES]; - } + case NSLeftMouseDown: + case NSRightMouseDown: + case NSOtherMouseDown: + case NSLeftMouseUp: + case NSRightMouseUp: + case NSOtherMouseUp: + if ([e window] != nil) { + /* Pointer event has an (AppKit) window. Probably something for the kit. */ + for_x = NO; + if (_x_active) + [self activateX:NO]; + } + else if ([self modalWindow] == nil) { + /* Must be an X window. Tell appkit it doesn't have focus. */ + for_appkit = NO; + + if ([self isActive]) { + [self deactivate]; + if (!_x_active && quartzProcs->IsX11Window([e windowNumber])) + [self activateX: YES]; } + } - /* We want to force sending to appkit if we're over the menu bar */ - if(!for_appkit) { - NSPoint NSlocation = [e locationInWindow]; - NSWindow *window = [e window]; - NSRect NSframe, NSvisibleFrame; - CGRect CGframe, CGvisibleFrame; - CGPoint CGlocation; - - if (window != nil) { - NSRect frame = [window frame]; - NSlocation.x += frame.origin.x; - NSlocation.y += frame.origin.y; - } + /* We want to force sending to appkit if we're over the menu bar */ + if (!for_appkit) { + NSPoint NSlocation =[e locationInWindow]; + NSWindow *window =[e window]; + NSRect NSframe, NSvisibleFrame; + CGRect CGframe, CGvisibleFrame; + CGPoint CGlocation; + + if (window != nil) { + NSRect frame =[window frame]; - NSframe = [[NSScreen mainScreen] frame]; - NSvisibleFrame = [[NSScreen mainScreen] visibleFrame]; - - CGframe = CGRectMake(NSframe.origin.x, NSframe.origin.y, - NSframe.size.width, NSframe.size.height); - CGvisibleFrame = CGRectMake(NSvisibleFrame.origin.x, - NSvisibleFrame.origin.y, - NSvisibleFrame.size.width, - NSvisibleFrame.size.height); - CGlocation = CGPointMake(NSlocation.x, NSlocation.y); - - if(CGRectContainsPoint(CGframe, CGlocation) && - !CGRectContainsPoint(CGvisibleFrame, CGlocation)) - for_appkit = YES; + NSlocation.x += frame.origin.x; + NSlocation.y += frame.origin.y; } - - break; - - case NSKeyDown: case NSKeyUp: - - if(_x_active) { - static BOOL do_swallow = NO; - static int swallow_keycode; - - if([e type] == NSKeyDown) { - /* Before that though, see if there are any global - * shortcuts bound to it. */ - - if(darwinAppKitModMask & [e modifierFlags]) { - /* Override to force sending to Appkit */ - swallow_keycode = [e keyCode]; - do_swallow = YES; - for_x = NO; + + NSframe =[[NSScreen mainScreen] frame]; + NSvisibleFrame =[[NSScreen mainScreen] visibleFrame]; + + CGframe = CGRectMake(NSframe.origin.x, NSframe.origin.y, + NSframe.size.width, NSframe.size.height); + CGvisibleFrame = CGRectMake(NSvisibleFrame.origin.x, + NSvisibleFrame.origin.y, + NSvisibleFrame.size.width, + NSvisibleFrame.size.height); + CGlocation = CGPointMake(NSlocation.x, NSlocation.y); + + if (CGRectContainsPoint(CGframe, CGlocation) && + !CGRectContainsPoint(CGvisibleFrame, CGlocation)) + for_appkit = YES; + } + + break; + + case NSKeyDown: + case NSKeyUp: + + if (_x_active) { + static BOOL do_swallow = NO; + static int swallow_keycode; + + if ([e type] == NSKeyDown) { + /* Before that though, see if there are any global + * shortcuts bound to it. */ + + if (darwinAppKitModMask &[e modifierFlags]) { + /* Override to force sending to Appkit */ + swallow_keycode =[e keyCode]; + do_swallow = YES; + for_x = NO; #if XPLUGIN_VERSION >= 1 - } else if(XQuartzEnableKeyEquivalents && - xp_is_symbolic_hotkey_event([e eventRef])) { - swallow_keycode = [e keyCode]; - do_swallow = YES; - for_x = NO; + } + else if (XQuartzEnableKeyEquivalents && + xp_is_symbolic_hotkey_event([e eventRef])) { + swallow_keycode =[e keyCode]; + do_swallow = YES; + for_x = NO; #endif - } else if(XQuartzEnableKeyEquivalents && - [[self mainMenu] performKeyEquivalent:e]) { - swallow_keycode = [e keyCode]; - do_swallow = YES; - for_appkit = NO; - for_x = NO; - } else if(!XQuartzIsRootless - && ([e modifierFlags] & ALL_KEY_MASKS) == (NSCommandKeyMask | NSAlternateKeyMask) - && ([e keyCode] == 0 /*a*/ || [e keyCode] == 53 /*Esc*/)) { - /* We have this here to force processing fullscreen - * toggle even if XQuartzEnableKeyEquivalents is disabled */ - swallow_keycode = [e keyCode]; - do_swallow = YES; - for_x = NO; - for_appkit = NO; - DarwinSendDDXEvent(kXquartzToggleFullscreen, 0); - } else { - /* No kit window is focused, so send it to X. */ - for_appkit = NO; - } - } else { /* KeyUp */ - /* If we saw a key equivalent on the down, don't pass - * the up through to X. */ - if (do_swallow && [e keyCode] == swallow_keycode) { - do_swallow = NO; - for_x = NO; - } } - } else { /* !_x_active */ - for_x = NO; + else if (XQuartzEnableKeyEquivalents &&[[self mainMenu] performKeyEquivalent:e]) + { + swallow_keycode =[e keyCode]; + do_swallow = YES; + for_appkit = NO; + for_x = NO; + } + else if (!XQuartzIsRootless + && ([e modifierFlags] & ALL_KEY_MASKS) == + (NSCommandKeyMask | NSAlternateKeyMask) + && ([e keyCode] == 0 /*a */ || + [e keyCode] == 53 /*Esc */ )) { + /* We have this here to force processing fullscreen + * toggle even if XQuartzEnableKeyEquivalents is disabled */ + swallow_keycode =[e keyCode]; + do_swallow = YES; + for_x = NO; + for_appkit = NO; + DarwinSendDDXEvent(kXquartzToggleFullscreen, 0); + } + else { + /* No kit window is focused, so send it to X. */ + for_appkit = NO; + } + } + else { /* KeyUp */ + /* If we saw a key equivalent on the down, don't pass + * the up through to X. */ + if (do_swallow &&[e keyCode] == swallow_keycode) { + do_swallow = NO; + for_x = NO; + } + } + } + else { /* !_x_active */ + for_x = NO; + } + break; + + case NSFlagsChanged: + /* Don't tell X11 about modifiers changing while it's not active */ + if (!_x_active) + for_x = NO; + break; + + case NSAppKitDefined: + switch ([e subtype]) { + static BOOL x_was_active = NO; + + case NSApplicationActivatedEventType: + for_x = NO; + if ([e window] == nil && x_was_active) { + BOOL order_all_windows = YES, workspaces, ok; + + for_appkit = NO; + + /* FIXME: This is a hack to avoid passing the event to AppKit which + * would result in it raising one of its windows. + */ + _appFlags._active = YES; + + [self set_front_process:nil]; + + /* Get the Spaces preference for SwitchOnActivate */ + (void) CFPreferencesAppSynchronize(CFSTR("com.apple.dock")); + workspaces = + CFPreferencesGetAppBooleanValue(CFSTR("workspaces"), + CFSTR("com.apple.dock"), + &ok); + if (!ok) + workspaces = NO; + + if (workspaces) { + (void) + CFPreferencesAppSynchronize(CFSTR + (".GlobalPreferences")); + order_all_windows = + CFPreferencesGetAppBooleanValue(CFSTR + ("AppleSpacesSwitchOnActivate"), + CFSTR + (".GlobalPreferences"), + &ok); + if (!ok) + order_all_windows = YES; + } + + /* TODO: In the workspaces && !AppleSpacesSwitchOnActivate case, the windows are ordered + * correctly, but we need to activate the top window on this space if there is + * none active. + * + * If there are no active windows, and there are minimized windows, we should + * be restoring one of them. + */ + if ([e data2] & 0x10) { // 0x10 (bfCPSOrderAllWindowsForward) is set when we use cmd-tab or the dock icon + DarwinSendDDXEvent(kXquartzBringAllToFront, 1, + order_all_windows); + } } break; - - case NSFlagsChanged: - /* Don't tell X11 about modifiers changing while it's not active */ - if (!_x_active) - for_x = NO; + + case 18: /* ApplicationDidReactivate */ + if (XQuartzFullscreenVisible) + for_appkit = NO; break; - - case NSAppKitDefined: - switch ([e subtype]) { - static BOOL x_was_active = NO; - case NSApplicationActivatedEventType: - for_x = NO; - if ([e window] == nil && x_was_active) { - BOOL order_all_windows = YES, workspaces, ok; - for_appkit = NO; - - /* FIXME: This is a hack to avoid passing the event to AppKit which - * would result in it raising one of its windows. - */ - _appFlags._active = YES; - - [self set_front_process:nil]; - - /* Get the Spaces preference for SwitchOnActivate */ - (void)CFPreferencesAppSynchronize(CFSTR("com.apple.dock")); - workspaces = CFPreferencesGetAppBooleanValue(CFSTR("workspaces"), CFSTR("com.apple.dock"), &ok); - if (!ok) - workspaces = NO; - - if (workspaces) { - (void)CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences")); - order_all_windows = CFPreferencesGetAppBooleanValue(CFSTR("AppleSpacesSwitchOnActivate"), CFSTR(".GlobalPreferences"), &ok); - if (!ok) - order_all_windows = YES; - } - - /* TODO: In the workspaces && !AppleSpacesSwitchOnActivate case, the windows are ordered - * correctly, but we need to activate the top window on this space if there is - * none active. - * - * If there are no active windows, and there are minimized windows, we should - * be restoring one of them. - */ - if ([e data2] & 0x10) { // 0x10 (bfCPSOrderAllWindowsForward) is set when we use cmd-tab or the dock icon - DarwinSendDDXEvent(kXquartzBringAllToFront, 1, order_all_windows); - } - } - break; - - case 18: /* ApplicationDidReactivate */ - if (XQuartzFullscreenVisible) for_appkit = NO; - break; - - case NSApplicationDeactivatedEventType: - for_x = NO; + case NSApplicationDeactivatedEventType: + for_x = NO; - x_was_active = _x_active; - if(_x_active) - [self activateX:NO]; - break; - } + x_was_active = _x_active; + if (_x_active) + [self activateX:NO]; break; - - default: break; /* for gcc */ + } + break; + + default: + break; /* for gcc */ } - - if (for_appkit) [super sendEvent:e]; - + + if (for_appkit) + [super sendEvent:e]; + if (for_x) { #ifdef HAVE_LIBDISPATCH - dispatch_async(eventTranslationQueue, ^{ + dispatch_async(eventTranslationQueue, ^ { #endif - [self sendX11NSEvent:e]; + [self sendX11NSEvent:e]; #ifdef HAVE_LIBDISPATCH - }); + } + ); #endif } } -- (void) set_window_menu:(NSArray *)list { - [_controller set_window_menu:list]; + -(void) set_window_menu:(NSArray *) list { + [_controller set_window_menu:list]; } -- (void) set_window_menu_check:(NSNumber *)n { - [_controller set_window_menu_check:n]; + -(void) set_window_menu_check:(NSNumber *) n { + [_controller set_window_menu_check:n]; } -- (void) set_apps_menu:(NSArray *)list { - [_controller set_apps_menu:list]; + -(void) set_apps_menu:(NSArray *) list { + [_controller set_apps_menu:list]; } -- (void) set_front_process:unused { - [NSApp activateIgnoringOtherApps:YES]; + -(void) set_front_process:unused { + [NSApp activateIgnoringOtherApps:YES]; - if ([self modalWindow] == nil) - [self activateX:YES]; + if ([self modalWindow] == nil) + [self activateX:YES]; } -- (void) set_can_quit:(NSNumber *)state { - [_controller set_can_quit:[state boolValue]]; + -(void) set_can_quit:(NSNumber *) state { + [_controller set_can_quit:[state boolValue]]; } -- (void) server_ready:unused { - [_controller server_ready]; + -(void) server_ready:unused { + [_controller server_ready]; } -- (void) show_hide_menubar:(NSNumber *)state { + -(void) show_hide_menubar:(NSNumber *) state { /* Also shows/hides the dock */ if ([state boolValue]) - SetSystemUIMode(kUIModeNormal, 0); + SetSystemUIMode(kUIModeNormal, 0); else - SetSystemUIMode(kUIModeAllHidden, XQuartzFullscreenMenu ? kUIOptionAutoShowMenuBar : 0); // kUIModeAllSuppressed or kUIOptionAutoShowMenuBar can be used to allow "mouse-activation" + SetSystemUIMode(kUIModeAllHidden, XQuartzFullscreenMenu ? kUIOptionAutoShowMenuBar : 0); // kUIModeAllSuppressed or kUIOptionAutoShowMenuBar can be used to allow "mouse-activation" } -- (void) launch_client:(NSString *)cmd { - (void)[_controller application:self openFile:cmd]; + -(void) launch_client:(NSString *) cmd { + (void)[_controller application: self openFile:cmd]; } /* user preferences */ @@ -457,457 +503,524 @@ static void message_kit_thread (SEL selector, NSObject *arg) { /* Note that these functions only work for arrays whose elements can be toll-free-bridged between NS and CF worlds. */ -static const void *cfretain (CFAllocatorRef a, const void *b) { - return CFRetain (b); +static const void * +cfretain(CFAllocatorRef a, const void *b) +{ + return CFRetain(b); } -static void cfrelease (CFAllocatorRef a, const void *b) { - CFRelease (b); +static void +cfrelease(CFAllocatorRef a, const void *b) +{ + CFRelease(b); } -static CFMutableArrayRef nsarray_to_cfarray (NSArray *in) { - CFMutableArrayRef out; - CFArrayCallBacks cb; - NSObject *ns; - const CFTypeRef *cf; - int i, count; +static CFMutableArrayRef +nsarray_to_cfarray(NSArray * in) +{ + CFMutableArrayRef out; + CFArrayCallBacks cb; + NSObject *ns; + const CFTypeRef *cf; + int i, count; + + memset(&cb, 0, sizeof(cb)); + cb.version = 0; + cb.retain = cfretain; + cb.release = cfrelease; + + count =[in count]; + out = CFArrayCreateMutable(NULL, count, &cb); + + for (i = 0; i < count; i++) { + ns =[in objectAtIndex:i]; + + if ([ns isKindOfClass:[NSArray class]]) + cf = (CFTypeRef) nsarray_to_cfarray((NSArray *) ns); + else + cf = CFRetain((CFTypeRef) ns); + + CFArrayAppendValue(out, cf); + CFRelease(cf); + } + + return out; +} - memset (&cb, 0, sizeof (cb)); - cb.version = 0; - cb.retain = cfretain; - cb.release = cfrelease; +static NSMutableArray * +cfarray_to_nsarray(CFArrayRef in) +{ + NSMutableArray *out; + const CFTypeRef *cf; + NSObject *ns; + int i, count; - count = [in count]; - out = CFArrayCreateMutable (NULL, count, &cb); + count = CFArrayGetCount(in); + out =[[NSMutableArray alloc] initWithCapacity:count]; - for (i = 0; i < count; i++) { - ns = [in objectAtIndex:i]; + for (i = 0; i < count; i++) { + cf = CFArrayGetValueAtIndex(in, i); - if ([ns isKindOfClass:[NSArray class]]) - cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns); - else - cf = CFRetain ((CFTypeRef) ns); + if (CFGetTypeID(cf) == CFArrayGetTypeID()) + ns = cfarray_to_nsarray((CFArrayRef) cf); + else + ns =[(id) cf retain]; - CFArrayAppendValue (out, cf); - CFRelease (cf); - } + [out addObject:ns]; + [ns release]; + } - return out; + return out; } -static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) { - NSMutableArray *out; - const CFTypeRef *cf; - NSObject *ns; - int i, count; + -(CFPropertyListRef) prefs_get_copy:(NSString *) key { + CFPropertyListRef value; - count = CFArrayGetCount (in); - out = [[NSMutableArray alloc] initWithCapacity:count]; + value = + CFPreferencesCopyAppValue((CFStringRef) key, app_prefs_domain_cfstr); - for (i = 0; i < count; i++) { - cf = CFArrayGetValueAtIndex (in, i); + if (value == NULL) { + static CFDictionaryRef defaults; + + if (defaults == NULL) { + CFStringRef error = NULL; + CFDataRef data; + CFURLRef url; + SInt32 error_code; + + url = (CFURLCreateFromFileSystemRepresentation + (NULL, (unsigned char *) DEFAULTS_FILE, + strlen(DEFAULTS_FILE), false)); + if (CFURLCreateDataAndPropertiesFromResource + (NULL, url, &data, NULL, NULL, &error_code)) { + defaults = + (CFPropertyListCreateFromXMLData + (NULL, data, kCFPropertyListMutableContainersAndLeaves, + &error)); + if (error != NULL) + CFRelease(error); + CFRelease(data); + } + CFRelease(url); + + if (defaults != NULL) { + NSMutableArray *apps, *elt; + int count, i; + NSString *name, *nname; + + /* Localize the names in the default apps menu. */ + + apps =[(NSDictionary *) defaults objectForKey:@PREFS_APPSMENU]; + if (apps != nil) { + count =[apps count]; + for (i = 0; i < count; i++) { + elt =[apps objectAtIndex:i]; + if (elt != nil &&[elt isKindOfClass:[NSArray class]]) { + name =[elt objectAtIndex: 0]; + if (name != nil) { + nname = NSLocalizedString(name, nil); + if (nname != nil && nname != name) + [elt replaceObjectAtIndex: 0 withObject:nname]; + } + } + } + } + } + } + + if (defaults != NULL) + value = CFDictionaryGetValue(defaults, key); + if (value != NULL) + CFRetain(value); + } + + return value; +} - if (CFGetTypeID (cf) == CFArrayGetTypeID ()) - ns = cfarray_to_nsarray ((CFArrayRef) cf); - else - ns = [(id)cf retain]; + -(int) prefs_get_integer:(NSString *) +key default:(int) def +{ + CFPropertyListRef value; + int ret; - [out addObject:ns]; - [ns release]; - } + value =[self prefs_get_copy:key]; + + if (value != NULL && CFGetTypeID(value) == CFNumberGetTypeID()) + CFNumberGetValue(value, kCFNumberIntType, &ret); + else if (value != NULL && CFGetTypeID(value) == CFStringGetTypeID()) + ret = CFStringGetIntValue(value); + else + ret = def; - return out; + if (value != NULL) + CFRelease(value); + + return ret; } -- (CFPropertyListRef) prefs_get_copy:(NSString *)key { + -(const char *) prefs_get_string:(NSString *) +key default:(const char *) def +{ CFPropertyListRef value; - - value = CFPreferencesCopyAppValue ((CFStringRef) key, app_prefs_domain_cfstr); - - if (value == NULL) { - static CFDictionaryRef defaults; - - if (defaults == NULL) { - CFStringRef error = NULL; - CFDataRef data; - CFURLRef url; - SInt32 error_code; - - url = (CFURLCreateFromFileSystemRepresentation - (NULL, (unsigned char *)DEFAULTS_FILE, strlen (DEFAULTS_FILE), false)); - if (CFURLCreateDataAndPropertiesFromResource (NULL, url, &data, - NULL, NULL, &error_code)) { - defaults = (CFPropertyListCreateFromXMLData - (NULL, data, kCFPropertyListMutableContainersAndLeaves, &error)); - if (error != NULL) CFRelease (error); - CFRelease (data); - } - CFRelease (url); - - if (defaults != NULL) { - NSMutableArray *apps, *elt; - int count, i; - NSString *name, *nname; - - /* Localize the names in the default apps menu. */ - - apps = [(NSDictionary *)defaults objectForKey:@PREFS_APPSMENU]; - if (apps != nil) { - count = [apps count]; - for (i = 0; i < count; i++) { - elt = [apps objectAtIndex:i]; - if (elt != nil && [elt isKindOfClass:[NSArray class]]) { - name = [elt objectAtIndex:0]; - if (name != nil) { - nname = NSLocalizedString (name, nil); - if (nname != nil && nname != name) - [elt replaceObjectAtIndex:0 withObject:nname]; - } - } - } - } - } - } - - if (defaults != NULL) value = CFDictionaryGetValue (defaults, key); - if (value != NULL) CFRetain (value); + const char *ret = NULL; + + value =[self prefs_get_copy:key]; + + if (value != NULL && CFGetTypeID(value) == CFStringGetTypeID()) { + NSString *s = (NSString *) value; + + ret =[s UTF8String]; } - - return value; -} -- (int) prefs_get_integer:(NSString *)key default:(int)def { - CFPropertyListRef value; - int ret; - - value = [self prefs_get_copy:key]; - - if (value != NULL && CFGetTypeID (value) == CFNumberGetTypeID ()) - CFNumberGetValue (value, kCFNumberIntType, &ret); - else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) - ret = CFStringGetIntValue (value); - else - ret = def; - - if (value != NULL) CFRelease (value); - - return ret; -} + if (value != NULL) + CFRelease(value); -- (const char *) prefs_get_string:(NSString *)key default:(const char *)def { - CFPropertyListRef value; - const char *ret = NULL; - - value = [self prefs_get_copy:key]; - - if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) { - NSString *s = (NSString *) value; - - ret = [s UTF8String]; - } - - if (value != NULL) CFRelease (value); - - return ret != NULL ? ret : def; + return ret != NULL ? ret : def; } -- (NSURL *) prefs_copy_url:(NSString *)key default:(NSURL *)def { + -(NSURL *) prefs_copy_url:(NSString *) +key default:(NSURL *) def +{ CFPropertyListRef value; NSURL *ret = NULL; - - value = [self prefs_get_copy:key]; - - if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) { + + value =[self prefs_get_copy:key]; + + if (value != NULL && CFGetTypeID(value) == CFStringGetTypeID()) { NSString *s = (NSString *) value; - ret = [NSURL URLWithString:s]; + ret =[NSURL URLWithString:s]; [ret retain]; } - - if (value != NULL) CFRelease (value); - + + if (value != NULL) + CFRelease(value); + return ret != NULL ? ret : def; } -- (float) prefs_get_float:(NSString *)key default:(float)def { - CFPropertyListRef value; - float ret = def; - - value = [self prefs_get_copy:key]; - - if (value != NULL - && CFGetTypeID (value) == CFNumberGetTypeID () - && CFNumberIsFloatType (value)) - CFNumberGetValue (value, kCFNumberFloatType, &ret); - else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) - ret = CFStringGetDoubleValue (value); - - if (value != NULL) CFRelease (value); - - return ret; + -(float) prefs_get_float:(NSString *) +key default:(float) def +{ + CFPropertyListRef value; + float ret = def; + + value =[self prefs_get_copy:key]; + + if (value != NULL && CFGetTypeID(value) == CFNumberGetTypeID() + && CFNumberIsFloatType(value)) + CFNumberGetValue(value, kCFNumberFloatType, &ret); + else if (value != NULL && CFGetTypeID(value) == CFStringGetTypeID()) + ret = CFStringGetDoubleValue(value); + + if (value != NULL) + CFRelease(value); + + return ret; } -- (int) prefs_get_boolean:(NSString *)key default:(int)def { - CFPropertyListRef value; - int ret = def; - - value = [self prefs_get_copy:key]; - - if (value != NULL) { - if (CFGetTypeID (value) == CFNumberGetTypeID ()) - CFNumberGetValue (value, kCFNumberIntType, &ret); - else if (CFGetTypeID (value) == CFBooleanGetTypeID ()) - ret = CFBooleanGetValue (value); - else if (CFGetTypeID (value) == CFStringGetTypeID ()) { - const char *tem = [(NSString *) value UTF8String]; - if (strcasecmp (tem, "true") == 0 || strcasecmp (tem, "yes") == 0) - ret = YES; - else - ret = NO; + -(int) prefs_get_boolean:(NSString *) +key default:(int) def +{ + CFPropertyListRef value; + int ret = def; + + value =[self prefs_get_copy:key]; + + if (value != NULL) { + if (CFGetTypeID(value) == CFNumberGetTypeID()) + CFNumberGetValue(value, kCFNumberIntType, &ret); + else if (CFGetTypeID(value) == CFBooleanGetTypeID()) + ret = CFBooleanGetValue(value); + else if (CFGetTypeID(value) == CFStringGetTypeID()) { + const char *tem =[(NSString *) value UTF8String]; + + if (strcasecmp(tem, "true") == 0 || strcasecmp(tem, "yes") == 0) + ret = YES; + else + ret = NO; + } + + CFRelease(value); } - - CFRelease (value); - } - return ret; + return ret; } -- (NSArray *) prefs_get_array:(NSString *)key { - NSArray *ret = nil; - CFPropertyListRef value; - - value = [self prefs_get_copy:key]; - - if (value != NULL) { - if (CFGetTypeID (value) == CFArrayGetTypeID ()) - ret = [cfarray_to_nsarray (value) autorelease]; - - CFRelease (value); - } - - return ret; + -(NSArray *) prefs_get_array:(NSString *) key { + NSArray *ret = nil; + CFPropertyListRef value; + + value =[self prefs_get_copy:key]; + + if (value != NULL) { + if (CFGetTypeID(value) == CFArrayGetTypeID()) + ret =[cfarray_to_nsarray(value) autorelease]; + + CFRelease(value); + } + + return ret; } -- (void) prefs_set_integer:(NSString *)key value:(int)value { + -(void) prefs_set_integer:(NSString *) +key value:(int) value +{ CFNumberRef x; - - x = CFNumberCreate (NULL, kCFNumberIntType, &value); - - CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, app_prefs_domain_cfstr, - kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - - CFRelease (x); + + x = CFNumberCreate(NULL, kCFNumberIntType, &value); + + CFPreferencesSetValue((CFStringRef) key, (CFTypeRef) x, + app_prefs_domain_cfstr, kCFPreferencesCurrentUser, + kCFPreferencesAnyHost); + + CFRelease(x); } -- (void) prefs_set_float:(NSString *)key value:(float)value { + -(void) prefs_set_float:(NSString *) +key value:(float) value +{ CFNumberRef x; - - x = CFNumberCreate (NULL, kCFNumberFloatType, &value); - - CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, app_prefs_domain_cfstr, - kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - - CFRelease (x); + + x = CFNumberCreate(NULL, kCFNumberFloatType, &value); + + CFPreferencesSetValue((CFStringRef) key, (CFTypeRef) x, + app_prefs_domain_cfstr, kCFPreferencesCurrentUser, + kCFPreferencesAnyHost); + + CFRelease(x); } -- (void) prefs_set_boolean:(NSString *)key value:(int)value { - CFPreferencesSetValue ((CFStringRef) key, - (CFTypeRef) (value ? kCFBooleanTrue - : kCFBooleanFalse), app_prefs_domain_cfstr, - kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - + -(void) prefs_set_boolean:(NSString *) +key value:(int) value +{ + CFPreferencesSetValue((CFStringRef) key, + (CFTypeRef) (value ? kCFBooleanTrue + : kCFBooleanFalse), + app_prefs_domain_cfstr, kCFPreferencesCurrentUser, + kCFPreferencesAnyHost); + } -- (void) prefs_set_array:(NSString *)key value:(NSArray *)value { - CFArrayRef cfarray; - - cfarray = nsarray_to_cfarray (value); - CFPreferencesSetValue ((CFStringRef) key, - (CFTypeRef) cfarray, - app_prefs_domain_cfstr, - kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - CFRelease (cfarray); + -(void) prefs_set_array:(NSString *) +key value:(NSArray *) value +{ + CFArrayRef cfarray; + + cfarray = nsarray_to_cfarray(value); + CFPreferencesSetValue((CFStringRef) key, + (CFTypeRef) cfarray, + app_prefs_domain_cfstr, + kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + CFRelease(cfarray); } -- (void) prefs_set_string:(NSString *)key value:(NSString *)value { - CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) value, - app_prefs_domain_cfstr, kCFPreferencesCurrentUser, - kCFPreferencesAnyHost); + -(void) prefs_set_string:(NSString *) +key value:(NSString *) value +{ + CFPreferencesSetValue((CFStringRef) key, (CFTypeRef) value, + app_prefs_domain_cfstr, kCFPreferencesCurrentUser, + kCFPreferencesAnyHost); } -- (void) prefs_synchronize { - CFPreferencesAppSynchronize (kCFPreferencesCurrentApplication); +-(void) prefs_synchronize { + CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication); } -- (void) read_defaults -{ +-(void) read_defaults { NSString *nsstr; const char *tem; - - XQuartzRootlessDefault = [self prefs_get_boolean:@PREFS_ROOTLESS - default:XQuartzRootlessDefault]; - XQuartzFullscreenMenu = [self prefs_get_boolean:@PREFS_FULLSCREEN_MENU - default:XQuartzFullscreenMenu]; - XQuartzFullscreenDisableHotkeys = ![self prefs_get_boolean:@PREFS_FULLSCREEN_HOTKEYS - default:!XQuartzFullscreenDisableHotkeys]; - darwinFakeButtons = [self prefs_get_boolean:@PREFS_FAKEBUTTONS - default:darwinFakeButtons]; - XQuartzOptionSendsAlt = [self prefs_get_boolean:@PREFS_OPTION_SENDS_ALT - default:XQuartzOptionSendsAlt]; + +XQuartzRootlessDefault =[self prefs_get_boolean: @PREFS_ROOTLESS default: +XQuartzRootlessDefault]; +XQuartzFullscreenMenu =[self prefs_get_boolean: @PREFS_FULLSCREEN_MENU default: +XQuartzFullscreenMenu]; +XQuartzFullscreenDisableHotkeys = ![self prefs_get_boolean: @PREFS_FULLSCREEN_HOTKEYS default: +!XQuartzFullscreenDisableHotkeys]; +darwinFakeButtons =[self prefs_get_boolean: @PREFS_FAKEBUTTONS default: +darwinFakeButtons]; +XQuartzOptionSendsAlt =[self prefs_get_boolean: @PREFS_OPTION_SENDS_ALT default: +XQuartzOptionSendsAlt]; if (darwinFakeButtons) { const char *fake2, *fake3; - fake2 = [self prefs_get_string:@PREFS_FAKE_BUTTON2 default:NULL]; - fake3 = [self prefs_get_string:@PREFS_FAKE_BUTTON3 default:NULL]; +fake2 =[self prefs_get_string: @PREFS_FAKE_BUTTON2 default: +NULL]; +fake3 =[self prefs_get_string: @PREFS_FAKE_BUTTON3 default: +NULL]; - if (fake2 != NULL) darwinFakeMouse2Mask = DarwinParseModifierList(fake2, TRUE); - if (fake3 != NULL) darwinFakeMouse3Mask = DarwinParseModifierList(fake3, TRUE); + if (fake2 != NULL) + darwinFakeMouse2Mask = DarwinParseModifierList(fake2, TRUE); + if (fake3 != NULL) + darwinFakeMouse3Mask = DarwinParseModifierList(fake3, TRUE); } - tem = [self prefs_get_string:@PREFS_APPKIT_MODIFIERS default:NULL]; - if (tem != NULL) darwinAppKitModMask = DarwinParseModifierList(tem, TRUE); - - tem = [self prefs_get_string:@PREFS_WINDOW_ITEM_MODIFIERS default:NULL]; +tem =[self prefs_get_string: @PREFS_APPKIT_MODIFIERS default: +NULL]; + if (tem != NULL) + darwinAppKitModMask = DarwinParseModifierList(tem, TRUE); + +tem =[self prefs_get_string: @PREFS_WINDOW_ITEM_MODIFIERS default: +NULL]; if (tem != NULL) { windowItemModMask = DarwinParseModifierList(tem, FALSE); - } else { - nsstr = NSLocalizedString (@"window item modifiers", @"window item modifiers"); - if(nsstr != NULL) { - tem = [nsstr UTF8String]; - if((tem != NULL) && strcmp(tem, "window item modifiers")) { + } + else { + nsstr = + NSLocalizedString(@"window item modifiers", + @"window item modifiers"); + if (nsstr != NULL) { + tem =[nsstr UTF8String]; + if ((tem != NULL) && strcmp(tem, "window item modifiers")) { windowItemModMask = DarwinParseModifierList(tem, FALSE); } } } - XQuartzEnableKeyEquivalents = [self prefs_get_boolean:@PREFS_KEYEQUIVS - default:XQuartzEnableKeyEquivalents]; - - darwinSyncKeymap = [self prefs_get_boolean:@PREFS_SYNC_KEYMAP - default:darwinSyncKeymap]; - - darwinDesiredDepth = [self prefs_get_integer:@PREFS_DEPTH - default:darwinDesiredDepth]; - - noTestExtensions = ![self prefs_get_boolean:@PREFS_TEST_EXTENSIONS - default:FALSE]; - - XQuartzScrollInDeviceDirection = [self prefs_get_boolean:@PREFS_SCROLL_IN_DEV_DIRECTION - default:XQuartzScrollInDeviceDirection]; +XQuartzEnableKeyEquivalents =[self prefs_get_boolean: @PREFS_KEYEQUIVS default: +XQuartzEnableKeyEquivalents]; + +darwinSyncKeymap =[self prefs_get_boolean: @PREFS_SYNC_KEYMAP default: +darwinSyncKeymap]; + +darwinDesiredDepth =[self prefs_get_integer: @PREFS_DEPTH default: +darwinDesiredDepth]; + +noTestExtensions = ![self prefs_get_boolean: @PREFS_TEST_EXTENSIONS default: +FALSE]; + +XQuartzScrollInDeviceDirection =[self prefs_get_boolean: @PREFS_SCROLL_IN_DEV_DIRECTION default: +XQuartzScrollInDeviceDirection]; #if XQUARTZ_SPARKLE - NSURL *url = [self prefs_copy_url:@PREFS_UPDATE_FEED default:nil]; - if(url) { - [[SUUpdater sharedUpdater] setFeedURL:url]; +NSURL *url =[self prefs_copy_url: @PREFS_UPDATE_FEED default: +nil]; + + if (url) { + [[SUUpdater sharedUpdater] setFeedURL:url]; [url release]; } #endif } /* This will end up at the end of the responder chain. */ -- (void) copy:sender { - DarwinSendDDXEvent(kXquartzPasteboardNotify, 1, - AppleWMCopyToPasteboard); + -(void) copy:sender { + DarwinSendDDXEvent(kXquartzPasteboardNotify, 1, AppleWMCopyToPasteboard); } -- (X11Controller *) controller { +-(X11Controller *) controller { return _controller; } -- (OSX_BOOL) x_active { +-(OSX_BOOL) x_active { return _x_active; } -@end +@end static NSArray * +array_with_strings_and_numbers(int nitems, const char **items, + const char *numbers) +{ + NSMutableArray *array, *subarray; + NSString *string, *number; + int i; -static NSArray * -array_with_strings_and_numbers (int nitems, const char **items, - const char *numbers) { - NSMutableArray *array, *subarray; - NSString *string, *number; - int i; - - /* (Can't autorelease on the X server thread) */ - - array = [[NSMutableArray alloc] initWithCapacity:nitems]; - - for (i = 0; i < nitems; i++) { - subarray = [[NSMutableArray alloc] initWithCapacity:2]; - - string = [[NSString alloc] initWithUTF8String:items[i]]; - [subarray addObject:string]; - [string release]; - - if (numbers[i] != 0) { - number = [[NSString alloc] initWithFormat:@"%d", numbers[i]]; - [subarray addObject:number]; - [number release]; - } else - [subarray addObject:@""]; - - [array addObject:subarray]; - [subarray release]; - } - - return array; + /* (Can't autorelease on the X server thread) */ + + array =[[NSMutableArray alloc] initWithCapacity:nitems]; + + for (i = 0; i < nitems; i++) { + subarray =[[NSMutableArray alloc] initWithCapacity:2]; + + string =[[NSString alloc] initWithUTF8String:items[i]]; + [subarray addObject:string]; + [string release]; + + if (numbers[i] != 0) { + number =[[NSString alloc] initWithFormat:@"%d", numbers[i]]; + [subarray addObject:number]; + [number release]; + } + else + [subarray addObject:@""]; + + [array addObject:subarray]; + [subarray release]; + } + + return array; } -void X11ApplicationSetWindowMenu (int nitems, const char **items, - const char *shortcuts) { - NSArray *array; - array = array_with_strings_and_numbers (nitems, items, shortcuts); - - /* Send the array of strings over to the appkit thread */ - - message_kit_thread (@selector (set_window_menu:), array); - [array release]; +void +X11ApplicationSetWindowMenu(int nitems, const char **items, + const char *shortcuts) +{ + NSArray *array; + + array = array_with_strings_and_numbers(nitems, items, shortcuts); + + /* Send the array of strings over to the appkit thread */ + + message_kit_thread(@selector(set_window_menu:), array); + [array release]; } -void X11ApplicationSetWindowMenuCheck (int idx) { - NSNumber *n; - - n = [[NSNumber alloc] initWithInt:idx]; - - message_kit_thread (@selector (set_window_menu_check:), n); - - [n release]; +void +X11ApplicationSetWindowMenuCheck(int idx) +{ + NSNumber *n; + + n =[[NSNumber alloc] initWithInt:idx]; + + message_kit_thread(@selector(set_window_menu_check:), n); + + [n release]; } -void X11ApplicationSetFrontProcess (void) { - message_kit_thread (@selector (set_front_process:), nil); +void +X11ApplicationSetFrontProcess(void) +{ + message_kit_thread(@selector(set_front_process:), nil); } -void X11ApplicationSetCanQuit (int state) { +void +X11ApplicationSetCanQuit(int state) +{ NSNumber *n; - - n = [[NSNumber alloc] initWithBool:state]; - - message_kit_thread (@selector (set_can_quit:), n); - + + n =[[NSNumber alloc] initWithBool:state]; + + message_kit_thread(@selector(set_can_quit:), n); + [n release]; } -void X11ApplicationServerReady (void) { - message_kit_thread (@selector (server_ready:), nil); +void +X11ApplicationServerReady(void) +{ + message_kit_thread(@selector(server_ready:), nil); } -void X11ApplicationShowHideMenubar (int state) { +void +X11ApplicationShowHideMenubar(int state) +{ NSNumber *n; - - n = [[NSNumber alloc] initWithBool:state]; - - message_kit_thread (@selector (show_hide_menubar:), n); - + + n =[[NSNumber alloc] initWithBool:state]; + + message_kit_thread(@selector(show_hide_menubar:), n); + [n release]; } -void X11ApplicationLaunchClient (const char *cmd) { +void +X11ApplicationLaunchClient(const char *cmd) +{ NSString *string; - - string = [[NSString alloc] initWithUTF8String:cmd]; - - message_kit_thread (@selector (launch_client:), string); - + + string =[[NSString alloc] initWithUTF8String:cmd]; + + message_kit_thread(@selector(launch_client:), string); + [string release]; } @@ -915,112 +1028,135 @@ void X11ApplicationLaunchClient (const char *cmd) { * not the AppKit thread. We want to block entering a screen-capturing RandR * mode until we notify the user about how to get out if the X11 client crashes. */ -Bool X11ApplicationCanEnterRandR(void) { +Bool +X11ApplicationCanEnterRandR(void) +{ NSString *title, *msg; - - if([X11App prefs_get_boolean:@PREFS_NO_RANDR_ALERT default:NO] || XQuartzShieldingWindowLevel != 0) + +if ([X11App prefs_get_boolean: @PREFS_NO_RANDR_ALERT default: +NO] || XQuartzShieldingWindowLevel != 0) return TRUE; - - title = NSLocalizedString(@"Enter RandR mode?", @"Dialog title when switching to RandR"); - msg = NSLocalizedString(@"An application has requested X11 to change the resolution of your display. X11 will restore the display to its previous state when the requesting application requests to return to the previous state. Alternatively, you can use the ⌥⌘A key sequence to force X11 to return to the previous state.", - @"Dialog when switching to RandR"); - if(!XQuartzIsRootless) + title = + NSLocalizedString(@"Enter RandR mode?", + @"Dialog title when switching to RandR"); + msg = + NSLocalizedString + (@"An application has requested X11 to change the resolution of your display. X11 will restore the display to its previous state when the requesting application requests to return to the previous state. Alternatively, you can use the ⌥⌘A key sequence to force X11 to return to the previous state.", + @"Dialog when switching to RandR"); + + if (!XQuartzIsRootless) QuartzShowFullscreen(FALSE); - - switch(NSRunAlertPanel(title, msg, NSLocalizedString(@"Allow", @""), NSLocalizedString (@"Cancel", @""), NSLocalizedString (@"Always Allow", @""))) { - case NSAlertOtherReturn: - [X11App prefs_set_boolean:@PREFS_NO_RANDR_ALERT value:YES]; - [X11App prefs_synchronize]; - case NSAlertDefaultReturn: - return YES; - default: - return NO; + switch (NSRunAlertPanel + (title, msg, NSLocalizedString(@"Allow", @""), + NSLocalizedString(@"Cancel", @""), + NSLocalizedString(@"Always Allow", @""))) { + case NSAlertOtherReturn: + [X11App prefs_set_boolean: @PREFS_NO_RANDR_ALERT value:YES]; + [X11App prefs_synchronize]; + case NSAlertDefaultReturn: + return YES; + + default: + return NO; } } -static void check_xinitrc (void) { +static void +check_xinitrc(void) +{ char *tem, buf[1024]; NSString *msg; - - if ([X11App prefs_get_boolean:@PREFS_DONE_XINIT_CHECK default:NO]) - return; - - tem = getenv ("HOME"); - if (tem == NULL) goto done; - - snprintf (buf, sizeof (buf), "%s/.xinitrc", tem); - if (access (buf, F_OK) != 0) - goto done; - - msg = NSLocalizedString (@"You have an existing ~/.xinitrc file.\n\n\ + +if ([X11App prefs_get_boolean: @PREFS_DONE_XINIT_CHECK default: +NO]) + return; + + tem = getenv("HOME"); + if (tem == NULL) + goto done; + + snprintf(buf, sizeof(buf), "%s/.xinitrc", tem); + if (access(buf, F_OK) != 0) + goto done; + + msg = NSLocalizedString(@"You have an existing ~/.xinitrc file.\n\n\ Windows displayed by X11 applications may not have titlebars, or may look \ different to windows displayed by native applications.\n\n\ Would you like to move aside the existing file and use the standard X11 \ environment the next time you start X11?", @"Startup xinitrc dialog"); - if(NSAlertDefaultReturn == NSRunAlertPanel (nil, msg, NSLocalizedString (@"Yes", @""), - NSLocalizedString (@"No", @""), nil)) { + if (NSAlertDefaultReturn == + NSRunAlertPanel(nil, msg, NSLocalizedString(@"Yes", @""), + NSLocalizedString(@"No", @""), nil)) { char buf2[1024]; int i = -1; - - snprintf (buf2, sizeof (buf2), "%s.old", buf); - - for(i = 1; access (buf2, F_OK) == 0; i++) - snprintf (buf2, sizeof (buf2), "%s.old.%d", buf, i); - rename (buf, buf2); + snprintf(buf2, sizeof(buf2), "%s.old", buf); + + for (i = 1; access(buf2, F_OK) == 0; i++) + snprintf(buf2, sizeof(buf2), "%s.old.%d", buf, i); + + rename(buf, buf2); } - + done: - [X11App prefs_set_boolean:@PREFS_DONE_XINIT_CHECK value:YES]; + [X11App prefs_set_boolean: @PREFS_DONE_XINIT_CHECK value:YES]; [X11App prefs_synchronize]; } -static inline pthread_t create_thread(void *(*func)(void *), void *arg) { +static inline pthread_t +create_thread(void *(*func) (void *), void *arg) +{ pthread_attr_t attr; pthread_t tid; - + pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_create(&tid, &attr, func, arg); pthread_attr_destroy(&attr); - + return tid; } -static void *xpbproxy_x_thread(void *args) { +static void * +xpbproxy_x_thread(void *args) +{ xpbproxy_run(); ErrorF("xpbproxy thread is terminating unexpectedly.\n"); return NULL; } -void X11ApplicationMain (int argc, char **argv, char **envp) { +void +X11ApplicationMain(int argc, char **argv, char **envp) +{ NSAutoreleasePool *pool; #ifdef DEBUG - while (access ("/tmp/x11-block", F_OK) == 0) sleep (1); + while (access("/tmp/x11-block", F_OK) == 0) + sleep(1); #endif - - pool = [[NSAutoreleasePool alloc] init]; - X11App = (X11Application *) [X11Application sharedApplication]; - init_ports (); - - app_prefs_domain_cfstr = (CFStringRef)[[NSBundle mainBundle] bundleIdentifier]; + + pool =[[NSAutoreleasePool alloc] init]; + X11App = (X11Application *)[X11Application sharedApplication]; + init_ports(); + + app_prefs_domain_cfstr = + (CFStringRef)[[NSBundle mainBundle] bundleIdentifier]; if (app_prefs_domain_cfstr == NULL) { - ErrorF("X11ApplicationMain: Unable to determine bundle identifier. Your installation of XQuartz may be broken.\n"); - app_prefs_domain_cfstr = CFSTR(BUNDLE_ID_PREFIX".X11"); + ErrorF + ("X11ApplicationMain: Unable to determine bundle identifier. Your installation of XQuartz may be broken.\n"); + app_prefs_domain_cfstr = CFSTR(BUNDLE_ID_PREFIX ".X11"); } [NSApp read_defaults]; - [NSBundle loadNibNamed:@"main" owner:NSApp]; - [[NSNotificationCenter defaultCenter] addObserver:NSApp - selector:@selector (became_key:) - name:NSWindowDidBecomeKeyNotification object:nil]; + [NSBundle loadNibNamed: @"main" owner:NSApp]; + [[NSNotificationCenter defaultCenter] addObserver: NSApp selector: @selector(became_key:) + name: NSWindowDidBecomeKeyNotification object:nil]; /* * The xpr Quartz mode is statically linked into this server. @@ -1030,23 +1166,27 @@ void X11ApplicationMain (int argc, char **argv, char **envp) { /* Calculate the height of the menubar so we can avoid it. */ aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) - - NSMaxY([[NSScreen mainScreen] visibleFrame]); + NSMaxY([[NSScreen mainScreen] visibleFrame]); #ifdef HAVE_LIBDISPATCH - eventTranslationQueue = dispatch_queue_create(BUNDLE_ID_PREFIX".X11.NSEventsToX11EventsQueue", NULL); + eventTranslationQueue = + dispatch_queue_create(BUNDLE_ID_PREFIX ".X11.NSEventsToX11EventsQueue", + NULL); assert(eventTranslationQueue != NULL); #endif - + /* Set the key layout seed before we start the server */ #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - last_key_layout = TISCopyCurrentKeyboardLayoutInputSource(); + last_key_layout = TISCopyCurrentKeyboardLayoutInputSource(); - if(!last_key_layout) - ErrorF("X11ApplicationMain: Unable to determine TISCopyCurrentKeyboardLayoutInputSource() at startup.\n"); + if (!last_key_layout) + ErrorF + ("X11ApplicationMain: Unable to determine TISCopyCurrentKeyboardLayoutInputSource() at startup.\n"); #else KLGetCurrentKeyboardLayout(&last_key_layout); - if(!last_key_layout) - ErrorF("X11ApplicationMain: Unable to determine KLGetCurrentKeyboardLayout() at startup.\n"); + if (!last_key_layout) + ErrorF + ("X11ApplicationMain: Unable to determine KLGetCurrentKeyboardLayout() at startup.\n"); #endif if (!QuartsResyncKeymap(FALSE)) { @@ -1055,12 +1195,12 @@ void X11ApplicationMain (int argc, char **argv, char **envp) { /* Tell the server thread that it can proceed */ QuartzInitServer(argc, argv, envp); - + /* This must be done after QuartzInitServer because it can result in * an mieqEnqueue() - <rdar://problem/6300249> */ check_xinitrc(); - + create_thread(xpbproxy_x_thread, NULL); #if XQUARTZ_SPARKLE @@ -1074,149 +1214,177 @@ void X11ApplicationMain (int argc, char **argv, char **envp) { /* not reached */ } -@implementation X11Application (Private) - +@implementation X11Application(Private) #ifdef NX_DEVICELCMDKEYMASK /* This is to workaround a bug in the VNC server where we sometimes see the L * modifier and sometimes see no "side" */ -static inline int ensure_flag(int flags, int device_independent, int device_dependents, int device_dependent_default) { - if( (flags & device_independent) && - !(flags & device_dependents)) +static inline int +ensure_flag(int flags, int device_independent, int device_dependents, + int device_dependent_default) +{ + if ((flags & device_independent) && !(flags & device_dependents)) flags |= device_dependent_default; return flags; } #endif #ifdef DEBUG_UNTRUSTED_POINTER_DELTA -static const char *untrusted_str(NSEvent *e) { - switch([e type]) { - case NSScrollWheel: - return "NSScrollWheel"; - case NSTabletPoint: - return "NSTabletPoint"; - case NSOtherMouseDown: - return "NSOtherMouseDown"; - case NSOtherMouseUp: - return "NSOtherMouseUp"; - case NSLeftMouseDown: - return "NSLeftMouseDown"; - case NSLeftMouseUp: - return "NSLeftMouseUp"; +static const char * +untrusted_str(NSEvent * e) +{ + switch ([e type]) { + case NSScrollWheel: + return "NSScrollWheel"; + case NSTabletPoint: + return "NSTabletPoint"; + case NSOtherMouseDown: + return "NSOtherMouseDown"; + case NSOtherMouseUp: + return "NSOtherMouseUp"; + case NSLeftMouseDown: + return "NSLeftMouseDown"; + case NSLeftMouseUp: + return "NSLeftMouseUp"; + default: + switch ([e subtype]) { + case NSTabletPointEventSubtype: + return "NSTabletPointEventSubtype"; + case NSTabletProximityEventSubtype: + return "NSTabletProximityEventSubtype"; default: - switch([e subtype]) { - case NSTabletPointEventSubtype: - return "NSTabletPointEventSubtype"; - case NSTabletProximityEventSubtype: - return "NSTabletProximityEventSubtype"; - default: - return "Other"; - } + return "Other"; + } } } #endif -- (void) sendX11NSEvent:(NSEvent *)e { + -(void) sendX11NSEvent:(NSEvent *) e { NSPoint location = NSZeroPoint; int ev_button, ev_type; - static float pressure = 0.0; // static so ProximityOut will have the value from the previous tablet event - static NSPoint tilt; // static so ProximityOut will have the value from the previous tablet event + static float pressure = 0.0; // static so ProximityOut will have the value from the previous tablet event + static NSPoint tilt; // static so ProximityOut will have the value from the previous tablet event static DeviceIntPtr darwinTabletCurrent = NULL; - static BOOL needsProximityIn = NO; // Do we do need to handle a pending ProximityIn once we have pressure/tilt? + static BOOL needsProximityIn = NO; // Do we do need to handle a pending ProximityIn once we have pressure/tilt? DeviceIntPtr pDev; int modifierFlags; BOOL isMouseOrTabletEvent, isTabletEvent; #ifdef HAVE_LIBDISPATCH static dispatch_once_t once_pred; - dispatch_once(&once_pred, ^{ - tilt = NSZeroPoint; - darwinTabletCurrent = darwinTabletStylus; - }); + + dispatch_once(&once_pred, ^ { + tilt = NSZeroPoint; + darwinTabletCurrent = darwinTabletStylus;}); #else - if(!darwinTabletCurrent) { + if (!darwinTabletCurrent) { tilt = NSZeroPoint; darwinTabletCurrent = darwinTabletStylus; } #endif - - isMouseOrTabletEvent = [e type] == NSLeftMouseDown || [e type] == NSOtherMouseDown || [e type] == NSRightMouseDown || - [e type] == NSLeftMouseUp || [e type] == NSOtherMouseUp || [e type] == NSRightMouseUp || - [e type] == NSLeftMouseDragged || [e type] == NSOtherMouseDragged || [e type] == NSRightMouseDragged || - [e type] == NSMouseMoved || [e type] == NSTabletPoint || [e type] == NSScrollWheel; + + isMouseOrTabletEvent =[e type] == NSLeftMouseDown || + [e type] == NSOtherMouseDown ||[e type] == NSRightMouseDown || + [e type] == NSLeftMouseUp ||[e type] == NSOtherMouseUp || + [e type] == NSRightMouseUp ||[e type] == NSLeftMouseDragged || + [e type] == NSOtherMouseDragged ||[e type] == NSRightMouseDragged || + [e type] == NSMouseMoved ||[e type] == NSTabletPoint || + [e type] == NSScrollWheel; isTabletEvent = ([e type] == NSTabletPoint) || - (isMouseOrTabletEvent && ([e subtype] == NSTabletPointEventSubtype || [e subtype] == NSTabletProximityEventSubtype)); + (isMouseOrTabletEvent && + ([e subtype] == NSTabletPointEventSubtype || + [e subtype] == NSTabletProximityEventSubtype)); - if(isMouseOrTabletEvent) { + if (isMouseOrTabletEvent) { static NSPoint lastpt; - NSWindow *window = [e window]; - NSRect screen = [[[NSScreen screens] objectAtIndex:0] frame]; - BOOL hasUntrustedPointerDelta; - + NSWindow *window =[e window]; + NSRect screen =[[[NSScreen screens] objectAtIndex:0] frame]; + BOOL hasUntrustedPointerDelta; + // NSEvents for tablets are not consistent wrt deltaXY between events, so we cannot rely on that // Thus tablets will be subject to the warp-pointer bug worked around by the delta, but tablets // are not normally used in cases where that bug would present itself, so this is a fair tradeoff // <rdar://problem/7111003> deltaX and deltaY are incorrect for NSMouseMoved, NSTabletPointEventSubtype // http://xquartz.macosforge.org/trac/ticket/288 hasUntrustedPointerDelta = isTabletEvent; - + // The deltaXY for middle click events also appear erroneous after fast user switching // <rdar://problem/7979468> deltaX and deltaY are incorrect for NSOtherMouseDown and NSOtherMouseUp after FUS // http://xquartz.macosforge.org/trac/ticket/389 - hasUntrustedPointerDelta = hasUntrustedPointerDelta || [e type] == NSOtherMouseDown || [e type] == NSOtherMouseUp; + hasUntrustedPointerDelta = hasUntrustedPointerDelta || + [e type] == NSOtherMouseDown ||[e type] == NSOtherMouseUp; // The deltaXY for scroll events correspond to the scroll delta, not the pointer delta // <rdar://problem/7989690> deltaXY for wheel events are being sent as mouse movement - hasUntrustedPointerDelta = hasUntrustedPointerDelta || [e type] == NSScrollWheel; + hasUntrustedPointerDelta = hasUntrustedPointerDelta || + [e type] == NSScrollWheel; #ifdef DEBUG_UNTRUSTED_POINTER_DELTA - hasUntrustedPointerDelta = hasUntrustedPointerDelta || [e type] == NSLeftMouseDown || [e type] == NSLeftMouseUp; + hasUntrustedPointerDelta = hasUntrustedPointerDelta || + [e type] == NSLeftMouseDown ||[e type] == NSLeftMouseUp; #endif - - if (window != nil) { - NSRect frame = [window frame]; - location = [e locationInWindow]; + + if (window != nil) { + NSRect frame =[window frame]; + + location =[e locationInWindow]; location.x += frame.origin.x; location.y += frame.origin.y; lastpt = location; - } else if(hasUntrustedPointerDelta) { + } + else if (hasUntrustedPointerDelta) { #ifdef DEBUG_UNTRUSTED_POINTER_DELTA ErrorF("--- Begin Event Debug ---\n"); ErrorF("Event type: %s\n", untrusted_str(e)); ErrorF("old lastpt: (%0.2f, %0.2f)\n", lastpt.x, lastpt.y); - ErrorF(" delta: (%0.2f, %0.2f)\n", [e deltaX], -[e deltaY]); - ErrorF(" location: (%0.2f, %0.2f)\n", lastpt.x + [e deltaX], lastpt.y - [e deltaY]); - ErrorF("workaround: (%0.2f, %0.2f)\n", [e locationInWindow].x, [e locationInWindow].y); + ErrorF(" delta: (%0.2f, %0.2f)\n",[e deltaX], -[e deltaY]); + ErrorF(" location: (%0.2f, %0.2f)\n", lastpt.x +[e deltaX], + lastpt.y -[e deltaY]); + ErrorF("workaround: (%0.2f, %0.2f)\n",[e locationInWindow].x, + [e locationInWindow].y); ErrorF("--- End Event Debug ---\n"); - location.x = lastpt.x + [e deltaX]; - location.y = lastpt.y - [e deltaY]; - lastpt = [e locationInWindow]; + location.x = lastpt.x +[e deltaX]; + location.y = lastpt.y -[e deltaY]; + lastpt =[e locationInWindow]; #else - location = [e locationInWindow]; + location =[e locationInWindow]; lastpt = location; #endif - } else { - location.x = lastpt.x + [e deltaX]; - location.y = lastpt.y - [e deltaY]; - lastpt = [e locationInWindow]; } - + else { + location.x = lastpt.x +[e deltaX]; + location.y = lastpt.y -[e deltaY]; + lastpt =[e locationInWindow]; + } + /* Convert coordinate system */ location.y = (screen.origin.y + screen.size.height) - location.y; } - - modifierFlags = [e modifierFlags]; - + + modifierFlags =[e modifierFlags]; + #ifdef NX_DEVICELCMDKEYMASK /* This is to workaround a bug in the VNC server where we sometimes see the L * modifier and sometimes see no "side" */ - modifierFlags = ensure_flag(modifierFlags, NX_CONTROLMASK, NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK, NX_DEVICELCTLKEYMASK); - modifierFlags = ensure_flag(modifierFlags, NX_SHIFTMASK, NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK, NX_DEVICELSHIFTKEYMASK); - modifierFlags = ensure_flag(modifierFlags, NX_COMMANDMASK, NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK, NX_DEVICELCMDKEYMASK); - modifierFlags = ensure_flag(modifierFlags, NX_ALTERNATEMASK, NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK, NX_DEVICELALTKEYMASK); + modifierFlags = + ensure_flag(modifierFlags, NX_CONTROLMASK, + NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK, + NX_DEVICELCTLKEYMASK); + modifierFlags = + ensure_flag(modifierFlags, NX_SHIFTMASK, + NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK, + NX_DEVICELSHIFTKEYMASK); + modifierFlags = + ensure_flag(modifierFlags, NX_COMMANDMASK, + NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK, + NX_DEVICELCMDKEYMASK); + modifierFlags = + ensure_flag(modifierFlags, NX_ALTERNATEMASK, + NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK, + NX_DEVICELALTKEYMASK); #endif modifierFlags &= darwin_all_modifier_mask; @@ -1225,192 +1393,236 @@ static const char *untrusted_str(NSEvent *e) { * emulation mucks this up, so we need to check our modifier flag state * on every event... ugg */ - - if(darwin_all_modifier_flags != modifierFlags) + + if (darwin_all_modifier_flags != modifierFlags) DarwinUpdateModKeys(modifierFlags); - - switch ([e type]) { - case NSLeftMouseDown: ev_button=1; ev_type=ButtonPress; goto handle_mouse; - case NSOtherMouseDown: ev_button=2; ev_type=ButtonPress; goto handle_mouse; - case NSRightMouseDown: ev_button=3; ev_type=ButtonPress; goto handle_mouse; - case NSLeftMouseUp: ev_button=1; ev_type=ButtonRelease; goto handle_mouse; - case NSOtherMouseUp: ev_button=2; ev_type=ButtonRelease; goto handle_mouse; - case NSRightMouseUp: ev_button=3; ev_type=ButtonRelease; goto handle_mouse; - case NSLeftMouseDragged: ev_button=1; ev_type=MotionNotify; goto handle_mouse; - case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto handle_mouse; - case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto handle_mouse; - case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse; - case NSTabletPoint: ev_button=0; ev_type=MotionNotify; goto handle_mouse; - - handle_mouse: - pDev = darwinPointer; - - /* NSTabletPoint can have no subtype */ - if([e type] != NSTabletPoint && - [e subtype] == NSTabletProximityEventSubtype) { - switch([e pointingDeviceType]) { - case NSEraserPointingDevice: - darwinTabletCurrent=darwinTabletEraser; - break; - case NSPenPointingDevice: - darwinTabletCurrent=darwinTabletStylus; - break; - case NSCursorPointingDevice: - case NSUnknownPointingDevice: - default: - darwinTabletCurrent=darwinTabletCursor; - break; - } - if([e isEnteringProximity]) - needsProximityIn = YES; - else - DarwinSendProximityEvents(darwinTabletCurrent, ProximityOut, - location.x, location.y, pressure, - tilt.x, tilt.y); - return; + switch ([e type]) { + case NSLeftMouseDown: + ev_button = 1; + ev_type = ButtonPress; + goto handle_mouse; + case NSOtherMouseDown: + ev_button = 2; + ev_type = ButtonPress; + goto handle_mouse; + case NSRightMouseDown: + ev_button = 3; + ev_type = ButtonPress; + goto handle_mouse; + case NSLeftMouseUp: + ev_button = 1; + ev_type = ButtonRelease; + goto handle_mouse; + case NSOtherMouseUp: + ev_button = 2; + ev_type = ButtonRelease; + goto handle_mouse; + case NSRightMouseUp: + ev_button = 3; + ev_type = ButtonRelease; + goto handle_mouse; + case NSLeftMouseDragged: + ev_button = 1; + ev_type = MotionNotify; + goto handle_mouse; + case NSOtherMouseDragged: + ev_button = 2; + ev_type = MotionNotify; + goto handle_mouse; + case NSRightMouseDragged: + ev_button = 3; + ev_type = MotionNotify; + goto handle_mouse; + case NSMouseMoved: + ev_button = 0; + ev_type = MotionNotify; + goto handle_mouse; + case NSTabletPoint: + ev_button = 0; + ev_type = MotionNotify; + goto handle_mouse; + + handle_mouse: + pDev = darwinPointer; + + /* NSTabletPoint can have no subtype */ + if ([e type] != NSTabletPoint && + [e subtype] == NSTabletProximityEventSubtype) { + switch ([e pointingDeviceType]) { + case NSEraserPointingDevice: + darwinTabletCurrent = darwinTabletEraser; + break; + case NSPenPointingDevice: + darwinTabletCurrent = darwinTabletStylus; + break; + case NSCursorPointingDevice: + case NSUnknownPointingDevice: + default: + darwinTabletCurrent = darwinTabletCursor; + break; } - if ([e type] == NSTabletPoint || [e subtype] == NSTabletPointEventSubtype) { - pressure = [e pressure]; - tilt = [e tilt]; - - pDev = darwinTabletCurrent; - - if(needsProximityIn) { - DarwinSendProximityEvents(darwinTabletCurrent, ProximityIn, - location.x, location.y, pressure, - tilt.x, tilt.y); - - needsProximityIn = NO; - } + if ([e isEnteringProximity]) + needsProximityIn = YES; + else + DarwinSendProximityEvents(darwinTabletCurrent, ProximityOut, + location.x, location.y, pressure, + tilt.x, tilt.y); + return; + } + + if ([e type] == NSTabletPoint || + [e subtype] == NSTabletPointEventSubtype) { + pressure =[e pressure]; + tilt =[e tilt]; + + pDev = darwinTabletCurrent; + + if (needsProximityIn) { + DarwinSendProximityEvents(darwinTabletCurrent, ProximityIn, + location.x, location.y, pressure, + tilt.x, tilt.y); + + needsProximityIn = NO; } + } - if(!XQuartzServerVisible && noTestExtensions) { + if (!XQuartzServerVisible && noTestExtensions) { #if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION > 0 /* Older libXplugin (Tiger/"Stock" Leopard) aren't thread safe, so we can't call xp_find_window from the Appkit thread */ - xp_window_id wid = 0; - xp_error err; + xp_window_id wid = 0; + xp_error err; - /* Sigh. Need to check that we're really over one of - * our windows. (We need to receive pointer events while - * not in the foreground, but we don't want to receive them - * when another window is over us or we might show a tooltip) - */ + /* Sigh. Need to check that we're really over one of + * our windows. (We need to receive pointer events while + * not in the foreground, but we don't want to receive them + * when another window is over us or we might show a tooltip) + */ - err = xp_find_window(location.x, location.y, 0, &wid); + err = xp_find_window(location.x, location.y, 0, &wid); - if (err != XP_Success || (err == XP_Success && wid == 0)) + if (err != XP_Success || (err == XP_Success && wid == 0)) #endif - { - bgMouseLocation = location; - bgMouseLocationUpdated = TRUE; - return; - } + { + bgMouseLocation = location; + bgMouseLocationUpdated = TRUE; + return; } - - if(bgMouseLocationUpdated) { - if(!(ev_type == MotionNotify && ev_button == 0)) { - DarwinSendPointerEvents(pDev, MotionNotify, 0, location.x, - location.y, pressure, tilt.x, tilt.y); - } - bgMouseLocationUpdated = FALSE; + } + + if (bgMouseLocationUpdated) { + if (!(ev_type == MotionNotify && ev_button == 0)) { + DarwinSendPointerEvents(pDev, MotionNotify, 0, location.x, + location.y, pressure, tilt.x, tilt.y); } + bgMouseLocationUpdated = FALSE; + } - DarwinSendPointerEvents(pDev, ev_type, ev_button, location.x, location.y, - pressure, tilt.x, tilt.y); - + DarwinSendPointerEvents(pDev, ev_type, ev_button, location.x, + location.y, pressure, tilt.x, tilt.y); + + break; + + case NSTabletProximity: + switch ([e pointingDeviceType]) { + case NSEraserPointingDevice: + darwinTabletCurrent = darwinTabletEraser; break; - - case NSTabletProximity: - switch([e pointingDeviceType]) { - case NSEraserPointingDevice: - darwinTabletCurrent=darwinTabletEraser; - break; - case NSPenPointingDevice: - darwinTabletCurrent=darwinTabletStylus; - break; - case NSCursorPointingDevice: - case NSUnknownPointingDevice: - default: - darwinTabletCurrent=darwinTabletCursor; - break; - } - - if([e isEnteringProximity]) - needsProximityIn = YES; - else - DarwinSendProximityEvents(darwinTabletCurrent, ProximityOut, - location.x, location.y, pressure, - tilt.x, tilt.y); + case NSPenPointingDevice: + darwinTabletCurrent = darwinTabletStylus; break; - - case NSScrollWheel: - { - float deltaX = [e deltaX]; - float deltaY = [e deltaY]; + case NSCursorPointingDevice: + case NSUnknownPointingDevice: + default: + darwinTabletCurrent = darwinTabletCursor; + break; + } + + if ([e isEnteringProximity]) + needsProximityIn = YES; + else + DarwinSendProximityEvents(darwinTabletCurrent, ProximityOut, + location.x, location.y, pressure, + tilt.x, tilt.y); + break; + + case NSScrollWheel: + { + float deltaX =[e deltaX]; + float deltaY =[e deltaY]; + #if !defined(XPLUGIN_VERSION) || XPLUGIN_VERSION == 0 - /* If we're in the background, we need to send a MotionNotify event - * first, since we aren't getting them on background mouse motion - */ - if(!XQuartzServerVisible && noTestExtensions) { - bgMouseLocationUpdated = FALSE; - DarwinSendPointerEvents(darwinPointer, MotionNotify, 0, location.x, - location.y, pressure, tilt.x, tilt.y); - } + /* If we're in the background, we need to send a MotionNotify event + * first, since we aren't getting them on background mouse motion + */ + if (!XQuartzServerVisible && noTestExtensions) { + bgMouseLocationUpdated = FALSE; + DarwinSendPointerEvents(darwinPointer, MotionNotify, 0, location.x, + location.y, pressure, tilt.x, tilt.y); + } #endif #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 - // TODO: Change 1117 to NSAppKitVersionNumber10_7 when it is defined - if(NSAppKitVersionNumber >= 1117 && XQuartzScrollInDeviceDirection && [e isDirectionInvertedFromDevice]) { - deltaX *= -1; - deltaY *= -1; - } + // TODO: Change 1117 to NSAppKitVersionNumber10_7 when it is defined + if (NSAppKitVersionNumber >= 1117 && XQuartzScrollInDeviceDirection && + [e isDirectionInvertedFromDevice]) { + deltaX *= -1; + deltaY *= -1; + } #endif - DarwinSendScrollEvents(deltaX, deltaY, location.x, location.y, - pressure, tilt.x, tilt.y); - break; - } - case NSKeyDown: case NSKeyUp: - { - /* XKB clobbers our keymap at startup, so we need to force it on the first keypress. - * TODO: Make this less of a kludge. - */ - static int force_resync_keymap = YES; - if(force_resync_keymap) { - DarwinSendDDXEvent(kXquartzReloadKeymap, 0); - force_resync_keymap = NO; - } - } + DarwinSendScrollEvents(deltaX, deltaY, location.x, location.y, + pressure, tilt.x, tilt.y); + break; + } + case NSKeyDown: + case NSKeyUp: + { + /* XKB clobbers our keymap at startup, so we need to force it on the first keypress. + * TODO: Make this less of a kludge. + */ + static int force_resync_keymap = YES; + + if (force_resync_keymap) { + DarwinSendDDXEvent(kXquartzReloadKeymap, 0); + force_resync_keymap = NO; + } + } - if(darwinSyncKeymap) { + if (darwinSyncKeymap) { #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - TISInputSourceRef key_layout = TISCopyCurrentKeyboardLayoutInputSource(); - TISInputSourceRef clear; - if (CFEqual(key_layout, last_key_layout)) { - CFRelease(key_layout); - } else { - /* Swap/free thread-safely */ - clear = last_key_layout; - last_key_layout = key_layout; - CFRelease(clear); + TISInputSourceRef key_layout = + TISCopyCurrentKeyboardLayoutInputSource(); + TISInputSourceRef clear; + + if (CFEqual(key_layout, last_key_layout)) { + CFRelease(key_layout); + } + else { + /* Swap/free thread-safely */ + clear = last_key_layout; + last_key_layout = key_layout; + CFRelease(clear); #else - KeyboardLayoutRef key_layout; - KLGetCurrentKeyboardLayout(&key_layout); - if(key_layout != last_key_layout) { - last_key_layout = key_layout; + KeyboardLayoutRef key_layout; + + KLGetCurrentKeyboardLayout(&key_layout); + if (key_layout != last_key_layout) { + last_key_layout = key_layout; #endif - /* Update keyInfo */ - if (!QuartsResyncKeymap(TRUE)) { - ErrorF("sendX11NSEvent: Could not build a valid keymap.\n"); - } + /* Update keyInfo */ + if (!QuartsResyncKeymap(TRUE)) { + ErrorF("sendX11NSEvent: Could not build a valid keymap.\n"); } } + } - ev_type = ([e type] == NSKeyDown) ? KeyPress : KeyRelease; - DarwinSendKeyboardEvents(ev_type, [e keyCode]); - break; - - default: break; /* for gcc */ - } + ev_type = ([e type] == NSKeyDown) ? KeyPress : KeyRelease; + DarwinSendKeyboardEvents(ev_type,[e keyCode]); + break; + + default: + break; /* for gcc */ + } } + @end diff --git a/xorg-server/hw/xquartz/X11Controller.h b/xorg-server/hw/xquartz/X11Controller.h index b9b1d4473..e7fcd453f 100644 --- a/xorg-server/hw/xquartz/X11Controller.h +++ b/xorg-server/hw/xquartz/X11Controller.h @@ -55,9 +55,9 @@ typedef unsigned int NSUInteger; #endif #endif -@interface X11Controller : NSObject + @interface X11Controller:NSObject #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 -<NSTableViewDataSource> + < NSTableViewDataSource > #endif { IBOutlet NSPanel *prefs_panel; @@ -85,6 +85,7 @@ typedef unsigned int NSUInteger; IBOutlet NSPopUpButton *depth; IBOutlet NSMenuItem *window_separator; + // window_separator is DEPRECATED due to this radar: // <rdar://problem/7088335> NSApplication releases the separator in the Windows menu even though it's an IBOutlet // It is kept around for localization compatability and is subject to removal "eventually" @@ -94,6 +95,7 @@ typedef unsigned int NSUInteger; IBOutlet NSMenuItem *dock_window_separator; IBOutlet NSMenuItem *apps_separator; IBOutlet NSMenuItem *toggle_fullscreen_item; + #ifdef XQUARTZ_SPARKLE NSMenuItem *check_for_updates_item; // Programatically enabled #endif @@ -105,7 +107,7 @@ typedef unsigned int NSUInteger; NSMutableArray *table_apps; IBOutlet NSMenu *dock_menu; - + // This is where in the Windows menu we'll start (this will be the index of the separator) NSInteger windows_menu_start; @@ -116,39 +118,40 @@ typedef unsigned int NSUInteger; OSX_BOOL can_quit; } -- (void) set_window_menu:(NSArray *)list; -- (void) set_window_menu_check:(NSNumber *)n; -- (void) set_apps_menu:(NSArray *)list; + -(void) set_window_menu:(NSArray *) list; + -(void) set_window_menu_check:(NSNumber *) n; + -(void) set_apps_menu:(NSArray *) list; #ifdef XQUARTZ_SPARKLE -- (void) setup_sparkle; -- (void) updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update; +-(void) setup_sparkle; + -(void) updater:(SUUpdater *) +updater willInstallUpdate:(SUAppcastItem *) update; #endif -- (void) set_can_quit:(OSX_BOOL)state; -- (void) server_ready; -- (OSX_BOOL) application:(NSApplication *)app openFile:(NSString *)filename; - -- (IBAction) apps_table_show:(id)sender; -- (IBAction) apps_table_done:(id)sender; -- (IBAction) apps_table_new:(id)sender; -- (IBAction) apps_table_duplicate:(id)sender; -- (IBAction) apps_table_delete:(id)sender; -- (IBAction) bring_to_front:(id)sender; -- (IBAction) close_window:(id)sender; -- (IBAction) minimize_window:(id)sender; -- (IBAction) zoom_window:(id)sender; -- (IBAction) next_window:(id)sender; -- (IBAction) previous_window:(id)sender; -- (IBAction) enable_fullscreen_changed:(id)sender; -- (IBAction) toggle_fullscreen:(id)sender; -- (IBAction) prefs_changed:(id)sender; -- (IBAction) prefs_show:(id)sender; -- (IBAction) quit:(id)sender; -- (IBAction) x11_help:(id)sender; + -(void) set_can_quit:(OSX_BOOL) state; +-(void) server_ready; + -(OSX_BOOL) application:(NSApplication *) +app openFile:(NSString *) filename; + + -(IBAction) apps_table_show:(id) sender; + -(IBAction) apps_table_done:(id) sender; + -(IBAction) apps_table_new:(id) sender; + -(IBAction) apps_table_duplicate:(id) sender; + -(IBAction) apps_table_delete:(id) sender; + -(IBAction) bring_to_front:(id) sender; + -(IBAction) close_window:(id) sender; + -(IBAction) minimize_window:(id) sender; + -(IBAction) zoom_window:(id) sender; + -(IBAction) next_window:(id) sender; + -(IBAction) previous_window:(id) sender; + -(IBAction) enable_fullscreen_changed:(id) sender; + -(IBAction) toggle_fullscreen:(id) sender; + -(IBAction) prefs_changed:(id) sender; + -(IBAction) prefs_show:(id) sender; + -(IBAction) quit:(id) sender; + -(IBAction) x11_help:(id) sender; @end +#endif /* __OBJC__ */ +void +X11ControllerMain(int argc, char **argv, char **envp); -#endif /* __OBJC__ */ - -void X11ControllerMain(int argc, char **argv, char **envp); - -#endif /* X11CONTROLLER_H */ +#endif /* X11CONTROLLER_H */ diff --git a/xorg-server/hw/xquartz/X11Controller.m b/xorg-server/hw/xquartz/X11Controller.m index 3de4e139d..b0bfc5858 100644 --- a/xorg-server/hw/xquartz/X11Controller.m +++ b/xorg-server/hw/xquartz/X11Controller.m @@ -53,304 +53,277 @@ #include <sys/types.h> #include <sys/wait.h> -@implementation X11Controller +@ implementation X11Controller - (void) awakeFromNib { + X11Application *xapp = NSApp; + NSArray *array; + + /* Point X11Application at ourself. */ + [xapp set_controller:self]; + + array =[xapp prefs_get_array:@PREFS_APPSMENU]; + if (array != nil) { + int count; + + /* convert from [TITLE1 COMMAND1 TITLE2 COMMAND2 ...] + to [[TITLE1 COMMAND1] [TITLE2 COMMAND2] ...] format. */ + + count =[array count]; + if (count > 0 && ![[array objectAtIndex: 0] isKindOfClass:[NSArray class]]) + { + int i; + NSMutableArray *copy, *sub; + + copy =[NSMutableArray arrayWithCapacity:(count / 2)]; + + for (i = 0; i < count / 2; i++) { + sub =[[NSMutableArray alloc] initWithCapacity:3]; + [sub addObject: [array objectAtIndex:i * 2]]; + [sub addObject: [array objectAtIndex:i * 2 + 1]]; + [sub addObject:@""]; + [copy addObject:sub]; + [sub release]; + } + + array = copy; + } + + [self set_apps_menu:array]; + } -- (void) awakeFromNib -{ - X11Application *xapp = NSApp; - NSArray *array; - - /* Point X11Application at ourself. */ - [xapp set_controller:self]; - - array = [xapp prefs_get_array:@PREFS_APPSMENU]; - if (array != nil) - { - int count; - - /* convert from [TITLE1 COMMAND1 TITLE2 COMMAND2 ...] - to [[TITLE1 COMMAND1] [TITLE2 COMMAND2] ...] format. */ - - count = [array count]; - if (count > 0 - && ![[array objectAtIndex:0] isKindOfClass:[NSArray class]]) - { - int i; - NSMutableArray *copy, *sub; - - copy = [NSMutableArray arrayWithCapacity:(count / 2)]; - - for (i = 0; i < count / 2; i++) - { - sub = [[NSMutableArray alloc] initWithCapacity:3]; - [sub addObject:[array objectAtIndex:i*2]]; - [sub addObject:[array objectAtIndex:i*2+1]]; - [sub addObject:@""]; - [copy addObject:sub]; - [sub release]; - } - - array = copy; - } - - [self set_apps_menu:array]; - } - [[NSNotificationCenter defaultCenter] - addObserver: self - selector: @selector(apps_table_done:) - name: NSWindowWillCloseNotification - object: [apps_table window]]; + addObserver: self selector: @selector(apps_table_done:) + name: NSWindowWillCloseNotification object:[apps_table window]]; // Setup data about our Windows menu - if(window_separator) { - [[window_separator menu] removeItem:window_separator]; + if (window_separator) { + [[window_separator menu] removeItem:window_separator]; window_separator = nil; } - - windows_menu_start = [[X11App windowsMenu] numberOfItems]; + + windows_menu_start =[[X11App windowsMenu] numberOfItems]; } -- (void) item_selected:sender -{ - [NSApp activateIgnoringOtherApps:YES]; - - DarwinSendDDXEvent(kXquartzControllerNotify, 2, - AppleWMWindowMenuItem, [sender tag]); + -(void) item_selected:sender { + [NSApp activateIgnoringOtherApps:YES]; + + DarwinSendDDXEvent(kXquartzControllerNotify, 2, + AppleWMWindowMenuItem,[sender tag]); } -- (void) remove_window_menu -{ - NSMenu *menu; - int count, i; +-(void) remove_window_menu { + NSMenu *menu; + int count, i; + + /* Work backwards so we don't mess up the indices */ + menu =[X11App windowsMenu]; + count =[menu numberOfItems]; + for (i = count - 1; i >= windows_menu_start; i--) + [menu removeItemAtIndex:i]; - /* Work backwards so we don't mess up the indices */ - menu = [X11App windowsMenu]; - count = [menu numberOfItems]; - for (i = count - 1; i >= windows_menu_start; i--) - [menu removeItemAtIndex:i]; - - count = [dock_menu indexOfItem:dock_window_separator]; - for (i = 0; i < count; i++) - [dock_menu removeItemAtIndex:0]; + count =[dock_menu indexOfItem:dock_window_separator]; + for (i = 0; i < count; i++) + [dock_menu removeItemAtIndex:0]; } -- (void) install_window_menu:(NSArray *)list -{ - NSMenu *menu; - NSMenuItem *item; - int first, count, i; - - menu = [X11App windowsMenu]; - first = windows_menu_start + 1; - count = [list count]; - - // Push a Separator - if(count) { - [menu addItem:[NSMenuItem separatorItem]]; - } - - for (i = 0; i < count; i++) - { - NSString *name, *shortcut; - - name = [[list objectAtIndex:i] objectAtIndex:0]; - shortcut = [[list objectAtIndex:i] objectAtIndex:1]; - - if(windowItemModMask == 0 || windowItemModMask == -1) - shortcut = @""; - - item = (NSMenuItem *) [menu addItemWithTitle:name action:@selector - (item_selected:) keyEquivalent:shortcut]; - [item setKeyEquivalentModifierMask:(NSUInteger) windowItemModMask]; - [item setTarget:self]; - [item setTag:i]; - [item setEnabled:YES]; - - item = (NSMenuItem *) [dock_menu insertItemWithTitle:name - action:@selector - (item_selected:) keyEquivalent:shortcut - atIndex:i]; - [item setKeyEquivalentModifierMask:(NSUInteger) windowItemModMask]; - [item setTarget:self]; - [item setTag:i]; - [item setEnabled:YES]; - } - - if (checked_window_item >= 0 && checked_window_item < count) - { - item = (NSMenuItem *) [menu itemAtIndex:first + checked_window_item]; - [item setState:NSOnState]; - item = (NSMenuItem *) [dock_menu itemAtIndex:checked_window_item]; - [item setState:NSOnState]; - } -} - -- (void) remove_apps_menu -{ - NSMenu *menu; - NSMenuItem *item; - int i; - - if (apps == nil || apps_separator == nil) return; - - menu = [apps_separator menu]; - - if (menu != nil) - { - for (i = [menu numberOfItems] - 1; i >= 0; i--) - { - item = (NSMenuItem *) [menu itemAtIndex:i]; - if ([item tag] != 0) - [menu removeItemAtIndex:i]; - } - } - - if (dock_apps_menu != nil) - { - for (i = [dock_apps_menu numberOfItems] - 1; i >= 0; i--) - { - item = (NSMenuItem *) [dock_apps_menu itemAtIndex:i]; - if ([item tag] != 0) - [dock_apps_menu removeItemAtIndex:i]; - } - } - - [apps release]; - apps = nil; -} - -- (void) prepend_apps_item:(NSArray *)list index:(int)i menu:(NSMenu *)menu -{ - NSString *title, *shortcut = @""; - NSArray *group; - NSMenuItem *item; - - group = [list objectAtIndex:i]; - title = [group objectAtIndex:0]; - if ([group count] >= 3) - shortcut = [group objectAtIndex:2]; - - if ([title length] != 0) - { - item = (NSMenuItem *) [menu insertItemWithTitle:title - action:@selector (app_selected:) - keyEquivalent:shortcut atIndex:0]; - [item setTarget:self]; - [item setEnabled:YES]; - } - else - { - item = (NSMenuItem *) [NSMenuItem separatorItem]; - [menu insertItem:item atIndex:0]; - } - - [item setTag:i+1]; /* can't be zero, so add one */ -} - -- (void) install_apps_menu:(NSArray *)list -{ - NSMenu *menu; - int i, count; - - count = [list count]; - - if (count == 0 || apps_separator == nil) return; - - menu = [apps_separator menu]; - - for (i = count - 1; i >= 0; i--) - { - if (menu != nil) - [self prepend_apps_item:list index:i menu:menu]; - if (dock_apps_menu != nil) - [self prepend_apps_item:list index:i menu:dock_apps_menu]; - } - - apps = [list retain]; -} - -- (void) set_window_menu:(NSArray *)list -{ - [self remove_window_menu]; - [self install_window_menu:list]; - - DarwinSendDDXEvent(kXquartzControllerNotify, 1, - AppleWMWindowMenuNotify); + -(void) install_window_menu:(NSArray *) list { + NSMenu *menu; + NSMenuItem *item; + int first, count, i; + + menu =[X11App windowsMenu]; + first = windows_menu_start + 1; + count =[list count]; + + // Push a Separator + if (count) { + [menu addItem:[NSMenuItem separatorItem]]; + } + + for (i = 0; i < count; i++) { + NSString *name, *shortcut; + + name =[[list objectAtIndex: i] objectAtIndex:0]; + shortcut =[[list objectAtIndex: i] objectAtIndex:1]; + + if (windowItemModMask == 0 || windowItemModMask == -1) + shortcut = @""; + + item = (NSMenuItem *)[menu addItemWithTitle: name action: @selector(item_selected: )keyEquivalent:shortcut]; + [item setKeyEquivalentModifierMask:(NSUInteger) windowItemModMask]; + [item setTarget:self]; + [item setTag:i]; + [item setEnabled:YES]; + + item = (NSMenuItem *)[dock_menu insertItemWithTitle: name action: @selector(item_selected: )keyEquivalent: shortcut atIndex:i]; + [item setKeyEquivalentModifierMask:(NSUInteger) windowItemModMask]; + [item setTarget:self]; + [item setTag:i]; + [item setEnabled:YES]; + } + + if (checked_window_item >= 0 && checked_window_item < count) { + item = (NSMenuItem *)[menu itemAtIndex:first + checked_window_item]; + [item setState:NSOnState]; + item = (NSMenuItem *)[dock_menu itemAtIndex:checked_window_item]; + [item setState:NSOnState]; + } } -- (void) set_window_menu_check:(NSNumber *)nn -{ - NSMenu *menu; - NSMenuItem *item; - int first, count; - int n = [nn intValue]; - - menu = [X11App windowsMenu]; - first = windows_menu_start + 1; - count = [menu numberOfItems] - first; - - if (checked_window_item >= 0 && checked_window_item < count) - { - item = (NSMenuItem *) [menu itemAtIndex:first + checked_window_item]; - [item setState:NSOffState]; - item = (NSMenuItem *) [dock_menu itemAtIndex:checked_window_item]; - [item setState:NSOffState]; - } - if (n >= 0 && n < count) - { - item = (NSMenuItem *) [menu itemAtIndex:first + n]; - [item setState:NSOnState]; - item = (NSMenuItem *) [dock_menu itemAtIndex:n]; - [item setState:NSOnState]; - } - checked_window_item = n; -} - -- (void) set_apps_menu:(NSArray *)list +-(void) remove_apps_menu { + NSMenu *menu; + NSMenuItem *item; + int i; + + if (apps == nil || apps_separator == nil) + return; + + menu =[apps_separator menu]; + + if (menu != nil) { + for (i =[menu numberOfItems] - 1; i >= 0; i--) { + item = (NSMenuItem *)[menu itemAtIndex:i]; + if ([item tag] != 0) + [menu removeItemAtIndex:i]; + } + } + + if (dock_apps_menu != nil) { + for (i =[dock_apps_menu numberOfItems] - 1; i >= 0; i--) { + item = (NSMenuItem *)[dock_apps_menu itemAtIndex:i]; + if ([item tag] != 0) + [dock_apps_menu removeItemAtIndex:i]; + } + } + + [apps release]; + apps = nil; +} + + -(void) prepend_apps_item:(NSArray *) +list index:(int) +i menu:(NSMenu *) menu { - [self remove_apps_menu]; - [self install_apps_menu:list]; + NSString *title, *shortcut = @""; + NSArray *group; + NSMenuItem *item; + + group =[list objectAtIndex:i]; + title =[group objectAtIndex:0]; + if ([group count] >= 3) + shortcut =[group objectAtIndex:2]; + + if ([title length] != 0) { + item = (NSMenuItem *)[menu insertItemWithTitle: title action: @selector(app_selected:) + keyEquivalent: shortcut atIndex:0]; + [item setTarget:self]; + [item setEnabled:YES]; + } + else { + item = (NSMenuItem *)[NSMenuItem separatorItem]; + [menu insertItem: item atIndex:0]; + } + + [item setTag:i + 1]; /* can't be zero, so add one */ +} + + -(void) install_apps_menu:(NSArray *) list { + NSMenu *menu; + int i, count; + + count =[list count]; + + if (count == 0 || apps_separator == nil) + return; + + menu =[apps_separator menu]; + + for (i = count - 1; i >= 0; i--) { + if (menu != nil) + [self prepend_apps_item: list index: i menu:menu]; + if (dock_apps_menu != nil) + [self prepend_apps_item: list index: i menu:dock_apps_menu]; + } + + apps =[list retain]; +} + + -(void) set_window_menu:(NSArray *) list { + [self remove_window_menu]; + [self install_window_menu:list]; + + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMWindowMenuNotify); +} + + -(void) set_window_menu_check:(NSNumber *) nn { + NSMenu *menu; + NSMenuItem *item; + int first, count; + int n =[nn intValue]; + + menu =[X11App windowsMenu]; + first = windows_menu_start + 1; + count =[menu numberOfItems] - first; + + if (checked_window_item >= 0 && checked_window_item < count) { + item = (NSMenuItem *)[menu itemAtIndex:first + checked_window_item]; + [item setState:NSOffState]; + item = (NSMenuItem *)[dock_menu itemAtIndex:checked_window_item]; + [item setState:NSOffState]; + } + if (n >= 0 && n < count) { + item = (NSMenuItem *)[menu itemAtIndex:first + n]; + [item setState:NSOnState]; + item = (NSMenuItem *)[dock_menu itemAtIndex:n]; + [item setState:NSOnState]; + } + checked_window_item = n; +} + + -(void) set_apps_menu:(NSArray *) list { + [self remove_apps_menu]; + [self install_apps_menu:list]; } #ifdef XQUARTZ_SPARKLE -- (void) setup_sparkle { - if(check_for_updates_item) - return; // already did it... +-(void) setup_sparkle { + if (check_for_updates_item) + return; // already did it... - NSMenu *menu = [x11_about_item menu]; + NSMenu *menu =[x11_about_item menu]; - check_for_updates_item = [menu insertItemWithTitle:NSLocalizedString(@"Check for X11 Updates...", @"Check for X11 Updates...") - action:@selector (checkForUpdates:) - keyEquivalent:@"" - atIndex:1]; - [check_for_updates_item setTarget:[SUUpdater sharedUpdater]]; - [check_for_updates_item setEnabled:YES]; + check_for_updates_item =[menu insertItemWithTitle:NSLocalizedString(@"Check for X11 Updates...", + @"Check for X11 Updates...") + action: @selector(checkForUpdates:) + keyEquivalent: @"" atIndex:1]; + [check_for_updates_item setTarget:[SUUpdater sharedUpdater]]; + [check_for_updates_item setEnabled:YES]; // Set X11Controller as the delegate for the updater. - [[SUUpdater sharedUpdater] setDelegate:self]; + [[SUUpdater sharedUpdater] setDelegate:self]; } // Sent immediately before installing the specified update. -- (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update { + -(void) updater:(SUUpdater *) +updater willInstallUpdate:(SUAppcastItem *) update +{ //[self set_can_quit:YES]; } #endif -- (void) launch_client:(NSString *)filename -{ + -(void) launch_client:(NSString *) filename { int child1, child2 = 0; int status; const char *newargv[4]; char buf[128]; char *s; - - newargv[0] = [X11App prefs_get_string:@PREFS_LOGIN_SHELL default:"/bin/sh"]; + +newargv[0] =[X11App prefs_get_string: @PREFS_LOGIN_SHELL default: +"/bin/sh"]; newargv[1] = "-c"; - newargv[2] = [filename UTF8String]; + newargv[2] =[filename UTF8String]; newargv[3] = NULL; - + s = getenv("DISPLAY"); if (s == NULL || s[0] == 0) { snprintf(buf, sizeof(buf), ":%s", display); @@ -360,502 +333,541 @@ /* Do the fork-twice trick to avoid having to reap zombies */ child1 = fork(); switch (child1) { - case -1: /* error */ - break; - - case 0: /* child1 */ - child2 = fork(); - - switch (child2) { - int max_files, i; - - case -1: /* error */ - _exit(1); - - case 0: /* child2 */ - /* close all open files except for standard streams */ - max_files = sysconf(_SC_OPEN_MAX); - for(i = 3; i < max_files; i++) - close(i); - - /* ensure stdin is on /dev/null */ - close(0); - open("/dev/null", O_RDONLY); - - execvp(newargv[0], (char **const) newargv); - _exit(2); - - default: /* parent (child1) */ - _exit(0); - } - break; - - default: /* parent */ - waitpid(child1, &status, 0); + case -1: /* error */ + break; + + case 0: /* child1 */ + child2 = fork(); + + switch (child2) { + int max_files, i; + + case -1: /* error */ + _exit(1); + + case 0: /* child2 */ + /* close all open files except for standard streams */ + max_files = sysconf(_SC_OPEN_MAX); + for (i = 3; i < max_files; i++) + close(i); + + /* ensure stdin is on /dev/null */ + close(0); + open("/dev/null", O_RDONLY); + + execvp(newargv[0], (char **const) newargv); + _exit(2); + + default: /* parent (child1) */ + _exit(0); + } + break; + + default: /* parent */ + waitpid(child1, &status, 0); } } -- (void) app_selected:sender -{ - int tag; - NSString *item; - - tag = [sender tag] - 1; - if (apps == nil || tag < 0 || tag >= [apps count]) - return; - - item = [[apps objectAtIndex:tag] objectAtIndex:1]; - - [self launch_client:item]; -} - -- (IBAction) apps_table_show:sender -{ - NSArray *columns; - NSMutableArray *oldapps = nil; - - if (table_apps != nil) - oldapps = table_apps; - - table_apps = [[NSMutableArray alloc] initWithCapacity:1]; - if(apps != nil) - [table_apps addObjectsFromArray:apps]; - - columns = [apps_table tableColumns]; - [[columns objectAtIndex:0] setIdentifier:@"0"]; - [[columns objectAtIndex:1] setIdentifier:@"1"]; - [[columns objectAtIndex:2] setIdentifier:@"2"]; - - [apps_table setDataSource:self]; - [apps_table selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; - - [[apps_table window] makeKeyAndOrderFront:sender]; - [apps_table reloadData]; - if(oldapps != nil) - [oldapps release]; -} - -- (IBAction) apps_table_done:sender -{ - [apps_table deselectAll:sender]; /* flush edits? */ - - [self remove_apps_menu]; - [self install_apps_menu:table_apps]; - - [NSApp prefs_set_array:@PREFS_APPSMENU value:table_apps]; - [NSApp prefs_synchronize]; - - [[apps_table window] orderOut:sender]; - - [table_apps release]; - table_apps = nil; -} - -- (IBAction) apps_table_new:sender -{ - NSMutableArray *item; - - int row = [apps_table selectedRow], i; - - if (row < 0) row = 0; - else row = row + 1; - - i = row; - if (i > [table_apps count]) - return; /* avoid exceptions */ - - [apps_table deselectAll:sender]; - - item = [[NSMutableArray alloc] initWithCapacity:3]; - [item addObject:@""]; - [item addObject:@""]; - [item addObject:@""]; - - [table_apps insertObject:item atIndex:i]; - [item release]; - - [apps_table reloadData]; - [apps_table selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; -} - -- (IBAction) apps_table_duplicate:sender -{ - int row = [apps_table selectedRow], i; - NSObject *item; - - if (row < 0) { - [self apps_table_new:sender]; - return; - } - - i = row; - if (i > [table_apps count] - 1) return; /* avoid exceptions */ - - [apps_table deselectAll:sender]; - - item = [[table_apps objectAtIndex:i] mutableCopy]; - [table_apps insertObject:item atIndex:i]; - [item release]; - - [apps_table reloadData]; - [apps_table selectRowIndexes:[NSIndexSet indexSetWithIndex:row+1] byExtendingSelection:NO]; -} - -- (IBAction) apps_table_delete:sender -{ - int row = [apps_table selectedRow]; - - if (row >= 0) - { - int i = row; - - if (i > [table_apps count] - 1) return; /* avoid exceptions */ - - [apps_table deselectAll:sender]; - - [table_apps removeObjectAtIndex:i]; - } - - [apps_table reloadData]; - - row = MIN (row, [table_apps count] - 1); - if (row >= 0) - [apps_table selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; -} - -- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView -{ - if (table_apps == nil) return 0; - - return [table_apps count]; + -(void) app_selected:sender { + int tag; + NSString *item; + + tag =[sender tag] - 1; + if (apps == nil || tag < 0 || tag >=[apps count]) + return; + + item =[[apps objectAtIndex: tag] objectAtIndex:1]; + + [self launch_client:item]; } -- (id) tableView:(NSTableView *)tableView -objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row -{ - NSArray *item; - int col; - - if (table_apps == nil) return nil; - - col = [[tableColumn identifier] intValue]; - - item = [table_apps objectAtIndex:row]; - if ([item count] > col) - return [item objectAtIndex:col]; - else - return @""; -} - -- (void) tableView:(NSTableView *)tableView setObjectValue:(id)object - forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row -{ - NSMutableArray *item; - int col; - - if (table_apps == nil) return; - - col = [[tableColumn identifier] intValue]; - - item = [table_apps objectAtIndex:row]; - [item replaceObjectAtIndex:col withObject:object]; -} - -- (void) hide_window:sender -{ - if ([X11App x_active]) - DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideWindow); - else - NSBeep (); /* FIXME: something here */ + -(IBAction) apps_table_show:sender { + NSArray *columns; + NSMutableArray *oldapps = nil; + + if (table_apps != nil) + oldapps = table_apps; + + table_apps =[[NSMutableArray alloc] initWithCapacity:1]; + if (apps != nil) + [table_apps addObjectsFromArray:apps]; + + columns =[apps_table tableColumns]; + [[columns objectAtIndex: 0] setIdentifier:@"0"]; + [[columns objectAtIndex: 1] setIdentifier:@"1"]; + [[columns objectAtIndex: 2] setIdentifier:@"2"]; + + [apps_table setDataSource:self]; + [apps_table selectRowIndexes: [NSIndexSet indexSetWithIndex: 0] byExtendingSelection:NO]; + + [[apps_table window] makeKeyAndOrderFront:sender]; + [apps_table reloadData]; + if (oldapps != nil) + [oldapps release]; } -- (IBAction)bring_to_front:sender -{ - DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMBringAllToFront); + -(IBAction) apps_table_done:sender { + [apps_table deselectAll:sender]; + /* flush edits? */ + + [self remove_apps_menu]; + [self install_apps_menu:table_apps]; + + [NSApp prefs_set_array: @PREFS_APPSMENU value:table_apps]; + [NSApp prefs_synchronize]; + + [[apps_table window] orderOut:sender]; + + [table_apps release]; + table_apps = nil; } -- (IBAction)close_window:sender -{ - if ([X11App x_active]) - DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMCloseWindow); - else - [[NSApp keyWindow] performClose:sender]; + -(IBAction) apps_table_new:sender { + NSMutableArray *item; + + int row =[apps_table selectedRow], i; + + if (row < 0) + row = 0; + else + row = row + 1; + + i = row; + if (i >[table_apps count]) + return; /* avoid exceptions */ + + [apps_table deselectAll:sender]; + + item =[[NSMutableArray alloc] initWithCapacity:3]; + [item addObject:@""]; + [item addObject:@""]; + [item addObject:@""]; + + [table_apps insertObject: item atIndex:i]; + [item release]; + + [apps_table reloadData]; + [apps_table selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection:NO]; } -- (IBAction)minimize_window:sender -{ - if ([X11App x_active]) - DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMMinimizeWindow); - else - [[NSApp keyWindow] performMiniaturize:sender]; + -(IBAction) apps_table_duplicate:sender { + int row =[apps_table selectedRow], i; + NSObject *item; + + if (row < 0) { + [self apps_table_new:sender]; + return; + } + + i = row; + if (i >[table_apps count] - 1) + return; /* avoid exceptions */ + + [apps_table deselectAll:sender]; + + item =[[table_apps objectAtIndex:i] mutableCopy]; + [table_apps insertObject: item atIndex:i]; + [item release]; + + [apps_table reloadData]; + [apps_table selectRowIndexes: [NSIndexSet indexSetWithIndex: row + 1] byExtendingSelection:NO]; } -- (IBAction)zoom_window:sender -{ - if ([X11App x_active]) - DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMZoomWindow); - else - [[NSApp keyWindow] performZoom:sender]; + -(IBAction) apps_table_delete:sender { + int row =[apps_table selectedRow]; + + if (row >= 0) { + int i = row; + + if (i >[table_apps count] - 1) + return; /* avoid exceptions */ + + [apps_table deselectAll:sender]; + + [table_apps removeObjectAtIndex:i]; + } + + [apps_table reloadData]; + + row = MIN(row,[table_apps count] - 1); + if (row >= 0) + [apps_table selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection:NO]; +} + + -(NSInteger) numberOfRowsInTableView:(NSTableView *) tableView { + if (table_apps == nil) + return 0; + + return[table_apps count]; } -- (IBAction) next_window:sender + -(id) tableView: (NSTableView *) tableView objectValueForTableColumn:(NSTableColumn + *) +tableColumn row:(NSInteger) row { - DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMNextWindow); + NSArray *item; + int col; + + if (table_apps == nil) + return nil; + + col =[[tableColumn identifier] intValue]; + + item =[table_apps objectAtIndex:row]; + if ([item count] > col) + return[item objectAtIndex:col]; + else + return @""; } -- (IBAction) previous_window:sender + -(void) tableView:(NSTableView *) +tableView setObjectValue:(id) object forTableColumn:(NSTableColumn *) +tableColumn row:(NSInteger) row { - DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMPreviousWindow); + NSMutableArray *item; + int col; + + if (table_apps == nil) + return; + + col =[[tableColumn identifier] intValue]; + + item =[table_apps objectAtIndex:row]; + [item replaceObjectAtIndex: col withObject:object]; +} + + -(void) hide_window:sender { + if ([X11App x_active]) + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideWindow); + else + NSBeep(); /* FIXME: something here */ +} + + -(IBAction) bring_to_front:sender { + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMBringAllToFront); +} + + -(IBAction) close_window:sender { + if ([X11App x_active]) + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMCloseWindow); + else + [[NSApp keyWindow] performClose:sender]; +} + + -(IBAction) minimize_window:sender { + if ([X11App x_active]) + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMMinimizeWindow); + else + [[NSApp keyWindow] performMiniaturize:sender]; } -- (IBAction) enable_fullscreen_changed:sender { + -(IBAction) zoom_window:sender { + if ([X11App x_active]) + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMZoomWindow); + else + [[NSApp keyWindow] performZoom:sender]; +} + + -(IBAction) next_window:sender { + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMNextWindow); +} + + -(IBAction) previous_window:sender { + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMPreviousWindow); +} + + -(IBAction) enable_fullscreen_changed:sender { XQuartzRootlessDefault = ![enable_fullscreen intValue]; - [enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault]; - [enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ? [NSColor disabledControlTextColor] : [NSColor controlTextColor]]; + [enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault]; + [enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ?[NSColor disabledControlTextColor] :[NSColor + controlTextColor]]; DarwinSendDDXEvent(kXquartzSetRootless, 1, XQuartzRootlessDefault); - [NSApp prefs_set_boolean:@PREFS_ROOTLESS value:XQuartzRootlessDefault]; + [NSApp prefs_set_boolean: @PREFS_ROOTLESS value:XQuartzRootlessDefault]; [NSApp prefs_synchronize]; } -- (IBAction) toggle_fullscreen:sender -{ - DarwinSendDDXEvent(kXquartzToggleFullscreen, 0); + -(IBAction) toggle_fullscreen:sender { + DarwinSendDDXEvent(kXquartzToggleFullscreen, 0); } -- (void) set_can_quit:(OSX_BOOL)state -{ - can_quit = state; + -(void) set_can_quit:(OSX_BOOL) state { + can_quit = state; } -- (IBAction)prefs_changed:sender -{ - if(!sender) + -(IBAction) prefs_changed:sender { + if (!sender) return; - - if(sender == fake_buttons) { - darwinFakeButtons = [fake_buttons intValue]; - [NSApp prefs_set_boolean:@PREFS_FAKEBUTTONS value:darwinFakeButtons]; - } else if(sender == enable_keyequivs) { - XQuartzEnableKeyEquivalents = [enable_keyequivs intValue]; - [NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:XQuartzEnableKeyEquivalents]; - } else if(sender == sync_keymap) { - darwinSyncKeymap = [sync_keymap intValue]; - [NSApp prefs_set_boolean:@PREFS_SYNC_KEYMAP value:darwinSyncKeymap]; - } else if(sender == enable_fullscreen_menu) { - XQuartzFullscreenMenu = [enable_fullscreen_menu intValue]; - [NSApp prefs_set_boolean:@PREFS_FULLSCREEN_MENU value:XQuartzFullscreenMenu]; - } else if(sender == option_sends_alt) { + + if (sender == fake_buttons) { + darwinFakeButtons =[fake_buttons intValue]; + [NSApp prefs_set_boolean: @PREFS_FAKEBUTTONS value:darwinFakeButtons]; + } + else if (sender == enable_keyequivs) { + XQuartzEnableKeyEquivalents =[enable_keyequivs intValue]; + [NSApp prefs_set_boolean: @PREFS_KEYEQUIVS value:XQuartzEnableKeyEquivalents]; + } + else if (sender == sync_keymap) { + darwinSyncKeymap =[sync_keymap intValue]; + [NSApp prefs_set_boolean: @PREFS_SYNC_KEYMAP value:darwinSyncKeymap]; + } + else if (sender == enable_fullscreen_menu) { + XQuartzFullscreenMenu =[enable_fullscreen_menu intValue]; + [NSApp prefs_set_boolean: @PREFS_FULLSCREEN_MENU value:XQuartzFullscreenMenu]; + } + else if (sender == option_sends_alt) { BOOL prev_opt_sends_alt = XQuartzOptionSendsAlt; - - XQuartzOptionSendsAlt = [option_sends_alt intValue]; - [NSApp prefs_set_boolean:@PREFS_OPTION_SENDS_ALT value:XQuartzOptionSendsAlt]; - if(prev_opt_sends_alt != XQuartzOptionSendsAlt) + XQuartzOptionSendsAlt =[option_sends_alt intValue]; + [NSApp prefs_set_boolean: @PREFS_OPTION_SENDS_ALT value:XQuartzOptionSendsAlt]; + + if (prev_opt_sends_alt != XQuartzOptionSendsAlt) QuartsResyncKeymap(TRUE); - } else if(sender == click_through) { - [NSApp prefs_set_boolean:@PREFS_CLICK_THROUGH value:[click_through intValue]]; - } else if(sender == focus_follows_mouse) { - [NSApp prefs_set_boolean:@PREFS_FFM value:[focus_follows_mouse intValue]]; - } else if(sender == focus_on_new_window) { - [NSApp prefs_set_boolean:@PREFS_FOCUS_ON_NEW_WINDOW value:[focus_on_new_window intValue]]; - } else if(sender == enable_auth) { - [NSApp prefs_set_boolean:@PREFS_NO_AUTH value:![enable_auth intValue]]; - } else if(sender == enable_tcp) { - [NSApp prefs_set_boolean:@PREFS_NO_TCP value:![enable_tcp intValue]]; - } else if(sender == depth) { - [NSApp prefs_set_integer:@PREFS_DEPTH value:[depth selectedTag]]; - } else if(sender == sync_pasteboard) { - BOOL pbproxy_active = [sync_pasteboard intValue]; - [NSApp prefs_set_boolean:@PREFS_SYNC_PB value:pbproxy_active]; - - [sync_pasteboard_to_clipboard setEnabled:pbproxy_active]; - [sync_pasteboard_to_primary setEnabled:pbproxy_active]; - [sync_clipboard_to_pasteboard setEnabled:pbproxy_active]; - [sync_primary_immediately setEnabled:pbproxy_active]; + } + else if (sender == click_through) { + [NSApp prefs_set_boolean: @PREFS_CLICK_THROUGH value:[click_through + intValue]]; + } + else if (sender == focus_follows_mouse) { + [NSApp prefs_set_boolean: @PREFS_FFM value:[focus_follows_mouse + intValue]]; + } + else if (sender == focus_on_new_window) { + [NSApp prefs_set_boolean: @PREFS_FOCUS_ON_NEW_WINDOW value:[focus_on_new_window + intValue]]; + } + else if (sender == enable_auth) { + [NSApp prefs_set_boolean: @PREFS_NO_AUTH value:![enable_auth + intValue]]; + } + else if (sender == enable_tcp) { + [NSApp prefs_set_boolean: @PREFS_NO_TCP value:![enable_tcp intValue]]; + } + else if (sender == depth) { + [NSApp prefs_set_integer: @PREFS_DEPTH value:[depth selectedTag]]; + } + else if (sender == sync_pasteboard) { + BOOL pbproxy_active =[sync_pasteboard intValue]; + + [NSApp prefs_set_boolean: @PREFS_SYNC_PB value:pbproxy_active]; + + [sync_pasteboard_to_clipboard setEnabled:pbproxy_active]; + [sync_pasteboard_to_primary setEnabled:pbproxy_active]; + [sync_clipboard_to_pasteboard setEnabled:pbproxy_active]; + [sync_primary_immediately setEnabled:pbproxy_active]; // setEnabled doesn't do this... - [sync_text1 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]]; - [sync_text2 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]]; - } else if(sender == sync_pasteboard_to_clipboard) { - [NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_CLIPBOARD value:[sync_pasteboard_to_clipboard intValue]]; - } else if(sender == sync_pasteboard_to_primary) { - [NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_PRIMARY value:[sync_pasteboard_to_primary intValue]]; - } else if(sender == sync_clipboard_to_pasteboard) { - [NSApp prefs_set_boolean:@PREFS_SYNC_CLIPBOARD_TO_PB value:[sync_clipboard_to_pasteboard intValue]]; - } else if(sender == sync_primary_immediately) { - [NSApp prefs_set_boolean:@PREFS_SYNC_PRIMARY_ON_SELECT value:[sync_primary_immediately intValue]]; - } else if(sender == scroll_in_device_direction) { - XQuartzScrollInDeviceDirection = [scroll_in_device_direction intValue]; - [NSApp prefs_set_boolean:@PREFS_SCROLL_IN_DEV_DIRECTION value:XQuartzScrollInDeviceDirection]; + [sync_text1 setTextColor:pbproxy_active ?[NSColor controlTextColor] :[NSColor + disabledControlTextColor]]; + [sync_text2 setTextColor:pbproxy_active ?[NSColor controlTextColor] :[NSColor + disabledControlTextColor]]; + } + else if (sender == sync_pasteboard_to_clipboard) { + [NSApp prefs_set_boolean: @PREFS_SYNC_PB_TO_CLIPBOARD value:[sync_pasteboard_to_clipboard + intValue]]; + } + else if (sender == sync_pasteboard_to_primary) { + [NSApp prefs_set_boolean: @PREFS_SYNC_PB_TO_PRIMARY value:[sync_pasteboard_to_primary + intValue]]; + } + else if (sender == sync_clipboard_to_pasteboard) { + [NSApp prefs_set_boolean: @PREFS_SYNC_CLIPBOARD_TO_PB value:[sync_clipboard_to_pasteboard + intValue]]; + } + else if (sender == sync_primary_immediately) { + [NSApp prefs_set_boolean: @PREFS_SYNC_PRIMARY_ON_SELECT value:[sync_primary_immediately + intValue]]; + } + else if (sender == scroll_in_device_direction) { + XQuartzScrollInDeviceDirection =[scroll_in_device_direction intValue]; + [NSApp prefs_set_boolean: @PREFS_SCROLL_IN_DEV_DIRECTION value:XQuartzScrollInDeviceDirection]; } [NSApp prefs_synchronize]; - + DarwinSendDDXEvent(kXquartzReloadPreferences, 0); } -- (IBAction) prefs_show:sender -{ - BOOL pbproxy_active = [NSApp prefs_get_boolean:@PREFS_SYNC_PB default:YES]; + -(IBAction) prefs_show:sender { +BOOL pbproxy_active =[NSApp prefs_get_boolean: @PREFS_SYNC_PB default: +YES]; // Remove preferences from the GUI which are not supported // TODO: Change 1117 to NSAppKitVersionNumber10_7 when it is defined - if(scroll_in_device_direction && NSAppKitVersionNumber < 1117) { + if (scroll_in_device_direction && NSAppKitVersionNumber < 1117) { [scroll_in_device_direction removeFromSuperview]; scroll_in_device_direction = nil; - } else { - [scroll_in_device_direction setIntValue:XQuartzScrollInDeviceDirection]; - } - - [fake_buttons setIntValue:darwinFakeButtons]; - [enable_keyequivs setIntValue:XQuartzEnableKeyEquivalents]; - [sync_keymap setIntValue:darwinSyncKeymap]; - [option_sends_alt setIntValue:XQuartzOptionSendsAlt]; - [click_through setIntValue:[NSApp prefs_get_boolean:@PREFS_CLICK_THROUGH default:NO]]; - [focus_follows_mouse setIntValue:[NSApp prefs_get_boolean:@PREFS_FFM default:NO]]; - [focus_on_new_window setIntValue:[NSApp prefs_get_boolean:@PREFS_FOCUS_ON_NEW_WINDOW default:YES]]; - - [enable_auth setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_AUTH default:NO]]; - [enable_tcp setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_TCP default:NO]]; - - [depth selectItemAtIndex:[depth indexOfItemWithTag:[NSApp prefs_get_integer:@PREFS_DEPTH default:-1]]]; - - [sync_pasteboard setIntValue:pbproxy_active]; - [sync_pasteboard_to_clipboard setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_PB_TO_CLIPBOARD default:YES]]; - [sync_pasteboard_to_primary setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_PB_TO_PRIMARY default:YES]]; - [sync_clipboard_to_pasteboard setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_CLIPBOARD_TO_PB default:YES]]; - [sync_primary_immediately setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_PRIMARY_ON_SELECT default:NO]]; - - [sync_pasteboard_to_clipboard setEnabled:pbproxy_active]; - [sync_pasteboard_to_primary setEnabled:pbproxy_active]; - [sync_clipboard_to_pasteboard setEnabled:pbproxy_active]; - [sync_primary_immediately setEnabled:pbproxy_active]; + } + else { + [scroll_in_device_direction setIntValue:XQuartzScrollInDeviceDirection]; + } + + [fake_buttons setIntValue:darwinFakeButtons]; + [enable_keyequivs setIntValue:XQuartzEnableKeyEquivalents]; + [sync_keymap setIntValue:darwinSyncKeymap]; + [option_sends_alt setIntValue:XQuartzOptionSendsAlt]; +[click_through setIntValue: [NSApp prefs_get_boolean: @PREFS_CLICK_THROUGH default: +NO]]; +[focus_follows_mouse setIntValue: [NSApp prefs_get_boolean: @PREFS_FFM default: +NO]]; +[focus_on_new_window setIntValue: [NSApp prefs_get_boolean: @PREFS_FOCUS_ON_NEW_WINDOW default: +YES]]; + +[enable_auth setIntValue: ![NSApp prefs_get_boolean: @PREFS_NO_AUTH default: +NO]]; +[enable_tcp setIntValue: ![NSApp prefs_get_boolean: @PREFS_NO_TCP default: +NO]]; + +[depth selectItemAtIndex: [depth indexOfItemWithTag: [NSApp prefs_get_integer: @PREFS_DEPTH default: +-1]]]; + + [sync_pasteboard setIntValue:pbproxy_active]; +[sync_pasteboard_to_clipboard setIntValue: [NSApp prefs_get_boolean: @PREFS_SYNC_PB_TO_CLIPBOARD default: +YES]]; +[sync_pasteboard_to_primary setIntValue: [NSApp prefs_get_boolean: @PREFS_SYNC_PB_TO_PRIMARY default: +YES]]; +[sync_clipboard_to_pasteboard setIntValue: [NSApp prefs_get_boolean: @PREFS_SYNC_CLIPBOARD_TO_PB default: +YES]]; +[sync_primary_immediately setIntValue: [NSApp prefs_get_boolean: @PREFS_SYNC_PRIMARY_ON_SELECT default: +NO]]; + + [sync_pasteboard_to_clipboard setEnabled:pbproxy_active]; + [sync_pasteboard_to_primary setEnabled:pbproxy_active]; + [sync_clipboard_to_pasteboard setEnabled:pbproxy_active]; + [sync_primary_immediately setEnabled:pbproxy_active]; // setEnabled doesn't do this... - [sync_text1 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]]; - [sync_text2 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]]; - - [enable_fullscreen setIntValue:!XQuartzRootlessDefault]; - [enable_fullscreen_menu setIntValue:XQuartzFullscreenMenu]; - [enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault]; - [enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ? [NSColor disabledControlTextColor] : [NSColor controlTextColor]]; + [sync_text1 setTextColor:pbproxy_active ?[NSColor controlTextColor] :[NSColor + disabledControlTextColor]]; + [sync_text2 setTextColor:pbproxy_active ?[NSColor controlTextColor] :[NSColor + disabledControlTextColor]]; - [prefs_panel makeKeyAndOrderFront:sender]; + [enable_fullscreen setIntValue:!XQuartzRootlessDefault]; + [enable_fullscreen_menu setIntValue:XQuartzFullscreenMenu]; + [enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault]; + [enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ?[NSColor disabledControlTextColor] :[NSColor + controlTextColor]]; + + [prefs_panel makeKeyAndOrderFront:sender]; } -- (IBAction) quit:sender { + -(IBAction) quit:sender { DarwinSendDDXEvent(kXquartzQuit, 0); } -- (IBAction) x11_help:sender { + -(IBAction) x11_help:sender { #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - AHLookupAnchor((CFStringRef)NSLocalizedString(@"Mac Help", no comment), CFSTR("mchlp2276")); + AHLookupAnchor((CFStringRef) NSLocalizedString(@"Mac Help", no comment), + CFSTR("mchlp2276")); #else AHLookupAnchor(CFSTR("com.apple.machelp"), CFSTR("mchlp2276")); #endif } -- (OSX_BOOL) validateMenuItem:(NSMenuItem *)item { - NSMenu *menu = [item menu]; - - if (item == toggle_fullscreen_item) - return !XQuartzIsRootless; - else if (menu == [X11App windowsMenu] || menu == dock_menu - || (menu == [x11_about_item menu] && [item tag] == 42)) - return (AppleWMSelectedEvents () & AppleWMControllerNotifyMask) != 0; - else - return TRUE; + -(OSX_BOOL) validateMenuItem:(NSMenuItem *) item { + NSMenu *menu =[item menu]; + + if (item == toggle_fullscreen_item) + return !XQuartzIsRootless; + else if (menu ==[X11App windowsMenu] || menu == dock_menu + || (menu ==[x11_about_item menu] &&[item tag] == 42)) + return (AppleWMSelectedEvents() & AppleWMControllerNotifyMask) != 0; + else + return TRUE; } -- (void) applicationDidHide:(NSNotification *)notify -{ - DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideAll); + -(void) applicationDidHide:(NSNotification *) notify { + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideAll); - /* Toggle off fullscreen mode to leave our non-default video - * mode and hide our guard window. - */ - if (!XQuartzIsRootless && XQuartzFullscreenVisible) { - DarwinSendDDXEvent(kXquartzToggleFullscreen, 0); - } + /* Toggle off fullscreen mode to leave our non-default video + * mode and hide our guard window. + */ + if (!XQuartzIsRootless && XQuartzFullscreenVisible) { + DarwinSendDDXEvent(kXquartzToggleFullscreen, 0); + } } -- (void) applicationDidUnhide:(NSNotification *)notify -{ - DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMShowAll); + -(void) applicationDidUnhide:(NSNotification *) notify { + DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMShowAll); } -- (NSApplicationTerminateReply) applicationShouldTerminate:sender { + -(NSApplicationTerminateReply) applicationShouldTerminate:sender { NSString *msg; NSString *title; - - if (can_quit || [X11App prefs_get_boolean:@PREFS_NO_QUIT_ALERT default:NO]) + +if (can_quit ||[X11App prefs_get_boolean: @PREFS_NO_QUIT_ALERT default: +NO]) return NSTerminateNow; - + /* Make sure we're frontmost. */ - [NSApp activateIgnoringOtherApps:YES]; - - title = NSLocalizedString(@"Do you really want to quit X11?", @"Dialog title when quitting"); - msg = NSLocalizedString(@"Any open X11 applications will stop immediately, and you will lose any unsaved changes.", @"Dialog when quitting"); + [NSApp activateIgnoringOtherApps:YES]; + + title = + NSLocalizedString(@"Do you really want to quit X11?", + @"Dialog title when quitting"); + msg = + NSLocalizedString + (@"Any open X11 applications will stop immediately, and you will lose any unsaved changes.", + @"Dialog when quitting"); /* FIXME: safe to run the alert in here? Or should we return Later * and then run the alert on a timer? It seems to work here, so.. */ - - return (NSRunAlertPanel (title, msg, NSLocalizedString (@"Quit", @""), - NSLocalizedString (@"Cancel", @""), nil) + + return (NSRunAlertPanel(title, msg, NSLocalizedString(@"Quit", @""), + NSLocalizedString(@"Cancel", @""), nil) == NSAlertDefaultReturn) ? NSTerminateNow : NSTerminateCancel; } -- (void) applicationWillTerminate:(NSNotification *)aNotification -{ - unsigned remain; - [X11App prefs_synchronize]; - - /* shutdown the X server, it will exit () for us. */ - DarwinSendDDXEvent(kXquartzQuit, 0); - - /* In case it doesn't, exit anyway after a while. */ - remain = 10000000; - while((remain = usleep(remain)) > 0); + -(void) applicationWillTerminate:(NSNotification *) aNotification { + unsigned remain; + + [X11App prefs_synchronize]; + + /* shutdown the X server, it will exit () for us. */ + DarwinSendDDXEvent(kXquartzQuit, 0); + + /* In case it doesn't, exit anyway after a while. */ + remain = 10000000; + while ((remain = usleep(remain)) > 0); - exit (1); + exit(1); } -- (void) server_ready -{ - x_list *node; - - finished_launching = YES; - - for (node = pending_apps; node != NULL; node = node->next) - { - NSString *filename = node->data; - [self launch_client:filename]; - [filename release]; - } - - x_list_free (pending_apps); - pending_apps = NULL; -} - -- (OSX_BOOL) application:(NSApplication *)app openFile:(NSString *)filename +-(void) server_ready { + x_list *node; + + finished_launching = YES; + + for (node = pending_apps; node != NULL; node = node->next) { + NSString *filename = node->data; + + [self launch_client:filename]; + [filename release]; + } + + x_list_free(pending_apps); + pending_apps = NULL; +} + + -(OSX_BOOL) application:(NSApplication *) +app openFile:(NSString *) filename { - const char *name = [filename UTF8String]; - + const char *name =[filename UTF8String]; + if (finished_launching) - [self launch_client:filename]; - else if (name[0] != ':') /* ignore display names */ - pending_apps = x_list_prepend (pending_apps, [filename retain]); - + [self launch_client:filename]; + else if (name[0] != ':') /* ignore display names */ + pending_apps = x_list_prepend(pending_apps,[filename retain]); + /* FIXME: report failures. */ return YES; } -@end - -void X11ControllerMain(int argc, char **argv, char **envp) { - X11ApplicationMain (argc, argv, envp); +@end void +X11ControllerMain(int argc, char **argv, char **envp) +{ + X11ApplicationMain(argc, argv, envp); } diff --git a/xorg-server/hw/xquartz/applewm.c b/xorg-server/hw/xquartz/applewm.c index 55976c454..70fb60a18 100644 --- a/xorg-server/hw/xquartz/applewm.c +++ b/xorg-server/hw/xquartz/applewm.c @@ -64,38 +64,41 @@ static Atom func (void) { \ } DEFINE_ATOM_HELPER(xa_native_screen_origin, "_NATIVE_SCREEN_ORIGIN") -DEFINE_ATOM_HELPER (xa_apple_no_order_in, "_APPLE_NO_ORDER_IN") + DEFINE_ATOM_HELPER(xa_apple_no_order_in, "_APPLE_NO_ORDER_IN") static AppleWMProcsPtr appleWMProcs; static int WMErrorBase; - static unsigned char WMReqCode = 0; static int WMEventBase = 0; -static RESTYPE ClientType, EventType; /* resource types for event masks */ +static RESTYPE ClientType, EventType; /* resource types for event masks */ static XID eventResource; /* Currently selected events */ static unsigned int eventMask = 0; -static int WMFreeClient (pointer data, XID id); -static int WMFreeEvents (pointer data, XID id); -static void SNotifyEvent(xAppleWMNotifyEvent *from, xAppleWMNotifyEvent *to); +static int +WMFreeClient(pointer data, XID id); +static int +WMFreeEvents(pointer data, XID id); +static void +SNotifyEvent(xAppleWMNotifyEvent * from, xAppleWMNotifyEvent * to); typedef struct _WMEvent *WMEventPtr; typedef struct _WMEvent { - WMEventPtr next; - ClientPtr client; - XID clientResource; - unsigned int mask; + WMEventPtr next; + ClientPtr client; + XID clientResource; + unsigned int mask; } WMEventRec; static inline BoxRec -make_box (int x, int y, int w, int h) +make_box(int x, int y, int w, int h) { BoxRec r; + r.x1 = x; r.y1 = y; r.x2 = x + w; @@ -105,9 +108,7 @@ make_box (int x, int y, int w, int h) /* Updates the _NATIVE_SCREEN_ORIGIN property on the given root window. */ void -AppleWMSetScreenOrigin( - WindowPtr pWin -) +AppleWMSetScreenOrigin(WindowPtr pWin) { int32_t data[2]; @@ -115,7 +116,7 @@ AppleWMSetScreenOrigin( data[1] = pWin->drawable.pScreen->y + darwinMainScreenY; dixChangeWindowProperty(serverClient, pWin, xa_native_screen_origin(), - XA_INTEGER, 32, PropModeReplace, 2, data, TRUE); + XA_INTEGER, 32, PropModeReplace, 2, data, TRUE); } /* Window managers can set the _APPLE_NO_ORDER_IN property on windows @@ -123,9 +124,7 @@ AppleWMSetScreenOrigin( be mapped but remain ordered-out until the animation completes (when the Dock will order them in). */ Bool -AppleWMDoReorderWindow( - WindowPtr pWin -) +AppleWMDoReorderWindow(WindowPtr pWin) { Atom atom; PropertyPtr prop; @@ -133,18 +132,15 @@ AppleWMDoReorderWindow( atom = xa_apple_no_order_in(); rc = dixLookupProperty(&prop, pWin, atom, serverClient, DixReadAccess); - - if(Success == rc && prop->type == atom) - return 0; - + + if (Success == rc && prop->type == atom) + return 0; + return 1; } - static int -ProcAppleWMQueryVersion( - register ClientPtr client -) +ProcAppleWMQueryVersion(register ClientPtr client) { xAppleWMQueryVersionReply rep; @@ -159,15 +155,14 @@ ProcAppleWMQueryVersion( swaps(&rep.sequenceNumber); swapl(&rep.length); } - WriteToClient(client, sizeof(xAppleWMQueryVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xAppleWMQueryVersionReply), (char *) &rep); return Success; } - /* events */ static inline void -updateEventMask (WMEventPtr *pHead) +updateEventMask(WMEventPtr * pHead) { WMEventPtr pCur; @@ -176,18 +171,21 @@ updateEventMask (WMEventPtr *pHead) eventMask |= pCur->mask; } -/*ARGSUSED*/ -static int -WMFreeClient (pointer data, XID id) { - WMEventPtr pEvent; - WMEventPtr *pHead, pCur, pPrev; + /*ARGSUSED*/ static int +WMFreeClient(pointer data, XID id) +{ + WMEventPtr pEvent; + WMEventPtr *pHead, pCur, pPrev; int i; pEvent = (WMEventPtr) data; - i = dixLookupResourceByType((pointer *)&pHead, eventResource, EventType, serverClient, DixReadAccess | DixWriteAccess | DixDestroyAccess); + i = dixLookupResourceByType((pointer *) &pHead, eventResource, EventType, + serverClient, + DixReadAccess | DixWriteAccess | + DixDestroyAccess); if (i == Success && pHead) { pPrev = 0; - for (pCur = *pHead; pCur && pCur != pEvent; pCur=pCur->next) + for (pCur = *pHead; pCur && pCur != pEvent; pCur = pCur->next) pPrev = pCur; if (pCur) { if (pPrev) @@ -195,21 +193,21 @@ WMFreeClient (pointer data, XID id) { else *pHead = pEvent->next; } - updateEventMask (pHead); + updateEventMask(pHead); } free((pointer) pEvent); return 1; } -/*ARGSUSED*/ -static int -WMFreeEvents (pointer data, XID id) { - WMEventPtr *pHead, pCur, pNext; + /*ARGSUSED*/ static int +WMFreeEvents(pointer data, XID id) +{ + WMEventPtr *pHead, pCur, pNext; pHead = (WMEventPtr *) data; for (pCur = *pHead; pCur; pCur = pNext) { pNext = pCur->next; - FreeResource (pCur->clientResource, ClientType); + FreeResource(pCur->clientResource, ClientType); free((pointer) pCur); } free((pointer) pHead); @@ -218,31 +216,30 @@ WMFreeEvents (pointer data, XID id) { } static int -ProcAppleWMSelectInput (register ClientPtr client) +ProcAppleWMSelectInput(register ClientPtr client) { REQUEST(xAppleWMSelectInputReq); - WMEventPtr pEvent, pNewEvent, *pHead; - XID clientResource; - int i; + WMEventPtr pEvent, pNewEvent, *pHead; + XID clientResource; + int i; - REQUEST_SIZE_MATCH (xAppleWMSelectInputReq); - i = dixLookupResourceByType((pointer *)&pHead, eventResource, EventType, client, DixWriteAccess); + REQUEST_SIZE_MATCH(xAppleWMSelectInputReq); + i = dixLookupResourceByType((pointer *) &pHead, eventResource, EventType, + client, DixWriteAccess); if (stuff->mask != 0) { if (i == Success && pHead) { /* check for existing entry. */ - for (pEvent = *pHead; pEvent; pEvent = pEvent->next) - { - if (pEvent->client == client) - { + for (pEvent = *pHead; pEvent; pEvent = pEvent->next) { + if (pEvent->client == client) { pEvent->mask = stuff->mask; - updateEventMask (pHead); + updateEventMask(pHead); return Success; } } } /* build the entry */ - pNewEvent = (WMEventPtr) malloc(sizeof (WMEventRec)); + pNewEvent = (WMEventPtr) malloc(sizeof(WMEventRec)); if (!pNewEvent) return BadAlloc; pNewEvent->next = 0; @@ -252,9 +249,9 @@ ProcAppleWMSelectInput (register ClientPtr client) * add a resource that will be deleted when * the client goes away */ - clientResource = FakeClientID (client->index); + clientResource = FakeClientID(client->index); pNewEvent->clientResource = clientResource; - if (!AddResource (clientResource, ClientType, (pointer)pNewEvent)) + if (!AddResource(clientResource, ClientType, (pointer) pNewEvent)) return BadAlloc; /* * create a resource to contain a pointer to the list @@ -262,21 +259,20 @@ ProcAppleWMSelectInput (register ClientPtr client) * the list may be arbitrarily rearranged which cannot be * done through the resource database. */ - if (i != Success || !pHead) - { - pHead = (WMEventPtr *) malloc(sizeof (WMEventPtr)); + if (i != Success || !pHead) { + pHead = (WMEventPtr *) malloc(sizeof(WMEventPtr)); if (!pHead || - !AddResource (eventResource, EventType, (pointer)pHead)) - { - FreeResource (clientResource, RT_NONE); + !AddResource(eventResource, EventType, (pointer) pHead)) { + FreeResource(clientResource, RT_NONE); return BadAlloc; } *pHead = 0; } pNewEvent->next = *pHead; *pHead = pNewEvent; - updateEventMask (pHead); - } else if (stuff->mask == 0) { + updateEventMask(pHead); + } + else if (stuff->mask == 0) { /* delete the interest */ if (i == Success && pHead) { pNewEvent = 0; @@ -286,16 +282,17 @@ ProcAppleWMSelectInput (register ClientPtr client) pNewEvent = pEvent; } if (pEvent) { - FreeResource (pEvent->clientResource, ClientType); + FreeResource(pEvent->clientResource, ClientType); if (pNewEvent) pNewEvent->next = pEvent->next; else *pHead = pEvent->next; free(pEvent); - updateEventMask (pHead); + updateEventMask(pHead); } } - } else { + } + else { client->errorValue = stuff->mask; return BadValue; } @@ -307,12 +304,14 @@ ProcAppleWMSelectInput (register ClientPtr client) */ void -AppleWMSendEvent (int type, unsigned int mask, int which, int arg) { - WMEventPtr *pHead, pEvent; +AppleWMSendEvent(int type, unsigned int mask, int which, int arg) +{ + WMEventPtr *pHead, pEvent; xAppleWMNotifyEvent se; - int i; + int i; - i = dixLookupResourceByType((pointer *)&pHead, eventResource, EventType, serverClient, DixReadAccess); + i = dixLookupResourceByType((pointer *) &pHead, eventResource, EventType, + serverClient, DixReadAccess); if (i != Success || !pHead) return; for (pEvent = *pHead; pEvent; pEvent = pEvent->next) { @@ -322,24 +321,21 @@ AppleWMSendEvent (int type, unsigned int mask, int which, int arg) { se.kind = which; se.arg = arg; se.time = currentTime.milliseconds; - WriteEventsToClient (pEvent->client, 1, (xEvent *) &se); + WriteEventsToClient(pEvent->client, 1, (xEvent *) &se); } } /* Safe to call from any thread. */ unsigned int -AppleWMSelectedEvents (void) +AppleWMSelectedEvents(void) { return eventMask; } - /* general utility functions */ static int -ProcAppleWMDisableUpdate( - register ClientPtr client -) +ProcAppleWMDisableUpdate(register ClientPtr client) { REQUEST_SIZE_MATCH(xAppleWMDisableUpdateReq); @@ -349,9 +345,7 @@ ProcAppleWMDisableUpdate( } static int -ProcAppleWMReenableUpdate( - register ClientPtr client -) +ProcAppleWMReenableUpdate(register ClientPtr client) { REQUEST_SIZE_MATCH(xAppleWMReenableUpdateReq); @@ -359,41 +353,37 @@ ProcAppleWMReenableUpdate( return Success; } - /* window functions */ static int -ProcAppleWMSetWindowMenu( - register ClientPtr client -) +ProcAppleWMSetWindowMenu(register ClientPtr client) { const char *bytes, **items; char *shortcuts; int max_len, nitems, i, j; + REQUEST(xAppleWMSetWindowMenuReq); REQUEST_AT_LEAST_SIZE(xAppleWMSetWindowMenuReq); nitems = stuff->nitems; - items = malloc(sizeof (char *) * nitems); - shortcuts = malloc(sizeof (char) * nitems); + items = malloc(sizeof(char *) * nitems); + shortcuts = malloc(sizeof(char) * nitems); max_len = (stuff->length << 2) - sizeof(xAppleWMSetWindowMenuReq); bytes = (char *) &stuff[1]; - for (i = j = 0; i < max_len && j < nitems;) - { + for (i = j = 0; i < max_len && j < nitems;) { shortcuts[j] = bytes[i++]; items[j++] = bytes + i; - while (i < max_len) - { + while (i < max_len) { if (bytes[i++] == 0) break; } } - X11ApplicationSetWindowMenu (nitems, items, shortcuts); + X11ApplicationSetWindowMenu(nitems, items, shortcuts); free(items); free(shortcuts); @@ -401,9 +391,7 @@ ProcAppleWMSetWindowMenu( } static int -ProcAppleWMSetWindowMenuCheck( - register ClientPtr client -) +ProcAppleWMSetWindowMenuCheck(register ClientPtr client) { REQUEST(xAppleWMSetWindowMenuCheckReq); @@ -413,9 +401,7 @@ ProcAppleWMSetWindowMenuCheck( } static int -ProcAppleWMSetFrontProcess( - register ClientPtr client -) +ProcAppleWMSetFrontProcess(register ClientPtr client) { REQUEST_SIZE_MATCH(xAppleWMSetFrontProcessReq); @@ -432,16 +418,15 @@ ProcAppleWMSetWindowLevel(register ClientPtr client) REQUEST_SIZE_MATCH(xAppleWMSetWindowLevelReq); - if (Success != dixLookupWindow(&pWin, stuff->window, client, - DixReadAccess)) + if (Success != dixLookupWindow(&pWin, stuff->window, client, DixReadAccess)) return BadValue; if (stuff->level >= AppleWMNumWindowLevels) { return BadValue; } - err = appleWMProcs->SetWindowLevel(pWin, stuff->level); - if (err != Success) { + err = appleWMProcs->SetWindowLevel(pWin, stuff->level); + if (err != Success) { return err; } @@ -453,10 +438,10 @@ ProcAppleWMSendPSN(register ClientPtr client) { REQUEST(xAppleWMSendPSNReq); int err; - + REQUEST_SIZE_MATCH(xAppleWMSendPSNReq); - - if(!appleWMProcs->SendPSN) + + if (!appleWMProcs->SendPSN) return BadRequest; err = appleWMProcs->SendPSN(stuff->psn_hi, stuff->psn_lo); @@ -471,21 +456,25 @@ static int ProcAppleWMAttachTransient(register ClientPtr client) { WindowPtr pWinChild, pWinParent; + REQUEST(xAppleWMAttachTransientReq); int err; - + REQUEST_SIZE_MATCH(xAppleWMAttachTransientReq); - - if(!appleWMProcs->AttachTransient) + + if (!appleWMProcs->AttachTransient) return BadRequest; - if (Success != dixLookupWindow(&pWinChild, stuff->child, client, DixReadAccess)) + if (Success != + dixLookupWindow(&pWinChild, stuff->child, client, DixReadAccess)) return BadValue; - if(stuff->parent) { - if(Success != dixLookupWindow(&pWinParent, stuff->parent, client, DixReadAccess)) + if (stuff->parent) { + if (Success != + dixLookupWindow(&pWinParent, stuff->parent, client, DixReadAccess)) return BadValue; - } else { + } + else { pWinParent = NULL; } @@ -498,9 +487,7 @@ ProcAppleWMAttachTransient(register ClientPtr client) } static int -ProcAppleWMSetCanQuit( - register ClientPtr client -) +ProcAppleWMSetCanQuit(register ClientPtr client) { REQUEST(xAppleWMSetCanQuitReq); @@ -509,17 +496,15 @@ ProcAppleWMSetCanQuit( X11ApplicationSetCanQuit(stuff->state); return Success; } - /* frame functions */ static int -ProcAppleWMFrameGetRect( - register ClientPtr client -) +ProcAppleWMFrameGetRect(register ClientPtr client) { xAppleWMFrameGetRectReply rep; BoxRec ir, or, rr; + REQUEST(xAppleWMFrameGetRectReq); REQUEST_SIZE_MATCH(xAppleWMFrameGetRectReq); @@ -527,13 +512,12 @@ ProcAppleWMFrameGetRect( rep.length = 0; rep.sequenceNumber = client->sequence; - ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih); - or = make_box (stuff->ox, stuff->oy, stuff->ow, stuff->oh); + ir = make_box(stuff->ix, stuff->iy, stuff->iw, stuff->ih); + or = make_box(stuff->ox, stuff->oy, stuff->ow, stuff->oh); if (appleWMProcs->FrameGetRect(stuff->frame_rect, stuff->frame_class, - &or, &ir, &rr) != Success) - { + &or, &ir, &rr) != Success) { return BadValue; } @@ -542,18 +526,17 @@ ProcAppleWMFrameGetRect( rep.w = rr.x2 - rr.x1; rep.h = rr.y2 - rr.y1; - WriteToClient(client, sizeof(xAppleWMFrameGetRectReply), (char *)&rep); + WriteToClient(client, sizeof(xAppleWMFrameGetRectReply), (char *) &rep); return Success; } static int -ProcAppleWMFrameHitTest( - register ClientPtr client -) +ProcAppleWMFrameHitTest(register ClientPtr client) { xAppleWMFrameHitTestReply rep; BoxRec ir, or; int ret; + REQUEST(xAppleWMFrameHitTestReq); REQUEST_SIZE_MATCH(xAppleWMFrameHitTestReq); @@ -561,40 +544,37 @@ ProcAppleWMFrameHitTest( rep.length = 0; rep.sequenceNumber = client->sequence; - ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih); - or = make_box (stuff->ox, stuff->oy, stuff->ow, stuff->oh); + ir = make_box(stuff->ix, stuff->iy, stuff->iw, stuff->ih); + or = make_box(stuff->ox, stuff->oy, stuff->ow, stuff->oh); if (appleWMProcs->FrameHitTest(stuff->frame_class, stuff->px, - stuff->py, &or, &ir, &ret) != Success) - { + stuff->py, &or, &ir, &ret) != Success) { return BadValue; } rep.ret = ret; - WriteToClient(client, sizeof(xAppleWMFrameHitTestReply), (char *)&rep); + WriteToClient(client, sizeof(xAppleWMFrameHitTestReply), (char *) &rep); return Success; } static int -ProcAppleWMFrameDraw( - register ClientPtr client -) +ProcAppleWMFrameDraw(register ClientPtr client) { BoxRec ir, or; unsigned int title_length, title_max; unsigned char *title_bytes; + REQUEST(xAppleWMFrameDrawReq); WindowPtr pWin; REQUEST_AT_LEAST_SIZE(xAppleWMFrameDrawReq); - if (Success != dixLookupWindow(&pWin, stuff->window, client, - DixReadAccess)) + if (Success != dixLookupWindow(&pWin, stuff->window, client, DixReadAccess)) return BadValue; - ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih); - or = make_box (stuff->ox, stuff->oy, stuff->ow, stuff->oh); + ir = make_box(stuff->ix, stuff->iy, stuff->iw, stuff->ih); + or = make_box(stuff->ox, stuff->oy, stuff->ow, stuff->oh); title_length = stuff->title_length; title_max = (stuff->length << 2) - sizeof(xAppleWMFrameDrawReq); @@ -613,19 +593,15 @@ ProcAppleWMFrameDraw( return Success; } - /* dispatch */ static int -ProcAppleWMDispatch ( - register ClientPtr client -) +ProcAppleWMDispatch(register ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { + switch (stuff->data) { case X_AppleWMQueryVersion: return ProcAppleWMQueryVersion(client); } @@ -633,8 +609,7 @@ ProcAppleWMDispatch ( if (!LocalClient(client)) return WMErrorBase + AppleWMClientNotLocal; - switch (stuff->data) - { + switch (stuff->data) { case X_AppleWMSelectInput: return ProcAppleWMSelectInput(client); case X_AppleWMDisableUpdate: @@ -667,18 +642,17 @@ ProcAppleWMDispatch ( } static void -SNotifyEvent(xAppleWMNotifyEvent *from, xAppleWMNotifyEvent *to) { +SNotifyEvent(xAppleWMNotifyEvent * from, xAppleWMNotifyEvent * to) +{ to->type = from->type; to->kind = from->kind; - cpswaps (from->sequenceNumber, to->sequenceNumber); - cpswapl (from->time, to->time); - cpswapl (from->arg, to->arg); + cpswaps(from->sequenceNumber, to->sequenceNumber); + cpswapl(from->time, to->time); + cpswapl(from->arg, to->arg); } static int -SProcAppleWMQueryVersion( - register ClientPtr client -) +SProcAppleWMQueryVersion(register ClientPtr client) { REQUEST(xAppleWMQueryVersionReq); swaps(&stuff->length); @@ -686,9 +660,7 @@ SProcAppleWMQueryVersion( } static int -SProcAppleWMDispatch ( - register ClientPtr client -) +SProcAppleWMDispatch(register ClientPtr client) { REQUEST(xReq); @@ -697,8 +669,7 @@ SProcAppleWMDispatch ( return WMErrorBase + AppleWMClientNotLocal; /* only local clients are allowed WM access */ - switch (stuff->data) - { + switch (stuff->data) { case X_AppleWMQueryVersion: return SProcAppleWMQueryVersion(client); default: @@ -707,10 +678,9 @@ SProcAppleWMDispatch ( } void -AppleWMExtensionInit( - AppleWMProcsPtr procsPtr) +AppleWMExtensionInit(AppleWMProcsPtr procsPtr) { - ExtensionEntry* extEntry; + ExtensionEntry *extEntry; ClientType = CreateNewResourceType(WMFreeClient, "WMClient"); EventType = CreateNewResourceType(WMFreeEvents, "WMEvent"); @@ -722,14 +692,13 @@ AppleWMExtensionInit( AppleWMNumberErrors, ProcAppleWMDispatch, SProcAppleWMDispatch, - NULL, - StandardMinorOpcode))) - { + NULL, StandardMinorOpcode))) { size_t i; - WMReqCode = (unsigned char)extEntry->base; + + WMReqCode = (unsigned char) extEntry->base; WMErrorBase = extEntry->errorBase; WMEventBase = extEntry->eventBase; - for (i=0; i < AppleWMNumberEvents; i++) + for (i = 0; i < AppleWMNumberEvents; i++) EventSwapVector[WMEventBase + i] = (EventSwapPtr) SNotifyEvent; appleWMProcs = procsPtr; } diff --git a/xorg-server/hw/xquartz/applewmExt.h b/xorg-server/hw/xquartz/applewmExt.h index c46a7bde4..2ad9f45b9 100644 --- a/xorg-server/hw/xquartz/applewmExt.h +++ b/xorg-server/hw/xquartz/applewmExt.h @@ -40,20 +40,21 @@ typedef int xp_frame_class; typedef int xp_frame_rect; #endif -typedef int (*DisableUpdateProc)(void); -typedef int (*EnableUpdateProc)(void); -typedef int (*SetWindowLevelProc)(WindowPtr pWin, int level); -typedef int (*FrameGetRectProc)(xp_frame_rect type, xp_frame_class class, const BoxRec *outer, - const BoxRec *inner, BoxRec *ret); -typedef int (*FrameHitTestProc)(xp_frame_class class, int x, int y, - const BoxRec *outer, - const BoxRec *inner, int *ret); -typedef int (*FrameDrawProc)(WindowPtr pWin, xp_frame_class class, xp_frame_attr attr, - const BoxRec *outer, const BoxRec *inner, - unsigned int title_len, - const unsigned char *title_bytes); -typedef int (*SendPSNProc)(uint32_t hi, uint32_t lo); -typedef int (*AttachTransientProc)(WindowPtr pWinChild, WindowPtr pWinParent); +typedef int (*DisableUpdateProc) (void); +typedef int (*EnableUpdateProc) (void); +typedef int (*SetWindowLevelProc) (WindowPtr pWin, int level); +typedef int (*FrameGetRectProc) (xp_frame_rect type, xp_frame_class class, + const BoxRec * outer, const BoxRec * inner, + BoxRec * ret); +typedef int (*FrameHitTestProc) (xp_frame_class class, int x, int y, + const BoxRec * outer, const BoxRec * inner, + int *ret); +typedef int (*FrameDrawProc) (WindowPtr pWin, xp_frame_class class, + xp_frame_attr attr, const BoxRec * outer, + const BoxRec * inner, unsigned int title_len, + const unsigned char *title_bytes); +typedef int (*SendPSNProc) (uint32_t hi, uint32_t lo); +typedef int (*AttachTransientProc) (WindowPtr pWinChild, WindowPtr pWinParent); /* * AppleWM implementation function list @@ -69,27 +70,19 @@ typedef struct _AppleWMProcs { AttachTransientProc AttachTransient; } AppleWMProcsRec, *AppleWMProcsPtr; -void AppleWMExtensionInit( - AppleWMProcsPtr procsPtr -); +void AppleWMExtensionInit(AppleWMProcsPtr procsPtr); -void AppleWMSetScreenOrigin( - WindowPtr pWin -); +void AppleWMSetScreenOrigin(WindowPtr pWin); -Bool AppleWMDoReorderWindow( - WindowPtr pWin -); +Bool AppleWMDoReorderWindow(WindowPtr pWin); -void AppleWMSendEvent( - int /* type */, - unsigned int /* mask */, - int /* which */, - int /* arg */ -); +void AppleWMSendEvent(int /* type */ , + unsigned int /* mask */ , + int /* which */ , + int /* arg */ + ); -unsigned int AppleWMSelectedEvents( - void -); +unsigned int AppleWMSelectedEvents(void + ); -#endif /* _APPLEWMEXT_H_ */ +#endif /* _APPLEWMEXT_H_ */ diff --git a/xorg-server/hw/xquartz/console_redirect.c b/xorg-server/hw/xquartz/console_redirect.c index 70a819e42..0f96a9512 100644 --- a/xorg-server/hw/xquartz/console_redirect.c +++ b/xorg-server/hw/xquartz/console_redirect.c @@ -94,12 +94,15 @@ static int n_redirect_fds = 0; * were processed. If the pipe is still open, the number of read bytes * is returned. */ -static inline int _read_redirect(int fd, int flush) { +static inline int +_read_redirect(int fd, int flush) +{ int total_read = 0; int nbytes; asl_redirect *aslr = &redirect_fds[fd]; - while((nbytes = read(fd, aslr->w, BUF_SIZE - (aslr->w - aslr->buf) - 1)) > 0) { + while ((nbytes = + read(fd, aslr->w, BUF_SIZE - (aslr->w - aslr->buf) - 1)) > 0) { char *s, *p; /* Increment our returned number read */ @@ -109,17 +112,19 @@ static inline int _read_redirect(int fd, int flush) { aslr->buf[nbytes] = '\0'; /* One line at a time */ - for(p=aslr->buf; *p && (p - aslr->buf) < nbytes; p = s + 1) { + for (p = aslr->buf; *p && (p - aslr->buf) < nbytes; p = s + 1) { // Find null or \n - for(s=p; *s && *s != '\n'; s++); - if(*s == '\n') { - *s='\0'; + for (s = p; *s && *s != '\n'; s++); + if (*s == '\n') { + *s = '\0'; asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p); - } else if(aslr->buf != p) { + } + else if (aslr->buf != p) { memmove(aslr->buf, p, BUF_SIZE - (p - aslr->buf)); aslr->w = aslr->buf + (s - p); break; - } else if(nbytes == BUF_SIZE - 1) { + } + else if (nbytes == BUF_SIZE - 1) { asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p); aslr->w = aslr->buf; break; @@ -128,29 +133,34 @@ static inline int _read_redirect(int fd, int flush) { } /* Flush if requested or we're at EOF */ - if(flush || nbytes == 0) { - if(aslr->w > aslr->buf) { + if (flush || nbytes == 0) { + if (aslr->w > aslr->buf) { *aslr->w = '\0'; asl_log(aslr->asl, aslr->msg, aslr->level, "%s", aslr->buf); } } - if(nbytes == 0) + if (nbytes == 0) return EOF; return total_read; } #ifdef HAVE_LIBDISPATCH -static void read_from_source(void *_source) { - dispatch_source_t source = (dispatch_source_t)_source; +static void +read_from_source(void *_source) +{ + dispatch_source_t source = (dispatch_source_t) _source; int fd = dispatch_source_get_handle(source); - if(_read_redirect(fd, 0) == EOF) { + + if (_read_redirect(fd, 0) == EOF) { dispatch_source_cancel(source); } } -static void cancel_source(void *_source) { - dispatch_source_t source = (dispatch_source_t)_source; +static void +cancel_source(void *_source) +{ + dispatch_source_t source = (dispatch_source_t) _source; int fd = dispatch_source_get_handle(source); asl_redirect *aslr = &redirect_fds[fd]; @@ -164,63 +174,70 @@ static void cancel_source(void *_source) { dispatch_group_leave(read_source_group); } -#else /* !HAVE_LIBDISPATCH */ -static void *redirect_thread(void *ctx __unused) { +#else /* !HAVE_LIBDISPATCH */ +static void * +redirect_thread(void *ctx __unused) +{ struct kevent ev; int n; - while(1) { + while (1) { n = kevent(kq, NULL, 0, &ev, 1, NULL); /* Bail on errors */ - if(n < 0) { - asl_log(NULL, NULL, ASL_LEVEL_ERR, "kevent failure: %s", strerror(errno)); + if (n < 0) { + asl_log(NULL, NULL, ASL_LEVEL_ERR, "kevent failure: %s", + strerror(errno)); break; } - + /* This should not happen */ - if(n == 0) + if (n == 0) continue; - switch(ev.filter) { - case EVFILT_READ: - pthread_mutex_lock(&redirect_fds_lock); - { - int fd = ev.ident; - int close_fd = 0; - asl_redirect *aslr = &redirect_fds[fd]; - - if(fd < 0 || fd >= n_redirect_fds || aslr->buf == NULL) { - asl_log(NULL, NULL, ASL_LEVEL_ERR, "Unexpected file descriptor: %d", fd); - goto next; - } + switch (ev.filter) { + case EVFILT_READ: + pthread_mutex_lock(&redirect_fds_lock); + { + int fd = ev.ident; + int close_fd = 0; + asl_redirect *aslr = &redirect_fds[fd]; + + if (fd < 0 || fd >= n_redirect_fds || aslr->buf == NULL) { + asl_log(NULL, NULL, ASL_LEVEL_ERR, + "Unexpected file descriptor: %d", fd); + goto next; + } - if(ev.flags & EV_EOF) { - close_fd = 1; - if(EOF != _read_redirect(fd, 1)) { - asl_log(NULL, NULL, ASL_LEVEL_ERR, "kevent reported EOF on %d, but read doesn't concur.", fd); - } - } else { - close_fd = (EOF == _read_redirect(fd, 0)); - } - - if(close_fd) { - EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, 0); - kevent(kq, &ev, 1, NULL, 0, NULL); - close(fd); - free(aslr->buf); - memset(aslr, 0, sizeof(*aslr)); + if (ev.flags & EV_EOF) { + close_fd = 1; + if (EOF != _read_redirect(fd, 1)) { + asl_log(NULL, NULL, ASL_LEVEL_ERR, + "kevent reported EOF on %d, but read doesn't concur.", + fd); } } - next: - pthread_mutex_unlock(&redirect_fds_lock); + else { + close_fd = (EOF == _read_redirect(fd, 0)); + } + + if (close_fd) { + EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, 0); + kevent(kq, &ev, 1, NULL, 0, NULL); + close(fd); + free(aslr->buf); + memset(aslr, 0, sizeof(*aslr)); + } + } + next: + pthread_mutex_unlock(&redirect_fds_lock); - case EVFILT_TIMER: - if(ev.udata == ASL_REDIRECT_TERMINATE) - return NULL; + case EVFILT_TIMER: + if (ev.udata == ASL_REDIRECT_TERMINATE) + return NULL; - default: - ;; + default: + ;; } } @@ -228,9 +245,11 @@ static void *redirect_thread(void *ctx __unused) { } #endif -static void redirect_atexit(void) { +static void +redirect_atexit(void) +{ /* stdout is linebuffered, so flush the buffer */ - if(redirect_fds[STDOUT_FILENO].buf) + if (redirect_fds[STDOUT_FILENO].buf) fflush(stdout); #ifdef HAVE_LIBDISPATCH @@ -238,30 +257,35 @@ static void redirect_atexit(void) { int i; /* Cancel all of our dispatch sources, so they flush to ASL */ - for(i=0; i < n_redirect_fds; i++) - if(redirect_fds[i].read_source) + for (i = 0; i < n_redirect_fds; i++) + if (redirect_fds[i].read_source) dispatch_source_cancel(redirect_fds[i].read_source); /* Wait at least three seconds for our sources to flush to ASL */ - dispatch_group_wait(read_source_group, dispatch_time(DISPATCH_TIME_NOW, 3LL * NSEC_PER_SEC)); + dispatch_group_wait(read_source_group, + dispatch_time(DISPATCH_TIME_NOW, + 3LL * NSEC_PER_SEC)); } #else { struct kevent ev; /* Tell our reader thread it is time to pack up and go home */ - EV_SET(&ev, 0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 0, ASL_REDIRECT_TERMINATE); + EV_SET(&ev, 0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 0, + ASL_REDIRECT_TERMINATE); kevent(kq, &ev, 1, NULL, 0, NULL); - + pthread_join(redirect_pthread, NULL); } #endif } #ifdef HAVE_LIBDISPATCH -static void xq_asl_init(void *ctx __unused) +static void +xq_asl_init(void *ctx __unused) #else -static void xq_asl_init(void) +static void +xq_asl_init(void) #endif { assert((redirect_fds = calloc(16, sizeof(*redirect_fds))) != NULL); @@ -281,20 +305,24 @@ static void xq_asl_init(void) atexit(redirect_atexit); } -int xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd) { +int +xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd) +{ #ifdef HAVE_LIBDISPATCH int err __block = 0; static dispatch_once_t once_control; + dispatch_once_f(&once_control, NULL, xq_asl_init); #else int err = 0; static pthread_once_t once_control = PTHREAD_ONCE_INIT; + assert(pthread_once(&once_control, xq_asl_init) == 0); #endif - - if(fd < 0) + + if (fd < 0) return EBADF; - + #ifdef HAVE_LIBDISPATCH #define BLOCK_DONE return dispatch_sync(redirect_serial_q, ^ @@ -304,10 +332,11 @@ int xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd) { #endif { /* Reallocate if we need more space */ - if(fd >= n_redirect_fds) { + if (fd >= n_redirect_fds) { size_t new_n = 1 << (ffs(fd) + 1); - asl_redirect *new_array = realloc(redirect_fds, new_n * sizeof(*redirect_fds)); - if(!new_array) { + asl_redirect *new_array = + realloc(redirect_fds, new_n * sizeof(*redirect_fds)); + if (!new_array) { err = errno; BLOCK_DONE; } @@ -315,33 +344,35 @@ int xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd) { memset(redirect_fds + n_redirect_fds, 0, new_n - n_redirect_fds); n_redirect_fds = new_n; } - + /* If we're already listening on it, return error. */ - if(redirect_fds[fd].buf != NULL) { + if (redirect_fds[fd].buf != NULL) { err = EBADF; BLOCK_DONE; } - + /* Initialize our buffer */ - redirect_fds[fd].buf = (char *)malloc(BUF_SIZE); - if(redirect_fds[fd].buf == NULL) { + redirect_fds[fd].buf = (char *) malloc(BUF_SIZE); + if (redirect_fds[fd].buf == NULL) { err = errno; BLOCK_DONE; } redirect_fds[fd].w = redirect_fds[fd].buf; - + /* Store our ASL settings */ redirect_fds[fd].level = level; redirect_fds[fd].asl = asl; redirect_fds[fd].msg = msg; - + /* Don't block on reads from this fd */ fcntl(fd, F_SETFL, O_NONBLOCK); - + /* Start listening */ #ifdef HAVE_LIBDISPATCH { - dispatch_source_t read_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, fd, 0, redirect_serial_q); + dispatch_source_t read_source = + dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, fd, 0, + redirect_serial_q); redirect_fds[fd].read_source = read_source; dispatch_set_context(read_source, read_source); dispatch_source_set_event_handler_f(read_source, read_from_source); @@ -352,6 +383,7 @@ int xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd) { #else { struct kevent ev; + EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, 0); kevent(kq, &ev, 1, NULL, 0, NULL); } @@ -360,36 +392,38 @@ int xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd) { #ifdef HAVE_LIBDISPATCH ); #else -done: + done: assert(pthread_mutex_unlock(&redirect_fds_lock) == 0); #endif #undef BLOCK_DONE - + return err; } -int xq_asl_capture_fd(aslclient asl, aslmsg msg, int level, int fd) { +int +xq_asl_capture_fd(aslclient asl, aslmsg msg, int level, int fd) +{ int pipepair[2]; - + /* Create pipe */ - if(pipe(pipepair) == -1) + if (pipe(pipepair) == -1) return errno; - + /* Close the read fd but not the write fd on exec */ - if(fcntl(pipepair[0], F_SETFD, FD_CLOEXEC) == -1) + if (fcntl(pipepair[0], F_SETFD, FD_CLOEXEC) == -1) return errno; /* Replace the existing fd */ - if(dup2(pipepair[1], fd) == -1) { + if (dup2(pipepair[1], fd) == -1) { close(pipepair[0]); close(pipepair[1]); return errno; } /* If we capture STDOUT_FILENO, make sure we linebuffer stdout */ - if(fd == STDOUT_FILENO) + if (fd == STDOUT_FILENO) setlinebuf(stdout); - + /* Close the duplicate fds since they've been reassigned */ close(pipepair[1]); @@ -398,7 +432,9 @@ int xq_asl_capture_fd(aslclient asl, aslmsg msg, int level, int fd) { } #ifdef DEBUG_CONSOLE_REDIRECT -int main(int argc __unused, char **argv __unused) { +int +main(int argc __unused, char **argv __unused) +{ xq_asl_capture_fd(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO); xq_asl_capture_fd(NULL, NULL, ASL_LEVEL_ERR, STDERR_FILENO); diff --git a/xorg-server/hw/xquartz/darwin.c b/xorg-server/hw/xquartz/darwin.c index 465a96d12..a0ce377b1 100644 --- a/xorg-server/hw/xquartz/darwin.c +++ b/xorg-server/hw/xquartz/darwin.c @@ -38,10 +38,10 @@ #include "servermd.h" #include "inputstr.h" #include "scrnintstr.h" -#include "mibstore.h" // mi backing store implementation -#include "mipointer.h" // mi software cursor -#include "micmap.h" // mi colormap code -#include "fb.h" // fb framebuffer code +#include "mibstore.h" // mi backing store implementation +#include "mipointer.h" // mi software cursor +#include "micmap.h" // mi colormap code +#include "fb.h" // fb framebuffer code #include "site.h" #include "globals.h" #include "dix.h" @@ -79,21 +79,24 @@ aslclient aslc; -void xq_asl_log (int level, const char *subsystem, const char *file, const char *function, int line, const char *fmt, ...) { +void +xq_asl_log(int level, const char *subsystem, const char *file, + const char *function, int line, const char *fmt, ...) +{ va_list args; aslmsg msg = asl_new(ASL_TYPE_MSG); - if(msg) { + if (msg) { char *_line; asl_set(msg, "File", file); asl_set(msg, "Function", function); asprintf(&_line, "%d", line); - if(_line) { + if (_line) { asl_set(msg, "Line", _line); free(_line); } - if(subsystem) + if (subsystem) asl_set(msg, "Subsystem", subsystem); } @@ -101,82 +104,86 @@ void xq_asl_log (int level, const char *subsystem, const char *file, const char asl_vlog(aslc, msg, level, fmt, args); va_end(args); - if(msg) + if (msg) asl_free(msg); } /* * X server shared global variables */ -int darwinScreensFound = 0; -DevPrivateKeyRec darwinScreenKeyRec; -io_connect_t darwinParamConnect = 0; -int darwinEventReadFD = -1; -int darwinEventWriteFD = -1; +int darwinScreensFound = 0; +DevPrivateKeyRec darwinScreenKeyRec; +io_connect_t darwinParamConnect = 0; +int darwinEventReadFD = -1; +int darwinEventWriteFD = -1; + // int darwinMouseAccelChange = 1; -int darwinFakeButtons = 0; +int darwinFakeButtons = 0; // location of X11's (0,0) point in global screen coordinates -int darwinMainScreenX = 0; -int darwinMainScreenY = 0; +int darwinMainScreenX = 0; +int darwinMainScreenY = 0; // parameters read from the command line or user preferences -int darwinDesiredDepth = -1; -int darwinSyncKeymap = FALSE; +int darwinDesiredDepth = -1; +int darwinSyncKeymap = FALSE; // modifier masks for faking mouse buttons - ANY of these bits trigger it (not all) #ifdef NX_DEVICELCMDKEYMASK -int darwinFakeMouse2Mask = NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK; -int darwinFakeMouse3Mask = NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK; +int darwinFakeMouse2Mask = NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK; +int darwinFakeMouse3Mask = NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK; #else -int darwinFakeMouse2Mask = NX_ALTERNATEMASK; -int darwinFakeMouse3Mask = NX_COMMANDMASK; +int darwinFakeMouse2Mask = NX_ALTERNATEMASK; +int darwinFakeMouse3Mask = NX_COMMANDMASK; #endif // Modifier mask for overriding event delivery to appkit (might be useful to set this to rcommand for input menu -unsigned int darwinAppKitModMask = 0; // Any of these bits +unsigned int darwinAppKitModMask = 0; // Any of these bits // Modifier mask for items in the Window menu (0 and -1 cause shortcuts to be disabled) -unsigned int windowItemModMask = NX_COMMANDMASK; +unsigned int windowItemModMask = NX_COMMANDMASK; // devices -DeviceIntPtr darwinKeyboard = NULL; -DeviceIntPtr darwinPointer = NULL; -DeviceIntPtr darwinTabletStylus = NULL; -DeviceIntPtr darwinTabletCursor = NULL; -DeviceIntPtr darwinTabletEraser = NULL; +DeviceIntPtr darwinKeyboard = NULL; +DeviceIntPtr darwinPointer = NULL; +DeviceIntPtr darwinTabletStylus = NULL; +DeviceIntPtr darwinTabletCursor = NULL; +DeviceIntPtr darwinTabletEraser = NULL; // Common pixmap formats static PixmapFormatRec formats[] = { - { 1, 1, BITMAP_SCANLINE_PAD }, - { 4, 8, BITMAP_SCANLINE_PAD }, - { 8, 8, BITMAP_SCANLINE_PAD }, - { 15, 16, BITMAP_SCANLINE_PAD }, - { 16, 16, BITMAP_SCANLINE_PAD }, - { 24, 32, BITMAP_SCANLINE_PAD }, - { 32, 32, BITMAP_SCANLINE_PAD } + {1, 1, BITMAP_SCANLINE_PAD}, + {4, 8, BITMAP_SCANLINE_PAD}, + {8, 8, BITMAP_SCANLINE_PAD}, + {15, 16, BITMAP_SCANLINE_PAD}, + {16, 16, BITMAP_SCANLINE_PAD}, + {24, 32, BITMAP_SCANLINE_PAD}, + {32, 32, BITMAP_SCANLINE_PAD} }; -const int NUMFORMATS = sizeof(formats)/sizeof(formats[0]); + +const int NUMFORMATS = sizeof(formats) / sizeof(formats[0]); void DarwinPrintBanner(void) -{ - ErrorF("Xquartz starting:\n"); - ErrorF("X.Org X Server %s\n", XSERVER_VERSION); - ErrorF("Build Date: %s\n", BUILD_DATE ); +{ + ErrorF("Xquartz starting:\n"); + ErrorF("X.Org X Server %s\n", XSERVER_VERSION); + ErrorF("Build Date: %s\n", BUILD_DATE); } - /* * DarwinSaveScreen * X screensaver support. Not implemented. */ -static Bool DarwinSaveScreen(ScreenPtr pScreen, int on) +static Bool +DarwinSaveScreen(ScreenPtr pScreen, int on) { // FIXME if (on == SCREEN_SAVER_FORCER) { - } else if (on == SCREEN_SAVER_ON) { - } else { + } + else if (on == SCREEN_SAVER_ON) { + } + else { } return TRUE; } @@ -186,14 +193,16 @@ static Bool DarwinSaveScreen(ScreenPtr pScreen, int on) * This is a callback from dix during AddScreen() from InitOutput(). * Initialize the screen and communicate information about it back to dix. */ -static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv) { - int dpi; - static int foundIndex = 0; - Bool ret; +static Bool +DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv) +{ + int dpi; + static int foundIndex = 0; + Bool ret; DarwinFramebufferPtr dfb; if (!dixRegisterPrivateKey(&darwinScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; + return FALSE; // reset index of found screens for each server generation if (index == 0) { @@ -212,23 +221,27 @@ static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv // setup hardware/mode specific details ret = QuartzAddScreen(foundIndex, pScreen); foundIndex++; - if (! ret) + if (!ret) return FALSE; // setup a single visual appropriate for our pixel type - if(!miSetVisualTypesAndMasks(dfb->depth, dfb->visuals, dfb->bitsPerRGB, - dfb->preferredCVC, dfb->redMask, - dfb->greenMask, dfb->blueMask)) { + if (!miSetVisualTypesAndMasks(dfb->depth, dfb->visuals, dfb->bitsPerRGB, + dfb->preferredCVC, dfb->redMask, + dfb->greenMask, dfb->blueMask)) { return FALSE; } - + // TODO: Make PseudoColor visuals not suck in TrueColor mode // if(dfb->depth > 8) // miSetVisualTypesAndMasks(8, PseudoColorMask, 8, PseudoColor, 0, 0, 0); - if(dfb->depth > 15) - miSetVisualTypesAndMasks(15, TrueColorMask, 5, TrueColor, RM_ARGB(0,5,5,5), GM_ARGB(0,5,5,5), BM_ARGB(0,5,5,5)); - if(dfb->depth > 24) - miSetVisualTypesAndMasks(24, TrueColorMask, 8, TrueColor, RM_ARGB(0,8,8,8), GM_ARGB(0,8,8,8), BM_ARGB(0,8,8,8)); + if (dfb->depth > 15) + miSetVisualTypesAndMasks(15, TrueColorMask, 5, TrueColor, + RM_ARGB(0, 5, 5, 5), GM_ARGB(0, 5, 5, 5), + BM_ARGB(0, 5, 5, 5)); + if (dfb->depth > 24) + miSetVisualTypesAndMasks(24, TrueColorMask, 8, TrueColor, + RM_ARGB(0, 8, 8, 8), GM_ARGB(0, 8, 8, 8), + BM_ARGB(0, 8, 8, 8)); miSetPixmapDepths(); @@ -240,17 +253,16 @@ static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv dpi = 96; // initialize fb - if (! fbScreenInit(pScreen, - dfb->framebuffer, // pointer to screen bitmap - dfb->width, dfb->height, // screen size in pixels - dpi, dpi, // dots per inch - dfb->pitch/(dfb->bitsPerPixel/8), // pixel width of framebuffer - dfb->bitsPerPixel)) // bits per pixel for screen + if (!fbScreenInit(pScreen, dfb->framebuffer, // pointer to screen bitmap + dfb->width, dfb->height, // screen size in pixels + dpi, dpi, // dots per inch + dfb->pitch / (dfb->bitsPerPixel / 8), // pixel width of framebuffer + dfb->bitsPerPixel)) // bits per pixel for screen { return FALSE; } - if (! fbPictureInit(pScreen, 0, 0)) { + if (!fbPictureInit(pScreen, 0, 0)) { return FALSE; } @@ -268,7 +280,7 @@ static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv // create and install the default colormap and // set pScreen->blackPixel / pScreen->white - if (!miCreateDefColormap( pScreen )) { + if (!miCreateDefColormap(pScreen)) { return FALSE; } @@ -276,7 +288,7 @@ static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv pScreen->y = dfb->y; /* ErrorF("Screen %d added: %dx%d @ (%d,%d)\n", - index, dfb->width, dfb->height, dfb->x, dfb->y); */ + index, dfb->width, dfb->height, dfb->x, dfb->y); */ return TRUE; } @@ -292,100 +304,110 @@ static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv /* * DarwinMouseProc: Handle the initialization, etc. of a mouse */ -static int DarwinMouseProc(DeviceIntPtr pPointer, int what) { +static int +DarwinMouseProc(DeviceIntPtr pPointer, int what) +{ #define NBUTTONS 7 #define NAXES 2 - // 7 buttons: left, right, middle, then four scroll wheel "buttons" - CARD8 map[NBUTTONS + 1] = {0, 1, 2, 3, 4, 5, 6, 7}; - Atom btn_labels[NBUTTONS] = {0}; - Atom axes_labels[NAXES] = {0}; + // 7 buttons: left, right, middle, then four scroll wheel "buttons" + CARD8 map[NBUTTONS + 1] = { 0, 1, 2, 3, 4, 5, 6, 7 }; + Atom btn_labels[NBUTTONS] = { 0 }; + Atom axes_labels[NAXES] = { 0 }; switch (what) { - case DEVICE_INIT: - pPointer->public.on = FALSE; - - 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); - - axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X); - axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y); - - - // Set button map. - InitPointerDeviceStruct((DevicePtr)pPointer, map, NBUTTONS, - btn_labels, - (PtrCtrlProcPtr)NoopDDA, - GetMotionHistorySize(), NAXES, - axes_labels); - InitValuatorAxisStruct(pPointer, 0, axes_labels[0], NO_AXIS_LIMITS, NO_AXIS_LIMITS, 0, 0, 0, Absolute); - InitValuatorAxisStruct(pPointer, 1, axes_labels[1], NO_AXIS_LIMITS, NO_AXIS_LIMITS, 0, 0, 0, Absolute); - break; - case DEVICE_ON: - pPointer->public.on = TRUE; - AddEnabledDevice( darwinEventReadFD ); - return Success; - case DEVICE_CLOSE: - case DEVICE_OFF: - pPointer->public.on = FALSE; - RemoveEnabledDevice(darwinEventReadFD); - return Success; + case DEVICE_INIT: + pPointer->public.on = FALSE; + + 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); + + axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X); + axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y); + + // Set button map. + InitPointerDeviceStruct((DevicePtr) pPointer, map, NBUTTONS, + btn_labels, + (PtrCtrlProcPtr) NoopDDA, + GetMotionHistorySize(), NAXES, axes_labels); + InitValuatorAxisStruct(pPointer, 0, axes_labels[0], NO_AXIS_LIMITS, + NO_AXIS_LIMITS, 0, 0, 0, Absolute); + InitValuatorAxisStruct(pPointer, 1, axes_labels[1], NO_AXIS_LIMITS, + NO_AXIS_LIMITS, 0, 0, 0, Absolute); + break; + case DEVICE_ON: + pPointer->public.on = TRUE; + AddEnabledDevice(darwinEventReadFD); + return Success; + case DEVICE_CLOSE: + case DEVICE_OFF: + pPointer->public.on = FALSE; + RemoveEnabledDevice(darwinEventReadFD); + return Success; } - + return Success; #undef NBUTTONS #undef NAXES } -static int DarwinTabletProc(DeviceIntPtr pPointer, int what) { +static int +DarwinTabletProc(DeviceIntPtr pPointer, int what) +{ #define NBUTTONS 3 #define NAXES 5 - CARD8 map[NBUTTONS + 1] = {0, 1, 2, 3}; - Atom btn_labels[NBUTTONS] = {0}; - Atom axes_labels[NAXES] = {0}; + CARD8 map[NBUTTONS + 1] = { 0, 1, 2, 3 }; + Atom btn_labels[NBUTTONS] = { 0 }; + Atom axes_labels[NAXES] = { 0 }; switch (what) { - case DEVICE_INIT: - pPointer->public.on = FALSE; - - 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); - - axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X); - axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y); - axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE); - axes_labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_X); - axes_labels[4] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_Y); - - // Set button map. - InitPointerDeviceStruct((DevicePtr)pPointer, map, NBUTTONS, - btn_labels, - (PtrCtrlProcPtr)NoopDDA, - GetMotionHistorySize(), NAXES, - axes_labels); - InitProximityClassDeviceStruct(pPointer); - - InitValuatorAxisStruct(pPointer, 0, axes_labels[0], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1, Absolute); - InitValuatorAxisStruct(pPointer, 1, axes_labels[1], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1, Absolute); - InitValuatorAxisStruct(pPointer, 2, axes_labels[2], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1, Absolute); - InitValuatorAxisStruct(pPointer, 3, axes_labels[3], -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1, Absolute); - InitValuatorAxisStruct(pPointer, 4, axes_labels[4], -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1, Absolute); + case DEVICE_INIT: + pPointer->public.on = FALSE; + + 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); + + axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X); + axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y); + axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE); + axes_labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_X); + axes_labels[4] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_Y); + + // Set button map. + InitPointerDeviceStruct((DevicePtr) pPointer, map, NBUTTONS, + btn_labels, + (PtrCtrlProcPtr) NoopDDA, + GetMotionHistorySize(), NAXES, axes_labels); + InitProximityClassDeviceStruct(pPointer); + + InitValuatorAxisStruct(pPointer, 0, axes_labels[0], 0, + XQUARTZ_VALUATOR_LIMIT, 1, 0, 1, Absolute); + InitValuatorAxisStruct(pPointer, 1, axes_labels[1], 0, + XQUARTZ_VALUATOR_LIMIT, 1, 0, 1, Absolute); + InitValuatorAxisStruct(pPointer, 2, axes_labels[2], 0, + XQUARTZ_VALUATOR_LIMIT, 1, 0, 1, Absolute); + InitValuatorAxisStruct(pPointer, 3, axes_labels[3], + -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, + 1, 0, 1, Absolute); + InitValuatorAxisStruct(pPointer, 4, axes_labels[4], + -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, + 1, 0, 1, Absolute); // pPointer->use = IsXExtensionDevice; - break; - case DEVICE_ON: - pPointer->public.on = TRUE; - AddEnabledDevice( darwinEventReadFD ); - return Success; - case DEVICE_CLOSE: - case DEVICE_OFF: - pPointer->public.on = FALSE; - RemoveEnabledDevice(darwinEventReadFD); - return Success; + break; + case DEVICE_ON: + pPointer->public.on = TRUE; + AddEnabledDevice(darwinEventReadFD); + return Success; + case DEVICE_CLOSE: + case DEVICE_OFF: + pPointer->public.on = FALSE; + RemoveEnabledDevice(darwinEventReadFD); + return Success; } return Success; #undef NBUTTONS @@ -396,22 +418,23 @@ static int DarwinTabletProc(DeviceIntPtr pPointer, int what) { * DarwinKeybdProc * Callback from X */ -static int DarwinKeybdProc( DeviceIntPtr pDev, int onoff ) +static int +DarwinKeybdProc(DeviceIntPtr pDev, int onoff) { - switch ( onoff ) { - case DEVICE_INIT: - DarwinKeyboardInit( pDev ); - break; - case DEVICE_ON: - pDev->public.on = TRUE; - AddEnabledDevice( darwinEventReadFD ); - break; - case DEVICE_OFF: - pDev->public.on = FALSE; - RemoveEnabledDevice( darwinEventReadFD ); - break; - case DEVICE_CLOSE: - break; + switch (onoff) { + case DEVICE_INIT: + DarwinKeyboardInit(pDev); + break; + case DEVICE_ON: + pDev->public.on = TRUE; + AddEnabledDevice(darwinEventReadFD); + break; + case DEVICE_OFF: + pDev->public.on = FALSE; + RemoveEnabledDevice(darwinEventReadFD); + break; + case DEVICE_CLOSE: + break; } return Success; @@ -429,7 +452,8 @@ static int DarwinKeybdProc( DeviceIntPtr pDev, int onoff ) * DarwinParseModifierList * Parse a list of modifier names and return a corresponding modifier mask */ -int DarwinParseModifierList(const char *constmodifiers, int separatelr) +int +DarwinParseModifierList(const char *constmodifiers, int separatelr) { int result = 0; @@ -440,9 +464,9 @@ int DarwinParseModifierList(const char *constmodifiers, int separatelr) char *p = modifiers; while (p) { - modifier = strsep(&p, " ,+&|/"); // allow lots of separators + modifier = strsep(&p, " ,+&|/"); // allow lots of separators nxkey = DarwinModifierStringToNXMask(modifier, separatelr); - if(nxkey) + if (nxkey) result |= nxkey; else ErrorF("fakebuttons: Unknown modifier \"%s\"\n", modifier); @@ -464,10 +488,12 @@ int DarwinParseModifierList(const char *constmodifiers, int separatelr) * InitInput * Register the keyboard and mouse devices */ -void InitInput( int argc, char **argv ) +void +InitInput(int argc, char **argv) { - XkbRMLVOSet rmlvo = { .rules = "base", .model = "empty", .layout = "empty", - .variant = NULL, .options = NULL }; + XkbRMLVOSet rmlvo = {.rules = "base",.model = "empty",.layout = "empty", + .variant = NULL,.options = NULL + }; /* We need to really have rules... or something... */ XkbSetRulesDflts(&rmlvo); @@ -475,18 +501,18 @@ void InitInput( int argc, char **argv ) darwinKeyboard->name = strdup("keyboard"); /* here's the snippet from the current gdk sources: - if (!strcmp (tmp_name, "pointer")) - gdkdev->info.source = GDK_SOURCE_MOUSE; - else if (!strcmp (tmp_name, "wacom") || - !strcmp (tmp_name, "pen")) - gdkdev->info.source = GDK_SOURCE_PEN; - else if (!strcmp (tmp_name, "eraser")) - gdkdev->info.source = GDK_SOURCE_ERASER; - else if (!strcmp (tmp_name, "cursor")) - gdkdev->info.source = GDK_SOURCE_CURSOR; - else - gdkdev->info.source = GDK_SOURCE_PEN; - */ + if (!strcmp (tmp_name, "pointer")) + gdkdev->info.source = GDK_SOURCE_MOUSE; + else if (!strcmp (tmp_name, "wacom") || + !strcmp (tmp_name, "pen")) + gdkdev->info.source = GDK_SOURCE_PEN; + else if (!strcmp (tmp_name, "eraser")) + gdkdev->info.source = GDK_SOURCE_ERASER; + else if (!strcmp (tmp_name, "cursor")) + gdkdev->info.source = GDK_SOURCE_CURSOR; + else + gdkdev->info.source = GDK_SOURCE_PEN; + */ darwinPointer = AddInputDevice(serverClient, DarwinMouseProc, TRUE); darwinPointer->name = strdup("pointer"); @@ -505,7 +531,8 @@ void InitInput( int argc, char **argv ) QuartzInitInput(argc, argv); } -void CloseInput(void) +void +CloseInput(void) { DarwinEQFini(); } @@ -525,18 +552,18 @@ void CloseInput(void) * easier target to hit. */ void -DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo) +DarwinAdjustScreenOrigins(ScreenInfo * pScreenInfo) { int i, left, top; left = pScreenInfo->screens[0]->x; - top = pScreenInfo->screens[0]->y; + top = pScreenInfo->screens[0]->y; /* Find leftmost screen. If there's a tie, take the topmost of the two. */ for (i = 1; i < pScreenInfo->numScreens; i++) { - if (pScreenInfo->screens[i]->x < left || - (pScreenInfo->screens[i]->x == left && pScreenInfo->screens[i]->y < top)) - { + if (pScreenInfo->screens[i]->x < left || + (pScreenInfo->screens[i]->x == left && + pScreenInfo->screens[i]->y < top)) { left = pScreenInfo->screens[i]->x; top = pScreenInfo->screens[i]->y; } @@ -544,7 +571,7 @@ DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo) darwinMainScreenX = left; darwinMainScreenY = top; - + DEBUG_LOG("top = %d, left=%d\n", top, left); /* Shift all screens so that there is a screen whose top left @@ -557,12 +584,12 @@ DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo) pScreenInfo->screens[i]->x -= darwinMainScreenX; pScreenInfo->screens[i]->y -= darwinMainScreenY; DEBUG_LOG("Screen %d placed at X11 coordinate (%d,%d).\n", - i, pScreenInfo->screens[i]->x, pScreenInfo->screens[i]->y); + i, pScreenInfo->screens[i]->x, + pScreenInfo->screens[i]->y); } } } - /* * InitOutput * Initialize screenInfo for all actually accessible framebuffers. @@ -576,7 +603,8 @@ DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo) * After other screen setup has been done, a mode specific * SetupScreen function can be called to finalize screen setup. */ -void InitOutput( ScreenInfo *pScreenInfo, int argc, char **argv ) +void +InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv) { int i; @@ -601,56 +629,62 @@ void InitOutput( ScreenInfo *pScreenInfo, int argc, char **argv ) DarwinAdjustScreenOrigins(pScreenInfo); } - /* * OsVendorFatalError */ -void OsVendorFatalError( void ) +void +OsVendorFatalError(void) { - ErrorF( " OsVendorFatalError\n" ); + ErrorF(" OsVendorFatalError\n"); } - /* * OsVendorInit * Initialization of Darwin OS support. */ -void OsVendorInit(void) +void +OsVendorInit(void) { if (serverGeneration == 1) { char *lf; char *home = getenv("HOME"); + assert(home); - assert(0 < asprintf(&lf, "%s/Library/Logs/%s.X11.log", home, bundle_id_prefix)); + assert(0 < + asprintf(&lf, "%s/Library/Logs/%s.X11.log", home, + bundle_id_prefix)); LogInit(lf, ".old"); free(lf); DarwinPrintBanner(); #ifdef ENABLE_DEBUG_LOG - { - char *home_dir=NULL, *log_file_path=NULL; - home_dir = getenv("HOME"); - if (home_dir) asprintf(&log_file_path, "%s/%s", home_dir, DEBUG_LOG_NAME); - if (log_file_path) { - if (!access(log_file_path, F_OK)) { - debug_log_fp = fopen(log_file_path, "a"); - if (debug_log_fp) ErrorF("Debug logging enabled to %s\n", log_file_path); - } - free(log_file_path); - } - } + { + char *home_dir = NULL, *log_file_path = NULL; + + home_dir = getenv("HOME"); + if (home_dir) + asprintf(&log_file_path, "%s/%s", home_dir, DEBUG_LOG_NAME); + if (log_file_path) { + if (!access(log_file_path, F_OK)) { + debug_log_fp = fopen(log_file_path, "a"); + if (debug_log_fp) + ErrorF("Debug logging enabled to %s\n", log_file_path); + } + free(log_file_path); + } + } #endif } } - /* * ddxProcessArgument * Process device-dependent command line args. Returns 0 if argument is * not device dependent, otherwise Count of number of elements of argv * that are part of a device dependent commandline option. */ -int ddxProcessArgument( int argc, char *argv[], int i ) +int +ddxProcessArgument(int argc, char *argv[], int i) { // if ( !strcmp( argv[i], "-fullscreen" ) ) { // ErrorF( "Running full screen in parallel with Mac OS X Quartz window server.\n" ); @@ -663,75 +697,74 @@ int ddxProcessArgument( int argc, char *argv[], int i ) // } // This command line arg is passed when launched from the Aqua GUI. - if ( !strncmp( argv[i], "-psn_", 5 ) ) { + if (!strncmp(argv[i], "-psn_", 5)) { return 1; } - if ( !strcmp( argv[i], "-fakebuttons" ) ) { + if (!strcmp(argv[i], "-fakebuttons")) { darwinFakeButtons = TRUE; - ErrorF( "Faking a three button mouse\n" ); + ErrorF("Faking a three button mouse\n"); return 1; } - if ( !strcmp( argv[i], "-nofakebuttons" ) ) { + if (!strcmp(argv[i], "-nofakebuttons")) { darwinFakeButtons = FALSE; - ErrorF( "Not faking a three button mouse\n" ); + ErrorF("Not faking a three button mouse\n"); return 1; } - if (!strcmp( argv[i], "-fakemouse2" ) ) { - if ( i == argc-1 ) { - FatalError( "-fakemouse2 must be followed by a modifer list\n" ); + if (!strcmp(argv[i], "-fakemouse2")) { + if (i == argc - 1) { + FatalError("-fakemouse2 must be followed by a modifer list\n"); } - if (!strcasecmp(argv[i+1], "none") || !strcmp(argv[i+1], "")) + if (!strcasecmp(argv[i + 1], "none") || !strcmp(argv[i + 1], "")) darwinFakeMouse2Mask = 0; else - darwinFakeMouse2Mask = DarwinParseModifierList(argv[i+1], 1); + darwinFakeMouse2Mask = DarwinParseModifierList(argv[i + 1], 1); ErrorF("Modifier mask to fake mouse button 2 = 0x%x\n", darwinFakeMouse2Mask); return 2; } - if (!strcmp( argv[i], "-fakemouse3" ) ) { - if ( i == argc-1 ) { - FatalError( "-fakemouse3 must be followed by a modifer list\n" ); + if (!strcmp(argv[i], "-fakemouse3")) { + if (i == argc - 1) { + FatalError("-fakemouse3 must be followed by a modifer list\n"); } - if (!strcasecmp(argv[i+1], "none") || !strcmp(argv[i+1], "")) + if (!strcasecmp(argv[i + 1], "none") || !strcmp(argv[i + 1], "")) darwinFakeMouse3Mask = 0; else - darwinFakeMouse3Mask = DarwinParseModifierList(argv[i+1], 1); + darwinFakeMouse3Mask = DarwinParseModifierList(argv[i + 1], 1); ErrorF("Modifier mask to fake mouse button 3 = 0x%x\n", darwinFakeMouse3Mask); return 2; } - if ( !strcmp( argv[i], "+synckeymap" ) ) { + if (!strcmp(argv[i], "+synckeymap")) { darwinSyncKeymap = TRUE; return 1; } - if ( !strcmp( argv[i], "-synckeymap" ) ) { + if (!strcmp(argv[i], "-synckeymap")) { darwinSyncKeymap = FALSE; return 1; } - if ( !strcmp( argv[i], "-depth" ) ) { - if ( i == argc-1 ) { - FatalError( "-depth must be followed by a number\n" ); + if (!strcmp(argv[i], "-depth")) { + if (i == argc - 1) { + FatalError("-depth must be followed by a number\n"); } - darwinDesiredDepth = atoi( argv[i+1] ); - if(darwinDesiredDepth != -1 && - darwinDesiredDepth != 8 && - darwinDesiredDepth != 15 && - darwinDesiredDepth != 24) { - FatalError( "Unsupported pixel depth. Use 8, 15, or 24 bits\n" ); + darwinDesiredDepth = atoi(argv[i + 1]); + if (darwinDesiredDepth != -1 && + darwinDesiredDepth != 8 && + darwinDesiredDepth != 15 && darwinDesiredDepth != 24) { + FatalError("Unsupported pixel depth. Use 8, 15, or 24 bits\n"); } - ErrorF( "Attempting to use pixel depth of %i\n", darwinDesiredDepth ); + ErrorF("Attempting to use pixel depth of %i\n", darwinDesiredDepth); return 2; } - if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) { + if (!strcmp(argv[i], "-showconfig") || !strcmp(argv[i], "-version")) { DarwinPrintBanner(); exit(0); } @@ -739,48 +772,51 @@ int ddxProcessArgument( int argc, char *argv[], int i ) return 0; } - /* * ddxUseMsg -- * Print out correct use of device dependent commandline options. * Maybe the user now knows what really to do ... */ -void ddxUseMsg( void ) +void +ddxUseMsg(void) { ErrorF("\n"); ErrorF("\n"); ErrorF("Device Dependent Usage:\n"); ErrorF("\n"); ErrorF("-depth <8,15,24> : use this bit depth.\n"); - ErrorF("-fakebuttons : fake a three button mouse with Command and Option keys.\n"); + ErrorF + ("-fakebuttons : fake a three button mouse with Command and Option keys.\n"); ErrorF("-nofakebuttons : don't fake a three button mouse.\n"); - ErrorF("-fakemouse2 <modifiers> : fake middle mouse button with modifier keys.\n"); - ErrorF("-fakemouse3 <modifiers> : fake right mouse button with modifier keys.\n"); - ErrorF(" ex: -fakemouse2 \"option,shift\" = option-shift-click is middle button.\n"); + ErrorF + ("-fakemouse2 <modifiers> : fake middle mouse button with modifier keys.\n"); + ErrorF + ("-fakemouse3 <modifiers> : fake right mouse button with modifier keys.\n"); + ErrorF + (" ex: -fakemouse2 \"option,shift\" = option-shift-click is middle button.\n"); ErrorF("-version : show the server version.\n"); ErrorF("\n"); } - /* * ddxGiveUp -- * Device dependent cleanup. Called by dix before normal server death. */ -void ddxGiveUp( enum ExitCode error ) +void +ddxGiveUp(enum ExitCode error) { LogClose(error); } - /* * AbortDDX -- * DDX - specific abort routine. Called by AbortServer(). The attempt is * made to restore all original setting of the displays. Also all devices * are closed. */ -_X_NORETURN -void AbortDDX( enum ExitCode error ) { - ErrorF( " AbortDDX\n" ); +_X_NORETURN void +AbortDDX(enum ExitCode error) +{ + ErrorF(" AbortDDX\n"); OsAbort(); } - diff --git a/xorg-server/hw/xquartz/darwin.h b/xorg-server/hw/xquartz/darwin.h index aafc12fbf..b1157ce97 100644 --- a/xorg-server/hw/xquartz/darwin.h +++ b/xorg-server/hw/xquartz/darwin.h @@ -39,7 +39,7 @@ // From darwin.c void DarwinPrintBanner(void); int DarwinParseModifierList(const char *constmodifiers, int separatelr); -void DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo); +void DarwinAdjustScreenOrigins(ScreenInfo * pScreenInfo); #define SCREEN_PRIV(pScreen) ((DarwinFramebufferPtr) \ dixLookupPrivate(&pScreen->devPrivates, darwinScreenKey)) @@ -48,39 +48,42 @@ void DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo); * Global variables from darwin.c */ extern DevPrivateKeyRec darwinScreenKeyRec; + #define darwinScreenKey (&darwinScreenKeyRec) -extern int darwinScreensFound; -extern io_connect_t darwinParamConnect; -extern int darwinEventReadFD; -extern int darwinEventWriteFD; -extern DeviceIntPtr darwinPointer; -extern DeviceIntPtr darwinTabletCursor; -extern DeviceIntPtr darwinTabletStylus; -extern DeviceIntPtr darwinTabletEraser; -extern DeviceIntPtr darwinKeyboard; +extern int darwinScreensFound; +extern io_connect_t darwinParamConnect; +extern int darwinEventReadFD; +extern int darwinEventWriteFD; +extern DeviceIntPtr darwinPointer; +extern DeviceIntPtr darwinTabletCursor; +extern DeviceIntPtr darwinTabletStylus; +extern DeviceIntPtr darwinTabletEraser; +extern DeviceIntPtr darwinKeyboard; // User preferences -extern int darwinMouseAccelChange; -extern int darwinFakeButtons; -extern int darwinFakeMouse2Mask; -extern int darwinFakeMouse3Mask; -extern unsigned int darwinAppKitModMask; -extern unsigned int windowItemModMask; -extern int darwinSyncKeymap; -extern int darwinDesiredDepth; +extern int darwinMouseAccelChange; +extern int darwinFakeButtons; +extern int darwinFakeMouse2Mask; +extern int darwinFakeMouse3Mask; +extern unsigned int darwinAppKitModMask; +extern unsigned int windowItemModMask; +extern int darwinSyncKeymap; +extern int darwinDesiredDepth; // location of X11's (0,0) point in global screen coordinates -extern int darwinMainScreenX; -extern int darwinMainScreenY; +extern int darwinMainScreenX; +extern int darwinMainScreenY; // bundle-main.c extern char *bundle_id_prefix; -_X_ATTRIBUTE_PRINTF(6,7) -extern void xq_asl_log (int level, const char *subsystem, const char *file, const char *function, int line, const char *fmt, ...); +_X_ATTRIBUTE_PRINTF(6, 7) +extern void +xq_asl_log(int level, const char *subsystem, const char *file, + const char *function, int line, const char *fmt, ...); #define ASL_LOG(level, subsystem, msg, args...) xq_asl_log(level, subsystem, __FILE__, __FUNCTION__, __LINE__, msg, ##args) #define DEBUG_LOG(msg, args...) ASL_LOG(ASL_LEVEL_DEBUG, "XQuartz", msg, ##args) #define TRACE() DEBUG_LOG("TRACE") -#endif /* _DARWIN_H */ +#endif /* _DARWIN_H */ diff --git a/xorg-server/hw/xquartz/darwinEvents.c b/xorg-server/hw/xquartz/darwinEvents.c index 3438da116..cf29a7b21 100644 --- a/xorg-server/hw/xquartz/darwinEvents.c +++ b/xorg-server/hw/xquartz/darwinEvents.c @@ -75,9 +75,10 @@ in this Software without prior written authorization from The Open Group. #include "applewmExt.h" /* FIXME: Abstract this better */ -extern Bool QuartzModeEventHandler(int screenNum, XQuartzEvent *e, DeviceIntPtr dev); +extern Bool QuartzModeEventHandler(int screenNum, XQuartzEvent * e, + DeviceIntPtr dev); -int darwin_all_modifier_flags = 0; // last known modifier state +int darwin_all_modifier_flags = 0; // last known modifier state int darwin_all_modifier_mask = 0; int darwin_x11_modifier_mask = 0; @@ -88,42 +89,50 @@ static pthread_mutex_t fd_add_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t fd_add_ready_cond = PTHREAD_COND_INITIALIZER; static pthread_t fd_add_tid = NULL; -static InternalEvent* darwinEvents = NULL; +static InternalEvent *darwinEvents = NULL; static pthread_mutex_t mieq_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t mieq_ready_cond = PTHREAD_COND_INITIALIZER; /*** Pthread Magics ***/ -static pthread_t create_thread(void *(*func)(void *), void *arg) { +static pthread_t +create_thread(void *(*func) (void *), void *arg) +{ pthread_attr_t attr; pthread_t tid; - pthread_attr_init (&attr); - pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM); - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&tid, &attr, func, arg); - pthread_attr_destroy (&attr); + pthread_attr_init(&attr); + pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&tid, &attr, func, arg); + pthread_attr_destroy(&attr); return tid; } void darwinEvents_lock(void); -void darwinEvents_lock(void) { +void +darwinEvents_lock(void) +{ int err; - if((err = pthread_mutex_lock(&mieq_lock))) { + + if ((err = pthread_mutex_lock(&mieq_lock))) { ErrorF("%s:%s:%d: Failed to lock mieq_lock: %d\n", __FILE__, __FUNCTION__, __LINE__, err); xorg_backtrace(); } - if(darwinEvents == NULL) { + if (darwinEvents == NULL) { pthread_cond_wait(&mieq_ready_cond, &mieq_lock); } } void darwinEvents_unlock(void); -void darwinEvents_unlock(void) { +void +darwinEvents_unlock(void) +{ int err; - if((err = pthread_mutex_unlock(&mieq_lock))) { + + if ((err = pthread_mutex_unlock(&mieq_lock))) { ErrorF("%s:%s:%d: Failed to unlock mieq_lock: %d\n", __FILE__, __FUNCTION__, __LINE__, err); xorg_backtrace(); @@ -134,7 +143,9 @@ void darwinEvents_unlock(void) { * DarwinPressModifierKey * Press or release the given modifier key (one of NX_MODIFIERKEY_* constants) */ -static void DarwinPressModifierKey(int pressed, int key) { +static void +DarwinPressModifierKey(int pressed, int key) +{ int keycode = DarwinModifierNXKeyToNXKeycode(key, 0); if (keycode == 0) { @@ -165,9 +176,9 @@ static int darwin_x11_modifier_mask_list[] = { static int darwin_all_modifier_mask_additions[] = { NX_SECONDARYFNMASK, }; -static void DarwinUpdateModifiers( - int pressed, // KeyPress or KeyRelease - int flags ) // modifier flags that have changed +static void +DarwinUpdateModifiers(int pressed, // KeyPress or KeyRelease + int flags) // modifier flags that have changed { int *f; int key; @@ -175,15 +186,15 @@ static void DarwinUpdateModifiers( /* Capslock is special. This mask is the state of capslock (on/off), * not the state of the button. Hopefully we can find a better solution. */ - if(NX_ALPHASHIFTMASK & flags) { + if (NX_ALPHASHIFTMASK & flags) { DarwinPressModifierKey(KeyPress, NX_MODIFIERKEY_ALPHALOCK); DarwinPressModifierKey(KeyRelease, NX_MODIFIERKEY_ALPHALOCK); } - - for(f=darwin_x11_modifier_mask_list; *f; f++) - if(*f & flags && *f != NX_ALPHASHIFTMASK) { + + for (f = darwin_x11_modifier_mask_list; *f; f++) + if (*f & flags && *f != NX_ALPHASHIFTMASK) { key = DarwinModifierNXMaskToNXKey(*f); - if(key == -1) + if (key == -1) ErrorF("DarwinUpdateModifiers: Unsupported NXMask: 0x%x\n", *f); else DarwinPressModifierKey(pressed, key); @@ -194,107 +205,107 @@ static void DarwinUpdateModifiers( be moved into their own individual functions and set as handlers using mieqSetHandler. */ -static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr dev) { +static void +DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr dev) +{ XQuartzEvent *e = &(ie->xquartz_event); - switch(e->subtype) { - case kXquartzControllerNotify: - DEBUG_LOG("kXquartzControllerNotify\n"); - AppleWMSendEvent(AppleWMControllerNotify, - AppleWMControllerNotifyMask, - e->data[0], - e->data[1]); - break; - - case kXquartzPasteboardNotify: - DEBUG_LOG("kXquartzPasteboardNotify\n"); - AppleWMSendEvent(AppleWMPasteboardNotify, - AppleWMPasteboardNotifyMask, - e->data[0], - e->data[1]); - break; - - case kXquartzActivate: - DEBUG_LOG("kXquartzActivate\n"); - QuartzShow(); - AppleWMSendEvent(AppleWMActivationNotify, - AppleWMActivationNotifyMask, - AppleWMIsActive, 0); - break; - - case kXquartzDeactivate: - DEBUG_LOG("kXquartzDeactivate\n"); - AppleWMSendEvent(AppleWMActivationNotify, - AppleWMActivationNotifyMask, - AppleWMIsInactive, 0); - QuartzHide(); - break; - - case kXquartzReloadPreferences: - DEBUG_LOG("kXquartzReloadPreferences\n"); - AppleWMSendEvent(AppleWMActivationNotify, - AppleWMActivationNotifyMask, - AppleWMReloadPreferences, 0); - break; - - case kXquartzToggleFullscreen: - DEBUG_LOG("kXquartzToggleFullscreen\n"); - if(XQuartzIsRootless) - ErrorF("Ignoring kXquartzToggleFullscreen because of rootless mode."); - else - QuartzRandRToggleFullscreen(); - break; - - case kXquartzSetRootless: - DEBUG_LOG("kXquartzSetRootless\n"); - if(e->data[0]) { - QuartzRandRSetFakeRootless(); - } else { - QuartzRandRSetFakeFullscreen(FALSE); - } - break; - - case kXquartzSetRootClip: - QuartzSetRootClip((Bool)e->data[0]); - break; - - case kXquartzQuit: - GiveUp(0); - break; - - case kXquartzSpaceChanged: - DEBUG_LOG("kXquartzSpaceChanged\n"); - QuartzSpaceChanged(e->data[0]); - break; - - case kXquartzListenOnOpenFD: - ErrorF("Calling ListenOnOpenFD() for new fd: %d\n", (int)e->data[0]); - ListenOnOpenFD((int)e->data[0], 1); - break; - - case kXquartzReloadKeymap: - DarwinKeyboardReloadHandler(); - break; - - case kXquartzDisplayChanged: - DEBUG_LOG("kXquartzDisplayChanged\n"); - QuartzUpdateScreens(); - - /* Update our RandR info */ - QuartzRandRUpdateFakeModes(TRUE); - break; - - default: - if(!QuartzModeEventHandler(screenNum, e, dev)) - ErrorF("Unknown application defined event type %d.\n", e->subtype); - } + switch (e->subtype) { + case kXquartzControllerNotify: + DEBUG_LOG("kXquartzControllerNotify\n"); + AppleWMSendEvent(AppleWMControllerNotify, + AppleWMControllerNotifyMask, e->data[0], e->data[1]); + break; + + case kXquartzPasteboardNotify: + DEBUG_LOG("kXquartzPasteboardNotify\n"); + AppleWMSendEvent(AppleWMPasteboardNotify, + AppleWMPasteboardNotifyMask, e->data[0], e->data[1]); + break; + + case kXquartzActivate: + DEBUG_LOG("kXquartzActivate\n"); + QuartzShow(); + AppleWMSendEvent(AppleWMActivationNotify, + AppleWMActivationNotifyMask, AppleWMIsActive, 0); + break; + + case kXquartzDeactivate: + DEBUG_LOG("kXquartzDeactivate\n"); + AppleWMSendEvent(AppleWMActivationNotify, + AppleWMActivationNotifyMask, AppleWMIsInactive, 0); + QuartzHide(); + break; + + case kXquartzReloadPreferences: + DEBUG_LOG("kXquartzReloadPreferences\n"); + AppleWMSendEvent(AppleWMActivationNotify, + AppleWMActivationNotifyMask, + AppleWMReloadPreferences, 0); + break; + + case kXquartzToggleFullscreen: + DEBUG_LOG("kXquartzToggleFullscreen\n"); + if (XQuartzIsRootless) + ErrorF + ("Ignoring kXquartzToggleFullscreen because of rootless mode."); + else + QuartzRandRToggleFullscreen(); + break; + + case kXquartzSetRootless: + DEBUG_LOG("kXquartzSetRootless\n"); + if (e->data[0]) { + QuartzRandRSetFakeRootless(); + } + else { + QuartzRandRSetFakeFullscreen(FALSE); + } + break; + + case kXquartzSetRootClip: + QuartzSetRootClip((Bool) e->data[0]); + break; + + case kXquartzQuit: + GiveUp(0); + break; + + case kXquartzSpaceChanged: + DEBUG_LOG("kXquartzSpaceChanged\n"); + QuartzSpaceChanged(e->data[0]); + break; + + case kXquartzListenOnOpenFD: + ErrorF("Calling ListenOnOpenFD() for new fd: %d\n", (int) e->data[0]); + ListenOnOpenFD((int) e->data[0], 1); + break; + + case kXquartzReloadKeymap: + DarwinKeyboardReloadHandler(); + break; + + case kXquartzDisplayChanged: + DEBUG_LOG("kXquartzDisplayChanged\n"); + QuartzUpdateScreens(); + + /* Update our RandR info */ + QuartzRandRUpdateFakeModes(TRUE); + break; + + default: + if (!QuartzModeEventHandler(screenNum, e, dev)) + ErrorF("Unknown application defined event type %d.\n", e->subtype); + } } -void DarwinListenOnOpenFD(int fd) { +void +DarwinListenOnOpenFD(int fd) +{ ErrorF("DarwinListenOnOpenFD: %d\n", fd); - + pthread_mutex_lock(&fd_add_lock); - if(fd_add_count < FD_ADD_MAX) + if (fd_add_count < FD_ADD_MAX) fd_add[fd_add_count++] = fd; else ErrorF("FD Addition buffer at max. Dropping fd addition request.\n"); @@ -303,7 +314,9 @@ void DarwinListenOnOpenFD(int fd) { pthread_mutex_unlock(&fd_add_lock); } -static void *DarwinProcessFDAdditionQueue_thread(void *args) { +static void * +DarwinProcessFDAdditionQueue_thread(void *args) +{ /* TODO: Possibly adjust this to no longer be a race... maybe trigger this * once a client connects and claims to be the WM. * @@ -320,15 +333,17 @@ static void *DarwinProcessFDAdditionQueue_thread(void *args) { sleep_for.tv_sec = 3; sleep_for.tv_nsec = 0; - ErrorF("X11.app: DarwinProcessFDAdditionQueue_thread: Sleeping to allow xinitrc to catchup.\n"); - while(nanosleep(&sleep_for, &sleep_remaining) != 0) { + ErrorF + ("X11.app: DarwinProcessFDAdditionQueue_thread: Sleeping to allow xinitrc to catchup.\n"); + while (nanosleep(&sleep_for, &sleep_remaining) != 0) { sleep_for = sleep_remaining; } pthread_mutex_lock(&fd_add_lock); - while(true) { - while(fd_add_count) { - DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1, fd_add[--fd_add_count]); + while (true) { + while (fd_add_count) { + DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1, + fd_add[--fd_add_count]); } pthread_cond_wait(&fd_add_ready_cond, &fd_add_lock); } @@ -336,17 +351,21 @@ static void *DarwinProcessFDAdditionQueue_thread(void *args) { return NULL; } -Bool DarwinEQInit(void) { +Bool +DarwinEQInit(void) +{ int *p; - for(p=darwin_x11_modifier_mask_list, darwin_all_modifier_mask=0; *p; p++) { + for (p = darwin_x11_modifier_mask_list, darwin_all_modifier_mask = 0; *p; + p++) { darwin_x11_modifier_mask |= *p; } - - for(p=darwin_all_modifier_mask_additions, darwin_all_modifier_mask= darwin_x11_modifier_mask; *p; p++) { + + for (p = darwin_all_modifier_mask_additions, darwin_all_modifier_mask = + darwin_x11_modifier_mask; *p; p++) { darwin_all_modifier_mask |= *p; } - + mieqInit(); mieqSetHandler(ET_XQuartz, DarwinEventHandler); @@ -356,22 +375,24 @@ Bool DarwinEQInit(void) { */ if (!darwinEvents) { darwinEvents = InitEventList(GetMaximumEventsNum());; - + if (!darwinEvents) FatalError("Couldn't allocate event buffer\n"); - + darwinEvents_lock(); pthread_cond_broadcast(&mieq_ready_cond); darwinEvents_unlock(); } - if(!fd_add_tid) + if (!fd_add_tid) fd_add_tid = create_thread(DarwinProcessFDAdditionQueue_thread, NULL); - + return TRUE; } -void DarwinEQFini(void) { +void +DarwinEQFini(void) +{ mieqFini(); } @@ -379,53 +400,65 @@ void DarwinEQFini(void) { * ProcessInputEvents * Read and process events from the event queue until it is empty. */ -void ProcessInputEvents(void) { +void +ProcessInputEvents(void) +{ char nullbyte; - int x = sizeof(nullbyte); - + int x = sizeof(nullbyte); + mieqProcessInputEvents(); // Empty the signaling pipe while (x == sizeof(nullbyte)) { - x = read(darwinEventReadFD, &nullbyte, sizeof(nullbyte)); + x = read(darwinEventReadFD, &nullbyte, sizeof(nullbyte)); } } /* Sends a null byte down darwinEventWriteFD, which will cause the Dispatch() event loop to check out event queue */ -static void DarwinPokeEQ(void) { - char nullbyte=0; - // <daniels> oh, i ... er ... christ. - write(darwinEventWriteFD, &nullbyte, sizeof(nullbyte)); +static void +DarwinPokeEQ(void) +{ + char nullbyte = 0; + + // <daniels> oh, i ... er ... christ. + write(darwinEventWriteFD, &nullbyte, sizeof(nullbyte)); } /* Convert from Appkit pointer input values to X input values: * Note: pointer_x and pointer_y are relative to the upper-left of primary * display. */ -static void DarwinPrepareValuators(DeviceIntPtr pDev, int *valuators, ScreenPtr screen, - float pointer_x, float pointer_y, - float pressure, float tilt_x, float tilt_y) { +static void +DarwinPrepareValuators(DeviceIntPtr pDev, int *valuators, ScreenPtr screen, + float pointer_x, float pointer_y, + float pressure, float tilt_x, float tilt_y) +{ /* Fix offset between darwin and X screens */ pointer_x -= darwinMainScreenX + screen->x; pointer_y -= darwinMainScreenY + screen->y; - if(pointer_x < 0.0) + if (pointer_x < 0.0) pointer_x = 0.0; - if(pointer_y < 0.0) + if (pointer_y < 0.0) pointer_y = 0.0; - - if(pDev == darwinPointer) { + + if (pDev == darwinPointer) { valuators[0] = pointer_x; valuators[1] = pointer_y; valuators[2] = 0; valuators[3] = 0; valuators[4] = 0; - } else { + } + else { /* Setup our array of values */ - valuators[0] = XQUARTZ_VALUATOR_LIMIT * (pointer_x / (float)screenInfo.screens[0]->width); - valuators[1] = XQUARTZ_VALUATOR_LIMIT * (pointer_y / (float)screenInfo.screens[0]->height); + valuators[0] = + XQUARTZ_VALUATOR_LIMIT * (pointer_x / + (float) screenInfo.screens[0]->width); + valuators[1] = + XQUARTZ_VALUATOR_LIMIT * (pointer_y / + (float) screenInfo.screens[0]->height); valuators[2] = XQUARTZ_VALUATOR_LIMIT * pressure; valuators[3] = XQUARTZ_VALUATOR_LIMIT * tilt_x; valuators[4] = XQUARTZ_VALUATOR_LIMIT * tilt_y; @@ -434,13 +467,17 @@ static void DarwinPrepareValuators(DeviceIntPtr pDev, int *valuators, ScreenPtr // valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]); } -void DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev) { +void +DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev) +{ darwinEvents_lock(); { int i; + if (pDev->button) { for (i = 0; i < pDev->button->numButtons; i++) { if (BitIsOn(pDev->button->down, i)) { - QueuePointerEvents(pDev, ButtonRelease, i, POINTER_ABSOLUTE, NULL); + QueuePointerEvents(pDev, ButtonRelease, i, POINTER_ABSOLUTE, + NULL); } } } @@ -448,157 +485,207 @@ void DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev) { if (pDev->key) { for (i = 0; i < NUM_KEYCODES; i++) { if (BitIsOn(pDev->key->down, i + MIN_KEYCODE)) { - QueueKeyboardEvents(pDev, KeyRelease, i + MIN_KEYCODE, NULL); + QueueKeyboardEvents(pDev, KeyRelease, i + MIN_KEYCODE, + NULL); } } } DarwinPokeEQ(); - } darwinEvents_unlock(); + } + darwinEvents_unlock(); } -void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, float pointer_x, float pointer_y, - float pressure, float tilt_x, float tilt_y) { - static int darwinFakeMouseButtonDown = 0; +void +DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, + float pointer_x, float pointer_y, float pressure, + float tilt_x, float tilt_y) +{ + static int darwinFakeMouseButtonDown = 0; ScreenPtr screen; int valuators[5]; - + //DEBUG_LOG("x=%f, y=%f, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y); - - if(!darwinEvents) { - DEBUG_LOG("DarwinSendPointerEvents called before darwinEvents was initialized\n"); - return; - } + + if (!darwinEvents) { + DEBUG_LOG + ("DarwinSendPointerEvents called before darwinEvents was initialized\n"); + return; + } screen = miPointerGetScreen(pDev); - if(!screen) { - DEBUG_LOG("DarwinSendPointerEvents called before screen was initialized\n"); + if (!screen) { + DEBUG_LOG + ("DarwinSendPointerEvents called before screen was initialized\n"); return; } /* Handle fake click */ - if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) { - if(darwinFakeMouseButtonDown != 0) { + if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) { + if (darwinFakeMouseButtonDown != 0) { /* We're currently "down" with another button, so release it first */ - DarwinSendPointerEvents(pDev, ButtonRelease, darwinFakeMouseButtonDown, pointer_x, pointer_y, pressure, tilt_x, tilt_y); - darwinFakeMouseButtonDown=0; + DarwinSendPointerEvents(pDev, ButtonRelease, + darwinFakeMouseButtonDown, pointer_x, + pointer_y, pressure, tilt_x, tilt_y); + darwinFakeMouseButtonDown = 0; } - if (darwin_all_modifier_flags & darwinFakeMouse2Mask) { + if (darwin_all_modifier_flags & darwinFakeMouse2Mask) { ev_button = 2; - darwinFakeMouseButtonDown = 2; - DarwinUpdateModKeys(darwin_all_modifier_flags & ~darwinFakeMouse2Mask); - } else if (darwin_all_modifier_flags & darwinFakeMouse3Mask) { + darwinFakeMouseButtonDown = 2; + DarwinUpdateModKeys(darwin_all_modifier_flags & + ~darwinFakeMouse2Mask); + } + else if (darwin_all_modifier_flags & darwinFakeMouse3Mask) { ev_button = 3; - darwinFakeMouseButtonDown = 3; - DarwinUpdateModKeys(darwin_all_modifier_flags & ~darwinFakeMouse3Mask); - } - } + darwinFakeMouseButtonDown = 3; + DarwinUpdateModKeys(darwin_all_modifier_flags & + ~darwinFakeMouse3Mask); + } + } - if (ev_type == ButtonRelease && ev_button == 1) { - if(darwinFakeMouseButtonDown) { + if (ev_type == ButtonRelease && ev_button == 1) { + if (darwinFakeMouseButtonDown) { ev_button = darwinFakeMouseButtonDown; } - if(darwinFakeMouseButtonDown == 2) { - DarwinUpdateModKeys(darwin_all_modifier_flags & ~darwinFakeMouse2Mask); - } else if(darwinFakeMouseButtonDown == 3) { - DarwinUpdateModKeys(darwin_all_modifier_flags & ~darwinFakeMouse3Mask); + if (darwinFakeMouseButtonDown == 2) { + DarwinUpdateModKeys(darwin_all_modifier_flags & + ~darwinFakeMouse2Mask); + } + else if (darwinFakeMouseButtonDown == 3) { + DarwinUpdateModKeys(darwin_all_modifier_flags & + ~darwinFakeMouse3Mask); } darwinFakeMouseButtonDown = 0; - } + } - DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, pressure, tilt_x, tilt_y); + DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, + pressure, tilt_x, tilt_y); darwinEvents_lock(); { ValuatorMask mask; - valuator_mask_set_range(&mask, 0, (pDev == darwinPointer) ? 2 : 5, valuators); + + valuator_mask_set_range(&mask, 0, (pDev == darwinPointer) ? 2 : 5, + valuators); QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE, &mask); DarwinPokeEQ(); } darwinEvents_unlock(); } -void DarwinSendKeyboardEvents(int ev_type, int keycode) { +void +DarwinSendKeyboardEvents(int ev_type, int keycode) +{ - if(!darwinEvents) { - DEBUG_LOG("DarwinSendKeyboardEvents called before darwinEvents was initialized\n"); - return; - } + if (!darwinEvents) { + DEBUG_LOG + ("DarwinSendKeyboardEvents called before darwinEvents was initialized\n"); + return; + } darwinEvents_lock(); { - QueueKeyboardEvents(darwinKeyboard, ev_type, keycode + MIN_KEYCODE, NULL); + QueueKeyboardEvents(darwinKeyboard, ev_type, keycode + MIN_KEYCODE, + NULL); DarwinPokeEQ(); - } darwinEvents_unlock(); + } + darwinEvents_unlock(); } -void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, float pointer_y, - float pressure, float tilt_x, float tilt_y) { +void +DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, + float pointer_y, float pressure, float tilt_x, + float tilt_y) +{ ScreenPtr screen; int valuators[5]; - DEBUG_LOG("DarwinSendProximityEvents: %d l:%f,%f p:%f t:%f,%f\n", ev_type, pointer_x, pointer_y, pressure, tilt_x, tilt_y); + DEBUG_LOG("DarwinSendProximityEvents: %d l:%f,%f p:%f t:%f,%f\n", ev_type, + pointer_x, pointer_y, pressure, tilt_x, tilt_y); - if(!darwinEvents) { - DEBUG_LOG("DarwinSendProximityEvents called before darwinEvents was initialized\n"); + if (!darwinEvents) { + DEBUG_LOG + ("DarwinSendProximityEvents called before darwinEvents was initialized\n"); return; } - + screen = miPointerGetScreen(pDev); - if(!screen) { - DEBUG_LOG("DarwinSendPointerEvents called before screen was initialized\n"); + if (!screen) { + DEBUG_LOG + ("DarwinSendPointerEvents called before screen was initialized\n"); return; - } + } - DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, pressure, tilt_x, tilt_y); + DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, + pressure, tilt_x, tilt_y); darwinEvents_lock(); { ValuatorMask mask; + valuator_mask_set_range(&mask, 0, 5, valuators); QueueProximityEvents(pDev, ev_type, &mask); DarwinPokeEQ(); } darwinEvents_unlock(); } - /* Send the appropriate number of button clicks to emulate scroll wheel */ -void DarwinSendScrollEvents(float count_x, float count_y, - float pointer_x, float pointer_y, - float pressure, float tilt_x, float tilt_y) { - int sign_x, sign_y; - if(!darwinEvents) { - DEBUG_LOG("DarwinSendScrollEvents called before darwinEvents was initialized\n"); - return; - } - - sign_x = count_x > 0.0f ? SCROLLWHEELLEFTFAKE : SCROLLWHEELRIGHTFAKE; - sign_y = count_y > 0.0f ? SCROLLWHEELUPFAKE : SCROLLWHEELDOWNFAKE; - count_x = fabs(count_x); - count_y = fabs(count_y); - - while ((count_x > 0.0f) || (count_y > 0.0f)) { - if (count_x > 0.0f) { - DarwinSendPointerEvents(darwinPointer, ButtonPress, sign_x, pointer_x, pointer_y, pressure, tilt_x, tilt_y); - DarwinSendPointerEvents(darwinPointer, ButtonRelease, sign_x, pointer_x, pointer_y, pressure, tilt_x, tilt_y); - count_x = count_x - 1.0f; - } - if (count_y > 0.0f) { - DarwinSendPointerEvents(darwinPointer, ButtonPress, sign_y, pointer_x, pointer_y, pressure, tilt_x, tilt_y); - DarwinSendPointerEvents(darwinPointer, ButtonRelease, sign_y, pointer_x, pointer_y, pressure, tilt_x, tilt_y); - count_y = count_y - 1.0f; - } - } +void +DarwinSendScrollEvents(float count_x, float count_y, + float pointer_x, float pointer_y, + float pressure, float tilt_x, float tilt_y) +{ + int sign_x, sign_y; + + if (!darwinEvents) { + DEBUG_LOG + ("DarwinSendScrollEvents called before darwinEvents was initialized\n"); + return; + } + + sign_x = count_x > 0.0f ? SCROLLWHEELLEFTFAKE : SCROLLWHEELRIGHTFAKE; + sign_y = count_y > 0.0f ? SCROLLWHEELUPFAKE : SCROLLWHEELDOWNFAKE; + count_x = fabs(count_x); + count_y = fabs(count_y); + + while ((count_x > 0.0f) || (count_y > 0.0f)) { + if (count_x > 0.0f) { + DarwinSendPointerEvents(darwinPointer, ButtonPress, sign_x, + pointer_x, pointer_y, pressure, tilt_x, + tilt_y); + DarwinSendPointerEvents(darwinPointer, ButtonRelease, sign_x, + pointer_x, pointer_y, pressure, tilt_x, + tilt_y); + count_x = count_x - 1.0f; + } + if (count_y > 0.0f) { + DarwinSendPointerEvents(darwinPointer, ButtonPress, sign_y, + pointer_x, pointer_y, pressure, tilt_x, + tilt_y); + DarwinSendPointerEvents(darwinPointer, ButtonRelease, sign_y, + pointer_x, pointer_y, pressure, tilt_x, + tilt_y); + count_y = count_y - 1.0f; + } + } } /* Send the appropriate KeyPress/KeyRelease events to GetKeyboardEvents to reflect changing modifier flags (alt, control, meta, etc) */ -void DarwinUpdateModKeys(int flags) { - DarwinUpdateModifiers(KeyRelease, darwin_all_modifier_flags & ~flags & darwin_x11_modifier_mask); - DarwinUpdateModifiers(KeyPress, ~darwin_all_modifier_flags & flags & darwin_x11_modifier_mask); - darwin_all_modifier_flags = flags; +void +DarwinUpdateModKeys(int flags) +{ + DarwinUpdateModifiers(KeyRelease, + darwin_all_modifier_flags & ~flags & + darwin_x11_modifier_mask); + DarwinUpdateModifiers(KeyPress, + ~darwin_all_modifier_flags & flags & + darwin_x11_modifier_mask); + darwin_all_modifier_flags = flags; } /* * DarwinSendDDXEvent * Send the X server thread a message by placing it on the event queue. */ -void DarwinSendDDXEvent(int type, int argc, ...) { +void +DarwinSendDDXEvent(int type, int argc, ...) +{ XQuartzEvent e; int i; va_list args; @@ -611,14 +698,14 @@ void DarwinSendDDXEvent(int type, int argc, ...) { e.subtype = type; if (argc > 0 && argc < XQUARTZ_EVENT_MAXARGS) { - va_start (args, argc); + va_start(args, argc); for (i = 0; i < argc; i++) - e.data[i] = (uint32_t) va_arg (args, uint32_t); - va_end (args); + e.data[i] = (uint32_t) va_arg(args, uint32_t); + va_end(args); } darwinEvents_lock(); { - mieqEnqueue(NULL, (InternalEvent*)&e); + mieqEnqueue(NULL, (InternalEvent *) &e); DarwinPokeEQ(); } darwinEvents_unlock(); } diff --git a/xorg-server/hw/xquartz/darwinEvents.h b/xorg-server/hw/xquartz/darwinEvents.h index a44872b69..515dd3049 100644 --- a/xorg-server/hw/xquartz/darwinEvents.h +++ b/xorg-server/hw/xquartz/darwinEvents.h @@ -37,13 +37,16 @@ void DarwinEQEnqueue(const xEventPtr e); void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e); void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX); void DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev); -void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, float pointer_x, float pointer_y, - float pressure, float tilt_x, float tilt_y); -void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, float pointer_y, - float pressure, float tilt_x, float tilt_y); +void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, + float pointer_x, float pointer_y, float pressure, + float tilt_x, float tilt_y); +void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, + float pointer_y, float pressure, float tilt_x, + float tilt_y); void DarwinSendKeyboardEvents(int ev_type, int keycode); -void DarwinSendScrollEvents(float count_x, float count_y, float pointer_x, float pointer_y, - float pressure, float tilt_x, float tilt_y); +void DarwinSendScrollEvents(float count_x, float count_y, float pointer_x, + float pointer_y, float pressure, float tilt_x, + float tilt_y); void DarwinUpdateModKeys(int flags); void DarwinListenOnOpenFD(int fd); @@ -51,28 +54,28 @@ void DarwinListenOnOpenFD(int fd); * Subtypes for the ET_XQuartz event type */ enum { - kXquartzReloadKeymap, // Reload system keymap - kXquartzActivate, // restore X drawing and cursor - kXquartzDeactivate, // clip X drawing and switch to Aqua cursor - kXquartzSetRootClip, // enable or disable drawing to the X screen - kXquartzQuit, // kill the X server and release the display - kXquartzBringAllToFront, // bring all X windows to front - kXquartzToggleFullscreen, // Enable/Disable fullscreen mode - kXquartzSetRootless, // Set rootless mode - kXquartzSpaceChanged, // Spaces changed - kXquartzListenOnOpenFD, // Listen to the launchd fd (passed as arg) + kXquartzReloadKeymap, // Reload system keymap + kXquartzActivate, // restore X drawing and cursor + kXquartzDeactivate, // clip X drawing and switch to Aqua cursor + kXquartzSetRootClip, // enable or disable drawing to the X screen + kXquartzQuit, // kill the X server and release the display + kXquartzBringAllToFront, // bring all X windows to front + kXquartzToggleFullscreen, // Enable/Disable fullscreen mode + kXquartzSetRootless, // Set rootless mode + kXquartzSpaceChanged, // Spaces changed + kXquartzListenOnOpenFD, // Listen to the launchd fd (passed as arg) /* * AppleWM events */ - kXquartzControllerNotify, // send an AppleWMControllerNotify event - kXquartzPasteboardNotify, // notify the WM to copy or paste - kXquartzReloadPreferences, // send AppleWMReloadPreferences + kXquartzControllerNotify, // send an AppleWMControllerNotify event + kXquartzPasteboardNotify, // notify the WM to copy or paste + kXquartzReloadPreferences, // send AppleWMReloadPreferences /* * Xplugin notification events */ - kXquartzDisplayChanged, // display configuration has changed - kXquartzWindowState, // window visibility state has changed - kXquartzWindowMoved, // window has moved on screen + kXquartzDisplayChanged, // display configuration has changed + kXquartzWindowState, // window visibility state has changed + kXquartzWindowMoved, // window has moved on screen }; /* Send one of the above events to the server thread. */ @@ -89,4 +92,4 @@ extern int darwin_x11_modifier_mask; /* The current state of the above listed modifiers */ extern int darwin_all_modifier_flags; -#endif /* _DARWIN_EVENTS_H */ +#endif /* _DARWIN_EVENTS_H */ diff --git a/xorg-server/hw/xquartz/darwinXinput.c b/xorg-server/hw/xquartz/darwinXinput.c index 94c31bb23..4d6604ed4 100644 --- a/xorg-server/hw/xquartz/darwinXinput.c +++ b/xorg-server/hw/xquartz/darwinXinput.c @@ -78,7 +78,7 @@ SOFTWARE. int SetDeviceMode(ClientPtr client, DeviceIntPtr dev, int mode) { - DEBUG_LOG("SetDeviceMode(%p, %p, %d)\n", client, dev, mode); + DEBUG_LOG("SetDeviceMode(%p, %p, %d)\n", client, dev, mode); return BadMatch; } @@ -96,11 +96,11 @@ SetDeviceMode(ClientPtr client, DeviceIntPtr dev, int mode) int SetDeviceValuators(ClientPtr client, DeviceIntPtr dev, - int *valuators, int first_valuator, int num_valuators) + int *valuators, int first_valuator, int num_valuators) { - DEBUG_LOG("SetDeviceValuators(%p, %p, %p, %d, %d)\n", client, - dev, valuators, first_valuator, num_valuators); - return BadMatch; + DEBUG_LOG("SetDeviceValuators(%p, %p, %p, %d, %d)\n", client, + dev, valuators, first_valuator, num_valuators); + return BadMatch; } /**************************************************************************** @@ -112,15 +112,13 @@ SetDeviceValuators(ClientPtr client, DeviceIntPtr dev, */ int -ChangeDeviceControl(ClientPtr client, DeviceIntPtr dev, - xDeviceCtl * control) +ChangeDeviceControl(ClientPtr client, DeviceIntPtr dev, xDeviceCtl * control) { - DEBUG_LOG("ChangeDeviceControl(%p, %p, %p)\n", client, dev, control); - return BadMatch; + DEBUG_LOG("ChangeDeviceControl(%p, %p, %p)\n", client, dev, control); + return BadMatch; } - /**************************************************************************** * * Caller: configAddDevice (and others) @@ -129,11 +127,11 @@ ChangeDeviceControl(ClientPtr client, DeviceIntPtr dev, * */ int -NewInputDeviceRequest(InputOption *options, InputAttributes *attrs, +NewInputDeviceRequest(InputOption *options, InputAttributes * attrs, DeviceIntPtr *pdev) { - DEBUG_LOG("NewInputDeviceRequest(%p, %p)\n", options, pdev); - return BadValue; + DEBUG_LOG("NewInputDeviceRequest(%p, %p)\n", options, pdev); + return BadValue; } /**************************************************************************** @@ -146,6 +144,5 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs, void DeleteInputDeviceRequest(DeviceIntPtr dev) { - DEBUG_LOG("DeleteInputDeviceRequest(%p)\n", dev); + DEBUG_LOG("DeleteInputDeviceRequest(%p)\n", dev); } - diff --git a/xorg-server/hw/xquartz/keysym2ucs.c b/xorg-server/hw/xquartz/keysym2ucs.c index 8626ebc4e..73ea55ad3 100644 --- a/xorg-server/hw/xquartz/keysym2ucs.c +++ b/xorg-server/hw/xquartz/keysym2ucs.c @@ -40,795 +40,796 @@ #include <string.h> struct codepair { - unsigned short keysym; - unsigned short ucs; + unsigned short keysym; + unsigned short ucs; }; const static struct codepair keysymtab[] = { - { 0x01a1, 0x0104 }, - { 0x01a2, 0x02d8 }, - { 0x01a3, 0x0141 }, - { 0x01a5, 0x013d }, - { 0x01a6, 0x015a }, - { 0x01a9, 0x0160 }, - { 0x01aa, 0x015e }, - { 0x01ab, 0x0164 }, - { 0x01ac, 0x0179 }, - { 0x01ae, 0x017d }, - { 0x01af, 0x017b }, - { 0x01b1, 0x0105 }, - { 0x01b2, 0x02db }, - { 0x01b3, 0x0142 }, - { 0x01b5, 0x013e }, - { 0x01b6, 0x015b }, - { 0x01b7, 0x02c7 }, - { 0x01b9, 0x0161 }, - { 0x01ba, 0x015f }, - { 0x01bb, 0x0165 }, - { 0x01bc, 0x017a }, - { 0x01bd, 0x02dd }, - { 0x01be, 0x017e }, - { 0x01bf, 0x017c }, - { 0x01c0, 0x0154 }, - { 0x01c3, 0x0102 }, - { 0x01c5, 0x0139 }, - { 0x01c6, 0x0106 }, - { 0x01c8, 0x010c }, - { 0x01ca, 0x0118 }, - { 0x01cc, 0x011a }, - { 0x01cf, 0x010e }, - { 0x01d0, 0x0110 }, - { 0x01d1, 0x0143 }, - { 0x01d2, 0x0147 }, - { 0x01d5, 0x0150 }, - { 0x01d8, 0x0158 }, - { 0x01d9, 0x016e }, - { 0x01db, 0x0170 }, - { 0x01de, 0x0162 }, - { 0x01e0, 0x0155 }, - { 0x01e3, 0x0103 }, - { 0x01e5, 0x013a }, - { 0x01e6, 0x0107 }, - { 0x01e8, 0x010d }, - { 0x01ea, 0x0119 }, - { 0x01ec, 0x011b }, - { 0x01ef, 0x010f }, - { 0x01f0, 0x0111 }, - { 0x01f1, 0x0144 }, - { 0x01f2, 0x0148 }, - { 0x01f5, 0x0151 }, - { 0x01f8, 0x0159 }, - { 0x01f9, 0x016f }, - { 0x01fb, 0x0171 }, - { 0x01fe, 0x0163 }, - { 0x01ff, 0x02d9 }, - { 0x02a1, 0x0126 }, - { 0x02a6, 0x0124 }, - { 0x02a9, 0x0130 }, - { 0x02ab, 0x011e }, - { 0x02ac, 0x0134 }, - { 0x02b1, 0x0127 }, - { 0x02b6, 0x0125 }, - { 0x02b9, 0x0131 }, - { 0x02bb, 0x011f }, - { 0x02bc, 0x0135 }, - { 0x02c5, 0x010a }, - { 0x02c6, 0x0108 }, - { 0x02d5, 0x0120 }, - { 0x02d8, 0x011c }, - { 0x02dd, 0x016c }, - { 0x02de, 0x015c }, - { 0x02e5, 0x010b }, - { 0x02e6, 0x0109 }, - { 0x02f5, 0x0121 }, - { 0x02f8, 0x011d }, - { 0x02fd, 0x016d }, - { 0x02fe, 0x015d }, - { 0x03a2, 0x0138 }, - { 0x03a3, 0x0156 }, - { 0x03a5, 0x0128 }, - { 0x03a6, 0x013b }, - { 0x03aa, 0x0112 }, - { 0x03ab, 0x0122 }, - { 0x03ac, 0x0166 }, - { 0x03b3, 0x0157 }, - { 0x03b5, 0x0129 }, - { 0x03b6, 0x013c }, - { 0x03ba, 0x0113 }, - { 0x03bb, 0x0123 }, - { 0x03bc, 0x0167 }, - { 0x03bd, 0x014a }, - { 0x03bf, 0x014b }, - { 0x03c0, 0x0100 }, - { 0x03c7, 0x012e }, - { 0x03cc, 0x0116 }, - { 0x03cf, 0x012a }, - { 0x03d1, 0x0145 }, - { 0x03d2, 0x014c }, - { 0x03d3, 0x0136 }, - { 0x03d9, 0x0172 }, - { 0x03dd, 0x0168 }, - { 0x03de, 0x016a }, - { 0x03e0, 0x0101 }, - { 0x03e7, 0x012f }, - { 0x03ec, 0x0117 }, - { 0x03ef, 0x012b }, - { 0x03f1, 0x0146 }, - { 0x03f2, 0x014d }, - { 0x03f3, 0x0137 }, - { 0x03f9, 0x0173 }, - { 0x03fd, 0x0169 }, - { 0x03fe, 0x016b }, - { 0x047e, 0x203e }, - { 0x04a1, 0x3002 }, - { 0x04a2, 0x300c }, - { 0x04a3, 0x300d }, - { 0x04a4, 0x3001 }, - { 0x04a5, 0x30fb }, - { 0x04a6, 0x30f2 }, - { 0x04a7, 0x30a1 }, - { 0x04a8, 0x30a3 }, - { 0x04a9, 0x30a5 }, - { 0x04aa, 0x30a7 }, - { 0x04ab, 0x30a9 }, - { 0x04ac, 0x30e3 }, - { 0x04ad, 0x30e5 }, - { 0x04ae, 0x30e7 }, - { 0x04af, 0x30c3 }, - { 0x04b0, 0x30fc }, - { 0x04b1, 0x30a2 }, - { 0x04b2, 0x30a4 }, - { 0x04b3, 0x30a6 }, - { 0x04b4, 0x30a8 }, - { 0x04b5, 0x30aa }, - { 0x04b6, 0x30ab }, - { 0x04b7, 0x30ad }, - { 0x04b8, 0x30af }, - { 0x04b9, 0x30b1 }, - { 0x04ba, 0x30b3 }, - { 0x04bb, 0x30b5 }, - { 0x04bc, 0x30b7 }, - { 0x04bd, 0x30b9 }, - { 0x04be, 0x30bb }, - { 0x04bf, 0x30bd }, - { 0x04c0, 0x30bf }, - { 0x04c1, 0x30c1 }, - { 0x04c2, 0x30c4 }, - { 0x04c3, 0x30c6 }, - { 0x04c4, 0x30c8 }, - { 0x04c5, 0x30ca }, - { 0x04c6, 0x30cb }, - { 0x04c7, 0x30cc }, - { 0x04c8, 0x30cd }, - { 0x04c9, 0x30ce }, - { 0x04ca, 0x30cf }, - { 0x04cb, 0x30d2 }, - { 0x04cc, 0x30d5 }, - { 0x04cd, 0x30d8 }, - { 0x04ce, 0x30db }, - { 0x04cf, 0x30de }, - { 0x04d0, 0x30df }, - { 0x04d1, 0x30e0 }, - { 0x04d2, 0x30e1 }, - { 0x04d3, 0x30e2 }, - { 0x04d4, 0x30e4 }, - { 0x04d5, 0x30e6 }, - { 0x04d6, 0x30e8 }, - { 0x04d7, 0x30e9 }, - { 0x04d8, 0x30ea }, - { 0x04d9, 0x30eb }, - { 0x04da, 0x30ec }, - { 0x04db, 0x30ed }, - { 0x04dc, 0x30ef }, - { 0x04dd, 0x30f3 }, - { 0x04de, 0x309b }, - { 0x04df, 0x309c }, - { 0x05ac, 0x060c }, - { 0x05bb, 0x061b }, - { 0x05bf, 0x061f }, - { 0x05c1, 0x0621 }, - { 0x05c2, 0x0622 }, - { 0x05c3, 0x0623 }, - { 0x05c4, 0x0624 }, - { 0x05c5, 0x0625 }, - { 0x05c6, 0x0626 }, - { 0x05c7, 0x0627 }, - { 0x05c8, 0x0628 }, - { 0x05c9, 0x0629 }, - { 0x05ca, 0x062a }, - { 0x05cb, 0x062b }, - { 0x05cc, 0x062c }, - { 0x05cd, 0x062d }, - { 0x05ce, 0x062e }, - { 0x05cf, 0x062f }, - { 0x05d0, 0x0630 }, - { 0x05d1, 0x0631 }, - { 0x05d2, 0x0632 }, - { 0x05d3, 0x0633 }, - { 0x05d4, 0x0634 }, - { 0x05d5, 0x0635 }, - { 0x05d6, 0x0636 }, - { 0x05d7, 0x0637 }, - { 0x05d8, 0x0638 }, - { 0x05d9, 0x0639 }, - { 0x05da, 0x063a }, - { 0x05e0, 0x0640 }, - { 0x05e1, 0x0641 }, - { 0x05e2, 0x0642 }, - { 0x05e3, 0x0643 }, - { 0x05e4, 0x0644 }, - { 0x05e5, 0x0645 }, - { 0x05e6, 0x0646 }, - { 0x05e7, 0x0647 }, - { 0x05e8, 0x0648 }, - { 0x05e9, 0x0649 }, - { 0x05ea, 0x064a }, - { 0x05eb, 0x064b }, - { 0x05ec, 0x064c }, - { 0x05ed, 0x064d }, - { 0x05ee, 0x064e }, - { 0x05ef, 0x064f }, - { 0x05f0, 0x0650 }, - { 0x05f1, 0x0651 }, - { 0x05f2, 0x0652 }, - { 0x06a1, 0x0452 }, - { 0x06a2, 0x0453 }, - { 0x06a3, 0x0451 }, - { 0x06a4, 0x0454 }, - { 0x06a5, 0x0455 }, - { 0x06a6, 0x0456 }, - { 0x06a7, 0x0457 }, - { 0x06a8, 0x0458 }, - { 0x06a9, 0x0459 }, - { 0x06aa, 0x045a }, - { 0x06ab, 0x045b }, - { 0x06ac, 0x045c }, - { 0x06ae, 0x045e }, - { 0x06af, 0x045f }, - { 0x06b0, 0x2116 }, - { 0x06b1, 0x0402 }, - { 0x06b2, 0x0403 }, - { 0x06b3, 0x0401 }, - { 0x06b4, 0x0404 }, - { 0x06b5, 0x0405 }, - { 0x06b6, 0x0406 }, - { 0x06b7, 0x0407 }, - { 0x06b8, 0x0408 }, - { 0x06b9, 0x0409 }, - { 0x06ba, 0x040a }, - { 0x06bb, 0x040b }, - { 0x06bc, 0x040c }, - { 0x06be, 0x040e }, - { 0x06bf, 0x040f }, - { 0x06c0, 0x044e }, - { 0x06c1, 0x0430 }, - { 0x06c2, 0x0431 }, - { 0x06c3, 0x0446 }, - { 0x06c4, 0x0434 }, - { 0x06c5, 0x0435 }, - { 0x06c6, 0x0444 }, - { 0x06c7, 0x0433 }, - { 0x06c8, 0x0445 }, - { 0x06c9, 0x0438 }, - { 0x06ca, 0x0439 }, - { 0x06cb, 0x043a }, - { 0x06cc, 0x043b }, - { 0x06cd, 0x043c }, - { 0x06ce, 0x043d }, - { 0x06cf, 0x043e }, - { 0x06d0, 0x043f }, - { 0x06d1, 0x044f }, - { 0x06d2, 0x0440 }, - { 0x06d3, 0x0441 }, - { 0x06d4, 0x0442 }, - { 0x06d5, 0x0443 }, - { 0x06d6, 0x0436 }, - { 0x06d7, 0x0432 }, - { 0x06d8, 0x044c }, - { 0x06d9, 0x044b }, - { 0x06da, 0x0437 }, - { 0x06db, 0x0448 }, - { 0x06dc, 0x044d }, - { 0x06dd, 0x0449 }, - { 0x06de, 0x0447 }, - { 0x06df, 0x044a }, - { 0x06e0, 0x042e }, - { 0x06e1, 0x0410 }, - { 0x06e2, 0x0411 }, - { 0x06e3, 0x0426 }, - { 0x06e4, 0x0414 }, - { 0x06e5, 0x0415 }, - { 0x06e6, 0x0424 }, - { 0x06e7, 0x0413 }, - { 0x06e8, 0x0425 }, - { 0x06e9, 0x0418 }, - { 0x06ea, 0x0419 }, - { 0x06eb, 0x041a }, - { 0x06ec, 0x041b }, - { 0x06ed, 0x041c }, - { 0x06ee, 0x041d }, - { 0x06ef, 0x041e }, - { 0x06f0, 0x041f }, - { 0x06f1, 0x042f }, - { 0x06f2, 0x0420 }, - { 0x06f3, 0x0421 }, - { 0x06f4, 0x0422 }, - { 0x06f5, 0x0423 }, - { 0x06f6, 0x0416 }, - { 0x06f7, 0x0412 }, - { 0x06f8, 0x042c }, - { 0x06f9, 0x042b }, - { 0x06fa, 0x0417 }, - { 0x06fb, 0x0428 }, - { 0x06fc, 0x042d }, - { 0x06fd, 0x0429 }, - { 0x06fe, 0x0427 }, - { 0x06ff, 0x042a }, - { 0x07a1, 0x0386 }, - { 0x07a2, 0x0388 }, - { 0x07a3, 0x0389 }, - { 0x07a4, 0x038a }, - { 0x07a5, 0x03aa }, - { 0x07a7, 0x038c }, - { 0x07a8, 0x038e }, - { 0x07a9, 0x03ab }, - { 0x07ab, 0x038f }, - { 0x07ae, 0x0385 }, - { 0x07af, 0x2015 }, - { 0x07b1, 0x03ac }, - { 0x07b2, 0x03ad }, - { 0x07b3, 0x03ae }, - { 0x07b4, 0x03af }, - { 0x07b5, 0x03ca }, - { 0x07b6, 0x0390 }, - { 0x07b7, 0x03cc }, - { 0x07b8, 0x03cd }, - { 0x07b9, 0x03cb }, - { 0x07ba, 0x03b0 }, - { 0x07bb, 0x03ce }, - { 0x07c1, 0x0391 }, - { 0x07c2, 0x0392 }, - { 0x07c3, 0x0393 }, - { 0x07c4, 0x0394 }, - { 0x07c5, 0x0395 }, - { 0x07c6, 0x0396 }, - { 0x07c7, 0x0397 }, - { 0x07c8, 0x0398 }, - { 0x07c9, 0x0399 }, - { 0x07ca, 0x039a }, - { 0x07cb, 0x039b }, - { 0x07cc, 0x039c }, - { 0x07cd, 0x039d }, - { 0x07ce, 0x039e }, - { 0x07cf, 0x039f }, - { 0x07d0, 0x03a0 }, - { 0x07d1, 0x03a1 }, - { 0x07d2, 0x03a3 }, - { 0x07d4, 0x03a4 }, - { 0x07d5, 0x03a5 }, - { 0x07d6, 0x03a6 }, - { 0x07d7, 0x03a7 }, - { 0x07d8, 0x03a8 }, - { 0x07d9, 0x03a9 }, - { 0x07e1, 0x03b1 }, - { 0x07e2, 0x03b2 }, - { 0x07e3, 0x03b3 }, - { 0x07e4, 0x03b4 }, - { 0x07e5, 0x03b5 }, - { 0x07e6, 0x03b6 }, - { 0x07e7, 0x03b7 }, - { 0x07e8, 0x03b8 }, - { 0x07e9, 0x03b9 }, - { 0x07ea, 0x03ba }, - { 0x07eb, 0x03bb }, - { 0x07ec, 0x03bc }, - { 0x07ed, 0x03bd }, - { 0x07ee, 0x03be }, - { 0x07ef, 0x03bf }, - { 0x07f0, 0x03c0 }, - { 0x07f1, 0x03c1 }, - { 0x07f2, 0x03c3 }, - { 0x07f3, 0x03c2 }, - { 0x07f4, 0x03c4 }, - { 0x07f5, 0x03c5 }, - { 0x07f6, 0x03c6 }, - { 0x07f7, 0x03c7 }, - { 0x07f8, 0x03c8 }, - { 0x07f9, 0x03c9 }, - { 0x08a1, 0x23b7 }, - { 0x08a2, 0x250c }, - { 0x08a3, 0x2500 }, - { 0x08a4, 0x2320 }, - { 0x08a5, 0x2321 }, - { 0x08a6, 0x2502 }, - { 0x08a7, 0x23a1 }, - { 0x08a8, 0x23a3 }, - { 0x08a9, 0x23a4 }, - { 0x08aa, 0x23a6 }, - { 0x08ab, 0x239b }, - { 0x08ac, 0x239d }, - { 0x08ad, 0x239e }, - { 0x08ae, 0x23a0 }, - { 0x08af, 0x23a8 }, - { 0x08b0, 0x23ac }, - { 0x08bc, 0x2264 }, - { 0x08bd, 0x2260 }, - { 0x08be, 0x2265 }, - { 0x08bf, 0x222b }, - { 0x08c0, 0x2234 }, - { 0x08c1, 0x221d }, - { 0x08c2, 0x221e }, - { 0x08c5, 0x2207 }, - { 0x08c8, 0x223c }, - { 0x08c9, 0x2243 }, - { 0x08cd, 0x21d4 }, - { 0x08ce, 0x21d2 }, - { 0x08cf, 0x2261 }, - { 0x08d6, 0x221a }, - { 0x08da, 0x2282 }, - { 0x08db, 0x2283 }, - { 0x08dc, 0x2229 }, - { 0x08dd, 0x222a }, - { 0x08de, 0x2227 }, - { 0x08df, 0x2228 }, - { 0x08ef, 0x2202 }, - { 0x08f6, 0x0192 }, - { 0x08fb, 0x2190 }, - { 0x08fc, 0x2191 }, - { 0x08fd, 0x2192 }, - { 0x08fe, 0x2193 }, - { 0x09e0, 0x25c6 }, - { 0x09e1, 0x2592 }, - { 0x09e2, 0x2409 }, - { 0x09e3, 0x240c }, - { 0x09e4, 0x240d }, - { 0x09e5, 0x240a }, - { 0x09e8, 0x2424 }, - { 0x09e9, 0x240b }, - { 0x09ea, 0x2518 }, - { 0x09eb, 0x2510 }, - { 0x09ec, 0x250c }, - { 0x09ed, 0x2514 }, - { 0x09ee, 0x253c }, - { 0x09ef, 0x23ba }, - { 0x09f0, 0x23bb }, - { 0x09f1, 0x2500 }, - { 0x09f2, 0x23bc }, - { 0x09f3, 0x23bd }, - { 0x09f4, 0x251c }, - { 0x09f5, 0x2524 }, - { 0x09f6, 0x2534 }, - { 0x09f7, 0x252c }, - { 0x09f8, 0x2502 }, - { 0x0aa1, 0x2003 }, - { 0x0aa2, 0x2002 }, - { 0x0aa3, 0x2004 }, - { 0x0aa4, 0x2005 }, - { 0x0aa5, 0x2007 }, - { 0x0aa6, 0x2008 }, - { 0x0aa7, 0x2009 }, - { 0x0aa8, 0x200a }, - { 0x0aa9, 0x2014 }, - { 0x0aaa, 0x2013 }, - { 0x0aae, 0x2026 }, - { 0x0aaf, 0x2025 }, - { 0x0ab0, 0x2153 }, - { 0x0ab1, 0x2154 }, - { 0x0ab2, 0x2155 }, - { 0x0ab3, 0x2156 }, - { 0x0ab4, 0x2157 }, - { 0x0ab5, 0x2158 }, - { 0x0ab6, 0x2159 }, - { 0x0ab7, 0x215a }, - { 0x0ab8, 0x2105 }, - { 0x0abb, 0x2012 }, - { 0x0abc, 0x2329 }, - { 0x0abe, 0x232a }, - { 0x0ac3, 0x215b }, - { 0x0ac4, 0x215c }, - { 0x0ac5, 0x215d }, - { 0x0ac6, 0x215e }, - { 0x0ac9, 0x2122 }, - { 0x0aca, 0x2613 }, - { 0x0acc, 0x25c1 }, - { 0x0acd, 0x25b7 }, - { 0x0ace, 0x25cb }, - { 0x0acf, 0x25af }, - { 0x0ad0, 0x2018 }, - { 0x0ad1, 0x2019 }, - { 0x0ad2, 0x201c }, - { 0x0ad3, 0x201d }, - { 0x0ad4, 0x211e }, - { 0x0ad6, 0x2032 }, - { 0x0ad7, 0x2033 }, - { 0x0ad9, 0x271d }, - { 0x0adb, 0x25ac }, - { 0x0adc, 0x25c0 }, - { 0x0add, 0x25b6 }, - { 0x0ade, 0x25cf }, - { 0x0adf, 0x25ae }, - { 0x0ae0, 0x25e6 }, - { 0x0ae1, 0x25ab }, - { 0x0ae2, 0x25ad }, - { 0x0ae3, 0x25b3 }, - { 0x0ae4, 0x25bd }, - { 0x0ae5, 0x2606 }, - { 0x0ae6, 0x2022 }, - { 0x0ae7, 0x25aa }, - { 0x0ae8, 0x25b2 }, - { 0x0ae9, 0x25bc }, - { 0x0aea, 0x261c }, - { 0x0aeb, 0x261e }, - { 0x0aec, 0x2663 }, - { 0x0aed, 0x2666 }, - { 0x0aee, 0x2665 }, - { 0x0af0, 0x2720 }, - { 0x0af1, 0x2020 }, - { 0x0af2, 0x2021 }, - { 0x0af3, 0x2713 }, - { 0x0af4, 0x2717 }, - { 0x0af5, 0x266f }, - { 0x0af6, 0x266d }, - { 0x0af7, 0x2642 }, - { 0x0af8, 0x2640 }, - { 0x0af9, 0x260e }, - { 0x0afa, 0x2315 }, - { 0x0afb, 0x2117 }, - { 0x0afc, 0x2038 }, - { 0x0afd, 0x201a }, - { 0x0afe, 0x201e }, - { 0x0ba3, 0x003c }, - { 0x0ba6, 0x003e }, - { 0x0ba8, 0x2228 }, - { 0x0ba9, 0x2227 }, - { 0x0bc0, 0x00af }, - { 0x0bc2, 0x22a5 }, - { 0x0bc3, 0x2229 }, - { 0x0bc4, 0x230a }, - { 0x0bc6, 0x005f }, - { 0x0bca, 0x2218 }, - { 0x0bcc, 0x2395 }, - { 0x0bce, 0x22a4 }, - { 0x0bcf, 0x25cb }, - { 0x0bd3, 0x2308 }, - { 0x0bd6, 0x222a }, - { 0x0bd8, 0x2283 }, - { 0x0bda, 0x2282 }, - { 0x0bdc, 0x22a2 }, - { 0x0bfc, 0x22a3 }, - { 0x0cdf, 0x2017 }, - { 0x0ce0, 0x05d0 }, - { 0x0ce1, 0x05d1 }, - { 0x0ce2, 0x05d2 }, - { 0x0ce3, 0x05d3 }, - { 0x0ce4, 0x05d4 }, - { 0x0ce5, 0x05d5 }, - { 0x0ce6, 0x05d6 }, - { 0x0ce7, 0x05d7 }, - { 0x0ce8, 0x05d8 }, - { 0x0ce9, 0x05d9 }, - { 0x0cea, 0x05da }, - { 0x0ceb, 0x05db }, - { 0x0cec, 0x05dc }, - { 0x0ced, 0x05dd }, - { 0x0cee, 0x05de }, - { 0x0cef, 0x05df }, - { 0x0cf0, 0x05e0 }, - { 0x0cf1, 0x05e1 }, - { 0x0cf2, 0x05e2 }, - { 0x0cf3, 0x05e3 }, - { 0x0cf4, 0x05e4 }, - { 0x0cf5, 0x05e5 }, - { 0x0cf6, 0x05e6 }, - { 0x0cf7, 0x05e7 }, - { 0x0cf8, 0x05e8 }, - { 0x0cf9, 0x05e9 }, - { 0x0cfa, 0x05ea }, - { 0x0da1, 0x0e01 }, - { 0x0da2, 0x0e02 }, - { 0x0da3, 0x0e03 }, - { 0x0da4, 0x0e04 }, - { 0x0da5, 0x0e05 }, - { 0x0da6, 0x0e06 }, - { 0x0da7, 0x0e07 }, - { 0x0da8, 0x0e08 }, - { 0x0da9, 0x0e09 }, - { 0x0daa, 0x0e0a }, - { 0x0dab, 0x0e0b }, - { 0x0dac, 0x0e0c }, - { 0x0dad, 0x0e0d }, - { 0x0dae, 0x0e0e }, - { 0x0daf, 0x0e0f }, - { 0x0db0, 0x0e10 }, - { 0x0db1, 0x0e11 }, - { 0x0db2, 0x0e12 }, - { 0x0db3, 0x0e13 }, - { 0x0db4, 0x0e14 }, - { 0x0db5, 0x0e15 }, - { 0x0db6, 0x0e16 }, - { 0x0db7, 0x0e17 }, - { 0x0db8, 0x0e18 }, - { 0x0db9, 0x0e19 }, - { 0x0dba, 0x0e1a }, - { 0x0dbb, 0x0e1b }, - { 0x0dbc, 0x0e1c }, - { 0x0dbd, 0x0e1d }, - { 0x0dbe, 0x0e1e }, - { 0x0dbf, 0x0e1f }, - { 0x0dc0, 0x0e20 }, - { 0x0dc1, 0x0e21 }, - { 0x0dc2, 0x0e22 }, - { 0x0dc3, 0x0e23 }, - { 0x0dc4, 0x0e24 }, - { 0x0dc5, 0x0e25 }, - { 0x0dc6, 0x0e26 }, - { 0x0dc7, 0x0e27 }, - { 0x0dc8, 0x0e28 }, - { 0x0dc9, 0x0e29 }, - { 0x0dca, 0x0e2a }, - { 0x0dcb, 0x0e2b }, - { 0x0dcc, 0x0e2c }, - { 0x0dcd, 0x0e2d }, - { 0x0dce, 0x0e2e }, - { 0x0dcf, 0x0e2f }, - { 0x0dd0, 0x0e30 }, - { 0x0dd1, 0x0e31 }, - { 0x0dd2, 0x0e32 }, - { 0x0dd3, 0x0e33 }, - { 0x0dd4, 0x0e34 }, - { 0x0dd5, 0x0e35 }, - { 0x0dd6, 0x0e36 }, - { 0x0dd7, 0x0e37 }, - { 0x0dd8, 0x0e38 }, - { 0x0dd9, 0x0e39 }, - { 0x0dda, 0x0e3a }, - { 0x0ddf, 0x0e3f }, - { 0x0de0, 0x0e40 }, - { 0x0de1, 0x0e41 }, - { 0x0de2, 0x0e42 }, - { 0x0de3, 0x0e43 }, - { 0x0de4, 0x0e44 }, - { 0x0de5, 0x0e45 }, - { 0x0de6, 0x0e46 }, - { 0x0de7, 0x0e47 }, - { 0x0de8, 0x0e48 }, - { 0x0de9, 0x0e49 }, - { 0x0dea, 0x0e4a }, - { 0x0deb, 0x0e4b }, - { 0x0dec, 0x0e4c }, - { 0x0ded, 0x0e4d }, - { 0x0df0, 0x0e50 }, - { 0x0df1, 0x0e51 }, - { 0x0df2, 0x0e52 }, - { 0x0df3, 0x0e53 }, - { 0x0df4, 0x0e54 }, - { 0x0df5, 0x0e55 }, - { 0x0df6, 0x0e56 }, - { 0x0df7, 0x0e57 }, - { 0x0df8, 0x0e58 }, - { 0x0df9, 0x0e59 }, - { 0x0ea1, 0x3131 }, - { 0x0ea2, 0x3132 }, - { 0x0ea3, 0x3133 }, - { 0x0ea4, 0x3134 }, - { 0x0ea5, 0x3135 }, - { 0x0ea6, 0x3136 }, - { 0x0ea7, 0x3137 }, - { 0x0ea8, 0x3138 }, - { 0x0ea9, 0x3139 }, - { 0x0eaa, 0x313a }, - { 0x0eab, 0x313b }, - { 0x0eac, 0x313c }, - { 0x0ead, 0x313d }, - { 0x0eae, 0x313e }, - { 0x0eaf, 0x313f }, - { 0x0eb0, 0x3140 }, - { 0x0eb1, 0x3141 }, - { 0x0eb2, 0x3142 }, - { 0x0eb3, 0x3143 }, - { 0x0eb4, 0x3144 }, - { 0x0eb5, 0x3145 }, - { 0x0eb6, 0x3146 }, - { 0x0eb7, 0x3147 }, - { 0x0eb8, 0x3148 }, - { 0x0eb9, 0x3149 }, - { 0x0eba, 0x314a }, - { 0x0ebb, 0x314b }, - { 0x0ebc, 0x314c }, - { 0x0ebd, 0x314d }, - { 0x0ebe, 0x314e }, - { 0x0ebf, 0x314f }, - { 0x0ec0, 0x3150 }, - { 0x0ec1, 0x3151 }, - { 0x0ec2, 0x3152 }, - { 0x0ec3, 0x3153 }, - { 0x0ec4, 0x3154 }, - { 0x0ec5, 0x3155 }, - { 0x0ec6, 0x3156 }, - { 0x0ec7, 0x3157 }, - { 0x0ec8, 0x3158 }, - { 0x0ec9, 0x3159 }, - { 0x0eca, 0x315a }, - { 0x0ecb, 0x315b }, - { 0x0ecc, 0x315c }, - { 0x0ecd, 0x315d }, - { 0x0ece, 0x315e }, - { 0x0ecf, 0x315f }, - { 0x0ed0, 0x3160 }, - { 0x0ed1, 0x3161 }, - { 0x0ed2, 0x3162 }, - { 0x0ed3, 0x3163 }, - { 0x0ed4, 0x11a8 }, - { 0x0ed5, 0x11a9 }, - { 0x0ed6, 0x11aa }, - { 0x0ed7, 0x11ab }, - { 0x0ed8, 0x11ac }, - { 0x0ed9, 0x11ad }, - { 0x0eda, 0x11ae }, - { 0x0edb, 0x11af }, - { 0x0edc, 0x11b0 }, - { 0x0edd, 0x11b1 }, - { 0x0ede, 0x11b2 }, - { 0x0edf, 0x11b3 }, - { 0x0ee0, 0x11b4 }, - { 0x0ee1, 0x11b5 }, - { 0x0ee2, 0x11b6 }, - { 0x0ee3, 0x11b7 }, - { 0x0ee4, 0x11b8 }, - { 0x0ee5, 0x11b9 }, - { 0x0ee6, 0x11ba }, - { 0x0ee7, 0x11bb }, - { 0x0ee8, 0x11bc }, - { 0x0ee9, 0x11bd }, - { 0x0eea, 0x11be }, - { 0x0eeb, 0x11bf }, - { 0x0eec, 0x11c0 }, - { 0x0eed, 0x11c1 }, - { 0x0eee, 0x11c2 }, - { 0x0eef, 0x316d }, - { 0x0ef0, 0x3171 }, - { 0x0ef1, 0x3178 }, - { 0x0ef2, 0x317f }, - { 0x0ef3, 0x3181 }, - { 0x0ef4, 0x3184 }, - { 0x0ef5, 0x3186 }, - { 0x0ef6, 0x318d }, - { 0x0ef7, 0x318e }, - { 0x0ef8, 0x11eb }, - { 0x0ef9, 0x11f0 }, - { 0x0efa, 0x11f9 }, - { 0x0eff, 0x20a9 }, + {0x01a1, 0x0104}, + {0x01a2, 0x02d8}, + {0x01a3, 0x0141}, + {0x01a5, 0x013d}, + {0x01a6, 0x015a}, + {0x01a9, 0x0160}, + {0x01aa, 0x015e}, + {0x01ab, 0x0164}, + {0x01ac, 0x0179}, + {0x01ae, 0x017d}, + {0x01af, 0x017b}, + {0x01b1, 0x0105}, + {0x01b2, 0x02db}, + {0x01b3, 0x0142}, + {0x01b5, 0x013e}, + {0x01b6, 0x015b}, + {0x01b7, 0x02c7}, + {0x01b9, 0x0161}, + {0x01ba, 0x015f}, + {0x01bb, 0x0165}, + {0x01bc, 0x017a}, + {0x01bd, 0x02dd}, + {0x01be, 0x017e}, + {0x01bf, 0x017c}, + {0x01c0, 0x0154}, + {0x01c3, 0x0102}, + {0x01c5, 0x0139}, + {0x01c6, 0x0106}, + {0x01c8, 0x010c}, + {0x01ca, 0x0118}, + {0x01cc, 0x011a}, + {0x01cf, 0x010e}, + {0x01d0, 0x0110}, + {0x01d1, 0x0143}, + {0x01d2, 0x0147}, + {0x01d5, 0x0150}, + {0x01d8, 0x0158}, + {0x01d9, 0x016e}, + {0x01db, 0x0170}, + {0x01de, 0x0162}, + {0x01e0, 0x0155}, + {0x01e3, 0x0103}, + {0x01e5, 0x013a}, + {0x01e6, 0x0107}, + {0x01e8, 0x010d}, + {0x01ea, 0x0119}, + {0x01ec, 0x011b}, + {0x01ef, 0x010f}, + {0x01f0, 0x0111}, + {0x01f1, 0x0144}, + {0x01f2, 0x0148}, + {0x01f5, 0x0151}, + {0x01f8, 0x0159}, + {0x01f9, 0x016f}, + {0x01fb, 0x0171}, + {0x01fe, 0x0163}, + {0x01ff, 0x02d9}, + {0x02a1, 0x0126}, + {0x02a6, 0x0124}, + {0x02a9, 0x0130}, + {0x02ab, 0x011e}, + {0x02ac, 0x0134}, + {0x02b1, 0x0127}, + {0x02b6, 0x0125}, + {0x02b9, 0x0131}, + {0x02bb, 0x011f}, + {0x02bc, 0x0135}, + {0x02c5, 0x010a}, + {0x02c6, 0x0108}, + {0x02d5, 0x0120}, + {0x02d8, 0x011c}, + {0x02dd, 0x016c}, + {0x02de, 0x015c}, + {0x02e5, 0x010b}, + {0x02e6, 0x0109}, + {0x02f5, 0x0121}, + {0x02f8, 0x011d}, + {0x02fd, 0x016d}, + {0x02fe, 0x015d}, + {0x03a2, 0x0138}, + {0x03a3, 0x0156}, + {0x03a5, 0x0128}, + {0x03a6, 0x013b}, + {0x03aa, 0x0112}, + {0x03ab, 0x0122}, + {0x03ac, 0x0166}, + {0x03b3, 0x0157}, + {0x03b5, 0x0129}, + {0x03b6, 0x013c}, + {0x03ba, 0x0113}, + {0x03bb, 0x0123}, + {0x03bc, 0x0167}, + {0x03bd, 0x014a}, + {0x03bf, 0x014b}, + {0x03c0, 0x0100}, + {0x03c7, 0x012e}, + {0x03cc, 0x0116}, + {0x03cf, 0x012a}, + {0x03d1, 0x0145}, + {0x03d2, 0x014c}, + {0x03d3, 0x0136}, + {0x03d9, 0x0172}, + {0x03dd, 0x0168}, + {0x03de, 0x016a}, + {0x03e0, 0x0101}, + {0x03e7, 0x012f}, + {0x03ec, 0x0117}, + {0x03ef, 0x012b}, + {0x03f1, 0x0146}, + {0x03f2, 0x014d}, + {0x03f3, 0x0137}, + {0x03f9, 0x0173}, + {0x03fd, 0x0169}, + {0x03fe, 0x016b}, + {0x047e, 0x203e}, + {0x04a1, 0x3002}, + {0x04a2, 0x300c}, + {0x04a3, 0x300d}, + {0x04a4, 0x3001}, + {0x04a5, 0x30fb}, + {0x04a6, 0x30f2}, + {0x04a7, 0x30a1}, + {0x04a8, 0x30a3}, + {0x04a9, 0x30a5}, + {0x04aa, 0x30a7}, + {0x04ab, 0x30a9}, + {0x04ac, 0x30e3}, + {0x04ad, 0x30e5}, + {0x04ae, 0x30e7}, + {0x04af, 0x30c3}, + {0x04b0, 0x30fc}, + {0x04b1, 0x30a2}, + {0x04b2, 0x30a4}, + {0x04b3, 0x30a6}, + {0x04b4, 0x30a8}, + {0x04b5, 0x30aa}, + {0x04b6, 0x30ab}, + {0x04b7, 0x30ad}, + {0x04b8, 0x30af}, + {0x04b9, 0x30b1}, + {0x04ba, 0x30b3}, + {0x04bb, 0x30b5}, + {0x04bc, 0x30b7}, + {0x04bd, 0x30b9}, + {0x04be, 0x30bb}, + {0x04bf, 0x30bd}, + {0x04c0, 0x30bf}, + {0x04c1, 0x30c1}, + {0x04c2, 0x30c4}, + {0x04c3, 0x30c6}, + {0x04c4, 0x30c8}, + {0x04c5, 0x30ca}, + {0x04c6, 0x30cb}, + {0x04c7, 0x30cc}, + {0x04c8, 0x30cd}, + {0x04c9, 0x30ce}, + {0x04ca, 0x30cf}, + {0x04cb, 0x30d2}, + {0x04cc, 0x30d5}, + {0x04cd, 0x30d8}, + {0x04ce, 0x30db}, + {0x04cf, 0x30de}, + {0x04d0, 0x30df}, + {0x04d1, 0x30e0}, + {0x04d2, 0x30e1}, + {0x04d3, 0x30e2}, + {0x04d4, 0x30e4}, + {0x04d5, 0x30e6}, + {0x04d6, 0x30e8}, + {0x04d7, 0x30e9}, + {0x04d8, 0x30ea}, + {0x04d9, 0x30eb}, + {0x04da, 0x30ec}, + {0x04db, 0x30ed}, + {0x04dc, 0x30ef}, + {0x04dd, 0x30f3}, + {0x04de, 0x309b}, + {0x04df, 0x309c}, + {0x05ac, 0x060c}, + {0x05bb, 0x061b}, + {0x05bf, 0x061f}, + {0x05c1, 0x0621}, + {0x05c2, 0x0622}, + {0x05c3, 0x0623}, + {0x05c4, 0x0624}, + {0x05c5, 0x0625}, + {0x05c6, 0x0626}, + {0x05c7, 0x0627}, + {0x05c8, 0x0628}, + {0x05c9, 0x0629}, + {0x05ca, 0x062a}, + {0x05cb, 0x062b}, + {0x05cc, 0x062c}, + {0x05cd, 0x062d}, + {0x05ce, 0x062e}, + {0x05cf, 0x062f}, + {0x05d0, 0x0630}, + {0x05d1, 0x0631}, + {0x05d2, 0x0632}, + {0x05d3, 0x0633}, + {0x05d4, 0x0634}, + {0x05d5, 0x0635}, + {0x05d6, 0x0636}, + {0x05d7, 0x0637}, + {0x05d8, 0x0638}, + {0x05d9, 0x0639}, + {0x05da, 0x063a}, + {0x05e0, 0x0640}, + {0x05e1, 0x0641}, + {0x05e2, 0x0642}, + {0x05e3, 0x0643}, + {0x05e4, 0x0644}, + {0x05e5, 0x0645}, + {0x05e6, 0x0646}, + {0x05e7, 0x0647}, + {0x05e8, 0x0648}, + {0x05e9, 0x0649}, + {0x05ea, 0x064a}, + {0x05eb, 0x064b}, + {0x05ec, 0x064c}, + {0x05ed, 0x064d}, + {0x05ee, 0x064e}, + {0x05ef, 0x064f}, + {0x05f0, 0x0650}, + {0x05f1, 0x0651}, + {0x05f2, 0x0652}, + {0x06a1, 0x0452}, + {0x06a2, 0x0453}, + {0x06a3, 0x0451}, + {0x06a4, 0x0454}, + {0x06a5, 0x0455}, + {0x06a6, 0x0456}, + {0x06a7, 0x0457}, + {0x06a8, 0x0458}, + {0x06a9, 0x0459}, + {0x06aa, 0x045a}, + {0x06ab, 0x045b}, + {0x06ac, 0x045c}, + {0x06ae, 0x045e}, + {0x06af, 0x045f}, + {0x06b0, 0x2116}, + {0x06b1, 0x0402}, + {0x06b2, 0x0403}, + {0x06b3, 0x0401}, + {0x06b4, 0x0404}, + {0x06b5, 0x0405}, + {0x06b6, 0x0406}, + {0x06b7, 0x0407}, + {0x06b8, 0x0408}, + {0x06b9, 0x0409}, + {0x06ba, 0x040a}, + {0x06bb, 0x040b}, + {0x06bc, 0x040c}, + {0x06be, 0x040e}, + {0x06bf, 0x040f}, + {0x06c0, 0x044e}, + {0x06c1, 0x0430}, + {0x06c2, 0x0431}, + {0x06c3, 0x0446}, + {0x06c4, 0x0434}, + {0x06c5, 0x0435}, + {0x06c6, 0x0444}, + {0x06c7, 0x0433}, + {0x06c8, 0x0445}, + {0x06c9, 0x0438}, + {0x06ca, 0x0439}, + {0x06cb, 0x043a}, + {0x06cc, 0x043b}, + {0x06cd, 0x043c}, + {0x06ce, 0x043d}, + {0x06cf, 0x043e}, + {0x06d0, 0x043f}, + {0x06d1, 0x044f}, + {0x06d2, 0x0440}, + {0x06d3, 0x0441}, + {0x06d4, 0x0442}, + {0x06d5, 0x0443}, + {0x06d6, 0x0436}, + {0x06d7, 0x0432}, + {0x06d8, 0x044c}, + {0x06d9, 0x044b}, + {0x06da, 0x0437}, + {0x06db, 0x0448}, + {0x06dc, 0x044d}, + {0x06dd, 0x0449}, + {0x06de, 0x0447}, + {0x06df, 0x044a}, + {0x06e0, 0x042e}, + {0x06e1, 0x0410}, + {0x06e2, 0x0411}, + {0x06e3, 0x0426}, + {0x06e4, 0x0414}, + {0x06e5, 0x0415}, + {0x06e6, 0x0424}, + {0x06e7, 0x0413}, + {0x06e8, 0x0425}, + {0x06e9, 0x0418}, + {0x06ea, 0x0419}, + {0x06eb, 0x041a}, + {0x06ec, 0x041b}, + {0x06ed, 0x041c}, + {0x06ee, 0x041d}, + {0x06ef, 0x041e}, + {0x06f0, 0x041f}, + {0x06f1, 0x042f}, + {0x06f2, 0x0420}, + {0x06f3, 0x0421}, + {0x06f4, 0x0422}, + {0x06f5, 0x0423}, + {0x06f6, 0x0416}, + {0x06f7, 0x0412}, + {0x06f8, 0x042c}, + {0x06f9, 0x042b}, + {0x06fa, 0x0417}, + {0x06fb, 0x0428}, + {0x06fc, 0x042d}, + {0x06fd, 0x0429}, + {0x06fe, 0x0427}, + {0x06ff, 0x042a}, + {0x07a1, 0x0386}, + {0x07a2, 0x0388}, + {0x07a3, 0x0389}, + {0x07a4, 0x038a}, + {0x07a5, 0x03aa}, + {0x07a7, 0x038c}, + {0x07a8, 0x038e}, + {0x07a9, 0x03ab}, + {0x07ab, 0x038f}, + {0x07ae, 0x0385}, + {0x07af, 0x2015}, + {0x07b1, 0x03ac}, + {0x07b2, 0x03ad}, + {0x07b3, 0x03ae}, + {0x07b4, 0x03af}, + {0x07b5, 0x03ca}, + {0x07b6, 0x0390}, + {0x07b7, 0x03cc}, + {0x07b8, 0x03cd}, + {0x07b9, 0x03cb}, + {0x07ba, 0x03b0}, + {0x07bb, 0x03ce}, + {0x07c1, 0x0391}, + {0x07c2, 0x0392}, + {0x07c3, 0x0393}, + {0x07c4, 0x0394}, + {0x07c5, 0x0395}, + {0x07c6, 0x0396}, + {0x07c7, 0x0397}, + {0x07c8, 0x0398}, + {0x07c9, 0x0399}, + {0x07ca, 0x039a}, + {0x07cb, 0x039b}, + {0x07cc, 0x039c}, + {0x07cd, 0x039d}, + {0x07ce, 0x039e}, + {0x07cf, 0x039f}, + {0x07d0, 0x03a0}, + {0x07d1, 0x03a1}, + {0x07d2, 0x03a3}, + {0x07d4, 0x03a4}, + {0x07d5, 0x03a5}, + {0x07d6, 0x03a6}, + {0x07d7, 0x03a7}, + {0x07d8, 0x03a8}, + {0x07d9, 0x03a9}, + {0x07e1, 0x03b1}, + {0x07e2, 0x03b2}, + {0x07e3, 0x03b3}, + {0x07e4, 0x03b4}, + {0x07e5, 0x03b5}, + {0x07e6, 0x03b6}, + {0x07e7, 0x03b7}, + {0x07e8, 0x03b8}, + {0x07e9, 0x03b9}, + {0x07ea, 0x03ba}, + {0x07eb, 0x03bb}, + {0x07ec, 0x03bc}, + {0x07ed, 0x03bd}, + {0x07ee, 0x03be}, + {0x07ef, 0x03bf}, + {0x07f0, 0x03c0}, + {0x07f1, 0x03c1}, + {0x07f2, 0x03c3}, + {0x07f3, 0x03c2}, + {0x07f4, 0x03c4}, + {0x07f5, 0x03c5}, + {0x07f6, 0x03c6}, + {0x07f7, 0x03c7}, + {0x07f8, 0x03c8}, + {0x07f9, 0x03c9}, + {0x08a1, 0x23b7}, + {0x08a2, 0x250c}, + {0x08a3, 0x2500}, + {0x08a4, 0x2320}, + {0x08a5, 0x2321}, + {0x08a6, 0x2502}, + {0x08a7, 0x23a1}, + {0x08a8, 0x23a3}, + {0x08a9, 0x23a4}, + {0x08aa, 0x23a6}, + {0x08ab, 0x239b}, + {0x08ac, 0x239d}, + {0x08ad, 0x239e}, + {0x08ae, 0x23a0}, + {0x08af, 0x23a8}, + {0x08b0, 0x23ac}, + {0x08bc, 0x2264}, + {0x08bd, 0x2260}, + {0x08be, 0x2265}, + {0x08bf, 0x222b}, + {0x08c0, 0x2234}, + {0x08c1, 0x221d}, + {0x08c2, 0x221e}, + {0x08c5, 0x2207}, + {0x08c8, 0x223c}, + {0x08c9, 0x2243}, + {0x08cd, 0x21d4}, + {0x08ce, 0x21d2}, + {0x08cf, 0x2261}, + {0x08d6, 0x221a}, + {0x08da, 0x2282}, + {0x08db, 0x2283}, + {0x08dc, 0x2229}, + {0x08dd, 0x222a}, + {0x08de, 0x2227}, + {0x08df, 0x2228}, + {0x08ef, 0x2202}, + {0x08f6, 0x0192}, + {0x08fb, 0x2190}, + {0x08fc, 0x2191}, + {0x08fd, 0x2192}, + {0x08fe, 0x2193}, + {0x09e0, 0x25c6}, + {0x09e1, 0x2592}, + {0x09e2, 0x2409}, + {0x09e3, 0x240c}, + {0x09e4, 0x240d}, + {0x09e5, 0x240a}, + {0x09e8, 0x2424}, + {0x09e9, 0x240b}, + {0x09ea, 0x2518}, + {0x09eb, 0x2510}, + {0x09ec, 0x250c}, + {0x09ed, 0x2514}, + {0x09ee, 0x253c}, + {0x09ef, 0x23ba}, + {0x09f0, 0x23bb}, + {0x09f1, 0x2500}, + {0x09f2, 0x23bc}, + {0x09f3, 0x23bd}, + {0x09f4, 0x251c}, + {0x09f5, 0x2524}, + {0x09f6, 0x2534}, + {0x09f7, 0x252c}, + {0x09f8, 0x2502}, + {0x0aa1, 0x2003}, + {0x0aa2, 0x2002}, + {0x0aa3, 0x2004}, + {0x0aa4, 0x2005}, + {0x0aa5, 0x2007}, + {0x0aa6, 0x2008}, + {0x0aa7, 0x2009}, + {0x0aa8, 0x200a}, + {0x0aa9, 0x2014}, + {0x0aaa, 0x2013}, + {0x0aae, 0x2026}, + {0x0aaf, 0x2025}, + {0x0ab0, 0x2153}, + {0x0ab1, 0x2154}, + {0x0ab2, 0x2155}, + {0x0ab3, 0x2156}, + {0x0ab4, 0x2157}, + {0x0ab5, 0x2158}, + {0x0ab6, 0x2159}, + {0x0ab7, 0x215a}, + {0x0ab8, 0x2105}, + {0x0abb, 0x2012}, + {0x0abc, 0x2329}, + {0x0abe, 0x232a}, + {0x0ac3, 0x215b}, + {0x0ac4, 0x215c}, + {0x0ac5, 0x215d}, + {0x0ac6, 0x215e}, + {0x0ac9, 0x2122}, + {0x0aca, 0x2613}, + {0x0acc, 0x25c1}, + {0x0acd, 0x25b7}, + {0x0ace, 0x25cb}, + {0x0acf, 0x25af}, + {0x0ad0, 0x2018}, + {0x0ad1, 0x2019}, + {0x0ad2, 0x201c}, + {0x0ad3, 0x201d}, + {0x0ad4, 0x211e}, + {0x0ad6, 0x2032}, + {0x0ad7, 0x2033}, + {0x0ad9, 0x271d}, + {0x0adb, 0x25ac}, + {0x0adc, 0x25c0}, + {0x0add, 0x25b6}, + {0x0ade, 0x25cf}, + {0x0adf, 0x25ae}, + {0x0ae0, 0x25e6}, + {0x0ae1, 0x25ab}, + {0x0ae2, 0x25ad}, + {0x0ae3, 0x25b3}, + {0x0ae4, 0x25bd}, + {0x0ae5, 0x2606}, + {0x0ae6, 0x2022}, + {0x0ae7, 0x25aa}, + {0x0ae8, 0x25b2}, + {0x0ae9, 0x25bc}, + {0x0aea, 0x261c}, + {0x0aeb, 0x261e}, + {0x0aec, 0x2663}, + {0x0aed, 0x2666}, + {0x0aee, 0x2665}, + {0x0af0, 0x2720}, + {0x0af1, 0x2020}, + {0x0af2, 0x2021}, + {0x0af3, 0x2713}, + {0x0af4, 0x2717}, + {0x0af5, 0x266f}, + {0x0af6, 0x266d}, + {0x0af7, 0x2642}, + {0x0af8, 0x2640}, + {0x0af9, 0x260e}, + {0x0afa, 0x2315}, + {0x0afb, 0x2117}, + {0x0afc, 0x2038}, + {0x0afd, 0x201a}, + {0x0afe, 0x201e}, + {0x0ba3, 0x003c}, + {0x0ba6, 0x003e}, + {0x0ba8, 0x2228}, + {0x0ba9, 0x2227}, + {0x0bc0, 0x00af}, + {0x0bc2, 0x22a5}, + {0x0bc3, 0x2229}, + {0x0bc4, 0x230a}, + {0x0bc6, 0x005f}, + {0x0bca, 0x2218}, + {0x0bcc, 0x2395}, + {0x0bce, 0x22a4}, + {0x0bcf, 0x25cb}, + {0x0bd3, 0x2308}, + {0x0bd6, 0x222a}, + {0x0bd8, 0x2283}, + {0x0bda, 0x2282}, + {0x0bdc, 0x22a2}, + {0x0bfc, 0x22a3}, + {0x0cdf, 0x2017}, + {0x0ce0, 0x05d0}, + {0x0ce1, 0x05d1}, + {0x0ce2, 0x05d2}, + {0x0ce3, 0x05d3}, + {0x0ce4, 0x05d4}, + {0x0ce5, 0x05d5}, + {0x0ce6, 0x05d6}, + {0x0ce7, 0x05d7}, + {0x0ce8, 0x05d8}, + {0x0ce9, 0x05d9}, + {0x0cea, 0x05da}, + {0x0ceb, 0x05db}, + {0x0cec, 0x05dc}, + {0x0ced, 0x05dd}, + {0x0cee, 0x05de}, + {0x0cef, 0x05df}, + {0x0cf0, 0x05e0}, + {0x0cf1, 0x05e1}, + {0x0cf2, 0x05e2}, + {0x0cf3, 0x05e3}, + {0x0cf4, 0x05e4}, + {0x0cf5, 0x05e5}, + {0x0cf6, 0x05e6}, + {0x0cf7, 0x05e7}, + {0x0cf8, 0x05e8}, + {0x0cf9, 0x05e9}, + {0x0cfa, 0x05ea}, + {0x0da1, 0x0e01}, + {0x0da2, 0x0e02}, + {0x0da3, 0x0e03}, + {0x0da4, 0x0e04}, + {0x0da5, 0x0e05}, + {0x0da6, 0x0e06}, + {0x0da7, 0x0e07}, + {0x0da8, 0x0e08}, + {0x0da9, 0x0e09}, + {0x0daa, 0x0e0a}, + {0x0dab, 0x0e0b}, + {0x0dac, 0x0e0c}, + {0x0dad, 0x0e0d}, + {0x0dae, 0x0e0e}, + {0x0daf, 0x0e0f}, + {0x0db0, 0x0e10}, + {0x0db1, 0x0e11}, + {0x0db2, 0x0e12}, + {0x0db3, 0x0e13}, + {0x0db4, 0x0e14}, + {0x0db5, 0x0e15}, + {0x0db6, 0x0e16}, + {0x0db7, 0x0e17}, + {0x0db8, 0x0e18}, + {0x0db9, 0x0e19}, + {0x0dba, 0x0e1a}, + {0x0dbb, 0x0e1b}, + {0x0dbc, 0x0e1c}, + {0x0dbd, 0x0e1d}, + {0x0dbe, 0x0e1e}, + {0x0dbf, 0x0e1f}, + {0x0dc0, 0x0e20}, + {0x0dc1, 0x0e21}, + {0x0dc2, 0x0e22}, + {0x0dc3, 0x0e23}, + {0x0dc4, 0x0e24}, + {0x0dc5, 0x0e25}, + {0x0dc6, 0x0e26}, + {0x0dc7, 0x0e27}, + {0x0dc8, 0x0e28}, + {0x0dc9, 0x0e29}, + {0x0dca, 0x0e2a}, + {0x0dcb, 0x0e2b}, + {0x0dcc, 0x0e2c}, + {0x0dcd, 0x0e2d}, + {0x0dce, 0x0e2e}, + {0x0dcf, 0x0e2f}, + {0x0dd0, 0x0e30}, + {0x0dd1, 0x0e31}, + {0x0dd2, 0x0e32}, + {0x0dd3, 0x0e33}, + {0x0dd4, 0x0e34}, + {0x0dd5, 0x0e35}, + {0x0dd6, 0x0e36}, + {0x0dd7, 0x0e37}, + {0x0dd8, 0x0e38}, + {0x0dd9, 0x0e39}, + {0x0dda, 0x0e3a}, + {0x0ddf, 0x0e3f}, + {0x0de0, 0x0e40}, + {0x0de1, 0x0e41}, + {0x0de2, 0x0e42}, + {0x0de3, 0x0e43}, + {0x0de4, 0x0e44}, + {0x0de5, 0x0e45}, + {0x0de6, 0x0e46}, + {0x0de7, 0x0e47}, + {0x0de8, 0x0e48}, + {0x0de9, 0x0e49}, + {0x0dea, 0x0e4a}, + {0x0deb, 0x0e4b}, + {0x0dec, 0x0e4c}, + {0x0ded, 0x0e4d}, + {0x0df0, 0x0e50}, + {0x0df1, 0x0e51}, + {0x0df2, 0x0e52}, + {0x0df3, 0x0e53}, + {0x0df4, 0x0e54}, + {0x0df5, 0x0e55}, + {0x0df6, 0x0e56}, + {0x0df7, 0x0e57}, + {0x0df8, 0x0e58}, + {0x0df9, 0x0e59}, + {0x0ea1, 0x3131}, + {0x0ea2, 0x3132}, + {0x0ea3, 0x3133}, + {0x0ea4, 0x3134}, + {0x0ea5, 0x3135}, + {0x0ea6, 0x3136}, + {0x0ea7, 0x3137}, + {0x0ea8, 0x3138}, + {0x0ea9, 0x3139}, + {0x0eaa, 0x313a}, + {0x0eab, 0x313b}, + {0x0eac, 0x313c}, + {0x0ead, 0x313d}, + {0x0eae, 0x313e}, + {0x0eaf, 0x313f}, + {0x0eb0, 0x3140}, + {0x0eb1, 0x3141}, + {0x0eb2, 0x3142}, + {0x0eb3, 0x3143}, + {0x0eb4, 0x3144}, + {0x0eb5, 0x3145}, + {0x0eb6, 0x3146}, + {0x0eb7, 0x3147}, + {0x0eb8, 0x3148}, + {0x0eb9, 0x3149}, + {0x0eba, 0x314a}, + {0x0ebb, 0x314b}, + {0x0ebc, 0x314c}, + {0x0ebd, 0x314d}, + {0x0ebe, 0x314e}, + {0x0ebf, 0x314f}, + {0x0ec0, 0x3150}, + {0x0ec1, 0x3151}, + {0x0ec2, 0x3152}, + {0x0ec3, 0x3153}, + {0x0ec4, 0x3154}, + {0x0ec5, 0x3155}, + {0x0ec6, 0x3156}, + {0x0ec7, 0x3157}, + {0x0ec8, 0x3158}, + {0x0ec9, 0x3159}, + {0x0eca, 0x315a}, + {0x0ecb, 0x315b}, + {0x0ecc, 0x315c}, + {0x0ecd, 0x315d}, + {0x0ece, 0x315e}, + {0x0ecf, 0x315f}, + {0x0ed0, 0x3160}, + {0x0ed1, 0x3161}, + {0x0ed2, 0x3162}, + {0x0ed3, 0x3163}, + {0x0ed4, 0x11a8}, + {0x0ed5, 0x11a9}, + {0x0ed6, 0x11aa}, + {0x0ed7, 0x11ab}, + {0x0ed8, 0x11ac}, + {0x0ed9, 0x11ad}, + {0x0eda, 0x11ae}, + {0x0edb, 0x11af}, + {0x0edc, 0x11b0}, + {0x0edd, 0x11b1}, + {0x0ede, 0x11b2}, + {0x0edf, 0x11b3}, + {0x0ee0, 0x11b4}, + {0x0ee1, 0x11b5}, + {0x0ee2, 0x11b6}, + {0x0ee3, 0x11b7}, + {0x0ee4, 0x11b8}, + {0x0ee5, 0x11b9}, + {0x0ee6, 0x11ba}, + {0x0ee7, 0x11bb}, + {0x0ee8, 0x11bc}, + {0x0ee9, 0x11bd}, + {0x0eea, 0x11be}, + {0x0eeb, 0x11bf}, + {0x0eec, 0x11c0}, + {0x0eed, 0x11c1}, + {0x0eee, 0x11c2}, + {0x0eef, 0x316d}, + {0x0ef0, 0x3171}, + {0x0ef1, 0x3178}, + {0x0ef2, 0x317f}, + {0x0ef3, 0x3181}, + {0x0ef4, 0x3184}, + {0x0ef5, 0x3186}, + {0x0ef6, 0x318d}, + {0x0ef7, 0x318e}, + {0x0ef8, 0x11eb}, + {0x0ef9, 0x11f0}, + {0x0efa, 0x11f9}, + {0x0eff, 0x20a9}, #if 0 - /* FIXME: there is no keysym 0x13a4? But 0x20ac is EuroSign in both - keysym and Unicode */ - { 0x13a4, 0x20ac }, + /* FIXME: there is no keysym 0x13a4? But 0x20ac is EuroSign in both + keysym and Unicode */ + {0x13a4, 0x20ac}, #endif - { 0x13bc, 0x0152 }, - { 0x13bd, 0x0153 }, - { 0x13be, 0x0178 }, - { 0x20ac, 0x20ac }, + {0x13bc, 0x0152}, + {0x13bd, 0x0153}, + {0x13be, 0x0178}, + {0x20ac, 0x20ac}, - /* Special function keys. */ + /* Special function keys. */ - { 0xff08, 0x0008 }, /* XK_BackSpace */ - { 0xff09, 0x0009 }, /* XK_Tab */ - { 0xff0a, 0x000a }, /* XK_Linefeed */ - { 0xff0d, 0x000d }, /* XK_Return */ - { 0xff13, 0x0013 }, /* XK_Pause */ - { 0xff1b, 0x001b }, /* XK_Escape */ - { 0xff50, 0x0001 }, /* XK_Home */ - { 0xff51, 0x001c }, /* XK_Left */ - { 0xff52, 0x001e }, /* XK_Up */ - { 0xff53, 0x001d }, /* XK_Right */ - { 0xff54, 0x001f }, /* XK_Down */ - { 0xff55, 0x000b }, /* XK_Prior */ - { 0xff56, 0x000c }, /* XK_Next */ - { 0xff57, 0x0004 }, /* XK_End */ - { 0xff6a, 0x0005 }, /* XK_Help */ - { 0xffff, 0x007f }, /* XK_Delete */ + {0xff08, 0x0008}, /* XK_BackSpace */ + {0xff09, 0x0009}, /* XK_Tab */ + {0xff0a, 0x000a}, /* XK_Linefeed */ + {0xff0d, 0x000d}, /* XK_Return */ + {0xff13, 0x0013}, /* XK_Pause */ + {0xff1b, 0x001b}, /* XK_Escape */ + {0xff50, 0x0001}, /* XK_Home */ + {0xff51, 0x001c}, /* XK_Left */ + {0xff52, 0x001e}, /* XK_Up */ + {0xff53, 0x001d}, /* XK_Right */ + {0xff54, 0x001f}, /* XK_Down */ + {0xff55, 0x000b}, /* XK_Prior */ + {0xff56, 0x000c}, /* XK_Next */ + {0xff57, 0x0004}, /* XK_End */ + {0xff6a, 0x0005}, /* XK_Help */ + {0xffff, 0x007f}, /* XK_Delete */ }; -long keysym2ucs(int keysym) +long +keysym2ucs(int keysym) { int min = 0; int max = sizeof(keysymtab) / sizeof(struct codepair) - 1; @@ -841,33 +842,35 @@ long keysym2ucs(int keysym) /* also check for directly encoded 24-bit UCS characters */ if ((keysym & 0xff000000) == 0x01000000) - return keysym & 0x00ffffff; + return keysym & 0x00ffffff; /* binary search in table */ while (max >= min) { - mid = (min + max) / 2; - if (keysymtab[mid].keysym < keysym) - min = mid + 1; - else if (keysymtab[mid].keysym > keysym) - max = mid - 1; - else { - /* found it */ - return keysymtab[mid].ucs; - } + mid = (min + max) / 2; + if (keysymtab[mid].keysym < keysym) + min = mid + 1; + else if (keysymtab[mid].keysym > keysym) + max = mid - 1; + else { + /* found it */ + return keysymtab[mid].ucs; + } } /* no matching Unicode value found */ return -1; } -static int reverse_compare (const void *a, const void *b) +static int +reverse_compare(const void *a, const void *b) { const struct codepair *ca = a, *cb = b; return ca->ucs - cb->ucs; } -int ucs2keysym(long ucs) +int +ucs2keysym(long ucs) { static struct codepair *reverse_keysymtab; @@ -875,33 +878,30 @@ int ucs2keysym(long ucs) int max = sizeof(keysymtab) / sizeof(struct codepair) - 1; int mid; - if (reverse_keysymtab == NULL) - { - reverse_keysymtab = malloc (sizeof (keysymtab)); - memcpy (reverse_keysymtab, keysymtab, sizeof (keysymtab)); + if (reverse_keysymtab == NULL) { + reverse_keysymtab = malloc(sizeof(keysymtab)); + memcpy(reverse_keysymtab, keysymtab, sizeof(keysymtab)); - qsort (reverse_keysymtab, - sizeof (keysymtab) / sizeof (struct codepair), - sizeof (struct codepair), - reverse_compare); + qsort(reverse_keysymtab, + sizeof(keysymtab) / sizeof(struct codepair), + sizeof(struct codepair), reverse_compare); } /* first check for Latin-1 characters (1:1 mapping) */ - if ((ucs >= 0x0020 && ucs <= 0x007e) || - (ucs >= 0x00a0 && ucs <= 0x00ff)) + if ((ucs >= 0x0020 && ucs <= 0x007e) || (ucs >= 0x00a0 && ucs <= 0x00ff)) return ucs; /* binary search in table */ while (max >= min) { - mid = (min + max) / 2; - if (reverse_keysymtab[mid].ucs < ucs) - min = mid + 1; - else if (reverse_keysymtab[mid].ucs > ucs) - max = mid - 1; - else { - /* found it */ - return reverse_keysymtab[mid].keysym; - } + mid = (min + max) / 2; + if (reverse_keysymtab[mid].ucs < ucs) + min = mid + 1; + else if (reverse_keysymtab[mid].ucs > ucs) + max = mid - 1; + else { + /* found it */ + return reverse_keysymtab[mid].keysym; + } } /* finally, assume a directly encoded 24-bit UCS character */ diff --git a/xorg-server/hw/xquartz/mach-startup/bundle-main.c b/xorg-server/hw/xquartz/mach-startup/bundle-main.c index 94c606823..7a53803da 100644 --- a/xorg-server/hw/xquartz/mach-startup/bundle-main.c +++ b/xorg-server/hw/xquartz/mach-startup/bundle-main.c @@ -69,8 +69,13 @@ void DarwinListenOnOpenFD(int fd); extern aslclient aslc; /* Ditto, from os/log.c */ -extern void ErrorF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2); -extern void FatalError(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2) _X_NORETURN; +extern void +ErrorF(const char *f, ...) +_X_ATTRIBUTE_PRINTF(1, 2); +extern void +FatalError(const char *f, ...) +_X_ATTRIBUTE_PRINTF(1, 2) + _X_NORETURN; extern int noPanoramiXExtension; @@ -85,16 +90,19 @@ extern int noPanoramiXExtension; #define XSERVER_VERSION "?" #endif -static char __crashreporter_info_buff__[4096] = {0}; -static const char *__crashreporter_info__ __attribute__((__used__)) = &__crashreporter_info_buff__[0]; +static char __crashreporter_info_buff__[4096] = { 0 }; + +static const char *__crashreporter_info__ __attribute__ ((__used__)) = + &__crashreporter_info_buff__[0]; #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 // This is actually a toolchain requirement, but I'm not sure the correct check, // but it should be fine to just only include it for Leopard and later. This line // just tells the linker to never strip this symbol (such as for space optimization) -asm (".desc ___crashreporter_info__, 0x10"); +asm(".desc ___crashreporter_info__, 0x10"); #endif -static const char *__crashreporter_info__base = "X.Org X Server " XSERVER_VERSION " Build Date: " BUILD_DATE; +static const char *__crashreporter_info__base = + "X.Org X Server " XSERVER_VERSION " Build Date: " BUILD_DATE; char *bundle_id_prefix = NULL; static char *server_bootstrap_name = NULL; @@ -113,16 +121,18 @@ static char *pref_startx_script; #ifndef HAVE_LIBDISPATCH /*** Pthread Magics ***/ -static pthread_t create_thread(void *(*func)(void *), void *arg) { +static pthread_t +create_thread(void *(*func) (void *), void *arg) +{ pthread_attr_t attr; pthread_t tid; - - pthread_attr_init (&attr); - pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM); - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&tid, &attr, func, arg); - pthread_attr_destroy (&attr); - + + pthread_attr_init(&attr); + pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&tid, &attr, func, arg); + pthread_attr_destroy(&attr); + return tid; } #endif @@ -130,11 +140,13 @@ static pthread_t create_thread(void *(*func)(void *), void *arg) { /*** Mach-O IPC Stuffs ***/ union MaxMsgSize { - union __RequestUnion__mach_startup_subsystem req; - union __ReplyUnion__mach_startup_subsystem rep; + union __RequestUnion__mach_startup_subsystem req; + union __ReplyUnion__mach_startup_subsystem rep; }; -static mach_port_t checkin_or_register(char *bname) { +static mach_port_t +checkin_or_register(char *bname) +{ kern_return_t kr; mach_port_t mp; @@ -150,7 +162,8 @@ static mach_port_t checkin_or_register(char *bname) { exit(EXIT_FAILURE); } - kr = mach_port_insert_right(mach_task_self(), mp, mp, MACH_MSG_TYPE_MAKE_SEND); + kr = mach_port_insert_right(mach_task_self(), mp, mp, + MACH_MSG_TYPE_MAKE_SEND); if (kr != KERN_SUCCESS) { ErrorF("mach_port_insert_right(): %s\n", mach_error_string(kr)); exit(EXIT_FAILURE); @@ -158,7 +171,7 @@ static mach_port_t checkin_or_register(char *bname) { #ifdef __clang__ #pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" // bootstrap_register +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // bootstrap_register #endif kr = bootstrap_register(bootstrap_port, bname, mp); #ifdef __clang__ @@ -174,23 +187,25 @@ static mach_port_t checkin_or_register(char *bname) { } /*** $DISPLAY handoff ***/ -static int accept_fd_handoff(int connected_fd) { +static int +accept_fd_handoff(int connected_fd) +{ int launchd_fd; - + char databuf[] = "display"; struct iovec iov[1]; - + union { struct cmsghdr hdr; char bytes[CMSG_SPACE(sizeof(int))]; } buf; - + struct msghdr msg; struct cmsghdr *cmsg; iov[0].iov_base = databuf; - iov[0].iov_len = sizeof(databuf); - + iov[0].iov_len = sizeof(databuf); + msg.msg_iov = iov; msg.msg_iovlen = 1; msg.msg_control = buf.bytes; @@ -198,23 +213,25 @@ static int accept_fd_handoff(int connected_fd) { msg.msg_name = 0; msg.msg_namelen = 0; msg.msg_flags = 0; - - cmsg = CMSG_FIRSTHDR (&msg); + + cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN(sizeof(int)); - + msg.msg_controllen = cmsg->cmsg_len; - - *((int*)CMSG_DATA(cmsg)) = -1; - - if(recvmsg(connected_fd, &msg, 0) < 0) { - ErrorF("X11.app: Error receiving $DISPLAY file descriptor. recvmsg() error: %s\n", strerror(errno)); + + *((int *) CMSG_DATA(cmsg)) = -1; + + if (recvmsg(connected_fd, &msg, 0) < 0) { + ErrorF + ("X11.app: Error receiving $DISPLAY file descriptor. recvmsg() error: %s\n", + strerror(errno)); return -1; } - - launchd_fd = *((int*)CMSG_DATA(cmsg)); - + + launchd_fd = *((int *) CMSG_DATA(cmsg)); + return launchd_fd; } @@ -227,10 +244,14 @@ typedef struct { * descriptor for the new connection to accept_fd_handoff() */ #ifdef HAVE_LIBDISPATCH -static void socket_handoff(socket_handoff_t *handoff_data) { +static void +socket_handoff(socket_handoff_t * handoff_data) +{ #else -static void *socket_handoff_thread(void *arg) { - socket_handoff_t *handoff_data = (socket_handoff_t *)arg; +static void * +socket_handoff_thread(void *arg) +{ + socket_handoff_t *handoff_data = (socket_handoff_t *) arg; #endif int launchd_fd = -1; @@ -239,17 +260,20 @@ static void *socket_handoff_thread(void *arg) { /* Now actually get the passed file descriptor from this connection * If we encounter an error, keep listening. */ - while(launchd_fd == -1) { + while (launchd_fd == -1) { connected_fd = accept(handoff_data->fd, NULL, NULL); - if(connected_fd == -1) { - ErrorF("X11.app: Failed to accept incoming connection on socket (fd=%d): %s\n", handoff_data->fd, strerror(errno)); + if (connected_fd == -1) { + ErrorF + ("X11.app: Failed to accept incoming connection on socket (fd=%d): %s\n", + handoff_data->fd, strerror(errno)); sleep(2); continue; } launchd_fd = accept_fd_handoff(connected_fd); - if(launchd_fd == -1) - ErrorF("X11.app: Error receiving $DISPLAY file descriptor, no descriptor received? Waiting for another connection.\n"); + if (launchd_fd == -1) + ErrorF + ("X11.app: Error receiving $DISPLAY file descriptor, no descriptor received? Waiting for another connection.\n"); close(connected_fd); } @@ -257,8 +281,10 @@ static void *socket_handoff_thread(void *arg) { close(handoff_data->fd); unlink(handoff_data->filename); free(handoff_data); - - ErrorF("X11.app Handing off fd to server thread via DarwinListenOnOpenFD(%d)\n", launchd_fd); + + ErrorF + ("X11.app Handing off fd to server thread via DarwinListenOnOpenFD(%d)\n", + launchd_fd); DarwinListenOnOpenFD(launchd_fd); #ifndef HAVE_LIBDISPATCH @@ -266,67 +292,78 @@ static void *socket_handoff_thread(void *arg) { #endif } -static int create_socket(char *filename_out) { +static int +create_socket(char *filename_out) +{ struct sockaddr_un servaddr_un; struct sockaddr *servaddr; socklen_t servaddr_len; int ret_fd; size_t try, try_max; - - for(try=0, try_max=5; try < try_max; try++) { + + for (try = 0, try_max = 5; try < try_max; try++) { tmpnam(filename_out); - + /* Setup servaddr_un */ - memset (&servaddr_un, 0, sizeof (struct sockaddr_un)); + memset(&servaddr_un, 0, sizeof(struct sockaddr_un)); servaddr_un.sun_family = AF_UNIX; - strlcpy(servaddr_un.sun_path, filename_out, sizeof(servaddr_un.sun_path)); - + strlcpy(servaddr_un.sun_path, filename_out, + sizeof(servaddr_un.sun_path)); + servaddr = (struct sockaddr *) &servaddr_un; - servaddr_len = sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) + strlen(filename_out); - + servaddr_len = + sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) + + strlen(filename_out); + ret_fd = socket(PF_UNIX, SOCK_STREAM, 0); - if(ret_fd == -1) { - ErrorF("X11.app: Failed to create socket (try %d / %d): %s - %s\n", (int)try+1, (int)try_max, filename_out, strerror(errno)); + if (ret_fd == -1) { + ErrorF("X11.app: Failed to create socket (try %d / %d): %s - %s\n", + (int) try + 1, (int) try_max, filename_out, strerror(errno)); continue; } - - if(bind(ret_fd, servaddr, servaddr_len) != 0) { - ErrorF("X11.app: Failed to bind socket: %d - %s\n", errno, strerror(errno)); + + if (bind(ret_fd, servaddr, servaddr_len) != 0) { + ErrorF("X11.app: Failed to bind socket: %d - %s\n", errno, + strerror(errno)); close(ret_fd); return 0; } - - if(listen(ret_fd, 10) != 0) { - ErrorF("X11.app: Failed to listen to socket: %s - %d - %s\n", filename_out, errno, strerror(errno)); + + if (listen(ret_fd, 10) != 0) { + ErrorF("X11.app: Failed to listen to socket: %s - %d - %s\n", + filename_out, errno, strerror(errno)); close(ret_fd); return 0; } - + #ifdef DEBUG - ErrorF("X11.app: Listening on socket for fd handoff: (%d) %s\n", ret_fd, filename_out); + ErrorF("X11.app: Listening on socket for fd handoff: (%d) %s\n", + ret_fd, filename_out); #endif - + return ret_fd; } - + return 0; } static int launchd_socket_handed_off = 0; -kern_return_t do_request_fd_handoff_socket(mach_port_t port, string_t filename) { +kern_return_t +do_request_fd_handoff_socket(mach_port_t port, string_t filename) +{ socket_handoff_t *handoff_data; - + launchd_socket_handed_off = 1; - handoff_data = (socket_handoff_t *)calloc(1,sizeof(socket_handoff_t)); - if(!handoff_data) { + handoff_data = (socket_handoff_t *) calloc(1, sizeof(socket_handoff_t)); + if (!handoff_data) { ErrorF("X11.app: Error allocating memory for handoff_data\n"); return KERN_FAILURE; } handoff_data->fd = create_socket(handoff_data->filename); - if(!handoff_data->fd) { + if (!handoff_data->fd) { free(handoff_data); return KERN_FAILURE; } @@ -334,71 +371,78 @@ kern_return_t do_request_fd_handoff_socket(mach_port_t port, string_t filename) strlcpy(filename, handoff_data->filename, STRING_T_SIZE); #ifdef HAVE_LIBDISPATCH - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{ - socket_handoff(handoff_data); - }); + dispatch_async(dispatch_get_global_queue + (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { + socket_handoff(handoff_data);} + ); #else create_thread(socket_handoff_thread, handoff_data); #endif - + #ifdef DEBUG - ErrorF("X11.app: Thread created for handoff. Returning success to tell caller to connect and push the fd.\n"); + ErrorF + ("X11.app: Thread created for handoff. Returning success to tell caller to connect and push the fd.\n"); #endif return KERN_SUCCESS; } -kern_return_t do_request_pid(mach_port_t port, int *my_pid) { +kern_return_t +do_request_pid(mach_port_t port, int *my_pid) +{ *my_pid = getpid(); return KERN_SUCCESS; } /*** Server Startup ***/ -kern_return_t do_start_x11_server(mach_port_t port, string_array_t argv, - mach_msg_type_number_t argvCnt, - string_array_t envp, - mach_msg_type_number_t envpCnt) { +kern_return_t +do_start_x11_server(mach_port_t port, string_array_t argv, + mach_msg_type_number_t argvCnt, + string_array_t envp, mach_msg_type_number_t envpCnt) +{ /* And now back to char ** */ char **_argv = alloca((argvCnt + 1) * sizeof(char *)); char **_envp = alloca((envpCnt + 1) * sizeof(char *)); size_t i; - + /* If we didn't get handed a launchd DISPLAY socket, we should * unset DISPLAY or we can run into problems with pbproxy */ - if(!launchd_socket_handed_off) { + if (!launchd_socket_handed_off) { ErrorF("X11.app: No launchd socket handed off, unsetting DISPLAY\n"); unsetenv("DISPLAY"); } - - if(!_argv || !_envp) { + + if (!_argv || !_envp) { return KERN_FAILURE; } ErrorF("X11.app: do_start_x11_server(): argc=%d\n", argvCnt); - for(i=0; i < argvCnt; i++) { + for (i = 0; i < argvCnt; i++) { _argv[i] = argv[i]; - ErrorF("\targv[%u] = %s\n", (unsigned)i, argv[i]); + ErrorF("\targv[%u] = %s\n", (unsigned) i, argv[i]); } _argv[argvCnt] = NULL; - - for(i=0; i < envpCnt; i++) { + + for (i = 0; i < envpCnt; i++) { _envp[i] = envp[i]; } _envp[envpCnt] = NULL; - - if(server_main(argvCnt, _argv, _envp) == 0) + + if (server_main(argvCnt, _argv, _envp) == 0) return KERN_SUCCESS; else return KERN_FAILURE; } -static int startup_trigger(int argc, char **argv, char **envp) { +static int +startup_trigger(int argc, char **argv, char **envp) +{ Display *display; const char *s; - + /* Take care of the case where we're called like a normal DDX */ - if(argc > 1 && argv[1][0] == ':') { + if (argc > 1 && argv[1][0] == ':') { size_t i; kern_return_t kr; mach_port_t mp; @@ -407,32 +451,35 @@ static int startup_trigger(int argc, char **argv, char **envp) { /* We need to count envp */ int envpc; - for(envpc=0; envp[envpc]; envpc++); + + for (envpc = 0; envp[envpc]; envpc++); /* We have fixed-size string lengths due to limitations in IPC, * so we need to copy our argv and envp. */ - newargv = (string_array_t)alloca(argc * sizeof(string_t)); - newenvp = (string_array_t)alloca(envpc * sizeof(string_t)); - - if(!newargv || !newenvp) { + newargv = (string_array_t) alloca(argc * sizeof(string_t)); + newenvp = (string_array_t) alloca(envpc * sizeof(string_t)); + + if (!newargv || !newenvp) { ErrorF("Memory allocation failure\n"); exit(EXIT_FAILURE); } - - for(i=0; i < argc; i++) { + + for (i = 0; i < argc; i++) { strlcpy(newargv[i], argv[i], STRING_T_SIZE); } - for(i=0; i < envpc; i++) { + for (i = 0; i < envpc; i++) { strlcpy(newenvp[i], envp[i], STRING_T_SIZE); } kr = bootstrap_look_up(bootstrap_port, server_bootstrap_name, &mp); if (kr != KERN_SUCCESS) { #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - ErrorF("bootstrap_look_up(%s): %s\n", server_bootstrap_name, bootstrap_strerror(kr)); + ErrorF("bootstrap_look_up(%s): %s\n", server_bootstrap_name, + bootstrap_strerror(kr)); #else - ErrorF("bootstrap_look_up(%s): %ul\n", server_bootstrap_name, (unsigned long)kr); + ErrorF("bootstrap_look_up(%s): %ul\n", server_bootstrap_name, + (unsigned long) kr); #endif exit(EXIT_FAILURE); } @@ -448,10 +495,10 @@ static int startup_trigger(int argc, char **argv, char **envp) { /* If we have a process serial number and it's our only arg, act as if * the user double clicked the app bundle: launch app_to_run if possible */ - if(argc == 1 || (argc == 2 && !strncmp(argv[1], "-psn_", 5))) { + if (argc == 1 || (argc == 2 && !strncmp(argv[1], "-psn_", 5))) { /* Now, try to open a display, if so, run the launcher */ display = XOpenDisplay(NULL); - if(display) { + if (display) { /* Could open the display, start the launcher */ XCloseDisplay(display); @@ -460,31 +507,41 @@ static int startup_trigger(int argc, char **argv, char **envp) { } /* Start the server */ - if((s = getenv("DISPLAY"))) { - ErrorF("X11.app: Could not connect to server (DISPLAY=\"%s\", unsetting). Starting X server.\n", s); + if ((s = getenv("DISPLAY"))) { + ErrorF + ("X11.app: Could not connect to server (DISPLAY=\"%s\", unsetting). Starting X server.\n", + s); unsetenv("DISPLAY"); - } else { - ErrorF("X11.app: Could not connect to server (DISPLAY is not set). Starting X server.\n"); + } + else { + ErrorF + ("X11.app: Could not connect to server (DISPLAY is not set). Starting X server.\n"); } return execute(pref_startx_script); } /** Setup the environment we want our child processes to inherit */ -static void ensure_path(const char *dir) { +static void +ensure_path(const char *dir) +{ char buf[1024], *temp; - + /* Make sure /usr/X11/bin is in the $PATH */ temp = getenv("PATH"); - if(temp == NULL || temp[0] == 0) { - snprintf(buf, sizeof(buf), "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:%s", dir); + if (temp == NULL || temp[0] == 0) { + snprintf(buf, sizeof(buf), + "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:%s", dir); setenv("PATH", buf, TRUE); - } else if(strnstr(temp, X11BINDIR, sizeof(temp)) == NULL) { + } + else if (strnstr(temp, X11BINDIR, sizeof(temp)) == NULL) { snprintf(buf, sizeof(buf), "%s:%s", temp, dir); setenv("PATH", buf, TRUE); } } -static void setup_console_redirect(const char *bundle_id) { +static void +setup_console_redirect(const char *bundle_id) +{ char *asl_sender; char *asl_facility; @@ -493,7 +550,7 @@ static void setup_console_redirect(const char *bundle_id) { asl_facility = strdup(bundle_id); assert(asl_facility); - if(strcmp(asl_facility + strlen(asl_facility) - 4, ".X11") == 0) + if (strcmp(asl_facility + strlen(asl_facility) - 4, ".X11") == 0) asl_facility[strlen(asl_facility) - 4] = '\0'; assert(aslc = asl_open(asl_sender, asl_facility, ASL_OPT_NO_DELAY)); @@ -505,7 +562,9 @@ static void setup_console_redirect(const char *bundle_id) { xq_asl_capture_fd(aslc, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO); } -static void setup_env(void) { +static void +setup_env(void) +{ char *temp; const char *pds = NULL; const char *disp = getenv("DISPLAY"); @@ -515,81 +574,93 @@ static void setup_env(void) { * quartz-wm and the Xquartz stub's MachIPC) */ CFBundleRef bundle = CFBundleGetMainBundle(); - if(bundle) { + + if (bundle) { CFStringRef pd = CFBundleGetIdentifier(bundle); - if(pd) { + + if (pd) { pds = CFStringGetCStringPtr(pd, 0); } } /* fallback to hardcoded value if we can't discover it */ - if(!pds) { - pds = BUNDLE_ID_PREFIX".X11"; + if (!pds) { + pds = BUNDLE_ID_PREFIX ".X11"; } setup_console_redirect(pds); server_bootstrap_name = strdup(pds); - if(!server_bootstrap_name) { + if (!server_bootstrap_name) { ErrorF("X11.app: Memory allocation error.\n"); exit(1); } setenv("X11_PREFS_DOMAIN", server_bootstrap_name, 1); - + len = strlen(server_bootstrap_name); bundle_id_prefix = malloc(sizeof(char) * (len - 3)); - if(!bundle_id_prefix) { + if (!bundle_id_prefix) { ErrorF("X11.app: Memory allocation error.\n"); exit(1); } strlcpy(bundle_id_prefix, server_bootstrap_name, len - 3); - + /* We need to unset DISPLAY if it is not our socket */ - if(disp) { + if (disp) { /* s = basename(disp) */ const char *d, *s; - for(s = NULL, d = disp; *d; d++) { - if(*d == '/') + + for (s = NULL, d = disp; *d; d++) { + if (*d == '/') s = d + 1; } - if(s && *s) { - if(strcmp(bundle_id_prefix, "org.x") == 0 && strcmp(s, ":0") == 0) { - ErrorF("X11.app: Detected old style launchd DISPLAY, please update xinit.\n"); - } else { - temp = (char *)malloc(sizeof(char) * len); - if(!temp) { - ErrorF("X11.app: Memory allocation error creating space for socket name test.\n"); + if (s && *s) { + if (strcmp(bundle_id_prefix, "org.x") == 0 && strcmp(s, ":0") == 0) { + ErrorF + ("X11.app: Detected old style launchd DISPLAY, please update xinit.\n"); + } + else { + temp = (char *) malloc(sizeof(char) * len); + if (!temp) { + ErrorF + ("X11.app: Memory allocation error creating space for socket name test.\n"); exit(1); } strlcpy(temp, bundle_id_prefix, len); strlcat(temp, ":0", len); - - if(strcmp(temp, s) != 0) { + + if (strcmp(temp, s) != 0) { /* If we don't have a match, unset it. */ - ErrorF("X11.app: DISPLAY (\"%s\") does not match our id (\"%s\"), unsetting.\n", disp, bundle_id_prefix); + ErrorF + ("X11.app: DISPLAY (\"%s\") does not match our id (\"%s\"), unsetting.\n", + disp, bundle_id_prefix); unsetenv("DISPLAY"); } free(temp); } - } else { + } + else { /* The DISPLAY environment variable is not formatted like a launchd socket, so reset. */ - ErrorF("X11.app: DISPLAY does not look like a launchd set variable, unsetting.\n"); + ErrorF + ("X11.app: DISPLAY does not look like a launchd set variable, unsetting.\n"); unsetenv("DISPLAY"); } } /* Make sure PATH is right */ ensure_path(X11BINDIR); - + /* cd $HOME */ temp = getenv("HOME"); - if(temp != NULL && temp[0] != '\0') + if (temp != NULL && temp[0] != '\0') chdir(temp); } /*** Main ***/ -int main(int argc, char **argv, char **envp) { +int +main(int argc, char **argv, char **envp) +{ Bool listenOnly = FALSE; int i; mach_msg_size_t mxmsgsz = sizeof(union MaxMsgSize) + MAX_TRAILER_SIZE; @@ -598,31 +669,32 @@ int main(int argc, char **argv, char **envp) { /* Setup our environment for our children */ setup_env(); - + /* The server must not run the PanoramiX operations. */ noPanoramiXExtension = TRUE; /* Setup the initial crasherporter info */ - strlcpy(__crashreporter_info_buff__, __crashreporter_info__base, sizeof(__crashreporter_info_buff__)); - + strlcpy(__crashreporter_info_buff__, __crashreporter_info__base, + sizeof(__crashreporter_info_buff__)); + ErrorF("X11.app: main(): argc=%d\n", argc); - for(i=0; i < argc; i++) { - ErrorF("\targv[%u] = %s\n", (unsigned)i, argv[i]); - if(!strcmp(argv[i], "--listenonly")) { + for (i = 0; i < argc; i++) { + ErrorF("\targv[%u] = %s\n", (unsigned) i, argv[i]); + if (!strcmp(argv[i], "--listenonly")) { listenOnly = TRUE; } } mp = checkin_or_register(server_bootstrap_name); - if(mp == MACH_PORT_NULL) { + if (mp == MACH_PORT_NULL) { ErrorF("NULL mach service: %s", server_bootstrap_name); return EXIT_FAILURE; } - + /* Check if we need to do something other than listen, and make another * thread handle it. */ - if(!listenOnly) { + if (!listenOnly) { pid_t child1, child2; int status; @@ -632,50 +704,51 @@ int main(int argc, char **argv, char **envp) { pref_login_shell = command_from_prefs("login_shell", DEFAULT_SHELL); assert(pref_login_shell); - pref_startx_script = command_from_prefs("startx_script", DEFAULT_STARTX); + pref_startx_script = + command_from_prefs("startx_script", DEFAULT_STARTX); assert(pref_startx_script); /* Do the fork-twice trick to avoid having to reap zombies */ child1 = fork(); switch (child1) { - case -1: /* error */ - FatalError("fork() failed: %s\n", strerror(errno)); + case -1: /* error */ + FatalError("fork() failed: %s\n", strerror(errno)); - case 0: /* child1 */ - child2 = fork(); + case 0: /* child1 */ + child2 = fork(); - switch (child2) { - int max_files; + switch (child2) { + int max_files; - case -1: /* error */ - FatalError("fork() failed: %s\n", strerror(errno)); + case -1: /* error */ + FatalError("fork() failed: %s\n", strerror(errno)); - case 0: /* child2 */ - /* close all open files except for standard streams */ - max_files = sysconf(_SC_OPEN_MAX); - for(i = 3; i < max_files; i++) - close(i); + case 0: /* child2 */ + /* close all open files except for standard streams */ + max_files = sysconf(_SC_OPEN_MAX); + for (i = 3; i < max_files; i++) + close(i); - /* ensure stdin is on /dev/null */ - close(0); - open("/dev/null", O_RDONLY); + /* ensure stdin is on /dev/null */ + close(0); + open("/dev/null", O_RDONLY); - return startup_trigger(argc, argv, envp); + return startup_trigger(argc, argv, envp); - default: /* parent (child1) */ - _exit(0); - } - break; + default: /* parent (child1) */ + _exit(0); + } + break; - default: /* parent */ - waitpid(child1, &status, 0); + default: /* parent */ + waitpid(child1, &status, 0); } free(pref_app_to_run); free(pref_login_shell); free(pref_startx_script); } - + /* Main event loop */ ErrorF("Waiting for startup parameters via Mach IPC.\n"); kr = mach_msg_server(mach_startup_server, mxmsgsz, mp, 0); @@ -683,72 +756,83 @@ int main(int argc, char **argv, char **envp) { ErrorF("%s.X11(mp): %s\n", BUNDLE_ID_PREFIX, mach_error_string(kr)); return EXIT_FAILURE; } - + return EXIT_SUCCESS; } -static int execute(const char *command) { +static int +execute(const char *command) +{ const char *newargv[4]; const char **p; - + newargv[0] = pref_login_shell; newargv[1] = "-c"; newargv[2] = command; newargv[3] = NULL; - + ErrorF("X11.app: Launching %s:\n", command); - for(p=newargv; *p; p++) { - ErrorF("\targv[%ld] = %s\n", (long int)(p - newargv), *p); + for (p = newargv; *p; p++) { + ErrorF("\targv[%ld] = %s\n", (long int) (p - newargv), *p); } - execvp (newargv[0], (char * const *) newargv); - perror ("X11.app: Couldn't exec."); + execvp(newargv[0], (char *const *) newargv); + perror("X11.app: Couldn't exec."); return 1; } -static char *command_from_prefs(const char *key, const char *default_value) { +static char * +command_from_prefs(const char *key, const char *default_value) +{ char *command = NULL; - + CFStringRef cfKey; CFPropertyListRef PlistRef; - if(!key) + if (!key) return NULL; cfKey = CFStringCreateWithCString(NULL, key, kCFStringEncodingASCII); - if(!cfKey) + if (!cfKey) return NULL; - PlistRef = CFPreferencesCopyAppValue(cfKey, kCFPreferencesCurrentApplication); - + PlistRef = + CFPreferencesCopyAppValue(cfKey, kCFPreferencesCurrentApplication); + if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) { - CFStringRef cfDefaultValue = CFStringCreateWithCString(NULL, default_value, kCFStringEncodingASCII); + CFStringRef cfDefaultValue = + CFStringCreateWithCString(NULL, default_value, + kCFStringEncodingASCII); int len = strlen(default_value) + 1; - if(!cfDefaultValue) + if (!cfDefaultValue) goto command_from_prefs_out; - CFPreferencesSetAppValue(cfKey, cfDefaultValue, kCFPreferencesCurrentApplication); + CFPreferencesSetAppValue(cfKey, cfDefaultValue, + kCFPreferencesCurrentApplication); CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication); CFRelease(cfDefaultValue); - - command = (char *)malloc(len * sizeof(char)); - if(!command) + + command = (char *) malloc(len * sizeof(char)); + if (!command) goto command_from_prefs_out; strcpy(command, default_value); - } else { - int len = CFStringGetLength((CFStringRef)PlistRef) + 1; - command = (char *)malloc(len * sizeof(char)); - if(!command) + } + else { + int len = CFStringGetLength((CFStringRef) PlistRef) + 1; + + command = (char *) malloc(len * sizeof(char)); + if (!command) goto command_from_prefs_out; - CFStringGetCString((CFStringRef)PlistRef, command, len, kCFStringEncodingASCII); + CFStringGetCString((CFStringRef) PlistRef, command, len, + kCFStringEncodingASCII); } -command_from_prefs_out: + command_from_prefs_out: if (PlistRef) CFRelease(PlistRef); - if(cfKey) + if (cfKey) CFRelease(cfKey); return command; } diff --git a/xorg-server/hw/xquartz/mach-startup/launchd_fd.c b/xorg-server/hw/xquartz/mach-startup/launchd_fd.c index 8003dd177..fd1d276e3 100644 --- a/xorg-server/hw/xquartz/mach-startup/launchd_fd.c +++ b/xorg-server/hw/xquartz/mach-startup/launchd_fd.c @@ -38,54 +38,68 @@ extern aslclient aslc; -int launchd_display_fd(void) { +int +launchd_display_fd(void) +{ launch_data_t sockets_dict, checkin_request, checkin_response; launch_data_t listening_fd_array, listening_fd; /* Get launchd fd */ if ((checkin_request = launch_data_new_string(LAUNCH_KEY_CHECKIN)) == NULL) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "launch_data_new_string(\"" LAUNCH_KEY_CHECKIN "\") Unable to create string.\n"); + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "launch_data_new_string(\"" LAUNCH_KEY_CHECKIN + "\") Unable to create string.\n"); return ERROR_FD; } - + if ((checkin_response = launch_msg(checkin_request)) == NULL) { - asl_log(aslc, NULL, ASL_LEVEL_WARNING, "launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %s\n",strerror(errno)); + asl_log(aslc, NULL, ASL_LEVEL_WARNING, + "launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %s\n", + strerror(errno)); return ERROR_FD; } - + if (LAUNCH_DATA_ERRNO == launch_data_get_type(checkin_response)) { // ignore EACCES, which is common if we weren't started by launchd if (launch_data_get_errno(checkin_response) != EACCES) - asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in failed: %s\n", strerror(launch_data_get_errno(checkin_response))); + asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in failed: %s\n", + strerror(launch_data_get_errno(checkin_response))); return ERROR_FD; - } - - sockets_dict = launch_data_dict_lookup(checkin_response, LAUNCH_JOBKEY_SOCKETS); + } + + sockets_dict = + launch_data_dict_lookup(checkin_response, LAUNCH_JOBKEY_SOCKETS); if (NULL == sockets_dict) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in: no sockets found to answer requests on!\n"); + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "launchd check-in: no sockets found to answer requests on!\n"); return ERROR_FD; } - + if (launch_data_dict_get_count(sockets_dict) > 1) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in: some sockets will be ignored!\n"); + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "launchd check-in: some sockets will be ignored!\n"); return ERROR_FD; } - - listening_fd_array = launch_data_dict_lookup(sockets_dict, BUNDLE_ID_PREFIX":0"); + + listening_fd_array = + launch_data_dict_lookup(sockets_dict, BUNDLE_ID_PREFIX ":0"); if (NULL == listening_fd_array) { listening_fd_array = launch_data_dict_lookup(sockets_dict, ":0"); if (NULL == listening_fd_array) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in: No known sockets found to answer requests on! \"%s:0\" and \":0\" failed.\n", BUNDLE_ID_PREFIX); + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "launchd check-in: No known sockets found to answer requests on! \"%s:0\" and \":0\" failed.\n", + BUNDLE_ID_PREFIX); return ERROR_FD; } } - - if (launch_data_array_get_count(listening_fd_array)!=1) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in: Expected 1 socket from launchd, got %u)\n", - (unsigned)launch_data_array_get_count(listening_fd_array)); + + if (launch_data_array_get_count(listening_fd_array) != 1) { + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "launchd check-in: Expected 1 socket from launchd, got %u)\n", + (unsigned) launch_data_array_get_count(listening_fd_array)); return ERROR_FD; } - - listening_fd=launch_data_array_get_index(listening_fd_array, 0); + + listening_fd = launch_data_array_get_index(listening_fd_array, 0); return launch_data_get_fd(listening_fd); } diff --git a/xorg-server/hw/xquartz/mach-startup/stub.c b/xorg-server/hw/xquartz/mach-startup/stub.c index d8e4abdd1..f457aaba0 100644 --- a/xorg-server/hw/xquartz/mach-startup/stub.c +++ b/xorg-server/hw/xquartz/mach-startup/stub.c @@ -58,85 +58,105 @@ static char x11_path[PATH_MAX + 1]; static pid_t x11app_pid = 0; aslclient aslc; -static void set_x11_path(void) { +static void +set_x11_path(void) +{ #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 CFURLRef appURL = NULL; - OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil, nil, &appURL); + OSStatus osstatus = + LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil, + nil, &appURL); switch (osstatus) { - case noErr: - if (appURL == NULL) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Invalid response from LSFindApplicationForInfo(%s)", - kX11AppBundleId); - exit(1); - } + case noErr: + if (appURL == NULL) { + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: Invalid response from LSFindApplicationForInfo(%s)", + kX11AppBundleId); + exit(1); + } - if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Error resolving URL for %s", kX11AppBundleId); - exit(3); - } + if (!CFURLGetFileSystemRepresentation + (appURL, true, (unsigned char *) x11_path, sizeof(x11_path))) { + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: Error resolving URL for %s", kX11AppBundleId); + exit(3); + } - strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path)); - asl_log(aslc, NULL, ASL_LEVEL_INFO, "Xquartz: X11.app = %s", x11_path); - break; - case kLSApplicationNotFoundErr: - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Unable to find application for %s", kX11AppBundleId); - exit(10); - default: - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Unable to find application for %s, error code = %d", - kX11AppBundleId, (int)osstatus); - exit(11); + strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path)); + asl_log(aslc, NULL, ASL_LEVEL_INFO, "Xquartz: X11.app = %s", x11_path); + break; + case kLSApplicationNotFoundErr: + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: Unable to find application for %s", kX11AppBundleId); + exit(10); + default: + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: Unable to find application for %s, error code = %d", + kX11AppBundleId, (int) osstatus); + exit(11); } #else /* TODO: Make Tiger smarter... but TBH, this should never get called on Tiger... */ - strlcpy(x11_path, "/Applications/Utilities/X11.app/Contents/MacOS/X11", sizeof(x11_path)); + strlcpy(x11_path, "/Applications/Utilities/X11.app/Contents/MacOS/X11", + sizeof(x11_path)); #endif } -static int connect_to_socket(const char *filename) { +static int +connect_to_socket(const char *filename) +{ struct sockaddr_un servaddr_un; struct sockaddr *servaddr; socklen_t servaddr_len; int ret_fd; /* Setup servaddr_un */ - memset (&servaddr_un, 0, sizeof (struct sockaddr_un)); + memset(&servaddr_un, 0, sizeof(struct sockaddr_un)); servaddr_un.sun_family = AF_UNIX; strlcpy(servaddr_un.sun_path, filename, sizeof(servaddr_un.sun_path)); - + servaddr = (struct sockaddr *) &servaddr_un; - servaddr_len = sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) + strlen(filename); - + servaddr_len = + sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) + + strlen(filename); + ret_fd = socket(PF_UNIX, SOCK_STREAM, 0); - if(ret_fd == -1) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Failed to create socket: %s - %s", filename, strerror(errno)); + if (ret_fd == -1) { + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: Failed to create socket: %s - %s", filename, + strerror(errno)); return -1; } - if(connect(ret_fd, servaddr, servaddr_len) < 0) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Failed to connect to socket: %s - %d - %s", filename, errno, strerror(errno)); + if (connect(ret_fd, servaddr, servaddr_len) < 0) { + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: Failed to connect to socket: %s - %d - %s", filename, + errno, strerror(errno)); close(ret_fd); return -1; } - + return ret_fd; } -static void send_fd_handoff(int connected_fd, int launchd_fd) { +static void +send_fd_handoff(int connected_fd, int launchd_fd) +{ char databuf[] = "display"; struct iovec iov[1]; - + union { struct cmsghdr hdr; char bytes[CMSG_SPACE(sizeof(int))]; } buf; - + struct msghdr msg; struct cmsghdr *cmsg; iov[0].iov_base = databuf; - iov[0].iov_len = sizeof(databuf); + iov[0].iov_len = sizeof(databuf); msg.msg_iov = iov; msg.msg_iovlen = 1; @@ -146,32 +166,39 @@ static void send_fd_handoff(int connected_fd, int launchd_fd) { msg.msg_namelen = 0; msg.msg_flags = 0; - cmsg = CMSG_FIRSTHDR (&msg); + cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN(sizeof(int)); msg.msg_controllen = cmsg->cmsg_len; - - *((int*)CMSG_DATA(cmsg)) = launchd_fd; - - if(sendmsg(connected_fd, &msg, 0) < 0) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Error sending $DISPLAY file descriptor over fd %d: %d -- %s", connected_fd, errno, strerror(errno)); + + *((int *) CMSG_DATA(cmsg)) = launchd_fd; + + if (sendmsg(connected_fd, &msg, 0) < 0) { + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: Error sending $DISPLAY file descriptor over fd %d: %d -- %s", + connected_fd, errno, strerror(errno)); return; } - asl_log(aslc, NULL, ASL_LEVEL_DEBUG, "Xquartz: Message sent. Closing handoff fd."); + asl_log(aslc, NULL, ASL_LEVEL_DEBUG, + "Xquartz: Message sent. Closing handoff fd."); close(connected_fd); } -__attribute__((__noreturn__)) -static void signal_handler(int sig) { - if(x11app_pid) +__attribute__ ((__noreturn__)) +static void +signal_handler(int sig) +{ + if (x11app_pid) kill(x11app_pid, sig); _exit(0); } -int main(int argc, char **argv, char **envp) { +int +main(int argc, char **argv, char **envp) +{ int envpc; kern_return_t kr; mach_port_t mp; @@ -185,7 +212,7 @@ int main(int argc, char **argv, char **envp) { char *asl_facility; char *server_bootstrap_name = kX11AppBundleId; - if(getenv("X11_PREFS_DOMAIN")) + if (getenv("X11_PREFS_DOMAIN")) server_bootstrap_name = getenv("X11_PREFS_DOMAIN"); asprintf(&asl_sender, "%s.stub", server_bootstrap_name); @@ -193,8 +220,8 @@ int main(int argc, char **argv, char **envp) { asl_facility = strdup(server_bootstrap_name); assert(asl_facility); - if(strcmp(asl_facility + strlen(asl_facility) - 4, ".X11") == 0) - asl_facility[strlen(asl_facility) - 4] = '\0'; + if (strcmp(asl_facility + strlen(asl_facility) - 4, ".X11") == 0) + asl_facility[strlen(asl_facility) - 4] = '\0'; assert(aslc = asl_open(asl_sender, asl_facility, ASL_OPT_NO_DELAY)); free(asl_sender); @@ -205,103 +232,119 @@ int main(int argc, char **argv, char **envp) { * time out waiting for it and will just poll for the server. */ handler = signal(SIGUSR1, SIG_IGN); - if(handler == SIG_IGN) + if (handler == SIG_IGN) kill(getppid(), SIGUSR1); signal(SIGUSR1, handler); /* Pass on SIGs to X11.app */ signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); - + /* Get the $DISPLAY FD */ launchd_fd = launchd_display_fd(); kr = bootstrap_look_up(bootstrap_port, server_bootstrap_name, &mp); - if(kr != KERN_SUCCESS) { + if (kr != KERN_SUCCESS) { pid_t child; - asl_log(aslc, NULL, ASL_LEVEL_WARNING, "Xquartz: Unable to locate waiting server: %s", server_bootstrap_name); + asl_log(aslc, NULL, ASL_LEVEL_WARNING, + "Xquartz: Unable to locate waiting server: %s", + server_bootstrap_name); set_x11_path(); /* This forking is ugly and will be cleaned up later */ child = fork(); - if(child == -1) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Could not fork: %s", strerror(errno)); + if (child == -1) { + asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Could not fork: %s", + strerror(errno)); return EXIT_FAILURE; } - if(child == 0) { + if (child == 0) { char *_argv[3]; + _argv[0] = x11_path; _argv[1] = "--listenonly"; _argv[2] = NULL; - asl_log(aslc, NULL, ASL_LEVEL_NOTICE, "Xquartz: Starting X server: %s --listenonly", x11_path); + asl_log(aslc, NULL, ASL_LEVEL_NOTICE, + "Xquartz: Starting X server: %s --listenonly", x11_path); return execvp(x11_path, _argv); } /* Try connecting for 10 seconds */ - for(i=0; i < 80; i++) { + for (i = 0; i < 80; i++) { usleep(250000); kr = bootstrap_look_up(bootstrap_port, server_bootstrap_name, &mp); - if(kr == KERN_SUCCESS) + if (kr == KERN_SUCCESS) break; } - if(kr != KERN_SUCCESS) { + if (kr != KERN_SUCCESS) { #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: bootstrap_look_up(): %s", bootstrap_strerror(kr)); + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: bootstrap_look_up(): %s", bootstrap_strerror(kr)); #else - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: bootstrap_look_up(): %ul", (unsigned long)kr); + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: bootstrap_look_up(): %ul", (unsigned long) kr); #endif return EXIT_FAILURE; } } - + /* Get X11.app's pid */ request_pid(mp, &x11app_pid); /* Handoff the $DISPLAY FD */ - if(launchd_fd != -1) { + if (launchd_fd != -1) { size_t try, try_max; int handoff_fd = -1; - for(try=0, try_max=5; try < try_max; try++) { - if(request_fd_handoff_socket(mp, handoff_socket_filename) != KERN_SUCCESS) { - asl_log(aslc, NULL, ASL_LEVEL_INFO, "Xquartz: Failed to request a socket from the server to send the $DISPLAY fd over (try %d of %d)", (int)try+1, (int)try_max); + for (try = 0, try_max = 5; try < try_max; try++) { + if (request_fd_handoff_socket(mp, handoff_socket_filename) != + KERN_SUCCESS) { + asl_log(aslc, NULL, ASL_LEVEL_INFO, + "Xquartz: Failed to request a socket from the server to send the $DISPLAY fd over (try %d of %d)", + (int) try + 1, (int) try_max); continue; } handoff_fd = connect_to_socket(handoff_socket_filename); - if(handoff_fd == -1) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Failed to connect to socket (try %d of %d)", (int)try+1, (int)try_max); + if (handoff_fd == -1) { + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: Failed to connect to socket (try %d of %d)", + (int) try + 1, (int) try_max); continue; } - asl_log(aslc, NULL, ASL_LEVEL_INFO, "Xquartz: Handoff connection established (try %d of %d) on fd %d, \"%s\". Sending message.", (int)try+1, (int)try_max, handoff_fd, handoff_socket_filename); - send_fd_handoff(handoff_fd, launchd_fd); + asl_log(aslc, NULL, ASL_LEVEL_INFO, + "Xquartz: Handoff connection established (try %d of %d) on fd %d, \"%s\". Sending message.", + (int) try + 1, (int) try_max, handoff_fd, + handoff_socket_filename); + send_fd_handoff(handoff_fd, launchd_fd); close(handoff_fd); break; } } /* Count envp */ - for(envpc=0; envp[envpc]; envpc++); - + for (envpc = 0; envp[envpc]; envpc++); + /* We have fixed-size string lengths due to limitations in IPC, * so we need to copy our argv and envp. */ - newargv = (string_array_t)calloc((1 + argc), sizeof(string_t)); - newenvp = (string_array_t)calloc((1 + envpc), sizeof(string_t)); + newargv = (string_array_t) calloc((1 + argc), sizeof(string_t)); + newenvp = (string_array_t) calloc((1 + envpc), sizeof(string_t)); - if(!newargv || !newenvp) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Memory allocation failure"); + if (!newargv || !newenvp) { + asl_log(aslc, NULL, ASL_LEVEL_ERR, + "Xquartz: Memory allocation failure"); return EXIT_FAILURE; } - - for(i=0; i < argc; i++) { + + for (i = 0; i < argc; i++) { strlcpy(newargv[i], argv[i], STRING_T_SIZE); } - for(i=0; i < envpc; i++) { + for (i = 0; i < envpc; i++) { strlcpy(newenvp[i], envp[i], STRING_T_SIZE); } @@ -311,7 +354,8 @@ int main(int argc, char **argv, char **envp) { free(newenvp); if (kr != KERN_SUCCESS) { - asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: start_x11_server: %s", mach_error_string(kr)); + asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: start_x11_server: %s", + mach_error_string(kr)); return EXIT_FAILURE; } return EXIT_SUCCESS; diff --git a/xorg-server/hw/xquartz/pbproxy/app-main.m b/xorg-server/hw/xquartz/pbproxy/app-main.m index 772c458a1..c061418d8 100644 --- a/xorg-server/hw/xquartz/pbproxy/app-main.m +++ b/xorg-server/hw/xquartz/pbproxy/app-main.m @@ -31,10 +31,10 @@ #import "x-selection.h" #include <pthread.h> -#include <unistd.h> /*for getpid*/ +#include <unistd.h> /*for getpid */ #include <Cocoa/Cocoa.h> -static const char *app_prefs_domain = BUNDLE_ID_PREFIX".xpbproxy"; +static const char *app_prefs_domain = BUNDLE_ID_PREFIX ".xpbproxy"; CFStringRef app_prefs_domain_cfstr; /* Stubs */ @@ -43,18 +43,20 @@ BOOL serverRunning = YES; pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER; -static void signal_handler (int sig) { - switch(sig) { - case SIGHUP: - xpbproxy_prefs_reload = YES; - break; - default: - _exit(EXIT_SUCCESS); +static void +signal_handler(int sig) +{ + switch (sig) { + case SIGHUP: + xpbproxy_prefs_reload = YES; + break; + default: + _exit(EXIT_SUCCESS); } } void -ErrorF(const char * f, ...) +ErrorF(const char *f, ...) { va_list args; @@ -64,7 +66,10 @@ ErrorF(const char * f, ...) } /* TODO: Have this actually log to ASL */ -void xq_asl_log (int level, const char *subsystem, const char *file, const char *function, int line, const char *fmt, ...) { +void +xq_asl_log(int level, const char *subsystem, const char *file, + const char *function, int line, const char *fmt, ...) +{ #ifdef DEBUG va_list args; @@ -74,7 +79,9 @@ void xq_asl_log (int level, const char *subsystem, const char *file, const char #endif } -int main (int argc, const char *argv[]) { +int +main(int argc, const char *argv[]) +{ const char *s; int i; @@ -84,31 +91,36 @@ int main (int argc, const char *argv[]) { xpbproxy_is_standalone = YES; - if((s = getenv("X11_PREFS_DOMAIN"))) + if ((s = getenv("X11_PREFS_DOMAIN"))) app_prefs_domain = s; for (i = 1; i < argc; i++) { - if(strcmp (argv[i], "--prefs-domain") == 0 && i+1 < argc) { + if (strcmp(argv[i], "--prefs-domain") == 0 && i + 1 < argc) { app_prefs_domain = argv[++i]; - } else if (strcmp (argv[i], "--help") == 0) { + } + else if (strcmp(argv[i], "--help") == 0) { ErrorF("usage: xpbproxy OPTIONS\n" "Pasteboard proxying for X11.\n\n" "--prefs-domain <domain> Change the domain used for reading preferences\n" - " (default: %s)\n", app_prefs_domain); + " (default: %s)\n", + app_prefs_domain); return 0; - } else { + } + else { ErrorF("usage: xpbproxy OPTIONS...\n" - "Try 'xpbproxy --help' for more information.\n"); + "Try 'xpbproxy --help' for more information.\n"); return 1; } } - - app_prefs_domain_cfstr = CFStringCreateWithCString(NULL, app_prefs_domain, kCFStringEncodingUTF8); - - signal (SIGINT, signal_handler); - signal (SIGTERM, signal_handler); - signal (SIGHUP, signal_handler); - signal (SIGPIPE, SIG_IGN); + + app_prefs_domain_cfstr = + CFStringCreateWithCString(NULL, app_prefs_domain, + kCFStringEncodingUTF8); + + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + signal(SIGHUP, signal_handler); + signal(SIGPIPE, SIG_IGN); return xpbproxy_run(); } diff --git a/xorg-server/hw/xquartz/pbproxy/main.m b/xorg-server/hw/xquartz/pbproxy/main.m index 29ce83b35..b52aec8a4 100644 --- a/xorg-server/hw/xquartz/pbproxy/main.m +++ b/xorg-server/hw/xquartz/pbproxy/main.m @@ -51,27 +51,31 @@ extern BOOL serverRunning; extern pthread_mutex_t serverRunningMutex; extern pthread_cond_t serverRunningCond; -static inline void wait_for_server_init(void) { +static inline void +wait_for_server_init(void) +{ /* If the server hasn't finished initializing, wait for it... */ - if(!serverRunning) { + if (!serverRunning) { pthread_mutex_lock(&serverRunningMutex); - while(!serverRunning) + while (!serverRunning) pthread_cond_wait(&serverRunningCond, &serverRunningMutex); pthread_mutex_unlock(&serverRunningMutex); } } -static int x_io_error_handler (Display *dpy) { +static int +x_io_error_handler(Display * dpy) +{ /* We lost our connection to the server. */ - - TRACE (); + + TRACE(); /* trigger the thread to restart? * NO - this would be to a "deeper" problem, and restarts would just * make things worse... */ #ifdef STANDALONE_XPBPROXY - if(xpbproxy_is_standalone) + if (xpbproxy_is_standalone) exit(EXIT_FAILURE); #endif @@ -80,70 +84,81 @@ static int x_io_error_handler (Display *dpy) { return 0; } -static int x_error_handler (Display *dpy, XErrorEvent *errevent) { +static int +x_error_handler(Display * dpy, XErrorEvent * errevent) +{ return 0; } -int xpbproxy_run (void) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +int +xpbproxy_run(void) +{ + NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init]; size_t i; - + wait_for_server_init(); - - for(i=0, xpbproxy_dpy=NULL; !xpbproxy_dpy && i<5; i++) { + + for (i = 0, xpbproxy_dpy = NULL; !xpbproxy_dpy && i < 5; i++) { xpbproxy_dpy = XOpenDisplay(NULL); - - if(!xpbproxy_dpy && display) { + + if (!xpbproxy_dpy && display) { char _display[32]; + snprintf(_display, sizeof(_display), ":%s", display); setenv("DISPLAY", _display, TRUE); - - xpbproxy_dpy=XOpenDisplay(_display); + + xpbproxy_dpy = XOpenDisplay(_display); } - if(!xpbproxy_dpy) + if (!xpbproxy_dpy) sleep(1); } - + if (xpbproxy_dpy == NULL) { ErrorF("xpbproxy: can't open default display\n"); [pool release]; return EXIT_FAILURE; } - - XSetIOErrorHandler (x_io_error_handler); - XSetErrorHandler (x_error_handler); - - if (!XAppleWMQueryExtension (xpbproxy_dpy, &xpbproxy_apple_wm_event_base, - &xpbproxy_apple_wm_error_base)) { + + XSetIOErrorHandler(x_io_error_handler); + XSetErrorHandler(x_error_handler); + + if (!XAppleWMQueryExtension(xpbproxy_dpy, &xpbproxy_apple_wm_event_base, + &xpbproxy_apple_wm_error_base)) { ErrorF("xpbproxy: can't open AppleWM server extension\n"); [pool release]; return EXIT_FAILURE; } - xpbproxy_have_xfixes = XFixesQueryExtension(xpbproxy_dpy, &xpbproxy_xfixes_event_base, &xpbproxy_xfixes_error_base); + xpbproxy_have_xfixes = + XFixesQueryExtension(xpbproxy_dpy, &xpbproxy_xfixes_event_base, + &xpbproxy_xfixes_error_base); + + XAppleWMSelectInput(xpbproxy_dpy, AppleWMActivationNotifyMask | + AppleWMPasteboardNotifyMask); - XAppleWMSelectInput (xpbproxy_dpy, AppleWMActivationNotifyMask | - AppleWMPasteboardNotifyMask); - - _selection_object = [[x_selection alloc] init]; - - if(!xpbproxy_input_register()) { + _selection_object =[[x_selection alloc] init]; + + if (!xpbproxy_input_register()) { [pool release]; return EXIT_FAILURE; } - + [pool release]; - + CFRunLoopRun(); return EXIT_SUCCESS; } -id xpbproxy_selection_object (void) { +id +xpbproxy_selection_object(void) +{ return _selection_object; } -Time xpbproxy_current_timestamp (void) { +Time +xpbproxy_current_timestamp(void) +{ /* FIXME: may want to fetch a timestamp from the server.. */ return CurrentTime; } diff --git a/xorg-server/hw/xquartz/pbproxy/pbproxy.h b/xorg-server/hw/xquartz/pbproxy/pbproxy.h index c80a660cc..bdb15aeca 100644 --- a/xorg-server/hw/xquartz/pbproxy/pbproxy.h +++ b/xorg-server/hw/xquartz/pbproxy/pbproxy.h @@ -65,11 +65,11 @@ extern BOOL xpbproxy_is_standalone; #endif /* from main.m */ -extern void xpbproxy_set_is_active (BOOL state); -extern BOOL xpbproxy_get_is_active (void); -extern id xpbproxy_selection_object (void); -extern Time xpbproxy_current_timestamp (void); -extern int xpbproxy_run (void); +extern void xpbproxy_set_is_active(BOOL state); +extern BOOL xpbproxy_get_is_active(void); +extern id xpbproxy_selection_object(void); +extern Time xpbproxy_current_timestamp(void); +extern int xpbproxy_run(void); extern Display *xpbproxy_dpy; extern int xpbproxy_apple_wm_event_base, xpbproxy_apple_wm_error_base; @@ -77,17 +77,21 @@ extern int xpbproxy_xfixes_event_base, xpbproxy_xfixes_error_base; extern BOOL xpbproxy_have_xfixes; /* from x-input.m */ -extern BOOL xpbproxy_input_register (void); +extern BOOL xpbproxy_input_register(void); /* os/log.c or app-main.m */ -extern void ErrorF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2); +extern void +ErrorF(const char *f, ...) +_X_ATTRIBUTE_PRINTF(1, 2); /* from darwin.h */ -_X_ATTRIBUTE_PRINTF(6,7) -extern void xq_asl_log (int level, const char *subsystem, const char *file, const char *function, int line, const char *fmt, ...); +_X_ATTRIBUTE_PRINTF(6, 7) +extern void +xq_asl_log(int level, const char *subsystem, const char *file, + const char *function, int line, const char *fmt, ...); #define ASL_LOG(level, subsystem, msg, args...) xq_asl_log(level, subsystem, __FILE__, __FUNCTION__, __LINE__, msg, ##args) #define DebugF(msg, args...) ASL_LOG(ASL_LEVEL_DEBUG, "xpbproxy", msg, ##args) #define TRACE() DebugF("TRACE") -#endif /* PBPROXY_H */ +#endif /* PBPROXY_H */ diff --git a/xorg-server/hw/xquartz/pbproxy/trick_autotools.c b/xorg-server/hw/xquartz/pbproxy/trick_autotools.c index a38f077b1..11aff526d 100644 --- a/xorg-server/hw/xquartz/pbproxy/trick_autotools.c +++ b/xorg-server/hw/xquartz/pbproxy/trick_autotools.c @@ -1,3 +1,5 @@ -int this_is_just_here_to_make_automake_work() { - return 0; +int +this_is_just_here_to_make_automake_work() +{ + return 0; } diff --git a/xorg-server/hw/xquartz/pbproxy/x-input.m b/xorg-server/hw/xquartz/pbproxy/x-input.m index ebb89980f..134bf59d8 100644 --- a/xorg-server/hw/xquartz/pbproxy/x-input.m +++ b/xorg-server/hw/xquartz/pbproxy/x-input.m @@ -48,126 +48,138 @@ BOOL xpbproxy_prefs_reload = NO; /* Timestamp when the X server last told us it's active */ static Time last_activation_time; -static void x_event_apple_wm_notify(XAppleWMNotifyEvent *e) { +static void +x_event_apple_wm_notify(XAppleWMNotifyEvent * e) +{ int type = e->type - xpbproxy_apple_wm_event_base; int kind = e->kind; /* We want to reload prefs even if we're not active */ - if(type == AppleWMActivationNotify && - kind == AppleWMReloadPreferences) - [xpbproxy_selection_object() reload_preferences]; + if (type == AppleWMActivationNotify && kind == AppleWMReloadPreferences) + [xpbproxy_selection_object()reload_preferences]; - if(![xpbproxy_selection_object() is_active]) + if (![xpbproxy_selection_object()is_active]) return; - switch (type) { - case AppleWMActivationNotify: - switch (kind) { - case AppleWMIsActive: - last_activation_time = e->time; - [xpbproxy_selection_object() x_active:e->time]; - break; - - case AppleWMIsInactive: - [xpbproxy_selection_object() x_inactive:e->time]; - break; - } + switch (type) { + case AppleWMActivationNotify: + switch (kind) { + case AppleWMIsActive: + last_activation_time = e->time; + [xpbproxy_selection_object()x_active:e->time]; break; - - case AppleWMPasteboardNotify: - switch (kind) { - case AppleWMCopyToPasteboard: - [xpbproxy_selection_object() x_copy:e->time]; - } + + case AppleWMIsInactive: + [xpbproxy_selection_object()x_inactive:e->time]; break; + } + break; + + case AppleWMPasteboardNotify: + switch (kind) { + case AppleWMCopyToPasteboard: + [xpbproxy_selection_object()x_copy:e->time]; + } + break; } } -static void xpbproxy_process_xevents(void) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - if(pool == nil) { +static void +xpbproxy_process_xevents(void) +{ + NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init]; + + if (pool == nil) { ErrorF("unable to allocate/init auto release pool!\n"); return; } - + while (XPending(xpbproxy_dpy) != 0) { XEvent e; - - XNextEvent (xpbproxy_dpy, &e); - - switch (e.type) { - case SelectionClear: - if([xpbproxy_selection_object() is_active]) - [xpbproxy_selection_object () clear_event:&e.xselectionclear]; - break; - - case SelectionRequest: - [xpbproxy_selection_object () request_event:&e.xselectionrequest]; - break; - - case SelectionNotify: - [xpbproxy_selection_object () notify_event:&e.xselection]; - break; - - case PropertyNotify: - [xpbproxy_selection_object () property_event:&e.xproperty]; - break; - - default: - if(e.type >= xpbproxy_apple_wm_event_base && - e.type < xpbproxy_apple_wm_event_base + AppleWMNumberEvents) { - x_event_apple_wm_notify((XAppleWMNotifyEvent *) &e); - } else if(e.type == xpbproxy_xfixes_event_base + XFixesSelectionNotify) { - [xpbproxy_selection_object() xfixes_selection_notify:(XFixesSelectionNotifyEvent *)&e]; - } - break; + + XNextEvent(xpbproxy_dpy, &e); + + switch (e.type) { + case SelectionClear: + if ([xpbproxy_selection_object()is_active]) + [xpbproxy_selection_object()clear_event:&e.xselectionclear]; + break; + + case SelectionRequest: + [xpbproxy_selection_object()request_event:&e.xselectionrequest]; + break; + + case SelectionNotify: + [xpbproxy_selection_object()notify_event:&e.xselection]; + break; + + case PropertyNotify: + [xpbproxy_selection_object()property_event:&e.xproperty]; + break; + + default: + if (e.type >= xpbproxy_apple_wm_event_base && + e.type < xpbproxy_apple_wm_event_base + AppleWMNumberEvents) { + x_event_apple_wm_notify((XAppleWMNotifyEvent *) & e); + } + else if (e.type == + xpbproxy_xfixes_event_base + XFixesSelectionNotify) { + [xpbproxy_selection_object()xfixes_selection_notify:(XFixesSelectionNotifyEvent *) & + e]; + } + break; } - + XFlush(xpbproxy_dpy); } - + [pool release]; } -static BOOL add_input_socket (int sock, CFOptionFlags callback_types, - CFSocketCallBack callback, const CFSocketContext *ctx, - CFRunLoopSourceRef *cf_source) { +static BOOL +add_input_socket(int sock, CFOptionFlags callback_types, + CFSocketCallBack callback, const CFSocketContext * ctx, + CFRunLoopSourceRef * cf_source) +{ CFSocketRef cf_sock; - - cf_sock = CFSocketCreateWithNative (kCFAllocatorDefault, sock, - callback_types, callback, ctx); + + cf_sock = CFSocketCreateWithNative(kCFAllocatorDefault, sock, + callback_types, callback, ctx); if (cf_sock == NULL) { - close (sock); + close(sock); return FALSE; } - - *cf_source = CFSocketCreateRunLoopSource (kCFAllocatorDefault, - cf_sock, 0); - CFRelease (cf_sock); - + + *cf_source = CFSocketCreateRunLoopSource(kCFAllocatorDefault, cf_sock, 0); + CFRelease(cf_sock); + if (*cf_source == NULL) return FALSE; - - CFRunLoopAddSource (CFRunLoopGetCurrent (), - *cf_source, kCFRunLoopDefaultMode); + + CFRunLoopAddSource(CFRunLoopGetCurrent(), + *cf_source, kCFRunLoopDefaultMode); return TRUE; } -static void x_input_callback (CFSocketRef sock, CFSocketCallBackType type, - CFDataRef address, const void *data, void *info) { +static void +x_input_callback(CFSocketRef sock, CFSocketCallBackType type, + CFDataRef address, const void *data, void *info) +{ #ifdef STANDALONE_XPBPROXY - if(xpbproxy_prefs_reload) { - [xpbproxy_selection_object() reload_preferences]; + if (xpbproxy_prefs_reload) { + [xpbproxy_selection_object()reload_preferences]; xpbproxy_prefs_reload = NO; } #endif - + xpbproxy_process_xevents(); } -BOOL xpbproxy_input_register(void) { - return add_input_socket(ConnectionNumber(xpbproxy_dpy), kCFSocketReadCallBack, - x_input_callback, NULL, &xpbproxy_dpy_source); +BOOL +xpbproxy_input_register(void) +{ + return add_input_socket(ConnectionNumber(xpbproxy_dpy), + kCFSocketReadCallBack, x_input_callback, NULL, + &xpbproxy_dpy_source); } diff --git a/xorg-server/hw/xquartz/pbproxy/x-selection.h b/xorg-server/hw/xquartz/pbproxy/x-selection.h index d4a39e58f..f5c6c9bd5 100644 --- a/xorg-server/hw/xquartz/pbproxy/x-selection.h +++ b/xorg-server/hw/xquartz/pbproxy/x-selection.h @@ -41,9 +41,9 @@ /* This stores image data or text. */ struct propdata { - unsigned char *data; - size_t length; - int format; + unsigned char *data; + size_t length; + int format; }; struct atom_list { @@ -52,16 +52,13 @@ struct atom_list { compound_text, atom_pair; }; - -@interface x_selection : NSObject -{ -@private - - /* The unmapped window we use for fetching selections. */ + @interface x_selection:NSObject { + @private + /* The unmapped window we use for fetching selections. */ Window _selection_window; Atom request_atom; - + struct { struct propdata propdata; Window requestor; @@ -74,37 +71,40 @@ struct atom_list { * pending_copy is > 0 we do it again. */ int pending_copy; + /* * This is used for the same purpose as pending_copy, but for the * CLIPBOARD. It also prevents a race with INCR transfers. */ - int pending_clipboard; - + int pending_clipboard; + struct atom_list atoms[1]; } -- (void) x_active:(Time)timestamp; -- (void) x_inactive:(Time)timestamp; - -- (void) x_copy:(Time)timestamp; - -- (void) clear_event:(XSelectionClearEvent *)e; -- (void) request_event:(XSelectionRequestEvent *)e; -- (void) notify_event:(XSelectionEvent *)e; -- (void) property_event:(XPropertyEvent *)e; -- (void) xfixes_selection_notify:(XFixesSelectionNotifyEvent *)e; -- (void) handle_selection:(Atom)selection type:(Atom)type propdata:(struct propdata *)pdata; -- (void) claim_clipboard; -- (BOOL) set_clipboard_manager_status:(BOOL)value; -- (void) own_clipboard; -- (void) copy_completed:(Atom)selection; - -- (void) reload_preferences; -- (BOOL) is_active; -- (void) send_none:(XSelectionRequestEvent *)e; -@end + -(void) x_active:(Time) timestamp; + -(void) x_inactive:(Time) timestamp; + + -(void) x_copy:(Time) timestamp; + + -(void) clear_event:(XSelectionClearEvent *) e; + -(void) request_event:(XSelectionRequestEvent *) e; + -(void) notify_event:(XSelectionEvent *) e; + -(void) property_event:(XPropertyEvent *) e; + -(void) xfixes_selection_notify:(XFixesSelectionNotifyEvent *) e; + -(void) handle_selection:(Atom) +selection type:(Atom) +type propdata:(struct propdata *) pdata; +-(void) claim_clipboard; + -(BOOL) set_clipboard_manager_status:(BOOL) value; +-(void) own_clipboard; + -(void) copy_completed:(Atom) selection; + +-(void) reload_preferences; +-(BOOL) is_active; + -(void) send_none:(XSelectionRequestEvent *) e; +@end /* main.m */ extern x_selection *_selection_object; -#endif /* X_SELECTION_H */ +#endif /* X_SELECTION_H */ diff --git a/xorg-server/hw/xquartz/pbproxy/x-selection.m b/xorg-server/hw/xquartz/pbproxy/x-selection.m index b5f4dde5c..317aed073 100644 --- a/xorg-server/hw/xquartz/pbproxy/x-selection.m +++ b/xorg-server/hw/xquartz/pbproxy/x-selection.m @@ -65,59 +65,61 @@ */ static struct { - BOOL active ; - BOOL primary_on_grab; /* This is provided as an option for people who - * want it and has issues that won't ever be - * addressed to make it *always* work. - */ + BOOL active; + BOOL primary_on_grab; /* This is provided as an option for people who + * want it and has issues that won't ever be + * addressed to make it *always* work. + */ BOOL clipboard_to_pasteboard; BOOL pasteboard_to_primary; BOOL pasteboard_to_clipboard; -} pbproxy_prefs = { YES, NO, YES, YES, YES }; +} pbproxy_prefs = { +YES, NO, YES, YES, YES}; @implementation x_selection - -static struct propdata null_propdata = {NULL, 0, 0}; + static struct propdata null_propdata = { NULL, 0, 0 }; #ifdef DEBUG static void -dump_prefs() { - ErrorF(fp, - "pbproxy preferences:\n" - "\tactive %u\n" - "\tprimary_on_grab %u\n" - "\tclipboard_to_pasteboard %u\n" - "\tpasteboard_to_primary %u\n" - "\tpasteboard_to_clipboard %u\n", - pbproxy_prefs.active, - pbproxy_prefs.primary_on_grab, - pbproxy_prefs.clipboard_to_pasteboard, - pbproxy_prefs.pasteboard_to_primary, - pbproxy_prefs.pasteboard_to_clipboard); +dump_prefs() +{ + ErrorF(fp, + "pbproxy preferences:\n" + "\tactive %u\n" + "\tprimary_on_grab %u\n" + "\tclipboard_to_pasteboard %u\n" + "\tpasteboard_to_primary %u\n" + "\tpasteboard_to_clipboard %u\n", + pbproxy_prefs.active, + pbproxy_prefs.primary_on_grab, + pbproxy_prefs.clipboard_to_pasteboard, + pbproxy_prefs.pasteboard_to_primary, + pbproxy_prefs.pasteboard_to_clipboard); } #endif extern CFStringRef app_prefs_domain_cfstr; static BOOL -prefs_get_bool (CFStringRef key, BOOL defaultValue) { +prefs_get_bool(CFStringRef key, BOOL defaultValue) +{ Boolean value, ok; - - value = CFPreferencesGetAppBooleanValue (key, app_prefs_domain_cfstr, &ok); - + + value = CFPreferencesGetAppBooleanValue(key, app_prefs_domain_cfstr, &ok); + return ok ? (BOOL) value : defaultValue; } static void -init_propdata (struct propdata *pdata) +init_propdata(struct propdata *pdata) { *pdata = null_propdata; } static void -free_propdata (struct propdata *pdata) +free_propdata(struct propdata *pdata) { - free (pdata->data); + free(pdata->data); *pdata = null_propdata; } @@ -127,188 +129,175 @@ free_propdata (struct propdata *pdata) * The property is only deleted when bytesleft is 0 if delete is True. */ static Bool -get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Atom *type) +get_property(Window win, Atom property, struct propdata *pdata, Bool delete, + Atom *type) { long offset = 0; unsigned long numitems, bytesleft = 0; + #ifdef TEST /* This is used to test the growth handling. */ unsigned long length = 4UL; #else - unsigned long length = (100000UL + 3) / 4; + unsigned long length = (100000UL + 3) / 4; #endif unsigned char *buf = NULL, *chunk = NULL; size_t buflen = 0, chunkbytesize = 0; int format; - TRACE (); - - if(None == property) - return True; - - do - { - unsigned long newbuflen = 0; - unsigned char *newbuf = NULL; - -#ifdef TEST - ErrorF("bytesleft %lu\n", bytesleft); + TRACE(); + + if (None == property) + return True; + + do { + unsigned long newbuflen = 0; + unsigned char *newbuf = NULL; + +#ifdef TEST + ErrorF("bytesleft %lu\n", bytesleft); #endif - if (Success != XGetWindowProperty (xpbproxy_dpy, win, property, - offset, length, delete, - AnyPropertyType, - type, &format, &numitems, - &bytesleft, &chunk)) - { - DebugF ("Error while getting window property.\n"); - *pdata = null_propdata; - free (buf); - return True; - } - + if (Success != XGetWindowProperty(xpbproxy_dpy, win, property, + offset, length, delete, + AnyPropertyType, + type, &format, &numitems, + &bytesleft, &chunk)) { + DebugF("Error while getting window property.\n"); + *pdata = null_propdata; + free(buf); + return True; + } + #ifdef TEST - ErrorF("format %d numitems %lu bytesleft %lu\n", - format, numitems, bytesleft); - - ErrorF("type %s\n", XGetAtomName (xpbproxy_dpy, *type)); + ErrorF("format %d numitems %lu bytesleft %lu\n", + format, numitems, bytesleft); + + ErrorF("type %s\n", XGetAtomName(xpbproxy_dpy, *type)); #endif - - /* Format is the number of bits. */ - if (format == 8) - chunkbytesize = numitems; - else if (format == 16) - chunkbytesize = numitems * sizeof(short); - else if (format == 32) - chunkbytesize = numitems * sizeof(long); + + /* Format is the number of bits. */ + if (format == 8) + chunkbytesize = numitems; + else if (format == 16) + chunkbytesize = numitems * sizeof(short); + else if (format == 32) + chunkbytesize = numitems * sizeof(long); #ifdef TEST - ErrorF("chunkbytesize %zu\n", chunkbytesize); + ErrorF("chunkbytesize %zu\n", chunkbytesize); #endif - newbuflen = buflen + chunkbytesize; - if (newbuflen > 0) - { - newbuf = realloc (buf, newbuflen); - - if (NULL == newbuf) - { - XFree (chunk); - free (buf); - return True; - } - - memcpy (newbuf + buflen, chunk, chunkbytesize); - XFree (chunk); - buf = newbuf; - buflen = newbuflen; - /* offset is a multiple of 32 bits*/ - offset += chunkbytesize / 4; - } - else - { - if (chunk) - XFree (chunk); - } - + newbuflen = buflen + chunkbytesize; + if (newbuflen > 0) { + newbuf = realloc(buf, newbuflen); + + if (NULL == newbuf) { + XFree(chunk); + free(buf); + return True; + } + + memcpy(newbuf + buflen, chunk, chunkbytesize); + XFree(chunk); + buf = newbuf; + buflen = newbuflen; + /* offset is a multiple of 32 bits */ + offset += chunkbytesize / 4; + } + else { + if (chunk) + XFree(chunk); + } + #ifdef TEST - ErrorF("bytesleft %lu\n", bytesleft); + ErrorF("bytesleft %lu\n", bytesleft); #endif } while (bytesleft > 0); - + pdata->data = buf; pdata->length = buflen; pdata->format = format; - return /*success*/ False; + return /*success */ False; } - /* Implementation methods */ /* This finds the preferred type from a TARGETS list.*/ -- (Atom) find_preferred:(struct propdata *)pdata -{ + -(Atom) find_preferred:(struct propdata *) pdata { Atom a = None; size_t i, step; Bool png = False, jpeg = False, utf8 = False, string = False; - TRACE (); - - if (pdata->format != 32) - { - ErrorF("Atom list is expected to be formatted as an array of 32bit values.\n"); - return None; - } - - for (i = 0, step = sizeof(long); i < pdata->length; i += step) - { - a = (Atom)*(long *)(pdata->data + i); - - if (a == atoms->image_png) - { - png = True; - } - else if (a == atoms->image_jpeg) - { - jpeg = True; - } - else if (a == atoms->utf8_string) - { - utf8 = True; - } - else if (a == atoms->string) - { - string = True; - } - else - { - char *type = XGetAtomName(xpbproxy_dpy, a); - if (type) - { - DebugF("Unhandled X11 mime type: %s", type); - XFree(type); - } - } - } - - /*We prefer PNG over strings, and UTF8 over a Latin-1 string.*/ + TRACE(); + + if (pdata->format != 32) { + ErrorF + ("Atom list is expected to be formatted as an array of 32bit values.\n"); + return None; + } + + for (i = 0, step = sizeof(long); i < pdata->length; i += step) { + a = (Atom) *(long *) (pdata->data + i); + + if (a == atoms->image_png) { + png = True; + } + else if (a == atoms->image_jpeg) { + jpeg = True; + } + else if (a == atoms->utf8_string) { + utf8 = True; + } + else if (a == atoms->string) { + string = True; + } + else { + char *type = XGetAtomName(xpbproxy_dpy, a); + + if (type) { + DebugF("Unhandled X11 mime type: %s", type); + XFree(type); + } + } + } + + /*We prefer PNG over strings, and UTF8 over a Latin-1 string. */ if (png) - return atoms->image_png; + return atoms->image_png; if (jpeg) - return atoms->image_jpeg; + return atoms->image_jpeg; if (utf8) - return atoms->utf8_string; + return atoms->utf8_string; if (string) - return atoms->string; + return atoms->string; - /* This is evidently something we don't know how to handle.*/ + /* This is evidently something we don't know how to handle. */ return None; } /* Return True if this is an INCR-style transfer. */ -- (Bool) is_incr_type:(XSelectionEvent *)e -{ + -(Bool) is_incr_type:(XSelectionEvent *) e { Atom seltype; int format; unsigned long numitems = 0UL, bytesleft = 0UL; unsigned char *chunk; - - TRACE (); - if (Success != XGetWindowProperty (xpbproxy_dpy, e->requestor, e->property, - /*offset*/ 0L, /*length*/ 4UL, - /*Delete*/ False, - AnyPropertyType, &seltype, &format, - &numitems, &bytesleft, &chunk)) - { - return False; + TRACE(); + + if (Success != XGetWindowProperty(xpbproxy_dpy, e->requestor, e->property, + /*offset */ 0L, /*length */ 4UL, + /*Delete */ False, + AnyPropertyType, &seltype, &format, + &numitems, &bytesleft, &chunk)) { + return False; } - if(chunk) - XFree(chunk); + if (chunk) + XFree(chunk); return (seltype == atoms->incr) ? True : False; } @@ -317,133 +306,122 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato * This should be called after a selection has been copied, * or when the selection is unfinished before a transfer completes. */ -- (void) release_pending -{ - TRACE (); +-(void) release_pending { + TRACE(); - free_propdata (&pending.propdata); + free_propdata(&pending.propdata); pending.requestor = None; pending.selection = None; } /* Return True if an error occurs during an append.*/ /* Return False if the append succeeds. */ -- (Bool) append_to_pending:(struct propdata *)pdata requestor:(Window)requestor + -(Bool) append_to_pending:(struct propdata *) +pdata requestor:(Window) requestor { unsigned char *newdata; size_t newlength; - - TRACE (); - - if (requestor != pending.requestor) - { - [self release_pending]; - pending.requestor = requestor; - } - + + TRACE(); + + if (requestor != pending.requestor) { + [self release_pending]; + pending.requestor = requestor; + } + newlength = pending.propdata.length + pdata->length; newdata = realloc(pending.propdata.data, newlength); - if(NULL == newdata) - { - perror("realloc propdata"); - [self release_pending]; + if (NULL == newdata) { + perror("realloc propdata"); + [self release_pending]; return True; } memcpy(newdata + pending.propdata.length, pdata->data, pdata->length); pending.propdata.data = newdata; pending.propdata.length = newlength; - + return False; } - - /* Called when X11 becomes active (i.e. has key focus) */ -- (void) x_active:(Time)timestamp -{ + -(void) x_active:(Time) timestamp { static NSInteger changeCount; NSInteger countNow; NSPasteboard *pb; - TRACE (); + TRACE(); - pb = [NSPasteboard generalPasteboard]; + pb =[NSPasteboard generalPasteboard]; if (nil == pb) - return; + return; - countNow = [pb changeCount]; + countNow =[pb changeCount]; - if (countNow != changeCount) - { - DebugF ("changed pasteboard!\n"); + if (countNow != changeCount) { + DebugF("changed pasteboard!\n"); changeCount = countNow; - - if (pbproxy_prefs.pasteboard_to_primary) - { - XSetSelectionOwner (xpbproxy_dpy, atoms->primary, _selection_window, CurrentTime); + + if (pbproxy_prefs.pasteboard_to_primary) { + XSetSelectionOwner(xpbproxy_dpy, atoms->primary, _selection_window, + CurrentTime); } - + if (pbproxy_prefs.pasteboard_to_clipboard) { [self own_clipboard]; } } #if 0 - /*gstaplin: we should perhaps investigate something like this branch above...*/ - if ([_pasteboard availableTypeFromArray: _known_types] != nil) - { - /* Pasteboard has data we should proxy; I think it makes - sense to put it on both CLIPBOARD and PRIMARY */ - - XSetSelectionOwner (xpbproxy_dpy, atoms->clipboard, - _selection_window, timestamp); - XSetSelectionOwner (xpbproxy_dpy, atoms->primary, - _selection_window, timestamp); - } + /*gstaplin: we should perhaps investigate something like this branch above... */ + if ([_pasteboard availableTypeFromArray:_known_types] != nil) { + /* Pasteboard has data we should proxy; I think it makes + sense to put it on both CLIPBOARD and PRIMARY */ + + XSetSelectionOwner(xpbproxy_dpy, atoms->clipboard, + _selection_window, timestamp); + XSetSelectionOwner(xpbproxy_dpy, atoms->primary, + _selection_window, timestamp); + } #endif } /* Called when X11 loses key focus */ -- (void) x_inactive:(Time)timestamp -{ - TRACE (); + -(void) x_inactive:(Time) timestamp { + TRACE(); } /* This requests the TARGETS list from the PRIMARY selection owner. */ -- (void) x_copy_request_targets -{ - TRACE (); +-(void) x_copy_request_targets { + TRACE(); request_atom = atoms->targets; - XConvertSelection (xpbproxy_dpy, atoms->primary, atoms->targets, - atoms->primary, _selection_window, CurrentTime); + XConvertSelection(xpbproxy_dpy, atoms->primary, atoms->targets, + atoms->primary, _selection_window, CurrentTime); } /* Called when the Edit/Copy item on the main X11 menubar is selected * and no appkit window claims it. */ -- (void) x_copy:(Time)timestamp -{ + -(void) x_copy:(Time) timestamp { Window w; - TRACE (); + TRACE(); - w = XGetSelectionOwner (xpbproxy_dpy, atoms->primary); + w = XGetSelectionOwner(xpbproxy_dpy, atoms->primary); - if (None != w) - { - ++pending_copy; - - if (1 == pending_copy) { - /* - * There are no other copy operations in progress, so we - * can proceed safely. Otherwise the copy_completed method - * will see that the pending_copy is > 1, and do another copy. - */ - [self x_copy_request_targets]; - } + if (None != w) { + ++pending_copy; + + if (1 == pending_copy) { + /* + * There are no other copy operations in progress, so we + * can proceed safely. Otherwise the copy_completed method + * will see that the pending_copy is > 1, and do another copy. + */ + [self x_copy_request_targets]; + } } } @@ -451,32 +429,37 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato * This prevents tools like xclipboard from causing havoc. * Returns TRUE on success */ -- (BOOL) set_clipboard_manager_status:(BOOL)value -{ - TRACE (); + -(BOOL) set_clipboard_manager_status:(BOOL) value { + TRACE(); - Window owner = XGetSelectionOwner (xpbproxy_dpy, atoms->clipboard_manager); + Window owner = XGetSelectionOwner(xpbproxy_dpy, atoms->clipboard_manager); - if(value) { - if(owner == _selection_window) + if (value) { + if (owner == _selection_window) return TRUE; - if(owner != None) { - ErrorF("A clipboard manager using window 0x%lx already owns the clipboard selection. " - "pbproxy will not sync clipboard to pasteboard.\n", owner); + if (owner != None) { + ErrorF + ("A clipboard manager using window 0x%lx already owns the clipboard selection. " + "pbproxy will not sync clipboard to pasteboard.\n", owner); return FALSE; } - - XSetSelectionOwner(xpbproxy_dpy, atoms->clipboard_manager, _selection_window, CurrentTime); - return (_selection_window == XGetSelectionOwner(xpbproxy_dpy, atoms->clipboard_manager)); - } else { - if(owner != _selection_window) + + XSetSelectionOwner(xpbproxy_dpy, atoms->clipboard_manager, + _selection_window, CurrentTime); + return (_selection_window == + XGetSelectionOwner(xpbproxy_dpy, atoms->clipboard_manager)); + } + else { + if (owner != _selection_window) return TRUE; - XSetSelectionOwner(xpbproxy_dpy, atoms->clipboard_manager, None, CurrentTime); - return(None == XGetSelectionOwner(xpbproxy_dpy, atoms->clipboard_manager)); + XSetSelectionOwner(xpbproxy_dpy, atoms->clipboard_manager, None, + CurrentTime); + return (None == + XGetSelectionOwner(xpbproxy_dpy, atoms->clipboard_manager)); } - + return FALSE; } @@ -484,31 +467,30 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato * This occurs when we previously owned a selection, * and then lost it from another client. */ -- (void) clear_event:(XSelectionClearEvent *)e -{ - + -(void) clear_event:(XSelectionClearEvent *) e { + + TRACE(); + + DebugF("e->selection %s\n", XGetAtomName(xpbproxy_dpy, e->selection)); - TRACE (); - - DebugF ("e->selection %s\n", XGetAtomName (xpbproxy_dpy, e->selection)); - - if(e->selection == atoms->clipboard) { + if (e->selection == atoms->clipboard) { /* * We lost ownership of the CLIPBOARD. */ ++pending_clipboard; - + if (1 == pending_clipboard) { /* Claim the clipboard contents from the new owner. */ [self claim_clipboard]; } - } else if(e->selection == atoms->clipboard_manager) { - if(pbproxy_prefs.clipboard_to_pasteboard) { + } + else if (e->selection == atoms->clipboard_manager) { + if (pbproxy_prefs.clipboard_to_pasteboard) { /* Another CLIPBOARD_MANAGER has set itself as owner. Disable syncing * to avoid a race. */ ErrorF("Another clipboard manager was started! " - "xpbproxy is disabling syncing with clipboard.\n"); + "xpbproxy is disabling syncing with clipboard.\n"); pbproxy_prefs.clipboard_to_pasteboard = NO; } } @@ -517,73 +499,71 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato /* * We greedily acquire the clipboard after it changes, and on startup. */ -- (void) claim_clipboard -{ +-(void) claim_clipboard { Window owner; - - TRACE (); - + + TRACE(); + if (!pbproxy_prefs.clipboard_to_pasteboard) return; - - owner = XGetSelectionOwner (xpbproxy_dpy, atoms->clipboard); + + owner = XGetSelectionOwner(xpbproxy_dpy, atoms->clipboard); if (None == owner) { /* * The owner probably died or we are just starting up pbproxy. * Set pbproxy's _selection_window as the owner, and continue. */ - DebugF ("No clipboard owner.\n"); - [self copy_completed:atoms->clipboard]; + DebugF("No clipboard owner.\n"); + [self copy_completed:atoms->clipboard]; return; - } else if (owner == _selection_window) { - [self copy_completed:atoms->clipboard]; + } + else if (owner == _selection_window) { + [self copy_completed:atoms->clipboard]; return; } - - DebugF ("requesting targets\n"); - + + DebugF("requesting targets\n"); + request_atom = atoms->targets; - XConvertSelection (xpbproxy_dpy, atoms->clipboard, atoms->targets, - atoms->clipboard, _selection_window, CurrentTime); - XFlush (xpbproxy_dpy); + XConvertSelection(xpbproxy_dpy, atoms->clipboard, atoms->targets, + atoms->clipboard, _selection_window, CurrentTime); + XFlush(xpbproxy_dpy); /* Now we will get a SelectionNotify event in the future. */ } /* Greedily acquire the clipboard. */ -- (void) own_clipboard -{ +-(void) own_clipboard { - TRACE (); + TRACE(); /* We should perhaps have a boundary limit on the number of iterations... */ - do - { - XSetSelectionOwner (xpbproxy_dpy, atoms->clipboard, _selection_window, - CurrentTime); - } while (_selection_window != XGetSelectionOwner (xpbproxy_dpy, - atoms->clipboard)); + do { + XSetSelectionOwner(xpbproxy_dpy, atoms->clipboard, _selection_window, + CurrentTime); + } while (_selection_window != XGetSelectionOwner(xpbproxy_dpy, + atoms->clipboard)); } -- (void) init_reply:(XEvent *)reply request:(XSelectionRequestEvent *)e + -(void) init_reply:(XEvent *) +reply request:(XSelectionRequestEvent *) e { reply->xselection.type = SelectionNotify; reply->xselection.selection = e->selection; reply->xselection.target = e->target; reply->xselection.requestor = e->requestor; reply->xselection.time = e->time; - reply->xselection.property = None; + reply->xselection.property = None; } -- (void) send_reply:(XEvent *)reply -{ + -(void) send_reply:(XEvent *) reply { /* * We are supposed to use an empty event mask, and not propagate * the event, according to the ICCCM. */ - DebugF ("reply->xselection.requestor 0x%lx\n", reply->xselection.requestor); - - XSendEvent (xpbproxy_dpy, reply->xselection.requestor, False, 0, reply); - XFlush (xpbproxy_dpy); + DebugF("reply->xselection.requestor 0x%lx\n", reply->xselection.requestor); + + XSendEvent(xpbproxy_dpy, reply->xselection.requestor, False, 0, reply); + XFlush(xpbproxy_dpy); } /* @@ -594,76 +574,75 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato * (in Latin-1 encoding). The requestor can then make the choice based on * the list. */ -- (void) send_targets:(XSelectionRequestEvent *)e pasteboard:(NSPasteboard *)pb + -(void) send_targets:(XSelectionRequestEvent *) +e pasteboard:(NSPasteboard *) pb { XEvent reply; NSArray *pbtypes; - [self init_reply:&reply request:e]; + [self init_reply: &reply request:e]; - pbtypes = [pb types]; - if (pbtypes) - { - long list[7]; /* Don't forget to increase this if we handle more types! */ + pbtypes =[pb types]; + if (pbtypes) { + long list[7]; /* Don't forget to increase this if we handle more types! */ long count = 0; - - /* - * I'm not sure if this is needed, but some toolkits/clients list - * TARGETS in response to targets. - */ - list[count] = atoms->targets; - ++count; - - if ([pbtypes containsObject:NSStringPboardType]) - { - /* We have a string type that we can convert to UTF8, or Latin-1... */ - DebugF ("NSStringPboardType\n"); - list[count] = atoms->utf8_string; - ++count; - list[count] = atoms->string; - ++count; - list[count] = atoms->compound_text; - ++count; - } - - /* TODO add the NSPICTPboardType back again, once we have conversion - * functionality in send_image. - */ + + /* + * I'm not sure if this is needed, but some toolkits/clients list + * TARGETS in response to targets. + */ + list[count] = atoms->targets; + ++count; + + if ([pbtypes containsObject:NSStringPboardType]) { + /* We have a string type that we can convert to UTF8, or Latin-1... */ + DebugF("NSStringPboardType\n"); + list[count] = atoms->utf8_string; + ++count; + list[count] = atoms->string; + ++count; + list[count] = atoms->compound_text; + ++count; + } + + /* TODO add the NSPICTPboardType back again, once we have conversion + * functionality in send_image. + */ #ifdef __clang__ #pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" // NSPICTPboardType +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // NSPICTPboardType #endif - if ([pbtypes containsObject:NSPICTPboardType] - || [pbtypes containsObject:NSTIFFPboardType]) - { - /* We can convert a TIFF to a PNG or JPEG. */ - DebugF ("NSTIFFPboardType\n"); - list[count] = atoms->image_png; - ++count; - list[count] = atoms->image_jpeg; - ++count; - } + if ([pbtypes containsObject:NSPICTPboardType] + ||[pbtypes containsObject:NSTIFFPboardType]) { + /* We can convert a TIFF to a PNG or JPEG. */ + DebugF("NSTIFFPboardType\n"); + list[count] = atoms->image_png; + ++count; + list[count] = atoms->image_jpeg; + ++count; + } #ifdef __clang__ #pragma clang diagnostic pop #endif - if (count) - { - /* We have a list of ATOMs to send. */ - XChangeProperty (xpbproxy_dpy, e->requestor, e->property, atoms->atom, 32, - PropModeReplace, (unsigned char *) list, count); - - reply.xselection.property = e->property; - } + if (count) { + /* We have a list of ATOMs to send. */ + XChangeProperty(xpbproxy_dpy, e->requestor, e->property, + atoms->atom, 32, PropModeReplace, + (unsigned char *) list, count); + + reply.xselection.property = e->property; + } } - [self send_reply:&reply]; + [self send_reply:&reply]; } - -- (void) send_string:(XSelectionRequestEvent *)e utf8:(BOOL)utf8 pasteboard:(NSPasteboard *)pb + -(void) send_string:(XSelectionRequestEvent *) +e utf8:(BOOL) +utf8 pasteboard:(NSPasteboard *) pb { XEvent reply; NSArray *pbtypes; @@ -671,162 +650,158 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato const char *bytes; NSUInteger length; - TRACE (); + TRACE(); + + [self init_reply: &reply request:e]; - [self init_reply:&reply request:e]; + pbtypes =[pb types]; - pbtypes = [pb types]; - - if (![pbtypes containsObject:NSStringPboardType]) - { - [self send_reply:&reply]; - return; + if (![pbtypes containsObject:NSStringPboardType]) { + [self send_reply:&reply]; + return; } #ifdef __LP64__ - DebugF ("pbtypes retainCount after containsObject: %lu\n", [pbtypes retainCount]); + DebugF("pbtypes retainCount after containsObject: %lu\n", + [pbtypes retainCount]); #else - DebugF ("pbtypes retainCount after containsObject: %u\n", [pbtypes retainCount]); + DebugF("pbtypes retainCount after containsObject: %u\n", + [pbtypes retainCount]); #endif - data = [pb stringForType:NSStringPboardType]; + data =[pb stringForType:NSStringPboardType]; - if (nil == data) - { - [self send_reply:&reply]; - return; - } - - if (utf8) - { - bytes = [data UTF8String]; - /* - * We don't want the UTF-8 string length here. - * We want the length in bytes. - */ - length = strlen (bytes); - - if (length < 50) { - DebugF ("UTF-8: %s\n", bytes); + if (nil == data) { + [self send_reply:&reply]; + return; + } + + if (utf8) { + bytes =[data UTF8String]; + /* + * We don't want the UTF-8 string length here. + * We want the length in bytes. + */ + length = strlen(bytes); + + if (length < 50) { + DebugF("UTF-8: %s\n", bytes); #ifdef __LP64__ - DebugF ("UTF-8 length: %lu\n", length); + DebugF("UTF-8 length: %lu\n", length); #else - DebugF ("UTF-8 length: %u\n", length); + DebugF("UTF-8 length: %u\n", length); #endif - } - } - else - { - DebugF ("Latin-1\n"); - bytes = [data cStringUsingEncoding:NSISOLatin1StringEncoding]; - /*WARNING: bytes is not NUL-terminated. */ - length = [data lengthOfBytesUsingEncoding:NSISOLatin1StringEncoding]; - } - - DebugF ("e->target %s\n", XGetAtomName (xpbproxy_dpy, e->target)); - - XChangeProperty (xpbproxy_dpy, e->requestor, e->property, e->target, - 8, PropModeReplace, (unsigned char *) bytes, length); - + } + } + else { + DebugF("Latin-1\n"); + bytes =[data cStringUsingEncoding:NSISOLatin1StringEncoding]; + /*WARNING: bytes is not NUL-terminated. */ + length =[data lengthOfBytesUsingEncoding:NSISOLatin1StringEncoding]; + } + + DebugF("e->target %s\n", XGetAtomName(xpbproxy_dpy, e->target)); + + XChangeProperty(xpbproxy_dpy, e->requestor, e->property, e->target, + 8, PropModeReplace, (unsigned char *) bytes, length); + reply.xselection.property = e->property; - [self send_reply:&reply]; + [self send_reply:&reply]; } -- (void) send_compound_text:(XSelectionRequestEvent *)e pasteboard:(NSPasteboard *)pb + -(void) send_compound_text:(XSelectionRequestEvent *) +e pasteboard:(NSPasteboard *) pb { XEvent reply; NSArray *pbtypes; - - TRACE (); - - [self init_reply:&reply request:e]; - - pbtypes = [pb types]; - - if ([pbtypes containsObject: NSStringPboardType]) - { - NSString *data = [pb stringForType:NSStringPboardType]; - if (nil != data) - { - /* - * Cast to (void *) to avoid a const warning. - * AFAIK Xutf8TextListToTextProperty does not modify the input memory. - */ - void *utf8 = (void *)[data UTF8String]; - char *list[] = { utf8, NULL }; - XTextProperty textprop; - - textprop.value = NULL; - - if (Success == Xutf8TextListToTextProperty (xpbproxy_dpy, list, 1, - XCompoundTextStyle, - &textprop)) - { - - if (8 != textprop.format) - DebugF ("textprop.format is unexpectedly not 8 - it's %d instead\n", - textprop.format); - - XChangeProperty (xpbproxy_dpy, e->requestor, e->property, - atoms->compound_text, textprop.format, - PropModeReplace, textprop.value, - textprop.nitems); - - reply.xselection.property = e->property; - } - - if (textprop.value) - XFree (textprop.value); - - } - } - - [self send_reply:&reply]; + + TRACE(); + + [self init_reply: &reply request:e]; + + pbtypes =[pb types]; + + if ([pbtypes containsObject:NSStringPboardType]) { + NSString *data =[pb stringForType:NSStringPboardType]; + + if (nil != data) { + /* + * Cast to (void *) to avoid a const warning. + * AFAIK Xutf8TextListToTextProperty does not modify the input memory. + */ + void *utf8 = (void *)[data UTF8String]; + char *list[] = { utf8, NULL }; + XTextProperty textprop; + + textprop.value = NULL; + + if (Success == Xutf8TextListToTextProperty(xpbproxy_dpy, list, 1, + XCompoundTextStyle, + &textprop)) { + + if (8 != textprop.format) + DebugF + ("textprop.format is unexpectedly not 8 - it's %d instead\n", + textprop.format); + + XChangeProperty(xpbproxy_dpy, e->requestor, e->property, + atoms->compound_text, textprop.format, + PropModeReplace, textprop.value, + textprop.nitems); + + reply.xselection.property = e->property; + } + + if (textprop.value) + XFree(textprop.value); + + } + } + + [self send_reply:&reply]; } /* Finding a test application that uses MULTIPLE has proven to be difficult. */ -- (void) send_multiple:(XSelectionRequestEvent *)e -{ + -(void) send_multiple:(XSelectionRequestEvent *) e { XEvent reply; - TRACE (); + TRACE(); + + [self init_reply: &reply request:e]; - [self init_reply:&reply request:e]; + if (None != e->property) { - if (None != e->property) - { - } - - [self send_reply:&reply]; + + [self send_reply:&reply]; } /* Return nil if an error occured. */ /* DO NOT retain the encdata for longer than the length of an event response. * The autorelease pool will reuse/free it. - */ -- (NSData *) encode_image_data:(NSData *)data type:(NSBitmapImageFileType)enctype + */ + -(NSData *) encode_image_data:(NSData *) +data type:(NSBitmapImageFileType) enctype { - NSBitmapImageRep *bmimage = nil; + NSBitmapImageRep *bmimage = nil; NSData *encdata = nil; NSDictionary *dict = nil; - bmimage = [[NSBitmapImageRep alloc] initWithData:data]; + bmimage =[[NSBitmapImageRep alloc] initWithData:data]; if (nil == bmimage) - return nil; + return nil; - dict = [[NSDictionary alloc] init]; - encdata = [bmimage representationUsingType:enctype properties:dict]; + dict =[[NSDictionary alloc] init]; + encdata =[bmimage representationUsingType: enctype properties:dict]; - if (nil == encdata) - { - [dict autorelease]; - [bmimage autorelease]; - return nil; + if (nil == encdata) { + [dict autorelease]; + [bmimage autorelease]; + return nil; } - + [dict autorelease]; [bmimage autorelease]; @@ -835,60 +810,53 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato /* Return YES when an error has occured when trying to send the PICT. */ /* The caller should send a default reponse with a property of None when an error occurs. */ -- (BOOL) send_image_pict_reply:(XSelectionRequestEvent *)e - pasteboard:(NSPasteboard *)pb - type:(NSBitmapImageFileType)imagetype + -(BOOL) send_image_pict_reply: (XSelectionRequestEvent *) e pasteboard: (NSPasteboard *) pb type:(NSBitmapImageFileType) imagetype { XEvent reply; NSImage *img = nil; NSData *data = nil, *encdata = nil; NSUInteger length; const void *bytes = NULL; - - img = [[NSImage alloc] initWithPasteboard:pb]; - if (nil == img) - { - return YES; + img =[[NSImage alloc] initWithPasteboard:pb]; + + if (nil == img) { + return YES; } - - data = [img TIFFRepresentation]; - if (nil == data) - { - [img autorelease]; - ErrorF("unable to convert PICT to TIFF!\n"); - return YES; - } - - encdata = [self encode_image_data:data type:imagetype]; - if(nil == encdata) - { - [img autorelease]; - return YES; - } - - [self init_reply:&reply request:e]; - - length = [encdata length]; - bytes = [encdata bytes]; - - XChangeProperty (xpbproxy_dpy, e->requestor, e->property, e->target, - 8, PropModeReplace, bytes, length); + data =[img TIFFRepresentation]; + + if (nil == data) { + [img autorelease]; + ErrorF("unable to convert PICT to TIFF!\n"); + return YES; + } + + encdata =[self encode_image_data: data type:imagetype]; + if (nil == encdata) { + [img autorelease]; + return YES; + } + + [self init_reply: &reply request:e]; + + length =[encdata length]; + bytes =[encdata bytes]; + + XChangeProperty(xpbproxy_dpy, e->requestor, e->property, e->target, + 8, PropModeReplace, bytes, length); reply.xselection.property = e->property; - [self send_reply:&reply]; + [self send_reply:&reply]; [img autorelease]; - return NO; /*no error*/ + return NO; /*no error */ } /* Return YES if an error occured. */ /* The caller should send a reply with a property of None when an error occurs. */ -- (BOOL) send_image_tiff_reply:(XSelectionRequestEvent *)e - pasteboard:(NSPasteboard *)pb - type:(NSBitmapImageFileType)imagetype + -(BOOL) send_image_tiff_reply: (XSelectionRequestEvent *) e pasteboard: (NSPasteboard *) pb type:(NSBitmapImageFileType) imagetype { XEvent reply; NSData *data = nil; @@ -896,91 +864,87 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato NSUInteger length; const void *bytes = NULL; - data = [pb dataForType:NSTIFFPboardType]; + data =[pb dataForType:NSTIFFPboardType]; if (nil == data) - return YES; - - encdata = [self encode_image_data:data type:imagetype]; + return YES; + + encdata =[self encode_image_data: data type:imagetype]; - if(nil == encdata) - return YES; + if (nil == encdata) + return YES; + + [self init_reply: &reply request:e]; - [self init_reply:&reply request:e]; + length =[encdata length]; + bytes =[encdata bytes]; - length = [encdata length]; - bytes = [encdata bytes]; - - XChangeProperty (xpbproxy_dpy, e->requestor, e->property, e->target, - 8, PropModeReplace, bytes, length); + XChangeProperty(xpbproxy_dpy, e->requestor, e->property, e->target, + 8, PropModeReplace, bytes, length); reply.xselection.property = e->property; - - [self send_reply:&reply]; - return NO; /*no error*/ + [self send_reply:&reply]; + + return NO; /*no error */ } -- (void) send_image:(XSelectionRequestEvent *)e pasteboard:(NSPasteboard *)pb + -(void) send_image:(XSelectionRequestEvent *) +e pasteboard:(NSPasteboard *) pb { NSArray *pbtypes = nil; NSBitmapImageFileType imagetype = NSPNGFileType; - TRACE (); + TRACE(); if (e->target == atoms->image_png) - imagetype = NSPNGFileType; + imagetype = NSPNGFileType; else if (e->target == atoms->image_jpeg) - imagetype = NSJPEGFileType; - else - { - ErrorF("internal failure in xpbproxy! imagetype being sent isn't PNG or JPEG.\n"); + imagetype = NSJPEGFileType; + else { + ErrorF + ("internal failure in xpbproxy! imagetype being sent isn't PNG or JPEG.\n"); } - pbtypes = [pb types]; + pbtypes =[pb types]; - if (pbtypes) - { - if ([pbtypes containsObject:NSTIFFPboardType]) - { - if (NO == [self send_image_tiff_reply:e pasteboard:pb type:imagetype]) - return; - } + if (pbtypes) { + if ([pbtypes containsObject:NSTIFFPboardType]) { + if (NO ==[self send_image_tiff_reply: e pasteboard: pb type:imagetype]) + return; + } #ifdef __clang__ #pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" // NSPICTPboardType +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // NSPICTPboardType #endif - else if ([pbtypes containsObject:NSPICTPboardType]) + else if ([pbtypes containsObject:NSPICTPboardType]) #ifdef __clang__ #pragma clang diagnostic pop #endif - { - if (NO == [self send_image_pict_reply:e pasteboard:pb type:imagetype]) - return; + { + if (NO ==[self send_image_pict_reply: e pasteboard: pb type:imagetype]) + return; - /* Fall through intentionally to the send_none: */ - } + /* Fall through intentionally to the send_none: */ + } } - [self send_none:e]; + [self send_none:e]; } -- (void)send_none:(XSelectionRequestEvent *)e -{ + -(void) send_none:(XSelectionRequestEvent *) e { XEvent reply; - TRACE (); + TRACE(); - [self init_reply:&reply request:e]; - [self send_reply:&reply]; + [self init_reply: &reply request:e]; + [self send_reply:&reply]; } - /* Another client requested the data or targets of data available from the clipboard. */ -- (void)request_event:(XSelectionRequestEvent *)e -{ + -(void) request_event:(XSelectionRequestEvent *) e { NSPasteboard *pb; - TRACE (); + TRACE(); /* TODO We should also keep track of the time of the selection, and * according to the ICCCM "refuse the request" if the event timestamp @@ -992,388 +956,367 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato * Perhaps we should just punt and ignore races. */ - /*TODO we need a COMPOUND_TEXT test app*/ - /*TODO we need a MULTIPLE test app*/ + /*TODO we need a COMPOUND_TEXT test app */ + /*TODO we need a MULTIPLE test app */ - pb = [NSPasteboard generalPasteboard]; - if (nil == pb) - { - [self send_none:e]; - return; + pb =[NSPasteboard generalPasteboard]; + if (nil == pb) { + [self send_none:e]; + return; } - if (None != e->target) - DebugF ("e->target %s\n", XGetAtomName (xpbproxy_dpy, e->target)); - - if (e->target == atoms->targets) - { - /* The paste requestor wants to know what TARGETS we support. */ - [self send_targets:e pasteboard:pb]; - } - else if (e->target == atoms->multiple) - { - /* - * This isn't finished, and may never be, unless I can find - * a good test app. - */ - [self send_multiple:e]; - } - else if (e->target == atoms->utf8_string) - { - [self send_string:e utf8:YES pasteboard:pb]; - } - else if (e->target == atoms->string) - { - [self send_string:e utf8:NO pasteboard:pb]; - } - else if (e->target == atoms->compound_text) - { - [self send_compound_text:e pasteboard:pb]; - } - else if (e->target == atoms->multiple) - { - [self send_multiple:e]; - } - else if (e->target == atoms->image_png || e->target == atoms->image_jpeg) - { - [self send_image:e pasteboard:pb]; + DebugF("e->target %s\n", XGetAtomName(xpbproxy_dpy, e->target)); + + if (e->target == atoms->targets) { + /* The paste requestor wants to know what TARGETS we support. */ + [self send_targets: e pasteboard:pb]; } - else - { - [self send_none:e]; + else if (e->target == atoms->multiple) { + /* + * This isn't finished, and may never be, unless I can find + * a good test app. + */ + [self send_multiple:e]; + } + else if (e->target == atoms->utf8_string) { + [self send_string: e utf8: YES pasteboard:pb]; + } + else if (e->target == atoms->string) { + [self send_string: e utf8: NO pasteboard:pb]; + } + else if (e->target == atoms->compound_text) { + [self send_compound_text: e pasteboard:pb]; + } + else if (e->target == atoms->multiple) { + [self send_multiple:e]; + } + else if (e->target == atoms->image_png || e->target == atoms->image_jpeg) { + [self send_image: e pasteboard:pb]; + } + else { + [self send_none:e]; } } /* This handles the events resulting from an XConvertSelection request. */ -- (void) notify_event:(XSelectionEvent *)e -{ + -(void) notify_event:(XSelectionEvent *) e { Atom type; struct propdata pdata; - - TRACE (); + + TRACE(); [self release_pending]; - + if (None == e->property) { - DebugF ("e->property is None.\n"); - [self copy_completed:e->selection]; - /* Nothing is selected. */ - return; + DebugF("e->property is None.\n"); + [self copy_completed:e->selection]; + /* Nothing is selected. */ + return; } #if 0 - ErrorF("e->selection %s\n", XGetAtomName (xpbproxy_dpy, e->selection)); - ErrorF("e->property %s\n", XGetAtomName (xpbproxy_dpy, e->property)); + ErrorF("e->selection %s\n", XGetAtomName(xpbproxy_dpy, e->selection)); + ErrorF("e->property %s\n", XGetAtomName(xpbproxy_dpy, e->property)); #endif - if ([self is_incr_type:e]) - { - /* - * This is an INCR-style transfer, which means that we - * will get the data after a series of PropertyNotify events. - */ - DebugF ("is INCR\n"); + if ([self is_incr_type:e]) { + /* + * This is an INCR-style transfer, which means that we + * will get the data after a series of PropertyNotify events. + */ + DebugF("is INCR\n"); - if (get_property (e->requestor, e->property, &pdata, /*Delete*/ True, &type)) - { - /* - * An error occured, so we should invoke the copy_completed:, but - * not handle_selection:type:propdata: - */ - [self copy_completed:e->selection]; - return; - } + if (get_property + (e->requestor, e->property, &pdata, /*Delete */ True, &type)) { + /* + * An error occured, so we should invoke the copy_completed:, but + * not handle_selection:type:propdata: + */ + [self copy_completed:e->selection]; + return; + } - free_propdata (&pdata); + free_propdata(&pdata); - pending.requestor = e->requestor; - pending.selection = e->selection; + pending.requestor = e->requestor; + pending.selection = e->selection; - DebugF ("set pending.requestor to 0x%lx\n", pending.requestor); + DebugF("set pending.requestor to 0x%lx\n", pending.requestor); } - else - { - if (get_property (e->requestor, e->property, &pdata, /*Delete*/ True, &type)) - { - [self copy_completed:e->selection]; - return; - } - - /* We have the complete selection data.*/ - [self handle_selection:e->selection type:type propdata:&pdata]; - - DebugF ("handled selection with the first notify_event\n"); + else { + if (get_property + (e->requestor, e->property, &pdata, /*Delete */ True, &type)) { + [self copy_completed:e->selection]; + return; + } + + /* We have the complete selection data. */ + [self handle_selection: e->selection type: type propdata:&pdata]; + + DebugF("handled selection with the first notify_event\n"); } } /* This is used for INCR transfers. See the ICCCM for the details. */ /* This is used to retrieve PRIMARY and CLIPBOARD selections. */ -- (void) property_event:(XPropertyEvent *)e -{ + -(void) property_event:(XPropertyEvent *) e { struct propdata pdata; Atom type; - TRACE (); - - if (None != e->atom) - { + TRACE(); + + if (None != e->atom) { #ifdef DEBUG - char *name = XGetAtomName (xpbproxy_dpy, e->atom); + char *name = XGetAtomName(xpbproxy_dpy, e->atom); - if (name) - { - DebugF ("e->atom %s\n", name); - XFree(name); - } + if (name) { + DebugF("e->atom %s\n", name); + XFree(name); + } #endif } - if (None != pending.requestor && PropertyNewValue == e->state) - { - DebugF ("pending.requestor 0x%lx\n", pending.requestor); + if (None != pending.requestor && PropertyNewValue == e->state) { + DebugF("pending.requestor 0x%lx\n", pending.requestor); - if (get_property (e->window, e->atom, &pdata, /*Delete*/ True, &type)) - { - [self copy_completed:pending.selection]; - [self release_pending]; - return; - } - - if (0 == pdata.length) - { - /* - * We completed the transfer. - * handle_selection will call copy_completed: for us. - */ - [self handle_selection:pending.selection type:type propdata:&pending.propdata]; - free_propdata(&pdata); - pending.propdata = null_propdata; - pending.requestor = None; - pending.selection = None; - } - else - { - [self append_to_pending:&pdata requestor:e->window]; - free_propdata (&pdata); - } + if (get_property(e->window, e->atom, &pdata, /*Delete */ True, &type)) { + [self copy_completed:pending.selection]; + [self release_pending]; + return; + } + + if (0 == pdata.length) { + /* + * We completed the transfer. + * handle_selection will call copy_completed: for us. + */ + [self handle_selection: pending.selection type: type propdata:&pending. + propdata]; + free_propdata(&pdata); + pending.propdata = null_propdata; + pending.requestor = None; + pending.selection = None; + } + else { + [self append_to_pending: &pdata requestor:e->window]; + free_propdata(&pdata); + } } } -- (void) xfixes_selection_notify:(XFixesSelectionNotifyEvent *)e { - if(!pbproxy_prefs.active) + -(void) xfixes_selection_notify:(XFixesSelectionNotifyEvent *) e { + if (!pbproxy_prefs.active) return; - - switch(e->subtype) { - case XFixesSetSelectionOwnerNotify: - if(e->selection == atoms->primary && pbproxy_prefs.primary_on_grab) - [self x_copy:e->timestamp]; - break; - - case XFixesSelectionWindowDestroyNotify: - case XFixesSelectionClientCloseNotify: - default: - ErrorF("Unhandled XFixesSelectionNotifyEvent: subtype=%d\n", e->subtype); - break; + + switch (e->subtype) { + case XFixesSetSelectionOwnerNotify: + if (e->selection == atoms->primary && pbproxy_prefs.primary_on_grab) + [self x_copy:e->timestamp]; + break; + + case XFixesSelectionWindowDestroyNotify: + case XFixesSelectionClientCloseNotify: + default: + ErrorF("Unhandled XFixesSelectionNotifyEvent: subtype=%d\n", + e->subtype); + break; } } -- (void) handle_targets: (Atom)selection propdata:(struct propdata *)pdata + -(void) handle_targets:(Atom) +selection propdata:(struct propdata *) pdata { /* Find a type we can handle and prefer from the list of ATOMs. */ Atom preferred; char *name; - TRACE (); + TRACE(); + + preferred =[self find_preferred:pdata]; - preferred = [self find_preferred:pdata]; - - if (None == preferred) - { - /* - * This isn't required by the ICCCM, but some apps apparently - * don't respond to TARGETS properly. - */ - preferred = atoms->string; + if (None == preferred) { + /* + * This isn't required by the ICCCM, but some apps apparently + * don't respond to TARGETS properly. + */ + preferred = atoms->string; } - (void)name; /* Avoid a warning with non-debug compiles. */ + (void) name; /* Avoid a warning with non-debug compiles. */ #ifdef DEBUG - name = XGetAtomName (xpbproxy_dpy, preferred); + name = XGetAtomName(xpbproxy_dpy, preferred); - if (name) - { - DebugF ("requesting %s\n", name); + if (name) { + DebugF("requesting %s\n", name); } #endif request_atom = preferred; - XConvertSelection (xpbproxy_dpy, selection, preferred, selection, - _selection_window, CurrentTime); + XConvertSelection(xpbproxy_dpy, selection, preferred, selection, + _selection_window, CurrentTime); } /* This handles the image type of selection (typically in CLIPBOARD). */ /* We convert to a TIFF, so that other applications can paste more easily. */ -- (void) handle_image: (struct propdata *)pdata pasteboard:(NSPasteboard *)pb + -(void) handle_image:(struct propdata *) +pdata pasteboard:(NSPasteboard *) pb { NSArray *pbtypes; NSUInteger length; NSData *data, *tiff; NSBitmapImageRep *bmimage; - TRACE (); + TRACE(); length = pdata->length; - data = [[NSData alloc] initWithBytes:pdata->data length:length]; + data =[[NSData alloc] initWithBytes: pdata->data length:length]; - if (nil == data) - { - DebugF ("unable to create NSData object!\n"); - return; + if (nil == data) { + DebugF("unable to create NSData object!\n"); + return; } #ifdef __LP64__ - DebugF ("data retainCount before NSBitmapImageRep initWithData: %lu\n", - [data retainCount]); + DebugF("data retainCount before NSBitmapImageRep initWithData: %lu\n", + [data retainCount]); #else - DebugF ("data retainCount before NSBitmapImageRep initWithData: %u\n", - [data retainCount]); + DebugF("data retainCount before NSBitmapImageRep initWithData: %u\n", + [data retainCount]); #endif - bmimage = [[NSBitmapImageRep alloc] initWithData:data]; + bmimage =[[NSBitmapImageRep alloc] initWithData:data]; - if (nil == bmimage) - { - [data autorelease]; - DebugF ("unable to create NSBitmapImageRep!\n"); - return; + if (nil == bmimage) { + [data autorelease]; + DebugF("unable to create NSBitmapImageRep!\n"); + return; } #ifdef __LP64__ - DebugF ("data retainCount after NSBitmapImageRep initWithData: %lu\n", - [data retainCount]); + DebugF("data retainCount after NSBitmapImageRep initWithData: %lu\n", + [data retainCount]); #else - DebugF ("data retainCount after NSBitmapImageRep initWithData: %u\n", - [data retainCount]); + DebugF("data retainCount after NSBitmapImageRep initWithData: %u\n", + [data retainCount]); #endif - @try - { - tiff = [bmimage TIFFRepresentation]; + @try { + tiff =[bmimage TIFFRepresentation]; } - @catch (NSException *e) - { - DebugF ("NSTIFFException!\n"); - [data autorelease]; - [bmimage autorelease]; - return; + @catch(NSException * e) { + DebugF("NSTIFFException!\n"); + [data autorelease]; + [bmimage autorelease]; + return; } - + #ifdef __LP64__ - DebugF ("bmimage retainCount after TIFFRepresentation %lu\n", [bmimage retainCount]); + DebugF("bmimage retainCount after TIFFRepresentation %lu\n", + [bmimage retainCount]); #else - DebugF ("bmimage retainCount after TIFFRepresentation %u\n", [bmimage retainCount]); + DebugF("bmimage retainCount after TIFFRepresentation %u\n", + [bmimage retainCount]); #endif - pbtypes = [NSArray arrayWithObjects:NSTIFFPboardType, nil]; + pbtypes =[NSArray arrayWithObjects:NSTIFFPboardType, nil]; - if (nil == pbtypes) - { - [data autorelease]; - [bmimage autorelease]; - return; + if (nil == pbtypes) { + [data autorelease]; + [bmimage autorelease]; + return; } - [pb declareTypes:pbtypes owner:nil]; - if (YES != [pb setData:tiff forType:NSTIFFPboardType]) - { - DebugF ("writing pasteboard data failed!\n"); + [pb declareTypes: pbtypes owner:nil]; + if (YES !=[pb setData: tiff forType:NSTIFFPboardType]) { + DebugF("writing pasteboard data failed!\n"); } [data autorelease]; #ifdef __LP64__ - DebugF ("bmimage retainCount before release %lu\n", [bmimage retainCount]); + DebugF("bmimage retainCount before release %lu\n",[bmimage retainCount]); #else - DebugF ("bmimage retainCount before release %u\n", [bmimage retainCount]); + DebugF("bmimage retainCount before release %u\n",[bmimage retainCount]); #endif [bmimage autorelease]; } /* This handles the UTF8_STRING type of selection. */ -- (void) handle_utf8_string:(struct propdata *)pdata pasteboard:(NSPasteboard *)pb + -(void) handle_utf8_string:(struct propdata *) +pdata pasteboard:(NSPasteboard *) pb { NSString *string; NSArray *pbtypes; - - TRACE (); - string = [[NSString alloc] initWithBytes:pdata->data length:pdata->length encoding:NSUTF8StringEncoding]; - + TRACE(); + + string =[[NSString alloc] initWithBytes: pdata->data length: pdata->length encoding:NSUTF8StringEncoding]; + if (nil == string) - return; + return; - pbtypes = [NSArray arrayWithObjects:NSStringPboardType, nil]; + pbtypes =[NSArray arrayWithObjects:NSStringPboardType, nil]; - if (nil == pbtypes) - { - [string autorelease]; - return; + if (nil == pbtypes) { + [string autorelease]; + return; } - [pb declareTypes:pbtypes owner:nil]; - - if (YES != [pb setString:string forType:NSStringPboardType]) { - ErrorF("pasteboard setString:forType: failed!\n"); + [pb declareTypes: pbtypes owner:nil]; + + if (YES !=[pb setString: string forType:NSStringPboardType]) { + ErrorF("pasteboard setString:forType: failed!\n"); } [string autorelease]; - DebugF ("done handling utf8 string\n"); + DebugF("done handling utf8 string\n"); } /* This handles the STRING type, which should be in Latin-1. */ -- (void) handle_string: (struct propdata *)pdata pasteboard:(NSPasteboard *)pb + -(void) handle_string:(struct propdata *) +pdata pasteboard:(NSPasteboard *) pb { - NSString *string; + NSString *string; NSArray *pbtypes; - TRACE (); + TRACE(); + + string =[[NSString alloc] initWithBytes: pdata->data length: pdata->length encoding:NSISOLatin1StringEncoding]; - string = [[NSString alloc] initWithBytes:pdata->data length:pdata->length encoding:NSISOLatin1StringEncoding]; - if (nil == string) - return; + return; - pbtypes = [NSArray arrayWithObjects:NSStringPboardType, nil]; + pbtypes =[NSArray arrayWithObjects:NSStringPboardType, nil]; - if (nil == pbtypes) - { - [string autorelease]; - return; + if (nil == pbtypes) { + [string autorelease]; + return; } - [pb declareTypes:pbtypes owner:nil]; - if (YES != [pb setString:string forType:NSStringPboardType]) { - ErrorF("pasteboard setString:forType failed in handle_string!\n"); + [pb declareTypes: pbtypes owner:nil]; + if (YES !=[pb setString: string forType:NSStringPboardType]) { + ErrorF("pasteboard setString:forType failed in handle_string!\n"); } [string autorelease]; } /* This is called when the selection is completely retrieved from another client. */ /* Warning: this frees the propdata. */ -- (void) handle_selection:(Atom)selection type:(Atom)type propdata:(struct propdata *)pdata + -(void) handle_selection:(Atom) +selection type:(Atom) +type propdata:(struct propdata *) pdata { NSPasteboard *pb; - TRACE (); + TRACE(); - pb = [NSPasteboard generalPasteboard]; + pb =[NSPasteboard generalPasteboard]; - if (nil == pb) - { - [self copy_completed:selection]; - free_propdata (pdata); - return; + if (nil == pb) { + [self copy_completed:selection]; + free_propdata(pdata); + return; } /* @@ -1381,205 +1324,201 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato * These aren't ICCCM compliant apps, but we need these to work... */ if (request_atom == atoms->targets - && (type == atoms->atom || type == atoms->targets)) - { - [self handle_targets:selection propdata:pdata]; - free_propdata(pdata); - return; - } - else if (type == atoms->image_png) - { - [self handle_image:pdata pasteboard:pb]; - } - else if (type == atoms->image_jpeg) - { - [self handle_image:pdata pasteboard:pb]; - } - else if (type == atoms->utf8_string) - { - [self handle_utf8_string:pdata pasteboard:pb]; - } - else if (type == atoms->string) - { - [self handle_string:pdata pasteboard:pb]; - } - + && (type == atoms->atom || type == atoms->targets)) { + [self handle_targets: selection propdata:pdata]; + free_propdata(pdata); + return; + } + else if (type == atoms->image_png) { + [self handle_image: pdata pasteboard:pb]; + } + else if (type == atoms->image_jpeg) { + [self handle_image: pdata pasteboard:pb]; + } + else if (type == atoms->utf8_string) { + [self handle_utf8_string: pdata pasteboard:pb]; + } + else if (type == atoms->string) { + [self handle_string: pdata pasteboard:pb]; + } + free_propdata(pdata); - [self copy_completed:selection]; + [self copy_completed:selection]; } - -- (void) copy_completed:(Atom)selection -{ - TRACE (); + -(void) copy_completed:(Atom) selection { + TRACE(); char *name; - (void)name; /* Avoid warning with non-debug compiles. */ + (void) name; /* Avoid warning with non-debug compiles. */ #ifdef DEBUG - name = XGetAtomName (xpbproxy_dpy, selection); - if (name) - { - DebugF ("copy_completed: %s\n", name); - XFree (name); + name = XGetAtomName(xpbproxy_dpy, selection); + if (name) { + DebugF("copy_completed: %s\n", name); + XFree(name); } #endif - if (selection == atoms->primary && pending_copy > 0) - { - --pending_copy; - if (pending_copy > 0) - { - /* Copy PRIMARY again. */ - [self x_copy_request_targets]; - return; - } - } - else if (selection == atoms->clipboard && pending_clipboard > 0) - { - --pending_clipboard; - if (pending_clipboard > 0) - { - /* Copy CLIPBOARD. */ - [self claim_clipboard]; - return; - } - else - { - /* We got the final data. Now set pbproxy as the owner. */ - [self own_clipboard]; - return; - } - } - + if (selection == atoms->primary && pending_copy > 0) { + --pending_copy; + if (pending_copy > 0) { + /* Copy PRIMARY again. */ + [self x_copy_request_targets]; + return; + } + } + else if (selection == atoms->clipboard && pending_clipboard > 0) { + --pending_clipboard; + if (pending_clipboard > 0) { + /* Copy CLIPBOARD. */ + [self claim_clipboard]; + return; + } + else { + /* We got the final data. Now set pbproxy as the owner. */ + [self own_clipboard]; + return; + } + } + /* * We had 1 or more primary in progress, and the clipboard arrived * while we were busy. */ - if (pending_clipboard > 0) - { - [self claim_clipboard]; + if (pending_clipboard > 0) { + [self claim_clipboard]; } } -- (void) reload_preferences -{ +-(void) reload_preferences { /* * It's uncertain how we could handle the synchronization failing, so cast to void. * The prefs_get_bool should fall back to defaults if the org.x.X11 plist doesn't exist or is invalid. */ - (void)CFPreferencesAppSynchronize(app_prefs_domain_cfstr); + (void) CFPreferencesAppSynchronize(app_prefs_domain_cfstr); #ifdef STANDALONE_XPBPROXY - if(xpbproxy_is_standalone) + if (xpbproxy_is_standalone) pbproxy_prefs.active = YES; else #endif - pbproxy_prefs.active = prefs_get_bool(CFSTR("sync_pasteboard"), pbproxy_prefs.active); - pbproxy_prefs.primary_on_grab = prefs_get_bool(CFSTR("sync_primary_on_select"), pbproxy_prefs.primary_on_grab); - pbproxy_prefs.clipboard_to_pasteboard = prefs_get_bool(CFSTR("sync_clipboard_to_pasteboard"), pbproxy_prefs.clipboard_to_pasteboard); - pbproxy_prefs.pasteboard_to_primary = prefs_get_bool(CFSTR("sync_pasteboard_to_primary"), pbproxy_prefs.pasteboard_to_primary); - pbproxy_prefs.pasteboard_to_clipboard = prefs_get_bool(CFSTR("sync_pasteboard_to_clipboard"), pbproxy_prefs.pasteboard_to_clipboard); + pbproxy_prefs.active = + prefs_get_bool(CFSTR("sync_pasteboard"), pbproxy_prefs.active); + pbproxy_prefs.primary_on_grab = + prefs_get_bool(CFSTR("sync_primary_on_select"), + pbproxy_prefs.primary_on_grab); + pbproxy_prefs.clipboard_to_pasteboard = + prefs_get_bool(CFSTR("sync_clipboard_to_pasteboard"), + pbproxy_prefs.clipboard_to_pasteboard); + pbproxy_prefs.pasteboard_to_primary = + prefs_get_bool(CFSTR("sync_pasteboard_to_primary"), + pbproxy_prefs.pasteboard_to_primary); + pbproxy_prefs.pasteboard_to_clipboard = + prefs_get_bool(CFSTR("sync_pasteboard_to_clipboard"), + pbproxy_prefs.pasteboard_to_clipboard); /* This is used for debugging. */ //dump_prefs(); - if(pbproxy_prefs.active && pbproxy_prefs.primary_on_grab && !xpbproxy_have_xfixes) { - ErrorF("Disabling sync_primary_on_select functionality due to missing XFixes extension.\n"); + if (pbproxy_prefs.active && pbproxy_prefs.primary_on_grab && + !xpbproxy_have_xfixes) { + ErrorF + ("Disabling sync_primary_on_select functionality due to missing XFixes extension.\n"); pbproxy_prefs.primary_on_grab = NO; } /* Claim or release the CLIPBOARD_MANAGER atom */ - if(![self set_clipboard_manager_status:(pbproxy_prefs.active && pbproxy_prefs.clipboard_to_pasteboard)]) + if (![self set_clipboard_manager_status:(pbproxy_prefs.active && + pbproxy_prefs. + clipboard_to_pasteboard)]) pbproxy_prefs.clipboard_to_pasteboard = NO; - - if(pbproxy_prefs.active && pbproxy_prefs.clipboard_to_pasteboard) + + if (pbproxy_prefs.active && pbproxy_prefs.clipboard_to_pasteboard) [self claim_clipboard]; } -- (BOOL) is_active -{ +-(BOOL) is_active { return pbproxy_prefs.active; } /* NSPasteboard-required methods */ -- (void) paste:(id)sender -{ - TRACE (); + -(void) paste:(id) sender { + TRACE(); } -- (void) pasteboard:(NSPasteboard *)pb provideDataForType:(NSString *)type + -(void) pasteboard:(NSPasteboard *) +pb provideDataForType:(NSString *) type { - TRACE (); + TRACE(); } -- (void) pasteboardChangedOwner:(NSPasteboard *)pb -{ - TRACE (); + -(void) pasteboardChangedOwner:(NSPasteboard *) pb { + TRACE(); /* Right now we don't care with this. */ } /* Allocation */ -- init -{ +-init { unsigned long pixel; - self = [super init]; + self =[super init]; if (self == nil) - return nil; - - atoms->primary = XInternAtom (xpbproxy_dpy, "PRIMARY", False); - atoms->clipboard = XInternAtom (xpbproxy_dpy, "CLIPBOARD", False); - atoms->text = XInternAtom (xpbproxy_dpy, "TEXT", False); - atoms->utf8_string = XInternAtom (xpbproxy_dpy, "UTF8_STRING", False); - atoms->string = XInternAtom (xpbproxy_dpy, "STRING", False); - atoms->targets = XInternAtom (xpbproxy_dpy, "TARGETS", False); - atoms->multiple = XInternAtom (xpbproxy_dpy, "MULTIPLE", False); - atoms->cstring = XInternAtom (xpbproxy_dpy, "CSTRING", False); - atoms->image_png = XInternAtom (xpbproxy_dpy, "image/png", False); - atoms->image_jpeg = XInternAtom (xpbproxy_dpy, "image/jpeg", False); - atoms->incr = XInternAtom (xpbproxy_dpy, "INCR", False); - atoms->atom = XInternAtom (xpbproxy_dpy, "ATOM", False); - atoms->clipboard_manager = XInternAtom (xpbproxy_dpy, "CLIPBOARD_MANAGER", False); - atoms->compound_text = XInternAtom (xpbproxy_dpy, "COMPOUND_TEXT", False); - atoms->atom_pair = XInternAtom (xpbproxy_dpy, "ATOM_PAIR", False); - - pixel = BlackPixel (xpbproxy_dpy, DefaultScreen (xpbproxy_dpy)); - _selection_window = XCreateSimpleWindow (xpbproxy_dpy, DefaultRootWindow (xpbproxy_dpy), - 0, 0, 1, 1, 0, pixel, pixel); + return nil; + + atoms->primary = XInternAtom(xpbproxy_dpy, "PRIMARY", False); + atoms->clipboard = XInternAtom(xpbproxy_dpy, "CLIPBOARD", False); + atoms->text = XInternAtom(xpbproxy_dpy, "TEXT", False); + atoms->utf8_string = XInternAtom(xpbproxy_dpy, "UTF8_STRING", False); + atoms->string = XInternAtom(xpbproxy_dpy, "STRING", False); + atoms->targets = XInternAtom(xpbproxy_dpy, "TARGETS", False); + atoms->multiple = XInternAtom(xpbproxy_dpy, "MULTIPLE", False); + atoms->cstring = XInternAtom(xpbproxy_dpy, "CSTRING", False); + atoms->image_png = XInternAtom(xpbproxy_dpy, "image/png", False); + atoms->image_jpeg = XInternAtom(xpbproxy_dpy, "image/jpeg", False); + atoms->incr = XInternAtom(xpbproxy_dpy, "INCR", False); + atoms->atom = XInternAtom(xpbproxy_dpy, "ATOM", False); + atoms->clipboard_manager = + XInternAtom(xpbproxy_dpy, "CLIPBOARD_MANAGER", False); + atoms->compound_text = XInternAtom(xpbproxy_dpy, "COMPOUND_TEXT", False); + atoms->atom_pair = XInternAtom(xpbproxy_dpy, "ATOM_PAIR", False); + + pixel = BlackPixel(xpbproxy_dpy, DefaultScreen(xpbproxy_dpy)); + _selection_window = + XCreateSimpleWindow(xpbproxy_dpy, DefaultRootWindow(xpbproxy_dpy), 0, 0, + 1, 1, 0, pixel, pixel); /* This is used to get PropertyNotify events when doing INCR transfers. */ - XSelectInput (xpbproxy_dpy, _selection_window, PropertyChangeMask); + XSelectInput(xpbproxy_dpy, _selection_window, PropertyChangeMask); request_atom = None; - init_propdata (&pending.propdata); + init_propdata(&pending.propdata); pending.requestor = None; pending.selection = None; pending_copy = 0; pending_clipboard = 0; - if(xpbproxy_have_xfixes) - XFixesSelectSelectionInput(xpbproxy_dpy, _selection_window, atoms->primary, + if (xpbproxy_have_xfixes) + XFixesSelectSelectionInput(xpbproxy_dpy, _selection_window, + atoms->primary, XFixesSetSelectionOwnerNotifyMask); [self reload_preferences]; - + return self; } -- (void) dealloc -{ - if (None != _selection_window) - { - XDestroyWindow (xpbproxy_dpy, _selection_window); - _selection_window = None; +-(void) dealloc { + if (None != _selection_window) { + XDestroyWindow(xpbproxy_dpy, _selection_window); + _selection_window = None; } - free_propdata (&pending.propdata); + free_propdata(&pending.propdata); [super dealloc]; } diff --git a/xorg-server/hw/xquartz/pseudoramiX.c b/xorg-server/hw/xquartz/pseudoramiX.c index 5a5b9c2e7..f5375039b 100644 --- a/xorg-server/hw/xquartz/pseudoramiX.c +++ b/xorg-server/hw/xquartz/pseudoramiX.c @@ -47,9 +47,9 @@ Equipment Corporation. Bool noPseudoramiXExtension = FALSE; -extern int ProcPanoramiXQueryVersion (ClientPtr client); +extern int ProcPanoramiXQueryVersion(ClientPtr client); -static void PseudoramiXResetProc(ExtensionEntry *extEntry); +static void PseudoramiXResetProc(ExtensionEntry * extEntry); static int ProcPseudoramiXQueryVersion(ClientPtr client); static int ProcPseudoramiXGetState(ClientPtr client); @@ -67,7 +67,6 @@ static int SProcPseudoramiXIsActive(ClientPtr client); static int SProcPseudoramiXQueryScreens(ClientPtr client); static int SProcPseudoramiXDispatch(ClientPtr client); - typedef struct { int x; int y; @@ -80,7 +79,6 @@ static int pseudoramiXScreensAllocated = 0; static int pseudoramiXNumScreens = 0; static unsigned long pseudoramiXGeneration = 0; - // Add a PseudoramiX screen. // The rest of the X server will know nothing about this screen. // Can be called before or after extension init. @@ -90,13 +88,14 @@ PseudoramiXAddScreen(int x, int y, int w, int h) { PseudoramiXScreenRec *s; - if (noPseudoramiXExtension) return; + if (noPseudoramiXExtension) + return; if (pseudoramiXNumScreens == pseudoramiXScreensAllocated) { pseudoramiXScreensAllocated += pseudoramiXScreensAllocated + 1; pseudoramiXScreens = realloc(pseudoramiXScreens, - pseudoramiXScreensAllocated * - sizeof(PseudoramiXScreenRec)); + pseudoramiXScreensAllocated * + sizeof(PseudoramiXScreenRec)); } DEBUG_LOG("x: %d, y: %d, w: %d, h: %d\n", x, y, w, h); @@ -108,15 +107,16 @@ PseudoramiXAddScreen(int x, int y, int w, int h) s->h = h; } - // Initialize PseudoramiX. // Copied from PanoramiXExtensionInit -void PseudoramiXExtensionInit(int argc, char *argv[]) +void +PseudoramiXExtensionInit(int argc, char *argv[]) { - Bool success = FALSE; - ExtensionEntry *extEntry; + Bool success = FALSE; + ExtensionEntry *extEntry; - if (noPseudoramiXExtension) return; + if (noPseudoramiXExtension) + return; TRACE(); @@ -134,11 +134,11 @@ void PseudoramiXExtensionInit(int argc, char *argv[]) extEntry = AddExtension(PANORAMIX_PROTOCOL_NAME, 0, 0, ProcPseudoramiXDispatch, SProcPseudoramiXDispatch, - PseudoramiXResetProc, - StandardMinorOpcode); + PseudoramiXResetProc, StandardMinorOpcode); if (!extEntry) { ErrorF("PseudoramiXExtensionInit(): AddExtension failed\n"); - } else { + } + else { pseudoramiXGeneration = serverGeneration; success = TRUE; } @@ -151,34 +151,34 @@ void PseudoramiXExtensionInit(int argc, char *argv[]) } } - -void PseudoramiXResetScreens(void) +void +PseudoramiXResetScreens(void) { TRACE(); pseudoramiXNumScreens = 0; } - -static void PseudoramiXResetProc(ExtensionEntry *extEntry) +static void +PseudoramiXResetProc(ExtensionEntry * extEntry) { TRACE(); PseudoramiXResetScreens(); } - // was PanoramiX -static int ProcPseudoramiXQueryVersion(ClientPtr client) +static int +ProcPseudoramiXQueryVersion(ClientPtr client) { TRACE(); return ProcPanoramiXQueryVersion(client); } - // was PanoramiX -static int ProcPseudoramiXGetState(ClientPtr client) +static int +ProcPseudoramiXGetState(ClientPtr client) { REQUEST(xPanoramiXGetStateReq); WindowPtr pWin; @@ -186,11 +186,11 @@ static int ProcPseudoramiXGetState(ClientPtr client) register int rc; TRACE(); - + REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; rep.length = 0; @@ -201,13 +201,13 @@ static int ProcPseudoramiXGetState(ClientPtr client) swapl(&rep.length); swaps(&rep.state); } - WriteToClient (client, sizeof (xPanoramiXGetStateReply), (char *) &rep); + WriteToClient(client, sizeof(xPanoramiXGetStateReply), (char *) &rep); return Success; } - // was PanoramiX -static int ProcPseudoramiXGetScreenCount(ClientPtr client) +static int +ProcPseudoramiXGetScreenCount(ClientPtr client) { REQUEST(xPanoramiXGetScreenCountReq); WindowPtr pWin; @@ -215,11 +215,11 @@ static int ProcPseudoramiXGetScreenCount(ClientPtr client) register int rc; TRACE(); - + REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; rep.length = 0; @@ -230,31 +230,31 @@ static int ProcPseudoramiXGetScreenCount(ClientPtr client) swapl(&rep.length); swaps(&rep.ScreenCount); } - WriteToClient (client, sizeof(xPanoramiXGetScreenCountReply), (char *)&rep); + WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), (char *) &rep); return Success; } - // was PanoramiX -static int ProcPseudoramiXGetScreenSize(ClientPtr client) +static int +ProcPseudoramiXGetScreenSize(ClientPtr client) { REQUEST(xPanoramiXGetScreenSizeReq); - WindowPtr pWin; - xPanoramiXGetScreenSizeReply rep; - register int n, rc; + WindowPtr pWin; + xPanoramiXGetScreenSizeReply rep; + register int n, rc; TRACE(); - + REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; /* screen dimensions */ - rep.width = pseudoramiXScreens[stuff->screen].w; + rep.width = pseudoramiXScreens[stuff->screen].w; // was screenInfo.screens[stuff->screen]->width; rep.height = pseudoramiXScreens[stuff->screen].h; // was screenInfo.screens[stuff->screen]->height; @@ -264,19 +264,19 @@ static int ProcPseudoramiXGetScreenSize(ClientPtr client) swaps(&rep.width); swaps(&rep.height); } - WriteToClient (client, sizeof(xPanoramiXGetScreenSizeReply), (char *)&rep); + WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), (char *) &rep); return Success; } - // was Xinerama -static int ProcPseudoramiXIsActive(ClientPtr client) +static int +ProcPseudoramiXIsActive(ClientPtr client) { /* REQUEST(xXineramaIsActiveReq); */ - xXineramaIsActiveReply rep; + xXineramaIsActiveReply rep; TRACE(); - + REQUEST_SIZE_MATCH(xXineramaIsActiveReq); rep.type = X_Reply; @@ -284,23 +284,24 @@ static int ProcPseudoramiXIsActive(ClientPtr client) rep.sequenceNumber = client->sequence; rep.state = !noPseudoramiXExtension; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.state); + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.state); } - WriteToClient (client, sizeof (xXineramaIsActiveReply), (char *) &rep); + WriteToClient(client, sizeof(xXineramaIsActiveReply), (char *) &rep); return Success; } - // was Xinerama -static int ProcPseudoramiXQueryScreens(ClientPtr client) +static int +ProcPseudoramiXQueryScreens(ClientPtr client) { /* REQUEST(xXineramaQueryScreensReq); */ - xXineramaQueryScreensReply rep; + xXineramaQueryScreensReply rep; + + DEBUG_LOG("noPseudoramiXExtension=%d, pseudoramiXNumScreens=%d\n", + noPseudoramiXExtension, pseudoramiXNumScreens); - DEBUG_LOG("noPseudoramiXExtension=%d, pseudoramiXNumScreens=%d\n", noPseudoramiXExtension, pseudoramiXNumScreens); - REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); rep.type = X_Reply; @@ -308,155 +309,150 @@ static int ProcPseudoramiXQueryScreens(ClientPtr client) rep.number = noPseudoramiXExtension ? 0 : pseudoramiXNumScreens; rep.length = bytes_to_int32(rep.number * sz_XineramaScreenInfo); if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.number); + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.number); } - WriteToClient (client, sizeof (xXineramaQueryScreensReply), (char *) &rep); + WriteToClient(client, sizeof(xXineramaQueryScreensReply), (char *) &rep); if (!noPseudoramiXExtension) { - xXineramaScreenInfo scratch; - int i; - - for(i = 0; i < pseudoramiXNumScreens; i++) { - scratch.x_org = pseudoramiXScreens[i].x; - scratch.y_org = pseudoramiXScreens[i].y; - scratch.width = pseudoramiXScreens[i].w; - scratch.height = pseudoramiXScreens[i].h; - - if(client->swapped) { - swaps(&scratch.x_org); - swaps(&scratch.y_org); - swaps(&scratch.width); - swaps(&scratch.height); - } - WriteToClient (client, sz_XineramaScreenInfo, (char *) &scratch); - } + xXineramaScreenInfo scratch; + int i; + + for (i = 0; i < pseudoramiXNumScreens; i++) { + scratch.x_org = pseudoramiXScreens[i].x; + scratch.y_org = pseudoramiXScreens[i].y; + scratch.width = pseudoramiXScreens[i].w; + scratch.height = pseudoramiXScreens[i].h; + + if (client->swapped) { + swaps(&scratch.x_org); + swaps(&scratch.y_org); + swaps(&scratch.width); + swaps(&scratch.height); + } + WriteToClient(client, sz_XineramaScreenInfo, (char *) &scratch); + } } return Success; } - // was PanoramiX -static int ProcPseudoramiXDispatch (ClientPtr client) -{ REQUEST(xReq); +static int +ProcPseudoramiXDispatch(ClientPtr client) +{ + REQUEST(xReq); TRACE(); - switch (stuff->data) - { - case X_PanoramiXQueryVersion: - return ProcPseudoramiXQueryVersion(client); - case X_PanoramiXGetState: - return ProcPseudoramiXGetState(client); - case X_PanoramiXGetScreenCount: - return ProcPseudoramiXGetScreenCount(client); - case X_PanoramiXGetScreenSize: - return ProcPseudoramiXGetScreenSize(client); - case X_XineramaIsActive: - return ProcPseudoramiXIsActive(client); - case X_XineramaQueryScreens: - return ProcPseudoramiXQueryScreens(client); + switch (stuff->data) { + case X_PanoramiXQueryVersion: + return ProcPseudoramiXQueryVersion(client); + case X_PanoramiXGetState: + return ProcPseudoramiXGetState(client); + case X_PanoramiXGetScreenCount: + return ProcPseudoramiXGetScreenCount(client); + case X_PanoramiXGetScreenSize: + return ProcPseudoramiXGetScreenSize(client); + case X_XineramaIsActive: + return ProcPseudoramiXIsActive(client); + case X_XineramaQueryScreens: + return ProcPseudoramiXQueryScreens(client); } return BadRequest; } - - static int -SProcPseudoramiXQueryVersion (ClientPtr client) +SProcPseudoramiXQueryVersion(ClientPtr client) { - REQUEST(xPanoramiXQueryVersionReq); + REQUEST(xPanoramiXQueryVersionReq); TRACE(); - swaps(&stuff->length); - REQUEST_SIZE_MATCH (xPanoramiXQueryVersionReq); - return ProcPseudoramiXQueryVersion(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq); + return ProcPseudoramiXQueryVersion(client); } static int SProcPseudoramiXGetState(ClientPtr client) { - REQUEST(xPanoramiXGetStateReq); + REQUEST(xPanoramiXGetStateReq); TRACE(); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); - return ProcPseudoramiXGetState(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); + return ProcPseudoramiXGetState(client); } static int SProcPseudoramiXGetScreenCount(ClientPtr client) { - REQUEST(xPanoramiXGetScreenCountReq); + REQUEST(xPanoramiXGetScreenCountReq); TRACE(); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); - return ProcPseudoramiXGetScreenCount(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); + return ProcPseudoramiXGetScreenCount(client); } static int SProcPseudoramiXGetScreenSize(ClientPtr client) { - REQUEST(xPanoramiXGetScreenSizeReq); + REQUEST(xPanoramiXGetScreenSizeReq); TRACE(); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); - return ProcPseudoramiXGetScreenSize(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); + return ProcPseudoramiXGetScreenSize(client); } - static int SProcPseudoramiXIsActive(ClientPtr client) { - REQUEST(xXineramaIsActiveReq); + REQUEST(xXineramaIsActiveReq); TRACE(); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xXineramaIsActiveReq); - return ProcPseudoramiXIsActive(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xXineramaIsActiveReq); + return ProcPseudoramiXIsActive(client); } - static int SProcPseudoramiXQueryScreens(ClientPtr client) { - REQUEST(xXineramaQueryScreensReq); + REQUEST(xXineramaQueryScreensReq); TRACE(); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); - return ProcPseudoramiXQueryScreens(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); + return ProcPseudoramiXQueryScreens(client); } - static int -SProcPseudoramiXDispatch (ClientPtr client) -{ REQUEST(xReq); +SProcPseudoramiXDispatch(ClientPtr client) +{ + REQUEST(xReq); TRACE(); - switch (stuff->data) - { - case X_PanoramiXQueryVersion: - return SProcPseudoramiXQueryVersion(client); - case X_PanoramiXGetState: - return SProcPseudoramiXGetState(client); - case X_PanoramiXGetScreenCount: - return SProcPseudoramiXGetScreenCount(client); - case X_PanoramiXGetScreenSize: - return SProcPseudoramiXGetScreenSize(client); - case X_XineramaIsActive: - return SProcPseudoramiXIsActive(client); - case X_XineramaQueryScreens: - return SProcPseudoramiXQueryScreens(client); + switch (stuff->data) { + case X_PanoramiXQueryVersion: + return SProcPseudoramiXQueryVersion(client); + case X_PanoramiXGetState: + return SProcPseudoramiXGetState(client); + case X_PanoramiXGetScreenCount: + return SProcPseudoramiXGetScreenCount(client); + case X_PanoramiXGetScreenSize: + return SProcPseudoramiXGetScreenSize(client); + case X_XineramaIsActive: + return SProcPseudoramiXIsActive(client); + case X_XineramaQueryScreens: + return SProcPseudoramiXQueryScreens(client); } return BadRequest; } diff --git a/xorg-server/hw/xquartz/quartz.c b/xorg-server/hw/xquartz/quartz.c index c395b42e6..e4578cc3e 100644 --- a/xorg-server/hw/xquartz/quartz.c +++ b/xorg-server/hw/xquartz/quartz.c @@ -68,10 +68,10 @@ #include <rootlessCommon.h> #include <Xplugin.h> -DevPrivateKeyRec quartzScreenKeyRec; -int aquaMenuBarHeight = 0; -QuartzModeProcsPtr quartzProcs = NULL; -const char *quartzOpenGLBundle = NULL; +DevPrivateKeyRec quartzScreenKeyRec; +int aquaMenuBarHeight = 0; +QuartzModeProcsPtr quartzProcs = NULL; +const char *quartzOpenGLBundle = NULL; Bool XQuartzFullscreenDisableHotkeys = TRUE; Bool XQuartzOptionSendsAlt = FALSE; @@ -96,9 +96,8 @@ int32_t XQuartzShieldingWindowLevel = 0; * QuartzAddScreen * Do mode dependent initialization of each screen for Quartz. */ -Bool QuartzAddScreen( - int index, - ScreenPtr pScreen) +Bool +QuartzAddScreen(int index, ScreenPtr pScreen) { // allocate space for private per screen Quartz specific storage QuartzScreenPtr displayInfo = calloc(sizeof(QuartzScreenRec), 1); @@ -110,25 +109,23 @@ Bool QuartzAddScreen( return quartzProcs->AddScreen(index, pScreen); } - /* * QuartzSetupScreen * Finalize mode specific setup of each screen. */ -Bool QuartzSetupScreen( - int index, - ScreenPtr pScreen) +Bool +QuartzSetupScreen(int index, ScreenPtr pScreen) { // do Quartz mode specific setup - if (! quartzProcs->SetupScreen(index, pScreen)) + if (!quartzProcs->SetupScreen(index, pScreen)) return FALSE; // setup cursor support - if (! quartzProcs->InitCursor(pScreen)) + if (!quartzProcs->InitCursor(pScreen)) return FALSE; #if defined(RANDR) - if(!QuartzRandRInit(pScreen)) { + if (!QuartzRandRInit(pScreen)) { DEBUG_LOG("Failed to init RandR extension.\n"); return FALSE; } @@ -137,14 +134,12 @@ Bool QuartzSetupScreen( return TRUE; } - /* * QuartzInitOutput * Quartz display initialization. */ -void QuartzInitOutput( - int argc, - char **argv ) +void +QuartzInitOutput(int argc, char **argv) { /* For XQuartz, we want to just use the default signal handler to work better with CrashTracer */ signal(SIGSEGV, SIG_DFL); @@ -167,27 +162,23 @@ void QuartzInitOutput( #endif if (!RegisterBlockAndWakeupHandlers(QuartzBlockHandler, - QuartzWakeupHandler, - NULL)) - { + QuartzWakeupHandler, NULL)) { FatalError("Could not register block and wakeup handlers."); } if (!dixRegisterPrivateKey(&quartzScreenKeyRec, PRIVATE_SCREEN, 0)) - FatalError("Failed to alloc quartz screen private.\n"); + FatalError("Failed to alloc quartz screen private.\n"); // Do display mode specific initialization quartzProcs->DisplayInit(); } - /* * QuartzInitInput * Inform the main thread the X server is ready to handle events. */ -void QuartzInitInput( - int argc, - char **argv ) +void +QuartzInitInput(int argc, char **argv) { X11ApplicationSetCanQuit(0); X11ApplicationServerReady(); @@ -196,44 +187,44 @@ void QuartzInitInput( quartzProcs->InitInput(argc, argv); } - -void QuartzUpdateScreens(void) { +void +QuartzUpdateScreens(void) +{ ScreenPtr pScreen; WindowPtr pRoot; int x, y, width, height, sx, sy; xEvent e; BoxRec bounds; - - if (noPseudoramiXExtension || screenInfo.numScreens != 1) - { + + if (noPseudoramiXExtension || screenInfo.numScreens != 1) { /* FIXME: if not using Xinerama, we have multiple screens, and - to do this properly may need to add or remove screens. Which - isn't possible. So don't do anything. Another reason why - we default to running with Xinerama. */ - + to do this properly may need to add or remove screens. Which + isn't possible. So don't do anything. Another reason why + we default to running with Xinerama. */ + return; } - + pScreen = screenInfo.screens[0]; - + PseudoramiXResetScreens(); quartzProcs->AddPseudoramiXScreens(&x, &y, &width, &height, pScreen); - + pScreen->x = x; pScreen->y = y; pScreen->mmWidth = pScreen->mmWidth * ((double) width / pScreen->width); pScreen->mmHeight = pScreen->mmHeight * ((double) height / pScreen->height); pScreen->width = width; pScreen->height = height; - + DarwinAdjustScreenOrigins(&screenInfo); - + /* DarwinAdjustScreenOrigins or UpdateScreen may change pScreen->x/y, * so use it rather than x/y */ sx = pScreen->x + darwinMainScreenX; sy = pScreen->y + darwinMainScreenY; - + /* Adjust the root window. */ pRoot = pScreen->root; AppleWMSetScreenOrigin(pRoot); @@ -250,7 +241,10 @@ void QuartzUpdateScreens(void) { inputInfo.pointer->spriteInfo->sprite->physLimits = bounds; inputInfo.pointer->spriteInfo->sprite->hotLimits = bounds; - DEBUG_LOG("Root Window: %dx%d @ (%d, %d) darwinMainScreen (%d, %d) xy (%d, %d) dixScreenOrigins (%d, %d)\n", width, height, x - sx, y - sy, darwinMainScreenX, darwinMainScreenY, x, y, pScreen->x, pScreen->y); + DEBUG_LOG + ("Root Window: %dx%d @ (%d, %d) darwinMainScreen (%d, %d) xy (%d, %d) dixScreenOrigins (%d, %d)\n", + width, height, x - sx, y - sy, darwinMainScreenX, darwinMainScreenY, x, + y, pScreen->x, pScreen->y); /* Send an event for the root reconfigure */ e.u.u.type = ConfigureNotify; @@ -267,74 +261,86 @@ void QuartzUpdateScreens(void) { quartzProcs->UpdateScreen(pScreen); /* miPaintWindow needs to be called after RootlessUpdateScreenPixmap (from xprUpdateScreen) */ - miPaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND); + miPaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND); /* Tell RandR about the new size, so new connections get the correct info */ RRScreenSizeNotify(pScreen); } -static void pokeActivityCallback(CFRunLoopTimerRef timer, void *info) { +static void +pokeActivityCallback(CFRunLoopTimerRef timer, void *info) +{ UpdateSystemActivity(OverallAct); } -static void QuartzScreenSaver(int state) { +static void +QuartzScreenSaver(int state) +{ static CFRunLoopTimerRef pokeActivityTimer = NULL; - static CFRunLoopTimerContext pokeActivityContext = { 0, NULL, NULL, NULL, NULL }; + static CFRunLoopTimerContext pokeActivityContext = + { 0, NULL, NULL, NULL, NULL }; static OSSpinLock pokeActivitySpinLock = OS_SPINLOCK_INIT; OSSpinLockLock(&pokeActivitySpinLock); - if(state) { - if(pokeActivityTimer == NULL) + if (state) { + if (pokeActivityTimer == NULL) goto QuartzScreenSaverEnd; CFRunLoopTimerInvalidate(pokeActivityTimer); CFRelease(pokeActivityTimer); pokeActivityTimer = NULL; - } else { - if(pokeActivityTimer != NULL) + } + else { + if (pokeActivityTimer != NULL) goto QuartzScreenSaverEnd; - - pokeActivityTimer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent(), 30, 0, 0, pokeActivityCallback, &pokeActivityContext); - if(pokeActivityTimer == NULL) { + + pokeActivityTimer = + CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent(), 30, 0, 0, + pokeActivityCallback, &pokeActivityContext); + if (pokeActivityTimer == NULL) { ErrorF("Unable to create pokeActivityTimer.\n"); goto QuartzScreenSaverEnd; } - CFRunLoopAddTimer(CFRunLoopGetMain(), pokeActivityTimer, kCFRunLoopCommonModes); + CFRunLoopAddTimer(CFRunLoopGetMain(), pokeActivityTimer, + kCFRunLoopCommonModes); } -QuartzScreenSaverEnd: + QuartzScreenSaverEnd: OSSpinLockUnlock(&pokeActivitySpinLock); } -void QuartzShowFullscreen(int state) { +void +QuartzShowFullscreen(int state) +{ int i; - + DEBUG_LOG("QuartzShowFullscreen: state=%d\n", state); - - if(XQuartzIsRootless) { + + if (XQuartzIsRootless) { ErrorF("QuartzShowFullscreen called while in rootless mode.\n"); return; } - + QuartzScreenSaver(!state); - - if(XQuartzFullscreenVisible == state) + + if (XQuartzFullscreenVisible == state) return; - + XQuartzFullscreenVisible = state; - - xp_disable_update (); - + + xp_disable_update(); + if (!XQuartzFullscreenVisible) RootlessHideAllWindows(); - + RootlessUpdateRooted(XQuartzFullscreenVisible); - + if (XQuartzFullscreenVisible) { - RootlessShowAllWindows (); - for (i=0; i < screenInfo.numScreens; i++) { - ScreenPtr pScreen = screenInfo.screens[i]; + RootlessShowAllWindows(); + for (i = 0; i < screenInfo.numScreens; i++) { + ScreenPtr pScreen = screenInfo.screens[i]; + RootlessRepositionWindows(pScreen); // JH: I don't think this is necessary, but keeping it here as a reminder //RootlessUpdateScreenPixmap(pScreen); @@ -345,32 +351,35 @@ void QuartzShowFullscreen(int state) { * in fullscreen mode, even though it's not visible. */ X11ApplicationShowHideMenubar(!XQuartzFullscreenVisible); - - xp_reenable_update (); - + + xp_reenable_update(); + if (XQuartzFullscreenDisableHotkeys) xp_disable_hot_keys(XQuartzFullscreenVisible); } -void QuartzSetRootless(Bool state) { +void +QuartzSetRootless(Bool state) +{ DEBUG_LOG("QuartzSetRootless state=%d\n", state); - - if(XQuartzIsRootless == state) + + if (XQuartzIsRootless == state) return; - - if(state) + + if (state) QuartzShowFullscreen(FALSE); - + XQuartzIsRootless = state; xp_disable_update(); - /* When in rootless, the menubar is not part of the screen, so we need to update our screens on toggle */ + /* When in rootless, the menubar is not part of the screen, so we need to update our screens on toggle */ QuartzUpdateScreens(); - if(XQuartzIsRootless) { + if (XQuartzIsRootless) { RootlessShowAllWindows(); - } else { + } + else { RootlessHideAllWindows(); } @@ -387,31 +396,33 @@ void QuartzSetRootless(Bool state) { * Calls mode specific screen resume to restore the X clip regions * (if needed) and the X server cursor state. */ -void QuartzShow(void) { +void +QuartzShow(void) +{ int i; if (XQuartzServerVisible) return; - + XQuartzServerVisible = TRUE; for (i = 0; i < screenInfo.numScreens; i++) { if (screenInfo.screens[i]) { quartzProcs->ResumeScreen(screenInfo.screens[i]); } } - + if (!XQuartzIsRootless) QuartzShowFullscreen(TRUE); } - /* * QuartzHide * Remove the X server display from the screen. Does nothing if already * hidden. Calls mode specific screen suspend to set X clip regions to * prevent drawing (if needed) and restore the Aqua cursor. */ -void QuartzHide(void) +void +QuartzHide(void) { int i; @@ -423,18 +434,17 @@ void QuartzHide(void) } } - if(!XQuartzIsRootless) + if (!XQuartzIsRootless) QuartzShowFullscreen(FALSE); XQuartzServerVisible = FALSE; } - /* * QuartzSetRootClip * Enable or disable rendering to the X screen. */ -void QuartzSetRootClip( - BOOL enable) +void +QuartzSetRootClip(BOOL enable) { int i; @@ -452,7 +462,9 @@ void QuartzSetRootClip( * QuartzSpaceChanged * Unmap offscreen windows, map onscreen windows */ -void QuartzSpaceChanged(uint32_t space_id) { +void +QuartzSpaceChanged(uint32_t space_id) +{ /* Do something special here, so we don't depend on quartz-wm for spaces to work... */ DEBUG_LOG("Space Changed (%u) ... do something interesting...\n", space_id); } @@ -462,26 +474,30 @@ void QuartzSpaceChanged(uint32_t space_id) { * Associate an X11 screen with one or more CoreGraphics display IDs by copying * the list into a private array. Free the previously copied array, if present. */ -void QuartzCopyDisplayIDs(ScreenPtr pScreen, - int displayCount, CGDirectDisplayID *displayIDs) { +void +QuartzCopyDisplayIDs(ScreenPtr pScreen, + int displayCount, CGDirectDisplayID * displayIDs) +{ QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); free(pQuartzScreen->displayIDs); - if(displayCount) { + if (displayCount) { size_t size = displayCount * sizeof(CGDirectDisplayID); + pQuartzScreen->displayIDs = malloc(size); memcpy(pQuartzScreen->displayIDs, displayIDs, size); - } else { - pQuartzScreen->displayIDs = NULL; + } + else { + pQuartzScreen->displayIDs = NULL; } pQuartzScreen->displayCount = displayCount; } void NSBeep(void); -void DDXRingBell( - int volume, // volume is % of max - int pitch, // pitch is Hz - int duration) // duration is milliseconds +void +DDXRingBell(int volume, // volume is % of max + int pitch, // pitch is Hz + int duration) // duration is milliseconds { if (volume) NSBeep(); diff --git a/xorg-server/hw/xquartz/quartzCocoa.m b/xorg-server/hw/xquartz/quartzCocoa.m index d1087015b..c0401b5e1 100644 --- a/xorg-server/hw/xquartz/quartzCocoa.m +++ b/xorg-server/hw/xquartz/quartzCocoa.m @@ -1,71 +1,66 @@ -/**************************************************************
- *
- * Quartz-specific support for the Darwin X Server
- * that requires Cocoa and Objective-C.
- *
- * This file is separate from the parts of Quartz support
- * that use X include files to avoid symbol collisions.
- *
- * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker.
- * 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 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 ABOVE LISTED COPYRIGHT HOLDER(S) 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(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#include "sanitizedCocoa.h"
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "quartzCommon.h"
-#include "inputstr.h"
-
-#include "darwin.h"
-
-/*
- * QuartzBlockHandler
- * Clean out any autoreleased objects.
- */
-void QuartzBlockHandler(
- pointer blockData,
- OSTimePtr pTimeout,
- pointer pReadmask)
-{
- static NSAutoreleasePool *aPool = nil;
-
- [aPool release];
- aPool = [[NSAutoreleasePool alloc] init];
-}
-
-
-/*
- * QuartzWakeupHandler
- */
-void QuartzWakeupHandler(
- pointer blockData,
- int result,
- pointer pReadmask)
-{
- // nothing here
-}
+/************************************************************** + * + * Quartz-specific support for the Darwin X Server + * that requires Cocoa and Objective-C. + * + * This file is separate from the parts of Quartz support + * that use X include files to avoid symbol collisions. + * + * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker. + * 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 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 ABOVE LISTED COPYRIGHT HOLDER(S) 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(s) of the above copyright + * holders shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written authorization. + */ + +#include "sanitizedCocoa.h" + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "quartzCommon.h" +#include "inputstr.h" + +#include "darwin.h" + +/* + * QuartzBlockHandler + * Clean out any autoreleased objects. + */ +void +QuartzBlockHandler(pointer blockData, OSTimePtr pTimeout, pointer pReadmask) +{ + static NSAutoreleasePool *aPool = nil; + + [aPool release]; + aPool =[[NSAutoreleasePool alloc] init]; +} + +/* + * QuartzWakeupHandler + */ +void +QuartzWakeupHandler(pointer blockData, int result, pointer pReadmask) +{ + // nothing here +} diff --git a/xorg-server/hw/xquartz/quartzCommon.h b/xorg-server/hw/xquartz/quartzCommon.h index ac089ac71..e12e1d25c 100644 --- a/xorg-server/hw/xquartz/quartzCommon.h +++ b/xorg-server/hw/xquartz/quartzCommon.h @@ -1,52 +1,54 @@ -/*
- * quartzCommon.h
- *
- * Common definitions used internally by all Quartz modes
- *
- * This file should be included before any X11 or IOKit headers
- * so that it can avoid symbol conflicts.
- *
- * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker.
- * 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 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 ABOVE LISTED COPYRIGHT HOLDER(S) 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(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#ifndef _QUARTZCOMMON_H
-#define _QUARTZCOMMON_H
-
-#include <X11/Xdefs.h>
-#include "privates.h"
-
-// Other shared data
-extern DevPrivateKeyRec quartzScreenKeyRec;
-#define quartzScreenKey (&quartzScreenKeyRec)
-extern int aquaMenuBarHeight;
-
-// Name of GLX bundle for native OpenGL
-extern const char *quartzOpenGLBundle;
-
-void QuartzBlockHandler(pointer blockData, OSTimePtr pTimeout, pointer pReadmask);
-void QuartzWakeupHandler(pointer blockData, int result, pointer pReadmask);
-
-#endif /* _QUARTZCOMMON_H */
+/* + * quartzCommon.h + * + * Common definitions used internally by all Quartz modes + * + * This file should be included before any X11 or IOKit headers + * so that it can avoid symbol conflicts. + * + * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker. + * 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 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 ABOVE LISTED COPYRIGHT HOLDER(S) 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(s) of the above copyright + * holders shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written authorization. + */ + +#ifndef _QUARTZCOMMON_H +#define _QUARTZCOMMON_H + +#include <X11/Xdefs.h> +#include "privates.h" + +// Other shared data +extern DevPrivateKeyRec quartzScreenKeyRec; + +#define quartzScreenKey (&quartzScreenKeyRec) +extern int aquaMenuBarHeight; + +// Name of GLX bundle for native OpenGL +extern const char *quartzOpenGLBundle; + +void QuartzBlockHandler(pointer blockData, OSTimePtr pTimeout, + pointer pReadmask); +void QuartzWakeupHandler(pointer blockData, int result, pointer pReadmask); + +#endif /* _QUARTZCOMMON_H */ diff --git a/xorg-server/hw/xquartz/quartzKeyboard.c b/xorg-server/hw/xquartz/quartzKeyboard.c index e682f08b6..e7aadbcf5 100644 --- a/xorg-server/hw/xquartz/quartzKeyboard.c +++ b/xorg-server/hw/xquartz/quartzKeyboard.c @@ -65,7 +65,7 @@ #include "keysym2ucs.h" extern void -CopyKeyClass(DeviceIntPtr device, DeviceIntPtr master); + CopyKeyClass(DeviceIntPtr device, DeviceIntPtr master); enum { MOD_COMMAND = 256, @@ -84,33 +84,31 @@ const static struct { unsigned short keycode; KeySym keysym; } known_keys[] = { - {55, XK_Meta_L}, - {56, XK_Shift_L}, - {57, XK_Caps_Lock}, - {58, XK_Alt_L}, - {59, XK_Control_L}, - - {60, XK_Shift_R}, - {61, XK_Alt_R}, - {62, XK_Control_R}, - {63, XK_Meta_R}, - - {122, XK_F1}, - {120, XK_F2}, - {99, XK_F3}, - {118, XK_F4}, - {96, XK_F5}, - {97, XK_F6}, - {98, XK_F7}, - {100, XK_F8}, - {101, XK_F9}, - {109, XK_F10}, - {103, XK_F11}, - {111, XK_F12}, - {105, XK_F13}, - {107, XK_F14}, - {113, XK_F15}, -}; + { + 55, XK_Meta_L}, { + 56, XK_Shift_L}, { + 57, XK_Caps_Lock}, { + 58, XK_Alt_L}, { + 59, XK_Control_L}, { + 60, XK_Shift_R}, { + 61, XK_Alt_R}, { + 62, XK_Control_R}, { + 63, XK_Meta_R}, { + 122, XK_F1}, { + 120, XK_F2}, { + 99, XK_F3}, { + 118, XK_F4}, { + 96, XK_F5}, { + 97, XK_F6}, { + 98, XK_F7}, { + 100, XK_F8}, { + 101, XK_F9}, { + 109, XK_F10}, { + 103, XK_F11}, { + 111, XK_F12}, { + 105, XK_F13}, { + 107, XK_F14}, { +113, XK_F15},}; #endif #if HACK_KEYPAD @@ -121,24 +119,24 @@ const static struct { unsigned short keycode; KeySym normal, keypad; } known_numeric_keys[] = { - {65, XK_period, XK_KP_Decimal}, - {67, XK_asterisk, XK_KP_Multiply}, - {69, XK_plus, XK_KP_Add}, - {75, XK_slash, XK_KP_Divide}, - {76, 0x01000003, XK_KP_Enter}, - {78, XK_minus, XK_KP_Subtract}, - {81, XK_equal, XK_KP_Equal}, - {82, XK_0, XK_KP_0}, - {83, XK_1, XK_KP_1}, - {84, XK_2, XK_KP_2}, - {85, XK_3, XK_KP_3}, - {86, XK_4, XK_KP_4}, - {87, XK_5, XK_KP_5}, - {88, XK_6, XK_KP_6}, - {89, XK_7, XK_KP_7}, - {91, XK_8, XK_KP_8}, - {92, XK_9, XK_KP_9}, -}; + { + 65, XK_period, XK_KP_Decimal}, { + 67, XK_asterisk, XK_KP_Multiply}, { + 69, XK_plus, XK_KP_Add}, { + 75, XK_slash, XK_KP_Divide}, { + 76, 0x01000003, XK_KP_Enter}, { + 78, XK_minus, XK_KP_Subtract}, { + 81, XK_equal, XK_KP_Equal}, { + 82, XK_0, XK_KP_0}, { + 83, XK_1, XK_KP_1}, { + 84, XK_2, XK_KP_2}, { + 85, XK_3, XK_KP_3}, { + 86, XK_4, XK_KP_4}, { + 87, XK_5, XK_KP_5}, { + 88, XK_6, XK_KP_6}, { + 89, XK_7, XK_KP_7}, { + 91, XK_8, XK_KP_8}, { +92, XK_9, XK_KP_9},}; #endif #if HACK_BLACKLIST @@ -148,7 +146,7 @@ const static struct { * * legacy Mac keycodes for arrow keys that shift-modify to math symbols */ -const static unsigned short keycode_blacklist[] = {66, 70, 72, 77}; +const static unsigned short keycode_blacklist[] = { 66, 70, 72, 77 }; #endif /* Table mapping normal keysyms to their dead equivalents. @@ -157,30 +155,40 @@ const static unsigned short keycode_blacklist[] = {66, 70, 72, 77}; const static struct { KeySym normal, dead; } dead_keys[] = { - {XK_grave, XK_dead_grave}, - {XK_apostrophe, XK_dead_acute}, /* US:"=" on a Czech keyboard */ - {XK_acute, XK_dead_acute}, - {UKEYSYM (0x384), XK_dead_acute}, /* US:";" on a Greek keyboard */ + { + XK_grave, XK_dead_grave}, { + XK_apostrophe, XK_dead_acute}, /* US:"=" on a Czech keyboard */ + { + XK_acute, XK_dead_acute}, { + UKEYSYM(0x384), XK_dead_acute}, /* US:";" on a Greek keyboard */ // {XK_Greek_accentdieresis, XK_dead_diaeresis}, /* US:"opt+;" on a Greek keyboard ... replace with dead_accentdieresis if there is one */ - {XK_asciicircum, XK_dead_circumflex}, - {UKEYSYM (0x2c6), XK_dead_circumflex}, /* MODIFIER LETTER CIRCUMFLEX ACCENT */ - {XK_asciitilde, XK_dead_tilde}, - {UKEYSYM (0x2dc), XK_dead_tilde}, /* SMALL TILDE */ - {XK_macron, XK_dead_macron}, - {XK_breve, XK_dead_breve}, - {XK_abovedot, XK_dead_abovedot}, - {XK_diaeresis, XK_dead_diaeresis}, - {UKEYSYM (0x2da), XK_dead_abovering}, /* DOT ABOVE */ - {XK_doubleacute, XK_dead_doubleacute}, - {XK_caron, XK_dead_caron}, - {XK_cedilla, XK_dead_cedilla}, - {XK_ogonek, XK_dead_ogonek}, - {UKEYSYM (0x269), XK_dead_iota}, /* LATIN SMALL LETTER IOTA */ - {UKEYSYM (0x2ec), XK_dead_voiced_sound}, /* MODIFIER LETTER VOICING */ + { + XK_asciicircum, XK_dead_circumflex}, { + UKEYSYM(0x2c6), XK_dead_circumflex}, /* MODIFIER LETTER CIRCUMFLEX ACCENT */ + { + XK_asciitilde, XK_dead_tilde}, { + UKEYSYM(0x2dc), XK_dead_tilde}, /* SMALL TILDE */ + { + XK_macron, XK_dead_macron}, { + XK_breve, XK_dead_breve}, { + XK_abovedot, XK_dead_abovedot}, { + XK_diaeresis, XK_dead_diaeresis}, { + UKEYSYM(0x2da), XK_dead_abovering}, /* DOT ABOVE */ + { + XK_doubleacute, XK_dead_doubleacute}, { + XK_caron, XK_dead_caron}, { + XK_cedilla, XK_dead_cedilla}, { + XK_ogonek, XK_dead_ogonek}, { + UKEYSYM(0x269), XK_dead_iota}, /* LATIN SMALL LETTER IOTA */ + { + UKEYSYM(0x2ec), XK_dead_voiced_sound}, /* MODIFIER LETTER VOICING */ /* {XK_semivoiced_sound, XK_dead_semivoiced_sound}, */ - {UKEYSYM (0x323), XK_dead_belowdot}, /* COMBINING DOT BELOW */ - {UKEYSYM (0x309), XK_dead_hook}, /* COMBINING HOOK ABOVE */ - {UKEYSYM (0x31b), XK_dead_horn}, /* COMBINING HORN */ + { + UKEYSYM(0x323), XK_dead_belowdot}, /* COMBINING DOT BELOW */ + { + UKEYSYM(0x309), XK_dead_hook}, /* COMBINING HOOK ABOVE */ + { + UKEYSYM(0x31b), XK_dead_horn}, /* COMBINING HORN */ }; typedef struct darwinKeyboardInfo_struct { @@ -192,7 +200,9 @@ typedef struct darwinKeyboardInfo_struct { darwinKeyboardInfo keyInfo; pthread_mutex_t keyInfo_mutex = PTHREAD_MUTEX_INITIALIZER; -static void DarwinChangeKeyboardControl(DeviceIntPtr device, KeybdCtrl *ctrl) { +static void +DarwinChangeKeyboardControl(DeviceIntPtr device, KeybdCtrl * ctrl) +{ // FIXME: to be implemented // keyclick, bell volume / pitch, autorepead, LED's } @@ -206,7 +216,9 @@ static void DarwinChangeKeyboardControl(DeviceIntPtr device, KeybdCtrl *ctrl) { * Use the keyMap field of keyboard info structure to populate * the modMap and modifierKeycodes fields. */ -static void DarwinBuildModifierMaps(darwinKeyboardInfo *info) { +static void +DarwinBuildModifierMaps(darwinKeyboardInfo * info) +{ int i; KeySym *k; @@ -217,83 +229,84 @@ static void DarwinBuildModifierMaps(darwinKeyboardInfo *info) { k = info->keyMap + i * GLYPHS_PER_KEY; switch (*k) { - case XK_Shift_L: - info->modifierKeycodes[NX_MODIFIERKEY_SHIFT][0] = i; - info->modMap[MIN_KEYCODE + i] = ShiftMask; - break; + case XK_Shift_L: + info->modifierKeycodes[NX_MODIFIERKEY_SHIFT][0] = i; + info->modMap[MIN_KEYCODE + i] = ShiftMask; + break; - case XK_Shift_R: + case XK_Shift_R: #ifdef NX_MODIFIERKEY_RSHIFT - info->modifierKeycodes[NX_MODIFIERKEY_RSHIFT][0] = i; + info->modifierKeycodes[NX_MODIFIERKEY_RSHIFT][0] = i; #else - info->modifierKeycodes[NX_MODIFIERKEY_SHIFT][0] = i; + info->modifierKeycodes[NX_MODIFIERKEY_SHIFT][0] = i; #endif - info->modMap[MIN_KEYCODE + i] = ShiftMask; - break; + info->modMap[MIN_KEYCODE + i] = ShiftMask; + break; - case XK_Control_L: - info->modifierKeycodes[NX_MODIFIERKEY_CONTROL][0] = i; - info->modMap[MIN_KEYCODE + i] = ControlMask; - break; + case XK_Control_L: + info->modifierKeycodes[NX_MODIFIERKEY_CONTROL][0] = i; + info->modMap[MIN_KEYCODE + i] = ControlMask; + break; - case XK_Control_R: + case XK_Control_R: #ifdef NX_MODIFIERKEY_RCONTROL - info->modifierKeycodes[NX_MODIFIERKEY_RCONTROL][0] = i; + info->modifierKeycodes[NX_MODIFIERKEY_RCONTROL][0] = i; #else - info->modifierKeycodes[NX_MODIFIERKEY_CONTROL][0] = i; + info->modifierKeycodes[NX_MODIFIERKEY_CONTROL][0] = i; #endif - info->modMap[MIN_KEYCODE + i] = ControlMask; - break; + info->modMap[MIN_KEYCODE + i] = ControlMask; + break; - case XK_Caps_Lock: - info->modifierKeycodes[NX_MODIFIERKEY_ALPHALOCK][0] = i; - info->modMap[MIN_KEYCODE + i] = LockMask; - break; + case XK_Caps_Lock: + info->modifierKeycodes[NX_MODIFIERKEY_ALPHALOCK][0] = i; + info->modMap[MIN_KEYCODE + i] = LockMask; + break; - case XK_Alt_L: - info->modifierKeycodes[NX_MODIFIERKEY_ALTERNATE][0] = i; - info->modMap[MIN_KEYCODE + i] = Mod1Mask; - if(!XQuartzOptionSendsAlt) - *k = XK_Mode_switch; // Yes, this is ugly. This needs to be cleaned up when we integrate quartzKeyboard with this code and refactor. - break; + case XK_Alt_L: + info->modifierKeycodes[NX_MODIFIERKEY_ALTERNATE][0] = i; + info->modMap[MIN_KEYCODE + i] = Mod1Mask; + if (!XQuartzOptionSendsAlt) + *k = XK_Mode_switch; // Yes, this is ugly. This needs to be cleaned up when we integrate quartzKeyboard with this code and refactor. + break; - case XK_Alt_R: + case XK_Alt_R: #ifdef NX_MODIFIERKEY_RALTERNATE - info->modifierKeycodes[NX_MODIFIERKEY_RALTERNATE][0] = i; + info->modifierKeycodes[NX_MODIFIERKEY_RALTERNATE][0] = i; #else - info->modifierKeycodes[NX_MODIFIERKEY_ALTERNATE][0] = i; + info->modifierKeycodes[NX_MODIFIERKEY_ALTERNATE][0] = i; #endif - if(!XQuartzOptionSendsAlt) - *k = XK_Mode_switch; // Yes, this is ugly. This needs to be cleaned up when we integrate quartzKeyboard with this code and refactor. - info->modMap[MIN_KEYCODE + i] = Mod1Mask; - break; + if (!XQuartzOptionSendsAlt) + *k = XK_Mode_switch; // Yes, this is ugly. This needs to be cleaned up when we integrate quartzKeyboard with this code and refactor. + info->modMap[MIN_KEYCODE + i] = Mod1Mask; + break; - case XK_Mode_switch: - ErrorF("DarwinBuildModifierMaps: XK_Mode_switch encountered, unable to determine side.\n"); - info->modifierKeycodes[NX_MODIFIERKEY_ALTERNATE][0] = i; + case XK_Mode_switch: + ErrorF + ("DarwinBuildModifierMaps: XK_Mode_switch encountered, unable to determine side.\n"); + info->modifierKeycodes[NX_MODIFIERKEY_ALTERNATE][0] = i; #ifdef NX_MODIFIERKEY_RALTERNATE - info->modifierKeycodes[NX_MODIFIERKEY_RALTERNATE][0] = i; + info->modifierKeycodes[NX_MODIFIERKEY_RALTERNATE][0] = i; #endif - info->modMap[MIN_KEYCODE + i] = Mod1Mask; - break; + info->modMap[MIN_KEYCODE + i] = Mod1Mask; + break; - case XK_Meta_L: - info->modifierKeycodes[NX_MODIFIERKEY_COMMAND][0] = i; - info->modMap[MIN_KEYCODE + i] = Mod2Mask; - break; + case XK_Meta_L: + info->modifierKeycodes[NX_MODIFIERKEY_COMMAND][0] = i; + info->modMap[MIN_KEYCODE + i] = Mod2Mask; + break; - case XK_Meta_R: + case XK_Meta_R: #ifdef NX_MODIFIERKEY_RCOMMAND - info->modifierKeycodes[NX_MODIFIERKEY_RCOMMAND][0] = i; + info->modifierKeycodes[NX_MODIFIERKEY_RCOMMAND][0] = i; #else - info->modifierKeycodes[NX_MODIFIERKEY_COMMAND][0] = i; + info->modifierKeycodes[NX_MODIFIERKEY_COMMAND][0] = i; #endif - info->modMap[MIN_KEYCODE + i] = Mod2Mask; - break; + info->modMap[MIN_KEYCODE + i] = Mod2Mask; + break; - case XK_Num_Lock: - info->modMap[MIN_KEYCODE + i] = Mod3Mask; - break; + case XK_Num_Lock: + info->modMap[MIN_KEYCODE + i] = Mod3Mask; + break; } } } @@ -304,7 +317,9 @@ static void DarwinBuildModifierMaps(darwinKeyboardInfo *info) { * X keyboard map and modifier map. Set the new keyboard * device structure. */ -void DarwinKeyboardInit(DeviceIntPtr pDev) { +void +DarwinKeyboardInit(DeviceIntPtr pDev) +{ // Open a shared connection to the HID System. // Note that the Event Status Driver is really just a wrapper // for a kIOHIDParamConnectType connection. @@ -320,46 +335,51 @@ void DarwinKeyboardInit(DeviceIntPtr pDev) { /* Set the repeat rates based on global preferences and keycodes for modifiers. * Precondition: Has the keyInfo_mutex lock. */ -static void DarwinKeyboardSetRepeat(DeviceIntPtr pDev, int initialKeyRepeatValue, int keyRepeatValue) { - if(initialKeyRepeatValue == 300000) { // off +static void +DarwinKeyboardSetRepeat(DeviceIntPtr pDev, int initialKeyRepeatValue, + int keyRepeatValue) +{ + if (initialKeyRepeatValue == 300000) { // off /* Turn off repeats globally */ XkbSetRepeatKeys(pDev, -1, AutoRepeatModeOff); - } else { + } + else { int i; - XkbControlsPtr ctrl; - XkbControlsRec old; + XkbControlsPtr ctrl; + XkbControlsRec old; /* Turn on repeats globally */ XkbSetRepeatKeys(pDev, -1, AutoRepeatModeOn); - + /* Setup the bit mask for individual key repeats */ ctrl = pDev->key->xkbInfo->desc->ctrls; - old= *ctrl; - + old = *ctrl; + ctrl->repeat_delay = initialKeyRepeatValue * 15; ctrl->repeat_interval = keyRepeatValue * 15; /* Turn off key-repeat for modifier keys, on for others */ /* First set them all on */ - for(i=0; i < XkbPerKeyBitArraySize; i++) + for (i = 0; i < XkbPerKeyBitArraySize; i++) ctrl->per_key_repeat[i] = -1; /* Now turn off the modifiers */ - for(i=0; i < 32; i++) { + for (i = 0; i < 32; i++) { unsigned char keycode; - + keycode = keyInfo.modifierKeycodes[i][0]; - if(keycode) + if (keycode) ClearBit(ctrl->per_key_repeat, keycode + MIN_KEYCODE); keycode = keyInfo.modifierKeycodes[i][1]; - if(keycode) + if (keycode) ClearBit(ctrl->per_key_repeat, keycode + MIN_KEYCODE); } /* Hurray for data duplication */ if (pDev->kbdfeed) - memcpy(pDev->kbdfeed->ctrl.autoRepeats, ctrl->per_key_repeat, XkbPerKeyBitArraySize); + memcpy(pDev->kbdfeed->ctrl.autoRepeats, ctrl->per_key_repeat, + XkbPerKeyBitArraySize); //ErrorF("per_key_repeat =\n"); //for(i=0; i < XkbPerKeyBitArraySize; i++) @@ -370,7 +390,9 @@ static void DarwinKeyboardSetRepeat(DeviceIntPtr pDev, int initialKeyRepeatValue } } -void DarwinKeyboardReloadHandler(void) { +void +DarwinKeyboardReloadHandler(void) +{ KeySymsRec keySyms; CFIndex initialKeyRepeatValue, keyRepeatValue; BOOL ok; @@ -383,62 +405,78 @@ void DarwinKeyboardReloadHandler(void) { DEBUG_LOG("DarwinKeyboardReloadHandler\n"); /* Get our key repeat settings from GlobalPreferences */ - (void)CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences")); - - initialKeyRepeatValue = CFPreferencesGetAppIntegerValue(CFSTR("InitialKeyRepeat"), CFSTR(".GlobalPreferences"), &ok); - if(!ok) + (void) CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences")); + + initialKeyRepeatValue = + CFPreferencesGetAppIntegerValue(CFSTR("InitialKeyRepeat"), + CFSTR(".GlobalPreferences"), &ok); + if (!ok) initialKeyRepeatValue = 35; - - keyRepeatValue = CFPreferencesGetAppIntegerValue(CFSTR("KeyRepeat"), CFSTR(".GlobalPreferences"), &ok); - if(!ok) + + keyRepeatValue = + CFPreferencesGetAppIntegerValue(CFSTR("KeyRepeat"), + CFSTR(".GlobalPreferences"), &ok); + if (!ok) keyRepeatValue = 6; - + pthread_mutex_lock(&keyInfo_mutex); { /* Initialize our keySyms */ keySyms.map = keyInfo.keyMap; - keySyms.mapWidth = GLYPHS_PER_KEY; + keySyms.mapWidth = GLYPHS_PER_KEY; keySyms.minKeyCode = MIN_KEYCODE; keySyms.maxKeyCode = MAX_KEYCODE; - // TODO: We should build the entire XkbDescRec and use XkbCopyKeymap + // TODO: We should build the entire XkbDescRec and use XkbCopyKeymap /* Apply the mappings to darwinKeyboard */ XkbApplyMappingChange(darwinKeyboard, &keySyms, keySyms.minKeyCode, keySyms.maxKeyCode - keySyms.minKeyCode + 1, keyInfo.modMap, serverClient); - DarwinKeyboardSetRepeat(darwinKeyboard, initialKeyRepeatValue, keyRepeatValue); + DarwinKeyboardSetRepeat(darwinKeyboard, initialKeyRepeatValue, + keyRepeatValue); /* Apply the mappings to the core keyboard */ for (pDev = inputInfo.devices; pDev; pDev = pDev->next) { if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) { XkbApplyMappingChange(pDev, &keySyms, keySyms.minKeyCode, - keySyms.maxKeyCode - keySyms.minKeyCode + 1, - keyInfo.modMap, serverClient); - DarwinKeyboardSetRepeat(pDev, initialKeyRepeatValue, keyRepeatValue); + keySyms.maxKeyCode - keySyms.minKeyCode + + 1, keyInfo.modMap, serverClient); + DarwinKeyboardSetRepeat(pDev, initialKeyRepeatValue, + keyRepeatValue); } } - } pthread_mutex_unlock(&keyInfo_mutex); + } + pthread_mutex_unlock(&keyInfo_mutex); /* Modify with xmodmap */ if (access(xmodmap, F_OK) == 0) { /* Check for system .Xmodmap */ if (access(sysmodmap, F_OK) == 0) { - if(snprintf (cmd, sizeof(cmd), "%s %s", xmodmap, sysmodmap) < sizeof(cmd)) { + if (snprintf(cmd, sizeof(cmd), "%s %s", xmodmap, sysmodmap) < + sizeof(cmd)) { X11ApplicationLaunchClient(cmd); - } else { - ErrorF("X11.app: Unable to create / execute xmodmap command line"); + } + else { + ErrorF + ("X11.app: Unable to create / execute xmodmap command line"); } } /* Check for user's local .Xmodmap */ - if ((homedir != NULL) && (snprintf (usermodmap, sizeof(usermodmap), "%s/.Xmodmap", homedir) < sizeof(usermodmap))) { + if ((homedir != NULL) && + (snprintf(usermodmap, sizeof(usermodmap), "%s/.Xmodmap", homedir) < + sizeof(usermodmap))) { if (access(usermodmap, F_OK) == 0) { - if(snprintf (cmd, sizeof(cmd), "%s %s", xmodmap, usermodmap) < sizeof(cmd)) { + if (snprintf(cmd, sizeof(cmd), "%s %s", xmodmap, usermodmap) < + sizeof(cmd)) { X11ApplicationLaunchClient(cmd); - } else { - ErrorF("X11.app: Unable to create / execute xmodmap command line"); + } + else { + ErrorF + ("X11.app: Unable to create / execute xmodmap command line"); } } - } else { + } + else { ErrorF("X11.app: Unable to determine path to user's .Xmodmap"); } } @@ -460,8 +498,11 @@ void DarwinKeyboardReloadHandler(void) { * side = 0 for left or 1 for right. * Returns 0 if key+side is not a known modifier. */ -int DarwinModifierNXKeyToNXKeycode(int key, int side) { +int +DarwinModifierNXKeyToNXKeycode(int key, int side) +{ int retval; + pthread_mutex_lock(&keyInfo_mutex); retval = keyInfo.modifierKeycodes[key][side]; pthread_mutex_unlock(&keyInfo_mutex); @@ -474,7 +515,9 @@ int DarwinModifierNXKeyToNXKeycode(int key, int side) { * Returns -1 if keycode+side is not a modifier key * outSide may be NULL, else it gets 0 for left and 1 for right. */ -int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide) { +int +DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide) +{ int key, side; keycode += MIN_KEYCODE; @@ -483,7 +526,8 @@ int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide) { pthread_mutex_lock(&keyInfo_mutex); for (key = 0; key < NX_NUMMODIFIERS; key++) { for (side = 0; side <= 1; side++) { - if (keyInfo.modifierKeycodes[key][side] == keycode) break; + if (keyInfo.modifierKeycodes[key][side] == keycode) + break; } } pthread_mutex_unlock(&keyInfo_mutex); @@ -491,7 +535,8 @@ int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide) { if (key == NX_NUMMODIFIERS) { return -1; } - if (outSide) *outSide = side; + if (outSide) + *outSide = side; return key; } @@ -500,32 +545,50 @@ int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide) { * DarwinModifierNXMaskToNXKey * Returns -1 if mask is not a known modifier mask. */ -int DarwinModifierNXMaskToNXKey(int mask) { +int +DarwinModifierNXMaskToNXKey(int mask) +{ switch (mask) { - case NX_ALPHASHIFTMASK: return NX_MODIFIERKEY_ALPHALOCK; - case NX_SHIFTMASK: return NX_MODIFIERKEY_SHIFT; + case NX_ALPHASHIFTMASK: + return NX_MODIFIERKEY_ALPHALOCK; + case NX_SHIFTMASK: + return NX_MODIFIERKEY_SHIFT; #ifdef NX_DEVICELSHIFTKEYMASK - case NX_DEVICELSHIFTKEYMASK: return NX_MODIFIERKEY_SHIFT; - case NX_DEVICERSHIFTKEYMASK: return NX_MODIFIERKEY_RSHIFT; + case NX_DEVICELSHIFTKEYMASK: + return NX_MODIFIERKEY_SHIFT; + case NX_DEVICERSHIFTKEYMASK: + return NX_MODIFIERKEY_RSHIFT; #endif - case NX_CONTROLMASK: return NX_MODIFIERKEY_CONTROL; + case NX_CONTROLMASK: + return NX_MODIFIERKEY_CONTROL; #ifdef NX_DEVICELCTLKEYMASK - case NX_DEVICELCTLKEYMASK: return NX_MODIFIERKEY_CONTROL; - case NX_DEVICERCTLKEYMASK: return NX_MODIFIERKEY_RCONTROL; + case NX_DEVICELCTLKEYMASK: + return NX_MODIFIERKEY_CONTROL; + case NX_DEVICERCTLKEYMASK: + return NX_MODIFIERKEY_RCONTROL; #endif - case NX_ALTERNATEMASK: return NX_MODIFIERKEY_ALTERNATE; + case NX_ALTERNATEMASK: + return NX_MODIFIERKEY_ALTERNATE; #ifdef NX_DEVICELALTKEYMASK - case NX_DEVICELALTKEYMASK: return NX_MODIFIERKEY_ALTERNATE; - case NX_DEVICERALTKEYMASK: return NX_MODIFIERKEY_RALTERNATE; + case NX_DEVICELALTKEYMASK: + return NX_MODIFIERKEY_ALTERNATE; + case NX_DEVICERALTKEYMASK: + return NX_MODIFIERKEY_RALTERNATE; #endif - case NX_COMMANDMASK: return NX_MODIFIERKEY_COMMAND; + case NX_COMMANDMASK: + return NX_MODIFIERKEY_COMMAND; #ifdef NX_DEVICELCMDKEYMASK - case NX_DEVICELCMDKEYMASK: return NX_MODIFIERKEY_COMMAND; - case NX_DEVICERCMDKEYMASK: return NX_MODIFIERKEY_RCOMMAND; -#endif - case NX_NUMERICPADMASK: return NX_MODIFIERKEY_NUMERICPAD; - case NX_HELPMASK: return NX_MODIFIERKEY_HELP; - case NX_SECONDARYFNMASK: return NX_MODIFIERKEY_SECONDARYFN; + case NX_DEVICELCMDKEYMASK: + return NX_MODIFIERKEY_COMMAND; + case NX_DEVICERCMDKEYMASK: + return NX_MODIFIERKEY_RCOMMAND; +#endif + case NX_NUMERICPADMASK: + return NX_MODIFIERKEY_NUMERICPAD; + case NX_HELPMASK: + return NX_MODIFIERKEY_HELP; + case NX_SECONDARYFNMASK: + return NX_MODIFIERKEY_SECONDARYFN; } return -1; } @@ -534,27 +597,45 @@ int DarwinModifierNXMaskToNXKey(int mask) { * DarwinModifierNXKeyToNXMask * Returns 0 if key is not a known modifier key. */ -int DarwinModifierNXKeyToNXMask(int key) { +int +DarwinModifierNXKeyToNXMask(int key) +{ switch (key) { - case NX_MODIFIERKEY_ALPHALOCK: return NX_ALPHASHIFTMASK; + case NX_MODIFIERKEY_ALPHALOCK: + return NX_ALPHASHIFTMASK; #ifdef NX_DEVICELSHIFTKEYMASK - case NX_MODIFIERKEY_SHIFT: return NX_DEVICELSHIFTKEYMASK; - case NX_MODIFIERKEY_RSHIFT: return NX_DEVICERSHIFTKEYMASK; - case NX_MODIFIERKEY_CONTROL: return NX_DEVICELCTLKEYMASK; - case NX_MODIFIERKEY_RCONTROL: return NX_DEVICERCTLKEYMASK; - case NX_MODIFIERKEY_ALTERNATE: return NX_DEVICELALTKEYMASK; - case NX_MODIFIERKEY_RALTERNATE: return NX_DEVICERALTKEYMASK; - case NX_MODIFIERKEY_COMMAND: return NX_DEVICELCMDKEYMASK; - case NX_MODIFIERKEY_RCOMMAND: return NX_DEVICERCMDKEYMASK; + case NX_MODIFIERKEY_SHIFT: + return NX_DEVICELSHIFTKEYMASK; + case NX_MODIFIERKEY_RSHIFT: + return NX_DEVICERSHIFTKEYMASK; + case NX_MODIFIERKEY_CONTROL: + return NX_DEVICELCTLKEYMASK; + case NX_MODIFIERKEY_RCONTROL: + return NX_DEVICERCTLKEYMASK; + case NX_MODIFIERKEY_ALTERNATE: + return NX_DEVICELALTKEYMASK; + case NX_MODIFIERKEY_RALTERNATE: + return NX_DEVICERALTKEYMASK; + case NX_MODIFIERKEY_COMMAND: + return NX_DEVICELCMDKEYMASK; + case NX_MODIFIERKEY_RCOMMAND: + return NX_DEVICERCMDKEYMASK; #else - case NX_MODIFIERKEY_SHIFT: return NX_SHIFTMASK; - case NX_MODIFIERKEY_CONTROL: return NX_CONTROLMASK; - case NX_MODIFIERKEY_ALTERNATE: return NX_ALTERNATEMASK; - case NX_MODIFIERKEY_COMMAND: return NX_COMMANDMASK; -#endif - case NX_MODIFIERKEY_NUMERICPAD: return NX_NUMERICPADMASK; - case NX_MODIFIERKEY_HELP: return NX_HELPMASK; - case NX_MODIFIERKEY_SECONDARYFN: return NX_SECONDARYFNMASK; + case NX_MODIFIERKEY_SHIFT: + return NX_SHIFTMASK; + case NX_MODIFIERKEY_CONTROL: + return NX_CONTROLMASK; + case NX_MODIFIERKEY_ALTERNATE: + return NX_ALTERNATEMASK; + case NX_MODIFIERKEY_COMMAND: + return NX_COMMANDMASK; +#endif + case NX_MODIFIERKEY_NUMERICPAD: + return NX_NUMERICPADMASK; + case NX_MODIFIERKEY_HELP: + return NX_HELPMASK; + case NX_MODIFIERKEY_SECONDARYFN: + return NX_SECONDARYFNMASK; } return 0; } @@ -563,48 +644,85 @@ int DarwinModifierNXKeyToNXMask(int key) { * DarwinModifierStringToNXMask * Returns 0 if string is not a known modifier. */ -int DarwinModifierStringToNXMask(const char *str, int separatelr) { +int +DarwinModifierStringToNXMask(const char *str, int separatelr) +{ #ifdef NX_DEVICELSHIFTKEYMASK - if(separatelr) { - if (!strcasecmp(str, "shift")) return NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK; - if (!strcasecmp(str, "control")) return NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK; - if (!strcasecmp(str, "option")) return NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK; - if (!strcasecmp(str, "alt")) return NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK; - if (!strcasecmp(str, "command")) return NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK; - if (!strcasecmp(str, "lshift")) return NX_DEVICELSHIFTKEYMASK; - if (!strcasecmp(str, "rshift")) return NX_DEVICERSHIFTKEYMASK; - if (!strcasecmp(str, "lcontrol")) return NX_DEVICELCTLKEYMASK; - if (!strcasecmp(str, "rcontrol")) return NX_DEVICERCTLKEYMASK; - if (!strcasecmp(str, "loption")) return NX_DEVICELALTKEYMASK; - if (!strcasecmp(str, "roption")) return NX_DEVICERALTKEYMASK; - if (!strcasecmp(str, "lalt")) return NX_DEVICELALTKEYMASK; - if (!strcasecmp(str, "ralt")) return NX_DEVICERALTKEYMASK; - if (!strcasecmp(str, "lcommand")) return NX_DEVICELCMDKEYMASK; - if (!strcasecmp(str, "rcommand")) return NX_DEVICERCMDKEYMASK; - } else { -#endif - if (!strcasecmp(str, "shift")) return NX_SHIFTMASK; - if (!strcasecmp(str, "control")) return NX_CONTROLMASK; - if (!strcasecmp(str, "option")) return NX_ALTERNATEMASK; - if (!strcasecmp(str, "alt")) return NX_ALTERNATEMASK; - if (!strcasecmp(str, "command")) return NX_COMMANDMASK; - if (!strcasecmp(str, "lshift")) return NX_SHIFTMASK; - if (!strcasecmp(str, "rshift")) return NX_SHIFTMASK; - if (!strcasecmp(str, "lcontrol")) return NX_CONTROLMASK; - if (!strcasecmp(str, "rcontrol")) return NX_CONTROLMASK; - if (!strcasecmp(str, "loption")) return NX_ALTERNATEMASK; - if (!strcasecmp(str, "roption")) return NX_ALTERNATEMASK; - if (!strcasecmp(str, "lalt")) return NX_ALTERNATEMASK; - if (!strcasecmp(str, "ralt")) return NX_ALTERNATEMASK; - if (!strcasecmp(str, "lcommand")) return NX_COMMANDMASK; - if (!strcasecmp(str, "rcommand")) return NX_COMMANDMASK; + if (separatelr) { + if (!strcasecmp(str, "shift")) + return NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK; + if (!strcasecmp(str, "control")) + return NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK; + if (!strcasecmp(str, "option")) + return NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK; + if (!strcasecmp(str, "alt")) + return NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK; + if (!strcasecmp(str, "command")) + return NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK; + if (!strcasecmp(str, "lshift")) + return NX_DEVICELSHIFTKEYMASK; + if (!strcasecmp(str, "rshift")) + return NX_DEVICERSHIFTKEYMASK; + if (!strcasecmp(str, "lcontrol")) + return NX_DEVICELCTLKEYMASK; + if (!strcasecmp(str, "rcontrol")) + return NX_DEVICERCTLKEYMASK; + if (!strcasecmp(str, "loption")) + return NX_DEVICELALTKEYMASK; + if (!strcasecmp(str, "roption")) + return NX_DEVICERALTKEYMASK; + if (!strcasecmp(str, "lalt")) + return NX_DEVICELALTKEYMASK; + if (!strcasecmp(str, "ralt")) + return NX_DEVICERALTKEYMASK; + if (!strcasecmp(str, "lcommand")) + return NX_DEVICELCMDKEYMASK; + if (!strcasecmp(str, "rcommand")) + return NX_DEVICERCMDKEYMASK; + } + else { +#endif + if (!strcasecmp(str, "shift")) + return NX_SHIFTMASK; + if (!strcasecmp(str, "control")) + return NX_CONTROLMASK; + if (!strcasecmp(str, "option")) + return NX_ALTERNATEMASK; + if (!strcasecmp(str, "alt")) + return NX_ALTERNATEMASK; + if (!strcasecmp(str, "command")) + return NX_COMMANDMASK; + if (!strcasecmp(str, "lshift")) + return NX_SHIFTMASK; + if (!strcasecmp(str, "rshift")) + return NX_SHIFTMASK; + if (!strcasecmp(str, "lcontrol")) + return NX_CONTROLMASK; + if (!strcasecmp(str, "rcontrol")) + return NX_CONTROLMASK; + if (!strcasecmp(str, "loption")) + return NX_ALTERNATEMASK; + if (!strcasecmp(str, "roption")) + return NX_ALTERNATEMASK; + if (!strcasecmp(str, "lalt")) + return NX_ALTERNATEMASK; + if (!strcasecmp(str, "ralt")) + return NX_ALTERNATEMASK; + if (!strcasecmp(str, "lcommand")) + return NX_COMMANDMASK; + if (!strcasecmp(str, "rcommand")) + return NX_COMMANDMASK; #ifdef NX_DEVICELSHIFTKEYMASK } #endif - if (!strcasecmp(str, "lock")) return NX_ALPHASHIFTMASK; - if (!strcasecmp(str, "fn")) return NX_SECONDARYFNMASK; - if (!strcasecmp(str, "help")) return NX_HELPMASK; - if (!strcasecmp(str, "numlock")) return NX_NUMERICPADMASK; + if (!strcasecmp(str, "lock")) + return NX_ALPHASHIFTMASK; + if (!strcasecmp(str, "fn")) + return NX_SECONDARYFNMASK; + if (!strcasecmp(str, "help")) + return NX_HELPMASK; + if (!strcasecmp(str, "numlock")) + return NX_NUMERICPADMASK; return 0; } @@ -613,12 +731,15 @@ int DarwinModifierStringToNXMask(const char *str, int separatelr) { * This allows the ddx layer to prevent some keys from being remapped * as modifier keys. */ -Bool LegalModifier(unsigned int key, DeviceIntPtr pDev) +Bool +LegalModifier(unsigned int key, DeviceIntPtr pDev) { return 1; } -static inline UniChar macroman2ucs(unsigned char c) { +static inline UniChar +macroman2ucs(unsigned char c) +{ /* Precalculated table mapping MacRoman-128 to Unicode. Generated by creating single element CFStringRefs then extracting the first character. */ @@ -642,20 +763,27 @@ static inline UniChar macroman2ucs(unsigned char c) { 0xaf, 0x2d8, 0x2d9, 0x2da, 0xb8, 0x2dd, 0x2db, 0x2c7, }; - if (c < 128) return c; - else return table[c - 128]; + if (c < 128) + return c; + else + return table[c - 128]; } -static KeySym make_dead_key(KeySym in) { +static KeySym +make_dead_key(KeySym in) +{ int i; - for (i = 0; i < sizeof (dead_keys) / sizeof (dead_keys[0]); i++) - if (dead_keys[i].normal == in) return dead_keys[i].dead; + for (i = 0; i < sizeof(dead_keys) / sizeof(dead_keys[0]); i++) + if (dead_keys[i].normal == in) + return dead_keys[i].dead; return in; } -static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) { +static Bool +QuartzReadSystemKeymap(darwinKeyboardInfo * info) +{ #if !defined(__LP64__) || MAC_OS_X_VERSION_MIN_REQUIRED < 1050 KeyboardLayoutRef key_layout; int is_uchr = 1; @@ -669,48 +797,58 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) { CFDataRef currentKeyLayoutDataRef = NULL; #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - TISInputSourceRef currentKeyLayoutRef = TISCopyCurrentKeyboardLayoutInputSource(); + TISInputSourceRef currentKeyLayoutRef = + TISCopyCurrentKeyboardLayoutInputSource(); if (currentKeyLayoutRef) { - currentKeyLayoutDataRef = (CFDataRef )TISGetInputSourceProperty(currentKeyLayoutRef, kTISPropertyUnicodeKeyLayoutData); - if (currentKeyLayoutDataRef) - chr_data = CFDataGetBytePtr(currentKeyLayoutDataRef); + currentKeyLayoutDataRef = + (CFDataRef) TISGetInputSourceProperty(currentKeyLayoutRef, + kTISPropertyUnicodeKeyLayoutData); + if (currentKeyLayoutDataRef) + chr_data = CFDataGetBytePtr(currentKeyLayoutDataRef); } #endif #ifdef __clang__ #pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" // KLGetCurrentKeyboardLayout, KLGetKeyboardLayoutProperty +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // KLGetCurrentKeyboardLayout, KLGetKeyboardLayoutProperty #endif #if !defined(__LP64__) || MAC_OS_X_VERSION_MIN_REQUIRED < 1050 if (chr_data == NULL) { #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - ErrorF("X11.app: Error detected in determining keyboard layout. If you are using an Apple-provided keyboard layout, please report this error at http://xquartz.macosforge.org and http://bugreport.apple.com\n"); - ErrorF("X11.app: Debug Info: keyboard_type=%u, currentKeyLayoutRef=%p, currentKeyLayoutDataRef=%p, chr_data=%p\n", - (unsigned)keyboard_type, currentKeyLayoutRef, currentKeyLayoutDataRef, chr_data); + ErrorF + ("X11.app: Error detected in determining keyboard layout. If you are using an Apple-provided keyboard layout, please report this error at http://xquartz.macosforge.org and http://bugreport.apple.com\n"); + ErrorF + ("X11.app: Debug Info: keyboard_type=%u, currentKeyLayoutRef=%p, currentKeyLayoutDataRef=%p, chr_data=%p\n", + (unsigned) keyboard_type, currentKeyLayoutRef, + currentKeyLayoutDataRef, chr_data); #endif - KLGetCurrentKeyboardLayout (&key_layout); - KLGetKeyboardLayoutProperty (key_layout, kKLuchrData, &chr_data); + KLGetCurrentKeyboardLayout(&key_layout); + KLGetKeyboardLayoutProperty(key_layout, kKLuchrData, &chr_data); #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - if(chr_data != NULL) { - ErrorF("X11.app: Fallback succeeded, but this is still a bug. Please report the above information.\n"); + if (chr_data != NULL) { + ErrorF + ("X11.app: Fallback succeeded, but this is still a bug. Please report the above information.\n"); } #endif } if (chr_data == NULL) { - ErrorF("X11.app: Debug Info: kKLuchrData failed, trying kKLKCHRData.\n"); - ErrorF("If you are using a 3rd party keyboard layout, please see http://xquartz.macosforge.org/trac/ticket/154\n"); - KLGetKeyboardLayoutProperty (key_layout, kKLKCHRData, &chr_data); + ErrorF + ("X11.app: Debug Info: kKLuchrData failed, trying kKLKCHRData.\n"); + ErrorF + ("If you are using a 3rd party keyboard layout, please see http://xquartz.macosforge.org/trac/ticket/154\n"); + KLGetKeyboardLayoutProperty(key_layout, kKLKCHRData, &chr_data); is_uchr = 0; num_keycodes = 128; - + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - if(chr_data != NULL) { - ErrorF("X11.app: Fallback succeeded, but this is still a bug. Please report the above information.\n"); + if (chr_data != NULL) { + ErrorF + ("X11.app: Fallback succeeded, but this is still a bug. Please report the above information.\n"); } #endif } @@ -721,61 +859,66 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) { #endif #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - if(currentKeyLayoutRef) + if (currentKeyLayoutRef) CFRelease(currentKeyLayoutRef); #endif - + if (chr_data == NULL) { - ErrorF ( "Couldn't get uchr or kchr resource\n"); - return FALSE; + ErrorF("Couldn't get uchr or kchr resource\n"); + return FALSE; } - + /* Scan the keycode range for the Unicode character that each key produces in the four shift states. Then convert that to an X11 keysym (which may just the bit that says "this is Unicode" if it can't find the real symbol.) */ - + /* KeyTranslate is not available on 64-bit platforms; UCKeyTranslate must be used instead. */ for (i = 0; i < num_keycodes; i++) { - static const int mods[4] = {0, MOD_SHIFT, MOD_OPTION, - MOD_OPTION | MOD_SHIFT}; + static const int mods[4] = { 0, MOD_SHIFT, MOD_OPTION, + MOD_OPTION | MOD_SHIFT + }; k = info->keyMap + i * GLYPHS_PER_KEY; for (j = 0; j < 4; j++) { #if !defined(__LP64__) || MAC_OS_X_VERSION_MIN_REQUIRED < 1050 - if (is_uchr) { + if (is_uchr) { #endif UniChar s[8]; UniCharCount len; UInt32 dead_key_state = 0, extra_dead = 0; - err = UCKeyTranslate (chr_data, i, kUCKeyActionDown, - mods[j] >> 8, keyboard_type, 0, - &dead_key_state, 8, &len, s); - if (err != noErr) continue; + err = UCKeyTranslate(chr_data, i, kUCKeyActionDown, + mods[j] >> 8, keyboard_type, 0, + &dead_key_state, 8, &len, s); + if (err != noErr) + continue; if (len == 0 && dead_key_state != 0) { /* Found a dead key. Work out which one it is, but remembering that it's dead. */ - err = UCKeyTranslate (chr_data, i, kUCKeyActionDown, - mods[j] >> 8, keyboard_type, - kUCKeyTranslateNoDeadKeysMask, - &extra_dead, 8, &len, s); - if (err != noErr) continue; + err = UCKeyTranslate(chr_data, i, kUCKeyActionDown, + mods[j] >> 8, keyboard_type, + kUCKeyTranslateNoDeadKeysMask, + &extra_dead, 8, &len, s); + if (err != noErr) + continue; } /* Not sure why 0x0010 is there. * 0x0000 - <rdar://problem/7793566> 'Unicode Hex Input' ... */ if (len > 0 && s[0] != 0x0010 && s[0] != 0x0000) { - k[j] = ucs2keysym (s[0]); - if (dead_key_state != 0) k[j] = make_dead_key (k[j]); + k[j] = ucs2keysym(s[0]); + if (dead_key_state != 0) + k[j] = make_dead_key(k[j]); } #if !defined(__LP64__) || MAC_OS_X_VERSION_MIN_REQUIRED < 1050 - } else { // kchr + } + else { // kchr UInt32 c, state = 0, state2 = 0; UInt16 code; @@ -783,10 +926,10 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) { #ifdef __clang__ #pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" // KeyTranslate +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // KeyTranslate #endif - c = KeyTranslate (chr_data, code, &state); + c = KeyTranslate(chr_data, code, &state); /* Dead keys are only processed on key-down, so ask to translate those events. When we find a dead key, @@ -794,7 +937,7 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) { us the actual dead character. */ if (state != 0) - c = KeyTranslate (chr_data, code | 128, &state2); + c = KeyTranslate(chr_data, code | 128, &state2); #ifdef __clang__ #pragma clang diagnostic pop @@ -803,45 +946,52 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) { /* Characters seem to be in MacRoman encoding. */ if (c != 0 && c != 0x0010) { - k[j] = ucs2keysym (macroman2ucs (c & 255)); + k[j] = ucs2keysym(macroman2ucs(c & 255)); - if (state != 0) k[j] = make_dead_key (k[j]); + if (state != 0) + k[j] = make_dead_key(k[j]); } } #endif } - if (k[3] == k[2]) k[3] = NoSymbol; - if (k[1] == k[0]) k[1] = NoSymbol; - if (k[0] == k[2] && k[1] == k[3]) k[2] = k[3] = NoSymbol; - if (k[3] == k[0] && k[2] == k[1] && k[2] == NoSymbol) k[3] = NoSymbol; + if (k[3] == k[2]) + k[3] = NoSymbol; + if (k[1] == k[0]) + k[1] = NoSymbol; + if (k[0] == k[2] && k[1] == k[3]) + k[2] = k[3] = NoSymbol; + if (k[3] == k[0] && k[2] == k[1] && k[2] == NoSymbol) + k[3] = NoSymbol; } #if HACK_MISSING /* Fix up some things that are normally missing.. */ - - for (i = 0; i < sizeof (known_keys) / sizeof (known_keys[0]); i++) { + + for (i = 0; i < sizeof(known_keys) / sizeof(known_keys[0]); i++) { k = info->keyMap + known_keys[i].keycode * GLYPHS_PER_KEY; - - if ( k[0] == NoSymbol && k[1] == NoSymbol + + if (k[0] == NoSymbol && k[1] == NoSymbol && k[2] == NoSymbol && k[3] == NoSymbol) k[0] = known_keys[i].keysym; } #endif - + #if HACK_KEYPAD /* And some more things. We find the right symbols for the numeric - keypad, but not the KP_ keysyms. So try to convert known keycodes. */ - for (i = 0; i < sizeof (known_numeric_keys) / sizeof (known_numeric_keys[0]); i++) { + keypad, but not the KP_ keysyms. So try to convert known keycodes. */ + for (i = 0; i < sizeof(known_numeric_keys) / sizeof(known_numeric_keys[0]); + i++) { k = info->keyMap + known_numeric_keys[i].keycode * GLYPHS_PER_KEY; - + if (k[0] == known_numeric_keys[i].normal) k[0] = known_numeric_keys[i].keypad; } #endif - + #if HACK_BLACKLIST - for (i = 0; i < sizeof (keycode_blacklist) / sizeof (keycode_blacklist[0]); i++) { + for (i = 0; i < sizeof(keycode_blacklist) / sizeof(keycode_blacklist[0]); + i++) { k = info->keyMap + keycode_blacklist[i] * GLYPHS_PER_KEY; k[0] = k[1] = k[2] = k[3] = NoSymbol; } @@ -852,8 +1002,11 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) { return TRUE; } -Bool QuartsResyncKeymap(Bool sendDDXEvent) { +Bool +QuartsResyncKeymap(Bool sendDDXEvent) +{ Bool retval; + /* Update keyInfo */ pthread_mutex_lock(&keyInfo_mutex); memset(keyInfo.keyMap, 0, sizeof(keyInfo.keyMap)); @@ -861,7 +1014,7 @@ Bool QuartsResyncKeymap(Bool sendDDXEvent) { pthread_mutex_unlock(&keyInfo_mutex); /* Tell server thread to deal with new keyInfo */ - if(sendDDXEvent) + if (sendDDXEvent) DarwinSendDDXEvent(kXquartzReloadKeymap, 0); return retval; diff --git a/xorg-server/hw/xquartz/quartzRandR.c b/xorg-server/hw/xquartz/quartzRandR.c index 98b382d65..b7c424f50 100644 --- a/xorg-server/hw/xquartz/quartzRandR.c +++ b/xorg-server/hw/xquartz/quartzRandR.c @@ -64,14 +64,17 @@ static Bool ignore_next_fake_mode_update = FALSE; #define CALLBACK_ERROR -1 typedef int (*QuartzModeCallback) - (ScreenPtr, QuartzModeInfoPtr, void *); + (ScreenPtr, QuartzModeInfoPtr, void *); #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 -static long getDictLong (CFDictionaryRef dictRef, CFStringRef key) { +static long +getDictLong(CFDictionaryRef dictRef, CFStringRef key) +{ long value; CFNumberRef numRef = (CFNumberRef) CFDictionaryGetValue(dictRef, key); + if (!numRef) return 0; @@ -80,10 +83,13 @@ static long getDictLong (CFDictionaryRef dictRef, CFStringRef key) { return value; } -static double getDictDouble (CFDictionaryRef dictRef, CFStringRef key) { +static double +getDictDouble(CFDictionaryRef dictRef, CFStringRef key) +{ double value; CFNumberRef numRef = (CFNumberRef) CFDictionaryGetValue(dictRef, key); + if (!numRef) return 0.0; @@ -92,43 +98,51 @@ static double getDictDouble (CFDictionaryRef dictRef, CFStringRef key) { return value; } -static void QuartzRandRGetModeInfo (CFDictionaryRef modeRef, - QuartzModeInfoPtr pMode) { +static void +QuartzRandRGetModeInfo(CFDictionaryRef modeRef, QuartzModeInfoPtr pMode) +{ pMode->width = (size_t) getDictLong(modeRef, kCGDisplayWidth); pMode->height = (size_t) getDictLong(modeRef, kCGDisplayHeight); - pMode->refresh = (int)(getDictDouble(modeRef, kCGDisplayRefreshRate) + 0.5); + pMode->refresh = + (int) (getDictDouble(modeRef, kCGDisplayRefreshRate) + 0.5); if (pMode->refresh == 0) pMode->refresh = DEFAULT_REFRESH; pMode->ref = NULL; pMode->pSize = NULL; } -static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId, - QuartzModeInfoPtr pMode) { +static Bool +QuartzRandRCopyCurrentModeInfo(CGDirectDisplayID screenId, + QuartzModeInfoPtr pMode) +{ CFDictionaryRef curModeRef = CGDisplayCurrentMode(screenId); + if (!curModeRef) return FALSE; QuartzRandRGetModeInfo(curModeRef, pMode); - pMode->ref = (void *)curModeRef; + pMode->ref = (void *) curModeRef; CFRetain(pMode->ref); return TRUE; } -static Bool QuartzRandRSetCGMode (CGDirectDisplayID screenId, - QuartzModeInfoPtr pMode) { +static Bool +QuartzRandRSetCGMode(CGDirectDisplayID screenId, QuartzModeInfoPtr pMode) +{ CFDictionaryRef modeRef = (CFDictionaryRef) pMode->ref; + return (CGDisplaySwitchToMode(screenId, modeRef) == kCGErrorSuccess); } -static Bool QuartzRandREnumerateModes (ScreenPtr pScreen, - QuartzModeCallback callback, - void *data) { +static Bool +QuartzRandREnumerateModes(ScreenPtr pScreen, + QuartzModeCallback callback, void *data) +{ Bool retval = FALSE; QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); /* Just an 800x600 fallback if we have no attached heads */ - if(pQuartzScreen->displayIDs) { + if (pQuartzScreen->displayIDs) { CFDictionaryRef curModeRef, modeRef; long curBpp; CFArrayRef modes; @@ -146,6 +160,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen, return FALSE; for (i = 0; i < CFArrayGetCount(modes); i++) { int cb; + modeRef = (CFDictionaryRef) CFArrayGetValueAtIndex(modes, i); /* Skip modes that are not usable on the current display or have a @@ -157,7 +172,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen, continue; QuartzRandRGetModeInfo(modeRef, &modeInfo); - modeInfo.ref = (void *)modeRef; + modeInfo.ref = (void *) modeRef; cb = callback(pScreen, &modeInfo, data); if (cb == CALLBACK_CONTINUE) retval = TRUE; @@ -168,35 +183,36 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen, } } - switch(callback(pScreen, &pQuartzScreen->rootlessMode, data)) { - case CALLBACK_SUCCESS: - return TRUE; - case CALLBACK_ERROR: - return FALSE; - case CALLBACK_CONTINUE: - retval = TRUE; - default: - break; + switch (callback(pScreen, &pQuartzScreen->rootlessMode, data)) { + case CALLBACK_SUCCESS: + return TRUE; + case CALLBACK_ERROR: + return FALSE; + case CALLBACK_CONTINUE: + retval = TRUE; + default: + break; } - switch(callback(pScreen, &pQuartzScreen->fullscreenMode, data)) { - case CALLBACK_SUCCESS: - return TRUE; - case CALLBACK_ERROR: - return FALSE; - case CALLBACK_CONTINUE: - retval = TRUE; - default: - break; + switch (callback(pScreen, &pQuartzScreen->fullscreenMode, data)) { + case CALLBACK_SUCCESS: + return TRUE; + case CALLBACK_ERROR: + return FALSE; + case CALLBACK_CONTINUE: + retval = TRUE; + default: + break; } return retval; } -#else /* we have the new CG APIs from Snow Leopard */ +#else /* we have the new CG APIs from Snow Leopard */ -static void QuartzRandRGetModeInfo (CGDisplayModeRef modeRef, - QuartzModeInfoPtr pMode) { +static void +QuartzRandRGetModeInfo(CGDisplayModeRef modeRef, QuartzModeInfoPtr pMode) +{ pMode->width = CGDisplayModeGetWidth(modeRef); pMode->height = CGDisplayModeGetHeight(modeRef); pMode->refresh = (int) (CGDisplayModeGetRefreshRate(modeRef) + 0.5); @@ -206,9 +222,12 @@ static void QuartzRandRGetModeInfo (CGDisplayModeRef modeRef, pMode->pSize = NULL; } -static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId, - QuartzModeInfoPtr pMode) { +static Bool +QuartzRandRCopyCurrentModeInfo(CGDirectDisplayID screenId, + QuartzModeInfoPtr pMode) +{ CGDisplayModeRef curModeRef = CGDisplayCopyDisplayMode(screenId); + if (!curModeRef) return FALSE; @@ -217,23 +236,27 @@ static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId, return TRUE; } -static Bool QuartzRandRSetCGMode (CGDirectDisplayID screenId, - QuartzModeInfoPtr pMode) { +static Bool +QuartzRandRSetCGMode(CGDirectDisplayID screenId, QuartzModeInfoPtr pMode) +{ CGDisplayModeRef modeRef = (CGDisplayModeRef) pMode->ref; + if (!modeRef) return FALSE; - return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) == kCGErrorSuccess); + return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) == + kCGErrorSuccess); } -static Bool QuartzRandREnumerateModes (ScreenPtr pScreen, - QuartzModeCallback callback, - void *data) { +static Bool +QuartzRandREnumerateModes(ScreenPtr pScreen, + QuartzModeCallback callback, void *data) +{ Bool retval = FALSE; QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); /* Just an 800x600 fallback if we have no attached heads */ - if(pQuartzScreen->displayIDs) { + if (pQuartzScreen->displayIDs) { CGDisplayModeRef curModeRef, modeRef; CFStringRef curPixelEnc, pixelEnc; CFComparisonResult pixelEncEqual; @@ -255,6 +278,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen, } for (i = 0; i < CFArrayGetCount(modes); i++) { int cb; + modeRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); /* Skip modes that are not usable on the current display or have a @@ -273,11 +297,13 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen, cb = callback(pScreen, &modeInfo, data); if (cb == CALLBACK_CONTINUE) { retval = TRUE; - } else if (cb == CALLBACK_SUCCESS) { + } + else if (cb == CALLBACK_SUCCESS) { CFRelease(modes); CFRelease(curPixelEnc); return TRUE; - } else if (cb == CALLBACK_ERROR) { + } + else if (cb == CALLBACK_ERROR) { CFRelease(modes); CFRelease(curPixelEnc); return FALSE; @@ -288,81 +314,91 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen, CFRelease(curPixelEnc); } - switch(callback(pScreen, &pQuartzScreen->rootlessMode, data)) { - case CALLBACK_SUCCESS: - return TRUE; - case CALLBACK_ERROR: - return FALSE; - case CALLBACK_CONTINUE: - retval = TRUE; - default: - break; + switch (callback(pScreen, &pQuartzScreen->rootlessMode, data)) { + case CALLBACK_SUCCESS: + return TRUE; + case CALLBACK_ERROR: + return FALSE; + case CALLBACK_CONTINUE: + retval = TRUE; + default: + break; } - switch(callback(pScreen, &pQuartzScreen->fullscreenMode, data)) { - case CALLBACK_SUCCESS: - return TRUE; - case CALLBACK_ERROR: - return FALSE; - case CALLBACK_CONTINUE: - retval = TRUE; - default: - break; + switch (callback(pScreen, &pQuartzScreen->fullscreenMode, data)) { + case CALLBACK_SUCCESS: + return TRUE; + case CALLBACK_ERROR: + return FALSE; + case CALLBACK_CONTINUE: + retval = TRUE; + default: + break; } return retval; } -#endif /* Snow Leopard CoreGraphics APIs */ +#endif /* Snow Leopard CoreGraphics APIs */ - -static Bool QuartzRandRModesEqual (QuartzModeInfoPtr pMode1, - QuartzModeInfoPtr pMode2) { +static Bool +QuartzRandRModesEqual(QuartzModeInfoPtr pMode1, QuartzModeInfoPtr pMode2) +{ return (pMode1->width == pMode2->width) && - (pMode1->height == pMode2->height) && - (pMode1->refresh == pMode2->refresh); + (pMode1->height == pMode2->height) && + (pMode1->refresh == pMode2->refresh); } -static Bool QuartzRandRRegisterMode (ScreenPtr pScreen, - QuartzModeInfoPtr pMode) { +static Bool +QuartzRandRRegisterMode(ScreenPtr pScreen, QuartzModeInfoPtr pMode) +{ QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); - Bool isCurrentMode = QuartzRandRModesEqual(&pQuartzScreen->currentMode, pMode); + Bool isCurrentMode = + QuartzRandRModesEqual(&pQuartzScreen->currentMode, pMode); /* TODO: DPI */ - pMode->pSize = RRRegisterSize(pScreen, pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight); + pMode->pSize = + RRRegisterSize(pScreen, pMode->width, pMode->height, pScreen->mmWidth, + pScreen->mmHeight); if (pMode->pSize) { //DEBUG_LOG("registering: %d x %d @ %d %s\n", (int)pMode->width, (int)pMode->height, (int)pMode->refresh, isCurrentMode ? "*" : ""); RRRegisterRate(pScreen, pMode->pSize, pMode->refresh); if (isCurrentMode) - RRSetCurrentConfig(pScreen, RR_Rotate_0, pMode->refresh, pMode->pSize); + RRSetCurrentConfig(pScreen, RR_Rotate_0, pMode->refresh, + pMode->pSize); return TRUE; } return FALSE; } -static int QuartzRandRRegisterModeCallback (ScreenPtr pScreen, - QuartzModeInfoPtr pMode, - void *data __unused) { - if(QuartzRandRRegisterMode(pScreen, pMode)) { +static int +QuartzRandRRegisterModeCallback(ScreenPtr pScreen, + QuartzModeInfoPtr pMode, void *data __unused) +{ + if (QuartzRandRRegisterMode(pScreen, pMode)) { return CALLBACK_CONTINUE; - } else { + } + else { return CALLBACK_ERROR; } } -static Bool QuartzRandRSetMode(ScreenPtr pScreen, QuartzModeInfoPtr pMode, BOOL doRegister) { +static Bool +QuartzRandRSetMode(ScreenPtr pScreen, QuartzModeInfoPtr pMode, BOOL doRegister) +{ QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); - Bool captureDisplay = (pMode->refresh != FAKE_REFRESH_FULLSCREEN && pMode->refresh != FAKE_REFRESH_ROOTLESS); + Bool captureDisplay = (pMode->refresh != FAKE_REFRESH_FULLSCREEN && + pMode->refresh != FAKE_REFRESH_ROOTLESS); CGDirectDisplayID screenId; - if(pQuartzScreen->displayIDs == NULL) + if (pQuartzScreen->displayIDs == NULL) return FALSE; screenId = pQuartzScreen->displayIDs[0]; - if(XQuartzShieldingWindowLevel == 0 && captureDisplay) { - if(!X11ApplicationCanEnterRandR()) + if (XQuartzShieldingWindowLevel == 0 && captureDisplay) { + if (!X11ApplicationCanEnterRandR()) return FALSE; CGCaptureAllDisplays(); XQuartzShieldingWindowLevel = CGShieldingWindowLevel(); // 2147483630 @@ -370,11 +406,14 @@ static Bool QuartzRandRSetMode(ScreenPtr pScreen, QuartzModeInfoPtr pMode, BOOL CGShieldingWindowID(screenId), XQuartzShieldingWindowLevel); } - if (pQuartzScreen->currentMode.ref && CFEqual(pMode->ref, pQuartzScreen->currentMode.ref)) { + if (pQuartzScreen->currentMode.ref && + CFEqual(pMode->ref, pQuartzScreen->currentMode.ref)) { DEBUG_LOG("Requested RandR resolution matches current CG mode\n"); - } if (QuartzRandRSetCGMode(screenId, pMode)) { + } + if (QuartzRandRSetCGMode(screenId, pMode)) { ignore_next_fake_mode_update = TRUE; - } else { + } + else { DEBUG_LOG("Error while requesting CG resolution change.\n"); return FALSE; } @@ -387,13 +426,13 @@ static Bool QuartzRandRSetMode(ScreenPtr pScreen, QuartzModeInfoPtr pMode, BOOL QuartzShowFullscreen(TRUE); } - if(pQuartzScreen->currentMode.ref) + if (pQuartzScreen->currentMode.ref) CFRelease(pQuartzScreen->currentMode.ref); pQuartzScreen->currentMode = *pMode; - if(pQuartzScreen->currentMode.ref) + if (pQuartzScreen->currentMode.ref) CFRetain(pQuartzScreen->currentMode.ref); - - if(XQuartzShieldingWindowLevel != 0 && !captureDisplay) { + + if (XQuartzShieldingWindowLevel != 0 && !captureDisplay) { CGReleaseAllDisplays(); XQuartzShieldingWindowLevel = 0; } @@ -401,32 +440,37 @@ static Bool QuartzRandRSetMode(ScreenPtr pScreen, QuartzModeInfoPtr pMode, BOOL return TRUE; } -static int QuartzRandRSetModeCallback (ScreenPtr pScreen, - QuartzModeInfoPtr pMode, - void *data) { +static int +QuartzRandRSetModeCallback(ScreenPtr pScreen, + QuartzModeInfoPtr pMode, void *data) +{ QuartzModeInfoPtr pReqMode = (QuartzModeInfoPtr) data; - + if (!QuartzRandRModesEqual(pMode, pReqMode)) - return CALLBACK_CONTINUE; /* continue enumeration */ + return CALLBACK_CONTINUE; /* continue enumeration */ - DEBUG_LOG("Found a match for requested RandR resolution (%dx%d@%d).\n", (int)pMode->width, (int)pMode->height, (int)pMode->refresh); + DEBUG_LOG("Found a match for requested RandR resolution (%dx%d@%d).\n", + (int) pMode->width, (int) pMode->height, (int) pMode->refresh); - if(QuartzRandRSetMode(pScreen, pMode, FALSE)) + if (QuartzRandRSetMode(pScreen, pMode, FALSE)) return CALLBACK_SUCCESS; else return CALLBACK_ERROR; } -static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) { - *rotations = RR_Rotate_0; /* TODO: support rotation */ +static Bool +QuartzRandRGetInfo(ScreenPtr pScreen, Rotation * rotations) +{ + *rotations = RR_Rotate_0; /* TODO: support rotation */ - return QuartzRandREnumerateModes(pScreen, QuartzRandRRegisterModeCallback, NULL); + return QuartzRandREnumerateModes(pScreen, QuartzRandRRegisterModeCallback, + NULL); } -static Bool QuartzRandRSetConfig (ScreenPtr pScreen, - Rotation randr, - int rate, - RRScreenSizePtr pSize) { +static Bool +QuartzRandRSetConfig(ScreenPtr pScreen, + Rotation randr, int rate, RRScreenSizePtr pSize) +{ QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); QuartzModeInfo reqMode; @@ -437,92 +481,111 @@ static Bool QuartzRandRSetConfig (ScreenPtr pScreen, /* Do not switch modes if requested mode is equal to current mode. */ if (QuartzRandRModesEqual(&reqMode, &pQuartzScreen->currentMode)) return TRUE; - - if (QuartzRandREnumerateModes(pScreen, QuartzRandRSetModeCallback, &reqMode)) { + + if (QuartzRandREnumerateModes + (pScreen, QuartzRandRSetModeCallback, &reqMode)) { return TRUE; } - - DEBUG_LOG("Unable to find a matching config: %d x %d @ %d\n", (int)reqMode.width, (int)reqMode.height, (int)reqMode.refresh); + + DEBUG_LOG("Unable to find a matching config: %d x %d @ %d\n", + (int) reqMode.width, (int) reqMode.height, (int) reqMode.refresh); return FALSE; } -static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) { +static Bool +_QuartzRandRUpdateFakeModes(ScreenPtr pScreen) +{ QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); QuartzModeInfo activeMode; - if(pQuartzScreen->displayCount > 0) { - if(!QuartzRandRCopyCurrentModeInfo(pQuartzScreen->displayIDs[0], &activeMode)) { + if (pQuartzScreen->displayCount > 0) { + if (!QuartzRandRCopyCurrentModeInfo + (pQuartzScreen->displayIDs[0], &activeMode)) { ErrorF("Unable to determine current display mode.\n"); return FALSE; } - } else { + } + else { memset(&activeMode, 0, sizeof(activeMode)); activeMode.width = 800; activeMode.height = 600; activeMode.refresh = 60; } - if(pQuartzScreen->fullscreenMode.ref) + if (pQuartzScreen->fullscreenMode.ref) CFRelease(pQuartzScreen->fullscreenMode.ref); - if(pQuartzScreen->currentMode.ref) + if (pQuartzScreen->currentMode.ref) CFRelease(pQuartzScreen->currentMode.ref); - if(pQuartzScreen->displayCount > 1) { + if (pQuartzScreen->displayCount > 1) { activeMode.width = pScreen->width; activeMode.height = pScreen->height; - if(XQuartzIsRootless) + if (XQuartzIsRootless) activeMode.height += aquaMenuBarHeight; } - pQuartzScreen->fullscreenMode = activeMode; + pQuartzScreen->fullscreenMode = activeMode; pQuartzScreen->fullscreenMode.refresh = FAKE_REFRESH_FULLSCREEN; pQuartzScreen->rootlessMode = activeMode; pQuartzScreen->rootlessMode.refresh = FAKE_REFRESH_ROOTLESS; pQuartzScreen->rootlessMode.height -= aquaMenuBarHeight; - if(XQuartzIsRootless) { + if (XQuartzIsRootless) { pQuartzScreen->currentMode = pQuartzScreen->rootlessMode; - } else { + } + else { pQuartzScreen->currentMode = pQuartzScreen->fullscreenMode; } /* This extra retain is for currentMode's copy. * fullscreen and rootless share a retain. */ - if(pQuartzScreen->currentMode.ref) + if (pQuartzScreen->currentMode.ref) CFRetain(pQuartzScreen->currentMode.ref); - - DEBUG_LOG("rootlessMode: %d x %d\n", (int)pQuartzScreen->rootlessMode.width, (int)pQuartzScreen->rootlessMode.height); - DEBUG_LOG("fullscreenMode: %d x %d\n", (int)pQuartzScreen->fullscreenMode.width, (int)pQuartzScreen->fullscreenMode.height); - DEBUG_LOG("currentMode: %d x %d\n", (int)pQuartzScreen->currentMode.width, (int)pQuartzScreen->currentMode.height); - + + DEBUG_LOG("rootlessMode: %d x %d\n", + (int) pQuartzScreen->rootlessMode.width, + (int) pQuartzScreen->rootlessMode.height); + DEBUG_LOG("fullscreenMode: %d x %d\n", + (int) pQuartzScreen->fullscreenMode.width, + (int) pQuartzScreen->fullscreenMode.height); + DEBUG_LOG("currentMode: %d x %d\n", (int) pQuartzScreen->currentMode.width, + (int) pQuartzScreen->currentMode.height); + return TRUE; } -Bool QuartzRandRUpdateFakeModes (BOOL force_update) { +Bool +QuartzRandRUpdateFakeModes(BOOL force_update) +{ ScreenPtr pScreen = screenInfo.screens[0]; - - if(ignore_next_fake_mode_update) { - DEBUG_LOG("Ignoring update request caused by RandR resolution change.\n"); + + if (ignore_next_fake_mode_update) { + DEBUG_LOG + ("Ignoring update request caused by RandR resolution change.\n"); ignore_next_fake_mode_update = FALSE; return TRUE; } - - if(!_QuartzRandRUpdateFakeModes(pScreen)) + + if (!_QuartzRandRUpdateFakeModes(pScreen)) return FALSE; - - if(force_update) + + if (force_update) RRGetInfo(pScreen, TRUE); return TRUE; } -Bool QuartzRandRInit (ScreenPtr pScreen) { - rrScrPrivPtr pScrPriv; - - if (!RRScreenInit (pScreen)) return FALSE; - if (!_QuartzRandRUpdateFakeModes (pScreen)) return FALSE; +Bool +QuartzRandRInit(ScreenPtr pScreen) +{ + rrScrPrivPtr pScrPriv; + + if (!RRScreenInit(pScreen)) + return FALSE; + if (!_QuartzRandRUpdateFakeModes(pScreen)) + return FALSE; pScrPriv = rrGetScrPriv(pScreen); pScrPriv->rrGetInfo = QuartzRandRGetInfo; @@ -530,12 +593,14 @@ Bool QuartzRandRInit (ScreenPtr pScreen) { return TRUE; } -void QuartzRandRSetFakeRootless (void) { +void +QuartzRandRSetFakeRootless(void) +{ int i; - + DEBUG_LOG("QuartzRandRSetFakeRootless called.\n"); - - for (i=0; i < screenInfo.numScreens; i++) { + + for (i = 0; i < screenInfo.numScreens; i++) { ScreenPtr pScreen = screenInfo.screens[i]; QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); @@ -543,18 +608,20 @@ void QuartzRandRSetFakeRootless (void) { } } -void QuartzRandRSetFakeFullscreen (BOOL state) { +void +QuartzRandRSetFakeFullscreen(BOOL state) +{ int i; DEBUG_LOG("QuartzRandRSetFakeFullscreen called.\n"); - - for (i=0; i < screenInfo.numScreens; i++) { + + for (i = 0; i < screenInfo.numScreens; i++) { ScreenPtr pScreen = screenInfo.screens[i]; QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); QuartzRandRSetMode(pScreen, &pQuartzScreen->fullscreenMode, TRUE); } - + QuartzShowFullscreen(state); } @@ -563,23 +630,31 @@ void QuartzRandRSetFakeFullscreen (BOOL state) { * mode, this will toggles us to the default fake mode and hide windows if * it is fullscreen */ -void QuartzRandRToggleFullscreen (void) { +void +QuartzRandRToggleFullscreen(void) +{ ScreenPtr pScreen = screenInfo.screens[0]; QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); if (pQuartzScreen->currentMode.ref == NULL) { - ErrorF("Ignoring QuartzRandRToggleFullscreen because don't have a current mode set.\n"); - } else if (pQuartzScreen->currentMode.refresh == FAKE_REFRESH_ROOTLESS) { - ErrorF("Ignoring QuartzRandRToggleFullscreen because we are in rootless mode.\n"); - } else if (pQuartzScreen->currentMode.refresh == FAKE_REFRESH_FULLSCREEN) { + ErrorF + ("Ignoring QuartzRandRToggleFullscreen because don't have a current mode set.\n"); + } + else if (pQuartzScreen->currentMode.refresh == FAKE_REFRESH_ROOTLESS) { + ErrorF + ("Ignoring QuartzRandRToggleFullscreen because we are in rootless mode.\n"); + } + else if (pQuartzScreen->currentMode.refresh == FAKE_REFRESH_FULLSCREEN) { /* Legacy fullscreen mode. Hide/Show */ QuartzShowFullscreen(!XQuartzFullscreenVisible); - } else { + } + else { /* RandR fullscreen mode. Return to default mode and hide if it is fullscreen. */ - if(XQuartzRootlessDefault) { + if (XQuartzRootlessDefault) { QuartzRandRSetFakeRootless(); - } else { + } + else { QuartzRandRSetFakeFullscreen(FALSE); } - } + } } diff --git a/xorg-server/hw/xquartz/quartzStartup.c b/xorg-server/hw/xquartz/quartzStartup.c index 25ef76efa..183bf7618 100644 --- a/xorg-server/hw/xquartz/quartzStartup.c +++ b/xorg-server/hw/xquartz/quartzStartup.c @@ -56,59 +56,68 @@ struct arg { char **envp; }; -_X_NORETURN -static void server_thread (void *arg) { - struct arg args = *((struct arg *)arg); +_X_NORETURN static void +server_thread(void *arg) +{ + struct arg args = *((struct arg *) arg); + free(arg); - exit (dix_main(args.argc, args.argv, args.envp)); + exit(dix_main(args.argc, args.argv, args.envp)); } -static pthread_t create_thread (void *func, void *arg) { +static pthread_t +create_thread(void *func, void *arg) +{ pthread_attr_t attr; pthread_t tid; - - pthread_attr_init (&attr); - pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM); - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&tid, &attr, func, arg); - pthread_attr_destroy (&attr); - + + pthread_attr_init(&attr); + pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&tid, &attr, func, arg); + pthread_attr_destroy(&attr); + return tid; } -void QuartzInitServer(int argc, char **argv, char **envp) { - struct arg *args = (struct arg*)malloc(sizeof(struct arg)); - if(!args) +void +QuartzInitServer(int argc, char **argv, char **envp) +{ + struct arg *args = (struct arg *) malloc(sizeof(struct arg)); + + if (!args) FatalError("Could not allocate memory.\n"); - + args->argc = argc; args->argv = argv; args->envp = envp; - + if (!create_thread(server_thread, args)) { FatalError("can't create secondary thread\n"); } } -int server_main(int argc, char **argv, char **envp) { - int i; - int fd[2]; +int +server_main(int argc, char **argv, char **envp) +{ + int i; + int fd[2]; /* Unset CFProcessPath, so our children don't inherit this kludge we need * to load our nib. If an xterm gets this set, then it fails to * 'open hi.txt' properly. */ unsetenv("CFProcessPath"); - + // Make a pipe to pass events - assert( pipe(fd) == 0 ); + assert(pipe(fd) == 0); darwinEventReadFD = fd[0]; darwinEventWriteFD = fd[1]; fcntl(darwinEventReadFD, F_SETFL, O_NONBLOCK); for (i = 1; i < argc; i++) { // Display version info without starting Mac OS X UI if requested - if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) { + if (!strcmp(argv[i], "-showconfig") || !strcmp(argv[i], "-version")) { DarwinPrintBanner(); exit(0); } diff --git a/xorg-server/hw/xquartz/xpr/appledri.c b/xorg-server/hw/xquartz/xpr/appledri.c index 44c132abc..4ef0061b2 100644 --- a/xorg-server/hw/xquartz/xpr/appledri.c +++ b/xorg-server/hw/xquartz/xpr/appledri.c @@ -59,36 +59,31 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. static int DRIErrorBase = 0; - -static void AppleDRIResetProc(ExtensionEntry* extEntry); +static void AppleDRIResetProc(ExtensionEntry * extEntry); static int ProcAppleDRICreatePixmap(ClientPtr client); static unsigned char DRIReqCode = 0; static int DRIEventBase = 0; -static void SNotifyEvent(xAppleDRINotifyEvent *from, xAppleDRINotifyEvent *to); +static void SNotifyEvent(xAppleDRINotifyEvent * from, + xAppleDRINotifyEvent * to); typedef struct _DRIEvent *DRIEventPtr; typedef struct _DRIEvent { - DRIEventPtr next; - ClientPtr client; - XID clientResource; - unsigned int mask; + DRIEventPtr next; + ClientPtr client; + XID clientResource; + unsigned int mask; } DRIEventRec; -/*ARGSUSED*/ -static void -AppleDRIResetProc ( - ExtensionEntry* extEntry -) + /*ARGSUSED*/ static void +AppleDRIResetProc(ExtensionEntry * extEntry) { DRIReset(); } static int -ProcAppleDRIQueryVersion( - register ClientPtr client -) +ProcAppleDRIQueryVersion(register ClientPtr client) { xAppleDRIQueryVersionReply rep; @@ -106,17 +101,14 @@ ProcAppleDRIQueryVersion( swaps(&rep.minorVersion); swapl(&rep.patchVersion); } - WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *) &rep); return Success; } - /* surfaces */ static int -ProcAppleDRIQueryDirectRenderingCapable( - register ClientPtr client -) +ProcAppleDRIQueryDirectRenderingCapable(register ClientPtr client) { xAppleDRIQueryDirectRenderingCapableReply rep; Bool isCapable; @@ -127,8 +119,8 @@ ProcAppleDRIQueryDirectRenderingCapable( rep.length = 0; rep.sequenceNumber = client->sequence; - if (!DRIQueryDirectRenderingCapable( screenInfo.screens[stuff->screen], - &isCapable)) { + if (!DRIQueryDirectRenderingCapable(screenInfo.screens[stuff->screen], + &isCapable)) { return BadValue; } rep.isCapable = isCapable; @@ -141,18 +133,17 @@ ProcAppleDRIQueryDirectRenderingCapable( swapl(&rep.length); } - WriteToClient(client, - sizeof(xAppleDRIQueryDirectRenderingCapableReply), (char *)&rep); + WriteToClient(client, + sizeof(xAppleDRIQueryDirectRenderingCapableReply), + (char *) &rep); return Success; } static int -ProcAppleDRIAuthConnection( - register ClientPtr client -) +ProcAppleDRIAuthConnection(register ClientPtr client) { xAppleDRIAuthConnectionReply rep; - + REQUEST(xAppleDRIAuthConnectionReq); REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq); @@ -161,25 +152,23 @@ ProcAppleDRIAuthConnection( rep.sequenceNumber = client->sequence; rep.authenticated = 1; - if (!DRIAuthConnection( screenInfo.screens[stuff->screen], stuff->magic)) { - ErrorF("Failed to authenticate %u\n", (unsigned int)stuff->magic); + if (!DRIAuthConnection(screenInfo.screens[stuff->screen], stuff->magic)) { + ErrorF("Failed to authenticate %u\n", (unsigned int) stuff->magic); rep.authenticated = 0; } if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); - swapl(&rep.authenticated); /* Yes, this is a CARD32 ... sigh */ + swapl(&rep.authenticated); /* Yes, this is a CARD32 ... sigh */ } - WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *)&rep); + WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *) &rep); return Success; } -static void surface_notify( - void *_arg, - void *data -) +static void +surface_notify(void *_arg, void *data) { DRISurfaceNotifyArg *arg = _arg; int client_index = (int) x_cvt_vptr_to_uint(data); @@ -192,13 +181,11 @@ static void surface_notify( se.kind = arg->kind; se.arg = arg->id; se.time = currentTime.milliseconds; - WriteEventsToClient (clients[client_index], 1, (xEvent *) &se); + WriteEventsToClient(clients[client_index], 1, (xEvent *) &se); } static int -ProcAppleDRICreateSurface( - ClientPtr client -) +ProcAppleDRICreateSurface(ClientPtr client) { xAppleDRICreateSurfaceReply rep; DrawablePtr pDrawable; @@ -213,17 +200,16 @@ ProcAppleDRICreateSurface( rep.sequenceNumber = client->sequence; rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0, - DixReadAccess); + DixReadAccess); if (rc != Success) - return rc; + return rc; rep.key_0 = rep.key_1 = rep.uid = 0; - if (!DRICreateSurface( screenInfo.screens[stuff->screen], - (Drawable)stuff->drawable, pDrawable, - stuff->client_id, &sid, key, - surface_notify, - x_cvt_uint_to_vptr(client->index))) { + if (!DRICreateSurface(screenInfo.screens[stuff->screen], + (Drawable) stuff->drawable, pDrawable, + stuff->client_id, &sid, key, + surface_notify, x_cvt_uint_to_vptr(client->index))) { return BadValue; } @@ -239,28 +225,27 @@ ProcAppleDRICreateSurface( swapl(&rep.uid); } - WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *)&rep); + WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *) &rep); return Success; } static int -ProcAppleDRIDestroySurface( - register ClientPtr client -) +ProcAppleDRIDestroySurface(register ClientPtr client) { int rc; + REQUEST(xAppleDRIDestroySurfaceReq); DrawablePtr pDrawable; + REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq); rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0, - DixReadAccess); + DixReadAccess); if (rc != Success) - return rc; + return rc; - if (!DRIDestroySurface( screenInfo.screens[stuff->screen], - (Drawable)stuff->drawable, - pDrawable, NULL, NULL)) { + if (!DRIDestroySurface(screenInfo.screens[stuff->screen], + (Drawable) stuff->drawable, pDrawable, NULL, NULL)) { return BadValue; } @@ -283,23 +268,21 @@ ProcAppleDRICreatePixmap(ClientPtr client) rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0, DixReadAccess); - if(rc != Success) + if (rc != Success) return rc; - - if(!DRICreatePixmap(screenInfo.screens[stuff->screen], - (Drawable)stuff->drawable, - pDrawable, - path, PATH_MAX)) { + + if (!DRICreatePixmap(screenInfo.screens[stuff->screen], + (Drawable) stuff->drawable, + pDrawable, path, PATH_MAX)) { + return BadValue; + } + + if (!DRIGetPixmapData(pDrawable, &width, &height, &pitch, &bpp, &ptr)) { return BadValue; } - if(!DRIGetPixmapData(pDrawable, &width, &height, - &pitch, &bpp, &ptr)) { - return BadValue; - } - rep.stringLength = strlen(path) + 1; - + rep.type = X_Reply; rep.length = bytes_to_int32(rep.stringLength); rep.sequenceNumber = client->sequence; @@ -309,9 +292,9 @@ ProcAppleDRICreatePixmap(ClientPtr client) rep.bpp = bpp; rep.size = pitch * height; - if(sizeof(rep) != sz_xAppleDRICreatePixmapReply) - ErrorF("error sizeof(rep) is %zu\n", sizeof(rep)); - + if (sizeof(rep) != sz_xAppleDRICreatePixmapReply) + ErrorF("error sizeof(rep) is %zu\n", sizeof(rep)); + if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); @@ -334,15 +317,16 @@ ProcAppleDRIDestroyPixmap(ClientPtr client) { DrawablePtr pDrawable; int rc; + REQUEST(xAppleDRIDestroyPixmapReq); REQUEST_SIZE_MATCH(xAppleDRIDestroyPixmapReq); rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0, - DixReadAccess); + DixReadAccess); + + if (rc != Success) + return rc; - if(rc != Success) - return rc; - DRIDestroyPixmap(pDrawable); return Success; @@ -351,14 +335,11 @@ ProcAppleDRIDestroyPixmap(ClientPtr client) /* dispatch */ static int -ProcAppleDRIDispatch ( - register ClientPtr client -) +ProcAppleDRIDispatch(register ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { + switch (stuff->data) { case X_AppleDRIQueryVersion: return ProcAppleDRIQueryVersion(client); case X_AppleDRIQueryDirectRenderingCapable: @@ -368,8 +349,7 @@ ProcAppleDRIDispatch ( if (!LocalClient(client)) return DRIErrorBase + AppleDRIClientNotLocal; - switch (stuff->data) - { + switch (stuff->data) { case X_AppleDRIAuthConnection: return ProcAppleDRIAuthConnection(client); case X_AppleDRICreateSurface: @@ -377,9 +357,9 @@ ProcAppleDRIDispatch ( case X_AppleDRIDestroySurface: return ProcAppleDRIDestroySurface(client); case X_AppleDRICreatePixmap: - return ProcAppleDRICreatePixmap(client); + return ProcAppleDRICreatePixmap(client); case X_AppleDRIDestroyPixmap: - return ProcAppleDRIDestroyPixmap(client); + return ProcAppleDRIDestroyPixmap(client); default: return BadRequest; @@ -387,22 +367,17 @@ ProcAppleDRIDispatch ( } static void -SNotifyEvent( - xAppleDRINotifyEvent *from, - xAppleDRINotifyEvent *to -) +SNotifyEvent(xAppleDRINotifyEvent * from, xAppleDRINotifyEvent * to) { to->type = from->type; to->kind = from->kind; - cpswaps (from->sequenceNumber, to->sequenceNumber); - cpswapl (from->time, to->time); - cpswapl (from->arg, to->arg); + cpswaps(from->sequenceNumber, to->sequenceNumber); + cpswapl(from->time, to->time); + cpswapl(from->arg, to->arg); } static int -SProcAppleDRIQueryVersion( - register ClientPtr client -) +SProcAppleDRIQueryVersion(register ClientPtr client) { REQUEST(xAppleDRIQueryVersionReq); swaps(&stuff->length); @@ -410,9 +385,7 @@ SProcAppleDRIQueryVersion( } static int -SProcAppleDRIQueryDirectRenderingCapable( - register ClientPtr client -) +SProcAppleDRIQueryDirectRenderingCapable(register ClientPtr client) { REQUEST(xAppleDRIQueryDirectRenderingCapableReq); swaps(&stuff->length); @@ -421,9 +394,7 @@ SProcAppleDRIQueryDirectRenderingCapable( } static int -SProcAppleDRIAuthConnection( - register ClientPtr client -) +SProcAppleDRIAuthConnection(register ClientPtr client) { REQUEST(xAppleDRIAuthConnectionReq); swaps(&stuff->length); @@ -433,9 +404,7 @@ SProcAppleDRIAuthConnection( } static int -SProcAppleDRICreateSurface( - register ClientPtr client -) +SProcAppleDRICreateSurface(register ClientPtr client) { REQUEST(xAppleDRICreateSurfaceReq); swaps(&stuff->length); @@ -446,9 +415,7 @@ SProcAppleDRICreateSurface( } static int -SProcAppleDRIDestroySurface( - register ClientPtr client -) +SProcAppleDRIDestroySurface(register ClientPtr client) { REQUEST(xAppleDRIDestroySurfaceReq); swaps(&stuff->length); @@ -458,9 +425,7 @@ SProcAppleDRIDestroySurface( } static int -SProcAppleDRICreatePixmap( - register ClientPtr client -) +SProcAppleDRICreatePixmap(register ClientPtr client) { REQUEST(xAppleDRICreatePixmapReq); swaps(&stuff->length); @@ -470,9 +435,7 @@ SProcAppleDRICreatePixmap( } static int -SProcAppleDRIDestroyPixmap( - register ClientPtr client -) +SProcAppleDRIDestroyPixmap(register ClientPtr client) { REQUEST(xAppleDRIDestroyPixmapReq); swaps(&stuff->length); @@ -481,14 +444,11 @@ SProcAppleDRIDestroyPixmap( } static int -SProcAppleDRIDispatch ( - register ClientPtr client -) +SProcAppleDRIDispatch(register ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { + switch (stuff->data) { case X_AppleDRIQueryVersion: return SProcAppleDRIQueryVersion(client); case X_AppleDRIQueryDirectRenderingCapable: @@ -498,8 +458,7 @@ SProcAppleDRIDispatch ( if (!LocalClient(client)) return DRIErrorBase + AppleDRIClientNotLocal; - switch (stuff->data) - { + switch (stuff->data) { case X_AppleDRIAuthConnection: return SProcAppleDRIAuthConnection(client); case X_AppleDRICreateSurface: @@ -507,9 +466,9 @@ SProcAppleDRIDispatch ( case X_AppleDRIDestroySurface: return SProcAppleDRIDestroySurface(client); case X_AppleDRICreatePixmap: - return SProcAppleDRICreatePixmap(client); + return SProcAppleDRICreatePixmap(client); case X_AppleDRIDestroyPixmap: - return SProcAppleDRIDestroyPixmap(client); + return SProcAppleDRIDestroyPixmap(client); default: return BadRequest; @@ -519,7 +478,7 @@ SProcAppleDRIDispatch ( void AppleDRIExtensionInit(void) { - ExtensionEntry* extEntry; + ExtensionEntry *extEntry; if (DRIExtensionInit() && (extEntry = AddExtension(APPLEDRINAME, @@ -527,13 +486,13 @@ AppleDRIExtensionInit(void) AppleDRINumberErrors, ProcAppleDRIDispatch, SProcAppleDRIDispatch, - AppleDRIResetProc, - StandardMinorOpcode))) { + AppleDRIResetProc, StandardMinorOpcode))) { size_t i; - DRIReqCode = (unsigned char)extEntry->base; + + DRIReqCode = (unsigned char) extEntry->base; DRIErrorBase = extEntry->errorBase; DRIEventBase = extEntry->eventBase; - for (i=0; i < AppleDRINumberEvents; i++) + for (i = 0; i < AppleDRINumberEvents; i++) EventSwapVector[DRIEventBase + i] = (EventSwapPtr) SNotifyEvent; } } diff --git a/xorg-server/hw/xquartz/xpr/appledristr.h b/xorg-server/hw/xquartz/xpr/appledristr.h index b5ffe5b46..131a699d9 100644 --- a/xorg-server/hw/xquartz/xpr/appledristr.h +++ b/xorg-server/hw/xquartz/xpr/appledristr.h @@ -46,207 +46,200 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define APPLE_DRI_MINOR_VERSION 0 #define APPLE_DRI_PATCH_VERSION 0 -typedef struct _AppleDRIQueryVersion -{ - CARD8 reqType; /* always DRIReqCode */ - CARD8 driReqType; /* always X_DRIQueryVersion */ - CARD16 length B16; +typedef struct _AppleDRIQueryVersion { + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIQueryVersion */ + CARD16 length B16; } xAppleDRIQueryVersionReq; + #define sz_xAppleDRIQueryVersionReq 4 -typedef struct -{ - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 majorVersion B16; /* major version of DRI protocol */ - CARD16 minorVersion B16; /* minor version of DRI protocol */ - CARD32 patchVersion B32; /* patch version of DRI protocol */ - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct { + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 majorVersion B16; /* major version of DRI protocol */ + CARD16 minorVersion B16; /* minor version of DRI protocol */ + CARD32 patchVersion B32; /* patch version of DRI protocol */ + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xAppleDRIQueryVersionReply; + #define sz_xAppleDRIQueryVersionReply 32 -typedef struct _AppleDRIQueryDirectRenderingCapable -{ - CARD8 reqType; /* always DRIReqCode */ - CARD8 driReqType; /* X_DRIQueryDirectRenderingCapable */ - CARD16 length B16; - CARD32 screen B32; +typedef struct _AppleDRIQueryDirectRenderingCapable { + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* X_DRIQueryDirectRenderingCapable */ + CARD16 length B16; + CARD32 screen B32; } xAppleDRIQueryDirectRenderingCapableReq; + #define sz_xAppleDRIQueryDirectRenderingCapableReq 8 -typedef struct -{ - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - BOOL isCapable; - BOOL pad2; - BOOL pad3; - BOOL pad4; - CARD32 pad5 B32; - CARD32 pad6 B32; - CARD32 pad7 B32; - CARD32 pad8 B32; - CARD32 pad9 B32; +typedef struct { + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + BOOL isCapable; + BOOL pad2; + BOOL pad3; + BOOL pad4; + CARD32 pad5 B32; + CARD32 pad6 B32; + CARD32 pad7 B32; + CARD32 pad8 B32; + CARD32 pad9 B32; } xAppleDRIQueryDirectRenderingCapableReply; + #define sz_xAppleDRIQueryDirectRenderingCapableReply 32 -typedef struct _AppleDRIAuthConnection -{ - CARD8 reqType; /* always DRIReqCode */ - CARD8 driReqType; /* always X_DRICloseConnection */ - CARD16 length B16; - CARD32 screen B32; - CARD32 magic B32; +typedef struct _AppleDRIAuthConnection { + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRICloseConnection */ + CARD16 length B16; + CARD32 screen B32; + CARD32 magic B32; } xAppleDRIAuthConnectionReq; + #define sz_xAppleDRIAuthConnectionReq 12 -typedef struct -{ - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 authenticated B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct { + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 authenticated B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xAppleDRIAuthConnectionReply; + #define zx_xAppleDRIAuthConnectionReply 32 -typedef struct _AppleDRICreateSurface -{ - CARD8 reqType; /* always DRIReqCode */ - CARD8 driReqType; /* always X_DRICreateSurface */ - CARD16 length B16; - CARD32 screen B32; - CARD32 drawable B32; - CARD32 client_id B32; +typedef struct _AppleDRICreateSurface { + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRICreateSurface */ + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; + CARD32 client_id B32; } xAppleDRICreateSurfaceReq; + #define sz_xAppleDRICreateSurfaceReq 16 -typedef struct -{ - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 key_0 B32; - CARD32 key_1 B32; - CARD32 uid B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct { + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 key_0 B32; + CARD32 key_1 B32; + CARD32 uid B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xAppleDRICreateSurfaceReply; + #define sz_xAppleDRICreateSurfaceReply 32 -typedef struct _AppleDRIDestroySurface -{ - CARD8 reqType; /* always DRIReqCode */ - CARD8 driReqType; /* always X_DRIDestroySurface */ - CARD16 length B16; - CARD32 screen B32; - CARD32 drawable B32; +typedef struct _AppleDRIDestroySurface { + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIDestroySurface */ + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; } xAppleDRIDestroySurfaceReq; + #define sz_xAppleDRIDestroySurfaceReq 12 -typedef struct _AppleDRINotify -{ - BYTE type; /* always eventBase + event type */ - BYTE kind; - CARD16 sequenceNumber B16; - CARD32 time B32; /* time of change */ - CARD32 pad1 B32; - CARD32 arg B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct _AppleDRINotify { + BYTE type; /* always eventBase + event type */ + BYTE kind; + CARD16 sequenceNumber B16; + CARD32 time B32; /* time of change */ + CARD32 pad1 B32; + CARD32 arg B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xAppleDRINotifyEvent; -#define sz_xAppleDRINotifyEvent 32 +#define sz_xAppleDRINotifyEvent 32 -typedef struct -{ - CARD8 reqType; - CARD8 driReqType; - CARD16 length B16; - CARD32 screen B32; - CARD32 drawable B32; - BOOL doubleSwap; - CARD8 pad1, pad2, pad3; +typedef struct { + CARD8 reqType; + CARD8 driReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; + BOOL doubleSwap; + CARD8 pad1, pad2, pad3; } xAppleDRICreateSharedBufferReq; #define sz_xAppleDRICreateSharedBufferReq 16 -typedef struct -{ - BYTE type; - BYTE data1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 stringLength B32; /* 0 on error */ - CARD32 width B32; - CARD32 height B32; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; +typedef struct { + BYTE type; + BYTE data1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 stringLength B32; /* 0 on error */ + CARD32 width B32; + CARD32 height B32; + CARD32 pad1 B32; + CARD32 pad2 B32; + CARD32 pad3 B32; } xAppleDRICreateSharedBufferReply; #define sz_xAppleDRICreateSharedBufferReply 32 -typedef struct -{ - CARD8 reqType; - CARD8 driReqType; - CARD16 length B16; - CARD32 screen B32; - CARD32 drawable B32; +typedef struct { + CARD8 reqType; + CARD8 driReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; } xAppleDRISwapBuffersReq; #define sz_xAppleDRISwapBuffersReq 12 -typedef struct -{ - CARD8 reqType; /*1 */ - CARD8 driReqType; /*2 */ - CARD16 length B16; /*4 */ - CARD32 screen B32; /*8 */ - CARD32 drawable B32; /*12 */ +typedef struct { + CARD8 reqType; /*1 */ + CARD8 driReqType; /*2 */ + CARD16 length B16; /*4 */ + CARD32 screen B32; /*8 */ + CARD32 drawable B32; /*12 */ } xAppleDRICreatePixmapReq; #define sz_xAppleDRICreatePixmapReq 12 -typedef struct -{ - BYTE type; /*1 */ - BOOL pad1; /*2 */ - CARD16 sequenceNumber B16; /*4 */ - CARD32 length B32; /*8 */ - CARD32 width B32; /*12 */ - CARD32 height B32; /*16 */ - CARD32 pitch B32; /*20 */ - CARD32 bpp B32; /*24 */ - CARD32 size B32; /*28 */ - CARD32 stringLength B32; /*32 */ +typedef struct { + BYTE type; /*1 */ + BOOL pad1; /*2 */ + CARD16 sequenceNumber B16; /*4 */ + CARD32 length B32; /*8 */ + CARD32 width B32; /*12 */ + CARD32 height B32; /*16 */ + CARD32 pitch B32; /*20 */ + CARD32 bpp B32; /*24 */ + CARD32 size B32; /*28 */ + CARD32 stringLength B32; /*32 */ } xAppleDRICreatePixmapReply; #define sz_xAppleDRICreatePixmapReply 32 -typedef struct -{ - CARD8 reqType; /*1 */ - CARD8 driReqType; /*2 */ - CARD16 length B16; /*4 */ - CARD32 drawable B32; /*8 */ +typedef struct { + CARD8 reqType; /*1 */ + CARD8 driReqType; /*2 */ + CARD16 length B16; /*4 */ + CARD32 drawable B32; /*8 */ } xAppleDRIDestroyPixmapReq; #define sz_xAppleDRIDestroyPixmapReq 8 @@ -255,12 +248,12 @@ typedef struct void AppleDRISendEvent( #if NeedFunctionPrototypes - int /* type */ , - unsigned int /* mask */ , - int /* which */ , - int /* arg */ + int /* type */ , + unsigned int /* mask */ , + int /* which */ , + int /* arg */ #endif - ); + ); -#endif /* _APPLEDRI_SERVER_ */ -#endif /* _APPLEDRISTR_H_ */ +#endif /* _APPLEDRI_SERVER_ */ +#endif /* _APPLEDRISTR_H_ */ diff --git a/xorg-server/hw/xquartz/xpr/dri.c b/xorg-server/hw/xquartz/xpr/dri.c index a58f2c76d..0ce1d0771 100644 --- a/xorg-server/hw/xquartz/xpr/dri.c +++ b/xorg-server/hw/xquartz/xpr/dri.c @@ -75,12 +75,16 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <AvailabilityMacros.h> static DevPrivateKeyRec DRIScreenPrivKeyRec; + #define DRIScreenPrivKey (&DRIScreenPrivKeyRec) static DevPrivateKeyRec DRIWindowPrivKeyRec; + #define DRIWindowPrivKey (&DRIWindowPrivKeyRec) static DevPrivateKeyRec DRIPixmapPrivKeyRec; + #define DRIPixmapPrivKey (&DRIPixmapPrivKeyRec) static DevPrivateKeyRec DRIPixmapBufferPrivKeyRec; + #define DRIPixmapBufferPrivKey (&DRIPixmapBufferPrivKeyRec) static RESTYPE DRIDrawablePrivResType; @@ -96,29 +100,29 @@ typedef struct { int width; int height; char shmPath[PATH_MAX]; - int fd; /* From shm_open (for now) */ - size_t length; /* length of buffer */ - void *buffer; + int fd; /* From shm_open (for now) */ + size_t length; /* length of buffer */ + void *buffer; } DRIPixmapBuffer, *DRIPixmapBufferPtr; Bool DRIScreenInit(ScreenPtr pScreen) { - DRIScreenPrivPtr pDRIPriv; - int i; + DRIScreenPrivPtr pDRIPriv; + int i; if (!dixRegisterPrivateKey(&DRIScreenPrivKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; + return FALSE; if (!dixRegisterPrivateKey(&DRIWindowPrivKeyRec, PRIVATE_WINDOW, 0)) - return FALSE; + return FALSE; if (!dixRegisterPrivateKey(&DRIPixmapPrivKeyRec, PRIVATE_PIXMAP, 0)) - return FALSE; + return FALSE; if (!dixRegisterPrivateKey(&DRIPixmapBufferPrivKeyRec, PRIVATE_PIXMAP, 0)) - return FALSE; + return FALSE; pDRIPriv = (DRIScreenPrivPtr) calloc(1, sizeof(DRIScreenPrivRec)); if (!pDRIPriv) { - dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL); + dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL); return FALSE; } @@ -137,7 +141,7 @@ DRIScreenInit(ScreenPtr pScreen) Bool DRIFinishScreenInit(ScreenPtr pScreen) { - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); /* Wrap DRI support */ pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree; @@ -167,7 +171,7 @@ DRICloseScreen(ScreenPtr pScreen) if (pDRIPriv && pDRIPriv->directRenderingSupport) { free(pDRIPriv); - dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL); + dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL); } } @@ -175,7 +179,7 @@ Bool DRIExtensionInit(void) { DRIDrawablePrivResType = CreateNewResourceType(DRIDrawablePrivDelete, - "DRIDrawable"); + "DRIDrawable"); return DRIDrawablePrivResType != 0; } @@ -193,7 +197,7 @@ DRIReset(void) } Bool -DRIQueryDirectRenderingCapable(ScreenPtr pScreen, Bool* isCapable) +DRIQueryDirectRenderingCapable(ScreenPtr pScreen, Bool *isCapable) { DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); @@ -213,7 +217,8 @@ DRIAuthConnection(ScreenPtr pScreen, unsigned int magic) DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - if (drmAuthMagic(pDRIPriv->drmFD, magic)) return FALSE; + if (drmAuthMagic(pDRIPriv->drmFD, magic)) + return FALSE; #endif return TRUE; } @@ -246,12 +251,13 @@ DRIUpdateSurface(DRIDrawablePrivPtr pDRIDrawablePriv, DrawablePtr pDraw) wc.shape_nrects = RegionNumRects(&pWin->clipList); wc.shape_rects = RegionRects(&pWin->clipList); - wc.shape_tx = - (pTopWin->drawable.x - pTopWin->borderWidth); - wc.shape_ty = - (pTopWin->drawable.y - pTopWin->borderWidth); + wc.shape_tx = -(pTopWin->drawable.x - pTopWin->borderWidth); + wc.shape_ty = -(pTopWin->drawable.y - pTopWin->borderWidth); flags |= XP_BOUNDS | XP_SHAPE; - } else if (pDraw->type == DRAWABLE_PIXMAP) { + } + else if (pDraw->type == DRAWABLE_PIXMAP) { wc.x = 0; wc.y = 0; wc.width = pDraw->width; @@ -265,7 +271,8 @@ DRIUpdateSurface(DRIDrawablePrivPtr pDRIDrawablePriv, DrawablePtr pDraw) /* Return NULL if an error occurs. */ static DRIDrawablePrivPtr -CreateSurfaceForWindow(ScreenPtr pScreen, WindowPtr pWin, xp_window_id *widPtr) { +CreateSurfaceForWindow(ScreenPtr pScreen, WindowPtr pWin, xp_window_id * widPtr) +{ DRIDrawablePrivPtr pDRIDrawablePriv; xp_window_id wid = 0; @@ -274,50 +281,49 @@ CreateSurfaceForWindow(ScreenPtr pScreen, WindowPtr pWin, xp_window_id *widPtr) pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); if (pDRIDrawablePriv == NULL) { - xp_error err; - xp_window_changes wc; - - /* allocate a DRI Window Private record */ - if (!(pDRIDrawablePriv = malloc(sizeof(*pDRIDrawablePriv)))) { - return NULL; - } - - pDRIDrawablePriv->pDraw = (DrawablePtr)pWin; - pDRIDrawablePriv->pScreen = pScreen; - pDRIDrawablePriv->refCount = 0; - pDRIDrawablePriv->drawableIndex = -1; - pDRIDrawablePriv->notifiers = NULL; - - /* find the physical window */ - wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWin, TRUE)); - - if (wid == 0) { - free(pDRIDrawablePriv); - return NULL; - } - - /* allocate the physical surface */ - err = xp_create_surface(wid, &pDRIDrawablePriv->sid); - - if (err != Success) { - free(pDRIDrawablePriv); - return NULL; - } - - /* Make it visible */ - wc.stack_mode = XP_MAPPED_ABOVE; - wc.sibling = 0; - err = xp_configure_surface(pDRIDrawablePriv->sid, XP_STACKING, &wc); - - if (err != Success) { - xp_destroy_surface(pDRIDrawablePriv->sid); - free(pDRIDrawablePriv); - return NULL; - } - - /* save private off of preallocated index */ - dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, - pDRIDrawablePriv); + xp_error err; + xp_window_changes wc; + + /* allocate a DRI Window Private record */ + if (!(pDRIDrawablePriv = malloc(sizeof(*pDRIDrawablePriv)))) { + return NULL; + } + + pDRIDrawablePriv->pDraw = (DrawablePtr) pWin; + pDRIDrawablePriv->pScreen = pScreen; + pDRIDrawablePriv->refCount = 0; + pDRIDrawablePriv->drawableIndex = -1; + pDRIDrawablePriv->notifiers = NULL; + + /* find the physical window */ + wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWin, TRUE)); + + if (wid == 0) { + free(pDRIDrawablePriv); + return NULL; + } + + /* allocate the physical surface */ + err = xp_create_surface(wid, &pDRIDrawablePriv->sid); + + if (err != Success) { + free(pDRIDrawablePriv); + return NULL; + } + + /* Make it visible */ + wc.stack_mode = XP_MAPPED_ABOVE; + wc.sibling = 0; + err = xp_configure_surface(pDRIDrawablePriv->sid, XP_STACKING, &wc); + + if (err != Success) { + xp_destroy_surface(pDRIDrawablePriv->sid); + free(pDRIDrawablePriv); + return NULL; + } + + /* save private off of preallocated index */ + dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, pDRIDrawablePriv); } *widPtr = wid; @@ -327,111 +333,109 @@ CreateSurfaceForWindow(ScreenPtr pScreen, WindowPtr pWin, xp_window_id *widPtr) /* Return NULL if an error occurs. */ static DRIDrawablePrivPtr -CreateSurfaceForPixmap(ScreenPtr pScreen, PixmapPtr pPix) { +CreateSurfaceForPixmap(ScreenPtr pScreen, PixmapPtr pPix) +{ DRIDrawablePrivPtr pDRIDrawablePriv; - + pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix); if (pDRIDrawablePriv == NULL) { - xp_error err; - - /* allocate a DRI Window Private record */ - if (!(pDRIDrawablePriv = calloc(1, sizeof(*pDRIDrawablePriv)))) { - return NULL; - } - - pDRIDrawablePriv->pDraw = (DrawablePtr)pPix; - pDRIDrawablePriv->pScreen = pScreen; - pDRIDrawablePriv->refCount = 0; - pDRIDrawablePriv->drawableIndex = -1; - pDRIDrawablePriv->notifiers = NULL; - - /* Passing a null window id to Xplugin in 10.3+ asks for - an accelerated offscreen surface. */ - - err = xp_create_surface(0, &pDRIDrawablePriv->sid); - if (err != Success) { - free(pDRIDrawablePriv); - return NULL; - } - - /* - * The DRIUpdateSurface will be called to resize the surface - * after this function, if the export is successful. - */ - - /* save private off of preallocated index */ - dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey, - pDRIDrawablePriv); - } - + xp_error err; + + /* allocate a DRI Window Private record */ + if (!(pDRIDrawablePriv = calloc(1, sizeof(*pDRIDrawablePriv)))) { + return NULL; + } + + pDRIDrawablePriv->pDraw = (DrawablePtr) pPix; + pDRIDrawablePriv->pScreen = pScreen; + pDRIDrawablePriv->refCount = 0; + pDRIDrawablePriv->drawableIndex = -1; + pDRIDrawablePriv->notifiers = NULL; + + /* Passing a null window id to Xplugin in 10.3+ asks for + an accelerated offscreen surface. */ + + err = xp_create_surface(0, &pDRIDrawablePriv->sid); + if (err != Success) { + free(pDRIDrawablePriv); + return NULL; + } + + /* + * The DRIUpdateSurface will be called to resize the surface + * after this function, if the export is successful. + */ + + /* save private off of preallocated index */ + dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey, pDRIDrawablePriv); + } + return pDRIDrawablePriv; } - Bool DRICreateSurface(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable, xp_client_id client_id, - xp_surface_id *surface_id, unsigned int ret_key[2], + xp_surface_id * surface_id, unsigned int ret_key[2], void (*notify) (void *arg, void *data), void *notify_data) { - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - xp_window_id wid = 0; - DRIDrawablePrivPtr pDRIDrawablePriv; + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + xp_window_id wid = 0; + DRIDrawablePrivPtr pDRIDrawablePriv; if (pDrawable->type == DRAWABLE_WINDOW) { - pDRIDrawablePriv = CreateSurfaceForWindow(pScreen, - (WindowPtr)pDrawable, &wid); + pDRIDrawablePriv = CreateSurfaceForWindow(pScreen, + (WindowPtr) pDrawable, &wid); - if(NULL == pDRIDrawablePriv) - return FALSE; /*error*/ + if (NULL == pDRIDrawablePriv) + return FALSE; /*error */ } #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 else if (pDrawable->type == DRAWABLE_PIXMAP) { - pDRIDrawablePriv = CreateSurfaceForPixmap(pScreen, - (PixmapPtr)pDrawable); + pDRIDrawablePriv = CreateSurfaceForPixmap(pScreen, + (PixmapPtr) pDrawable); - if(NULL == pDRIDrawablePriv) - return FALSE; /*error*/ + if (NULL == pDRIDrawablePriv) + return FALSE; /*error */ } #endif else { - /* We handle GLXPbuffers in a different way (via CGL). */ + /* We handle GLXPbuffers in a different way (via CGL). */ return FALSE; } - - + /* Finish initialization of new surfaces */ if (pDRIDrawablePriv->refCount == 0) { - unsigned int key[2] = {0}; + unsigned int key[2] = { 0 }; xp_error err; /* try to give the client access to the surface */ if (client_id != 0) { - /* - * Xplugin accepts a 0 wid if the surface id is offscreen, such - * as for a pixmap. - */ - err = xp_export_surface(wid, pDRIDrawablePriv->sid, - client_id, key); + /* + * Xplugin accepts a 0 wid if the surface id is offscreen, such + * as for a pixmap. + */ + err = xp_export_surface(wid, pDRIDrawablePriv->sid, client_id, key); if (err != Success) { xp_destroy_surface(pDRIDrawablePriv->sid); free(pDRIDrawablePriv); - - /* - * Now set the dix privates to NULL that were previously set. - * This prevents reusing an invalid pointer. - */ - if(pDrawable->type == DRAWABLE_WINDOW) { - WindowPtr pWin = (WindowPtr)pDrawable; - - dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL); - } else if(pDrawable->type == DRAWABLE_PIXMAP) { - PixmapPtr pPix = (PixmapPtr)pDrawable; - - dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey, NULL); - } - + + /* + * Now set the dix privates to NULL that were previously set. + * This prevents reusing an invalid pointer. + */ + if (pDrawable->type == DRAWABLE_WINDOW) { + WindowPtr pWin = (WindowPtr) pDrawable; + + dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL); + } + else if (pDrawable->type == DRAWABLE_PIXMAP) { + PixmapPtr pPix = (PixmapPtr) pDrawable; + + dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey, NULL); + } + return FALSE; } } @@ -445,10 +449,11 @@ DRICreateSurface(ScreenPtr pScreen, Drawable id, if (surface_hash == NULL) surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL); x_hash_table_insert(surface_hash, - x_cvt_uint_to_vptr(pDRIDrawablePriv->sid), pDRIDrawablePriv); + x_cvt_uint_to_vptr(pDRIDrawablePriv->sid), + pDRIDrawablePriv); /* track this in case this window is destroyed */ - AddResource(id, DRIDrawablePrivResType, (pointer)pDrawable); + AddResource(id, DRIDrawablePrivResType, (pointer) pDrawable); /* Initialize shape */ DRIUpdateSurface(pDRIDrawablePriv, pDrawable); @@ -475,38 +480,40 @@ Bool DRIDestroySurface(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable, void (*notify) (void *, void *), void *notify_data) { - DRIDrawablePrivPtr pDRIDrawablePriv; + DRIDrawablePrivPtr pDRIDrawablePriv; if (pDrawable->type == DRAWABLE_WINDOW) { - pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW((WindowPtr)pDrawable); - } else if (pDrawable->type == DRAWABLE_PIXMAP) { - pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP((PixmapPtr)pDrawable); - } else { + pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW((WindowPtr) pDrawable); + } + else if (pDrawable->type == DRAWABLE_PIXMAP) { + pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP((PixmapPtr) pDrawable); + } + else { return FALSE; } if (pDRIDrawablePriv != NULL) { - /* - * This doesn't seem to be used, because notify is NULL in all callers. - */ + /* + * This doesn't seem to be used, because notify is NULL in all callers. + */ if (notify != NULL) { - pDRIDrawablePriv->notifiers = x_hook_remove(pDRIDrawablePriv->notifiers, - notify, notify_data); + pDRIDrawablePriv->notifiers = + x_hook_remove(pDRIDrawablePriv->notifiers, notify, notify_data); } - --pDRIDrawablePriv->refCount; + --pDRIDrawablePriv->refCount; - /* - * Check if the drawable privates still have a reference to the - * surface. - */ + /* + * Check if the drawable privates still have a reference to the + * surface. + */ if (pDRIDrawablePriv->refCount <= 0) { /* - * This calls back to DRIDrawablePrivDelete which - * frees the private area and dispatches events, if needed. - */ + * This calls back to DRIDrawablePrivDelete which + * frees the private area and dispatches events, if needed. + */ FreeResourceByType(id, DRIDrawablePrivResType, FALSE); } } @@ -521,38 +528,38 @@ DRIDestroySurface(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable, Bool DRIDrawablePrivDelete(pointer pResource, XID id) { - DrawablePtr pDrawable = (DrawablePtr)pResource; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pDrawable->pScreen); - DRIDrawablePrivPtr pDRIDrawablePriv = NULL; - WindowPtr pWin = NULL; - PixmapPtr pPix = NULL; + DrawablePtr pDrawable = (DrawablePtr) pResource; + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pDrawable->pScreen); + DRIDrawablePrivPtr pDRIDrawablePriv = NULL; + WindowPtr pWin = NULL; + PixmapPtr pPix = NULL; if (pDrawable->type == DRAWABLE_WINDOW) { - pWin = (WindowPtr)pDrawable; + pWin = (WindowPtr) pDrawable; pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); - } else if (pDrawable->type == DRAWABLE_PIXMAP) { - pPix = (PixmapPtr)pDrawable; + } + else if (pDrawable->type == DRAWABLE_PIXMAP) { + pPix = (PixmapPtr) pDrawable; pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix); } if (pDRIDrawablePriv == NULL) { - /* - * We reuse __func__ and the resource type for the GLXPixmap code. - * Attempt to free a pixmap buffer associated with the resource - * if possible. - */ - return DRIFreePixmapImp(pDrawable); - } - + /* + * We reuse __func__ and the resource type for the GLXPixmap code. + * Attempt to free a pixmap buffer associated with the resource + * if possible. + */ + return DRIFreePixmapImp(pDrawable); + } + if (pDRIDrawablePriv->drawableIndex != -1) { /* release drawable table entry */ pDRIPriv->DRIDrawables[pDRIDrawablePriv->drawableIndex] = NULL; } if (pDRIDrawablePriv->sid != 0) { - DRISurfaceNotify(pDRIDrawablePriv->sid, AppleDRISurfaceNotifyDestroyed); + DRISurfaceNotify(pDRIDrawablePriv->sid, AppleDRISurfaceNotifyDestroyed); } - if (pDRIDrawablePriv->notifiers != NULL) x_hook_free(pDRIDrawablePriv->notifiers); @@ -560,9 +567,10 @@ DRIDrawablePrivDelete(pointer pResource, XID id) free(pDRIDrawablePriv); if (pDrawable->type == DRAWABLE_WINDOW) { - dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL); - } else if (pDrawable->type == DRAWABLE_PIXMAP) { - dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey, NULL); + dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL); + } + else if (pDrawable->type == DRAWABLE_PIXMAP) { + dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey, NULL); } --pDRIPriv->nrWindows; @@ -583,7 +591,7 @@ DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg) pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures; - (*pScreen->WindowExposures)(pWin, prgn, bsreg); + (*pScreen->WindowExposures) (pWin, prgn, bsreg); pScreen->WindowExposures = DRIWindowExposures; } @@ -596,17 +604,17 @@ DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) DRIDrawablePrivPtr pDRIDrawablePriv; if (pDRIPriv->nrWindows > 0) { - pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); - if (pDRIDrawablePriv != NULL) { + pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); + if (pDRIDrawablePriv != NULL) { DRIUpdateSurface(pDRIDrawablePriv, &pWin->drawable); - } + } } /* unwrap */ pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow; /* call lower layers */ - (*pScreen->CopyWindow)(pWin, ptOldOrg, prgnSrc); + (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc); /* rewrap */ pScreen->CopyWindow = DRICopyWindow; @@ -623,7 +631,7 @@ DRIValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind) pScreen->ValidateTree = pDRIPriv->wrap.ValidateTree; /* call lower layers */ - returnValue = (*pScreen->ValidateTree)(pParent, pChild, kind); + returnValue = (*pScreen->ValidateTree) (pParent, pChild, kind); /* rewrap */ pScreen->ValidateTree = DRIValidateTree; @@ -639,7 +647,8 @@ DRIPostValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind) if (pParent) { pScreen = pParent->drawable.pScreen; - } else { + } + else { pScreen = pChild->drawable.pScreen; } pDRIPriv = DRI_SCREEN_PRIV(pScreen); @@ -649,7 +658,7 @@ DRIPostValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind) pScreen->PostValidateTree = pDRIPriv->wrap.PostValidateTree; /* call lower layers */ - (*pScreen->PostValidateTree)(pParent, pChild, kind); + (*pScreen->PostValidateTree) (pParent, pChild, kind); /* rewrap */ pScreen->PostValidateTree = DRIPostValidateTree; @@ -661,7 +670,7 @@ DRIClipNotify(WindowPtr pWin, int dx, int dy) { ScreenPtr pScreen = pWin->drawable.pScreen; DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIDrawablePrivPtr pDRIDrawablePriv; + DRIDrawablePrivPtr pDRIDrawablePriv; if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) { DRIUpdateSurface(pDRIDrawablePriv, &pWin->drawable); @@ -670,7 +679,7 @@ DRIClipNotify(WindowPtr pWin, int dx, int dy) if (pDRIPriv->wrap.ClipNotify) { pScreen->ClipNotify = pDRIPriv->wrap.ClipNotify; - (*pScreen->ClipNotify)(pWin, dx, dy); + (*pScreen->ClipNotify) (pWin, dx, dy); pScreen->ClipNotify = DRIClipNotify; } @@ -687,9 +696,7 @@ DRIGetWrappedFuncs(ScreenPtr pScreen) } void -DRIQueryVersion(int *majorVersion, - int *minorVersion, - int *patchVersion) +DRIQueryVersion(int *majorVersion, int *minorVersion, int *patchVersion) { *majorVersion = APPLE_DRI_MAJOR_VERSION; *minorVersion = APPLE_DRI_MINOR_VERSION; @@ -700,7 +707,7 @@ DRIQueryVersion(int *majorVersion, * Note: this also cleans up the hash table in addition to notifying clients. * The sid/surface-id should not be used after this, because it will be * invalid. - */ + */ void DRISurfaceNotify(xp_surface_id id, int kind) { @@ -710,8 +717,7 @@ DRISurfaceNotify(xp_surface_id id, int kind) arg.id = id; arg.kind = kind; - if (surface_hash != NULL) - { + if (surface_hash != NULL) { pDRIDrawablePriv = x_hash_table_lookup(surface_hash, x_cvt_uint_to_vptr(id), NULL); } @@ -719,24 +725,22 @@ DRISurfaceNotify(xp_surface_id id, int kind) if (pDRIDrawablePriv == NULL) return; - if (kind == AppleDRISurfaceNotifyDestroyed) - { - x_hash_table_remove(surface_hash, x_cvt_uint_to_vptr(id)); + if (kind == AppleDRISurfaceNotifyDestroyed) { + x_hash_table_remove(surface_hash, x_cvt_uint_to_vptr(id)); } x_hook_run(pDRIDrawablePriv->notifiers, &arg); - if (kind == AppleDRISurfaceNotifyDestroyed) - { - xp_error error; - - error = xp_destroy_surface(pDRIDrawablePriv->sid); - - if(error) - ErrorF("%s: xp_destroy_surface failed: %d\n", __func__, error); - - /* Guard against reuse, even though we are freeing after this. */ - pDRIDrawablePriv->sid = 0; + if (kind == AppleDRISurfaceNotifyDestroyed) { + xp_error error; + + error = xp_destroy_surface(pDRIDrawablePriv->sid); + + if (error) + ErrorF("%s: xp_destroy_surface failed: %d\n", __func__, error); + + /* Guard against reuse, even though we are freeing after this. */ + pDRIDrawablePriv->sid = 0; FreeResourceByType(pDRIDrawablePriv->pDraw->id, DRIDrawablePrivResType, FALSE); @@ -747,137 +751,140 @@ DRISurfaceNotify(xp_surface_id id, int kind) * This creates a shared memory buffer for use with GLXPixmaps * and AppleSGLX. */ -Bool DRICreatePixmap(ScreenPtr pScreen, Drawable id, - DrawablePtr pDrawable, char *path, - size_t pathmax) +Bool +DRICreatePixmap(ScreenPtr pScreen, Drawable id, + DrawablePtr pDrawable, char *path, size_t pathmax) { DRIPixmapBufferPtr shared; PixmapPtr pPix; - - if(pDrawable->type != DRAWABLE_PIXMAP) - return FALSE; - pPix = (PixmapPtr)pDrawable; + if (pDrawable->type != DRAWABLE_PIXMAP) + return FALSE; + + pPix = (PixmapPtr) pDrawable; shared = malloc(sizeof(*shared)); - if(NULL == shared) { + if (NULL == shared) { FatalError("failed to allocate DRIPixmapBuffer in %s\n", __func__); } - + shared->pDrawable = pDrawable; shared->refCount = 1; - if(pDrawable->bitsPerPixel >= 24) { - shared->bytesPerPixel = 4; - } else if(pDrawable->bitsPerPixel <= 16) { - shared->bytesPerPixel = 2; + if (pDrawable->bitsPerPixel >= 24) { + shared->bytesPerPixel = 4; } - + else if (pDrawable->bitsPerPixel <= 16) { + shared->bytesPerPixel = 2; + } + shared->width = pDrawable->width; shared->height = pDrawable->height; - - if(-1 == snprintf(shared->shmPath, sizeof(shared->shmPath), - "%d_0x%lx", getpid(), - (unsigned long)id)) { + + if (-1 == snprintf(shared->shmPath, sizeof(shared->shmPath), + "%d_0x%lx", getpid(), (unsigned long) id)) { FatalError("buffer overflow in %s\n", __func__); } - - shared->fd = shm_open(shared->shmPath, - O_RDWR | O_EXCL | O_CREAT, + + shared->fd = shm_open(shared->shmPath, + O_RDWR | O_EXCL | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH); - - if(-1 == shared->fd) { - free(shared); + + if (-1 == shared->fd) { + free(shared); return FALSE; - } - + } + shared->length = shared->width * shared->height * shared->bytesPerPixel; - - if(-1 == ftruncate(shared->fd, shared->length)) { - ErrorF("failed to ftruncate (extend) file."); - shm_unlink(shared->shmPath); - close(shared->fd); - free(shared); - return FALSE; + + if (-1 == ftruncate(shared->fd, shared->length)) { + ErrorF("failed to ftruncate (extend) file."); + shm_unlink(shared->shmPath); + close(shared->fd); + free(shared); + return FALSE; } shared->buffer = mmap(NULL, shared->length, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, shared->fd, 0); - - if(MAP_FAILED == shared->buffer) { - ErrorF("failed to mmap shared memory."); - shm_unlink(shared->shmPath); - close(shared->fd); - free(shared); - return FALSE; - } - + + if (MAP_FAILED == shared->buffer) { + ErrorF("failed to mmap shared memory."); + shm_unlink(shared->shmPath); + close(shared->fd); + free(shared); + return FALSE; + } + strlcpy(path, shared->shmPath, pathmax); - + dixSetPrivate(&pPix->devPrivates, DRIPixmapBufferPrivKey, shared); - AddResource(id, DRIDrawablePrivResType, (pointer)pDrawable); + AddResource(id, DRIDrawablePrivResType, (pointer) pDrawable); return TRUE; } - -Bool DRIGetPixmapData(DrawablePtr pDrawable, int *width, int *height, - int *pitch, int *bpp, void **ptr) { +Bool +DRIGetPixmapData(DrawablePtr pDrawable, int *width, int *height, + int *pitch, int *bpp, void **ptr) +{ PixmapPtr pPix; DRIPixmapBufferPtr shared; - if(pDrawable->type != DRAWABLE_PIXMAP) - return FALSE; + if (pDrawable->type != DRAWABLE_PIXMAP) + return FALSE; - pPix = (PixmapPtr)pDrawable; + pPix = (PixmapPtr) pDrawable; shared = dixLookupPrivate(&pPix->devPrivates, DRIPixmapBufferPrivKey); - if(NULL == shared) - return FALSE; + if (NULL == shared) + return FALSE; assert(pDrawable->width == shared->width); assert(pDrawable->height == shared->height); - + *width = shared->width; *height = shared->height; *bpp = shared->bytesPerPixel; *pitch = shared->width * shared->bytesPerPixel; - *ptr = shared->buffer; + *ptr = shared->buffer; return TRUE; } static Bool -DRIFreePixmapImp(DrawablePtr pDrawable) { +DRIFreePixmapImp(DrawablePtr pDrawable) +{ DRIPixmapBufferPtr shared; PixmapPtr pPix; - if(pDrawable->type != DRAWABLE_PIXMAP) - return FALSE; + if (pDrawable->type != DRAWABLE_PIXMAP) + return FALSE; - pPix = (PixmapPtr)pDrawable; + pPix = (PixmapPtr) pDrawable; shared = dixLookupPrivate(&pPix->devPrivates, DRIPixmapBufferPrivKey); - if(NULL == shared) - return FALSE; + if (NULL == shared) + return FALSE; close(shared->fd); munmap(shared->buffer, shared->length); shm_unlink(shared->shmPath); free(shared); - dixSetPrivate(&pPix->devPrivates, DRIPixmapBufferPrivKey, (pointer)NULL); + dixSetPrivate(&pPix->devPrivates, DRIPixmapBufferPrivKey, (pointer) NULL); return TRUE; } -void -DRIDestroyPixmap(DrawablePtr pDrawable) { - if(DRIFreePixmapImp(pDrawable)) - FreeResourceByType(pDrawable->id, DRIDrawablePrivResType, FALSE); +void +DRIDestroyPixmap(DrawablePtr pDrawable) +{ + if (DRIFreePixmapImp(pDrawable)) + FreeResourceByType(pDrawable->id, DRIDrawablePrivResType, FALSE); } diff --git a/xorg-server/hw/xquartz/xpr/dri.h b/xorg-server/hw/xquartz/xpr/dri.h index 48fea3668..b4342617c 100644 --- a/xorg-server/hw/xquartz/xpr/dri.h +++ b/xorg-server/hw/xquartz/xpr/dri.h @@ -43,8 +43,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "appledri.h" #include <Xplugin.h> -typedef void (*ClipNotifyPtr)( WindowPtr, int, int ); - +typedef void (*ClipNotifyPtr) (WindowPtr, int, int); /* * These functions can be wrapped by the DRI. Each of these have @@ -52,11 +51,11 @@ typedef void (*ClipNotifyPtr)( WindowPtr, int, int ); * overridden by the driver in its [driver]DRIScreenInit function. */ typedef struct { - WindowExposuresProcPtr WindowExposures; - CopyWindowProcPtr CopyWindow; - ValidateTreeProcPtr ValidateTree; - PostValidateTreeProcPtr PostValidateTree; - ClipNotifyProcPtr ClipNotify; + WindowExposuresProcPtr WindowExposures; + CopyWindowProcPtr CopyWindow; + ValidateTreeProcPtr ValidateTree; + PostValidateTreeProcPtr PostValidateTree; + ClipNotifyProcPtr ClipNotify; } DRIWrappedFuncsRec, *DRIWrappedFuncsPtr; typedef struct { @@ -74,8 +73,7 @@ extern Bool DRIExtensionInit(void); extern void DRIReset(void); -extern Bool DRIQueryDirectRenderingCapable(ScreenPtr pScreen, - Bool *isCapable); +extern Bool DRIQueryDirectRenderingCapable(ScreenPtr pScreen, Bool *isCapable); extern Bool DRIAuthConnection(ScreenPtr pScreen, unsigned int magic); @@ -83,55 +81,43 @@ extern Bool DRICreateSurface(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable, xp_client_id client_id, - xp_surface_id *surface_id, + xp_surface_id * surface_id, unsigned int key[2], void (*notify) (void *arg, void *data), void *notify_data); extern Bool DRIDestroySurface(ScreenPtr pScreen, - Drawable id, - DrawablePtr pDrawable, - void (*notify) (void *arg, void *data), - void *notify_data); + Drawable id, + DrawablePtr pDrawable, + void (*notify) (void *arg, void *data), + void *notify_data); -extern Bool DRIDrawablePrivDelete(pointer pResource, - XID id); +extern Bool DRIDrawablePrivDelete(pointer pResource, XID id); extern DRIWrappedFuncsRec *DRIGetWrappedFuncs(ScreenPtr pScreen); extern void DRICopyWindow(WindowPtr pWin, - DDXPointRec ptOldOrg, - RegionPtr prgnSrc); + DDXPointRec ptOldOrg, RegionPtr prgnSrc); -extern int DRIValidateTree(WindowPtr pParent, - WindowPtr pChild, - VTKind kind); +extern int DRIValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind); extern void DRIPostValidateTree(WindowPtr pParent, - WindowPtr pChild, - VTKind kind); + WindowPtr pChild, VTKind kind); -extern void DRIClipNotify(WindowPtr pWin, - int dx, - int dy); +extern void DRIClipNotify(WindowPtr pWin, int dx, int dy); -extern void DRIWindowExposures(WindowPtr pWin, - RegionPtr prgn, - RegionPtr bsreg); +extern void DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg); -extern void DRISurfaceNotify (xp_surface_id id, int kind); +extern void DRISurfaceNotify(xp_surface_id id, int kind); extern void DRIQueryVersion(int *majorVersion, - int *minorVersion, - int *patchVersion); + int *minorVersion, int *patchVersion); extern Bool DRICreatePixmap(ScreenPtr pScreen, Drawable id, - DrawablePtr pDrawable, char *path, - size_t pathmax); + DrawablePtr pDrawable, char *path, size_t pathmax); extern Bool DRIGetPixmapData(DrawablePtr pDrawable, int *width, int *height, - int *pitch, int *bpp, void **ptr); - + int *pitch, int *bpp, void **ptr); extern void DRIDestroyPixmap(DrawablePtr pDrawable); diff --git a/xorg-server/hw/xquartz/xpr/driWrap.c b/xorg-server/hw/xquartz/xpr/driWrap.c index c38761555..eca31b263 100644 --- a/xorg-server/hw/xquartz/xpr/driWrap.c +++ b/xorg-server/hw/xquartz/xpr/driWrap.c @@ -1,537 +1,552 @@ -/*
-Copyright (c) 2009 Apple Computer, Inc.
-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, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <stddef.h>
-#include "mi.h"
-#include "scrnintstr.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-#include "windowstr.h"
-#include "dixfontstr.h"
-#include "mivalidate.h"
-#include "driWrap.h"
-#include "dri.h"
-
-#include <OpenGL/OpenGL.h>
-
-typedef struct {
- GCOps *originalOps;
-} DRIGCRec;
-
-typedef struct {
- GCOps *originalOps;
- CreateGCProcPtr CreateGC;
-} DRIWrapScreenRec;
-
-typedef struct {
- Bool didSave;
- int devKind;
- DevUnion devPrivate;
-} DRISavedDrawableState;
-
-static DevPrivateKeyRec driGCKeyRec;
-#define driGCKey (&driGCKeyRec)
-
-static DevPrivateKeyRec driWrapScreenKeyRec;
-#define driWrapScreenKey (&driWrapScreenKeyRec)
-
-static GCOps driGCOps;
-
-#define wrap(priv, real, member, func) { \
- priv->member = real->member; \
- real->member = func; \
- }
-
-#define unwrap(priv, real, member) { \
- real->member = priv->member; \
- }
-
-static DRIGCRec *
-DRIGetGCPriv(GCPtr pGC) {
- return dixLookupPrivate(&pGC->devPrivates, driGCKey);
-}
-
-static void
-DRIUnwrapGC(GCPtr pGC) {
- DRIGCRec *pGCPriv = DRIGetGCPriv(pGC);
-
- pGC->ops = pGCPriv->originalOps;
-}
-
-static void
-DRIWrapGC(GCPtr pGC) {
- pGC->ops = &driGCOps;
-}
-
-static void
-DRISurfaceSetDrawable(DrawablePtr pDraw,
- DRISavedDrawableState *saved) {
- saved->didSave = FALSE;
-
- if(pDraw->type == DRAWABLE_PIXMAP) {
- int pitch, width, height, bpp;
- void *buffer;
-
- if(DRIGetPixmapData(pDraw, &width, &height, &pitch, &bpp, &buffer)) {
- PixmapPtr pPix = (PixmapPtr)pDraw;
-
- saved->devKind = pPix->devKind;
- saved->devPrivate.ptr = pPix->devPrivate.ptr;
- saved->didSave = TRUE;
-
- pPix->devKind = pitch;
- pPix->devPrivate.ptr = buffer;
- }
- }
-}
-
-static void
-DRISurfaceRestoreDrawable(DrawablePtr pDraw,
- DRISavedDrawableState *saved) {
- PixmapPtr pPix = (PixmapPtr)pDraw;
-
- if(!saved->didSave)
- return;
-
- pPix->devKind = saved->devKind;
- pPix->devPrivate.ptr = saved->devPrivate.ptr;
-}
-
-static void
-DRIFillSpans(DrawablePtr dst, GCPtr pGC, int nInit,
- DDXPointPtr pptInit, int *pwidthInit,
- int sorted) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->FillSpans(dst, pGC, nInit, pptInit, pwidthInit, sorted);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRISetSpans(DrawablePtr dst, GCPtr pGC, char *pSrc,
- DDXPointPtr pptInit, int *pwidthInit,
- int nspans, int sorted) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->SetSpans(dst, pGC, pSrc, pptInit, pwidthInit, nspans, sorted);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIPutImage(DrawablePtr dst, GCPtr pGC,
- int depth, int x, int y, int w, int h,
- int leftPad, int format, char *pBits) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->PutImage(dst, pGC, depth, x, y, w, h, leftPad, format, pBits);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static RegionPtr
-DRICopyArea(DrawablePtr pSrc, DrawablePtr dst, GCPtr pGC,
- int srcx, int srcy, int w, int h,
- int dstx, int dsty) {
- RegionPtr pReg;
- DRISavedDrawableState pSrcSaved, dstSaved;
-
- DRISurfaceSetDrawable(pSrc, &pSrcSaved);
- DRISurfaceSetDrawable(dst, &dstSaved);
-
- DRIUnwrapGC(pGC);
-
- pReg = pGC->ops->CopyArea(pSrc, dst, pGC, srcx, srcy, w, h, dstx, dsty);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(pSrc, &pSrcSaved);
- DRISurfaceRestoreDrawable(dst, &dstSaved);
-
- return pReg;
-}
-
-static RegionPtr
-DRICopyPlane(DrawablePtr pSrc, DrawablePtr dst,
- GCPtr pGC, int srcx, int srcy,
- int w, int h, int dstx, int dsty,
- unsigned long plane) {
- RegionPtr pReg;
- DRISavedDrawableState pSrcSaved, dstSaved;
-
- DRISurfaceSetDrawable(pSrc, &pSrcSaved);
- DRISurfaceSetDrawable(dst, &dstSaved);
-
-
- DRIUnwrapGC(pGC);
-
- pReg = pGC->ops->CopyPlane(pSrc, dst, pGC, srcx, srcy, w, h, dstx, dsty,
- plane);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(pSrc, &pSrcSaved);
- DRISurfaceRestoreDrawable(dst, &dstSaved);
-
- return pReg;
-}
-
-static void
-DRIPolyPoint(DrawablePtr dst, GCPtr pGC,
- int mode, int npt, DDXPointPtr pptInit) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->PolyPoint(dst, pGC, mode, npt, pptInit);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIPolylines(DrawablePtr dst, GCPtr pGC,
- int mode, int npt, DDXPointPtr pptInit) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->Polylines(dst, pGC, mode, npt, pptInit);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIPolySegment(DrawablePtr dst, GCPtr pGC,
- int nseg, xSegment *pSeg) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->PolySegment(dst, pGC, nseg, pSeg);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIPolyRectangle(DrawablePtr dst, GCPtr pGC,
- int nRects, xRectangle *pRects) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->PolyRectangle(dst, pGC, nRects, pRects);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-static void
-DRIPolyArc(DrawablePtr dst, GCPtr pGC, int narcs, xArc *parcs) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->PolyArc(dst, pGC, narcs, parcs);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIFillPolygon(DrawablePtr dst, GCPtr pGC,
- int shape, int mode, int count,
- DDXPointPtr pptInit) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->FillPolygon(dst, pGC, shape, mode, count, pptInit);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIPolyFillRect(DrawablePtr dst, GCPtr pGC,
- int nRectsInit, xRectangle *pRectsInit) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->PolyFillRect(dst, pGC, nRectsInit, pRectsInit);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIPolyFillArc(DrawablePtr dst, GCPtr pGC,
- int narcsInit, xArc *parcsInit) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->PolyFillArc(dst, pGC, narcsInit, parcsInit);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static int
-DRIPolyText8(DrawablePtr dst, GCPtr pGC,
- int x, int y, int count, char *chars) {
- int ret;
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- ret = pGC->ops->PolyText8(dst, pGC, x, y, count, chars);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-
- return ret;
-}
-
-static int
-DRIPolyText16(DrawablePtr dst, GCPtr pGC,
- int x, int y, int count, unsigned short *chars) {
- int ret;
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- ret = pGC->ops->PolyText16(dst, pGC, x, y, count, chars);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-
- return ret;
-}
-
-static void
-DRIImageText8(DrawablePtr dst, GCPtr pGC,
- int x, int y, int count, char *chars) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->ImageText8(dst, pGC, x, y, count, chars);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIImageText16(DrawablePtr dst, GCPtr pGC,
- int x, int y, int count, unsigned short *chars) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->ImageText16(dst, pGC, x, y, count, chars);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIImageGlyphBlt(DrawablePtr dst, GCPtr pGC,
- int x, int y, unsigned int nglyphInit,
- CharInfoPtr *ppciInit, pointer unused) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->ImageGlyphBlt(dst, pGC, x, y, nglyphInit, ppciInit, unused);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void DRIPolyGlyphBlt(DrawablePtr dst, GCPtr pGC,
- int x, int y, unsigned int nglyph,
- CharInfoPtr *ppci, pointer pglyphBase) {
- DRISavedDrawableState saved;
-
- DRISurfaceSetDrawable(dst, &saved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->PolyGlyphBlt(dst, pGC, x, y, nglyph, ppci, pglyphBase);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(dst, &saved);
-}
-
-static void
-DRIPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr dst,
- int dx, int dy, int xOrg, int yOrg) {
- DRISavedDrawableState bitMapSaved, dstSaved;
-
- DRISurfaceSetDrawable(&pBitMap->drawable, &bitMapSaved);
- DRISurfaceSetDrawable(dst, &dstSaved);
-
- DRIUnwrapGC(pGC);
-
- pGC->ops->PushPixels(pGC, pBitMap, dst, dx, dy, xOrg, yOrg);
-
- DRIWrapGC(pGC);
-
- DRISurfaceRestoreDrawable(&pBitMap->drawable, &bitMapSaved);
- DRISurfaceRestoreDrawable(dst, &dstSaved);
-}
-
-
-static GCOps driGCOps = {
- DRIFillSpans,
- DRISetSpans,
- DRIPutImage,
- DRICopyArea,
- DRICopyPlane,
- DRIPolyPoint,
- DRIPolylines,
- DRIPolySegment,
- DRIPolyRectangle,
- DRIPolyArc,
- DRIFillPolygon,
- DRIPolyFillRect,
- DRIPolyFillArc,
- DRIPolyText8,
- DRIPolyText16,
- DRIImageText8,
- DRIImageText16,
- DRIImageGlyphBlt,
- DRIPolyGlyphBlt,
- DRIPushPixels
-};
-
-
-static Bool
-DRICreateGC(GCPtr pGC) {
- ScreenPtr pScreen = pGC->pScreen;
- DRIWrapScreenRec *pScreenPriv;
- DRIGCRec *pGCPriv;
- Bool ret;
-
- pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, driWrapScreenKey);
-
- pGCPriv = DRIGetGCPriv(pGC);
-
- unwrap(pScreenPriv, pScreen, CreateGC);
- ret = pScreen->CreateGC(pGC);
-
- if(ret) {
- pGCPriv->originalOps = pGC->ops;
- pGC->ops = &driGCOps;
- }
-
- wrap(pScreenPriv, pScreen, CreateGC, DRICreateGC);
-
- return ret;
-}
-
-
-/* Return false if an error occurred. */
-Bool
-DRIWrapInit(ScreenPtr pScreen) {
- DRIWrapScreenRec *pScreenPriv;
-
- if(!dixRegisterPrivateKey(&driGCKeyRec, PRIVATE_GC, sizeof(DRIGCRec)))
- return FALSE;
-
- if(!dixRegisterPrivateKey(&driWrapScreenKeyRec, PRIVATE_SCREEN, sizeof(DRIWrapScreenRec)))
- return FALSE;
-
- pScreenPriv = dixGetPrivateAddr(&pScreen->devPrivates, &driWrapScreenKeyRec);
- pScreenPriv->CreateGC = pScreen->CreateGC;
- pScreen->CreateGC = DRICreateGC;
-
- return TRUE;
-}
+/* +Copyright (c) 2009 Apple Computer, Inc. +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, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <stddef.h> +#include "mi.h" +#include "scrnintstr.h" +#include "gcstruct.h" +#include "pixmapstr.h" +#include "windowstr.h" +#include "dixfontstr.h" +#include "mivalidate.h" +#include "driWrap.h" +#include "dri.h" + +#include <OpenGL/OpenGL.h> + +typedef struct { + GCOps *originalOps; +} DRIGCRec; + +typedef struct { + GCOps *originalOps; + CreateGCProcPtr CreateGC; +} DRIWrapScreenRec; + +typedef struct { + Bool didSave; + int devKind; + DevUnion devPrivate; +} DRISavedDrawableState; + +static DevPrivateKeyRec driGCKeyRec; + +#define driGCKey (&driGCKeyRec) + +static DevPrivateKeyRec driWrapScreenKeyRec; + +#define driWrapScreenKey (&driWrapScreenKeyRec) + +static GCOps driGCOps; + +#define wrap(priv, real, member, func) { \ + priv->member = real->member; \ + real->member = func; \ + } + +#define unwrap(priv, real, member) { \ + real->member = priv->member; \ + } + +static DRIGCRec * +DRIGetGCPriv(GCPtr pGC) +{ + return dixLookupPrivate(&pGC->devPrivates, driGCKey); +} + +static void +DRIUnwrapGC(GCPtr pGC) +{ + DRIGCRec *pGCPriv = DRIGetGCPriv(pGC); + + pGC->ops = pGCPriv->originalOps; +} + +static void +DRIWrapGC(GCPtr pGC) +{ + pGC->ops = &driGCOps; +} + +static void +DRISurfaceSetDrawable(DrawablePtr pDraw, DRISavedDrawableState * saved) +{ + saved->didSave = FALSE; + + if (pDraw->type == DRAWABLE_PIXMAP) { + int pitch, width, height, bpp; + void *buffer; + + if (DRIGetPixmapData(pDraw, &width, &height, &pitch, &bpp, &buffer)) { + PixmapPtr pPix = (PixmapPtr) pDraw; + + saved->devKind = pPix->devKind; + saved->devPrivate.ptr = pPix->devPrivate.ptr; + saved->didSave = TRUE; + + pPix->devKind = pitch; + pPix->devPrivate.ptr = buffer; + } + } +} + +static void +DRISurfaceRestoreDrawable(DrawablePtr pDraw, DRISavedDrawableState * saved) +{ + PixmapPtr pPix = (PixmapPtr) pDraw; + + if (!saved->didSave) + return; + + pPix->devKind = saved->devKind; + pPix->devPrivate.ptr = saved->devPrivate.ptr; +} + +static void +DRIFillSpans(DrawablePtr dst, GCPtr pGC, int nInit, + DDXPointPtr pptInit, int *pwidthInit, int sorted) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->FillSpans(dst, pGC, nInit, pptInit, pwidthInit, sorted); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRISetSpans(DrawablePtr dst, GCPtr pGC, char *pSrc, + DDXPointPtr pptInit, int *pwidthInit, int nspans, int sorted) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->SetSpans(dst, pGC, pSrc, pptInit, pwidthInit, nspans, sorted); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIPutImage(DrawablePtr dst, GCPtr pGC, + int depth, int x, int y, int w, int h, + int leftPad, int format, char *pBits) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->PutImage(dst, pGC, depth, x, y, w, h, leftPad, format, pBits); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static RegionPtr +DRICopyArea(DrawablePtr pSrc, DrawablePtr dst, GCPtr pGC, + int srcx, int srcy, int w, int h, int dstx, int dsty) +{ + RegionPtr pReg; + DRISavedDrawableState pSrcSaved, dstSaved; + + DRISurfaceSetDrawable(pSrc, &pSrcSaved); + DRISurfaceSetDrawable(dst, &dstSaved); + + DRIUnwrapGC(pGC); + + pReg = pGC->ops->CopyArea(pSrc, dst, pGC, srcx, srcy, w, h, dstx, dsty); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(pSrc, &pSrcSaved); + DRISurfaceRestoreDrawable(dst, &dstSaved); + + return pReg; +} + +static RegionPtr +DRICopyPlane(DrawablePtr pSrc, DrawablePtr dst, + GCPtr pGC, int srcx, int srcy, + int w, int h, int dstx, int dsty, unsigned long plane) +{ + RegionPtr pReg; + DRISavedDrawableState pSrcSaved, dstSaved; + + DRISurfaceSetDrawable(pSrc, &pSrcSaved); + DRISurfaceSetDrawable(dst, &dstSaved); + + DRIUnwrapGC(pGC); + + pReg = pGC->ops->CopyPlane(pSrc, dst, pGC, srcx, srcy, w, h, dstx, dsty, + plane); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(pSrc, &pSrcSaved); + DRISurfaceRestoreDrawable(dst, &dstSaved); + + return pReg; +} + +static void +DRIPolyPoint(DrawablePtr dst, GCPtr pGC, int mode, int npt, DDXPointPtr pptInit) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->PolyPoint(dst, pGC, mode, npt, pptInit); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIPolylines(DrawablePtr dst, GCPtr pGC, int mode, int npt, DDXPointPtr pptInit) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->Polylines(dst, pGC, mode, npt, pptInit); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIPolySegment(DrawablePtr dst, GCPtr pGC, int nseg, xSegment * pSeg) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->PolySegment(dst, pGC, nseg, pSeg); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIPolyRectangle(DrawablePtr dst, GCPtr pGC, int nRects, xRectangle *pRects) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->PolyRectangle(dst, pGC, nRects, pRects); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIPolyArc(DrawablePtr dst, GCPtr pGC, int narcs, xArc * parcs) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->PolyArc(dst, pGC, narcs, parcs); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIFillPolygon(DrawablePtr dst, GCPtr pGC, + int shape, int mode, int count, DDXPointPtr pptInit) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->FillPolygon(dst, pGC, shape, mode, count, pptInit); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIPolyFillRect(DrawablePtr dst, GCPtr pGC, + int nRectsInit, xRectangle *pRectsInit) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->PolyFillRect(dst, pGC, nRectsInit, pRectsInit); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIPolyFillArc(DrawablePtr dst, GCPtr pGC, int narcsInit, xArc * parcsInit) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->PolyFillArc(dst, pGC, narcsInit, parcsInit); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static int +DRIPolyText8(DrawablePtr dst, GCPtr pGC, int x, int y, int count, char *chars) +{ + int ret; + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + ret = pGC->ops->PolyText8(dst, pGC, x, y, count, chars); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); + + return ret; +} + +static int +DRIPolyText16(DrawablePtr dst, GCPtr pGC, + int x, int y, int count, unsigned short *chars) +{ + int ret; + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + ret = pGC->ops->PolyText16(dst, pGC, x, y, count, chars); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); + + return ret; +} + +static void +DRIImageText8(DrawablePtr dst, GCPtr pGC, int x, int y, int count, char *chars) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->ImageText8(dst, pGC, x, y, count, chars); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIImageText16(DrawablePtr dst, GCPtr pGC, + int x, int y, int count, unsigned short *chars) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->ImageText16(dst, pGC, x, y, count, chars); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIImageGlyphBlt(DrawablePtr dst, GCPtr pGC, + int x, int y, unsigned int nglyphInit, + CharInfoPtr * ppciInit, pointer unused) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->ImageGlyphBlt(dst, pGC, x, y, nglyphInit, ppciInit, unused); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIPolyGlyphBlt(DrawablePtr dst, GCPtr pGC, + int x, int y, unsigned int nglyph, + CharInfoPtr * ppci, pointer pglyphBase) +{ + DRISavedDrawableState saved; + + DRISurfaceSetDrawable(dst, &saved); + + DRIUnwrapGC(pGC); + + pGC->ops->PolyGlyphBlt(dst, pGC, x, y, nglyph, ppci, pglyphBase); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(dst, &saved); +} + +static void +DRIPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr dst, + int dx, int dy, int xOrg, int yOrg) +{ + DRISavedDrawableState bitMapSaved, dstSaved; + + DRISurfaceSetDrawable(&pBitMap->drawable, &bitMapSaved); + DRISurfaceSetDrawable(dst, &dstSaved); + + DRIUnwrapGC(pGC); + + pGC->ops->PushPixels(pGC, pBitMap, dst, dx, dy, xOrg, yOrg); + + DRIWrapGC(pGC); + + DRISurfaceRestoreDrawable(&pBitMap->drawable, &bitMapSaved); + DRISurfaceRestoreDrawable(dst, &dstSaved); +} + +static GCOps driGCOps = { + DRIFillSpans, + DRISetSpans, + DRIPutImage, + DRICopyArea, + DRICopyPlane, + DRIPolyPoint, + DRIPolylines, + DRIPolySegment, + DRIPolyRectangle, + DRIPolyArc, + DRIFillPolygon, + DRIPolyFillRect, + DRIPolyFillArc, + DRIPolyText8, + DRIPolyText16, + DRIImageText8, + DRIImageText16, + DRIImageGlyphBlt, + DRIPolyGlyphBlt, + DRIPushPixels +}; + +static Bool +DRICreateGC(GCPtr pGC) +{ + ScreenPtr pScreen = pGC->pScreen; + DRIWrapScreenRec *pScreenPriv; + DRIGCRec *pGCPriv; + Bool ret; + + pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, driWrapScreenKey); + + pGCPriv = DRIGetGCPriv(pGC); + + unwrap(pScreenPriv, pScreen, CreateGC); + ret = pScreen->CreateGC(pGC); + + if (ret) { + pGCPriv->originalOps = pGC->ops; + pGC->ops = &driGCOps; + } + + wrap(pScreenPriv, pScreen, CreateGC, DRICreateGC); + + return ret; +} + +/* Return false if an error occurred. */ +Bool +DRIWrapInit(ScreenPtr pScreen) +{ + DRIWrapScreenRec *pScreenPriv; + + if (!dixRegisterPrivateKey(&driGCKeyRec, PRIVATE_GC, sizeof(DRIGCRec))) + return FALSE; + + if (!dixRegisterPrivateKey + (&driWrapScreenKeyRec, PRIVATE_SCREEN, sizeof(DRIWrapScreenRec))) + return FALSE; + + pScreenPriv = + dixGetPrivateAddr(&pScreen->devPrivates, &driWrapScreenKeyRec); + pScreenPriv->CreateGC = pScreen->CreateGC; + pScreen->CreateGC = DRICreateGC; + + return TRUE; +} diff --git a/xorg-server/hw/xquartz/xpr/dristruct.h b/xorg-server/hw/xquartz/xpr/dristruct.h index 19d78a973..13d590b1f 100644 --- a/xorg-server/hw/xquartz/xpr/dristruct.h +++ b/xorg-server/hw/xquartz/xpr/dristruct.h @@ -46,15 +46,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) ((DRIDrawablePrivPtr) \ dixLookupPrivate(&(pPix)->devPrivates, DRIPixmapPrivKey)) -typedef struct _DRIDrawablePrivRec -{ - xp_surface_id sid; - int drawableIndex; - DrawablePtr pDraw; - ScreenPtr pScreen; - int refCount; - unsigned int key[2]; - x_list *notifiers; /* list of (FUN . DATA) */ +typedef struct _DRIDrawablePrivRec { + xp_surface_id sid; + int drawableIndex; + DrawablePtr pDraw; + ScreenPtr pScreen; + int refCount; + unsigned int key[2]; + x_list *notifiers; /* list of (FUN . DATA) */ } DRIDrawablePrivRec, *DRIDrawablePrivPtr; #define DRI_SCREEN_PRIV(pScreen) ((DRIScreenPrivPtr) \ @@ -64,13 +63,11 @@ typedef struct _DRIDrawablePrivRec dixLookupPrivate(&screenInfo.screens[screenIndex]->devPrivates, \ DRIScreenPrivKey)) - -typedef struct _DRIScreenPrivRec -{ - Bool directRenderingSupport; - int nrWindows; - DRIWrappedFuncsRec wrap; - DrawablePtr DRIDrawables[DRI_MAX_DRAWABLES]; +typedef struct _DRIScreenPrivRec { + Bool directRenderingSupport; + int nrWindows; + DRIWrappedFuncsRec wrap; + DrawablePtr DRIDrawables[DRI_MAX_DRAWABLES]; } DRIScreenPrivRec, *DRIScreenPrivPtr; -#endif /* DRI_STRUCT_H */ +#endif /* DRI_STRUCT_H */ diff --git a/xorg-server/hw/xquartz/xpr/x-hash.c b/xorg-server/hw/xquartz/xpr/x-hash.c index 7c6a67bd1..a3ff66177 100644 --- a/xorg-server/hw/xquartz/xpr/x-hash.c +++ b/xorg-server/hw/xquartz/xpr/x-hash.c @@ -65,13 +65,13 @@ static const unsigned int bucket_sizes[] = { #define N_BUCKET_SIZES (sizeof (bucket_sizes) / sizeof (bucket_sizes[0])) static inline unsigned int -hash_table_total_buckets (x_hash_table *h) +hash_table_total_buckets(x_hash_table * h) { return bucket_sizes[h->bucket_index]; } static inline void -hash_table_destroy_item (x_hash_table *h, void *k, void *v) +hash_table_destroy_item(x_hash_table * h, void *k, void *v) { if (h->destroy_key != 0) (*h->destroy_key) (k); @@ -81,7 +81,7 @@ hash_table_destroy_item (x_hash_table *h, void *k, void *v) } static inline size_t -hash_table_hash_key (x_hash_table *h, void *k) +hash_table_hash_key(x_hash_table * h, void *k) { if (h->hash_key != 0) return (*h->hash_key) (k); @@ -90,7 +90,7 @@ hash_table_hash_key (x_hash_table *h, void *k) } static inline int -hash_table_compare_keys (x_hash_table *h, void *k1, void *k2) +hash_table_compare_keys(x_hash_table * h, void *k1, void *k2) { if (h->compare_keys == 0) return k1 == k2; @@ -99,7 +99,7 @@ hash_table_compare_keys (x_hash_table *h, void *k1, void *k2) } static void -hash_table_split (x_hash_table *h) +hash_table_split(x_hash_table * h) { x_list **new, **old; x_list *node, *item, *next; @@ -110,28 +110,25 @@ hash_table_split (x_hash_table *h) if (h->bucket_index == N_BUCKET_SIZES - 1) return; - old_size = hash_table_total_buckets (h); + old_size = hash_table_total_buckets(h); old = h->buckets; h->bucket_index++; - new_size = hash_table_total_buckets (h); - new = calloc (new_size, sizeof (x_list *)); + new_size = hash_table_total_buckets(h); + new = calloc(new_size, sizeof(x_list *)); - if (new == 0) - { + if (new == 0) { h->bucket_index--; return; } - for (i = 0; i < old_size; i++) - { - for (node = old[i]; node != 0; node = next) - { + for (i = 0; i < old_size; i++) { + for (node = old[i]; node != 0; node = next) { next = node->next; item = node->data; - b = hash_table_hash_key (h, ITEM_KEY (item)) % new_size; + b = hash_table_hash_key(h, ITEM_KEY(item)) % new_size; node->next = new[b]; new[b] = node; @@ -139,30 +136,27 @@ hash_table_split (x_hash_table *h) } h->buckets = new; - free (old); + free(old); } -X_EXTERN x_hash_table * -X_PFX (hash_table_new) (x_hash_fun *hash, - x_compare_fun *compare, - x_destroy_fun *key_destroy, - x_destroy_fun *value_destroy) -{ +X_EXTERN x_hash_table *X_PFX(hash_table_new) (x_hash_fun * hash, + x_compare_fun * compare, + x_destroy_fun * key_destroy, + x_destroy_fun * value_destroy) { x_hash_table *h; - h = calloc (1, sizeof (x_hash_table)); + h = calloc(1, sizeof(x_hash_table)); if (h == 0) return 0; h->bucket_index = 0; - h->buckets = calloc (hash_table_total_buckets (h), sizeof (x_list *)); + h->buckets = calloc(hash_table_total_buckets(h), sizeof(x_list *)); - if (h->buckets == 0) - { - free (h); + if (h->buckets == 0) { + free(h); return 0; } - + h->hash_key = hash; h->compare_keys = compare; h->destroy_key = key_destroy; @@ -172,66 +166,57 @@ X_PFX (hash_table_new) (x_hash_fun *hash, } X_EXTERN void -X_PFX (hash_table_free) (x_hash_table *h) -{ + X_PFX(hash_table_free) (x_hash_table * h) { int n, i; x_list *node, *item; - assert (h != NULL); + assert(h != NULL); - n = hash_table_total_buckets (h); + n = hash_table_total_buckets(h); - for (i = 0; i < n; i++) - { - for (node = h->buckets[i]; node != 0; node = node->next) - { + for (i = 0; i < n; i++) { + for (node = h->buckets[i]; node != 0; node = node->next) { item = node->data; - hash_table_destroy_item (h, ITEM_KEY (item), ITEM_VALUE (item)); - ITEM_FREE (item); + hash_table_destroy_item(h, ITEM_KEY(item), ITEM_VALUE(item)); + ITEM_FREE(item); } - X_PFX (list_free) (h->buckets[i]); + X_PFX(list_free) (h->buckets[i]); } - free (h->buckets); - free (h); + free(h->buckets); + free(h); } X_EXTERN unsigned int -X_PFX (hash_table_size) (x_hash_table *h) -{ - assert (h != NULL); + X_PFX(hash_table_size) (x_hash_table * h) { + assert(h != NULL); return h->total_keys; } static void -hash_table_modify (x_hash_table *h, void *k, void *v, int replace) +hash_table_modify(x_hash_table * h, void *k, void *v, int replace) { size_t hash_value; x_list *node, *item; - assert (h != NULL); + assert(h != NULL); - hash_value = hash_table_hash_key (h, k); + hash_value = hash_table_hash_key(h, k); - for (node = h->buckets[hash_value % hash_table_total_buckets (h)]; - node != 0; node = node->next) - { + for (node = h->buckets[hash_value % hash_table_total_buckets(h)]; + node != 0; node = node->next) { item = node->data; - if (hash_table_compare_keys (h, ITEM_KEY (item), k)) - { - if (replace) - { - hash_table_destroy_item (h, ITEM_KEY (item), - ITEM_VALUE (item)); + if (hash_table_compare_keys(h, ITEM_KEY(item), k)) { + if (replace) { + hash_table_destroy_item(h, ITEM_KEY(item), ITEM_VALUE(item)); item->next = k; - ITEM_VALUE (item) = v; + ITEM_VALUE(item) = v; } - else - { - hash_table_destroy_item (h, k, ITEM_VALUE (item)); - ITEM_VALUE (item) = v; + else { + hash_table_destroy_item(h, k, ITEM_VALUE(item)); + ITEM_VALUE(item) = v; } return; } @@ -240,78 +225,69 @@ hash_table_modify (x_hash_table *h, void *k, void *v, int replace) /* Key isn't already in the table. Insert it. */ if (h->total_keys + 1 - > hash_table_total_buckets (h) * SPLIT_THRESHOLD_FACTOR) - { - hash_table_split (h); + > hash_table_total_buckets(h) * SPLIT_THRESHOLD_FACTOR) { + hash_table_split(h); } - hash_value = hash_value % hash_table_total_buckets (h); - h->buckets[hash_value] = X_PFX (list_prepend) (h->buckets[hash_value], - ITEM_NEW (k, v)); + hash_value = hash_value % hash_table_total_buckets(h); + h->buckets[hash_value] = X_PFX(list_prepend) (h->buckets[hash_value], + ITEM_NEW(k, v)); h->total_keys++; } X_EXTERN void -X_PFX (hash_table_insert) (x_hash_table *h, void *k, void *v) -{ - hash_table_modify (h, k, v, 0); + X_PFX(hash_table_insert) (x_hash_table * h, void *k, void *v) { + hash_table_modify(h, k, v, 0); } X_EXTERN void -X_PFX (hash_table_replace) (x_hash_table *h, void *k, void *v) -{ - hash_table_modify (h, k, v, 1); + X_PFX(hash_table_replace) (x_hash_table * h, void *k, void *v) { + hash_table_modify(h, k, v, 1); } X_EXTERN void -X_PFX (hash_table_remove) (x_hash_table *h, void *k) -{ + X_PFX(hash_table_remove) (x_hash_table * h, void *k) { size_t hash_value; x_list **ptr, *item; - assert (h != NULL); + assert(h != NULL); - hash_value = hash_table_hash_key (h, k); + hash_value = hash_table_hash_key(h, k); - for (ptr = &h->buckets[hash_value % hash_table_total_buckets (h)]; - *ptr != 0; ptr = &((*ptr)->next)) - { + for (ptr = &h->buckets[hash_value % hash_table_total_buckets(h)]; + *ptr != 0; ptr = &((*ptr)->next)) { item = (*ptr)->data; - if (hash_table_compare_keys (h, ITEM_KEY (item), k)) - { - hash_table_destroy_item (h, ITEM_KEY (item), ITEM_VALUE (item)); - ITEM_FREE (item); + if (hash_table_compare_keys(h, ITEM_KEY(item), k)) { + hash_table_destroy_item(h, ITEM_KEY(item), ITEM_VALUE(item)); + ITEM_FREE(item); item = *ptr; *ptr = item->next; - X_PFX (list_free_1) (item); + X_PFX(list_free_1) (item); h->total_keys--; return; } } } -X_EXTERN void * -X_PFX (hash_table_lookup) (x_hash_table *h, void *k, void **k_ret) -{ +X_EXTERN void *X_PFX(hash_table_lookup) (x_hash_table * h, void *k, + void **k_ret) { size_t hash_value; x_list *node, *item; - assert (h != NULL); + assert(h != NULL); - hash_value = hash_table_hash_key (h, k); + hash_value = hash_table_hash_key(h, k); - for (node = h->buckets[hash_value % hash_table_total_buckets (h)]; - node != 0; node = node->next) - { + for (node = h->buckets[hash_value % hash_table_total_buckets(h)]; + node != 0; node = node->next) { item = node->data; - if (hash_table_compare_keys (h, ITEM_KEY (item), k)) - { + if (hash_table_compare_keys(h, ITEM_KEY(item), k)) { if (k_ret != 0) - *k_ret = ITEM_KEY (item); + *k_ret = ITEM_KEY(item); - return ITEM_VALUE (item); + return ITEM_VALUE(item); } } @@ -322,22 +298,20 @@ X_PFX (hash_table_lookup) (x_hash_table *h, void *k, void **k_ret) } X_EXTERN void -X_PFX (hash_table_foreach) (x_hash_table *h, - x_hash_foreach_fun *fun, void *data) -{ + +X_PFX(hash_table_foreach) (x_hash_table * h, + x_hash_foreach_fun * fun, void *data) { int i, n; x_list *node, *item; - assert (h != NULL); + assert(h != NULL); - n = hash_table_total_buckets (h); + n = hash_table_total_buckets(h); - for (i = 0; i < n; i++) - { - for (node = h->buckets[i]; node != 0; node = node->next) - { + for (i = 0; i < n; i++) { + for (node = h->buckets[i]; node != 0; node = node->next) { item = node->data; - (*fun) (ITEM_KEY (item), ITEM_VALUE (item), data); + (*fun) (ITEM_KEY(item), ITEM_VALUE(item), data); } } } diff --git a/xorg-server/hw/xquartz/xpr/x-hash.h b/xorg-server/hw/xquartz/xpr/x-hash.h index f876b6b71..c4543346a 100644 --- a/xorg-server/hw/xquartz/xpr/x-hash.h +++ b/xorg-server/hw/xquartz/xpr/x-hash.h @@ -43,49 +43,45 @@ typedef void (x_hash_foreach_fun) (void *k, void *v, void *data); /* for X_PFX and X_EXTERN */ #include "x-list.h" -X_EXTERN x_hash_table *X_PFX (hash_table_new) (x_hash_fun *hash, - x_compare_fun *compare, - x_destroy_fun *key_destroy, - x_destroy_fun *value_destroy); -X_EXTERN void X_PFX (hash_table_free) (x_hash_table *h); - -X_EXTERN unsigned int X_PFX (hash_table_size) (x_hash_table *h); - -X_EXTERN void X_PFX (hash_table_insert) (x_hash_table *h, void *k, void *v); -X_EXTERN void X_PFX (hash_table_replace) (x_hash_table *h, void *k, void *v); -X_EXTERN void X_PFX (hash_table_remove) (x_hash_table *h, void *k); -X_EXTERN void *X_PFX (hash_table_lookup) (x_hash_table *h, - void *k, void **k_ret); -X_EXTERN void X_PFX (hash_table_foreach) (x_hash_table *h, - x_hash_foreach_fun *fun, - void *data); +X_EXTERN x_hash_table *X_PFX(hash_table_new) (x_hash_fun * hash, + x_compare_fun * compare, + x_destroy_fun * key_destroy, + x_destroy_fun * value_destroy); +X_EXTERN void X_PFX(hash_table_free) (x_hash_table * h); + +X_EXTERN unsigned int X_PFX(hash_table_size) (x_hash_table * h); + +X_EXTERN void X_PFX(hash_table_insert) (x_hash_table * h, void *k, void *v); +X_EXTERN void X_PFX(hash_table_replace) (x_hash_table * h, void *k, void *v); +X_EXTERN void X_PFX(hash_table_remove) (x_hash_table * h, void *k); +X_EXTERN void *X_PFX(hash_table_lookup) (x_hash_table * h, + void *k, void **k_ret); +X_EXTERN void X_PFX(hash_table_foreach) (x_hash_table * h, + x_hash_foreach_fun * fun, void *data); /* Conversion between unsigned int (e.g. xp_resource_id) and void pointer */ /* Forward declarations */ -static __inline__ void * -X_PFX (cvt_uint_to_vptr) (unsigned int val) __attribute__((always_inline)); +static __inline__ void *X_PFX(cvt_uint_to_vptr) (unsigned int val) + __attribute__ ((always_inline)); static __inline__ unsigned int -X_PFX (cvt_vptr_to_uint) (void * val) __attribute__((always_inline)); + X_PFX(cvt_vptr_to_uint) (void *val) __attribute__ ((always_inline)); /* Implementations */ -static __inline__ void * -X_PFX (cvt_uint_to_vptr) (unsigned int val) -{ - return (void*)((unsigned long)(val)); +static __inline__ void *X_PFX(cvt_uint_to_vptr) (unsigned int val) { + return (void *) ((unsigned long) (val)); } static __inline__ unsigned int -X_PFX (cvt_vptr_to_uint) (void * val) -{ - size_t sv = (size_t)val; - unsigned int uv = (unsigned int)sv; - - /* If this assert fails, chances are val actually is a pointer, - or there's been memory corruption */ - assert(sv == uv); - - return uv; + X_PFX(cvt_vptr_to_uint) (void *val) { + size_t sv = (size_t) val; + unsigned int uv = (unsigned int) sv; + + /* If this assert fails, chances are val actually is a pointer, + or there's been memory corruption */ + assert(sv == uv); + + return uv; } -#endif /* X_HASH_H */ +#endif /* X_HASH_H */ diff --git a/xorg-server/hw/xquartz/xpr/x-hook.c b/xorg-server/hw/xquartz/xpr/x-hook.c index c65b6fc68..fd34658e7 100644 --- a/xorg-server/hw/xquartz/xpr/x-hook.c +++ b/xorg-server/hw/xquartz/xpr/x-hook.c @@ -1,120 +1,111 @@ -/* x-hook.c
-
- Copyright (c) 2003 Apple Computer, Inc. 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 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 ABOVE LISTED COPYRIGHT
- HOLDER(S) 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(s) of the above
- copyright holders shall not be used in advertising or otherwise to
- promote the sale, use or other dealings in this Software without
- prior written authorization. */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "x-hook.h"
-#include <stdlib.h>
-#include <assert.h>
-#include "os.h"
-
-#define CELL_NEW(f,d) X_PFX (list_prepend) ((x_list *) (f), (d))
-#define CELL_FREE(c) X_PFX (list_free_1) (c)
-#define CELL_FUN(c) ((x_hook_function *) ((c)->next))
-#define CELL_DATA(c) ((c)->data)
-
-X_EXTERN x_list *
-X_PFX (hook_add) (x_list *lst, x_hook_function *fun, void *data)
-{
- return X_PFX (list_prepend) (lst, CELL_NEW (fun, data));
-}
-
-X_EXTERN x_list *
-X_PFX (hook_remove) (x_list *lst, x_hook_function *fun, void *data)
-{
- x_list *node, *cell;
- x_list *to_delete = NULL;
-
- for (node = lst; node != NULL; node = node->next)
- {
- cell = node->data;
- if (CELL_FUN (cell) == fun && CELL_DATA (cell) == data)
- to_delete = X_PFX (list_prepend) (to_delete, cell);
- }
-
- for (node = to_delete; node != NULL; node = node->next)
- {
- cell = node->data;
- lst = X_PFX (list_remove) (lst, cell);
- CELL_FREE (cell);
- }
-
- X_PFX (list_free) (to_delete);
- return lst;
-}
-
-X_EXTERN void
-X_PFX (hook_run) (x_list *lst, void *arg)
-{
- x_list *node, *cell;
- x_hook_function **fun;
- void **data;
- int length, i;
-
- if(!lst)
- return;
-
- length = X_PFX (list_length) (lst);
- fun = malloc(sizeof (x_hook_function *) * length);
- data = malloc(sizeof (void *) * length);
-
- if(!fun || !data) {
- FatalError("Failed to allocate memory in %s\n", __func__);
- }
-
- for (i = 0, node = lst; node != NULL; node = node->next, i++)
- {
- cell = node->data;
- fun[i] = CELL_FUN (cell);
- data[i] = CELL_DATA (cell);
- }
-
- for (i = 0; i < length; i++)
- {
- (*fun[i]) (arg, data[i]);
- }
-
- free(fun);
- free(data);
-}
-
-X_EXTERN void
-X_PFX (hook_free) (x_list *lst)
-{
- x_list *node;
-
- for (node = lst; node != NULL; node = node->next)
- {
- CELL_FREE (node->data);
- }
-
- X_PFX (list_free) (lst);
-}
+/* x-hook.c + + Copyright (c) 2003 Apple Computer, Inc. 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 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 ABOVE LISTED COPYRIGHT + HOLDER(S) 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(s) of the above + copyright holders shall not be used in advertising or otherwise to + promote the sale, use or other dealings in this Software without + prior written authorization. */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "x-hook.h" +#include <stdlib.h> +#include <assert.h> +#include "os.h" + +#define CELL_NEW(f,d) X_PFX (list_prepend) ((x_list *) (f), (d)) +#define CELL_FREE(c) X_PFX (list_free_1) (c) +#define CELL_FUN(c) ((x_hook_function *) ((c)->next)) +#define CELL_DATA(c) ((c)->data) + +X_EXTERN x_list *X_PFX(hook_add) (x_list * lst, x_hook_function * fun, + void *data) { + return X_PFX(list_prepend) (lst, CELL_NEW(fun, data)); +} + +X_EXTERN x_list *X_PFX(hook_remove) (x_list * lst, x_hook_function * fun, + void *data) { + x_list *node, *cell; + x_list *to_delete = NULL; + + for (node = lst; node != NULL; node = node->next) { + cell = node->data; + if (CELL_FUN(cell) == fun && CELL_DATA(cell) == data) + to_delete = X_PFX(list_prepend) (to_delete, cell); + } + + for (node = to_delete; node != NULL; node = node->next) { + cell = node->data; + lst = X_PFX(list_remove) (lst, cell); + CELL_FREE(cell); + } + + X_PFX(list_free) (to_delete); + return lst; +} + +X_EXTERN void + X_PFX(hook_run) (x_list * lst, void *arg) { + x_list *node, *cell; + x_hook_function **fun; + void **data; + int length, i; + + if (!lst) + return; + + length = X_PFX(list_length) (lst); + fun = malloc(sizeof(x_hook_function *) * length); + data = malloc(sizeof(void *) * length); + + if (!fun || !data) { + FatalError("Failed to allocate memory in %s\n", __func__); + } + + for (i = 0, node = lst; node != NULL; node = node->next, i++) { + cell = node->data; + fun[i] = CELL_FUN(cell); + data[i] = CELL_DATA(cell); + } + + for (i = 0; i < length; i++) { + (*fun[i]) (arg, data[i]); + } + + free(fun); + free(data); +} + +X_EXTERN void + X_PFX(hook_free) (x_list * lst) { + x_list *node; + + for (node = lst; node != NULL; node = node->next) { + CELL_FREE(node->data); + } + + X_PFX(list_free) (lst); +} diff --git a/xorg-server/hw/xquartz/xpr/x-hook.h b/xorg-server/hw/xquartz/xpr/x-hook.h index 392352d50..da3407f92 100644 --- a/xorg-server/hw/xquartz/xpr/x-hook.h +++ b/xorg-server/hw/xquartz/xpr/x-hook.h @@ -32,11 +32,13 @@ #include "x-list.h" -typedef void x_hook_function (void *arg, void *data); +typedef void x_hook_function(void *arg, void *data); -X_EXTERN x_list *X_PFX (hook_add) (x_list *lst, x_hook_function *fun, void *data); -X_EXTERN x_list *X_PFX (hook_remove) (x_list *lst, x_hook_function *fun, void *data); -X_EXTERN void X_PFX (hook_run) (x_list *lst, void *arg); -X_EXTERN void X_PFX (hook_free) (x_list *lst); +X_EXTERN x_list *X_PFX(hook_add) (x_list * lst, x_hook_function * fun, + void *data); +X_EXTERN x_list *X_PFX(hook_remove) (x_list * lst, x_hook_function * fun, + void *data); +X_EXTERN void X_PFX(hook_run) (x_list * lst, void *arg); +X_EXTERN void X_PFX(hook_free) (x_list * lst); -#endif /* X_HOOK_H */ +#endif /* X_HOOK_H */ diff --git a/xorg-server/hw/xquartz/xpr/x-list.c b/xorg-server/hw/xquartz/xpr/x-list.c index 77c9309aa..757ff4cb0 100644 --- a/xorg-server/hw/xquartz/xpr/x-list.c +++ b/xorg-server/hw/xquartz/xpr/x-list.c @@ -50,57 +50,51 @@ static x_list *freelist; static pthread_mutex_t freelist_lock = PTHREAD_MUTEX_INITIALIZER; static inline void -list_free_1 (x_list *node) +list_free_1(x_list * node) { node->next = freelist; freelist = node; } X_EXTERN void -X_PFX (list_free_1) (x_list *node) -{ - assert (node != NULL); + X_PFX(list_free_1) (x_list * node) { + assert(node != NULL); - pthread_mutex_lock (&freelist_lock); + pthread_mutex_lock(&freelist_lock); - list_free_1 (node); + list_free_1(node); - pthread_mutex_unlock (&freelist_lock); + pthread_mutex_unlock(&freelist_lock); } X_EXTERN void -X_PFX (list_free) (x_list *lst) -{ + X_PFX(list_free) (x_list * lst) { x_list *next; - pthread_mutex_lock (&freelist_lock); + pthread_mutex_lock(&freelist_lock); - for (; lst != NULL; lst = next) - { + for (; lst != NULL; lst = next) { next = lst->next; - list_free_1 (lst); + list_free_1(lst); } - pthread_mutex_unlock (&freelist_lock); + pthread_mutex_unlock(&freelist_lock); } -X_EXTERN x_list * -X_PFX (list_prepend) (x_list *lst, void *data) -{ +X_EXTERN x_list *X_PFX(list_prepend) (x_list * lst, void *data) { x_list *node; - pthread_mutex_lock (&freelist_lock); + pthread_mutex_lock(&freelist_lock); - if (freelist == NULL) - { + if (freelist == NULL) { x_list_block *b; int i; - b = malloc (sizeof (x_list_block)); + b = malloc(sizeof(x_list_block)); assert(b != NULL); for (i = 0; i < NODES_PER_BLOCK - 1; i++) - b->l[i].next = &(b->l[i+1]); + b->l[i].next = &(b->l[i + 1]); b->l[i].next = NULL; freelist = b->l; @@ -109,7 +103,7 @@ X_PFX (list_prepend) (x_list *lst, void *data) node = freelist; freelist = node->next; - pthread_mutex_unlock (&freelist_lock); + pthread_mutex_unlock(&freelist_lock); node->next = lst; node->data = data; @@ -117,29 +111,24 @@ X_PFX (list_prepend) (x_list *lst, void *data) return node; } -X_EXTERN x_list * -X_PFX (list_append) (x_list *lst, void *data) -{ +X_EXTERN x_list *X_PFX(list_append) (x_list * lst, void *data) { x_list *head = lst; if (lst == NULL) - return X_PFX (list_prepend) (NULL, data); + return X_PFX(list_prepend) (NULL, data); while (lst->next != NULL) lst = lst->next; - lst->next = X_PFX (list_prepend) (NULL, data); + lst->next = X_PFX(list_prepend) (NULL, data); return head; } -X_EXTERN x_list * -X_PFX (list_reverse) (x_list *lst) -{ +X_EXTERN x_list *X_PFX(list_reverse) (x_list * lst) { x_list *head = NULL, *next; - - while (lst != NULL) - { + + while (lst != NULL) { next = lst->next; lst->next = head; head = lst; @@ -149,11 +138,8 @@ X_PFX (list_reverse) (x_list *lst) return head; } -X_EXTERN x_list * -X_PFX (list_find) (x_list *lst, void *data) -{ - for (; lst != NULL; lst = lst->next) - { +X_EXTERN x_list *X_PFX(list_find) (x_list * lst, void *data) { + for (; lst != NULL; lst = lst->next) { if (lst->data == data) return lst; } @@ -161,26 +147,22 @@ X_PFX (list_find) (x_list *lst, void *data) return NULL; } -X_EXTERN x_list * -X_PFX (list_nth) (x_list *lst, int n) -{ +X_EXTERN x_list *X_PFX(list_nth) (x_list * lst, int n) { while (n-- > 0 && lst != NULL) lst = lst->next; return lst; } -X_EXTERN x_list * -X_PFX (list_pop) (x_list *lst, void **data_ret) -{ +X_EXTERN x_list *X_PFX(list_pop) (x_list * lst, void **data_ret) { void *data = NULL; - if (lst != NULL) - { + if (lst != NULL) { x_list *tem = lst; + data = lst->data; lst = lst->next; - X_PFX (list_free_1) (tem); + X_PFX(list_free_1) (tem); } if (data_ret != NULL) @@ -189,61 +171,50 @@ X_PFX (list_pop) (x_list *lst, void **data_ret) return lst; } -X_EXTERN x_list * -X_PFX (list_filter) (x_list *lst, - int (*pred) (void *item, void *data), void *data) -{ +X_EXTERN x_list *X_PFX(list_filter) (x_list * lst, + int (*pred) (void *item, void *data), + void *data) { x_list *ret = NULL, *node; - for (node = lst; node != NULL; node = node->next) - { + for (node = lst; node != NULL; node = node->next) { if ((*pred) (node->data, data)) - ret = X_PFX (list_prepend) (ret, node->data); + ret = X_PFX(list_prepend) (ret, node->data); } - return X_PFX (list_reverse) (ret); + return X_PFX(list_reverse) (ret); } -X_EXTERN x_list * -X_PFX (list_map) (x_list *lst, - void *(*fun) (void *item, void *data), void *data) -{ +X_EXTERN x_list *X_PFX(list_map) (x_list * lst, + void *(*fun) (void *item, void *data), + void *data) { x_list *ret = NULL, *node; - for (node = lst; node != NULL; node = node->next) - { - X_PFX (list_prepend) (ret, fun (node->data, data)); + for (node = lst; node != NULL; node = node->next) { + X_PFX(list_prepend) (ret, fun(node->data, data)); } - return X_PFX (list_reverse) (ret); + return X_PFX(list_reverse) (ret); } -X_EXTERN x_list * -X_PFX (list_copy) (x_list *lst) -{ +X_EXTERN x_list *X_PFX(list_copy) (x_list * lst) { x_list *copy = NULL; - for (; lst != NULL; lst = lst->next) - { - copy = X_PFX (list_prepend) (copy, lst->data); + for (; lst != NULL; lst = lst->next) { + copy = X_PFX(list_prepend) (copy, lst->data); } - return X_PFX (list_reverse) (copy); + return X_PFX(list_reverse) (copy); } -X_EXTERN x_list * -X_PFX (list_remove) (x_list *lst, void *data) -{ +X_EXTERN x_list *X_PFX(list_remove) (x_list * lst, void *data) { x_list **ptr, *node; - for (ptr = &lst; *ptr != NULL;) - { + for (ptr = &lst; *ptr != NULL;) { node = *ptr; - if (node->data == data) - { + if (node->data == data) { *ptr = node->next; - X_PFX (list_free_1) (node); + X_PFX(list_free_1) (node); } else ptr = &((*ptr)->next); @@ -253,8 +224,7 @@ X_PFX (list_remove) (x_list *lst, void *data) } X_EXTERN unsigned int -X_PFX (list_length) (x_list *lst) -{ + X_PFX(list_length) (x_list * lst) { unsigned int n; n = 0; @@ -265,19 +235,17 @@ X_PFX (list_length) (x_list *lst) } X_EXTERN void -X_PFX (list_foreach) (x_list *lst, - void (*fun) (void *data, void *user_data), - void *user_data) -{ - for (; lst != NULL; lst = lst->next) - { + +X_PFX(list_foreach) (x_list * lst, + void (*fun) (void *data, void *user_data), + void *user_data) { + for (; lst != NULL; lst = lst->next) { (*fun) (lst->data, user_data); } } static x_list * -list_sort_1 (x_list *lst, int length, - int (*less) (const void *, const void *)) +list_sort_1(x_list * lst, int length, int (*less) (const void *, const void *)) { x_list *mid, *ptr; x_list *out_head, *out; @@ -299,20 +267,19 @@ list_sort_1 (x_list *lst, int length, /* Sort each sub-list. */ - lst = list_sort_1 (lst, mid_point, less); - mid = list_sort_1 (mid, length - mid_point, less); + lst = list_sort_1(lst, mid_point, less); + mid = list_sort_1(mid, length - mid_point, less); /* Then merge them back together. */ - assert (lst != NULL && mid != NULL); + assert(lst != NULL && mid != NULL); if ((*less) (mid->data, lst->data)) out = out_head = mid, mid = mid->next; else out = out_head = lst, lst = lst->next; - while (lst != NULL && mid != NULL) - { + while (lst != NULL && mid != NULL) { if ((*less) (mid->data, lst->data)) out = out->next = mid, mid = mid->next; else @@ -327,12 +294,11 @@ list_sort_1 (x_list *lst, int length, return out_head; } -X_EXTERN x_list * -X_PFX (list_sort) (x_list *lst, int (*less) (const void *, const void *)) -{ +X_EXTERN x_list *X_PFX(list_sort) (x_list * lst, + int (*less) (const void *, const void *)) { int length; - length = X_PFX (list_length) (lst); + length = X_PFX(list_length) (lst); - return list_sort_1 (lst, length, less); + return list_sort_1(lst, length, less); } diff --git a/xorg-server/hw/xquartz/xpr/xprAppleWM.c b/xorg-server/hw/xquartz/xpr/xprAppleWM.c index b6b9a5fc8..77b9fa3e8 100644 --- a/xorg-server/hw/xquartz/xpr/xprAppleWM.c +++ b/xorg-server/hw/xquartz/xpr/xprAppleWM.c @@ -43,9 +43,8 @@ #include "quartz.h" #include "x-hash.h" -static int xprSetWindowLevel( - WindowPtr pWin, - int level) +static int +xprSetWindowLevel(WindowPtr pWin, int level) { xp_window_id wid; xp_window_changes wc; @@ -56,25 +55,25 @@ static int xprSetWindowLevel( if (level < 0 || level >= AppleWMNumWindowLevels) { return BadValue; } - - wid = x_cvt_vptr_to_uint(RootlessFrameForWindow (pWin, TRUE)); + + wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWin, TRUE)); if (wid == 0) return BadWindow; - RootlessStopDrawing (pWin, FALSE); + RootlessStopDrawing(pWin, FALSE); winRec = WINREC(pWin); - - if(!winRec) + + if (!winRec) return BadWindow; - - if(XQuartzIsRootless) + + if (XQuartzIsRootless) wc.window_level = normal_window_levels[level]; - else if(XQuartzShieldingWindowLevel) + else if (XQuartzShieldingWindowLevel) wc.window_level = XQuartzShieldingWindowLevel + 1; else wc.window_level = rooted_window_levels[level]; - - if (xp_configure_window (wid, XP_WINDOW_LEVEL, &wc) != Success) { + + if (xp_configure_window(wid, XP_WINDOW_LEVEL, &wc) != Success) { return BadValue; } @@ -84,52 +83,54 @@ static int xprSetWindowLevel( } #if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION >= 3 -static int xprAttachTransient(WindowPtr pWinChild, WindowPtr pWinParent) { - xp_window_id child_wid, parent_wid; +static int +xprAttachTransient(WindowPtr pWinChild, WindowPtr pWinParent) +{ + xp_window_id child_wid, parent_wid; xp_window_changes wc; child_wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinChild, TRUE)); if (child_wid == 0) return BadWindow; - if(pWinParent) { - parent_wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinParent, TRUE)); + if (pWinParent) { + parent_wid = + x_cvt_vptr_to_uint(RootlessFrameForWindow(pWinParent, TRUE)); if (parent_wid == 0) return BadWindow; - } else { + } + else { parent_wid = 0; } - + wc.transient_for = parent_wid; - RootlessStopDrawing (pWinChild, FALSE); + RootlessStopDrawing(pWinChild, FALSE); if (xp_configure_window(child_wid, XP_ATTACH_TRANSIENT, &wc) != Success) { return BadValue; } - return Success; + return Success; } #endif -static int xprFrameDraw( - WindowPtr pWin, - xp_frame_class class, - xp_frame_attr attr, - const BoxRec *outer, - const BoxRec *inner, - unsigned int title_len, - const unsigned char *title_bytes) +static int +xprFrameDraw(WindowPtr pWin, + xp_frame_class class, + xp_frame_attr attr, + const BoxRec * outer, + const BoxRec * inner, + unsigned int title_len, const unsigned char *title_bytes) { xp_window_id wid; - wid = x_cvt_vptr_to_uint(RootlessFrameForWindow (pWin, FALSE)); + wid = x_cvt_vptr_to_uint(RootlessFrameForWindow(pWin, FALSE)); if (wid == 0) return BadWindow; - if (xp_frame_draw (wid, class, attr, outer, inner, - title_len, title_bytes) != Success) - { + if (xp_frame_draw(wid, class, attr, outer, inner, + title_len, title_bytes) != Success) { return BadValue; } @@ -155,8 +156,8 @@ static AppleWMProcsRec xprAppleWMProcs = { #endif }; - -void xprAppleWMInit(void) +void +xprAppleWMInit(void) { AppleWMExtensionInit(&xprAppleWMProcs); } diff --git a/xorg-server/hw/xquartz/xpr/xprCursor.c b/xorg-server/hw/xquartz/xpr/xprCursor.c index 2b31865a5..b0afa8c0e 100644 --- a/xorg-server/hw/xquartz/xpr/xprCursor.c +++ b/xorg-server/hw/xquartz/xpr/xprCursor.c @@ -51,12 +51,13 @@ #include "x-hash.h" typedef struct { - int cursorVisible; - QueryBestSizeProcPtr QueryBestSize; - miPointerSpriteFuncPtr spriteFuncs; + int cursorVisible; + QueryBestSizeProcPtr QueryBestSize; + miPointerSpriteFuncPtr spriteFuncs; } QuartzCursorScreenRec, *QuartzCursorScreenPtr; static DevPrivateKeyRec darwinCursorScreenKeyRec; + #define darwinCursorScreenKey (&darwinCursorScreenKeyRec) #define CURSOR_PRIV(pScreen) ((QuartzCursorScreenPtr) \ @@ -85,22 +86,22 @@ load_cursor(CursorPtr src, int screen) hot_y = src->bits->yhot; #ifdef ARGB_CURSOR - if (src->bits->argb != NULL) - { + if (src->bits->argb != NULL) { #if BITMAP_BIT_ORDER == MSBFirst - rowbytes = src->bits->width * sizeof (CARD32); + rowbytes = src->bits->width * sizeof(CARD32); data = (uint32_t *) src->bits->argb; #else - const uint32_t *be_data=(uint32_t *) src->bits->argb; + const uint32_t *be_data = (uint32_t *) src->bits->argb; unsigned i; - rowbytes = src->bits->width * sizeof (CARD32); + + rowbytes = src->bits->width * sizeof(CARD32); data = malloc(rowbytes * src->bits->height); free_data = TRUE; - if(!data) { + if (!data) { FatalError("Failed to allocate memory in %s\n", __func__); } - for(i=0;i<(src->bits->width*src->bits->height);i++) - data[i]=ntohl(be_data[i]); + for (i = 0; i < (src->bits->width * src->bits->height); i++) + data[i] = ntohl(be_data[i]); #endif } else @@ -123,42 +124,43 @@ load_cursor(CursorPtr src, int screen) rowbytes = ((src->bits->width * 4) + 31) & ~31; data = malloc(rowbytes * src->bits->height); free_data = TRUE; - if(!data) { + if (!data) { FatalError("Failed to allocate memory in %s\n", __func__); } - - if (!src->bits->emptyMask) - { + + if (!src->bits->emptyMask) { ycount = src->bits->height; - srow = src->bits->source; mrow = src->bits->mask; + srow = src->bits->source; + mrow = src->bits->mask; drow = data; - while (ycount-- > 0) - { + while (ycount-- > 0) { xcount = bits_to_bytes(src->bits->width); - sptr = srow; mptr = mrow; + sptr = srow; + mptr = mrow; dptr = drow; - while (xcount-- > 0) - { + while (xcount-- > 0) { uint8_t s, m; int i; - s = *sptr++; m = *mptr++; - for (i = 0; i < 8; i++) - { + s = *sptr++; + m = *mptr++; + for (i = 0; i < 8; i++) { #if BITMAP_BIT_ORDER == MSBFirst if (m & 128) *dptr++ = (s & 128) ? fg_color : bg_color; else *dptr++ = 0; - s <<= 1; m <<= 1; + s <<= 1; + m <<= 1; #else if (m & 1) *dptr++ = (s & 1) ? fg_color : bg_color; else *dptr++ = 0; - s >>= 1; m >>= 1; + s >>= 1; + m >>= 1; #endif } } @@ -168,19 +170,17 @@ load_cursor(CursorPtr src, int screen) drow = (uint32_t *) ((char *) drow + rowbytes); } } - else - { + else { memset(data, 0, src->bits->height * rowbytes); } } err = xp_set_cursor(width, height, hot_x, hot_y, data, rowbytes); - if(free_data) + if (free_data) free(data); return err == Success; } - /* =========================================================================== @@ -196,7 +196,7 @@ load_cursor(CursorPtr src, int screen) static Bool QuartzRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) { - if(pCursor == NULL || pCursor->bits == NULL) + if (pCursor == NULL || pCursor->bits == NULL) return FALSE; /* FIXME: cache ARGB8888 representation? */ @@ -204,7 +204,6 @@ QuartzRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) return TRUE; } - /* * QuartzUnrealizeCursor * Free the storage space associated with a realized cursor. @@ -215,33 +214,29 @@ QuartzUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) return TRUE; } - /* * QuartzSetCursor * Set the cursor sprite and position. */ static void -QuartzSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, int y) +QuartzSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, + int y) { QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen); if (!XQuartzServerVisible) return; - if (pCursor == NULL) - { - if (ScreenPriv->cursorVisible) - { + if (pCursor == NULL) { + if (ScreenPriv->cursorVisible) { xp_hide_cursor(); ScreenPriv->cursorVisible = FALSE; } } - else - { + else { load_cursor(pCursor, pScreen->myNum); - if (!ScreenPriv->cursorVisible) - { + if (!ScreenPriv->cursorVisible) { xp_show_cursor(); ScreenPriv->cursorVisible = TRUE; } @@ -274,7 +269,6 @@ QuartzCursorOffScreen(ScreenPtr *pScreen, int *x, int *y) return FALSE; } - /* * QuartzCrossScreen */ @@ -284,7 +278,6 @@ QuartzCrossScreen(ScreenPtr pScreen, Bool entering) return; } - /* * QuartzWarpCursor * Change the cursor position without generating an event or motion history. @@ -294,8 +287,7 @@ QuartzCrossScreen(ScreenPtr pScreen, Bool entering) static void QuartzWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) { - if (XQuartzServerVisible) - { + if (XQuartzServerVisible) { int sx, sy; sx = pScreen->x + darwinMainScreenX; @@ -308,7 +300,6 @@ QuartzWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) miPointerUpdateSprite(pDev); } - static miPointerScreenFuncRec quartzScreenFuncsRec = { QuartzCursorOffScreen, QuartzCrossScreen, @@ -317,7 +308,6 @@ static miPointerScreenFuncRec quartzScreenFuncsRec = { NULL }; - /* =========================================================================== @@ -336,15 +326,13 @@ QuartzCursorQueryBestSize(int class, unsigned short *width, { QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen); - if (class == CursorShape) - { + if (class == CursorShape) { /* FIXME: query window server? */ *width = 32; *height = 32; } - else - { - (*ScreenPriv->QueryBestSize)(class, width, height, pScreen); + else { + (*ScreenPriv->QueryBestSize) (class, width, height, pScreen); } } @@ -363,7 +351,7 @@ QuartzInitCursor(ScreenPtr pScreen) return FALSE; if (!dixRegisterPrivateKey(&darwinCursorScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; + return FALSE; ScreenPriv = calloc(1, sizeof(QuartzCursorScreenRec)); if (ScreenPriv == NULL) @@ -384,7 +372,7 @@ QuartzInitCursor(ScreenPtr pScreen) PointPriv->spriteFuncs->UnrealizeCursor = QuartzUnrealizeCursor; PointPriv->spriteFuncs->SetCursor = QuartzSetCursor; PointPriv->spriteFuncs->MoveCursor = QuartzMoveCursor; - + ScreenPriv->cursorVisible = TRUE; return TRUE; } @@ -398,7 +386,6 @@ QuartzSuspendXCursor(ScreenPtr pScreen) { } - /* * QuartzResumeXCursor * X server is showing. Restore the X cursor. @@ -410,7 +397,7 @@ QuartzResumeXCursor(ScreenPtr pScreen) CursorPtr pCursor; /* TODO: Tablet? */ - + pWin = GetSpriteWindow(darwinPointer); if (pWin->drawable.pScreen != pScreen) return; diff --git a/xorg-server/hw/xquartz/xpr/xprEvent.c b/xorg-server/hw/xquartz/xpr/xprEvent.c index 4e7ece64f..7f4b077c3 100644 --- a/xorg-server/hw/xquartz/xpr/xprEvent.c +++ b/xorg-server/hw/xquartz/xpr/xprEvent.c @@ -55,24 +55,25 @@ #include "rootlessWindow.h" #include "xprEvent.h" -Bool QuartzModeEventHandler(int screenNum, XQuartzEvent *e, DeviceIntPtr dev) { - switch(e->subtype) { - case kXquartzWindowState: - DEBUG_LOG("kXquartzWindowState\n"); - RootlessNativeWindowStateChanged(xprGetXWindow(e->data[0]), - e->data[1]); - return TRUE; - - case kXquartzWindowMoved: - DEBUG_LOG("kXquartzWindowMoved\n"); - RootlessNativeWindowMoved(xprGetXWindow(e->data[0])); - return TRUE; - - case kXquartzBringAllToFront: - DEBUG_LOG("kXquartzBringAllToFront\n"); - RootlessOrderAllWindows(e->data[0]); - return TRUE; - default: - return FALSE; +Bool +QuartzModeEventHandler(int screenNum, XQuartzEvent * e, DeviceIntPtr dev) +{ + switch (e->subtype) { + case kXquartzWindowState: + DEBUG_LOG("kXquartzWindowState\n"); + RootlessNativeWindowStateChanged(xprGetXWindow(e->data[0]), e->data[1]); + return TRUE; + + case kXquartzWindowMoved: + DEBUG_LOG("kXquartzWindowMoved\n"); + RootlessNativeWindowMoved(xprGetXWindow(e->data[0])); + return TRUE; + + case kXquartzBringAllToFront: + DEBUG_LOG("kXquartzBringAllToFront\n"); + RootlessOrderAllWindows(e->data[0]); + return TRUE; + default: + return FALSE; } } diff --git a/xorg-server/hw/xquartz/xpr/xprFrame.c b/xorg-server/hw/xquartz/xpr/xprFrame.c index 98f1cc3ed..ed81c4b48 100644 --- a/xorg-server/hw/xquartz/xpr/xprFrame.c +++ b/xorg-server/hw/xquartz/xpr/xprFrame.c @@ -73,37 +73,51 @@ static pthread_rwlock_t window_hash_rwlock; #endif /* Prototypes for static functions */ -static Bool xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen, +static Bool +xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen, int newX, int newY, RegionPtr pShape); -static void xprDestroyFrame(RootlessFrameID wid); -static void xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY); -static void xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen, +static void +xprDestroyFrame(RootlessFrameID wid); +static void +xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY); +static void +xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY, unsigned int newW, unsigned int newH, unsigned int gravity); -static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid); -static void xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape); -static void xprUnmapFrame(RootlessFrameID wid); -static void xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow); -static void xprStopDrawing(RootlessFrameID wid, Bool flush); -static void xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage); -static void xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects, +static void +xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid); +static void +xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape); +static void +xprUnmapFrame(RootlessFrameID wid); +static void +xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow); +static void +xprStopDrawing(RootlessFrameID wid, Bool flush); +static void +xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage); +static void +xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec * rects, int shift_x, int shift_y); -static void xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin); -static Bool xprDoReorderWindow(RootlessWindowPtr pFrame); -static void xprHideWindow(RootlessFrameID wid); -static void xprUpdateColormap(RootlessFrameID wid, ScreenPtr pScreen); -static void xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects, +static void +xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin); +static Bool +xprDoReorderWindow(RootlessWindowPtr pFrame); +static void +xprHideWindow(RootlessFrameID wid); +static void +xprUpdateColormap(RootlessFrameID wid, ScreenPtr pScreen); +static void +xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec * dstRects, int dx, int dy); - static inline xp_error xprConfigureWindow(xp_window_id id, unsigned int mask, - const xp_window_changes *values) + const xp_window_changes * values) { return xp_configure_window(id, mask, values); } - static void xprSetNativeProperty(RootlessWindowPtr pFrame) { @@ -112,20 +126,22 @@ xprSetNativeProperty(RootlessWindowPtr pFrame) long data; err = xp_get_native_window(x_cvt_vptr_to_uint(pFrame->wid), &native_id); - if (err == Success) - { + if (err == Success) { /* FIXME: move this to AppleWM extension */ data = native_id; - dixChangeWindowProperty(serverClient, pFrame->win, xa_native_window_id(), - XA_INTEGER, 32, PropModeReplace, 1, &data, TRUE); + dixChangeWindowProperty(serverClient, pFrame->win, + xa_native_window_id(), XA_INTEGER, 32, + PropModeReplace, 1, &data, TRUE); } } static xp_error -xprColormapCallback(void *data, int first_color, int n_colors, uint32_t *colors) +xprColormapCallback(void *data, int first_color, int n_colors, + uint32_t * colors) { - return (RootlessResolveColormap (data, first_color, n_colors, colors) ? XP_Success : XP_BadMatch); + return (RootlessResolveColormap(data, first_color, n_colors, colors) ? + XP_Success : XP_BadMatch); } /* @@ -147,8 +163,7 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen, wc.bit_gravity = XP_GRAVITY_NONE; mask |= XP_BOUNDS; - if (pWin->drawable.depth == 8) - { + if (pWin->drawable.depth == 8) { wc.depth = XP_DEPTH_INDEX8; wc.colormap = xprColormapCallback; wc.colormap_data = pScreen; @@ -162,35 +177,34 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen, wc.depth = XP_DEPTH_NIL; mask |= XP_DEPTH; - if (pShape != NULL) - { + if (pShape != NULL) { wc.shape_nrects = RegionNumRects(pShape); wc.shape_rects = RegionRects(pShape); wc.shape_tx = wc.shape_ty = 0; mask |= XP_SHAPE; } - pFrame->level = !IsRoot (pWin) ? AppleWMWindowLevelNormal : AppleWMNumWindowLevels; + pFrame->level = + !IsRoot(pWin) ? AppleWMWindowLevelNormal : AppleWMNumWindowLevels; - if(XQuartzIsRootless) + if (XQuartzIsRootless) wc.window_level = normal_window_levels[pFrame->level]; - else if(XQuartzShieldingWindowLevel) + else if (XQuartzShieldingWindowLevel) wc.window_level = XQuartzShieldingWindowLevel + 1; else wc.window_level = rooted_window_levels[pFrame->level]; mask |= XP_WINDOW_LEVEL; - err = xp_create_window(mask, &wc, (xp_window_id *) &pFrame->wid); + err = xp_create_window(mask, &wc, (xp_window_id *) & pFrame->wid); - if (err != Success) - { + if (err != Success) { return FALSE; } #ifdef HAVE_LIBDISPATCH - dispatch_async(window_hash_serial_q, ^{ - x_hash_table_insert(window_hash, pFrame->wid, pFrame); - }); + dispatch_async(window_hash_serial_q, ^ { + x_hash_table_insert(window_hash, pFrame->wid, pFrame);} + ); #else pthread_rwlock_wrlock(&window_hash_rwlock); x_hash_table_insert(window_hash, pFrame->wid, pFrame); @@ -202,7 +216,6 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen, return TRUE; } - /* * Destroy a frame. */ @@ -212,9 +225,8 @@ xprDestroyFrame(RootlessFrameID wid) xp_error err; #ifdef HAVE_LIBDISPATCH - dispatch_async(window_hash_serial_q, ^{ - x_hash_table_remove(window_hash, wid); - }); + dispatch_async(window_hash_serial_q, ^ { + x_hash_table_remove(window_hash, wid);}); #else pthread_rwlock_wrlock(&window_hash_rwlock); x_hash_table_remove(window_hash, wid); @@ -223,10 +235,10 @@ xprDestroyFrame(RootlessFrameID wid) err = xp_destroy_window(x_cvt_vptr_to_uint(wid)); if (err != Success) - FatalError("Could not destroy window %d (%d).", (int)x_cvt_vptr_to_uint(wid), (int)err); + FatalError("Could not destroy window %d (%d).", + (int) x_cvt_vptr_to_uint(wid), (int) err); } - /* * Move a frame on screen. */ @@ -241,7 +253,6 @@ xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY) xprConfigureWindow(x_cvt_vptr_to_uint(wid), XP_ORIGIN, &wc); } - /* * Resize and move a frame. */ @@ -264,43 +275,46 @@ xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen, xprConfigureWindow(x_cvt_vptr_to_uint(wid), XP_BOUNDS, &wc); } - /* * Change frame stacking. */ -static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) { +static void +xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) +{ xp_window_changes wc; unsigned int mask = XP_STACKING; + #ifdef HAVE_LIBDISPATCH __block #endif - RootlessWindowRec *winRec; + RootlessWindowRec * winRec; /* Stack frame below nextWid it if it exists, or raise frame above everything otherwise. */ - if(nextWid == NULL) { + if (nextWid == NULL) { wc.stack_mode = XP_MAPPED_ABOVE; wc.sibling = 0; - } else { + } + else { wc.stack_mode = XP_MAPPED_BELOW; wc.sibling = x_cvt_vptr_to_uint(nextWid); } #ifdef HAVE_LIBDISPATCH - dispatch_sync(window_hash_serial_q, ^{ - winRec = x_hash_table_lookup(window_hash, wid, NULL); - }); + dispatch_sync(window_hash_serial_q, ^ { + winRec = x_hash_table_lookup(window_hash, wid, NULL);} + ); #else pthread_rwlock_rdlock(&window_hash_rwlock); winRec = x_hash_table_lookup(window_hash, wid, NULL); pthread_rwlock_unlock(&window_hash_rwlock); #endif - - if(winRec) { - if(XQuartzIsRootless) + + if (winRec) { + if (XQuartzIsRootless) wc.window_level = normal_window_levels[winRec->level]; - else if(XQuartzShieldingWindowLevel) + else if (XQuartzShieldingWindowLevel) wc.window_level = XQuartzShieldingWindowLevel + 1; else wc.window_level = rooted_window_levels[winRec->level]; @@ -310,7 +324,6 @@ static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) { xprConfigureWindow(x_cvt_vptr_to_uint(wid), mask, &wc); } - /* * Change the frame's shape. */ @@ -319,13 +332,11 @@ xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape) { xp_window_changes wc; - if (pShape != NULL) - { + if (pShape != NULL) { wc.shape_nrects = RegionNumRects(pShape); wc.shape_rects = RegionRects(pShape); } - else - { + else { wc.shape_nrects = -1; wc.shape_rects = NULL; } @@ -335,7 +346,6 @@ xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape) xprConfigureWindow(x_cvt_vptr_to_uint(wid), XP_SHAPE, &wc); } - /* * Unmap a frame. */ @@ -350,7 +360,6 @@ xprUnmapFrame(RootlessFrameID wid) xprConfigureWindow(x_cvt_vptr_to_uint(wid), XP_STACKING, &wc); } - /* * Start drawing to a frame. * Prepare for direct access to its backing buffer. @@ -362,15 +371,17 @@ xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow) unsigned int rowbytes[2]; xp_error err; - err = xp_lock_window(x_cvt_vptr_to_uint(wid), NULL, NULL, data, rowbytes, NULL); + err = + xp_lock_window(x_cvt_vptr_to_uint(wid), NULL, NULL, data, rowbytes, + NULL); if (err != Success) - FatalError("Could not lock window %d for drawing (%d).", (int)x_cvt_vptr_to_uint(wid), (int)err); + FatalError("Could not lock window %d for drawing (%d).", + (int) x_cvt_vptr_to_uint(wid), (int) err); *pixelData = data[0]; *bytesPerRow = rowbytes[0]; } - /* * Stop drawing to a frame. */ @@ -383,11 +394,11 @@ xprStopDrawing(RootlessFrameID wid, Bool flush) /* This should be a FatalError, but we started tripping over it. Make it a * FatalError after http://xquartz.macosforge.org/trac/ticket/482 is fixed. */ - if(err != Success) - ErrorF("Could not unlock window %d after drawing (%d).", (int)x_cvt_vptr_to_uint(wid), (int)err); + if (err != Success) + ErrorF("Could not unlock window %d after drawing (%d).", + (int) x_cvt_vptr_to_uint(wid), (int) err); } - /* * Flush drawing updates to the screen. */ @@ -397,18 +408,16 @@ xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage) xp_flush_window(x_cvt_vptr_to_uint(wid)); } - /* * Mark damaged rectangles as requiring redisplay to screen. */ static void -xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects, +xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec * rects, int shift_x, int shift_y) { xp_mark_window(x_cvt_vptr_to_uint(wid), nrects, rects, shift_x, shift_y); } - /* * Called after the window associated with a frame has been switched * to a new top-level parent. @@ -421,31 +430,29 @@ xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin) xprSetNativeProperty(pFrame); } - /* * Called to check if the frame should be reordered when it is restacked. */ -static Bool xprDoReorderWindow(RootlessWindowPtr pFrame) +static Bool +xprDoReorderWindow(RootlessWindowPtr pFrame) { WindowPtr pWin = pFrame->win; return AppleWMDoReorderWindow(pWin); } - /* * Copy area in frame to another part of frame. * Used to accelerate scrolling. */ static void -xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects, +xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec * dstRects, int dx, int dy) { xp_copy_window(x_cvt_vptr_to_uint(wid), x_cvt_vptr_to_uint(wid), dstNrects, dstRects, dx, dy); } - static RootlessFrameProcsRec xprRootlessProcs = { xprCreateFrame, xprDestroyFrame, @@ -466,7 +473,6 @@ static RootlessFrameProcsRec xprRootlessProcs = { xprCopyWindow }; - /* * Initialize XPR implementation */ @@ -480,15 +486,16 @@ xprInit(ScreenPtr pScreen) assert((window_hash = x_hash_table_new(NULL, NULL, NULL, NULL))); #ifdef HAVE_LIBDISPATCH - assert((window_hash_serial_q = dispatch_queue_create(BUNDLE_ID_PREFIX".X11.xpr_window_hash", NULL))); + assert((window_hash_serial_q = + dispatch_queue_create(BUNDLE_ID_PREFIX ".X11.xpr_window_hash", + NULL))); #else assert(0 == pthread_rwlock_init(&window_hash_rwlock, NULL)); #endif - + return TRUE; } - /* * Given the id of a physical window, try to find the top-level (or root) * X window that it represents. @@ -498,11 +505,14 @@ xprGetXWindow(xp_window_id wid) { #ifdef HAVE_LIBDISPATCH RootlessWindowRec *winRec __block; - dispatch_sync(window_hash_serial_q, ^{ - winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL); - }); + + dispatch_sync(window_hash_serial_q, ^ { + winRec = + x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), + NULL);}); #else RootlessWindowRec *winRec; + pthread_rwlock_rdlock(&window_hash_rwlock); winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL); pthread_rwlock_unlock(&window_hash_rwlock); @@ -529,7 +539,6 @@ xprIsX11Window(int windowNumber) return ret; } - /* * xprHideWindows * Hide or unhide all top level windows. This is called for application hide/ @@ -544,6 +553,7 @@ xprHideWindows(Bool hide) for (screen = 0; screen < screenInfo.numScreens; screen++) { RootlessFrameID prevWid = NULL; + pRoot = screenInfo.screens[screen]->root; for (pWin = pRoot->firstChild; pWin; pWin = pWin->nextSib) { @@ -552,7 +562,8 @@ xprHideWindows(Bool hide) if (winRec != NULL) { if (hide) { xprUnmapFrame(winRec->wid); - } else { + } + else { BoxRec box; xprRestackFrame(winRec->wid, prevWid); @@ -577,32 +588,35 @@ xprHideWindows(Bool hide) Bool no_configure_window; static inline int -configure_window (xp_window_id id, unsigned int mask, - const xp_window_changes *values) +configure_window(xp_window_id id, unsigned int mask, + const xp_window_changes * values) { - if (!no_configure_window) - return xp_configure_window (id, mask, values); - else - return XP_Success; + if (!no_configure_window) + return xp_configure_window(id, mask, values); + else + return XP_Success; } - static -void xprUpdateColormap(RootlessFrameID wid, ScreenPtr pScreen) + void +xprUpdateColormap(RootlessFrameID wid, ScreenPtr pScreen) { - /* This is how we tell xp that the colormap may have changed. */ - xp_window_changes wc; - wc.colormap = xprColormapCallback; - wc.colormap_data = pScreen; + /* This is how we tell xp that the colormap may have changed. */ + xp_window_changes wc; - configure_window(MAKE_WINDOW_ID(wid), XP_COLORMAP, &wc); + wc.colormap = xprColormapCallback; + wc.colormap_data = pScreen; + + configure_window(MAKE_WINDOW_ID(wid), XP_COLORMAP, &wc); } static -void xprHideWindow(RootlessFrameID wid) + void +xprHideWindow(RootlessFrameID wid) { - xp_window_changes wc; - wc.stack_mode = XP_UNMAPPED; - wc.sibling = 0; - configure_window(MAKE_WINDOW_ID(wid), XP_STACKING, &wc); + xp_window_changes wc; + + wc.stack_mode = XP_UNMAPPED; + wc.sibling = 0; + configure_window(MAKE_WINDOW_ID(wid), XP_STACKING, &wc); } diff --git a/xorg-server/hw/xquartz/xpr/xprScreen.c b/xorg-server/hw/xquartz/xpr/xprScreen.c index 002355eca..185369e6b 100644 --- a/xorg-server/hw/xquartz/xpr/xprScreen.c +++ b/xorg-server/hw/xquartz/xpr/xprScreen.c @@ -51,7 +51,7 @@ #include "rootlessCommon.h" #ifdef DAMAGE -# include "damage.h" +#include "damage.h" #endif /* 10.4's deferred update makes X slower.. have to live with the tearing @@ -65,61 +65,67 @@ static const char *xprOpenGLBundle = "glxCGL.bundle"; * eventHandler * Callback handler for Xplugin events. */ -static void eventHandler(unsigned int type, const void *arg, - unsigned int arg_size, void *data) { - +static void +eventHandler(unsigned int type, const void *arg, + unsigned int arg_size, void *data) +{ + switch (type) { - case XP_EVENT_DISPLAY_CHANGED: - DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n"); - DarwinSendDDXEvent(kXquartzDisplayChanged, 0); - break; - - case XP_EVENT_WINDOW_STATE_CHANGED: - if (arg_size >= sizeof(xp_window_state_event)) { - const xp_window_state_event *ws_arg = arg; - - DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: id=%d, state=%d\n", ws_arg->id, ws_arg->state); - DarwinSendDDXEvent(kXquartzWindowState, 2, - ws_arg->id, ws_arg->state); - } else { - DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: ignored\n"); - } - break; - - case XP_EVENT_WINDOW_MOVED: - DEBUG_LOG("XP_EVENT_WINDOW_MOVED\n"); - if (arg_size == sizeof(xp_window_id)) { - xp_window_id id = * (xp_window_id *) arg; - DarwinSendDDXEvent(kXquartzWindowMoved, 1, id); - } - break; - - case XP_EVENT_SURFACE_DESTROYED: - DEBUG_LOG("XP_EVENT_SURFACE_DESTROYED\n"); - case XP_EVENT_SURFACE_CHANGED: - DEBUG_LOG("XP_EVENT_SURFACE_CHANGED\n"); - if (arg_size == sizeof(xp_surface_id)) { - int kind; - - if (type == XP_EVENT_SURFACE_DESTROYED) - kind = AppleDRISurfaceNotifyDestroyed; - else - kind = AppleDRISurfaceNotifyChanged; - - DRISurfaceNotify(*(xp_surface_id *) arg, kind); - } - break; + case XP_EVENT_DISPLAY_CHANGED: + DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n"); + DarwinSendDDXEvent(kXquartzDisplayChanged, 0); + break; + + case XP_EVENT_WINDOW_STATE_CHANGED: + if (arg_size >= sizeof(xp_window_state_event)) { + const xp_window_state_event *ws_arg = arg; + + DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: id=%d, state=%d\n", + ws_arg->id, ws_arg->state); + DarwinSendDDXEvent(kXquartzWindowState, 2, ws_arg->id, + ws_arg->state); + } + else { + DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: ignored\n"); + } + break; + + case XP_EVENT_WINDOW_MOVED: + DEBUG_LOG("XP_EVENT_WINDOW_MOVED\n"); + if (arg_size == sizeof(xp_window_id)) { + xp_window_id id = *(xp_window_id *) arg; + + DarwinSendDDXEvent(kXquartzWindowMoved, 1, id); + } + break; + + case XP_EVENT_SURFACE_DESTROYED: + DEBUG_LOG("XP_EVENT_SURFACE_DESTROYED\n"); + case XP_EVENT_SURFACE_CHANGED: + DEBUG_LOG("XP_EVENT_SURFACE_CHANGED\n"); + if (arg_size == sizeof(xp_surface_id)) { + int kind; + + if (type == XP_EVENT_SURFACE_DESTROYED) + kind = AppleDRISurfaceNotifyDestroyed; + else + kind = AppleDRISurfaceNotifyChanged; + + DRISurfaceNotify(*(xp_surface_id *) arg, kind); + } + break; #ifdef XP_EVENT_SPACE_CHANGED - case XP_EVENT_SPACE_CHANGED: - DEBUG_LOG("XP_EVENT_SPACE_CHANGED\n"); - if(arg_size == sizeof(uint32_t)) { - uint32_t space_id = *(uint32_t *)arg; - DarwinSendDDXEvent(kXquartzSpaceChanged, 1, space_id); - } - break; + case XP_EVENT_SPACE_CHANGED: + DEBUG_LOG("XP_EVENT_SPACE_CHANGED\n"); + if (arg_size == sizeof(uint32_t)) { + uint32_t space_id = *(uint32_t *) arg; + + DarwinSendDDXEvent(kXquartzSpaceChanged, 1, space_id); + } + break; #endif - default: - ErrorF("Unknown XP_EVENT type (%d) in xprScreen:eventHandler\n", type); + default: + ErrorF("Unknown XP_EVENT type (%d) in xprScreen:eventHandler\n", type); } } @@ -132,7 +138,7 @@ displayAtIndex(int index) { CGError err; CGDisplayCount cnt; - CGDirectDisplayID dpy[index+1]; + CGDirectDisplayID dpy[index + 1]; err = CGGetActiveDisplayList(index + 1, dpy, &cnt); if (err == kCGErrorSuccess && cnt == index + 1) @@ -153,19 +159,18 @@ displayScreenBounds(CGDirectDisplayID id) frame = CGDisplayBounds(id); DEBUG_LOG(" %dx%d @ (%d,%d).\n", - (int)frame.size.width, (int)frame.size.height, - (int)frame.origin.x, (int)frame.origin.y); - + (int) frame.size.width, (int) frame.size.height, + (int) frame.origin.x, (int) frame.origin.y); + /* Remove menubar to help standard X11 window managers. */ - if (XQuartzIsRootless && - frame.origin.x == 0 && frame.origin.y == 0) { + if (XQuartzIsRootless && frame.origin.x == 0 && frame.origin.y == 0) { frame.origin.y += aquaMenuBarHeight; frame.size.height -= aquaMenuBarHeight; } DEBUG_LOG(" %dx%d @ (%d,%d).\n", - (int)frame.size.width, (int)frame.size.height, - (int)frame.origin.x, (int)frame.origin.y); + (int) frame.size.width, (int) frame.size.height, + (int) frame.origin.x, (int) frame.origin.y); return frame; } @@ -176,7 +181,8 @@ displayScreenBounds(CGDirectDisplayID id) * with PseudoramiX. */ static void -xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, ScreenPtr pScreen) +xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, + ScreenPtr pScreen) { CGDisplayCount i, displayCount; CGDirectDisplayID *displayList = NULL; @@ -184,10 +190,11 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, ScreenPtr pScr // Find all the CoreGraphics displays CGGetActiveDisplayList(0, NULL, &displayCount); - DEBUG_LOG("displayCount: %d\n", (int)displayCount); + DEBUG_LOG("displayCount: %d\n", (int) displayCount); - if(!displayCount) { - ErrorF("CoreGraphics has reported no connected displays. Creating a stub 800x600 display.\n"); + if (!displayCount) { + ErrorF + ("CoreGraphics has reported no connected displays. Creating a stub 800x600 display.\n"); *x = *y = 0; *width = 800; *height = 600; @@ -204,7 +211,7 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, ScreenPtr pScr displayCount = 1; displayList = malloc(displayCount * sizeof(CGDirectDisplayID)); - if(!displayList) + if (!displayList) FatalError("Unable to allocate memory for list of displays.\n"); CGGetActiveDisplayList(displayCount, displayList, &displayCount); QuartzCopyDisplayIDs(pScreen, displayCount, displayList); @@ -212,6 +219,7 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, ScreenPtr pScr /* Get the union of all screens */ for (i = 0; i < displayCount; i++) { CGDirectDisplayID dpy = displayList[i]; + frame = displayScreenBounds(dpy); unionRect = CGRectUnion(unionRect, frame); } @@ -226,8 +234,7 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, ScreenPtr pScr *x, *y, *width, *height); /* Tell PseudoramiX about the real screens. */ - for (i = 0; i < displayCount; i++) - { + for (i = 0; i < displayCount; i++) { CGDirectDisplayID dpy = displayList[i]; frame = displayScreenBounds(dpy); @@ -235,7 +242,7 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, ScreenPtr pScr frame.origin.y -= unionRect.origin.y; DEBUG_LOG(" placed at X11 coordinate (%d,%d).\n", - (int)frame.origin.x, (int)frame.origin.y); + (int) frame.origin.x, (int) frame.origin.y); PseudoramiXAddScreen(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); @@ -263,20 +270,18 @@ xprDisplayInit(void) if (noPseudoramiXExtension) darwinScreensFound = displayCount; else - darwinScreensFound = 1; + darwinScreensFound = 1; if (xp_init(XP_BACKGROUND_EVENTS | XP_NO_DEFERRED_UPDATES) != Success) FatalError("Could not initialize the Xplugin library."); xp_select_events(XP_EVENT_DISPLAY_CHANGED - | XP_EVENT_WINDOW_STATE_CHANGED - | XP_EVENT_WINDOW_MOVED + | XP_EVENT_WINDOW_STATE_CHANGED | XP_EVENT_WINDOW_MOVED #ifdef XP_EVENT_SPACE_CHANGED | XP_EVENT_SPACE_CHANGED #endif | XP_EVENT_SURFACE_CHANGED - | XP_EVENT_SURFACE_DESTROYED, - eventHandler, NULL); + | XP_EVENT_SURFACE_DESTROYED, eventHandler, NULL); AppleDRIExtensionInit(); xprAppleWMInit(); @@ -297,81 +302,92 @@ xprAddScreen(int index, ScreenPtr pScreen) int depth = darwinDesiredDepth; DEBUG_LOG("index=%d depth=%d\n", index, depth); - - if(depth == -1) { + + if (depth == -1) { #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - depth = CGDisplaySamplesPerPixel(kCGDirectMainDisplay) * CGDisplayBitsPerSample(kCGDirectMainDisplay); + depth = + CGDisplaySamplesPerPixel(kCGDirectMainDisplay) * + CGDisplayBitsPerSample(kCGDirectMainDisplay); #else CGDisplayModeRef modeRef; CFStringRef encStrRef; - + modeRef = CGDisplayCopyDisplayMode(kCGDirectMainDisplay); - if(!modeRef) + if (!modeRef) goto have_depth; encStrRef = CGDisplayModeCopyPixelEncoding(modeRef); CFRelease(modeRef); - if(!encStrRef) + if (!encStrRef) goto have_depth; - - if(CFStringCompare(encStrRef, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + + if (CFStringCompare + (encStrRef, CFSTR(IO32BitDirectPixels), + kCFCompareCaseInsensitive) == kCFCompareEqualTo) { depth = 24; - } else if(CFStringCompare(encStrRef, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + } + else if (CFStringCompare + (encStrRef, CFSTR(IO16BitDirectPixels), + kCFCompareCaseInsensitive) == kCFCompareEqualTo) { depth = 15; - } else if(CFStringCompare(encStrRef, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + } + else if (CFStringCompare + (encStrRef, CFSTR(IO8BitIndexedPixels), + kCFCompareCaseInsensitive) == kCFCompareEqualTo) { depth = 8; } CFRelease(encStrRef); #endif } - + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 -have_depth: + have_depth: #endif - switch(depth) { - case 8: // pseudo-working - dfb->visuals = PseudoColorMask; - dfb->preferredCVC = PseudoColor; - dfb->depth = 8; - dfb->bitsPerRGB = 8; - dfb->bitsPerPixel = 8; - dfb->redMask = 0; - dfb->greenMask = 0; - dfb->blueMask = 0; - break; - case 15: - dfb->visuals = TrueColorMask; //LARGE_VISUALS; - dfb->preferredCVC = TrueColor; - dfb->depth = 15; - dfb->bitsPerRGB = 5; - dfb->bitsPerPixel = 16; - dfb->redMask = RM_ARGB(0,5,5,5); - dfb->greenMask = GM_ARGB(0,5,5,5); - dfb->blueMask = BM_ARGB(0,5,5,5); - break; + switch (depth) { + case 8: // pseudo-working + dfb->visuals = PseudoColorMask; + dfb->preferredCVC = PseudoColor; + dfb->depth = 8; + dfb->bitsPerRGB = 8; + dfb->bitsPerPixel = 8; + dfb->redMask = 0; + dfb->greenMask = 0; + dfb->blueMask = 0; + break; + case 15: + dfb->visuals = TrueColorMask; //LARGE_VISUALS; + dfb->preferredCVC = TrueColor; + dfb->depth = 15; + dfb->bitsPerRGB = 5; + dfb->bitsPerPixel = 16; + dfb->redMask = RM_ARGB(0, 5, 5, 5); + dfb->greenMask = GM_ARGB(0, 5, 5, 5); + dfb->blueMask = BM_ARGB(0, 5, 5, 5); + break; // case 24: - default: - if(depth != 24) - ErrorF("Unsupported color depth requested. Defaulting to 24bit. (depth=%d darwinDesiredDepth=%d)\n", depth, darwinDesiredDepth); - dfb->visuals = TrueColorMask; //LARGE_VISUALS; - dfb->preferredCVC = TrueColor; - dfb->depth = 24; - dfb->bitsPerRGB = 8; - dfb->bitsPerPixel = 32; - dfb->redMask = RM_ARGB(0,8,8,8); - dfb->greenMask = GM_ARGB(0,8,8,8); - dfb->blueMask = BM_ARGB(0,8,8,8); - break; + default: + if (depth != 24) + ErrorF + ("Unsupported color depth requested. Defaulting to 24bit. (depth=%d darwinDesiredDepth=%d)\n", + depth, darwinDesiredDepth); + dfb->visuals = TrueColorMask; //LARGE_VISUALS; + dfb->preferredCVC = TrueColor; + dfb->depth = 24; + dfb->bitsPerRGB = 8; + dfb->bitsPerPixel = 32; + dfb->redMask = RM_ARGB(0, 8, 8, 8); + dfb->greenMask = GM_ARGB(0, 8, 8, 8); + dfb->blueMask = BM_ARGB(0, 8, 8, 8); + break; } - if (noPseudoramiXExtension) - { + if (noPseudoramiXExtension) { CGDirectDisplayID dpy; CGRect frame; ErrorF("Warning: noPseudoramiXExtension!\n"); - + dpy = displayAtIndex(index); QuartzCopyDisplayIDs(pScreen, 1, &dpy); @@ -379,12 +395,12 @@ have_depth: dfb->x = frame.origin.x; dfb->y = frame.origin.y; - dfb->width = frame.size.width; + dfb->width = frame.size.width; dfb->height = frame.size.height; } - else - { - xprAddPseudoramiXScreens(&dfb->x, &dfb->y, &dfb->width, &dfb->height, pScreen); + else { + xprAddPseudoramiXScreens(&dfb->x, &dfb->y, &dfb->width, &dfb->height, + pScreen); } /* Passing zero width (pitch) makes miCreateScreenResources set the |