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 |
|
extern int win_button_size; |
36 |
|
BOOL enable_compose = False; |
37 |
|
BOOL focused; |
38 |
|
BOOL mouse_in_wnd; |
39 |
|
|
40 |
Display *display = NULL; |
Display *display; |
41 |
static int x_socket; |
static int x_socket; |
42 |
|
static Screen *screen; |
43 |
static Window wnd; |
static Window wnd; |
44 |
static GC gc; |
static GC gc; |
45 |
static Visual *visual; |
static Visual *visual; |
46 |
static int depth; |
static int depth; |
47 |
static int bpp; |
static int bpp; |
48 |
static int dpy_width; |
static XIM IM; |
49 |
static int dpy_height; |
static XIC IC; |
50 |
|
static XModifierKeymap *mod_map; |
51 |
|
static Cursor current_cursor; |
52 |
|
static Atom protocol_atom, kill_atom; |
53 |
|
|
54 |
/* endianness */ |
/* endianness */ |
55 |
static BOOL host_be; |
static BOOL host_be; |
59 |
static BOOL ownbackstore; |
static BOOL ownbackstore; |
60 |
static Pixmap backstore; |
static Pixmap backstore; |
61 |
|
|
62 |
|
/* MWM decorations */ |
63 |
|
#define MWM_HINTS_DECORATIONS (1L << 1) |
64 |
|
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
65 |
|
typedef struct |
66 |
|
{ |
67 |
|
uint32 flags; |
68 |
|
uint32 functions; |
69 |
|
uint32 decorations; |
70 |
|
sint32 inputMode; |
71 |
|
uint32 status; |
72 |
|
} |
73 |
|
PropMotifWmHints; |
74 |
|
|
75 |
|
typedef struct |
76 |
|
{ |
77 |
|
uint32 red; |
78 |
|
uint32 green; |
79 |
|
uint32 blue; |
80 |
|
} |
81 |
|
PixelColour; |
82 |
|
|
83 |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
84 |
{ \ |
{ \ |
85 |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
87 |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
88 |
} |
} |
89 |
|
|
90 |
|
#define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\ |
91 |
|
{ \ |
92 |
|
XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \ |
93 |
|
} |
94 |
|
|
95 |
/* colour maps */ |
/* colour maps */ |
96 |
static BOOL owncolmap; |
BOOL owncolmap = False; |
97 |
static Colormap xcolmap; |
static Colormap xcolmap; |
|
static uint32 white; |
|
98 |
static uint32 *colmap; |
static uint32 *colmap; |
|
static XIM IM = NULL; |
|
|
static XIC IC = NULL; |
|
|
|
|
|
/* Compose support */ |
|
|
BOOL enable_compose = False; |
|
|
|
|
|
/* toggle fullscreen globals */ |
|
|
static XSetWindowAttributes attribs; |
|
|
static unsigned long input_mask; |
|
99 |
|
|
100 |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
#define TRANSLATE(col) ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) ) |
101 |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
102 |
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
103 |
|
|
124 |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
125 |
|
|
126 |
static void |
static void |
127 |
translate8(uint8 * data, uint8 * out, uint8 * end) |
mwm_hide_decorations(void) |
128 |
{ |
{ |
129 |
while (out < end) |
PropMotifWmHints motif_hints; |
130 |
*(out++) = (uint8) colmap[*(data++)]; |
Atom hintsatom; |
|
} |
|
131 |
|
|
132 |
static void |
/* setup the property */ |
133 |
translate16(uint8 * data, uint16 * out, uint16 * end) |
motif_hints.flags = MWM_HINTS_DECORATIONS; |
134 |
{ |
motif_hints.decorations = 0; |
|
while (out < end) |
|
|
*(out++) = (uint16) colmap[*(data++)]; |
|
|
} |
|
135 |
|
|
136 |
/* little endian - conversion happens when colourmap is built */ |
/* get the atom for the property */ |
137 |
static void |
hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); |
138 |
translate24(uint8 * data, uint8 * out, uint8 * end) |
if (!hintsatom) |
|
{ |
|
|
uint32 value; |
|
|
|
|
|
while (out < end) |
|
139 |
{ |
{ |
140 |
value = colmap[*(data++)]; |
warning("Failed to get atom _MOTIF_WM_HINTS: probably your window manager does not support MWM hints\n"); |
141 |
*(out++) = value; |
return; |
|
*(out++) = value >> 8; |
|
|
*(out++) = value >> 16; |
|
142 |
} |
} |
143 |
|
|
144 |
|
XChangeProperty(display, wnd, hintsatom, hintsatom, 32, PropModeReplace, |
145 |
|
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
146 |
} |
} |
147 |
|
|
148 |
static void |
static PixelColour |
149 |
translate32(uint8 * data, uint32 * out, uint32 * end) |
split_colour15(uint32 colour) |
150 |
{ |
{ |
151 |
while (out < end) |
PixelColour rv; |
152 |
*(out++) = colmap[*(data++)]; |
rv.red = (colour & 0x7c00) >> 10; |
153 |
|
rv.red = (rv.red * 0xff) / 0x1f; |
154 |
|
rv.green = (colour & 0x03e0) >> 5; |
155 |
|
rv.green = (rv.green * 0xff) / 0x1f; |
156 |
|
rv.blue = (colour & 0x1f); |
157 |
|
rv.blue = (rv.blue * 0xff) / 0x1f; |
158 |
|
return rv; |
159 |
} |
} |
160 |
|
|
161 |
static uint8 * |
static PixelColour |
162 |
translate_image(int width, int height, uint8 * data) |
split_colour16(uint32 colour) |
163 |
{ |
{ |
164 |
int size = width * height * bpp / 8; |
PixelColour rv; |
165 |
uint8 *out = xmalloc(size); |
rv.red = (colour & 0xf800) >> 11; |
166 |
uint8 *end = out + size; |
rv.red = (rv.red * 0xff) / 0x1f; |
167 |
|
rv.green = (colour & 0x07e0) >> 5; |
168 |
switch (bpp) |
rv.green = (rv.green * 0xff) / 0x3f; |
169 |
{ |
rv.blue = (colour & 0x001f); |
170 |
case 8: |
rv.blue = (rv.blue * 0xff) / 0x1f; |
171 |
translate8(data, out, end); |
return rv; |
172 |
break; |
} |
173 |
|
|
174 |
case 16: |
static PixelColour |
175 |
translate16(data, (uint16 *) out, (uint16 *) end); |
split_colour24(uint32 colour) |
176 |
break; |
{ |
177 |
|
PixelColour rv; |
178 |
|
rv.blue = (colour & 0xff0000) >> 16; |
179 |
|
rv.green = (colour & 0xff00) >> 8; |
180 |
|
rv.red = (colour & 0xff); |
181 |
|
return rv; |
182 |
|
} |
183 |
|
|
184 |
case 24: |
static uint32 |
185 |
translate24(data, out, end); |
make_colour16(PixelColour pc) |
186 |
break; |
{ |
187 |
|
pc.red = (pc.red * 0x1f) / 0xff; |
188 |
|
pc.green = (pc.green * 0x3f) / 0xff; |
189 |
|
pc.blue = (pc.blue * 0x1f) / 0xff; |
190 |
|
return (pc.red << 11) | (pc.green << 5) | pc.blue; |
191 |
|
} |
192 |
|
|
193 |
case 32: |
static uint32 |
194 |
translate32(data, (uint32 *) out, (uint32 *) end); |
make_colour24(PixelColour pc) |
195 |
break; |
{ |
196 |
} |
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
197 |
|
} |
198 |
|
|
199 |
return out; |
static uint32 |
200 |
|
make_colour32(PixelColour pc) |
201 |
|
{ |
202 |
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
203 |
} |
} |
204 |
|
|
205 |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
210 |
static uint32 |
static uint32 |
211 |
translate_colour(uint32 colour) |
translate_colour(uint32 colour) |
212 |
{ |
{ |
213 |
|
switch (server_bpp) |
214 |
|
{ |
215 |
|
case 15: |
216 |
|
switch (bpp) |
217 |
|
{ |
218 |
|
case 16: |
219 |
|
colour = make_colour16(split_colour15(colour)); |
220 |
|
break; |
221 |
|
case 24: |
222 |
|
colour = make_colour24(split_colour15(colour)); |
223 |
|
break; |
224 |
|
case 32: |
225 |
|
colour = make_colour32(split_colour15(colour)); |
226 |
|
break; |
227 |
|
} |
228 |
|
break; |
229 |
|
case 16: |
230 |
|
switch (bpp) |
231 |
|
{ |
232 |
|
case 16: |
233 |
|
break; |
234 |
|
case 24: |
235 |
|
colour = make_colour24(split_colour16(colour)); |
236 |
|
break; |
237 |
|
case 32: |
238 |
|
colour = make_colour32(split_colour16(colour)); |
239 |
|
break; |
240 |
|
} |
241 |
|
break; |
242 |
|
case 24: |
243 |
|
switch (bpp) |
244 |
|
{ |
245 |
|
case 16: |
246 |
|
colour = make_colour16(split_colour24(colour)); |
247 |
|
break; |
248 |
|
case 24: |
249 |
|
break; |
250 |
|
case 32: |
251 |
|
colour = make_colour32(split_colour24(colour)); |
252 |
|
break; |
253 |
|
} |
254 |
|
break; |
255 |
|
} |
256 |
switch (bpp) |
switch (bpp) |
257 |
{ |
{ |
258 |
case 16: |
case 16: |
274 |
return colour; |
return colour; |
275 |
} |
} |
276 |
|
|
277 |
static unsigned long |
static void |
278 |
init_inputmethod(void) |
translate8to8(uint8 * data, uint8 * out, uint8 * end) |
279 |
|
{ |
280 |
|
while (out < end) |
281 |
|
*(out++) = (uint8) colmap[*(data++)]; |
282 |
|
} |
283 |
|
|
284 |
|
static void |
285 |
|
translate8to16(uint8 * data, uint16 * out, uint16 * end) |
286 |
|
{ |
287 |
|
while (out < end) |
288 |
|
*(out++) = (uint16) colmap[*(data++)]; |
289 |
|
} |
290 |
|
|
291 |
|
/* little endian - conversion happens when colourmap is built */ |
292 |
|
static void |
293 |
|
translate8to24(uint8 * data, uint8 * out, uint8 * end) |
294 |
{ |
{ |
295 |
unsigned long filtered_events = 0; |
uint32 value; |
296 |
|
|
297 |
IM = XOpenIM(display, NULL, NULL, NULL); |
while (out < end) |
|
if (IM == NULL) |
|
298 |
{ |
{ |
299 |
error("Failed to open input method\n"); |
value = colmap[*(data++)]; |
300 |
|
*(out++) = value; |
301 |
|
*(out++) = value >> 8; |
302 |
|
*(out++) = value >> 16; |
303 |
} |
} |
304 |
|
} |
305 |
|
|
306 |
if (IM != NULL) |
static void |
307 |
{ |
translate8to32(uint8 * data, uint32 * out, uint32 * end) |
308 |
/* Must be done after XCreateWindow */ |
{ |
309 |
IC = XCreateIC(IM, XNInputStyle, |
while (out < end) |
310 |
(XIMPreeditNothing | XIMStatusNothing), |
*(out++) = colmap[*(data++)]; |
311 |
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
} |
312 |
|
|
313 |
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; |
|
|
} |
|
|
} |
|
314 |
|
|
315 |
/* For correct Multi_key/Compose processing, I guess. |
static void |
316 |
It seems to work alright anyway, though. */ |
translate15to16(uint16 * data, uint16 * out, uint16 * end) |
317 |
if (IC != NULL) |
{ |
318 |
{ |
while (out < end) |
319 |
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; |
|
320 |
} |
} |
321 |
|
|
322 |
static void |
static void |
323 |
close_inputmethod(void) |
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
324 |
{ |
{ |
325 |
if (IC != NULL) |
uint32 value; |
326 |
|
|
327 |
|
while (out < end) |
328 |
{ |
{ |
329 |
XDestroyIC(IC); |
value = make_colour24(split_colour15(*(data++))); |
330 |
if (IM != NULL) |
*(out++) = value; |
331 |
{ |
*(out++) = value >> 8; |
332 |
XCloseIM(IM); |
*(out++) = value >> 16; |
|
IM = NULL; |
|
|
} |
|
333 |
} |
} |
334 |
} |
} |
335 |
|
|
336 |
static BOOL |
static void |
337 |
get_key_state(int keysym) |
translate15to32(uint16 * data, uint32 * out, uint32 * end) |
338 |
{ |
{ |
339 |
int keysymMask = 0, modifierpos, key; |
while (out < end) |
340 |
Window wDummy1, wDummy2; |
*(out++) = make_colour32(split_colour15(*(data++))); |
341 |
int iDummy3, iDummy4, iDummy5, iDummy6; |
} |
|
unsigned int current_state; |
|
|
int offset; |
|
342 |
|
|
343 |
XModifierKeymap *map = XGetModifierMapping(display); |
static void |
344 |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
345 |
|
{ |
346 |
|
while (out < end) |
347 |
|
*(out++) = (uint16) (*(data++)); |
348 |
|
} |
349 |
|
|
|
if (keycode == NoSymbol) |
|
|
return False; |
|
350 |
|
|
351 |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
static void |
352 |
{ |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
353 |
offset = map->max_keypermod * modifierpos; |
{ |
354 |
|
uint32 value; |
355 |
|
|
356 |
for (key = 0; key < map->max_keypermod; key++) |
while (out < end) |
357 |
{ |
{ |
358 |
if (map->modifiermap[offset + key] == keycode) |
value = make_colour24(split_colour16(*(data++))); |
359 |
keysymMask = 1 << modifierpos; |
*(out++) = value; |
360 |
} |
*(out++) = value >> 8; |
361 |
|
*(out++) = value >> 16; |
362 |
} |
} |
|
|
|
|
XQueryPointer(display, DefaultRootWindow(display), &wDummy1, |
|
|
&wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, ¤t_state); |
|
|
|
|
|
XFreeModifiermap(map); |
|
|
|
|
|
return (current_state & keysymMask) ? True : False; |
|
363 |
} |
} |
364 |
|
|
365 |
|
static void |
366 |
|
translate16to32(uint16 * data, uint32 * out, uint32 * end) |
367 |
|
{ |
368 |
|
while (out < end) |
369 |
|
*(out++) = make_colour32(split_colour16(*(data++))); |
370 |
|
} |
371 |
|
|
372 |
BOOL |
static void |
373 |
ui_init() |
translate24to16(uint8 * data, uint16 * out, uint16 * end) |
374 |
{ |
{ |
375 |
Screen *screen; |
uint32 pixel = 0; |
376 |
display = XOpenDisplay(NULL); |
while (out < end) |
|
if (display == NULL) |
|
377 |
{ |
{ |
378 |
error("Failed to open display\n"); |
pixel = *(data++) << 16; |
379 |
return False; |
pixel |= *(data++) << 8; |
380 |
|
pixel |= *(data++); |
381 |
|
*(out++) = (uint16) make_colour16(split_colour24(pixel)); |
382 |
} |
} |
383 |
if (fullscreen) |
} |
384 |
|
|
385 |
|
static void |
386 |
|
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
387 |
|
{ |
388 |
|
while (out < end) |
389 |
{ |
{ |
390 |
screen = DefaultScreenOfDisplay(display); |
*(out++) = (*(data++)); |
|
width = WidthOfScreen(screen); |
|
|
height = HeightOfScreen(screen); |
|
391 |
} |
} |
|
return True; |
|
392 |
} |
} |
393 |
|
|
394 |
void |
static void |
395 |
ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask) |
translate24to32(uint8 * data, uint32 * out, uint32 * end) |
396 |
{ |
{ |
397 |
XClassHint *classhints; |
uint32 pixel = 0; |
398 |
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) |
|
399 |
{ |
{ |
400 |
classhints->res_name = classhints->res_class = "rdesktop"; |
memcpy(&pixel, data, 3); |
401 |
XSetClassHint(display, wnd, classhints); |
data += 3; |
402 |
XFree(classhints); |
*(out++) = pixel; |
403 |
} |
} |
404 |
|
} |
405 |
|
|
406 |
sizehints = XAllocSizeHints(); |
static uint8 * |
407 |
if (sizehints) |
translate_image(int width, int height, uint8 * data) |
408 |
|
{ |
409 |
|
int size = width * height * bpp / 8; |
410 |
|
uint8 *out = xmalloc(size); |
411 |
|
uint8 *end = out + size; |
412 |
|
|
413 |
|
switch (server_bpp) |
414 |
{ |
{ |
415 |
sizehints->flags = PMinSize | PMaxSize; |
case 24: |
416 |
sizehints->min_width = sizehints->max_width = width; |
switch (bpp) |
417 |
sizehints->min_height = sizehints->max_height = height; |
{ |
418 |
XSetWMNormalHints(display, wnd, sizehints); |
case 32: |
419 |
XFree(sizehints); |
translate24to32(data, (uint32 *) out, (uint32 *) end); |
420 |
|
break; |
421 |
|
case 24: |
422 |
|
translate24to24(data, out, end); |
423 |
|
break; |
424 |
|
case 16: |
425 |
|
translate24to16(data, (uint16 *) out, (uint16 *) end); |
426 |
|
break; |
427 |
|
} |
428 |
|
break; |
429 |
|
case 16: |
430 |
|
switch (bpp) |
431 |
|
{ |
432 |
|
case 32: |
433 |
|
translate16to32((uint16 *) data, (uint32 *) out, |
434 |
|
(uint32 *) end); |
435 |
|
break; |
436 |
|
case 24: |
437 |
|
translate16to24((uint16 *) data, out, end); |
438 |
|
break; |
439 |
|
case 16: |
440 |
|
translate16to16((uint16 *) data, (uint16 *) out, |
441 |
|
(uint16 *) end); |
442 |
|
break; |
443 |
|
} |
444 |
|
break; |
445 |
|
case 15: |
446 |
|
switch (bpp) |
447 |
|
{ |
448 |
|
case 32: |
449 |
|
translate15to32((uint16 *) data, (uint32 *) out, |
450 |
|
(uint32 *) end); |
451 |
|
break; |
452 |
|
case 24: |
453 |
|
translate15to24((uint16 *) data, out, end); |
454 |
|
break; |
455 |
|
case 16: |
456 |
|
translate15to16((uint16 *) data, (uint16 *) out, |
457 |
|
(uint16 *) end); |
458 |
|
break; |
459 |
|
} |
460 |
|
break; |
461 |
|
case 8: |
462 |
|
switch (bpp) |
463 |
|
{ |
464 |
|
case 8: |
465 |
|
translate8to8(data, out, end); |
466 |
|
break; |
467 |
|
case 16: |
468 |
|
translate8to16(data, (uint16 *) out, (uint16 *) end); |
469 |
|
break; |
470 |
|
case 24: |
471 |
|
translate8to24(data, out, end); |
472 |
|
break; |
473 |
|
case 32: |
474 |
|
translate8to32(data, (uint32 *) out, (uint32 *) end); |
475 |
|
break; |
476 |
|
} |
477 |
|
break; |
478 |
} |
} |
479 |
|
return out; |
480 |
|
} |
481 |
|
|
482 |
if (enable_compose) |
BOOL |
483 |
input_mask |= init_inputmethod(); |
get_key_state(unsigned int state, uint32 keysym) |
484 |
|
{ |
485 |
XSelectInput(display, wnd, input_mask); |
int modifierpos, key, keysymMask = 0; |
486 |
|
int offset; |
487 |
|
|
488 |
gc = XCreateGC(display, wnd, 0, NULL); |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
489 |
|
|
490 |
XMapWindow(display, wnd); |
if (keycode == NoSymbol) |
491 |
|
return False; |
492 |
|
|
493 |
/* Wait for VisibilityNotify Event */ |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
|
for (;;) |
|
494 |
{ |
{ |
495 |
XNextEvent(display, &xevent); |
offset = mod_map->max_keypermod * modifierpos; |
|
if (xevent.type == VisibilityNotify) |
|
|
break; |
|
|
} |
|
496 |
|
|
497 |
if (ownbackstore) |
for (key = 0; key < mod_map->max_keypermod; key++) |
498 |
backstore = XCreatePixmap(display, wnd, width, height, depth); |
{ |
499 |
|
if (mod_map->modifiermap[offset + key] == keycode) |
500 |
|
keysymMask |= 1 << modifierpos; |
501 |
|
} |
502 |
|
} |
503 |
|
|
504 |
/* 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); |
|
505 |
} |
} |
506 |
|
|
507 |
BOOL |
BOOL |
508 |
ui_create_window() |
ui_init(void) |
509 |
{ |
{ |
510 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
|
Screen *screen; |
|
511 |
uint16 test; |
uint16 test; |
512 |
int i; |
int i; |
513 |
|
|
514 |
|
display = XOpenDisplay(NULL); |
515 |
|
if (display == NULL) |
516 |
|
{ |
517 |
|
error("Failed to open display: %s\n", XDisplayName(NULL)); |
518 |
|
return False; |
519 |
|
} |
520 |
|
|
521 |
x_socket = ConnectionNumber(display); |
x_socket = ConnectionNumber(display); |
522 |
screen = DefaultScreenOfDisplay(display); |
screen = DefaultScreenOfDisplay(display); |
523 |
visual = DefaultVisualOfScreen(screen); |
visual = DefaultVisualOfScreen(screen); |
545 |
return False; |
return False; |
546 |
} |
} |
547 |
|
|
548 |
if (depth <= 8) |
if (owncolmap != True) |
549 |
owncolmap = True; |
{ |
|
else |
|
550 |
xcolmap = DefaultColormapOfScreen(screen); |
xcolmap = DefaultColormapOfScreen(screen); |
551 |
|
if (depth <= 8) |
552 |
|
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
553 |
|
} |
554 |
|
|
555 |
|
gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); |
556 |
|
|
557 |
|
if (DoesBackingStore(screen) != Always) |
558 |
|
ownbackstore = True; |
559 |
|
|
560 |
test = 1; |
test = 1; |
561 |
host_be = !(BOOL) (*(uint8 *) (&test)); |
host_be = !(BOOL) (*(uint8 *) (&test)); |
562 |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
563 |
|
|
564 |
white = WhitePixelOfScreen(screen); |
if ((width == 0) || (height == 0)) |
565 |
attribs.background_pixel = BlackPixelOfScreen(screen); |
{ |
566 |
attribs.backing_store = DoesBackingStore(screen); |
/* Fetch geometry from _NET_WORKAREA */ |
567 |
|
uint32 x, y, cx, cy; |
|
if (attribs.backing_store == NotUseful) |
|
|
ownbackstore = True; |
|
568 |
|
|
569 |
dpy_width = WidthOfScreen(screen); |
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
570 |
dpy_height = HeightOfScreen(screen); |
{ |
571 |
|
width = cx; |
572 |
|
height = cy; |
573 |
|
} |
574 |
|
else |
575 |
|
{ |
576 |
|
warning("Failed to get workarea: probably your window manager does not support extended hints\n"); |
577 |
|
width = 800; |
578 |
|
height = 600; |
579 |
|
} |
580 |
|
} |
581 |
|
|
582 |
if (fullscreen) |
if (fullscreen) |
583 |
{ |
{ |
584 |
attribs.override_redirect = True; |
width = WidthOfScreen(screen); |
585 |
width = dpy_width; |
height = HeightOfScreen(screen); |
|
height = dpy_height; |
|
586 |
} |
} |
587 |
else |
|
588 |
|
/* make sure width is a multiple of 4 */ |
589 |
|
width = (width + 3) & ~3; |
590 |
|
|
591 |
|
if (ownbackstore) |
592 |
{ |
{ |
593 |
attribs.override_redirect = False; |
backstore = |
594 |
|
XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); |
595 |
|
|
596 |
|
/* clear to prevent rubbish being exposed at startup */ |
597 |
|
XSetForeground(display, gc, BlackPixelOfScreen(screen)); |
598 |
|
XFillRectangle(display, backstore, gc, 0, 0, width, height); |
599 |
} |
} |
600 |
|
|
601 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
mod_map = XGetModifierMapping(display); |
|
VisibilityChangeMask | FocusChangeMask; |
|
602 |
|
|
603 |
if (grab_keyboard) |
if (enable_compose) |
604 |
input_mask |= EnterWindowMask | LeaveWindowMask; |
IM = XOpenIM(display, NULL, NULL, NULL); |
|
if (sendmotion) |
|
|
input_mask |= PointerMotionMask; |
|
|
|
|
|
if (ownbackstore) |
|
|
input_mask |= ExposureMask; |
|
605 |
|
|
606 |
if (fullscreen) |
xkeymap_init(); |
|
ui_create_window_obj(0, 0, width, height, |
|
|
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
|
|
else |
|
|
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
|
607 |
|
|
608 |
xkeymap_init2(); |
/* todo take this out when high colour is done */ |
609 |
|
printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth); |
610 |
|
|
611 |
return True; |
return True; |
612 |
} |
} |
613 |
|
|
614 |
void |
void |
615 |
ui_destroy_window() |
ui_deinit(void) |
616 |
{ |
{ |
617 |
|
if (IM != NULL) |
618 |
|
XCloseIM(IM); |
619 |
|
|
620 |
|
XFreeModifiermap(mod_map); |
621 |
|
|
622 |
if (ownbackstore) |
if (ownbackstore) |
623 |
XFreePixmap(display, backstore); |
XFreePixmap(display, backstore); |
624 |
|
|
625 |
XFreeGC(display, gc); |
XFreeGC(display, gc); |
|
|
|
|
close_inputmethod(); |
|
|
|
|
|
XDestroyWindow(display, wnd); |
|
626 |
XCloseDisplay(display); |
XCloseDisplay(display); |
627 |
display = NULL; |
display = NULL; |
628 |
} |
} |
629 |
|
|
630 |
void |
BOOL |
631 |
reset_keys() |
ui_create_window(void) |
632 |
{ |
{ |
633 |
/* reset keys */ |
XSetWindowAttributes attribs; |
634 |
uint32 ev_time; |
XClassHint *classhints; |
635 |
ev_time = time(NULL); |
XSizeHints *sizehints; |
636 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
int wndwidth, wndheight; |
637 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
long input_mask, ic_input_mask; |
638 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
XEvent xevent; |
639 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
|
640 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
wndwidth = fullscreen ? WidthOfScreen(screen) : width; |
641 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
wndheight = fullscreen ? HeightOfScreen(screen) : height; |
642 |
|
|
643 |
|
attribs.background_pixel = BlackPixelOfScreen(screen); |
644 |
|
attribs.backing_store = ownbackstore ? NotUseful : Always; |
645 |
|
attribs.override_redirect = fullscreen; |
646 |
|
|
647 |
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth, wndheight, |
648 |
|
0, CopyFromParent, InputOutput, CopyFromParent, |
649 |
|
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
650 |
|
|
651 |
|
XStoreName(display, wnd, title); |
652 |
|
|
653 |
|
if (hide_decorations) |
654 |
|
mwm_hide_decorations(); |
655 |
|
|
656 |
|
classhints = XAllocClassHint(); |
657 |
|
if (classhints != NULL) |
658 |
|
{ |
659 |
|
classhints->res_name = classhints->res_class = "rdesktop"; |
660 |
|
XSetClassHint(display, wnd, classhints); |
661 |
|
XFree(classhints); |
662 |
|
} |
663 |
|
|
664 |
|
sizehints = XAllocSizeHints(); |
665 |
|
if (sizehints) |
666 |
|
{ |
667 |
|
sizehints->flags = PMinSize | PMaxSize; |
668 |
|
sizehints->min_width = sizehints->max_width = width; |
669 |
|
sizehints->min_height = sizehints->max_height = height; |
670 |
|
XSetWMNormalHints(display, wnd, sizehints); |
671 |
|
XFree(sizehints); |
672 |
|
} |
673 |
|
|
674 |
|
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
675 |
|
VisibilityChangeMask | FocusChangeMask; |
676 |
|
|
677 |
|
if (sendmotion) |
678 |
|
input_mask |= PointerMotionMask; |
679 |
|
if (ownbackstore) |
680 |
|
input_mask |= ExposureMask; |
681 |
|
if (fullscreen || grab_keyboard) |
682 |
|
input_mask |= EnterWindowMask; |
683 |
|
if (grab_keyboard) |
684 |
|
input_mask |= LeaveWindowMask; |
685 |
|
|
686 |
|
if (IM != NULL) |
687 |
|
{ |
688 |
|
IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), |
689 |
|
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
690 |
|
|
691 |
|
if ((IC != NULL) |
692 |
|
&& (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) |
693 |
|
input_mask |= ic_input_mask; |
694 |
|
} |
695 |
|
|
696 |
|
XSelectInput(display, wnd, input_mask); |
697 |
|
XMapWindow(display, wnd); |
698 |
|
|
699 |
|
/* wait for VisibilityNotify */ |
700 |
|
do |
701 |
|
{ |
702 |
|
XMaskEvent(display, VisibilityChangeMask, &xevent); |
703 |
|
} |
704 |
|
while (xevent.type != VisibilityNotify); |
705 |
|
|
706 |
|
focused = False; |
707 |
|
mouse_in_wnd = False; |
708 |
|
|
709 |
|
/* handle the WM_DELETE_WINDOW protocol */ |
710 |
|
protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True); |
711 |
|
kill_atom = XInternAtom(display, "WM_DELETE_WINDOW", True); |
712 |
|
XSetWMProtocols(display, wnd, &kill_atom, 1); |
713 |
|
|
714 |
|
return True; |
715 |
} |
} |
716 |
|
|
717 |
void |
void |
718 |
toggle_fullscreen() |
ui_destroy_window(void) |
719 |
{ |
{ |
720 |
/* save window contents */ |
if (IC != NULL) |
721 |
Pixmap pixmap; |
XDestroyIC(IC); |
722 |
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); |
|
723 |
XDestroyWindow(display, wnd); |
XDestroyWindow(display, wnd); |
724 |
if (fullscreen) |
} |
725 |
|
|
726 |
|
void |
727 |
|
xwin_toggle_fullscreen(void) |
728 |
|
{ |
729 |
|
Pixmap contents = 0; |
730 |
|
|
731 |
|
if (!ownbackstore) |
732 |
{ |
{ |
733 |
attribs.override_redirect = True; |
/* need to save contents of window */ |
734 |
ui_create_window_obj(0, 0, dpy_width, dpy_height, |
contents = XCreatePixmap(display, wnd, width, height, depth); |
735 |
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
XCopyArea(display, wnd, contents, gc, 0, 0, width, height, 0, 0); |
736 |
} |
} |
737 |
else |
|
738 |
|
ui_destroy_window(); |
739 |
|
fullscreen = !fullscreen; |
740 |
|
ui_create_window(); |
741 |
|
|
742 |
|
XDefineCursor(display, wnd, current_cursor); |
743 |
|
|
744 |
|
if (!ownbackstore) |
745 |
{ |
{ |
746 |
attribs.override_redirect = False; |
XCopyArea(display, contents, wnd, gc, 0, 0, width, height, 0, 0); |
747 |
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
XFreePixmap(display, contents); |
748 |
} |
} |
|
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); |
|
749 |
} |
} |
750 |
|
|
751 |
static void |
/* Process all events in Xlib queue |
752 |
xwin_process_events() |
Returns 0 after user quit, 1 otherwise */ |
753 |
|
static int |
754 |
|
xwin_process_events(void) |
755 |
{ |
{ |
756 |
XEvent xevent; |
XEvent xevent; |
|
|
|
757 |
KeySym keysym; |
KeySym keysym; |
758 |
uint16 button, flags; |
uint16 button, flags; |
759 |
uint32 ev_time; |
uint32 ev_time; |
760 |
key_translation tr; |
key_translation tr; |
|
char *ksname = NULL; |
|
761 |
char str[256]; |
char str[256]; |
762 |
Status status; |
Status status; |
763 |
|
unsigned int state; |
764 |
|
Window wdummy; |
765 |
|
int dummy; |
766 |
|
|
767 |
/* 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)) |
|
768 |
{ |
{ |
769 |
if (xevent.xmapping.request == MappingKeyboard |
XNextEvent(display, &xevent); |
|
|| xevent.xmapping.request == MappingModifier) |
|
|
XRefreshKeyboardMapping(&xevent.xmapping); |
|
|
} |
|
770 |
|
|
771 |
while (XCheckMaskEvent(display, ~0, &xevent)) |
if ((IC != NULL) && (XFilterEvent(&xevent, None) == True)) |
|
{ |
|
|
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
|
772 |
{ |
{ |
773 |
DEBUG_KBD(("Filtering event\n")); |
DEBUG_KBD(("Filtering event\n")); |
774 |
continue; |
continue; |
775 |
} |
} |
776 |
|
|
|
ev_time = time(NULL); |
|
777 |
flags = 0; |
flags = 0; |
778 |
|
|
779 |
switch (xevent.type) |
switch (xevent.type) |
780 |
{ |
{ |
781 |
|
case ClientMessage: |
782 |
|
/* the window manager told us to quit */ |
783 |
|
if ((xevent.xclient.message_type == protocol_atom) |
784 |
|
&& (xevent.xclient.data.l[0] == kill_atom)) |
785 |
|
/* Quit */ |
786 |
|
return 0; |
787 |
|
break; |
788 |
|
|
789 |
case KeyPress: |
case KeyPress: |
790 |
if (IC != NULL) |
if (IC != NULL) |
791 |
/* Multi_key compatible version */ |
/* Multi_key compatible version */ |
803 |
else |
else |
804 |
{ |
{ |
805 |
/* Plain old XLookupString */ |
/* Plain old XLookupString */ |
806 |
DEBUG_KBD(("No input context, using XLookupString\n")); |
DEBUG_KBD(("\nNo input context, using XLookupString\n")); |
807 |
XLookupString((XKeyEvent *) & xevent, |
XLookupString((XKeyEvent *) & xevent, |
808 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
809 |
} |
} |
810 |
|
|
811 |
if (keysym == XK_Break) /* toggle full screen */ |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, |
812 |
{ |
get_ksname(keysym))); |
|
if (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R)) |
|
|
{ |
|
|
toggle_fullscreen(); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
ksname = get_ksname(keysym); |
|
|
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
|
813 |
|
|
814 |
if (inhibit_key(keysym)) |
ev_time = time(NULL); |
815 |
{ |
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
|
DEBUG_KBD(("Inhibiting key\n")); |
|
816 |
break; |
break; |
|
} |
|
817 |
|
|
818 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
819 |
xevent.xkey.keycode, xevent.xkey.state); |
xevent.xkey.keycode, xevent.xkey.state); |
820 |
|
|
|
ensure_remote_modifiers(ev_time, tr); |
|
|
|
|
821 |
if (tr.scancode == 0) |
if (tr.scancode == 0) |
822 |
break; |
break; |
823 |
|
|
824 |
|
ensure_remote_modifiers(ev_time, tr); |
825 |
|
|
826 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
827 |
break; |
break; |
828 |
|
|
829 |
case KeyRelease: |
case KeyRelease: |
830 |
XLookupString((XKeyEvent *) & xevent, str, |
XLookupString((XKeyEvent *) & xevent, str, |
831 |
sizeof(str), &keysym, NULL); |
sizeof(str), &keysym, NULL); |
832 |
|
|
|
ksname = get_ksname(keysym); |
|
833 |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
834 |
ksname)); |
get_ksname(keysym))); |
835 |
|
|
836 |
if (inhibit_key(keysym)) |
ev_time = time(NULL); |
837 |
|
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False)) |
838 |
break; |
break; |
839 |
|
|
840 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
855 |
if (button == 0) |
if (button == 0) |
856 |
break; |
break; |
857 |
|
|
858 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
/* If win_button_size is nonzero, enable single app mode */ |
859 |
|
if (xevent.xbutton.y < win_button_size) |
860 |
|
{ |
861 |
|
/* Check from right to left: */ |
862 |
|
|
863 |
|
if (xevent.xbutton.x >= width - win_button_size) |
864 |
|
{ |
865 |
|
/* The close button, continue */ |
866 |
|
; |
867 |
|
} |
868 |
|
else if (xevent.xbutton.x >= width - win_button_size * 2) |
869 |
|
{ |
870 |
|
/* The maximize/restore button. Do not send to |
871 |
|
server. It might be a good idea to change the |
872 |
|
cursor or give some other visible indication |
873 |
|
that rdesktop inhibited this click */ |
874 |
|
break; |
875 |
|
} |
876 |
|
else if (xevent.xbutton.x >= width - win_button_size * 3) |
877 |
|
{ |
878 |
|
/* The minimize button. Iconify window. */ |
879 |
|
XIconifyWindow(display, wnd, |
880 |
|
DefaultScreen(display)); |
881 |
|
break; |
882 |
|
} |
883 |
|
else |
884 |
|
{ |
885 |
|
/* Ignore clicks to the rest of the border. This includes |
886 |
|
the system menu, but also inhibits double clicks on the |
887 |
|
border itself. */ |
888 |
|
break; |
889 |
|
} |
890 |
|
} |
891 |
|
|
892 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
893 |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
894 |
break; |
break; |
895 |
|
|
896 |
case MotionNotify: |
case MotionNotify: |
897 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
if (fullscreen && !focused) |
898 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
899 |
|
CurrentTime); |
900 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
901 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
902 |
break; |
break; |
903 |
|
|
904 |
case FocusIn: |
case FocusIn: |
905 |
/* fall through */ |
if (xevent.xfocus.mode == NotifyGrab) |
906 |
case EnterNotify: |
break; |
907 |
if (grab_keyboard) |
focused = True; |
908 |
|
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, |
909 |
|
&dummy, &dummy, &state); |
910 |
|
reset_modifier_keys(state); |
911 |
|
if (grab_keyboard && mouse_in_wnd) |
912 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
913 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
914 |
break; |
break; |
915 |
|
|
916 |
case FocusOut: |
case FocusOut: |
917 |
reset_keys(); |
if (xevent.xfocus.mode == NotifyUngrab) |
918 |
/* fall through */ |
break; |
919 |
case LeaveNotify: |
focused = False; |
920 |
if (grab_keyboard) |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
921 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
922 |
break; |
break; |
923 |
|
|
924 |
|
case EnterNotify: |
925 |
|
/* we only register for this event when in fullscreen mode */ |
926 |
|
/* or grab_keyboard */ |
927 |
|
mouse_in_wnd = True; |
928 |
|
if (fullscreen) |
929 |
|
{ |
930 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
931 |
|
CurrentTime); |
932 |
|
break; |
933 |
|
} |
934 |
|
if (focused) |
935 |
|
XGrabKeyboard(display, wnd, True, |
936 |
|
GrabModeAsync, GrabModeAsync, CurrentTime); |
937 |
|
break; |
938 |
|
|
939 |
|
case LeaveNotify: |
940 |
|
/* we only register for this event when grab_keyboard */ |
941 |
|
mouse_in_wnd = False; |
942 |
|
XUngrabKeyboard(display, CurrentTime); |
943 |
|
break; |
944 |
|
|
945 |
case Expose: |
case Expose: |
946 |
XCopyArea(display, backstore, wnd, gc, |
XCopyArea(display, backstore, wnd, gc, |
947 |
xevent.xexpose.x, xevent.xexpose.y, |
xevent.xexpose.x, xevent.xexpose.y, |
949 |
xevent.xexpose.height, |
xevent.xexpose.height, |
950 |
xevent.xexpose.x, xevent.xexpose.y); |
xevent.xexpose.x, xevent.xexpose.y); |
951 |
break; |
break; |
952 |
|
|
953 |
|
case MappingNotify: |
954 |
|
/* Refresh keyboard mapping if it has changed. This is important for |
955 |
|
Xvnc, since it allocates keycodes dynamically */ |
956 |
|
if (xevent.xmapping.request == MappingKeyboard |
957 |
|
|| xevent.xmapping.request == MappingModifier) |
958 |
|
XRefreshKeyboardMapping(&xevent.xmapping); |
959 |
|
|
960 |
|
if (xevent.xmapping.request == MappingModifier) |
961 |
|
{ |
962 |
|
XFreeModifiermap(mod_map); |
963 |
|
mod_map = XGetModifierMapping(display); |
964 |
|
} |
965 |
|
break; |
966 |
|
|
967 |
} |
} |
968 |
} |
} |
969 |
|
/* Keep going */ |
970 |
|
return 1; |
971 |
} |
} |
972 |
|
|
973 |
void |
/* Returns 0 after user quit, 1 otherwise */ |
974 |
|
int |
975 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
976 |
{ |
{ |
977 |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
981 |
|
|
982 |
while (True) |
while (True) |
983 |
{ |
{ |
984 |
|
/* Process any events already waiting */ |
985 |
|
if (!xwin_process_events()) |
986 |
|
/* User quit */ |
987 |
|
return 0; |
988 |
|
|
989 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
990 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
991 |
if (display != NULL) |
FD_SET(x_socket, &rfds); |
|
{ |
|
|
FD_SET(x_socket, &rfds); |
|
|
XFlush(display); |
|
|
} |
|
992 |
|
|
993 |
switch (select(n, &rfds, NULL, NULL, NULL)) |
switch (select(n, &rfds, NULL, NULL, NULL)) |
994 |
{ |
{ |
999 |
continue; |
continue; |
1000 |
} |
} |
1001 |
|
|
|
if (FD_ISSET(x_socket, &rfds)) |
|
|
xwin_process_events(); |
|
|
|
|
1002 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
1003 |
return; |
return 1; |
1004 |
} |
} |
1005 |
} |
} |
1006 |
|
|
1020 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
1021 |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
1022 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
1023 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
1024 |
|
|
1025 |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
1026 |
|
|
1035 |
{ |
{ |
1036 |
XImage *image; |
XImage *image; |
1037 |
uint8 *tdata; |
uint8 *tdata; |
|
|
|
1038 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
1039 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
1040 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
1041 |
|
|
1042 |
if (ownbackstore) |
if (ownbackstore) |
1043 |
{ |
{ |
1166 |
void |
void |
1167 |
ui_set_cursor(HCURSOR cursor) |
ui_set_cursor(HCURSOR cursor) |
1168 |
{ |
{ |
1169 |
XDefineCursor(display, wnd, (Cursor) cursor); |
current_cursor = (Cursor) cursor; |
1170 |
|
XDefineCursor(display, wnd, current_cursor); |
1171 |
} |
} |
1172 |
|
|
1173 |
void |
void |
1182 |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
1183 |
(xc)->flags = DoRed | DoGreen | DoBlue; |
(xc)->flags = DoRed | DoGreen | DoBlue; |
1184 |
|
|
1185 |
|
|
1186 |
HCOLOURMAP |
HCOLOURMAP |
1187 |
ui_create_colourmap(COLOURMAP * colours) |
ui_create_colourmap(COLOURMAP * colours) |
1188 |
{ |
{ |
1189 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
1190 |
int i, ncolours = colours->ncolours; |
int i, ncolours = colours->ncolours; |
1191 |
|
if (!owncolmap) |
1192 |
|
{ |
1193 |
|
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
1194 |
|
XColor xentry; |
1195 |
|
XColor xc_cache[256]; |
1196 |
|
uint32 colour; |
1197 |
|
int colLookup = 256; |
1198 |
|
for (i = 0; i < ncolours; i++) |
1199 |
|
{ |
1200 |
|
entry = &colours->colours[i]; |
1201 |
|
MAKE_XCOLOR(&xentry, entry); |
1202 |
|
|
1203 |
|
if (XAllocColor(display, xcolmap, &xentry) == 0) |
1204 |
|
{ |
1205 |
|
/* Allocation failed, find closest match. */ |
1206 |
|
int j = 256; |
1207 |
|
int nMinDist = 3 * 256 * 256; |
1208 |
|
long nDist = nMinDist; |
1209 |
|
|
1210 |
|
/* only get the colors once */ |
1211 |
|
while (colLookup--) |
1212 |
|
{ |
1213 |
|
xc_cache[colLookup].pixel = colLookup; |
1214 |
|
xc_cache[colLookup].red = xc_cache[colLookup].green = |
1215 |
|
xc_cache[colLookup].blue = 0; |
1216 |
|
xc_cache[colLookup].flags = 0; |
1217 |
|
XQueryColor(display, |
1218 |
|
DefaultColormap(display, |
1219 |
|
DefaultScreen(display)), |
1220 |
|
&xc_cache[colLookup]); |
1221 |
|
} |
1222 |
|
colLookup = 0; |
1223 |
|
|
1224 |
|
/* approximate the pixel */ |
1225 |
|
while (j--) |
1226 |
|
{ |
1227 |
|
if (xc_cache[j].flags) |
1228 |
|
{ |
1229 |
|
nDist = ((long) (xc_cache[j].red >> 8) - |
1230 |
|
(long) (xentry.red >> 8)) * |
1231 |
|
((long) (xc_cache[j].red >> 8) - |
1232 |
|
(long) (xentry.red >> 8)) + |
1233 |
|
((long) (xc_cache[j].green >> 8) - |
1234 |
|
(long) (xentry.green >> 8)) * |
1235 |
|
((long) (xc_cache[j].green >> 8) - |
1236 |
|
(long) (xentry.green >> 8)) + |
1237 |
|
((long) (xc_cache[j].blue >> 8) - |
1238 |
|
(long) (xentry.blue >> 8)) * |
1239 |
|
((long) (xc_cache[j].blue >> 8) - |
1240 |
|
(long) (xentry.blue >> 8)); |
1241 |
|
} |
1242 |
|
if (nDist < nMinDist) |
1243 |
|
{ |
1244 |
|
nMinDist = nDist; |
1245 |
|
xentry.pixel = j; |
1246 |
|
} |
1247 |
|
} |
1248 |
|
} |
1249 |
|
colour = xentry.pixel; |
1250 |
|
|
1251 |
|
/* update our cache */ |
1252 |
|
if (xentry.pixel < 256) |
1253 |
|
{ |
1254 |
|
xc_cache[xentry.pixel].red = xentry.red; |
1255 |
|
xc_cache[xentry.pixel].green = xentry.green; |
1256 |
|
xc_cache[xentry.pixel].blue = xentry.blue; |
1257 |
|
|
1258 |
if (owncolmap) |
} |
1259 |
|
|
1260 |
|
|
1261 |
|
/* byte swap here to make translate_image faster */ |
1262 |
|
map[i] = translate_colour(colour); |
1263 |
|
} |
1264 |
|
return map; |
1265 |
|
} |
1266 |
|
else |
1267 |
{ |
{ |
1268 |
XColor *xcolours, *xentry; |
XColor *xcolours, *xentry; |
1269 |
Colormap map; |
Colormap map; |
1283 |
xfree(xcolours); |
xfree(xcolours); |
1284 |
return (HCOLOURMAP) map; |
return (HCOLOURMAP) map; |
1285 |
} |
} |
|
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; |
|
|
} |
|
1286 |
} |
} |
1287 |
|
|
1288 |
void |
void |
1289 |
ui_destroy_colourmap(HCOLOURMAP map) |
ui_destroy_colourmap(HCOLOURMAP map) |
1290 |
{ |
{ |
1291 |
if (owncolmap) |
if (!owncolmap) |
|
XFreeColormap(display, (Colormap) map); |
|
|
else |
|
1292 |
xfree(map); |
xfree(map); |
1293 |
|
else |
1294 |
|
XFreeColormap(display, (Colormap) map); |
1295 |
} |
} |
1296 |
|
|
1297 |
void |
void |
1298 |
ui_set_colourmap(HCOLOURMAP map) |
ui_set_colourmap(HCOLOURMAP map) |
1299 |
{ |
{ |
1300 |
if (owncolmap) |
if (!owncolmap) |
|
XSetWindowColormap(display, wnd, (Colormap) map); |
|
|
else |
|
1301 |
colmap = map; |
colmap = map; |
1302 |
|
else |
1303 |
|
XSetWindowColormap(display, wnd, (Colormap) map); |
1304 |
} |
} |
1305 |
|
|
1306 |
void |
void |
1316 |
} |
} |
1317 |
|
|
1318 |
void |
void |
1319 |
ui_reset_clip() |
ui_reset_clip(void) |
1320 |
{ |
{ |
1321 |
XRectangle rect; |
XRectangle rect; |
1322 |
|
|
1328 |
} |
} |
1329 |
|
|
1330 |
void |
void |
1331 |
ui_bell() |
ui_bell(void) |
1332 |
{ |
{ |
1333 |
XBell(display, 0); |
XBell(display, 0); |
1334 |
} |
} |
1463 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE(x, y, cx, cy); |
1464 |
} |
} |
1465 |
|
|
1466 |
|
/* warning, this function only draws on wnd or backstore, not both */ |
1467 |
void |
void |
1468 |
ui_draw_glyph(int mixmode, |
ui_draw_glyph(int mixmode, |
1469 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
1478 |
XSetStipple(display, gc, (Pixmap) glyph); |
XSetStipple(display, gc, (Pixmap) glyph); |
1479 |
XSetTSOrigin(display, gc, x, y); |
XSetTSOrigin(display, gc, x, y); |
1480 |
|
|
1481 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
1482 |
|
|
1483 |
XSetFillStyle(display, gc, FillSolid); |
XSetFillStyle(display, gc, FillSolid); |
1484 |
} |
} |
1507 |
}\ |
}\ |
1508 |
if (glyph != NULL)\ |
if (glyph != NULL)\ |
1509 |
{\ |
{\ |
1510 |
ui_draw_glyph (mixmode, x + (short) glyph->offset,\ |
ui_draw_glyph (mixmode, x + glyph->offset,\ |
1511 |
y + (short) glyph->baseline,\ |
y + glyph->baseline,\ |
1512 |
glyph->width, glyph->height,\ |
glyph->width, glyph->height,\ |
1513 |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
1514 |
if (flags & TEXT2_IMPLICIT_X)\ |
if (flags & TEXT2_IMPLICIT_X)\ |
1530 |
|
|
1531 |
if (boxcx > 1) |
if (boxcx > 1) |
1532 |
{ |
{ |
1533 |
FILL_RECTANGLE(boxx, boxy, boxcx, boxcy); |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |
1534 |
} |
} |
1535 |
else if (mixmode == MIX_OPAQUE) |
else if (mixmode == MIX_OPAQUE) |
1536 |
{ |
{ |
1537 |
FILL_RECTANGLE(clipx, clipy, clipcx, clipcy); |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
1538 |
} |
} |
1539 |
|
|
1540 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
1548 |
else |
else |
1549 |
{ |
{ |
1550 |
error("this shouldn't be happening\n"); |
error("this shouldn't be happening\n"); |
1551 |
break; |
exit(1); |
1552 |
} |
} |
1553 |
/* this will move pointer from start to first character after FF command */ |
/* this will move pointer from start to first character after FF command */ |
1554 |
length -= i + 3; |
length -= i + 3; |
1568 |
else |
else |
1569 |
x += text[i + 2]; |
x += text[i + 2]; |
1570 |
} |
} |
|
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; |
|
1571 |
for (j = 0; j < entry->size; j++) |
for (j = 0; j < entry->size; j++) |
1572 |
DO_GLYPH(((uint8 *) (entry->data)), j); |
DO_GLYPH(((uint8 *) (entry->data)), j); |
1573 |
} |
} |
1574 |
|
if (i + 2 < length) |
1575 |
|
i += 3; |
1576 |
|
else |
1577 |
|
i += 2; |
1578 |
|
length -= i; |
1579 |
|
/* this will move pointer from start to first character after FE command */ |
1580 |
|
text = &(text[i]); |
1581 |
|
i = 0; |
1582 |
break; |
break; |
1583 |
|
|
1584 |
default: |
default: |
1587 |
break; |
break; |
1588 |
} |
} |
1589 |
} |
} |
1590 |
|
if (ownbackstore) |
1591 |
|
{ |
1592 |
|
if (boxcx > 1) |
1593 |
|
XCopyArea(display, backstore, wnd, gc, boxx, |
1594 |
|
boxy, boxcx, boxcy, boxx, boxy); |
1595 |
|
else |
1596 |
|
XCopyArea(display, backstore, wnd, gc, clipx, |
1597 |
|
clipy, clipcx, clipcy, clipx, clipy); |
1598 |
|
} |
1599 |
} |
} |
1600 |
|
|
1601 |
void |
void |