1 |
/* |
/* |
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-2001 |
Copyright (C) Matthew Chapman 1999-2002 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
7 |
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 |
22 |
#include <X11/Xutil.h> |
#include <X11/Xutil.h> |
23 |
#include <time.h> |
#include <time.h> |
24 |
#include <errno.h> |
#include <errno.h> |
|
#define XK_MISCELLANY |
|
|
#include <X11/keysymdef.h> |
|
25 |
#include "rdesktop.h" |
#include "rdesktop.h" |
|
#include "scancodes.h" |
|
26 |
|
|
27 |
extern int width; |
extern int width; |
28 |
extern int height; |
extern int height; |
29 |
extern BOOL sendmotion; |
extern BOOL sendmotion; |
30 |
extern BOOL fullscreen; |
extern BOOL fullscreen; |
31 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
32 |
|
extern BOOL hide_decorations; |
33 |
extern char title[]; |
extern char title[]; |
34 |
|
extern int server_bpp; |
35 |
|
BOOL enable_compose = False; |
36 |
|
BOOL focused; |
37 |
|
BOOL mouse_in_wnd; |
38 |
|
|
39 |
Display *display = NULL; |
Display *display; |
40 |
static int x_socket; |
static int x_socket; |
41 |
|
static Screen *screen; |
42 |
static Window wnd; |
static Window wnd; |
43 |
static GC gc; |
static GC gc; |
44 |
static Visual *visual; |
static Visual *visual; |
45 |
static int depth; |
static int depth; |
46 |
static int bpp; |
static int bpp; |
47 |
static int dpy_width; |
static XIM IM; |
48 |
static int dpy_height; |
static XIC IC; |
49 |
|
static XModifierKeymap *mod_map; |
50 |
|
static Cursor current_cursor; |
51 |
|
static Atom protocol_atom, kill_atom; |
52 |
|
|
53 |
/* endianness */ |
/* endianness */ |
54 |
static BOOL host_be; |
static BOOL host_be; |
58 |
static BOOL ownbackstore; |
static BOOL ownbackstore; |
59 |
static Pixmap backstore; |
static Pixmap backstore; |
60 |
|
|
61 |
|
/* MWM decorations */ |
62 |
|
#define MWM_HINTS_DECORATIONS (1L << 1) |
63 |
|
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
64 |
|
typedef struct |
65 |
|
{ |
66 |
|
uint32 flags; |
67 |
|
uint32 functions; |
68 |
|
uint32 decorations; |
69 |
|
sint32 inputMode; |
70 |
|
uint32 status; |
71 |
|
} |
72 |
|
PropMotifWmHints; |
73 |
|
|
74 |
|
typedef struct |
75 |
|
{ |
76 |
|
uint32 red; |
77 |
|
uint32 green; |
78 |
|
uint32 blue; |
79 |
|
} |
80 |
|
PixelColour; |
81 |
|
|
82 |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
83 |
{ \ |
{ \ |
84 |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
86 |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
87 |
} |
} |
88 |
|
|
89 |
|
#define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\ |
90 |
|
{ \ |
91 |
|
XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \ |
92 |
|
} |
93 |
|
|
94 |
/* colour maps */ |
/* colour maps */ |
95 |
static BOOL owncolmap; |
BOOL owncolmap = False; |
96 |
static Colormap xcolmap; |
static Colormap xcolmap; |
|
static uint32 white; |
|
97 |
static uint32 *colmap; |
static uint32 *colmap; |
|
static XIM IM = NULL; |
|
|
static XIC IC = NULL; |
|
|
|
|
|
/* Compose support */ |
|
|
BOOL enable_compose = False; |
|
98 |
|
|
99 |
/* toggle fullscreen globals */ |
#define TRANSLATE(col) ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) ) |
|
static XSetWindowAttributes attribs; |
|
|
static unsigned long input_mask; |
|
|
|
|
|
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
|
100 |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
101 |
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
102 |
|
|
122 |
#define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); } |
#define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); } |
123 |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
124 |
|
|
125 |
static void |
void |
126 |
translate8(uint8 * data, uint8 * out, uint8 * end) |
mwm_hide_decorations(void) |
|
{ |
|
|
while (out < end) |
|
|
*(out++) = (uint8) colmap[*(data++)]; |
|
|
} |
|
|
|
|
|
static void |
|
|
translate16(uint8 * data, uint16 * out, uint16 * end) |
|
127 |
{ |
{ |
128 |
while (out < end) |
PropMotifWmHints motif_hints; |
129 |
*(out++) = (uint16) colmap[*(data++)]; |
Atom hintsatom; |
|
} |
|
130 |
|
|
131 |
/* little endian - conversion happens when colourmap is built */ |
/* setup the property */ |
132 |
static void |
motif_hints.flags = MWM_HINTS_DECORATIONS; |
133 |
translate24(uint8 * data, uint8 * out, uint8 * end) |
motif_hints.decorations = 0; |
|
{ |
|
|
uint32 value; |
|
134 |
|
|
135 |
while (out < end) |
/* get the atom for the property */ |
136 |
|
hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); |
137 |
|
if (!hintsatom) |
138 |
{ |
{ |
139 |
value = colmap[*(data++)]; |
warning("Failed to get atom _MOTIF_WM_HINTS: probably your window manager does not support MWM hints\n"); |
140 |
*(out++) = value; |
return; |
|
*(out++) = value >> 8; |
|
|
*(out++) = value >> 16; |
|
141 |
} |
} |
142 |
|
|
143 |
|
XChangeProperty(display, wnd, hintsatom, hintsatom, 32, PropModeReplace, |
144 |
|
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
145 |
} |
} |
146 |
|
|
147 |
static void |
PixelColour |
148 |
translate32(uint8 * data, uint32 * out, uint32 * end) |
split_colour15(uint32 colour) |
149 |
{ |
{ |
150 |
while (out < end) |
PixelColour rv; |
151 |
*(out++) = colmap[*(data++)]; |
rv.red = (colour & 0x7c00) >> 10; |
152 |
|
rv.red = (rv.red * 0xff) / 0x1f; |
153 |
|
rv.green = (colour & 0x03e0) >> 5; |
154 |
|
rv.green = (rv.green * 0xff) / 0x1f; |
155 |
|
rv.blue = (colour & 0x1f); |
156 |
|
rv.blue = (rv.blue * 0xff) / 0x1f; |
157 |
|
return rv; |
158 |
} |
} |
159 |
|
|
160 |
static uint8 * |
PixelColour |
161 |
translate_image(int width, int height, uint8 * data) |
split_colour16(uint32 colour) |
162 |
{ |
{ |
163 |
int size = width * height * bpp / 8; |
PixelColour rv; |
164 |
uint8 *out = xmalloc(size); |
rv.red = (colour & 0xf800) >> 11; |
165 |
uint8 *end = out + size; |
rv.red = (rv.red * 0xff) / 0x1f; |
166 |
|
rv.green = (colour & 0x07e0) >> 5; |
167 |
switch (bpp) |
rv.green = (rv.green * 0xff) / 0x3f; |
168 |
{ |
rv.blue = (colour & 0x001f); |
169 |
case 8: |
rv.blue = (rv.blue * 0xff) / 0x1f; |
170 |
translate8(data, out, end); |
return rv; |
171 |
break; |
} |
172 |
|
|
173 |
case 16: |
PixelColour |
174 |
translate16(data, (uint16 *) out, (uint16 *) end); |
split_colour24(uint32 colour) |
175 |
break; |
{ |
176 |
|
PixelColour rv; |
177 |
|
rv.blue = (colour & 0xff0000) >> 16; |
178 |
|
rv.green = (colour & 0xff00) >> 8; |
179 |
|
rv.red = (colour & 0xff); |
180 |
|
return rv; |
181 |
|
} |
182 |
|
|
183 |
case 24: |
uint32 make_colour16(PixelColour pc) |
184 |
translate24(data, out, end); |
{ |
185 |
break; |
pc.red = (pc.red * 0x1f) / 0xff; |
186 |
|
pc.green = (pc.green * 0x3f) / 0xff; |
187 |
|
pc.blue = (pc.blue * 0x1f) / 0xff; |
188 |
|
return (pc.red << 11) | (pc.green << 5) | pc.blue; |
189 |
|
} |
190 |
|
|
191 |
case 32: |
uint32 make_colour24(PixelColour pc) |
192 |
translate32(data, (uint32 *) out, (uint32 *) end); |
{ |
193 |
break; |
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
194 |
} |
} |
195 |
|
|
196 |
return out; |
uint32 make_colour32(PixelColour pc) |
197 |
|
{ |
198 |
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
199 |
} |
} |
200 |
|
|
201 |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
206 |
static uint32 |
static uint32 |
207 |
translate_colour(uint32 colour) |
translate_colour(uint32 colour) |
208 |
{ |
{ |
209 |
|
switch (server_bpp) |
210 |
|
{ |
211 |
|
case 15: |
212 |
|
switch (bpp) |
213 |
|
{ |
214 |
|
case 16: |
215 |
|
colour = make_colour16(split_colour15(colour)); |
216 |
|
break; |
217 |
|
case 24: |
218 |
|
colour = make_colour24(split_colour15(colour)); |
219 |
|
break; |
220 |
|
case 32: |
221 |
|
colour = make_colour32(split_colour15(colour)); |
222 |
|
break; |
223 |
|
} |
224 |
|
break; |
225 |
|
case 16: |
226 |
|
switch (bpp) |
227 |
|
{ |
228 |
|
case 16: |
229 |
|
break; |
230 |
|
case 24: |
231 |
|
colour = make_colour24(split_colour16(colour)); |
232 |
|
break; |
233 |
|
case 32: |
234 |
|
colour = make_colour32(split_colour16(colour)); |
235 |
|
break; |
236 |
|
} |
237 |
|
break; |
238 |
|
case 24: |
239 |
|
switch (bpp) |
240 |
|
{ |
241 |
|
case 16: |
242 |
|
colour = make_colour16(split_colour24(colour)); |
243 |
|
break; |
244 |
|
case 24: |
245 |
|
break; |
246 |
|
case 32: |
247 |
|
colour = make_colour32(split_colour24(colour)); |
248 |
|
break; |
249 |
|
} |
250 |
|
break; |
251 |
|
} |
252 |
switch (bpp) |
switch (bpp) |
253 |
{ |
{ |
254 |
case 16: |
case 16: |
270 |
return colour; |
return colour; |
271 |
} |
} |
272 |
|
|
273 |
static unsigned long |
static void |
274 |
init_inputmethod(void) |
translate8to8(uint8 * data, uint8 * out, uint8 * end) |
275 |
|
{ |
276 |
|
while (out < end) |
277 |
|
*(out++) = (uint8) colmap[*(data++)]; |
278 |
|
} |
279 |
|
|
280 |
|
static void |
281 |
|
translate8to16(uint8 * data, uint16 * out, uint16 * end) |
282 |
|
{ |
283 |
|
while (out < end) |
284 |
|
*(out++) = (uint16) colmap[*(data++)]; |
285 |
|
} |
286 |
|
|
287 |
|
/* little endian - conversion happens when colourmap is built */ |
288 |
|
static void |
289 |
|
translate8to24(uint8 * data, uint8 * out, uint8 * end) |
290 |
{ |
{ |
291 |
unsigned long filtered_events = 0; |
uint32 value; |
292 |
|
|
293 |
IM = XOpenIM(display, NULL, NULL, NULL); |
while (out < end) |
|
if (IM == NULL) |
|
294 |
{ |
{ |
295 |
error("Failed to open input method\n"); |
value = colmap[*(data++)]; |
296 |
|
*(out++) = value; |
297 |
|
*(out++) = value >> 8; |
298 |
|
*(out++) = value >> 16; |
299 |
} |
} |
300 |
|
} |
301 |
|
|
302 |
if (IM != NULL) |
static void |
303 |
{ |
translate8to32(uint8 * data, uint32 * out, uint32 * end) |
304 |
/* Must be done after XCreateWindow */ |
{ |
305 |
IC = XCreateIC(IM, XNInputStyle, |
while (out < end) |
306 |
(XIMPreeditNothing | XIMStatusNothing), |
*(out++) = colmap[*(data++)]; |
307 |
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
} |
308 |
|
|
309 |
if (IC == NULL) |
/* todo the remaining translate function might need some big endian check ?? */ |
|
{ |
|
|
error("Failed to create input context\n"); |
|
|
XCloseIM(IM); |
|
|
IM = NULL; |
|
|
} |
|
|
} |
|
310 |
|
|
311 |
/* For correct Multi_key/Compose processing, I guess. |
static void |
312 |
It seems to work alright anyway, though. */ |
translate15to16(uint16 * data, uint16 * out, uint16 * end) |
313 |
if (IC != NULL) |
{ |
314 |
{ |
while (out < end) |
315 |
if (XGetICValues(IC, XNFilterEvents, &filtered_events, NULL) != NULL) |
*(out++) = (uint16) make_colour16(split_colour15(*(data++))); |
|
{ |
|
|
error("Failed to obtain XNFilterEvents value from IC\n"); |
|
|
filtered_events = 0; |
|
|
} |
|
|
} |
|
|
return filtered_events; |
|
316 |
} |
} |
317 |
|
|
318 |
static void |
static void |
319 |
close_inputmethod(void) |
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
320 |
{ |
{ |
321 |
if (IC != NULL) |
uint32 value; |
322 |
|
|
323 |
|
while (out < end) |
324 |
{ |
{ |
325 |
XDestroyIC(IC); |
value = make_colour24(split_colour15(*(data++))); |
326 |
if (IM != NULL) |
*(out++) = value; |
327 |
{ |
*(out++) = value >> 8; |
328 |
XCloseIM(IM); |
*(out++) = value >> 16; |
|
IM = NULL; |
|
|
} |
|
329 |
} |
} |
330 |
} |
} |
331 |
|
|
332 |
static BOOL |
static void |
333 |
get_key_state(int keysym) |
translate15to32(uint16 * data, uint32 * out, uint32 * end) |
334 |
{ |
{ |
335 |
int keysymMask = 0, modifierpos, key; |
while (out < end) |
336 |
Window wDummy1, wDummy2; |
*(out++) = make_colour32(split_colour15(*(data++))); |
337 |
int iDummy3, iDummy4, iDummy5, iDummy6; |
} |
|
unsigned int current_state; |
|
|
int offset; |
|
338 |
|
|
339 |
XModifierKeymap *map = XGetModifierMapping(display); |
static void |
340 |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
341 |
|
{ |
342 |
|
while (out < end) |
343 |
|
*(out++) = (uint16) (*(data++)); |
344 |
|
} |
345 |
|
|
|
if (keycode == NoSymbol) |
|
|
return False; |
|
346 |
|
|
347 |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
static void |
348 |
{ |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
349 |
offset = map->max_keypermod * modifierpos; |
{ |
350 |
|
uint32 value; |
351 |
|
|
352 |
for (key = 0; key < map->max_keypermod; key++) |
while (out < end) |
353 |
{ |
{ |
354 |
if (map->modifiermap[offset + key] == keycode) |
value = make_colour24(split_colour16(*(data++))); |
355 |
keysymMask = 1 << modifierpos; |
*(out++) = value; |
356 |
} |
*(out++) = value >> 8; |
357 |
|
*(out++) = value >> 16; |
358 |
} |
} |
|
|
|
|
XQueryPointer(display, DefaultRootWindow(display), &wDummy1, |
|
|
&wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, ¤t_state); |
|
|
|
|
|
XFreeModifiermap(map); |
|
|
|
|
|
return (current_state & keysymMask) ? True : False; |
|
359 |
} |
} |
360 |
|
|
361 |
|
static void |
362 |
|
translate16to32(uint16 * data, uint32 * out, uint32 * end) |
363 |
|
{ |
364 |
|
while (out < end) |
365 |
|
*(out++) = make_colour32(split_colour16(*(data++))); |
366 |
|
} |
367 |
|
|
368 |
BOOL |
static void |
369 |
ui_init() |
translate24to16(uint8 * data, uint16 * out, uint16 * end) |
370 |
{ |
{ |
371 |
Screen *screen; |
uint32 pixel = 0; |
372 |
display = XOpenDisplay(NULL); |
while (out < end) |
|
if (display == NULL) |
|
373 |
{ |
{ |
374 |
error("Failed to open display\n"); |
pixel = *(data++) << 16; |
375 |
return False; |
pixel |= *(data++) << 8; |
376 |
|
pixel |= *(data++); |
377 |
|
*(out++) = (uint16) make_colour16(split_colour24(pixel)); |
378 |
} |
} |
379 |
if (fullscreen) |
} |
380 |
|
|
381 |
|
static void |
382 |
|
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
383 |
|
{ |
384 |
|
while (out < end) |
385 |
{ |
{ |
386 |
screen = DefaultScreenOfDisplay(display); |
*(out++) = (*(data++)); |
|
width = WidthOfScreen(screen); |
|
|
height = HeightOfScreen(screen); |
|
387 |
} |
} |
|
return True; |
|
388 |
} |
} |
389 |
|
|
390 |
void |
static void |
391 |
ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask) |
translate24to32(uint8 * data, uint32 * out, uint32 * end) |
392 |
{ |
{ |
393 |
XClassHint *classhints; |
uint32 pixel = 0; |
394 |
XSizeHints *sizehints; |
while (out < end) |
|
XEvent xevent; |
|
|
Screen *screen; |
|
|
|
|
|
screen = DefaultScreenOfDisplay(display); |
|
|
|
|
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), xpos, |
|
|
ypos, width, height, 0, CopyFromParent, |
|
|
InputOutput, CopyFromParent, valuemask, &attribs); |
|
|
|
|
|
|
|
|
XStoreName(display, wnd, title); |
|
|
|
|
|
classhints = XAllocClassHint(); |
|
|
if (classhints != NULL) |
|
395 |
{ |
{ |
396 |
classhints->res_name = classhints->res_class = "rdesktop"; |
memcpy(&pixel, data, 3); |
397 |
XSetClassHint(display, wnd, classhints); |
data += 3; |
398 |
XFree(classhints); |
*(out++) = pixel; |
399 |
} |
} |
400 |
|
} |
401 |
|
|
402 |
sizehints = XAllocSizeHints(); |
static uint8 * |
403 |
if (sizehints) |
translate_image(int width, int height, uint8 * data) |
404 |
|
{ |
405 |
|
int size = width * height * bpp / 8; |
406 |
|
uint8 *out = xmalloc(size); |
407 |
|
uint8 *end = out + size; |
408 |
|
|
409 |
|
switch (server_bpp) |
410 |
{ |
{ |
411 |
sizehints->flags = PMinSize | PMaxSize; |
case 24: |
412 |
sizehints->min_width = sizehints->max_width = width; |
switch (bpp) |
413 |
sizehints->min_height = sizehints->max_height = height; |
{ |
414 |
XSetWMNormalHints(display, wnd, sizehints); |
case 32: |
415 |
XFree(sizehints); |
translate24to32(data, (uint32 *) out, (uint32 *) end); |
416 |
|
break; |
417 |
|
case 24: |
418 |
|
translate24to24(data, out, end); |
419 |
|
break; |
420 |
|
case 16: |
421 |
|
translate24to16(data, (uint16 *) out, (uint16 *) end); |
422 |
|
break; |
423 |
|
} |
424 |
|
break; |
425 |
|
case 16: |
426 |
|
switch (bpp) |
427 |
|
{ |
428 |
|
case 32: |
429 |
|
translate16to32((uint16 *) data, (uint32 *) out, (uint32 *) end); |
430 |
|
break; |
431 |
|
case 24: |
432 |
|
translate16to24((uint16 *) data, out, end); |
433 |
|
break; |
434 |
|
case 16: |
435 |
|
translate16to16((uint16 *) data, (uint16 *) out, (uint16 *) end); |
436 |
|
break; |
437 |
|
} |
438 |
|
break; |
439 |
|
case 15: |
440 |
|
switch (bpp) |
441 |
|
{ |
442 |
|
case 32: |
443 |
|
translate15to32((uint16 *) data, (uint32 *) out, (uint32 *) end); |
444 |
|
break; |
445 |
|
case 24: |
446 |
|
translate15to24((uint16 *) data, out, end); |
447 |
|
break; |
448 |
|
case 16: |
449 |
|
translate15to16((uint16 *) data, (uint16 *) out, (uint16 *) end); |
450 |
|
break; |
451 |
|
} |
452 |
|
break; |
453 |
|
case 8: |
454 |
|
switch (bpp) |
455 |
|
{ |
456 |
|
case 8: |
457 |
|
translate8to8(data, out, end); |
458 |
|
break; |
459 |
|
case 16: |
460 |
|
translate8to16(data, (uint16 *) out, (uint16 *) end); |
461 |
|
break; |
462 |
|
case 24: |
463 |
|
translate8to24(data, out, end); |
464 |
|
break; |
465 |
|
case 32: |
466 |
|
translate8to32(data, (uint32 *) out, (uint32 *) end); |
467 |
|
break; |
468 |
|
} |
469 |
|
break; |
470 |
} |
} |
471 |
|
return out; |
472 |
|
} |
473 |
|
|
474 |
if (enable_compose) |
BOOL |
475 |
input_mask |= init_inputmethod(); |
get_key_state(unsigned int state, uint32 keysym) |
476 |
|
{ |
477 |
XSelectInput(display, wnd, input_mask); |
int modifierpos, key, keysymMask = 0; |
478 |
|
int offset; |
479 |
|
|
480 |
gc = XCreateGC(display, wnd, 0, NULL); |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
481 |
|
|
482 |
XMapWindow(display, wnd); |
if (keycode == NoSymbol) |
483 |
|
return False; |
484 |
|
|
485 |
/* Wait for VisibilityNotify Event */ |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
|
for (;;) |
|
486 |
{ |
{ |
487 |
XNextEvent(display, &xevent); |
offset = mod_map->max_keypermod * modifierpos; |
|
if (xevent.type == VisibilityNotify) |
|
|
break; |
|
|
} |
|
488 |
|
|
489 |
if (ownbackstore) |
for (key = 0; key < mod_map->max_keypermod; key++) |
490 |
backstore = XCreatePixmap(display, wnd, width, height, depth); |
{ |
491 |
|
if (mod_map->modifiermap[offset + key] == keycode) |
492 |
|
keysymMask |= 1 << modifierpos; |
493 |
|
} |
494 |
|
} |
495 |
|
|
496 |
/* clear the window so that cached data is not viewed upon start... */ |
return (state & keysymMask) ? True : False; |
|
XSetBackground(display, gc, 0); |
|
|
XSetForeground(display, gc, 0); |
|
|
FILL_RECTANGLE(0, 0, width, height); |
|
|
/* make sure the window is focused */ |
|
|
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
|
497 |
} |
} |
498 |
|
|
499 |
BOOL |
BOOL |
500 |
ui_create_window() |
ui_init(void) |
501 |
{ |
{ |
502 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
|
Screen *screen; |
|
503 |
uint16 test; |
uint16 test; |
504 |
int i; |
int i; |
505 |
|
|
506 |
|
display = XOpenDisplay(NULL); |
507 |
|
if (display == NULL) |
508 |
|
{ |
509 |
|
error("Failed to open display: %s\n", XDisplayName(NULL)); |
510 |
|
return False; |
511 |
|
} |
512 |
|
|
513 |
x_socket = ConnectionNumber(display); |
x_socket = ConnectionNumber(display); |
514 |
screen = DefaultScreenOfDisplay(display); |
screen = DefaultScreenOfDisplay(display); |
515 |
visual = DefaultVisualOfScreen(screen); |
visual = DefaultVisualOfScreen(screen); |
537 |
return False; |
return False; |
538 |
} |
} |
539 |
|
|
540 |
if (depth <= 8) |
if (owncolmap != True) |
541 |
owncolmap = True; |
{ |
|
else |
|
542 |
xcolmap = DefaultColormapOfScreen(screen); |
xcolmap = DefaultColormapOfScreen(screen); |
543 |
|
if (depth <= 8) |
544 |
|
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
545 |
|
} |
546 |
|
|
547 |
|
gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); |
548 |
|
|
549 |
|
if (DoesBackingStore(screen) != Always) |
550 |
|
ownbackstore = True; |
551 |
|
|
552 |
test = 1; |
test = 1; |
553 |
host_be = !(BOOL) (*(uint8 *) (&test)); |
host_be = !(BOOL) (*(uint8 *) (&test)); |
554 |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
555 |
|
|
556 |
white = WhitePixelOfScreen(screen); |
if ((width == 0) || (height == 0)) |
557 |
attribs.background_pixel = BlackPixelOfScreen(screen); |
{ |
558 |
attribs.backing_store = DoesBackingStore(screen); |
/* Fetch geometry from _NET_WORKAREA */ |
559 |
|
uint32 x, y, cx, cy; |
|
if (attribs.backing_store == NotUseful) |
|
|
ownbackstore = True; |
|
560 |
|
|
561 |
dpy_width = WidthOfScreen(screen); |
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
562 |
dpy_height = HeightOfScreen(screen); |
{ |
563 |
|
width = cx; |
564 |
|
height = cy; |
565 |
|
} |
566 |
|
else |
567 |
|
{ |
568 |
|
warning("Failed to get workarea: probably your window manager does not support extended hints\n"); |
569 |
|
width = 800; |
570 |
|
height = 600; |
571 |
|
} |
572 |
|
} |
573 |
|
|
574 |
if (fullscreen) |
if (fullscreen) |
575 |
{ |
{ |
576 |
attribs.override_redirect = True; |
width = WidthOfScreen(screen); |
577 |
width = dpy_width; |
height = HeightOfScreen(screen); |
|
height = dpy_height; |
|
578 |
} |
} |
579 |
else |
|
580 |
|
/* make sure width is a multiple of 4 */ |
581 |
|
width = (width + 3) & ~3; |
582 |
|
|
583 |
|
if (ownbackstore) |
584 |
{ |
{ |
585 |
attribs.override_redirect = False; |
backstore = |
586 |
|
XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); |
587 |
|
|
588 |
|
/* clear to prevent rubbish being exposed at startup */ |
589 |
|
XSetForeground(display, gc, BlackPixelOfScreen(screen)); |
590 |
|
XFillRectangle(display, backstore, gc, 0, 0, width, height); |
591 |
} |
} |
592 |
|
|
593 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
mod_map = XGetModifierMapping(display); |
|
VisibilityChangeMask | FocusChangeMask; |
|
594 |
|
|
595 |
if (grab_keyboard) |
if (enable_compose) |
596 |
input_mask |= EnterWindowMask | LeaveWindowMask; |
IM = XOpenIM(display, NULL, NULL, NULL); |
|
if (sendmotion) |
|
|
input_mask |= PointerMotionMask; |
|
597 |
|
|
598 |
if (ownbackstore) |
xkeymap_init(); |
|
input_mask |= ExposureMask; |
|
599 |
|
|
600 |
if (fullscreen) |
/* todo take this out when high colour is done */ |
601 |
ui_create_window_obj(0, 0, width, height, |
printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth); |
|
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
|
|
else |
|
|
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
|
|
|
|
|
xkeymap_init2(); |
|
602 |
|
|
603 |
return True; |
return True; |
604 |
} |
} |
605 |
|
|
606 |
void |
void |
607 |
ui_destroy_window() |
ui_deinit(void) |
608 |
{ |
{ |
609 |
|
if (IM != NULL) |
610 |
|
XCloseIM(IM); |
611 |
|
|
612 |
|
XFreeModifiermap(mod_map); |
613 |
|
|
614 |
if (ownbackstore) |
if (ownbackstore) |
615 |
XFreePixmap(display, backstore); |
XFreePixmap(display, backstore); |
616 |
|
|
617 |
XFreeGC(display, gc); |
XFreeGC(display, gc); |
|
|
|
|
close_inputmethod(); |
|
|
|
|
|
XDestroyWindow(display, wnd); |
|
618 |
XCloseDisplay(display); |
XCloseDisplay(display); |
619 |
display = NULL; |
display = NULL; |
620 |
} |
} |
621 |
|
|
622 |
void |
BOOL |
623 |
reset_keys() |
ui_create_window(void) |
624 |
{ |
{ |
625 |
/* reset keys */ |
XSetWindowAttributes attribs; |
626 |
uint32 ev_time; |
XClassHint *classhints; |
627 |
ev_time = time(NULL); |
XSizeHints *sizehints; |
628 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
int wndwidth, wndheight; |
629 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
long input_mask, ic_input_mask; |
630 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
XEvent xevent; |
631 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
|
632 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
wndwidth = fullscreen ? WidthOfScreen(screen) : width; |
633 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
wndheight = fullscreen ? HeightOfScreen(screen) : height; |
634 |
|
|
635 |
|
attribs.background_pixel = BlackPixelOfScreen(screen); |
636 |
|
attribs.backing_store = ownbackstore ? NotUseful : Always; |
637 |
|
attribs.override_redirect = fullscreen; |
638 |
|
|
639 |
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth, wndheight, |
640 |
|
0, CopyFromParent, InputOutput, CopyFromParent, |
641 |
|
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
642 |
|
|
643 |
|
XStoreName(display, wnd, title); |
644 |
|
|
645 |
|
if (hide_decorations) |
646 |
|
mwm_hide_decorations(); |
647 |
|
|
648 |
|
classhints = XAllocClassHint(); |
649 |
|
if (classhints != NULL) |
650 |
|
{ |
651 |
|
classhints->res_name = classhints->res_class = "rdesktop"; |
652 |
|
XSetClassHint(display, wnd, classhints); |
653 |
|
XFree(classhints); |
654 |
|
} |
655 |
|
|
656 |
|
sizehints = XAllocSizeHints(); |
657 |
|
if (sizehints) |
658 |
|
{ |
659 |
|
sizehints->flags = PMinSize | PMaxSize; |
660 |
|
sizehints->min_width = sizehints->max_width = width; |
661 |
|
sizehints->min_height = sizehints->max_height = height; |
662 |
|
XSetWMNormalHints(display, wnd, sizehints); |
663 |
|
XFree(sizehints); |
664 |
|
} |
665 |
|
|
666 |
|
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
667 |
|
VisibilityChangeMask | FocusChangeMask; |
668 |
|
|
669 |
|
if (sendmotion) |
670 |
|
input_mask |= PointerMotionMask; |
671 |
|
if (ownbackstore) |
672 |
|
input_mask |= ExposureMask; |
673 |
|
if (fullscreen || grab_keyboard) |
674 |
|
input_mask |= EnterWindowMask; |
675 |
|
if (grab_keyboard) |
676 |
|
input_mask |= LeaveWindowMask; |
677 |
|
|
678 |
|
if (IM != NULL) |
679 |
|
{ |
680 |
|
IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), |
681 |
|
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
682 |
|
|
683 |
|
if ((IC != NULL) |
684 |
|
&& (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) |
685 |
|
input_mask |= ic_input_mask; |
686 |
|
} |
687 |
|
|
688 |
|
XSelectInput(display, wnd, input_mask); |
689 |
|
XMapWindow(display, wnd); |
690 |
|
|
691 |
|
/* wait for VisibilityNotify */ |
692 |
|
do |
693 |
|
{ |
694 |
|
XMaskEvent(display, VisibilityChangeMask, &xevent); |
695 |
|
} |
696 |
|
while (xevent.type != VisibilityNotify); |
697 |
|
|
698 |
|
focused = False; |
699 |
|
mouse_in_wnd = False; |
700 |
|
|
701 |
|
/* handle the WM_DELETE_WINDOW protocol */ |
702 |
|
protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True); |
703 |
|
kill_atom = XInternAtom(display, "WM_DELETE_WINDOW", True); |
704 |
|
XSetWMProtocols(display, wnd, &kill_atom, 1); |
705 |
|
|
706 |
|
return True; |
707 |
} |
} |
708 |
|
|
709 |
void |
void |
710 |
toggle_fullscreen() |
ui_destroy_window(void) |
711 |
{ |
{ |
712 |
/* save window contents */ |
if (IC != NULL) |
713 |
Pixmap pixmap; |
XDestroyIC(IC); |
714 |
pixmap = XCreatePixmap(display, wnd, width, height, depth); |
|
|
if (ownbackstore) |
|
|
XCopyArea(display, backstore, pixmap, gc, 0, 0, width, height, 0, 0); |
|
|
else |
|
|
XCopyArea(display, wnd, pixmap, gc, 0, 0, width, height, 0, 0); |
|
|
fullscreen = fullscreen ? False : True; |
|
|
close_inputmethod(); |
|
|
if (ownbackstore) |
|
|
XFreePixmap(display, backstore); |
|
|
XFreeGC(display, gc); |
|
715 |
XDestroyWindow(display, wnd); |
XDestroyWindow(display, wnd); |
716 |
if (fullscreen) |
} |
717 |
|
|
718 |
|
void |
719 |
|
xwin_toggle_fullscreen(void) |
720 |
|
{ |
721 |
|
Pixmap contents = 0; |
722 |
|
|
723 |
|
if (!ownbackstore) |
724 |
{ |
{ |
725 |
attribs.override_redirect = True; |
/* need to save contents of window */ |
726 |
ui_create_window_obj(0, 0, dpy_width, dpy_height, |
contents = XCreatePixmap(display, wnd, width, height, depth); |
727 |
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
XCopyArea(display, wnd, contents, gc, 0, 0, width, height, 0, 0); |
728 |
} |
} |
729 |
else |
|
730 |
|
ui_destroy_window(); |
731 |
|
fullscreen = !fullscreen; |
732 |
|
ui_create_window(); |
733 |
|
|
734 |
|
XDefineCursor(display, wnd, current_cursor); |
735 |
|
|
736 |
|
if (!ownbackstore) |
737 |
{ |
{ |
738 |
attribs.override_redirect = False; |
XCopyArea(display, contents, wnd, gc, 0, 0, width, height, 0, 0); |
739 |
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
XFreePixmap(display, contents); |
740 |
} |
} |
|
ui_set_cursor(cache_get_cursor(0)); |
|
|
ui_move_pointer(width / 2, height / 2); |
|
|
reset_keys(); |
|
|
/* restore window contents */ |
|
|
if (ownbackstore) |
|
|
XCopyArea(display, pixmap, backstore, gc, 0, 0, width, height, 0, 0); |
|
|
XCopyArea(display, pixmap, wnd, gc, 0, 0, width, height, 0, 0); |
|
|
XFreePixmap(display, pixmap); |
|
741 |
} |
} |
742 |
|
|
743 |
static void |
/* Process all events in Xlib queue |
744 |
xwin_process_events() |
Returns 0 after user quit, 1 otherwise */ |
745 |
|
static int |
746 |
|
xwin_process_events(void) |
747 |
{ |
{ |
748 |
XEvent xevent; |
XEvent xevent; |
|
|
|
749 |
KeySym keysym; |
KeySym keysym; |
750 |
uint16 button, flags; |
uint16 button, flags; |
751 |
uint32 ev_time; |
uint32 ev_time; |
752 |
key_translation tr; |
key_translation tr; |
|
char *ksname = NULL; |
|
753 |
char str[256]; |
char str[256]; |
754 |
Status status; |
Status status; |
755 |
|
unsigned int state; |
756 |
|
Window wdummy; |
757 |
|
int dummy; |
758 |
|
|
759 |
/* Refresh keyboard mapping if it has changed. This is important for |
while (XPending(display) > 0) |
|
Xvnc, since it allocates keycodes dynamically */ |
|
|
if (XCheckTypedEvent(display, MappingNotify, &xevent)) |
|
760 |
{ |
{ |
761 |
if (xevent.xmapping.request == MappingKeyboard |
XNextEvent(display, &xevent); |
|
|| xevent.xmapping.request == MappingModifier) |
|
|
XRefreshKeyboardMapping(&xevent.xmapping); |
|
|
} |
|
762 |
|
|
763 |
while (XCheckMaskEvent(display, ~0, &xevent)) |
if ((IC != NULL) && (XFilterEvent(&xevent, None) == True)) |
|
{ |
|
|
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
|
764 |
{ |
{ |
765 |
DEBUG_KBD(("Filtering event\n")); |
DEBUG_KBD(("Filtering event\n")); |
766 |
continue; |
continue; |
767 |
} |
} |
768 |
|
|
|
ev_time = time(NULL); |
|
769 |
flags = 0; |
flags = 0; |
770 |
|
|
771 |
switch (xevent.type) |
switch (xevent.type) |
772 |
{ |
{ |
773 |
|
case ClientMessage: |
774 |
|
/* the window manager told us to quit */ |
775 |
|
if ((xevent.xclient.message_type == protocol_atom) |
776 |
|
&& (xevent.xclient.data.l[0] == kill_atom)) |
777 |
|
/* Quit */ |
778 |
|
return 0; |
779 |
|
break; |
780 |
|
|
781 |
case KeyPress: |
case KeyPress: |
782 |
if (IC != NULL) |
if (IC != NULL) |
783 |
/* Multi_key compatible version */ |
/* Multi_key compatible version */ |
795 |
else |
else |
796 |
{ |
{ |
797 |
/* Plain old XLookupString */ |
/* Plain old XLookupString */ |
798 |
DEBUG_KBD(("No input context, using XLookupString\n")); |
DEBUG_KBD(("\nNo input context, using XLookupString\n")); |
799 |
XLookupString((XKeyEvent *) & xevent, |
XLookupString((XKeyEvent *) & xevent, |
800 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
801 |
} |
} |
802 |
|
|
803 |
if (keysym == XK_Break) /* toggle full screen */ |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, |
804 |
{ |
get_ksname(keysym))); |
|
if (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R)) |
|
|
{ |
|
|
toggle_fullscreen(); |
|
|
break; |
|
|
} |
|
|
} |
|
805 |
|
|
806 |
ksname = get_ksname(keysym); |
ev_time = time(NULL); |
807 |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
|
|
|
|
if (inhibit_key(keysym)) |
|
|
{ |
|
|
DEBUG_KBD(("Inhibiting key\n")); |
|
808 |
break; |
break; |
|
} |
|
809 |
|
|
810 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
811 |
xevent.xkey.keycode, xevent.xkey.state); |
xevent.xkey.keycode, xevent.xkey.state); |
817 |
|
|
818 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
819 |
break; |
break; |
820 |
|
|
821 |
case KeyRelease: |
case KeyRelease: |
822 |
XLookupString((XKeyEvent *) & xevent, str, |
XLookupString((XKeyEvent *) & xevent, str, |
823 |
sizeof(str), &keysym, NULL); |
sizeof(str), &keysym, NULL); |
824 |
|
|
|
ksname = get_ksname(keysym); |
|
825 |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
826 |
ksname)); |
get_ksname(keysym))); |
827 |
|
|
828 |
if (inhibit_key(keysym)) |
ev_time = time(NULL); |
829 |
|
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False)) |
830 |
break; |
break; |
831 |
|
|
832 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
847 |
if (button == 0) |
if (button == 0) |
848 |
break; |
break; |
849 |
|
|
850 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
851 |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
852 |
break; |
break; |
853 |
|
|
854 |
case MotionNotify: |
case MotionNotify: |
855 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
if (fullscreen && !focused) |
856 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
857 |
|
CurrentTime); |
858 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
859 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
860 |
break; |
break; |
861 |
|
|
862 |
case FocusIn: |
case FocusIn: |
863 |
/* fall through */ |
if (xevent.xfocus.mode == NotifyGrab) |
864 |
case EnterNotify: |
break; |
865 |
if (grab_keyboard) |
focused = True; |
866 |
|
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, |
867 |
|
&dummy, &dummy, &state); |
868 |
|
reset_modifier_keys(state); |
869 |
|
if (grab_keyboard && mouse_in_wnd) |
870 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
871 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
872 |
break; |
break; |
873 |
|
|
874 |
case FocusOut: |
case FocusOut: |
875 |
reset_keys(); |
if (xevent.xfocus.mode == NotifyUngrab) |
876 |
/* fall through */ |
break; |
877 |
case LeaveNotify: |
focused = False; |
878 |
if (grab_keyboard) |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
879 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
880 |
break; |
break; |
881 |
|
|
882 |
|
case EnterNotify: |
883 |
|
/* we only register for this event when in fullscreen mode */ |
884 |
|
/* or grab_keyboard */ |
885 |
|
mouse_in_wnd = True; |
886 |
|
if (fullscreen) |
887 |
|
{ |
888 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
889 |
|
CurrentTime); |
890 |
|
break; |
891 |
|
} |
892 |
|
if (focused) |
893 |
|
XGrabKeyboard(display, wnd, True, |
894 |
|
GrabModeAsync, GrabModeAsync, CurrentTime); |
895 |
|
break; |
896 |
|
|
897 |
|
case LeaveNotify: |
898 |
|
/* we only register for this event when grab_keyboard */ |
899 |
|
mouse_in_wnd = False; |
900 |
|
XUngrabKeyboard(display, CurrentTime); |
901 |
|
break; |
902 |
|
|
903 |
case Expose: |
case Expose: |
904 |
XCopyArea(display, backstore, wnd, gc, |
XCopyArea(display, backstore, wnd, gc, |
905 |
xevent.xexpose.x, xevent.xexpose.y, |
xevent.xexpose.x, xevent.xexpose.y, |
907 |
xevent.xexpose.height, |
xevent.xexpose.height, |
908 |
xevent.xexpose.x, xevent.xexpose.y); |
xevent.xexpose.x, xevent.xexpose.y); |
909 |
break; |
break; |
910 |
|
|
911 |
|
case MappingNotify: |
912 |
|
/* Refresh keyboard mapping if it has changed. This is important for |
913 |
|
Xvnc, since it allocates keycodes dynamically */ |
914 |
|
if (xevent.xmapping.request == MappingKeyboard |
915 |
|
|| xevent.xmapping.request == MappingModifier) |
916 |
|
XRefreshKeyboardMapping(&xevent.xmapping); |
917 |
|
|
918 |
|
if (xevent.xmapping.request == MappingModifier) |
919 |
|
{ |
920 |
|
XFreeModifiermap(mod_map); |
921 |
|
mod_map = XGetModifierMapping(display); |
922 |
|
} |
923 |
|
break; |
924 |
|
|
925 |
} |
} |
926 |
} |
} |
927 |
|
/* Keep going */ |
928 |
|
return 1; |
929 |
} |
} |
930 |
|
|
931 |
void |
/* Returns 0 after user quit, 1 otherwise */ |
932 |
|
int |
933 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
934 |
{ |
{ |
935 |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
939 |
|
|
940 |
while (True) |
while (True) |
941 |
{ |
{ |
942 |
|
/* Process any events already waiting */ |
943 |
|
if (!xwin_process_events()) |
944 |
|
/* User quit */ |
945 |
|
return 0; |
946 |
|
|
947 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
948 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
949 |
if (display != NULL) |
FD_SET(x_socket, &rfds); |
|
{ |
|
|
FD_SET(x_socket, &rfds); |
|
|
XFlush(display); |
|
|
} |
|
950 |
|
|
951 |
switch (select(n, &rfds, NULL, NULL, NULL)) |
switch (select(n, &rfds, NULL, NULL, NULL)) |
952 |
{ |
{ |
957 |
continue; |
continue; |
958 |
} |
} |
959 |
|
|
|
if (FD_ISSET(x_socket, &rfds)) |
|
|
xwin_process_events(); |
|
|
|
|
960 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
961 |
return; |
return 1; |
962 |
} |
} |
963 |
} |
} |
964 |
|
|
978 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
979 |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
980 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
981 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
982 |
|
|
983 |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
984 |
|
|
993 |
{ |
{ |
994 |
XImage *image; |
XImage *image; |
995 |
uint8 *tdata; |
uint8 *tdata; |
|
|
|
996 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
997 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
998 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
999 |
|
|
1000 |
if (ownbackstore) |
if (ownbackstore) |
1001 |
{ |
{ |
1124 |
void |
void |
1125 |
ui_set_cursor(HCURSOR cursor) |
ui_set_cursor(HCURSOR cursor) |
1126 |
{ |
{ |
1127 |
XDefineCursor(display, wnd, (Cursor) cursor); |
current_cursor = (Cursor) cursor; |
1128 |
|
XDefineCursor(display, wnd, current_cursor); |
1129 |
} |
} |
1130 |
|
|
1131 |
void |
void |
1140 |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
1141 |
(xc)->flags = DoRed | DoGreen | DoBlue; |
(xc)->flags = DoRed | DoGreen | DoBlue; |
1142 |
|
|
1143 |
|
|
1144 |
HCOLOURMAP |
HCOLOURMAP |
1145 |
ui_create_colourmap(COLOURMAP * colours) |
ui_create_colourmap(COLOURMAP * colours) |
1146 |
{ |
{ |
1147 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
1148 |
int i, ncolours = colours->ncolours; |
int i, ncolours = colours->ncolours; |
1149 |
|
if (!owncolmap) |
1150 |
|
{ |
1151 |
|
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
1152 |
|
XColor xentry; |
1153 |
|
XColor xc_cache[256]; |
1154 |
|
uint32 colour; |
1155 |
|
int colLookup = 256; |
1156 |
|
for (i = 0; i < ncolours; i++) |
1157 |
|
{ |
1158 |
|
entry = &colours->colours[i]; |
1159 |
|
MAKE_XCOLOR(&xentry, entry); |
1160 |
|
|
1161 |
if (owncolmap) |
if (XAllocColor(display, xcolmap, &xentry) == 0) |
1162 |
|
{ |
1163 |
|
/* Allocation failed, find closest match. */ |
1164 |
|
int j = 256; |
1165 |
|
int nMinDist = 3 * 256 * 256; |
1166 |
|
long nDist = nMinDist; |
1167 |
|
|
1168 |
|
/* only get the colors once */ |
1169 |
|
while (colLookup--) |
1170 |
|
{ |
1171 |
|
xc_cache[colLookup].pixel = colLookup; |
1172 |
|
xc_cache[colLookup].red = xc_cache[colLookup].green = |
1173 |
|
xc_cache[colLookup].blue = 0; |
1174 |
|
xc_cache[colLookup].flags = 0; |
1175 |
|
XQueryColor(display, |
1176 |
|
DefaultColormap(display, |
1177 |
|
DefaultScreen(display)), |
1178 |
|
&xc_cache[colLookup]); |
1179 |
|
} |
1180 |
|
colLookup = 0; |
1181 |
|
|
1182 |
|
/* approximate the pixel */ |
1183 |
|
while (j--) |
1184 |
|
{ |
1185 |
|
if (xc_cache[j].flags) |
1186 |
|
{ |
1187 |
|
nDist = ((long) (xc_cache[j].red >> 8) - |
1188 |
|
(long) (xentry.red >> 8)) * |
1189 |
|
((long) (xc_cache[j].red >> 8) - |
1190 |
|
(long) (xentry.red >> 8)) + |
1191 |
|
((long) (xc_cache[j].green >> 8) - |
1192 |
|
(long) (xentry.green >> 8)) * |
1193 |
|
((long) (xc_cache[j].green >> 8) - |
1194 |
|
(long) (xentry.green >> 8)) + |
1195 |
|
((long) (xc_cache[j].blue >> 8) - |
1196 |
|
(long) (xentry.blue >> 8)) * |
1197 |
|
((long) (xc_cache[j].blue >> 8) - |
1198 |
|
(long) (xentry.blue >> 8)); |
1199 |
|
} |
1200 |
|
if (nDist < nMinDist) |
1201 |
|
{ |
1202 |
|
nMinDist = nDist; |
1203 |
|
xentry.pixel = j; |
1204 |
|
} |
1205 |
|
} |
1206 |
|
} |
1207 |
|
colour = xentry.pixel; |
1208 |
|
|
1209 |
|
/* update our cache */ |
1210 |
|
if (xentry.pixel < 256) |
1211 |
|
{ |
1212 |
|
xc_cache[xentry.pixel].red = xentry.red; |
1213 |
|
xc_cache[xentry.pixel].green = xentry.green; |
1214 |
|
xc_cache[xentry.pixel].blue = xentry.blue; |
1215 |
|
|
1216 |
|
} |
1217 |
|
|
1218 |
|
|
1219 |
|
/* byte swap here to make translate_image faster */ |
1220 |
|
map[i] = translate_colour(colour); |
1221 |
|
} |
1222 |
|
return map; |
1223 |
|
} |
1224 |
|
else |
1225 |
{ |
{ |
1226 |
XColor *xcolours, *xentry; |
XColor *xcolours, *xentry; |
1227 |
Colormap map; |
Colormap map; |
1241 |
xfree(xcolours); |
xfree(xcolours); |
1242 |
return (HCOLOURMAP) map; |
return (HCOLOURMAP) map; |
1243 |
} |
} |
|
else |
|
|
{ |
|
|
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
|
|
XColor xentry; |
|
|
uint32 colour; |
|
|
|
|
|
for (i = 0; i < ncolours; i++) |
|
|
{ |
|
|
entry = &colours->colours[i]; |
|
|
MAKE_XCOLOR(&xentry, entry); |
|
|
|
|
|
if (XAllocColor(display, xcolmap, &xentry) != 0) |
|
|
colour = xentry.pixel; |
|
|
else |
|
|
colour = white; |
|
|
|
|
|
/* byte swap here to make translate_image faster */ |
|
|
map[i] = translate_colour(colour); |
|
|
} |
|
|
|
|
|
return map; |
|
|
} |
|
1244 |
} |
} |
1245 |
|
|
1246 |
void |
void |
1247 |
ui_destroy_colourmap(HCOLOURMAP map) |
ui_destroy_colourmap(HCOLOURMAP map) |
1248 |
{ |
{ |
1249 |
if (owncolmap) |
if (!owncolmap) |
|
XFreeColormap(display, (Colormap) map); |
|
|
else |
|
1250 |
xfree(map); |
xfree(map); |
1251 |
|
else |
1252 |
|
XFreeColormap(display, (Colormap) map); |
1253 |
} |
} |
1254 |
|
|
1255 |
void |
void |
1256 |
ui_set_colourmap(HCOLOURMAP map) |
ui_set_colourmap(HCOLOURMAP map) |
1257 |
{ |
{ |
1258 |
if (owncolmap) |
if (!owncolmap) |
|
XSetWindowColormap(display, wnd, (Colormap) map); |
|
|
else |
|
1259 |
colmap = map; |
colmap = map; |
1260 |
|
else |
1261 |
|
XSetWindowColormap(display, wnd, (Colormap) map); |
1262 |
} |
} |
1263 |
|
|
1264 |
void |
void |
1274 |
} |
} |
1275 |
|
|
1276 |
void |
void |
1277 |
ui_reset_clip() |
ui_reset_clip(void) |
1278 |
{ |
{ |
1279 |
XRectangle rect; |
XRectangle rect; |
1280 |
|
|
1286 |
} |
} |
1287 |
|
|
1288 |
void |
void |
1289 |
ui_bell() |
ui_bell(void) |
1290 |
{ |
{ |
1291 |
XBell(display, 0); |
XBell(display, 0); |
1292 |
} |
} |
1421 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE(x, y, cx, cy); |
1422 |
} |
} |
1423 |
|
|
1424 |
|
/* warning, this function only draws on wnd or backstore, not both */ |
1425 |
void |
void |
1426 |
ui_draw_glyph(int mixmode, |
ui_draw_glyph(int mixmode, |
1427 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
1436 |
XSetStipple(display, gc, (Pixmap) glyph); |
XSetStipple(display, gc, (Pixmap) glyph); |
1437 |
XSetTSOrigin(display, gc, x, y); |
XSetTSOrigin(display, gc, x, y); |
1438 |
|
|
1439 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
1440 |
|
|
1441 |
XSetFillStyle(display, gc, FillSolid); |
XSetFillStyle(display, gc, FillSolid); |
1442 |
} |
} |
1465 |
}\ |
}\ |
1466 |
if (glyph != NULL)\ |
if (glyph != NULL)\ |
1467 |
{\ |
{\ |
1468 |
ui_draw_glyph (mixmode, x + (short) glyph->offset,\ |
ui_draw_glyph (mixmode, x + glyph->offset,\ |
1469 |
y + (short) glyph->baseline,\ |
y + glyph->baseline,\ |
1470 |
glyph->width, glyph->height,\ |
glyph->width, glyph->height,\ |
1471 |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
1472 |
if (flags & TEXT2_IMPLICIT_X)\ |
if (flags & TEXT2_IMPLICIT_X)\ |
1488 |
|
|
1489 |
if (boxcx > 1) |
if (boxcx > 1) |
1490 |
{ |
{ |
1491 |
FILL_RECTANGLE(boxx, boxy, boxcx, boxcy); |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |
1492 |
} |
} |
1493 |
else if (mixmode == MIX_OPAQUE) |
else if (mixmode == MIX_OPAQUE) |
1494 |
{ |
{ |
1495 |
FILL_RECTANGLE(clipx, clipy, clipcx, clipcy); |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
1496 |
} |
} |
1497 |
|
|
1498 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
1506 |
else |
else |
1507 |
{ |
{ |
1508 |
error("this shouldn't be happening\n"); |
error("this shouldn't be happening\n"); |
1509 |
break; |
exit(1); |
1510 |
} |
} |
1511 |
/* this will move pointer from start to first character after FF command */ |
/* this will move pointer from start to first character after FF command */ |
1512 |
length -= i + 3; |
length -= i + 3; |
1526 |
else |
else |
1527 |
x += text[i + 2]; |
x += text[i + 2]; |
1528 |
} |
} |
|
if (i + 2 < length) |
|
|
i += 3; |
|
|
else |
|
|
i += 2; |
|
|
length -= i; |
|
|
/* this will move pointer from start to first character after FE command */ |
|
|
text = &(text[i]); |
|
|
i = 0; |
|
1529 |
for (j = 0; j < entry->size; j++) |
for (j = 0; j < entry->size; j++) |
1530 |
DO_GLYPH(((uint8 *) (entry->data)), j); |
DO_GLYPH(((uint8 *) (entry->data)), j); |
1531 |
} |
} |
1532 |
|
if (i + 2 < length) |
1533 |
|
i += 3; |
1534 |
|
else |
1535 |
|
i += 2; |
1536 |
|
length -= i; |
1537 |
|
/* this will move pointer from start to first character after FE command */ |
1538 |
|
text = &(text[i]); |
1539 |
|
i = 0; |
1540 |
break; |
break; |
1541 |
|
|
1542 |
default: |
default: |
1545 |
break; |
break; |
1546 |
} |
} |
1547 |
} |
} |
1548 |
|
if (ownbackstore) |
1549 |
|
{ |
1550 |
|
if (boxcx > 1) |
1551 |
|
XCopyArea(display, backstore, wnd, gc, boxx, |
1552 |
|
boxy, boxcx, boxcy, boxx, boxy); |
1553 |
|
else |
1554 |
|
XCopyArea(display, backstore, wnd, gc, clipx, |
1555 |
|
clipy, clipcx, clipcy, clipx, clipy); |
1556 |
|
} |
1557 |
} |
} |
1558 |
|
|
1559 |
void |
void |