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]) ) |
278 |
return (current_state & keysymMask) ? True : False; |
return (current_state & keysymMask) ? True : False; |
279 |
} |
} |
280 |
|
|
281 |
|
static void |
282 |
BOOL |
xwin_map_window() |
|
ui_init() |
|
|
{ |
|
|
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; |
|
|
} |
|
|
|
|
|
void |
|
|
ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask) |
|
283 |
{ |
{ |
|
XClassHint *classhints; |
|
|
XSizeHints *sizehints; |
|
284 |
XEvent xevent; |
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) |
|
|
{ |
|
|
classhints->res_name = classhints->res_class = "rdesktop"; |
|
|
XSetClassHint(display, wnd, classhints); |
|
|
XFree(classhints); |
|
|
} |
|
|
|
|
|
sizehints = XAllocSizeHints(); |
|
|
if (sizehints) |
|
|
{ |
|
|
sizehints->flags = PMinSize | PMaxSize; |
|
|
sizehints->min_width = sizehints->max_width = width; |
|
|
sizehints->min_height = sizehints->max_height = height; |
|
|
XSetWMNormalHints(display, wnd, sizehints); |
|
|
XFree(sizehints); |
|
|
} |
|
|
|
|
|
if (enable_compose) |
|
|
input_mask |= init_inputmethod(); |
|
|
|
|
|
XSelectInput(display, wnd, input_mask); |
|
|
|
|
|
gc = XCreateGC(display, wnd, 0, NULL); |
|
285 |
|
|
286 |
XMapWindow(display, wnd); |
XMapWindow(display, wnd); |
287 |
|
|
288 |
/* Wait for VisibilityNotify Event */ |
/* wait for VisibilityChange */ |
289 |
for (;;) |
XMaskEvent(display, VisibilityChangeMask, &xevent); |
|
{ |
|
|
XNextEvent(display, &xevent); |
|
|
if (xevent.type == VisibilityNotify) |
|
|
break; |
|
|
} |
|
|
|
|
|
if (ownbackstore) |
|
|
backstore = XCreatePixmap(display, wnd, width, height, depth); |
|
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 |
|
/* make sure width is a multiple of 4 */ |
355 |
|
width = (width + 3) & ~3; |
356 |
|
|
357 |
|
xkeymap_init(); |
358 |
|
return True; |
359 |
|
} |
360 |
|
|
361 |
|
BOOL |
362 |
|
ui_create_window() |
363 |
|
{ |
364 |
|
XSetWindowAttributes attribs; |
365 |
|
XClassHint *classhints; |
366 |
|
XSizeHints *sizehints; |
367 |
|
XEvent xevent; |
368 |
|
|
369 |
attribs.background_pixel = BlackPixelOfScreen(screen); |
attribs.background_pixel = BlackPixelOfScreen(screen); |
370 |
attribs.backing_store = DoesBackingStore(screen); |
attribs.backing_store = ownbackstore ? NotUseful : Always; |
371 |
|
attribs.override_redirect = fullscreen; |
372 |
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height, |
373 |
|
0, CopyFromParent, InputOutput, CopyFromParent, |
374 |
|
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
375 |
|
|
376 |
if (attribs.backing_store == NotUseful) |
if (ownbackstore) |
377 |
ownbackstore = True; |
backstore = XCreatePixmap(display, wnd, width, height, depth); |
378 |
|
|
379 |
dpy_width = WidthOfScreen(screen); |
XStoreName(display, wnd, title); |
|
dpy_height = HeightOfScreen(screen); |
|
380 |
|
|
381 |
if (fullscreen) |
classhints = XAllocClassHint(); |
382 |
|
if (classhints != NULL) |
383 |
{ |
{ |
384 |
attribs.override_redirect = True; |
classhints->res_name = classhints->res_class = "rdesktop"; |
385 |
width = dpy_width; |
XSetClassHint(display, wnd, classhints); |
386 |
height = dpy_height; |
XFree(classhints); |
387 |
} |
} |
388 |
else |
|
389 |
|
sizehints = XAllocSizeHints(); |
390 |
|
if (sizehints) |
391 |
{ |
{ |
392 |
attribs.override_redirect = False; |
sizehints->flags = PMinSize | PMaxSize; |
393 |
|
sizehints->min_width = sizehints->max_width = width; |
394 |
|
sizehints->min_height = sizehints->max_height = height; |
395 |
|
XSetWMNormalHints(display, wnd, sizehints); |
396 |
|
XFree(sizehints); |
397 |
} |
} |
398 |
|
|
399 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
403 |
input_mask |= EnterWindowMask | LeaveWindowMask; |
input_mask |= EnterWindowMask | LeaveWindowMask; |
404 |
if (sendmotion) |
if (sendmotion) |
405 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
|
|
|
406 |
if (ownbackstore) |
if (ownbackstore) |
407 |
input_mask |= ExposureMask; |
input_mask |= ExposureMask; |
408 |
|
if (enable_compose) |
409 |
|
input_mask |= init_inputmethod(); |
410 |
|
|
411 |
if (fullscreen) |
XSelectInput(display, wnd, input_mask); |
|
ui_create_window_obj(0, 0, width, height, |
|
|
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
|
|
else |
|
|
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
|
412 |
|
|
413 |
xkeymap_init2(); |
xwin_map_window(); |
414 |
|
|
415 |
|
/* clear the window so that cached data is not seen */ |
416 |
|
gc = XCreateGC(display, wnd, 0, NULL); |
417 |
|
XSetForeground(display, gc, 0); |
418 |
|
FILL_RECTANGLE(0, 0, width, height); |
419 |
|
|
420 |
return True; |
return True; |
421 |
} |
} |
435 |
display = NULL; |
display = NULL; |
436 |
} |
} |
437 |
|
|
|
void |
|
|
reset_keys() |
|
|
{ |
|
|
/* reset keys */ |
|
|
uint32 ev_time; |
|
|
ev_time = time(NULL); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
|
|
} |
|
438 |
|
|
439 |
void |
void |
440 |
toggle_fullscreen() |
xwin_toggle_fullscreen() |
441 |
{ |
{ |
442 |
/* save window contents */ |
XEvent xevent; |
443 |
Pixmap pixmap; |
XSetWindowAttributes attribs; |
444 |
pixmap = XCreatePixmap(display, wnd, width, height, depth); |
int newwidth, newheight; |
445 |
if (ownbackstore) |
|
446 |
XCopyArea(display, backstore, pixmap, gc, 0, 0, width, height, 0, 0); |
fullscreen = !fullscreen; |
447 |
else |
newwidth = fullscreen ? WidthOfScreen(screen) : width; |
448 |
XCopyArea(display, wnd, pixmap, gc, 0, 0, width, height, 0, 0); |
newheight = fullscreen ? HeightOfScreen(screen) : height; |
449 |
fullscreen = fullscreen ? False : True; |
|
450 |
close_inputmethod(); |
XUnmapWindow(display, wnd); |
451 |
if (ownbackstore) |
attribs.override_redirect = fullscreen; |
452 |
XFreePixmap(display, backstore); |
XMoveResizeWindow(display, wnd, 0, 0, newwidth, newheight); |
453 |
XFreeGC(display, gc); |
XChangeWindowAttributes(display, wnd, CWOverrideRedirect, &attribs); |
454 |
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); |
|
455 |
} |
} |
456 |
|
|
457 |
/* Process all events in Xlib queue */ |
/* Process all events in Xlib queue */ |
459 |
xwin_process_events() |
xwin_process_events() |
460 |
{ |
{ |
461 |
XEvent xevent; |
XEvent xevent; |
|
|
|
462 |
KeySym keysym; |
KeySym keysym; |
463 |
uint16 button, flags; |
uint16 button, flags; |
464 |
uint32 ev_time; |
uint32 ev_time; |
467 |
char str[256]; |
char str[256]; |
468 |
Status status; |
Status status; |
469 |
|
|
470 |
while (XCheckMaskEvent(display, ~0, &xevent)) |
while (XPending(display) > 0) |
471 |
{ |
{ |
472 |
|
XNextEvent(display, &xevent); |
473 |
|
|
474 |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
475 |
{ |
{ |
476 |
DEBUG_KBD(("Filtering event\n")); |
DEBUG_KBD(("Filtering event\n")); |
499 |
else |
else |
500 |
{ |
{ |
501 |
/* Plain old XLookupString */ |
/* Plain old XLookupString */ |
502 |
DEBUG_KBD(("No input context, using XLookupString\n")); |
DEBUG_KBD(("\nNo input context, using XLookupString\n")); |
503 |
XLookupString((XKeyEvent *) & xevent, |
XLookupString((XKeyEvent *) & xevent, |
504 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
505 |
} |
} |
506 |
|
|
507 |
ksname = get_ksname(keysym); |
ksname = get_ksname(keysym); |
508 |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
509 |
|
|
510 |
if (handle_special_keys(keysym, ev_time, True)) |
if (handle_special_keys(keysym, ev_time, True)) |
511 |
break; |
break; |
558 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
559 |
break; |
break; |
560 |
|
|
|
case FocusIn: |
|
|
/* fall through */ |
|
561 |
case EnterNotify: |
case EnterNotify: |
562 |
if (grab_keyboard) |
if (grab_keyboard) |
563 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
564 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
565 |
break; |
break; |
566 |
|
|
|
case FocusOut: |
|
|
reset_keys(); |
|
|
/* fall through */ |
|
567 |
case LeaveNotify: |
case LeaveNotify: |
568 |
if (grab_keyboard) |
if (grab_keyboard) |
569 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
570 |
break; |
break; |
571 |
|
|
572 |
|
case FocusIn: |
573 |
|
reset_modifier_keys(); |
574 |
|
break; |
575 |
|
|
576 |
case Expose: |
case Expose: |
577 |
XCopyArea(display, backstore, wnd, gc, |
XCopyArea(display, backstore, wnd, gc, |
578 |
xevent.xexpose.x, xevent.xexpose.y, |
xevent.xexpose.x, xevent.xexpose.y, |
598 |
{ |
{ |
599 |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
600 |
fd_set rfds; |
fd_set rfds; |
|
XEvent xevent; |
|
601 |
|
|
602 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
603 |
|
|
604 |
while (True) |
while (True) |
605 |
{ |
{ |
606 |
/* Process any events already in queue */ |
/* Process any events already waiting */ |
607 |
xwin_process_events(); |
xwin_process_events(); |
608 |
|
|
609 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
610 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
611 |
if (display != NULL) |
FD_SET(x_socket, &rfds); |
|
{ |
|
|
FD_SET(x_socket, &rfds); |
|
|
XFlush(display); |
|
|
} |
|
612 |
|
|
613 |
switch (select(n, &rfds, NULL, NULL, NULL)) |
switch (select(n, &rfds, NULL, NULL, NULL)) |
614 |
{ |
{ |
619 |
continue; |
continue; |
620 |
} |
} |
621 |
|
|
|
if (FD_ISSET(x_socket, &rfds)) |
|
|
{ |
|
|
/* Move new events from socket to queue */ |
|
|
XPeekEvent(display, &xevent); |
|
|
continue; |
|
|
} |
|
|
|
|
622 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
623 |
return; |
return; |
624 |
} |
} |
842 |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
843 |
colour = xentry.pixel; |
colour = xentry.pixel; |
844 |
else |
else |
845 |
colour = white; |
colour = WhitePixelOfScreen(screen); |
846 |
|
|
847 |
/* byte swap here to make translate_image faster */ |
/* byte swap here to make translate_image faster */ |
848 |
map[i] = translate_colour(colour); |
map[i] = translate_colour(colour); |