xiwarppointer.c revision 7e31ba66
1/* 2 * Copyright 2007-2008 Peter Hutterer 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 * 23 * Author: Peter Hutterer, University of South Australia, NICTA 24 */ 25 26/*********************************************************************** 27 * 28 * Request to Warp the pointer location of an extension input device. 29 * 30 */ 31 32#ifdef HAVE_DIX_CONFIG_H 33#include <dix-config.h> 34#endif 35 36#include <X11/X.h> /* for inputstr.h */ 37#include <X11/Xproto.h> /* Request macro */ 38#include "inputstr.h" /* DeviceIntPtr */ 39#include "windowstr.h" /* window structure */ 40#include "scrnintstr.h" /* screen structure */ 41#include <X11/extensions/XI.h> 42#include <X11/extensions/XI2proto.h> 43#include "extnsionst.h" 44#include "exevents.h" 45#include "exglobals.h" 46#include "mipointer.h" /* for miPointerUpdateSprite */ 47 48#include "xiwarppointer.h" 49/*********************************************************************** 50 * 51 * This procedure allows a client to warp the pointer of a device. 52 * 53 */ 54 55int _X_COLD 56SProcXIWarpPointer(ClientPtr client) 57{ 58 REQUEST(xXIWarpPointerReq); 59 REQUEST_SIZE_MATCH(xXIWarpPointerReq); 60 61 swaps(&stuff->length); 62 swapl(&stuff->src_win); 63 swapl(&stuff->dst_win); 64 swapl(&stuff->src_x); 65 swapl(&stuff->src_y); 66 swaps(&stuff->src_width); 67 swaps(&stuff->src_height); 68 swapl(&stuff->dst_x); 69 swapl(&stuff->dst_y); 70 swaps(&stuff->deviceid); 71 return (ProcXIWarpPointer(client)); 72} 73 74int 75ProcXIWarpPointer(ClientPtr client) 76{ 77 int rc; 78 int x, y; 79 WindowPtr dest = NULL; 80 DeviceIntPtr pDev; 81 SpritePtr pSprite; 82 ScreenPtr newScreen; 83 int src_x, src_y; 84 int dst_x, dst_y; 85 86 REQUEST(xXIWarpPointerReq); 87 REQUEST_SIZE_MATCH(xXIWarpPointerReq); 88 89 /* FIXME: panoramix stuff is missing, look at ProcWarpPointer */ 90 91 rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixWriteAccess); 92 93 if (rc != Success) { 94 client->errorValue = stuff->deviceid; 95 return rc; 96 } 97 98 if ((!IsMaster(pDev) && !IsFloating(pDev)) || 99 (IsMaster(pDev) && !IsPointerDevice(pDev))) { 100 client->errorValue = stuff->deviceid; 101 return BadDevice; 102 } 103 104 if (stuff->dst_win != None) { 105 rc = dixLookupWindow(&dest, stuff->dst_win, client, DixGetAttrAccess); 106 if (rc != Success) { 107 client->errorValue = stuff->dst_win; 108 return rc; 109 } 110 } 111 112 pSprite = pDev->spriteInfo->sprite; 113 x = pSprite->hotPhys.x; 114 y = pSprite->hotPhys.y; 115 116 src_x = stuff->src_x / (double) (1 << 16); 117 src_y = stuff->src_y / (double) (1 << 16); 118 dst_x = stuff->dst_x / (double) (1 << 16); 119 dst_y = stuff->dst_y / (double) (1 << 16); 120 121 if (stuff->src_win != None) { 122 int winX, winY; 123 WindowPtr src; 124 125 rc = dixLookupWindow(&src, stuff->src_win, client, DixGetAttrAccess); 126 if (rc != Success) { 127 client->errorValue = stuff->src_win; 128 return rc; 129 } 130 131 winX = src->drawable.x; 132 winY = src->drawable.y; 133 if (src->drawable.pScreen != pSprite->hotPhys.pScreen || 134 x < winX + src_x || 135 y < winY + src_y || 136 (stuff->src_width != 0 && 137 winX + src_x + (int) stuff->src_width < 0) || 138 (stuff->src_height != 0 && 139 winY + src_y + (int) stuff->src_height < y) || 140 !PointInWindowIsVisible(src, x, y)) 141 return Success; 142 } 143 144 if (dest) { 145 x = dest->drawable.x; 146 y = dest->drawable.y; 147 newScreen = dest->drawable.pScreen; 148 } 149 else 150 newScreen = pSprite->hotPhys.pScreen; 151 152 x += dst_x; 153 y += dst_y; 154 155 if (x < 0) 156 x = 0; 157 else if (x > newScreen->width) 158 x = newScreen->width - 1; 159 160 if (y < 0) 161 y = 0; 162 else if (y > newScreen->height) 163 y = newScreen->height - 1; 164 165 if (newScreen == pSprite->hotPhys.pScreen) { 166 if (x < pSprite->physLimits.x1) 167 x = pSprite->physLimits.x1; 168 else if (x >= pSprite->physLimits.x2) 169 x = pSprite->physLimits.x2 - 1; 170 171 if (y < pSprite->physLimits.y1) 172 y = pSprite->physLimits.y1; 173 else if (y >= pSprite->physLimits.y2) 174 y = pSprite->physLimits.y2 - 1; 175 176 if (pSprite->hotShape) 177 ConfineToShape(pDev, pSprite->hotShape, &x, &y); 178 (*newScreen->SetCursorPosition) (pDev, newScreen, x, y, TRUE); 179 } 180 else if (!PointerConfinedToScreen(pDev)) { 181 NewCurrentScreen(pDev, newScreen, x, y); 182 } 183 184 /* if we don't update the device, we get a jump next time it moves */ 185 pDev->last.valuators[0] = x; 186 pDev->last.valuators[1] = y; 187 miPointerUpdateSprite(pDev); 188 189 if (*newScreen->CursorWarpedTo) 190 (*newScreen->CursorWarpedTo) (pDev, newScreen, client, 191 dest, pSprite, x, y); 192 193 /* FIXME: XWarpPointer is supposed to generate an event. It doesn't do it 194 here though. */ 195 return Success; 196} 197