20 |
|
|
21 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
22 |
#include <X11/Xutil.h> |
#include <X11/Xutil.h> |
23 |
|
#include <unistd.h> |
24 |
|
#include <sys/time.h> |
25 |
#include <time.h> |
#include <time.h> |
26 |
#include <errno.h> |
#include <errno.h> |
27 |
|
#include <strings.h> |
28 |
#include "rdesktop.h" |
#include "rdesktop.h" |
29 |
#include "xproto.h" |
#include "xproto.h" |
30 |
|
|
37 |
extern char g_title[]; |
extern char g_title[]; |
38 |
extern int g_server_bpp; |
extern int g_server_bpp; |
39 |
extern int g_win_button_size; |
extern int g_win_button_size; |
|
BOOL g_enable_compose = False; |
|
|
BOOL g_focused; |
|
|
BOOL g_mouse_in_wnd; |
|
40 |
|
|
41 |
Display *g_display; |
Display *g_display; |
42 |
Time g_last_gesturetime; |
Time g_last_gesturetime; |
43 |
static int g_x_socket; |
static int g_x_socket; |
44 |
static Screen *g_screen; |
static Screen *g_screen; |
45 |
Window g_wnd; |
Window g_wnd; |
46 |
static GC g_gc; |
uint32 g_embed_wnd; |
47 |
|
BOOL g_enable_compose = False; |
48 |
|
static GC g_gc = NULL; |
49 |
static Visual *g_visual; |
static Visual *g_visual; |
50 |
static int g_depth; |
static int g_depth; |
51 |
static int g_bpp; |
static int g_bpp; |
53 |
static XIC g_IC; |
static XIC g_IC; |
54 |
static XModifierKeymap *g_mod_map; |
static XModifierKeymap *g_mod_map; |
55 |
static Cursor g_current_cursor; |
static Cursor g_current_cursor; |
56 |
|
static HCURSOR g_null_cursor = NULL; |
57 |
static Atom g_protocol_atom, g_kill_atom; |
static Atom g_protocol_atom, g_kill_atom; |
58 |
|
static BOOL g_focused; |
59 |
|
static BOOL g_mouse_in_wnd; |
60 |
|
static BOOL g_arch_match = False; /* set to True if RGB XServer and little endian */ |
61 |
|
|
62 |
/* endianness */ |
/* endianness */ |
63 |
static BOOL g_host_be; |
static BOOL g_host_be; |
64 |
static BOOL g_xserver_be; |
static BOOL g_xserver_be; |
65 |
|
static int g_red_shift_r, g_blue_shift_r, g_green_shift_r; |
66 |
|
static int g_red_shift_l, g_blue_shift_l, g_green_shift_l; |
67 |
|
|
68 |
/* software backing store */ |
/* software backing store */ |
69 |
static BOOL g_ownbackstore; |
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
70 |
static Pixmap g_backstore; |
static Pixmap g_backstore = 0; |
71 |
|
|
72 |
/* Moving in single app mode */ |
/* Moving in single app mode */ |
73 |
static BOOL g_moving_wnd; |
static BOOL g_moving_wnd; |
77 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
78 |
extern int g_dsp_fd; |
extern int g_dsp_fd; |
79 |
extern BOOL g_dsp_busy; |
extern BOOL g_dsp_busy; |
80 |
|
extern BOOL g_rdpsnd; |
81 |
#endif |
#endif |
82 |
|
|
83 |
/* MWM decorations */ |
/* MWM decorations */ |
119 |
static Colormap g_xcolmap; |
static Colormap g_xcolmap; |
120 |
static uint32 *g_colmap = NULL; |
static uint32 *g_colmap = NULL; |
121 |
|
|
122 |
#define TRANSLATE(col) ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : translate_colour(g_colmap[col]) ) |
#define TRANSLATE(col) ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] ) |
123 |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
124 |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
125 |
|
|
171 |
split_colour15(uint32 colour) |
split_colour15(uint32 colour) |
172 |
{ |
{ |
173 |
PixelColour rv; |
PixelColour rv; |
174 |
rv.red = (colour & 0x7c00) >> 10; |
rv.red = (colour & 0x7c00) >> 7; |
175 |
rv.red = (rv.red * 0xff) / 0x1f; |
rv.green = (colour & 0x03e0) >> 2; |
176 |
rv.green = (colour & 0x03e0) >> 5; |
rv.blue = (colour & 0x001f) << 3; |
|
rv.green = (rv.green * 0xff) / 0x1f; |
|
|
rv.blue = (colour & 0x1f); |
|
|
rv.blue = (rv.blue * 0xff) / 0x1f; |
|
177 |
return rv; |
return rv; |
178 |
} |
} |
179 |
|
|
181 |
split_colour16(uint32 colour) |
split_colour16(uint32 colour) |
182 |
{ |
{ |
183 |
PixelColour rv; |
PixelColour rv; |
184 |
rv.red = (colour & 0xf800) >> 11; |
rv.red = (colour & 0xf800) >> 8; |
185 |
rv.red = (rv.red * 0xff) / 0x1f; |
rv.green = (colour & 0x07e0) >> 3; |
186 |
rv.green = (colour & 0x07e0) >> 5; |
rv.blue = (colour & 0x001f) << 3; |
|
rv.green = (rv.green * 0xff) / 0x3f; |
|
|
rv.blue = (colour & 0x001f); |
|
|
rv.blue = (rv.blue * 0xff) / 0x1f; |
|
187 |
return rv; |
return rv; |
188 |
} |
} |
189 |
|
|
192 |
{ |
{ |
193 |
PixelColour rv; |
PixelColour rv; |
194 |
rv.blue = (colour & 0xff0000) >> 16; |
rv.blue = (colour & 0xff0000) >> 16; |
195 |
rv.green = (colour & 0xff00) >> 8; |
rv.green = (colour & 0x00ff00) >> 8; |
196 |
rv.red = (colour & 0xff); |
rv.red = (colour & 0x0000ff); |
197 |
return rv; |
return rv; |
198 |
} |
} |
199 |
|
|
200 |
static uint32 |
static uint32 |
201 |
make_colour16(PixelColour pc) |
make_colour(PixelColour pc) |
|
{ |
|
|
pc.red = (pc.red * 0x1f) / 0xff; |
|
|
pc.green = (pc.green * 0x3f) / 0xff; |
|
|
pc.blue = (pc.blue * 0x1f) / 0xff; |
|
|
return (pc.red << 11) | (pc.green << 5) | pc.blue; |
|
|
} |
|
|
|
|
|
static uint32 |
|
|
make_colour24(PixelColour pc) |
|
202 |
{ |
{ |
203 |
if (g_xserver_be) |
return (((pc.red >> g_red_shift_r) << g_red_shift_l) |
204 |
{ |
| ((pc.green >> g_green_shift_r) << g_green_shift_l) |
205 |
return pc.red | (pc.green << 8) | (pc.blue << 16); |
| ((pc.blue >> g_blue_shift_r) << g_blue_shift_l)); |
|
} |
|
|
else |
|
|
{ |
|
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
|
|
} |
|
|
} |
|
|
|
|
|
static uint32 |
|
|
make_colour32(PixelColour pc) |
|
|
{ |
|
|
if (g_xserver_be) |
|
|
{ |
|
|
return pc.red | (pc.green << 8) | (pc.blue << 16); |
|
|
} |
|
|
else |
|
|
{ |
|
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
|
|
} |
|
206 |
} |
} |
207 |
|
|
208 |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
209 |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); } |
210 |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
211 |
x = (x << 16) | (x >> 16); } |
x = (x << 16) | (x >> 16); } |
212 |
|
|
213 |
static uint32 |
static uint32 |
214 |
translate_colour(uint32 colour) |
translate_colour(uint32 colour) |
215 |
{ |
{ |
216 |
|
PixelColour pc; |
217 |
switch (g_server_bpp) |
switch (g_server_bpp) |
218 |
{ |
{ |
219 |
case 15: |
case 15: |
220 |
switch (g_bpp) |
pc = split_colour15(colour); |
|
{ |
|
|
case 16: |
|
|
colour = make_colour16(split_colour15(colour)); |
|
|
break; |
|
|
case 24: |
|
|
colour = make_colour24(split_colour15(colour)); |
|
|
break; |
|
|
case 32: |
|
|
colour = make_colour32(split_colour15(colour)); |
|
|
break; |
|
|
} |
|
|
break; |
|
|
case 16: |
|
|
switch (g_bpp) |
|
|
{ |
|
|
case 16: |
|
|
break; |
|
|
case 24: |
|
|
colour = make_colour24(split_colour16(colour)); |
|
|
break; |
|
|
case 32: |
|
|
colour = make_colour32(split_colour16(colour)); |
|
|
break; |
|
|
} |
|
221 |
break; |
break; |
|
case 24: |
|
|
switch (g_bpp) |
|
|
{ |
|
|
case 16: |
|
|
colour = make_colour16(split_colour24(colour)); |
|
|
break; |
|
|
case 24: |
|
|
break; |
|
|
case 32: |
|
|
colour = make_colour32(split_colour24(colour)); |
|
|
break; |
|
|
} |
|
|
break; |
|
|
} |
|
|
switch (g_bpp) |
|
|
{ |
|
222 |
case 16: |
case 16: |
223 |
if (g_host_be != g_xserver_be) |
pc = split_colour16(colour); |
|
BSWAP16(colour); |
|
224 |
break; |
break; |
|
|
|
225 |
case 24: |
case 24: |
226 |
if (g_xserver_be) |
pc = split_colour24(colour); |
|
BSWAP24(colour); |
|
|
break; |
|
|
|
|
|
case 32: |
|
|
if (g_host_be != g_xserver_be) |
|
|
BSWAP32(colour); |
|
227 |
break; |
break; |
228 |
} |
} |
229 |
|
return make_colour(pc); |
|
return colour; |
|
230 |
} |
} |
231 |
|
|
232 |
static void |
static void |
237 |
} |
} |
238 |
|
|
239 |
static void |
static void |
240 |
translate8to16(uint8 * data, uint16 * out, uint16 * end) |
translate8to16(uint8 * data, uint8 * out, uint8 * end) |
241 |
{ |
{ |
242 |
while (out < end) |
uint16 value; |
243 |
*(out++) = (uint16) g_colmap[*(data++)]; |
|
244 |
|
if (g_xserver_be) |
245 |
|
{ |
246 |
|
while (out < end) |
247 |
|
{ |
248 |
|
value = (uint16) g_colmap[*(data++)]; |
249 |
|
*(out++) = value >> 8; |
250 |
|
*(out++) = value; |
251 |
|
} |
252 |
|
} |
253 |
|
else |
254 |
|
{ |
255 |
|
while (out < end) |
256 |
|
{ |
257 |
|
value = (uint16) g_colmap[*(data++)]; |
258 |
|
*(out++) = value; |
259 |
|
*(out++) = value >> 8; |
260 |
|
} |
261 |
|
} |
262 |
} |
} |
263 |
|
|
264 |
/* little endian - conversion happens when colourmap is built */ |
/* little endian - conversion happens when colourmap is built */ |
267 |
{ |
{ |
268 |
uint32 value; |
uint32 value; |
269 |
|
|
270 |
while (out < end) |
if (g_xserver_be) |
271 |
{ |
{ |
272 |
value = g_colmap[*(data++)]; |
while (out < end) |
273 |
*(out++) = value; |
{ |
274 |
*(out++) = value >> 8; |
value = g_colmap[*(data++)]; |
275 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
276 |
|
*(out++) = value >> 8; |
277 |
|
*(out++) = value; |
278 |
|
} |
279 |
|
} |
280 |
|
else |
281 |
|
{ |
282 |
|
while (out < end) |
283 |
|
{ |
284 |
|
value = g_colmap[*(data++)]; |
285 |
|
*(out++) = value; |
286 |
|
*(out++) = value >> 8; |
287 |
|
*(out++) = value >> 16; |
288 |
|
} |
289 |
} |
} |
290 |
} |
} |
291 |
|
|
292 |
static void |
static void |
293 |
translate8to32(uint8 * data, uint32 * out, uint32 * end) |
translate8to32(uint8 * data, uint8 * out, uint8 * end) |
294 |
{ |
{ |
295 |
while (out < end) |
uint32 value; |
|
*(out++) = g_colmap[*(data++)]; |
|
|
} |
|
296 |
|
|
297 |
/* todo the remaining translate function might need some big endian check ?? */ |
if (g_xserver_be) |
298 |
|
{ |
299 |
|
while (out < end) |
300 |
|
{ |
301 |
|
value = g_colmap[*(data++)]; |
302 |
|
*(out++) = value >> 24; |
303 |
|
*(out++) = value >> 16; |
304 |
|
*(out++) = value >> 8; |
305 |
|
*(out++) = value; |
306 |
|
} |
307 |
|
} |
308 |
|
else |
309 |
|
{ |
310 |
|
while (out < end) |
311 |
|
{ |
312 |
|
value = g_colmap[*(data++)]; |
313 |
|
*(out++) = value; |
314 |
|
*(out++) = value >> 8; |
315 |
|
*(out++) = value >> 16; |
316 |
|
*(out++) = value >> 24; |
317 |
|
} |
318 |
|
} |
319 |
|
} |
320 |
|
|
321 |
static void |
static void |
322 |
translate15to16(uint16 * data, uint16 * out, uint16 * end) |
translate15to16(uint16 * data, uint8 * out, uint8 * end) |
323 |
{ |
{ |
324 |
|
uint16 pixel; |
325 |
|
uint16 value; |
326 |
|
|
327 |
while (out < end) |
while (out < end) |
328 |
*(out++) = (uint16) make_colour16(split_colour15(*(data++))); |
{ |
329 |
|
pixel = *(data++); |
330 |
|
|
331 |
|
if (g_host_be) |
332 |
|
{ |
333 |
|
BSWAP16(pixel); |
334 |
|
} |
335 |
|
|
336 |
|
value = make_colour(split_colour15(pixel)); |
337 |
|
|
338 |
|
if (g_xserver_be) |
339 |
|
{ |
340 |
|
*(out++) = value >> 8; |
341 |
|
*(out++) = value; |
342 |
|
} |
343 |
|
else |
344 |
|
{ |
345 |
|
*(out++) = value; |
346 |
|
*(out++) = value >> 8; |
347 |
|
} |
348 |
|
} |
349 |
} |
} |
350 |
|
|
351 |
static void |
static void |
352 |
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
353 |
{ |
{ |
354 |
uint32 value; |
uint32 value; |
355 |
|
uint16 pixel; |
356 |
|
|
357 |
while (out < end) |
while (out < end) |
358 |
{ |
{ |
359 |
value = make_colour24(split_colour15(*(data++))); |
pixel = *(data++); |
360 |
*(out++) = value; |
|
361 |
*(out++) = value >> 8; |
if (g_host_be) |
362 |
*(out++) = value >> 16; |
{ |
363 |
|
BSWAP16(pixel); |
364 |
|
} |
365 |
|
|
366 |
|
value = make_colour(split_colour15(pixel)); |
367 |
|
if (g_xserver_be) |
368 |
|
{ |
369 |
|
*(out++) = value >> 16; |
370 |
|
*(out++) = value >> 8; |
371 |
|
*(out++) = value; |
372 |
|
} |
373 |
|
else |
374 |
|
{ |
375 |
|
*(out++) = value; |
376 |
|
*(out++) = value >> 8; |
377 |
|
*(out++) = value >> 16; |
378 |
|
} |
379 |
} |
} |
380 |
} |
} |
381 |
|
|
382 |
static void |
static void |
383 |
translate15to32(uint16 * data, uint32 * out, uint32 * end) |
translate15to32(uint16 * data, uint8 * out, uint8 * end) |
384 |
{ |
{ |
385 |
uint16 pixel; |
uint16 pixel; |
386 |
|
uint32 value; |
387 |
|
|
388 |
while (out < end) |
while (out < end) |
389 |
{ |
{ |
390 |
|
pixel = *(data++); |
391 |
|
|
392 |
if (g_host_be) |
if (g_host_be) |
393 |
{ |
{ |
394 |
pixel = *(data++); |
BSWAP16(pixel); |
395 |
pixel = (pixel & 0xff) << 8 | (pixel & 0xff00) >> 8; |
} |
396 |
*(out++) = make_colour32(split_colour15(pixel)); |
|
397 |
|
value = make_colour(split_colour15(pixel)); |
398 |
|
|
399 |
|
if (g_xserver_be) |
400 |
|
{ |
401 |
|
*(out++) = value >> 24; |
402 |
|
*(out++) = value >> 16; |
403 |
|
*(out++) = value >> 8; |
404 |
|
*(out++) = value; |
405 |
} |
} |
406 |
else |
else |
407 |
{ |
{ |
408 |
*(out++) = make_colour32(split_colour15(*(data++))); |
*(out++) = value; |
409 |
|
*(out++) = value >> 8; |
410 |
|
*(out++) = value >> 16; |
411 |
|
*(out++) = value >> 24; |
412 |
} |
} |
413 |
} |
} |
414 |
} |
} |
415 |
|
|
416 |
static void |
static void |
417 |
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
translate16to16(uint16 * data, uint8 * out, uint8 * end) |
418 |
{ |
{ |
419 |
|
uint16 pixel; |
420 |
|
uint16 value; |
421 |
|
|
422 |
while (out < end) |
while (out < end) |
423 |
*(out++) = (uint16) (*(data++)); |
{ |
424 |
} |
pixel = *(data++); |
425 |
|
|
426 |
|
if (g_host_be) |
427 |
|
{ |
428 |
|
BSWAP16(pixel); |
429 |
|
} |
430 |
|
|
431 |
|
value = make_colour(split_colour16(pixel)); |
432 |
|
|
433 |
|
if (g_xserver_be) |
434 |
|
{ |
435 |
|
*(out++) = value >> 8; |
436 |
|
*(out++) = value; |
437 |
|
} |
438 |
|
else |
439 |
|
{ |
440 |
|
*(out++) = value; |
441 |
|
*(out++) = value >> 8; |
442 |
|
} |
443 |
|
} |
444 |
|
} |
445 |
|
|
446 |
static void |
static void |
447 |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
448 |
{ |
{ |
449 |
uint32 value; |
uint32 value; |
450 |
|
uint16 pixel; |
451 |
|
|
452 |
while (out < end) |
while (out < end) |
453 |
{ |
{ |
454 |
value = make_colour24(split_colour16(*(data++))); |
pixel = *(data++); |
455 |
*(out++) = value; |
|
456 |
*(out++) = value >> 8; |
if (g_host_be) |
457 |
*(out++) = value >> 16; |
{ |
458 |
|
BSWAP16(pixel); |
459 |
|
} |
460 |
|
|
461 |
|
value = make_colour(split_colour16(pixel)); |
462 |
|
|
463 |
|
if (g_xserver_be) |
464 |
|
{ |
465 |
|
*(out++) = value >> 16; |
466 |
|
*(out++) = value >> 8; |
467 |
|
*(out++) = value; |
468 |
|
} |
469 |
|
else |
470 |
|
{ |
471 |
|
*(out++) = value; |
472 |
|
*(out++) = value >> 8; |
473 |
|
*(out++) = value >> 16; |
474 |
|
} |
475 |
} |
} |
476 |
} |
} |
477 |
|
|
478 |
static void |
static void |
479 |
translate16to32(uint16 * data, uint32 * out, uint32 * end) |
translate16to32(uint16 * data, uint8 * out, uint8 * end) |
480 |
{ |
{ |
481 |
uint16 pixel; |
uint16 pixel; |
482 |
|
uint32 value; |
483 |
|
|
484 |
while (out < end) |
while (out < end) |
485 |
{ |
{ |
486 |
|
pixel = *(data++); |
487 |
|
|
488 |
if (g_host_be) |
if (g_host_be) |
489 |
{ |
{ |
490 |
pixel = *(data++); |
BSWAP16(pixel); |
491 |
pixel = (pixel & 0xff) << 8 | (pixel & 0xff00) >> 8; |
} |
492 |
*(out++) = make_colour32(split_colour16(pixel)); |
|
493 |
|
value = make_colour(split_colour16(pixel)); |
494 |
|
|
495 |
|
if (g_xserver_be) |
496 |
|
{ |
497 |
|
*(out++) = value >> 24; |
498 |
|
*(out++) = value >> 16; |
499 |
|
*(out++) = value >> 8; |
500 |
|
*(out++) = value; |
501 |
} |
} |
502 |
else |
else |
503 |
{ |
{ |
504 |
*(out++) = make_colour32(split_colour16(*(data++))); |
*(out++) = value; |
505 |
|
*(out++) = value >> 8; |
506 |
|
*(out++) = value >> 16; |
507 |
|
*(out++) = value >> 24; |
508 |
} |
} |
509 |
} |
} |
510 |
} |
} |
511 |
|
|
512 |
static void |
static void |
513 |
translate24to16(uint8 * data, uint16 * out, uint16 * end) |
translate24to16(uint8 * data, uint8 * out, uint8 * end) |
514 |
{ |
{ |
515 |
uint32 pixel = 0; |
uint32 pixel = 0; |
516 |
|
uint16 value; |
517 |
while (out < end) |
while (out < end) |
518 |
{ |
{ |
519 |
pixel = *(data++) << 16; |
pixel = *(data++) << 16; |
520 |
pixel |= *(data++) << 8; |
pixel |= *(data++) << 8; |
521 |
pixel |= *(data++); |
pixel |= *(data++); |
522 |
*(out++) = (uint16) make_colour16(split_colour24(pixel)); |
|
523 |
|
value = (uint16) make_colour(split_colour24(pixel)); |
524 |
|
|
525 |
|
if (g_xserver_be) |
526 |
|
{ |
527 |
|
*(out++) = value >> 8; |
528 |
|
*(out++) = value; |
529 |
|
} |
530 |
|
else |
531 |
|
{ |
532 |
|
*(out++) = value; |
533 |
|
*(out++) = value >> 8; |
534 |
|
} |
535 |
} |
} |
536 |
} |
} |
537 |
|
|
538 |
static void |
static void |
539 |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
540 |
{ |
{ |
541 |
|
uint32 pixel; |
542 |
|
uint32 value; |
543 |
|
|
544 |
while (out < end) |
while (out < end) |
545 |
{ |
{ |
546 |
*(out++) = (*(data++)); |
pixel = *(data++) << 16; |
547 |
|
pixel |= *(data++) << 8; |
548 |
|
pixel |= *(data++); |
549 |
|
|
550 |
|
value = make_colour(split_colour24(pixel)); |
551 |
|
|
552 |
|
if (g_xserver_be) |
553 |
|
{ |
554 |
|
*(out++) = value >> 16; |
555 |
|
*(out++) = value >> 8; |
556 |
|
*(out++) = value; |
557 |
|
} |
558 |
|
else |
559 |
|
{ |
560 |
|
*(out++) = value; |
561 |
|
*(out++) = value >> 8; |
562 |
|
*(out++) = value >> 16; |
563 |
|
} |
564 |
} |
} |
565 |
} |
} |
566 |
|
|
567 |
static void |
static void |
568 |
translate24to32(uint8 * data, uint32 * out, uint32 * end) |
translate24to32(uint8 * data, uint8 * out, uint8 * end) |
569 |
{ |
{ |
570 |
uint32 pixel = 0; |
uint32 pixel; |
571 |
|
uint32 value; |
572 |
|
|
573 |
while (out < end) |
while (out < end) |
574 |
{ |
{ |
575 |
if (g_host_be) |
pixel = *(data++) << 16; |
576 |
|
pixel |= *(data++) << 8; |
577 |
|
pixel |= *(data++); |
578 |
|
|
579 |
|
value = make_colour(split_colour24(pixel)); |
580 |
|
|
581 |
|
if (g_xserver_be) |
582 |
{ |
{ |
583 |
pixel = *(data++) << 16; |
*(out++) = value >> 24; |
584 |
pixel |= *(data++) << 8; |
*(out++) = value >> 16; |
585 |
pixel |= *(data++); |
*(out++) = value >> 8; |
586 |
|
*(out++) = value; |
587 |
} |
} |
588 |
else |
else |
589 |
{ |
{ |
590 |
pixel = *(data++); |
*(out++) = value; |
591 |
pixel |= *(data++) << 8; |
*(out++) = value >> 8; |
592 |
pixel |= *(data++) << 16; |
*(out++) = value >> 16; |
593 |
|
*(out++) = value >> 24; |
594 |
} |
} |
|
*(out++) = pixel; |
|
595 |
} |
} |
596 |
} |
} |
597 |
|
|
598 |
static uint8 * |
static uint8 * |
599 |
translate_image(int width, int height, uint8 * data) |
translate_image(int width, int height, uint8 * data) |
600 |
{ |
{ |
601 |
int size = width * height * g_bpp / 8; |
int size; |
602 |
uint8 *out = (uint8 *) xmalloc(size); |
uint8 *out; |
603 |
uint8 *end = out + size; |
uint8 *end; |
604 |
|
|
605 |
|
/* if server and xserver bpp match, */ |
606 |
|
/* and arch(endian) matches, no need to translate */ |
607 |
|
/* just return data */ |
608 |
|
if (g_depth > 8) |
609 |
|
if (g_arch_match) |
610 |
|
if (g_depth == g_server_bpp) |
611 |
|
return data; |
612 |
|
|
613 |
|
size = width * height * (g_bpp / 8); |
614 |
|
out = (uint8 *) xmalloc(size); |
615 |
|
end = out + size; |
616 |
|
|
617 |
switch (g_server_bpp) |
switch (g_server_bpp) |
618 |
{ |
{ |
620 |
switch (g_bpp) |
switch (g_bpp) |
621 |
{ |
{ |
622 |
case 32: |
case 32: |
623 |
translate24to32(data, (uint32 *) out, (uint32 *) end); |
translate24to32(data, out, end); |
624 |
break; |
break; |
625 |
case 24: |
case 24: |
626 |
translate24to24(data, out, end); |
translate24to24(data, out, end); |
627 |
break; |
break; |
628 |
case 16: |
case 16: |
629 |
translate24to16(data, (uint16 *) out, (uint16 *) end); |
translate24to16(data, out, end); |
630 |
break; |
break; |
631 |
} |
} |
632 |
break; |
break; |
634 |
switch (g_bpp) |
switch (g_bpp) |
635 |
{ |
{ |
636 |
case 32: |
case 32: |
637 |
translate16to32((uint16 *) data, (uint32 *) out, |
translate16to32((uint16 *) data, out, end); |
|
(uint32 *) end); |
|
638 |
break; |
break; |
639 |
case 24: |
case 24: |
640 |
translate16to24((uint16 *) data, out, end); |
translate16to24((uint16 *) data, out, end); |
641 |
break; |
break; |
642 |
case 16: |
case 16: |
643 |
translate16to16((uint16 *) data, (uint16 *) out, |
translate16to16((uint16 *) data, out, end); |
|
(uint16 *) end); |
|
644 |
break; |
break; |
645 |
} |
} |
646 |
break; |
break; |
648 |
switch (g_bpp) |
switch (g_bpp) |
649 |
{ |
{ |
650 |
case 32: |
case 32: |
651 |
translate15to32((uint16 *) data, (uint32 *) out, |
translate15to32((uint16 *) data, out, end); |
|
(uint32 *) end); |
|
652 |
break; |
break; |
653 |
case 24: |
case 24: |
654 |
translate15to24((uint16 *) data, out, end); |
translate15to24((uint16 *) data, out, end); |
655 |
break; |
break; |
656 |
case 16: |
case 16: |
657 |
translate15to16((uint16 *) data, (uint16 *) out, |
translate15to16((uint16 *) data, out, end); |
|
(uint16 *) end); |
|
658 |
break; |
break; |
659 |
} |
} |
660 |
break; |
break; |
665 |
translate8to8(data, out, end); |
translate8to8(data, out, end); |
666 |
break; |
break; |
667 |
case 16: |
case 16: |
668 |
translate8to16(data, (uint16 *) out, (uint16 *) end); |
translate8to16(data, out, end); |
669 |
break; |
break; |
670 |
case 24: |
case 24: |
671 |
translate8to24(data, out, end); |
translate8to24(data, out, end); |
672 |
break; |
break; |
673 |
case 32: |
case 32: |
674 |
translate8to32(data, (uint32 *) out, (uint32 *) end); |
translate8to32(data, out, end); |
675 |
break; |
break; |
676 |
} |
} |
677 |
break; |
break; |
704 |
return (state & keysymMask) ? True : False; |
return (state & keysymMask) ? True : False; |
705 |
} |
} |
706 |
|
|
707 |
|
static void |
708 |
|
calculate_shifts(uint32 mask, int *shift_r, int *shift_l) |
709 |
|
{ |
710 |
|
*shift_l = ffs(mask) - 1; |
711 |
|
mask >>= *shift_l; |
712 |
|
*shift_r = 8 - ffs(mask & ~(mask >> 1)); |
713 |
|
} |
714 |
|
|
715 |
BOOL |
BOOL |
716 |
ui_init(void) |
ui_init(void) |
717 |
{ |
{ |
718 |
|
XVisualInfo vi; |
719 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
720 |
uint16 test; |
uint16 test; |
721 |
int i; |
int i, screen_num, nvisuals; |
722 |
|
XVisualInfo *vmatches = NULL; |
723 |
|
XVisualInfo template; |
724 |
|
Bool TrueColorVisual = False; |
725 |
|
|
726 |
g_display = XOpenDisplay(NULL); |
g_display = XOpenDisplay(NULL); |
727 |
if (g_display == NULL) |
if (g_display == NULL) |
730 |
return False; |
return False; |
731 |
} |
} |
732 |
|
|
733 |
|
screen_num = DefaultScreen(g_display); |
734 |
g_x_socket = ConnectionNumber(g_display); |
g_x_socket = ConnectionNumber(g_display); |
735 |
g_screen = DefaultScreenOfDisplay(g_display); |
g_screen = ScreenOfDisplay(g_display, screen_num); |
|
g_visual = DefaultVisualOfScreen(g_screen); |
|
736 |
g_depth = DefaultDepthOfScreen(g_screen); |
g_depth = DefaultDepthOfScreen(g_screen); |
737 |
|
|
738 |
|
/* Search for best TrueColor depth */ |
739 |
|
template.class = TrueColor; |
740 |
|
vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals); |
741 |
|
|
742 |
|
nvisuals--; |
743 |
|
while (nvisuals >= 0) |
744 |
|
{ |
745 |
|
if ((vmatches + nvisuals)->depth > g_depth) |
746 |
|
{ |
747 |
|
g_depth = (vmatches + nvisuals)->depth; |
748 |
|
} |
749 |
|
nvisuals--; |
750 |
|
TrueColorVisual = True; |
751 |
|
} |
752 |
|
|
753 |
|
test = 1; |
754 |
|
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
755 |
|
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
756 |
|
|
757 |
|
if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8))) |
758 |
|
{ |
759 |
|
/* we use a colourmap, so the default visual should do */ |
760 |
|
g_visual = DefaultVisualOfScreen(g_screen); |
761 |
|
g_depth = DefaultDepthOfScreen(g_screen); |
762 |
|
|
763 |
|
/* Do not allocate colours on a TrueColor visual */ |
764 |
|
if (g_visual->class == TrueColor) |
765 |
|
{ |
766 |
|
g_owncolmap = False; |
767 |
|
} |
768 |
|
} |
769 |
|
else |
770 |
|
{ |
771 |
|
/* need a truecolour visual */ |
772 |
|
if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi)) |
773 |
|
{ |
774 |
|
error("The display does not support true colour - high colour support unavailable.\n"); |
775 |
|
return False; |
776 |
|
} |
777 |
|
|
778 |
|
g_visual = vi.visual; |
779 |
|
g_owncolmap = False; |
780 |
|
calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l); |
781 |
|
calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l); |
782 |
|
calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l); |
783 |
|
|
784 |
|
/* if RGB video and averything is little endian */ |
785 |
|
if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) |
786 |
|
if (!g_xserver_be && !g_host_be) |
787 |
|
g_arch_match = True; |
788 |
|
} |
789 |
|
|
790 |
pfm = XListPixmapFormats(g_display, &i); |
pfm = XListPixmapFormats(g_display, &i); |
791 |
if (pfm != NULL) |
if (pfm != NULL) |
792 |
{ |
{ |
809 |
return False; |
return False; |
810 |
} |
} |
811 |
|
|
812 |
if (g_owncolmap != True) |
if (!g_owncolmap) |
813 |
{ |
{ |
814 |
g_xcolmap = DefaultColormapOfScreen(g_screen); |
g_xcolmap = |
815 |
|
XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual, |
816 |
|
AllocNone); |
817 |
if (g_depth <= 8) |
if (g_depth <= 8) |
818 |
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
819 |
} |
} |
820 |
|
|
821 |
g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL); |
if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) |
822 |
|
{ |
823 |
if (DoesBackingStore(g_screen) != Always) |
warning("External BackingStore not available, using internal\n"); |
824 |
g_ownbackstore = True; |
g_ownbackstore = True; |
825 |
|
} |
826 |
|
|
827 |
test = 1; |
/* |
828 |
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
* Determine desktop size |
829 |
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
*/ |
830 |
|
if (g_fullscreen) |
831 |
if ((g_width == 0) || (g_height == 0)) |
{ |
832 |
|
g_width = WidthOfScreen(g_screen); |
833 |
|
g_height = HeightOfScreen(g_screen); |
834 |
|
} |
835 |
|
else if (g_width < 0) |
836 |
|
{ |
837 |
|
/* Percent of screen */ |
838 |
|
g_height = HeightOfScreen(g_screen) * (-g_width) / 100; |
839 |
|
g_width = WidthOfScreen(g_screen) * (-g_width) / 100; |
840 |
|
} |
841 |
|
else if (g_width == 0) |
842 |
{ |
{ |
843 |
/* Fetch geometry from _NET_WORKAREA */ |
/* Fetch geometry from _NET_WORKAREA */ |
844 |
uint32 x, y, cx, cy; |
uint32 x, y, cx, cy; |
856 |
} |
} |
857 |
} |
} |
858 |
|
|
|
if (g_fullscreen) |
|
|
{ |
|
|
g_width = WidthOfScreen(g_screen); |
|
|
g_height = HeightOfScreen(g_screen); |
|
|
} |
|
|
|
|
859 |
/* make sure width is a multiple of 4 */ |
/* make sure width is a multiple of 4 */ |
860 |
g_width = (g_width + 3) & ~3; |
g_width = (g_width + 3) & ~3; |
861 |
|
|
|
if (g_ownbackstore) |
|
|
{ |
|
|
g_backstore = |
|
|
XCreatePixmap(g_display, RootWindowOfScreen(g_screen), g_width, g_height, |
|
|
g_depth); |
|
|
|
|
|
/* clear to prevent rubbish being exposed at startup */ |
|
|
XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen)); |
|
|
XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height); |
|
|
} |
|
|
|
|
862 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
863 |
|
|
864 |
|
xkeymap_init(); |
865 |
|
|
866 |
if (g_enable_compose) |
if (g_enable_compose) |
867 |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
868 |
|
|
|
xkeymap_init(); |
|
869 |
xclip_init(); |
xclip_init(); |
870 |
|
|
871 |
/* todo take this out when high colour is done */ |
DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth)); |
|
printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth); |
|
872 |
|
|
873 |
return True; |
return True; |
874 |
} |
} |
879 |
if (g_IM != NULL) |
if (g_IM != NULL) |
880 |
XCloseIM(g_IM); |
XCloseIM(g_IM); |
881 |
|
|
882 |
|
if (g_null_cursor != NULL) |
883 |
|
ui_destroy_cursor(g_null_cursor); |
884 |
|
|
885 |
XFreeModifiermap(g_mod_map); |
XFreeModifiermap(g_mod_map); |
886 |
|
|
887 |
if (g_ownbackstore) |
if (g_ownbackstore) |
895 |
BOOL |
BOOL |
896 |
ui_create_window(void) |
ui_create_window(void) |
897 |
{ |
{ |
898 |
|
uint8 null_pointer_mask[1] = { 0x80 }; |
899 |
|
uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 }; |
900 |
XSetWindowAttributes attribs; |
XSetWindowAttributes attribs; |
901 |
XClassHint *classhints; |
XClassHint *classhints; |
902 |
XSizeHints *sizehints; |
XSizeHints *sizehints; |
908 |
wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; |
wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; |
909 |
|
|
910 |
attribs.background_pixel = BlackPixelOfScreen(g_screen); |
attribs.background_pixel = BlackPixelOfScreen(g_screen); |
911 |
|
attribs.border_pixel = WhitePixelOfScreen(g_screen); |
912 |
attribs.backing_store = g_ownbackstore ? NotUseful : Always; |
attribs.backing_store = g_ownbackstore ? NotUseful : Always; |
913 |
attribs.override_redirect = g_fullscreen; |
attribs.override_redirect = g_fullscreen; |
914 |
|
attribs.colormap = g_xcolmap; |
915 |
|
|
916 |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight, |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight, |
917 |
0, CopyFromParent, InputOutput, CopyFromParent, |
0, g_depth, InputOutput, g_visual, |
918 |
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
CWBackPixel | CWBackingStore | CWOverrideRedirect | |
919 |
|
CWColormap | CWBorderPixel, &attribs); |
920 |
|
|
921 |
|
if (g_gc == NULL) |
922 |
|
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
923 |
|
|
924 |
|
if ((g_ownbackstore) && (g_backstore == 0)) |
925 |
|
{ |
926 |
|
g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth); |
927 |
|
|
928 |
|
/* clear to prevent rubbish being exposed at startup */ |
929 |
|
XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen)); |
930 |
|
XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height); |
931 |
|
} |
932 |
|
|
933 |
XStoreName(g_display, g_wnd, g_title); |
XStoreName(g_display, g_wnd, g_title); |
934 |
|
|
953 |
XFree(sizehints); |
XFree(sizehints); |
954 |
} |
} |
955 |
|
|
956 |
|
if ( g_embed_wnd ) |
957 |
|
{ |
958 |
|
XReparentWindow(g_display, g_wnd, (Window)g_embed_wnd, 0, 0); |
959 |
|
} |
960 |
|
|
961 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
962 |
VisibilityChangeMask | FocusChangeMask; |
VisibilityChangeMask | FocusChangeMask; |
963 |
|
|
998 |
g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True); |
g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True); |
999 |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
1000 |
|
|
1001 |
|
/* create invisible 1x1 cursor to be used as null cursor */ |
1002 |
|
if (g_null_cursor == NULL) |
1003 |
|
g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data); |
1004 |
|
|
1005 |
return True; |
return True; |
1006 |
} |
} |
1007 |
|
|
1051 |
key_translation tr; |
key_translation tr; |
1052 |
char str[256]; |
char str[256]; |
1053 |
Status status; |
Status status; |
|
unsigned int state; |
|
|
Window wdummy; |
|
|
int dummy; |
|
1054 |
|
|
1055 |
while (XPending(g_display) > 0) |
while (XPending(g_display) > 0) |
1056 |
{ |
{ |
1223 |
if (xevent.xfocus.mode == NotifyGrab) |
if (xevent.xfocus.mode == NotifyGrab) |
1224 |
break; |
break; |
1225 |
g_focused = True; |
g_focused = True; |
1226 |
XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, |
reset_modifier_keys(); |
|
&dummy, &dummy, &state); |
|
|
reset_modifier_keys(state); |
|
1227 |
if (g_grab_keyboard && g_mouse_in_wnd) |
if (g_grab_keyboard && g_mouse_in_wnd) |
1228 |
XGrabKeyboard(g_display, g_wnd, True, |
XGrabKeyboard(g_display, g_wnd, True, |
1229 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
1303 |
int |
int |
1304 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
1305 |
{ |
{ |
1306 |
int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1; |
int n; |
1307 |
fd_set rfds, wfds; |
fd_set rfds, wfds; |
1308 |
|
struct timeval tv; |
1309 |
FD_ZERO(&rfds); |
BOOL s_timeout = False; |
1310 |
|
|
1311 |
while (True) |
while (True) |
1312 |
{ |
{ |
1313 |
|
n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket; |
1314 |
/* Process any events already waiting */ |
/* Process any events already waiting */ |
1315 |
if (!xwin_process_events()) |
if (!xwin_process_events()) |
1316 |
/* User quit */ |
/* User quit */ |
1326 |
if (g_dsp_busy) |
if (g_dsp_busy) |
1327 |
{ |
{ |
1328 |
FD_SET(g_dsp_fd, &wfds); |
FD_SET(g_dsp_fd, &wfds); |
1329 |
n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; |
n = (g_dsp_fd > n) ? g_dsp_fd : n; |
1330 |
} |
} |
1331 |
#endif |
#endif |
1332 |
|
/* default timeout */ |
1333 |
|
tv.tv_sec = 60; |
1334 |
|
tv.tv_usec = 0; |
1335 |
|
|
1336 |
|
/* add redirection handles */ |
1337 |
|
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
1338 |
|
|
1339 |
|
n++; |
1340 |
|
|
1341 |
switch (select(n, &rfds, &wfds, NULL, NULL)) |
switch (select(n, &rfds, &wfds, NULL, &tv)) |
1342 |
{ |
{ |
1343 |
case -1: |
case -1: |
1344 |
error("select: %s\n", strerror(errno)); |
error("select: %s\n", strerror(errno)); |
1345 |
|
|
1346 |
case 0: |
case 0: |
1347 |
|
/* TODO: if tv.tv_sec just times out |
1348 |
|
* we will segfault. |
1349 |
|
* FIXME: |
1350 |
|
*/ |
1351 |
|
//s_timeout = True; |
1352 |
|
//rdpdr_check_fds(&rfds, &wfds, (BOOL) True); |
1353 |
continue; |
continue; |
1354 |
} |
} |
1355 |
|
|
1356 |
|
rdpdr_check_fds(&rfds, &wfds, (BOOL) False); |
1357 |
|
|
1358 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
1359 |
return 1; |
return 1; |
1360 |
|
|
1361 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
1362 |
if (FD_ISSET(g_dsp_fd, &wfds)) |
if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds)) |
1363 |
wave_out_play(); |
wave_out_play(); |
1364 |
#endif |
#endif |
1365 |
} |
} |
1377 |
XImage *image; |
XImage *image; |
1378 |
Pixmap bitmap; |
Pixmap bitmap; |
1379 |
uint8 *tdata; |
uint8 *tdata; |
1380 |
|
int bitmap_pad; |
1381 |
|
|
1382 |
|
if (g_server_bpp == 8) |
1383 |
|
{ |
1384 |
|
bitmap_pad = 8; |
1385 |
|
} |
1386 |
|
else |
1387 |
|
{ |
1388 |
|
bitmap_pad = g_bpp; |
1389 |
|
|
1390 |
|
if (g_bpp == 24) |
1391 |
|
bitmap_pad = 32; |
1392 |
|
} |
1393 |
|
|
1394 |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
1395 |
bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth); |
bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth); |
1396 |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
1397 |
(char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); |
(char *) tdata, width, height, bitmap_pad, 0); |
1398 |
|
|
1399 |
XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height); |
XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height); |
1400 |
|
|
1401 |
XFree(image); |
XFree(image); |
1402 |
if (!g_owncolmap) |
if (tdata != data) |
1403 |
xfree(tdata); |
xfree(tdata); |
1404 |
return (HBITMAP) bitmap; |
return (HBITMAP) bitmap; |
1405 |
} |
} |
1409 |
{ |
{ |
1410 |
XImage *image; |
XImage *image; |
1411 |
uint8 *tdata; |
uint8 *tdata; |
1412 |
|
int bitmap_pad; |
1413 |
|
|
1414 |
|
if (g_server_bpp == 8) |
1415 |
|
{ |
1416 |
|
bitmap_pad = 8; |
1417 |
|
} |
1418 |
|
else |
1419 |
|
{ |
1420 |
|
bitmap_pad = g_bpp; |
1421 |
|
|
1422 |
|
if (g_bpp == 24) |
1423 |
|
bitmap_pad = 32; |
1424 |
|
} |
1425 |
|
|
1426 |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
1427 |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
1428 |
(char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); |
(char *) tdata, width, height, bitmap_pad, 0); |
1429 |
|
|
1430 |
if (g_ownbackstore) |
if (g_ownbackstore) |
1431 |
{ |
{ |
1438 |
} |
} |
1439 |
|
|
1440 |
XFree(image); |
XFree(image); |
1441 |
if (!g_owncolmap) |
if (tdata != data) |
1442 |
xfree(tdata); |
xfree(tdata); |
1443 |
} |
} |
1444 |
|
|
1564 |
XFreeCursor(g_display, (Cursor) cursor); |
XFreeCursor(g_display, (Cursor) cursor); |
1565 |
} |
} |
1566 |
|
|
1567 |
|
void |
1568 |
|
ui_set_null_cursor(void) |
1569 |
|
{ |
1570 |
|
ui_set_cursor(g_null_cursor); |
1571 |
|
} |
1572 |
|
|
1573 |
#define MAKE_XCOLOR(xc,c) \ |
#define MAKE_XCOLOR(xc,c) \ |
1574 |
(xc)->red = ((c)->red << 8) | (c)->red; \ |
(xc)->red = ((c)->red << 8) | (c)->red; \ |
1575 |
(xc)->green = ((c)->green << 8) | (c)->green; \ |
(xc)->green = ((c)->green << 8) | (c)->green; \ |
1651 |
|
|
1652 |
} |
} |
1653 |
|
|
1654 |
|
map[i] = colour; |
|
/* byte swap here to make translate_image faster */ |
|
|
map[i] = translate_colour(colour); |
|
1655 |
} |
} |
1656 |
return map; |
return map; |
1657 |
} |
} |
1768 |
case 2: /* Hatch */ |
case 2: /* Hatch */ |
1769 |
fill = (Pixmap) ui_create_glyph(8, 8, |
fill = (Pixmap) ui_create_glyph(8, 8, |
1770 |
hatch_patterns + brush->pattern[0] * 8); |
hatch_patterns + brush->pattern[0] * 8); |
1771 |
SET_FOREGROUND(bgcolour); |
SET_FOREGROUND(fgcolour); |
1772 |
SET_BACKGROUND(fgcolour); |
SET_BACKGROUND(bgcolour); |
1773 |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
1774 |
XSetStipple(g_display, g_gc, fill); |
XSetStipple(g_display, g_gc, fill); |
1775 |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |
1810 |
/* src */ int srcx, int srcy) |
/* src */ int srcx, int srcy) |
1811 |
{ |
{ |
1812 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
|
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
|
1813 |
if (g_ownbackstore) |
if (g_ownbackstore) |
1814 |
|
{ |
1815 |
|
XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
1816 |
XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y); |
XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y); |
1817 |
|
} |
1818 |
|
else |
1819 |
|
{ |
1820 |
|
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
1821 |
|
} |
1822 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
1823 |
} |
} |
1824 |
|
|
1913 |
{\ |
{\ |
1914 |
glyph = cache_get_font (font, ttext[idx]);\ |
glyph = cache_get_font (font, ttext[idx]);\ |
1915 |
if (!(flags & TEXT2_IMPLICIT_X))\ |
if (!(flags & TEXT2_IMPLICIT_X))\ |
1916 |
|
{\ |
1917 |
|
xyoffset = ttext[++idx];\ |
1918 |
|
if ((xyoffset & 0x80))\ |
1919 |
{\ |
{\ |
1920 |
xyoffset = ttext[++idx];\ |
if (flags & TEXT2_VERTICAL)\ |
1921 |
if ((xyoffset & 0x80))\ |
y += ttext[idx+1] | (ttext[idx+2] << 8);\ |
|
{\ |
|
|
if (flags & TEXT2_VERTICAL) \ |
|
|
y += ttext[idx+1] | (ttext[idx+2] << 8);\ |
|
|
else\ |
|
|
x += ttext[idx+1] | (ttext[idx+2] << 8);\ |
|
|
idx += 2;\ |
|
|
}\ |
|
1922 |
else\ |
else\ |
1923 |
{\ |
x += ttext[idx+1] | (ttext[idx+2] << 8);\ |
1924 |
if (flags & TEXT2_VERTICAL) \ |
idx += 2;\ |
|
y += xyoffset;\ |
|
|
else\ |
|
|
x += xyoffset;\ |
|
|
}\ |
|
1925 |
}\ |
}\ |
1926 |
if (glyph != NULL)\ |
else\ |
1927 |
{\ |
{\ |
1928 |
ui_draw_glyph (mixmode, x + glyph->offset,\ |
if (flags & TEXT2_VERTICAL)\ |
1929 |
y + glyph->baseline,\ |
y += xyoffset;\ |
1930 |
glyph->width, glyph->height,\ |
else\ |
1931 |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
x += xyoffset;\ |
|
if (flags & TEXT2_IMPLICIT_X)\ |
|
|
x += glyph->width;\ |
|
1932 |
}\ |
}\ |
1933 |
|
}\ |
1934 |
|
if (glyph != NULL)\ |
1935 |
|
{\ |
1936 |
|
x1 = x + glyph->offset;\ |
1937 |
|
y1 = y + glyph->baseline;\ |
1938 |
|
XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\ |
1939 |
|
XSetTSOrigin(g_display, g_gc, x1, y1);\ |
1940 |
|
FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\ |
1941 |
|
if (flags & TEXT2_IMPLICIT_X)\ |
1942 |
|
x += glyph->width;\ |
1943 |
|
}\ |
1944 |
} |
} |
1945 |
|
|
1946 |
void |
void |
1950 |
int fgcolour, uint8 * text, uint8 length) |
int fgcolour, uint8 * text, uint8 length) |
1951 |
{ |
{ |
1952 |
FONTGLYPH *glyph; |
FONTGLYPH *glyph; |
1953 |
int i, j, xyoffset; |
int i, j, xyoffset, x1, y1; |
1954 |
DATABLOB *entry; |
DATABLOB *entry; |
1955 |
|
|
1956 |
SET_FOREGROUND(bgcolour); |
SET_FOREGROUND(bgcolour); |
1957 |
|
|
1958 |
|
/* Sometimes, the boxcx value is something really large, like |
1959 |
|
32691. This makes XCopyArea fail with Xvnc. The code below |
1960 |
|
is a quick fix. */ |
1961 |
|
if (boxx + boxcx > g_width) |
1962 |
|
boxcx = g_width - boxx; |
1963 |
|
|
1964 |
if (boxcx > 1) |
if (boxcx > 1) |
1965 |
{ |
{ |
1966 |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |
1970 |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
1971 |
} |
} |
1972 |
|
|
1973 |
|
SET_FOREGROUND(fgcolour); |
1974 |
|
SET_BACKGROUND(bgcolour); |
1975 |
|
XSetFillStyle(g_display, g_gc, FillStippled); |
1976 |
|
|
1977 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
1978 |
for (i = 0; i < length;) |
for (i = 0; i < length;) |
1979 |
{ |
{ |
2024 |
break; |
break; |
2025 |
} |
} |
2026 |
} |
} |
2027 |
|
|
2028 |
|
XSetFillStyle(g_display, g_gc, FillSolid); |
2029 |
|
|
2030 |
if (g_ownbackstore) |
if (g_ownbackstore) |
2031 |
{ |
{ |
2032 |
if (boxcx > 1) |
if (boxcx > 1) |