--- sourceforge.net/trunk/rdesktop/xwin.c 2002/08/03 22:28:05 87 +++ sourceforge.net/trunk/rdesktop/xwin.c 2002/09/11 11:11:27 116 @@ -32,6 +32,7 @@ extern BOOL sendmotion; extern BOOL fullscreen; extern BOOL grab_keyboard; +extern char title[]; Display *display = NULL; static int x_socket; @@ -40,6 +41,8 @@ static Visual *visual; static int depth; static int bpp; +static int dpy_width; +static int dpy_height; /* endianness */ static BOOL host_be; @@ -67,6 +70,10 @@ /* Compose support */ BOOL enable_compose = False; +/* toggle fullscreen globals */ +static XSetWindowAttributes attribs; +static unsigned long input_mask; + #define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) #define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); #define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); @@ -240,6 +247,41 @@ } } +static 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() { @@ -259,18 +301,76 @@ return True; } -BOOL -ui_create_window(char *title) +void +ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask) { - XSetWindowAttributes attribs; XClassHint *classhints; XSizeHints *sizehints; - unsigned long input_mask; + 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); + + XMapWindow(display, wnd); + + /* Wait for VisibilityNotify Event */ + for (;;) + { + XNextEvent(display, &xevent); + if (xevent.type == VisibilityNotify) + break; + } + + if (ownbackstore) + backstore = XCreatePixmap(display, wnd, width, height, depth); + + /* clear the window so that cached data is not viewed upon start... */ + XSetBackground(display, gc, 0); + XSetForeground(display, gc, 0); + FILL_RECTANGLE(0, 0, width, height); + /* make sure the window is focused */ + XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); +} + +BOOL +ui_create_window() +{ XPixmapFormatValues *pfm; Screen *screen; uint16 test; int i; - XEvent xevent; x_socket = ConnectionNumber(display); screen = DefaultScreenOfDisplay(display); @@ -315,48 +415,23 @@ if (attribs.backing_store == NotUseful) ownbackstore = True; + dpy_width = WidthOfScreen(screen); + dpy_height = HeightOfScreen(screen); + if (fullscreen) { attribs.override_redirect = True; - width = WidthOfScreen(screen); - height = HeightOfScreen(screen); + width = dpy_width; + height = dpy_height; } else { attribs.override_redirect = False; } - width = (width + 3) & ~3; /* make width a multiple of 32 bits */ - - wnd = XCreateWindow(display, RootWindowOfScreen(screen), - 0, 0, width, height, 0, CopyFromParent, - InputOutput, CopyFromParent, - CWBackingStore | CWBackPixel | CWOverrideRedirect, &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); - } - - xkeymap_init2(); - input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | - VisibilityChangeMask; + VisibilityChangeMask | FocusChangeMask; + if (grab_keyboard) input_mask |= EnterWindowMask | LeaveWindowMask; if (sendmotion) @@ -365,29 +440,13 @@ if (ownbackstore) input_mask |= ExposureMask; - if (enable_compose) - input_mask |= init_inputmethod(); - - XSelectInput(display, wnd, input_mask); - - gc = XCreateGC(display, wnd, 0, NULL); - - if (ownbackstore) - backstore = XCreatePixmap(display, wnd, width, height, depth); - - XMapWindow(display, wnd); - - /* Wait for VisibilityNotify Event */ - for (;;) { - XNextEvent(display, &xevent); - if (xevent.type == VisibilityNotify) - break; - } + if (fullscreen) + ui_create_window_obj(0, 0, width, height, + CWBackingStore | CWBackPixel | CWOverrideRedirect); + else + ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); - /* clear the window so that cached data is not viewed upon start... */ - XSetBackground(display, gc, 0); - XSetForeground(display, gc, 0); - FILL_RECTANGLE(0, 0, width, height); + xkeymap_init2(); return True; } @@ -407,6 +466,57 @@ display = NULL; } +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); +} + +void +toggle_fullscreen() +{ + /* save window contents */ + Pixmap pixmap; + pixmap = XCreatePixmap(display, wnd, width, height, depth); + if (ownbackstore) + XCopyArea(display, backstore, pixmap, gc, 0, 0, width, height, 0, 0); + else + XCopyArea(display, wnd, pixmap, gc, 0, 0, width, height, 0, 0); + fullscreen = fullscreen ? False : True; + close_inputmethod(); + if (ownbackstore) + XFreePixmap(display, backstore); + XFreeGC(display, gc); + XDestroyWindow(display, wnd); + 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); +} + static void xwin_process_events() { @@ -420,7 +530,7 @@ char str[256]; Status status; - /* Refresh keyboard mapping if it has changed. This is important for + /* Refresh keyboard mapping if it has changed. This is important for Xvnc, since it allocates keycodes dynamically */ if (XCheckTypedEvent(display, MappingNotify, &xevent)) { @@ -464,23 +574,26 @@ str, sizeof(str), &keysym, NULL); } - ksname = get_ksname(keysym); - DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); - - if (inhibit_key(keysym)) + if (keysym == XK_Break) /* toggle full screen */ { - DEBUG_KBD(("Inhibiting key\n")); - break; + if (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R)) + { + toggle_fullscreen(); + break; + } } + ksname = get_ksname(keysym); + DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); + 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: @@ -491,9 +604,6 @@ DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, ksname)); - if (inhibit_key(keysym)) - break; - tr = xkeymap_translate_key(keysym, xevent.xkey.keycode, xevent.xkey.state); @@ -530,11 +640,7 @@ 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); + reset_keys(); /* fall through */ case LeaveNotify: if (grab_keyboard)