diff options
Diffstat (limited to 'nx-X11/programs/Xserver/hw/nxagent/Window.c')
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/Window.c | 313 |
1 files changed, 105 insertions, 208 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c index 8da5d8bd1..2da21b91c 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Window.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c @@ -1,6 +1,6 @@ /**************************************************************************/ /* */ -/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */ +/* Copyright (c) 2001, 2010 NoMachine, http://www.nomachine.com/. */ /* */ /* NXAGENT, NX protocol compression and NX extensions to this software */ /* are copyright of NoMachine. Redistribution and use of the present */ @@ -9,7 +9,7 @@ /* */ /* Check http://www.nomachine.com/licensing.html for applicability. */ /* */ -/* NX and NoMachine are trademarks of NoMachine S.r.l. */ +/* NX and NoMachine are trademarks of Medialogic S.p.A. */ /* */ /* All rights reserved. */ /* */ @@ -692,222 +692,91 @@ void nxagentRestackWindow(WindowPtr pWin, WindowPtr pOldNextSib) void nxagentSwitchFullscreen(ScreenPtr pScreen, Bool switchOn) { - Window w; - XSetWindowAttributes attributes; - unsigned long valuemask; + XEvent e; + XSizeHints sizeHints; - if (nxagentOption(Rootless)) + if (nxagentOption(Rootless) == 1) { return; } - if (!switchOn) + if (switchOn == 0) { nxagentWMDetect(); - if (!nxagentWMIsRunning) - { - #ifdef WARNING - fprintf(stderr, "Warning: Can't switch to window mode, no window manager has been detected.\n"); - #endif - - return; - } - } - - w = nxagentDefaultWindows[pScreen -> myNum]; - attributes.override_redirect = switchOn; - valuemask = CWOverrideRedirect; - XUnmapWindow(nxagentDisplay, w); - XChangeWindowAttributes(nxagentDisplay, w, valuemask, &attributes); - - if (switchOn) - { /* - * Change to fullscreen mode. + * The smart scheduler could be stopped while + * waiting for the reply. In this case we need + * to yield explicitly to avoid to be stuck in + * the dispatch loop forever. */ - struct timeval timeout; - int i; - XEvent e; - - /* - * Wait for window manager reparenting the default window. - */ + isItTimeToYield = 1; - for (i = 0; i < 100 && nxagentWMIsRunning; i++) + if (nxagentWMIsRunning == 0) { - #ifdef TEST - fprintf(stderr, "nxagentSwitchFullscreen: WARNING! Going to wait for the ReparentNotify event.\n"); + #ifdef WARNING + fprintf(stderr, "Warning: Can't switch to window mode, no window manager " + "has been detected.\n"); #endif - if (XCheckTypedWindowEvent(nxagentDisplay, w, ReparentNotify, &e)) - { - break; - } - - /* - * This should also flush - * the NX link for us. - */ - - XSync(nxagentDisplay, 0); - - timeout.tv_sec = 0; - timeout.tv_usec = 50 * 1000; - - nxagentWaitEvents(nxagentDisplay, &timeout); + return; } + } - if (i < 100) - { - /* - * The window manager has done with the reparent - * operation. We can resize and map the window. - */ - - nxagentChangeOption(Fullscreen, True); - - /* - * Save the window-mode configuration. - */ - - nxagentChangeOption(SavedX, nxagentOption(X)); - nxagentChangeOption(SavedY, nxagentOption(Y)); - nxagentChangeOption(SavedWidth, nxagentOption(Width)); - nxagentChangeOption(SavedHeight, nxagentOption(Height)); - nxagentChangeOption(SavedRootWidth, nxagentOption(RootWidth)); - nxagentChangeOption(SavedRootHeight, nxagentOption(RootHeight)); - - /* - * Reconf the Default window. - */ - - nxagentChangeOption(X, 0); - nxagentChangeOption(Y, 0); - nxagentChangeOption(Width, WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay))); - nxagentChangeOption(Height, HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay))); - - /* - * Move the root window. - */ - - nxagentChangeOption(RootX, (nxagentOption(Width) - nxagentOption(RootWidth)) / 2); - nxagentChangeOption(RootY, (nxagentOption(Height) - nxagentOption(RootHeight)) / 2); - nxagentChangeOption(ViewportXSpan, nxagentOption(Width) - nxagentOption(RootWidth)); - nxagentChangeOption(ViewportYSpan, nxagentOption(Height) - nxagentOption(RootHeight)); - - XMoveResizeWindow(nxagentDisplay, w, nxagentOption(X), nxagentOption(Y), - nxagentOption(Width), nxagentOption(Height)); - - nxagentUpdateViewportFrame(0, 0, nxagentOption(RootWidth), nxagentOption(RootHeight)); - - XMoveWindow(nxagentDisplay, nxagentWindow(WindowTable[pScreen -> myNum]), - nxagentOption(RootX), nxagentOption(RootY)); - - /* - * We disable the screensaver when changing - * mode to fullscreen. Is it really needed? - */ - - XSetScreenSaver(nxagentDisplay, 0, 0, DefaultExposures, DefaultBlanking); - - if (nxagentIconWindow == None) - { - nxagentIconWindow = nxagentCreateIconWindow(); + #ifdef TEST + fprintf(stderr, "nxagentSwitchFullscreen: Switching to %s mode.\n", + switchOn ? "fullscreen" : "windowed"); + #endif - XMapWindow(nxagentDisplay, nxagentIconWindow); - } + nxagentChangeOption(Fullscreen, switchOn); - XMapRaised(nxagentDisplay, w); - XSetInputFocus(nxagentDisplay, w, RevertToParent, CurrentTime); - XCheckTypedWindowEvent(nxagentDisplay, w, LeaveNotify, &e); - nxagentFullscreenWindow = w; + if (nxagentOption(DesktopResize) == 1) + { + sizeHints.flags = PSize; - if (nxagentOption(DesktopResize) == 1) - { - if (nxagentOption(Shadow) == 0) - { - nxagentRRSetScreenConfig(pScreen, WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)), - HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay))); - } - else - { - nxagentShadowAdaptToRatio(); - } - } - } - else + if (switchOn == 1) { - /* - * We have waited for a reparent event unsuccessfully. - * Something happened to the window manager. - */ - - #ifdef WARNING - fprintf(stderr, "nxagentSwitchFullscreen: WARNING! Expected ReparentNotify event missing.\n"); - #endif - - nxagentWMIsRunning = False; - attributes.override_redirect = False; - XChangeWindowAttributes(nxagentDisplay, w, valuemask, &attributes); - XMapWindow(nxagentDisplay, w); + sizeHints.width = + WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); + sizeHints.height = + HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); } - } - else - { - /* - * FIXME: - * It could be necessary: - * - To restore screensaver. - * - To set or reset nxagentForceBackingStore flag. - * - To grab keyboard. - * - To propagate device settings to the X server if no WM is running. - */ - - /* - * Change to windowed mode. - */ - - nxagentChangeOption(Fullscreen, False); - XDestroyWindow(nxagentDisplay, nxagentIconWindow); - nxagentIconWindow = nxagentFullscreenWindow = None; - - if (nxagentOption(DesktopResize) == 1) + else { - nxagentChangeOption(RootWidth, nxagentOption(SavedRootWidth)); - nxagentChangeOption(RootHeight, nxagentOption(SavedRootHeight)); - - if (nxagentOption(Shadow) == 0) - { - nxagentRRSetScreenConfig(pScreen, nxagentOption(RootWidth), nxagentOption(RootHeight)); - } + sizeHints.width = nxagentOption(RootWidth); + sizeHints.height = nxagentOption(RootHeight); } - nxagentChangeOption(X, nxagentOption(SavedX)); - nxagentChangeOption(Y, nxagentOption(SavedY)); - nxagentChangeOption(Width, nxagentOption(SavedWidth)); - nxagentChangeOption(Height, nxagentOption(SavedHeight)); + XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen -> myNum], + &sizeHints); + } - if (nxagentOption(Shadow) == 1 && nxagentOption(DesktopResize) == 1) - { - nxagentShadowAdaptToRatio(); - } + memset(&e, 0, sizeof(e)); - XMoveResizeWindow(nxagentDisplay, w, nxagentOption(X), nxagentOption(Y), - nxagentOption(Width), nxagentOption(Height)); + e.xclient.type = ClientMessage; + e.xclient.message_type = nxagentAtoms[13]; /* _NET_WM_STATE */ + e.xclient.display = nxagentDisplay; + e.xclient.window = nxagentDefaultWindows[pScreen -> myNum]; + e.xclient.format = 32; + e.xclient.data.l[0] = nxagentOption(Fullscreen) ? 1 : 0; + e.xclient.data.l[1] = nxagentAtoms[14]; /* _NET_WM_STATE_FULLSCREEN */ - nxagentUpdateViewportFrame(0, 0, nxagentOption(Width), nxagentOption(Height)); + XSendEvent(nxagentDisplay, DefaultRootWindow(nxagentDisplay), False, + SubstructureRedirectMask, &e); - XMoveWindow(nxagentDisplay, nxagentWindow(WindowTable[pScreen -> myNum]), 0, 0); - XMapWindow(nxagentDisplay, w); + if (switchOn == 1) + { + nxagentFullscreenWindow = nxagentDefaultWindows[pScreen -> myNum]; - nxagentChangeOption(RootX, 0); - nxagentChangeOption(RootY, 0); + nxagentGrabPointerAndKeyboard(NULL); } + else + { + nxagentFullscreenWindow = None; - XMoveResizeWindow(nxagentDisplay, nxagentInputWindows[0], 0, 0, - nxagentOption(Width), nxagentOption(Height)); + nxagentUngrabPointerAndKeyboard(NULL); + } } #ifdef VIEWPORT_FRAME @@ -2409,6 +2278,11 @@ void nxagentMapDefaultWindows() #endif XMapWindow(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum]); + + if (nxagentOption(Fullscreen) == 1 && nxagentWMIsRunning == 1) + { + nxagentSwitchFullscreen(pScreen, 1); + } } /* @@ -2439,26 +2313,6 @@ void nxagentMapDefaultWindows() } /* - * Map the icon window. - */ - - if (nxagentIconWindow != 0) - { - #ifdef TEST - fprintf(stderr, "nxagentMapDefaultWindows: Mapping icon window id [%ld].\n", - nxagentIconWindow); - #endif - - XMapWindow(nxagentDisplay, nxagentIconWindow); - - if (nxagentIpaq != 0) - { - XIconifyWindow(nxagentDisplay, nxagentIconWindow, - DefaultScreen(nxagentDisplay)); - } - } - - /* * Ensure that the fullscreen window gets the focus. */ @@ -2895,6 +2749,13 @@ FIXME: Do we need to set save unders attribute here? XSizeHints *props, hints; unsigned char *data = NULL; + #ifdef _XSERVER64 + + unsigned char *data64 = NULL; + unsigned int i; + + #endif + hints.flags = 0; ret = GetWindowProperty(pWin, @@ -2903,10 +2764,13 @@ FIXME: Do we need to set save unders attribute here? False, XA_WM_SIZE_HINTS, &type, &format, &nItems, &bytesLeft, &data); - props = (XSizeHints*) data; + /* + * 72 is the number of bytes returned by + * sizeof(XSizeHints) on 32 bit platforms. + */ if (ret == Success && - ((format >> 3) * nItems) == sizeof(XSizeHints) && + ((format >> 3) * nItems) == 72 && bytesLeft == 0 && type == XA_WM_SIZE_HINTS) { @@ -2915,6 +2779,30 @@ FIXME: Do we need to set save unders attribute here? (void*)pWin, pWin -> drawable.id, nxagentWindow(pWin)); #endif + #ifdef _XSERVER64 + + data64 = (unsigned char *) malloc(sizeof(XSizeHints) + 4); + + for (i = 0; i < 4; i++) + { + *(data64 + i) = *(data + i); + } + + *(((int *) data64) + 1) = 0; + + for (i = 8; i < sizeof(XSizeHints) + 4; i++) + { + *(data64 + i) = *(data + i - 4); + } + + props = (XSizeHints *) data64; + + #else + + props = (XSizeHints *) data; + + #endif /* _XSERVER64 */ + hints = *props; } else @@ -2933,6 +2821,15 @@ FIXME: Do we need to set save unders attribute here? XSetWMNormalHints(nxagentDisplay, nxagentWindow(pWin), &hints); + + #ifdef _XSERVER64 + + if (data64 != NULL) + { + free(data64); + } + + #endif } } |