summaryrefslogtreecommitdiff
path: root/packages/xorg-xserver/xserver-kdrive-1.3.0.0/hide-cursor-and-ppm-root.patch
blob: c160cd41dcf5e06be9b1faae0fc2786fb98cba4a (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
diff -u -r xorg-server-X11R7.1-1.1.0.orig/dix/window.c xorg-server-X11R7.1-1.1.0/dix/window.c
--- xorg-server-X11R7.1-1.1.0.orig/dix/window.c	2007-01-08 14:30:38.000000000 +0000
+++ xorg-server-X11R7.1-1.1.0/dix/window.c	2007-01-16 17:16:19.000000000 +0000
@@ -185,6 +185,8 @@
 _X_EXPORT int numSaveUndersViewable = 0;
 _X_EXPORT int deltaSaveUndersViewable = 0;
 
+char* RootPPM = NULL;
+
 #ifdef DEBUG
 /******
  * PrintWindowTree
@@ -311,6 +313,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)
 {
@@ -321,6 +432,36 @@
     register unsigned char *from, *to;
     register 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);
+
+	    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);
 
@@ -357,6 +498,7 @@
 
 }
 
+
 WindowPtr
 AllocateWindow(ScreenPtr pScreen)
 {
diff -u -r xorg-server-X11R7.1-1.1.0.orig/hw/kdrive/src/kdrive.c xorg-server-X11R7.1-1.1.0/hw/kdrive/src/kdrive.c
--- xorg-server-X11R7.1-1.1.0.orig/hw/kdrive/src/kdrive.c	2007-01-08 14:30:38.000000000 +0000
+++ xorg-server-X11R7.1-1.1.0/hw/kdrive/src/kdrive.c	2007-01-15 17:53:06.000000000 +0000
@@ -58,6 +58,9 @@
     { 32, 32 }
 };
 
+int 
+ProcXFixesHideCursor (ClientPtr client) ;
+
 #define NUM_KD_DEPTHS (sizeof (kdDepths) / sizeof (kdDepths[0]))
 
 int                 kdScreenPrivateIndex;
@@ -84,6 +87,9 @@
 KdOsFuncs	*kdOsFuncs;
 extern WindowPtr *WindowTable;
 
+extern Bool CursorInitiallyHidden; /* See Xfixes cursor.c */
+extern char* RootPPM;		   /* dix/window.c */
+
 void
 KdSetRootClip (ScreenPtr pScreen, BOOL enable)
 {
@@ -312,6 +318,7 @@
     KdSetRootClip (pScreen, TRUE);
     if (pScreenPriv->card->cfuncs->dpms)
 	(*pScreenPriv->card->cfuncs->dpms) (pScreen, pScreenPriv->dpmsState);
+
     return TRUE;
 }
 
@@ -686,10 +693,14 @@
     ErrorF("-mouse path[,n]  Filename of mouse device, n is number of buttons\n");
     ErrorF("-switchCmd       Command to execute on vt switch\n");
     ErrorF("-nozap           Don't terminate server on Ctrl+Alt+Backspace\n");
+    ErrorF("-hide-cursor     Start with cursor hidden\n");
+    ErrorF("-root-ppm [path] Specify ppm file to use as root window background.\n");
     ErrorF("vtxx             Use virtual terminal xx instead of the next available\n");
 #ifdef PSEUDO8
     p8UseMsg ();
 #endif
+
+
 }
 
 int
@@ -761,6 +772,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;
diff -u -r xorg-server-X11R7.1-1.1.0.orig/xfixes/cursor.c xorg-server-X11R7.1-1.1.0/xfixes/cursor.c
--- xorg-server-X11R7.1-1.1.0.orig/xfixes/cursor.c	2007-01-08 14:30:38.000000000 +0000
+++ xorg-server-X11R7.1-1.1.0/xfixes/cursor.c	2007-01-11 16:33:00.000000000 +0000
@@ -59,9 +59,12 @@
 static RESTYPE		CursorWindowType;
 static int		CursorScreenPrivateIndex = -1;
 static int		CursorGeneration;
+static Bool             CursorGloballyHidden; 
 static CursorPtr	CursorCurrent;
 static CursorPtr        pInvisibleCursor = NULL;
 
+Bool CursorInitiallyHidden = FALSE;
+
 static void deleteCursorHideCountsForScreen (ScreenPtr pScreen);
 
 #define VERIFY_CURSOR(pCursor, cursor, client, access) { \
@@ -130,7 +133,7 @@
 
     Unwrap (cs, pScreen, DisplayCursor);
 
-    if (cs->pCursorHideCounts != NULL) {
+    if (cs->pCursorHideCounts != NULL || CursorGloballyHidden) {
 	ret = (*pScreen->DisplayCursor) (pScreen, pInvisibleCursor);
     } else {
 	ret = (*pScreen->DisplayCursor) (pScreen, pCursor);
@@ -848,6 +851,12 @@
 	return BadWindow;
     }
 
+    /* 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. 
@@ -899,9 +908,19 @@
 	return BadWindow;
     }
 
+    /* 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) {
@@ -1009,6 +1028,8 @@
 XFixesCursorInit (void)
 {
     int	i;
+
+    CursorGloballyHidden = CursorInitiallyHidden;
     
     if (CursorGeneration != serverGeneration)
     {