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 |
|
|
44 |
static Screen *g_screen; |
static Screen *g_screen; |
45 |
Window g_wnd; |
Window g_wnd; |
46 |
BOOL g_enable_compose = False; |
BOOL g_enable_compose = False; |
47 |
static GC g_gc; |
static GC g_gc = NULL; |
48 |
static Visual *g_visual; |
static Visual *g_visual; |
49 |
static int g_depth; |
static int g_depth; |
50 |
static int g_bpp; |
static int g_bpp; |
52 |
static XIC g_IC; |
static XIC g_IC; |
53 |
static XModifierKeymap *g_mod_map; |
static XModifierKeymap *g_mod_map; |
54 |
static Cursor g_current_cursor; |
static Cursor g_current_cursor; |
55 |
|
static HCURSOR g_null_cursor = NULL; |
56 |
static Atom g_protocol_atom, g_kill_atom; |
static Atom g_protocol_atom, g_kill_atom; |
57 |
static BOOL g_focused; |
static BOOL g_focused; |
58 |
static BOOL g_mouse_in_wnd; |
static BOOL g_mouse_in_wnd; |
60 |
/* endianness */ |
/* endianness */ |
61 |
static BOOL g_host_be; |
static BOOL g_host_be; |
62 |
static BOOL g_xserver_be; |
static BOOL g_xserver_be; |
63 |
|
static int g_red_shift_r, g_blue_shift_r, g_green_shift_r; |
64 |
|
static int g_red_shift_l, g_blue_shift_l, g_green_shift_l; |
65 |
|
|
66 |
/* software backing store */ |
/* software backing store */ |
67 |
static BOOL g_ownbackstore; |
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
68 |
static Pixmap g_backstore; |
static Pixmap g_backstore = 0; |
69 |
|
|
70 |
/* Moving in single app mode */ |
/* Moving in single app mode */ |
71 |
static BOOL g_moving_wnd; |
static BOOL g_moving_wnd; |
75 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
76 |
extern int g_dsp_fd; |
extern int g_dsp_fd; |
77 |
extern BOOL g_dsp_busy; |
extern BOOL g_dsp_busy; |
78 |
|
extern BOOL g_rdpsnd; |
79 |
#endif |
#endif |
80 |
|
|
81 |
/* MWM decorations */ |
/* MWM decorations */ |
117 |
static Colormap g_xcolmap; |
static Colormap g_xcolmap; |
118 |
static uint32 *g_colmap = NULL; |
static uint32 *g_colmap = NULL; |
119 |
|
|
120 |
#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] ) |
121 |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
122 |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
123 |
|
|
169 |
split_colour15(uint32 colour) |
split_colour15(uint32 colour) |
170 |
{ |
{ |
171 |
PixelColour rv; |
PixelColour rv; |
172 |
rv.red = (colour & 0x7c00) >> 10; |
rv.red = (colour & 0x7c00) >> 7; |
173 |
rv.red = (rv.red * 0xff) / 0x1f; |
rv.green = (colour & 0x03e0) >> 2; |
174 |
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; |
|
175 |
return rv; |
return rv; |
176 |
} |
} |
177 |
|
|
179 |
split_colour16(uint32 colour) |
split_colour16(uint32 colour) |
180 |
{ |
{ |
181 |
PixelColour rv; |
PixelColour rv; |
182 |
rv.red = (colour & 0xf800) >> 11; |
rv.red = (colour & 0xf800) >> 8; |
183 |
rv.red = (rv.red * 0xff) / 0x1f; |
rv.green = (colour & 0x07e0) >> 3; |
184 |
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; |
|
185 |
return rv; |
return rv; |
186 |
} |
} |
187 |
|
|
189 |
split_colour24(uint32 colour) |
split_colour24(uint32 colour) |
190 |
{ |
{ |
191 |
PixelColour rv; |
PixelColour rv; |
192 |
rv.blue = (colour & 0xff0000) >> 16; |
rv.blue = (colour & 0xff0000) >> 16; |
193 |
rv.green = (colour & 0xff00) >> 8; |
rv.green = (colour & 0x00ff00) >> 8; |
194 |
rv.red = (colour & 0xff); |
rv.red = (colour & 0x0000ff); |
195 |
return rv; |
return rv; |
196 |
} |
} |
197 |
|
|
198 |
static uint32 |
static uint32 |
199 |
make_colour16(PixelColour pc) |
make_colour(PixelColour pc) |
200 |
{ |
{ |
201 |
pc.red = (pc.red * 0x1f) / 0xff; |
return (((pc.red >> g_red_shift_r) << g_red_shift_l) |
202 |
pc.green = (pc.green * 0x3f) / 0xff; |
| ((pc.green >> g_green_shift_r) << g_green_shift_l) |
203 |
pc.blue = (pc.blue * 0x1f) / 0xff; |
| ((pc.blue >> g_blue_shift_r) << g_blue_shift_l)); |
|
return (pc.red << 11) | (pc.green << 5) | pc.blue; |
|
|
} |
|
|
|
|
|
static uint32 |
|
|
make_colour24(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; |
|
|
} |
|
|
} |
|
|
|
|
|
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; |
|
|
} |
|
204 |
} |
} |
205 |
|
|
206 |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
207 |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); } |
208 |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
209 |
x = (x << 16) | (x >> 16); } |
x = (x << 16) | (x >> 16); } |
210 |
|
|
211 |
static uint32 |
static uint32 |
212 |
translate_colour(uint32 colour) |
translate_colour(uint32 colour) |
213 |
{ |
{ |
214 |
|
PixelColour pc; |
215 |
switch (g_server_bpp) |
switch (g_server_bpp) |
216 |
{ |
{ |
217 |
case 15: |
case 15: |
218 |
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; |
|
|
} |
|
219 |
break; |
break; |
220 |
case 16: |
case 16: |
221 |
switch (g_bpp) |
pc = split_colour16(colour); |
|
{ |
|
|
case 16: |
|
|
break; |
|
|
case 24: |
|
|
colour = make_colour24(split_colour16(colour)); |
|
|
break; |
|
|
case 32: |
|
|
colour = make_colour32(split_colour16(colour)); |
|
|
break; |
|
|
} |
|
222 |
break; |
break; |
223 |
case 24: |
case 24: |
224 |
switch (g_bpp) |
pc = split_colour24(colour); |
|
{ |
|
|
case 16: |
|
|
colour = make_colour16(split_colour24(colour)); |
|
|
break; |
|
|
case 24: |
|
|
break; |
|
|
case 32: |
|
|
colour = make_colour32(split_colour24(colour)); |
|
|
break; |
|
|
} |
|
225 |
break; |
break; |
226 |
} |
} |
227 |
return colour; |
return make_colour(pc); |
228 |
} |
} |
229 |
|
|
230 |
static void |
static void |
235 |
} |
} |
236 |
|
|
237 |
static void |
static void |
238 |
translate8to16(uint8 * data, uint16 * out, uint16 * end) |
translate8to16(uint8 * data, uint8 * out, uint8 * end) |
239 |
{ |
{ |
240 |
|
uint16 value; |
241 |
|
|
242 |
while (out < end) |
while (out < end) |
243 |
*(out++) = (uint16) g_colmap[*(data++)]; |
{ |
244 |
|
value = (uint16) g_colmap[*(data++)]; |
245 |
|
|
246 |
|
if (g_xserver_be) |
247 |
|
{ |
248 |
|
*(out++) = value >> 8; |
249 |
|
*(out++) = value; |
250 |
|
} |
251 |
|
else |
252 |
|
{ |
253 |
|
*(out++) = value; |
254 |
|
*(out++) = value >> 8; |
255 |
|
} |
256 |
|
} |
257 |
} |
} |
258 |
|
|
259 |
/* little endian - conversion happens when colourmap is built */ |
/* little endian - conversion happens when colourmap is built */ |
265 |
while (out < end) |
while (out < end) |
266 |
{ |
{ |
267 |
value = g_colmap[*(data++)]; |
value = g_colmap[*(data++)]; |
268 |
*(out++) = value; |
|
269 |
*(out++) = value >> 8; |
if (g_xserver_be) |
270 |
*(out++) = value >> 16; |
{ |
271 |
|
*(out++) = value >> 16; |
272 |
|
*(out++) = value >> 8; |
273 |
|
*(out++) = value; |
274 |
|
} |
275 |
|
else |
276 |
|
{ |
277 |
|
*(out++) = value; |
278 |
|
*(out++) = value >> 8; |
279 |
|
*(out++) = value >> 16; |
280 |
|
} |
281 |
} |
} |
282 |
} |
} |
283 |
|
|
284 |
static void |
static void |
285 |
translate8to32(uint8 * data, uint32 * out, uint32 * end) |
translate8to32(uint8 * data, uint8 * out, uint8 * end) |
286 |
{ |
{ |
287 |
|
uint32 value; |
288 |
|
|
289 |
while (out < end) |
while (out < end) |
290 |
*(out++) = g_colmap[*(data++)]; |
{ |
291 |
} |
value = g_colmap[*(data++)]; |
292 |
|
|
293 |
/* todo the remaining translate function might need some big endian check ?? */ |
if (g_xserver_be) |
294 |
|
{ |
295 |
|
*(out++) = value >> 24; |
296 |
|
*(out++) = value >> 16; |
297 |
|
*(out++) = value >> 8; |
298 |
|
*(out++) = value; |
299 |
|
} |
300 |
|
else |
301 |
|
{ |
302 |
|
*(out++) = value; |
303 |
|
*(out++) = value >> 8; |
304 |
|
*(out++) = value >> 16; |
305 |
|
*(out++) = value >> 24; |
306 |
|
} |
307 |
|
} |
308 |
|
} |
309 |
|
|
310 |
static void |
static void |
311 |
translate15to16(uint16 * data, uint8 * out, uint8 * end) |
translate15to16(uint16 * data, uint8 * out, uint8 * end) |
319 |
|
|
320 |
if (g_host_be) |
if (g_host_be) |
321 |
{ |
{ |
322 |
BSWAP16(pixel) |
BSWAP16(pixel); |
323 |
} |
} |
324 |
|
|
325 |
value = make_colour16(split_colour15(pixel)); |
value = make_colour(split_colour15(pixel)); |
326 |
|
|
327 |
if (g_xserver_be) |
if (g_xserver_be) |
328 |
{ |
{ |
349 |
|
|
350 |
if (g_host_be) |
if (g_host_be) |
351 |
{ |
{ |
352 |
BSWAP16(pixel) |
BSWAP16(pixel); |
353 |
} |
} |
354 |
|
|
355 |
value = make_colour24(split_colour15(pixel)); |
value = make_colour(split_colour15(pixel)); |
356 |
if (g_xserver_be) |
if (g_xserver_be) |
357 |
{ |
{ |
358 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
383 |
BSWAP16(pixel); |
BSWAP16(pixel); |
384 |
} |
} |
385 |
|
|
386 |
value = make_colour32(split_colour15(pixel)); |
value = make_colour(split_colour15(pixel)); |
387 |
|
|
388 |
if (g_xserver_be) |
if (g_xserver_be) |
389 |
{ |
{ |
403 |
} |
} |
404 |
|
|
405 |
static void |
static void |
406 |
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
translate16to16(uint16 * data, uint8 * out, uint8 * end) |
407 |
{ |
{ |
408 |
|
uint16 pixel; |
409 |
uint16 value; |
uint16 value; |
410 |
|
|
411 |
if (g_xserver_be) |
while (out < end) |
412 |
{ |
{ |
413 |
while (out < end) |
pixel = *(data++); |
414 |
|
|
415 |
|
if (g_host_be) |
416 |
{ |
{ |
417 |
value = *data; |
BSWAP16(pixel); |
|
BSWAP16(value); |
|
|
*out = value; |
|
|
data++; |
|
|
out++; |
|
418 |
} |
} |
419 |
|
|
420 |
} |
value = make_colour(split_colour16(pixel)); |
421 |
else |
|
422 |
{ |
if (g_xserver_be) |
|
while (out < end) |
|
423 |
{ |
{ |
424 |
*out = *data; |
*(out++) = value >> 8; |
425 |
out++; |
*(out++) = value; |
426 |
data++; |
} |
427 |
|
else |
428 |
|
{ |
429 |
|
*(out++) = value; |
430 |
|
*(out++) = value >> 8; |
431 |
} |
} |
432 |
} |
} |
433 |
} |
} |
434 |
|
|
|
|
|
435 |
static void |
static void |
436 |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
437 |
{ |
{ |
444 |
|
|
445 |
if (g_host_be) |
if (g_host_be) |
446 |
{ |
{ |
447 |
BSWAP16(pixel) |
BSWAP16(pixel); |
448 |
} |
} |
449 |
|
|
450 |
value = make_colour24(split_colour16(pixel)); |
value = make_colour(split_colour16(pixel)); |
451 |
|
|
452 |
if (g_xserver_be) |
if (g_xserver_be) |
453 |
{ |
{ |
476 |
|
|
477 |
if (g_host_be) |
if (g_host_be) |
478 |
{ |
{ |
479 |
BSWAP16(pixel) |
BSWAP16(pixel); |
480 |
} |
} |
481 |
|
|
482 |
value = make_colour32(split_colour16(pixel)); |
value = make_colour(split_colour16(pixel)); |
483 |
|
|
484 |
if (g_xserver_be) |
if (g_xserver_be) |
485 |
{ |
{ |
487 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
488 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
489 |
*(out++) = value; |
*(out++) = value; |
490 |
} |
} |
491 |
else |
else |
492 |
{ |
{ |
493 |
*(out++) = value; |
*(out++) = value; |
494 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
495 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
496 |
*(out++) = value >> 24; |
*(out++) = value >> 24; |
497 |
} |
} |
498 |
} |
} |
499 |
} |
} |
500 |
|
|
501 |
static void |
static void |
509 |
pixel |= *(data++) << 8; |
pixel |= *(data++) << 8; |
510 |
pixel |= *(data++); |
pixel |= *(data++); |
511 |
|
|
512 |
value = (uint16) make_colour16(split_colour24(pixel)); |
value = (uint16) make_colour(split_colour24(pixel)); |
513 |
|
|
514 |
if (g_xserver_be) |
if (g_xserver_be) |
515 |
{ |
{ |
527 |
static void |
static void |
528 |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
529 |
{ |
{ |
530 |
|
uint32 pixel; |
531 |
|
uint32 value; |
532 |
|
|
533 |
while (out < end) |
while (out < end) |
534 |
{ |
{ |
535 |
*(out++) = (*(data++)); |
pixel = *(data++) << 16; |
536 |
|
pixel |= *(data++) << 8; |
537 |
|
pixel |= *(data++); |
538 |
|
|
539 |
|
value = make_colour(split_colour24(pixel)); |
540 |
|
|
541 |
|
if (g_xserver_be) |
542 |
|
{ |
543 |
|
*(out++) = value >> 16; |
544 |
|
*(out++) = value >> 8; |
545 |
|
*(out++) = value; |
546 |
|
} |
547 |
|
else |
548 |
|
{ |
549 |
|
*(out++) = value; |
550 |
|
*(out++) = value >> 8; |
551 |
|
*(out++) = value >> 16; |
552 |
|
} |
553 |
} |
} |
554 |
} |
} |
555 |
|
|
556 |
static void |
static void |
557 |
translate24to32(uint8 * data, uint8 * out, uint8 * end) |
translate24to32(uint8 * data, uint8 * out, uint8 * end) |
558 |
{ |
{ |
559 |
|
uint32 pixel; |
560 |
|
uint32 value; |
561 |
|
|
562 |
while (out < end) |
while (out < end) |
563 |
{ |
{ |
564 |
|
pixel = *(data++) << 16; |
565 |
|
pixel |= *(data++) << 8; |
566 |
|
pixel |= *(data++); |
567 |
|
|
568 |
|
value = make_colour(split_colour24(pixel)); |
569 |
|
|
570 |
if (g_xserver_be) |
if (g_xserver_be) |
571 |
{ |
{ |
572 |
*(out++) = 0x00; |
*(out++) = value >> 24; |
573 |
*(out++) = *(data++); |
*(out++) = value >> 16; |
574 |
*(out++) = *(data++); |
*(out++) = value >> 8; |
575 |
*(out++) = *(data++); |
*(out++) = value; |
576 |
} |
} |
577 |
else |
else |
578 |
{ |
{ |
579 |
*(out++) = *(data++); |
*(out++) = value; |
580 |
*(out++) = *(data++); |
*(out++) = value >> 8; |
581 |
*(out++) = *(data++); |
*(out++) = value >> 16; |
582 |
*(out++) = 0x00; |
*(out++) = value >> 24; |
583 |
} |
} |
584 |
} |
} |
585 |
} |
} |
617 |
translate16to24((uint16 *) data, out, end); |
translate16to24((uint16 *) data, out, end); |
618 |
break; |
break; |
619 |
case 16: |
case 16: |
620 |
translate16to16((uint16 *) data, (uint16 *) out, |
translate16to16((uint16 *) data, out, end); |
|
(uint16 *) end); |
|
621 |
break; |
break; |
622 |
} |
} |
623 |
break; |
break; |
642 |
translate8to8(data, out, end); |
translate8to8(data, out, end); |
643 |
break; |
break; |
644 |
case 16: |
case 16: |
645 |
translate8to16(data, (uint16 *) out, (uint16 *) end); |
translate8to16(data, out, end); |
646 |
break; |
break; |
647 |
case 24: |
case 24: |
648 |
translate8to24(data, out, end); |
translate8to24(data, out, end); |
649 |
break; |
break; |
650 |
case 32: |
case 32: |
651 |
translate8to32(data, (uint32 *) out, (uint32 *) end); |
translate8to32(data, out, end); |
652 |
break; |
break; |
653 |
} |
} |
654 |
break; |
break; |
681 |
return (state & keysymMask) ? True : False; |
return (state & keysymMask) ? True : False; |
682 |
} |
} |
683 |
|
|
684 |
|
static void |
685 |
|
calculate_shifts(uint32 mask, int *shift_r, int *shift_l) |
686 |
|
{ |
687 |
|
*shift_l = ffs(mask) - 1; |
688 |
|
mask >>= *shift_l; |
689 |
|
*shift_r = 8 - ffs(mask & ~(mask >> 1)); |
690 |
|
} |
691 |
|
|
692 |
BOOL |
BOOL |
693 |
ui_init(void) |
ui_init(void) |
694 |
{ |
{ |
695 |
|
XVisualInfo vi; |
696 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
697 |
uint16 test; |
uint16 test; |
698 |
int i; |
int i, screen_num, nvisuals; |
699 |
|
XVisualInfo *vmatches = NULL; |
700 |
|
XVisualInfo template; |
701 |
|
Bool TrueColorVisual = False; |
702 |
|
|
703 |
g_display = XOpenDisplay(NULL); |
g_display = XOpenDisplay(NULL); |
704 |
if (g_display == NULL) |
if (g_display == NULL) |
707 |
return False; |
return False; |
708 |
} |
} |
709 |
|
|
710 |
|
screen_num = DefaultScreen(g_display); |
711 |
g_x_socket = ConnectionNumber(g_display); |
g_x_socket = ConnectionNumber(g_display); |
712 |
g_screen = DefaultScreenOfDisplay(g_display); |
g_screen = ScreenOfDisplay(g_display, screen_num); |
|
g_visual = DefaultVisualOfScreen(g_screen); |
|
713 |
g_depth = DefaultDepthOfScreen(g_screen); |
g_depth = DefaultDepthOfScreen(g_screen); |
714 |
|
|
715 |
|
/* Search for best TrueColor depth */ |
716 |
|
template.class = TrueColor; |
717 |
|
vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals); |
718 |
|
|
719 |
|
nvisuals--; |
720 |
|
while (nvisuals >= 0) |
721 |
|
{ |
722 |
|
if ((vmatches + nvisuals)->depth > g_depth) |
723 |
|
{ |
724 |
|
g_depth = (vmatches + nvisuals)->depth; |
725 |
|
} |
726 |
|
nvisuals--; |
727 |
|
TrueColorVisual = True; |
728 |
|
} |
729 |
|
|
730 |
|
if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8))) |
731 |
|
{ |
732 |
|
/* we use a colourmap, so the default visual should do */ |
733 |
|
g_visual = DefaultVisualOfScreen(g_screen); |
734 |
|
g_depth = DefaultDepthOfScreen(g_screen); |
735 |
|
|
736 |
|
/* Do not allocate colours on a TrueColor visual */ |
737 |
|
if (g_visual->class == TrueColor) |
738 |
|
{ |
739 |
|
g_owncolmap = False; |
740 |
|
} |
741 |
|
} |
742 |
|
else |
743 |
|
{ |
744 |
|
/* need a truecolour visual */ |
745 |
|
if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi)) |
746 |
|
{ |
747 |
|
error("The display does not support true colour - high colour support unavailable.\n"); |
748 |
|
return False; |
749 |
|
} |
750 |
|
|
751 |
|
g_visual = vi.visual; |
752 |
|
g_owncolmap = False; |
753 |
|
calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l); |
754 |
|
calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l); |
755 |
|
calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l); |
756 |
|
} |
757 |
|
|
758 |
pfm = XListPixmapFormats(g_display, &i); |
pfm = XListPixmapFormats(g_display, &i); |
759 |
if (pfm != NULL) |
if (pfm != NULL) |
760 |
{ |
{ |
777 |
return False; |
return False; |
778 |
} |
} |
779 |
|
|
780 |
if (g_owncolmap != True) |
if (!g_owncolmap) |
781 |
{ |
{ |
782 |
g_xcolmap = DefaultColormapOfScreen(g_screen); |
g_xcolmap = |
783 |
|
XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual, |
784 |
|
AllocNone); |
785 |
if (g_depth <= 8) |
if (g_depth <= 8) |
786 |
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"); |
787 |
} |
} |
788 |
|
|
789 |
g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL); |
if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) |
790 |
|
{ |
791 |
if (DoesBackingStore(g_screen) != Always) |
warning("External BackingStore not available, using internal\n"); |
792 |
g_ownbackstore = True; |
g_ownbackstore = True; |
793 |
|
} |
794 |
|
|
795 |
test = 1; |
test = 1; |
796 |
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
797 |
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
798 |
|
|
799 |
if ((g_width == 0) || (g_height == 0)) |
/* |
800 |
|
* Determine desktop size |
801 |
|
*/ |
802 |
|
if (g_fullscreen) |
803 |
|
{ |
804 |
|
g_width = WidthOfScreen(g_screen); |
805 |
|
g_height = HeightOfScreen(g_screen); |
806 |
|
} |
807 |
|
else if (g_width < 0) |
808 |
|
{ |
809 |
|
/* Percent of screen */ |
810 |
|
g_height = HeightOfScreen(g_screen) * (-g_width) / 100; |
811 |
|
g_width = WidthOfScreen(g_screen) * (-g_width) / 100; |
812 |
|
} |
813 |
|
else if (g_width == 0) |
814 |
{ |
{ |
815 |
/* Fetch geometry from _NET_WORKAREA */ |
/* Fetch geometry from _NET_WORKAREA */ |
816 |
uint32 x, y, cx, cy; |
uint32 x, y, cx, cy; |
828 |
} |
} |
829 |
} |
} |
830 |
|
|
|
if (g_fullscreen) |
|
|
{ |
|
|
g_width = WidthOfScreen(g_screen); |
|
|
g_height = HeightOfScreen(g_screen); |
|
|
} |
|
|
|
|
831 |
/* make sure width is a multiple of 4 */ |
/* make sure width is a multiple of 4 */ |
832 |
g_width = (g_width + 3) & ~3; |
g_width = (g_width + 3) & ~3; |
833 |
|
|
|
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); |
|
|
} |
|
|
|
|
834 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
835 |
|
|
836 |
|
xkeymap_init(); |
837 |
|
|
838 |
if (g_enable_compose) |
if (g_enable_compose) |
839 |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
840 |
|
|
|
xkeymap_init(); |
|
841 |
xclip_init(); |
xclip_init(); |
842 |
|
|
843 |
/* 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); |
|
844 |
|
|
845 |
return True; |
return True; |
846 |
} |
} |
851 |
if (g_IM != NULL) |
if (g_IM != NULL) |
852 |
XCloseIM(g_IM); |
XCloseIM(g_IM); |
853 |
|
|
854 |
|
if (g_null_cursor != NULL) |
855 |
|
ui_destroy_cursor(g_null_cursor); |
856 |
|
|
857 |
XFreeModifiermap(g_mod_map); |
XFreeModifiermap(g_mod_map); |
858 |
|
|
859 |
if (g_ownbackstore) |
if (g_ownbackstore) |
867 |
BOOL |
BOOL |
868 |
ui_create_window(void) |
ui_create_window(void) |
869 |
{ |
{ |
870 |
|
uint8 null_pointer_mask[1] = { 0x80 }; |
871 |
|
uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 }; |
872 |
XSetWindowAttributes attribs; |
XSetWindowAttributes attribs; |
873 |
XClassHint *classhints; |
XClassHint *classhints; |
874 |
XSizeHints *sizehints; |
XSizeHints *sizehints; |
880 |
wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; |
wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; |
881 |
|
|
882 |
attribs.background_pixel = BlackPixelOfScreen(g_screen); |
attribs.background_pixel = BlackPixelOfScreen(g_screen); |
883 |
|
attribs.border_pixel = WhitePixelOfScreen(g_screen); |
884 |
attribs.backing_store = g_ownbackstore ? NotUseful : Always; |
attribs.backing_store = g_ownbackstore ? NotUseful : Always; |
885 |
attribs.override_redirect = g_fullscreen; |
attribs.override_redirect = g_fullscreen; |
886 |
|
attribs.colormap = g_xcolmap; |
887 |
|
|
888 |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight, |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight, |
889 |
0, CopyFromParent, InputOutput, CopyFromParent, |
0, g_depth, InputOutput, g_visual, |
890 |
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
CWBackPixel | CWBackingStore | CWOverrideRedirect | |
891 |
|
CWColormap | CWBorderPixel, &attribs); |
892 |
|
|
893 |
|
if (g_gc == NULL) |
894 |
|
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
895 |
|
|
896 |
|
if ((g_ownbackstore) && (g_backstore == 0)) |
897 |
|
{ |
898 |
|
g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth); |
899 |
|
|
900 |
|
/* clear to prevent rubbish being exposed at startup */ |
901 |
|
XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen)); |
902 |
|
XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height); |
903 |
|
} |
904 |
|
|
905 |
XStoreName(g_display, g_wnd, g_title); |
XStoreName(g_display, g_wnd, g_title); |
906 |
|
|
965 |
g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True); |
g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True); |
966 |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
967 |
|
|
968 |
|
/* create invisible 1x1 cursor to be used as null cursor */ |
969 |
|
if (g_null_cursor == NULL) |
970 |
|
g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data); |
971 |
|
|
972 |
return True; |
return True; |
973 |
} |
} |
974 |
|
|
1018 |
key_translation tr; |
key_translation tr; |
1019 |
char str[256]; |
char str[256]; |
1020 |
Status status; |
Status status; |
|
unsigned int state; |
|
|
Window wdummy; |
|
|
int dummy; |
|
1021 |
|
|
1022 |
while (XPending(g_display) > 0) |
while (XPending(g_display) > 0) |
1023 |
{ |
{ |
1190 |
if (xevent.xfocus.mode == NotifyGrab) |
if (xevent.xfocus.mode == NotifyGrab) |
1191 |
break; |
break; |
1192 |
g_focused = True; |
g_focused = True; |
1193 |
XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, |
reset_modifier_keys(); |
|
&dummy, &dummy, &state); |
|
|
reset_modifier_keys(state); |
|
1194 |
if (g_grab_keyboard && g_mouse_in_wnd) |
if (g_grab_keyboard && g_mouse_in_wnd) |
1195 |
XGrabKeyboard(g_display, g_wnd, True, |
XGrabKeyboard(g_display, g_wnd, True, |
1196 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
1270 |
int |
int |
1271 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
1272 |
{ |
{ |
1273 |
int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1; |
int n; |
1274 |
fd_set rfds, wfds; |
fd_set rfds, wfds; |
1275 |
|
struct timeval tv; |
1276 |
|
BOOL s_timeout = False; |
1277 |
|
|
1278 |
while (True) |
while (True) |
1279 |
{ |
{ |
1280 |
|
n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket; |
1281 |
/* Process any events already waiting */ |
/* Process any events already waiting */ |
1282 |
if (!xwin_process_events()) |
if (!xwin_process_events()) |
1283 |
/* User quit */ |
/* User quit */ |
1293 |
if (g_dsp_busy) |
if (g_dsp_busy) |
1294 |
{ |
{ |
1295 |
FD_SET(g_dsp_fd, &wfds); |
FD_SET(g_dsp_fd, &wfds); |
1296 |
n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; |
n = (g_dsp_fd > n) ? g_dsp_fd : n; |
1297 |
} |
} |
1298 |
#endif |
#endif |
1299 |
|
/* default timeout */ |
1300 |
|
tv.tv_sec = 60; |
1301 |
|
tv.tv_usec = 0; |
1302 |
|
|
1303 |
|
/* add redirection handles */ |
1304 |
|
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
1305 |
|
|
1306 |
|
n++; |
1307 |
|
|
1308 |
switch (select(n, &rfds, &wfds, NULL, NULL)) |
switch (select(n, &rfds, &wfds, NULL, &tv)) |
1309 |
{ |
{ |
1310 |
case -1: |
case -1: |
1311 |
error("select: %s\n", strerror(errno)); |
error("select: %s\n", strerror(errno)); |
1312 |
|
|
1313 |
case 0: |
case 0: |
1314 |
|
/* TODO: if tv.tv_sec just times out |
1315 |
|
* we will segfault. |
1316 |
|
* FIXME: |
1317 |
|
*/ |
1318 |
|
//s_timeout = True; |
1319 |
|
//rdpdr_check_fds(&rfds, &wfds, (BOOL) True); |
1320 |
continue; |
continue; |
1321 |
} |
} |
1322 |
|
|
1323 |
|
rdpdr_check_fds(&rfds, &wfds, (BOOL) False); |
1324 |
|
|
1325 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
1326 |
return 1; |
return 1; |
1327 |
|
|
1344 |
XImage *image; |
XImage *image; |
1345 |
Pixmap bitmap; |
Pixmap bitmap; |
1346 |
uint8 *tdata; |
uint8 *tdata; |
1347 |
|
int bitmap_pad; |
1348 |
|
|
1349 |
|
if (g_server_bpp == 8) |
1350 |
|
{ |
1351 |
|
bitmap_pad = 8; |
1352 |
|
} |
1353 |
|
else |
1354 |
|
{ |
1355 |
|
bitmap_pad = g_bpp; |
1356 |
|
|
1357 |
|
if (g_bpp == 24) |
1358 |
|
bitmap_pad = 32; |
1359 |
|
} |
1360 |
|
|
1361 |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
1362 |
bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth); |
bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth); |
1363 |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
1364 |
(char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); |
(char *) tdata, width, height, bitmap_pad, 0); |
1365 |
|
|
1366 |
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); |
1367 |
|
|
1376 |
{ |
{ |
1377 |
XImage *image; |
XImage *image; |
1378 |
uint8 *tdata; |
uint8 *tdata; |
1379 |
|
int bitmap_pad; |
1380 |
|
|
1381 |
|
if (g_server_bpp == 8) |
1382 |
|
{ |
1383 |
|
bitmap_pad = 8; |
1384 |
|
} |
1385 |
|
else |
1386 |
|
{ |
1387 |
|
bitmap_pad = g_bpp; |
1388 |
|
|
1389 |
|
if (g_bpp == 24) |
1390 |
|
bitmap_pad = 32; |
1391 |
|
} |
1392 |
|
|
1393 |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
1394 |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
1395 |
(char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); |
(char *) tdata, width, height, bitmap_pad, 0); |
1396 |
|
|
1397 |
if (g_ownbackstore) |
if (g_ownbackstore) |
1398 |
{ |
{ |
1531 |
XFreeCursor(g_display, (Cursor) cursor); |
XFreeCursor(g_display, (Cursor) cursor); |
1532 |
} |
} |
1533 |
|
|
1534 |
|
void |
1535 |
|
ui_set_null_cursor(void) |
1536 |
|
{ |
1537 |
|
ui_set_cursor(g_null_cursor); |
1538 |
|
} |
1539 |
|
|
1540 |
#define MAKE_XCOLOR(xc,c) \ |
#define MAKE_XCOLOR(xc,c) \ |
1541 |
(xc)->red = ((c)->red << 8) | (c)->red; \ |
(xc)->red = ((c)->red << 8) | (c)->red; \ |
1542 |
(xc)->green = ((c)->green << 8) | (c)->green; \ |
(xc)->green = ((c)->green << 8) | (c)->green; \ |
1618 |
|
|
1619 |
} |
} |
1620 |
|
|
1621 |
|
map[i] = colour; |
|
/* byte swap here to make translate_image faster */ |
|
|
map[i] = translate_colour(colour); |
|
1622 |
} |
} |
1623 |
return map; |
return map; |
1624 |
} |
} |
1777 |
/* src */ int srcx, int srcy) |
/* src */ int srcx, int srcy) |
1778 |
{ |
{ |
1779 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
|
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
|
1780 |
if (g_ownbackstore) |
if (g_ownbackstore) |
1781 |
|
{ |
1782 |
|
XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
1783 |
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); |
1784 |
|
} |
1785 |
|
else |
1786 |
|
{ |
1787 |
|
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
1788 |
|
} |
1789 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
1790 |
} |
} |
1791 |
|
|
1880 |
{\ |
{\ |
1881 |
glyph = cache_get_font (font, ttext[idx]);\ |
glyph = cache_get_font (font, ttext[idx]);\ |
1882 |
if (!(flags & TEXT2_IMPLICIT_X))\ |
if (!(flags & TEXT2_IMPLICIT_X))\ |
1883 |
|
{\ |
1884 |
|
xyoffset = ttext[++idx];\ |
1885 |
|
if ((xyoffset & 0x80))\ |
1886 |
{\ |
{\ |
1887 |
xyoffset = ttext[++idx];\ |
if (flags & TEXT2_VERTICAL)\ |
1888 |
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;\ |
|
|
}\ |
|
1889 |
else\ |
else\ |
1890 |
{\ |
x += ttext[idx+1] | (ttext[idx+2] << 8);\ |
1891 |
if (flags & TEXT2_VERTICAL) \ |
idx += 2;\ |
|
y += xyoffset;\ |
|
|
else\ |
|
|
x += xyoffset;\ |
|
|
}\ |
|
1892 |
}\ |
}\ |
1893 |
if (glyph != NULL)\ |
else\ |
1894 |
{\ |
{\ |
1895 |
ui_draw_glyph (mixmode, x + glyph->offset,\ |
if (flags & TEXT2_VERTICAL)\ |
1896 |
y + glyph->baseline,\ |
y += xyoffset;\ |
1897 |
glyph->width, glyph->height,\ |
else\ |
1898 |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
x += xyoffset;\ |
|
if (flags & TEXT2_IMPLICIT_X)\ |
|
|
x += glyph->width;\ |
|
1899 |
}\ |
}\ |
1900 |
|
}\ |
1901 |
|
if (glyph != NULL)\ |
1902 |
|
{\ |
1903 |
|
x1 = x + glyph->offset;\ |
1904 |
|
y1 = y + glyph->baseline;\ |
1905 |
|
XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\ |
1906 |
|
XSetTSOrigin(g_display, g_gc, x1, y1);\ |
1907 |
|
FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\ |
1908 |
|
if (flags & TEXT2_IMPLICIT_X)\ |
1909 |
|
x += glyph->width;\ |
1910 |
|
}\ |
1911 |
} |
} |
1912 |
|
|
1913 |
void |
void |
1917 |
int fgcolour, uint8 * text, uint8 length) |
int fgcolour, uint8 * text, uint8 length) |
1918 |
{ |
{ |
1919 |
FONTGLYPH *glyph; |
FONTGLYPH *glyph; |
1920 |
int i, j, xyoffset; |
int i, j, xyoffset, x1, y1; |
1921 |
DATABLOB *entry; |
DATABLOB *entry; |
1922 |
|
|
1923 |
SET_FOREGROUND(bgcolour); |
SET_FOREGROUND(bgcolour); |
1931 |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
1932 |
} |
} |
1933 |
|
|
1934 |
|
SET_FOREGROUND(fgcolour); |
1935 |
|
SET_BACKGROUND(bgcolour); |
1936 |
|
XSetFillStyle(g_display, g_gc, FillStippled); |
1937 |
|
|
1938 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
1939 |
for (i = 0; i < length;) |
for (i = 0; i < length;) |
1940 |
{ |
{ |
1985 |
break; |
break; |
1986 |
} |
} |
1987 |
} |
} |
1988 |
|
|
1989 |
|
XSetFillStyle(g_display, g_gc, FillSolid); |
1990 |
|
|
1991 |
if (g_ownbackstore) |
if (g_ownbackstore) |
1992 |
{ |
{ |
1993 |
if (boxcx > 1) |
if (boxcx > 1) |