34 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
35 |
extern char title[]; |
extern char title[]; |
36 |
|
|
37 |
Display *display = NULL; |
Display *display; |
38 |
static int x_socket; |
static int x_socket; |
39 |
|
static Screen *screen; |
40 |
static Window wnd; |
static Window wnd; |
41 |
static GC gc; |
static GC gc; |
42 |
static Visual *visual; |
static Visual *visual; |
43 |
static int depth; |
static int depth; |
44 |
static int bpp; |
static int bpp; |
|
static int dpy_width; |
|
|
static int dpy_height; |
|
45 |
|
|
46 |
/* endianness */ |
/* endianness */ |
47 |
static BOOL host_be; |
static BOOL host_be; |
61 |
/* colour maps */ |
/* colour maps */ |
62 |
static BOOL owncolmap; |
static BOOL owncolmap; |
63 |
static Colormap xcolmap; |
static Colormap xcolmap; |
|
static uint32 white; |
|
64 |
static uint32 *colmap; |
static uint32 *colmap; |
|
static XIM IM = NULL; |
|
|
static XIC IC = NULL; |
|
65 |
|
|
66 |
/* Compose support */ |
/* Compose support */ |
67 |
BOOL enable_compose = False; |
BOOL enable_compose = False; |
68 |
|
static XIM IM = NULL; |
69 |
|
static XIC IC = NULL; |
70 |
|
|
71 |
/* toggle fullscreen globals */ |
/* toggle fullscreen globals */ |
|
static XSetWindowAttributes attribs; |
|
72 |
static unsigned long input_mask; |
static unsigned long input_mask; |
73 |
|
|
74 |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
245 |
} |
} |
246 |
|
|
247 |
BOOL |
BOOL |
248 |
ui_init() |
get_key_state(int keysym) |
249 |
{ |
{ |
250 |
Screen *screen; |
int keysymMask = 0, modifierpos, key; |
251 |
display = XOpenDisplay(NULL); |
Window wDummy1, wDummy2; |
252 |
if (display == NULL) |
int iDummy3, iDummy4, iDummy5, iDummy6; |
253 |
{ |
unsigned int current_state; |
254 |
error("Failed to open display\n"); |
int offset; |
|
return False; |
|
|
} |
|
|
if (fullscreen) |
|
|
{ |
|
|
screen = DefaultScreenOfDisplay(display); |
|
|
width = WidthOfScreen(screen); |
|
|
height = HeightOfScreen(screen); |
|
|
} |
|
|
return True; |
|
|
} |
|
255 |
|
|
256 |
BOOL |
XModifierKeymap *map = XGetModifierMapping(display); |
257 |
ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask) |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
|
{ |
|
|
XClassHint *classhints; |
|
|
XSizeHints *sizehints; |
|
|
XEvent xevent; |
|
|
Screen *screen; |
|
|
|
|
|
screen = DefaultScreenOfDisplay(display); |
|
|
|
|
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), xpos, |
|
|
ypos, width, height, 0, CopyFromParent, |
|
|
InputOutput, CopyFromParent, valuemask, &attribs); |
|
258 |
|
|
259 |
|
if (keycode == NoSymbol) |
260 |
|
return False; |
261 |
|
|
262 |
XStoreName(display, wnd, title); |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
|
|
|
|
classhints = XAllocClassHint(); |
|
|
if (classhints != NULL) |
|
263 |
{ |
{ |
264 |
classhints->res_name = classhints->res_class = "rdesktop"; |
offset = map->max_keypermod * modifierpos; |
|
XSetClassHint(display, wnd, classhints); |
|
|
XFree(classhints); |
|
|
} |
|
265 |
|
|
266 |
sizehints = XAllocSizeHints(); |
for (key = 0; key < map->max_keypermod; key++) |
267 |
if (sizehints) |
{ |
268 |
{ |
if (map->modifiermap[offset + key] == keycode) |
269 |
sizehints->flags = PMinSize | PMaxSize; |
keysymMask = 1 << modifierpos; |
270 |
sizehints->min_width = sizehints->max_width = width; |
} |
|
sizehints->min_height = sizehints->max_height = height; |
|
|
XSetWMNormalHints(display, wnd, sizehints); |
|
|
XFree(sizehints); |
|
271 |
} |
} |
272 |
|
|
273 |
if (enable_compose) |
XQueryPointer(display, DefaultRootWindow(display), &wDummy1, |
274 |
input_mask |= init_inputmethod(); |
&wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, ¤t_state); |
275 |
|
|
276 |
XSelectInput(display, wnd, input_mask); |
XFreeModifiermap(map); |
277 |
|
|
278 |
gc = XCreateGC(display, wnd, 0, NULL); |
return (current_state & keysymMask) ? True : False; |
279 |
|
} |
280 |
|
|
281 |
XMapWindow(display, wnd); |
static void |
282 |
|
xwin_map_window() |
283 |
|
{ |
284 |
|
XEvent xevent; |
285 |
|
|
286 |
/* Wait for VisibilityNotify Event */ |
XMapWindow(display, wnd); |
|
for (;;) |
|
|
{ |
|
|
XNextEvent(display, &xevent); |
|
|
if (xevent.type == VisibilityNotify) |
|
|
break; |
|
|
} |
|
287 |
|
|
288 |
if (ownbackstore) |
/* wait for VisibilityChange */ |
289 |
backstore = XCreatePixmap(display, wnd, width, height, depth); |
XMaskEvent(display, VisibilityChangeMask, &xevent); |
290 |
|
|
291 |
/* clear the window so that cached data is not viewed upon start... */ |
if (fullscreen) |
292 |
XSetBackground(display, gc, 0); |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
|
XSetForeground(display, gc, 0); |
|
|
FILL_RECTANGLE(0, 0, width, height); |
|
|
/* make sure the window is focused */ |
|
|
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
|
293 |
} |
} |
294 |
|
|
295 |
BOOL |
BOOL |
296 |
ui_create_window() |
ui_init() |
297 |
{ |
{ |
298 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
|
Screen *screen; |
|
299 |
uint16 test; |
uint16 test; |
300 |
int i; |
int i; |
301 |
|
|
302 |
|
display = XOpenDisplay(NULL); |
303 |
|
if (display == NULL) |
304 |
|
{ |
305 |
|
error("Failed to open display\n"); |
306 |
|
return False; |
307 |
|
} |
308 |
|
|
309 |
x_socket = ConnectionNumber(display); |
x_socket = ConnectionNumber(display); |
310 |
screen = DefaultScreenOfDisplay(display); |
screen = DefaultScreenOfDisplay(display); |
311 |
visual = DefaultVisualOfScreen(screen); |
visual = DefaultVisualOfScreen(screen); |
338 |
else |
else |
339 |
xcolmap = DefaultColormapOfScreen(screen); |
xcolmap = DefaultColormapOfScreen(screen); |
340 |
|
|
341 |
|
if (DoesBackingStore(screen) == NotUseful) |
342 |
|
ownbackstore = True; |
343 |
|
|
344 |
test = 1; |
test = 1; |
345 |
host_be = !(BOOL) (*(uint8 *) (&test)); |
host_be = !(BOOL) (*(uint8 *) (&test)); |
346 |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
347 |
|
|
348 |
white = WhitePixelOfScreen(screen); |
if (fullscreen) |
349 |
|
{ |
350 |
|
width = WidthOfScreen(screen); |
351 |
|
height = HeightOfScreen(screen); |
352 |
|
} |
353 |
|
|
354 |
|
xkeymap_init(); |
355 |
|
return True; |
356 |
|
} |
357 |
|
|
358 |
|
BOOL |
359 |
|
ui_create_window() |
360 |
|
{ |
361 |
|
XSetWindowAttributes attribs; |
362 |
|
XClassHint *classhints; |
363 |
|
XSizeHints *sizehints; |
364 |
|
XEvent xevent; |
365 |
|
|
366 |
attribs.background_pixel = BlackPixelOfScreen(screen); |
attribs.background_pixel = BlackPixelOfScreen(screen); |
367 |
attribs.backing_store = DoesBackingStore(screen); |
attribs.backing_store = ownbackstore ? NotUseful : Always; |
368 |
|
attribs.override_redirect = fullscreen; |
369 |
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height, |
370 |
|
0, CopyFromParent, InputOutput, CopyFromParent, |
371 |
|
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
372 |
|
|
373 |
if (attribs.backing_store == NotUseful) |
if (ownbackstore) |
374 |
ownbackstore = True; |
backstore = XCreatePixmap(display, wnd, width, height, depth); |
375 |
|
|
376 |
dpy_width = WidthOfScreen(screen); |
XStoreName(display, wnd, title); |
|
dpy_height = HeightOfScreen(screen); |
|
377 |
|
|
378 |
if (fullscreen) |
classhints = XAllocClassHint(); |
379 |
|
if (classhints != NULL) |
380 |
{ |
{ |
381 |
attribs.override_redirect = True; |
classhints->res_name = classhints->res_class = "rdesktop"; |
382 |
width = dpy_width; |
XSetClassHint(display, wnd, classhints); |
383 |
height = dpy_height; |
XFree(classhints); |
384 |
} |
} |
385 |
else |
|
386 |
|
sizehints = XAllocSizeHints(); |
387 |
|
if (sizehints) |
388 |
{ |
{ |
389 |
attribs.override_redirect = False; |
sizehints->flags = PMinSize | PMaxSize; |
390 |
|
sizehints->min_width = sizehints->max_width = width; |
391 |
|
sizehints->min_height = sizehints->max_height = height; |
392 |
|
XSetWMNormalHints(display, wnd, sizehints); |
393 |
|
XFree(sizehints); |
394 |
} |
} |
395 |
|
|
|
width = (width + 3) & ~3; /* make width a multiple of 32 bits */ |
|
|
|
|
|
|
|
396 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
397 |
VisibilityChangeMask | FocusChangeMask; |
VisibilityChangeMask | FocusChangeMask; |
398 |
|
|
400 |
input_mask |= EnterWindowMask | LeaveWindowMask; |
input_mask |= EnterWindowMask | LeaveWindowMask; |
401 |
if (sendmotion) |
if (sendmotion) |
402 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
|
|
|
403 |
if (ownbackstore) |
if (ownbackstore) |
404 |
input_mask |= ExposureMask; |
input_mask |= ExposureMask; |
405 |
|
if (enable_compose) |
406 |
|
input_mask |= init_inputmethod(); |
407 |
|
|
408 |
if (fullscreen) |
XSelectInput(display, wnd, input_mask); |
409 |
ui_create_window_obj(0, 0, width, height, |
|
410 |
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
xwin_map_window(); |
|
else |
|
|
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
|
411 |
|
|
412 |
xkeymap_init2(); |
/* clear the window so that cached data is not seen */ |
413 |
|
gc = XCreateGC(display, wnd, 0, NULL); |
414 |
|
XSetForeground(display, gc, 0); |
415 |
|
FILL_RECTANGLE(0, 0, width, height); |
416 |
|
|
417 |
return True; |
return True; |
418 |
} |
} |
432 |
display = NULL; |
display = NULL; |
433 |
} |
} |
434 |
|
|
435 |
void |
static void |
436 |
reset_keys() |
xwin_reset_keys() |
437 |
{ |
{ |
438 |
/* reset keys */ |
/* reset keys */ |
439 |
uint32 ev_time; |
uint32 ev_time; |
447 |
} |
} |
448 |
|
|
449 |
void |
void |
450 |
toggle_fullscreen() |
xwin_toggle_fullscreen() |
451 |
{ |
{ |
452 |
/* save window contents */ |
XEvent xevent; |
453 |
Pixmap pixmap; |
XSetWindowAttributes attribs; |
454 |
pixmap = XCreatePixmap(display, wnd, width, height, depth); |
int newwidth, newheight; |
455 |
if (ownbackstore) |
|
456 |
XCopyArea(display, backstore, pixmap, gc, 0, 0, width, height, 0, 0); |
fullscreen = !fullscreen; |
457 |
else |
newwidth = fullscreen ? WidthOfScreen(screen) : width; |
458 |
XCopyArea(display, wnd, pixmap, gc, 0, 0, width, height, 0, 0); |
newheight = fullscreen ? HeightOfScreen(screen) : height; |
459 |
fullscreen = fullscreen ? False : True; |
|
460 |
close_inputmethod(); |
XUnmapWindow(display, wnd); |
461 |
if (ownbackstore) |
attribs.override_redirect = fullscreen; |
462 |
XFreePixmap(display, backstore); |
XChangeWindowAttributes(display, wnd, CWOverrideRedirect, &attribs); |
463 |
XFreeGC(display, gc); |
XResizeWindow(display, wnd, newwidth, newheight); |
464 |
XDestroyWindow(display, wnd); |
xwin_map_window(); |
|
if (fullscreen) |
|
|
{ |
|
|
attribs.override_redirect = True; |
|
|
ui_create_window_obj(0, 0, dpy_width, dpy_height, |
|
|
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
|
|
} |
|
|
else |
|
|
{ |
|
|
attribs.override_redirect = False; |
|
|
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
|
|
} |
|
|
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); |
|
465 |
} |
} |
466 |
|
|
467 |
|
/* Process all events in Xlib queue */ |
468 |
static void |
static void |
469 |
xwin_process_events() |
xwin_process_events() |
470 |
{ |
{ |
471 |
XEvent xevent; |
XEvent xevent; |
|
|
|
472 |
KeySym keysym; |
KeySym keysym; |
473 |
uint16 button, flags; |
uint16 button, flags; |
474 |
uint32 ev_time; |
uint32 ev_time; |
477 |
char str[256]; |
char str[256]; |
478 |
Status status; |
Status status; |
479 |
|
|
480 |
/* 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)) |
|
481 |
{ |
{ |
482 |
if (xevent.xmapping.request == MappingKeyboard |
XNextEvent(display, &xevent); |
|
|| xevent.xmapping.request == MappingModifier) |
|
|
XRefreshKeyboardMapping(&xevent.xmapping); |
|
|
} |
|
483 |
|
|
|
while (XCheckMaskEvent(display, ~0, &xevent)) |
|
|
{ |
|
484 |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
485 |
{ |
{ |
486 |
DEBUG_KBD(("Filtering event\n")); |
DEBUG_KBD(("Filtering event\n")); |
514 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
515 |
} |
} |
516 |
|
|
|
/* FIXME needs alt modifier */ |
|
|
if (keysym == XK_Break) /* toggle full screen */ |
|
|
{ |
|
|
toggle_fullscreen(); |
|
|
break; |
|
|
} |
|
517 |
ksname = get_ksname(keysym); |
ksname = get_ksname(keysym); |
518 |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
519 |
|
|
520 |
if (inhibit_key(keysym)) |
if (handle_special_keys(keysym, ev_time, True)) |
|
{ |
|
|
DEBUG_KBD(("Inhibiting key\n")); |
|
521 |
break; |
break; |
|
} |
|
522 |
|
|
523 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
524 |
xevent.xkey.keycode, xevent.xkey.state); |
xevent.xkey.keycode, xevent.xkey.state); |
525 |
|
|
|
ensure_remote_modifiers(ev_time, tr); |
|
|
|
|
526 |
if (tr.scancode == 0) |
if (tr.scancode == 0) |
527 |
break; |
break; |
528 |
|
|
529 |
|
ensure_remote_modifiers(ev_time, tr); |
530 |
|
|
531 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
532 |
break; |
break; |
533 |
case KeyRelease: |
case KeyRelease: |
538 |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
539 |
ksname)); |
ksname)); |
540 |
|
|
541 |
if (inhibit_key(keysym)) |
if (handle_special_keys(keysym, ev_time, False)) |
542 |
break; |
break; |
543 |
|
|
544 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
577 |
break; |
break; |
578 |
|
|
579 |
case FocusOut: |
case FocusOut: |
580 |
reset_keys(); |
xwin_reset_keys(); |
581 |
/* fall through */ |
/* fall through */ |
582 |
case LeaveNotify: |
case LeaveNotify: |
583 |
if (grab_keyboard) |
if (grab_keyboard) |
591 |
xevent.xexpose.height, |
xevent.xexpose.height, |
592 |
xevent.xexpose.x, xevent.xexpose.y); |
xevent.xexpose.x, xevent.xexpose.y); |
593 |
break; |
break; |
594 |
|
|
595 |
|
case MappingNotify: |
596 |
|
/* Refresh keyboard mapping if it has changed. This is important for |
597 |
|
Xvnc, since it allocates keycodes dynamically */ |
598 |
|
if (xevent.xmapping.request == MappingKeyboard |
599 |
|
|| xevent.xmapping.request == MappingModifier) |
600 |
|
XRefreshKeyboardMapping(&xevent.xmapping); |
601 |
|
break; |
602 |
|
|
603 |
} |
} |
604 |
} |
} |
605 |
} |
} |
614 |
|
|
615 |
while (True) |
while (True) |
616 |
{ |
{ |
617 |
|
/* Process any events already waiting */ |
618 |
|
xwin_process_events(); |
619 |
|
|
620 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
621 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
622 |
if (display != NULL) |
FD_SET(x_socket, &rfds); |
|
{ |
|
|
FD_SET(x_socket, &rfds); |
|
|
XFlush(display); |
|
|
} |
|
623 |
|
|
624 |
switch (select(n, &rfds, NULL, NULL, NULL)) |
switch (select(n, &rfds, NULL, NULL, NULL)) |
625 |
{ |
{ |
630 |
continue; |
continue; |
631 |
} |
} |
632 |
|
|
|
if (FD_ISSET(x_socket, &rfds)) |
|
|
xwin_process_events(); |
|
|
|
|
633 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
634 |
return; |
return; |
635 |
} |
} |
853 |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
854 |
colour = xentry.pixel; |
colour = xentry.pixel; |
855 |
else |
else |
856 |
colour = white; |
colour = WhitePixelOfScreen(screen); |
857 |
|
|
858 |
/* byte swap here to make translate_image faster */ |
/* byte swap here to make translate_image faster */ |
859 |
map[i] = translate_colour(colour); |
map[i] = translate_colour(colour); |