32 |
extern BOOL sendmotion; |
extern BOOL sendmotion; |
33 |
extern BOOL fullscreen; |
extern BOOL fullscreen; |
34 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
35 |
|
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; |
45 |
|
static int dpy_width; |
46 |
|
static int dpy_height; |
47 |
|
|
48 |
/* endianness */ |
/* endianness */ |
49 |
static BOOL host_be; |
static BOOL host_be; |
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 */ |
74 |
|
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]) ) |
77 |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
247 |
} |
} |
248 |
|
|
249 |
BOOL |
BOOL |
250 |
ui_init() |
get_key_state(int keysym) |
251 |
{ |
{ |
252 |
Screen *screen; |
int keysymMask = 0, modifierpos, key; |
253 |
display = XOpenDisplay(NULL); |
Window wDummy1, wDummy2; |
254 |
if (display == NULL) |
int iDummy3, iDummy4, iDummy5, iDummy6; |
255 |
{ |
unsigned int current_state; |
256 |
error("Failed to open display\n"); |
int offset; |
257 |
|
|
258 |
|
XModifierKeymap *map = XGetModifierMapping(display); |
259 |
|
KeyCode keycode = XKeysymToKeycode(display, keysym); |
260 |
|
|
261 |
|
if (keycode == NoSymbol) |
262 |
return False; |
return False; |
263 |
} |
|
264 |
if (fullscreen) |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
265 |
{ |
{ |
266 |
screen = DefaultScreenOfDisplay(display); |
offset = map->max_keypermod * modifierpos; |
267 |
width = WidthOfScreen(screen); |
|
268 |
height = HeightOfScreen(screen); |
for (key = 0; key < map->max_keypermod; key++) |
269 |
|
{ |
270 |
|
if (map->modifiermap[offset + key] == keycode) |
271 |
|
keysymMask = 1 << modifierpos; |
272 |
|
} |
273 |
} |
} |
274 |
return True; |
|
275 |
|
XQueryPointer(display, DefaultRootWindow(display), &wDummy1, |
276 |
|
&wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, ¤t_state); |
277 |
|
|
278 |
|
XFreeModifiermap(map); |
279 |
|
|
280 |
|
return (current_state & keysymMask) ? True : False; |
281 |
} |
} |
282 |
|
|
283 |
|
|
284 |
BOOL |
BOOL |
285 |
ui_create_window(char *title) |
ui_init() |
286 |
{ |
{ |
|
XSetWindowAttributes attribs; |
|
|
XClassHint *classhints; |
|
|
XSizeHints *sizehints; |
|
|
unsigned long input_mask; |
|
287 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
|
Screen *screen; |
|
288 |
uint16 test; |
uint16 test; |
289 |
int i; |
int i; |
290 |
XEvent xevent; |
|
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); |
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 |
|
|
|
white = WhitePixelOfScreen(screen); |
|
|
attribs.background_pixel = BlackPixelOfScreen(screen); |
|
|
attribs.backing_store = DoesBackingStore(screen); |
|
|
|
|
|
if (attribs.backing_store == NotUseful) |
|
|
ownbackstore = True; |
|
|
|
|
337 |
if (fullscreen) |
if (fullscreen) |
338 |
{ |
{ |
|
attribs.override_redirect = True; |
|
339 |
width = WidthOfScreen(screen); |
width = WidthOfScreen(screen); |
340 |
height = HeightOfScreen(screen); |
height = HeightOfScreen(screen); |
341 |
} |
} |
|
else |
|
|
{ |
|
|
attribs.override_redirect = False; |
|
|
} |
|
342 |
|
|
343 |
width = (width + 3) & ~3; /* make width a multiple of 32 bits */ |
xkeymap_init(); |
344 |
|
return True; |
345 |
|
} |
346 |
|
|
347 |
wnd = XCreateWindow(display, RootWindowOfScreen(screen), |
BOOL |
348 |
0, 0, width, height, 0, CopyFromParent, |
ui_create_window() |
349 |
InputOutput, CopyFromParent, |
{ |
350 |
CWBackingStore | CWBackPixel | CWOverrideRedirect, &attribs); |
XSetWindowAttributes attribs; |
351 |
|
XClassHint *classhints; |
352 |
|
XSizeHints *sizehints; |
353 |
|
XEvent xevent; |
354 |
|
|
355 |
|
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); |
XStoreName(display, wnd, title); |
363 |
|
|
379 |
XFree(sizehints); |
XFree(sizehints); |
380 |
} |
} |
381 |
|
|
|
xkeymap_init2(); |
|
|
|
|
382 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
383 |
VisibilityChangeMask; |
VisibilityChangeMask | FocusChangeMask; |
384 |
|
|
385 |
if (grab_keyboard) |
if (grab_keyboard) |
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) |
if (enable_compose) |
392 |
input_mask |= init_inputmethod(); |
input_mask |= init_inputmethod(); |
393 |
|
|
395 |
|
|
396 |
gc = XCreateGC(display, wnd, 0, NULL); |
gc = XCreateGC(display, wnd, 0, NULL); |
397 |
|
|
|
if (ownbackstore) |
|
|
backstore = XCreatePixmap(display, wnd, width, height, depth); |
|
|
|
|
398 |
XMapWindow(display, wnd); |
XMapWindow(display, wnd); |
399 |
|
|
400 |
/* Wait for VisibilityNotify Event */ |
/* Wait for VisibilityNotify Event */ |
401 |
for (;;) { |
for (;;) |
402 |
|
{ |
403 |
XNextEvent(display, &xevent); |
XNextEvent(display, &xevent); |
404 |
if (xevent.type == VisibilityNotify) |
if (xevent.type == VisibilityNotify) |
405 |
break; |
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... */ |
/* clear the window so that cached data is not viewed upon start... */ |
412 |
XSetBackground(display, gc, 0); |
XSetBackground(display, gc, 0); |
413 |
XSetForeground(display, gc, 0); |
XSetForeground(display, gc, 0); |
414 |
FILL_RECTANGLE(0, 0, width, height); |
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 |
} |
} |
433 |
display = NULL; |
display = NULL; |
434 |
} |
} |
435 |
|
|
436 |
|
void |
437 |
|
reset_keys() |
438 |
|
{ |
439 |
|
/* reset keys */ |
440 |
|
uint32 ev_time; |
441 |
|
ev_time = time(NULL); |
442 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
443 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
444 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
445 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
446 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
447 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
448 |
|
} |
449 |
|
|
450 |
|
void |
451 |
|
toggle_fullscreen() |
452 |
|
{ |
453 |
|
/* save window contents */ |
454 |
|
Pixmap pixmap; |
455 |
|
pixmap = XCreatePixmap(display, wnd, width, height, depth); |
456 |
|
if (ownbackstore) |
457 |
|
XCopyArea(display, backstore, pixmap, gc, 0, 0, width, height, 0, 0); |
458 |
|
else |
459 |
|
XCopyArea(display, wnd, pixmap, gc, 0, 0, width, height, 0, 0); |
460 |
|
fullscreen = fullscreen ? False : True; |
461 |
|
close_inputmethod(); |
462 |
|
if (ownbackstore) |
463 |
|
XFreePixmap(display, backstore); |
464 |
|
XFreeGC(display, gc); |
465 |
|
XDestroyWindow(display, wnd); |
466 |
|
ui_create_window(); |
467 |
|
ui_set_cursor(cache_get_cursor(0)); |
468 |
|
ui_move_pointer(width / 2, height / 2); |
469 |
|
reset_keys(); |
470 |
|
/* restore window contents */ |
471 |
|
if (ownbackstore) |
472 |
|
XCopyArea(display, pixmap, backstore, gc, 0, 0, width, height, 0, 0); |
473 |
|
XCopyArea(display, pixmap, wnd, gc, 0, 0, width, height, 0, 0); |
474 |
|
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)) |
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, |
586 |
break; |
break; |
587 |
|
|
588 |
case FocusOut: |
case FocusOut: |
589 |
/* reset keys */ |
reset_keys(); |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, |
|
|
KBD_FLAG_DOWN | KBD_FLAG_UP, SCANCODE_CHAR_LCTRL, 0); |
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, |
|
|
KBD_FLAG_DOWN | KBD_FLAG_UP, SCANCODE_CHAR_LALT, 0); |
|
590 |
/* fall through */ |
/* fall through */ |
591 |
case LeaveNotify: |
case LeaveNotify: |
592 |
if (grab_keyboard) |
if (grab_keyboard) |
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); |