summaryrefslogtreecommitdiffstats
path: root/contrib/packages/rpm/el5/SOURCES/xserver-1.7.7-randr-cursor-dead-zones.patch
blob: 975b1cd066aa058ccdfbf886b759f90646efbc86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
From ca589bdc757401aebd7daa0dafaa860b5c8ec15a Mon Sep 17 00:00:00 2001
From: Adam Jackson <ajax@redhat.com>
Date: Thu, 5 Aug 2010 13:45:22 -0400
Subject: [PATCH 1/2] randr: Add additional cursor constraint logic

Signed-off-by: Adam Jackson <ajax@redhat.com>
---
 include/scrnintstr.h |   11 +++-
 mi/mibstore.c        |    1 -
 mi/mipointer.c       |    3 +
 mi/mipointrst.h      |    4 +-
 mi/miscrinit.c       |    1 -
 randr/randr.c        |    2 +
 randr/randrstr.h     |    4 +
 randr/rrcrtc.c       |  186 ++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 207 insertions(+), 5 deletions(-)

diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index ab50e7a..1e2d645 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -446,6 +446,11 @@ typedef    void (* DeviceCursorCleanupProcPtr)(
         DeviceIntPtr /* pDev */,
         ScreenPtr    /* pScreen */);
 
+typedef struct _miPointer *miPointerPtr;
+
+typedef void (*ConstrainCursorHarderProcPtr)(
+	miPointerPtr, ScreenPtr, int *, int *);
+
 typedef struct _Screen {
     int			myNum;	/* index of this instance in Screens[] */
     ATOM		id;
@@ -506,9 +511,13 @@ typedef struct _Screen {
     CreatePixmapProcPtr		CreatePixmap;
     DestroyPixmapProcPtr	DestroyPixmap;
 
-    /* Backing store procedures */
+    /* Reuse the SDA slot for CCH for minimal ABI hassle */
+    ConstrainCursorHarderProcPtr ConstrainCursorHarder;
 
+    /* Backing store procedures */
+#if 0
     SaveDoomedAreasProcPtr	SaveDoomedAreas;
+#endif
     RestoreAreasProcPtr		RestoreAreas;
     ExposeCopyProcPtr		ExposeCopy;
     TranslateBackingStoreProcPtr TranslateBackingStore;
diff --git a/mi/mibstore.c b/mi/mibstore.c
index 262b494..1388189 100644
--- a/mi/mibstore.c
+++ b/mi/mibstore.c
@@ -40,7 +40,6 @@
 void
 miInitializeBackingStore (ScreenPtr pScreen)
 {
-    pScreen->SaveDoomedAreas = NULL;
     pScreen->RestoreAreas = NULL;
     pScreen->ExposeCopy = NULL;
     pScreen->TranslateBackingStore = NULL;
diff --git a/mi/mipointer.c b/mi/mipointer.c
index e1f63be..3c4552a 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -534,6 +534,9 @@ miPointerSetPosition(DeviceIntPtr pDev, int *x, int *y)
     if (*y >= pPointer->limits.y2)
 	*y = pPointer->limits.y2 - 1;
 
+    if (pScreen->ConstrainCursorHarder)
+	pScreen->ConstrainCursorHarder(pPointer, pScreen, x, y);
+
     if (pPointer->x == *x && pPointer->y == *y && 
             pPointer->pScreen == pScreen) 
         return;
diff --git a/mi/mipointrst.h b/mi/mipointrst.h
index bd9c24a..f643c01 100644
--- a/mi/mipointrst.h
+++ b/mi/mipointrst.h
@@ -35,7 +35,7 @@ in this Software without prior written authorization from The Open Group.
 #include "mipointer.h"
 #include "scrnintstr.h"
 
-typedef struct {
+typedef struct _miPointer {
     ScreenPtr		    pScreen;    /* current screen */
     ScreenPtr		    pSpriteScreen;/* screen containing current sprite */
     CursorPtr		    pCursor;    /* current cursor */
@@ -44,7 +44,7 @@ typedef struct {
     Bool		    confined;	/* pointer can't change screens */
     int			    x, y;	/* hot spot location */
     int			    devx, devy;	/* sprite position */
-} miPointerRec, *miPointerPtr;
+} miPointerRec /* , *miPointerPtr */;
 
 typedef struct {
     miPointerSpriteFuncPtr  spriteFuncs;	/* sprite-specific methods */
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index 96113d6..71a3e07 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -281,7 +281,6 @@ miScreenInit(
     pScreen->SetShape = miSetShape;
     pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow;
 
-    pScreen->SaveDoomedAreas = 0;
     pScreen->RestoreAreas = 0;
     pScreen->ExposeCopy = 0;
     pScreen->TranslateBackingStore = 0;
diff --git a/randr/randr.c b/randr/randr.c
index a21753f..3489d7e 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -269,6 +269,8 @@ Bool RRScreenInit(ScreenPtr pScreen)
     
     wrap (pScrPriv, pScreen, CloseScreen, RRCloseScreen);
 
+    pScreen->ConstrainCursorHarder = RRConstrainCursorHarder;
+
     pScrPriv->numOutputs = 0;
     pScrPriv->outputs = NULL;
     pScrPriv->numCrtcs = 0;
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 975fe33..e30dfd0 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -299,6 +299,7 @@ typedef struct _rrScrPriv {
     int			    rate;
     int			    size;
 #endif
+    Bool		    discontiguous;
 } rrScrPrivRec, *rrScrPrivPtr;
 
 extern _X_EXPORT DevPrivateKey rrPrivKey;
@@ -731,6 +732,9 @@ ProcRRGetPanning (ClientPtr client);
 int
 ProcRRSetPanning (ClientPtr client);
 
+void
+RRConstrainCursorHarder (miPointerPtr, ScreenPtr, int *, int *);
+
 /* rrdispatch.c */
 extern _X_EXPORT Bool
 RRClientKnowsRates (ClientPtr	pClient);
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 0e14b36..2a4f884 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2006 Keith Packard
+ * Copyright 2010 Red Hat, Inc
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -23,6 +24,7 @@
 #include "randrstr.h"
 #include "swaprep.h"
 #include "registry.h"
+#include "mipointrst.h"
 
 RESTYPE	RRCrtcType;
 
@@ -295,6 +297,102 @@ RRCrtcPendingProperties (RRCrtcPtr crtc)
     return FALSE;
 }
 
+/* overlapping counts as adjacent */
+static Bool
+crtcs_adjacent(const RRCrtcPtr a, const RRCrtcPtr b)
+{
+    int al = a->x, ar = a->x + a->mode->mode.width;
+    int bl = b->x, br = b->x + b->mode->mode.width;
+    int at = a->y, ab = a->y + a->mode->mode.height;
+    int bt = b->y, bb = b->y + b->mode->mode.height;
+
+    int cl = max(al, bl);
+    int cr = min(ar, br);
+    int ct = max(at, ct);
+    int cb = min(ab, bb);
+
+    return (cl <= cr) && (ct <= cb);
+}
+
+/*
+ * This isn't really multiplication, but we don't need it to be.  All
+ * we need is a boolean for connectivity, not an integer for number of
+ * paths.  As a result we can scale to gratuitously large n without
+ * worrying about integer overflow.
+ */
+static Bool
+matrix_pseudomultiply(char *left, const char *right, int n)
+{
+    int i, j, k;
+    char *res = calloc(1, n * n);
+
+    if (!res)
+	return FALSE;
+
+    for (i = 0; i < n; i++)
+	for (j = 0; j < n; j++)
+	    for (k = 0; k < n; k++)
+		res[i*n + j] |= left[i*n + k] && right[k*n + j];
+
+    memcpy(left, res, n * n);
+
+    free(res);
+
+    return TRUE;
+}
+
+static void
+RRComputeContiguity (ScreenPtr pScreen)
+{
+    rrScrPriv(pScreen);
+    Bool discontiguous = TRUE;
+    int i, j, n = pScrPriv->numCrtcs;
+    RRCrtcPtr a, b;
+    char *matrix = NULL, *m = NULL;
+
+    matrix = calloc(1, n*n);
+    m = calloc(1, n*n);
+    if (!matrix || !m)
+	goto out;
+
+    /* compute adjacency matrix; everything is adjacent with itself */
+    for (i = 0; i < n; i++) {
+	a = pScrPriv->crtcs[i];
+
+	if (!a->mode)
+	    continue;
+
+	for (j = 0; j < n; j++) {
+	    b = pScrPriv->crtcs[j];
+
+	    if (!b->mode)
+		continue;
+
+	    if (a == b || crtcs_adjacent(a, b))
+		matrix[i*n + j] = 1;
+	}
+    }
+
+    memcpy(m, matrix, n*n);
+
+    /* raise it to the n-1th; finds connected paths */
+    for (i = 0; i < n-1; i++)
+	if (!matrix_pseudomultiply(m, matrix, n))
+	    goto out;
+
+    /* check for connectivity */
+    for (i = 0; i < n; i++)
+	if (pScrPriv->crtcs[i]->mode && !m[i])
+	    goto out;
+
+    discontiguous = FALSE;
+
+out:
+    free(matrix);
+    free(m);
+    pScrPriv->discontiguous = discontiguous;
+}
+
 /*
  * Request that the Crtc be reconfigured
  */
@@ -309,6 +407,7 @@ RRCrtcSet (RRCrtcPtr    crtc,
 {
     ScreenPtr	pScreen = crtc->pScreen;
     Bool	ret = FALSE;
+    Bool	recompute = TRUE;
     rrScrPriv(pScreen);
 
     /* See if nothing changed */
@@ -322,6 +421,7 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	!RRCrtcPendingTransform (crtc))
     {
 	ret = TRUE;
+	recompute = FALSE;
     }
     else
     {
@@ -384,6 +484,10 @@ RRCrtcSet (RRCrtcPtr    crtc,
 		RRPostPendingProperties (outputs[o]);
 	}
     }
+
+    if (recompute)
+	RRComputeContiguity(pScreen);
+
     return ret;
 }
 
@@ -1387,3 +1491,85 @@ ProcRRGetCrtcTransform (ClientPtr client)
     xfree(reply);
     return client->noClientException;
 }
+
+static void
+crtc_bounds(RRCrtcPtr crtc, int *left, int *right, int *top, int *bottom)
+{
+    *left = crtc->x;
+    *top = crtc->y;
+
+    switch (crtc->rotation) {
+    case RR_Rotate_0:
+    case RR_Rotate_180:
+	*right = crtc->x + crtc->mode->mode.width;
+	*bottom = crtc->y + crtc->mode->mode.height;
+	return;
+    case RR_Rotate_90:
+    case RR_Rotate_270:
+	*right = crtc->x + crtc->mode->mode.height;
+	*bottom = crtc->y + crtc->mode->mode.width;
+    default:
+	return;
+    }
+}
+
+void
+RRConstrainCursorHarder(miPointerPtr pDev, ScreenPtr pScreen, int *x, int *y)
+{
+    rrScrPriv (pScreen);
+    int i;
+
+    /* intentional dead space -> let it float */
+    if (pScrPriv->discontiguous)
+	return;
+
+    /* if we're moving inside a crtc, we're fine */
+    for (i = 0; i < pScrPriv->numCrtcs; i++) {
+	RRCrtcPtr crtc = pScrPriv->crtcs[i];
+
+	int left, right, top, bottom;
+
+	if (!crtc->mode)
+	    continue;
+
+	crtc_bounds(crtc, &left, &right, &top, &bottom);
+
+	if ((*x >= left) && (*x <= right) && (*y >= top) && (*y <= bottom))
+	    return;
+    }
+
+    /* if we're trying to escape, clamp to the CRTC we're coming from */
+    for (i = 0; i < pScrPriv->numCrtcs; i++) {
+	RRCrtcPtr crtc = pScrPriv->crtcs[i];
+	int nx = pDev->x;
+	int ny = pDev->y;
+	int left, right, top, bottom;
+
+	if (!crtc->mode)
+	    continue;
+
+	crtc_bounds(crtc, &left, &right, &top, &bottom);
+
+	if ((nx >= left) && (nx <= right) && (ny >= top) && (ny <= bottom)) {
+	    if ((*x <= left) || (*x >= right)) {
+		int dx = *x - nx;
+
+		if (dx > 0)
+		    *x = right;
+		else if (dx < 0)
+		    *x = left;
+	    }
+
+	    if ((*y <= top) || (*y >= bottom)) {
+		int dy = *y - ny;
+
+		if (dy > 0)
+		    *y = bottom;
+		else if (dy < 0)
+		    *y = top;
+	    }
+
+	    return;
+	}
+    }
+}
-- 
1.7.2