Add patch that contain Mali fixes.
[deb_xorg-server.git] / Xi / xiwarppointer.c
CommitLineData
a09e091a
JB
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
56SProcXIWarpPointer(ClientPtr client)
57{
58 REQUEST(xXIWarpPointerReq);
59 swaps(&stuff->length);
60 swapl(&stuff->src_win);
61 swapl(&stuff->dst_win);
62 swapl(&stuff->src_x);
63 swapl(&stuff->src_y);
64 swaps(&stuff->src_width);
65 swaps(&stuff->src_height);
66 swapl(&stuff->dst_x);
67 swapl(&stuff->dst_y);
68 swaps(&stuff->deviceid);
69 return (ProcXIWarpPointer(client));
70}
71
72int
73ProcXIWarpPointer(ClientPtr client)
74{
75 int rc;
76 int x, y;
77 WindowPtr dest = NULL;
78 DeviceIntPtr pDev;
79 SpritePtr pSprite;
80 ScreenPtr newScreen;
81 int src_x, src_y;
82 int dst_x, dst_y;
83
84 REQUEST(xXIWarpPointerReq);
85 REQUEST_SIZE_MATCH(xXIWarpPointerReq);
86
87 /* FIXME: panoramix stuff is missing, look at ProcWarpPointer */
88
89 rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixWriteAccess);
90
91 if (rc != Success) {
92 client->errorValue = stuff->deviceid;
93 return rc;
94 }
95
96 if ((!IsMaster(pDev) && !IsFloating(pDev)) ||
97 (IsMaster(pDev) && !IsPointerDevice(pDev))) {
98 client->errorValue = stuff->deviceid;
99 return BadDevice;
100 }
101
102 if (stuff->dst_win != None) {
103 rc = dixLookupWindow(&dest, stuff->dst_win, client, DixGetAttrAccess);
104 if (rc != Success) {
105 client->errorValue = stuff->dst_win;
106 return rc;
107 }
108 }
109
110 pSprite = pDev->spriteInfo->sprite;
111 x = pSprite->hotPhys.x;
112 y = pSprite->hotPhys.y;
113
114 src_x = stuff->src_x / (double) (1 << 16);
115 src_y = stuff->src_y / (double) (1 << 16);
116 dst_x = stuff->dst_x / (double) (1 << 16);
117 dst_y = stuff->dst_y / (double) (1 << 16);
118
119 if (stuff->src_win != None) {
120 int winX, winY;
121 WindowPtr src;
122
123 rc = dixLookupWindow(&src, stuff->src_win, client, DixGetAttrAccess);
124 if (rc != Success) {
125 client->errorValue = stuff->src_win;
126 return rc;
127 }
128
129 winX = src->drawable.x;
130 winY = src->drawable.y;
131 if (src->drawable.pScreen != pSprite->hotPhys.pScreen ||
132 x < winX + src_x ||
133 y < winY + src_y ||
134 (stuff->src_width != 0 &&
135 winX + src_x + (int) stuff->src_width < 0) ||
136 (stuff->src_height != 0 &&
137 winY + src_y + (int) stuff->src_height < y) ||
138 !PointInWindowIsVisible(src, x, y))
139 return Success;
140 }
141
142 if (dest) {
143 x = dest->drawable.x;
144 y = dest->drawable.y;
145 newScreen = dest->drawable.pScreen;
146 }
147 else
148 newScreen = pSprite->hotPhys.pScreen;
149
150 x += dst_x;
151 y += dst_y;
152
153 if (x < 0)
154 x = 0;
155 else if (x > newScreen->width)
156 x = newScreen->width - 1;
157
158 if (y < 0)
159 y = 0;
160 else if (y > newScreen->height)
161 y = newScreen->height - 1;
162
163 if (newScreen == pSprite->hotPhys.pScreen) {
164 if (x < pSprite->physLimits.x1)
165 x = pSprite->physLimits.x1;
166 else if (x >= pSprite->physLimits.x2)
167 x = pSprite->physLimits.x2 - 1;
168
169 if (y < pSprite->physLimits.y1)
170 y = pSprite->physLimits.y1;
171 else if (y >= pSprite->physLimits.y2)
172 y = pSprite->physLimits.y2 - 1;
173
174 if (pSprite->hotShape)
175 ConfineToShape(pDev, pSprite->hotShape, &x, &y);
176 (*newScreen->SetCursorPosition) (pDev, newScreen, x, y, TRUE);
177 }
178 else if (!PointerConfinedToScreen(pDev)) {
179 NewCurrentScreen(pDev, newScreen, x, y);
180 }
181
182 /* if we don't update the device, we get a jump next time it moves */
183 pDev->last.valuators[0] = x;
184 pDev->last.valuators[1] = y;
185 miPointerUpdateSprite(pDev);
186
187 /* FIXME: XWarpPointer is supposed to generate an event. It doesn't do it
188 here though. */
189 return Success;
190}