--- sourceforge.net/trunk/rdesktop/xwin.c 2002/09/26 14:04:30 203 +++ sourceforge.net/trunk/rdesktop/xwin.c 2002/11/18 18:12:49 263 @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. User interface services - X Window System - Copyright (C) Matthew Chapman 1999-2001 + Copyright (C) Matthew Chapman 1999-2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,8 +29,11 @@ extern BOOL sendmotion; extern BOOL fullscreen; extern BOOL grab_keyboard; +extern BOOL hide_decorations; extern char title[]; BOOL enable_compose = False; +BOOL focused; +BOOL mouse_in_wnd; Display *display; static int x_socket; @@ -53,6 +56,20 @@ static BOOL ownbackstore; static Pixmap backstore; +/* MWM decorations */ +#define MWM_HINTS_DECORATIONS (1L << 1) +#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 +typedef struct +{ + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long inputMode; + unsigned long status; +} +PropMotifWmHints; + + #define FILL_RECTANGLE(x,y,cx,cy)\ { \ XFillRectangle(display, wnd, gc, x, y, cx, cy); \ @@ -89,6 +106,28 @@ #define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); } #define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } +void +mwm_hide_decorations(void) +{ + PropMotifWmHints motif_hints; + Atom hintsatom; + + /* setup the property */ + motif_hints.flags = MWM_HINTS_DECORATIONS; + motif_hints.decorations = 0; + + /* get the atom for the property */ + hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); + if (!hintsatom) + { + error("Failed to get atom _MOTIF_WM_HINTS\n"); + return; + } + + XChangeProperty(display, wnd, hintsatom, hintsatom, 32, PropModeReplace, + (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); +} + static void translate8(uint8 * data, uint8 * out, uint8 * end) { @@ -184,7 +223,7 @@ } BOOL -get_key_state(uint32 keysym, unsigned int state) +get_key_state(unsigned int state, uint32 keysym) { int modifierpos, key, keysymMask = 0; int offset; @@ -218,7 +257,7 @@ display = XOpenDisplay(NULL); if (display == NULL) { - error("Failed to open display\n"); + error("Failed to open display: %s\n", XDisplayName(NULL)); return False; } @@ -259,6 +298,19 @@ host_be = !(BOOL) (*(uint8 *) (&test)); xserver_be = (ImageByteOrder(display) == MSBFirst); + if ((width == 0) || (height == 0)) + { + /* Fetch geometry from _NET_WORKAREA */ + uint32 xpos, ypos; + + if (get_current_workarea(&xpos, &ypos, &width, &height) < 0) + { + error("Failed to get workarea.\n"); + error("Perhaps your window manager does not support EWMH?\n"); + exit(1); + } + } + if (fullscreen) { width = WidthOfScreen(screen); @@ -293,7 +345,7 @@ if (IM != NULL) XCloseIM(IM); - XFreeModifierMap(mod_map); + XFreeModifiermap(mod_map); if (ownbackstore) XFreePixmap(display, backstore); @@ -326,6 +378,9 @@ XStoreName(display, wnd, title); + if (hide_decorations) + mwm_hide_decorations(); + classhints = XAllocClassHint(); if (classhints != NULL) { @@ -345,12 +400,16 @@ } input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | - StructureNotifyMask | FocusChangeMask; + VisibilityChangeMask | FocusChangeMask; if (sendmotion) input_mask |= PointerMotionMask; if (ownbackstore) input_mask |= ExposureMask; + if (fullscreen || grab_keyboard) + input_mask |= EnterWindowMask; + if (grab_keyboard) + input_mask |= LeaveWindowMask; if (IM != NULL) { @@ -365,15 +424,15 @@ XSelectInput(display, wnd, input_mask); XMapWindow(display, wnd); - /* wait for MapNotify */ + /* wait for VisibilityNotify */ do { - XMaskEvent(display, StructureNotifyMask, &xevent); + XMaskEvent(display, VisibilityChangeMask, &xevent); } - while (xevent.type != MapNotify); + while (xevent.type != VisibilityNotify); - if (fullscreen) - XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); + focused = False; + mouse_in_wnd = False; return True; } @@ -463,7 +522,8 @@ str, sizeof(str), &keysym, NULL); } - DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym))); + DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, + get_ksname(keysym))); ev_time = time(NULL); if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) @@ -519,18 +579,46 @@ break; case FocusIn: - XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); + if (xevent.xfocus.mode == NotifyGrab) + break; + focused = True; + XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, + &dummy, &dummy, &state); reset_modifier_keys(state); - if (grab_keyboard) + if (grab_keyboard && mouse_in_wnd) XGrabKeyboard(display, wnd, True, GrabModeAsync, GrabModeAsync, CurrentTime); break; case FocusOut: + if (xevent.xfocus.mode == NotifyUngrab) + break; + focused = False; if (xevent.xfocus.mode == NotifyWhileGrabbed) XUngrabKeyboard(display, CurrentTime); break; + case EnterNotify: + /* we only register for this event when in fullscreen mode */ + /* or grab_keyboard */ + mouse_in_wnd = True; + if (fullscreen) + { + XSetInputFocus(display, wnd, RevertToPointerRoot, + CurrentTime); + break; + } + if (focused) + XGrabKeyboard(display, wnd, True, + GrabModeAsync, GrabModeAsync, CurrentTime); + break; + + case LeaveNotify: + /* we only register for this event when grab_keyboard */ + mouse_in_wnd = False; + XUngrabKeyboard(display, CurrentTime); + break; + case Expose: XCopyArea(display, backstore, wnd, gc, xevent.xexpose.x, xevent.xexpose.y, @@ -548,7 +636,7 @@ if (xevent.xmapping.request == MappingModifier) { - XFreeModifierMap(mod_map); + XFreeModifiermap(mod_map); mod_map = XGetModifierMapping(display); } break;