--- sourceforge.net/trunk/rdesktop/xwin.c 2002/07/29 19:21:51 73 +++ sourceforge.net/trunk/rdesktop/xwin.c 2002/07/30 01:57:39 81 @@ -25,11 +25,13 @@ #define XK_MISCELLANY #include #include "rdesktop.h" +#include "scancodes.h" extern int width; extern int height; extern BOOL sendmotion; extern BOOL fullscreen; +extern BOOL grab_keyboard; Display *display = NULL; static int x_socket; @@ -239,6 +241,24 @@ } } +BOOL +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; +} BOOL ui_create_window(char *title) @@ -252,14 +272,6 @@ uint16 test; int i; - display = XOpenDisplay(NULL); - - if (display == NULL) - { - error("Failed to open display\n"); - return False; - } - x_socket = ConnectionNumber(display); screen = DefaultScreenOfDisplay(display); visual = DefaultVisualOfScreen(screen); @@ -347,7 +359,9 @@ input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | - ButtonReleaseMask | EnterWindowMask | LeaveWindowMask; + ButtonReleaseMask; + if (grab_keyboard) + input_mask |= EnterWindowMask | LeaveWindowMask; if (sendmotion) input_mask |= PointerMotionMask; @@ -518,14 +532,28 @@ xevent.xmotion.y); break; + case FocusIn: + /* fall through */ case EnterNotify: - XGrabKeyboard(display, wnd, True, - GrabModeAsync, GrabModeAsync, - CurrentTime); + if (grab_keyboard) + XGrabKeyboard(display, wnd, True, + GrabModeAsync, + GrabModeAsync, + CurrentTime); break; + case FocusOut: + /* 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); + /* fall through */ case LeaveNotify: - XUngrabKeyboard(display, CurrentTime); + if (grab_keyboard) + XUngrabKeyboard(display, CurrentTime); break; case Expose: @@ -589,8 +617,8 @@ tdata = (owncolmap ? data : translate_image(width, height, data)); bitmap = XCreatePixmap(display, wnd, width, height, depth); - image = XCreateImage(display, visual, depth, ZPixmap, 0, (char *)tdata, - width, height, 8, 0); + image = XCreateImage(display, visual, depth, ZPixmap, 0, + (char *) tdata, width, height, 8, 0); XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); @@ -608,8 +636,8 @@ uint8 *tdata; tdata = (owncolmap ? data : translate_image(width, height, data)); - image = XCreateImage(display, visual, depth, ZPixmap, 0, (char *)tdata, - width, height, 8, 0); + image = XCreateImage(display, visual, depth, ZPixmap, 0, + (char *) tdata, width, height, 8, 0); if (ownbackstore) { @@ -645,7 +673,7 @@ bitmap = XCreatePixmap(display, wnd, width, height, 1); gc = XCreateGC(display, bitmap, 0, NULL); - image = XCreateImage(display, visual, 1, ZPixmap, 0, (char *)data, + image = XCreateImage(display, visual, 1, ZPixmap, 0, (char *) data, width, height, 8, scanline); image->byte_order = MSBFirst; image->bitmap_bit_order = MSBFirst; @@ -892,6 +920,7 @@ FILL_RECTANGLE(x, y, cx, cy); XSetFillStyle(display, gc, FillSolid); + XSetTSOrigin(display, gc, 0, 0); ui_destroy_glyph((HGLYPH) fill); break; @@ -1157,8 +1186,9 @@ if (data == NULL) return; - image = XCreateImage(display, visual, depth, ZPixmap, 0, (char *)data, - cx, cy, BitmapPad(display), cx * bpp / 8); + image = XCreateImage(display, visual, depth, ZPixmap, 0, + (char *) data, cx, cy, BitmapPad(display), + cx * bpp / 8); if (ownbackstore) {