--- sourceforge.net/trunk/rdesktop/xwin.c 2002/09/24 07:59:14 192 +++ sourceforge.net/trunk/rdesktop/xwin.c 2002/09/26 14:04:30 203 @@ -42,6 +42,7 @@ static int bpp; static XIM IM; static XIC IC; +static XModifierKeymap *mod_map; static Cursor current_cursor; /* endianness */ @@ -183,15 +184,11 @@ } BOOL -get_key_state(int keysym) +get_key_state(uint32 keysym, unsigned int state) { - int keysymMask = 0, modifierpos, key; - Window wDummy1, wDummy2; - int iDummy3, iDummy4, iDummy5, iDummy6; - unsigned int current_state; + int modifierpos, key, keysymMask = 0; int offset; - XModifierKeymap *map = XGetModifierMapping(display); KeyCode keycode = XKeysymToKeycode(display, keysym); if (keycode == NoSymbol) @@ -199,21 +196,16 @@ for (modifierpos = 0; modifierpos < 8; modifierpos++) { - offset = map->max_keypermod * modifierpos; + offset = mod_map->max_keypermod * modifierpos; - for (key = 0; key < map->max_keypermod; key++) + for (key = 0; key < mod_map->max_keypermod; key++) { - if (map->modifiermap[offset + key] == keycode) - keysymMask = 1 << modifierpos; + if (mod_map->modifiermap[offset + key] == keycode) + keysymMask |= 1 << modifierpos; } } - XQueryPointer(display, DefaultRootWindow(display), &wDummy1, - &wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, ¤t_state); - - XFreeModifiermap(map); - - return (current_state & keysymMask) ? True : False; + return (state & keysymMask) ? True : False; } BOOL @@ -278,13 +270,16 @@ if (ownbackstore) { - backstore = XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); + backstore = + XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); /* clear to prevent rubbish being exposed at startup */ XSetForeground(display, gc, BlackPixelOfScreen(screen)); XFillRectangle(display, backstore, gc, 0, 0, width, height); } + mod_map = XGetModifierMapping(display); + if (enable_compose) IM = XOpenIM(display, NULL, NULL, NULL); @@ -298,6 +293,8 @@ if (IM != NULL) XCloseIM(IM); + XFreeModifierMap(mod_map); + if (ownbackstore) XFreePixmap(display, backstore); @@ -316,7 +313,7 @@ long input_mask, ic_input_mask; XEvent xevent; - wndwidth = fullscreen ? WidthOfScreen(screen) : width; + wndwidth = fullscreen ? WidthOfScreen(screen) : width; wndheight = fullscreen ? HeightOfScreen(screen) : height; attribs.background_pixel = BlackPixelOfScreen(screen); @@ -350,8 +347,6 @@ input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | FocusChangeMask; - if (grab_keyboard) - input_mask |= EnterWindowMask | LeaveWindowMask; if (sendmotion) input_mask |= PointerMotionMask; if (ownbackstore) @@ -362,7 +357,8 @@ IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), XNClientWindow, wnd, XNFocusWindow, wnd, NULL); - if ((IC != NULL) && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) + if ((IC != NULL) + && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) input_mask |= ic_input_mask; } @@ -370,9 +366,11 @@ XMapWindow(display, wnd); /* wait for MapNotify */ - do { + do + { XMaskEvent(display, StructureNotifyMask, &xevent); - } while (xevent.type != MapNotify); + } + while (xevent.type != MapNotify); if (fullscreen) XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); @@ -423,9 +421,11 @@ uint16 button, flags; uint32 ev_time; key_translation tr; - char *ksname = NULL; char str[256]; Status status; + unsigned int state; + Window wdummy; + int dummy; while (XPending(display) > 0) { @@ -437,7 +437,6 @@ continue; } - ev_time = time(NULL); flags = 0; switch (xevent.type) @@ -464,10 +463,10 @@ str, sizeof(str), &keysym, NULL); } - ksname = get_ksname(keysym); - DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); + DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym))); - if (handle_special_keys(keysym, ev_time, True)) + ev_time = time(NULL); + if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) break; tr = xkeymap_translate_key(keysym, @@ -480,15 +479,16 @@ rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); break; + case KeyRelease: XLookupString((XKeyEvent *) & xevent, str, sizeof(str), &keysym, NULL); - ksname = get_ksname(keysym); DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, - ksname)); + get_ksname(keysym))); - if (handle_special_keys(keysym, ev_time, False)) + ev_time = time(NULL); + if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False)) break; tr = xkeymap_translate_key(keysym, @@ -509,30 +509,28 @@ if (button == 0) break; - rdp_send_input(ev_time, RDP_INPUT_MOUSE, + rdp_send_input(time(NULL), RDP_INPUT_MOUSE, flags | button, xevent.xbutton.x, xevent.xbutton.y); break; case MotionNotify: - rdp_send_input(ev_time, RDP_INPUT_MOUSE, + rdp_send_input(time(NULL), RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); break; - case EnterNotify: + case FocusIn: + XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); + reset_modifier_keys(state); if (grab_keyboard) XGrabKeyboard(display, wnd, True, GrabModeAsync, GrabModeAsync, CurrentTime); break; - case LeaveNotify: - if (grab_keyboard) + case FocusOut: + if (xevent.xfocus.mode == NotifyWhileGrabbed) XUngrabKeyboard(display, CurrentTime); break; - case FocusIn: - reset_modifier_keys(); - break; - case Expose: XCopyArea(display, backstore, wnd, gc, xevent.xexpose.x, xevent.xexpose.y, @@ -547,6 +545,12 @@ if (xevent.xmapping.request == MappingKeyboard || xevent.xmapping.request == MappingModifier) XRefreshKeyboardMapping(&xevent.xmapping); + + if (xevent.xmapping.request == MappingModifier) + { + XFreeModifierMap(mod_map); + mod_map = XGetModifierMapping(display); + } break; } @@ -784,26 +788,38 @@ long nDist = nMinDist; /* only get the colors once */ - while( colLookup-- ){ + while (colLookup--) + { xc_cache[colLookup].pixel = colLookup; - xc_cache[colLookup].red = xc_cache[colLookup].green = xc_cache[colLookup].blue = 0; + xc_cache[colLookup].red = xc_cache[colLookup].green = + xc_cache[colLookup].blue = 0; xc_cache[colLookup].flags = 0; - XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &xc_cache[colLookup]); + XQueryColor(display, + DefaultColormap(display, DefaultScreen(display)), + &xc_cache[colLookup]); } colLookup = 0; /* approximate the pixel */ - while( j-- ){ - if( xc_cache[j].flags ){ - nDist = - ((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) * - ((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) + - ((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) * - ((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) + - ((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)) * - ((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)); + while (j--) + { + if (xc_cache[j].flags) + { + nDist = ((long) (xc_cache[j].red >> 8) - + (long) (xentry.red >> 8)) * + ((long) (xc_cache[j].red >> 8) - + (long) (xentry.red >> 8)) + + ((long) (xc_cache[j].green >> 8) - + (long) (xentry.green >> 8)) * + ((long) (xc_cache[j].green >> 8) - + (long) (xentry.green >> 8)) + + ((long) (xc_cache[j].blue >> 8) - + (long) (xentry.blue >> 8)) * + ((long) (xc_cache[j].blue >> 8) - + (long) (xentry.blue >> 8)); } - if( nDist < nMinDist ){ + if (nDist < nMinDist) + { nMinDist = nDist; xentry.pixel = j; } @@ -812,7 +828,8 @@ colour = xentry.pixel; /* update our cache */ - if( xentry.pixel < 256 ){ + if (xentry.pixel < 256) + { xc_cache[xentry.pixel].red = xentry.red; xc_cache[xentry.pixel].green = xentry.green; xc_cache[xentry.pixel].blue = xentry.blue;