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 |
|
extern RD_BOOL g_seamless_rdp; |
90 |
|
|
91 |
extern uint32 g_embed_wnd; |
extern uint32 g_embed_wnd; |
92 |
BOOL g_enable_compose = False; |
RD_BOOL g_enable_compose = False; |
93 |
BOOL g_Unobscured; /* used for screenblt */ |
RD_BOOL g_Unobscured; /* used for screenblt */ |
94 |
static GC g_gc = NULL; |
static GC g_gc = NULL; |
95 |
static GC g_create_bitmap_gc = NULL; |
static GC g_create_bitmap_gc = NULL; |
96 |
static GC g_create_glyph_gc = NULL; |
static GC g_create_glyph_gc = NULL; |
97 |
|
static XRectangle g_clip_rectangle; |
98 |
static Visual *g_visual; |
static Visual *g_visual; |
99 |
|
/* Color depth of the X11 visual of our window (e.g. 24 for True Color R8G8B visual). |
100 |
|
This may be 32 for R8G8B8 visuals, and then the rest of the bits are undefined |
101 |
|
as far as we're concerned. */ |
102 |
static int g_depth; |
static int g_depth; |
103 |
|
/* Bits-per-Pixel of the pixmaps we'll be using to draw on our window. |
104 |
|
This may be larger than g_depth, in which case some of the bits would |
105 |
|
be kept solely for alignment (e.g. 32bpp pixmaps on a 24bpp visual). */ |
106 |
static int g_bpp; |
static int g_bpp; |
107 |
static XIM g_IM; |
static XIM g_IM; |
108 |
static XIC g_IC; |
static XIC g_IC; |
109 |
static XModifierKeymap *g_mod_map; |
static XModifierKeymap *g_mod_map; |
110 |
|
/* Maps logical (xmodmap -pp) pointing device buttons (0-based) back |
111 |
|
to physical (1-based) indices. */ |
112 |
|
static unsigned char g_pointer_log_to_phys_map[16]; |
113 |
static Cursor g_current_cursor; |
static Cursor g_current_cursor; |
114 |
static HCURSOR g_null_cursor = NULL; |
static RD_HCURSOR g_null_cursor = NULL; |
115 |
static Atom g_protocol_atom, g_kill_atom; |
static Atom g_protocol_atom, g_kill_atom; |
116 |
static BOOL g_focused; |
extern Atom g_net_wm_state_atom; |
117 |
static BOOL g_mouse_in_wnd; |
extern Atom g_net_wm_desktop_atom; |
118 |
static BOOL g_arch_match = False; /* set to True if RGB XServer and little endian */ |
static RD_BOOL g_focused; |
119 |
|
static RD_BOOL g_mouse_in_wnd; |
120 |
|
/* Indicates that: |
121 |
|
1) visual has 15, 16 or 24 depth and the same color channel masks |
122 |
|
as its RDP equivalent (implies X server is LE), |
123 |
|
2) host is LE |
124 |
|
This will trigger an optimization whose real value is questionable. |
125 |
|
*/ |
126 |
|
static RD_BOOL g_compatible_arch; |
127 |
|
/* Indicates whether RDP's bitmaps and our XImages have the same |
128 |
|
binary format. If so, we can avoid an expensive translation. |
129 |
|
Note that this can be true when g_compatible_arch is false, |
130 |
|
e.g.: |
131 |
|
|
132 |
|
RDP(LE) <-> host(BE) <-> X-Server(LE) |
133 |
|
|
134 |
|
('host' is the machine running rdesktop; the host simply memcpy's |
135 |
|
so its endianess doesn't matter) |
136 |
|
*/ |
137 |
|
static RD_BOOL g_no_translate_image = False; |
138 |
|
|
139 |
/* endianness */ |
/* endianness */ |
140 |
static BOOL g_host_be; |
static RD_BOOL g_host_be; |
141 |
static BOOL g_xserver_be; |
static RD_BOOL g_xserver_be; |
142 |
static int g_red_shift_r, g_blue_shift_r, g_green_shift_r; |
static int g_red_shift_r, g_blue_shift_r, g_green_shift_r; |
143 |
static int g_red_shift_l, g_blue_shift_l, g_green_shift_l; |
static int g_red_shift_l, g_blue_shift_l, g_green_shift_l; |
144 |
|
|
145 |
/* software backing store */ |
/* software backing store */ |
146 |
extern BOOL g_ownbackstore; |
extern RD_BOOL g_ownbackstore; |
147 |
static Pixmap g_backstore = 0; |
static Pixmap g_backstore = 0; |
148 |
|
|
149 |
/* Moving in single app mode */ |
/* Moving in single app mode */ |
150 |
static BOOL g_moving_wnd; |
static RD_BOOL g_moving_wnd; |
151 |
static int g_move_x_offset = 0; |
static int g_move_x_offset = 0; |
152 |
static int g_move_y_offset = 0; |
static int g_move_y_offset = 0; |
153 |
static BOOL g_using_full_workarea = False; |
static RD_BOOL g_using_full_workarea = False; |
154 |
|
|
155 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
156 |
extern int g_dsp_fd; |
extern RD_BOOL g_rdpsnd; |
|
extern BOOL g_dsp_busy; |
|
|
extern BOOL g_rdpsnd; |
|
157 |
#endif |
#endif |
158 |
|
|
159 |
/* MWM decorations */ |
/* MWM decorations */ |
161 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
162 |
typedef struct |
typedef struct |
163 |
{ |
{ |
164 |
uint32 flags; |
unsigned long flags; |
165 |
uint32 functions; |
unsigned long functions; |
166 |
uint32 decorations; |
unsigned long decorations; |
167 |
sint32 inputMode; |
long inputMode; |
168 |
uint32 status; |
unsigned long status; |
169 |
} |
} |
170 |
PropMotifWmHints; |
PropMotifWmHints; |
171 |
|
|
177 |
} |
} |
178 |
PixelColour; |
PixelColour; |
179 |
|
|
180 |
|
#define ON_ALL_SEAMLESS_WINDOWS(func, args) \ |
181 |
|
do { \ |
182 |
|
seamless_window *sw; \ |
183 |
|
XRectangle rect; \ |
184 |
|
if (!g_seamless_windows) break; \ |
185 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) { \ |
186 |
|
rect.x = g_clip_rectangle.x - sw->xoffset; \ |
187 |
|
rect.y = g_clip_rectangle.y - sw->yoffset; \ |
188 |
|
rect.width = g_clip_rectangle.width; \ |
189 |
|
rect.height = g_clip_rectangle.height; \ |
190 |
|
XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded); \ |
191 |
|
func args; \ |
192 |
|
} \ |
193 |
|
XSetClipRectangles(g_display, g_gc, 0, 0, &g_clip_rectangle, 1, YXBanded); \ |
194 |
|
} while (0) |
195 |
|
|
196 |
|
static void |
197 |
|
seamless_XFillPolygon(Drawable d, XPoint * points, int npoints, int xoffset, int yoffset) |
198 |
|
{ |
199 |
|
points[0].x -= xoffset; |
200 |
|
points[0].y -= yoffset; |
201 |
|
XFillPolygon(g_display, d, g_gc, points, npoints, Complex, CoordModePrevious); |
202 |
|
points[0].x += xoffset; |
203 |
|
points[0].y += yoffset; |
204 |
|
} |
205 |
|
|
206 |
|
static void |
207 |
|
seamless_XDrawLines(Drawable d, XPoint * points, int npoints, int xoffset, int yoffset) |
208 |
|
{ |
209 |
|
points[0].x -= xoffset; |
210 |
|
points[0].y -= yoffset; |
211 |
|
XDrawLines(g_display, d, g_gc, points, npoints, CoordModePrevious); |
212 |
|
points[0].x += xoffset; |
213 |
|
points[0].y += yoffset; |
214 |
|
} |
215 |
|
|
216 |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
217 |
{ \ |
{ \ |
218 |
XFillRectangle(g_display, g_wnd, g_gc, x, y, cx, cy); \ |
XFillRectangle(g_display, g_wnd, g_gc, x, y, cx, cy); \ |
219 |
|
ON_ALL_SEAMLESS_WINDOWS(XFillRectangle, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy)); \ |
220 |
if (g_ownbackstore) \ |
if (g_ownbackstore) \ |
221 |
XFillRectangle(g_display, g_backstore, g_gc, x, y, cx, cy); \ |
XFillRectangle(g_display, g_backstore, g_gc, x, y, cx, cy); \ |
222 |
} |
} |
231 |
XFillPolygon(g_display, g_wnd, g_gc, p, np, Complex, CoordModePrevious); \ |
XFillPolygon(g_display, g_wnd, g_gc, p, np, Complex, CoordModePrevious); \ |
232 |
if (g_ownbackstore) \ |
if (g_ownbackstore) \ |
233 |
XFillPolygon(g_display, g_backstore, g_gc, p, np, Complex, CoordModePrevious); \ |
XFillPolygon(g_display, g_backstore, g_gc, p, np, Complex, CoordModePrevious); \ |
234 |
|
ON_ALL_SEAMLESS_WINDOWS(seamless_XFillPolygon, (sw->wnd, p, np, sw->xoffset, sw->yoffset)); \ |
235 |
} |
} |
236 |
|
|
237 |
#define DRAW_ELLIPSE(x,y,cx,cy,m)\ |
#define DRAW_ELLIPSE(x,y,cx,cy,m)\ |
240 |
{ \ |
{ \ |
241 |
case 0: /* Outline */ \ |
case 0: /* Outline */ \ |
242 |
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); \ |
243 |
|
ON_ALL_SEAMLESS_WINDOWS(XDrawArc, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy, 0, 360*64)); \ |
244 |
if (g_ownbackstore) \ |
if (g_ownbackstore) \ |
245 |
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); \ |
246 |
break; \ |
break; \ |
247 |
case 1: /* Filled */ \ |
case 1: /* Filled */ \ |
248 |
XFillArc(g_display, g_ownbackstore ? g_backstore : g_wnd, g_gc, x, y, \ |
XFillArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \ |
249 |
cx, cy, 0, 360*64); \ |
ON_ALL_SEAMLESS_WINDOWS(XFillArc, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy, 0, 360*64)); \ |
250 |
if (g_ownbackstore) \ |
if (g_ownbackstore) \ |
251 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); \ |
XFillArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \ |
252 |
break; \ |
break; \ |
253 |
} \ |
} \ |
254 |
} |
} |
255 |
|
|
256 |
/* colour maps */ |
/* colour maps */ |
257 |
extern BOOL g_owncolmap; |
extern RD_BOOL g_owncolmap; |
258 |
static Colormap g_xcolmap; |
static Colormap g_xcolmap; |
259 |
static uint32 *g_colmap = NULL; |
static uint32 *g_colmap = NULL; |
260 |
|
|
261 |
#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] ) |
262 |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
263 |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
264 |
|
|
284 |
#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]); } |
285 |
#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); } |
286 |
|
|
287 |
|
static seamless_window * |
288 |
|
sw_get_window_by_id(unsigned long id) |
289 |
|
{ |
290 |
|
seamless_window *sw; |
291 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
292 |
|
{ |
293 |
|
if (sw->id == id) |
294 |
|
return sw; |
295 |
|
} |
296 |
|
return NULL; |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
|
static seamless_window * |
301 |
|
sw_get_window_by_wnd(Window wnd) |
302 |
|
{ |
303 |
|
seamless_window *sw; |
304 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
305 |
|
{ |
306 |
|
if (sw->wnd == wnd) |
307 |
|
return sw; |
308 |
|
} |
309 |
|
return NULL; |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
|
static void |
314 |
|
sw_remove_window(seamless_window * win) |
315 |
|
{ |
316 |
|
seamless_window *sw, **prevnext = &g_seamless_windows; |
317 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
318 |
|
{ |
319 |
|
if (sw == win) |
320 |
|
{ |
321 |
|
*prevnext = sw->next; |
322 |
|
sw->group->refcnt--; |
323 |
|
if (sw->group->refcnt == 0) |
324 |
|
{ |
325 |
|
XDestroyWindow(g_display, sw->group->wnd); |
326 |
|
xfree(sw->group); |
327 |
|
} |
328 |
|
xfree(sw->position_timer); |
329 |
|
xfree(sw); |
330 |
|
return; |
331 |
|
} |
332 |
|
prevnext = &sw->next; |
333 |
|
} |
334 |
|
return; |
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
|
/* Move all windows except wnd to new desktop */ |
339 |
|
static void |
340 |
|
sw_all_to_desktop(Window wnd, unsigned int desktop) |
341 |
|
{ |
342 |
|
seamless_window *sw; |
343 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
344 |
|
{ |
345 |
|
if (sw->wnd == wnd) |
346 |
|
continue; |
347 |
|
if (sw->desktop != desktop) |
348 |
|
{ |
349 |
|
ewmh_move_to_desktop(sw->wnd, desktop); |
350 |
|
sw->desktop = desktop; |
351 |
|
} |
352 |
|
} |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
|
/* Send our position */ |
357 |
|
static void |
358 |
|
sw_update_position(seamless_window * sw) |
359 |
|
{ |
360 |
|
XWindowAttributes wa; |
361 |
|
int x, y; |
362 |
|
Window child_return; |
363 |
|
unsigned int serial; |
364 |
|
|
365 |
|
XGetWindowAttributes(g_display, sw->wnd, &wa); |
366 |
|
XTranslateCoordinates(g_display, sw->wnd, wa.root, |
367 |
|
-wa.border_width, -wa.border_width, &x, &y, &child_return); |
368 |
|
|
369 |
|
serial = seamless_send_position(sw->id, x, y, wa.width, wa.height, 0); |
370 |
|
|
371 |
|
sw->outstanding_position = True; |
372 |
|
sw->outpos_serial = serial; |
373 |
|
|
374 |
|
sw->outpos_xoffset = x; |
375 |
|
sw->outpos_yoffset = y; |
376 |
|
sw->outpos_width = wa.width; |
377 |
|
sw->outpos_height = wa.height; |
378 |
|
} |
379 |
|
|
380 |
|
|
381 |
|
/* Check if it's time to send our position */ |
382 |
|
static void |
383 |
|
sw_check_timers() |
384 |
|
{ |
385 |
|
seamless_window *sw; |
386 |
|
struct timeval now; |
387 |
|
|
388 |
|
gettimeofday(&now, NULL); |
389 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
390 |
|
{ |
391 |
|
if (timerisset(sw->position_timer) && timercmp(sw->position_timer, &now, <)) |
392 |
|
{ |
393 |
|
timerclear(sw->position_timer); |
394 |
|
sw_update_position(sw); |
395 |
|
} |
396 |
|
} |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
|
static void |
401 |
|
sw_restack_window(seamless_window * sw, unsigned long behind) |
402 |
|
{ |
403 |
|
seamless_window *sw_above; |
404 |
|
|
405 |
|
/* Remove window from stack */ |
406 |
|
for (sw_above = g_seamless_windows; sw_above; sw_above = sw_above->next) |
407 |
|
{ |
408 |
|
if (sw_above->behind == sw->id) |
409 |
|
break; |
410 |
|
} |
411 |
|
|
412 |
|
if (sw_above) |
413 |
|
sw_above->behind = sw->behind; |
414 |
|
|
415 |
|
/* And then add it at the new position */ |
416 |
|
for (sw_above = g_seamless_windows; sw_above; sw_above = sw_above->next) |
417 |
|
{ |
418 |
|
if (sw_above->behind == behind) |
419 |
|
break; |
420 |
|
} |
421 |
|
|
422 |
|
if (sw_above) |
423 |
|
sw_above->behind = sw->id; |
424 |
|
|
425 |
|
sw->behind = behind; |
426 |
|
} |
427 |
|
|
428 |
|
|
429 |
|
static void |
430 |
|
sw_handle_restack(seamless_window * sw) |
431 |
|
{ |
432 |
|
Status status; |
433 |
|
Window root, parent, *children; |
434 |
|
unsigned int nchildren, i; |
435 |
|
seamless_window *sw_below; |
436 |
|
|
437 |
|
status = XQueryTree(g_display, RootWindowOfScreen(g_screen), |
438 |
|
&root, &parent, &children, &nchildren); |
439 |
|
if (!status || !nchildren) |
440 |
|
return; |
441 |
|
|
442 |
|
sw_below = NULL; |
443 |
|
|
444 |
|
i = 0; |
445 |
|
while (children[i] != sw->wnd) |
446 |
|
{ |
447 |
|
i++; |
448 |
|
if (i >= nchildren) |
449 |
|
goto end; |
450 |
|
} |
451 |
|
|
452 |
|
for (i++; i < nchildren; i++) |
453 |
|
{ |
454 |
|
sw_below = sw_get_window_by_wnd(children[i]); |
455 |
|
if (sw_below) |
456 |
|
break; |
457 |
|
} |
458 |
|
|
459 |
|
if (!sw_below && !sw->behind) |
460 |
|
goto end; |
461 |
|
if (sw_below && (sw_below->id == sw->behind)) |
462 |
|
goto end; |
463 |
|
|
464 |
|
if (sw_below) |
465 |
|
{ |
466 |
|
seamless_send_zchange(sw->id, sw_below->id, 0); |
467 |
|
sw_restack_window(sw, sw_below->id); |
468 |
|
} |
469 |
|
else |
470 |
|
{ |
471 |
|
seamless_send_zchange(sw->id, 0, 0); |
472 |
|
sw_restack_window(sw, 0); |
473 |
|
} |
474 |
|
|
475 |
|
end: |
476 |
|
XFree(children); |
477 |
|
} |
478 |
|
|
479 |
|
|
480 |
|
static seamless_group * |
481 |
|
sw_find_group(unsigned long id, RD_BOOL dont_create) |
482 |
|
{ |
483 |
|
seamless_window *sw; |
484 |
|
seamless_group *sg; |
485 |
|
XSetWindowAttributes attribs; |
486 |
|
|
487 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
488 |
|
{ |
489 |
|
if (sw->group->id == id) |
490 |
|
return sw->group; |
491 |
|
} |
492 |
|
|
493 |
|
if (dont_create) |
494 |
|
return NULL; |
495 |
|
|
496 |
|
sg = xmalloc(sizeof(seamless_group)); |
497 |
|
|
498 |
|
sg->wnd = |
499 |
|
XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0, |
500 |
|
CopyFromParent, CopyFromParent, CopyFromParent, 0, &attribs); |
501 |
|
|
502 |
|
sg->id = id; |
503 |
|
sg->refcnt = 0; |
504 |
|
|
505 |
|
return sg; |
506 |
|
} |
507 |
|
|
508 |
|
|
509 |
static void |
static void |
510 |
mwm_hide_decorations(void) |
mwm_hide_decorations(Window wnd) |
511 |
{ |
{ |
512 |
PropMotifWmHints motif_hints; |
PropMotifWmHints motif_hints; |
513 |
Atom hintsatom; |
Atom hintsatom; |
524 |
return; |
return; |
525 |
} |
} |
526 |
|
|
527 |
XChangeProperty(g_display, g_wnd, hintsatom, hintsatom, 32, PropModeReplace, |
XChangeProperty(g_display, wnd, hintsatom, hintsatom, 32, PropModeReplace, |
528 |
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
529 |
|
|
530 |
} |
} |
531 |
|
|
532 |
#define SPLITCOLOUR15(colour, rv) \ |
#define SPLITCOLOUR15(colour, rv) \ |
560 |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
561 |
x = (x << 16) | (x >> 16); } |
x = (x << 16) | (x >> 16); } |
562 |
|
|
563 |
|
/* The following macros output the same octet sequences |
564 |
|
on both BE and LE hosts: */ |
565 |
|
|
566 |
#define BOUT16(o, x) { *(o++) = x >> 8; *(o++) = x; } |
#define BOUT16(o, x) { *(o++) = x >> 8; *(o++) = x; } |
567 |
#define BOUT24(o, x) { *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; } |
#define BOUT24(o, x) { *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; } |
568 |
#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; } |
574 |
translate_colour(uint32 colour) |
translate_colour(uint32 colour) |
575 |
{ |
{ |
576 |
PixelColour pc; |
PixelColour pc; |
577 |
switch (g_server_bpp) |
switch (g_server_depth) |
578 |
{ |
{ |
579 |
case 15: |
case 15: |
580 |
SPLITCOLOUR15(colour, pc); |
SPLITCOLOUR15(colour, pc); |
583 |
SPLITCOLOUR16(colour, pc); |
SPLITCOLOUR16(colour, pc); |
584 |
break; |
break; |
585 |
case 24: |
case 24: |
586 |
|
case 32: |
587 |
SPLITCOLOUR24(colour, pc); |
SPLITCOLOUR24(colour, pc); |
588 |
break; |
break; |
589 |
|
default: |
590 |
|
/* Avoid warning */ |
591 |
|
pc.red = 0; |
592 |
|
pc.green = 0; |
593 |
|
pc.blue = 0; |
594 |
|
break; |
595 |
} |
} |
596 |
return MAKECOLOUR(pc); |
return MAKECOLOUR(pc); |
597 |
} |
} |
643 |
{ |
{ |
644 |
uint16 value; |
uint16 value; |
645 |
|
|
646 |
if (g_arch_match) |
if (g_compatible_arch) |
647 |
{ |
{ |
648 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
649 |
REPEAT2 |
REPEAT2 |
677 |
{ |
{ |
678 |
uint32 value; |
uint32 value; |
679 |
|
|
680 |
if (g_xserver_be) |
if (g_compatible_arch) |
681 |
{ |
{ |
682 |
while (out < end) |
while (out < end) |
683 |
{ |
{ |
700 |
{ |
{ |
701 |
uint32 value; |
uint32 value; |
702 |
|
|
703 |
if (g_arch_match) |
if (g_compatible_arch) |
704 |
{ |
{ |
705 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
706 |
REPEAT4 |
REPEAT4 |
772 |
uint16 pixel; |
uint16 pixel; |
773 |
PixelColour pc; |
PixelColour pc; |
774 |
|
|
775 |
if (g_arch_match) |
if (g_compatible_arch) |
776 |
{ |
{ |
777 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
778 |
REPEAT3 |
REPEAT3 |
822 |
uint32 value; |
uint32 value; |
823 |
PixelColour pc; |
PixelColour pc; |
824 |
|
|
825 |
if (g_arch_match) |
if (g_compatible_arch) |
826 |
{ |
{ |
827 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
828 |
REPEAT4 |
REPEAT4 |
930 |
uint16 pixel; |
uint16 pixel; |
931 |
PixelColour pc; |
PixelColour pc; |
932 |
|
|
933 |
if (g_arch_match) |
if (g_compatible_arch) |
934 |
{ |
{ |
935 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
936 |
REPEAT3 |
REPEAT3 |
1000 |
uint32 value; |
uint32 value; |
1001 |
PixelColour pc; |
PixelColour pc; |
1002 |
|
|
1003 |
if (g_arch_match) |
if (g_compatible_arch) |
1004 |
{ |
{ |
1005 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
1006 |
REPEAT4 |
REPEAT4 |
1129 |
uint32 value; |
uint32 value; |
1130 |
PixelColour pc; |
PixelColour pc; |
1131 |
|
|
1132 |
if (g_arch_match) |
if (g_compatible_arch) |
1133 |
{ |
{ |
1134 |
/* *INDENT-OFF* */ |
/* *INDENT-OFF* */ |
1135 |
#ifdef NEED_ALIGN |
#ifdef NEED_ALIGN |
1143 |
#else |
#else |
1144 |
REPEAT4 |
REPEAT4 |
1145 |
( |
( |
1146 |
*((uint32 *) out) = *((uint32 *) data); |
/* Only read 3 bytes. Reading 4 bytes means reading beyond buffer. */ |
1147 |
out += 4; |
*((uint32 *) out) = *((uint16 *) data) + (*((uint8 *) data + 2) << 16); |
1148 |
data += 3; |
out += 4; |
1149 |
|
data += 3; |
1150 |
) |
) |
1151 |
#endif |
#endif |
1152 |
/* *INDENT-ON* */ |
/* *INDENT-ON* */ |
1184 |
uint8 *out; |
uint8 *out; |
1185 |
uint8 *end; |
uint8 *end; |
1186 |
|
|
1187 |
/* if server and xserver bpp match, */ |
/* |
1188 |
/* and arch(endian) matches, no need to translate */ |
If RDP depth and X Visual depths match, |
1189 |
/* just return data */ |
and arch(endian) matches, no need to translate: |
1190 |
if (g_arch_match) |
just return data. |
1191 |
|
Note: select_visual should've already ensured g_no_translate |
1192 |
|
is only set for compatible depths, but the RDP depth might've |
1193 |
|
changed during connection negotiations. |
1194 |
|
*/ |
1195 |
|
|
1196 |
|
/* todo */ |
1197 |
|
if (g_server_depth == 32 && g_depth == 24) |
1198 |
{ |
{ |
1199 |
if (g_depth == 15 && g_server_bpp == 15) |
return data; |
1200 |
return data; |
} |
1201 |
if (g_depth == 16 && g_server_bpp == 16) |
|
1202 |
return data; |
if (g_no_translate_image) |
1203 |
if (g_depth == 24 && g_bpp == 24 && g_server_bpp == 24) |
{ |
1204 |
|
if ((g_depth == 15 && g_server_depth == 15) || |
1205 |
|
(g_depth == 16 && g_server_depth == 16) || |
1206 |
|
(g_depth == 24 && g_server_depth == 24)) |
1207 |
return data; |
return data; |
1208 |
} |
} |
1209 |
|
|
1211 |
out = (uint8 *) xmalloc(size); |
out = (uint8 *) xmalloc(size); |
1212 |
end = out + size; |
end = out + size; |
1213 |
|
|
1214 |
switch (g_server_bpp) |
switch (g_server_depth) |
1215 |
{ |
{ |
1216 |
case 24: |
case 24: |
1217 |
switch (g_bpp) |
switch (g_bpp) |
1276 |
return out; |
return out; |
1277 |
} |
} |
1278 |
|
|
1279 |
BOOL |
static void |
1280 |
|
xwin_refresh_pointer_map(void) |
1281 |
|
{ |
1282 |
|
unsigned char phys_to_log_map[sizeof(g_pointer_log_to_phys_map)]; |
1283 |
|
int i, pointer_buttons; |
1284 |
|
|
1285 |
|
pointer_buttons = XGetPointerMapping(g_display, phys_to_log_map, sizeof(phys_to_log_map)); |
1286 |
|
for (i = 0; i < pointer_buttons; ++i) |
1287 |
|
{ |
1288 |
|
/* This might produce multiple logical buttons mapping |
1289 |
|
to a single physical one, but hey, that's |
1290 |
|
life... */ |
1291 |
|
g_pointer_log_to_phys_map[phys_to_log_map[i] - 1] = i + 1; |
1292 |
|
} |
1293 |
|
} |
1294 |
|
|
1295 |
|
RD_BOOL |
1296 |
get_key_state(unsigned int state, uint32 keysym) |
get_key_state(unsigned int state, uint32 keysym) |
1297 |
{ |
{ |
1298 |
int modifierpos, key, keysymMask = 0; |
int modifierpos, key, keysymMask = 0; |
1325 |
*shift_r = 8 - ffs(mask & ~(mask >> 1)); |
*shift_r = 8 - ffs(mask & ~(mask >> 1)); |
1326 |
} |
} |
1327 |
|
|
1328 |
BOOL |
/* Given a mask of a colour channel (e.g. XVisualInfo.red_mask), |
1329 |
ui_init(void) |
calculates the bits-per-pixel of this channel (a.k.a. colour weight). |
1330 |
|
*/ |
1331 |
|
static unsigned |
1332 |
|
calculate_mask_weight(uint32 mask) |
1333 |
|
{ |
1334 |
|
unsigned weight = 0; |
1335 |
|
do |
1336 |
|
{ |
1337 |
|
weight += (mask & 1); |
1338 |
|
} |
1339 |
|
while (mask >>= 1); |
1340 |
|
return weight; |
1341 |
|
} |
1342 |
|
|
1343 |
|
static RD_BOOL |
1344 |
|
select_visual(int screen_num) |
1345 |
{ |
{ |
|
XVisualInfo vi; |
|
1346 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
1347 |
uint16 test; |
int pixmap_formats_count, visuals_count; |
|
int i, screen_num, nvisuals; |
|
1348 |
XVisualInfo *vmatches = NULL; |
XVisualInfo *vmatches = NULL; |
1349 |
XVisualInfo template; |
XVisualInfo template; |
1350 |
Bool TrueColorVisual = False; |
int i; |
1351 |
|
unsigned red_weight, blue_weight, green_weight; |
1352 |
|
|
1353 |
g_display = XOpenDisplay(NULL); |
red_weight = blue_weight = green_weight = 0; |
1354 |
if (g_display == NULL) |
|
1355 |
|
if (g_server_depth == -1) |
1356 |
{ |
{ |
1357 |
error("Failed to open display: %s\n", XDisplayName(NULL)); |
g_server_depth = DisplayPlanes(g_display, DefaultScreen(g_display)); |
|
return False; |
|
1358 |
} |
} |
1359 |
|
|
1360 |
screen_num = DefaultScreen(g_display); |
pfm = XListPixmapFormats(g_display, &pixmap_formats_count); |
1361 |
g_x_socket = ConnectionNumber(g_display); |
if (pfm == NULL) |
1362 |
g_screen = ScreenOfDisplay(g_display, screen_num); |
{ |
1363 |
g_depth = DefaultDepthOfScreen(g_screen); |
error("Unable to get list of pixmap formats from display.\n"); |
1364 |
|
XCloseDisplay(g_display); |
1365 |
|
return False; |
1366 |
|
} |
1367 |
|
|
1368 |
/* Search for best TrueColor depth */ |
/* Search for best TrueColor visual */ |
1369 |
template.class = TrueColor; |
template.class = TrueColor; |
1370 |
vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals); |
template.screen = screen_num; |
1371 |
|
vmatches = |
1372 |
|
XGetVisualInfo(g_display, VisualClassMask | VisualScreenMask, &template, |
1373 |
|
&visuals_count); |
1374 |
|
g_visual = NULL; |
1375 |
|
g_no_translate_image = False; |
1376 |
|
g_compatible_arch = False; |
1377 |
|
if (vmatches != NULL) |
1378 |
|
{ |
1379 |
|
for (i = 0; i < visuals_count; ++i) |
1380 |
|
{ |
1381 |
|
XVisualInfo *visual_info = &vmatches[i]; |
1382 |
|
RD_BOOL can_translate_to_bpp = False; |
1383 |
|
int j; |
1384 |
|
|
1385 |
|
/* Try to find a no-translation visual that'll |
1386 |
|
allow us to use RDP bitmaps directly as ZPixmaps. */ |
1387 |
|
if (!g_xserver_be && (((visual_info->depth == 15) && |
1388 |
|
/* R5G5B5 */ |
1389 |
|
(visual_info->red_mask == 0x7c00) && |
1390 |
|
(visual_info->green_mask == 0x3e0) && |
1391 |
|
(visual_info->blue_mask == 0x1f)) || |
1392 |
|
((visual_info->depth == 16) && |
1393 |
|
/* R5G6B5 */ |
1394 |
|
(visual_info->red_mask == 0xf800) && |
1395 |
|
(visual_info->green_mask == 0x7e0) && |
1396 |
|
(visual_info->blue_mask == 0x1f)) || |
1397 |
|
((visual_info->depth == 24) && |
1398 |
|
/* R8G8B8 */ |
1399 |
|
(visual_info->red_mask == 0xff0000) && |
1400 |
|
(visual_info->green_mask == 0xff00) && |
1401 |
|
(visual_info->blue_mask == 0xff)))) |
1402 |
|
{ |
1403 |
|
g_visual = visual_info->visual; |
1404 |
|
g_depth = visual_info->depth; |
1405 |
|
g_compatible_arch = !g_host_be; |
1406 |
|
g_no_translate_image = (visual_info->depth == g_server_depth); |
1407 |
|
if (g_no_translate_image) |
1408 |
|
/* We found the best visual */ |
1409 |
|
break; |
1410 |
|
} |
1411 |
|
else |
1412 |
|
{ |
1413 |
|
g_compatible_arch = False; |
1414 |
|
} |
1415 |
|
|
1416 |
nvisuals--; |
if (visual_info->depth > 24) |
1417 |
while (nvisuals >= 0) |
{ |
1418 |
{ |
/* Avoid 32-bit visuals and likes like the plague. |
1419 |
if ((vmatches + nvisuals)->depth > g_depth) |
They're either untested or proven to work bad |
1420 |
{ |
(e.g. nvidia's Composite 32-bit visual). |
1421 |
g_depth = (vmatches + nvisuals)->depth; |
Most implementation offer a 24-bit visual anyway. */ |
1422 |
|
continue; |
1423 |
|
} |
1424 |
|
|
1425 |
|
/* Only care for visuals, for whose BPPs (not depths!) |
1426 |
|
we have a translateXtoY function. */ |
1427 |
|
for (j = 0; j < pixmap_formats_count; ++j) |
1428 |
|
{ |
1429 |
|
if (pfm[j].depth == visual_info->depth) |
1430 |
|
{ |
1431 |
|
if ((pfm[j].bits_per_pixel == 16) || |
1432 |
|
(pfm[j].bits_per_pixel == 24) || |
1433 |
|
(pfm[j].bits_per_pixel == 32)) |
1434 |
|
{ |
1435 |
|
can_translate_to_bpp = True; |
1436 |
|
} |
1437 |
|
break; |
1438 |
|
} |
1439 |
|
} |
1440 |
|
|
1441 |
|
/* Prefer formats which have the most colour depth. |
1442 |
|
We're being truly aristocratic here, minding each |
1443 |
|
weight on its own. */ |
1444 |
|
if (can_translate_to_bpp) |
1445 |
|
{ |
1446 |
|
unsigned vis_red_weight = |
1447 |
|
calculate_mask_weight(visual_info->red_mask); |
1448 |
|
unsigned vis_green_weight = |
1449 |
|
calculate_mask_weight(visual_info->green_mask); |
1450 |
|
unsigned vis_blue_weight = |
1451 |
|
calculate_mask_weight(visual_info->blue_mask); |
1452 |
|
if ((vis_red_weight >= red_weight) |
1453 |
|
&& (vis_green_weight >= green_weight) |
1454 |
|
&& (vis_blue_weight >= blue_weight)) |
1455 |
|
{ |
1456 |
|
red_weight = vis_red_weight; |
1457 |
|
green_weight = vis_green_weight; |
1458 |
|
blue_weight = vis_blue_weight; |
1459 |
|
g_visual = visual_info->visual; |
1460 |
|
g_depth = visual_info->depth; |
1461 |
|
} |
1462 |
|
} |
1463 |
} |
} |
1464 |
nvisuals--; |
XFree(vmatches); |
|
TrueColorVisual = True; |
|
1465 |
} |
} |
1466 |
|
|
1467 |
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))) |
|
1468 |
{ |
{ |
1469 |
/* we use a colourmap, so the default visual should do */ |
g_owncolmap = False; |
1470 |
g_visual = DefaultVisualOfScreen(g_screen); |
calculate_shifts(g_visual->red_mask, &g_red_shift_r, &g_red_shift_l); |
1471 |
g_depth = DefaultDepthOfScreen(g_screen); |
calculate_shifts(g_visual->green_mask, &g_green_shift_r, &g_green_shift_l); |
1472 |
|
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; |
|
|
} |
|
1473 |
} |
} |
1474 |
else |
else |
1475 |
{ |
{ |
1476 |
/* need a truecolour visual */ |
template.class = PseudoColor; |
1477 |
if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi)) |
template.depth = 8; |
1478 |
{ |
template.colormap_size = 256; |
1479 |
error("The display does not support true colour - high colour support unavailable.\n"); |
vmatches = |
1480 |
|
XGetVisualInfo(g_display, |
1481 |
|
VisualClassMask | VisualDepthMask | VisualColormapSizeMask, |
1482 |
|
&template, &visuals_count); |
1483 |
|
if (vmatches == NULL) |
1484 |
|
{ |
1485 |
|
error("No usable TrueColor or PseudoColor visuals on this display.\n"); |
1486 |
|
XCloseDisplay(g_display); |
1487 |
|
XFree(pfm); |
1488 |
return False; |
return False; |
1489 |
} |
} |
1490 |
|
|
1491 |
g_visual = vi.visual; |
/* we use a colourmap, so the default visual should do */ |
1492 |
g_owncolmap = False; |
g_owncolmap = True; |
1493 |
calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l); |
g_visual = vmatches[0].visual; |
1494 |
calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l); |
g_depth = vmatches[0].depth; |
1495 |
calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l); |
} |
1496 |
|
|
1497 |
/* if RGB video and everything is little endian */ |
g_bpp = 0; |
1498 |
if ((vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) && |
for (i = 0; i < pixmap_formats_count; ++i) |
1499 |
!g_xserver_be && !g_host_be) |
{ |
1500 |
|
XPixmapFormatValues *pf = &pfm[i]; |
1501 |
|
if (pf->depth == g_depth) |
1502 |
{ |
{ |
1503 |
if (g_depth <= 16 || (g_red_shift_l == 16 && g_green_shift_l == 8 && |
g_bpp = pf->bits_per_pixel; |
1504 |
g_blue_shift_l == 0)) |
|
1505 |
|
if (g_no_translate_image) |
1506 |
{ |
{ |
1507 |
g_arch_match = True; |
switch (g_server_depth) |
1508 |
|
{ |
1509 |
|
case 15: |
1510 |
|
case 16: |
1511 |
|
if (g_bpp != 16) |
1512 |
|
g_no_translate_image = False; |
1513 |
|
break; |
1514 |
|
case 24: |
1515 |
|
/* Yes, this will force image translation |
1516 |
|
on most modern servers which use 32 bits |
1517 |
|
for R8G8B8. */ |
1518 |
|
if (g_bpp != 24) |
1519 |
|
g_no_translate_image = False; |
1520 |
|
break; |
1521 |
|
default: |
1522 |
|
g_no_translate_image = False; |
1523 |
|
break; |
1524 |
|
} |
1525 |
} |
} |
|
} |
|
1526 |
|
|
1527 |
if (g_arch_match) |
/* Pixmap formats list is a depth-to-bpp mapping -- |
1528 |
{ |
there's just a single entry for every depth, |
1529 |
DEBUG(("Architectures match, enabling little endian optimisations.\n")); |
so we can safely break here */ |
1530 |
|
break; |
1531 |
} |
} |
1532 |
} |
} |
1533 |
|
XFree(pfm); |
1534 |
|
pfm = NULL; |
1535 |
|
return True; |
1536 |
|
} |
1537 |
|
|
1538 |
pfm = XListPixmapFormats(g_display, &i); |
static XErrorHandler g_old_error_handler; |
1539 |
if (pfm != NULL) |
|
1540 |
|
static int |
1541 |
|
error_handler(Display * dpy, XErrorEvent * eev) |
1542 |
|
{ |
1543 |
|
if ((eev->error_code == BadMatch) && (eev->request_code == X_ConfigureWindow)) |
1544 |
{ |
{ |
1545 |
/* Use maximum bpp for this depth - this is generally |
fprintf(stderr, "Got \"BadMatch\" when trying to restack windows.\n"); |
1546 |
desirable, e.g. 24 bits->32 bits. */ |
fprintf(stderr, |
1547 |
while (i--) |
"This is most likely caused by a broken window manager (commonly KWin).\n"); |
1548 |
{ |
return 0; |
|
if ((pfm[i].depth == g_depth) && (pfm[i].bits_per_pixel > g_bpp)) |
|
|
{ |
|
|
g_bpp = pfm[i].bits_per_pixel; |
|
|
} |
|
|
} |
|
|
XFree(pfm); |
|
1549 |
} |
} |
1550 |
|
|
1551 |
if (g_bpp < 8) |
return g_old_error_handler(dpy, eev); |
1552 |
|
} |
1553 |
|
|
1554 |
|
RD_BOOL |
1555 |
|
ui_init(void) |
1556 |
|
{ |
1557 |
|
int screen_num; |
1558 |
|
|
1559 |
|
g_display = XOpenDisplay(NULL); |
1560 |
|
if (g_display == NULL) |
1561 |
{ |
{ |
1562 |
error("Less than 8 bpp not currently supported.\n"); |
error("Failed to open display: %s\n", XDisplayName(NULL)); |
|
XCloseDisplay(g_display); |
|
1563 |
return False; |
return False; |
1564 |
} |
} |
1565 |
|
|
1566 |
|
{ |
1567 |
|
uint16 endianess_test = 1; |
1568 |
|
g_host_be = !(RD_BOOL) (*(uint8 *) (&endianess_test)); |
1569 |
|
} |
1570 |
|
|
1571 |
|
g_old_error_handler = XSetErrorHandler(error_handler); |
1572 |
|
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
1573 |
|
screen_num = DefaultScreen(g_display); |
1574 |
|
g_x_socket = ConnectionNumber(g_display); |
1575 |
|
g_screen = ScreenOfDisplay(g_display, screen_num); |
1576 |
|
g_depth = DefaultDepthOfScreen(g_screen); |
1577 |
|
|
1578 |
|
if (!select_visual(screen_num)) |
1579 |
|
return False; |
1580 |
|
|
1581 |
|
if (g_no_translate_image) |
1582 |
|
{ |
1583 |
|
DEBUG(("Performance optimization possible: avoiding image translation (colour depth conversion).\n")); |
1584 |
|
} |
1585 |
|
|
1586 |
|
if (g_server_depth > g_bpp) |
1587 |
|
{ |
1588 |
|
warning("Remote desktop colour depth %d higher than display colour depth %d.\n", |
1589 |
|
g_server_depth, g_bpp); |
1590 |
|
} |
1591 |
|
|
1592 |
|
DEBUG(("RDP depth: %d, display depth: %d, display bpp: %d, X server BE: %d, host BE: %d\n", |
1593 |
|
g_server_depth, g_depth, g_bpp, g_xserver_be, g_host_be)); |
1594 |
|
|
1595 |
if (!g_owncolmap) |
if (!g_owncolmap) |
1596 |
{ |
{ |
1597 |
g_xcolmap = |
g_xcolmap = |
1598 |
XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual, |
XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual, |
1599 |
AllocNone); |
AllocNone); |
1600 |
if (g_depth <= 8) |
if (g_depth <= 8) |
1601 |
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); |
1602 |
} |
} |
1603 |
|
|
1604 |
if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) |
if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) |
1605 |
{ |
{ |
1606 |
warning("External BackingStore not available, using internal\n"); |
warning("External BackingStore not available. Using internal.\n"); |
1607 |
g_ownbackstore = True; |
g_ownbackstore = True; |
1608 |
} |
} |
1609 |
|
|
1614 |
{ |
{ |
1615 |
g_width = WidthOfScreen(g_screen); |
g_width = WidthOfScreen(g_screen); |
1616 |
g_height = HeightOfScreen(g_screen); |
g_height = HeightOfScreen(g_screen); |
1617 |
|
g_using_full_workarea = True; |
1618 |
} |
} |
1619 |
else if (g_width < 0) |
else if (g_width < 0) |
1620 |
{ |
{ |
1628 |
{ |
{ |
1629 |
/* Fetch geometry from _NET_WORKAREA */ |
/* Fetch geometry from _NET_WORKAREA */ |
1630 |
uint32 x, y, cx, cy; |
uint32 x, y, cx, cy; |
|
g_using_full_workarea = True; |
|
|
|
|
1631 |
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
1632 |
{ |
{ |
1633 |
g_width = cx; |
g_width = cx; |
1634 |
g_height = cy; |
g_height = cy; |
1635 |
|
g_using_full_workarea = True; |
1636 |
} |
} |
1637 |
else |
else |
1638 |
{ |
{ |
1639 |
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"); |
1640 |
g_width = 800; |
g_width = WidthOfScreen(g_screen); |
1641 |
g_height = 600; |
g_height = HeightOfScreen(g_screen); |
1642 |
} |
} |
1643 |
} |
} |
1644 |
|
|
1646 |
g_width = (g_width + 3) & ~3; |
g_width = (g_width + 3) & ~3; |
1647 |
|
|
1648 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
1649 |
|
xwin_refresh_pointer_map(); |
1650 |
|
|
1651 |
xkeymap_init(); |
xkeymap_init(); |
1652 |
|
|
1654 |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
1655 |
|
|
1656 |
xclip_init(); |
xclip_init(); |
1657 |
|
ewmh_init(); |
1658 |
|
if (g_seamless_rdp) |
1659 |
|
seamless_init(); |
1660 |
|
|
1661 |
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)); |
1662 |
|
|
1663 |
return True; |
return True; |
1664 |
} |
} |
1666 |
void |
void |
1667 |
ui_deinit(void) |
ui_deinit(void) |
1668 |
{ |
{ |
1669 |
|
while (g_seamless_windows) |
1670 |
|
{ |
1671 |
|
XDestroyWindow(g_display, g_seamless_windows->wnd); |
1672 |
|
sw_remove_window(g_seamless_windows); |
1673 |
|
} |
1674 |
|
|
1675 |
|
xclip_deinit(); |
1676 |
|
|
1677 |
if (g_IM != NULL) |
if (g_IM != NULL) |
1678 |
XCloseIM(g_IM); |
XCloseIM(g_IM); |
1679 |
|
|
1690 |
g_display = NULL; |
g_display = NULL; |
1691 |
} |
} |
1692 |
|
|
1693 |
BOOL |
|
1694 |
|
static void |
1695 |
|
get_window_attribs(XSetWindowAttributes * attribs) |
1696 |
|
{ |
1697 |
|
attribs->background_pixel = BlackPixelOfScreen(g_screen); |
1698 |
|
attribs->background_pixel = WhitePixelOfScreen(g_screen); |
1699 |
|
attribs->border_pixel = WhitePixelOfScreen(g_screen); |
1700 |
|
attribs->backing_store = g_ownbackstore ? NotUseful : Always; |
1701 |
|
attribs->override_redirect = g_fullscreen; |
1702 |
|
attribs->colormap = g_xcolmap; |
1703 |
|
} |
1704 |
|
|
1705 |
|
static void |
1706 |
|
get_input_mask(long *input_mask) |
1707 |
|
{ |
1708 |
|
*input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
1709 |
|
VisibilityChangeMask | FocusChangeMask | StructureNotifyMask; |
1710 |
|
|
1711 |
|
if (g_sendmotion) |
1712 |
|
*input_mask |= PointerMotionMask; |
1713 |
|
if (g_ownbackstore) |
1714 |
|
*input_mask |= ExposureMask; |
1715 |
|
if (g_fullscreen || g_grab_keyboard) |
1716 |
|
*input_mask |= EnterWindowMask; |
1717 |
|
if (g_grab_keyboard) |
1718 |
|
*input_mask |= LeaveWindowMask; |
1719 |
|
} |
1720 |
|
|
1721 |
|
RD_BOOL |
1722 |
ui_create_window(void) |
ui_create_window(void) |
1723 |
{ |
{ |
1724 |
uint8 null_pointer_mask[1] = { 0x80 }; |
uint8 null_pointer_mask[1] = { 0x80 }; |
1740 |
if (g_ypos < 0 || (g_ypos == 0 && (g_pos & 4))) |
if (g_ypos < 0 || (g_ypos == 0 && (g_pos & 4))) |
1741 |
g_ypos = HeightOfScreen(g_screen) + g_ypos - g_height; |
g_ypos = HeightOfScreen(g_screen) + g_ypos - g_height; |
1742 |
|
|
1743 |
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; |
|
1744 |
|
|
1745 |
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, |
1746 |
wndheight, 0, g_depth, InputOutput, g_visual, |
wndheight, 0, g_depth, InputOutput, g_visual, |
1748 |
CWBorderPixel, &attribs); |
CWBorderPixel, &attribs); |
1749 |
|
|
1750 |
if (g_gc == NULL) |
if (g_gc == NULL) |
1751 |
|
{ |
1752 |
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
1753 |
|
ui_reset_clip(); |
1754 |
|
} |
1755 |
|
|
1756 |
if (g_create_bitmap_gc == NULL) |
if (g_create_bitmap_gc == NULL) |
1757 |
g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
1766 |
} |
} |
1767 |
|
|
1768 |
XStoreName(g_display, g_wnd, g_title); |
XStoreName(g_display, g_wnd, g_title); |
1769 |
|
ewmh_set_wm_name(g_wnd, g_title); |
1770 |
|
|
1771 |
if (g_hide_decorations) |
if (g_hide_decorations) |
1772 |
mwm_hide_decorations(); |
mwm_hide_decorations(g_wnd); |
1773 |
|
|
1774 |
classhints = XAllocClassHint(); |
classhints = XAllocClassHint(); |
1775 |
if (classhints != NULL) |
if (classhints != NULL) |
1796 |
XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0); |
XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0); |
1797 |
} |
} |
1798 |
|
|
1799 |
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; |
|
1800 |
|
|
1801 |
if (g_IM != NULL) |
if (g_IM != NULL) |
1802 |
{ |
{ |
1881 |
{ |
{ |
1882 |
Pixmap contents = 0; |
Pixmap contents = 0; |
1883 |
|
|
1884 |
|
if (g_seamless_active) |
1885 |
|
/* Turn off SeamlessRDP mode */ |
1886 |
|
ui_seamless_toggle(); |
1887 |
|
|
1888 |
if (!g_ownbackstore) |
if (!g_ownbackstore) |
1889 |
{ |
{ |
1890 |
/* need to save contents of window */ |
/* need to save contents of window */ |
1906 |
} |
} |
1907 |
|
|
1908 |
static void |
static void |
1909 |
handle_button_event(XEvent xevent, BOOL down) |
handle_button_event(XEvent xevent, RD_BOOL down) |
1910 |
{ |
{ |
1911 |
uint16 button, flags = 0; |
uint16 button, flags = 0; |
1912 |
g_last_gesturetime = xevent.xbutton.time; |
g_last_gesturetime = xevent.xbutton.time; |
1913 |
|
/* Reverse the pointer button mapping, e.g. in the case of |
1914 |
|
"left-handed mouse mode"; the RDP session expects to |
1915 |
|
receive physical buttons (true in mstsc as well) and |
1916 |
|
logical button behavior depends on the remote desktop's own |
1917 |
|
mouse settings */ |
1918 |
|
xevent.xbutton.button = g_pointer_log_to_phys_map[xevent.xbutton.button - 1]; |
1919 |
button = xkeymap_translate_button(xevent.xbutton.button); |
button = xkeymap_translate_button(xevent.xbutton.button); |
1920 |
if (button == 0) |
if (button == 0) |
1921 |
return; |
return; |
1979 |
} |
} |
1980 |
} |
} |
1981 |
|
|
1982 |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
if (xevent.xmotion.window == g_wnd) |
1983 |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
{ |
1984 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
1985 |
|
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
1986 |
|
} |
1987 |
|
else |
1988 |
|
{ |
1989 |
|
/* SeamlessRDP */ |
1990 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
1991 |
|
flags | button, xevent.xbutton.x_root, xevent.xbutton.y_root); |
1992 |
|
} |
1993 |
} |
} |
1994 |
|
|
1995 |
|
|
1996 |
/* Process events in Xlib queue |
/* Process events in Xlib queue |
1997 |
Returns 0 after user quit, 1 otherwise */ |
Returns 0 after user quit, 1 otherwise */ |
1998 |
static int |
static int |
2004 |
char str[256]; |
char str[256]; |
2005 |
Status status; |
Status status; |
2006 |
int events = 0; |
int events = 0; |
2007 |
|
seamless_window *sw; |
2008 |
|
|
2009 |
while ((XPending(g_display) > 0) && events++ < 20) |
while ((XPending(g_display) > 0) && events++ < 20) |
2010 |
{ |
{ |
2019 |
switch (xevent.type) |
switch (xevent.type) |
2020 |
{ |
{ |
2021 |
case VisibilityNotify: |
case VisibilityNotify: |
2022 |
g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured; |
if (xevent.xvisibility.window == g_wnd) |
2023 |
|
g_Unobscured = |
2024 |
|
xevent.xvisibility.state == VisibilityUnobscured; |
2025 |
|
|
2026 |
break; |
break; |
2027 |
case ClientMessage: |
case ClientMessage: |
2028 |
/* the window manager told us to quit */ |
/* the window manager told us to quit */ |
2029 |
if ((xevent.xclient.message_type == g_protocol_atom) |
if ((xevent.xclient.message_type == g_protocol_atom) |
2030 |
&& ((Atom) xevent.xclient.data.l[0] == g_kill_atom)) |
&& ((Atom) xevent.xclient.data.l[0] == g_kill_atom)) |
2031 |
/* Quit */ |
{ |
2032 |
return 0; |
/* When killing a seamless window, close the window on the |
2033 |
|
serverside instead of terminating rdesktop */ |
2034 |
|
sw = sw_get_window_by_wnd(xevent.xclient.window); |
2035 |
|
if (!sw) |
2036 |
|
/* Otherwise, quit */ |
2037 |
|
return 0; |
2038 |
|
/* send seamless destroy process message */ |
2039 |
|
seamless_send_destroy(sw->id); |
2040 |
|
} |
2041 |
break; |
break; |
2042 |
|
|
2043 |
case KeyPress: |
case KeyPress: |
2110 |
if (g_fullscreen && !g_focused) |
if (g_fullscreen && !g_focused) |
2111 |
XSetInputFocus(g_display, g_wnd, RevertToPointerRoot, |
XSetInputFocus(g_display, g_wnd, RevertToPointerRoot, |
2112 |
CurrentTime); |
CurrentTime); |
2113 |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
|
2114 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
if (xevent.xmotion.window == g_wnd) |
2115 |
|
{ |
2116 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, |
2117 |
|
xevent.xmotion.x, xevent.xmotion.y); |
2118 |
|
} |
2119 |
|
else |
2120 |
|
{ |
2121 |
|
/* SeamlessRDP */ |
2122 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, |
2123 |
|
xevent.xmotion.x_root, |
2124 |
|
xevent.xmotion.y_root); |
2125 |
|
} |
2126 |
break; |
break; |
2127 |
|
|
2128 |
case FocusIn: |
case FocusIn: |
2133 |
if (g_grab_keyboard && g_mouse_in_wnd) |
if (g_grab_keyboard && g_mouse_in_wnd) |
2134 |
XGrabKeyboard(g_display, g_wnd, True, |
XGrabKeyboard(g_display, g_wnd, True, |
2135 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
2136 |
|
|
2137 |
|
sw = sw_get_window_by_wnd(xevent.xfocus.window); |
2138 |
|
if (!sw) |
2139 |
|
break; |
2140 |
|
|
2141 |
|
if (sw->id != g_seamless_focused) |
2142 |
|
{ |
2143 |
|
seamless_send_focus(sw->id, 0); |
2144 |
|
g_seamless_focused = sw->id; |
2145 |
|
} |
2146 |
break; |
break; |
2147 |
|
|
2148 |
case FocusOut: |
case FocusOut: |
2175 |
break; |
break; |
2176 |
|
|
2177 |
case Expose: |
case Expose: |
2178 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, |
if (xevent.xexpose.window == g_wnd) |
2179 |
xevent.xexpose.x, xevent.xexpose.y, |
{ |
2180 |
xevent.xexpose.width, |
XCopyArea(g_display, g_backstore, xevent.xexpose.window, |
2181 |
xevent.xexpose.height, |
g_gc, |
2182 |
xevent.xexpose.x, xevent.xexpose.y); |
xevent.xexpose.x, xevent.xexpose.y, |
2183 |
|
xevent.xexpose.width, xevent.xexpose.height, |
2184 |
|
xevent.xexpose.x, xevent.xexpose.y); |
2185 |
|
} |
2186 |
|
else |
2187 |
|
{ |
2188 |
|
sw = sw_get_window_by_wnd(xevent.xexpose.window); |
2189 |
|
if (!sw) |
2190 |
|
break; |
2191 |
|
XCopyArea(g_display, g_backstore, |
2192 |
|
xevent.xexpose.window, g_gc, |
2193 |
|
xevent.xexpose.x + sw->xoffset, |
2194 |
|
xevent.xexpose.y + sw->yoffset, |
2195 |
|
xevent.xexpose.width, |
2196 |
|
xevent.xexpose.height, xevent.xexpose.x, |
2197 |
|
xevent.xexpose.y); |
2198 |
|
} |
2199 |
|
|
2200 |
break; |
break; |
2201 |
|
|
2202 |
case MappingNotify: |
case MappingNotify: |
2211 |
XFreeModifiermap(g_mod_map); |
XFreeModifiermap(g_mod_map); |
2212 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
2213 |
} |
} |
2214 |
|
|
2215 |
|
if (xevent.xmapping.request == MappingPointer) |
2216 |
|
{ |
2217 |
|
xwin_refresh_pointer_map(); |
2218 |
|
} |
2219 |
|
|
2220 |
break; |
break; |
2221 |
|
|
2222 |
/* clipboard stuff */ |
/* clipboard stuff */ |
2231 |
break; |
break; |
2232 |
case PropertyNotify: |
case PropertyNotify: |
2233 |
xclip_handle_PropertyNotify(&xevent.xproperty); |
xclip_handle_PropertyNotify(&xevent.xproperty); |
2234 |
|
if (xevent.xproperty.window == g_wnd) |
2235 |
|
break; |
2236 |
|
if (xevent.xproperty.window == DefaultRootWindow(g_display)) |
2237 |
|
break; |
2238 |
|
|
2239 |
|
/* seamless */ |
2240 |
|
sw = sw_get_window_by_wnd(xevent.xproperty.window); |
2241 |
|
if (!sw) |
2242 |
|
break; |
2243 |
|
|
2244 |
|
if ((xevent.xproperty.atom == g_net_wm_state_atom) |
2245 |
|
&& (xevent.xproperty.state == PropertyNewValue)) |
2246 |
|
{ |
2247 |
|
sw->state = ewmh_get_window_state(sw->wnd); |
2248 |
|
seamless_send_state(sw->id, sw->state, 0); |
2249 |
|
} |
2250 |
|
|
2251 |
|
if ((xevent.xproperty.atom == g_net_wm_desktop_atom) |
2252 |
|
&& (xevent.xproperty.state == PropertyNewValue)) |
2253 |
|
{ |
2254 |
|
sw->desktop = ewmh_get_window_desktop(sw->wnd); |
2255 |
|
sw_all_to_desktop(sw->wnd, sw->desktop); |
2256 |
|
} |
2257 |
|
|
2258 |
break; |
break; |
2259 |
case MapNotify: |
case MapNotify: |
2260 |
rdp_send_client_window_status(1); |
if (!g_seamless_active) |
2261 |
|
rdp_send_client_window_status(1); |
2262 |
break; |
break; |
2263 |
case UnmapNotify: |
case UnmapNotify: |
2264 |
rdp_send_client_window_status(0); |
if (!g_seamless_active) |
2265 |
|
rdp_send_client_window_status(0); |
2266 |
|
break; |
2267 |
|
case ConfigureNotify: |
2268 |
|
if (!g_seamless_active) |
2269 |
|
break; |
2270 |
|
|
2271 |
|
sw = sw_get_window_by_wnd(xevent.xconfigure.window); |
2272 |
|
if (!sw) |
2273 |
|
break; |
2274 |
|
|
2275 |
|
gettimeofday(sw->position_timer, NULL); |
2276 |
|
if (sw->position_timer->tv_usec + SEAMLESSRDP_POSITION_TIMER >= |
2277 |
|
1000000) |
2278 |
|
{ |
2279 |
|
sw->position_timer->tv_usec += |
2280 |
|
SEAMLESSRDP_POSITION_TIMER - 1000000; |
2281 |
|
sw->position_timer->tv_sec += 1; |
2282 |
|
} |
2283 |
|
else |
2284 |
|
{ |
2285 |
|
sw->position_timer->tv_usec += SEAMLESSRDP_POSITION_TIMER; |
2286 |
|
} |
2287 |
|
|
2288 |
|
sw_handle_restack(sw); |
2289 |
break; |
break; |
2290 |
} |
} |
2291 |
} |
} |
2300 |
int n; |
int n; |
2301 |
fd_set rfds, wfds; |
fd_set rfds, wfds; |
2302 |
struct timeval tv; |
struct timeval tv; |
2303 |
BOOL s_timeout = False; |
RD_BOOL s_timeout = False; |
2304 |
|
|
2305 |
while (True) |
while (True) |
2306 |
{ |
{ |
2310 |
/* User quit */ |
/* User quit */ |
2311 |
return 0; |
return 0; |
2312 |
|
|
2313 |
|
if (g_seamless_active) |
2314 |
|
sw_check_timers(); |
2315 |
|
|
2316 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
2317 |
FD_ZERO(&wfds); |
FD_ZERO(&wfds); |
2318 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
2319 |
FD_SET(g_x_socket, &rfds); |
FD_SET(g_x_socket, &rfds); |
2320 |
|
|
|
#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 |
|
2321 |
/* default timeout */ |
/* default timeout */ |
2322 |
tv.tv_sec = 60; |
tv.tv_sec = 60; |
2323 |
tv.tv_usec = 0; |
tv.tv_usec = 0; |
2324 |
|
|
2325 |
|
#ifdef WITH_RDPSND |
2326 |
|
rdpsnd_add_fds(&n, &rfds, &wfds, &tv); |
2327 |
|
#endif |
2328 |
|
|
2329 |
/* add redirection handles */ |
/* add redirection handles */ |
2330 |
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
2331 |
|
seamless_select_timeout(&tv); |
2332 |
|
|
2333 |
n++; |
n++; |
2334 |
|
|
2338 |
error("select: %s\n", strerror(errno)); |
error("select: %s\n", strerror(errno)); |
2339 |
|
|
2340 |
case 0: |
case 0: |
2341 |
|
#ifdef WITH_RDPSND |
2342 |
|
rdpsnd_check_fds(&rfds, &wfds); |
2343 |
|
#endif |
2344 |
|
|
2345 |
/* Abort serial read calls */ |
/* Abort serial read calls */ |
2346 |
if (s_timeout) |
if (s_timeout) |
2347 |
rdpdr_check_fds(&rfds, &wfds, (BOOL) True); |
rdpdr_check_fds(&rfds, &wfds, (RD_BOOL) True); |
2348 |
continue; |
continue; |
2349 |
} |
} |
2350 |
|
|
2351 |
rdpdr_check_fds(&rfds, &wfds, (BOOL) False); |
#ifdef WITH_RDPSND |
2352 |
|
rdpsnd_check_fds(&rfds, &wfds); |
2353 |
|
#endif |
2354 |
|
|
2355 |
|
rdpdr_check_fds(&rfds, &wfds, (RD_BOOL) False); |
2356 |
|
|
2357 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
2358 |
return 1; |
return 1; |
2359 |
|
|
|
#ifdef WITH_RDPSND |
|
|
if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds)) |
|
|
wave_out_play(); |
|
|
#endif |
|
2360 |
} |
} |
2361 |
} |
} |
2362 |
|
|
2366 |
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); |
2367 |
} |
} |
2368 |
|
|
2369 |
HBITMAP |
RD_HBITMAP |
2370 |
ui_create_bitmap(int width, int height, uint8 * data) |
ui_create_bitmap(int width, int height, uint8 * data) |
2371 |
{ |
{ |
2372 |
XImage *image; |
XImage *image; |
2374 |
uint8 *tdata; |
uint8 *tdata; |
2375 |
int bitmap_pad; |
int bitmap_pad; |
2376 |
|
|
2377 |
if (g_server_bpp == 8) |
if (g_server_depth == 8) |
2378 |
{ |
{ |
2379 |
bitmap_pad = 8; |
bitmap_pad = 8; |
2380 |
} |
} |
2396 |
XFree(image); |
XFree(image); |
2397 |
if (tdata != data) |
if (tdata != data) |
2398 |
xfree(tdata); |
xfree(tdata); |
2399 |
return (HBITMAP) bitmap; |
return (RD_HBITMAP) bitmap; |
2400 |
} |
} |
2401 |
|
|
2402 |
void |
void |
2406 |
uint8 *tdata; |
uint8 *tdata; |
2407 |
int bitmap_pad; |
int bitmap_pad; |
2408 |
|
|
2409 |
if (g_server_bpp == 8) |
if (g_server_depth == 8) |
2410 |
{ |
{ |
2411 |
bitmap_pad = 8; |
bitmap_pad = 8; |
2412 |
} |
} |
2426 |
{ |
{ |
2427 |
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); |
2428 |
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); |
2429 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
2430 |
|
(g_display, g_backstore, sw->wnd, g_gc, x, y, cx, cy, |
2431 |
|
x - sw->xoffset, y - sw->yoffset)); |
2432 |
} |
} |
2433 |
else |
else |
2434 |
{ |
{ |
2435 |
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); |
2436 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
2437 |
|
(g_display, g_wnd, sw->wnd, g_gc, x, y, cx, cy, |
2438 |
|
x - sw->xoffset, y - sw->yoffset)); |
2439 |
} |
} |
2440 |
|
|
2441 |
XFree(image); |
XFree(image); |
2444 |
} |
} |
2445 |
|
|
2446 |
void |
void |
2447 |
ui_destroy_bitmap(HBITMAP bmp) |
ui_destroy_bitmap(RD_HBITMAP bmp) |
2448 |
{ |
{ |
2449 |
XFreePixmap(g_display, (Pixmap) bmp); |
XFreePixmap(g_display, (Pixmap) bmp); |
2450 |
} |
} |
2451 |
|
|
2452 |
HGLYPH |
RD_HGLYPH |
2453 |
ui_create_glyph(int width, int height, uint8 * data) |
ui_create_glyph(int width, int height, uint8 * data) |
2454 |
{ |
{ |
2455 |
XImage *image; |
XImage *image; |
2471 |
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); |
2472 |
|
|
2473 |
XFree(image); |
XFree(image); |
2474 |
return (HGLYPH) bitmap; |
return (RD_HGLYPH) bitmap; |
2475 |
} |
} |
2476 |
|
|
2477 |
void |
void |
2478 |
ui_destroy_glyph(HGLYPH glyph) |
ui_destroy_glyph(RD_HGLYPH glyph) |
2479 |
{ |
{ |
2480 |
XFreePixmap(g_display, (Pixmap) glyph); |
XFreePixmap(g_display, (Pixmap) glyph); |
2481 |
} |
} |
2482 |
|
|
2483 |
HCURSOR |
RD_HCURSOR |
2484 |
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, |
2485 |
uint8 * andmask, uint8 * xormask) |
uint8 * andmask, uint8 * xormask) |
2486 |
{ |
{ |
2487 |
HGLYPH maskglyph, cursorglyph; |
RD_HGLYPH maskglyph, cursorglyph; |
2488 |
XColor bg, fg; |
XColor bg, fg; |
2489 |
Cursor xcursor; |
Cursor xcursor; |
2490 |
uint8 *cursor, *pcursor; |
uint8 *cursor, *pcursor; |
2548 |
ui_destroy_glyph(cursorglyph); |
ui_destroy_glyph(cursorglyph); |
2549 |
xfree(mask); |
xfree(mask); |
2550 |
xfree(cursor); |
xfree(cursor); |
2551 |
return (HCURSOR) xcursor; |
return (RD_HCURSOR) xcursor; |
2552 |
} |
} |
2553 |
|
|
2554 |
void |
void |
2555 |
ui_set_cursor(HCURSOR cursor) |
ui_set_cursor(RD_HCURSOR cursor) |
2556 |
{ |
{ |
2557 |
g_current_cursor = (Cursor) cursor; |
g_current_cursor = (Cursor) cursor; |
2558 |
XDefineCursor(g_display, g_wnd, g_current_cursor); |
XDefineCursor(g_display, g_wnd, g_current_cursor); |
2559 |
|
ON_ALL_SEAMLESS_WINDOWS(XDefineCursor, (g_display, sw->wnd, g_current_cursor)); |
2560 |
} |
} |
2561 |
|
|
2562 |
void |
void |
2563 |
ui_destroy_cursor(HCURSOR cursor) |
ui_destroy_cursor(RD_HCURSOR cursor) |
2564 |
{ |
{ |
2565 |
XFreeCursor(g_display, (Cursor) cursor); |
XFreeCursor(g_display, (Cursor) cursor); |
2566 |
} |
} |
2578 |
(xc)->flags = DoRed | DoGreen | DoBlue; |
(xc)->flags = DoRed | DoGreen | DoBlue; |
2579 |
|
|
2580 |
|
|
2581 |
HCOLOURMAP |
RD_HCOLOURMAP |
2582 |
ui_create_colourmap(COLOURMAP * colours) |
ui_create_colourmap(COLOURMAP * colours) |
2583 |
{ |
{ |
2584 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
2674 |
XStoreColors(g_display, map, xcolours, ncolours); |
XStoreColors(g_display, map, xcolours, ncolours); |
2675 |
|
|
2676 |
xfree(xcolours); |
xfree(xcolours); |
2677 |
return (HCOLOURMAP) map; |
return (RD_HCOLOURMAP) map; |
2678 |
} |
} |
2679 |
} |
} |
2680 |
|
|
2681 |
void |
void |
2682 |
ui_destroy_colourmap(HCOLOURMAP map) |
ui_destroy_colourmap(RD_HCOLOURMAP map) |
2683 |
{ |
{ |
2684 |
if (!g_owncolmap) |
if (!g_owncolmap) |
2685 |
xfree(map); |
xfree(map); |
2688 |
} |
} |
2689 |
|
|
2690 |
void |
void |
2691 |
ui_set_colourmap(HCOLOURMAP map) |
ui_set_colourmap(RD_HCOLOURMAP map) |
2692 |
{ |
{ |
2693 |
if (!g_owncolmap) |
if (!g_owncolmap) |
2694 |
{ |
{ |
2698 |
g_colmap = (uint32 *) map; |
g_colmap = (uint32 *) map; |
2699 |
} |
} |
2700 |
else |
else |
2701 |
|
{ |
2702 |
XSetWindowColormap(g_display, g_wnd, (Colormap) map); |
XSetWindowColormap(g_display, g_wnd, (Colormap) map); |
2703 |
|
ON_ALL_SEAMLESS_WINDOWS(XSetWindowColormap, (g_display, sw->wnd, (Colormap) map)); |
2704 |
|
} |
2705 |
} |
} |
2706 |
|
|
2707 |
void |
void |
2708 |
ui_set_clip(int x, int y, int cx, int cy) |
ui_set_clip(int x, int y, int cx, int cy) |
2709 |
{ |
{ |
2710 |
XRectangle rect; |
g_clip_rectangle.x = x; |
2711 |
|
g_clip_rectangle.y = y; |
2712 |
rect.x = x; |
g_clip_rectangle.width = cx; |
2713 |
rect.y = y; |
g_clip_rectangle.height = cy; |
2714 |
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); |
|
2715 |
} |
} |
2716 |
|
|
2717 |
void |
void |
2718 |
ui_reset_clip(void) |
ui_reset_clip(void) |
2719 |
{ |
{ |
2720 |
XRectangle rect; |
g_clip_rectangle.x = 0; |
2721 |
|
g_clip_rectangle.y = 0; |
2722 |
rect.x = 0; |
g_clip_rectangle.width = g_width; |
2723 |
rect.y = 0; |
g_clip_rectangle.height = g_height; |
2724 |
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); |
|
2725 |
} |
} |
2726 |
|
|
2727 |
void |
void |
2776 |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
2777 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
2778 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
2779 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
2780 |
break; |
break; |
2781 |
|
|
2782 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
2791 |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
2792 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
2793 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
2794 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
2795 |
break; |
break; |
2796 |
|
|
2797 |
default: |
default: |
2802 |
|
|
2803 |
if (g_ownbackstore) |
if (g_ownbackstore) |
2804 |
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); |
2805 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
2806 |
|
(g_display, g_ownbackstore ? g_backstore : g_wnd, sw->wnd, g_gc, |
2807 |
|
x, y, cx, cy, x - sw->xoffset, y - sw->yoffset)); |
2808 |
} |
} |
2809 |
|
|
2810 |
void |
void |
2815 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
2816 |
if (g_ownbackstore) |
if (g_ownbackstore) |
2817 |
{ |
{ |
2818 |
if (g_Unobscured) |
XCopyArea(g_display, g_Unobscured ? g_wnd : g_backstore, |
2819 |
{ |
g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
2820 |
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); |
|
|
} |
|
2821 |
} |
} |
2822 |
else |
else |
2823 |
{ |
{ |
2824 |
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); |
2825 |
} |
} |
2826 |
|
|
2827 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
2828 |
|
(g_display, g_ownbackstore ? g_backstore : g_wnd, |
2829 |
|
sw->wnd, g_gc, x, y, cx, cy, x - sw->xoffset, y - sw->yoffset)); |
2830 |
|
|
2831 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
2832 |
} |
} |
2833 |
|
|
2834 |
void |
void |
2835 |
ui_memblt(uint8 opcode, |
ui_memblt(uint8 opcode, |
2836 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
2837 |
/* src */ HBITMAP src, int srcx, int srcy) |
/* src */ RD_HBITMAP src, int srcx, int srcy) |
2838 |
{ |
{ |
2839 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
2840 |
XCopyArea(g_display, (Pixmap) src, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
XCopyArea(g_display, (Pixmap) src, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); |
2841 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
2842 |
|
(g_display, (Pixmap) src, sw->wnd, g_gc, |
2843 |
|
srcx, srcy, cx, cy, x - sw->xoffset, y - sw->yoffset)); |
2844 |
if (g_ownbackstore) |
if (g_ownbackstore) |
2845 |
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); |
2846 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
2849 |
void |
void |
2850 |
ui_triblt(uint8 opcode, |
ui_triblt(uint8 opcode, |
2851 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
2852 |
/* src */ HBITMAP src, int srcx, int srcy, |
/* src */ RD_HBITMAP src, int srcx, int srcy, |
2853 |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
2854 |
{ |
{ |
2855 |
/* This is potentially difficult to do in general. Until someone |
/* This is potentially difficult to do in general. Until someone |
2887 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
2888 |
SET_FOREGROUND(pen->colour); |
SET_FOREGROUND(pen->colour); |
2889 |
XDrawLine(g_display, g_wnd, g_gc, startx, starty, endx, endy); |
XDrawLine(g_display, g_wnd, g_gc, startx, starty, endx, endy); |
2890 |
|
ON_ALL_SEAMLESS_WINDOWS(XDrawLine, (g_display, sw->wnd, g_gc, |
2891 |
|
startx - sw->xoffset, starty - sw->yoffset, |
2892 |
|
endx - sw->xoffset, endy - sw->yoffset)); |
2893 |
if (g_ownbackstore) |
if (g_ownbackstore) |
2894 |
XDrawLine(g_display, g_backstore, g_gc, startx, starty, endx, endy); |
XDrawLine(g_display, g_backstore, g_gc, startx, starty, endx, endy); |
2895 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
2907 |
void |
void |
2908 |
ui_polygon(uint8 opcode, |
ui_polygon(uint8 opcode, |
2909 |
/* mode */ uint8 fillmode, |
/* mode */ uint8 fillmode, |
2910 |
/* dest */ POINT * point, int npoints, |
/* dest */ RD_POINT * point, int npoints, |
2911 |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
/* brush */ BRUSH * brush, int bgcolour, int fgcolour) |
2912 |
{ |
{ |
2913 |
uint8 style, i, ipattern[8]; |
uint8 style, i, ipattern[8]; |
2950 |
FILL_POLYGON((XPoint *) point, npoints); |
FILL_POLYGON((XPoint *) point, npoints); |
2951 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
2952 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
2953 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
2954 |
break; |
break; |
2955 |
|
|
2956 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
2965 |
FILL_POLYGON((XPoint *) point, npoints); |
FILL_POLYGON((XPoint *) point, npoints); |
2966 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
2967 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
2968 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
2969 |
break; |
break; |
2970 |
|
|
2971 |
default: |
default: |
2977 |
|
|
2978 |
void |
void |
2979 |
ui_polyline(uint8 opcode, |
ui_polyline(uint8 opcode, |
2980 |
/* dest */ POINT * points, int npoints, |
/* dest */ RD_POINT * points, int npoints, |
2981 |
/* pen */ PEN * pen) |
/* pen */ PEN * pen) |
2982 |
{ |
{ |
2983 |
/* TODO: set join style */ |
/* TODO: set join style */ |
2987 |
if (g_ownbackstore) |
if (g_ownbackstore) |
2988 |
XDrawLines(g_display, g_backstore, g_gc, (XPoint *) points, npoints, |
XDrawLines(g_display, g_backstore, g_gc, (XPoint *) points, npoints, |
2989 |
CoordModePrevious); |
CoordModePrevious); |
2990 |
|
|
2991 |
|
ON_ALL_SEAMLESS_WINDOWS(seamless_XDrawLines, |
2992 |
|
(sw->wnd, (XPoint *) points, npoints, sw->xoffset, sw->yoffset)); |
2993 |
|
|
2994 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
2995 |
} |
} |
2996 |
|
|
3028 |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
3029 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3030 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3031 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3032 |
break; |
break; |
3033 |
|
|
3034 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
3043 |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
DRAW_ELLIPSE(x, y, cx, cy, fillmode); |
3044 |
XSetFillStyle(g_display, g_gc, FillSolid); |
XSetFillStyle(g_display, g_gc, FillSolid); |
3045 |
XSetTSOrigin(g_display, g_gc, 0, 0); |
XSetTSOrigin(g_display, g_gc, 0, 0); |
3046 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((RD_HGLYPH) fill); |
3047 |
break; |
break; |
3048 |
|
|
3049 |
default: |
default: |
3057 |
void |
void |
3058 |
ui_draw_glyph(int mixmode, |
ui_draw_glyph(int mixmode, |
3059 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
3060 |
/* src */ HGLYPH glyph, int srcx, int srcy, |
/* src */ RD_HGLYPH glyph, int srcx, int srcy, |
3061 |
int bgcolour, int fgcolour) |
int bgcolour, int fgcolour) |
3062 |
{ |
{ |
3063 |
SET_FOREGROUND(fgcolour); |
SET_FOREGROUND(fgcolour); |
3146 |
switch (text[i]) |
switch (text[i]) |
3147 |
{ |
{ |
3148 |
case 0xff: |
case 0xff: |
3149 |
if (i + 2 < length) |
/* At least two bytes needs to follow */ |
3150 |
cache_put_text(text[i + 1], text, text[i + 2]); |
if (i + 3 > length) |
|
else |
|
3151 |
{ |
{ |
3152 |
error("this shouldn't be happening\n"); |
warning("Skipping short 0xff command:"); |
3153 |
exit(1); |
for (j = 0; j < length; j++) |
3154 |
|
fprintf(stderr, "%02x ", text[j]); |
3155 |
|
fprintf(stderr, "\n"); |
3156 |
|
i = length = 0; |
3157 |
|
break; |
3158 |
} |
} |
3159 |
|
cache_put_text(text[i + 1], text, text[i + 2]); |
3160 |
|
i += 3; |
3161 |
|
length -= i; |
3162 |
/* this will move pointer from start to first character after FF command */ |
/* this will move pointer from start to first character after FF command */ |
3163 |
length -= i + 3; |
text = &(text[i]); |
|
text = &(text[i + 3]); |
|
3164 |
i = 0; |
i = 0; |
3165 |
break; |
break; |
3166 |
|
|
3167 |
case 0xfe: |
case 0xfe: |
3168 |
|
/* At least one byte needs to follow */ |
3169 |
|
if (i + 2 > length) |
3170 |
|
{ |
3171 |
|
warning("Skipping short 0xfe command:"); |
3172 |
|
for (j = 0; j < length; j++) |
3173 |
|
fprintf(stderr, "%02x ", text[j]); |
3174 |
|
fprintf(stderr, "\n"); |
3175 |
|
i = length = 0; |
3176 |
|
break; |
3177 |
|
} |
3178 |
entry = cache_get_text(text[i + 1]); |
entry = cache_get_text(text[i + 1]); |
3179 |
if (entry != NULL) |
if (entry->data != NULL) |
3180 |
{ |
{ |
3181 |
if ((((uint8 *) (entry->data))[1] == |
if ((((uint8 *) (entry->data))[1] == 0) |
3182 |
0) && (!(flags & TEXT2_IMPLICIT_X))) |
&& (!(flags & TEXT2_IMPLICIT_X)) && (i + 2 < length)) |
3183 |
{ |
{ |
3184 |
if (flags & TEXT2_VERTICAL) |
if (flags & TEXT2_VERTICAL) |
3185 |
y += text[i + 2]; |
y += text[i + 2]; |
3211 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3212 |
{ |
{ |
3213 |
if (boxcx > 1) |
if (boxcx > 1) |
3214 |
|
{ |
3215 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, boxx, |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, boxx, |
3216 |
boxy, boxcx, boxcy, boxx, boxy); |
boxy, boxcx, boxcy, boxx, boxy); |
3217 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3218 |
|
(g_display, g_backstore, sw->wnd, g_gc, |
3219 |
|
boxx, boxy, |
3220 |
|
boxcx, boxcy, |
3221 |
|
boxx - sw->xoffset, boxy - sw->yoffset)); |
3222 |
|
} |
3223 |
else |
else |
3224 |
|
{ |
3225 |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, clipx, |
XCopyArea(g_display, g_backstore, g_wnd, g_gc, clipx, |
3226 |
clipy, clipcx, clipcy, clipx, clipy); |
clipy, clipcx, clipcy, clipx, clipy); |
3227 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3228 |
|
(g_display, g_backstore, sw->wnd, g_gc, |
3229 |
|
clipx, clipy, |
3230 |
|
clipcx, clipcy, clipx - sw->xoffset, |
3231 |
|
clipy - sw->yoffset)); |
3232 |
|
} |
3233 |
} |
} |
3234 |
} |
} |
3235 |
|
|
3242 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3243 |
{ |
{ |
3244 |
image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap); |
image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap); |
3245 |
|
exit_if_null(image); |
3246 |
} |
} |
3247 |
else |
else |
3248 |
{ |
{ |
3249 |
pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth); |
pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth); |
3250 |
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); |
3251 |
image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap); |
image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap); |
3252 |
|
exit_if_null(image); |
3253 |
XFreePixmap(g_display, pix); |
XFreePixmap(g_display, pix); |
3254 |
} |
} |
3255 |
|
|
3271 |
return; |
return; |
3272 |
|
|
3273 |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
3274 |
(char *) data, cx, cy, BitmapPad(g_display), cx * g_bpp / 8); |
(char *) data, cx, cy, g_bpp, 0); |
3275 |
|
|
3276 |
if (g_ownbackstore) |
if (g_ownbackstore) |
3277 |
{ |
{ |
3278 |
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); |
3279 |
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); |
3280 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3281 |
|
(g_display, g_backstore, sw->wnd, g_gc, |
3282 |
|
x, y, cx, cy, x - sw->xoffset, y - sw->yoffset)); |
3283 |
} |
} |
3284 |
else |
else |
3285 |
{ |
{ |
3286 |
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); |
3287 |
|
ON_ALL_SEAMLESS_WINDOWS(XCopyArea, |
3288 |
|
(g_display, g_wnd, sw->wnd, g_gc, x, y, cx, cy, |
3289 |
|
x - sw->xoffset, y - sw->yoffset)); |
3290 |
} |
} |
3291 |
|
|
3292 |
XFree(image); |
XFree(image); |
3302 |
ui_end_update(void) |
ui_end_update(void) |
3303 |
{ |
{ |
3304 |
} |
} |
3305 |
|
|
3306 |
|
|
3307 |
|
void |
3308 |
|
ui_seamless_begin(RD_BOOL hidden) |
3309 |
|
{ |
3310 |
|
if (!g_seamless_rdp) |
3311 |
|
return; |
3312 |
|
|
3313 |
|
if (g_seamless_started) |
3314 |
|
return; |
3315 |
|
|
3316 |
|
g_seamless_started = True; |
3317 |
|
g_seamless_hidden = hidden; |
3318 |
|
|
3319 |
|
if (!hidden) |
3320 |
|
ui_seamless_toggle(); |
3321 |
|
} |
3322 |
|
|
3323 |
|
|
3324 |
|
void |
3325 |
|
ui_seamless_hide_desktop() |
3326 |
|
{ |
3327 |
|
if (!g_seamless_rdp) |
3328 |
|
return; |
3329 |
|
|
3330 |
|
if (!g_seamless_started) |
3331 |
|
return; |
3332 |
|
|
3333 |
|
if (g_seamless_active) |
3334 |
|
ui_seamless_toggle(); |
3335 |
|
|
3336 |
|
g_seamless_hidden = True; |
3337 |
|
} |
3338 |
|
|
3339 |
|
|
3340 |
|
void |
3341 |
|
ui_seamless_unhide_desktop() |
3342 |
|
{ |
3343 |
|
if (!g_seamless_rdp) |
3344 |
|
return; |
3345 |
|
|
3346 |
|
if (!g_seamless_started) |
3347 |
|
return; |
3348 |
|
|
3349 |
|
g_seamless_hidden = False; |
3350 |
|
|
3351 |
|
ui_seamless_toggle(); |
3352 |
|
} |
3353 |
|
|
3354 |
|
|
3355 |
|
void |
3356 |
|
ui_seamless_toggle() |
3357 |
|
{ |
3358 |
|
if (!g_seamless_rdp) |
3359 |
|
return; |
3360 |
|
|
3361 |
|
if (!g_seamless_started) |
3362 |
|
return; |
3363 |
|
|
3364 |
|
if (g_seamless_hidden) |
3365 |
|
return; |
3366 |
|
|
3367 |
|
if (g_seamless_active) |
3368 |
|
{ |
3369 |
|
/* Deactivate */ |
3370 |
|
while (g_seamless_windows) |
3371 |
|
{ |
3372 |
|
XDestroyWindow(g_display, g_seamless_windows->wnd); |
3373 |
|
sw_remove_window(g_seamless_windows); |
3374 |
|
} |
3375 |
|
XMapWindow(g_display, g_wnd); |
3376 |
|
} |
3377 |
|
else |
3378 |
|
{ |
3379 |
|
/* Activate */ |
3380 |
|
XUnmapWindow(g_display, g_wnd); |
3381 |
|
seamless_send_sync(); |
3382 |
|
} |
3383 |
|
|
3384 |
|
g_seamless_active = !g_seamless_active; |
3385 |
|
} |
3386 |
|
|
3387 |
|
|
3388 |
|
void |
3389 |
|
ui_seamless_create_window(unsigned long id, unsigned long group, unsigned long parent, |
3390 |
|
unsigned long flags) |
3391 |
|
{ |
3392 |
|
Window wnd; |
3393 |
|
XSetWindowAttributes attribs; |
3394 |
|
XClassHint *classhints; |
3395 |
|
XSizeHints *sizehints; |
3396 |
|
XWMHints *wmhints; |
3397 |
|
long input_mask; |
3398 |
|
seamless_window *sw, *sw_parent; |
3399 |
|
|
3400 |
|
if (!g_seamless_active) |
3401 |
|
return; |
3402 |
|
|
3403 |
|
/* Ignore CREATEs for existing windows */ |
3404 |
|
sw = sw_get_window_by_id(id); |
3405 |
|
if (sw) |
3406 |
|
return; |
3407 |
|
|
3408 |
|
get_window_attribs(&attribs); |
3409 |
|
wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0, g_depth, |
3410 |
|
InputOutput, g_visual, |
3411 |
|
CWBackPixel | CWBackingStore | CWColormap | CWBorderPixel, &attribs); |
3412 |
|
|
3413 |
|
XStoreName(g_display, wnd, "SeamlessRDP"); |
3414 |
|
ewmh_set_wm_name(wnd, "SeamlessRDP"); |
3415 |
|
|
3416 |
|
mwm_hide_decorations(wnd); |
3417 |
|
|
3418 |
|
classhints = XAllocClassHint(); |
3419 |
|
if (classhints != NULL) |
3420 |
|
{ |
3421 |
|
classhints->res_name = "rdesktop"; |
3422 |
|
classhints->res_class = "SeamlessRDP"; |
3423 |
|
XSetClassHint(g_display, wnd, classhints); |
3424 |
|
XFree(classhints); |
3425 |
|
} |
3426 |
|
|
3427 |
|
/* WM_NORMAL_HINTS */ |
3428 |
|
sizehints = XAllocSizeHints(); |
3429 |
|
if (sizehints != NULL) |
3430 |
|
{ |
3431 |
|
sizehints->flags = USPosition; |
3432 |
|
XSetWMNormalHints(g_display, wnd, sizehints); |
3433 |
|
XFree(sizehints); |
3434 |
|
} |
3435 |
|
|
3436 |
|
/* Parent-less transient windows */ |
3437 |
|
if (parent == 0xFFFFFFFF) |
3438 |
|
{ |
3439 |
|
XSetTransientForHint(g_display, wnd, RootWindowOfScreen(g_screen)); |
3440 |
|
/* Some buggy wm:s (kwin) do not handle the above, so fake it |
3441 |
|
using some other hints. */ |
3442 |
|
ewmh_set_window_popup(wnd); |
3443 |
|
} |
3444 |
|
/* Normal transient windows */ |
3445 |
|
else if (parent != 0x00000000) |
3446 |
|
{ |
3447 |
|
sw_parent = sw_get_window_by_id(parent); |
3448 |
|
if (sw_parent) |
3449 |
|
XSetTransientForHint(g_display, wnd, sw_parent->wnd); |
3450 |
|
else |
3451 |
|
warning("ui_seamless_create_window: No parent window 0x%lx\n", parent); |
3452 |
|
} |
3453 |
|
|
3454 |
|
if (flags & SEAMLESSRDP_CREATE_MODAL) |
3455 |
|
{ |
3456 |
|
/* We do this to support buggy wm:s (*cough* metacity *cough*) |
3457 |
|
somewhat at least */ |
3458 |
|
if (parent == 0x00000000) |
3459 |
|
XSetTransientForHint(g_display, wnd, RootWindowOfScreen(g_screen)); |
3460 |
|
ewmh_set_window_modal(wnd); |
3461 |
|
} |
3462 |
|
|
3463 |
|
if (flags & SEAMLESSRDP_CREATE_TOPMOST) |
3464 |
|
{ |
3465 |
|
/* Make window always-on-top */ |
3466 |
|
ewmh_set_window_above(wnd); |
3467 |
|
} |
3468 |
|
|
3469 |
|
/* FIXME: Support for Input Context:s */ |
3470 |
|
|
3471 |
|
get_input_mask(&input_mask); |
3472 |
|
input_mask |= PropertyChangeMask; |
3473 |
|
|
3474 |
|
XSelectInput(g_display, wnd, input_mask); |
3475 |
|
|
3476 |
|
/* handle the WM_DELETE_WINDOW protocol. */ |
3477 |
|
XSetWMProtocols(g_display, wnd, &g_kill_atom, 1); |
3478 |
|
|
3479 |
|
sw = xmalloc(sizeof(seamless_window)); |
3480 |
|
|
3481 |
|
memset(sw, 0, sizeof(seamless_window)); |
3482 |
|
|
3483 |
|
sw->wnd = wnd; |
3484 |
|
sw->id = id; |
3485 |
|
sw->group = sw_find_group(group, False); |
3486 |
|
sw->group->refcnt++; |
3487 |
|
sw->state = SEAMLESSRDP_NOTYETMAPPED; |
3488 |
|
sw->desktop = 0; |
3489 |
|
sw->position_timer = xmalloc(sizeof(struct timeval)); |
3490 |
|
timerclear(sw->position_timer); |
3491 |
|
|
3492 |
|
sw->outstanding_position = False; |
3493 |
|
sw->outpos_serial = 0; |
3494 |
|
sw->outpos_xoffset = sw->outpos_yoffset = 0; |
3495 |
|
sw->outpos_width = sw->outpos_height = 0; |
3496 |
|
|
3497 |
|
sw->next = g_seamless_windows; |
3498 |
|
g_seamless_windows = sw; |
3499 |
|
|
3500 |
|
/* WM_HINTS */ |
3501 |
|
wmhints = XAllocWMHints(); |
3502 |
|
if (wmhints) |
3503 |
|
{ |
3504 |
|
wmhints->flags = WindowGroupHint; |
3505 |
|
wmhints->window_group = sw->group->wnd; |
3506 |
|
XSetWMHints(g_display, sw->wnd, wmhints); |
3507 |
|
XFree(wmhints); |
3508 |
|
} |
3509 |
|
} |
3510 |
|
|
3511 |
|
|
3512 |
|
void |
3513 |
|
ui_seamless_destroy_window(unsigned long id, unsigned long flags) |
3514 |
|
{ |
3515 |
|
seamless_window *sw; |
3516 |
|
|
3517 |
|
if (!g_seamless_active) |
3518 |
|
return; |
3519 |
|
|
3520 |
|
sw = sw_get_window_by_id(id); |
3521 |
|
if (!sw) |
3522 |
|
{ |
3523 |
|
warning("ui_seamless_destroy_window: No information for window 0x%lx\n", id); |
3524 |
|
return; |
3525 |
|
} |
3526 |
|
|
3527 |
|
XDestroyWindow(g_display, sw->wnd); |
3528 |
|
sw_remove_window(sw); |
3529 |
|
} |
3530 |
|
|
3531 |
|
|
3532 |
|
void |
3533 |
|
ui_seamless_destroy_group(unsigned long id, unsigned long flags) |
3534 |
|
{ |
3535 |
|
seamless_window *sw, *sw_next; |
3536 |
|
|
3537 |
|
if (!g_seamless_active) |
3538 |
|
return; |
3539 |
|
|
3540 |
|
for (sw = g_seamless_windows; sw; sw = sw_next) |
3541 |
|
{ |
3542 |
|
sw_next = sw->next; |
3543 |
|
|
3544 |
|
if (sw->group->id == id) |
3545 |
|
{ |
3546 |
|
XDestroyWindow(g_display, sw->wnd); |
3547 |
|
sw_remove_window(sw); |
3548 |
|
} |
3549 |
|
} |
3550 |
|
} |
3551 |
|
|
3552 |
|
|
3553 |
|
void |
3554 |
|
ui_seamless_seticon(unsigned long id, const char *format, int width, int height, int chunk, |
3555 |
|
const char *data, int chunk_len) |
3556 |
|
{ |
3557 |
|
seamless_window *sw; |
3558 |
|
|
3559 |
|
if (!g_seamless_active) |
3560 |
|
return; |
3561 |
|
|
3562 |
|
sw = sw_get_window_by_id(id); |
3563 |
|
if (!sw) |
3564 |
|
{ |
3565 |
|
warning("ui_seamless_seticon: No information for window 0x%lx\n", id); |
3566 |
|
return; |
3567 |
|
} |
3568 |
|
|
3569 |
|
if (chunk == 0) |
3570 |
|
{ |
3571 |
|
if (sw->icon_size) |
3572 |
|
warning("ui_seamless_seticon: New icon started before previous completed\n"); |
3573 |
|
|
3574 |
|
if (strcmp(format, "RGBA") != 0) |
3575 |
|
{ |
3576 |
|
warning("ui_seamless_seticon: Uknown icon format \"%s\"\n", format); |
3577 |
|
return; |
3578 |
|
} |
3579 |
|
|
3580 |
|
sw->icon_size = width * height * 4; |
3581 |
|
if (sw->icon_size > 32 * 32 * 4) |
3582 |
|
{ |
3583 |
|
warning("ui_seamless_seticon: Icon too large (%d bytes)\n", sw->icon_size); |
3584 |
|
sw->icon_size = 0; |
3585 |
|
return; |
3586 |
|
} |
3587 |
|
|
3588 |
|
sw->icon_offset = 0; |
3589 |
|
} |
3590 |
|
else |
3591 |
|
{ |
3592 |
|
if (!sw->icon_size) |
3593 |
|
return; |
3594 |
|
} |
3595 |
|
|
3596 |
|
if (chunk_len > (sw->icon_size - sw->icon_offset)) |
3597 |
|
{ |
3598 |
|
warning("ui_seamless_seticon: Too large chunk received (%d bytes > %d bytes)\n", |
3599 |
|
chunk_len, sw->icon_size - sw->icon_offset); |
3600 |
|
sw->icon_size = 0; |
3601 |
|
return; |
3602 |
|
} |
3603 |
|
|
3604 |
|
memcpy(sw->icon_buffer + sw->icon_offset, data, chunk_len); |
3605 |
|
sw->icon_offset += chunk_len; |
3606 |
|
|
3607 |
|
if (sw->icon_offset == sw->icon_size) |
3608 |
|
{ |
3609 |
|
ewmh_set_icon(sw->wnd, width, height, sw->icon_buffer); |
3610 |
|
sw->icon_size = 0; |
3611 |
|
} |
3612 |
|
} |
3613 |
|
|
3614 |
|
|
3615 |
|
void |
3616 |
|
ui_seamless_delicon(unsigned long id, const char *format, int width, int height) |
3617 |
|
{ |
3618 |
|
seamless_window *sw; |
3619 |
|
|
3620 |
|
if (!g_seamless_active) |
3621 |
|
return; |
3622 |
|
|
3623 |
|
sw = sw_get_window_by_id(id); |
3624 |
|
if (!sw) |
3625 |
|
{ |
3626 |
|
warning("ui_seamless_seticon: No information for window 0x%lx\n", id); |
3627 |
|
return; |
3628 |
|
} |
3629 |
|
|
3630 |
|
if (strcmp(format, "RGBA") != 0) |
3631 |
|
{ |
3632 |
|
warning("ui_seamless_seticon: Uknown icon format \"%s\"\n", format); |
3633 |
|
return; |
3634 |
|
} |
3635 |
|
|
3636 |
|
ewmh_del_icon(sw->wnd, width, height); |
3637 |
|
} |
3638 |
|
|
3639 |
|
|
3640 |
|
void |
3641 |
|
ui_seamless_move_window(unsigned long id, int x, int y, int width, int height, unsigned long flags) |
3642 |
|
{ |
3643 |
|
seamless_window *sw; |
3644 |
|
|
3645 |
|
if (!g_seamless_active) |
3646 |
|
return; |
3647 |
|
|
3648 |
|
sw = sw_get_window_by_id(id); |
3649 |
|
if (!sw) |
3650 |
|
{ |
3651 |
|
warning("ui_seamless_move_window: No information for window 0x%lx\n", id); |
3652 |
|
return; |
3653 |
|
} |
3654 |
|
|
3655 |
|
/* We ignore server updates until it has handled our request. */ |
3656 |
|
if (sw->outstanding_position) |
3657 |
|
return; |
3658 |
|
|
3659 |
|
if (!width || !height) |
3660 |
|
/* X11 windows must be at least 1x1 */ |
3661 |
|
return; |
3662 |
|
|
3663 |
|
sw->xoffset = x; |
3664 |
|
sw->yoffset = y; |
3665 |
|
sw->width = width; |
3666 |
|
sw->height = height; |
3667 |
|
|
3668 |
|
/* If we move the window in a maximized state, then KDE won't |
3669 |
|
accept restoration */ |
3670 |
|
switch (sw->state) |
3671 |
|
{ |
3672 |
|
case SEAMLESSRDP_MINIMIZED: |
3673 |
|
case SEAMLESSRDP_MAXIMIZED: |
3674 |
|
return; |
3675 |
|
} |
3676 |
|
|
3677 |
|
/* FIXME: Perhaps use ewmh_net_moveresize_window instead */ |
3678 |
|
XMoveResizeWindow(g_display, sw->wnd, sw->xoffset, sw->yoffset, sw->width, sw->height); |
3679 |
|
} |
3680 |
|
|
3681 |
|
|
3682 |
|
void |
3683 |
|
ui_seamless_restack_window(unsigned long id, unsigned long behind, unsigned long flags) |
3684 |
|
{ |
3685 |
|
seamless_window *sw; |
3686 |
|
|
3687 |
|
if (!g_seamless_active) |
3688 |
|
return; |
3689 |
|
|
3690 |
|
sw = sw_get_window_by_id(id); |
3691 |
|
if (!sw) |
3692 |
|
{ |
3693 |
|
warning("ui_seamless_restack_window: No information for window 0x%lx\n", id); |
3694 |
|
return; |
3695 |
|
} |
3696 |
|
|
3697 |
|
if (behind) |
3698 |
|
{ |
3699 |
|
seamless_window *sw_behind; |
3700 |
|
Window wnds[2]; |
3701 |
|
|
3702 |
|
sw_behind = sw_get_window_by_id(behind); |
3703 |
|
if (!sw_behind) |
3704 |
|
{ |
3705 |
|
warning("ui_seamless_restack_window: No information for window 0x%lx\n", |
3706 |
|
behind); |
3707 |
|
return; |
3708 |
|
} |
3709 |
|
|
3710 |
|
wnds[1] = sw_behind->wnd; |
3711 |
|
wnds[0] = sw->wnd; |
3712 |
|
|
3713 |
|
XRestackWindows(g_display, wnds, 2); |
3714 |
|
} |
3715 |
|
else |
3716 |
|
{ |
3717 |
|
XRaiseWindow(g_display, sw->wnd); |
3718 |
|
} |
3719 |
|
|
3720 |
|
sw_restack_window(sw, behind); |
3721 |
|
|
3722 |
|
if (flags & SEAMLESSRDP_CREATE_TOPMOST) |
3723 |
|
{ |
3724 |
|
/* Make window always-on-top */ |
3725 |
|
ewmh_set_window_above(sw->wnd); |
3726 |
|
} |
3727 |
|
} |
3728 |
|
|
3729 |
|
|
3730 |
|
void |
3731 |
|
ui_seamless_settitle(unsigned long id, const char *title, unsigned long flags) |
3732 |
|
{ |
3733 |
|
seamless_window *sw; |
3734 |
|
|
3735 |
|
if (!g_seamless_active) |
3736 |
|
return; |
3737 |
|
|
3738 |
|
sw = sw_get_window_by_id(id); |
3739 |
|
if (!sw) |
3740 |
|
{ |
3741 |
|
warning("ui_seamless_settitle: No information for window 0x%lx\n", id); |
3742 |
|
return; |
3743 |
|
} |
3744 |
|
|
3745 |
|
/* FIXME: Might want to convert the name for non-EWMH WMs */ |
3746 |
|
XStoreName(g_display, sw->wnd, title); |
3747 |
|
ewmh_set_wm_name(sw->wnd, title); |
3748 |
|
} |
3749 |
|
|
3750 |
|
|
3751 |
|
void |
3752 |
|
ui_seamless_setstate(unsigned long id, unsigned int state, unsigned long flags) |
3753 |
|
{ |
3754 |
|
seamless_window *sw; |
3755 |
|
|
3756 |
|
if (!g_seamless_active) |
3757 |
|
return; |
3758 |
|
|
3759 |
|
sw = sw_get_window_by_id(id); |
3760 |
|
if (!sw) |
3761 |
|
{ |
3762 |
|
warning("ui_seamless_setstate: No information for window 0x%lx\n", id); |
3763 |
|
return; |
3764 |
|
} |
3765 |
|
|
3766 |
|
switch (state) |
3767 |
|
{ |
3768 |
|
case SEAMLESSRDP_NORMAL: |
3769 |
|
case SEAMLESSRDP_MAXIMIZED: |
3770 |
|
ewmh_change_state(sw->wnd, state); |
3771 |
|
XMapWindow(g_display, sw->wnd); |
3772 |
|
break; |
3773 |
|
case SEAMLESSRDP_MINIMIZED: |
3774 |
|
/* EWMH says: "if an Application asks to toggle _NET_WM_STATE_HIDDEN |
3775 |
|
the Window Manager should probably just ignore the request, since |
3776 |
|
_NET_WM_STATE_HIDDEN is a function of some other aspect of the window |
3777 |
|
such as minimization, rather than an independent state." Besides, |
3778 |
|
XIconifyWindow is easier. */ |
3779 |
|
if (sw->state == SEAMLESSRDP_NOTYETMAPPED) |
3780 |
|
{ |
3781 |
|
XWMHints *hints; |
3782 |
|
hints = XGetWMHints(g_display, sw->wnd); |
3783 |
|
if (hints) |
3784 |
|
{ |
3785 |
|
hints->flags |= StateHint; |
3786 |
|
hints->initial_state = IconicState; |
3787 |
|
XSetWMHints(g_display, sw->wnd, hints); |
3788 |
|
XFree(hints); |
3789 |
|
} |
3790 |
|
XMapWindow(g_display, sw->wnd); |
3791 |
|
} |
3792 |
|
else |
3793 |
|
XIconifyWindow(g_display, sw->wnd, DefaultScreen(g_display)); |
3794 |
|
break; |
3795 |
|
default: |
3796 |
|
warning("SeamlessRDP: Invalid state %d\n", state); |
3797 |
|
break; |
3798 |
|
} |
3799 |
|
|
3800 |
|
sw->state = state; |
3801 |
|
} |
3802 |
|
|
3803 |
|
|
3804 |
|
void |
3805 |
|
ui_seamless_syncbegin(unsigned long flags) |
3806 |
|
{ |
3807 |
|
if (!g_seamless_active) |
3808 |
|
return; |
3809 |
|
|
3810 |
|
/* Destroy all seamless windows */ |
3811 |
|
while (g_seamless_windows) |
3812 |
|
{ |
3813 |
|
XDestroyWindow(g_display, g_seamless_windows->wnd); |
3814 |
|
sw_remove_window(g_seamless_windows); |
3815 |
|
} |
3816 |
|
} |
3817 |
|
|
3818 |
|
|
3819 |
|
void |
3820 |
|
ui_seamless_ack(unsigned int serial) |
3821 |
|
{ |
3822 |
|
seamless_window *sw; |
3823 |
|
for (sw = g_seamless_windows; sw; sw = sw->next) |
3824 |
|
{ |
3825 |
|
if (sw->outstanding_position && (sw->outpos_serial == serial)) |
3826 |
|
{ |
3827 |
|
sw->xoffset = sw->outpos_xoffset; |
3828 |
|
sw->yoffset = sw->outpos_yoffset; |
3829 |
|
sw->width = sw->outpos_width; |
3830 |
|
sw->height = sw->outpos_height; |
3831 |
|
sw->outstanding_position = False; |
3832 |
|
|
3833 |
|
/* Do a complete redraw of the window as part of the |
3834 |
|
completion of the move. This is to remove any |
3835 |
|
artifacts caused by our lack of synchronization. */ |
3836 |
|
XCopyArea(g_display, g_backstore, |
3837 |
|
sw->wnd, g_gc, |
3838 |
|
sw->xoffset, sw->yoffset, sw->width, sw->height, 0, 0); |
3839 |
|
|
3840 |
|
break; |
3841 |
|
} |
3842 |
|
} |
3843 |
|
} |