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; |
63 |
/* colour maps */ |
/* colour maps */ |
64 |
static BOOL owncolmap; |
static BOOL owncolmap; |
65 |
static Colormap xcolmap; |
static Colormap xcolmap; |
|
static uint32 white; |
|
66 |
static uint32 *colmap; |
static uint32 *colmap; |
|
static XIM IM = NULL; |
|
|
static XIC IC = NULL; |
|
67 |
|
|
68 |
/* Compose support */ |
/* Compose support */ |
69 |
BOOL enable_compose = False; |
BOOL enable_compose = False; |
70 |
|
static XIM IM = NULL; |
71 |
|
static XIC IC = NULL; |
72 |
|
|
73 |
/* toggle fullscreen globals */ |
/* toggle fullscreen globals */ |
|
static XSetWindowAttributes attribs; |
|
74 |
static unsigned long input_mask; |
static unsigned long input_mask; |
75 |
|
|
76 |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
247 |
} |
} |
248 |
|
|
249 |
BOOL |
BOOL |
250 |
ui_init() |
get_key_state(int keysym) |
|
{ |
|
|
Screen *screen; |
|
|
display = XOpenDisplay(NULL); |
|
|
if (display == NULL) |
|
|
{ |
|
|
error("Failed to open display\n"); |
|
|
return False; |
|
|
} |
|
|
if (fullscreen) |
|
|
{ |
|
|
screen = DefaultScreenOfDisplay(display); |
|
|
width = WidthOfScreen(screen); |
|
|
height = HeightOfScreen(screen); |
|
|
} |
|
|
return True; |
|
|
} |
|
|
|
|
|
BOOL |
|
|
ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask) |
|
251 |
{ |
{ |
252 |
XClassHint *classhints; |
int keysymMask = 0, modifierpos, key; |
253 |
XSizeHints *sizehints; |
Window wDummy1, wDummy2; |
254 |
XEvent xevent; |
int iDummy3, iDummy4, iDummy5, iDummy6; |
255 |
Screen *screen; |
unsigned int current_state; |
256 |
|
int offset; |
|
screen = DefaultScreenOfDisplay(display); |
|
|
|
|
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), xpos, |
|
|
ypos, width, height, 0, CopyFromParent, |
|
|
InputOutput, CopyFromParent, valuemask, &attribs); |
|
257 |
|
|
258 |
|
XModifierKeymap *map = XGetModifierMapping(display); |
259 |
|
KeyCode keycode = XKeysymToKeycode(display, keysym); |
260 |
|
|
261 |
XStoreName(display, wnd, title); |
if (keycode == NoSymbol) |
262 |
|
return False; |
263 |
|
|
264 |
classhints = XAllocClassHint(); |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
|
if (classhints != NULL) |
|
265 |
{ |
{ |
266 |
classhints->res_name = classhints->res_class = "rdesktop"; |
offset = map->max_keypermod * modifierpos; |
|
XSetClassHint(display, wnd, classhints); |
|
|
XFree(classhints); |
|
|
} |
|
267 |
|
|
268 |
sizehints = XAllocSizeHints(); |
for (key = 0; key < map->max_keypermod; key++) |
269 |
if (sizehints) |
{ |
270 |
{ |
if (map->modifiermap[offset + key] == keycode) |
271 |
sizehints->flags = PMinSize | PMaxSize; |
keysymMask = 1 << modifierpos; |
272 |
sizehints->min_width = sizehints->max_width = width; |
} |
|
sizehints->min_height = sizehints->max_height = height; |
|
|
XSetWMNormalHints(display, wnd, sizehints); |
|
|
XFree(sizehints); |
|
273 |
} |
} |
274 |
|
|
275 |
if (enable_compose) |
XQueryPointer(display, DefaultRootWindow(display), &wDummy1, |
276 |
input_mask |= init_inputmethod(); |
&wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, ¤t_state); |
|
|
|
|
XSelectInput(display, wnd, input_mask); |
|
|
|
|
|
gc = XCreateGC(display, wnd, 0, NULL); |
|
|
|
|
|
XMapWindow(display, wnd); |
|
277 |
|
|
278 |
/* Wait for VisibilityNotify Event */ |
XFreeModifiermap(map); |
|
for (;;) |
|
|
{ |
|
|
XNextEvent(display, &xevent); |
|
|
if (xevent.type == VisibilityNotify) |
|
|
break; |
|
|
} |
|
|
|
|
|
if (ownbackstore) |
|
|
backstore = XCreatePixmap(display, wnd, width, height, depth); |
|
279 |
|
|
280 |
/* clear the window so that cached data is not viewed upon start... */ |
return (current_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); |
|
281 |
} |
} |
282 |
|
|
283 |
|
|
284 |
BOOL |
BOOL |
285 |
ui_create_window() |
ui_init() |
286 |
{ |
{ |
287 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
|
Screen *screen; |
|
288 |
uint16 test; |
uint16 test; |
289 |
int i; |
int i; |
290 |
|
|
291 |
|
display = XOpenDisplay(NULL); |
292 |
|
if (display == NULL) |
293 |
|
{ |
294 |
|
error("Failed to open display\n"); |
295 |
|
return False; |
296 |
|
} |
297 |
|
|
298 |
x_socket = ConnectionNumber(display); |
x_socket = ConnectionNumber(display); |
299 |
screen = DefaultScreenOfDisplay(display); |
screen = DefaultScreenOfDisplay(display); |
300 |
visual = DefaultVisualOfScreen(screen); |
visual = DefaultVisualOfScreen(screen); |
327 |
else |
else |
328 |
xcolmap = DefaultColormapOfScreen(screen); |
xcolmap = DefaultColormapOfScreen(screen); |
329 |
|
|
330 |
|
if (DoesBackingStore(screen) == NotUseful) |
331 |
|
ownbackstore = True; |
332 |
|
|
333 |
test = 1; |
test = 1; |
334 |
host_be = !(BOOL) (*(uint8 *) (&test)); |
host_be = !(BOOL) (*(uint8 *) (&test)); |
335 |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
336 |
|
|
337 |
white = WhitePixelOfScreen(screen); |
if (fullscreen) |
338 |
attribs.background_pixel = BlackPixelOfScreen(screen); |
{ |
339 |
attribs.backing_store = DoesBackingStore(screen); |
width = WidthOfScreen(screen); |
340 |
|
height = HeightOfScreen(screen); |
341 |
|
} |
342 |
|
|
343 |
if (attribs.backing_store == NotUseful) |
xkeymap_init(); |
344 |
ownbackstore = True; |
return True; |
345 |
|
} |
346 |
|
|
347 |
dpy_width = WidthOfScreen(screen); |
BOOL |
348 |
dpy_height = HeightOfScreen(screen); |
ui_create_window() |
349 |
|
{ |
350 |
|
XSetWindowAttributes attribs; |
351 |
|
XClassHint *classhints; |
352 |
|
XSizeHints *sizehints; |
353 |
|
XEvent xevent; |
354 |
|
|
355 |
if (fullscreen) |
attribs.background_pixel = BlackPixelOfScreen(screen); |
356 |
|
attribs.backing_store = ownbackstore ? NotUseful : Always; |
357 |
|
attribs.override_redirect = fullscreen; |
358 |
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height, |
359 |
|
0, CopyFromParent, InputOutput, CopyFromParent, |
360 |
|
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
361 |
|
|
362 |
|
XStoreName(display, wnd, title); |
363 |
|
|
364 |
|
classhints = XAllocClassHint(); |
365 |
|
if (classhints != NULL) |
366 |
{ |
{ |
367 |
attribs.override_redirect = True; |
classhints->res_name = classhints->res_class = "rdesktop"; |
368 |
width = dpy_width; |
XSetClassHint(display, wnd, classhints); |
369 |
height = dpy_height; |
XFree(classhints); |
370 |
} |
} |
371 |
else |
|
372 |
|
sizehints = XAllocSizeHints(); |
373 |
|
if (sizehints) |
374 |
{ |
{ |
375 |
attribs.override_redirect = False; |
sizehints->flags = PMinSize | PMaxSize; |
376 |
|
sizehints->min_width = sizehints->max_width = width; |
377 |
|
sizehints->min_height = sizehints->max_height = height; |
378 |
|
XSetWMNormalHints(display, wnd, sizehints); |
379 |
|
XFree(sizehints); |
380 |
} |
} |
381 |
|
|
|
width = (width + 3) & ~3; /* make width a multiple of 32 bits */ |
|
|
|
|
|
|
|
382 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
383 |
VisibilityChangeMask | FocusChangeMask; |
VisibilityChangeMask | FocusChangeMask; |
384 |
|
|
386 |
input_mask |= EnterWindowMask | LeaveWindowMask; |
input_mask |= EnterWindowMask | LeaveWindowMask; |
387 |
if (sendmotion) |
if (sendmotion) |
388 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
|
|
|
389 |
if (ownbackstore) |
if (ownbackstore) |
390 |
input_mask |= ExposureMask; |
input_mask |= ExposureMask; |
391 |
|
if (enable_compose) |
392 |
|
input_mask |= init_inputmethod(); |
393 |
|
|
394 |
if (fullscreen) |
XSelectInput(display, wnd, input_mask); |
395 |
ui_create_window_obj(0, 0, width, height, |
|
396 |
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
gc = XCreateGC(display, wnd, 0, NULL); |
397 |
else |
|
398 |
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
XMapWindow(display, wnd); |
399 |
|
|
400 |
xkeymap_init2(); |
/* Wait for VisibilityNotify Event */ |
401 |
|
for (;;) |
402 |
|
{ |
403 |
|
XNextEvent(display, &xevent); |
404 |
|
if (xevent.type == VisibilityNotify) |
405 |
|
break; |
406 |
|
} |
407 |
|
|
408 |
|
if (ownbackstore) |
409 |
|
backstore = XCreatePixmap(display, wnd, width, height, depth); |
410 |
|
|
411 |
|
/* clear the window so that cached data is not viewed upon start... */ |
412 |
|
XSetBackground(display, gc, 0); |
413 |
|
XSetForeground(display, gc, 0); |
414 |
|
FILL_RECTANGLE(0, 0, width, height); |
415 |
|
/* make sure the window is focused */ |
416 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
417 |
|
|
418 |
return True; |
return True; |
419 |
} |
} |
463 |
XFreePixmap(display, backstore); |
XFreePixmap(display, backstore); |
464 |
XFreeGC(display, gc); |
XFreeGC(display, gc); |
465 |
XDestroyWindow(display, wnd); |
XDestroyWindow(display, wnd); |
466 |
if (fullscreen) |
ui_create_window(); |
|
{ |
|
|
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); |
|
|
} |
|
467 |
ui_set_cursor(cache_get_cursor(0)); |
ui_set_cursor(cache_get_cursor(0)); |
468 |
ui_move_pointer(width / 2, height / 2); |
ui_move_pointer(width / 2, height / 2); |
469 |
reset_keys(); |
reset_keys(); |
474 |
XFreePixmap(display, pixmap); |
XFreePixmap(display, pixmap); |
475 |
} |
} |
476 |
|
|
477 |
|
/* Process all events in Xlib queue */ |
478 |
static void |
static void |
479 |
xwin_process_events() |
xwin_process_events() |
480 |
{ |
{ |
488 |
char str[256]; |
char str[256]; |
489 |
Status status; |
Status status; |
490 |
|
|
|
/* Refresh keyboard mapping if it has changed. This is important for |
|
|
Xvnc, since it allocates keycodes dynamically */ |
|
|
if (XCheckTypedEvent(display, MappingNotify, &xevent)) |
|
|
{ |
|
|
if (xevent.xmapping.request == MappingKeyboard |
|
|
|| xevent.xmapping.request == MappingModifier) |
|
|
XRefreshKeyboardMapping(&xevent.xmapping); |
|
|
} |
|
|
|
|
491 |
while (XCheckMaskEvent(display, ~0, &xevent)) |
while (XCheckMaskEvent(display, ~0, &xevent)) |
492 |
{ |
{ |
493 |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
523 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
524 |
} |
} |
525 |
|
|
|
/* FIXME needs alt modifier */ |
|
|
if (keysym == XK_Break) /* toggle full screen */ |
|
|
{ |
|
|
toggle_fullscreen(); |
|
|
break; |
|
|
} |
|
526 |
ksname = get_ksname(keysym); |
ksname = get_ksname(keysym); |
527 |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
528 |
|
|
529 |
if (inhibit_key(keysym)) |
if (handle_special_keys(keysym, ev_time, True)) |
|
{ |
|
|
DEBUG_KBD(("Inhibiting key\n")); |
|
530 |
break; |
break; |
|
} |
|
531 |
|
|
532 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
533 |
xevent.xkey.keycode, xevent.xkey.state); |
xevent.xkey.keycode, xevent.xkey.state); |
534 |
|
|
|
ensure_remote_modifiers(ev_time, tr); |
|
|
|
|
535 |
if (tr.scancode == 0) |
if (tr.scancode == 0) |
536 |
break; |
break; |
537 |
|
|
538 |
|
ensure_remote_modifiers(ev_time, tr); |
539 |
|
|
540 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
541 |
break; |
break; |
542 |
case KeyRelease: |
case KeyRelease: |
547 |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
548 |
ksname)); |
ksname)); |
549 |
|
|
550 |
if (inhibit_key(keysym)) |
if (handle_special_keys(keysym, ev_time, False)) |
551 |
break; |
break; |
552 |
|
|
553 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
600 |
xevent.xexpose.height, |
xevent.xexpose.height, |
601 |
xevent.xexpose.x, xevent.xexpose.y); |
xevent.xexpose.x, xevent.xexpose.y); |
602 |
break; |
break; |
603 |
|
|
604 |
|
case MappingNotify: |
605 |
|
/* Refresh keyboard mapping if it has changed. This is important for |
606 |
|
Xvnc, since it allocates keycodes dynamically */ |
607 |
|
if (xevent.xmapping.request == MappingKeyboard |
608 |
|
|| xevent.xmapping.request == MappingModifier) |
609 |
|
XRefreshKeyboardMapping(&xevent.xmapping); |
610 |
|
break; |
611 |
|
|
612 |
} |
} |
613 |
} |
} |
614 |
} |
} |
623 |
|
|
624 |
while (True) |
while (True) |
625 |
{ |
{ |
626 |
|
/* Process any events already waiting */ |
627 |
|
XFlush(display); |
628 |
|
xwin_process_events(); |
629 |
|
|
630 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
631 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
632 |
if (display != NULL) |
FD_SET(x_socket, &rfds); |
|
{ |
|
|
FD_SET(x_socket, &rfds); |
|
|
XFlush(display); |
|
|
} |
|
633 |
|
|
634 |
switch (select(n, &rfds, NULL, NULL, NULL)) |
switch (select(n, &rfds, NULL, NULL, NULL)) |
635 |
{ |
{ |
640 |
continue; |
continue; |
641 |
} |
} |
642 |
|
|
|
if (FD_ISSET(x_socket, &rfds)) |
|
|
xwin_process_events(); |
|
|
|
|
643 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
644 |
return; |
return; |
645 |
} |
} |
863 |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
864 |
colour = xentry.pixel; |
colour = xentry.pixel; |
865 |
else |
else |
866 |
colour = white; |
colour = WhitePixelOfScreen(screen); |
867 |
|
|
868 |
/* byte swap here to make translate_image faster */ |
/* byte swap here to make translate_image faster */ |
869 |
map[i] = translate_colour(colour); |
map[i] = translate_colour(colour); |