diff -ruN xwin-20031017-1340/Imakefile xwin/Imakefile --- xwin-20031017-1340/Imakefile Thu Jan 1 09:00:00 1970 +++ xwin/Imakefile Sat Oct 18 10:22:06 2003 @@ -0,0 +1,176 @@ +XCOMM $XConsortium: Imakefile /main/10 1996/12/02 10:20:33 lehors $ +XCOMM $XFree86: xc/programs/Xserver/hw/xwin/Imakefile,v 1.16 2003/07/29 21:25:15 dawes Exp $ + +#include + +#if HasShm +SHMDEF = -DHAS_SHM +#endif + +MMAPDEF = -DHAS_MMAP + + +SRCS = InitInput.c \ + InitOutput.c \ + stubs.c \ + wingc.c \ + winpolyline.c \ + winfillsp.c \ + wingetsp.c \ + winsetsp.c \ + winwindow.c \ + winpntwin.c \ + winpixmap.c \ + winfont.c \ + wincmap.c \ + winclip.c \ + winallpriv.c \ + winscrinit.c \ + winmisc.c \ + winblock.c \ + winwakeup.c \ + wincursor.c \ + winwndproc.c \ + winshadgdi.c \ + winshaddd.c \ + winshadddnl.c \ + winpfbdd.c \ + winkeybd.c \ + winmouse.c \ + wincutpaste.c \ + winnativegdi.c \ + winlayer.c \ + winerror.c \ + winengine.c \ + wincreatewnd.c \ + winregistry.c \ + winconfig.c \ + winmsg.c \ + winmultiwindowclass.c \ + winmultiwindowicons.c \ + winmultiwindowshape.c \ + winmultiwindowwindow.c \ + winmultiwindowwm.c \ + winmultiwindowwndproc.c \ + winclipboardinit.c \ + winclipboardtextconv.c \ + winclipboardthread.c \ + winclipboardunicode.c \ + winclipboardwndproc.c \ + winclipboardxevents.c \ + winvideo.c \ + wintrayicon.c \ + windialogs.c \ + winrop.c \ + winpushpxl.c \ + winprefsyacc.y \ + winprefslex.l \ + winprefs.c \ + winwin32rootless.c + +winprefsyacc.c: winprefsyacc.y + bison -d -o winprefsyacc.c winprefsyacc.y + +winprefsyacc.h: winprefsyacc.c + +winprefslex.c: winprefsyacc.y winprefslex.l winprefsyacc.h + flex -owinprefslex.c winprefslex.l + +clean:: + $(RM) winprefslex.c winprefsyacc.h winprefsyacc.c + +depend:: winprefslex.c winprefsyacc.h winprefsyacc.c + +/* + * NOTE: The XWin.rc file is compiled into XWin.res. + * This compiled-resource file must be directly linked into XWin.exe + * by the commands in xc/programs/Xserver/Imakefile; it cannot be + * linked into libXwin.a because it will not be correctly positioned + * in the XWin.exe image for Windows to be able to find the resources. + */ + +OBJS = InitInput.o \ + InitOutput.o \ + stubs.o \ + wingc.o \ + winpolyline.o \ + winfillsp.o \ + wingetsp.o \ + winsetsp.o \ + winwindow.o \ + winpntwin.o \ + winpixmap.o \ + winfont.o \ + wincmap.o \ + winclip.o \ + winallpriv.o \ + winscrinit.o \ + winmisc.o \ + winblock.o \ + winwakeup.o \ + wincursor.o \ + winwndproc.o \ + winshadgdi.o \ + winshaddd.o \ + winshadddnl.o \ + winpfbdd.o \ + winkeybd.o \ + winmouse.o \ + wincutpaste.o \ + winnativegdi.o \ + winlayer.o \ + winerror.o \ + winengine.o \ + wincreatewnd.o \ + winregistry.o \ + winconfig.o \ + winmsg.o \ + winmultiwindowclass.o \ + winmultiwindowicons.o \ + winmultiwindowshape.o \ + winmultiwindowwindow.o \ + winmultiwindowwm.o \ + winmultiwindowwndproc.o \ + winclipboardinit.o \ + winclipboardtextconv.o \ + winclipboardthread.o \ + winclipboardunicode.o \ + winclipboardwndproc.o \ + winclipboardxevents.o \ + winvideo.o \ + wintrayicon.o \ + windialogs.o \ + winrop.o \ + winpushpxl.o \ + winprefs.o \ + winprefsyacc.o \ + winprefslex.o \ + winwin32rootless.o + +INCLUDES = -I. -I$(XBUILDINCDIR) -I$(FONTINCSRC) \ + -I$(SERVERSRC)/fb -I$(SERVERSRC)/mi \ + -I$(SERVERSRC)/miext/shadow -I$(SERVERSRC)/miext/layer \ + -I$(SERVERSRC)/include -I$(SERVERSRC)/os \ + -I$(EXTINCSRC) -I$(XINCLUDESRC) \ + -I$(SERVERSRC)/render -I$(SERVERSRC)/randr \ + -I$(SERVERSRC)/miext/rootless + +DEFINES = $(OS_DEFINES) $(SHMDEF) $(MMAPDEF) -UXFree86LOADER -UXF86DRI \ + -DPROJECTROOT="\"$(PROJECTROOT)\"" + +LinkSourceFile(stubs.c,$(SERVERSRC)/Xi) +SpecialCObjectRule(stubs,$(ICONFIGFILES),$(EXT_DEFINES)) + + +/* + * Build the Windows resource file (contains the program icon, etc.) + */ + +ResourceObjectRule(XWin,X.ico,) + +NormalLibraryObjectRule() +NormalLibraryTarget(Xwin,$(OBJS)) + +InstallManPage(XWin,$(MANDIR)) + +DependTarget() diff -ruN xwin-20031017-1340/InitOutput.c xwin/InitOutput.c --- xwin-20031017-1340/InitOutput.c Mon Oct 13 11:49:30 2003 +++ xwin/InitOutput.c Sat Oct 18 10:23:11 2003 @@ -151,6 +151,7 @@ g_ScreenInfo[i].fDecoration = TRUE; g_ScreenInfo[i].fRootless = FALSE; g_ScreenInfo[i].fMultiWindow = FALSE; + g_ScreenInfo[i].fWin32Rootless = FALSE; g_ScreenInfo[i].fMultipleMonitors = FALSE; g_ScreenInfo[i].fClipboard = FALSE; g_ScreenInfo[i].fLessPointer = FALSE; @@ -714,6 +715,32 @@ { /* Parameter is for a single screen */ g_ScreenInfo[g_iLastScreen].fMultiWindow = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-win32rootless' argument + */ + if (strcmp (argv[i], "-win32rootless") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fWin32Rootless = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fWin32Rootless = TRUE; } /* Indicate that we have processed this argument */ diff -ruN xwin-20031017-1340/win.h xwin/win.h --- xwin-20031017-1340/win.h Sun Oct 5 03:48:45 2003 +++ xwin/win.h Sat Oct 18 10:23:11 2003 @@ -54,7 +54,7 @@ #define WIN_UPDATE_STATS NO /* Turn debug messages on or off */ -#define CYGDEBUG NO +#define CYGDEBUG YES #define NEED_EVENTS @@ -172,6 +172,7 @@ #include "shadow.h" #include "fb.h" #include "layer.h" +#include "rootless.h" #ifdef RENDER #include "mipict.h" @@ -397,6 +398,7 @@ Bool fDecoration; Bool fRootless; Bool fMultiWindow; + Bool fWin32Rootless; Bool fMultipleMonitors; Bool fClipboard; Bool fLessPointer; @@ -1528,6 +1530,50 @@ winWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + +/* + * winwin32rootless.c + */ + +Bool +winWin32RootlessCreateFrame (RootlessWindowPtr pFrame, ScreenPtr pScreen, + int newX, int newY, RegionPtr pShape); + +void +winWin32RootlessDestroyFrame (RootlessFrameID wid); + +void +winWin32RootlessMoveFrame (RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY); + +void +winWin32RootlessResizeFrame (RootlessFrameID wid, ScreenPtr pScreen, + int newX, int newY, unsigned int newW, unsigned int newH, + unsigned int gravity); + +void +winWin32RootlessRestackFrame (RootlessFrameID wid, RootlessFrameID nextWid); + +void +winWin32RootlessReshapeFrame (RootlessFrameID wid, RegionPtr pShape); + +void +winWin32RootlessUnmapFrame (RootlessFrameID wid); + +void +winWin32RootlessStartDrawing (RootlessFrameID wid, char **pixelData, int *bytesPerRow); + +void +winWin32RootlessStopDrawing (RootlessFrameID wid, Bool flush); + +void +winWin32RootlessUpdateRegion (RootlessFrameID wid, RegionPtr pDamage); + +void +winWin32RootlessDamageRects (RootlessFrameID wid, int count, const BoxRec *rects, + int shift_x, int shift_y); + +void +winWin32RootlessRootlessSwitchWindow (RootlessWindowPtr pFrame, WindowPtr oldWin); /* * END DDX and DIX Function Prototypes diff -ruN xwin-20031017-1340/wincreatewnd.c xwin/wincreatewnd.c --- xwin-20031017-1340/wincreatewnd.c Sat Sep 20 14:59:53 2003 +++ xwin/wincreatewnd.c Sat Oct 18 10:23:11 2003 @@ -155,7 +155,8 @@ /* Decorated or undecorated window */ if (pScreenInfo->fDecoration && !pScreenInfo->fRootless - && !pScreenInfo->fMultiWindow) + && !pScreenInfo->fMultiWindow + && !pScreenInfo->fWin32Rootless) { dwWindowStyle |= WS_CAPTION; if (pScreenInfo->fScrollbars) @@ -195,7 +196,8 @@ /* Adjust the window width and height for borders and title bar */ if (pScreenInfo->fDecoration && !pScreenInfo->fRootless - && !pScreenInfo->fMultiWindow) + && !pScreenInfo->fMultiWindow + && !pScreenInfo->fWin32Rootless) { #if CYGDEBUG ErrorF ("winCreateBoundingWindowWindowed - Window has decoration\n"); @@ -261,7 +263,8 @@ /* Clean up the scrollbars flag, if necessary */ if ((!pScreenInfo->fDecoration || pScreenInfo->fRootless - || pScreenInfo->fMultiWindow) + || pScreenInfo->fMultiWindow + || pScreenInfo->fWin32Rootless) && pScreenInfo->fScrollbars) { /* We cannot have scrollbars if we do not have a window border */ @@ -396,7 +399,7 @@ #endif /* Show the window */ - if (pScreenInfo->fMultiWindow) + if (pScreenInfo->fMultiWindow || pScreenInfo->fWin32Rootless) { pScreenPriv->fRootWindowShown = FALSE; ShowWindow (*phwnd, SW_HIDE); diff -ruN xwin-20031017-1340/winengine.c xwin/winengine.c --- xwin-20031017-1340/winengine.c Thu Jul 31 07:34:53 2003 +++ xwin/winengine.c Sat Oct 18 10:23:11 2003 @@ -182,7 +182,7 @@ } /* ShadowGDI is the only engine that supports Multi Window Mode */ - if (pScreenInfo->fMultiWindow) + if (pScreenInfo->fMultiWindow || pScreenInfo->fWin32Rootless) { ErrorF ("winSetEngine - Multi Window => ShadowGDI\n"); pScreenInfo->dwEngine = WIN_SERVER_SHADOW_GDI; diff -ruN xwin-20031017-1340/winscrinit.c xwin/winscrinit.c --- xwin-20031017-1340/winscrinit.c Wed Oct 8 03:19:57 2003 +++ xwin/winscrinit.c Sat Oct 18 11:48:58 2003 @@ -36,6 +36,29 @@ #include "win.h" +static RootlessFrameProcsRec winWin32RootlessProcs = { + winWin32RootlessCreateFrame, + winWin32RootlessDestroyFrame, + + winWin32RootlessMoveFrame, + winWin32RootlessResizeFrame, + winWin32RootlessRestackFrame, + winWin32RootlessReshapeFrame, + winWin32RootlessUnmapFrame, + + winWin32RootlessStartDrawing, + winWin32RootlessStopDrawing, + winWin32RootlessUpdateRegion, +#ifndef ROOTLESS_TRACK_DAMAGE + winWin32RootlessDamageRects, +#endif + winWin32RootlessRootlessSwitchWindow, + + NULL, + NULL, + NULL +}; + /* * Determine what type of screen we are initializing * and call the appropriate procedure to intiailize @@ -406,6 +429,8 @@ || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL) { + if(!pScreenInfo->fWin32Rootless) + { #if CYGDEBUG ErrorF ("winFinishScreenInitFB - Calling shadowInit ()\n"); #endif @@ -417,6 +442,7 @@ return FALSE; } } + } #endif @@ -497,6 +523,19 @@ /* Undefine the WRAP macro, as it is not needed elsewhere */ #undef WRAP + } + + if(pScreenInfo->fWin32Rootless) + { + ErrorF ("winScreenInit - RootlessInit\n"); + + RootlessInit(pScreen, &winWin32RootlessProcs); + + ErrorF ("winScreenInit - RootlessInit - done\n"); + + rootless_CopyBytes_threshold = 0; + rootless_FillBytes_threshold = 0; + rootless_CopyWindow_threshold = 0; } /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */ diff -ruN xwin-20031017-1340/winwin32rootless.c xwin/winwin32rootless.c --- xwin-20031017-1340/winwin32rootless.c Thu Jan 1 09:00:00 1970 +++ xwin/winwin32rootless.c Sat Oct 18 11:04:45 2003 @@ -0,0 +1,852 @@ +/* + *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + * + *Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + *"Software"), to deal in the Software without restriction, including + *without limitation the rights to use, copy, modify, merge, publish, + *distribute, sublicense, and/or sell copies of the Software, and to + *permit persons to whom the Software is furnished to do so, subject to + *the following conditions: + * + *The above copyright notice and this permission notice shall be + *included in all copies or substantial portions of the Software. + * + *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR + *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *Except as contained in this notice, the name of the XFree86 Project + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from the XFree86 Project. + * + * Authors: Kensuke Matsuzaki + */ +#include "win.h" + +/* + * Constant defines + */ + +#define MOUSE_POLLING_INTERVAL 500 + +/* + * External global variables + */ + +extern HICON g_hiconX; +extern Bool g_fCursor; + +/* + * Local globals + */ + +static UINT_PTR g_uipMousePollingTimerID = 0; + + + +LRESULT CALLBACK +winWin32RootlessWindowProc (HWND hwnd, UINT message, + WPARAM wParam, LPARAM lParam); +typedef struct { + HWND hWnd; + DWORD dwX; + DWORD dwY; + DWORD dwWidth; + DWORD dwHeight; + WindowPtr pWin; + int dwWidthBytes; + HBITMAP hbmpShadow; + HDC hdcShadow; + HDC hdcScreen; + BOOL fResized; + char *pfb; +} Win32RootlessWindowRec, *Win32RootlessWindowPtr; + + +/* + * Internal function to get the DIB format that is compatible with the screen + * Fixme: Share code with winshadgdi.c + */ + +static +Bool +winQueryWin32RootlessDIBFormat (Win32RootlessWindowPtr pRLWinPriv, BITMAPINFOHEADER *pbmih) +{ + HBITMAP hbmp; +#if CYGDEBUG + LPDWORD pdw = NULL; +#endif + + /* Create a memory bitmap compatible with the screen */ + hbmp = CreateCompatibleBitmap (pRLWinPriv->hdcScreen, 1, 1); + if (hbmp == NULL) + { + ErrorF ("winQueryWin32RootlessDIBFormat - CreateCompatibleBitmap failed\n"); + return FALSE; + } + + /* Initialize our bitmap info header */ + ZeroMemory (pbmih, sizeof (BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD)); + pbmih->biSize = sizeof (BITMAPINFOHEADER); + + /* Get the biBitCount */ + if (!GetDIBits (pRLWinPriv->hdcScreen, + hbmp, + 0, 1, + NULL, + (BITMAPINFO*) pbmih, + DIB_RGB_COLORS)) + { + ErrorF ("winQueryWin32RootlessDIBFormat - First call to GetDIBits failed\n"); + DeleteObject (hbmp); + return FALSE; + } + +#if CYGDEBUG + /* Get a pointer to bitfields */ + pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER)); + + ErrorF ("winQueryWin32RootlessDIBFormat - First call masks: %08x %08x %08x\n", + pdw[0], pdw[1], pdw[2]); +#endif + + /* Get optimal color table, or the optimal bitfields */ + if (!GetDIBits (pRLWinPriv->hdcScreen, + hbmp, + 0, 1, + NULL, + (BITMAPINFO*)pbmih, + DIB_RGB_COLORS)) + { + ErrorF ("winQueryWin32RootlessDIBFormat - Second call to GetDIBits " + "failed\n"); + DeleteObject (hbmp); + return FALSE; + } + + /* Free memory */ + DeleteObject (hbmp); + + return TRUE; +} + +Bool +winWin32RootlessCreateFrame (RootlessWindowPtr pFrame, ScreenPtr pScreen, + int newX, int newY, RegionPtr pShape) +{ +#define CLASS_NAME_LENGTH 512 + Bool fResult = TRUE; + Win32RootlessWindowPtr pRLWinPriv; + WNDCLASS wc; + char pszClass[CLASS_NAME_LENGTH]; + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessCreateFrame\n"); +#endif + + pRLWinPriv = (Win32RootlessWindowPtr) malloc (sizeof (Win32RootlessWindowRec)); + pRLWinPriv->dwX = newX; + pRLWinPriv->dwY = newY; + pRLWinPriv->dwWidth = pFrame->width; + pRLWinPriv->dwHeight = pFrame->height; + pRLWinPriv->pWin = pFrame->win; + pRLWinPriv->pfb = NULL; + pRLWinPriv->hbmpShadow = NULL; + pRLWinPriv->hdcShadow = NULL; + pRLWinPriv->hdcScreen = NULL; + pRLWinPriv->fResized = TRUE; + + sprintf (pszClass, "Win32RootlessWindowClass"); + /* Setup our window class */ + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = winWin32RootlessWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = g_hInstance; + wc.hIcon = NULL; + wc.hCursor = 0; + wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); + wc.lpszMenuName = NULL; + wc.lpszClassName = pszClass; + RegisterClass (&wc); + + /* Create the window */ + pRLWinPriv->hWnd = CreateWindowExA (WS_EX_TOOLWINDOW/*|WS_EX_NOACTIVATE|WS_EX_APPWINDOW*/, /* Extended styles */ + pszClass, /* Class name */ + WINDOW_TITLE_X, /* Window name */ + WS_POPUP | WS_CLIPCHILDREN, + pRLWinPriv->dwX, /* Horizontal position */ + pRLWinPriv->dwY, /* Vertical position */ + pRLWinPriv->dwWidth, /* Right edge */ + pRLWinPriv->dwHeight, /* Bottom edge */ + (HWND) NULL, /* No parent or owner window */ + (HMENU) NULL, /* No menu */ + GetModuleHandle (NULL), /* Instance handle */ + pRLWinPriv); /* ScreenPrivates */ + if (pRLWinPriv->hWnd == NULL) + { + ErrorF ("winCreateWindowsWindow - CreateWindowExA () failed: %d\n", + GetLastError ()); + fResult = FALSE; + } + + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessCreateFrame - ShowWindow\n"); +#endif + ShowWindow (pRLWinPriv->hWnd, SW_SHOWNA); + + // Store the implementation private frame ID + pFrame->wid = (RootlessFrameID) pRLWinPriv; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessCreateFrame - (%08x)\n", pFrame->wid); +#endif + return fResult; +} + +void +winWin32RootlessDestroyFrame (RootlessFrameID wid) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessDestroyFrame (%08x)\n", pRLWinPriv); +#endif + pRLWinPriv->pfb = NULL; + /* Destroy the Windows window */ + DestroyWindow (pRLWinPriv->hWnd); +} + +void +winWin32RootlessMoveFrame (RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessMoveFrame (%08x)\n", pRLWinPriv); +#endif + pRLWinPriv->dwX = newX; + pRLWinPriv->dwY = newY; + MoveWindow (pRLWinPriv->hWnd, + pRLWinPriv->dwX, pRLWinPriv->dwY, + pRLWinPriv->dwWidth, pRLWinPriv->dwHeight, + TRUE); +} + +void +winWin32RootlessResizeFrame (RootlessFrameID wid, ScreenPtr pScreen, + int newX, int newY, unsigned int newW, unsigned int newH, + unsigned int gravity) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessResizeFrame (%08x)\n", pRLWinPriv); +#endif + pRLWinPriv->fResized = (pRLWinPriv->dwWidth != newW) || (pRLWinPriv->dwHeight != newH); + pRLWinPriv->dwX = newX; + pRLWinPriv->dwY = newY; + pRLWinPriv->dwWidth = newW; + pRLWinPriv->dwHeight = newH; + MoveWindow (pRLWinPriv->hWnd, + pRLWinPriv->dwX, pRLWinPriv->dwY, + pRLWinPriv->dwWidth, pRLWinPriv->dwHeight, + TRUE); +} + +void +winWin32RootlessRestackFrame (RootlessFrameID wid, RootlessFrameID nextWid) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + Win32RootlessWindowPtr pRLNextWinPriv = (Win32RootlessWindowPtr) nextWid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessRestackFrame (%08x)\n", pRLWinPriv); +#endif + ShowWindow (pRLWinPriv->hWnd, SW_SHOWNA); /* Is this right behavior? */ + SetWindowPos (pRLWinPriv->hWnd, (pRLNextWinPriv == NULL) ? HWND_TOP : pRLNextWinPriv->hWnd, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); +} + +void +winWin32RootlessReshapeFrame (RootlessFrameID wid, RegionPtr pShape) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessReshapeFrame (%08x)\n", pRLWinPriv); +#endif + ErrorF ("winWin32RootlessReshapeFrame - Unimplemented.\n"); +} + +void +winWin32RootlessUnmapFrame (RootlessFrameID wid) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessUnmapFrame (%08x)\n", pRLWinPriv); +#endif + ShowWindow (pRLWinPriv->hWnd, SW_HIDE); +} + +/* + * Fixme: Code sharing with winshadgdi.c and other engine support + */ +void +winWin32RootlessStartDrawing (RootlessFrameID wid, char **pixelData, int *bytesPerRow) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + winPrivScreenPtr pScreenPriv = NULL; + winScreenInfo *pScreenInfo = NULL; + ScreenPtr pScreen = NULL; + BITMAPINFOHEADER *pbmih = NULL; + DIBSECTION dibsection; + Bool fReturn = TRUE; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessStartDrawing (%08x)\n", pRLWinPriv); +#endif + + pScreen = pRLWinPriv->pWin->drawable.pScreen; + if (pScreen) pScreenPriv = winGetScreenPriv(pScreen); + if (pScreenPriv) pScreenInfo = pScreenPriv->pScreenInfo; + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("pScreenPriv %08X\n", pScreenPriv); + ErrorF ("pScreenInfo %08X\n", pScreenInfo); +#endif + if (pRLWinPriv->fResized) + { + /* Free the shadow DC; which allows the bitmap to be freed */ + DeleteDC (pRLWinPriv->hdcShadow); + pRLWinPriv->hdcShadow = NULL; + + /* Free the shadow bitmap */ + DeleteObject (pRLWinPriv->hbmpShadow); + pRLWinPriv->hbmpShadow = NULL; + + /* Free the screen DC */ + ReleaseDC (pRLWinPriv->hWnd, pRLWinPriv->hdcScreen); + pRLWinPriv->hdcScreen = NULL; + pRLWinPriv->fResized = FALSE; + pRLWinPriv->pfb = NULL; + } + if (pRLWinPriv->hdcScreen == NULL || pRLWinPriv->hdcShadow == NULL + || pRLWinPriv->hbmpShadow == NULL || pRLWinPriv->pfb == NULL) + { + pRLWinPriv->pfb = NULL; + pRLWinPriv->hdcScreen = GetDC (pRLWinPriv->hWnd); + pRLWinPriv->hdcShadow = CreateCompatibleDC (pRLWinPriv->hdcScreen); + + /* Allocate bitmap info header */ + pbmih = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER) + + 256 * sizeof (RGBQUAD)); + if (pbmih == NULL) + { + ErrorF ("winWin32RootlessStartDrawing - malloc () failed\n"); + //return FALSE; + } + + /* Query the screen format */ + fReturn = winQueryWin32RootlessDIBFormat (pRLWinPriv, pbmih); + + /* Describe shadow bitmap to be created */ + pbmih->biWidth = pRLWinPriv->dwWidth; + pbmih->biHeight = -pRLWinPriv->dwHeight; + + /* Create a DI shadow bitmap with a bit pointer */ + pRLWinPriv->hbmpShadow = CreateDIBSection (pRLWinPriv->hdcScreen, + (BITMAPINFO *) pbmih, + DIB_RGB_COLORS, + (VOID**) &pRLWinPriv->pfb, + NULL, + 0); + if (pRLWinPriv->hbmpShadow == NULL || pRLWinPriv->pfb == NULL) + { + ErrorF ("winWin32RootlessStartDrawing - CreateDIBSection failed\n"); + //return FALSE; + } + else + { +#if CYGDEBUG + ErrorF ("winWin32RootlessStartDrawing - Shadow buffer allocated\n"); +#endif + } + + /* Get information about the bitmap that was allocated */ + GetObject (pRLWinPriv->hbmpShadow, + sizeof (dibsection), + &dibsection); + +#if CYGDEBUG || YES + /* Print information about bitmap allocated */ + ErrorF ("winWin32RootlessStartDrawing - Dibsection width: %d height: %d " + "depth: %d size image: %d\n", + dibsection.dsBmih.biWidth, dibsection.dsBmih.biHeight, + dibsection.dsBmih.biBitCount, + dibsection.dsBmih.biSizeImage); +#endif + + /* Select the shadow bitmap into the shadow DC */ + SelectObject (pRLWinPriv->hdcShadow, + pRLWinPriv->hbmpShadow); + +#if CYGDEBUG + ErrorF ("winWin32RootlessStartDrawing - Attempting a shadow blit\n"); +#endif + + /* Do a test blit from the shadow to the screen, I think */ + fReturn = BitBlt (pRLWinPriv->hdcScreen, + 0, 0, + pRLWinPriv->dwWidth, pRLWinPriv->dwHeight, + pRLWinPriv->hdcShadow, + 0, 0, + SRCCOPY); + if (fReturn) + { +#if CYGDEBUG + ErrorF ("winWin32RootlessStartDrawing - Shadow blit success\n"); +#endif + } + else + { + ErrorF ("winWin32RootlessStartDrawing - Shadow blit failure\n"); + //return FALSE; + } + + /* Look for height weirdness */ + if (dibsection.dsBmih.biHeight < 0) + { + /* FIXME: Figure out why biHeight is sometimes negative */ + ErrorF ("winWin32RootlessStartDrawing - WEIRDNESS - biHeight " + "still negative: %d\n" + "winAllocateFBShadowGDI - WEIRDNESS - Flipping biHeight sign\n", + dibsection.dsBmih.biHeight); + dibsection.dsBmih.biHeight = -dibsection.dsBmih.biHeight; + } + + pRLWinPriv->dwWidthBytes = dibsection.dsBm.bmWidthBytes; + +#if CYGDEBUG || YES + ErrorF ("winWin32RootlessStartDrawing - bytesPerRow: %d\n", + dibsection.dsBm.bmWidthBytes); +#endif + } +#if CYGDEBUG || YES + ErrorF ("winWin32RootlessStartDrawing - 0x%08x %d\n", + pRLWinPriv->pfb, dibsection.dsBm.bmWidthBytes); +#endif + *pixelData = pRLWinPriv->pfb; + *bytesPerRow = pRLWinPriv->dwWidthBytes; +} + +void +winWin32RootlessStopDrawing (RootlessFrameID wid, Bool flush) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessStopDrawing (%08x)\n", pRLWinPriv); +#endif +} + +void +winWin32RootlessUpdateRegion (RootlessFrameID wid, RegionPtr pDamage) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessUpdateRegion (%08x)\n", pRLWinPriv); +#endif + InvalidateRect (pRLWinPriv->hWnd, NULL, FALSE);/* is this right? */ +} + +void +winWin32RootlessDamageRects (RootlessFrameID wid, int count, const BoxRec *rects, + int shift_x, int shift_y) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessDamageRects (%08x)\n", pRLWinPriv); +#endif + InvalidateRect (pRLWinPriv->hWnd, NULL, FALSE);/* is this right? */ +} + +void +winWin32RootlessRootlessSwitchWindow (RootlessWindowPtr pFrame, WindowPtr oldWin) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) pFrame->wid; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessRootlessSwitchWindow (%08x)\n", pRLWinPriv); +#endif + pRLWinPriv->pWin = pFrame->win; + pRLWinPriv->fResized = TRUE; + pRLWinPriv->dwX = pFrame->x; + pRLWinPriv->dwY = pFrame->y; + pRLWinPriv->dwWidth = pFrame->width; + pRLWinPriv->dwHeight = pFrame->height; +} + +/* + * winWin32RootlessWindowProc - Window procedure + */ + +LRESULT CALLBACK +winWin32RootlessWindowProc (HWND hwnd, UINT message, + WPARAM wParam, LPARAM lParam) +{ + Win32RootlessWindowPtr pRLWinPriv = NULL; + ScreenPtr pScreen = NULL; + winPrivScreenPtr pScreenPriv = NULL; + winScreenInfo *pScreenInfo = NULL; + HWND hwndScreen = NULL; + POINT ptMouse; + static Bool s_fTracking = FALSE; + HDC hdcUpdate; + PAINTSTRUCT ps; + + /* Check if the Windows window property for our X window pointer is valid */ + if ((pRLWinPriv = (Win32RootlessWindowPtr)GetProp (hwnd, WIN_WINDOW_PROP)) != NULL) + { + pScreen = pRLWinPriv->pWin->drawable.pScreen; + if (pScreen) pScreenPriv = winGetScreenPriv(pScreen); + if (pScreenPriv) pScreenInfo = pScreenPriv->pScreenInfo; + if (pScreenPriv) hwndScreen = pScreenPriv->hwndScreen; +#if 0 + ErrorF ("hWnd %08X\n", hwnd); + ErrorF ("pScreenPriv %08X\n", pScreenPriv); + ErrorF ("pScreenInfo %08X\n", pScreenInfo); + ErrorF ("hwndScreen %08X\n", hwndScreen); +#endif + } + /* Branch on message type */ + switch (message) + { + case WM_CREATE: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_CREATE\n"); +#endif + /* */ + SetProp (hwnd, + WIN_WINDOW_PROP, + (HANDLE)((LPCREATESTRUCT) lParam)->lpCreateParams); + return 0; + + case WM_CLOSE: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_CLOSE\n"); +#endif + DestroyWindow (hwnd); + return 0; + + case WM_DESTROY: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_DESTROY\n"); +#endif + /* Free the shadow DC; which allows the bitmap to be freed */ + DeleteDC (pRLWinPriv->hdcShadow); + pRLWinPriv->hdcShadow = NULL; + + /* Free the shadow bitmap */ + DeleteObject (pRLWinPriv->hbmpShadow); + pRLWinPriv->hbmpShadow = NULL; + + /* Free the screen DC */ + ReleaseDC (pRLWinPriv->hWnd, pRLWinPriv->hdcScreen); + pRLWinPriv->hdcScreen = NULL; + pRLWinPriv->fResized = FALSE; + pRLWinPriv->pfb = NULL; + free (pRLWinPriv); + SetProp (hwnd, WIN_WINDOW_PROP, (HANDLE)NULL); + break; + + case WM_MOUSEMOVE: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_MOUSEMOVE\n"); +#endif + /* Unpack the client area mouse coordinates */ + ptMouse.x = GET_X_LPARAM(lParam); + ptMouse.y = GET_Y_LPARAM(lParam); + + /* Translate the client area mouse coordinates to screen coordinates */ + ClientToScreen (hwnd, &ptMouse); + + /* Screen Coords from (-X, -Y) -> Root Window (0, 0) */ + ptMouse.x -= GetSystemMetrics (SM_XVIRTUALSCREEN); + ptMouse.y -= GetSystemMetrics (SM_YVIRTUALSCREEN); + + /* We can't do anything without privates */ + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + + /* Has the mouse pointer crossed screens? */ + if (pScreen != miPointerCurrentScreen ()) + miPointerSetNewScreen (pScreenInfo->dwScreen, + ptMouse.x - pScreenInfo->dwXOffset, + ptMouse.y - pScreenInfo->dwYOffset); + + /* Are we tracking yet? */ + if (!s_fTracking) + { + TRACKMOUSEEVENT tme; + + /* Setup data structure */ + ZeroMemory (&tme, sizeof (tme)); + tme.cbSize = sizeof (tme); + tme.dwFlags = TME_LEAVE; + tme.hwndTrack = hwnd; + + /* Call the tracking function */ + if (!(*g_fpTrackMouseEvent) (&tme)) + ErrorF ("winTopLevelWindowProc - _TrackMouseEvent failed\n"); + + /* Flag that we are tracking now */ + s_fTracking = TRUE; + } + + /* Hide or show the Windows mouse cursor */ + if (g_fCursor) + { + /* Hide Windows cursor */ + g_fCursor = FALSE; + //ShowCursor (FALSE); + } + + /* Kill the timer used to poll mouse events */ + if (g_uipMousePollingTimerID != 0) + { + KillTimer (pScreenPriv->hwndScreen, WIN_POLLING_MOUSE_TIMER_ID); + g_uipMousePollingTimerID = 0; + } + + /* Deliver absolute cursor position to X Server */ + miPointerAbsoluteCursor (ptMouse.x - pScreenInfo->dwXOffset, + ptMouse.y - pScreenInfo->dwYOffset, + g_c32LastInputEventTime = GetTickCount ()); + return 0; + + case WM_NCMOUSEMOVE: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_NCMOUSEMOVE\n"); +#endif + /* + * We break instead of returning 0 since we need to call + * DefWindowProc to get the mouse cursor changes + * and min/max/close button highlighting in Windows XP. + * The Platform SDK says that you should return 0 if you + * process this message, but it fails to mention that you + * will give up any default functionality if you do return 0. + */ + + /* We can't do anything without privates */ + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + + /* Non-client mouse movement, show Windows cursor */ + if (!g_fCursor) + { + g_fCursor = TRUE; + //ShowCursor (TRUE); + } + + /* + * Timer to poll mouse events. This is needed to make + * programs like xeyes follow the mouse properly. + */ + if (g_uipMousePollingTimerID == 0) + g_uipMousePollingTimerID = SetTimer (pScreenPriv->hwndScreen, + WIN_POLLING_MOUSE_TIMER_ID, + MOUSE_POLLING_INTERVAL, + NULL); + break; + + case WM_MOUSELEAVE: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_MOUSELEAVE\n"); +#endif + /* Mouse has left our client area */ + + /* Flag that we are no longer tracking */ + s_fTracking = FALSE; + + /* Show the mouse cursor, if necessary */ + if (!g_fCursor) + { + g_fCursor = TRUE; + //ShowCursor (TRUE); + } + + /* + * Timer to poll mouse events. This is needed to make + * programs like xeyes follow the mouse properly. + */ + if (g_uipMousePollingTimerID == 0) + g_uipMousePollingTimerID = SetTimer (pScreenPriv->hwndScreen, + WIN_POLLING_MOUSE_TIMER_ID, + MOUSE_POLLING_INTERVAL, + NULL); + return 0; + + case WM_LBUTTONDBLCLK: + case WM_LBUTTONDOWN: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_LBUTTONDBLCLK\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + SetCapture (hwnd); + return winMouseButtonsHandle (pScreen, ButtonPress, Button1, wParam); + + case WM_LBUTTONUP: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_LBUTTONUP\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + ReleaseCapture (); + return winMouseButtonsHandle (pScreen, ButtonRelease, Button1, wParam); + + case WM_MBUTTONDBLCLK: + case WM_MBUTTONDOWN: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_MBUTTONDBLCLK\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + SetCapture (hwnd); + return winMouseButtonsHandle (pScreen, ButtonPress, Button2, wParam); + + case WM_MBUTTONUP: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_MBUTTONUP\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + ReleaseCapture (); + return winMouseButtonsHandle (pScreen, ButtonRelease, Button2, wParam); + + case WM_RBUTTONDBLCLK: + case WM_RBUTTONDOWN: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_RBUTTONDBLCLK\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + SetCapture (hwnd); + return winMouseButtonsHandle (pScreen, ButtonPress, Button3, wParam); + + case WM_RBUTTONUP: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_RBUTTONUP\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + ReleaseCapture (); + return winMouseButtonsHandle (pScreen, ButtonRelease, Button3, wParam); + + case WM_MOUSEWHEEL: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessWindowProc - WM_MOUSEWHEEL\n"); +#endif + + /* Pass the message to the root window */ + SendMessage (hwndScreen, message, wParam, lParam); + return 0; + + case WM_KILLFOCUS: + /* Pop any pressed keys since we are losing keyboard focus */ + winKeybdReleaseKeys (); + return 0; + + case WM_SYSDEADCHAR: + case WM_DEADCHAR: + /* + * NOTE: We do nothing with WM_*CHAR messages, + * nor does the root window, so we can just toss these messages. + */ + return 0; + + case WM_SYSKEYDOWN: + case WM_KEYDOWN: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winTopLevelWindowProc - WM_*KEYDOWN\n"); +#endif + + /* + * Don't pass Alt-F4 key combo to root window, + * let Windows translate to WM_CLOSE and close this top-level window. + * + * NOTE: We purposely don't check the fUseWinKillKey setting because + * it should only apply to the key handling for the root window, + * not for top-level window-manager windows. + * + * ALSO NOTE: We do pass Ctrl-Alt-Backspace to the root window + * because that is a key combo that no X app should be expecting to + * receive, since it has historically been used to shutdown the X server. + * Passing Ctrl-Alt-Backspace to the root window preserves that + * behavior, assuming that -unixkill has been passed as a parameter. + */ + if (wParam == VK_F4 && (GetKeyState (VK_MENU) & 0x8000)) + break; + + /* Pass the message to the root window */ + SendMessage (hwndScreen, message, wParam, lParam); + return 0; + + case WM_SYSKEYUP: + case WM_KEYUP: + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winTopLevelWindowProc - WM_*KEYUP\n"); +#endif + + /* Pass the message to the root window */ + SendMessage (hwndScreen, message, wParam, lParam); + return 0; + + case WM_HOTKEY: +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winTopLevelWindowProc - WM_HOTKEY\n"); +#endif + + /* Pass the message to the root window */ + SendMessage (hwndScreen, message, wParam, lParam); + return 0; + case WM_PAINT: + + /* BeginPaint gives us an hdc that clips to the invalidated region */ + hdcUpdate = BeginPaint (hwnd, &ps); + + /* Try to copy from the shadow buffer */ + if (!BitBlt (hdcUpdate, + 0, 0, + pRLWinPriv->dwWidth, pRLWinPriv->dwHeight, + pRLWinPriv->hdcShadow, + 0, 0, + SRCCOPY)) + { + LPVOID lpMsgBuf; + + /* Display a fancy error message */ + FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError (), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, + 0, NULL); + + ErrorF ("winTopLevelWindowProc - BitBlt failed: %s\n", + (LPSTR)lpMsgBuf); + LocalFree (lpMsgBuf); + } + + /* EndPaint frees the DC */ + EndPaint (hwnd, &ps); + break; + + default: + break; + } + + return DefWindowProc (hwnd, message, wParam, lParam); +} diff -ruN xwin-20031017-1340/winwindow.h xwin/winwindow.h --- xwin-20031017-1340/winwindow.h Sun Oct 5 03:54:27 2003 +++ xwin/winwindow.h Sat Oct 18 10:23:11 2003 @@ -53,7 +53,7 @@ #define WIN_WID_PROP "cyg_wid_prop_rl" #define WIN_NEEDMANAGE_PROP "cyg_override_redirect_prop_rl" #define WIN_HWND_CACHE "cyg_privmap_rl" -#define CYGMULTIWINDOW_DEBUG NO +#define CYGMULTIWINDOW_DEBUG YES typedef struct _winPrivScreenRec *winPrivScreenPtr;