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 <time.h> |
#include <time.h> |
25 |
#include <errno.h> |
#include <errno.h> |
26 |
#include "rdesktop.h" |
#include "rdesktop.h" |
64 |
/* software backing store */ |
/* software backing store */ |
65 |
static BOOL g_ownbackstore; |
static BOOL g_ownbackstore; |
66 |
static Pixmap g_backstore; |
static Pixmap g_backstore; |
67 |
|
static BOOL g_backstore_initialized = False; |
68 |
|
|
69 |
/* Moving in single app mode */ |
/* Moving in single app mode */ |
70 |
static BOOL g_moving_wnd; |
static BOOL g_moving_wnd; |
209 |
} |
} |
210 |
|
|
211 |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
212 |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); } |
213 |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
214 |
x = (x << 16) | (x >> 16); } |
x = (x << 16) | (x >> 16); } |
215 |
|
|
247 |
while (out < end) |
while (out < end) |
248 |
{ |
{ |
249 |
value = (uint16) g_colmap[*(data++)]; |
value = (uint16) g_colmap[*(data++)]; |
250 |
|
|
251 |
if (g_xserver_be) |
if (g_xserver_be) |
252 |
{ |
{ |
253 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
270 |
while (out < end) |
while (out < end) |
271 |
{ |
{ |
272 |
value = g_colmap[*(data++)]; |
value = g_colmap[*(data++)]; |
273 |
|
|
274 |
if (g_xserver_be) |
if (g_xserver_be) |
275 |
{ |
{ |
276 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
312 |
} |
} |
313 |
} |
} |
314 |
|
|
|
/* todo the remaining translate function might need some big endian check ?? */ |
|
|
|
|
315 |
static void |
static void |
316 |
translate15to16(uint16 * data, uint8 * out, uint8 * end) |
translate15to16(uint16 * data, uint8 * out, uint8 * end) |
317 |
{ |
{ |
481 |
|
|
482 |
if (g_host_be) |
if (g_host_be) |
483 |
{ |
{ |
484 |
BSWAP16(pixel)} |
BSWAP16(pixel); |
485 |
|
} |
486 |
|
|
487 |
value = make_colour(split_colour16(pixel)); |
value = make_colour(split_colour16(pixel)); |
488 |
|
|
532 |
static void |
static void |
533 |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
534 |
{ |
{ |
535 |
|
uint32 pixel; |
536 |
|
uint32 value; |
537 |
|
|
538 |
while (out < end) |
while (out < end) |
539 |
{ |
{ |
540 |
*(out++) = (*(data++)); |
pixel = *(data++) << 16; |
541 |
|
pixel |= *(data++) << 8; |
542 |
|
pixel |= *(data++); |
543 |
|
|
544 |
|
value = make_colour(split_colour24(pixel)); |
545 |
|
|
546 |
|
if (g_xserver_be) |
547 |
|
{ |
548 |
|
*(out++) = value >> 16; |
549 |
|
*(out++) = value >> 8; |
550 |
|
*(out++) = value; |
551 |
|
} |
552 |
|
else |
553 |
|
{ |
554 |
|
*(out++) = value; |
555 |
|
*(out++) = value >> 8; |
556 |
|
*(out++) = value >> 16; |
557 |
|
} |
558 |
} |
} |
559 |
} |
} |
560 |
|
|
561 |
static void |
static void |
562 |
translate24to32(uint8 * data, uint8 * out, uint8 * end) |
translate24to32(uint8 * data, uint8 * out, uint8 * end) |
563 |
{ |
{ |
564 |
|
uint32 pixel; |
565 |
|
uint32 value; |
566 |
|
|
567 |
while (out < end) |
while (out < end) |
568 |
{ |
{ |
569 |
|
pixel = *(data++) << 16; |
570 |
|
pixel |= *(data++) << 8; |
571 |
|
pixel |= *(data++); |
572 |
|
|
573 |
|
value = make_colour(split_colour24(pixel)); |
574 |
|
|
575 |
if (g_xserver_be) |
if (g_xserver_be) |
576 |
{ |
{ |
577 |
*(out++) = 0x00; |
*(out++) = value >> 24; |
578 |
*(out++) = *(data++); |
*(out++) = value >> 16; |
579 |
*(out++) = *(data++); |
*(out++) = value >> 8; |
580 |
*(out++) = *(data++); |
*(out++) = value; |
581 |
} |
} |
582 |
else |
else |
583 |
{ |
{ |
584 |
*(out++) = *(data++); |
*(out++) = value; |
585 |
*(out++) = *(data++); |
*(out++) = value >> 8; |
586 |
*(out++) = *(data++); |
*(out++) = value >> 16; |
587 |
*(out++) = 0x00; |
*(out++) = value >> 24; |
588 |
} |
} |
589 |
} |
} |
590 |
} |
} |
700 |
XVisualInfo vi; |
XVisualInfo vi; |
701 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
702 |
uint16 test; |
uint16 test; |
703 |
int i, screen_num; |
int i, screen_num, nvisuals; |
704 |
|
XVisualInfo *vmatches = NULL; |
705 |
|
XVisualInfo template; |
706 |
|
Bool TrueColorVisual = False; |
707 |
|
|
708 |
g_display = XOpenDisplay(NULL); |
g_display = XOpenDisplay(NULL); |
709 |
if (g_display == NULL) |
if (g_display == NULL) |
717 |
g_screen = ScreenOfDisplay(g_display, screen_num); |
g_screen = ScreenOfDisplay(g_display, screen_num); |
718 |
g_depth = DefaultDepthOfScreen(g_screen); |
g_depth = DefaultDepthOfScreen(g_screen); |
719 |
|
|
720 |
if (g_server_bpp == 8) |
/* Search for best TrueColor depth */ |
721 |
|
template.class = TrueColor; |
722 |
|
vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals); |
723 |
|
|
724 |
|
nvisuals--; |
725 |
|
while (nvisuals >= 0) |
726 |
{ |
{ |
727 |
/* we use a colourmap, so any visual should do */ |
if ((vmatches + nvisuals)->depth > g_depth) |
728 |
|
{ |
729 |
|
g_depth = (vmatches + nvisuals)->depth; |
730 |
|
} |
731 |
|
nvisuals--; |
732 |
|
TrueColorVisual = True; |
733 |
|
} |
734 |
|
|
735 |
|
if ((g_server_bpp == 8) && ((! TrueColorVisual) || (g_depth <= 8))) |
736 |
|
{ |
737 |
|
/* we use a colourmap, so the default visual should do */ |
738 |
g_visual = DefaultVisualOfScreen(g_screen); |
g_visual = DefaultVisualOfScreen(g_screen); |
739 |
|
g_depth = DefaultDepthOfScreen(g_screen); |
740 |
|
|
741 |
|
/* Do not allocate colours on a TrueColor visual */ |
742 |
|
if (g_visual->class == TrueColor) |
743 |
|
{ |
744 |
|
g_owncolmap = False; |
745 |
|
} |
746 |
} |
} |
747 |
else |
else |
748 |
{ |
{ |
755 |
|
|
756 |
g_visual = vi.visual; |
g_visual = vi.visual; |
757 |
g_owncolmap = False; |
g_owncolmap = False; |
758 |
calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l); |
calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l); |
759 |
calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l); |
calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l); |
760 |
calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l); |
calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l); |
761 |
} |
} |
762 |
|
|
784 |
|
|
785 |
if (!g_owncolmap) |
if (!g_owncolmap) |
786 |
{ |
{ |
787 |
g_xcolmap = DefaultColormapOfScreen(g_screen); |
g_xcolmap = XCreateColormap(g_display,RootWindowOfScreen(g_screen),g_visual,AllocNone); |
788 |
if (g_depth <= 8) |
if (g_depth <= 8) |
789 |
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"); |
790 |
} |
} |
791 |
|
|
|
g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL); |
|
|
|
|
792 |
if (DoesBackingStore(g_screen) != Always) |
if (DoesBackingStore(g_screen) != Always) |
793 |
g_ownbackstore = True; |
g_ownbackstore = True; |
794 |
|
|
799 |
/* |
/* |
800 |
* Determine desktop size |
* Determine desktop size |
801 |
*/ |
*/ |
802 |
if (g_width < 0) |
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 */ |
/* Percent of screen */ |
810 |
g_height = HeightOfScreen(g_screen) * (-g_width) / 100; |
g_height = HeightOfScreen(g_screen) * (-g_width) / 100; |
827 |
g_height = 600; |
g_height = 600; |
828 |
} |
} |
829 |
} |
} |
|
else if (g_fullscreen) |
|
|
{ |
|
|
g_width = WidthOfScreen(g_screen); |
|
|
g_height = HeightOfScreen(g_screen); |
|
|
} |
|
830 |
|
|
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(); |
xkeymap_init(); |
861 |
g_display = NULL; |
g_display = NULL; |
862 |
} |
} |
863 |
|
|
|
#define NULL_POINTER_MASK "\x80" |
|
|
#define NULL_POINTER_DATA "\x0\x0\x0" |
|
|
|
|
864 |
BOOL |
BOOL |
865 |
ui_create_window(void) |
ui_create_window(void) |
866 |
{ |
{ |
867 |
|
uint8 null_pointer_mask[1] = { 0x80 }; |
868 |
|
uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 }; |
869 |
XSetWindowAttributes attribs; |
XSetWindowAttributes attribs; |
870 |
XClassHint *classhints; |
XClassHint *classhints; |
871 |
XSizeHints *sizehints; |
XSizeHints *sizehints; |
877 |
wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; |
wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; |
878 |
|
|
879 |
attribs.background_pixel = BlackPixelOfScreen(g_screen); |
attribs.background_pixel = BlackPixelOfScreen(g_screen); |
880 |
|
attribs.border_pixel = WhitePixelOfScreen(g_screen); |
881 |
attribs.backing_store = g_ownbackstore ? NotUseful : Always; |
attribs.backing_store = g_ownbackstore ? NotUseful : Always; |
882 |
attribs.override_redirect = g_fullscreen; |
attribs.override_redirect = g_fullscreen; |
883 |
|
attribs.colormap = g_xcolmap; |
884 |
|
|
885 |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight, |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight, |
886 |
0, CopyFromParent, InputOutput, CopyFromParent, |
0, g_depth, InputOutput, g_visual, |
887 |
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
CWBackPixel | CWBackingStore | CWOverrideRedirect | |
888 |
|
CWColormap | CWBorderPixel, &attribs); |
889 |
|
|
890 |
|
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
891 |
|
|
892 |
|
if ((g_ownbackstore) && (! g_backstore_initialized)) |
893 |
|
{ |
894 |
|
g_backstore = |
895 |
|
XCreatePixmap(g_display, g_wnd, g_width, g_height, |
896 |
|
g_depth); |
897 |
|
|
898 |
|
/* clear to prevent rubbish being exposed at startup */ |
899 |
|
XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen)); |
900 |
|
XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height); |
901 |
|
g_backstore_initialized = True; |
902 |
|
} |
903 |
|
|
904 |
XStoreName(g_display, g_wnd, g_title); |
XStoreName(g_display, g_wnd, g_title); |
905 |
|
|
965 |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
966 |
|
|
967 |
/* create invisible 1x1 cursor to be used as null cursor */ |
/* create invisible 1x1 cursor to be used as null cursor */ |
968 |
g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA); |
g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data); |
969 |
|
|
970 |
return True; |
return True; |
971 |
} |
} |
973 |
void |
void |
974 |
ui_destroy_window(void) |
ui_destroy_window(void) |
975 |
{ |
{ |
|
ui_destroy_cursor(g_null_cursor); |
|
|
|
|
976 |
if (g_IC != NULL) |
if (g_IC != NULL) |
977 |
XDestroyIC(g_IC); |
XDestroyIC(g_IC); |
978 |
|
|
1016 |
key_translation tr; |
key_translation tr; |
1017 |
char str[256]; |
char str[256]; |
1018 |
Status status; |
Status status; |
|
unsigned int state; |
|
|
Window wdummy; |
|
|
int dummy; |
|
1019 |
|
|
1020 |
while (XPending(g_display) > 0) |
while (XPending(g_display) > 0) |
1021 |
{ |
{ |
1188 |
if (xevent.xfocus.mode == NotifyGrab) |
if (xevent.xfocus.mode == NotifyGrab) |
1189 |
break; |
break; |
1190 |
g_focused = True; |
g_focused = True; |
1191 |
XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, |
reset_modifier_keys(); |
|
&dummy, &dummy, &state); |
|
|
reset_modifier_keys(state); |
|
1192 |
if (g_grab_keyboard && g_mouse_in_wnd) |
if (g_grab_keyboard && g_mouse_in_wnd) |
1193 |
XGrabKeyboard(g_display, g_wnd, True, |
XGrabKeyboard(g_display, g_wnd, True, |
1194 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
1853 |
{\ |
{\ |
1854 |
glyph = cache_get_font (font, ttext[idx]);\ |
glyph = cache_get_font (font, ttext[idx]);\ |
1855 |
if (!(flags & TEXT2_IMPLICIT_X))\ |
if (!(flags & TEXT2_IMPLICIT_X))\ |
1856 |
|
{\ |
1857 |
|
xyoffset = ttext[++idx];\ |
1858 |
|
if ((xyoffset & 0x80))\ |
1859 |
{\ |
{\ |
1860 |
xyoffset = ttext[++idx];\ |
if (flags & TEXT2_VERTICAL)\ |
1861 |
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;\ |
|
|
}\ |
|
1862 |
else\ |
else\ |
1863 |
{\ |
x += ttext[idx+1] | (ttext[idx+2] << 8);\ |
1864 |
if (flags & TEXT2_VERTICAL) \ |
idx += 2;\ |
|
y += xyoffset;\ |
|
|
else\ |
|
|
x += xyoffset;\ |
|
|
}\ |
|
1865 |
}\ |
}\ |
1866 |
if (glyph != NULL)\ |
else\ |
1867 |
{\ |
{\ |
1868 |
ui_draw_glyph (mixmode, x + glyph->offset,\ |
if (flags & TEXT2_VERTICAL)\ |
1869 |
y + glyph->baseline,\ |
y += xyoffset;\ |
1870 |
glyph->width, glyph->height,\ |
else\ |
1871 |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
x += xyoffset;\ |
|
if (flags & TEXT2_IMPLICIT_X)\ |
|
|
x += glyph->width;\ |
|
1872 |
}\ |
}\ |
1873 |
|
}\ |
1874 |
|
if (glyph != NULL)\ |
1875 |
|
{\ |
1876 |
|
x1 = x + glyph->offset;\ |
1877 |
|
y1 = y + glyph->baseline;\ |
1878 |
|
XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\ |
1879 |
|
XSetTSOrigin(g_display, g_gc, x1, y1);\ |
1880 |
|
FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\ |
1881 |
|
if (flags & TEXT2_IMPLICIT_X)\ |
1882 |
|
x += glyph->width;\ |
1883 |
|
}\ |
1884 |
} |
} |
1885 |
|
|
1886 |
void |
void |
1890 |
int fgcolour, uint8 * text, uint8 length) |
int fgcolour, uint8 * text, uint8 length) |
1891 |
{ |
{ |
1892 |
FONTGLYPH *glyph; |
FONTGLYPH *glyph; |
1893 |
int i, j, xyoffset; |
int i, j, xyoffset, x1, y1; |
1894 |
DATABLOB *entry; |
DATABLOB *entry; |
1895 |
|
|
1896 |
SET_FOREGROUND(bgcolour); |
SET_FOREGROUND(bgcolour); |
1904 |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
1905 |
} |
} |
1906 |
|
|
1907 |
|
SET_FOREGROUND(fgcolour); |
1908 |
|
SET_BACKGROUND(bgcolour); |
1909 |
|
XSetFillStyle(g_display, g_gc, FillStippled); |
1910 |
|
|
1911 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
1912 |
for (i = 0; i < length;) |
for (i = 0; i < length;) |
1913 |
{ |
{ |
1958 |
break; |
break; |
1959 |
} |
} |
1960 |
} |
} |
1961 |
|
|
1962 |
|
XSetFillStyle(g_display, g_gc, FillSolid); |
1963 |
|
|
1964 |
if (g_ownbackstore) |
if (g_ownbackstore) |
1965 |
{ |
{ |
1966 |
if (boxcx > 1) |
if (boxcx > 1) |