1/* 2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 3 * Copyright 2010 Red Hat, Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 * 24 * Copyright © 2002 Keith Packard 25 * 26 * Permission to use, copy, modify, distribute, and sell this software and its 27 * documentation for any purpose is hereby granted without fee, provided that 28 * the above copyright notice appear in all copies and that both that 29 * copyright notice and this permission notice appear in supporting 30 * documentation, and that the name of Keith Packard not be used in 31 * advertising or publicity pertaining to distribution of the software without 32 * specific, written prior permission. Keith Packard makes no 33 * representations about the suitability of this software for any purpose. It 34 * is provided "as is" without express or implied warranty. 35 * 36 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 37 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 38 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 39 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 40 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 41 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 42 * PERFORMANCE OF THIS SOFTWARE. 43 */ 44 45#ifdef HAVE_DIX_CONFIG_H 46#include <dix-config.h> 47#endif 48 49#include "xfixesint.h" 50#include "opaque.h" 51 52static DevPrivateKeyRec ClientDisconnectPrivateKeyRec; 53 54#define ClientDisconnectPrivateKey (&ClientDisconnectPrivateKeyRec) 55 56typedef struct _ClientDisconnect { 57 int disconnect_mode; 58} ClientDisconnectRec, *ClientDisconnectPtr; 59 60#define GetClientDisconnect(s) \ 61 ((ClientDisconnectPtr) dixLookupPrivate(&(s)->devPrivates, \ 62 ClientDisconnectPrivateKey)) 63 64int 65ProcXFixesSetClientDisconnectMode(ClientPtr client) 66{ 67 ClientDisconnectPtr pDisconnect = GetClientDisconnect(client); 68 69 REQUEST(xXFixesSetClientDisconnectModeReq); 70 REQUEST_SIZE_MATCH(xXFixesSetClientDisconnectModeReq); 71 72 pDisconnect->disconnect_mode = stuff->disconnect_mode; 73 74 return Success; 75} 76 77int _X_COLD 78SProcXFixesSetClientDisconnectMode(ClientPtr client) 79{ 80 REQUEST(xXFixesSetClientDisconnectModeReq); 81 82 swaps(&stuff->length); 83 84 REQUEST_SIZE_MATCH(xXFixesSetClientDisconnectModeReq); 85 86 swapl(&stuff->disconnect_mode); 87 88 return (*ProcXFixesVector[stuff->xfixesReqType]) (client); 89} 90 91int 92ProcXFixesGetClientDisconnectMode(ClientPtr client) 93{ 94 ClientDisconnectPtr pDisconnect = GetClientDisconnect(client); 95 xXFixesGetClientDisconnectModeReply reply; 96 97 REQUEST_SIZE_MATCH(xXFixesGetClientDisconnectModeReq); 98 99 reply = (xXFixesGetClientDisconnectModeReply) { 100 .type = X_Reply, 101 .sequenceNumber = client->sequence, 102 .length = 0, 103 .disconnect_mode = pDisconnect->disconnect_mode, 104 }; 105 if (client->swapped) { 106 swaps(&reply.sequenceNumber); 107 swapl(&reply.disconnect_mode); 108 } 109 WriteToClient(client, sizeof(xXFixesGetClientDisconnectModeReply), &reply); 110 111 return Success; 112} 113 114int _X_COLD 115SProcXFixesGetClientDisconnectMode(ClientPtr client) 116{ 117 REQUEST(xXFixesGetClientDisconnectModeReq); 118 119 swaps(&stuff->length); 120 121 REQUEST_SIZE_MATCH(xXFixesGetClientDisconnectModeReq); 122 123 return (*ProcXFixesVector[stuff->xfixesReqType]) (client); 124} 125 126Bool 127XFixesShouldDisconnectClient(ClientPtr client) 128{ 129 ClientDisconnectPtr pDisconnect = GetClientDisconnect(client); 130 131 if (!pDisconnect) 132 return FALSE; 133 134 if (dispatchExceptionAtReset & DE_TERMINATE) 135 return (pDisconnect->disconnect_mode & XFixesClientDisconnectFlagTerminate); 136 137 return FALSE; 138} 139 140Bool 141XFixesClientDisconnectInit(void) 142{ 143 if (!dixRegisterPrivateKey(&ClientDisconnectPrivateKeyRec, 144 PRIVATE_CLIENT, sizeof(ClientDisconnectRec))) 145 return FALSE; 146 147 return TRUE; 148} 149