--- sourceforge.net/trunk/rdesktop/xwin.c 2002/08/26 17:12:43 101 +++ sourceforge.net/trunk/rdesktop/xwin.c 2002/09/12 09:38:31 119 @@ -248,6 +248,41 @@ } BOOL +get_key_state(int keysym) +{ + int keysymMask = 0, modifierpos, key; + Window wDummy1, wDummy2; + int iDummy3, iDummy4, iDummy5, iDummy6; + unsigned int current_state; + int offset; + + XModifierKeymap *map = XGetModifierMapping(display); + KeyCode keycode = XKeysymToKeycode(display, keysym); + + if (keycode == NoSymbol) + return False; + + for (modifierpos = 0; modifierpos < 8; modifierpos++) + { + offset = map->max_keypermod * modifierpos; + + for (key = 0; key < map->max_keypermod; key++) + { + if (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; +} + + +BOOL ui_init() { Screen *screen; @@ -266,7 +301,7 @@ return True; } -BOOL +void ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask) { XClassHint *classhints; @@ -394,9 +429,6 @@ attribs.override_redirect = False; } - width = (width + 3) & ~3; /* make width a multiple of 32 bits */ - - input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | VisibilityChangeMask | FocusChangeMask; @@ -485,6 +517,7 @@ XFreePixmap(display, pixmap); } +/* Process all events in Xlib queue */ static void xwin_process_events() { @@ -498,15 +531,6 @@ char str[256]; Status status; - /* 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); - } - while (XCheckMaskEvent(display, ~0, &xevent)) { if (enable_compose && (XFilterEvent(&xevent, None) == True)) @@ -542,29 +566,20 @@ str, sizeof(str), &keysym, NULL); } - /* FIXME needs alt modifier */ - if (keysym == XK_Break) /* toggle full screen */ - { - toggle_fullscreen(); - break; - } ksname = get_ksname(keysym); DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); - if (inhibit_key(keysym)) - { - DEBUG_KBD(("Inhibiting key\n")); + if (handle_special_keys(keysym, ev_time, True)) break; - } tr = xkeymap_translate_key(keysym, xevent.xkey.keycode, xevent.xkey.state); - ensure_remote_modifiers(ev_time, tr); - if (tr.scancode == 0) break; + ensure_remote_modifiers(ev_time, tr); + rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); break; case KeyRelease: @@ -575,7 +590,7 @@ DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, ksname)); - if (inhibit_key(keysym)) + if (handle_special_keys(keysym, ev_time, False)) break; tr = xkeymap_translate_key(keysym, @@ -628,6 +643,15 @@ xevent.xexpose.height, xevent.xexpose.x, xevent.xexpose.y); break; + + case MappingNotify: + /* Refresh keyboard mapping if it has changed. This is important for + Xvnc, since it allocates keycodes dynamically */ + if (xevent.xmapping.request == MappingKeyboard + || xevent.xmapping.request == MappingModifier) + XRefreshKeyboardMapping(&xevent.xmapping); + break; + } } } @@ -637,11 +661,15 @@ { int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; fd_set rfds; + XEvent xevent; FD_ZERO(&rfds); while (True) { + /* Process any events already in queue */ + xwin_process_events(); + FD_ZERO(&rfds); FD_SET(rdp_socket, &rfds); if (display != NULL) @@ -660,7 +688,11 @@ } if (FD_ISSET(x_socket, &rfds)) - xwin_process_events(); + { + /* Move new events from socket to queue */ + XPeekEvent(display, &xevent); + continue; + } if (FD_ISSET(rdp_socket, &rfds)) return;