--- sourceforge.net/trunk/rdesktop/xwin.c 2002/11/03 12:33:02 250 +++ sourceforge.net/trunk/rdesktop/xwin.c 2002/11/19 10:37:39 265 @@ -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) { @@ -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); @@ -326,6 +378,9 @@ XStoreName(display, wnd, title); + if (hide_decorations) + mwm_hide_decorations(); + classhints = XAllocClassHint(); if (classhints != NULL) { @@ -351,8 +406,10 @@ input_mask |= PointerMotionMask; if (ownbackstore) input_mask |= ExposureMask; - if (fullscreen) + if (fullscreen || grab_keyboard) input_mask |= EnterWindowMask; + if (grab_keyboard) + input_mask |= LeaveWindowMask; if (IM != NULL) { @@ -374,6 +431,9 @@ } while (xevent.type != VisibilityNotify); + focused = False; + mouse_in_wnd = False; + return True; } @@ -462,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)) @@ -518,21 +579,44 @@ 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 */ - XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); + /* 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: @@ -1104,7 +1188,7 @@ else { error("this shouldn't be happening\n"); - break; + exit(1); } /* this will move pointer from start to first character after FF command */ length -= i + 3;