aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-graphics/xorg-xserver/xserver-kdrive-1.7.99.2/hide-cursor-and-ppm-root.patch
blob: 73f30ee716d5f52379ed6fe03ec674920eca08d7 (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
Index: xorg-server-1.7.99.2/dix/window.c
===================================================================
--- xorg-server-1.7.99.2.orig/dix/window.c	2009-11-04 16:25:50.000000000 +0000
+++ xorg-server-1.7.99.2/dix/window.c	2010-02-10 17:42:22.719078216 +0000
@@ -179,6 +179,8 @@
 
 #define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent))
 
+char* RootPPM = NULL;
+
 #ifdef DEBUG
 /******
  * PrintWindowTree
@@ -304,6 +306,115 @@
 #endif
 }
 
+static int
+get_int(FILE *fp)
+{
+  int c = 0;
+
+  while ((c = getc(fp)) != EOF)
+    {
+      if (isspace(c))
+	continue;
+
+      if (c == '#')
+	while (c = getc(fp))
+	  if (c == EOF)
+	    return 0;
+	  else if (c == '\n')
+	    break;
+
+      if (isdigit(c)) 
+	{
+	  int val = c - '0';
+	  while ((c = getc(fp)) && isdigit(c))
+	    val = (val * 10) + (c - '0');
+	  return val;
+	}
+    }
+
+  return 0;
+}
+
+static unsigned char*
+ppm_load (const char* path, int depth, int *width, int *height)
+{
+  FILE *fp;
+  int   max, n = 0, w, h, i, j, bytes_per_line;
+  unsigned char *data, *res, h1, h2;
+
+  if (depth < 16 || depth > 32)
+    return NULL;
+
+  if (depth > 16)
+    depth = 32;
+
+  fp = fopen (path, "r");
+  if (fp == NULL)
+    return FALSE;
+
+  h1 = getc(fp);
+  h2 = getc(fp);
+
+  /* magic is 'P6' for raw ppm */
+  if (h1 != 'P' && h2 != '6')
+      goto fail;
+
+  w = get_int(fp);
+  h = get_int(fp);
+
+  if (w == 0 || h == 0)
+    goto fail;
+
+  max = get_int(fp);
+
+  if (max != 255)
+      goto fail;
+
+  bytes_per_line = ((w * depth + 31) >> 5) << 2;
+
+  res = data = malloc(bytes_per_line * h);
+
+  for (i=0; i<h; i++)
+    {
+      for (j=0; j<w; j++)
+	{
+	  unsigned char buf[3];
+	  fread(buf, 1, 3, fp);
+	  
+	  switch (depth)
+	    {
+	    case 24:
+	    case 32:
+	      *data     = buf[2];
+	      *(data+1) = buf[1];
+	      *(data+2) = buf[0];
+	      data += 4;
+	      break;
+	    case 16:
+	    default:
+	      *(unsigned short*)data
+		= ((buf[0] >> 3) << 11) | ((buf[1] >> 2) << 5) | (buf[2] >> 3);
+	      data += 2;
+	      break;
+	    }
+	}
+      data += (bytes_per_line - (w*(depth>>3)));
+    }
+
+  data = res;
+
+  *width  = w;
+  *height = h;
+
+  fclose(fp);
+
+  return res;
+
+ fail:
+  fclose(fp);
+  return NULL;
+}
+
 static void
 MakeRootTile(WindowPtr pWin)
 {
@@ -314,6 +425,36 @@
     unsigned char *from, *to;
     int i, j;
 
+    if (RootPPM != NULL)
+      {
+	int            w, h;
+	unsigned char *data;
+
+	if ((data = ppm_load (RootPPM, pScreen->rootDepth, &w, &h)) != NULL)
+	  {
+	    pWin->background.pixmap 
+	      = (*pScreen->CreatePixmap)(pScreen, w, h, pScreen->rootDepth, 0);
+
+	    pWin->backgroundState = BackgroundPixmap;
+	    pGC = GetScratchGC(pScreen->rootDepth, pScreen);
+	    if (!pWin->background.pixmap || !pGC)
+	      FatalError("could not create root tile");
+
+	    ValidateGC((DrawablePtr)pWin->background.pixmap, pGC);
+
+	    (*pGC->ops->PutImage)((DrawablePtr)pWin->background.pixmap, 
+				  pGC, 
+				  pScreen->rootDepth,
+				  0, 0, w, h, 0, ZPixmap, (char *)data);
+	    FreeScratchGC(pGC);
+	    
+	    free(data);
+	    return;
+	  }
+	else
+	  ErrorF("Unable to load root window image.");
+      }
+
     pWin->background.pixmap = (*pScreen->CreatePixmap)(pScreen, 4, 4,
 						    pScreen->rootDepth, 0);
 
@@ -530,6 +671,7 @@
 }
 
 
+
 WindowPtr
 RealChildHead(WindowPtr pWin)
 {
Index: xorg-server-1.7.99.2/hw/kdrive/src/kdrive.c
===================================================================
--- xorg-server-1.7.99.2.orig/hw/kdrive/src/kdrive.c	2010-02-10 17:36:36.000000000 +0000
+++ xorg-server-1.7.99.2/hw/kdrive/src/kdrive.c	2010-02-10 17:43:07.797828099 +0000
@@ -60,6 +60,9 @@
     { 32, 32 }
 };
 
+int 
+ProcXFixesHideCursor (ClientPtr client) ;
+
 #define NUM_KD_DEPTHS (sizeof (kdDepths) / sizeof (kdDepths[0]))
 
 #define KD_DEFAULT_BUTTONS 5
@@ -92,6 +95,9 @@
 
 KdOsFuncs	*kdOsFuncs;
 
+extern Bool CursorInitiallyHidden; /* See Xfixes cursor.c */
+extern char* RootPPM;		   /* dix/window.c */
+
 void
 KdSetRootClip (ScreenPtr pScreen, BOOL enable)
 {
@@ -275,6 +281,7 @@
     KdSetRootClip (pScreen, TRUE);
     if (pScreenPriv->card->cfuncs->dpms)
 	(*pScreenPriv->card->cfuncs->dpms) (pScreen, pScreenPriv->dpmsState);
+
     return TRUE;
 }
 
@@ -553,6 +560,8 @@
     ErrorF("-switchCmd       Command to execute on vt switch\n");
     ErrorF("-zap             Terminate server on Ctrl+Alt+Backspace\n");
     ErrorF("vtxx             Use virtual terminal xx instead of the next available\n");
+    ErrorF("-hide-cursor     Start with cursor hidden\n");
+    ErrorF("-root-ppm [path] Specify ppm file to use as root window background.\n");
 }
 
 int
@@ -616,6 +625,19 @@
 	kdSoftCursor = TRUE;
 	return 1;
     }
+    if (!strcmp (argv[i], "-hide-cursor"))
+    {
+      CursorInitiallyHidden = TRUE;
+      return 1;
+    }
+    if (!strcmp (argv[i], "-root-ppm"))
+    {
+      if ((i+1) < argc)
+	RootPPM =  argv[i+1];
+      else
+	UseMsg ();
+      return 2;
+    }
     if (!strcmp (argv[i], "-videoTest"))
     {
 	kdVideoTest = TRUE;
Index: xorg-server-1.7.99.2/xfixes/cursor.c
===================================================================
--- xorg-server-1.7.99.2.orig/xfixes/cursor.c	2009-12-19 01:43:53.000000000 +0000
+++ xorg-server-1.7.99.2/xfixes/cursor.c	2010-02-10 17:45:02.089079491 +0000
@@ -57,6 +57,7 @@
 static RESTYPE		CursorClientType;
 static RESTYPE		CursorHideCountType;
 static RESTYPE		CursorWindowType;
+static Bool             CursorGloballyHidden; 
 static CursorPtr	CursorCurrent[MAXDEVICES];
 static CursorPtr        pInvisibleCursor = NULL;
 
@@ -65,6 +66,8 @@
 
 static void deleteCursorHideCountsForScreen (ScreenPtr pScreen);
 
+Bool CursorInitiallyHidden = FALSE;
+
 #define VERIFY_CURSOR(pCursor, cursor, client, access)			\
     do {								\
 	int err;							\
@@ -150,7 +153,7 @@
     if (ConnectionInfo)
 	CursorVisible = EnableCursor;
 
-    if (cs->pCursorHideCounts != NULL || !CursorVisible) {
+    if (cs->pCursorHideCounts != NULL || !CursorVisible || CursorGloballyHidden) {
         ret = ((*pScreen->RealizeCursor)(pDev, pScreen, pInvisibleCursor) &&
 	       (*pScreen->DisplayCursor) (pDev, pScreen, pInvisibleCursor));
     } else {
@@ -887,6 +890,12 @@
 	return (ret == BadValue) ? BadWindow : ret;
     }
 
+    /* Is cursor set to be initially hidden ?, if so reset this 
+     * flag as now visibility assumed under control of client.
+    */
+    if (CursorGloballyHidden)
+      CursorGloballyHidden = FALSE;
+
     /* 
      * Has client hidden the cursor before on this screen? 
      * If so, just increment the count. 
@@ -950,9 +959,19 @@
 	return (rc == BadValue) ? BadWindow : rc;
     }
 
+    /* X was started with cursor hidden, therefore just reset our flag
+     * (returning to normal client control) and cause cursor to now be
+     * shown.
+    */
+    if (CursorGloballyHidden == TRUE)
+      {
+	CursorGloballyHidden = FALSE;
+	return (client->noClientException);
+      }
+
     /* 
      * Has client hidden the cursor on this screen?
-     * If not, generate an error.
+     * If so, generate an error.
      */
     pChc = findCursorHideCount(client, pWin->drawable.pScreen);
     if (pChc == NULL) {
@@ -1068,6 +1087,8 @@
 {
     int	i;
 
+    CursorGloballyHidden = CursorInitiallyHidden;
+
     if (party_like_its_1989)
 	CursorVisible = EnableCursor;