diff -rubN xwin-20031017-1340/Imakefile xwin/Imakefile --- xwin-20031017-1340/Imakefile Wed Oct 22 13:58:18 2003 +++ xwin/Imakefile Sat Oct 25 14:49:16 2003 @@ -65,7 +65,9 @@ winpushpxl.c \ winprefsyacc.y \ winprefslex.l \ - winprefs.c + winprefs.c \ + winwin32rootless.c \ + winwin32rootlesscursor.c winprefsyacc.c: winprefsyacc.y bison -d -o winprefsyacc.c winprefsyacc.y @@ -143,11 +145,15 @@ winpushpxl.o \ winprefs.o \ winprefsyacc.o \ - winprefslex.o + winprefslex.o \ + winwin32rootless.o \ + winwin32rootlesscursor.o INCLUDES = -I. -I$(XBUILDINCDIR) -I$(FONTINCSRC) \ -I$(SERVERSRC)/fb -I$(SERVERSRC)/mi \ -I$(SERVERSRC)/miext/shadow -I$(SERVERSRC)/miext/layer \ + -I$(SERVERSRC)/miext/rootless \ + -I$(SERVERSRC)/miext/rootless/safeAlpha \ -I$(SERVERSRC)/include -I$(SERVERSRC)/os \ -I$(EXTINCSRC) -I$(XINCLUDESRC) \ -I$(SERVERSRC)/render -I$(SERVERSRC)/randr diff -rubN xwin-20031017-1340/Imakefile~ xwin/Imakefile~ --- xwin-20031017-1340/Imakefile~ Thu Jan 1 09:00:00 1970 +++ xwin/Imakefile~ Wed Oct 22 13:59:52 2003 @@ -0,0 +1,177 @@ +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 \ + winwin32rootlesscursor.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 \ + winwin32rootlesscursor.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 + +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 -rubN 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 25 22:54:14 2003 @@ -172,6 +172,7 @@ #include "shadow.h" #include "fb.h" #include "layer.h" +#include "rootless.h" #ifdef RENDER #include "mipict.h" @@ -498,6 +499,9 @@ /* Privates used by both shadow fb DirectDraw servers */ LPDIRECTDRAWCLIPPER pddcPrimary; + /* Privates used by rootless server */ + RootlessFrameID widTop; + /* Privates used by multi-window server */ pthread_t ptWMProc; pthread_t ptXMsgProc; @@ -530,7 +534,7 @@ winCreatePrimarySurfaceProcPtr pwinCreatePrimarySurface; winReleasePrimarySurfaceProcPtr pwinReleasePrimarySurface; - /* Window Procedures for Rootless mode */ + /* Window Procedures for multi-window mode */ CreateWindowProcPtr CreateWindow; DestroyWindowProcPtr DestroyWindow; PositionWindowProcPtr PositionWindow; @@ -1403,29 +1407,6 @@ Bool winMapWindowNativeGDI (WindowPtr pWindow); -Bool -winCreateWindowPRootless (WindowPtr pWindow); - -Bool -winDestroyWindowPRootless (WindowPtr pWindow); - -Bool -winPositionWindowPRootless (WindowPtr pWindow, int x, int y); - -Bool -winChangeWindowAttributesPRootless (WindowPtr pWindow, unsigned long mask); - -Bool -winUnmapWindowPRootless (WindowPtr pWindow); - -Bool -winMapWindowPRootless (WindowPtr pWindow); - -#ifdef SHAPE -void -winSetShapePRootless (WindowPtr pWindow); -#endif - /* * winmultiwindowicons.c @@ -1528,6 +1509,77 @@ 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); + +void +winWin32RootlessCopyBytes (unsigned int width, unsigned int height, + const void *src, unsigned int srcRowBytes, + void *dst, unsigned int dstRowBytes); + +void +winWin32RootlessFillBytes (unsigned int width, unsigned int height, unsigned int value, + void *dst, unsigned int dstRowBytes); + +int +winWin32RootlessCompositePixels (unsigned int width, unsigned int height, unsigned int function, + void *src[2], unsigned int srcRowBytes[2], + void *mask, unsigned int maskRowBytes, + void *dst[2], unsigned int dstRowBytes[2]); + +void +winWin32RootlessCopyWindow (RootlessFrameID wid, int dstNrects, const BoxRec *dstRects, + int dx, int dy); + + +/* + * winwin32rootlesscursor.c + */ + +Bool +winWin32RootlessInitCursor (ScreenPtr pScreen); /* * END DDX and DIX Function Prototypes diff -rubN xwin-20031017-1340/win.h~ xwin/win.h~ --- xwin-20031017-1340/win.h~ Thu Jan 1 09:00:00 1970 +++ xwin/win.h~ Fri Oct 24 09:27:32 2003 @@ -0,0 +1,1586 @@ +/* + *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: Dakshinamurthy Karra + * Suhaib M Siddiqi + * Peter Busch + * Harold L Hunt II + * Kensuke Matsuzaki + */ +/* $XFree86: xc/programs/Xserver/hw/xwin/win.h,v 1.37 2003/10/02 13:30:09 eich Exp $ */ + +#ifndef _WIN_H_ +#define _WIN_H_ + + +#ifndef NO +#define NO 0 +#endif +#ifndef YES +#define YES 1 +#endif + +/* + * Build toggles for experimental features + */ +#define WIN_NATIVE_GDI_SUPPORT YES +#define WIN_LAYER_SUPPORT NO +#define WIN_NEW_KEYBOARD_SUPPORT NO +#define WIN_EMULATE_PSEUDO_SUPPORT YES +#define WIN_UPDATE_STATS NO + +/* Turn debug messages on or off */ +#define CYGDEBUG NO + +#define NEED_EVENTS + +#define WIN_DEFAULT_BPP 0 +#define WIN_DEFAULT_WHITEPIXEL 255 +#define WIN_DEFAULT_BLACKPIXEL 0 +#define WIN_DEFAULT_LINEBIAS 0 +#define WIN_DEFAULT_E3B_TIME 50 /* milliseconds */ +#define WIN_DEFAULT_DPI 75 +#define WIN_DEFAULT_REFRESH 0 +#define WIN_DEFAULT_WIN_KILL TRUE +#define WIN_DEFAULT_UNIX_KILL FALSE +#define WIN_DEFAULT_CLIP_UPDATES_NBOXES 0 +#define WIN_DEFAULT_EMULATE_PSEUDO FALSE +#define WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH FALSE + +#define WIN_DIB_MAXIMUM_SIZE 0x08000000 /* 16 MB on Windows 95, 98, Me */ +#define WIN_DIB_MAXIMUM_SIZE_MB (WIN_DIB_MAXIMUM_SIZE / 8 / 1024 / 1024) + +/* + * Windows only supports 256 color palettes + */ +#define WIN_NUM_PALETTE_ENTRIES 256 + +/* + * Number of times to call Restore in an attempt to restore the primary surface + */ +#define WIN_REGAIN_SURFACE_RETRIES 1 + +/* + * Build a supported display depths mask by shifting one to the left + * by the number of bits in the supported depth. + */ +#define WIN_SUPPORTED_BPPS ( (1 << (32 - 1)) | (1 << (24 - 1)) \ + | (1 << (16 - 1)) | (1 << (15 - 1)) \ + | (1 << ( 8 - 1))) +#define WIN_CHECK_DEPTH YES + +/* + * Timer IDs for WM_TIMER + */ +#define WIN_E3B_TIMER_ID 1 +#define WIN_POLLING_MOUSE_TIMER_ID 2 + + +#define WIN_E3B_OFF -1 +#define WIN_FD_INVALID -1 + +#define WIN_SERVER_NONE 0x0L /* 0 */ +#define WIN_SERVER_SHADOW_GDI 0x1L /* 1 */ +#define WIN_SERVER_SHADOW_DD 0x2L /* 2 */ +#define WIN_SERVER_SHADOW_DDNL 0x4L /* 4 */ +#define WIN_SERVER_PRIMARY_DD 0x8L /* 8 */ +#define WIN_SERVER_NATIVE_GDI 0x10L /* 16 */ + +#define AltMapIndex Mod1MapIndex +#define NumLockMapIndex Mod2MapIndex +#define AltLangMapIndex Mod3MapIndex +#define KanaMapIndex Mod4MapIndex +#define ScrollLockMapIndex Mod5MapIndex + +#define WIN_MOD_LALT 0x00000001 +#define WIN_MOD_RALT 0x00000002 +#define WIN_MOD_LCONTROL 0x00000004 +#define WIN_MOD_RCONTROL 0x00000008 + +#define WIN_24BPP_MASK_RED 0x00FF0000 +#define WIN_24BPP_MASK_GREEN 0x0000FF00 +#define WIN_24BPP_MASK_BLUE 0x000000FF + +#define WIN_MAX_KEYS_PER_KEY 4 + +#include +#include +#include +#include +#include + +#include + +#ifdef HAS_MMAP +#include +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif /* MAP_FILE */ +#endif /* HAS_MMAP */ + +#include "X.h" +#include "Xproto.h" +#include "Xos.h" +#include "Xprotostr.h" +#include "scrnintstr.h" +#include "pixmapstr.h" +#include "pixmap.h" +#include "region.h" +#include "gcstruct.h" +#include "colormap.h" +#include "colormapst.h" +#include "miscstruct.h" +#include "servermd.h" +#include "windowstr.h" +#include "mi.h" +#include "micmap.h" +#include "migc.h" +#include "mifillarc.h" +#include "mifpoly.h" +#include "mibstore.h" +#include "input.h" +#include "mipointer.h" +#include "keysym.h" +#include "mibstore.h" +#include "micoord.h" +#include "dix.h" +#include "miline.h" +#include "shadow.h" +#include "fb.h" +#include "layer.h" +#include "rootless.h" + +#ifdef RENDER +#include "mipict.h" +#include "picturestr.h" +#endif + +#ifdef RANDR +#include "randrstr.h" +#endif + +/* + * Windows headers + */ +#include "winms.h" + + +/* + * Define Windows constants + */ + +#define WM_TRAYICON (WM_USER + 1000) +#define WM_INIT_SYS_MENU (WM_USER + 1001) +#define WM_GIVEUP (WM_USER + 1002) + + +/* + * Multi-Window Window Manager header + */ + +#include "winwindow.h" + + +/* Cygwin's winuser.h does not define VK_KANA as of 28Mar2001 */ +/* NOTE: Cygwin's winuser.h was fixed shortly after 28Mar2001. */ +#ifndef VK_KANA +#define VK_KANA 15 +#endif + + +/* + * Debugging macros + */ + +#if CYGDEBUG +#define DEBUG_MSG(str,...) \ +if (fDebugProcMsg) \ +{ \ + char *pszTemp; \ + int iLength; \ + \ + iLength = sprintf (NULL, str, ##__VA_ARGS__); \ + \ + pszTemp = malloc (iLength + 1); \ + \ + sprintf (pszTemp, str, ##__VA_ARGS__); \ + \ + MessageBox (NULL, pszTemp, szFunctionName, MB_OK); \ + \ + free (pszTemp); \ +} +#else +#define DEBUG_MSG(str,...) +#endif + +#if CYGDEBUG +#define DEBUG_FN_NAME(str) PTSTR szFunctionName = str +#else +#define DEBUG_FN_NAME(str) +#endif + +#if CYGDEBUG || YES +#define DEBUGVARS BOOL fDebugProcMsg = FALSE +#else +#define DEBUGVARS +#endif + +#if CYGDEBUG || YES +#define DEBUGPROC_MSG fDebugProcMsg = TRUE +#else +#define DEBUGPROC_MSG +#endif + +/* We use xor this macro for detecting toggle key state changes */ +#define WIN_XOR(a,b) ((!(a) && (b)) || ((a) && !(b))) + + +/* + * Typedefs for engine dependent function pointers + */ + +typedef Bool (*winAllocateFBProcPtr)(ScreenPtr); + +typedef void (*winShadowUpdateProcPtr)(ScreenPtr, shadowBufPtr); + +typedef Bool (*winCloseScreenProcPtr)(int, ScreenPtr); + +typedef Bool (*winInitVisualsProcPtr)(ScreenPtr); + +typedef Bool (*winAdjustVideoModeProcPtr)(ScreenPtr); + +typedef Bool (*winCreateBoundingWindowProcPtr)(ScreenPtr); + +typedef Bool (*winFinishScreenInitProcPtr)(int, ScreenPtr, int, char **); + +typedef Bool (*winBltExposedRegionsProcPtr)(ScreenPtr); + +typedef Bool (*winActivateAppProcPtr)(ScreenPtr); + +typedef Bool (*winRedrawScreenProcPtr)(ScreenPtr pScreen); + +typedef Bool (*winRealizeInstalledPaletteProcPtr)(ScreenPtr pScreen); + +typedef Bool (*winInstallColormapProcPtr)(ColormapPtr pColormap); + +typedef Bool (*winStoreColorsProcPtr)(ColormapPtr pmap, + int ndef, xColorItem *pdefs); + +typedef Bool (*winCreateColormapProcPtr)(ColormapPtr pColormap); + +typedef Bool (*winDestroyColormapProcPtr)(ColormapPtr pColormap); + +typedef Bool (*winHotKeyAltTabProcPtr)(ScreenPtr); + +typedef Bool (*winCreatePrimarySurfaceProcPtr)(ScreenPtr); + +typedef Bool (*winReleasePrimarySurfaceProcPtr)(ScreenPtr); + + +/* + * GC (graphics context) privates + */ + +typedef struct +{ + HDC hdc; + HDC hdcMem; +} winPrivGCRec, *winPrivGCPtr; + + +/* + * Pixmap privates + */ + +typedef struct +{ + HDC hdcSelected; + HBITMAP hBitmap; + BYTE *pbBits; + DWORD dwScanlineBytes; + BITMAPINFOHEADER *pbmih; +} winPrivPixmapRec, *winPrivPixmapPtr; + + +/* + * Colormap privates + */ + +typedef struct +{ + HPALETTE hPalette; + LPDIRECTDRAWPALETTE lpDDPalette; + RGBQUAD rgbColors[WIN_NUM_PALETTE_ENTRIES]; + PALETTEENTRY peColors[WIN_NUM_PALETTE_ENTRIES]; +} winPrivCmapRec, *winPrivCmapPtr; + + +#if WIN_NEW_KEYBOARD_SUPPORT +/* + * Keyboard event structure + */ + +typedef struct +{ + DWORD dwXKeycodes[WIN_MAX_KEYS_PER_KEY]; + DWORD dwReleaseModifiers; +} winKeyEventsRec, *winKeyEventsPtr; + +#endif /* WIN_NEW_KEYBOARD_SUPPORT */ + +/* + * Screen information structure that we need before privates are available + * in the server startup sequence. + */ + +typedef struct +{ + ScreenPtr pScreen; + + /* Did the user specify a height and width? */ + Bool fUserGaveHeightAndWidth; + + DWORD dwScreen; + DWORD dwUserWidth; + DWORD dwUserHeight; + DWORD dwWidth; + DWORD dwHeight; + DWORD dwWidth_mm; + DWORD dwHeight_mm; + DWORD dwPaddedWidth; + + /* + * dwStride is the number of whole pixels that occupy a scanline, + * including those pixels that are not displayed. This is basically + * a rounding up of the width. + */ + DWORD dwStride; + + /* Offset of the screen in the window when using scrollbars */ + DWORD dwXOffset; + DWORD dwYOffset; + + DWORD dwBPP; + DWORD dwDepth; + DWORD dwRefreshRate; + char *pfb; + XWDColor *pXWDCmap; + XWDFileHeader *pXWDHeader; + DWORD dwEngine; + DWORD dwEnginePreferred; + DWORD dwClipUpdatesNBoxes; + Bool fEmulatePseudo; + Bool fFullScreen; + Bool fDecoration; + Bool fRootless; + Bool fMultiWindow; + Bool fMultipleMonitors; + Bool fClipboard; + Bool fLessPointer; + Bool fScrollbars; + Bool fNoTrayIcon; + int iE3BTimeout; + /* Windows (Alt+F4) and Unix (Ctrl+Alt+Backspace) Killkey */ + Bool fUseWinKillKey; + Bool fUseUnixKillKey; + Bool fIgnoreInput; + + /* Did the user explicitly set this screen? */ + Bool fExplicitScreen; +} winScreenInfo, *winScreenInfoPtr; + + +/* + * Screen privates + */ + +typedef struct _winPrivScreenRec +{ + winScreenInfoPtr pScreenInfo; + + Bool fEnabled; + Bool fClosed; + Bool fActive; + Bool fBadDepth; + + int iDeltaZ; + + CloseScreenProcPtr CloseScreen; + + DWORD dwRedMask; + DWORD dwGreenMask; + DWORD dwBlueMask; + DWORD dwBitsPerRGB; + + DWORD dwModeKeyStates; + + /* Handle to icons that must be freed */ + HICON hiconNotifyIcon; + + /* Clipboard support */ + pthread_t ptClipboardProc; + +#if 0 + HWND hwndNextViewer; + void *display; + int window; +#endif + + /* Last width, height, and depth of the Windows display */ + DWORD dwLastWindowsWidth; + DWORD dwLastWindowsHeight; + DWORD dwLastWindowsBitsPixel; + + /* Layer support */ +#if WIN_LAYER_SUPPORT + DWORD dwLayerKind; + LayerPtr pLayer; +#endif + + /* Palette management */ + ColormapPtr pcmapInstalled; + + /* Pointer to the root visual so we only have to look it up once */ + VisualPtr pRootVisual; + + /* 3 button emulation variables */ + int iE3BCachedPress; + Bool fE3BFakeButton2Sent; + + /* Privates used by shadow fb GDI server */ + HBITMAP hbmpShadow; + HDC hdcScreen; + HDC hdcShadow; + HWND hwndScreen; + + /* Privates used by shadow fb and primary fb DirectDraw servers */ + LPDIRECTDRAW pdd; + LPDIRECTDRAWSURFACE2 pddsPrimary; + LPDIRECTDRAW2 pdd2; + + /* Privates used by shadow fb DirectDraw server */ + LPDIRECTDRAWSURFACE2 pddsShadow; + LPDDSURFACEDESC pddsdShadow; + + /* Privates used by primary fb DirectDraw server */ + LPDIRECTDRAWSURFACE2 pddsOffscreen; + LPDDSURFACEDESC pddsdOffscreen; + LPDDSURFACEDESC pddsdPrimary; + + /* Privates used by shadow fb DirectDraw Nonlocking server */ + LPDIRECTDRAW4 pdd4; + LPDIRECTDRAWSURFACE4 pddsShadow4; + LPDIRECTDRAWSURFACE4 pddsPrimary4; + + /* Privates used by both shadow fb DirectDraw servers */ + LPDIRECTDRAWCLIPPER pddcPrimary; + + /* Privates used by multi-window server */ + pthread_t ptWMProc; + pthread_t ptXMsgProc; + void *pWMInfo; + Bool fWindowOrderChanged; + Bool fRestacking; + Bool fRootWindowShown; + + /* Privates used for any module running in a seperate thread */ + pthread_mutex_t pmServerStarted; + Bool fServerStarted; + + /* Engine specific functions */ + winAllocateFBProcPtr pwinAllocateFB; + winShadowUpdateProcPtr pwinShadowUpdate; + winCloseScreenProcPtr pwinCloseScreen; + winInitVisualsProcPtr pwinInitVisuals; + winAdjustVideoModeProcPtr pwinAdjustVideoMode; + winCreateBoundingWindowProcPtr pwinCreateBoundingWindow; + winFinishScreenInitProcPtr pwinFinishScreenInit; + winBltExposedRegionsProcPtr pwinBltExposedRegions; + winActivateAppProcPtr pwinActivateApp; + winRedrawScreenProcPtr pwinRedrawScreen; + winRealizeInstalledPaletteProcPtr pwinRealizeInstalledPalette; + winInstallColormapProcPtr pwinInstallColormap; + winStoreColorsProcPtr pwinStoreColors; + winCreateColormapProcPtr pwinCreateColormap; + winDestroyColormapProcPtr pwinDestroyColormap; + winHotKeyAltTabProcPtr pwinHotKeyAltTab; + winCreatePrimarySurfaceProcPtr pwinCreatePrimarySurface; + winReleasePrimarySurfaceProcPtr pwinReleasePrimarySurface; + + /* Window Procedures for multi-window mode */ + CreateWindowProcPtr CreateWindow; + DestroyWindowProcPtr DestroyWindow; + PositionWindowProcPtr PositionWindow; + ChangeWindowAttributesProcPtr ChangeWindowAttributes; + RealizeWindowProcPtr RealizeWindow; + UnrealizeWindowProcPtr UnrealizeWindow; + ValidateTreeProcPtr ValidateTree; + PostValidateTreeProcPtr PostValidateTree; + WindowExposuresProcPtr WindowExposures; + PaintWindowBackgroundProcPtr PaintWindowBackground; + PaintWindowBorderProcPtr PaintWindowBorder; + CopyWindowProcPtr CopyWindow; + ClearToBackgroundProcPtr ClearToBackground; + ClipNotifyProcPtr ClipNotify; + RestackWindowProcPtr RestackWindow; + ReparentWindowProcPtr ReparentWindow; +#ifdef SHAPE + SetShapeProcPtr SetShape; +#endif +} winPrivScreenRec; + + +typedef struct { + pointer value; + XID id; +} WindowIDPairRec, *WindowIDPairPtr; + + +/* + * Extern declares for general global variables + */ + +extern winScreenInfo g_ScreenInfo[]; +extern miPointerScreenFuncRec g_winPointerCursorFuncs; +extern DWORD g_dwEvents; +extern int g_fdMessageQueue; +extern int g_iScreenPrivateIndex; +extern int g_iCmapPrivateIndex; +extern int g_iGCPrivateIndex; +extern int g_iPixmapPrivateIndex; +extern int g_iWindowPrivateIndex; +extern unsigned long g_ulServerGeneration; +extern CARD32 g_c32LastInputEventTime; +extern DWORD g_dwEnginesSupported; +extern HINSTANCE g_hInstance; +extern HWND g_hDlgDepthChange; +extern HWND g_hDlgExit; +extern int g_copyROP[]; +extern int g_patternROP[]; +extern const char * g_pszQueryHost; + + +/* + * Extern declares for dynamically loaded libraries and function pointers + */ + +extern HMODULE g_hmodDirectDraw; +extern FARPROC g_fpDirectDrawCreate; +extern FARPROC g_fpDirectDrawCreateClipper; + +extern HMODULE g_hmodCommonControls; +extern FARPROC g_fpTrackMouseEvent; + + +/* + * Screen privates macros + */ + +#define winGetScreenPriv(pScreen) \ + ((winPrivScreenPtr) (pScreen)->devPrivates[g_iScreenPrivateIndex].ptr) + +#define winSetScreenPriv(pScreen,v) \ + ((pScreen)->devPrivates[g_iScreenPrivateIndex].ptr = (pointer) v) + +#define winScreenPriv(pScreen) \ + winPrivScreenPtr pScreenPriv = winGetScreenPriv(pScreen) + + +/* + * Colormap privates macros + */ + +#define winGetCmapPriv(pCmap) \ + ((winPrivCmapPtr) (pCmap)->devPrivates[g_iCmapPrivateIndex].ptr) + +#define winSetCmapPriv(pCmap,v) \ + ((pCmap)->devPrivates[g_iCmapPrivateIndex].ptr = (pointer) v) + +#define winCmapPriv(pCmap) \ + winPrivCmapPtr pCmapPriv = winGetCmapPriv(pCmap) + + +/* + * GC privates macros + */ + +#define winGetGCPriv(pGC) \ + ((winPrivGCPtr) (pGC)->devPrivates[g_iGCPrivateIndex].ptr) + +#define winSetGCPriv(pGC,v) \ + ((pGC)->devPrivates[g_iGCPrivateIndex].ptr = (pointer) v) + +#define winGCPriv(pGC) \ + winPrivGCPtr pGCPriv = winGetGCPriv(pGC) + + +/* + * Pixmap privates macros + */ + +#define winGetPixmapPriv(pPixmap) \ + ((winPrivPixmapPtr) (pPixmap)->devPrivates[g_iPixmapPrivateIndex].ptr) + +#define winSetPixmapPriv(pPixmap,v) \ + ((pPixmap)->devPrivates[g_iPixmapPrivateIndex].ptr = (pointer) v) + +#define winPixmapPriv(pPixmap) \ + winPrivPixmapPtr pPixmapPriv = winGetPixmapPriv(pPixmap) + + +/* + * Window privates macros + */ + +#define winGetWindowPriv(pWin) \ + ((winPrivWinPtr) (pWin)->devPrivates[g_iWindowPrivateIndex].ptr) + +#define winSetWindowPriv(pWin,v) \ + ((pWin)->devPrivates[g_iWindowPrivateIndex].ptr = (pointer) v) + +#define winWindowPriv(pWin) \ + winPrivWinPtr pWinPriv = winGetWindowPriv(pWin) + + +/* + * FIXME: Windows mouse wheel macro; should be in Cygwin w32api headers. + * Has been fixed after May 05, 2001. Remove this section after the + * fixed headers are in distribution. + */ + +#ifndef GET_WHEEL_DELTA_WPARAM +#define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam)) +#endif /* GET_WHEEL_DELTA_WPARAM */ + + +/* + * FIXME: Windows shell API defines. Should be in w32api shellapi.h + */ + +#ifndef ABS_AUTOHIDE +#define ABS_AUTOHIDE 0x00000001 +#endif +#ifndef ABS_ALWAYSONTOP +#define ABS_ALWAYSONTOP 0x00000002 +#endif + + +/* + * BEGIN DDX and DIX Function Prototypes + */ + + +/* + * winallpriv.c + */ + +Bool +winAllocatePrivates (ScreenPtr pScreen); + +Bool +winInitCmapPrivates (ColormapPtr pCmap); + +Bool +winAllocateCmapPrivates (ColormapPtr pCmap); + + +/* + * winblock.c + */ + +void +winBlockHandler (int nScreen, + pointer pBlockData, + pointer pTimeout, + pointer pReadMask); + + +/* + * winclip.c + */ + +RegionPtr +winPixmapToRegionNativeGDI (PixmapPtr pPix); + + +/* + * winclipboardinit.c + */ + +Bool +winInitClipboard (pthread_t *ptClipboardProc, + pthread_mutex_t *ppmServerStarted, + DWORD dwScreen); + +/* + * winclipboardthread.c + */ + +void +winDeinitClipboard (); + + +/* + * wincmap.c + */ + +int +winListInstalledColormaps (ScreenPtr pScreen, Colormap *pmaps); + +void +winStoreColors (ColormapPtr pmap, int ndef, xColorItem *pdefs); + +void +winInstallColormap (ColormapPtr pmap); + +void +winUninstallColormap (ColormapPtr pmap); + +void +winResolveColor (unsigned short *pred, + unsigned short *pgreen, + unsigned short *pblue, + VisualPtr pVisual); + +Bool +winCreateColormap (ColormapPtr pmap); + +void +winDestroyColormap (ColormapPtr pmap); + +int +winExpandDirectColors (ColormapPtr pmap, int ndef, + xColorItem *indefs, xColorItem *outdefs); + +Bool +winCreateDefColormap (ScreenPtr pScreen); + +Bool +winSetVisualTypesNativeGDI (int nDepth, int nVisuals, int nBitsPerRGB); + +void +winClearVisualTypes (void); + + +/* + * wincreatewnd.c + */ + +Bool +winCreateBoundingWindowFullScreen (ScreenPtr pScreen); + +Bool +winCreateBoundingWindowWindowed (ScreenPtr pScreen); + + +/* + * wincursor.c + */ + +void +winPointerWarpCursor (ScreenPtr pScreen, int x, int y); + +Bool +winCursorOffScreen (ScreenPtr *ppScreen, int *x, int *y); + +void +winCrossScreen (ScreenPtr pScreen, Bool fEntering); + + +/* + * windialogs.c + */ + +void +winDisplayExitDialog (winPrivScreenPtr pScreenPriv); + + +void +winDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv); + + +/* + * winengine.c + */ + +void +winDetectSupportedEngines (); + +Bool +winSetEngine (ScreenPtr pScreen); + +Bool +winGetDDProcAddresses (); + + +/* + * winerror.c + */ + +void +OSVenderVErrorF (const char *pszFormat, va_list va_args); + + +/* + * winfillsp.c + */ + +void +winFillSpansNativeGDI (DrawablePtr pDrawable, + GCPtr pGC, + int nSpans, + DDXPointPtr pPoints, + int *pWidths, + int fSorted); + + +/* + * winfont.c + */ + +Bool +winRealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont); + +Bool +winUnrealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont); + + +/* + * wingc.c + */ + +Bool +winCreateGCNativeGDI (GCPtr pGC); + +void +winChangeGCNativeGDI (GCPtr pGC, unsigned long ulChanges); + +void +winPadPixmapNativdGDI (PixmapPtr pPixmap); + +void +winValidateGCNativeGDI (GCPtr pGC, + unsigned long changes, + DrawablePtr pDrawable); + +void +winCopyGCNativeGDI (GCPtr pGCsrc, unsigned long ulMask, GCPtr pGCdst); + +void +winDestroyGCNativeGDI (GCPtr pGC); + +void +winChangeClipNativeGDI (GCPtr pGC, int nType, pointer pValue, int nRects); + +void +winDestroyClipNativeGDI (GCPtr pGC); + +void +winCopyClipNativeGDI (GCPtr pGCdst, GCPtr pGCsrc); + + +/* + * wingetsp.c + */ + +void +winGetSpansNativeGDI (DrawablePtr pDrawable, + int wMax, + DDXPointPtr pPoints, + int *pWidths, + int nSpans, + char *pDst); + + +/* + * winkeybd.c + */ + +#if WIN_NEW_KEYBOARD_SUPPORT +winKeyEventsRec +winTranslateKey (DWORD dwVirtualKey, DWORD dwKeyData); +#else +void +winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode); +#endif + +void +winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap); + +void +winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt, + pointer pCtrl, int iClass); + +void +winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl); + +int +winKeybdProc (DeviceIntPtr pDeviceInt, int iState); + +void +winInitializeModeKeyStates (void); + +void +winStoreModeKeyStates (ScreenPtr pScreen); + +void +winRestoreModeKeyStates (ScreenPtr pScreen); + +Bool +winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam); + +void +winKeybdReleaseKeys (); + +void +winSendKeyEvent (DWORD dwKey, Bool fDown); + +#if WIN_NEW_KEYBOARD_SUPPORT +void +winProcessKeyEvent (DWORD dwVirtKey, DWORD dwKeyData); +#endif + + +/* + * winlayer.c + */ + +#if WIN_LAYER_SUPPORT + +LayerPtr +winLayerCreate (ScreenPtr pScreen); + +int +winLayerAdd (WindowPtr pWindow, pointer value); + +int +winLayerRemove (WindowPtr pWindow, pointer value); + +#ifdef RANDR +Bool +winRandRGetInfo (ScreenPtr pScreen, Rotation *pRotations); + +Bool +winRandRSetConfig (ScreenPtr pScreen, + Rotation rotateKind, + RRScreenSizePtr pSize); + +Bool +winRandRInit (ScreenPtr pScreen); +#endif /* RANDR */ +#endif /* WIN_LAYER_SUPPORT */ + + +/* + * winmisc.c + */ + +void +winQueryBestSizeNativeGDI (int class, unsigned short *pWidth, + unsigned short *pHeight, ScreenPtr pScreen); + +CARD8 +winCountBits (DWORD dw); + +Bool +winUpdateFBPointer (ScreenPtr pScreen, void *pbits); + +BOOL +winPaintBackground (HWND hwnd, COLORREF colorref); + + +/* + * winmouse.c + */ + +void +winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl); + +int +winMouseProc (DeviceIntPtr pDeviceInt, int iState); + +int +winMouseWheel (ScreenPtr pScreen, int iDeltaZ); + +void +winMouseButtonsSendEvent (int iEventType, int iButton); + +int +winMouseButtonsHandle (ScreenPtr pScreen, + int iEventType, int iButton, + WPARAM wParam); + + +/* + * winnativegdi.c + */ + +HBITMAP +winCreateDIBNativeGDI (int iWidth, int iHeight, int iDepth, + BYTE **ppbBits, BITMAPINFO **ppbmi); + +Bool +winAllocateFBNativeGDI (ScreenPtr pScreen); + +void +winShadowUpdateNativeGDI (ScreenPtr pScreen, + shadowBufPtr pBuf); + +Bool +winCloseScreenNativeGDI (int nIndex, ScreenPtr pScreen); + +Bool +winInitVisualsNativeGDI (ScreenPtr pScreen); + +Bool +winAdjustVideoModeNativeGDI (ScreenPtr pScreen); + +Bool +winBltExposedRegionsNativeGDI (ScreenPtr pScreen); + +Bool +winActivateAppNativeGDI (ScreenPtr pScreen); + +Bool +winSetEngineFunctionsNativeGDI (ScreenPtr pScreen); + +Bool +winRedrawScreenNativeGDI (ScreenPtr pScreen); + +Bool +winRealizeInstalledPaletteNativeGDI (ScreenPtr pScreen); + +Bool +winInstallColormapNativeGDI (ColormapPtr pColormap); + +Bool +winStoreColorsNativeGDI (ColormapPtr pmap, + int ndef, + xColorItem *pdefs); + +Bool +winCreateColormapNativeGDI (ColormapPtr pColormap); + +Bool +winDestroyColormapNativeGDI (ColormapPtr pColormap); + + + +/* + * winpfbddd.c + */ + +Bool +winAllocateFBPrimaryDD (ScreenPtr pScreen); + +Bool +winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen); + +Bool +winInitVisualsPrimaryDD (ScreenPtr pScreen); + +Bool +winAdjustVideoModePrimaryDD (ScreenPtr pScreen); + +Bool +winActivateAppPrimaryDD (ScreenPtr pScreen); + +Bool +winSetEngineFunctionsPrimaryDD (ScreenPtr pScreen); + +Bool +winHotKeyAltTabPrimaryDD (ScreenPtr pScreen); + + +/* + * winpixmap.c + */ + +PixmapPtr +winCreatePixmapNativeGDI (ScreenPtr pScreen, int width, int height, int depth); + +Bool +winDestroyPixmapNativeGDI (PixmapPtr pPixmap); + +void +winXRotatePixmapNativeGDI (PixmapPtr pPix, int rw); + +void +winYRotatePixmapNativeGDI (PixmapPtr pPix, int rh); + +void +winCopyRotatePixmapNativeGDI (PixmapPtr psrcPix, PixmapPtr *ppdstPix, + int xrot, int yrot); + +Bool +winModifyPixmapHeaderNativeGDI (PixmapPtr pPixmap, + int iWidth, int iHeight, + int iDepth, + int iBitsPerPixel, + int devKind, + pointer pPixData); + + +/* + * winpntwin.c + */ + +void +winPaintWindowNativeGDI (WindowPtr pWin, RegionPtr pRegion, int what); + + +/* + * winpolyline.c + */ + +void +winPolyLineNativeGDI (DrawablePtr pDrawable, + GCPtr pGC, + int mode, + int npt, + DDXPointPtr ppt); + + +/* + * winscrinit.c + */ + +Bool +winScreenInit (int index, + ScreenPtr pScreen, + int argc, char **argv); + +Bool +winFinishScreenInitFB (int index, + ScreenPtr pScreen, + int argc, char **argv); + +Bool +winFinishScreenInitNativeGDI (int index, + ScreenPtr pScreen, + int argc, char **argv); + +Bool +winSaveScreen (ScreenPtr pScreen, int on); + +PixmapPtr +winGetWindowPixmap (WindowPtr pWin); + +void +winSetWindowPixmap (WindowPtr pWin, PixmapPtr pPix); + + +/* + * winsetsp.c + */ + +void +winSetSpansNativeGDI (DrawablePtr pDrawable, + GCPtr pGC, + char *pSrc, + DDXPointPtr pPoints, + int *pWidth, + int nSpans, + int fSorted); + +/* + * winshaddd.c + */ + +Bool +winAllocateFBShadowDD (ScreenPtr pScreen); + +void +winShadowUpdateDD (ScreenPtr pScreen, + shadowBufPtr pBuf); + +Bool +winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen); + +Bool +winInitVisualsShadowDD (ScreenPtr pScreen); + +Bool +winAdjustVideoModeShadowDD (ScreenPtr pScreen); + +Bool +winBltExposedRegionsShadowDD (ScreenPtr pScreen); + +Bool +winActivateAppShadowDD (ScreenPtr pScreen); + +Bool +winSetEngineFunctionsShadowDD (ScreenPtr pScreen); + +Bool +winRedrawScreenShadowDD (ScreenPtr pScreen); + +Bool +winRealizeInstalledPaletteShadowDD (ScreenPtr pScreen); + +Bool +winInstallColormapShadowDD (ColormapPtr pColormap); + +Bool +winStoreColorsShadowDD (ColormapPtr pmap, + int ndef, + xColorItem *pdefs); + +Bool +winCreateColormapShadowDD (ColormapPtr pColormap); + +Bool +winDestroyColormapShadowDD (ColormapPtr pColormap); + +Bool +winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen); + +Bool +winReleasePrimarySurfaceShadowDD (ScreenPtr pScreen); + + +/* + * winshadddnl.c + */ + +Bool +winAllocateFBShadowDDNL (ScreenPtr pScreen); + +void +winShadowUpdateDDNL (ScreenPtr pScreen, + shadowBufPtr pBuf); + +Bool +winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen); + +Bool +winInitVisualsShadowDDNL (ScreenPtr pScreen); + +Bool +winAdjustVideoModeShadowDDNL (ScreenPtr pScreen); + +Bool +winBltExposedRegionsShadowDDNL (ScreenPtr pScreen); + +Bool +winActivateAppShadowDDNL (ScreenPtr pScreen); + +Bool +winSetEngineFunctionsShadowDDNL (ScreenPtr pScreen); + +Bool +winRedrawScreenShadowDDNL (ScreenPtr pScreen); + +Bool +winRealizeInstalledPaletteShadowDDNL (ScreenPtr pScreen); + +Bool +winInstallColormapShadowDDNL (ColormapPtr pColormap); + +Bool +winStoreColorsShadowDDNL (ColormapPtr pmap, + int ndef, + xColorItem *pdefs); + +Bool +winCreateColormapShadowDDNL (ColormapPtr pColormap); + +Bool +winDestroyColormapShadowDDNL (ColormapPtr pColormap); + +Bool +winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen); + +Bool +winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen); + + +/* + * winshadgdi.c + */ + +Bool +winAllocateFBShadowGDI (ScreenPtr pScreen); + +void +winShadowUpdateGDI (ScreenPtr pScreen, + shadowBufPtr pBuf); + +Bool +winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen); + +Bool +winInitVisualsShadowGDI (ScreenPtr pScreen); + +Bool +winAdjustVideoModeShadowGDI (ScreenPtr pScreen); + +Bool +winActivateAppShadowGDI (ScreenPtr pScreen); + +Bool +winRedrawScreenShadowGDI (ScreenPtr pScreen); + +Bool +winSetEngineFunctionsShadowGDI (ScreenPtr pScreen); + +Bool +winRealizeInstalledPaletteShadowGDI (ScreenPtr pScreen); + +Bool +winInstallColormapShadowGDI (ColormapPtr pColormap); + +Bool +winStoreColorsShadowGDI (ColormapPtr pmap, + int ndef, + xColorItem *pdefs); + +Bool +winCreateColormapShadowGDI (ColormapPtr pColormap); + +Bool +winDestroyColormapShadowGDI (ColormapPtr pColormap); + + +/* + * winwakeup.c + */ + +void +winWakeupHandler (int nScreen, + pointer pWakeupData, + unsigned long ulResult, + pointer pReadmask); + + +/* + * winwindow.c + */ + +Bool +winCreateWindowNativeGDI (WindowPtr pWin); + +Bool +winDestroyWindowNativeGDI (WindowPtr pWin); + +Bool +winPositionWindowNativeGDI (WindowPtr pWin, int x, int y); + +void +winCopyWindowNativeGDI (WindowPtr pWin, + DDXPointRec ptOldOrg, + RegionPtr prgnSrc); + +Bool +winChangeWindowAttributesNativeGDI (WindowPtr pWin, unsigned long mask); + +Bool +winUnmapWindowNativeGDI (WindowPtr pWindow); + +Bool +winMapWindowNativeGDI (WindowPtr pWindow); + + +/* + * winmultiwindowicons.c + */ + +HICON +winXIconToHICON (WindowPtr pWin); + +void +winUpdateIcon (Window id); + + +/* + * winmultiwindowshape.c + */ + +#ifdef SHAPE +void +winReshapeMultiWindow (WindowPtr pWin); + +void +winSetShapeMultiWindow (WindowPtr pWindow); + +void +winUpdateRgnMultiWindow (WindowPtr pWindow); +#endif + + +/* + * winmultiwindowwindow.c + */ + +Bool +winCreateWindowMultiWindow (WindowPtr pWindow); + +Bool +winDestroyWindowMultiWindow (WindowPtr pWindow); + +Bool +winPositionWindowMultiWindow (WindowPtr pWindow, int x, int y); + +Bool +winChangeWindowAttributesMultiWindow (WindowPtr pWindow, unsigned long mask); + +Bool +winUnmapWindowMultiWindow (WindowPtr pWindow); + +Bool +winMapWindowMultiWindow (WindowPtr pWindow); + +void +winReparentWindowMultiWindow (WindowPtr pWin, WindowPtr pPriorParent); + +void +winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib); + +void +winReorderWindowsMultiWindow (ScreenPtr pScreen); + +void +winMoveXWindow (WindowPtr pWin, int x, int y); + +void +winResizeXWindow (WindowPtr pWin, int w, int h); + +XID +winGetWindowID (WindowPtr pWin); + + +/* + * winmultiwindowwndproc.c + */ + +LRESULT CALLBACK +winTopLevelWindowProc (HWND hwnd, UINT message, + WPARAM wParam, LPARAM lParam); + + +/* + * wintrayicon.c + */ + +void +winInitNotifyIcon (winPrivScreenPtr pScreenPriv); + +void +winDeleteNotifyIcon (winPrivScreenPtr pScreenPriv); + +LRESULT +winHandleIconMessage (HWND hwnd, UINT message, + WPARAM wParam, LPARAM lParam, + winPrivScreenPtr pScreenPriv); + + +/* + * winwndproc.c + */ + +LRESULT CALLBACK +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); + +void +winWin32RootlessCopyBytes (unsigned int width, unsigned int height, + const void *src, unsigned int srcRowBytes, + void *dst, unsigned int dstRowBytes); + +void +winWin32RootlessFillBytes (unsigned int width, unsigned int height, unsigned int value, + void *dst, unsigned int dstRowBytes); + +int +winWin32RootlessCompositePixels (unsigned int width, unsigned int height, unsigned int function, + void *src[2], unsigned int srcRowBytes[2], + void *mask, unsigned int maskRowBytes, + void *dst[2], unsigned int dstRowBytes[2]); + +void +winWin32RootlessCopyWindow (RootlessFrameID wid, int dstNrects, const BoxRec *dstRects, + int dx, int dy); + + +/* + * winwin32rootlesscursor.c + */ + +Bool +winWin32RootlessInitCursor (ScreenPtr pScreen); + +/* + * END DDX and DIX Function Prototypes + */ + +#endif /* _WIN_H_ */ + diff -rubN xwin-20031017-1340/winblock.c xwin/winblock.c --- xwin-20031017-1340/winblock.c Thu Jul 31 07:34:53 2003 +++ xwin/winblock.c Sun Oct 19 10:51:13 2003 @@ -76,5 +76,6 @@ DispatchMessage (&msg); } } + if (pScreenPriv->pScreenInfo->fMultiWindow) winReorderWindowsMultiWindow ((ScreenPtr)pBlockData); } diff -rubN xwin-20031017-1340/wincreatewnd.c xwin/wincreatewnd.c --- xwin-20031017-1340/wincreatewnd.c Sat Sep 20 14:59:53 2003 +++ xwin/wincreatewnd.c Wed Oct 22 05:45:16 2003 @@ -396,7 +396,7 @@ #endif /* Show the window */ - if (pScreenInfo->fMultiWindow) + if (pScreenInfo->fMultiWindow || pScreenInfo->fRootless) { pScreenPriv->fRootWindowShown = FALSE; ShowWindow (*phwnd, SW_HIDE); diff -rubN xwin-20031017-1340/winengine.c xwin/winengine.c --- xwin-20031017-1340/winengine.c Thu Jul 31 07:34:53 2003 +++ xwin/winengine.c Wed Oct 22 05:45:27 2003 @@ -182,7 +182,7 @@ } /* ShadowGDI is the only engine that supports Multi Window Mode */ - if (pScreenInfo->fMultiWindow) + if (pScreenInfo->fMultiWindow || pScreenInfo->fRootless) { ErrorF ("winSetEngine - Multi Window => ShadowGDI\n"); pScreenInfo->dwEngine = WIN_SERVER_SHADOW_GDI; diff -rubN xwin-20031017-1340/winscrinit.BAK xwin/winscrinit.BAK --- xwin-20031017-1340/winscrinit.BAK Thu Jan 1 09:00:00 1970 +++ xwin/winscrinit.BAK Sat Oct 25 20:35:44 2003 @@ -0,0 +1,787 @@ +/* + *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: Dakshinamurthy Karra + * Suhaib M Siddiqi + * Peter Busch + * Harold L Hunt II + * Kensuke Matsuzaki + */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winscrinit.c,v 1.28 2003/08/07 23:47:58 alanh Exp $ */ + +#include "win.h" +#include "safeAlpha.h" + + +static RootlessFrameProcsRec winWin32RootlessProcs = { + winWin32RootlessCreateFrame, + winWin32RootlessDestroyFrame, + + winWin32RootlessMoveFrame, + winWin32RootlessResizeFrame, + winWin32RootlessRestackFrame, + winWin32RootlessReshapeFrame, + winWin32RootlessUnmapFrame, + + winWin32RootlessStartDrawing, + winWin32RootlessStopDrawing, + winWin32RootlessUpdateRegion, +#ifndef ROOTLESS_TRACK_DAMAGE + winWin32RootlessDamageRects, +#endif + winWin32RootlessRootlessSwitchWindow, + + winWin32RootlessCopyBytes, + winWin32RootlessFillBytes, + winWin32RootlessCompositePixels, + winWin32RootlessCopyWindow +}; + +/* + * Determine what type of screen we are initializing + * and call the appropriate procedure to intiailize + * that type of screen. + */ + +Bool +winScreenInit (int index, + ScreenPtr pScreen, + int argc, char **argv) +{ + winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; + winPrivScreenPtr pScreenPriv; + HDC hdc; + +#if CYGDEBUG + ErrorF ("winScreenInit - dwWidth: %d dwHeight: %d\n", + pScreenInfo->dwWidth, pScreenInfo->dwHeight); +#endif + + /* Bail if -rootless and -multiwindow flags both present */ + if (pScreenInfo->fRootless && pScreenInfo->fMultiWindow) + { + ErrorF ("winScreenInit - The -rootless and -multiwindow parameters\n" + "\tcannot be used together. Note that the -rootless parameter\n" + "\trequires an external window manager (e.g. twm), while the\n" + "\t-multiwindow parameter forbids an external window manager\n" + "\tsince it uses an internal window manager. Please correct\n" + "\tyour command-line parameters; do not forget to stop\n" + "\tlaunching an external window manager if you are using\n" + "\tthe -multiwindow command-line parameter."); + return FALSE; + } + + /* Allocate privates for this screen */ + if (!winAllocatePrivates (pScreen)) + { + ErrorF ("winScreenInit - Couldn't allocate screen privates\n"); + return FALSE; + } + + /* Get a pointer to the privates structure that was allocated */ + pScreenPriv = winGetScreenPriv (pScreen); + + /* Save a pointer to this screen in the screen info structure */ + pScreenInfo->pScreen = pScreen; + + /* Save a pointer to the screen info in the screen privates structure */ + /* This allows us to get back to the screen info from a screen pointer */ + pScreenPriv->pScreenInfo = pScreenInfo; + + /* + * Determine which engine to use. + * + * NOTE: This is done once per screen because each screen possibly has + * a preferred engine specified on the command line. + */ + if (!winSetEngine (pScreen)) + { + ErrorF ("winScreenInit - winSetEngine () failed\n"); + return FALSE; + } + + /* Adjust the video mode for our engine type */ + if (!(*pScreenPriv->pwinAdjustVideoMode) (pScreen)) + { + ErrorF ("winScreenInit - winAdjustVideoMode () failed\n"); + return FALSE; + } + + /* Check for supported display depth */ + if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1)))) + { + ErrorF ("winScreenInit - Unsupported display depth: %d\n" \ + "Change your Windows display depth to 15, 16, 24, or 32 bits " + "per pixel.\n", + pScreenInfo->dwBPP); + ErrorF ("winScreenInit - Supported depths: %08x\n", + WIN_SUPPORTED_BPPS); +#if WIN_CHECK_DEPTH + return FALSE; +#endif + } + + /* + * Check that all monitors have the same display depth if we are using + * multiple monitors + */ + if (pScreenInfo->fMultipleMonitors + && !GetSystemMetrics (SM_SAMEDISPLAYFORMAT)) + { + ErrorF ("winScreenInit - Monitors do not all have same pixel format / " + "display depth.\n" + "Using primary display only.\n"); + pScreenInfo->fMultipleMonitors = FALSE; + } + + /* Create display window */ + if (!(*pScreenPriv->pwinCreateBoundingWindow) (pScreen)) + { + ErrorF ("winScreenInit - pwinCreateBoundingWindow () " + "failed\n"); + return FALSE; + } + + /* Get a device context */ + hdc = GetDC (pScreenPriv->hwndScreen); + + /* Store the initial height, width, and depth of the display */ + /* Are we using multiple monitors? */ + if (pScreenInfo->fMultipleMonitors) + { + pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); + pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); + + /* + * In this case, some of the defaults set in + * winInitializeDefaultScreens () are not correct ... + */ + if (!pScreenInfo->fUserGaveHeightAndWidth) + { + pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); + pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); + pScreenInfo->dwWidth_mm = (pScreenInfo->dwWidth / + WIN_DEFAULT_DPI) * 25.4; + pScreenInfo->dwHeight_mm = (pScreenInfo->dwHeight / + WIN_DEFAULT_DPI) * 25.4; + } + } + else + { + pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXSCREEN); + pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYSCREEN); + } + + /* Save the original bits per pixel */ + pScreenPriv->dwLastWindowsBitsPixel = GetDeviceCaps (hdc, BITSPIXEL); + + /* Release the device context */ + ReleaseDC (pScreenPriv->hwndScreen, hdc); + + /* Clear the visuals list */ + miClearVisualTypes (); + + /* Set the padded screen width */ + pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth, + pScreenInfo->dwBPP); + + /* Call the engine dependent screen initialization procedure */ + if (!((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv))) + { + ErrorF ("winScreenInit - winFinishScreenInit () failed\n"); + return FALSE; + } + +#if CYGDEBUG || YES + ErrorF ("winScreenInit - returning\n"); +#endif + + return TRUE; +} + + +/* See Porting Layer Definition - p. 20 */ +Bool +winFinishScreenInitFB (int index, + ScreenPtr pScreen, + int argc, char **argv) +{ + winScreenPriv(pScreen); + winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; + VisualPtr pVisual = NULL; + char *pbits = NULL; + int iReturn; + +#if WIN_LAYER_SUPPORT + pScreenPriv->dwLayerKind = LAYER_SHADOW; +#endif + + /* Create framebuffer */ + if (!(*pScreenPriv->pwinAllocateFB) (pScreen)) + { + ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n"); + return FALSE; + } + + /* + * Grab the number of bits that are used to represent color in each pixel. + */ + if (pScreenInfo->dwBPP == 8) + pScreenInfo->dwDepth = 8; + else + pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask) + + winCountBits (pScreenPriv->dwGreenMask) + + winCountBits (pScreenPriv->dwBlueMask); + + ErrorF ("winFinishScreenInitFB - Masks: %08x %08x %08x\n", + pScreenPriv->dwRedMask, pScreenPriv->dwGreenMask, + pScreenPriv->dwBlueMask); + + /* Init visuals */ + if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) + { + ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n"); + return FALSE; + } + + /* Setup a local variable to point to the framebuffer */ + pbits = pScreenInfo->pfb; + + /* Apparently we need this for the render extension */ + miSetPixmapDepths (); + + /* Start fb initialization */ + if (!fbSetupScreen (pScreen, + pScreenInfo->pfb, + pScreenInfo->dwWidth, pScreenInfo->dwHeight, + monitorResolution, monitorResolution, + pScreenInfo->dwStride, + pScreenInfo->dwBPP)) + { + ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n"); + return FALSE; + } + + /* Override default colormap routines if visual class is dynamic */ + if (pScreenInfo->dwDepth == 8 + && (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI + || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL + && pScreenInfo->fFullScreen) + || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD + && pScreenInfo->fFullScreen))) + { + pScreen->CreateColormap = winCreateColormap; + pScreen->DestroyColormap = winDestroyColormap; + pScreen->InstallColormap = winInstallColormap; + pScreen->UninstallColormap = winUninstallColormap; + pScreen->ListInstalledColormaps = winListInstalledColormaps; + pScreen->StoreColors = winStoreColors; + pScreen->ResolveColor = winResolveColor; + + /* + * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its + * own colormap, as it cannot allocate 7 planes in the default + * colormap. Setting whitePixel to 1 allows Magic to get 7 + * planes in the default colormap, so it doesn't create its + * own colormap. This latter situation is highly desireable, + * as it keeps the Magic window viewable when switching to + * other X clients that use the default colormap. + */ + pScreen->blackPixel = 0; + pScreen->whitePixel = 1; + } + + /* Place our save screen function */ + pScreen->SaveScreen = winSaveScreen; + + /* Backing store functions */ + /* + * FIXME: Backing store support still doesn't seem to be working. + */ + pScreen->BackingStoreFuncs.SaveAreas = fbSaveAreas; + pScreen->BackingStoreFuncs.RestoreAreas = fbRestoreAreas; + + /* Finish fb initialization */ + if (!fbFinishScreenInit (pScreen, + pScreenInfo->pfb, + pScreenInfo->dwWidth, pScreenInfo->dwHeight, + monitorResolution, monitorResolution, + pScreenInfo->dwStride, + pScreenInfo->dwBPP)) + { + ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n"); + return FALSE; + } + + /* Save a pointer to the root visual */ + for (pVisual = pScreen->visuals; + pVisual->vid != pScreen->rootVisual; + pVisual++); + pScreenPriv->pRootVisual = pVisual; + + /* + * Setup points to the block and wakeup handlers. Pass a pointer + * to the current screen as pWakeupdata. + */ + pScreen->BlockHandler = winBlockHandler; + pScreen->WakeupHandler = winWakeupHandler; + pScreen->blockData = pScreen; + pScreen->wakeupData = pScreen; + +#ifdef RENDER + /* Render extension initialization, calls miPictureInit */ + if (!fbPictureInit (pScreen, NULL, 0)) + { + ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n"); + return FALSE; + } +#endif + +#if WIN_LAYER_SUPPORT + /* KDrive does LayerStartInit right after fbPictureInit */ + if (!LayerStartInit (pScreen)) + { + ErrorF ("winFinishScreenInitFB - LayerStartInit () failed\n"); + return FALSE; + } + + /* Not sure what we're adding to shadow, but add it anyway */ + if (!shadowAdd (pScreen, 0, pScreenPriv->pwinShadowUpdate, NULL, 0, 0)) + { + ErrorF ("winFinishScreenInitFB - shadowAdd () failed\n"); + return FALSE; + } + + /* KDrive does LayerFinishInit right after LayerStartInit */ + if (!LayerFinishInit (pScreen)) + { + ErrorF ("winFinishScreenInitFB - LayerFinishInit () failed\n"); + return FALSE; + } + + /* KDrive does LayerCreate right after LayerFinishInit */ + pScreenPriv->pLayer = winLayerCreate (pScreen); + if (!pScreenPriv->pLayer) + { + ErrorF ("winFinishScreenInitFB - winLayerCreate () failed\n"); + return FALSE; + } + + /* KDrive does RandRInit right after LayerCreate */ +#ifdef RANDR + if (pScreenInfo->dwDepth != 8 && !winRandRInit (pScreen)) + { + ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n"); + return FALSE; + } +#endif +#endif + + /* + * Backing store support should reduce network traffic and increase + * performance. + */ + miInitializeBackingStore (pScreen); + + /* KDrive does miDCInitialize right after miInitializeBackingStore */ + /* Setup the cursor routines */ +#if CYGDEBUG + ErrorF ("winFinishScreenInitFB - Calling miDCInitialize ()\n"); +#endif + miDCInitialize (pScreen, &g_winPointerCursorFuncs); + + /* KDrive does winCreateDefColormap right after miDCInitialize */ + /* Create a default colormap */ +#if CYGDEBUG + ErrorF ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n"); +#endif + if (!winCreateDefColormap (pScreen)) + { + ErrorF ("winFinishScreenInitFB - Could not create colormap\n"); + return FALSE; + } + +#if !WIN_LAYER_SUPPORT + /* Initialize the shadow framebuffer layer */ + if (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI + || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD + || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL) + { + if(!pScreenInfo->fRootless) /* FIXME: Darwin don't call shadowInit. Calling this make crash. */ + { +#if CYGDEBUG + ErrorF ("winFinishScreenInitFB - Calling shadowInit ()\n"); +#endif + if (!shadowInit (pScreen, + pScreenPriv->pwinShadowUpdate, + NULL)) + { + ErrorF ("winFinishScreenInitFB - shadowInit () failed\n"); + return FALSE; + } + } + } +#endif + + + /* Handle multi window mode */ + if (pScreenInfo->fMultiWindow) + { + /* Define the WRAP macro temporarily for local use */ +#define WRAP(a) \ + if (pScreen->a) { \ + pScreenPriv->a = pScreen->a; \ + } else { \ + ErrorF("null screen fn " #a "\n"); \ + pScreenPriv->a = NULL; \ + } + + /* Save a pointer to each lower-level window procedure */ + WRAP(CreateWindow); + WRAP(DestroyWindow); + WRAP(RealizeWindow); + WRAP(UnrealizeWindow); + WRAP(PositionWindow); + WRAP(ChangeWindowAttributes); + WRAP(ReparentWindow); + WRAP(RestackWindow); +#ifdef SHAPE + WRAP(SetShape); +#endif + + /* Assign multi-window window procedures to be top level procedures */ + pScreen->CreateWindow = winCreateWindowMultiWindow; + pScreen->DestroyWindow = winDestroyWindowMultiWindow; + pScreen->PositionWindow = winPositionWindowMultiWindow; + pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow; + pScreen->RealizeWindow = winMapWindowMultiWindow; + pScreen->UnrealizeWindow = winUnmapWindowMultiWindow; + pScreen->ReparentWindow = winReparentWindowMultiWindow; + pScreen->RestackWindow = winRestackWindowMultiWindow; +#ifdef SHAPE + pScreen->SetShape = winSetShapeMultiWindow; +#endif + + /* Undefine the WRAP macro, as it is not needed elsewhere */ +#undef WRAP + } + + if (pScreenInfo->fRootless) + { + ErrorF ("winScreenInit - RootlessInit\n"); + + RootlessInit(pScreen, &winWin32RootlessProcs); + + ErrorF ("winScreenInit - RootlessInit - done\n"); + + rootless_CopyBytes_threshold = 0; + rootless_FillBytes_threshold = 0; + rootless_CompositePixels_threshold = 0; + rootless_CopyWindow_threshold = 1;/* FIXME: How many? Profiling needed? */ + + if (!winWin32RootlessInitCursor (pScreen)) + { + return FALSE; + } + } + + /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */ + pScreenPriv->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; + + /* Create a mutex for modules in seperate threads to wait for */ + iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL); + if (iReturn != 0) + { + ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n", + iReturn); + return FALSE; + } + + /* Own the mutex for modules in seperate threads */ + iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted); + if (iReturn != 0) + { + ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n", + iReturn); + return FALSE; + } + + /* Set the ServerStarted flag to false */ + pScreenPriv->fServerStarted = FALSE; + + /* Set the WindowOrderChanged flag to false */ + pScreenPriv->fWindowOrderChanged = FALSE; + + pScreenPriv->fRestacking = FALSE; + +#if CYGDEBUG || YES + if (pScreenInfo->fMultiWindow) + ErrorF ("winFinishScreenInitFB - Calling winInitWM.\n"); +#endif + + /* Initialize multi window mode */ + if (pScreenInfo->fMultiWindow + && !winInitWM (&pScreenPriv->pWMInfo, + &pScreenPriv->ptWMProc, + &pScreenPriv->ptXMsgProc, + &pScreenPriv->pmServerStarted, + pScreenInfo->dwScreen)) + { + ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n"); + return FALSE; + } + +#if CYGDEBUG || YES + if (pScreenInfo->fClipboard) + ErrorF ("winFinishScreenInitFB - Calling winInitClipboard.\n"); +#endif + + /* Initialize the clipboard manager */ + if (pScreenInfo->fClipboard + && !winInitClipboard (&pScreenPriv->ptClipboardProc, + &pScreenPriv->pmServerStarted, + pScreenInfo->dwScreen)) + { + ErrorF ("winFinishScreenInitFB - winClipboardInit () failed.\n"); + return FALSE; + } + + /* Tell the server that we are enabled */ + pScreenPriv->fEnabled = TRUE; + + /* Tell the server that we have a valid depth */ + pScreenPriv->fBadDepth = FALSE; + +#if CYGDEBUG || YES + ErrorF ("winFinishScreenInitFB - returning\n"); +#endif + + return TRUE; +} + + +/* + * + * + * + * + * TEST CODE BELOW - NOT USED IN NORMAL COMPILATION + * + * + * + * + * + */ + + +/* See Porting Layer Definition - p. 20 */ + +Bool +winFinishScreenInitNativeGDI (int index, + ScreenPtr pScreen, + int argc, char **argv) +{ + winScreenPriv(pScreen); + winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; + VisualPtr pVisuals = NULL; + DepthPtr pDepths = NULL; + VisualID rootVisual = 0; + int nVisuals = 0, nDepths = 0, nRootDepth = 0; + + /* Ignore user input (mouse, keyboard) */ + pScreenInfo->fIgnoreInput = FALSE; + + /* Get device contexts for the screen and shadow bitmap */ + pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen); + if (pScreenPriv->hdcScreen == NULL) + FatalError ("winFinishScreenInitNativeGDI - Couldn't get a DC\n"); + + /* Init visuals */ + if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) + { + ErrorF ("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n"); + return FALSE; + } + + /* Initialize the mi visuals */ + if (!miInitVisuals (&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth, + &rootVisual, + ((unsigned long)1 << (pScreenInfo->dwDepth - 1)), 8, + TrueColor)) + { + ErrorF ("winFinishScreenInitNativeGDI - miInitVisuals () failed\n"); + return FALSE; + } + + /* Initialize the CloseScreen procedure pointer */ + pScreen->CloseScreen = NULL; + + /* Initialize the mi code */ + if (!miScreenInit (pScreen, + NULL, /* No framebuffer */ + pScreenInfo->dwWidth, pScreenInfo->dwHeight, + monitorResolution, monitorResolution, + pScreenInfo->dwStride, + nRootDepth, nDepths, pDepths, rootVisual, + nVisuals, pVisuals)) + { + ErrorF ("winFinishScreenInitNativeGDI - miScreenInit failed\n"); + return FALSE; + } + + pScreen->defColormap = FakeClientID(0); + + /* + * Register our block and wakeup handlers; these procedures + * process messages in our Windows message queue; specifically, + * they process mouse and keyboard input. + */ + pScreen->BlockHandler = winBlockHandler; + pScreen->WakeupHandler = winWakeupHandler; + pScreen->blockData = pScreen; + pScreen->wakeupData = pScreen; + + /* Place our save screen function */ + pScreen->SaveScreen = winSaveScreen; + + /* Pixmaps */ + pScreen->CreatePixmap = winCreatePixmapNativeGDI; + pScreen->DestroyPixmap = winDestroyPixmapNativeGDI; + + /* Other Screen Routines */ + pScreen->QueryBestSize = winQueryBestSizeNativeGDI; + pScreen->SaveScreen = winSaveScreen; + pScreen->GetImage = miGetImage; + pScreen->GetSpans = winGetSpansNativeGDI; + + /* Window Procedures */ + pScreen->CreateWindow = winCreateWindowNativeGDI; + pScreen->DestroyWindow = winDestroyWindowNativeGDI; + pScreen->PositionWindow = winPositionWindowNativeGDI; + pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI; + pScreen->RealizeWindow = winMapWindowNativeGDI; + pScreen->UnrealizeWindow = winUnmapWindowNativeGDI; + + /* Paint window */ + if (pScreenInfo->fRootless && 0) + { + pScreen->PaintWindowBackground = SafeAlphaPaintWindow; + pScreen->PaintWindowBorder = SafeAlphaPaintWindow; + } + else + { + pScreen->PaintWindowBackground = miPaintWindow; + pScreen->PaintWindowBorder = miPaintWindow; + } +#ifdef RENDER + if (pScreenInfo->fRootless && 0) + { + //PictureScreenPtr ps = GetPictureScreen(pScreen); + //ps->Composite = SafeAlphaComposite; + } +#endif /* RENDER */ + + pScreen->CopyWindow = winCopyWindowNativeGDI; + + /* Fonts */ + pScreen->RealizeFont = winRealizeFontNativeGDI; + pScreen->UnrealizeFont = winUnrealizeFontNativeGDI; + + /* GC */ + pScreen->CreateGC = winCreateGCNativeGDI; + + /* Colormap Routines */ + pScreen->CreateColormap = miInitializeColormap; + pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)()) NoopDDA; + pScreen->InstallColormap = miInstallColormap; + pScreen->UninstallColormap = miUninstallColormap; + pScreen->ListInstalledColormaps = miListInstalledColormaps; + pScreen->StoreColors = (StoreColorsProcPtr) (void (*)()) NoopDDA; + pScreen->ResolveColor = miResolveColor; + + /* Bitmap */ + pScreen->BitmapToRegion = winPixmapToRegionNativeGDI; + + ErrorF ("winFinishScreenInitNativeGDI - calling miDCInitialize\n"); + + /* Set the default white and black pixel positions */ + pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0; + + /* Initialize the cursor */ + if (!miDCInitialize (pScreen, &g_winPointerCursorFuncs)) + { + ErrorF ("winFinishScreenInitNativeGDI - miDCInitialize failed\n"); + return FALSE; + } + + /* Create a default colormap */ + if (!miCreateDefColormap (pScreen)) + { + ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () " + "failed\n"); + return FALSE; + } + + ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () " + "returned\n"); + + /* mi doesn't use a CloseScreen procedure, so no need to wrap */ + pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; + + /* Tell the server that we are enabled */ + pScreenPriv->fEnabled = TRUE; + + ErrorF ("winFinishScreenInitNativeGDI - Successful addition of " + "screen %08x\n", + pScreen); + + return TRUE; +} + + +/* See Porting Layer Definition - p. 33 */ +Bool +winSaveScreen (ScreenPtr pScreen, int on) +{ + return TRUE; +} + + +PixmapPtr +winGetWindowPixmap (WindowPtr pwin) +{ + ErrorF ("winGetWindowPixmap ()\n"); + return NULL; +} + + +void +winSetWindowPixmap (WindowPtr pwin, PixmapPtr pPix) +{ + ErrorF ("winSetWindowPixmap ()\n"); +} diff -rubN 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 25 20:35:50 2003 @@ -34,8 +34,33 @@ /* $XFree86: xc/programs/Xserver/hw/xwin/winscrinit.c,v 1.28 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" +#include "safeAlpha.h" +static RootlessFrameProcsRec winWin32RootlessProcs = { + winWin32RootlessCreateFrame, + winWin32RootlessDestroyFrame, + + winWin32RootlessMoveFrame, + winWin32RootlessResizeFrame, + winWin32RootlessRestackFrame, + winWin32RootlessReshapeFrame, + winWin32RootlessUnmapFrame, + + winWin32RootlessStartDrawing, + winWin32RootlessStopDrawing, + winWin32RootlessUpdateRegion, +#ifndef ROOTLESS_TRACK_DAMAGE + winWin32RootlessDamageRects, +#endif + winWin32RootlessRootlessSwitchWindow, + + winWin32RootlessCopyBytes, + winWin32RootlessFillBytes, + winWin32RootlessCompositePixels, + winWin32RootlessCopyWindow +}; + /* * Determine what type of screen we are initializing * and call the appropriate procedure to intiailize @@ -406,6 +431,8 @@ || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL) { + if(!pScreenInfo->fRootless) /* FIXME: Darwin don't call shadowInit. Calling this make crash. */ + { #if CYGDEBUG ErrorF ("winFinishScreenInitFB - Calling shadowInit ()\n"); #endif @@ -417,48 +444,12 @@ return FALSE; } } -#endif - - - /* Handle pseudo-rootless mode */ - if (pScreenInfo->fRootless) - { - /* Define the WRAP macro temporarily for local use */ -#define WRAP(a) \ - if (pScreen->a) { \ - pScreenPriv->a = pScreen->a; \ - } else { \ - ErrorF("null screen fn " #a "\n"); \ - pScreenPriv->a = NULL; \ } - - /* Save a pointer to each lower-level window procedure */ - WRAP(CreateWindow); - WRAP(DestroyWindow); - WRAP(RealizeWindow); - WRAP(UnrealizeWindow); - WRAP(PositionWindow); - WRAP(ChangeWindowAttributes); -#ifdef SHAPE - WRAP(SetShape); #endif - /* Assign pseudo-rootless window procedures to be top level procedures */ - pScreen->CreateWindow = winCreateWindowPRootless; - pScreen->DestroyWindow = winDestroyWindowPRootless; - pScreen->PositionWindow = winPositionWindowPRootless; - pScreen->ChangeWindowAttributes = winChangeWindowAttributesPRootless; - pScreen->RealizeWindow = winMapWindowPRootless; - pScreen->UnrealizeWindow = winUnmapWindowPRootless; -#ifdef SHAPE - pScreen->SetShape = winSetShapePRootless; -#endif - /* Undefine the WRAP macro, as it is not needed elsewhere */ -#undef WRAP - } /* Handle multi window mode */ - else if (pScreenInfo->fMultiWindow) + if (pScreenInfo->fMultiWindow) { /* Define the WRAP macro temporarily for local use */ #define WRAP(a) \ @@ -499,6 +490,25 @@ #undef WRAP } + if (pScreenInfo->fRootless) + { + ErrorF ("winScreenInit - RootlessInit\n"); + + RootlessInit(pScreen, &winWin32RootlessProcs); + + ErrorF ("winScreenInit - RootlessInit - done\n"); + + rootless_CopyBytes_threshold = 0; + rootless_FillBytes_threshold = 0; + rootless_CompositePixels_threshold = 0; + rootless_CopyWindow_threshold = 1;/* FIXME: How many? Profiling needed? */ + + if (!winWin32RootlessInitCursor (pScreen)) + { + return FALSE; + } + } + /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */ pScreenPriv->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; @@ -678,8 +688,24 @@ pScreen->UnrealizeWindow = winUnmapWindowNativeGDI; /* Paint window */ + if (pScreenInfo->fRootless && 0) + { + pScreen->PaintWindowBackground = SafeAlphaPaintWindow; + pScreen->PaintWindowBorder = SafeAlphaPaintWindow; + } + else + { pScreen->PaintWindowBackground = miPaintWindow; pScreen->PaintWindowBorder = miPaintWindow; + } +#ifdef RENDER + if (pScreenInfo->fRootless && 0) + { + PictureScreenPtr ps = GetPictureScreen(pScreen); + ps->Composite = SafeAlphaComposite; + } +#endif /* RENDER */ + pScreen->CopyWindow = winCopyWindowNativeGDI; /* Fonts */ diff -rubN xwin-20031017-1340/winscrinit.c~ xwin/winscrinit.c~ --- xwin-20031017-1340/winscrinit.c~ Thu Jan 1 09:00:00 1970 +++ xwin/winscrinit.c~ Fri Oct 24 21:54:19 2003 @@ -0,0 +1,770 @@ +/* + *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: Dakshinamurthy Karra + * Suhaib M Siddiqi + * Peter Busch + * Harold L Hunt II + * Kensuke Matsuzaki + */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winscrinit.c,v 1.28 2003/08/07 23:47:58 alanh Exp $ */ + +#include "win.h" + + +static RootlessFrameProcsRec winWin32RootlessProcs = { + winWin32RootlessCreateFrame, + winWin32RootlessDestroyFrame, + + winWin32RootlessMoveFrame, + winWin32RootlessResizeFrame, + winWin32RootlessRestackFrame, + winWin32RootlessReshapeFrame, + winWin32RootlessUnmapFrame, + + winWin32RootlessStartDrawing, + winWin32RootlessStopDrawing, + winWin32RootlessUpdateRegion, +#ifndef ROOTLESS_TRACK_DAMAGE + winWin32RootlessDamageRects, +#endif + winWin32RootlessRootlessSwitchWindow, + + winWin32RootlessCopyBytes, + winWin32RootlessFillBytes, + winWin32RootlessCompositePixels, + winWin32RootlessCopyWindow +}; + +/* + * Determine what type of screen we are initializing + * and call the appropriate procedure to intiailize + * that type of screen. + */ + +Bool +winScreenInit (int index, + ScreenPtr pScreen, + int argc, char **argv) +{ + winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; + winPrivScreenPtr pScreenPriv; + HDC hdc; + +#if CYGDEBUG + ErrorF ("winScreenInit - dwWidth: %d dwHeight: %d\n", + pScreenInfo->dwWidth, pScreenInfo->dwHeight); +#endif + + /* Bail if -rootless and -multiwindow flags both present */ + if (pScreenInfo->fRootless && pScreenInfo->fMultiWindow) + { + ErrorF ("winScreenInit - The -rootless and -multiwindow parameters\n" + "\tcannot be used together. Note that the -rootless parameter\n" + "\trequires an external window manager (e.g. twm), while the\n" + "\t-multiwindow parameter forbids an external window manager\n" + "\tsince it uses an internal window manager. Please correct\n" + "\tyour command-line parameters; do not forget to stop\n" + "\tlaunching an external window manager if you are using\n" + "\tthe -multiwindow command-line parameter."); + return FALSE; + } + + /* Allocate privates for this screen */ + if (!winAllocatePrivates (pScreen)) + { + ErrorF ("winScreenInit - Couldn't allocate screen privates\n"); + return FALSE; + } + + /* Get a pointer to the privates structure that was allocated */ + pScreenPriv = winGetScreenPriv (pScreen); + + /* Save a pointer to this screen in the screen info structure */ + pScreenInfo->pScreen = pScreen; + + /* Save a pointer to the screen info in the screen privates structure */ + /* This allows us to get back to the screen info from a screen pointer */ + pScreenPriv->pScreenInfo = pScreenInfo; + + /* + * Determine which engine to use. + * + * NOTE: This is done once per screen because each screen possibly has + * a preferred engine specified on the command line. + */ + if (!winSetEngine (pScreen)) + { + ErrorF ("winScreenInit - winSetEngine () failed\n"); + return FALSE; + } + + /* Adjust the video mode for our engine type */ + if (!(*pScreenPriv->pwinAdjustVideoMode) (pScreen)) + { + ErrorF ("winScreenInit - winAdjustVideoMode () failed\n"); + return FALSE; + } + + /* Check for supported display depth */ + if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1)))) + { + ErrorF ("winScreenInit - Unsupported display depth: %d\n" \ + "Change your Windows display depth to 15, 16, 24, or 32 bits " + "per pixel.\n", + pScreenInfo->dwBPP); + ErrorF ("winScreenInit - Supported depths: %08x\n", + WIN_SUPPORTED_BPPS); +#if WIN_CHECK_DEPTH + return FALSE; +#endif + } + + /* + * Check that all monitors have the same display depth if we are using + * multiple monitors + */ + if (pScreenInfo->fMultipleMonitors + && !GetSystemMetrics (SM_SAMEDISPLAYFORMAT)) + { + ErrorF ("winScreenInit - Monitors do not all have same pixel format / " + "display depth.\n" + "Using primary display only.\n"); + pScreenInfo->fMultipleMonitors = FALSE; + } + + /* Create display window */ + if (!(*pScreenPriv->pwinCreateBoundingWindow) (pScreen)) + { + ErrorF ("winScreenInit - pwinCreateBoundingWindow () " + "failed\n"); + return FALSE; + } + + /* Get a device context */ + hdc = GetDC (pScreenPriv->hwndScreen); + + /* Store the initial height, width, and depth of the display */ + /* Are we using multiple monitors? */ + if (pScreenInfo->fMultipleMonitors) + { + pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); + pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); + + /* + * In this case, some of the defaults set in + * winInitializeDefaultScreens () are not correct ... + */ + if (!pScreenInfo->fUserGaveHeightAndWidth) + { + pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); + pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); + pScreenInfo->dwWidth_mm = (pScreenInfo->dwWidth / + WIN_DEFAULT_DPI) * 25.4; + pScreenInfo->dwHeight_mm = (pScreenInfo->dwHeight / + WIN_DEFAULT_DPI) * 25.4; + } + } + else + { + pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXSCREEN); + pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYSCREEN); + } + + /* Save the original bits per pixel */ + pScreenPriv->dwLastWindowsBitsPixel = GetDeviceCaps (hdc, BITSPIXEL); + + /* Release the device context */ + ReleaseDC (pScreenPriv->hwndScreen, hdc); + + /* Clear the visuals list */ + miClearVisualTypes (); + + /* Set the padded screen width */ + pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth, + pScreenInfo->dwBPP); + + /* Call the engine dependent screen initialization procedure */ + if (!((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv))) + { + ErrorF ("winScreenInit - winFinishScreenInit () failed\n"); + return FALSE; + } + +#if CYGDEBUG || YES + ErrorF ("winScreenInit - returning\n"); +#endif + + return TRUE; +} + + +/* See Porting Layer Definition - p. 20 */ +Bool +winFinishScreenInitFB (int index, + ScreenPtr pScreen, + int argc, char **argv) +{ + winScreenPriv(pScreen); + winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; + VisualPtr pVisual = NULL; + char *pbits = NULL; + int iReturn; + +#if WIN_LAYER_SUPPORT + pScreenPriv->dwLayerKind = LAYER_SHADOW; +#endif + + /* Create framebuffer */ + if (!(*pScreenPriv->pwinAllocateFB) (pScreen)) + { + ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n"); + return FALSE; + } + + /* + * Grab the number of bits that are used to represent color in each pixel. + */ + if (pScreenInfo->dwBPP == 8) + pScreenInfo->dwDepth = 8; + else + pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask) + + winCountBits (pScreenPriv->dwGreenMask) + + winCountBits (pScreenPriv->dwBlueMask); + + ErrorF ("winFinishScreenInitFB - Masks: %08x %08x %08x\n", + pScreenPriv->dwRedMask, pScreenPriv->dwGreenMask, + pScreenPriv->dwBlueMask); + + /* Init visuals */ + if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) + { + ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n"); + return FALSE; + } + + /* Setup a local variable to point to the framebuffer */ + pbits = pScreenInfo->pfb; + + /* Apparently we need this for the render extension */ + miSetPixmapDepths (); + + /* Start fb initialization */ + if (!fbSetupScreen (pScreen, + pScreenInfo->pfb, + pScreenInfo->dwWidth, pScreenInfo->dwHeight, + monitorResolution, monitorResolution, + pScreenInfo->dwStride, + pScreenInfo->dwBPP)) + { + ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n"); + return FALSE; + } + + /* Override default colormap routines if visual class is dynamic */ + if (pScreenInfo->dwDepth == 8 + && (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI + || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL + && pScreenInfo->fFullScreen) + || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD + && pScreenInfo->fFullScreen))) + { + pScreen->CreateColormap = winCreateColormap; + pScreen->DestroyColormap = winDestroyColormap; + pScreen->InstallColormap = winInstallColormap; + pScreen->UninstallColormap = winUninstallColormap; + pScreen->ListInstalledColormaps = winListInstalledColormaps; + pScreen->StoreColors = winStoreColors; + pScreen->ResolveColor = winResolveColor; + + /* + * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its + * own colormap, as it cannot allocate 7 planes in the default + * colormap. Setting whitePixel to 1 allows Magic to get 7 + * planes in the default colormap, so it doesn't create its + * own colormap. This latter situation is highly desireable, + * as it keeps the Magic window viewable when switching to + * other X clients that use the default colormap. + */ + pScreen->blackPixel = 0; + pScreen->whitePixel = 1; + } + + /* Place our save screen function */ + pScreen->SaveScreen = winSaveScreen; + + /* Backing store functions */ + /* + * FIXME: Backing store support still doesn't seem to be working. + */ + pScreen->BackingStoreFuncs.SaveAreas = fbSaveAreas; + pScreen->BackingStoreFuncs.RestoreAreas = fbRestoreAreas; + + /* Finish fb initialization */ + if (!fbFinishScreenInit (pScreen, + pScreenInfo->pfb, + pScreenInfo->dwWidth, pScreenInfo->dwHeight, + monitorResolution, monitorResolution, + pScreenInfo->dwStride, + pScreenInfo->dwBPP)) + { + ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n"); + return FALSE; + } + + /* Save a pointer to the root visual */ + for (pVisual = pScreen->visuals; + pVisual->vid != pScreen->rootVisual; + pVisual++); + pScreenPriv->pRootVisual = pVisual; + + /* + * Setup points to the block and wakeup handlers. Pass a pointer + * to the current screen as pWakeupdata. + */ + pScreen->BlockHandler = winBlockHandler; + pScreen->WakeupHandler = winWakeupHandler; + pScreen->blockData = pScreen; + pScreen->wakeupData = pScreen; + +#ifdef RENDER + /* Render extension initialization, calls miPictureInit */ + if (!fbPictureInit (pScreen, NULL, 0)) + { + ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n"); + return FALSE; + } +#endif + +#if WIN_LAYER_SUPPORT + /* KDrive does LayerStartInit right after fbPictureInit */ + if (!LayerStartInit (pScreen)) + { + ErrorF ("winFinishScreenInitFB - LayerStartInit () failed\n"); + return FALSE; + } + + /* Not sure what we're adding to shadow, but add it anyway */ + if (!shadowAdd (pScreen, 0, pScreenPriv->pwinShadowUpdate, NULL, 0, 0)) + { + ErrorF ("winFinishScreenInitFB - shadowAdd () failed\n"); + return FALSE; + } + + /* KDrive does LayerFinishInit right after LayerStartInit */ + if (!LayerFinishInit (pScreen)) + { + ErrorF ("winFinishScreenInitFB - LayerFinishInit () failed\n"); + return FALSE; + } + + /* KDrive does LayerCreate right after LayerFinishInit */ + pScreenPriv->pLayer = winLayerCreate (pScreen); + if (!pScreenPriv->pLayer) + { + ErrorF ("winFinishScreenInitFB - winLayerCreate () failed\n"); + return FALSE; + } + + /* KDrive does RandRInit right after LayerCreate */ +#ifdef RANDR + if (pScreenInfo->dwDepth != 8 && !winRandRInit (pScreen)) + { + ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n"); + return FALSE; + } +#endif +#endif + + /* + * Backing store support should reduce network traffic and increase + * performance. + */ + miInitializeBackingStore (pScreen); + + /* KDrive does miDCInitialize right after miInitializeBackingStore */ + /* Setup the cursor routines */ +#if CYGDEBUG + ErrorF ("winFinishScreenInitFB - Calling miDCInitialize ()\n"); +#endif + miDCInitialize (pScreen, &g_winPointerCursorFuncs); + + /* KDrive does winCreateDefColormap right after miDCInitialize */ + /* Create a default colormap */ +#if CYGDEBUG + ErrorF ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n"); +#endif + if (!winCreateDefColormap (pScreen)) + { + ErrorF ("winFinishScreenInitFB - Could not create colormap\n"); + return FALSE; + } + +#if !WIN_LAYER_SUPPORT + /* Initialize the shadow framebuffer layer */ + if (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI + || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD + || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL) + { + if(!pScreenInfo->fRootless) /* FIXME: Darwin don't call shadowInit. Calling this make crash. */ + { +#if CYGDEBUG + ErrorF ("winFinishScreenInitFB - Calling shadowInit ()\n"); +#endif + if (!shadowInit (pScreen, + pScreenPriv->pwinShadowUpdate, + NULL)) + { + ErrorF ("winFinishScreenInitFB - shadowInit () failed\n"); + return FALSE; + } + } + } +#endif + + + /* Handle multi window mode */ + if (pScreenInfo->fMultiWindow) + { + /* Define the WRAP macro temporarily for local use */ +#define WRAP(a) \ + if (pScreen->a) { \ + pScreenPriv->a = pScreen->a; \ + } else { \ + ErrorF("null screen fn " #a "\n"); \ + pScreenPriv->a = NULL; \ + } + + /* Save a pointer to each lower-level window procedure */ + WRAP(CreateWindow); + WRAP(DestroyWindow); + WRAP(RealizeWindow); + WRAP(UnrealizeWindow); + WRAP(PositionWindow); + WRAP(ChangeWindowAttributes); + WRAP(ReparentWindow); + WRAP(RestackWindow); +#ifdef SHAPE + WRAP(SetShape); +#endif + + /* Assign multi-window window procedures to be top level procedures */ + pScreen->CreateWindow = winCreateWindowMultiWindow; + pScreen->DestroyWindow = winDestroyWindowMultiWindow; + pScreen->PositionWindow = winPositionWindowMultiWindow; + pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow; + pScreen->RealizeWindow = winMapWindowMultiWindow; + pScreen->UnrealizeWindow = winUnmapWindowMultiWindow; + pScreen->ReparentWindow = winReparentWindowMultiWindow; + pScreen->RestackWindow = winRestackWindowMultiWindow; +#ifdef SHAPE + pScreen->SetShape = winSetShapeMultiWindow; +#endif + + /* Undefine the WRAP macro, as it is not needed elsewhere */ +#undef WRAP + } + + if (pScreenInfo->fRootless) + { + ErrorF ("winScreenInit - RootlessInit\n"); + + RootlessInit(pScreen, &winWin32RootlessProcs); + + ErrorF ("winScreenInit - RootlessInit - done\n"); + + rootless_CopyBytes_threshold = 0; + rootless_FillBytes_threshold = 0; + rootless_CompositePixels_threshold = 0; + rootless_CopyWindow_threshold = 1;/* FIXME: How many? Profiling needed? */ + + if (!winWin32RootlessInitCursor (pScreen)) + { + return FALSE; + } + } + + /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */ + pScreenPriv->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; + + /* Create a mutex for modules in seperate threads to wait for */ + iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL); + if (iReturn != 0) + { + ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n", + iReturn); + return FALSE; + } + + /* Own the mutex for modules in seperate threads */ + iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted); + if (iReturn != 0) + { + ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n", + iReturn); + return FALSE; + } + + /* Set the ServerStarted flag to false */ + pScreenPriv->fServerStarted = FALSE; + + /* Set the WindowOrderChanged flag to false */ + pScreenPriv->fWindowOrderChanged = FALSE; + + pScreenPriv->fRestacking = FALSE; + +#if CYGDEBUG || YES + if (pScreenInfo->fMultiWindow) + ErrorF ("winFinishScreenInitFB - Calling winInitWM.\n"); +#endif + + /* Initialize multi window mode */ + if (pScreenInfo->fMultiWindow + && !winInitWM (&pScreenPriv->pWMInfo, + &pScreenPriv->ptWMProc, + &pScreenPriv->ptXMsgProc, + &pScreenPriv->pmServerStarted, + pScreenInfo->dwScreen)) + { + ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n"); + return FALSE; + } + +#if CYGDEBUG || YES + if (pScreenInfo->fClipboard) + ErrorF ("winFinishScreenInitFB - Calling winInitClipboard.\n"); +#endif + + /* Initialize the clipboard manager */ + if (pScreenInfo->fClipboard + && !winInitClipboard (&pScreenPriv->ptClipboardProc, + &pScreenPriv->pmServerStarted, + pScreenInfo->dwScreen)) + { + ErrorF ("winFinishScreenInitFB - winClipboardInit () failed.\n"); + return FALSE; + } + + /* Tell the server that we are enabled */ + pScreenPriv->fEnabled = TRUE; + + /* Tell the server that we have a valid depth */ + pScreenPriv->fBadDepth = FALSE; + +#if CYGDEBUG || YES + ErrorF ("winFinishScreenInitFB - returning\n"); +#endif + + return TRUE; +} + + +/* + * + * + * + * + * TEST CODE BELOW - NOT USED IN NORMAL COMPILATION + * + * + * + * + * + */ + + +/* See Porting Layer Definition - p. 20 */ + +Bool +winFinishScreenInitNativeGDI (int index, + ScreenPtr pScreen, + int argc, char **argv) +{ + winScreenPriv(pScreen); + winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; + VisualPtr pVisuals = NULL; + DepthPtr pDepths = NULL; + VisualID rootVisual = 0; + int nVisuals = 0, nDepths = 0, nRootDepth = 0; + + /* Ignore user input (mouse, keyboard) */ + pScreenInfo->fIgnoreInput = FALSE; + + /* Get device contexts for the screen and shadow bitmap */ + pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen); + if (pScreenPriv->hdcScreen == NULL) + FatalError ("winFinishScreenInitNativeGDI - Couldn't get a DC\n"); + + /* Init visuals */ + if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) + { + ErrorF ("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n"); + return FALSE; + } + + /* Initialize the mi visuals */ + if (!miInitVisuals (&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth, + &rootVisual, + ((unsigned long)1 << (pScreenInfo->dwDepth - 1)), 8, + TrueColor)) + { + ErrorF ("winFinishScreenInitNativeGDI - miInitVisuals () failed\n"); + return FALSE; + } + + /* Initialize the CloseScreen procedure pointer */ + pScreen->CloseScreen = NULL; + + /* Initialize the mi code */ + if (!miScreenInit (pScreen, + NULL, /* No framebuffer */ + pScreenInfo->dwWidth, pScreenInfo->dwHeight, + monitorResolution, monitorResolution, + pScreenInfo->dwStride, + nRootDepth, nDepths, pDepths, rootVisual, + nVisuals, pVisuals)) + { + ErrorF ("winFinishScreenInitNativeGDI - miScreenInit failed\n"); + return FALSE; + } + + pScreen->defColormap = FakeClientID(0); + + /* + * Register our block and wakeup handlers; these procedures + * process messages in our Windows message queue; specifically, + * they process mouse and keyboard input. + */ + pScreen->BlockHandler = winBlockHandler; + pScreen->WakeupHandler = winWakeupHandler; + pScreen->blockData = pScreen; + pScreen->wakeupData = pScreen; + + /* Place our save screen function */ + pScreen->SaveScreen = winSaveScreen; + + /* Pixmaps */ + pScreen->CreatePixmap = winCreatePixmapNativeGDI; + pScreen->DestroyPixmap = winDestroyPixmapNativeGDI; + + /* Other Screen Routines */ + pScreen->QueryBestSize = winQueryBestSizeNativeGDI; + pScreen->SaveScreen = winSaveScreen; + pScreen->GetImage = miGetImage; + pScreen->GetSpans = winGetSpansNativeGDI; + + /* Window Procedures */ + pScreen->CreateWindow = winCreateWindowNativeGDI; + pScreen->DestroyWindow = winDestroyWindowNativeGDI; + pScreen->PositionWindow = winPositionWindowNativeGDI; + pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI; + pScreen->RealizeWindow = winMapWindowNativeGDI; + pScreen->UnrealizeWindow = winUnmapWindowNativeGDI; + + /* Paint window */ + pScreen->PaintWindowBackground = miPaintWindow; + pScreen->PaintWindowBorder = miPaintWindow; + pScreen->CopyWindow = winCopyWindowNativeGDI; + + /* Fonts */ + pScreen->RealizeFont = winRealizeFontNativeGDI; + pScreen->UnrealizeFont = winUnrealizeFontNativeGDI; + + /* GC */ + pScreen->CreateGC = winCreateGCNativeGDI; + + /* Colormap Routines */ + pScreen->CreateColormap = miInitializeColormap; + pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)()) NoopDDA; + pScreen->InstallColormap = miInstallColormap; + pScreen->UninstallColormap = miUninstallColormap; + pScreen->ListInstalledColormaps = miListInstalledColormaps; + pScreen->StoreColors = (StoreColorsProcPtr) (void (*)()) NoopDDA; + pScreen->ResolveColor = miResolveColor; + + /* Bitmap */ + pScreen->BitmapToRegion = winPixmapToRegionNativeGDI; + + ErrorF ("winFinishScreenInitNativeGDI - calling miDCInitialize\n"); + + /* Set the default white and black pixel positions */ + pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0; + + /* Initialize the cursor */ + if (!miDCInitialize (pScreen, &g_winPointerCursorFuncs)) + { + ErrorF ("winFinishScreenInitNativeGDI - miDCInitialize failed\n"); + return FALSE; + } + + /* Create a default colormap */ + if (!miCreateDefColormap (pScreen)) + { + ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () " + "failed\n"); + return FALSE; + } + + ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () " + "returned\n"); + + /* mi doesn't use a CloseScreen procedure, so no need to wrap */ + pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; + + /* Tell the server that we are enabled */ + pScreenPriv->fEnabled = TRUE; + + ErrorF ("winFinishScreenInitNativeGDI - Successful addition of " + "screen %08x\n", + pScreen); + + return TRUE; +} + + +/* See Porting Layer Definition - p. 33 */ +Bool +winSaveScreen (ScreenPtr pScreen, int on) +{ + return TRUE; +} + + +PixmapPtr +winGetWindowPixmap (WindowPtr pwin) +{ + ErrorF ("winGetWindowPixmap ()\n"); + return NULL; +} + + +void +winSetWindowPixmap (WindowPtr pwin, PixmapPtr pPix) +{ + ErrorF ("winSetWindowPixmap ()\n"); +} diff -rubN xwin-20031017-1340/winwakeup.c xwin/winwakeup.c --- xwin-20031017-1340/winwakeup.c Thu Jul 31 07:34:54 2003 +++ xwin/winwakeup.c Sun Oct 19 11:12:46 2003 @@ -41,9 +41,7 @@ unsigned long ulResult, pointer pReadmask) { -#if 0 winScreenPriv((ScreenPtr)pWakeupData); -#endif MSG msg; /* Process all messages on our queue */ @@ -57,6 +55,7 @@ DispatchMessage (&msg); } } + if (pScreenPriv->pScreenInfo->fMultiWindow) winReorderWindowsMultiWindow ((ScreenPtr)pWakeupData); } diff -rubN xwin-20031017-1340/winwin32rootless.BAK xwin/winwin32rootless.BAK --- xwin-20031017-1340/winwin32rootless.BAK Thu Jan 1 09:00:00 1970 +++ xwin/winwin32rootless.BAK Sat Oct 25 17:06:04 2003 @@ -0,0 +1,1072 @@ +/* + * Look at hw/darwin/quartz/xpr/xprFrame.c and hw/darwin/quartz/cr/crFrame.c + */ +#include "win.h" +#include + +/* + * Constant defines + */ + +#define MOUSE_POLLING_INTERVAL 500 + +#define ULW_COLORKEY 0x00000001 +#define ULW_ALPHA 0x00000002 +#define ULW_OPAQUE 0x00000004 +#define AC_SRC_ALPHA 0x01 +/* + * External global variables + */ + +extern HICON g_hiconX; + +/* + * 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; + BITMAPINFOHEADER *pbmihShadow; + HBITMAP hbmpShadow; + HDC hdcShadow; + HDC hdcScreen; + BOOL fResized; + BOOL fRestackingNow; + BOOL fXTop; + 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; +} + +static HRGN +CreateRgnFromRegion (RegionPtr pShape) +{ + int nRects; + BoxPtr pRects, pEnd; + HRGN hRgn, hRgnRect; + + if (pShape == NULL) return NULL; + + nRects = REGION_NUM_RECTS(pShape); + pRects = REGION_RECTS(pShape); + + hRgn = CreateRectRgn (0, 0, 0, 0); + if (hRgn == NULL) + { + ErrorF ("winReshape - Initial CreateRectRgn (%d, %d, %d, %d) " + "failed: %d\n", + 0, 0, 0, 0, GetLastError ()); + } + + /* Loop through all rectangles in the X region */ + for (pEnd = pRects + nRects; pRects < pEnd; pRects++) + { + /* Create a Windows region for the X rectangle */ + hRgnRect = CreateRectRgn (pRects->x1, + pRects->y1, + pRects->x2, + pRects->y2); + if (hRgnRect == NULL) + { + ErrorF ("winReshape - Loop CreateRectRgn (%d, %d, %d, %d) " + "failed: %d\n", + pRects->x1, + pRects->y1, + pRects->x2, + pRects->y2, + GetLastError ()); + } + + /* Merge the Windows region with the accumulated region */ + if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR) + { + ErrorF ("winReshape - CombineRgn () failed: %d\n", + GetLastError ()); + } + + /* Delete the temporary Windows region */ + DeleteObject (hRgnRect); + } + + return hRgn; +} + +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; + pRLWinPriv->fRestackingNow = FALSE; + pRLWinPriv->fXTop = FALSE; + + 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_LAYERED*/, /* 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; + + pRLWinPriv->hdcScreen = GetDC (pRLWinPriv->hWnd); + pRLWinPriv->hdcShadow = CreateCompatibleDC (pRLWinPriv->hdcScreen); + pRLWinPriv->hbmpShadow = NULL; + + /* Allocate bitmap info header */ + pRLWinPriv->pbmihShadow = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER) + + 256 * sizeof (RGBQUAD)); + if (pRLWinPriv->pbmihShadow == NULL) + { + ErrorF ("winWin32RootlessCreateFrame - malloc () failed\n"); + return FALSE; + } + + /* Query the screen format */ + fResult = winQueryWin32RootlessDIBFormat (pRLWinPriv, + pRLWinPriv->pbmihShadow); + + if (pShape != NULL) + { + winWin32RootlessReshapeFrame (pFrame->wid, pShape); + } + +#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 + /* Free the shadow DC; which allows the bitmap to be freed */ + DeleteDC (pRLWinPriv->hdcShadow); + pRLWinPriv->hdcShadow = NULL; + + /* Free the screen DC */ + ReleaseDC (pRLWinPriv->hWnd, pRLWinPriv->hdcScreen); + pRLWinPriv->hdcScreen = NULL; + + /* Free bitmap info header */ + free (pRLWinPriv->pbmihShadow); + pRLWinPriv->pbmihShadow = NULL; + + 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; + HWND hWnd; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessRestackFrame (%08x)\n", pRLWinPriv); +#endif + + pRLWinPriv->fRestackingNow = TRUE; + + /* Is this correct behavior? */ + ShowWindow (pRLWinPriv->hWnd, SW_SHOWNA); + + if (pRLNextWinPriv == NULL) + { + pRLWinPriv->fXTop = TRUE; + SetWindowPos (pRLWinPriv->hWnd, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + } + else + { + pRLWinPriv->fXTop = FALSE; + hWnd = GetNextWindow (pRLWinPriv->hWnd, GW_HWNDPREV); + do + { + if (hWnd == pRLNextWinPriv->hWnd) + { + SetWindowPos (pRLWinPriv->hWnd, pRLNextWinPriv->hWnd, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + break; + } + hWnd = GetNextWindow (hWnd, GW_HWNDPREV); + } + while (hWnd); + } + pRLWinPriv->fRestackingNow = FALSE; +} + +void +winWin32RootlessReshapeFrame (RootlessFrameID wid, RegionPtr pShape) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + HRGN hRgn; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessReshapeFrame (%08x)\n", pRLWinPriv); +#endif + hRgn = CreateRgnFromRegion (pShape); + SetWindowRgn (pRLWinPriv->hWnd, hRgn, TRUE); +} + +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; + DIBSECTION dibsection; + Bool fReturn = TRUE; + HDC hdcNew; + HBITMAP hbmpNew; +#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) + { + RECT rc; + HBRUSH hbBlack; + HBRUSH hbOld; + + hdcNew = CreateCompatibleDC (pRLWinPriv->hdcScreen); + /* Describe shadow bitmap to be created */ + pRLWinPriv->pbmihShadow->biWidth = pRLWinPriv->dwWidth; + pRLWinPriv->pbmihShadow->biHeight = -pRLWinPriv->dwHeight; + + /* Create a DI shadow bitmap with a bit pointer */ + hbmpNew = CreateDIBSection (pRLWinPriv->hdcScreen, + (BITMAPINFO *) pRLWinPriv->pbmihShadow, + DIB_RGB_COLORS, + (VOID**) &pRLWinPriv->pfb, + NULL, + 0); + if (hbmpNew == 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 (hbmpNew, sizeof (dibsection), &dibsection); + +#if CYGDEBUG + /* 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 (hdcNew, hbmpNew); + + hbBlack = CreateSolidBrush (0xff000000); + rc.left = 0; + rc.top = 0; + rc.right = pRLWinPriv->dwWidth; + rc.bottom = pRLWinPriv->dwHeight; + hbOld = (HBRUSH) SelectObject (hdcNew, hbBlack); + FillRect (hdcNew, &rc, hbBlack); + SelectObject (hdcNew, hbOld); +#if CYGDEBUG + ErrorF ("winWin32RootlessStartDrawing - Attempting a shadow blit\n"); +#endif + + /* Blit from the old shadow to the new shadow */ + fReturn = BitBlt (hdcNew, + 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 + ErrorF ("winWin32RootlessStartDrawing - bytesPerRow: %d\n", + dibsection.dsBm.bmWidthBytes); +#endif + + /* Free the old shadow bitmap */ + DeleteObject (pRLWinPriv->hdcShadow); + DeleteObject (pRLWinPriv->hbmpShadow); + + pRLWinPriv->hdcShadow = hdcNew; + pRLWinPriv->hbmpShadow = hbmpNew; + + pRLWinPriv->fResized = FALSE; + } +#if CYGDEBUG + ErrorF ("winWin32RootlessStartDrawing - 0x%08x %d\n", + pRLWinPriv->pfb, dibsection.dsBm.bmWidthBytes); +#endif + *pixelData = pRLWinPriv->pfb; + *bytesPerRow = pRLWinPriv->dwWidthBytes; +} + +void +winWin32RootlessStopDrawing (RootlessFrameID wid, Bool flush) +{ +#if 0 + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + BLENDFUNCTION bfBlend; + SIZE szWin; + POINT ptSrc; +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessStopDrawing (%08x)\n", pRLWinPriv); +#endif + szWin.cx = pRLWinPriv->dwWidth; + szWin.cy = pRLWinPriv->dwHeight; + ptSrc.x = 0; + ptSrc.y = 0; + bfBlend.BlendOp = AC_SRC_OVER; + bfBlend.BlendFlags = 0; + bfBlend.SourceConstantAlpha = 255; + bfBlend.AlphaFormat = AC_SRC_ALPHA; + + if (!UpdateLayeredWindow (pRLWinPriv->hWnd, + NULL, NULL, &szWin, + pRLWinPriv->hdcShadow, &ptSrc, + 0, &bfBlend, ULW_ALPHA)) + { + ErrorF ("winWin32RootlessStopDrawing - UpdateLayeredWindow failed\n"); + } +#endif +} + +void +winWin32RootlessUpdateRegion (RootlessFrameID wid, RegionPtr pDamage) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if 0 + BLENDFUNCTION bfBlend; + SIZE szWin; + POINT ptSrc; +#endif +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessUpdateRegion (%08x)\n", pRLWinPriv); +#endif +#if 0 + szWin.cx = pRLWinPriv->dwWidth; + szWin.cy = pRLWinPriv->dwHeight; + ptSrc.x = 0; + ptSrc.y = 0; + bfBlend.BlendOp = AC_SRC_OVER; + bfBlend.BlendFlags = 0; + bfBlend.SourceConstantAlpha = 255; + bfBlend.AlphaFormat = AC_SRC_ALPHA; + + if (!UpdateLayeredWindow (pRLWinPriv->hWnd, + NULL, NULL, &szWin, + pRLWinPriv->hdcShadow, &ptSrc, + 0, &bfBlend, ULW_ALPHA)) + { + 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 ("winWin32RootlessUpdateRegion - UpdateLayeredWindow failed: %s\n", + (LPSTR)lpMsgBuf); + LocalFree (lpMsgBuf); + } +#endif + UpdateWindow (pRLWinPriv->hWnd); +} + +void +winWin32RootlessDamageRects (RootlessFrameID wid, int nCount, const BoxRec *pRects, + int shift_x, int shift_y) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + const BoxRec *pEnd; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessDamageRects (%08x, %d, %08x, %d, %d)\n", + pRLWinPriv, nCount, pRects, shift_x, shift_y); +#endif + + for (pEnd = pRects + nCount; pRects < pEnd; pRects++) { + RECT rcDmg; + rcDmg.left = pRects->x1 + shift_x; + rcDmg.top = pRects->y1 + shift_y; + rcDmg.right = pRects->x2 + shift_x; + rcDmg.bottom = pRects->y2 + shift_y; + + InvalidateRect (pRLWinPriv->hWnd, &rcDmg, FALSE); + } +} + +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; +} + +void +winWin32RootlessCopyBytes (unsigned int width, unsigned int height, + const void *src, unsigned int srcRowBytes, + void *dst, unsigned int dstRowBytes) +{ +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessCopyBytes - Not implemented\n"); +#endif +} + +void +winWin32RootlessFillBytes (unsigned int width, unsigned int height, unsigned int value, + void *dst, unsigned int dstRowBytes) +{ +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessFillBytes - Not implemented\n"); +#endif +} + +int +winWin32RootlessCompositePixels (unsigned int width, unsigned int height, unsigned int function, + void *src[2], unsigned int srcRowBytes[2], + void *mask, unsigned int maskRowBytes, + void *dst[2], unsigned int dstRowBytes[2]) +{ +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessCompositePixels - Not implemented\n"); +#endif + return 0; +} + + +void +winWin32RootlessCopyWindow (RootlessFrameID wid, int nDstRects, const BoxRec *pDstRects, + int nDx, int nDy) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + const BoxRec *pEnd; + RECT rcDmg; +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessCopyWindow (%08x, %d, %08x, %d, %d)\n", + pRLWinPriv, nDstRects, pDstRects, nDx, nDy); +#endif + + for (pEnd = pDstRects + nDstRects; pDstRects < pEnd; pDstRects++) + { + ErrorF ("BitBlt (%d, %d, %d, %d) (%d, %d)\n", + pDstRects->x1, pDstRects->y1, + pDstRects->x2 - pDstRects->x1, + pDstRects->y2 - pDstRects->y1, + pDstRects->x1 + nDx, + pDstRects->y1 + nDy); + + if (!BitBlt (pRLWinPriv->hdcShadow, + pDstRects->x1, pDstRects->y1, + pDstRects->x2 - pDstRects->x1, + pDstRects->y2 - pDstRects->y1, + pRLWinPriv->hdcShadow, + pDstRects->x1 + nDx, pDstRects->y1 + nDy, + SRCCOPY)) + { + ErrorF ("winWin32RootlessCopyWindow - BitBlt failed.\n"); + } + + rcDmg.left = pDstRects->x1; + rcDmg.top = pDstRects->y1; + rcDmg.right = pDstRects->x2; + rcDmg.bottom = pDstRects->y2; + + InvalidateRect (pRLWinPriv->hWnd, &rcDmg, FALSE); + } +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessCopyWindow - done\n"); +#endif +} + +/* + * 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; + WINDOWPOS *pWinPos; + + /* 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; + } + + /* 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; + + /* + * 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; + + /* + * 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, + ps.rcPaint.left, ps.rcPaint.top, + ps.rcPaint.right - ps.rcPaint.left, + ps.rcPaint.bottom - ps.rcPaint.top, + pRLWinPriv->hdcShadow, + ps.rcPaint.left, ps.rcPaint.top, + 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; + + case WM_WINDOWPOSCHANGING: + /* Window manager does restacking */ + if (pRLWinPriv->fRestackingNow || pRLWinPriv->fXTop) break; + pWinPos = (LPWINDOWPOS)lParam; + pWinPos->flags |= SWP_NOZORDER; + break; + + default: + break; + } + + return DefWindowProc (hwnd, message, wParam, lParam); +} diff -rubN 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 25 23:16:11 2003 @@ -0,0 +1,1102 @@ +/* + * Look at hw/darwin/quartz/xpr/xprFrame.c and hw/darwin/quartz/cr/crFrame.c + */ +#include "win.h" +#include + +/* + * Constant defines + */ + +#define MOUSE_POLLING_INTERVAL 500 + +#define ULW_COLORKEY 0x00000001 +#define ULW_ALPHA 0x00000002 +#define ULW_OPAQUE 0x00000004 +#define AC_SRC_ALPHA 0x01 +/* + * External global variables + */ + +extern HICON g_hiconX; + +/* + * 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; + BITMAPINFOHEADER *pbmihShadow; + HBITMAP hbmpShadow; + HDC hdcShadow; + HDC hdcScreen; + BOOL fResized; + BOOL fRestackingNow; + //BOOL fXTop; + 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; +} + +static HRGN +CreateRgnFromRegion (RegionPtr pShape) +{ + int nRects; + BoxPtr pRects, pEnd; + HRGN hRgn, hRgnRect; + + if (pShape == NULL) return NULL; + + nRects = REGION_NUM_RECTS(pShape); + pRects = REGION_RECTS(pShape); + + hRgn = CreateRectRgn (0, 0, 0, 0); + if (hRgn == NULL) + { + ErrorF ("winReshape - Initial CreateRectRgn (%d, %d, %d, %d) " + "failed: %d\n", + 0, 0, 0, 0, GetLastError ()); + } + + /* Loop through all rectangles in the X region */ + for (pEnd = pRects + nRects; pRects < pEnd; pRects++) + { + /* Create a Windows region for the X rectangle */ + hRgnRect = CreateRectRgn (pRects->x1, + pRects->y1, + pRects->x2, + pRects->y2); + if (hRgnRect == NULL) + { + ErrorF ("winReshape - Loop CreateRectRgn (%d, %d, %d, %d) " + "failed: %d\n", + pRects->x1, + pRects->y1, + pRects->x2, + pRects->y2, + GetLastError ()); + } + + /* Merge the Windows region with the accumulated region */ + if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR) + { + ErrorF ("winReshape - CombineRgn () failed: %d\n", + GetLastError ()); + } + + /* Delete the temporary Windows region */ + DeleteObject (hRgnRect); + } + + return hRgn; +} + +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; + pRLWinPriv->fRestackingNow = FALSE; + //pRLWinPriv->fXTop = FALSE; + + 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_LAYERED*/, /* 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; + + pRLWinPriv->hdcScreen = GetDC (pRLWinPriv->hWnd); + pRLWinPriv->hdcShadow = CreateCompatibleDC (pRLWinPriv->hdcScreen); + pRLWinPriv->hbmpShadow = NULL; + + /* Allocate bitmap info header */ + pRLWinPriv->pbmihShadow = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER) + + 256 * sizeof (RGBQUAD)); + if (pRLWinPriv->pbmihShadow == NULL) + { + ErrorF ("winWin32RootlessCreateFrame - malloc () failed\n"); + return FALSE; + } + + /* Query the screen format */ + fResult = winQueryWin32RootlessDIBFormat (pRLWinPriv, + pRLWinPriv->pbmihShadow); + + if (pShape != NULL) + { + winWin32RootlessReshapeFrame (pFrame->wid, pShape); + } + +#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 + /* Free the shadow DC; which allows the bitmap to be freed */ + DeleteDC (pRLWinPriv->hdcShadow); + pRLWinPriv->hdcShadow = NULL; + + /* Free the screen DC */ + ReleaseDC (pRLWinPriv->hWnd, pRLWinPriv->hdcScreen); + pRLWinPriv->hdcScreen = NULL; + + /* Free bitmap info header */ + free (pRLWinPriv->pbmihShadow); + pRLWinPriv->pbmihShadow = NULL; + + 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; + winScreenPriv(pRLWinPriv->pWin->drawable.pScreen); + HWND hWnd; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessRestackFrame (%08x)\n", pRLWinPriv); +#endif + + pRLWinPriv->fRestackingNow = TRUE; + + /* Is this correct behavior? */ + ShowWindow (pRLWinPriv->hWnd, SW_SHOWNA); + + if (pRLNextWinPriv == NULL) + { + ErrorF ("Win %08x is top\n", pRLWinPriv); + pScreenPriv->widTop = wid; + //pRLWinPriv->fXTop = TRUE; + SetWindowPos (pRLWinPriv->hWnd, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + } + else + { + //ErrorF ("Win %08x is not top\n", pRLWinPriv); + //pRLWinPriv->fXTop = FALSE; + hWnd = GetNextWindow (pRLWinPriv->hWnd, GW_HWNDPREV); + do + { + if (hWnd == pRLNextWinPriv->hWnd) + { + SetWindowPos (pRLWinPriv->hWnd, pRLNextWinPriv->hWnd, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + break; + } + hWnd = GetNextWindow (hWnd, GW_HWNDPREV); + } + while (hWnd); + } + pRLWinPriv->fRestackingNow = FALSE; +} + +void +winWin32RootlessReshapeFrame (RootlessFrameID wid, RegionPtr pShape) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + HRGN hRgn; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessReshapeFrame (%08x)\n", pRLWinPriv); +#endif + hRgn = CreateRgnFromRegion (pShape); + SetWindowRgn (pRLWinPriv->hWnd, hRgn, TRUE); +} + +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; + DIBSECTION dibsection; + Bool fReturn = TRUE; + HDC hdcNew; + HBITMAP hbmpNew; +#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) + { + hdcNew = CreateCompatibleDC (pRLWinPriv->hdcScreen); + /* Describe shadow bitmap to be created */ + pRLWinPriv->pbmihShadow->biWidth = pRLWinPriv->dwWidth; + pRLWinPriv->pbmihShadow->biHeight = -pRLWinPriv->dwHeight; + + /* Create a DI shadow bitmap with a bit pointer */ + hbmpNew = CreateDIBSection (pRLWinPriv->hdcScreen, + (BITMAPINFO *) pRLWinPriv->pbmihShadow, + DIB_RGB_COLORS, + (VOID**) &pRLWinPriv->pfb, + NULL, + 0); + if (hbmpNew == 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 (hbmpNew, sizeof (dibsection), &dibsection); + +#if CYGDEBUG + /* 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 (hdcNew, hbmpNew); + +#if CYGDEBUG + ErrorF ("winWin32RootlessStartDrawing - Attempting a shadow blit\n"); +#endif + + /* Blit from the old shadow to the new shadow */ + fReturn = BitBlt (hdcNew, + 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 + ErrorF ("winWin32RootlessStartDrawing - bytesPerRow: %d\n", + dibsection.dsBm.bmWidthBytes); +#endif + + /* Free the old shadow bitmap */ + DeleteObject (pRLWinPriv->hdcShadow); + DeleteObject (pRLWinPriv->hbmpShadow); + + pRLWinPriv->hdcShadow = hdcNew; + pRLWinPriv->hbmpShadow = hbmpNew; + + pRLWinPriv->fResized = FALSE; + } +#if CYGDEBUG + ErrorF ("winWin32RootlessStartDrawing - 0x%08x %d\n", + pRLWinPriv->pfb, dibsection.dsBm.bmWidthBytes); +#endif + *pixelData = pRLWinPriv->pfb; + *bytesPerRow = pRLWinPriv->dwWidthBytes; +} + +void +winWin32RootlessStopDrawing (RootlessFrameID wid, Bool flush) +{ +#if 0 + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + BLENDFUNCTION bfBlend; + SIZE szWin; + POINT ptSrc; +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessStopDrawing (%08x)\n", pRLWinPriv); +#endif + szWin.cx = pRLWinPriv->dwWidth; + szWin.cy = pRLWinPriv->dwHeight; + ptSrc.x = 0; + ptSrc.y = 0; + bfBlend.BlendOp = AC_SRC_OVER; + bfBlend.BlendFlags = 0; + bfBlend.SourceConstantAlpha = 255; + bfBlend.AlphaFormat = AC_SRC_ALPHA; + + if (!UpdateLayeredWindow (pRLWinPriv->hWnd, + NULL, NULL, &szWin, + pRLWinPriv->hdcShadow, &ptSrc, + 0, &bfBlend, ULW_ALPHA)) + { + ErrorF ("winWin32RootlessStopDrawing - UpdateLayeredWindow failed\n"); + } +#endif +} + +void +winWin32RootlessUpdateRegion (RootlessFrameID wid, RegionPtr pDamage) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if 0 + BLENDFUNCTION bfBlend; + SIZE szWin; + POINT ptSrc; +#endif +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessUpdateRegion (%08x)\n", pRLWinPriv); +#endif +#if 0 + szWin.cx = pRLWinPriv->dwWidth; + szWin.cy = pRLWinPriv->dwHeight; + ptSrc.x = 0; + ptSrc.y = 0; + bfBlend.BlendOp = AC_SRC_OVER; + bfBlend.BlendFlags = 0; + bfBlend.SourceConstantAlpha = 255; + bfBlend.AlphaFormat = AC_SRC_ALPHA; + + if (!UpdateLayeredWindow (pRLWinPriv->hWnd, + NULL, NULL, &szWin, + pRLWinPriv->hdcShadow, &ptSrc, + 0, &bfBlend, ULW_ALPHA)) + { + 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 ("winWin32RootlessUpdateRegion - UpdateLayeredWindow failed: %s\n", + (LPSTR)lpMsgBuf); + LocalFree (lpMsgBuf); + } +#endif + UpdateWindow (pRLWinPriv->hWnd); +} + +void +winWin32RootlessDamageRects (RootlessFrameID wid, int nCount, const BoxRec *pRects, + int shift_x, int shift_y) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + const BoxRec *pEnd; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessDamageRects (%08x, %d, %08x, %d, %d)\n", + pRLWinPriv, nCount, pRects, shift_x, shift_y); +#endif + + for (pEnd = pRects + nCount; pRects < pEnd; pRects++) { + RECT rcDmg; + rcDmg.left = pRects->x1 + shift_x; + rcDmg.top = pRects->y1 + shift_y; + rcDmg.right = pRects->x2 + shift_x; + rcDmg.bottom = pRects->y2 + shift_y; + + InvalidateRect (pRLWinPriv->hWnd, &rcDmg, FALSE); + } +} + +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; +} + +void +winWin32RootlessCopyBytes (unsigned int width, unsigned int height, + const void *src, unsigned int srcRowBytes, + void *dst, unsigned int dstRowBytes) +{ +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessCopyBytes - Not implemented\n"); +#endif +} + +void +winWin32RootlessFillBytes (unsigned int width, unsigned int height, unsigned int value, + void *dst, unsigned int dstRowBytes) +{ +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessFillBytes - Not implemented\n"); +#endif +} + +int +winWin32RootlessCompositePixels (unsigned int width, unsigned int height, unsigned int function, + void *src[2], unsigned int srcRowBytes[2], + void *mask, unsigned int maskRowBytes, + void *dst[2], unsigned int dstRowBytes[2]) +{ +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessCompositePixels - Not implemented\n"); +#endif + return 0; +} + + +void +winWin32RootlessCopyWindow (RootlessFrameID wid, int nDstRects, const BoxRec *pDstRects, + int nDx, int nDy) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + const BoxRec *pEnd; + RECT rcDmg; +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessCopyWindow (%08x, %d, %08x, %d, %d)\n", + pRLWinPriv, nDstRects, pDstRects, nDx, nDy); +#endif + + for (pEnd = pDstRects + nDstRects; pDstRects < pEnd; pDstRects++) + { + ErrorF ("BitBlt (%d, %d, %d, %d) (%d, %d)\n", + pDstRects->x1, pDstRects->y1, + pDstRects->x2 - pDstRects->x1, + pDstRects->y2 - pDstRects->y1, + pDstRects->x1 + nDx, + pDstRects->y1 + nDy); + + if (!BitBlt (pRLWinPriv->hdcShadow, + pDstRects->x1, pDstRects->y1, + pDstRects->x2 - pDstRects->x1, + pDstRects->y2 - pDstRects->y1, + pRLWinPriv->hdcShadow, + pDstRects->x1 + nDx, pDstRects->y1 + nDy, + SRCCOPY)) + { + ErrorF ("winWin32RootlessCopyWindow - BitBlt failed.\n"); + } + + rcDmg.left = pDstRects->x1; + rcDmg.top = pDstRects->y1; + rcDmg.right = pDstRects->x2; + rcDmg.bottom = pDstRects->y2; + + InvalidateRect (pRLWinPriv->hWnd, &rcDmg, FALSE); + } +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessCopyWindow - done\n"); +#endif +} + +/* + * 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; + WINDOWPOS *pWinPos; + HWND hInsWnd; + + /* 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; + } + + /* 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; + + /* + * 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; + + /* + * 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, + ps.rcPaint.left, ps.rcPaint.top, + ps.rcPaint.right - ps.rcPaint.left, + ps.rcPaint.bottom - ps.rcPaint.top, + pRLWinPriv->hdcShadow, + ps.rcPaint.left, ps.rcPaint.top, + 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; + + case WM_WINDOWPOSCHANGING: + pWinPos = (LPWINDOWPOS)lParam; + /* Window manager does restacking */ + if (!(pWinPos->flags & SWP_NOZORDER)) + { + if (pRLWinPriv->fRestackingNow) + { + ErrorF ("Win %08x is now restacking.\n", pRLWinPriv); + return 0; + } + + //if (pRLWinPriv->fXTop) + if (pScreenPriv->widTop == pRLWinPriv) + { +#if 0 + if ((pWinPos->hwndInsertAfter == HWND_TOP)|| + (pWinPos->hwndInsertAfter == HWND_TOPMOST)|| + (pWinPos->hwndInsertAfter == HWND_NOTOPMOST)) + { + ErrorF ("Win %08x is top and become top/topmost/notopmost.\n", pRLWinPriv); + return 0; + } + + for (hInsWnd = GetNextWindow (hwnd, GW_HWNDPREV); + hInsWnd; hInsWnd = GetNextWindow (hInsWnd, GW_HWNDPREV)) + { + if (hInsWnd == pWinPos->hwndInsertAfter) + { + ErrorF ("Win %08x is top and go above.\n", + pRLWinPriv); + return 0; + } + hInsWnd = GetNextWindow (hInsWnd, GW_HWNDPREV); + } + ErrorF ("Win %08x is top but forbid.\n", pRLWinPriv); +#endif + return 0; + } + ErrorF ("Win %08x forbid to change z order (%08x).\n", + pRLWinPriv, pWinPos->hwndInsertAfter); + pWinPos->flags |= SWP_NOZORDER; + } + break; + + default: + break; + } + + return DefWindowProc (hwnd, message, wParam, lParam); +} diff -rubN 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 25 17:06:50 2003 @@ -0,0 +1,1060 @@ +/* + * Look at hw/darwin/quartz/xpr/xprFrame.c and hw/darwin/quartz/cr/crFrame.c + */ +#include "win.h" +#include + +/* + * Constant defines + */ + +#define MOUSE_POLLING_INTERVAL 500 + +#define ULW_COLORKEY 0x00000001 +#define ULW_ALPHA 0x00000002 +#define ULW_OPAQUE 0x00000004 +#define AC_SRC_ALPHA 0x01 +/* + * External global variables + */ + +extern HICON g_hiconX; + +/* + * 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; + BITMAPINFOHEADER *pbmihShadow; + HBITMAP hbmpShadow; + HDC hdcShadow; + HDC hdcScreen; + BOOL fResized; + BOOL fRestackingNow; + BOOL fXTop; + 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; +} + +static HRGN +CreateRgnFromRegion (RegionPtr pShape) +{ + int nRects; + BoxPtr pRects, pEnd; + HRGN hRgn, hRgnRect; + + if (pShape == NULL) return NULL; + + nRects = REGION_NUM_RECTS(pShape); + pRects = REGION_RECTS(pShape); + + hRgn = CreateRectRgn (0, 0, 0, 0); + if (hRgn == NULL) + { + ErrorF ("winReshape - Initial CreateRectRgn (%d, %d, %d, %d) " + "failed: %d\n", + 0, 0, 0, 0, GetLastError ()); + } + + /* Loop through all rectangles in the X region */ + for (pEnd = pRects + nRects; pRects < pEnd; pRects++) + { + /* Create a Windows region for the X rectangle */ + hRgnRect = CreateRectRgn (pRects->x1, + pRects->y1, + pRects->x2, + pRects->y2); + if (hRgnRect == NULL) + { + ErrorF ("winReshape - Loop CreateRectRgn (%d, %d, %d, %d) " + "failed: %d\n", + pRects->x1, + pRects->y1, + pRects->x2, + pRects->y2, + GetLastError ()); + } + + /* Merge the Windows region with the accumulated region */ + if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR) + { + ErrorF ("winReshape - CombineRgn () failed: %d\n", + GetLastError ()); + } + + /* Delete the temporary Windows region */ + DeleteObject (hRgnRect); + } + + return hRgn; +} + +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; + pRLWinPriv->fRestackingNow = FALSE; + pRLWinPriv->fXTop = FALSE; + + 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_LAYERED*/, /* 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; + + pRLWinPriv->hdcScreen = GetDC (pRLWinPriv->hWnd); + pRLWinPriv->hdcShadow = CreateCompatibleDC (pRLWinPriv->hdcScreen); + pRLWinPriv->hbmpShadow = NULL; + + /* Allocate bitmap info header */ + pRLWinPriv->pbmihShadow = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER) + + 256 * sizeof (RGBQUAD)); + if (pRLWinPriv->pbmihShadow == NULL) + { + ErrorF ("winWin32RootlessCreateFrame - malloc () failed\n"); + return FALSE; + } + + /* Query the screen format */ + fResult = winQueryWin32RootlessDIBFormat (pRLWinPriv, + pRLWinPriv->pbmihShadow); + + if (pShape != NULL) + { + winWin32RootlessReshapeFrame (pFrame->wid, pShape); + } + +#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 + /* Free the shadow DC; which allows the bitmap to be freed */ + DeleteDC (pRLWinPriv->hdcShadow); + pRLWinPriv->hdcShadow = NULL; + + /* Free the screen DC */ + ReleaseDC (pRLWinPriv->hWnd, pRLWinPriv->hdcScreen); + pRLWinPriv->hdcScreen = NULL; + + /* Free bitmap info header */ + free (pRLWinPriv->pbmihShadow); + pRLWinPriv->pbmihShadow = NULL; + + 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; + HWND hWnd; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessRestackFrame (%08x)\n", pRLWinPriv); +#endif + + pRLWinPriv->fRestackingNow = TRUE; + + /* Is this correct behavior? */ + ShowWindow (pRLWinPriv->hWnd, SW_SHOWNA); + + if (pRLNextWinPriv == NULL) + { + pRLWinPriv->fXTop = TRUE; + SetWindowPos (pRLWinPriv->hWnd, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + } + else + { + pRLWinPriv->fXTop = FALSE; + hWnd = GetNextWindow (pRLWinPriv->hWnd, GW_HWNDPREV); + do + { + if (hWnd == pRLNextWinPriv->hWnd) + { + SetWindowPos (pRLWinPriv->hWnd, pRLNextWinPriv->hWnd, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + break; + } + hWnd = GetNextWindow (hWnd, GW_HWNDPREV); + } + while (hWnd); + } + pRLWinPriv->fRestackingNow = FALSE; +} + +void +winWin32RootlessReshapeFrame (RootlessFrameID wid, RegionPtr pShape) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + HRGN hRgn; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessReshapeFrame (%08x)\n", pRLWinPriv); +#endif + hRgn = CreateRgnFromRegion (pShape); + SetWindowRgn (pRLWinPriv->hWnd, hRgn, TRUE); +} + +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; + DIBSECTION dibsection; + Bool fReturn = TRUE; + HDC hdcNew; + HBITMAP hbmpNew; +#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) + { + hdcNew = CreateCompatibleDC (pRLWinPriv->hdcScreen); + /* Describe shadow bitmap to be created */ + pRLWinPriv->pbmihShadow->biWidth = pRLWinPriv->dwWidth; + pRLWinPriv->pbmihShadow->biHeight = -pRLWinPriv->dwHeight; + + /* Create a DI shadow bitmap with a bit pointer */ + hbmpNew = CreateDIBSection (pRLWinPriv->hdcScreen, + (BITMAPINFO *) pRLWinPriv->pbmihShadow, + DIB_RGB_COLORS, + (VOID**) &pRLWinPriv->pfb, + NULL, + 0); + if (hbmpNew == 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 (hbmpNew, sizeof (dibsection), &dibsection); + +#if CYGDEBUG + /* 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 (hdcNew, hbmpNew); + +#if CYGDEBUG + ErrorF ("winWin32RootlessStartDrawing - Attempting a shadow blit\n"); +#endif + + /* Blit from the old shadow to the new shadow */ + fReturn = BitBlt (hdcNew, + 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 + ErrorF ("winWin32RootlessStartDrawing - bytesPerRow: %d\n", + dibsection.dsBm.bmWidthBytes); +#endif + + /* Free the old shadow bitmap */ + DeleteObject (pRLWinPriv->hdcShadow); + DeleteObject (pRLWinPriv->hbmpShadow); + + pRLWinPriv->hdcShadow = hdcNew; + pRLWinPriv->hbmpShadow = hbmpNew; + + pRLWinPriv->fResized = FALSE; + } +#if CYGDEBUG + ErrorF ("winWin32RootlessStartDrawing - 0x%08x %d\n", + pRLWinPriv->pfb, dibsection.dsBm.bmWidthBytes); +#endif + *pixelData = pRLWinPriv->pfb; + *bytesPerRow = pRLWinPriv->dwWidthBytes; +} + +void +winWin32RootlessStopDrawing (RootlessFrameID wid, Bool flush) +{ +#if 0 + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + BLENDFUNCTION bfBlend; + SIZE szWin; + POINT ptSrc; +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessStopDrawing (%08x)\n", pRLWinPriv); +#endif + szWin.cx = pRLWinPriv->dwWidth; + szWin.cy = pRLWinPriv->dwHeight; + ptSrc.x = 0; + ptSrc.y = 0; + bfBlend.BlendOp = AC_SRC_OVER; + bfBlend.BlendFlags = 0; + bfBlend.SourceConstantAlpha = 255; + bfBlend.AlphaFormat = AC_SRC_ALPHA; + + if (!UpdateLayeredWindow (pRLWinPriv->hWnd, + NULL, NULL, &szWin, + pRLWinPriv->hdcShadow, &ptSrc, + 0, &bfBlend, ULW_ALPHA)) + { + ErrorF ("winWin32RootlessStopDrawing - UpdateLayeredWindow failed\n"); + } +#endif +} + +void +winWin32RootlessUpdateRegion (RootlessFrameID wid, RegionPtr pDamage) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; +#if 0 + BLENDFUNCTION bfBlend; + SIZE szWin; + POINT ptSrc; +#endif +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessUpdateRegion (%08x)\n", pRLWinPriv); +#endif +#if 0 + szWin.cx = pRLWinPriv->dwWidth; + szWin.cy = pRLWinPriv->dwHeight; + ptSrc.x = 0; + ptSrc.y = 0; + bfBlend.BlendOp = AC_SRC_OVER; + bfBlend.BlendFlags = 0; + bfBlend.SourceConstantAlpha = 255; + bfBlend.AlphaFormat = AC_SRC_ALPHA; + + if (!UpdateLayeredWindow (pRLWinPriv->hWnd, + NULL, NULL, &szWin, + pRLWinPriv->hdcShadow, &ptSrc, + 0, &bfBlend, ULW_ALPHA)) + { + 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 ("winWin32RootlessUpdateRegion - UpdateLayeredWindow failed: %s\n", + (LPSTR)lpMsgBuf); + LocalFree (lpMsgBuf); + } +#endif + UpdateWindow (pRLWinPriv->hWnd); +} + +void +winWin32RootlessDamageRects (RootlessFrameID wid, int nCount, const BoxRec *pRects, + int shift_x, int shift_y) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + const BoxRec *pEnd; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessDamageRects (%08x, %d, %08x, %d, %d)\n", + pRLWinPriv, nCount, pRects, shift_x, shift_y); +#endif + + for (pEnd = pRects + nCount; pRects < pEnd; pRects++) { + RECT rcDmg; + rcDmg.left = pRects->x1 + shift_x; + rcDmg.top = pRects->y1 + shift_y; + rcDmg.right = pRects->x2 + shift_x; + rcDmg.bottom = pRects->y2 + shift_y; + + InvalidateRect (pRLWinPriv->hWnd, &rcDmg, FALSE); + } +} + +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; +} + +void +winWin32RootlessCopyBytes (unsigned int width, unsigned int height, + const void *src, unsigned int srcRowBytes, + void *dst, unsigned int dstRowBytes) +{ +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessCopyBytes - Not implemented\n"); +#endif +} + +void +winWin32RootlessFillBytes (unsigned int width, unsigned int height, unsigned int value, + void *dst, unsigned int dstRowBytes) +{ +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessFillBytes - Not implemented\n"); +#endif +} + +int +winWin32RootlessCompositePixels (unsigned int width, unsigned int height, unsigned int function, + void *src[2], unsigned int srcRowBytes[2], + void *mask, unsigned int maskRowBytes, + void *dst[2], unsigned int dstRowBytes[2]) +{ +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWin32RootlessCompositePixels - Not implemented\n"); +#endif + return 0; +} + + +void +winWin32RootlessCopyWindow (RootlessFrameID wid, int nDstRects, const BoxRec *pDstRects, + int nDx, int nDy) +{ + Win32RootlessWindowPtr pRLWinPriv = (Win32RootlessWindowPtr) wid; + const BoxRec *pEnd; + RECT rcDmg; +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessCopyWindow (%08x, %d, %08x, %d, %d)\n", + pRLWinPriv, nDstRects, pDstRects, nDx, nDy); +#endif + + for (pEnd = pDstRects + nDstRects; pDstRects < pEnd; pDstRects++) + { + ErrorF ("BitBlt (%d, %d, %d, %d) (%d, %d)\n", + pDstRects->x1, pDstRects->y1, + pDstRects->x2 - pDstRects->x1, + pDstRects->y2 - pDstRects->y1, + pDstRects->x1 + nDx, + pDstRects->y1 + nDy); + + if (!BitBlt (pRLWinPriv->hdcShadow, + pDstRects->x1, pDstRects->y1, + pDstRects->x2 - pDstRects->x1, + pDstRects->y2 - pDstRects->y1, + pRLWinPriv->hdcShadow, + pDstRects->x1 + nDx, pDstRects->y1 + nDy, + SRCCOPY)) + { + ErrorF ("winWin32RootlessCopyWindow - BitBlt failed.\n"); + } + + rcDmg.left = pDstRects->x1; + rcDmg.top = pDstRects->y1; + rcDmg.right = pDstRects->x2; + rcDmg.bottom = pDstRects->y2; + + InvalidateRect (pRLWinPriv->hWnd, &rcDmg, FALSE); + } +#if CYGMULTIWINDOW_DEBUG | TRUE + ErrorF ("winWin32RootlessCopyWindow - done\n"); +#endif +} + +/* + * 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; + WINDOWPOS *pWinPos; + + /* 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; + } + + /* 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; + + /* + * 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; + + /* + * 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, + ps.rcPaint.left, ps.rcPaint.top, + ps.rcPaint.right - ps.rcPaint.left, + ps.rcPaint.bottom - ps.rcPaint.top, + pRLWinPriv->hdcShadow, + ps.rcPaint.left, ps.rcPaint.top, + 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; + + case WM_WINDOWPOSCHANGING: + /* Window manager does restacking */ + if (pRLWinPriv->fRestackingNow || pRLWinPriv->fXTop) break; + pWinPos = (LPWINDOWPOS)lParam; + pWinPos->flags |= SWP_NOZORDER; + break; + + default: + break; + } + + return DefWindowProc (hwnd, message, wParam, lParam); +} diff -rubN xwin-20031017-1340/winwin32rootlesscursor.c xwin/winwin32rootlesscursor.c --- xwin-20031017-1340/winwin32rootlesscursor.c Thu Jan 1 09:00:00 1970 +++ xwin/winwin32rootlesscursor.c Wed Oct 22 13:39:47 2003 @@ -0,0 +1,334 @@ +/* + * Look at hw/darwin/quartz/xpr/xprCursor.c + */ +#include "win.h" +#include "mipointrst.h" +#include "cursorstr.h" + + +typedef struct { + QueryBestSizeProcPtr QueryBestSize; + miPointerSpriteFuncPtr spriteFuncs; + HCURSOR hCursor; + Bool fCursorVisible; + int nCX; + int nCY; +} winCursorScreenRec, *winCursorScreenPtr; + +static int g_iWinCursorScreenIndex = -1; +static unsigned long g_ulWinCursorGeneration = 0; + +#define CURSOR_PRIV(pScreen) \ + ((winCursorScreenPtr)pScreen->devPrivates[g_iWinCursorScreenIndex].ptr) + +static unsigned char +reverse(unsigned char c) +{ + int i; + unsigned char ret = 0; + for (i = 0; i < 8; ++i) + { + ret |= ((c >> i)&1) << (7 - i); + } + return ret; +} +/* + * Convert X cursor to Windows cursor + * FIXME: Perhaps there are more smart code + */ +static HCURSOR +winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen) +{ + winCursorScreenPtr pScreenPriv = CURSOR_PRIV(pScreen); + HCURSOR hCursor = NULL; + unsigned char *pAnd; + unsigned char *pXor; + int nCX, nCY; + int nBytes; + int nBytesPerRow; + int i; + double dForeY; + double dBackY; + BOOL fReverse; + + /* We can use only White and Black, so calc brightness of color */ + dForeY = pCursor->foreRed*0.299 + pCursor->foreGreen*.587 + pCursor->foreBlue*.114; + dBackY = pCursor->backRed*0.299 + pCursor->backGreen*.587 + pCursor->backBlue*.114; + fReverse = dForeY < dBackY; + + if (pScreenPriv->nCX < pCursor->bits->width || pScreenPriv->nCY < pCursor->bits->height) + { + ErrorF ("winLoadCursor - Windows requires %dx%d cursor\n" + "\tbut X requires %dx%d\n", + pScreenPriv->nCX, pScreenPriv->nCY, + pCursor->bits->width, pCursor->bits->height); + } + + /* round up to 8 pixel boundary so we can convert whole bytes */ + nBytes = (pScreenPriv->nCX + 7) / 8 * pScreenPriv->nCY; + +#define MIN(x,y) ((xnCX, pCursor->bits->width); + nCY = MIN(pScreenPriv->nCY, pCursor->bits->height); +#undef MIN +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winLoadCursor - Windows requires %dx%d cursor use %d bytes\n", + pScreenPriv->nCX, pScreenPriv->nCY, nBytes); +#endif + + pAnd = malloc (nBytes); + memset (pAnd, 0xFF, nBytes); + pXor = malloc (nBytes); + memset (pXor, 0x00, nBytes); + + if (pCursor->bits->emptyMask) + { + int y; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winLoadCursor - Empty Mask\n"); +#endif + for (y = 0; y < nCY; ++y) + { + int x; + int xmax = (nCX + 7)/8; + for (x = 0; x < xmax; ++x) + { + int nWinPix = (pScreenPriv->nCX + 7) / 8 * y + x; + int nXPix = (pCursor->bits->width + 7) / 8 * y + x; + pAnd[nWinPix] = 0; + if (fReverse) + { + pXor[nWinPix] = reverse (~pCursor->bits->source[nXPix]); + } + else + { + pXor[nWinPix] = reverse (pCursor->bits->source[nXPix]); + } + } + } + } + else + { + int y; + for (y = 0; y < nCY; ++y) + { + int x; + int xmax = (nCX + 7)/8; + for (x = 0; x < xmax; ++x) + { + int nWinPix = (pScreenPriv->nCX + 7) / 8 * y + x; + int nXPix = BitmapBytePad(pCursor->bits->width) * y + x; + + pAnd[nWinPix] = reverse (~pCursor->bits->mask[nXPix]); + if (fReverse) + { + pXor[nWinPix] = reverse (~pCursor->bits->source[nXPix] & pCursor->bits->mask[nXPix]); + } + else + { + pXor[nWinPix] = reverse (pCursor->bits->source[nXPix] & pCursor->bits->mask[nXPix]); + } + } + } + } + + hCursor = CreateCursor (g_hInstance, + pCursor->bits->xhot, pCursor->bits->yhot, + pScreenPriv->nCX, pScreenPriv->nCY, + pAnd, pXor); + + free (pAnd); + free (pXor); + + if (hCursor == NULL) + { + 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 ("winLoadCursor - CreateCursor failed\n" + "\t%s\n", (LPSTR)lpMsgBuf); + LocalFree (lpMsgBuf); + } + return hCursor; +} + +/* +=========================================================================== + + Pointer sprite functions + +=========================================================================== +*/ + +/* + * winWin32RootlessRealizeCursor + * Convert the X cursor representation to native format if possible. + */ +static Bool +winWin32RootlessRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor) +{ + if(pCursor == NULL || pCursor->bits == NULL) + return FALSE; + + /* FIXME: cache ARGB8888 representation? */ + + return TRUE; +} + + +/* + * winWin32RootlessUnrealizeCursor + * Free the storage space associated with a realized cursor. + */ +static Bool +winWin32RootlessUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) +{ + return TRUE; +} + + +/* + * winWin32RootlessSetCursor + * Set the cursor sprite and position. + */ +static void +winWin32RootlessSetCursor (ScreenPtr pScreen, CursorPtr pCursor, int x, int y) +{ + winCursorScreenPtr pScreenPriv = CURSOR_PRIV(pScreen); + + if (pCursor == NULL) + { + if (pScreenPriv->fCursorVisible) + { + ShowCursor (FALSE); + pScreenPriv->fCursorVisible = FALSE; + } + } + else + { + if (pScreenPriv->hCursor) + { + SetCursor (NULL); + DestroyCursor (pScreenPriv->hCursor); + pScreenPriv->hCursor = NULL; + } + pScreenPriv->hCursor = winLoadCursor (pScreen, pCursor, pScreen->myNum); + SetCursor (pScreenPriv->hCursor); + + if (!pScreenPriv->fCursorVisible) + { + ShowCursor (TRUE); + pScreenPriv->fCursorVisible = TRUE; + } + } +} + + +/* + * winWin32RootlessReallySetCursor + * Not needed for xpr. Cursor is set from the X server thread. + */ +void +winWin32RootlessReallySetCursor () +{ +} + + +/* + * QuartzMoveCursor + * Move the cursor. This is a noop for us. + */ +static void +winWin32RootlessMoveCursor (ScreenPtr pScreen, int x, int y) +{ +} + + +static miPointerSpriteFuncRec g_winSpriteFuncsRec = { + winWin32RootlessRealizeCursor, + winWin32RootlessUnrealizeCursor, + winWin32RootlessSetCursor, + winWin32RootlessMoveCursor +}; + + +/* +=========================================================================== + + Other screen functions + +=========================================================================== +*/ + +/* + * winWin32RootlessCursorQueryBestSize + * Handle queries for best cursor size + */ +static void +winWin32RootlessCursorQueryBestSize (int class, unsigned short *width, + unsigned short *height, ScreenPtr pScreen) +{ + winCursorScreenPtr pScreenPriv = CURSOR_PRIV(pScreen); + + if (class == CursorShape) + { + *width = pScreenPriv->nCX; + *height = pScreenPriv->nCY; + } + else + { + (*pScreenPriv->QueryBestSize)(class, width, height, pScreen); + } +} + +/* + * winWin32RootlessInitCursor + * Initialize cursor support + */ +Bool +winWin32RootlessInitCursor (ScreenPtr pScreen) +{ + winCursorScreenPtr pScreenPriv; + miPointerScreenPtr pPointPriv; + + /* allocate private storage for this screen's cursor info */ + if (g_ulWinCursorGeneration != g_ulServerGeneration) + { + if ((g_iWinCursorScreenIndex = AllocateScreenPrivateIndex()) < 0) + return FALSE; + + g_ulWinCursorGeneration = g_ulServerGeneration; + } + + pScreenPriv = xcalloc(1, sizeof(winCursorScreenRec)); + if (pScreenPriv == NULL) + return FALSE; + + CURSOR_PRIV(pScreen) = pScreenPriv; + + /* override some screen procedures */ + pScreenPriv->QueryBestSize = pScreen->QueryBestSize; + pScreen->QueryBestSize = winWin32RootlessCursorQueryBestSize; + + pPointPriv = (miPointerScreenPtr) pScreen->devPrivates[miPointerScreenIndex].ptr; + + pScreenPriv->spriteFuncs = pPointPriv->spriteFuncs; + pPointPriv->spriteFuncs = &g_winSpriteFuncsRec; + + pScreenPriv->hCursor = NULL; + pScreenPriv->fCursorVisible = TRUE; + + pScreenPriv->nCX = GetSystemMetrics (SM_CXCURSOR); + pScreenPriv->nCY = GetSystemMetrics (SM_CYCURSOR); + + return TRUE; +} diff -rubN xwin-20031017-1340/winwindow.c xwin/winwindow.c --- xwin-20031017-1340/winwindow.c Thu Sep 18 03:21:04 2003 +++ xwin/winwindow.c Wed Oct 22 13:56:04 2003 @@ -32,23 +32,6 @@ #include "win.h" -/* - * Prototypes for local functions - */ - -static int -winAddRgn (WindowPtr pWindow, pointer data); - -static -void -winUpdateRgnPRootless (WindowPtr pWindow); - -#ifdef SHAPE -static -void -winReshapePRootless (WindowPtr pWin); -#endif - /* See Porting Layer Definition - p. 37 */ /* See mfb/mfbwindow.c - mfbCreateWindow() */ @@ -212,330 +195,3 @@ return TRUE; } - - -/* See Porting Layer Definition - p. 37 */ -/* See mfb/mfbwindow.c - mfbCreateWindow() */ - -Bool -winCreateWindowPRootless (WindowPtr pWin) -{ - Bool fResult = FALSE; - winWindowPriv(pWin); - -#if CYGDEBUG - ErrorF ("winCreateWindowPRootless ()\n"); -#endif - - fResult = winGetScreenPriv(pWin->drawable.pScreen)->CreateWindow(pWin); - - pWinPriv->hRgn = NULL; - - return fResult; -} - - -/* See Porting Layer Definition - p. 37 */ -/* See mfb/mfbwindow.c - mfbDestroyWindow() */ - -Bool -winDestroyWindowPRootless (WindowPtr pWin) -{ - Bool fResult = FALSE; - winWindowPriv(pWin); - -#if CYGDEBUG - ErrorF ("winDestroyWindowPRootless ()\n"); -#endif - - fResult = winGetScreenPriv(pWin->drawable.pScreen)->DestroyWindow(pWin); - - if (pWinPriv->hRgn != NULL) - { - DeleteObject(pWinPriv->hRgn); - pWinPriv->hRgn = NULL; - } - - winUpdateRgnPRootless (pWin); - - return fResult; -} - - -/* See Porting Layer Definition - p. 37 */ -/* See mfb/mfbwindow.c - mfbPositionWindow() */ - -Bool -winPositionWindowPRootless (WindowPtr pWin, int x, int y) -{ - Bool fResult = FALSE; - -#if CYGDEBUG - ErrorF ("winPositionWindowPRootless ()\n"); -#endif - - fResult = winGetScreenPriv(pWin->drawable.pScreen)->PositionWindow(pWin, x, y); - - winUpdateRgnPRootless (pWin); - - return fResult; -} - - -/* See Porting Layer Definition - p. 37 */ -/* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */ - -Bool -winChangeWindowAttributesPRootless (WindowPtr pWin, unsigned long mask) -{ - Bool fResult = FALSE; - -#if CYGDEBUG - ErrorF ("winChangeWindowAttributesPRootless ()\n"); -#endif - - fResult = winGetScreenPriv(pWin->drawable.pScreen)->ChangeWindowAttributes(pWin, mask); - - winUpdateRgnPRootless (pWin); - - return fResult; -} - - -/* See Porting Layer Definition - p. 37 - * Also referred to as UnrealizeWindow - */ - -Bool -winUnmapWindowPRootless (WindowPtr pWin) -{ - Bool fResult = FALSE; - winWindowPriv(pWin); - -#if CYGDEBUG - ErrorF ("winUnmapWindowPRootless ()\n"); -#endif - - fResult = winGetScreenPriv(pWin->drawable.pScreen)->UnrealizeWindow(pWin); - - if (pWinPriv->hRgn != NULL) - { - DeleteObject(pWinPriv->hRgn); - pWinPriv->hRgn = NULL; - } - - winUpdateRgnPRootless (pWin); - - return fResult; -} - - -/* See Porting Layer Definition - p. 37 - * Also referred to as RealizeWindow - */ - -Bool -winMapWindowPRootless (WindowPtr pWin) -{ - Bool fResult = FALSE; - -#if CYGDEBUG - ErrorF ("winMapWindowPRootless ()\n"); -#endif - - fResult = winGetScreenPriv(pWin->drawable.pScreen)->RealizeWindow(pWin); - - winReshapePRootless (pWin); - - winUpdateRgnPRootless (pWin); - - return fResult; -} - - -#ifdef SHAPE -void -winSetShapePRootless (WindowPtr pWin) -{ -#if CYGDEBUG - ErrorF ("winSetShapePRootless ()\n"); -#endif - - winGetScreenPriv(pWin->drawable.pScreen)->SetShape(pWin); - - winReshapePRootless (pWin); - winUpdateRgnPRootless (pWin); - - return; -} -#endif - - -/* - * Local function for adding a region to the Windows window region - */ - -static -int -winAddRgn (WindowPtr pWin, pointer data) -{ - int iX, iY, iWidth, iHeight, iBorder; - HRGN hRgn = *(HRGN*)data; - HRGN hRgnWin; - winWindowPriv(pWin); - - /* If pWin is not Root */ - if (pWin->parent != NULL) - { -#if CYGDEBUG - ErrorF ("winAddRgn ()\n"); -#endif - if (pWin->mapped) - { - iBorder = wBorderWidth (pWin); - - iX = pWin->drawable.x - iBorder; - iY = pWin->drawable.y - iBorder; - - iWidth = pWin->drawable.width + iBorder * 2; - iHeight = pWin->drawable.height + iBorder * 2; - - hRgnWin = CreateRectRgn (0, 0, iWidth, iHeight); - - if (hRgnWin == NULL) - { - ErrorF ("winAddRgn - CreateRectRgn () failed\n"); - ErrorF (" Rect %d %d %d %d\n", - iX, iY, iX + iWidth, iY + iHeight); - } - - if (pWinPriv->hRgn) - { - if (CombineRgn (hRgnWin, hRgnWin, pWinPriv->hRgn, RGN_AND) - == ERROR) - { - ErrorF ("winAddRgn - CombineRgn () failed\n"); - } - } - - OffsetRgn (hRgnWin, iX, iY); - - if (CombineRgn (hRgn, hRgn, hRgnWin, RGN_OR) == ERROR) - { - ErrorF ("winAddRgn - CombineRgn () failed\n"); - } - - DeleteObject (hRgnWin); - } - return WT_DONTWALKCHILDREN; - } - else - { - return WT_WALKCHILDREN; - } -} - - -/* - * Local function to update the Windows window's region - */ - -static -void -winUpdateRgnPRootless (WindowPtr pWin) -{ - HRGN hRgn = CreateRectRgn (0, 0, 0, 0); - - if (hRgn != NULL) - { - WalkTree (pWin->drawable.pScreen, winAddRgn, &hRgn); - SetWindowRgn (winGetScreenPriv(pWin->drawable.pScreen)->hwndScreen, - hRgn, TRUE); - } - else - { - ErrorF ("winUpdateRgnPRootless - CreateRectRgn failed.\n"); - } -} - - -#ifdef SHAPE -static -void -winReshapePRootless (WindowPtr pWin) -{ - int nRects; -#if 0 - ScreenPtr pScreen = pWin->drawable.pScreen; -#endif - RegionRec rrNewShape; - BoxPtr pShape, pRects, pEnd; - HRGN hRgn, hRgnRect; - winWindowPriv(pWin); - -#if CYGDEBUG - ErrorF ("winReshapePRootless ()\n"); -#endif - - /* Bail if the window is the root window */ - if (pWin->parent == NULL) - return; - - /* Bail if the window is not top level */ - if (pWin->parent->parent != NULL) - return; - - /* Free any existing window region stored in the window privates */ - if (pWinPriv->hRgn != NULL) - { - DeleteObject (pWinPriv->hRgn); - pWinPriv->hRgn = NULL; - } - - /* Bail if the window has no bounding region defined */ - if (!wBoundingShape (pWin)) - return; - - REGION_INIT(pScreen, &rrNewShape, NullBox, 0); - REGION_COPY(pScreen, &rrNewShape, wBoundingShape(pWin)); - REGION_TRANSLATE(pScreen, &rrNewShape, pWin->borderWidth, - pWin->borderWidth); - - nRects = REGION_NUM_RECTS(&rrNewShape); - pShape = REGION_RECTS(&rrNewShape); - - if (nRects > 0) - { - /* Create initial empty Windows region */ - hRgn = CreateRectRgn (0, 0, 0, 0); - - /* Loop through all rectangles in the X region */ - for (pRects = pShape, pEnd = pShape + nRects; pRects < pEnd; pRects++) - { - /* Create a Windows region for the X rectangle */ - hRgnRect = CreateRectRgn (pRects->x1, pRects->y1, - pRects->x2, pRects->y2); - if (hRgnRect == NULL) - { - ErrorF("winReshapePRootless - CreateRectRgn() failed\n"); - } - - /* Merge the Windows region with the accumulated region */ - if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR) - { - ErrorF("winReshapePRootless - CombineRgn() failed\n"); - } - - /* Delete the temporary Windows region */ - DeleteObject (hRgnRect); - } - - /* Save a handle to the composite region in the window privates */ - pWinPriv->hRgn = hRgn; - } - - REGION_UNINIT(pScreen, &rrNewShape); - - return; -} -#endif