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> |
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 |
extern int g_server_bpp; |
/* Color depth of the RDP session. |
44 |
|
As of RDP 5.1, it may be 8, 15, 16 or 24. */ |
45 |
|
extern int g_server_depth; |
46 |
extern int g_win_button_size; |
extern int g_win_button_size; |
47 |
|
|
48 |
Display *g_display; |
Display *g_display; |
50 |
static int g_x_socket; |
static int g_x_socket; |
51 |
static Screen *g_screen; |
static Screen *g_screen; |
52 |
Window g_wnd; |
Window g_wnd; |
53 |
|
|
54 |
|
/* SeamlessRDP support */ |
55 |
|
typedef struct _seamless_group |
56 |
|
{ |
57 |
|
Window wnd; |
58 |
|
unsigned long id; |
59 |
|
unsigned int refcnt; |
60 |
|
} seamless_group; |
61 |
|
typedef struct _seamless_window |
62 |
|
{ |
63 |
|
Window wnd; |
64 |
|
unsigned long id; |
65 |
|
unsigned long behind; |
66 |
|
seamless_group *group; |
67 |
|
int xoffset, yoffset; |
68 |
|
int width, height; |
69 |
|
int state; /* normal/minimized/maximized. */ |
70 |
|
unsigned int desktop; |
71 |
|
struct timeval *position_timer; |
72 |
|
|
73 |
|
RD_BOOL outstanding_position; |
74 |
|
unsigned int outpos_serial; |
75 |
|
int outpos_xoffset, outpos_yoffset; |
76 |
|
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; |
83 |
|
} seamless_window; |
84 |
|
static seamless_window *g_seamless_windows = NULL; |
85 |
|
static unsigned long g_seamless_focused = 0; |
86 |
|
static RD_BOOL g_seamless_started = False; /* Server end is up and running */ |
87 |
|
static RD_BOOL g_seamless_active = False; /* We are currently in seamless mode */ |
88 |
|
static RD_BOOL g_seamless_hidden = False; /* Desktop is hidden on server */ |
89 |
|
static RD_BOOL g_seamless_broken_restack = False; /* WM does not properly restack */ |
90 |
|
extern RD_BOOL g_seamless_rdp; |
91 |
|
|
92 |
extern uint32 g_embed_wnd; |
extern uint32 g_embed_wnd; |
93 |
BOOL g_enable_compose = False; |
RD_BOOL g_enable_compose = False; |
94 |
BOOL g_Unobscured; /* used for screenblt */ |
RD_BOOL g_Unobscured; /* used for screenblt */ |
95 |
static GC g_gc = NULL; |
static GC g_gc = NULL; |
96 |
static GC g_create_bitmap_gc = NULL; |
static GC g_create_bitmap_gc = NULL; |
97 |
static GC g_create_glyph_gc = NULL; |
static GC g_create_glyph_gc = NULL; |
98 |
|
static XRectangle g_clip_rectangle; |
99 |
static Visual *g_visual; |
static Visual *g_visual; |
100 |
|
/* Color depth of the X11 visual of our window (e.g. 24 for True Color R8G8B visual). |
101 |
|
This may be 32 for R8G8B8 visuals, and then the rest of the bits are undefined |
102 |
|
as far as we're concerned. */ |
103 |
static int g_depth; |
static int g_depth; |
104 |
|
/* Bits-per-Pixel of the pixmaps we'll be using to draw on our window. |
105 |
|
This may be larger than g_depth, in which case some of the bits would |
106 |
|
be kept solely for alignment (e.g. 32bpp pixmaps on a 24bpp visual). */ |
107 |
static int g_bpp; |
static int g_bpp; |
108 |
static XIM g_IM; |
static XIM g_IM; |
109 |
static XIC g_IC; |
static XIC g_IC; |
110 |
static XModifierKeymap *g_mod_map; |
static XModifierKeymap *g_mod_map; |
111 |
|
/* Maps logical (xmodmap -pp) pointing device buttons (0-based) back |
112 |
|
to physical (1-based) indices. */ |
113 |
|
static unsigned char g_pointer_log_to_phys_map[16]; |
114 |
static Cursor g_current_cursor; |
static Cursor g_current_cursor; |
115 |
static HCURSOR g_null_cursor = NULL; |
static RD_HCURSOR g_null_cursor = NULL; |
116 |
static Atom g_protocol_atom, g_kill_atom; |
static Atom g_protocol_atom, g_kill_atom; |
117 |
static BOOL g_focused; |
extern Atom g_net_wm_state_atom; |
118 |
static BOOL g_mouse_in_wnd; |
extern Atom g_net_wm_desktop_atom; |
119 |
static BOOL g_arch_match = False; /* set to True if RGB XServer and little endian */ |
static RD_BOOL g_focused; |
120 |
|
static RD_BOOL g_mouse_in_wnd; |
121 |
|
/* Indicates that: |
122 |
|
1) visual has 15, 16 or 24 depth and the same color channel masks |
123 |
|
as its RDP equivalent (implies X server is LE), |
124 |
|
2) host is LE |
125 |
|
This will trigger an optimization whose real value is questionable. |
126 |
|
*/ |
127 |
|
static RD_BOOL g_compatible_arch; |
128 |
|
/* Indicates whether RDP's bitmaps and our XImages have the same |
129 |
|
binary format. If so, we can avoid an expensive translation. |
130 |
|
Note that this can be true when g_compatible_arch is false, |
131 |
|
e.g.: |
132 |
|
|
133 |
|
RDP(LE) <-> host(BE) <-> X-Server(LE) |
134 |
|
|
135 |
|
('host' is the machine running rdesktop; the host simply memcpy's |
136 |
|
so its endianess doesn't matter) |
137 |
|
*/ |
138 |
|
static RD_BOOL g_no_translate_image = False; |
139 |
|
|
140 |
/* endianness */ |
/* endianness */ |
141 |
static BOOL g_host_be; |
static RD_BOOL g_host_be; |
142 |
static BOOL g_xserver_be; |
static RD_BOOL g_xserver_be; |
143 |
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; |
144 |
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; |
145 |
|
|
146 |
/* software backing store */ |
/* software backing store */ |
147 |
extern BOOL g_ownbackstore; |
extern RD_BOOL g_ownbackstore; |
148 |
static Pixmap g_backstore = 0; |
static Pixmap g_backstore = 0; |
149 |
|
|
150 |
/* Moving in single app mode */ |
/* Moving in single app mode */ |
151 |
static BOOL g_moving_wnd; |
static RD_BOOL g_moving_wnd; |
152 |
static int g_move_x_offset = 0; |
static int g_move_x_offset = 0; |
153 |
static int g_move_y_offset = 0; |
static int g_move_y_offset = 0; |
154 |
static BOOL g_using_full_workarea = False; |
static RD_BOOL g_using_full_workarea = False; |
155 |
|
|
156 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
157 |
extern int g_dsp_fd; |
extern RD_BOOL g_rdpsnd; |
|
extern BOOL g_dsp_busy; |
|
|
extern BOOL g_rdpsnd; |
|
158 |
#endif |
#endif |
159 |
|
|
160 |
/* MWM decorations */ |
/* MWM decorations */ |
162 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
163 |
typedef struct |
typedef struct |
164 |
{ |
{ |
165 |
uint32 flags; |
unsigned long flags; |
166 |
uint32 functions; |
unsigned long functions; |
167 |
uint32 decorations; |
unsigned long decorations; |
168 |
sint32 inputMode; |
long inputMode; |
169 |
uint32 status; |
unsigned long status; |
170 |
} |
} |
171 |
PropMotifWmHints; |
PropMotifWmHints; |
172 |
|
|
178 |
} |
} |
179 |
PixelColour; |
PixelColour; |
180 |
|
|
181 |
|
#define ON_ALL_SEAMLESS_WINDOWS(func, args) \ |
182 |
|
do { \ |
183 |
|
seamless_window *sw; \ |
184 |
|
XRectangle rect; \ |
185 |
|
if (!g_seamless_windows) break; \ |
186 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) { \ |
187 |
|
rect.x = g_clip_rectangle.x - sw->xoffset; \ |
188 |
|
rect.y = g_clip_rectangle.y - sw->yoffset; \ |
189 |
|
rect.width = g_clip_rectangle.width; \ |
190 |
|
rect.height = g_clip_rectangle.height; \ |
191 |
|
XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded); \ |
192 |
|
func args; \ |
193 |
|
} \ |
194 |
|
XSetClipRectangles(g_display, g_gc, 0, 0, &g_clip_rectangle, 1, YXBanded); \ |
195 |
|
} while (0) |
196 |
|
|
197 |
|
static void |
198 |
|
seamless_XFillPolygon(Drawable d, XPoint * points, int npoints, int xoffset, int yoffset) |
199 |
|
{ |
200 |
|
points[0].x -= xoffset; |
201 |
|
points[0].y -= yoffset; |
202 |
|
XFillPolygon(g_display, d, g_gc, points, npoints, Complex, CoordModePrevious); |
203 |
|
points[0].x += xoffset; |
204 |
|
points[0].y += yoffset; |
205 |
|
} |
206 |
|
|
207 |
|
static void |
208 |
|
seamless_XDrawLines(Drawable d, XPoint * points, int npoints, int xoffset, int yoffset) |
209 |
|
{ |
210 |
|
points[0].x -= xoffset; |
211 |
|
points[0].y -= yoffset; |
212 |
|
XDrawLines(g_display, d, g_gc, points, npoints, CoordModePrevious); |
213 |
|
points[0].x += xoffset; |
214 |
|
points[0].y += yoffset; |
215 |
|
} |
216 |
|
|
217 |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
218 |
{ \ |
{ \ |
219 |
XFillRectangle(g_display, g_wnd, g_gc, x, y, cx, cy); \ |
XFillRectangle(g_display, g_wnd, g_gc, x, y, cx, cy); \ |
220 |
|
ON_ALL_SEAMLESS_WINDOWS(XFillRectangle, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy)); \ |
221 |
if (g_ownbackstore) \ |
if (g_ownbackstore) \ |
222 |
XFillRectangle(g_display, g_backstore, g_gc, x, y, cx, cy); \ |
XFillRectangle(g_display, g_backstore, g_gc, x, y, cx, cy); \ |
223 |
} |
} |
232 |
XFillPolygon(g_display, g_wnd, g_gc, p, np, Complex, CoordModePrevious); \ |
XFillPolygon(g_display, g_wnd, g_gc, p, np, Complex, CoordModePrevious); \ |
233 |
if (g_ownbackstore) \ |
if (g_ownbackstore) \ |
234 |
XFillPolygon(g_display, g_backstore, g_gc, p, np, Complex, CoordModePrevious); \ |
XFillPolygon(g_display, g_backstore, g_gc, p, np, Complex, CoordModePrevious); \ |
235 |
|
ON_ALL_SEAMLESS_WINDOWS(seamless_XFillPolygon, (sw->wnd, p, np, sw->xoffset, sw->yoffset)); \ |
236 |
} |
} |
237 |
|
|
238 |
#define DRAW_ELLIPSE(x,y,cx,cy,m)\ |
#define DRAW_ELLIPSE(x,y,cx,cy,m)\ |
241 |
{ \ |
{ \ |
242 |
case 0: /* Outline */ \ |
case 0: /* Outline */ \ |
243 |
XDrawArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \ |
XDrawArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \ |
244 |
|
ON_ALL_SEAMLESS_WINDOWS(XDrawArc, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy, 0, 360*64)); \ |
245 |
if (g_ownbackstore) \ |
if (g_ownbackstore) \ |
246 |
XDrawArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \ |
XDrawArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \ |
247 |
break; \ |
break; \ |
248 |
case 1: /* Filled */ \ |
case 1: /* Filled */ \ |
249 |
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); \ |
250 |
|
ON_ALL_SEAMLESS_WINDOWS(XFillArc, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy, 0, 360*64)); \ |
251 |
if (g_ownbackstore) \ |
if (g_ownbackstore) \ |
252 |
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); \ |
253 |
break; \ |
break; \ |
255 |
} |
} |
256 |
|
|
257 |
/* colour maps */ |
/* colour maps */ |
258 |
extern BOOL g_owncolmap; |
extern RD_BOOL g_owncolmap; |
259 |
static Colormap g_xcolmap; |
static Colormap g_xcolmap; |
260 |
static uint32 *g_colmap = NULL; |
static uint32 *g_colmap = NULL; |
261 |
|
|
262 |
#define TRANSLATE(col) ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] ) |
#define TRANSLATE(col) ( g_server_depth != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] ) |
263 |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
264 |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
265 |
|
|
285 |
#define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, rop2_map[rop2]); } |
#define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, rop2_map[rop2]); } |
286 |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, GXcopy); } |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, GXcopy); } |
287 |
|
|
288 |
|
static seamless_window * |
289 |
|
sw_get_window_by_id(unsigned long id) |
290 |
|
{ |
291 |
|
seamless_window *sw; |
292 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
293 |
|
{ |
294 |
|
if (sw->id == id) |
295 |
|
return sw; |
296 |
|
} |
297 |
|
return NULL; |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
|
static seamless_window * |
302 |
|
sw_get_window_by_wnd(Window wnd) |
303 |
|
{ |
304 |
|
seamless_window *sw; |
305 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
306 |
|
{ |
307 |
|
if (sw->wnd == wnd) |
308 |
|
return sw; |
309 |
|
} |
310 |
|
return NULL; |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
|
static void |
315 |
|
sw_remove_window(seamless_window * win) |
316 |
|
{ |
317 |
|
seamless_window *sw, **prevnext = &g_seamless_windows; |
318 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
319 |
|
{ |
320 |
|
if (sw == win) |
321 |
|
{ |
322 |
|
*prevnext = sw->next; |
323 |
|
sw->group->refcnt--; |
324 |
|
if (sw->group->refcnt == 0) |
325 |
|
{ |
326 |
|
XDestroyWindow(g_display, sw->group->wnd); |
327 |
|
xfree(sw->group); |
328 |
|
} |
329 |
|
xfree(sw->position_timer); |
330 |
|
xfree(sw); |
331 |
|
return; |
332 |
|
} |
333 |
|
prevnext = &sw->next; |
334 |
|
} |
335 |
|
return; |
336 |
|
} |
337 |
|
|
338 |
|
|
339 |
|
/* Move all windows except wnd to new desktop */ |
340 |
|
static void |
341 |
|
sw_all_to_desktop(Window wnd, unsigned int desktop) |
342 |
|
{ |
343 |
|
seamless_window *sw; |
344 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
345 |
|
{ |
346 |
|
if (sw->wnd == wnd) |
347 |
|
continue; |
348 |
|
if (sw->desktop != desktop) |
349 |
|
{ |
350 |
|
ewmh_move_to_desktop(sw->wnd, desktop); |
351 |
|
sw->desktop = desktop; |
352 |
|
} |
353 |
|
} |
354 |
|
} |
355 |
|
|
356 |
|
|
357 |
|
/* Send our position */ |
358 |
|
static void |
359 |
|
sw_update_position(seamless_window * sw) |
360 |
|
{ |
361 |
|
XWindowAttributes wa; |
362 |
|
int x, y; |
363 |
|
Window child_return; |
364 |
|
unsigned int serial; |
365 |
|
|
366 |
|
XGetWindowAttributes(g_display, sw->wnd, &wa); |
367 |
|
XTranslateCoordinates(g_display, sw->wnd, wa.root, |
368 |
|
-wa.border_width, -wa.border_width, &x, &y, &child_return); |
369 |
|
|
370 |
|
serial = seamless_send_position(sw->id, x, y, wa.width, wa.height, 0); |
371 |
|
|
372 |
|
sw->outstanding_position = True; |
373 |
|
sw->outpos_serial = serial; |
374 |
|
|
375 |
|
sw->outpos_xoffset = x; |
376 |
|
sw->outpos_yoffset = y; |
377 |
|
sw->outpos_width = wa.width; |
378 |
|
sw->outpos_height = wa.height; |
379 |
|
} |
380 |
|
|
381 |
|
|
382 |
|
/* Check if it's time to send our position */ |
383 |
|
static void |
384 |
|
sw_check_timers() |
385 |
|
{ |
386 |
|
seamless_window *sw; |
387 |
|
struct timeval now; |
388 |
|
|
389 |
|
gettimeofday(&now, NULL); |
390 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
391 |
|
{ |
392 |
|
if (timerisset(sw->position_timer) && timercmp(sw->position_timer, &now, <)) |
393 |
|
{ |
394 |
|
timerclear(sw->position_timer); |
395 |
|
sw_update_position(sw); |
396 |
|
} |
397 |
|
} |
398 |
|
} |
399 |
|
|
400 |
|
|
401 |
|
static void |
402 |
|
sw_restack_window(seamless_window * sw, unsigned long behind) |
403 |
|
{ |
404 |
|
seamless_window *sw_above; |
405 |
|
|
406 |
|
/* Remove window from stack */ |
407 |
|
for (sw_above = g_seamless_windows; sw_above; sw_above = sw_above->next) |
408 |
|
{ |
409 |
|
if (sw_above->behind == sw->id) |
410 |
|
break; |
411 |
|
} |
412 |
|
|
413 |
|
if (sw_above) |
414 |
|
sw_above->behind = sw->behind; |
415 |
|
|
416 |
|
/* And then add it at the new position */ |
417 |
|
for (sw_above = g_seamless_windows; sw_above; sw_above = sw_above->next) |
418 |
|
{ |
419 |
|
if (sw_above->behind == behind) |
420 |
|
break; |
421 |
|
} |
422 |
|
|
423 |
|
if (sw_above) |
424 |
|
sw_above->behind = sw->id; |
425 |
|
|
426 |
|
sw->behind = behind; |
427 |
|
} |
428 |
|
|
429 |
|
|
430 |
|
static void |
431 |
|
sw_handle_restack(seamless_window * sw) |
432 |
|
{ |
433 |
|
Status status; |
434 |
|
Window root, parent, *children; |
435 |
|
unsigned int nchildren, i; |
436 |
|
seamless_window *sw_below; |
437 |
|
|
438 |
|
status = XQueryTree(g_display, RootWindowOfScreen(g_screen), |
439 |
|
&root, &parent, &children, &nchildren); |
440 |
|
if (!status || !nchildren) |
441 |
|
return; |
442 |
|
|
443 |
|
sw_below = NULL; |
444 |
|
|
445 |
|
i = 0; |
446 |
|
while (children[i] != sw->wnd) |
447 |
|
{ |
448 |
|
i++; |
449 |
|
if (i >= nchildren) |
450 |
|
goto end; |
451 |
|
} |
452 |
|
|
453 |
|
for (i++; i < nchildren; i++) |
454 |
|
{ |
455 |
|
sw_below = sw_get_window_by_wnd(children[i]); |
456 |
|
if (sw_below) |
457 |
|
break; |
458 |
|
} |
459 |
|
|
460 |
|
if (!sw_below && !sw->behind) |
461 |
|
goto end; |
462 |
|
if (sw_below && (sw_below->id == sw->behind)) |
463 |
|
goto end; |
464 |
|
|
465 |
|
if (sw_below) |
466 |
|
{ |
467 |
|
seamless_send_zchange(sw->id, sw_below->id, 0); |
468 |
|
sw_restack_window(sw, sw_below->id); |
469 |
|
} |
470 |
|
else |
471 |
|
{ |
472 |
|
seamless_send_zchange(sw->id, 0, 0); |
473 |
|
sw_restack_window(sw, 0); |
474 |
|
} |
475 |
|
|
476 |
|
end: |
477 |
|
XFree(children); |
478 |
|
} |
479 |
|
|
480 |
|
|
481 |
|
static seamless_group * |
482 |
|
sw_find_group(unsigned long id, RD_BOOL dont_create) |
483 |
|
{ |
484 |
|
seamless_window *sw; |
485 |
|
seamless_group *sg; |
486 |
|
XSetWindowAttributes attribs; |
487 |
|
|
488 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
489 |
|
{ |
490 |
|
if (sw->group->id == id) |
491 |
|
return sw->group; |
492 |
|
} |
493 |
|
|
494 |
|
if (dont_create) |
495 |
|
return NULL; |
496 |
|
|
497 |
|
sg = xmalloc(sizeof(seamless_group)); |
498 |
|
|
499 |
|
sg->wnd = |
500 |
|
XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0, |
501 |
|
CopyFromParent, CopyFromParent, CopyFromParent, 0, &attribs); |
502 |
|
|
503 |
|
sg->id = id; |
504 |
|
sg->refcnt = 0; |
505 |
|
|
506 |
|
return sg; |
507 |
|
} |
508 |
|
|
509 |
|
|
510 |
static void |
static void |
511 |
mwm_hide_decorations(void) |
mwm_hide_decorations(Window wnd) |
512 |
{ |
{ |
513 |
PropMotifWmHints motif_hints; |
PropMotifWmHints motif_hints; |
514 |
Atom hintsatom; |
Atom hintsatom; |
525 |
return; |
return; |
526 |
} |
} |
527 |
|
|
528 |
XChangeProperty(g_display, g_wnd, hintsatom, hintsatom, 32, PropModeReplace, |
XChangeProperty(g_display, wnd, hintsatom, hintsatom, 32, PropModeReplace, |
529 |
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
530 |
|
|
531 |
|
} |
532 |
|
|
533 |
|
typedef struct _sw_configurenotify_context |
534 |
|
{ |
535 |
|
Window window; |
536 |
|
unsigned long serial; |
537 |
|
} sw_configurenotify_context; |
538 |
|
|
539 |
|
/* Predicate procedure for sw_wait_configurenotify */ |
540 |
|
static Bool |
541 |
|
sw_configurenotify_p(Display * display, XEvent * xevent, XPointer arg) |
542 |
|
{ |
543 |
|
sw_configurenotify_context *context = (sw_configurenotify_context *) arg; |
544 |
|
if (xevent->xany.type == ConfigureNotify |
545 |
|
&& xevent->xconfigure.window == context->window |
546 |
|
&& xevent->xany.serial >= context->serial) |
547 |
|
return True; |
548 |
|
|
549 |
|
return False; |
550 |
|
} |
551 |
|
|
552 |
|
/* Wait for a ConfigureNotify, with a equal or larger serial, on the |
553 |
|
specified window. The event will be removed from the queue. We |
554 |
|
could use XMaskEvent(StructureNotifyMask), but we would then risk |
555 |
|
throwing away crucial events like DestroyNotify. |
556 |
|
|
557 |
|
After a ConfigureWindow, according to ICCCM section 4.1.5, we |
558 |
|
should recieve a ConfigureNotify, either a real or synthetic |
559 |
|
one. This indicates that the configure has been "completed". |
560 |
|
However, some WMs such as several versions of Metacity fails to |
561 |
|
send synthetic events. See bug |
562 |
|
http://bugzilla.gnome.org/show_bug.cgi?id=322840. We need to use a |
563 |
|
timeout to avoid a hang. Tk uses the same approach. */ |
564 |
|
static void |
565 |
|
sw_wait_configurenotify(Window wnd, unsigned long serial) |
566 |
|
{ |
567 |
|
XEvent xevent; |
568 |
|
sw_configurenotify_context context; |
569 |
|
time_t start; |
570 |
|
RD_BOOL got = False; |
571 |
|
|
572 |
|
context.window = wnd; |
573 |
|
context.serial = serial; |
574 |
|
start = time(NULL); |
575 |
|
|
576 |
|
do |
577 |
|
{ |
578 |
|
if (XCheckIfEvent(g_display, &xevent, sw_configurenotify_p, (XPointer) & context)) |
579 |
|
{ |
580 |
|
got = True; |
581 |
|
break; |
582 |
|
} |
583 |
|
usleep(100000); |
584 |
|
} |
585 |
|
while (time(NULL) - start < 2); |
586 |
|
|
587 |
|
if (!got) |
588 |
|
{ |
589 |
|
warning("Broken Window Manager: Timeout while waiting for ConfigureNotify\n"); |
590 |
|
} |
591 |
|
} |
592 |
|
|
593 |
|
/* Get the toplevel window, in case of reparenting */ |
594 |
|
static Window |
595 |
|
sw_get_toplevel(Window wnd) |
596 |
|
{ |
597 |
|
Window root, parent; |
598 |
|
Window *child_list; |
599 |
|
unsigned int num_children; |
600 |
|
|
601 |
|
while (1) |
602 |
|
{ |
603 |
|
XQueryTree(g_display, wnd, &root, &parent, &child_list, &num_children); |
604 |
|
if (root == parent) |
605 |
|
{ |
606 |
|
break; |
607 |
|
} |
608 |
|
else if (!parent) |
609 |
|
{ |
610 |
|
warning("Internal error: sw_get_toplevel called with root window\n"); |
611 |
|
} |
612 |
|
|
613 |
|
wnd = parent; |
614 |
|
} |
615 |
|
|
616 |
|
return wnd; |
617 |
|
} |
618 |
|
|
619 |
|
|
620 |
|
/* Check if wnd is already behind a window wrt stacking order */ |
621 |
|
static RD_BOOL |
622 |
|
sw_window_is_behind(Window wnd, Window behind) |
623 |
|
{ |
624 |
|
Window dummy1, dummy2; |
625 |
|
Window *child_list; |
626 |
|
unsigned int num_children; |
627 |
|
unsigned int i; |
628 |
|
RD_BOOL found_behind = False; |
629 |
|
RD_BOOL found_wnd = False; |
630 |
|
|
631 |
|
wnd = sw_get_toplevel(wnd); |
632 |
|
behind = sw_get_toplevel(behind); |
633 |
|
|
634 |
|
XQueryTree(g_display, RootWindowOfScreen(g_screen), &dummy1, &dummy2, &child_list, |
635 |
|
&num_children); |
636 |
|
|
637 |
|
for (i = num_children - 1; i >= 0; i--) |
638 |
|
{ |
639 |
|
if (child_list[i] == behind) |
640 |
|
{ |
641 |
|
found_behind = True; |
642 |
|
} |
643 |
|
else if (child_list[i] == wnd) |
644 |
|
{ |
645 |
|
found_wnd = True; |
646 |
|
break; |
647 |
|
} |
648 |
|
} |
649 |
|
|
650 |
|
if (child_list) |
651 |
|
XFree(child_list); |
652 |
|
|
653 |
|
if (!found_wnd) |
654 |
|
{ |
655 |
|
warning("sw_window_is_behind: Unable to find window 0x%lx\n", wnd); |
656 |
|
|
657 |
|
if (!found_behind) |
658 |
|
{ |
659 |
|
warning("sw_window_is_behind: Unable to find behind window 0x%lx\n", |
660 |
|
behind); |
661 |
|
} |
662 |
|
} |
663 |
|
|
664 |
|
return found_behind; |
665 |
|
} |
666 |
|
|
667 |
|
|
668 |
|
/* Test if the window manager correctly handles window restacking. In |
669 |
|
particular, we are testing if it's possible to place a window |
670 |
|
between two other windows. Many WMs such as Metacity can only stack |
671 |
|
windows on the top or bottom. The window creation should mostly |
672 |
|
match ui_seamless_create_window. */ |
673 |
|
static void |
674 |
|
seamless_restack_test() |
675 |
|
{ |
676 |
|
/* The goal is to have the middle window between top and |
677 |
|
bottom. The middle window is initially at the top, |
678 |
|
though. */ |
679 |
|
Window wnds[3]; /* top, middle and bottom */ |
680 |
|
int i; |
681 |
|
XEvent xevent; |
682 |
|
XWindowChanges values; |
683 |
|
unsigned long restack_serial; |
684 |
|
|
685 |
|
for (i = 0; i < 3; i++) |
686 |
|
{ |
687 |
|
char name[64]; |
688 |
|
wnds[i] = |
689 |
|
XCreateSimpleWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, 20, 20, |
690 |
|
0, 0, 0); |
691 |
|
snprintf(name, sizeof(name), "SeamlessRDP restack test - window %d", i); |
692 |
|
XStoreName(g_display, wnds[i], name); |
693 |
|
ewmh_set_wm_name(wnds[i], name); |
694 |
|
|
695 |
|
/* Hide decorations. Often this means that no |
696 |
|
reparenting will be done, which makes the restack |
697 |
|
easier. Besides, we want to mimic our other |
698 |
|
seamless windows as much as possible. We must still |
699 |
|
handle the case with reparenting, though. */ |
700 |
|
mwm_hide_decorations(wnds[i]); |
701 |
|
|
702 |
|
/* Prevent windows from appearing in task bar */ |
703 |
|
XSetTransientForHint(g_display, wnds[i], RootWindowOfScreen(g_screen)); |
704 |
|
ewmh_set_window_popup(wnds[i]); |
705 |
|
|
706 |
|
/* We need to catch MapNotify/ConfigureNotify */ |
707 |
|
XSelectInput(g_display, wnds[i], StructureNotifyMask); |
708 |
|
} |
709 |
|
|
710 |
|
/* Map Windows. Currently, we assume that XMapRaised places |
711 |
|
the window on the top of the stack. Should be fairly safe; |
712 |
|
the window is configured before it's mapped. */ |
713 |
|
XMapRaised(g_display, wnds[2]); /* bottom */ |
714 |
|
do |
715 |
|
{ |
716 |
|
XWindowEvent(g_display, wnds[2], StructureNotifyMask, &xevent); |
717 |
|
} |
718 |
|
while (xevent.type != MapNotify); |
719 |
|
XMapRaised(g_display, wnds[0]); /* top */ |
720 |
|
do |
721 |
|
{ |
722 |
|
XWindowEvent(g_display, wnds[0], StructureNotifyMask, &xevent); |
723 |
|
} |
724 |
|
while (xevent.type != MapNotify); |
725 |
|
XMapRaised(g_display, wnds[1]); /* middle */ |
726 |
|
do |
727 |
|
{ |
728 |
|
XWindowEvent(g_display, wnds[1], StructureNotifyMask, &xevent); |
729 |
|
} |
730 |
|
while (xevent.type != MapNotify); |
731 |
|
|
732 |
|
/* The stacking order should now be 1 - 0 - 2 */ |
733 |
|
if (!sw_window_is_behind(wnds[0], wnds[1]) || !sw_window_is_behind(wnds[2], wnds[1])) |
734 |
|
{ |
735 |
|
/* Ok, technically a WM is allowed to stack windows arbitrarily, but... */ |
736 |
|
warning("Broken Window Manager: Unable to test window restacking\n"); |
737 |
|
g_seamless_broken_restack = True; |
738 |
|
for (i = 0; i < 3; i++) |
739 |
|
XDestroyWindow(g_display, wnds[i]); |
740 |
|
return; |
741 |
|
} |
742 |
|
|
743 |
|
/* Restack, using XReconfigureWMWindow, which should correctly |
744 |
|
handle reparented windows as well as nonreparenting WMs. */ |
745 |
|
values.stack_mode = Below; |
746 |
|
values.sibling = wnds[0]; |
747 |
|
restack_serial = XNextRequest(g_display); |
748 |
|
XReconfigureWMWindow(g_display, wnds[1], DefaultScreen(g_display), CWStackMode | CWSibling, |
749 |
|
&values); |
750 |
|
sw_wait_configurenotify(wnds[1], restack_serial); |
751 |
|
|
752 |
|
/* Now verify that middle is behind top but not behind |
753 |
|
bottom */ |
754 |
|
if (!sw_window_is_behind(wnds[1], wnds[0])) |
755 |
|
{ |
756 |
|
warning("Broken Window Manager: doesn't handle restack (restack request was ignored)\n"); |
757 |
|
g_seamless_broken_restack = True; |
758 |
|
} |
759 |
|
else if (sw_window_is_behind(wnds[1], wnds[2])) |
760 |
|
{ |
761 |
|
warning("Broken Window Manager: doesn't handle restack (window was moved to bottom)\n"); |
762 |
|
g_seamless_broken_restack = True; |
763 |
|
} |
764 |
|
|
765 |
|
/* Destroy windows */ |
766 |
|
for (i = 0; i < 3; i++) |
767 |
|
XDestroyWindow(g_display, wnds[i]); |
768 |
} |
} |
769 |
|
|
770 |
#define SPLITCOLOUR15(colour, rv) \ |
#define SPLITCOLOUR15(colour, rv) \ |
798 |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
799 |
x = (x << 16) | (x >> 16); } |
x = (x << 16) | (x >> 16); } |
800 |
|
|
801 |
|
/* The following macros output the same octet sequences |
802 |
|
on both BE and LE hosts: */ |
803 |
|
|
804 |
#define BOUT16(o, x) { *(o++) = x >> 8; *(o++) = x; } |
#define BOUT16(o, x) { *(o++) = x >> 8; *(o++) = x; } |
805 |
#define BOUT24(o, x) { *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; } |
#define BOUT24(o, x) { *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; } |
806 |
#define BOUT32(o, x) { *(o++) = x >> 24; *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; } |
#define BOUT32(o, x) { *(o++) = x >> 24; *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; } |
812 |
translate_colour(uint32 colour) |
translate_colour(uint32 colour) |
813 |
{ |
{ |
814 |
PixelColour pc; |
PixelColour pc; |
815 |
switch (g_server_bpp) |
switch (g_server_depth) |
816 |
{ |
{ |
817 |
case 15: |
case 15: |
818 |
SPLITCOLOUR15(colour, pc); |
SPLITCOLOUR15(colour, pc); |
821 |
SPLITCOLOUR16(colour, pc); |
SPLITCOLOUR16(colour, pc); |
822 |
break; |
break; |
823 |
case 24: |
case 24: |
824 |
|
case 32: |
825 |
SPLITCOLOUR24(colour, pc); |
SPLITCOLOUR24(colour, pc); |
826 |
break; |
break; |
827 |
|
default: |
828 |
|
/* Avoid warning */ |
829 |
|
pc.red = 0; |
830 |
|
pc.green = 0; |
831 |
|
pc.blue = 0; |
832 |
|
break; |
833 |
} |
} |
834 |
return MAKECOLOUR(pc); |
return MAKECOLOUR(pc); |
835 |
} |
} |
881 |
{ |
{ |
882 |
uint16 value; |
uint16 value; |
883 |
|
|
884 |
if (g_arch_match) |
if (g_compatible_arch) |
885 |
{ |
{ |
886 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
887 |
REPEAT2 |
REPEAT2 |
915 |
{ |
{ |
916 |
uint32 value; |
uint32 value; |
917 |
|
|
918 |
if (g_xserver_be) |
if (g_compatible_arch) |
919 |
{ |
{ |
920 |
while (out < end) |
while (out < end) |
921 |
{ |
{ |
938 |
{ |
{ |
939 |
uint32 value; |
uint32 value; |
940 |
|
|
941 |
if (g_arch_match) |
if (g_compatible_arch) |
942 |
{ |
{ |
943 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
944 |
REPEAT4 |
REPEAT4 |
1010 |
uint16 pixel; |
uint16 pixel; |
1011 |
PixelColour pc; |
PixelColour pc; |
1012 |
|
|
1013 |
if (g_arch_match) |
if (g_compatible_arch) |
1014 |
{ |
{ |
1015 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
1016 |
REPEAT3 |
REPEAT3 |
1060 |
uint32 value; |
uint32 value; |
1061 |
PixelColour pc; |
PixelColour pc; |
1062 |
|
|
1063 |
if (g_arch_match) |
if (g_compatible_arch) |
1064 |
{ |
{ |
1065 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
1066 |
REPEAT4 |
REPEAT4 |
1168 |
uint16 pixel; |
uint16 pixel; |
1169 |
PixelColour pc; |
PixelColour pc; |
1170 |
|
|
1171 |
if (g_arch_match) |
if (g_compatible_arch) |
1172 |
{ |
{ |
1173 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
1174 |
REPEAT3 |
REPEAT3 |
1238 |
uint32 value; |
uint32 value; |
1239 |
PixelColour pc; |
PixelColour pc; |
1240 |
|
|
1241 |
if (g_arch_match) |
if (g_compatible_arch) |
1242 |
{ |
{ |
1243 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
1244 |
REPEAT4 |
REPEAT4 |
1367 |
uint32 value; |
uint32 value; |
1368 |
PixelColour pc; |
PixelColour pc; |
1369 |
|
|
1370 |
if (g_arch_match) |
if (g_compatible_arch) |
1371 |
{ |
{ |
1372 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
1373 |
#ifdef NEED_ALIGN |
#ifdef NEED_ALIGN |
1381 |
#else |
#else |
1382 |
REPEAT4 |
REPEAT4 |
1383 |
( |
( |
1384 |
*((uint32 *) out) = *((uint32 *) data); |
/* Only read 3 bytes. Reading 4 bytes means reading beyond buffer. */ |
1385 |
out += 4; |
*((uint32 *) out) = *((uint16 *) data) + (*((uint8 *) data + 2) << 16); |
1386 |
data += 3; |
out += 4; |
1387 |
|
data += 3; |
1388 |
) |
) |
1389 |
#endif |
#endif |
1390 |
/* *INDENT-ON* */ |
/* *INDENT-ON* */ |
1422 |
uint8 *out; |
uint8 *out; |
1423 |
uint8 *end; |
uint8 *end; |
1424 |
|
|
1425 |
/* if server and xserver bpp match, */ |
/* |
1426 |
/* and arch(endian) matches, no need to translate */ |
If RDP depth and X Visual depths match, |
1427 |
/* just return data */ |
and arch(endian) matches, no need to translate: |
1428 |
if (g_arch_match) |
just return data. |
1429 |
|
Note: select_visual should've already ensured g_no_translate |
1430 |
|
is only set for compatible depths, but the RDP depth might've |
1431 |
|
changed during connection negotiations. |
1432 |
|
*/ |
1433 |
|
|
1434 |
|
/* todo */ |
1435 |
|
if (g_server_depth == 32 && g_depth == 24) |
1436 |
{ |
{ |
1437 |
if (g_depth == 15 && g_server_bpp == 15) |
return data; |
1438 |
return data; |
} |
1439 |
if (g_depth == 16 && g_server_bpp == 16) |
|
1440 |
return data; |
if (g_no_translate_image) |
1441 |
if (g_depth == 24 && g_bpp == 24 && g_server_bpp == 24) |
{ |
1442 |
|
if ((g_depth == 15 && g_server_depth == 15) || |
1443 |
|
(g_depth == 16 && g_server_depth == 16) || |
1444 |
|
(g_depth == 24 && g_server_depth == 24)) |
1445 |
return data; |
return data; |
1446 |
} |
} |
1447 |
|
|
1449 |
out = (uint8 *) xmalloc(size); |
out = (uint8 *) xmalloc(size); |
1450 |
end = out + size; |
end = out + size; |
1451 |
|
|
1452 |
switch (g_server_bpp) |
switch (g_server_depth) |
1453 |
{ |
{ |
1454 |
case 24: |
case 24: |
1455 |
switch (g_bpp) |
switch (g_bpp) |
1514 |
return out; |
return out; |
1515 |
} |
} |
1516 |
|
|
1517 |
BOOL |
static void |
1518 |
|
xwin_refresh_pointer_map(void) |
1519 |
|
{ |
1520 |
|
unsigned char phys_to_log_map[sizeof(g_pointer_log_to_phys_map)]; |
1521 |
|
int i, pointer_buttons; |
1522 |
|
|
1523 |
|
pointer_buttons = XGetPointerMapping(g_display, phys_to_log_map, sizeof(phys_to_log_map)); |
1524 |
|
for (i = 0; i < pointer_buttons; ++i) |
1525 |
|
{ |
1526 |
|
/* This might produce multiple logical buttons mapping |
1527 |
|
to a single physical one, but hey, that's |
1528 |
|
life... */ |
1529 |
|
g_pointer_log_to_phys_map[phys_to_log_map[i] - 1] = i + 1; |
1530 |
|
} |
1531 |
|
} |
1532 |
|
|
1533 |
|
RD_BOOL |
1534 |
get_key_state(unsigned int state, uint32 keysym) |
get_key_state(unsigned int state, uint32 keysym) |
1535 |
{ |
{ |
1536 |
int modifierpos, key, keysymMask = 0; |
int modifierpos, key, keysymMask = 0; |
1563 |
*shift_r = 8 - ffs(mask & ~(mask >> 1)); |
*shift_r = 8 - ffs(mask & ~(mask >> 1)); |
1564 |
} |
} |
1565 |
|
|
1566 |
BOOL |
/* Given a mask of a colour channel (e.g. XVisualInfo.red_mask), |
1567 |
ui_init(void) |
calculates the bits-per-pixel of this channel (a.k.a. colour weight). |
1568 |
|
*/ |
1569 |
|
static unsigned |
1570 |
|
calculate_mask_weight(uint32 mask) |
1571 |
|
{ |
1572 |
|
unsigned weight = 0; |
1573 |
|
do |
1574 |
|
{ |
1575 |
|
weight += (mask & 1); |
1576 |
|
} |
1577 |
|
while (mask >>= 1); |
1578 |
|
return weight; |
1579 |
|
} |
1580 |
|
|
1581 |
|
static RD_BOOL |
1582 |
|
select_visual(int screen_num) |
1583 |
{ |
{ |
|
XVisualInfo vi; |
|
1584 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
1585 |
uint16 test; |
int pixmap_formats_count, visuals_count; |
|
int i, screen_num, nvisuals; |
|
1586 |
XVisualInfo *vmatches = NULL; |
XVisualInfo *vmatches = NULL; |
1587 |
XVisualInfo template; |
XVisualInfo template; |
1588 |
Bool TrueColorVisual = False; |
int i; |
1589 |
|
unsigned red_weight, blue_weight, green_weight; |
1590 |
|
|
1591 |
g_display = XOpenDisplay(NULL); |
red_weight = blue_weight = green_weight = 0; |
1592 |
if (g_display == NULL) |
|
1593 |
|
if (g_server_depth == -1) |
1594 |
{ |
{ |
1595 |
error("Failed to open display: %s\n", XDisplayName(NULL)); |
g_server_depth = DisplayPlanes(g_display, DefaultScreen(g_display)); |
|
return False; |
|
1596 |
} |
} |
1597 |
|
|
1598 |
screen_num = DefaultScreen(g_display); |
pfm = XListPixmapFormats(g_display, &pixmap_formats_count); |
1599 |
g_x_socket = ConnectionNumber(g_display); |
if (pfm == NULL) |
1600 |
g_screen = ScreenOfDisplay(g_display, screen_num); |
{ |
1601 |
g_depth = DefaultDepthOfScreen(g_screen); |
error("Unable to get list of pixmap formats from display.\n"); |
1602 |
|
XCloseDisplay(g_display); |
1603 |
|
return False; |
1604 |
|
} |
1605 |
|
|
1606 |
/* Search for best TrueColor depth */ |
/* Search for best TrueColor visual */ |
1607 |
template.class = TrueColor; |
template.class = TrueColor; |
1608 |
vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals); |
template.screen = screen_num; |
1609 |
|
vmatches = |
1610 |
|
XGetVisualInfo(g_display, VisualClassMask | VisualScreenMask, &template, |
1611 |
|
&visuals_count); |
1612 |
|
g_visual = NULL; |
1613 |
|
g_no_translate_image = False; |
1614 |
|
g_compatible_arch = False; |
1615 |
|
if (vmatches != NULL) |
1616 |
|
{ |
1617 |
|
for (i = 0; i < visuals_count; ++i) |
1618 |
|
{ |
1619 |
|
XVisualInfo *visual_info = &vmatches[i]; |
1620 |
|
RD_BOOL can_translate_to_bpp = False; |
1621 |
|
int j; |
1622 |
|
|
1623 |
|
/* Try to find a no-translation visual that'll |
1624 |
|
allow us to use RDP bitmaps directly as ZPixmaps. */ |
1625 |
|
if (!g_xserver_be && (((visual_info->depth == 15) && |
1626 |
|
/* R5G5B5 */ |
1627 |
|
(visual_info->red_mask == 0x7c00) && |
1628 |
|
(visual_info->green_mask == 0x3e0) && |
1629 |
|
(visual_info->blue_mask == 0x1f)) || |
1630 |
|
((visual_info->depth == 16) && |
1631 |
|
/* R5G6B5 */ |
1632 |
|
(visual_info->red_mask == 0xf800) && |
1633 |
|
(visual_info->green_mask == 0x7e0) && |
1634 |
|
(visual_info->blue_mask == 0x1f)) || |
1635 |
|
((visual_info->depth == 24) && |
1636 |
|
/* R8G8B8 */ |
1637 |
|
(visual_info->red_mask == 0xff0000) && |
1638 |
|
(visual_info->green_mask == 0xff00) && |
1639 |
|
(visual_info->blue_mask == 0xff)))) |
1640 |
|
{ |
1641 |
|
g_visual = visual_info->visual; |
1642 |
|
g_depth = visual_info->depth; |
1643 |
|
g_compatible_arch = !g_host_be; |
1644 |
|
g_no_translate_image = (visual_info->depth == g_server_depth); |
1645 |
|
if (g_no_translate_image) |
1646 |
|
/* We found the best visual */ |
1647 |
|
break; |
1648 |
|
} |
1649 |
|
else |
1650 |
|
{ |
1651 |
|
g_compatible_arch = False; |
1652 |
|
} |
1653 |
|
|
1654 |
nvisuals--; |
if (visual_info->depth > 24) |
1655 |
while (nvisuals >= 0) |
{ |
1656 |
{ |
/* Avoid 32-bit visuals and likes like the plague. |
1657 |
if ((vmatches + nvisuals)->depth > g_depth) |
They're either untested or proven to work bad |
1658 |
{ |
(e.g. nvidia's Composite 32-bit visual). |
1659 |
g_depth = (vmatches + nvisuals)->depth; |
Most implementation offer a 24-bit visual anyway. */ |
1660 |
|
continue; |
1661 |
|
} |
1662 |
|
|
1663 |
|
/* Only care for visuals, for whose BPPs (not depths!) |
1664 |
|
we have a translateXtoY function. */ |
1665 |
|
for (j = 0; j < pixmap_formats_count; ++j) |
1666 |
|
{ |
1667 |
|
if (pfm[j].depth == visual_info->depth) |
1668 |
|
{ |
1669 |
|
if ((pfm[j].bits_per_pixel == 16) || |
1670 |
|
(pfm[j].bits_per_pixel == 24) || |
1671 |
|
(pfm[j].bits_per_pixel == 32)) |
1672 |
|
{ |
1673 |
|
can_translate_to_bpp = True; |
1674 |
|
} |
1675 |
|
break; |
1676 |
|
} |
1677 |
|
} |
1678 |
|
|
1679 |
|
/* Prefer formats which have the most colour depth. |
1680 |
|
We're being truly aristocratic here, minding each |
1681 |
|
weight on its own. */ |
1682 |
|
if (can_translate_to_bpp) |
1683 |
|
{ |
1684 |
|
unsigned vis_red_weight = |
1685 |
|
calculate_mask_weight(visual_info->red_mask); |
1686 |
|
unsigned vis_green_weight = |
1687 |
|
calculate_mask_weight(visual_info->green_mask); |
1688 |
|
unsigned vis_blue_weight = |
1689 |
|
calculate_mask_weight(visual_info->blue_mask); |
1690 |
|
if ((vis_red_weight >= red_weight) |
1691 |
|
&& (vis_green_weight >= green_weight) |
1692 |
|
&& (vis_blue_weight >= blue_weight)) |
1693 |
|
{ |
1694 |
|
red_weight = vis_red_weight; |
1695 |
|
green_weight = vis_green_weight; |
1696 |
|
blue_weight = vis_blue_weight; |
1697 |
|
g_visual = visual_info->visual; |
1698 |
|
g_depth = visual_info->depth; |
1699 |
|
} |
1700 |
|
} |
1701 |
} |
} |
1702 |
nvisuals--; |
XFree(vmatches); |
|
TrueColorVisual = True; |
|
1703 |
} |
} |
1704 |
|
|
1705 |
test = 1; |
if (g_visual != NULL) |
|
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
|
|
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
|
|
|
|
|
if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8))) |
|
1706 |
{ |
{ |
1707 |
/* we use a colourmap, so the default visual should do */ |
g_owncolmap = False; |
1708 |
g_visual = DefaultVisualOfScreen(g_screen); |
calculate_shifts(g_visual->red_mask, &g_red_shift_r, &g_red_shift_l); |
1709 |
g_depth = DefaultDepthOfScreen(g_screen); |
calculate_shifts(g_visual->green_mask, &g_green_shift_r, &g_green_shift_l); |
1710 |
|
calculate_shifts(g_visual->blue_mask, &g_blue_shift_r, &g_blue_shift_l); |
|
/* Do not allocate colours on a TrueColor visual */ |
|
|
if (g_visual->class == TrueColor) |
|
|
{ |
|
|
g_owncolmap = False; |
|
|
} |
|
1711 |
} |
} |
1712 |
else |
else |
1713 |
{ |
{ |
1714 |
/* need a truecolour visual */ |
template.class = PseudoColor; |
1715 |
if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi)) |
template.depth = 8; |
1716 |
{ |
template.colormap_size = 256; |
1717 |
error("The display does not support true colour - high colour support unavailable.\n"); |
vmatches = |
1718 |
|
XGetVisualInfo(g_display, |
1719 |
|
VisualClassMask | VisualDepthMask | VisualColormapSizeMask, |
1720 |
|
&template, &visuals_count); |
1721 |
|
if (vmatches == NULL) |
1722 |
|
{ |
1723 |
|
error("No usable TrueColor or PseudoColor visuals on this display.\n"); |
1724 |
|
XCloseDisplay(g_display); |
1725 |
|
XFree(pfm); |
1726 |
return False; |
return False; |
1727 |
} |
} |
1728 |
|
|
1729 |
g_visual = vi.visual; |
/* we use a colourmap, so the default visual should do */ |
1730 |
g_owncolmap = False; |
g_owncolmap = True; |
1731 |
calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l); |
g_visual = vmatches[0].visual; |
1732 |
calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l); |
g_depth = vmatches[0].depth; |
1733 |
calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l); |
} |
1734 |
|
|
1735 |
/* if RGB video and everything is little endian */ |
g_bpp = 0; |
1736 |
if ((vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) && |
for (i = 0; i < pixmap_formats_count; ++i) |
1737 |
!g_xserver_be && !g_host_be) |
{ |
1738 |
|
XPixmapFormatValues *pf = &pfm[i]; |
1739 |
|
if (pf->depth == g_depth) |
1740 |
{ |
{ |
1741 |
if (g_depth <= 16 || (g_red_shift_l == 16 && g_green_shift_l == 8 && |
g_bpp = pf->bits_per_pixel; |
1742 |
g_blue_shift_l == 0)) |
|
1743 |
|
if (g_no_translate_image) |
1744 |
{ |
{ |
1745 |
g_arch_match = True; |
switch (g_server_depth) |
1746 |
|
{ |
1747 |
|
case 15: |
1748 |
|
case 16: |
1749 |
|
if (g_bpp != 16) |
1750 |
|
g_no_translate_image = False; |
1751 |
|
break; |
1752 |
|
case 24: |
1753 |
|
/* Yes, this will force image translation |
1754 |
|
on most modern servers which use 32 bits |
1755 |
|
for R8G8B8. */ |
1756 |
|
if (g_bpp != 24) |
1757 |
|
g_no_translate_image = False; |
1758 |
|
break; |
1759 |
|
default: |
1760 |
|
g_no_translate_image = False; |
1761 |
|
break; |
1762 |
|
} |
1763 |
} |
} |
|
} |
|
1764 |
|
|
1765 |
if (g_arch_match) |
/* Pixmap formats list is a depth-to-bpp mapping -- |
1766 |
{ |
there's just a single entry for every depth, |
1767 |
DEBUG(("Architectures match, enabling little endian optimisations.\n")); |
so we can safely break here */ |
1768 |
|
break; |
1769 |
} |
} |
1770 |
} |
} |
1771 |
|
XFree(pfm); |
1772 |
|
pfm = NULL; |
1773 |
|
return True; |
1774 |
|
} |
1775 |
|
|
1776 |
|
static XErrorHandler g_old_error_handler; |
1777 |
|
static RD_BOOL g_error_expected = False; |
1778 |
|
|
1779 |
|
/* Check if the X11 window corresponding to a seamless window with |
1780 |
|
specified id exists. */ |
1781 |
|
RD_BOOL |
1782 |
|
sw_window_exists(unsigned long id) |
1783 |
|
{ |
1784 |
|
seamless_window *sw; |
1785 |
|
char *name; |
1786 |
|
Status sts = 0; |
1787 |
|
|
1788 |
pfm = XListPixmapFormats(g_display, &i); |
sw = sw_get_window_by_id(id); |
1789 |
if (pfm != NULL) |
if (!sw) |
1790 |
|
return False; |
1791 |
|
|
1792 |
|
g_error_expected = True; |
1793 |
|
sts = XFetchName(g_display, sw->wnd, &name); |
1794 |
|
g_error_expected = False; |
1795 |
|
if (sts) |
1796 |
{ |
{ |
1797 |
/* Use maximum bpp for this depth - this is generally |
XFree(name); |
1798 |
desirable, e.g. 24 bits->32 bits. */ |
} |
1799 |
while (i--) |
|
1800 |
{ |
return sts; |
1801 |
if ((pfm[i].depth == g_depth) && (pfm[i].bits_per_pixel > g_bpp)) |
} |
1802 |
{ |
|
1803 |
g_bpp = pfm[i].bits_per_pixel; |
static int |
1804 |
} |
error_handler(Display * dpy, XErrorEvent * eev) |
1805 |
} |
{ |
1806 |
XFree(pfm); |
if (g_error_expected) |
1807 |
|
return 0; |
1808 |
|
|
1809 |
|
return g_old_error_handler(dpy, eev); |
1810 |
|
} |
1811 |
|
|
1812 |
|
RD_BOOL |
1813 |
|
ui_init(void) |
1814 |
|
{ |
1815 |
|
int screen_num; |
1816 |
|
|
1817 |
|
g_display = XOpenDisplay(NULL); |
1818 |
|
if (g_display == NULL) |
1819 |
|
{ |
1820 |
|
error("Failed to open display: %s\n", XDisplayName(NULL)); |
1821 |
|
return False; |
1822 |
} |
} |
1823 |
|
|
|
if (g_bpp < 8) |
|
1824 |
{ |
{ |
1825 |
error("Less than 8 bpp not currently supported.\n"); |
uint16 endianess_test = 1; |
1826 |
XCloseDisplay(g_display); |
g_host_be = !(RD_BOOL) (*(uint8 *) (&endianess_test)); |
1827 |
|
} |
1828 |
|
|
1829 |
|
g_old_error_handler = XSetErrorHandler(error_handler); |
1830 |
|
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
1831 |
|
screen_num = DefaultScreen(g_display); |
1832 |
|
g_x_socket = ConnectionNumber(g_display); |
1833 |
|
g_screen = ScreenOfDisplay(g_display, screen_num); |
1834 |
|
g_depth = DefaultDepthOfScreen(g_screen); |
1835 |
|
|
1836 |
|
if (!select_visual(screen_num)) |
1837 |
return False; |
return False; |
1838 |
|
|
1839 |
|
if (g_no_translate_image) |
1840 |
|
{ |
1841 |
|
DEBUG(("Performance optimization possible: avoiding image translation (colour depth conversion).\n")); |
1842 |
|
} |
1843 |
|
|
1844 |
|
if (g_server_depth > g_bpp) |
1845 |
|
{ |
1846 |
|
warning("Remote desktop colour depth %d higher than display colour depth %d.\n", |
1847 |
|
g_server_depth, g_bpp); |
1848 |
} |
} |
1849 |
|
|
1850 |
|
DEBUG(("RDP depth: %d, display depth: %d, display bpp: %d, X server BE: %d, host BE: %d\n", |
1851 |
|
g_server_depth, g_depth, g_bpp, g_xserver_be, g_host_be)); |
1852 |
|
|
1853 |
if (!g_owncolmap) |
if (!g_owncolmap) |
1854 |
{ |
{ |
1855 |
g_xcolmap = |
g_xcolmap = |
1856 |
XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual, |
XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual, |
1857 |
AllocNone); |
AllocNone); |
1858 |
if (g_depth <= 8) |
if (g_depth <= 8) |
1859 |
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
warning("Display colour depth is %d bit: you may want to use -C for a private colourmap.\n", g_depth); |
1860 |
} |
} |
1861 |
|
|
1862 |
if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) |
if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) |
1863 |
{ |
{ |
1864 |
warning("External BackingStore not available, using internal\n"); |
warning("External BackingStore not available. Using internal.\n"); |
1865 |
g_ownbackstore = True; |
g_ownbackstore = True; |
1866 |
} |
} |
1867 |
|
|
1872 |
{ |
{ |
1873 |
g_width = WidthOfScreen(g_screen); |
g_width = WidthOfScreen(g_screen); |
1874 |
g_height = HeightOfScreen(g_screen); |
g_height = HeightOfScreen(g_screen); |
1875 |
|
g_using_full_workarea = True; |
1876 |
} |
} |
1877 |
else if (g_width < 0) |
else if (g_width < 0) |
1878 |
{ |
{ |
1886 |
{ |
{ |
1887 |
/* Fetch geometry from _NET_WORKAREA */ |
/* Fetch geometry from _NET_WORKAREA */ |
1888 |
uint32 x, y, cx, cy; |
uint32 x, y, cx, cy; |
|
g_using_full_workarea = True; |
|
|
|
|
1889 |
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
1890 |
{ |
{ |
1891 |
g_width = cx; |
g_width = cx; |
1892 |
g_height = cy; |
g_height = cy; |
1893 |
|
g_using_full_workarea = True; |
1894 |
} |
} |
1895 |
else |
else |
1896 |
{ |
{ |
1897 |
warning("Failed to get workarea: probably your window manager does not support extended hints\n"); |
warning("Failed to get workarea: probably your window manager does not support extended hints\n"); |
1898 |
g_width = 800; |
g_width = WidthOfScreen(g_screen); |
1899 |
g_height = 600; |
g_height = HeightOfScreen(g_screen); |
1900 |
} |
} |
1901 |
} |
} |
1902 |
|
|
1904 |
g_width = (g_width + 3) & ~3; |
g_width = (g_width + 3) & ~3; |
1905 |
|
|
1906 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
1907 |
|
xwin_refresh_pointer_map(); |
1908 |
|
|
1909 |
xkeymap_init(); |
xkeymap_init(); |
1910 |
|
|
1912 |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
1913 |
|
|
1914 |
xclip_init(); |
xclip_init(); |
1915 |
|
ewmh_init(); |
1916 |
|
if (g_seamless_rdp) |
1917 |
|
{ |
1918 |
|
seamless_restack_test(); |
1919 |
|
seamless_init(); |
1920 |
|
} |
1921 |
|
|
1922 |
DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth)); |
DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_depth, g_bpp, g_depth)); |
1923 |
|
|
1924 |
return True; |
return True; |
1925 |
} |
} |
1927 |
void |
void |
1928 |
ui_deinit(void) |
ui_deinit(void) |
1929 |
{ |
{ |
1930 |
|
while (g_seamless_windows) |
1931 |
|
{ |
1932 |
|
XDestroyWindow(g_display, g_seamless_windows->wnd); |
1933 |
|
sw_remove_window(g_seamless_windows); |
1934 |
|
} |
1935 |
|
|
1936 |
|
xclip_deinit(); |
1937 |
|
|
1938 |
if (g_IM != NULL) |
if (g_IM != NULL) |
1939 |
XCloseIM(g_IM); |
XCloseIM(g_IM); |
1940 |
|
|
1951 |
g_display = NULL; |
g_display = NULL; |
1952 |
} |
} |
1953 |
|
|
1954 |
BOOL |
|
1955 |
|
static void |
1956 |
|
get_window_attribs(XSetWindowAttributes * attribs) |
1957 |
|
{ |
1958 |
|
attribs->background_pixel = BlackPixelOfScreen(g_screen); |
1959 |
|
attribs->background_pixel = WhitePixelOfScreen(g_screen); |
1960 |
|
attribs->border_pixel = WhitePixelOfScreen(g_screen); |
1961 |
|
attribs->backing_store = g_ownbackstore ? NotUseful : Always; |
1962 |
|
attribs->override_redirect = g_fullscreen; |
1963 |
|
attribs->colormap = g_xcolmap; |
1964 |
|
} |
1965 |
|
|
1966 |
|
static void |
1967 |
|
get_input_mask(long *input_mask) |
1968 |
|
{ |
1969 |
|
*input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
1970 |
|
VisibilityChangeMask | FocusChangeMask | StructureNotifyMask; |
1971 |
|
|
1972 |
|
if (g_sendmotion) |
1973 |
|
*input_mask |= PointerMotionMask; |
1974 |
|
if (g_ownbackstore) |
1975 |
|
*input_mask |= ExposureMask; |
1976 |
|
if (g_fullscreen || g_grab_keyboard) |
1977 |
|
*input_mask |= EnterWindowMask; |
1978 |
|
if (g_grab_keyboard) |
1979 |
|
*input_mask |= LeaveWindowMask; |
1980 |
|
} |
1981 |
|
|
1982 |
|
RD_BOOL |
1983 |
ui_create_window(void) |
ui_create_window(void) |
1984 |
{ |
{ |
1985 |
uint8 null_pointer_mask[1] = { 0x80 }; |
uint8 null_pointer_mask[1] = { 0x80 }; |
2001 |
if (g_ypos < 0 || (g_ypos == 0 && (g_pos & 4))) |
if (g_ypos < 0 || (g_ypos == 0 && (g_pos & 4))) |
2002 |
g_ypos = HeightOfScreen(g_screen) + g_ypos - g_height; |
g_ypos = HeightOfScreen(g_screen) + g_ypos - g_height; |
2003 |
|
|
2004 |
attribs.background_pixel = BlackPixelOfScreen(g_screen); |
get_window_attribs(&attribs); |
|
attribs.border_pixel = WhitePixelOfScreen(g_screen); |
|
|
attribs.backing_store = g_ownbackstore ? NotUseful : Always; |
|
|
attribs.override_redirect = g_fullscreen; |
|
|
attribs.colormap = g_xcolmap; |
|
2005 |
|
|
2006 |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), g_xpos, g_ypos, wndwidth, |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), g_xpos, g_ypos, wndwidth, |
2007 |
wndheight, 0, g_depth, InputOutput, g_visual, |
wndheight, 0, g_depth, InputOutput, g_visual, |
2009 |
CWBorderPixel, &attribs); |
CWBorderPixel, &attribs); |
2010 |
|
|
2011 |
if (g_gc == NULL) |
if (g_gc == NULL) |
2012 |
|
{ |
2013 |
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
2014 |
|
ui_reset_clip(); |
2015 |
|
} |
2016 |
|
|
2017 |
if (g_create_bitmap_gc == NULL) |
if (g_create_bitmap_gc == NULL) |
2018 |
g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
2027 |
} |
} |
2028 |
|
|
2029 |
XStoreName(g_display, g_wnd, g_title); |
XStoreName(g_display, g_wnd, g_title); |
2030 |
|
ewmh_set_wm_name(g_wnd, g_title); |
2031 |
|
|
2032 |
if (g_hide_decorations) |
if (g_hide_decorations) |
2033 |
mwm_hide_decorations(); |
mwm_hide_decorations(g_wnd); |
2034 |
|
|
2035 |
classhints = XAllocClassHint(); |
classhints = XAllocClassHint(); |
2036 |
if (classhints != NULL) |
if (classhints != NULL) |
2057 |
XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0); |
XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0); |
2058 |
} |
} |
2059 |
|
|
2060 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
get_input_mask(&input_mask); |
|
VisibilityChangeMask | FocusChangeMask | StructureNotifyMask; |
|
|
|
|
|
if (g_sendmotion) |
|
|
input_mask |= PointerMotionMask; |
|
|
if (g_ownbackstore) |
|
|
input_mask |= ExposureMask; |
|
|
if (g_fullscreen || g_grab_keyboard) |
|
|
input_mask |= EnterWindowMask; |
|
|
if (g_grab_keyboard) |
|
|
input_mask |= LeaveWindowMask; |
|
2061 |
|
|
2062 |
if (g_IM != NULL) |
if (g_IM != NULL) |
2063 |
{ |
{ |
2142 |
{ |
{ |
2143 |
Pixmap contents = 0; |
Pixmap contents = 0; |
2144 |
|
|
2145 |
|
if (g_seamless_active) |
2146 |
|
/* Turn off SeamlessRDP mode */ |
2147 |
|
ui_seamless_toggle(); |
2148 |
|
|
2149 |
if (!g_ownbackstore) |
if (!g_ownbackstore) |
2150 |
{ |
{ |
2151 |
/* need to save contents of window */ |
/* need to save contents of window */ |
2167 |
} |
} |
2168 |
|
|
2169 |
static void |
static void |
2170 |
handle_button_event(XEvent xevent, BOOL down) |
handle_button_event(XEvent xevent, RD_BOOL down) |
2171 |
{ |
{ |
2172 |
uint16 button, flags = 0; |
uint16 button, flags = 0; |
2173 |
g_last_gesturetime = xevent.xbutton.time; |
g_last_gesturetime = xevent.xbutton.time; |
2174 |
|
/* Reverse the pointer button mapping, e.g. in the case of |
2175 |
|
"left-handed mouse mode"; the RDP session expects to |
2176 |
|
receive physical buttons (true in mstsc as well) and |
2177 |
|
logical button behavior depends on the remote desktop's own |
2178 |
|
mouse settings */ |
2179 |
|
xevent.xbutton.button = g_pointer_log_to_phys_map[xevent.xbutton.button - 1]; |
2180 |
button = xkeymap_translate_button(xevent.xbutton.button); |
button = xkeymap_translate_button(xevent.xbutton.button); |
2181 |
if (button == 0) |
if (button == 0) |
2182 |
return; |
return; |
2240 |
} |
} |
2241 |
} |
} |
2242 |
|
|
2243 |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
if (xevent.xmotion.window == g_wnd) |
2244 |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
{ |
2245 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
2246 |
|
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
2247 |
|
} |
2248 |
|
else |
2249 |
|
{ |
2250 |
|
/* SeamlessRDP */ |
2251 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
2252 |
|
flags | button, xevent.xbutton.x_root, xevent.xbutton.y_root); |
2253 |
|
} |
2254 |
} |
} |
2255 |
|
|
2256 |
|
|
2257 |
/* Process events in Xlib queue |
/* Process events in Xlib queue |
2258 |
Returns 0 after user quit, 1 otherwise */ |
Returns 0 after user quit, 1 otherwise */ |
2259 |
static int |
static int |
2265 |
char str[256]; |
char str[256]; |
2266 |
Status status; |
Status status; |
2267 |
int events = 0; |
int events = 0; |
2268 |
|
seamless_window *sw; |
2269 |
|
|
2270 |
while ((XPending(g_display) > 0) && events++ < 20) |
while ((XPending(g_display) > 0) && events++ < 20) |
2271 |
{ |
{ |
2280 |
switch (xevent.type) |
switch (xevent.type) |
2281 |
{ |
{ |
2282 |
case VisibilityNotify: |
case VisibilityNotify: |
2283 |
g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured; |
if (xevent.xvisibility.window == g_wnd) |
2284 |
|
g_Unobscured = |
2285 |
|
xevent.xvisibility.state == VisibilityUnobscured; |
2286 |
|
|
2287 |
break; |
break; |
2288 |
case ClientMessage: |
case ClientMessage: |
2289 |
/* the window manager told us to quit */ |
/* the window manager told us to quit */ |
2290 |
if ((xevent.xclient.message_type == g_protocol_atom) |
if ((xevent.xclient.message_type == g_protocol_atom) |
2291 |
&& ((Atom) xevent.xclient.data.l[0] == g_kill_atom)) |
&& ((Atom) xevent.xclient.data.l[0] == g_kill_atom)) |
2292 |
/* Quit */ |
{ |
2293 |
return 0; |
/* When killing a seamless window, close the window on the |
2294 |
|
serverside instead of terminating rdesktop */ |
2295 |
|
sw = sw_get_window_by_wnd(xevent.xclient.window); |
2296 |
|
if (!sw) |
2297 |
|
/* Otherwise, quit */ |
2298 |
|
return 0; |
2299 |
|
/* send seamless destroy process message */ |
2300 |
|
seamless_send_destroy(sw->id); |
2301 |
|
} |
2302 |
break; |
break; |
2303 |
|
|
2304 |
case KeyPress: |
case KeyPress: |
2371 |
if (g_fullscreen && !g_focused) |
if (g_fullscreen && !g_focused) |
2372 |
XSetInputFocus(g_display, g_wnd, RevertToPointerRoot, |
XSetInputFocus(g_display, g_wnd, RevertToPointerRoot, |
2373 |
CurrentTime); |
CurrentTime); |
2374 |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
|
2375 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
if (xevent.xmotion.window == g_wnd) |
2376 |
|
{ |
2377 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, |
2378 |
|
xevent.xmotion.x, xevent.xmotion.y); |
2379 |
|
} |
2380 |
|
else |
2381 |
|
{ |
2382 |
|
/* SeamlessRDP */ |
2383 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, |
2384 |
|
xevent.xmotion.x_root, |
2385 |
|
xevent.xmotion.y_root); |
2386 |
|
} |
2387 |
break; |
break; |
2388 |
|
|
2389 |
case FocusIn: |
case FocusIn: |
2394 |
if (g_grab_keyboard && g_mouse_in_wnd) |
if (g_grab_keyboard && g_mouse_in_wnd) |
2395 |
XGrabKeyboard(g_display, g_wnd, True, |
XGrabKeyboard(g_display, g_wnd, True, |
2396 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
2397 |
|
|
2398 |
|
sw = sw_get_window_by_wnd(xevent.xfocus.window); |
2399 |
|
if (!sw) |
2400 |
|
break; |
2401 |
|
|
2402 |
|
/* Menu windows are real X11 windows, |
2403 |
|
with focus. When such a window is |
2404 |
|
destroyed, focus is reverted to the |
2405 |
|
main application window, which |
2406 |
|
would cause us to send FOCUS. This |
2407 |
|
breaks window switching in, say, |
2408 |
|
Seamonkey. We shouldn't need to |
2409 |
|
send FOCUS: Windows should also |
2410 |
|
revert focus to some other window |
2411 |
|
when the menu window is |
2412 |
|
destroyed. So, we only send FOCUS |
2413 |
|
if the previous focus window still |
2414 |
|
exists. */ |
2415 |
|
if (sw->id != g_seamless_focused) |
2416 |
|
{ |
2417 |
|
|
2418 |
|
if (sw_window_exists(g_seamless_focused)) |
2419 |
|
seamless_send_focus(sw->id, 0); |
2420 |
|
g_seamless_focused = sw->id; |
2421 |
|
} |
2422 |
break; |
break; |
2423 |
|
|
2424 |
case FocusOut: |
case FocusOut: |
2451 |
break; |
break; |
2452 |
|
|
2453 |
case Expose: |
case Expose: |
2454 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, |
if (xevent.xexpose.window == g_wnd) |
2455 |
xevent.xexpose.x, xevent.xexpose.y, |
{ |
2456 |
xevent.xexpose.width, |
XCopyArea(g_display, g_backstore, xevent.xexpose.window, |
2457 |
xevent.xexpose.height, |
g_gc, |
2458 |
xevent.xexpose.x, xevent.xexpose.y); |
xevent.xexpose.x, xevent.xexpose.y, |
2459 |
|
xevent.xexpose.width, xevent.xexpose.height, |
2460 |
|
xevent.xexpose.x, xevent.xexpose.y); |
2461 |
|
} |
2462 |
|
else |
2463 |
|
{ |
2464 |
|
sw = sw_get_window_by_wnd(xevent.xexpose.window); |
2465 |
|
if (!sw) |
2466 |
|
break; |
2467 |
|
XCopyArea(g_display, g_backstore, |
2468 |
|
xevent.xexpose.window, g_gc, |
2469 |
|
xevent.xexpose.x + sw->xoffset, |
2470 |
|
xevent.xexpose.y + sw->yoffset, |
2471 |
|
xevent.xexpose.width, |
2472 |
|
xevent.xexpose.height, xevent.xexpose.x, |
2473 |
|
xevent.xexpose.y); |
2474 |
|
} |
2475 |
|
|
2476 |
break; |
break; |
2477 |
|
|
2478 |
case MappingNotify: |
case MappingNotify: |
2487 |
XFreeModifiermap(g_mod_map); |
XFreeModifiermap(g_mod_map); |
2488 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
2489 |
} |
} |
2490 |
|
|
2491 |
|
if (xevent.xmapping.request == MappingPointer) |
2492 |
|
{ |
2493 |
|
xwin_refresh_pointer_map(); |
2494 |
|
} |
2495 |
|
|
2496 |
break; |
break; |
2497 |
|
|
2498 |
/* clipboard stuff */ |
/* clipboard stuff */ |
2507 |
break; |
break; |
2508 |
case PropertyNotify: |
case PropertyNotify: |
2509 |
xclip_handle_PropertyNotify(&xevent.xproperty); |
xclip_handle_PropertyNotify(&xevent.xproperty); |
2510 |
|
if (xevent.xproperty.window == g_wnd) |
2511 |
|
break; |
2512 |
|
if (xevent.xproperty.window == DefaultRootWindow(g_display)) |
2513 |
|
break; |
2514 |
|
|
2515 |
|
/* seamless */ |
2516 |
|
sw = sw_get_window_by_wnd(xevent.xproperty.window); |
2517 |
|
if (!sw) |
2518 |
|
break; |
2519 |
|
|
2520 |
|
if ((xevent.xproperty.atom == g_net_wm_state_atom) |
2521 |
|
&& (xevent.xproperty.state == PropertyNewValue)) |
2522 |
|
{ |
2523 |
|
sw->state = ewmh_get_window_state(sw->wnd); |
2524 |
|
seamless_send_state(sw->id, sw->state, 0); |
2525 |
|
} |
2526 |
|
|
2527 |
|
if ((xevent.xproperty.atom == g_net_wm_desktop_atom) |
2528 |
|
&& (xevent.xproperty.state == PropertyNewValue)) |
2529 |
|
{ |
2530 |
|
sw->desktop = ewmh_get_window_desktop(sw->wnd); |
2531 |
|
sw_all_to_desktop(sw->wnd, sw->desktop); |
2532 |
|
} |
2533 |
|
|
2534 |
break; |
break; |
2535 |
case MapNotify: |
case MapNotify: |
2536 |
rdp_send_client_window_status(1); |
if (!g_seamless_active) |
2537 |
|
rdp_send_client_window_status(1); |
2538 |
break; |
break; |
2539 |
case UnmapNotify: |
case UnmapNotify: |
2540 |
rdp_send_client_window_status(0); |
if (!g_seamless_active) |
2541 |
|
rdp_send_client_window_status(0); |
2542 |
|
break; |
2543 |
|
case ConfigureNotify: |
2544 |
|
if (!g_seamless_active) |
2545 |
|
break; |
2546 |
|
|
2547 |
|
sw = sw_get_window_by_wnd(xevent.xconfigure.window); |
2548 |
|
if (!sw) |
2549 |
|
break; |
2550 |
|
|
2551 |
|
gettimeofday(sw->position_timer, NULL); |
2552 |
|
if (sw->position_timer->tv_usec + SEAMLESSRDP_POSITION_TIMER >= |
2553 |
|
1000000) |
2554 |
|
{ |
2555 |
|
sw->position_timer->tv_usec += |
2556 |
|
SEAMLESSRDP_POSITION_TIMER - 1000000; |
2557 |
|
sw->position_timer->tv_sec += 1; |
2558 |
|
} |
2559 |
|
else |
2560 |
|
{ |
2561 |
|
sw->position_timer->tv_usec += SEAMLESSRDP_POSITION_TIMER; |
2562 |
|
} |
2563 |
|
|
2564 |
|
sw_handle_restack(sw); |
2565 |
break; |
break; |
2566 |
} |
} |
2567 |
} |
} |
2576 |
int n; |
int n; |
2577 |
fd_set rfds, wfds; |
fd_set rfds, wfds; |
2578 |
struct timeval tv; |
struct timeval tv; |
2579 |
BOOL s_timeout = False; |
RD_BOOL s_timeout = False; |
2580 |
|
|
2581 |
while (True) |
while (True) |
2582 |
{ |
{ |
2586 |
/* User quit */ |
/* User quit */ |
2587 |
return 0; |
return 0; |
2588 |
|
|
2589 |
|
if (g_seamless_active) |
2590 |
|
sw_check_timers(); |
2591 |
|
|
2592 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
2593 |
FD_ZERO(&wfds); |
FD_ZERO(&wfds); |
2594 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
2595 |
FD_SET(g_x_socket, &rfds); |
FD_SET(g_x_socket, &rfds); |
2596 |
|
|
|
#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 |
|
2597 |
/* default timeout */ |
/* default timeout */ |
2598 |
tv.tv_sec = 60; |
tv.tv_sec = 60; |
2599 |
tv.tv_usec = 0; |
tv.tv_usec = 0; |
2600 |
|
|
2601 |
|
#ifdef WITH_RDPSND |
2602 |
|
rdpsnd_add_fds(&n, &rfds, &wfds, &tv); |
2603 |
|
#endif |
2604 |
|
|
2605 |
/* add redirection handles */ |
/* add redirection handles */ |
2606 |
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
2607 |
|
seamless_select_timeout(&tv); |
2608 |
|
|
2609 |
n++; |
n++; |
2610 |
|
|
2614 |
error("select: %s\n", strerror(errno)); |
error("select: %s\n", strerror(errno)); |
2615 |
|
|
2616 |
case 0: |
case 0: |
2617 |
|
#ifdef WITH_RDPSND |
2618 |
|
rdpsnd_check_fds(&rfds, &wfds); |
2619 |
|
#endif |
2620 |
|
|
2621 |
/* Abort serial read calls */ |
/* Abort serial read calls */ |
2622 |
if (s_timeout) |
if (s_timeout) |
2623 |
rdpdr_check_fds(&rfds, &wfds, (BOOL) True); |
rdpdr_check_fds(&rfds, &wfds, (RD_BOOL) True); |
2624 |
continue; |
continue; |
2625 |
} |
} |
2626 |
|
|
2627 |
rdpdr_check_fds(&rfds, &wfds, (BOOL) False); |
#ifdef WITH_RDPSND |
2628 |
|
rdpsnd_check_fds(&rfds, &wfds); |
2629 |
|
#endif |
2630 |
|
|
2631 |
|
rdpdr_check_fds(&rfds, &wfds, (RD_BOOL) False); |
2632 |
|
|
2633 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
2634 |
return 1; |
return 1; |
2635 |
|
|
|
#ifdef WITH_RDPSND |
|
|
if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds)) |
|
|
wave_out_play(); |
|
|
#endif |
|
2636 |
} |
} |
2637 |
} |
} |
2638 |
|
|
2642 |
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); |
2643 |
} |
} |
2644 |
|
|
2645 |
HBITMAP |
RD_HBITMAP |
2646 |
ui_create_bitmap(int width, int height, uint8 * data) |
ui_create_bitmap(int width, int height, uint8 * data) |
2647 |
{ |
{ |
2648 |
XImage *image; |
XImage *image; |
2650 |
uint8 *tdata; |
uint8 *tdata; |
2651 |
int bitmap_pad; |
int bitmap_pad; |
2652 |
|
|
2653 |
if (g_server_bpp == 8) |
if (g_server_depth == 8) |
2654 |
{ |
{ |
2655 |
bitmap_pad = 8; |
bitmap_pad = 8; |
2656 |
} |
} |
2672 |
XFree(image); |
XFree(image); |
2673 |
if (tdata != data) |
if (tdata != data) |
2674 |
xfree(tdata); |
xfree(tdata); |
2675 |
return (HBITMAP) bitmap; |
return (RD_HBITMAP) bitmap; |
2676 |
} |
} |
2677 |
|
|
2678 |
void |
void |
2682 |
uint8 *tdata; |
uint8 *tdata; |
2683 |
int bitmap_pad; |
int bitmap_pad; |
2684 |
|
|
2685 |
if (g_server_bpp == 8) |
if (g_server_depth == 8) |
2686 |
{ |
{ |
2687 |
bitmap_pad = 8; |
bitmap_pad = 8; |
2688 |
} |
} |
2702 |
{ |
{ |
2703 |
XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy); |
XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy); |
2704 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); |
2705 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
2706 |
|
(g_display, g_backstore, sw->wnd, g_gc, x, y, cx, cy, |
2707 |
|
x - sw->xoffset, y - sw->yoffset)); |
2708 |
} |
} |
2709 |
else |
else |
2710 |
{ |
{ |
2711 |
XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy); |
XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy); |
2712 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
2713 |
|
(g_display, g_wnd, sw->wnd, g_gc, x, y, cx, cy, |
2714 |
|
x - sw->xoffset, y - sw->yoffset)); |
2715 |
} |
} |
2716 |
|
|
2717 |
XFree(image); |
XFree(image); |
2720 |
} |
} |
2721 |
|
|
2722 |
void |
void |
2723 |
ui_destroy_bitmap(HBITMAP bmp) |
ui_destroy_bitmap(RD_HBITMAP bmp) |
2724 |
{ |
{ |
2725 |
XFreePixmap(g_display, (Pixmap) bmp); |
XFreePixmap(g_display, (Pixmap) bmp); |
2726 |
} |
} |
2727 |
|
|
2728 |
HGLYPH |
RD_HGLYPH |
2729 |
ui_create_glyph(int width, int height, uint8 * data) |
ui_create_glyph(int width, int height, uint8 * data) |
2730 |
{ |
{ |
2731 |
XImage *image; |
XImage *image; |
2747 |
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); |
2748 |
|
|
2749 |
XFree(image); |
XFree(image); |
2750 |
return (HGLYPH) bitmap; |
return (RD_HGLYPH) bitmap; |
2751 |
} |
} |
2752 |
|
|
2753 |
void |
void |
2754 |
ui_destroy_glyph(HGLYPH glyph) |
ui_destroy_glyph(RD_HGLYPH glyph) |
2755 |
{ |
{ |
2756 |
XFreePixmap(g_display, (Pixmap) glyph); |
XFreePixmap(g_display, (Pixmap) glyph); |
2757 |
} |
} |
2758 |
|
|
2759 |
HCURSOR |
RD_HCURSOR |
2760 |
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, |
2761 |
uint8 * andmask, uint8 * xormask) |
uint8 * andmask, uint8 * xormask) |
2762 |
{ |
{ |
2763 |
HGLYPH maskglyph, cursorglyph; |
RD_HGLYPH maskglyph, cursorglyph; |
2764 |
XColor bg, fg; |
XColor bg, fg; |
2765 |
Cursor xcursor; |
Cursor xcursor; |
2766 |
uint8 *cursor, *pcursor; |
uint8 *cursor, *pcursor; |
2824 |
ui_destroy_glyph(cursorglyph); |
ui_destroy_glyph(cursorglyph); |
2825 |
xfree(mask); |
xfree(mask); |
2826 |
xfree(cursor); |
xfree(cursor); |
2827 |
return (HCURSOR) xcursor; |
return (RD_HCURSOR) xcursor; |
2828 |
} |
} |
2829 |
|
|
2830 |
void |
void |
2831 |
ui_set_cursor(HCURSOR cursor) |
ui_set_cursor(RD_HCURSOR cursor) |
2832 |
{ |
{ |
2833 |
g_current_cursor = (Cursor) cursor; |
g_current_cursor = (Cursor) cursor; |
2834 |
XDefineCursor(g_display, g_wnd, g_current_cursor); |
XDefineCursor(g_display, g_wnd, g_current_cursor); |
2835 |
|
ON_ALL_SEAMLESS_WINDOWS(XDefineCursor, (g_display, sw->wnd, g_current_cursor)); |
2836 |
} |
} |
2837 |
|
|
2838 |
void |
void |
2839 |
ui_destroy_cursor(HCURSOR cursor) |
ui_destroy_cursor(RD_HCURSOR cursor) |
2840 |
{ |
{ |
2841 |
XFreeCursor(g_display, (Cursor) cursor); |
XFreeCursor(g_display, (Cursor) cursor); |
2842 |
} |
} |
2854 |
(xc)->flags = DoRed | DoGreen | DoBlue; |
(xc)->flags = DoRed | DoGreen | DoBlue; |
2855 |
|
|
2856 |
|
|
2857 |
HCOLOURMAP |
RD_HCOLOURMAP |
2858 |
ui_create_colourmap(COLOURMAP * colours) |
ui_create_colourmap(COLOURMAP * colours) |
2859 |
{ |
{ |
2860 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
2950 |
XStoreColors(g_display, map, xcolours, ncolours); |
XStoreColors(g_display, map, xcolours, ncolours); |
2951 |
|
|
2952 |
xfree(xcolours); |
xfree(xcolours); |
2953 |
return (HCOLOURMAP) map; |
return (RD_HCOLOURMAP) map; |
2954 |
} |
} |
2955 |
} |
} |
2956 |
|
|
2957 |
void |
void |
2958 |
ui_destroy_colourmap(HCOLOURMAP map) |
ui_destroy_colourmap(RD_HCOLOURMAP map) |
2959 |
{ |
{ |
2960 |
if (!g_owncolmap) |
if (!g_owncolmap) |
2961 |
xfree(map); |
xfree(map); |
2964 |
} |
} |
2965 |
|
|
2966 |
void |
void |
2967 |
ui_set_colourmap(HCOLOURMAP map) |
ui_set_colourmap(RD_HCOLOURMAP map) |
2968 |
{ |
{ |
2969 |
if (!g_owncolmap) |
if (!g_owncolmap) |
2970 |
{ |
{ |
2974 |
g_colmap = (uint32 *) map; |
g_colmap = (uint32 *) map; |
2975 |
} |
} |
2976 |
else |
else |
2977 |
|
{ |
2978 |
XSetWindowColormap(g_display, g_wnd, (Colormap) map); |
XSetWindowColormap(g_display, g_wnd, (Colormap) map); |
2979 |
|
ON_ALL_SEAMLESS_WINDOWS(XSetWindowColormap, (g_display, sw->wnd, (Colormap) map)); |
2980 |
|
} |
2981 |
} |
} |
2982 |
|
|
2983 |
void |
void |
2984 |
ui_set_clip(int x, int y, int cx, int cy) |
ui_set_clip(int x, int y, int cx, int cy) |
2985 |
{ |
{ |
2986 |
XRectangle rect; |
g_clip_rectangle.x = x; |
2987 |
|
g_clip_rectangle.y = y; |
2988 |
rect.x = x; |
g_clip_rectangle.width = cx; |
2989 |
rect.y = y; |
g_clip_rectangle.height = cy; |
2990 |
rect.width = cx; |
XSetClipRectangles(g_display, g_gc, 0, 0, &g_clip_rectangle, 1, YXBanded); |
|
rect.height = cy; |
|
|
XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded); |
|
2991 |
} |
} |
2992 |
|
|
2993 |
void |
void |
2994 |
ui_reset_clip(void) |
ui_reset_clip(void) |
2995 |
{ |
{ |
2996 |
XRectangle rect; |
g_clip_rectangle.x = 0; |
2997 |
|
g_clip_rectangle.y = 0; |
2998 |
rect.x = 0; |
g_clip_rectangle.width = g_width; |
2999 |
rect.y = 0; |
g_clip_rectangle.height = g_height; |
3000 |
rect.width = g_width; |
XSetClipRectangles(g_display, g_gc, 0, 0, &g_clip_rectangle, 1, YXBanded); |
|
rect.height = g_height; |
|
|
XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded); |
|
3001 |
} |
} |
3002 |
|
|
3003 |
void |
void |
3052 |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
3053 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3054 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3055 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3056 |
break; |
break; |
3057 |
|
|
3058 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
3067 |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
3068 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3069 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3070 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3071 |
break; |
break; |
3072 |
|
|
3073 |
default: |
default: |
3078 |
|
|
3079 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3080 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); |
3081 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3082 |
|
(g_display, g_ownbackstore ? g_backstore : g_wnd, sw->wnd, g_gc, |
3083 |
|
x, y, cx, cy, x - sw->xoffset, y - sw->yoffset)); |
3084 |
} |
} |
3085 |
|
|
3086 |
void |
void |
3091 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
3092 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3093 |
{ |
{ |
3094 |
if (g_Unobscured) |
XCopyArea(g_display, g_Unobscured ? g_wnd : g_backstore, |
3095 |
{ |
g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
3096 |
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
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); |
|
|
} |
|
|
else |
|
|
{ |
|
|
XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
|
|
XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, |
|
|
y); |
|
|
} |
|
3097 |
} |
} |
3098 |
else |
else |
3099 |
{ |
{ |
3100 |
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
3101 |
} |
} |
3102 |
|
|
3103 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3104 |
|
(g_display, g_ownbackstore ? g_backstore : g_wnd, |
3105 |
|
sw->wnd, g_gc, x, y, cx, cy, x - sw->xoffset, y - sw->yoffset)); |
3106 |
|
|
3107 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
3108 |
} |
} |
3109 |
|
|
3110 |
void |
void |
3111 |
ui_memblt(uint8 opcode, |
ui_memblt(uint8 opcode, |
3112 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
3113 |
/* src */ HBITMAP src, int srcx, int srcy) |
/* src */ RD_HBITMAP src, int srcx, int srcy) |
3114 |
{ |
{ |
3115 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
3116 |
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); |
3117 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3118 |
|
(g_display, (Pixmap) src, sw->wnd, g_gc, |
3119 |
|
srcx, srcy, cx, cy, x - sw->xoffset, y - sw->yoffset)); |
3120 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3121 |
XCopyArea(g_display, (Pixmap) src, g_backstore, g_gc, srcx, srcy, cx, cy, x, y); |
XCopyArea(g_display, (Pixmap) src, g_backstore, g_gc, srcx, srcy, cx, cy, x, y); |
3122 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
3125 |
void |
void |
3126 |
ui_triblt(uint8 opcode, |
ui_triblt(uint8 opcode, |
3127 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
3128 |
/* src */ HBITMAP src, int srcx, int srcy, |
/* src */ RD_HBITMAP src, int srcx, int srcy, |
3129 |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
3130 |
{ |
{ |
3131 |
/* This is potentially difficult to do in general. Until someone |
/* This is potentially difficult to do in general. Until someone |
3163 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
3164 |
SET_FOREGROUND(pen->colour); |
SET_FOREGROUND(pen->colour); |
3165 |
XDrawLine(g_display, g_wnd, g_gc, startx, starty, endx, endy); |
XDrawLine(g_display, g_wnd, g_gc, startx, starty, endx, endy); |
3166 |
|
ON_ALL_SEAMLESS_WINDOWS(XDrawLine, (g_display, sw->wnd, g_gc, |
3167 |
|
startx - sw->xoffset, starty - sw->yoffset, |
3168 |
|
endx - sw->xoffset, endy - sw->yoffset)); |
3169 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3170 |
XDrawLine(g_display, g_backstore, g_gc, startx, starty, endx, endy); |
XDrawLine(g_display, g_backstore, g_gc, startx, starty, endx, endy); |
3171 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
3183 |
void |
void |
3184 |
ui_polygon(uint8 opcode, |
ui_polygon(uint8 opcode, |
3185 |
/* mode */ uint8 fillmode, |
/* mode */ uint8 fillmode, |
3186 |
/* dest */ POINT * point, int npoints, |
/* dest */ RD_POINT * point, int npoints, |
3187 |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
3188 |
{ |
{ |
3189 |
uint8 style, i, ipattern[8]; |
uint8 style, i, ipattern[8]; |
3226 |
FILL_POLYGON((XPoint *) point, npoints); |
FILL_POLYGON((XPoint *) point, npoints); |
3227 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3228 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3229 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3230 |
break; |
break; |
3231 |
|
|
3232 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
3241 |
FILL_POLYGON((XPoint *) point, npoints); |
FILL_POLYGON((XPoint *) point, npoints); |
3242 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3243 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3244 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3245 |
break; |
break; |
3246 |
|
|
3247 |
default: |
default: |
3253 |
|
|
3254 |
void |
void |
3255 |
ui_polyline(uint8 opcode, |
ui_polyline(uint8 opcode, |
3256 |
/* dest */ POINT * points, int npoints, |
/* dest */ RD_POINT * points, int npoints, |
3257 |
/* pen */ PEN * pen) |
/* pen */ PEN * pen) |
3258 |
{ |
{ |
3259 |
/* TODO: set join style */ |
/* TODO: set join style */ |
3263 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3264 |
XDrawLines(g_display, g_backstore, g_gc, (XPoint *) points, npoints, |
XDrawLines(g_display, g_backstore, g_gc, (XPoint *) points, npoints, |
3265 |
CoordModePrevious); |
CoordModePrevious); |
3266 |
|
|
3267 |
|
ON_ALL_SEAMLESS_WINDOWS(seamless_XDrawLines, |
3268 |
|
(sw->wnd, (XPoint *) points, npoints, sw->xoffset, sw->yoffset)); |
3269 |
|
|
3270 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
3271 |
} |
} |
3272 |
|
|
3304 |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
3305 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3306 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3307 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3308 |
break; |
break; |
3309 |
|
|
3310 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
3319 |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
3320 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3321 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3322 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3323 |
break; |
break; |
3324 |
|
|
3325 |
default: |
default: |
3333 |
void |
void |
3334 |
ui_draw_glyph(int mixmode, |
ui_draw_glyph(int mixmode, |
3335 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
3336 |
/* src */ HGLYPH glyph, int srcx, int srcy, |
/* src */ RD_HGLYPH glyph, int srcx, int srcy, |
3337 |
int bgcolour, int fgcolour) |
int bgcolour, int fgcolour) |
3338 |
{ |
{ |
3339 |
SET_FOREGROUND(fgcolour); |
SET_FOREGROUND(fgcolour); |
3422 |
switch (text[i]) |
switch (text[i]) |
3423 |
{ |
{ |
3424 |
case 0xff: |
case 0xff: |
3425 |
|
/* At least two bytes needs to follow */ |
3426 |
if (i + 3 > length) |
if (i + 3 > length) |
3427 |
{ |
{ |
3428 |
/* short command, skip */ |
warning("Skipping short 0xff command:"); |
3429 |
|
for (j = 0; j < length; j++) |
3430 |
|
fprintf(stderr, "%02x ", text[j]); |
3431 |
|
fprintf(stderr, "\n"); |
3432 |
i = length = 0; |
i = length = 0; |
3433 |
break; |
break; |
3434 |
} |
} |
3441 |
break; |
break; |
3442 |
|
|
3443 |
case 0xfe: |
case 0xfe: |
3444 |
if (i + 3 > length) |
/* At least one byte needs to follow */ |
3445 |
|
if (i + 2 > length) |
3446 |
{ |
{ |
3447 |
/* short command, skip */ |
warning("Skipping short 0xfe command:"); |
3448 |
|
for (j = 0; j < length; j++) |
3449 |
|
fprintf(stderr, "%02x ", text[j]); |
3450 |
|
fprintf(stderr, "\n"); |
3451 |
i = length = 0; |
i = length = 0; |
3452 |
break; |
break; |
3453 |
} |
} |
3454 |
entry = cache_get_text(text[i + 1]); |
entry = cache_get_text(text[i + 1]); |
3455 |
if (entry != NULL) |
if (entry->data != NULL) |
3456 |
{ |
{ |
3457 |
if ((((uint8 *) (entry->data))[1] == |
if ((((uint8 *) (entry->data))[1] == 0) |
3458 |
0) && (!(flags & TEXT2_IMPLICIT_X))) |
&& (!(flags & TEXT2_IMPLICIT_X)) && (i + 2 < length)) |
3459 |
{ |
{ |
3460 |
if (flags & TEXT2_VERTICAL) |
if (flags & TEXT2_VERTICAL) |
3461 |
y += text[i + 2]; |
y += text[i + 2]; |
3465 |
for (j = 0; j < entry->size; j++) |
for (j = 0; j < entry->size; j++) |
3466 |
DO_GLYPH(((uint8 *) (entry->data)), j); |
DO_GLYPH(((uint8 *) (entry->data)), j); |
3467 |
} |
} |
3468 |
i += 3; |
if (i + 2 < length) |
3469 |
|
i += 3; |
3470 |
|
else |
3471 |
|
i += 2; |
3472 |
length -= i; |
length -= i; |
3473 |
/* this will move pointer from start to first character after FE command */ |
/* this will move pointer from start to first character after FE command */ |
3474 |
text = &(text[i]); |
text = &(text[i]); |
3487 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3488 |
{ |
{ |
3489 |
if (boxcx > 1) |
if (boxcx > 1) |
3490 |
|
{ |
3491 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, boxx, |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, boxx, |
3492 |
boxy, boxcx, boxcy, boxx, boxy); |
boxy, boxcx, boxcy, boxx, boxy); |
3493 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3494 |
|
(g_display, g_backstore, sw->wnd, g_gc, |
3495 |
|
boxx, boxy, |
3496 |
|
boxcx, boxcy, |
3497 |
|
boxx - sw->xoffset, boxy - sw->yoffset)); |
3498 |
|
} |
3499 |
else |
else |
3500 |
|
{ |
3501 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, clipx, |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, clipx, |
3502 |
clipy, clipcx, clipcy, clipx, clipy); |
clipy, clipcx, clipcy, clipx, clipy); |
3503 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3504 |
|
(g_display, g_backstore, sw->wnd, g_gc, |
3505 |
|
clipx, clipy, |
3506 |
|
clipcx, clipcy, clipx - sw->xoffset, |
3507 |
|
clipy - sw->yoffset)); |
3508 |
|
} |
3509 |
} |
} |
3510 |
} |
} |
3511 |
|
|
3518 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3519 |
{ |
{ |
3520 |
image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap); |
image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap); |
3521 |
|
exit_if_null(image); |
3522 |
} |
} |
3523 |
else |
else |
3524 |
{ |
{ |
3525 |
pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth); |
pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth); |
3526 |
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); |
3527 |
image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap); |
image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap); |
3528 |
|
exit_if_null(image); |
3529 |
XFreePixmap(g_display, pix); |
XFreePixmap(g_display, pix); |
3530 |
} |
} |
3531 |
|
|
3547 |
return; |
return; |
3548 |
|
|
3549 |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
3550 |
(char *) data, cx, cy, BitmapPad(g_display), cx * g_bpp / 8); |
(char *) data, cx, cy, g_bpp, 0); |
3551 |
|
|
3552 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3553 |
{ |
{ |
3554 |
XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy); |
XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy); |
3555 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); |
3556 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3557 |
|
(g_display, g_backstore, sw->wnd, g_gc, |
3558 |
|
x, y, cx, cy, x - sw->xoffset, y - sw->yoffset)); |
3559 |
} |
} |
3560 |
else |
else |
3561 |
{ |
{ |
3562 |
XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy); |
XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy); |
3563 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3564 |
|
(g_display, g_wnd, sw->wnd, g_gc, x, y, cx, cy, |
3565 |
|
x - sw->xoffset, y - sw->yoffset)); |
3566 |
} |
} |
3567 |
|
|
3568 |
XFree(image); |
XFree(image); |
3578 |
ui_end_update(void) |
ui_end_update(void) |
3579 |
{ |
{ |
3580 |
} |
} |
3581 |
|
|
3582 |
|
|
3583 |
|
void |
3584 |
|
ui_seamless_begin(RD_BOOL hidden) |
3585 |
|
{ |
3586 |
|
if (!g_seamless_rdp) |
3587 |
|
return; |
3588 |
|
|
3589 |
|
if (g_seamless_started) |
3590 |
|
return; |
3591 |
|
|
3592 |
|
g_seamless_started = True; |
3593 |
|
g_seamless_hidden = hidden; |
3594 |
|
|
3595 |
|
if (!hidden) |
3596 |
|
ui_seamless_toggle(); |
3597 |
|
} |
3598 |
|
|
3599 |
|
|
3600 |
|
void |
3601 |
|
ui_seamless_hide_desktop() |
3602 |
|
{ |
3603 |
|
if (!g_seamless_rdp) |
3604 |
|
return; |
3605 |
|
|
3606 |
|
if (!g_seamless_started) |
3607 |
|
return; |
3608 |
|
|
3609 |
|
if (g_seamless_active) |
3610 |
|
ui_seamless_toggle(); |
3611 |
|
|
3612 |
|
g_seamless_hidden = True; |
3613 |
|
} |
3614 |
|
|
3615 |
|
|
3616 |
|
void |
3617 |
|
ui_seamless_unhide_desktop() |
3618 |
|
{ |
3619 |
|
if (!g_seamless_rdp) |
3620 |
|
return; |
3621 |
|
|
3622 |
|
if (!g_seamless_started) |
3623 |
|
return; |
3624 |
|
|
3625 |
|
g_seamless_hidden = False; |
3626 |
|
|
3627 |
|
ui_seamless_toggle(); |
3628 |
|
} |
3629 |
|
|
3630 |
|
|
3631 |
|
void |
3632 |
|
ui_seamless_toggle() |
3633 |
|
{ |
3634 |
|
if (!g_seamless_rdp) |
3635 |
|
return; |
3636 |
|
|
3637 |
|
if (!g_seamless_started) |
3638 |
|
return; |
3639 |
|
|
3640 |
|
if (g_seamless_hidden) |
3641 |
|
return; |
3642 |
|
|
3643 |
|
if (g_seamless_active) |
3644 |
|
{ |
3645 |
|
/* Deactivate */ |
3646 |
|
while (g_seamless_windows) |
3647 |
|
{ |
3648 |
|
XDestroyWindow(g_display, g_seamless_windows->wnd); |
3649 |
|
sw_remove_window(g_seamless_windows); |
3650 |
|
} |
3651 |
|
XMapWindow(g_display, g_wnd); |
3652 |
|
} |
3653 |
|
else |
3654 |
|
{ |
3655 |
|
/* Activate */ |
3656 |
|
XUnmapWindow(g_display, g_wnd); |
3657 |
|
seamless_send_sync(); |
3658 |
|
} |
3659 |
|
|
3660 |
|
g_seamless_active = !g_seamless_active; |
3661 |
|
} |
3662 |
|
|
3663 |
|
|
3664 |
|
void |
3665 |
|
ui_seamless_create_window(unsigned long id, unsigned long group, unsigned long parent, |
3666 |
|
unsigned long flags) |
3667 |
|
{ |
3668 |
|
Window wnd; |
3669 |
|
XSetWindowAttributes attribs; |
3670 |
|
XClassHint *classhints; |
3671 |
|
XSizeHints *sizehints; |
3672 |
|
XWMHints *wmhints; |
3673 |
|
long input_mask; |
3674 |
|
seamless_window *sw, *sw_parent; |
3675 |
|
|
3676 |
|
if (!g_seamless_active) |
3677 |
|
return; |
3678 |
|
|
3679 |
|
/* Ignore CREATEs for existing windows */ |
3680 |
|
sw = sw_get_window_by_id(id); |
3681 |
|
if (sw) |
3682 |
|
return; |
3683 |
|
|
3684 |
|
get_window_attribs(&attribs); |
3685 |
|
wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0, g_depth, |
3686 |
|
InputOutput, g_visual, |
3687 |
|
CWBackPixel | CWBackingStore | CWColormap | CWBorderPixel, &attribs); |
3688 |
|
|
3689 |
|
XStoreName(g_display, wnd, "SeamlessRDP"); |
3690 |
|
ewmh_set_wm_name(wnd, "SeamlessRDP"); |
3691 |
|
|
3692 |
|
mwm_hide_decorations(wnd); |
3693 |
|
|
3694 |
|
classhints = XAllocClassHint(); |
3695 |
|
if (classhints != NULL) |
3696 |
|
{ |
3697 |
|
classhints->res_name = "rdesktop"; |
3698 |
|
classhints->res_class = "SeamlessRDP"; |
3699 |
|
XSetClassHint(g_display, wnd, classhints); |
3700 |
|
XFree(classhints); |
3701 |
|
} |
3702 |
|
|
3703 |
|
/* WM_NORMAL_HINTS */ |
3704 |
|
sizehints = XAllocSizeHints(); |
3705 |
|
if (sizehints != NULL) |
3706 |
|
{ |
3707 |
|
sizehints->flags = USPosition; |
3708 |
|
XSetWMNormalHints(g_display, wnd, sizehints); |
3709 |
|
XFree(sizehints); |
3710 |
|
} |
3711 |
|
|
3712 |
|
/* Parent-less transient windows */ |
3713 |
|
if (parent == 0xFFFFFFFF) |
3714 |
|
{ |
3715 |
|
XSetTransientForHint(g_display, wnd, RootWindowOfScreen(g_screen)); |
3716 |
|
/* Some buggy wm:s (kwin) do not handle the above, so fake it |
3717 |
|
using some other hints. */ |
3718 |
|
ewmh_set_window_popup(wnd); |
3719 |
|
} |
3720 |
|
/* Normal transient windows */ |
3721 |
|
else if (parent != 0x00000000) |
3722 |
|
{ |
3723 |
|
sw_parent = sw_get_window_by_id(parent); |
3724 |
|
if (sw_parent) |
3725 |
|
XSetTransientForHint(g_display, wnd, sw_parent->wnd); |
3726 |
|
else |
3727 |
|
warning("ui_seamless_create_window: No parent window 0x%lx\n", parent); |
3728 |
|
} |
3729 |
|
|
3730 |
|
if (flags & SEAMLESSRDP_CREATE_MODAL) |
3731 |
|
{ |
3732 |
|
/* We do this to support buggy wm:s (*cough* metacity *cough*) |
3733 |
|
somewhat at least */ |
3734 |
|
if (parent == 0x00000000) |
3735 |
|
XSetTransientForHint(g_display, wnd, RootWindowOfScreen(g_screen)); |
3736 |
|
ewmh_set_window_modal(wnd); |
3737 |
|
} |
3738 |
|
|
3739 |
|
if (flags & SEAMLESSRDP_CREATE_TOPMOST) |
3740 |
|
{ |
3741 |
|
/* Make window always-on-top */ |
3742 |
|
ewmh_set_window_above(wnd); |
3743 |
|
} |
3744 |
|
|
3745 |
|
/* FIXME: Support for Input Context:s */ |
3746 |
|
|
3747 |
|
get_input_mask(&input_mask); |
3748 |
|
input_mask |= PropertyChangeMask; |
3749 |
|
|
3750 |
|
XSelectInput(g_display, wnd, input_mask); |
3751 |
|
|
3752 |
|
/* handle the WM_DELETE_WINDOW protocol. */ |
3753 |
|
XSetWMProtocols(g_display, wnd, &g_kill_atom, 1); |
3754 |
|
|
3755 |
|
sw = xmalloc(sizeof(seamless_window)); |
3756 |
|
|
3757 |
|
memset(sw, 0, sizeof(seamless_window)); |
3758 |
|
|
3759 |
|
sw->wnd = wnd; |
3760 |
|
sw->id = id; |
3761 |
|
sw->group = sw_find_group(group, False); |
3762 |
|
sw->group->refcnt++; |
3763 |
|
sw->state = SEAMLESSRDP_NOTYETMAPPED; |
3764 |
|
sw->desktop = 0; |
3765 |
|
sw->position_timer = xmalloc(sizeof(struct timeval)); |
3766 |
|
timerclear(sw->position_timer); |
3767 |
|
|
3768 |
|
sw->outstanding_position = False; |
3769 |
|
sw->outpos_serial = 0; |
3770 |
|
sw->outpos_xoffset = sw->outpos_yoffset = 0; |
3771 |
|
sw->outpos_width = sw->outpos_height = 0; |
3772 |
|
|
3773 |
|
sw->next = g_seamless_windows; |
3774 |
|
g_seamless_windows = sw; |
3775 |
|
|
3776 |
|
/* WM_HINTS */ |
3777 |
|
wmhints = XAllocWMHints(); |
3778 |
|
if (wmhints) |
3779 |
|
{ |
3780 |
|
wmhints->flags = WindowGroupHint; |
3781 |
|
wmhints->window_group = sw->group->wnd; |
3782 |
|
XSetWMHints(g_display, sw->wnd, wmhints); |
3783 |
|
XFree(wmhints); |
3784 |
|
} |
3785 |
|
} |
3786 |
|
|
3787 |
|
|
3788 |
|
void |
3789 |
|
ui_seamless_destroy_window(unsigned long id, unsigned long flags) |
3790 |
|
{ |
3791 |
|
seamless_window *sw; |
3792 |
|
|
3793 |
|
if (!g_seamless_active) |
3794 |
|
return; |
3795 |
|
|
3796 |
|
sw = sw_get_window_by_id(id); |
3797 |
|
if (!sw) |
3798 |
|
{ |
3799 |
|
warning("ui_seamless_destroy_window: No information for window 0x%lx\n", id); |
3800 |
|
return; |
3801 |
|
} |
3802 |
|
|
3803 |
|
XDestroyWindow(g_display, sw->wnd); |
3804 |
|
sw_remove_window(sw); |
3805 |
|
} |
3806 |
|
|
3807 |
|
|
3808 |
|
void |
3809 |
|
ui_seamless_destroy_group(unsigned long id, unsigned long flags) |
3810 |
|
{ |
3811 |
|
seamless_window *sw, *sw_next; |
3812 |
|
|
3813 |
|
if (!g_seamless_active) |
3814 |
|
return; |
3815 |
|
|
3816 |
|
for (sw = g_seamless_windows; sw; sw = sw_next) |
3817 |
|
{ |
3818 |
|
sw_next = sw->next; |
3819 |
|
|
3820 |
|
if (sw->group->id == id) |
3821 |
|
{ |
3822 |
|
XDestroyWindow(g_display, sw->wnd); |
3823 |
|
sw_remove_window(sw); |
3824 |
|
} |
3825 |
|
} |
3826 |
|
} |
3827 |
|
|
3828 |
|
|
3829 |
|
void |
3830 |
|
ui_seamless_seticon(unsigned long id, const char *format, int width, int height, int chunk, |
3831 |
|
const char *data, int chunk_len) |
3832 |
|
{ |
3833 |
|
seamless_window *sw; |
3834 |
|
|
3835 |
|
if (!g_seamless_active) |
3836 |
|
return; |
3837 |
|
|
3838 |
|
sw = sw_get_window_by_id(id); |
3839 |
|
if (!sw) |
3840 |
|
{ |
3841 |
|
warning("ui_seamless_seticon: No information for window 0x%lx\n", id); |
3842 |
|
return; |
3843 |
|
} |
3844 |
|
|
3845 |
|
if (chunk == 0) |
3846 |
|
{ |
3847 |
|
if (sw->icon_size) |
3848 |
|
warning("ui_seamless_seticon: New icon started before previous completed\n"); |
3849 |
|
|
3850 |
|
if (strcmp(format, "RGBA") != 0) |
3851 |
|
{ |
3852 |
|
warning("ui_seamless_seticon: Uknown icon format \"%s\"\n", format); |
3853 |
|
return; |
3854 |
|
} |
3855 |
|
|
3856 |
|
sw->icon_size = width * height * 4; |
3857 |
|
if (sw->icon_size > 32 * 32 * 4) |
3858 |
|
{ |
3859 |
|
warning("ui_seamless_seticon: Icon too large (%d bytes)\n", sw->icon_size); |
3860 |
|
sw->icon_size = 0; |
3861 |
|
return; |
3862 |
|
} |
3863 |
|
|
3864 |
|
sw->icon_offset = 0; |
3865 |
|
} |
3866 |
|
else |
3867 |
|
{ |
3868 |
|
if (!sw->icon_size) |
3869 |
|
return; |
3870 |
|
} |
3871 |
|
|
3872 |
|
if (chunk_len > (sw->icon_size - sw->icon_offset)) |
3873 |
|
{ |
3874 |
|
warning("ui_seamless_seticon: Too large chunk received (%d bytes > %d bytes)\n", |
3875 |
|
chunk_len, sw->icon_size - sw->icon_offset); |
3876 |
|
sw->icon_size = 0; |
3877 |
|
return; |
3878 |
|
} |
3879 |
|
|
3880 |
|
memcpy(sw->icon_buffer + sw->icon_offset, data, chunk_len); |
3881 |
|
sw->icon_offset += chunk_len; |
3882 |
|
|
3883 |
|
if (sw->icon_offset == sw->icon_size) |
3884 |
|
{ |
3885 |
|
ewmh_set_icon(sw->wnd, width, height, sw->icon_buffer); |
3886 |
|
sw->icon_size = 0; |
3887 |
|
} |
3888 |
|
} |
3889 |
|
|
3890 |
|
|
3891 |
|
void |
3892 |
|
ui_seamless_delicon(unsigned long id, const char *format, int width, int height) |
3893 |
|
{ |
3894 |
|
seamless_window *sw; |
3895 |
|
|
3896 |
|
if (!g_seamless_active) |
3897 |
|
return; |
3898 |
|
|
3899 |
|
sw = sw_get_window_by_id(id); |
3900 |
|
if (!sw) |
3901 |
|
{ |
3902 |
|
warning("ui_seamless_seticon: No information for window 0x%lx\n", id); |
3903 |
|
return; |
3904 |
|
} |
3905 |
|
|
3906 |
|
if (strcmp(format, "RGBA") != 0) |
3907 |
|
{ |
3908 |
|
warning("ui_seamless_seticon: Uknown icon format \"%s\"\n", format); |
3909 |
|
return; |
3910 |
|
} |
3911 |
|
|
3912 |
|
ewmh_del_icon(sw->wnd, width, height); |
3913 |
|
} |
3914 |
|
|
3915 |
|
|
3916 |
|
void |
3917 |
|
ui_seamless_move_window(unsigned long id, int x, int y, int width, int height, unsigned long flags) |
3918 |
|
{ |
3919 |
|
seamless_window *sw; |
3920 |
|
|
3921 |
|
if (!g_seamless_active) |
3922 |
|
return; |
3923 |
|
|
3924 |
|
sw = sw_get_window_by_id(id); |
3925 |
|
if (!sw) |
3926 |
|
{ |
3927 |
|
warning("ui_seamless_move_window: No information for window 0x%lx\n", id); |
3928 |
|
return; |
3929 |
|
} |
3930 |
|
|
3931 |
|
/* We ignore server updates until it has handled our request. */ |
3932 |
|
if (sw->outstanding_position) |
3933 |
|
return; |
3934 |
|
|
3935 |
|
if (!width || !height) |
3936 |
|
/* X11 windows must be at least 1x1 */ |
3937 |
|
return; |
3938 |
|
|
3939 |
|
sw->xoffset = x; |
3940 |
|
sw->yoffset = y; |
3941 |
|
sw->width = width; |
3942 |
|
sw->height = height; |
3943 |
|
|
3944 |
|
/* If we move the window in a maximized state, then KDE won't |
3945 |
|
accept restoration */ |
3946 |
|
switch (sw->state) |
3947 |
|
{ |
3948 |
|
case SEAMLESSRDP_MINIMIZED: |
3949 |
|
case SEAMLESSRDP_MAXIMIZED: |
3950 |
|
return; |
3951 |
|
} |
3952 |
|
|
3953 |
|
/* FIXME: Perhaps use ewmh_net_moveresize_window instead */ |
3954 |
|
XMoveResizeWindow(g_display, sw->wnd, sw->xoffset, sw->yoffset, sw->width, sw->height); |
3955 |
|
} |
3956 |
|
|
3957 |
|
|
3958 |
|
void |
3959 |
|
ui_seamless_restack_window(unsigned long id, unsigned long behind, unsigned long flags) |
3960 |
|
{ |
3961 |
|
seamless_window *sw; |
3962 |
|
XWindowChanges values; |
3963 |
|
unsigned long restack_serial; |
3964 |
|
|
3965 |
|
if (!g_seamless_active) |
3966 |
|
return; |
3967 |
|
|
3968 |
|
sw = sw_get_window_by_id(id); |
3969 |
|
if (!sw) |
3970 |
|
{ |
3971 |
|
warning("ui_seamless_restack_window: No information for window 0x%lx\n", id); |
3972 |
|
return; |
3973 |
|
} |
3974 |
|
|
3975 |
|
if (behind) |
3976 |
|
{ |
3977 |
|
seamless_window *sw_behind; |
3978 |
|
|
3979 |
|
sw_behind = sw_get_window_by_id(behind); |
3980 |
|
if (!sw_behind) |
3981 |
|
{ |
3982 |
|
warning("ui_seamless_restack_window: No information for behind window 0x%lx\n", behind); |
3983 |
|
return; |
3984 |
|
} |
3985 |
|
|
3986 |
|
if (!g_seamless_broken_restack) |
3987 |
|
{ |
3988 |
|
values.stack_mode = Below; |
3989 |
|
values.sibling = sw_behind->wnd; |
3990 |
|
restack_serial = XNextRequest(g_display); |
3991 |
|
XReconfigureWMWindow(g_display, sw->wnd, DefaultScreen(g_display), |
3992 |
|
CWStackMode | CWSibling, &values); |
3993 |
|
sw_wait_configurenotify(sw->wnd, restack_serial); |
3994 |
|
} |
3995 |
|
} |
3996 |
|
else |
3997 |
|
{ |
3998 |
|
values.stack_mode = Above; |
3999 |
|
restack_serial = XNextRequest(g_display); |
4000 |
|
XReconfigureWMWindow(g_display, sw->wnd, DefaultScreen(g_display), CWStackMode, |
4001 |
|
&values); |
4002 |
|
sw_wait_configurenotify(sw->wnd, restack_serial); |
4003 |
|
} |
4004 |
|
|
4005 |
|
sw_restack_window(sw, behind); |
4006 |
|
|
4007 |
|
if (flags & SEAMLESSRDP_CREATE_TOPMOST) |
4008 |
|
{ |
4009 |
|
/* Make window always-on-top */ |
4010 |
|
ewmh_set_window_above(sw->wnd); |
4011 |
|
} |
4012 |
|
} |
4013 |
|
|
4014 |
|
|
4015 |
|
void |
4016 |
|
ui_seamless_settitle(unsigned long id, const char *title, unsigned long flags) |
4017 |
|
{ |
4018 |
|
seamless_window *sw; |
4019 |
|
|
4020 |
|
if (!g_seamless_active) |
4021 |
|
return; |
4022 |
|
|
4023 |
|
sw = sw_get_window_by_id(id); |
4024 |
|
if (!sw) |
4025 |
|
{ |
4026 |
|
warning("ui_seamless_settitle: No information for window 0x%lx\n", id); |
4027 |
|
return; |
4028 |
|
} |
4029 |
|
|
4030 |
|
/* FIXME: Might want to convert the name for non-EWMH WMs */ |
4031 |
|
XStoreName(g_display, sw->wnd, title); |
4032 |
|
ewmh_set_wm_name(sw->wnd, title); |
4033 |
|
} |
4034 |
|
|
4035 |
|
|
4036 |
|
void |
4037 |
|
ui_seamless_setstate(unsigned long id, unsigned int state, unsigned long flags) |
4038 |
|
{ |
4039 |
|
seamless_window *sw; |
4040 |
|
|
4041 |
|
if (!g_seamless_active) |
4042 |
|
return; |
4043 |
|
|
4044 |
|
sw = sw_get_window_by_id(id); |
4045 |
|
if (!sw) |
4046 |
|
{ |
4047 |
|
warning("ui_seamless_setstate: No information for window 0x%lx\n", id); |
4048 |
|
return; |
4049 |
|
} |
4050 |
|
|
4051 |
|
switch (state) |
4052 |
|
{ |
4053 |
|
case SEAMLESSRDP_NORMAL: |
4054 |
|
case SEAMLESSRDP_MAXIMIZED: |
4055 |
|
ewmh_change_state(sw->wnd, state); |
4056 |
|
XMapWindow(g_display, sw->wnd); |
4057 |
|
break; |
4058 |
|
case SEAMLESSRDP_MINIMIZED: |
4059 |
|
/* EWMH says: "if an Application asks to toggle _NET_WM_STATE_HIDDEN |
4060 |
|
the Window Manager should probably just ignore the request, since |
4061 |
|
_NET_WM_STATE_HIDDEN is a function of some other aspect of the window |
4062 |
|
such as minimization, rather than an independent state." Besides, |
4063 |
|
XIconifyWindow is easier. */ |
4064 |
|
if (sw->state == SEAMLESSRDP_NOTYETMAPPED) |
4065 |
|
{ |
4066 |
|
XWMHints *hints; |
4067 |
|
hints = XGetWMHints(g_display, sw->wnd); |
4068 |
|
if (hints) |
4069 |
|
{ |
4070 |
|
hints->flags |= StateHint; |
4071 |
|
hints->initial_state = IconicState; |
4072 |
|
XSetWMHints(g_display, sw->wnd, hints); |
4073 |
|
XFree(hints); |
4074 |
|
} |
4075 |
|
XMapWindow(g_display, sw->wnd); |
4076 |
|
} |
4077 |
|
else |
4078 |
|
XIconifyWindow(g_display, sw->wnd, DefaultScreen(g_display)); |
4079 |
|
break; |
4080 |
|
default: |
4081 |
|
warning("SeamlessRDP: Invalid state %d\n", state); |
4082 |
|
break; |
4083 |
|
} |
4084 |
|
|
4085 |
|
sw->state = state; |
4086 |
|
} |
4087 |
|
|
4088 |
|
|
4089 |
|
void |
4090 |
|
ui_seamless_syncbegin(unsigned long flags) |
4091 |
|
{ |
4092 |
|
if (!g_seamless_active) |
4093 |
|
return; |
4094 |
|
|
4095 |
|
/* Destroy all seamless windows */ |
4096 |
|
while (g_seamless_windows) |
4097 |
|
{ |
4098 |
|
XDestroyWindow(g_display, g_seamless_windows->wnd); |
4099 |
|
sw_remove_window(g_seamless_windows); |
4100 |
|
} |
4101 |
|
} |
4102 |
|
|
4103 |
|
|
4104 |
|
void |
4105 |
|
ui_seamless_ack(unsigned int serial) |
4106 |
|
{ |
4107 |
|
seamless_window *sw; |
4108 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
4109 |
|
{ |
4110 |
|
if (sw->outstanding_position && (sw->outpos_serial == serial)) |
4111 |
|
{ |
4112 |
|
sw->xoffset = sw->outpos_xoffset; |
4113 |
|
sw->yoffset = sw->outpos_yoffset; |
4114 |
|
sw->width = sw->outpos_width; |
4115 |
|
sw->height = sw->outpos_height; |
4116 |
|
sw->outstanding_position = False; |
4117 |
|
|
4118 |
|
/* Do a complete redraw of the window as part of the |
4119 |
|
completion of the move. This is to remove any |
4120 |
|
artifacts caused by our lack of synchronization. */ |
4121 |
|
XCopyArea(g_display, g_backstore, |
4122 |
|
sw->wnd, g_gc, |
4123 |
|
sw->xoffset, sw->yoffset, sw->width, sw->height, 0, 0); |
4124 |
|
|
4125 |
|
break; |
4126 |
|
} |
4127 |
|
} |
4128 |
|
} |