1 |
/* -*- c-basic-offset: 8 -*- |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
User interface services - X Window System |
User interface services - X Window System |
4 |
Copyright (C) Matthew Chapman 1999-2005 |
Copyright (C) Matthew Chapman 1999-2007 |
5 |
|
Copyright 2007 Pierre Ossman <ossman@cendio.se> for Cendio AB |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
8 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
21 |
|
|
22 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
23 |
#include <X11/Xutil.h> |
#include <X11/Xutil.h> |
24 |
|
#include <X11/Xproto.h> |
25 |
#include <unistd.h> |
#include <unistd.h> |
26 |
#include <sys/time.h> |
#include <sys/time.h> |
27 |
#include <time.h> |
#include <time.h> |
30 |
#include "rdesktop.h" |
#include "rdesktop.h" |
31 |
#include "xproto.h" |
#include "xproto.h" |
32 |
|
|
|
/* We can't include Xproto.h because of conflicting defines for BOOL */ |
|
|
#define X_ConfigureWindow 12 |
|
|
|
|
33 |
extern int g_width; |
extern int g_width; |
34 |
extern int g_height; |
extern int g_height; |
35 |
extern int g_xpos; |
extern int g_xpos; |
36 |
extern int g_ypos; |
extern int g_ypos; |
37 |
extern int g_pos; |
extern int g_pos; |
38 |
extern BOOL g_sendmotion; |
extern RD_BOOL g_sendmotion; |
39 |
extern BOOL g_fullscreen; |
extern RD_BOOL g_fullscreen; |
40 |
extern BOOL g_grab_keyboard; |
extern RD_BOOL g_grab_keyboard; |
41 |
extern BOOL g_hide_decorations; |
extern RD_BOOL g_hide_decorations; |
42 |
extern char g_title[]; |
extern char g_title[]; |
43 |
/* Color depth of the RDP session. |
/* Color depth of the RDP session. |
44 |
As of RDP 5.1, it may be 8, 15, 16 or 24. */ |
As of RDP 5.1, it may be 8, 15, 16 or 24. */ |
70 |
unsigned int desktop; |
unsigned int desktop; |
71 |
struct timeval *position_timer; |
struct timeval *position_timer; |
72 |
|
|
73 |
BOOL outstanding_position; |
RD_BOOL outstanding_position; |
74 |
unsigned int outpos_serial; |
unsigned int outpos_serial; |
75 |
int outpos_xoffset, outpos_yoffset; |
int outpos_xoffset, outpos_yoffset; |
76 |
int outpos_width, outpos_height; |
int outpos_width, outpos_height; |
77 |
|
|
78 |
|
unsigned int icon_size; |
79 |
|
unsigned int icon_offset; |
80 |
|
char icon_buffer[32 * 32 * 4]; |
81 |
|
|
82 |
struct _seamless_window *next; |
struct _seamless_window *next; |
83 |
} seamless_window; |
} seamless_window; |
84 |
static seamless_window *g_seamless_windows = NULL; |
static seamless_window *g_seamless_windows = NULL; |
85 |
static unsigned long g_seamless_focused = 0; |
static unsigned long g_seamless_focused = 0; |
86 |
static BOOL g_seamless_started = False; /* Server end is up and running */ |
static RD_BOOL g_seamless_started = False; /* Server end is up and running */ |
87 |
static BOOL g_seamless_active = False; /* We are currently in seamless mode */ |
static RD_BOOL g_seamless_active = False; /* We are currently in seamless mode */ |
88 |
static BOOL g_seamless_hidden = False; /* Desktop is hidden on server */ |
static RD_BOOL g_seamless_hidden = False; /* Desktop is hidden on server */ |
89 |
extern BOOL g_seamless_rdp; |
extern RD_BOOL g_seamless_rdp; |
90 |
|
|
91 |
extern uint32 g_embed_wnd; |
extern uint32 g_embed_wnd; |
92 |
BOOL g_enable_compose = False; |
RD_BOOL g_enable_compose = False; |
93 |
BOOL g_Unobscured; /* used for screenblt */ |
RD_BOOL g_Unobscured; /* used for screenblt */ |
94 |
static GC g_gc = NULL; |
static GC g_gc = NULL; |
95 |
static GC g_create_bitmap_gc = NULL; |
static GC g_create_bitmap_gc = NULL; |
96 |
static GC g_create_glyph_gc = NULL; |
static GC g_create_glyph_gc = NULL; |
107 |
static XIM g_IM; |
static XIM g_IM; |
108 |
static XIC g_IC; |
static XIC g_IC; |
109 |
static XModifierKeymap *g_mod_map; |
static XModifierKeymap *g_mod_map; |
110 |
|
/* Maps logical (xmodmap -pp) pointing device buttons (0-based) back |
111 |
|
to physical (1-based) indices. */ |
112 |
|
static unsigned char g_pointer_log_to_phys_map[16]; |
113 |
static Cursor g_current_cursor; |
static Cursor g_current_cursor; |
114 |
static HCURSOR g_null_cursor = NULL; |
static RD_HCURSOR g_null_cursor = NULL; |
115 |
static Atom g_protocol_atom, g_kill_atom; |
static Atom g_protocol_atom, g_kill_atom; |
116 |
extern Atom g_net_wm_state_atom; |
extern Atom g_net_wm_state_atom; |
117 |
extern Atom g_net_wm_desktop_atom; |
extern Atom g_net_wm_desktop_atom; |
118 |
static BOOL g_focused; |
static RD_BOOL g_focused; |
119 |
static BOOL g_mouse_in_wnd; |
static RD_BOOL g_mouse_in_wnd; |
120 |
/* Indicates that: |
/* Indicates that: |
121 |
1) visual has 15, 16 or 24 depth and the same color channel masks |
1) visual has 15, 16 or 24 depth and the same color channel masks |
122 |
as its RDP equivalent (implies X server is LE), |
as its RDP equivalent (implies X server is LE), |
123 |
2) host is LE |
2) host is LE |
124 |
This will trigger an optimization whose real value is questionable. |
This will trigger an optimization whose real value is questionable. |
125 |
*/ |
*/ |
126 |
static BOOL g_compatible_arch; |
static RD_BOOL g_compatible_arch; |
127 |
/* Indicates whether RDP's bitmaps and our XImages have the same |
/* Indicates whether RDP's bitmaps and our XImages have the same |
128 |
binary format. If so, we can avoid an expensive translation. |
binary format. If so, we can avoid an expensive translation. |
129 |
Note that this can be true when g_compatible_arch is false, |
Note that this can be true when g_compatible_arch is false, |
134 |
('host' is the machine running rdesktop; the host simply memcpy's |
('host' is the machine running rdesktop; the host simply memcpy's |
135 |
so its endianess doesn't matter) |
so its endianess doesn't matter) |
136 |
*/ |
*/ |
137 |
static BOOL g_no_translate_image = False; |
static RD_BOOL g_no_translate_image = False; |
138 |
|
|
139 |
/* endianness */ |
/* endianness */ |
140 |
static BOOL g_host_be; |
static RD_BOOL g_host_be; |
141 |
static BOOL g_xserver_be; |
static RD_BOOL g_xserver_be; |
142 |
static int g_red_shift_r, g_blue_shift_r, g_green_shift_r; |
static int g_red_shift_r, g_blue_shift_r, g_green_shift_r; |
143 |
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; |
144 |
|
|
145 |
/* software backing store */ |
/* software backing store */ |
146 |
extern BOOL g_ownbackstore; |
extern RD_BOOL g_ownbackstore; |
147 |
static Pixmap g_backstore = 0; |
static Pixmap g_backstore = 0; |
148 |
|
|
149 |
/* Moving in single app mode */ |
/* Moving in single app mode */ |
150 |
static BOOL g_moving_wnd; |
static RD_BOOL g_moving_wnd; |
151 |
static int g_move_x_offset = 0; |
static int g_move_x_offset = 0; |
152 |
static int g_move_y_offset = 0; |
static int g_move_y_offset = 0; |
153 |
static BOOL g_using_full_workarea = False; |
static RD_BOOL g_using_full_workarea = False; |
154 |
|
|
155 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
156 |
extern int g_dsp_fd; |
extern RD_BOOL g_rdpsnd; |
|
extern BOOL g_dsp_busy; |
|
|
extern BOOL g_rdpsnd; |
|
157 |
#endif |
#endif |
158 |
|
|
159 |
/* MWM decorations */ |
/* MWM decorations */ |
246 |
break; \ |
break; \ |
247 |
case 1: /* Filled */ \ |
case 1: /* Filled */ \ |
248 |
XFillArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \ |
XFillArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \ |
249 |
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, (g_display, g_ownbackstore ? g_backstore : g_wnd, sw->wnd, g_gc, \ |
ON_ALL_SEAMLESS_WINDOWS(XFillArc, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy, 0, 360*64)); \ |
|
x, y, cx, cy, x-sw->xoffset, y-sw->yoffset)); \ |
|
250 |
if (g_ownbackstore) \ |
if (g_ownbackstore) \ |
251 |
XFillArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \ |
XFillArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \ |
252 |
break; \ |
break; \ |
254 |
} |
} |
255 |
|
|
256 |
/* colour maps */ |
/* colour maps */ |
257 |
extern BOOL g_owncolmap; |
extern RD_BOOL g_owncolmap; |
258 |
static Colormap g_xcolmap; |
static Colormap g_xcolmap; |
259 |
static uint32 *g_colmap = NULL; |
static uint32 *g_colmap = NULL; |
260 |
|
|
478 |
|
|
479 |
|
|
480 |
static seamless_group * |
static seamless_group * |
481 |
sw_find_group(unsigned long id, BOOL dont_create) |
sw_find_group(unsigned long id, RD_BOOL dont_create) |
482 |
{ |
{ |
483 |
seamless_window *sw; |
seamless_window *sw; |
484 |
seamless_group *sg; |
seamless_group *sg; |
583 |
SPLITCOLOUR16(colour, pc); |
SPLITCOLOUR16(colour, pc); |
584 |
break; |
break; |
585 |
case 24: |
case 24: |
586 |
|
case 32: |
587 |
SPLITCOLOUR24(colour, pc); |
SPLITCOLOUR24(colour, pc); |
588 |
break; |
break; |
589 |
default: |
default: |
1192 |
is only set for compatible depths, but the RDP depth might've |
is only set for compatible depths, but the RDP depth might've |
1193 |
changed during connection negotiations. |
changed during connection negotiations. |
1194 |
*/ |
*/ |
1195 |
|
|
1196 |
|
/* todo */ |
1197 |
|
if (g_server_depth == 32 && g_depth == 24) |
1198 |
|
{ |
1199 |
|
return data; |
1200 |
|
} |
1201 |
|
|
1202 |
if (g_no_translate_image) |
if (g_no_translate_image) |
1203 |
{ |
{ |
1204 |
if ((g_depth == 15 && g_server_depth == 15) || |
if ((g_depth == 15 && g_server_depth == 15) || |
1276 |
return out; |
return out; |
1277 |
} |
} |
1278 |
|
|
1279 |
BOOL |
static void |
1280 |
|
xwin_refresh_pointer_map(void) |
1281 |
|
{ |
1282 |
|
unsigned char phys_to_log_map[sizeof(g_pointer_log_to_phys_map)]; |
1283 |
|
int i, pointer_buttons; |
1284 |
|
|
1285 |
|
pointer_buttons = XGetPointerMapping(g_display, phys_to_log_map, sizeof(phys_to_log_map)); |
1286 |
|
for (i = 0; i < pointer_buttons; ++i) |
1287 |
|
{ |
1288 |
|
/* This might produce multiple logical buttons mapping |
1289 |
|
to a single physical one, but hey, that's |
1290 |
|
life... */ |
1291 |
|
g_pointer_log_to_phys_map[phys_to_log_map[i] - 1] = i + 1; |
1292 |
|
} |
1293 |
|
} |
1294 |
|
|
1295 |
|
RD_BOOL |
1296 |
get_key_state(unsigned int state, uint32 keysym) |
get_key_state(unsigned int state, uint32 keysym) |
1297 |
{ |
{ |
1298 |
int modifierpos, key, keysymMask = 0; |
int modifierpos, key, keysymMask = 0; |
1340 |
return weight; |
return weight; |
1341 |
} |
} |
1342 |
|
|
1343 |
static BOOL |
static RD_BOOL |
1344 |
select_visual() |
select_visual(int screen_num) |
1345 |
{ |
{ |
1346 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
1347 |
int pixmap_formats_count, visuals_count; |
int pixmap_formats_count, visuals_count; |
1367 |
|
|
1368 |
/* Search for best TrueColor visual */ |
/* Search for best TrueColor visual */ |
1369 |
template.class = TrueColor; |
template.class = TrueColor; |
1370 |
vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &visuals_count); |
template.screen = screen_num; |
1371 |
|
vmatches = |
1372 |
|
XGetVisualInfo(g_display, VisualClassMask | VisualScreenMask, &template, |
1373 |
|
&visuals_count); |
1374 |
g_visual = NULL; |
g_visual = NULL; |
1375 |
g_no_translate_image = False; |
g_no_translate_image = False; |
1376 |
g_compatible_arch = False; |
g_compatible_arch = False; |
1379 |
for (i = 0; i < visuals_count; ++i) |
for (i = 0; i < visuals_count; ++i) |
1380 |
{ |
{ |
1381 |
XVisualInfo *visual_info = &vmatches[i]; |
XVisualInfo *visual_info = &vmatches[i]; |
1382 |
BOOL can_translate_to_bpp = False; |
RD_BOOL can_translate_to_bpp = False; |
1383 |
int j; |
int j; |
1384 |
|
|
1385 |
/* Try to find a no-translation visual that'll |
/* Try to find a no-translation visual that'll |
1551 |
return g_old_error_handler(dpy, eev); |
return g_old_error_handler(dpy, eev); |
1552 |
} |
} |
1553 |
|
|
1554 |
BOOL |
RD_BOOL |
1555 |
ui_init(void) |
ui_init(void) |
1556 |
{ |
{ |
1557 |
int screen_num; |
int screen_num; |
1565 |
|
|
1566 |
{ |
{ |
1567 |
uint16 endianess_test = 1; |
uint16 endianess_test = 1; |
1568 |
g_host_be = !(BOOL) (*(uint8 *) (&endianess_test)); |
g_host_be = !(RD_BOOL) (*(uint8 *) (&endianess_test)); |
1569 |
} |
} |
1570 |
|
|
1571 |
g_old_error_handler = XSetErrorHandler(error_handler); |
g_old_error_handler = XSetErrorHandler(error_handler); |
1575 |
g_screen = ScreenOfDisplay(g_display, screen_num); |
g_screen = ScreenOfDisplay(g_display, screen_num); |
1576 |
g_depth = DefaultDepthOfScreen(g_screen); |
g_depth = DefaultDepthOfScreen(g_screen); |
1577 |
|
|
1578 |
if (!select_visual()) |
if (!select_visual(screen_num)) |
1579 |
return False; |
return False; |
1580 |
|
|
1581 |
if (g_no_translate_image) |
if (g_no_translate_image) |
1646 |
g_width = (g_width + 3) & ~3; |
g_width = (g_width + 3) & ~3; |
1647 |
|
|
1648 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
1649 |
|
xwin_refresh_pointer_map(); |
1650 |
|
|
1651 |
xkeymap_init(); |
xkeymap_init(); |
1652 |
|
|
1718 |
*input_mask |= LeaveWindowMask; |
*input_mask |= LeaveWindowMask; |
1719 |
} |
} |
1720 |
|
|
1721 |
BOOL |
RD_BOOL |
1722 |
ui_create_window(void) |
ui_create_window(void) |
1723 |
{ |
{ |
1724 |
uint8 null_pointer_mask[1] = { 0x80 }; |
uint8 null_pointer_mask[1] = { 0x80 }; |
1766 |
} |
} |
1767 |
|
|
1768 |
XStoreName(g_display, g_wnd, g_title); |
XStoreName(g_display, g_wnd, g_title); |
1769 |
|
ewmh_set_wm_name(g_wnd, g_title); |
1770 |
|
|
1771 |
if (g_hide_decorations) |
if (g_hide_decorations) |
1772 |
mwm_hide_decorations(g_wnd); |
mwm_hide_decorations(g_wnd); |
1906 |
} |
} |
1907 |
|
|
1908 |
static void |
static void |
1909 |
handle_button_event(XEvent xevent, BOOL down) |
handle_button_event(XEvent xevent, RD_BOOL down) |
1910 |
{ |
{ |
1911 |
uint16 button, flags = 0; |
uint16 button, flags = 0; |
1912 |
g_last_gesturetime = xevent.xbutton.time; |
g_last_gesturetime = xevent.xbutton.time; |
1913 |
|
/* Reverse the pointer button mapping, e.g. in the case of |
1914 |
|
"left-handed mouse mode"; the RDP session expects to |
1915 |
|
receive physical buttons (true in mstsc as well) and |
1916 |
|
logical button behavior depends on the remote desktop's own |
1917 |
|
mouse settings */ |
1918 |
|
xevent.xbutton.button = g_pointer_log_to_phys_map[xevent.xbutton.button - 1]; |
1919 |
button = xkeymap_translate_button(xevent.xbutton.button); |
button = xkeymap_translate_button(xevent.xbutton.button); |
1920 |
if (button == 0) |
if (button == 0) |
1921 |
return; |
return; |
2203 |
XFreeModifiermap(g_mod_map); |
XFreeModifiermap(g_mod_map); |
2204 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
2205 |
} |
} |
2206 |
|
|
2207 |
|
if (xevent.xmapping.request == MappingPointer) |
2208 |
|
{ |
2209 |
|
xwin_refresh_pointer_map(); |
2210 |
|
} |
2211 |
|
|
2212 |
break; |
break; |
2213 |
|
|
2214 |
/* clipboard stuff */ |
/* clipboard stuff */ |
2292 |
int n; |
int n; |
2293 |
fd_set rfds, wfds; |
fd_set rfds, wfds; |
2294 |
struct timeval tv; |
struct timeval tv; |
2295 |
BOOL s_timeout = False; |
RD_BOOL s_timeout = False; |
2296 |
|
|
2297 |
while (True) |
while (True) |
2298 |
{ |
{ |
2310 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
2311 |
FD_SET(g_x_socket, &rfds); |
FD_SET(g_x_socket, &rfds); |
2312 |
|
|
|
#ifdef WITH_RDPSND |
|
|
/* FIXME: there should be an API for registering fds */ |
|
|
if (g_dsp_busy) |
|
|
{ |
|
|
FD_SET(g_dsp_fd, &wfds); |
|
|
n = (g_dsp_fd > n) ? g_dsp_fd : n; |
|
|
} |
|
|
#endif |
|
2313 |
/* default timeout */ |
/* default timeout */ |
2314 |
tv.tv_sec = 60; |
tv.tv_sec = 60; |
2315 |
tv.tv_usec = 0; |
tv.tv_usec = 0; |
2316 |
|
|
2317 |
|
#ifdef WITH_RDPSND |
2318 |
|
rdpsnd_add_fds(&n, &rfds, &wfds, &tv); |
2319 |
|
#endif |
2320 |
|
|
2321 |
/* add redirection handles */ |
/* add redirection handles */ |
2322 |
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
2323 |
seamless_select_timeout(&tv); |
seamless_select_timeout(&tv); |
2330 |
error("select: %s\n", strerror(errno)); |
error("select: %s\n", strerror(errno)); |
2331 |
|
|
2332 |
case 0: |
case 0: |
2333 |
|
#ifdef WITH_RDPSND |
2334 |
|
rdpsnd_check_fds(&rfds, &wfds); |
2335 |
|
#endif |
2336 |
|
|
2337 |
/* Abort serial read calls */ |
/* Abort serial read calls */ |
2338 |
if (s_timeout) |
if (s_timeout) |
2339 |
rdpdr_check_fds(&rfds, &wfds, (BOOL) True); |
rdpdr_check_fds(&rfds, &wfds, (RD_BOOL) True); |
2340 |
continue; |
continue; |
2341 |
} |
} |
2342 |
|
|
2343 |
rdpdr_check_fds(&rfds, &wfds, (BOOL) False); |
#ifdef WITH_RDPSND |
2344 |
|
rdpsnd_check_fds(&rfds, &wfds); |
2345 |
|
#endif |
2346 |
|
|
2347 |
|
rdpdr_check_fds(&rfds, &wfds, (RD_BOOL) False); |
2348 |
|
|
2349 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
2350 |
return 1; |
return 1; |
2351 |
|
|
|
#ifdef WITH_RDPSND |
|
|
if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds)) |
|
|
wave_out_play(); |
|
|
#endif |
|
2352 |
} |
} |
2353 |
} |
} |
2354 |
|
|
2358 |
XWarpPointer(g_display, g_wnd, g_wnd, 0, 0, 0, 0, x, y); |
XWarpPointer(g_display, g_wnd, g_wnd, 0, 0, 0, 0, x, y); |
2359 |
} |
} |
2360 |
|
|
2361 |
HBITMAP |
RD_HBITMAP |
2362 |
ui_create_bitmap(int width, int height, uint8 * data) |
ui_create_bitmap(int width, int height, uint8 * data) |
2363 |
{ |
{ |
2364 |
XImage *image; |
XImage *image; |
2388 |
XFree(image); |
XFree(image); |
2389 |
if (tdata != data) |
if (tdata != data) |
2390 |
xfree(tdata); |
xfree(tdata); |
2391 |
return (HBITMAP) bitmap; |
return (RD_HBITMAP) bitmap; |
2392 |
} |
} |
2393 |
|
|
2394 |
void |
void |
2436 |
} |
} |
2437 |
|
|
2438 |
void |
void |
2439 |
ui_destroy_bitmap(HBITMAP bmp) |
ui_destroy_bitmap(RD_HBITMAP bmp) |
2440 |
{ |
{ |
2441 |
XFreePixmap(g_display, (Pixmap) bmp); |
XFreePixmap(g_display, (Pixmap) bmp); |
2442 |
} |
} |
2443 |
|
|
2444 |
HGLYPH |
RD_HGLYPH |
2445 |
ui_create_glyph(int width, int height, uint8 * data) |
ui_create_glyph(int width, int height, uint8 * data) |
2446 |
{ |
{ |
2447 |
XImage *image; |
XImage *image; |
2463 |
XPutImage(g_display, bitmap, g_create_glyph_gc, image, 0, 0, 0, 0, width, height); |
XPutImage(g_display, bitmap, g_create_glyph_gc, image, 0, 0, 0, 0, width, height); |
2464 |
|
|
2465 |
XFree(image); |
XFree(image); |
2466 |
return (HGLYPH) bitmap; |
return (RD_HGLYPH) bitmap; |
2467 |
} |
} |
2468 |
|
|
2469 |
void |
void |
2470 |
ui_destroy_glyph(HGLYPH glyph) |
ui_destroy_glyph(RD_HGLYPH glyph) |
2471 |
{ |
{ |
2472 |
XFreePixmap(g_display, (Pixmap) glyph); |
XFreePixmap(g_display, (Pixmap) glyph); |
2473 |
} |
} |
2474 |
|
|
2475 |
HCURSOR |
RD_HCURSOR |
2476 |
ui_create_cursor(unsigned int x, unsigned int y, int width, int height, |
ui_create_cursor(unsigned int x, unsigned int y, int width, int height, |
2477 |
uint8 * andmask, uint8 * xormask) |
uint8 * andmask, uint8 * xormask) |
2478 |
{ |
{ |
2479 |
HGLYPH maskglyph, cursorglyph; |
RD_HGLYPH maskglyph, cursorglyph; |
2480 |
XColor bg, fg; |
XColor bg, fg; |
2481 |
Cursor xcursor; |
Cursor xcursor; |
2482 |
uint8 *cursor, *pcursor; |
uint8 *cursor, *pcursor; |
2540 |
ui_destroy_glyph(cursorglyph); |
ui_destroy_glyph(cursorglyph); |
2541 |
xfree(mask); |
xfree(mask); |
2542 |
xfree(cursor); |
xfree(cursor); |
2543 |
return (HCURSOR) xcursor; |
return (RD_HCURSOR) xcursor; |
2544 |
} |
} |
2545 |
|
|
2546 |
void |
void |
2547 |
ui_set_cursor(HCURSOR cursor) |
ui_set_cursor(RD_HCURSOR cursor) |
2548 |
{ |
{ |
2549 |
g_current_cursor = (Cursor) cursor; |
g_current_cursor = (Cursor) cursor; |
2550 |
XDefineCursor(g_display, g_wnd, g_current_cursor); |
XDefineCursor(g_display, g_wnd, g_current_cursor); |
2552 |
} |
} |
2553 |
|
|
2554 |
void |
void |
2555 |
ui_destroy_cursor(HCURSOR cursor) |
ui_destroy_cursor(RD_HCURSOR cursor) |
2556 |
{ |
{ |
2557 |
XFreeCursor(g_display, (Cursor) cursor); |
XFreeCursor(g_display, (Cursor) cursor); |
2558 |
} |
} |
2570 |
(xc)->flags = DoRed | DoGreen | DoBlue; |
(xc)->flags = DoRed | DoGreen | DoBlue; |
2571 |
|
|
2572 |
|
|
2573 |
HCOLOURMAP |
RD_HCOLOURMAP |
2574 |
ui_create_colourmap(COLOURMAP * colours) |
ui_create_colourmap(COLOURMAP * colours) |
2575 |
{ |
{ |
2576 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
2666 |
XStoreColors(g_display, map, xcolours, ncolours); |
XStoreColors(g_display, map, xcolours, ncolours); |
2667 |
|
|
2668 |
xfree(xcolours); |
xfree(xcolours); |
2669 |
return (HCOLOURMAP) map; |
return (RD_HCOLOURMAP) map; |
2670 |
} |
} |
2671 |
} |
} |
2672 |
|
|
2673 |
void |
void |
2674 |
ui_destroy_colourmap(HCOLOURMAP map) |
ui_destroy_colourmap(RD_HCOLOURMAP map) |
2675 |
{ |
{ |
2676 |
if (!g_owncolmap) |
if (!g_owncolmap) |
2677 |
xfree(map); |
xfree(map); |
2680 |
} |
} |
2681 |
|
|
2682 |
void |
void |
2683 |
ui_set_colourmap(HCOLOURMAP map) |
ui_set_colourmap(RD_HCOLOURMAP map) |
2684 |
{ |
{ |
2685 |
if (!g_owncolmap) |
if (!g_owncolmap) |
2686 |
{ |
{ |
2768 |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
2769 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
2770 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
2771 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
2772 |
break; |
break; |
2773 |
|
|
2774 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
2783 |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
2784 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
2785 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
2786 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
2787 |
break; |
break; |
2788 |
|
|
2789 |
default: |
default: |
2826 |
void |
void |
2827 |
ui_memblt(uint8 opcode, |
ui_memblt(uint8 opcode, |
2828 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
2829 |
/* src */ HBITMAP src, int srcx, int srcy) |
/* src */ RD_HBITMAP src, int srcx, int srcy) |
2830 |
{ |
{ |
2831 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
2832 |
XCopyArea(g_display, (Pixmap) src, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
XCopyArea(g_display, (Pixmap) src, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
2841 |
void |
void |
2842 |
ui_triblt(uint8 opcode, |
ui_triblt(uint8 opcode, |
2843 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
2844 |
/* src */ HBITMAP src, int srcx, int srcy, |
/* src */ RD_HBITMAP src, int srcx, int srcy, |
2845 |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
2846 |
{ |
{ |
2847 |
/* This is potentially difficult to do in general. Until someone |
/* This is potentially difficult to do in general. Until someone |
2899 |
void |
void |
2900 |
ui_polygon(uint8 opcode, |
ui_polygon(uint8 opcode, |
2901 |
/* mode */ uint8 fillmode, |
/* mode */ uint8 fillmode, |
2902 |
/* dest */ POINT * point, int npoints, |
/* dest */ RD_POINT * point, int npoints, |
2903 |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
2904 |
{ |
{ |
2905 |
uint8 style, i, ipattern[8]; |
uint8 style, i, ipattern[8]; |
2942 |
FILL_POLYGON((XPoint *) point, npoints); |
FILL_POLYGON((XPoint *) point, npoints); |
2943 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
2944 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
2945 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
2946 |
break; |
break; |
2947 |
|
|
2948 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
2957 |
FILL_POLYGON((XPoint *) point, npoints); |
FILL_POLYGON((XPoint *) point, npoints); |
2958 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
2959 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
2960 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
2961 |
break; |
break; |
2962 |
|
|
2963 |
default: |
default: |
2969 |
|
|
2970 |
void |
void |
2971 |
ui_polyline(uint8 opcode, |
ui_polyline(uint8 opcode, |
2972 |
/* dest */ POINT * points, int npoints, |
/* dest */ RD_POINT * points, int npoints, |
2973 |
/* pen */ PEN * pen) |
/* pen */ PEN * pen) |
2974 |
{ |
{ |
2975 |
/* TODO: set join style */ |
/* TODO: set join style */ |
3020 |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
3021 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3022 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3023 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3024 |
break; |
break; |
3025 |
|
|
3026 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
3035 |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
3036 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3037 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3038 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3039 |
break; |
break; |
3040 |
|
|
3041 |
default: |
default: |
3049 |
void |
void |
3050 |
ui_draw_glyph(int mixmode, |
ui_draw_glyph(int mixmode, |
3051 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
3052 |
/* src */ HGLYPH glyph, int srcx, int srcy, |
/* src */ RD_HGLYPH glyph, int srcx, int srcy, |
3053 |
int bgcolour, int fgcolour) |
int bgcolour, int fgcolour) |
3054 |
{ |
{ |
3055 |
SET_FOREGROUND(fgcolour); |
SET_FOREGROUND(fgcolour); |
3234 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3235 |
{ |
{ |
3236 |
image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap); |
image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap); |
3237 |
|
exit_if_null(image); |
3238 |
} |
} |
3239 |
else |
else |
3240 |
{ |
{ |
3241 |
pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth); |
pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth); |
3242 |
XCopyArea(g_display, g_wnd, pix, g_gc, x, y, cx, cy, 0, 0); |
XCopyArea(g_display, g_wnd, pix, g_gc, x, y, cx, cy, 0, 0); |
3243 |
image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap); |
image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap); |
3244 |
|
exit_if_null(image); |
3245 |
XFreePixmap(g_display, pix); |
XFreePixmap(g_display, pix); |
3246 |
} |
} |
3247 |
|
|
3263 |
return; |
return; |
3264 |
|
|
3265 |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
3266 |
(char *) data, cx, cy, BitmapPad(g_display), cx * g_bpp / 8); |
(char *) data, cx, cy, g_bpp, 0); |
3267 |
|
|
3268 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3269 |
{ |
{ |
3297 |
|
|
3298 |
|
|
3299 |
void |
void |
3300 |
ui_seamless_begin(BOOL hidden) |
ui_seamless_begin(RD_BOOL hidden) |
3301 |
{ |
{ |
3302 |
if (!g_seamless_rdp) |
if (!g_seamless_rdp) |
3303 |
return; |
return; |
3465 |
XSetWMProtocols(g_display, wnd, &g_kill_atom, 1); |
XSetWMProtocols(g_display, wnd, &g_kill_atom, 1); |
3466 |
|
|
3467 |
sw = xmalloc(sizeof(seamless_window)); |
sw = xmalloc(sizeof(seamless_window)); |
3468 |
|
|
3469 |
|
memset(sw, 0, sizeof(seamless_window)); |
3470 |
|
|
3471 |
sw->wnd = wnd; |
sw->wnd = wnd; |
3472 |
sw->id = id; |
sw->id = id; |
|
sw->behind = 0; |
|
3473 |
sw->group = sw_find_group(group, False); |
sw->group = sw_find_group(group, False); |
3474 |
sw->group->refcnt++; |
sw->group->refcnt++; |
|
sw->xoffset = 0; |
|
|
sw->yoffset = 0; |
|
|
sw->width = 0; |
|
|
sw->height = 0; |
|
3475 |
sw->state = SEAMLESSRDP_NOTYETMAPPED; |
sw->state = SEAMLESSRDP_NOTYETMAPPED; |
3476 |
sw->desktop = 0; |
sw->desktop = 0; |
3477 |
sw->position_timer = xmalloc(sizeof(struct timeval)); |
sw->position_timer = xmalloc(sizeof(struct timeval)); |
3538 |
} |
} |
3539 |
|
|
3540 |
|
|
3541 |
|
void |
3542 |
|
ui_seamless_seticon(unsigned long id, const char *format, int width, int height, int chunk, |
3543 |
|
const char *data, int chunk_len) |
3544 |
|
{ |
3545 |
|
seamless_window *sw; |
3546 |
|
|
3547 |
|
if (!g_seamless_active) |
3548 |
|
return; |
3549 |
|
|
3550 |
|
sw = sw_get_window_by_id(id); |
3551 |
|
if (!sw) |
3552 |
|
{ |
3553 |
|
warning("ui_seamless_seticon: No information for window 0x%lx\n", id); |
3554 |
|
return; |
3555 |
|
} |
3556 |
|
|
3557 |
|
if (chunk == 0) |
3558 |
|
{ |
3559 |
|
if (sw->icon_size) |
3560 |
|
warning("ui_seamless_seticon: New icon started before previous completed\n"); |
3561 |
|
|
3562 |
|
if (strcmp(format, "RGBA") != 0) |
3563 |
|
{ |
3564 |
|
warning("ui_seamless_seticon: Uknown icon format \"%s\"\n", format); |
3565 |
|
return; |
3566 |
|
} |
3567 |
|
|
3568 |
|
sw->icon_size = width * height * 4; |
3569 |
|
if (sw->icon_size > 32 * 32 * 4) |
3570 |
|
{ |
3571 |
|
warning("ui_seamless_seticon: Icon too large (%d bytes)\n", sw->icon_size); |
3572 |
|
sw->icon_size = 0; |
3573 |
|
return; |
3574 |
|
} |
3575 |
|
|
3576 |
|
sw->icon_offset = 0; |
3577 |
|
} |
3578 |
|
else |
3579 |
|
{ |
3580 |
|
if (!sw->icon_size) |
3581 |
|
return; |
3582 |
|
} |
3583 |
|
|
3584 |
|
if (chunk_len > (sw->icon_size - sw->icon_offset)) |
3585 |
|
{ |
3586 |
|
warning("ui_seamless_seticon: Too large chunk received (%d bytes > %d bytes)\n", |
3587 |
|
chunk_len, sw->icon_size - sw->icon_offset); |
3588 |
|
sw->icon_size = 0; |
3589 |
|
return; |
3590 |
|
} |
3591 |
|
|
3592 |
|
memcpy(sw->icon_buffer + sw->icon_offset, data, chunk_len); |
3593 |
|
sw->icon_offset += chunk_len; |
3594 |
|
|
3595 |
|
if (sw->icon_offset == sw->icon_size) |
3596 |
|
{ |
3597 |
|
ewmh_set_icon(sw->wnd, width, height, sw->icon_buffer); |
3598 |
|
sw->icon_size = 0; |
3599 |
|
} |
3600 |
|
} |
3601 |
|
|
3602 |
|
|
3603 |
|
void |
3604 |
|
ui_seamless_delicon(unsigned long id, const char *format, int width, int height) |
3605 |
|
{ |
3606 |
|
seamless_window *sw; |
3607 |
|
|
3608 |
|
if (!g_seamless_active) |
3609 |
|
return; |
3610 |
|
|
3611 |
|
sw = sw_get_window_by_id(id); |
3612 |
|
if (!sw) |
3613 |
|
{ |
3614 |
|
warning("ui_seamless_seticon: No information for window 0x%lx\n", id); |
3615 |
|
return; |
3616 |
|
} |
3617 |
|
|
3618 |
|
if (strcmp(format, "RGBA") != 0) |
3619 |
|
{ |
3620 |
|
warning("ui_seamless_seticon: Uknown icon format \"%s\"\n", format); |
3621 |
|
return; |
3622 |
|
} |
3623 |
|
|
3624 |
|
ewmh_del_icon(sw->wnd, width, height); |
3625 |
|
} |
3626 |
|
|
3627 |
|
|
3628 |
void |
void |
3629 |
ui_seamless_move_window(unsigned long id, int x, int y, int width, int height, unsigned long flags) |
ui_seamless_move_window(unsigned long id, int x, int y, int width, int height, unsigned long flags) |
3630 |
{ |
{ |