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 |
|
uint32 g_embed_wnd; |
47 |
BOOL g_enable_compose = False; |
BOOL g_enable_compose = False; |
48 |
static GC g_gc = NULL; |
static GC g_gc = NULL; |
49 |
static Visual *g_visual; |
static Visual *g_visual; |
65 |
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; |
66 |
|
|
67 |
/* software backing store */ |
/* software backing store */ |
68 |
static BOOL g_ownbackstore; |
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
69 |
static Pixmap g_backstore = NULL; |
static Pixmap g_backstore = 0; |
70 |
|
|
71 |
/* Moving in single app mode */ |
/* Moving in single app mode */ |
72 |
static BOOL g_moving_wnd; |
static BOOL g_moving_wnd; |
170 |
split_colour15(uint32 colour) |
split_colour15(uint32 colour) |
171 |
{ |
{ |
172 |
PixelColour rv; |
PixelColour rv; |
173 |
rv.red = (colour & 0x7c00) >> 10; |
rv.red = (colour & 0x7c00) >> 7; |
174 |
rv.red = (rv.red * 0xff) / 0x1f; |
rv.green = (colour & 0x03e0) >> 2; |
175 |
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; |
|
176 |
return rv; |
return rv; |
177 |
} |
} |
178 |
|
|
180 |
split_colour16(uint32 colour) |
split_colour16(uint32 colour) |
181 |
{ |
{ |
182 |
PixelColour rv; |
PixelColour rv; |
183 |
rv.red = (colour & 0xf800) >> 11; |
rv.red = (colour & 0xf800) >> 8; |
184 |
rv.red = (rv.red * 0xff) / 0x1f; |
rv.green = (colour & 0x07e0) >> 3; |
185 |
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; |
|
186 |
return rv; |
return rv; |
187 |
} |
} |
188 |
|
|
191 |
{ |
{ |
192 |
PixelColour rv; |
PixelColour rv; |
193 |
rv.blue = (colour & 0xff0000) >> 16; |
rv.blue = (colour & 0xff0000) >> 16; |
194 |
rv.green = (colour & 0xff00) >> 8; |
rv.green = (colour & 0x00ff00) >> 8; |
195 |
rv.red = (colour & 0xff); |
rv.red = (colour & 0x0000ff); |
196 |
return rv; |
return rv; |
197 |
} |
} |
198 |
|
|
240 |
{ |
{ |
241 |
uint16 value; |
uint16 value; |
242 |
|
|
243 |
while (out < end) |
if (g_xserver_be) |
244 |
{ |
{ |
245 |
value = (uint16) g_colmap[*(data++)]; |
while (out < end) |
|
|
|
|
if (g_xserver_be) |
|
246 |
{ |
{ |
247 |
|
value = (uint16) g_colmap[*(data++)]; |
248 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
249 |
*(out++) = value; |
*(out++) = value; |
250 |
} |
} |
251 |
else |
} |
252 |
|
else |
253 |
|
{ |
254 |
|
while (out < end) |
255 |
{ |
{ |
256 |
|
value = (uint16) g_colmap[*(data++)]; |
257 |
*(out++) = value; |
*(out++) = value; |
258 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
259 |
} |
} |
266 |
{ |
{ |
267 |
uint32 value; |
uint32 value; |
268 |
|
|
269 |
while (out < end) |
if (g_xserver_be) |
270 |
{ |
{ |
271 |
value = g_colmap[*(data++)]; |
while (out < end) |
|
|
|
|
if (g_xserver_be) |
|
272 |
{ |
{ |
273 |
|
value = g_colmap[*(data++)]; |
274 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
275 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
276 |
*(out++) = value; |
*(out++) = value; |
277 |
} |
} |
278 |
else |
} |
279 |
|
else |
280 |
|
{ |
281 |
|
while (out < end) |
282 |
{ |
{ |
283 |
|
value = g_colmap[*(data++)]; |
284 |
*(out++) = value; |
*(out++) = value; |
285 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
286 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
293 |
{ |
{ |
294 |
uint32 value; |
uint32 value; |
295 |
|
|
296 |
while (out < end) |
if (g_xserver_be) |
297 |
{ |
{ |
298 |
value = g_colmap[*(data++)]; |
while (out < end) |
|
|
|
|
if (g_xserver_be) |
|
299 |
{ |
{ |
300 |
|
value = g_colmap[*(data++)]; |
301 |
*(out++) = value >> 24; |
*(out++) = value >> 24; |
302 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
303 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
304 |
*(out++) = value; |
*(out++) = value; |
305 |
} |
} |
306 |
else |
} |
307 |
|
else |
308 |
|
{ |
309 |
|
while (out < end) |
310 |
{ |
{ |
311 |
|
value = g_colmap[*(data++)]; |
312 |
*(out++) = value; |
*(out++) = value; |
313 |
*(out++) = value >> 8; |
*(out++) = value >> 8; |
314 |
*(out++) = value >> 16; |
*(out++) = value >> 16; |
796 |
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"); |
797 |
} |
} |
798 |
|
|
799 |
if (DoesBackingStore(g_screen) != Always) |
if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) |
800 |
|
{ |
801 |
|
warning("External BackingStore not available, using internal\n"); |
802 |
g_ownbackstore = True; |
g_ownbackstore = True; |
803 |
|
} |
804 |
|
|
805 |
test = 1; |
test = 1; |
806 |
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
903 |
if (g_gc == NULL) |
if (g_gc == NULL) |
904 |
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
905 |
|
|
906 |
if ((g_ownbackstore) && (g_backstore == NULL)) |
if ((g_ownbackstore) && (g_backstore == 0)) |
907 |
{ |
{ |
908 |
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); |
909 |
|
|
935 |
XFree(sizehints); |
XFree(sizehints); |
936 |
} |
} |
937 |
|
|
938 |
|
if ( g_embed_wnd ) |
939 |
|
{ |
940 |
|
XReparentWindow(g_display, g_wnd, (Window)g_embed_wnd, 0, 0); |
941 |
|
} |
942 |
|
|
943 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
944 |
VisibilityChangeMask | FocusChangeMask; |
VisibilityChangeMask | FocusChangeMask; |
945 |
|
|
1285 |
int |
int |
1286 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
1287 |
{ |
{ |
1288 |
int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1; |
int n; |
1289 |
fd_set rfds, wfds; |
fd_set rfds, wfds; |
1290 |
|
struct timeval tv; |
1291 |
|
BOOL s_timeout = False; |
1292 |
|
|
1293 |
while (True) |
while (True) |
1294 |
{ |
{ |
1295 |
|
n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket; |
1296 |
/* Process any events already waiting */ |
/* Process any events already waiting */ |
1297 |
if (!xwin_process_events()) |
if (!xwin_process_events()) |
1298 |
/* User quit */ |
/* User quit */ |
1308 |
if (g_dsp_busy) |
if (g_dsp_busy) |
1309 |
{ |
{ |
1310 |
FD_SET(g_dsp_fd, &wfds); |
FD_SET(g_dsp_fd, &wfds); |
1311 |
n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; |
n = (g_dsp_fd > n) ? g_dsp_fd : n; |
1312 |
} |
} |
1313 |
#endif |
#endif |
1314 |
|
/* default timeout */ |
1315 |
|
tv.tv_sec = 60; |
1316 |
|
tv.tv_usec = 0; |
1317 |
|
|
1318 |
|
/* add redirection handles */ |
1319 |
|
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
1320 |
|
|
1321 |
switch (select(n, &rfds, &wfds, NULL, NULL)) |
n++; |
1322 |
|
|
1323 |
|
switch (select(n, &rfds, &wfds, NULL, &tv)) |
1324 |
{ |
{ |
1325 |
case -1: |
case -1: |
1326 |
error("select: %s\n", strerror(errno)); |
error("select: %s\n", strerror(errno)); |
1327 |
|
|
1328 |
case 0: |
case 0: |
1329 |
|
/* TODO: if tv.tv_sec just times out |
1330 |
|
* we will segfault. |
1331 |
|
* FIXME: |
1332 |
|
*/ |
1333 |
|
//s_timeout = True; |
1334 |
|
//rdpdr_check_fds(&rfds, &wfds, (BOOL) True); |
1335 |
continue; |
continue; |
1336 |
} |
} |
1337 |
|
|
1338 |
|
rdpdr_check_fds(&rfds, &wfds, (BOOL) False); |
1339 |
|
|
1340 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
1341 |
return 1; |
return 1; |
1342 |
|
|
1792 |
/* src */ int srcx, int srcy) |
/* src */ int srcx, int srcy) |
1793 |
{ |
{ |
1794 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
|
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
|
1795 |
if (g_ownbackstore) |
if (g_ownbackstore) |
1796 |
|
{ |
1797 |
|
XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
1798 |
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); |
1799 |
|
} |
1800 |
|
else |
1801 |
|
{ |
1802 |
|
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
1803 |
|
} |
1804 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
1805 |
} |
} |
1806 |
|
|
1937 |
|
|
1938 |
SET_FOREGROUND(bgcolour); |
SET_FOREGROUND(bgcolour); |
1939 |
|
|
1940 |
|
/* Sometimes, the boxcx value is something really large, like |
1941 |
|
32691. This makes XCopyArea fail with Xvnc. The code below |
1942 |
|
is a quick fix. */ |
1943 |
|
if (boxx + boxcx > g_width) |
1944 |
|
boxcx = g_width - boxx; |
1945 |
|
|
1946 |
if (boxcx > 1) |
if (boxcx > 1) |
1947 |
{ |
{ |
1948 |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |