21 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
22 |
#include <X11/Xutil.h> |
#include <X11/Xutil.h> |
23 |
#include <unistd.h> |
#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 |
|
|
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 |
|
extern uint32 g_embed_wnd; |
47 |
BOOL g_enable_compose = False; |
BOOL g_enable_compose = False; |
48 |
|
BOOL g_Unobscured; /* used for screenblt */ |
49 |
static GC g_gc = NULL; |
static GC g_gc = NULL; |
50 |
static Visual *g_visual; |
static Visual *g_visual; |
51 |
static int g_depth; |
static int g_depth; |
58 |
static Atom g_protocol_atom, g_kill_atom; |
static Atom g_protocol_atom, g_kill_atom; |
59 |
static BOOL g_focused; |
static BOOL g_focused; |
60 |
static BOOL g_mouse_in_wnd; |
static BOOL g_mouse_in_wnd; |
61 |
|
static BOOL g_arch_match = False; /* set to True if RGB XServer and little endian */ |
62 |
|
|
63 |
/* endianness */ |
/* endianness */ |
64 |
static BOOL g_host_be; |
static BOOL g_host_be; |
67 |
static int g_red_shift_l, g_blue_shift_l, g_green_shift_l; |
static int g_red_shift_l, g_blue_shift_l, g_green_shift_l; |
68 |
|
|
69 |
/* software backing store */ |
/* software backing store */ |
70 |
static BOOL g_ownbackstore; |
extern BOOL g_ownbackstore; |
71 |
static Pixmap g_backstore = NULL; |
static Pixmap g_backstore = 0; |
72 |
|
|
73 |
/* Moving in single app mode */ |
/* Moving in single app mode */ |
74 |
static BOOL g_moving_wnd; |
static BOOL g_moving_wnd; |
116 |
} |
} |
117 |
|
|
118 |
/* colour maps */ |
/* colour maps */ |
119 |
BOOL g_owncolmap = False; |
extern BOOL g_owncolmap; |
120 |
static Colormap g_xcolmap; |
static Colormap g_xcolmap; |
121 |
static uint32 *g_colmap = NULL; |
static uint32 *g_colmap = NULL; |
122 |
|
|
172 |
split_colour15(uint32 colour) |
split_colour15(uint32 colour) |
173 |
{ |
{ |
174 |
PixelColour rv; |
PixelColour rv; |
175 |
rv.red = (colour & 0x7c00) >> 10; |
rv.red = (colour & 0x7c00) >> 7; |
176 |
rv.red = (rv.red * 0xff) / 0x1f; |
rv.green = (colour & 0x03e0) >> 2; |
177 |
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; |
|
178 |
return rv; |
return rv; |
179 |
} |
} |
180 |
|
|
182 |
split_colour16(uint32 colour) |
split_colour16(uint32 colour) |
183 |
{ |
{ |
184 |
PixelColour rv; |
PixelColour rv; |
185 |
rv.red = (colour & 0xf800) >> 11; |
rv.red = (colour & 0xf800) >> 8; |
186 |
rv.red = (rv.red * 0xff) / 0x1f; |
rv.green = (colour & 0x07e0) >> 3; |
187 |
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; |
|
188 |
return rv; |
return rv; |
189 |
} |
} |
190 |
|
|
193 |
{ |
{ |
194 |
PixelColour rv; |
PixelColour rv; |
195 |
rv.blue = (colour & 0xff0000) >> 16; |
rv.blue = (colour & 0xff0000) >> 16; |
196 |
rv.green = (colour & 0xff00) >> 8; |
rv.green = (colour & 0x00ff00) >> 8; |
197 |
rv.red = (colour & 0xff); |
rv.red = (colour & 0x0000ff); |
198 |
return rv; |
return rv; |
199 |
} |
} |
200 |
|
|
230 |
return make_colour(pc); |
return make_colour(pc); |
231 |
} |
} |
232 |
|
|
233 |
|
#define UNROLL8(stm) { stm stm stm stm stm stm stm stm } |
234 |
|
#define REPEAT(stm) \ |
235 |
|
{ \ |
236 |
|
while (out <= end - 8 * 4) \ |
237 |
|
UNROLL8(stm) \ |
238 |
|
while (out < end) \ |
239 |
|
{ stm } \ |
240 |
|
} |
241 |
|
|
242 |
static void |
static void |
243 |
translate8to8(uint8 * data, uint8 * out, uint8 * end) |
translate8to8(uint8 * data, uint8 * out, uint8 * end) |
244 |
{ |
{ |
251 |
{ |
{ |
252 |
uint16 value; |
uint16 value; |
253 |
|
|
254 |
while (out < end) |
if (g_arch_match) |
255 |
|
REPEAT(*(((uint16 *) out)++) = g_colmap[*(data++)]; |
256 |
|
) |
257 |
|
else if (g_xserver_be) |
258 |
{ |
{ |
259 |
value = (uint16) g_colmap[*(data++)]; |
while (out < end) |
|
|
|
|
if (g_xserver_be) |
|
260 |
{ |
{ |
261 |
|
value = (uint16) g_colmap[*(data++)]; |
262 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
263 |
*(out++) = value; |
*(out++) = value; |
264 |
} |
} |
265 |
else |
} |
266 |
|
else |
267 |
|
{ |
268 |
|
while (out < end) |
269 |
{ |
{ |
270 |
|
value = (uint16) g_colmap[*(data++)]; |
271 |
*(out++) = value; |
*(out++) = value; |
272 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
273 |
} |
} |
280 |
{ |
{ |
281 |
uint32 value; |
uint32 value; |
282 |
|
|
283 |
while (out < end) |
if (g_xserver_be) |
284 |
{ |
{ |
285 |
value = g_colmap[*(data++)]; |
while (out < end) |
|
|
|
|
if (g_xserver_be) |
|
286 |
{ |
{ |
287 |
|
value = g_colmap[*(data++)]; |
288 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
289 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
290 |
*(out++) = value; |
*(out++) = value; |
291 |
} |
} |
292 |
else |
} |
293 |
|
else |
294 |
|
{ |
295 |
|
while (out < end) |
296 |
{ |
{ |
297 |
|
value = g_colmap[*(data++)]; |
298 |
*(out++) = value; |
*(out++) = value; |
299 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
300 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
307 |
{ |
{ |
308 |
uint32 value; |
uint32 value; |
309 |
|
|
310 |
while (out < end) |
if (g_arch_match) |
311 |
|
REPEAT(*(((uint32 *) out)++) = g_colmap[*(data++)]; |
312 |
|
) |
313 |
|
else if (g_xserver_be) |
314 |
{ |
{ |
315 |
value = g_colmap[*(data++)]; |
while (out < end) |
|
|
|
|
if (g_xserver_be) |
|
316 |
{ |
{ |
317 |
|
value = g_colmap[*(data++)]; |
318 |
*(out++) = value >> 24; |
*(out++) = value >> 24; |
319 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
320 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
321 |
*(out++) = value; |
*(out++) = value; |
322 |
} |
} |
323 |
else |
} |
324 |
|
else |
325 |
|
{ |
326 |
|
while (out < end) |
327 |
{ |
{ |
328 |
|
value = g_colmap[*(data++)]; |
329 |
*(out++) = value; |
*(out++) = value; |
330 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
331 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
614 |
static uint8 * |
static uint8 * |
615 |
translate_image(int width, int height, uint8 * data) |
translate_image(int width, int height, uint8 * data) |
616 |
{ |
{ |
617 |
int size = width * height * g_bpp / 8; |
int size; |
618 |
uint8 *out = (uint8 *) xmalloc(size); |
uint8 *out; |
619 |
uint8 *end = out + size; |
uint8 *end; |
620 |
|
|
621 |
|
/* if server and xserver bpp match, */ |
622 |
|
/* and arch(endian) matches, no need to translate */ |
623 |
|
/* just return data */ |
624 |
|
if (g_arch_match) |
625 |
|
{ |
626 |
|
if (g_depth == 15 && g_server_bpp == 15) |
627 |
|
return data; |
628 |
|
if (g_depth == 16 && g_server_bpp == 16) |
629 |
|
return data; |
630 |
|
} |
631 |
|
|
632 |
|
size = width * height * (g_bpp / 8); |
633 |
|
out = (uint8 *) xmalloc(size); |
634 |
|
end = out + size; |
635 |
|
|
636 |
switch (g_server_bpp) |
switch (g_server_bpp) |
637 |
{ |
{ |
769 |
TrueColorVisual = True; |
TrueColorVisual = True; |
770 |
} |
} |
771 |
|
|
772 |
|
test = 1; |
773 |
|
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
774 |
|
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
775 |
|
|
776 |
if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8))) |
if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8))) |
777 |
{ |
{ |
778 |
/* we use a colourmap, so the default visual should do */ |
/* we use a colourmap, so the default visual should do */ |
799 |
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); |
800 |
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); |
801 |
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); |
802 |
|
|
803 |
|
/* if RGB video and averything is little endian */ |
804 |
|
if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) |
805 |
|
if (!g_xserver_be && !g_host_be) |
806 |
|
g_arch_match = True; |
807 |
} |
} |
808 |
|
|
809 |
pfm = XListPixmapFormats(g_display, &i); |
pfm = XListPixmapFormats(g_display, &i); |
837 |
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"); |
838 |
} |
} |
839 |
|
|
840 |
if (DoesBackingStore(g_screen) != Always) |
if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) |
841 |
|
{ |
842 |
|
warning("External BackingStore not available, using internal\n"); |
843 |
g_ownbackstore = True; |
g_ownbackstore = True; |
844 |
|
} |
|
test = 1; |
|
|
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
|
|
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
|
845 |
|
|
846 |
/* |
/* |
847 |
* Determine desktop size |
* Determine desktop size |
940 |
if (g_gc == NULL) |
if (g_gc == NULL) |
941 |
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
942 |
|
|
943 |
if ((g_ownbackstore) && (g_backstore == NULL)) |
if ((g_ownbackstore) && (g_backstore == 0)) |
944 |
{ |
{ |
945 |
g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth); |
g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth); |
946 |
|
|
972 |
XFree(sizehints); |
XFree(sizehints); |
973 |
} |
} |
974 |
|
|
975 |
|
if (g_embed_wnd) |
976 |
|
{ |
977 |
|
XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0); |
978 |
|
} |
979 |
|
|
980 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
981 |
VisibilityChangeMask | FocusChangeMask; |
VisibilityChangeMask | FocusChangeMask; |
982 |
|
|
1008 |
XMaskEvent(g_display, VisibilityChangeMask, &xevent); |
XMaskEvent(g_display, VisibilityChangeMask, &xevent); |
1009 |
} |
} |
1010 |
while (xevent.type != VisibilityNotify); |
while (xevent.type != VisibilityNotify); |
1011 |
|
g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured; |
1012 |
|
|
1013 |
g_focused = False; |
g_focused = False; |
1014 |
g_mouse_in_wnd = False; |
g_mouse_in_wnd = False; |
1026 |
} |
} |
1027 |
|
|
1028 |
void |
void |
1029 |
|
ui_resize_window() |
1030 |
|
{ |
1031 |
|
XSizeHints *sizehints; |
1032 |
|
|
1033 |
|
sizehints = XAllocSizeHints(); |
1034 |
|
if (sizehints) |
1035 |
|
{ |
1036 |
|
sizehints->flags = PMinSize | PMaxSize; |
1037 |
|
sizehints->min_width = sizehints->max_width = g_width; |
1038 |
|
sizehints->min_height = sizehints->max_height = g_height; |
1039 |
|
XSetWMNormalHints(g_display, g_wnd, sizehints); |
1040 |
|
XFree(sizehints); |
1041 |
|
} |
1042 |
|
|
1043 |
|
if (!(g_fullscreen || g_embed_wnd)) |
1044 |
|
{ |
1045 |
|
XResizeWindow(g_display, g_wnd, g_width, g_height); |
1046 |
|
} |
1047 |
|
} |
1048 |
|
|
1049 |
|
void |
1050 |
ui_destroy_window(void) |
ui_destroy_window(void) |
1051 |
{ |
{ |
1052 |
if (g_IC != NULL) |
if (g_IC != NULL) |
1107 |
|
|
1108 |
switch (xevent.type) |
switch (xevent.type) |
1109 |
{ |
{ |
1110 |
|
case VisibilityNotify: |
1111 |
|
g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured; |
1112 |
|
break; |
1113 |
case ClientMessage: |
case ClientMessage: |
1114 |
/* the window manager told us to quit */ |
/* the window manager told us to quit */ |
1115 |
if ((xevent.xclient.message_type == g_protocol_atom) |
if ((xevent.xclient.message_type == g_protocol_atom) |
1347 |
int |
int |
1348 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
1349 |
{ |
{ |
1350 |
int n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket; |
int n; |
1351 |
fd_set rfds, wfds; |
fd_set rfds, wfds; |
1352 |
struct timeval tv; |
struct timeval tv; |
1353 |
BOOL s_timeout = False; |
BOOL s_timeout = False; |
1354 |
|
|
1355 |
while (True) |
while (True) |
1356 |
{ |
{ |
1357 |
|
n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket; |
1358 |
/* Process any events already waiting */ |
/* Process any events already waiting */ |
1359 |
if (!xwin_process_events()) |
if (!xwin_process_events()) |
1360 |
/* User quit */ |
/* User quit */ |
1443 |
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); |
1444 |
|
|
1445 |
XFree(image); |
XFree(image); |
1446 |
if (!g_owncolmap) |
if (tdata != data) |
1447 |
xfree(tdata); |
xfree(tdata); |
1448 |
return (HBITMAP) bitmap; |
return (HBITMAP) bitmap; |
1449 |
} |
} |
1482 |
} |
} |
1483 |
|
|
1484 |
XFree(image); |
XFree(image); |
1485 |
if (!g_owncolmap) |
if (tdata != data) |
1486 |
xfree(tdata); |
xfree(tdata); |
1487 |
} |
} |
1488 |
|
|
1806 |
{ |
{ |
1807 |
case 0: /* Solid */ |
case 0: /* Solid */ |
1808 |
SET_FOREGROUND(fgcolour); |
SET_FOREGROUND(fgcolour); |
1809 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
1810 |
break; |
break; |
1811 |
|
|
1812 |
case 2: /* Hatch */ |
case 2: /* Hatch */ |
1817 |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
1818 |
XSetStipple(g_display, g_gc, fill); |
XSetStipple(g_display, g_gc, fill); |
1819 |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |
1820 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
1821 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
1822 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
1823 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((HGLYPH) fill); |
1827 |
for (i = 0; i != 8; i++) |
for (i = 0; i != 8; i++) |
1828 |
ipattern[7 - i] = brush->pattern[i]; |
ipattern[7 - i] = brush->pattern[i]; |
1829 |
fill = (Pixmap) ui_create_glyph(8, 8, ipattern); |
fill = (Pixmap) ui_create_glyph(8, 8, ipattern); |
|
|
|
1830 |
SET_FOREGROUND(bgcolour); |
SET_FOREGROUND(bgcolour); |
1831 |
SET_BACKGROUND(fgcolour); |
SET_BACKGROUND(fgcolour); |
1832 |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
1833 |
XSetStipple(g_display, g_gc, fill); |
XSetStipple(g_display, g_gc, fill); |
1834 |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |
1835 |
|
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
|
FILL_RECTANGLE(x, y, cx, cy); |
|
|
|
|
1836 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
1837 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
1838 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((HGLYPH) fill); |
1843 |
} |
} |
1844 |
|
|
1845 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
1846 |
|
|
1847 |
|
if (g_ownbackstore) |
1848 |
|
XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); |
1849 |
} |
} |
1850 |
|
|
1851 |
void |
void |
1854 |
/* src */ int srcx, int srcy) |
/* src */ int srcx, int srcy) |
1855 |
{ |
{ |
1856 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
|
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
|
1857 |
if (g_ownbackstore) |
if (g_ownbackstore) |
1858 |
XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y); |
{ |
1859 |
|
if (g_Unobscured) |
1860 |
|
{ |
1861 |
|
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
1862 |
|
XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, |
1863 |
|
y); |
1864 |
|
} |
1865 |
|
else |
1866 |
|
{ |
1867 |
|
XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
1868 |
|
XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, |
1869 |
|
y); |
1870 |
|
} |
1871 |
|
} |
1872 |
|
else |
1873 |
|
{ |
1874 |
|
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
1875 |
|
} |
1876 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
1877 |
} |
} |
1878 |
|
|
2009 |
|
|
2010 |
SET_FOREGROUND(bgcolour); |
SET_FOREGROUND(bgcolour); |
2011 |
|
|
2012 |
|
/* Sometimes, the boxcx value is something really large, like |
2013 |
|
32691. This makes XCopyArea fail with Xvnc. The code below |
2014 |
|
is a quick fix. */ |
2015 |
|
if (boxx + boxcx > g_width) |
2016 |
|
boxcx = g_width - boxx; |
2017 |
|
|
2018 |
if (boxcx > 1) |
if (boxcx > 1) |
2019 |
{ |
{ |
2020 |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |