diff options
86 files changed, 13891 insertions, 4113 deletions
diff --git a/hw/xwin/ChangeLog b/hw/xwin/ChangeLog new file mode 100644 index 000000000..8695f6c0f --- /dev/null +++ b/hw/xwin/ChangeLog @@ -0,0 +1,64 @@ +2004-05-27 Alexander Gottwald <ago@freedesktop.org> + + * winpriv.c: Create win32 window if not already created + * winmultiwindowwindow.c: Export winCreateWindowWindow + +2004-05-27 Alexander Gottwald <ago@freedesktop.org> + + * win.h: Allow CYGDEBUG to defined in the Makefile + * winwindow.h: Allow CYGWINDOWING_DEBUG to defined in the Makefile + +2004-05-19 Alexander Gottwald <ago@freedesktop.org> + + * winmultiwindowicons.c (winInitGlobalIcons): Load the small default + icon too + * winprefs.h, winprefs.c (winOverrideDefaultIcon): Takes the iconsize + as parameter + +2004-05-19 Alexander Gottwald <ago@freedesktop.org> + + * win.h, winmultiwindowicons.c (winXIconToHICON): Takes iconsize + as parameter + * winglobals.c, winmultiwindowicons.c: Rename g_hiconX to g_hIconX. + Added new variable g_hSmallIconX for 16x16 icon. + * winwindow.h, winmultiwindowicons.c (winInitGlobalIcons): Inits the + global g_hIconX handles. + * winwindow.h, winmultiwindowicons.c (winDestroyIcon): Free the icon + without messing with the global icon handle. + * winmultiwindowicons.c (winSelectIcons): Generate a custom icon from + window settigns or set them to globals. + * winmultiwindowshape.c, winmultiwindowwindow.c, winwin32rootless.c, + winwin32rootlesswindow.c, winwin32rootlesswndproc.c: Remove + declaration of g_hiconX; + * winmultiwindowwindow.c (winCreateWindowsWindow), + winwin32rootless.c (winMWExtWMCreateFrame): Use winSelectIcons + to get the window icons. Set the small icon too. + * winmultiwindowwindow.c (winDestroyWindowsWindow), + winmultiwindowicons.c (winUpdateIcon), + winprefs.c (ReloadEnumWindowsProc), + winwin32rootlesswindow.c (winMWExtWMUpdateIcon), + winwin32rootless.c (winMWExtWMDestroyFrame): Use winDestroyIcon + to free the icon without destroying the global icon. + +2004-05-17 Alexander Gottwald <ago@freedesktop.org> + + * windialogs.c (winExitDlgProc, winAboutDlgProc), + winmultiwindowwndproc.c (winTopLevelWindowProc), + winwndproc.c (winWindowProc): Check if g_fSoftwareCursor is set + before calling ShowCursor. + +2004-05-09 Dan Wilks <Dan_Wilks@intuit.com> + + * winclipboard.h: Add extern prototypes for winDebug, winErrorFVerb + copied from winmsg.h. + * winclipboardinit.c (winFixClipboardChain): Post rather than send the + reinit message to the clipboard window. Sending the message caused, + or possibly just exacerbated an existing, race condition that would + cause the X server to hang when coming back from a remote desktop + session. + * winclipboardwndproc.c (winProcessXEventsTimeout): switch to new + logging api's. + * winclipboardwindproc.c (winClipboardWindowProc): switch to new + logging api's. Add some additional debug logging. Make best effort + to prevent our window appearing twice in the clipboard chain. Also + detect loops when they occur and try to behave in a reasonable way. diff --git a/hw/xwin/InitInput.c b/hw/xwin/InitInput.c index 92fb5c3e5..6219fa2b9 100644 --- a/hw/xwin/InitInput.c +++ b/hw/xwin/InitInput.c @@ -29,9 +29,40 @@ /* $XFree86: xc/programs/Xserver/hw/xwin/InitInput.c,v 1.11 2002/07/05 09:19:25 alanh Exp $ */ #include "win.h" -#include "../../Xext/xf86miscproc.h" +#ifdef XWIN_CLIPBOARD +# include "../../Xext/xf86miscproc.h" +#endif +#include "dixstruct.h" + + +/* + * Local function prototypes + */ + +#ifdef XWIN_CLIPBOARD +DISPATCH_PROC(winProcEstablishConnection); +DISPATCH_PROC(winProcQueryTree); +DISPATCH_PROC(winProcSetSelectionOwner); +#endif + + +/* + * Local global declarations + */ + +CARD32 g_c32LastInputEventTime = 0; + + +/* + * References to external symbols + */ -CARD32 g_c32LastInputEventTime = 0; +extern int g_fdMessageQueue; +extern Bool g_fXdmcpEnabled; +#ifdef XWIN_CLIPBOARD +extern winDispatchProcPtr winProcEstablishConnectionOrig; +extern winDispatchProcPtr winProcQueryTreeOrig; +#endif /* Called from dix/devices.c */ @@ -87,7 +118,24 @@ InitInput (int argc, char *argv[]) DeviceIntPtr pMouse, pKeyboard; #if CYGDEBUG - ErrorF ("InitInput\n"); + winDebug ("InitInput\n"); +#endif + +#ifdef XWIN_CLIPBOARD + /* + * Wrap some functions at every generation of the server. + */ + if (InitialVector[2] != winProcEstablishConnection) + { + winProcEstablishConnectionOrig = InitialVector[2]; + InitialVector[2] = winProcEstablishConnection; + } + if (g_fXdmcpEnabled + && ProcVector[X_QueryTree] != winProcQueryTree) + { + winProcQueryTreeOrig = ProcVector[X_QueryTree]; + ProcVector[X_QueryTree] = winProcQueryTree; + } #endif pMouse = AddInputDevice (winMouseProc, TRUE); @@ -118,36 +166,8 @@ InitInput (int argc, char *argv[]) AddEnabledDevice (g_fdMessageQueue); } -#if 0 - { - MiscExtReturn ret; - pointer kbd; - -#if 0 - if ((kbd = MiscExtCreateStruct(MISC_KEYBOARD)) == (pointer) 0) - return BadAlloc; -#else - kbd = MiscExtCreateStruct (MISC_KEYBOARD); -#endif - - MiscExtSetKbdValue(kbd, MISC_KBD_TYPE, 0); - MiscExtSetKbdValue(kbd, MISC_KBD_RATE, 0); - MiscExtSetKbdValue(kbd, MISC_KBD_DELAY, 0); - MiscExtSetKbdValue(kbd, MISC_KBD_SERVNUMLOCK, 0); - - switch ((ret = MiscExtApply (kbd, MISC_KEYBOARD))) - { - case MISC_RET_SUCCESS: break; - case MISC_RET_BADVAL: - case MISC_RET_BADKBDTYPE: - default: - ErrorF ("Unexpected return from MiscExtApply(KEYBOARD) = %d\n", ret); - } - } -#endif - #if CYGDEBUG - ErrorF ("InitInput - returning\n"); + winDebug ("InitInput - returning\n"); #endif } diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c index 68910be1a..c8f92d25a 100644 --- a/hw/xwin/InitOutput.c +++ b/hw/xwin/InitOutput.c @@ -29,54 +29,79 @@ from The Open Group. /* $XFree86: xc/programs/Xserver/hw/xwin/InitOutput.c,v 1.34 2003/10/02 13:30:09 eich Exp $ */ #include "win.h" +#include "winmsg.h" +#ifdef XWIN_XF86CONFIG #include "winconfig.h" +#endif #include "winprefs.h" +#include "X11/Xlocale.h" + /* - * General global variables + * References to external symbols */ -int g_iNumScreens = 0; -winScreenInfo g_ScreenInfo[MAXSCREENS]; -int g_iLastScreen = -1; -int g_fdMessageQueue = WIN_FD_INVALID; -int g_iScreenPrivateIndex = -1; -int g_iCmapPrivateIndex = -1; -int g_iGCPrivateIndex = -1; -int g_iPixmapPrivateIndex = -1; -int g_iWindowPrivateIndex = -1; -unsigned long g_ulServerGeneration = 0; -Bool g_fInitializedDefaultScreens = FALSE; -DWORD g_dwEnginesSupported = 0; -HINSTANCE g_hInstance = 0; -HWND g_hDlgDepthChange = NULL; -HWND g_hDlgExit = NULL; -Bool g_fCalledSetLocale = FALSE; -Bool g_fCalledXInitThreads = FALSE; -int g_iLogVerbose = 4; -char * g_pszLogFile = WIN_LOG_FNAME; -Bool g_fLogInited = FALSE; -const char * g_pszQueryHost = NULL; - +extern int g_iNumScreens; +extern winScreenInfo g_ScreenInfo[]; +extern int g_iLastScreen; +extern char * g_pszCommandLine; +extern Bool g_fUseMsg; + +extern char * g_pszLogFile; +extern int g_iLogVerbose; +Bool g_fLogInited; + +extern Bool g_fXdmcpEnabled; +extern int g_fdMessageQueue; +extern const char * g_pszQueryHost; +extern HINSTANCE g_hInstance; + +#ifdef XWIN_CLIPBOARD +extern Bool g_fUnicodeClipboard; +extern Bool g_fClipboardLaunched; +extern Bool g_fClipboardStarted; +extern pthread_t g_ptClipboardProc; +extern HWND g_hwndClipboard; +extern Bool g_fClipboard; +#endif +extern HMODULE g_hmodDirectDraw; +extern FARPROC g_fpDirectDrawCreate; +extern FARPROC g_fpDirectDrawCreateClipper; + +extern HMODULE g_hmodCommonControls; +extern FARPROC g_fpTrackMouseEvent; +extern Bool g_fNoHelpMessageBox; + + /* - * Global variables for dynamically loaded libraries and - * their function pointers + * Function prototypes */ -HMODULE g_hmodDirectDraw = NULL; -FARPROC g_fpDirectDrawCreate = NULL; -FARPROC g_fpDirectDrawCreateClipper = NULL; +#ifdef XWIN_CLIPBOARD +static void +winClipboardShutdown (void); +#endif + +#if defined(DDXOSVERRORF) +void +OsVendorVErrorF (const char *pszFormat, va_list va_args); +#endif -HMODULE g_hmodCommonControls = NULL; -FARPROC g_fpTrackMouseEvent = (FARPROC) (void (*)())NoopDDA; +void +winInitializeDefaultScreens (void); +static Bool +winCheckDisplayNumber (void); -/* Function prototypes */ +void +winLogCommandLine (int argc, char *argv[]); -#ifdef DDXOSVERRORF -void OsVendorVErrorF (const char *pszFormat, va_list va_args); -#endif +void +winLogVersionInfo (void); + +Bool +winValidateArgs (void); /* @@ -106,86 +131,80 @@ static PixmapFormatRec g_PixmapFormats[] = { const int NUMFORMATS = sizeof (g_PixmapFormats) / sizeof (g_PixmapFormats[0]); - -void -winInitializeDefaultScreens (void) +#ifdef XWIN_CLIPBOARD +static void +winClipboardShutdown (void) { - int i; - DWORD dwWidth, dwHeight; - - /* Bail out early if default screens have already been initialized */ - if (g_fInitializedDefaultScreens) - return; - - /* Zero the memory used for storing the screen info */ - ZeroMemory (g_ScreenInfo, MAXSCREENS * sizeof (winScreenInfo)); + /* Close down clipboard resources */ + if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) + { + /* Synchronously destroy the clipboard window */ + if (g_hwndClipboard != NULL) + { + SendMessage (g_hwndClipboard, WM_DESTROY, 0, 0); + /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */ + } + else + return; + + /* Wait for the clipboard thread to exit */ + if (g_ptClipboardProc) + { + pthread_join (g_ptClipboardProc, NULL); + g_ptClipboardProc = 0; + } + else + return; - /* Get default width and height */ - /* - * NOTE: These defaults will cause the window to cover only - * the primary monitor in the case that we have multiple monitors. - */ - dwWidth = GetSystemMetrics (SM_CXSCREEN); - dwHeight = GetSystemMetrics (SM_CYSCREEN); + g_fClipboardLaunched = FALSE; + g_fClipboardStarted = FALSE; - ErrorF ("winInitializeDefaultScreens - w %d h %d\n", dwWidth, dwHeight); + winDebug ("winClipboardShutdown - Clipboard thread has exited.\n"); + } +} +#endif - /* Set a default DPI, if no parameter was passed */ - if (monitorResolution == 0) - monitorResolution = WIN_DEFAULT_DPI; - for (i = 0; i < MAXSCREENS; ++i) - { - g_ScreenInfo[i].dwScreen = i; - g_ScreenInfo[i].dwWidth = dwWidth; - g_ScreenInfo[i].dwHeight = dwHeight; - g_ScreenInfo[i].dwUserWidth = dwWidth; - g_ScreenInfo[i].dwUserHeight = dwHeight; - g_ScreenInfo[i].fUserGaveHeightAndWidth - = WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH; - g_ScreenInfo[i].dwBPP = WIN_DEFAULT_BPP; - g_ScreenInfo[i].dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES; - g_ScreenInfo[i].fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO; - g_ScreenInfo[i].dwRefreshRate = WIN_DEFAULT_REFRESH; - g_ScreenInfo[i].pfb = NULL; - g_ScreenInfo[i].fFullScreen = FALSE; - g_ScreenInfo[i].fDecoration = TRUE; - g_ScreenInfo[i].fRootless = FALSE; - g_ScreenInfo[i].fMultiWindow = FALSE; - g_ScreenInfo[i].fMultipleMonitors = FALSE; - g_ScreenInfo[i].fClipboard = FALSE; - g_ScreenInfo[i].fLessPointer = FALSE; - g_ScreenInfo[i].fScrollbars = FALSE; - g_ScreenInfo[i].fNoTrayIcon = FALSE; - g_ScreenInfo[i].iE3BTimeout = WIN_E3B_OFF; - g_ScreenInfo[i].dwWidth_mm = (dwWidth / WIN_DEFAULT_DPI) - * 25.4; - g_ScreenInfo[i].dwHeight_mm = (dwHeight / WIN_DEFAULT_DPI) - * 25.4; - g_ScreenInfo[i].fUseWinKillKey = WIN_DEFAULT_WIN_KILL; - g_ScreenInfo[i].fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL; - g_ScreenInfo[i].fIgnoreInput = FALSE; - g_ScreenInfo[i].fExplicitScreen = FALSE; - } +#if defined(DDXBEFORERESET) +/* + * Called right before KillAllClients when the server is going to reset, + * allows us to shutdown our seperate threads cleanly. + */ - /* Signal that the default screens have been initialized */ - g_fInitializedDefaultScreens = TRUE; +void +ddxBeforeReset (void) +{ + winDebug ("ddxBeforeReset - Hello\n"); - ErrorF ("winInitializeDefaultScreens - Returning\n"); +#ifdef XWIN_CLIPBOARD + winClipboardShutdown (); +#endif } +#endif /* See Porting Layer Definition - p. 57 */ void -ddxGiveUp() +ddxGiveUp (void) { + int i; + #if CYGDEBUG - ErrorF ("ddxGiveUp\n"); + winDebug ("ddxGiveUp\n"); #endif + /* Perform per-screen deinitialization */ + for (i = 0; i < g_iNumScreens; ++i) + { + /* Delete the tray icon */ + if (!g_ScreenInfo[i].fNoTrayIcon && g_ScreenInfo[i].pScreen) + winDeleteNotifyIcon (winGetScreenPriv (g_ScreenInfo[i].pScreen)); + } + +#ifdef XWIN_MULTIWINDOW /* Notify the worker threads we're exiting */ - winDeinitClipboard (); winDeinitMultiWindowWM (); +#endif /* Close our handle to our message queue */ if (g_fdMessageQueue != WIN_FD_INVALID) @@ -198,10 +217,10 @@ ddxGiveUp() } if (!g_fLogInited) { - LogInit(g_pszLogFile, NULL); + LogInit (g_pszLogFile, NULL); g_fLogInited = TRUE; } - LogClose(); + LogClose (); /* * At this point we aren't creating any new screens, so @@ -220,9 +239,19 @@ ddxGiveUp() { FreeLibrary (g_hmodCommonControls); g_hmodCommonControls = NULL; - g_fpTrackMouseEvent = (FARPROC) (void (*)())NoopDDA; + g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; } + /* Free concatenated command line */ + if (g_pszCommandLine) + { + free (g_pszCommandLine); + g_pszCommandLine = NULL; + } + + /* Remove our keyboard hook if it is installed */ + winRemoveKeyboardHookLL (); + /* Tell Windows that we want to end the app */ PostQuitMessage (0); } @@ -233,7 +262,7 @@ void AbortDDX (void) { #if CYGDEBUG - ErrorF ("AbortDDX\n"); + winDebug ("AbortDDX\n"); #endif ddxGiveUp (); } @@ -242,22 +271,35 @@ AbortDDX (void) void OsVendorInit (void) { + /* Re-initialize global variables on server reset */ + winInitializeGlobals (); + #ifdef DDXOSVERRORF if (!OsVendorVErrorFProc) OsVendorVErrorFProc = OsVendorVErrorF; #endif if (!g_fLogInited) { - LogInit(g_pszLogFile, NULL); + /* keep this order. If LogInit fails it calls Abort which then calls + * ddxGiveUp where LogInit is called again and creates an infinite + * recursion. If we set g_fLogInited to TRUE before the init we + * avoid the second call + */ g_fLogInited = TRUE; + LogInit (g_pszLogFile, NULL); } - LogSetParameter(XLOG_FLUSH, 1); - LogSetParameter(XLOG_VERBOSITY, g_iLogVerbose); + LogSetParameter (XLOG_FLUSH, 1); + LogSetParameter (XLOG_VERBOSITY, g_iLogVerbose); + LogSetParameter (XLOG_FILE_VERBOSITY, 1); + + /* Log the version information */ + if (serverGeneration == 1) + winLogVersionInfo (); /* Add a default screen if no screens were specified */ if (g_iNumScreens == 0) { - ErrorF ("OsVendorInit - Creating bogus screen 0\n"); + winDebug ("OsVendorInit - Creating bogus screen 0\n"); /* * We need to initialize default screens if no arguments @@ -280,9 +322,8 @@ OsVendorInit (void) } -/* See Porting Layer Definition - p. 57 */ void -ddxUseMsg (void) +winUseMsg (void) { ErrorF ("-depth bits_per_pixel\n" "\tSpecify an optional bitdepth to use in fullscreen mode\n" @@ -297,7 +338,10 @@ ddxUseMsg (void) "\t\t1 - Shadow GDI\n" "\t\t2 - Shadow DirectDraw\n" "\t\t4 - Shadow DirectDraw4 Non-Locking\n" - "\t\t16 - Native GDI - experimental\n"); +#ifdef XWIN_NATIVEGDI + "\t\t16 - Native GDI - experimental\n" +#endif + ); ErrorF ("-fullscreen\n" "\tRun the server in fullscreen mode.\n"); @@ -312,25 +356,38 @@ ddxUseMsg (void) ErrorF ("-lesspointer\n" "\tHide the windows mouse pointer when it is over an inactive\n" - "\tX window. This prevents ghost cursors appearing where\n" + "\tCygwin/X window. This prevents ghost cursors appearing where\n" "\tthe Windows cursor is drawn overtop of the X cursor\n"); ErrorF ("-nodecoration\n" "\tDo not draw a window border, title bar, etc. Windowed\n" "\tmode only.\n"); +#ifdef XWIN_MULTIWINDOWEXTWM + ErrorF ("-mwextwm\n" + "\tRun the server in multi-window external window manager mode.\n"); +#endif + ErrorF ("-rootless\n" - "\tEXPERIMENTAL: Run the server in pseudo-rootless mode.\n"); + "\tRun the server in rootless mode.\n"); +#ifdef XWIN_MULTIWINDOW ErrorF ("-multiwindow\n" - "\tEXPERIMENTAL: Run the server in multi-window mode.\n"); + "\tRun the server in multi-window mode.\n"); +#endif ErrorF ("-multiplemonitors\n" "\tEXPERIMENTAL: Use the entire virtual screen if multiple\n" "\tmonitors are present.\n"); +#ifdef XWIN_CLIPBOARD ErrorF ("-clipboard\n" - "\tEXPERIMENTAL: Run the clipboard integration module.\n"); + "\tRun the clipboard integration module.\n" + "\tDo not use at the same time as 'xwinclip'.\n"); + + ErrorF ("-nounicodeclipboard\n" + "\tDo not use Unicode clipboard even if NT-based platform.\n"); +#endif ErrorF ("-scrollbars\n" "\tIn windowed mode, allow screens bigger than the Windows desktop.\n" @@ -348,12 +405,14 @@ ddxUseMsg (void) "\tthe updated region when num_boxes, or more, are in the\n" "\tupdated region. Currently supported only by `-engine 1'.\n"); +#ifdef XWIN_EMULATEPSEUDO ErrorF ("-emulatepseudo\n" "\tCreate a depth 8 PseudoColor visual when running in\n" "\tdepths 15, 16, 24, or 32, collectively known as TrueColor\n" "\tdepths. The PseudoColor visual does not have correct colors,\n" "\tand it may crash, but it at least allows you to run your\n" "\tapplication in TrueColor modes.\n"); +#endif ErrorF ("-[no]unixkill\n" "\tCtrl+Alt+Backspace exits the X Server.\n"); @@ -361,893 +420,81 @@ ddxUseMsg (void) ErrorF ("-[no]winkill\n" "\tAlt+F4 exits the X Server.\n"); +#ifdef XWIN_XF86CONFIG ErrorF ("-config\n" "\tSpecify a configuration file.\n"); ErrorF ("-keyboard\n" "\tSpecify a keyboard device from the configuration file.\n"); -} - - -/* See Porting Layer Definition - p. 57 */ -/* - * INPUT - * argv: pointer to an array of null-terminated strings, one for - * each token in the X Server command line; the first token - * is 'XWin.exe', or similar. - * argc: a count of the number of tokens stored in argv. - * i: a zero-based index into argv indicating the current token being - * processed. - * - * OUTPUT - * return: return the number of tokens processed correctly. - * - * NOTE - * When looking for n tokens, check that i + n is less than argc. Or, - * you may check if i is greater than or equal to argc, in which case - * you should display the UseMsg () and return 0. - */ - -/* Check if enough arguments are given for the option */ -#define CHECK_ARGS(count) if (i + count >= argc) { UseMsg (); return 0; } - -/* Compare the current option with the string. */ -#define IS_OPTION(name) (strcmp (argv[i], name) == 0) - -/* ddxInitGlobals - called by |InitGlobals| from os/util.c */ -void ddxInitGlobals(void) -{ -} - -int -ddxProcessArgument (int argc, char *argv[], int i) -{ - static Bool s_fBeenHere = FALSE; - - /* Initialize once */ - if (!s_fBeenHere) - { -#ifdef DDXOSVERRORF - /* - * This initialises our hook into VErrorF () for catching log messages - * that are generated before OsInit () is called. - */ - OsVendorVErrorFProc = OsVendorVErrorF; #endif - s_fBeenHere = TRUE; - - /* - * Initialize default screen settings. We have to do this before - * OsVendorInit () gets called, otherwise we will overwrite - * settings changed by parameters such as -fullscreen, etc. - */ - ErrorF ("ddxProcessArgument - Initializing default screens\n"); - winInitializeDefaultScreens (); - } - -#if CYGDEBUG - ErrorF ("ddxProcessArgument - arg: %s\n", argv[i]); -#endif - - /* - * Look for the '-screen scr_num [width height]' argument - */ - if (strcmp (argv[i], "-screen") == 0) - { - int iArgsProcessed = 1; - int nScreenNum; - int iWidth, iHeight; - -#if CYGDEBUG - ErrorF ("ddxProcessArgument - screen - argc: %d i: %d\n", - argc, i); -#endif - - /* Display the usage message if the argument is malformed */ - if (i + 1 >= argc) - { - return 0; - } - - /* Grab screen number */ - nScreenNum = atoi (argv[i + 1]); - - /* Validate the specified screen number */ - if (nScreenNum < 0 || nScreenNum >= MAXSCREENS) - { - ErrorF ("ddxProcessArgument - screen - Invalid screen number %d\n", - nScreenNum); - UseMsg (); - return 0; - } - - /* Look for 'WxD' or 'W D' */ - if (i + 2 < argc - && 2 == sscanf (argv[i + 2], "%dx%d", - (int *) &iWidth, - (int *) &iHeight)) - { - ErrorF ("ddxProcessArgument - screen - Found ``WxD'' arg\n"); - iArgsProcessed = 3; - g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE; - g_ScreenInfo[nScreenNum].dwWidth = iWidth; - g_ScreenInfo[nScreenNum].dwHeight = iHeight; - g_ScreenInfo[nScreenNum].dwUserWidth = iWidth; - g_ScreenInfo[nScreenNum].dwUserHeight = iHeight; - } - else if (i + 3 < argc - && 1 == sscanf (argv[i + 2], "%d", - (int *) &iWidth) - && 1 == sscanf (argv[i + 3], "%d", - (int *) &iHeight)) - { - ErrorF ("ddxProcessArgument - screen - Found ``W D'' arg\n"); - iArgsProcessed = 4; - g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE; - g_ScreenInfo[nScreenNum].dwWidth = iWidth; - g_ScreenInfo[nScreenNum].dwHeight = iHeight; - g_ScreenInfo[nScreenNum].dwUserWidth = iWidth; - g_ScreenInfo[nScreenNum].dwUserHeight = iHeight; - } - else - { - ErrorF ("ddxProcessArgument - screen - Did not find size arg. " - "dwWidth: %d dwHeight: %d\n", - g_ScreenInfo[nScreenNum].dwWidth, - g_ScreenInfo[nScreenNum].dwHeight); - iArgsProcessed = 2; - g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE; - } - - /* Calculate the screen width and height in millimeters */ - if (g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth) - { - g_ScreenInfo[nScreenNum].dwWidth_mm - = (g_ScreenInfo[nScreenNum].dwWidth - / monitorResolution) * 25.4; - g_ScreenInfo[nScreenNum].dwHeight_mm - = (g_ScreenInfo[nScreenNum].dwHeight - / monitorResolution) * 25.4; - } - - /* Flag that this screen was explicity specified by the user */ - g_ScreenInfo[nScreenNum].fExplicitScreen = TRUE; - - /* - * Keep track of the last screen number seen, as parameters seen - * before a screen number apply to all screens, whereas parameters - * seen after a screen number apply to that screen number only. - */ - g_iLastScreen = nScreenNum; - - /* Keep a count of the number of screens */ - ++g_iNumScreens; - - return iArgsProcessed; - } - - /* - * Look for the '-engine n' argument - */ - if (strcmp (argv[i], "-engine") == 0) - { - DWORD dwEngine = 0; - CARD8 c8OnBits = 0; - - /* Display the usage message if the argument is malformed */ - if (++i >= argc) - { - UseMsg (); - return 0; - } - - /* Grab the argument */ - dwEngine = atoi (argv[i]); - - /* Count the one bits in the engine argument */ - c8OnBits = winCountBits (dwEngine); - - /* Argument should only have a single bit on */ - if (c8OnBits != 1) - { - UseMsg (); - return 0; - } - - /* Is this parameter attached to a screen or global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].dwEnginePreferred = dwEngine; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].dwEnginePreferred = dwEngine; - } - - /* Indicate that we have processed the argument */ - return 2; - } - - /* - * Look for the '-fullscreen' argument - */ - if (strcmp (argv[i], "-fullscreen") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fFullScreen = TRUE; - - /* - * No scrollbars in fullscreen mode. Later, we may want to have - * a fullscreen with a bigger virtual screen? - */ - g_ScreenInfo[j].fScrollbars = FALSE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fFullScreen = TRUE; - - /* - * No scrollbars in fullscreen mode. Later, we may want to have - * a fullscreen with a bigger virtual screen? - */ - g_ScreenInfo[g_iLastScreen].fScrollbars = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-lesspointer' argument - */ - if (strcmp (argv[i], "-lesspointer") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fLessPointer = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fLessPointer = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-nodecoration' argument - */ - if (strcmp (argv[i], "-nodecoration") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fDecoration = FALSE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fDecoration = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-rootless' argument - */ - if (strcmp (argv[i], "-rootless") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fRootless = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fRootless = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-multiwindow' argument - */ - if (strcmp (argv[i], "-multiwindow") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fMultiWindow = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fMultiWindow = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-multiplemonitors' argument - */ - if (strcmp (argv[i], "-multiplemonitors") == 0 - || strcmp (argv[i], "-multimonitors") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fMultipleMonitors = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-scrollbars' argument - */ - if (strcmp (argv[i], "-scrollbars") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - /* No scrollbar in fullscreen mode */ - if (!g_ScreenInfo[j].fFullScreen) - g_ScreenInfo[j].fScrollbars = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - if (!g_ScreenInfo[g_iLastScreen].fFullScreen) - { - /* No scrollbar in fullscreen mode */ - g_ScreenInfo[g_iLastScreen].fScrollbars = TRUE; - } - } - - /* Indicate that we have processed this argument */ - return 1; - } - - - - /* - * Look for the '-clipboard' argument - */ - if (strcmp (argv[i], "-clipboard") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fClipboard = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fClipboard = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-ignoreinput' argument - */ - if (strcmp (argv[i], "-ignoreinput") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fIgnoreInput = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fIgnoreInput = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-emulate3buttons' argument - */ - if (strcmp (argv[i], "-emulate3buttons") == 0) - { - int iArgsProcessed = 1; - int iE3BTimeout = WIN_DEFAULT_E3B_TIME; - - /* Grab the optional timeout value */ - if (i + 1 < argc - && 1 == sscanf (argv[i + 1], "%d", - &iE3BTimeout)) - { - /* Indicate that we have processed the next argument */ - iArgsProcessed++; - } - else - { - /* - * sscanf () won't modify iE3BTimeout if it doesn't find - * the specified format; however, I want to be explicit - * about setting the default timeout in such cases to - * prevent some programs (me) from getting confused. - */ - iE3BTimeout = WIN_DEFAULT_E3B_TIME; - } - - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].iE3BTimeout = iE3BTimeout; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].iE3BTimeout = iE3BTimeout; - } - - /* Indicate that we have processed this argument */ - return iArgsProcessed; - } - - /* - * Look for the '-depth n' argument - */ - if (strcmp (argv[i], "-depth") == 0) - { - DWORD dwBPP = 0; - - /* Display the usage message if the argument is malformed */ - if (++i >= argc) - { - UseMsg (); - return 0; - } - - /* Grab the argument */ - dwBPP = atoi (argv[i]); - - /* Is this parameter attached to a screen or global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].dwBPP = dwBPP; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].dwBPP = dwBPP; - } - - /* Indicate that we have processed the argument */ - return 2; - } - - /* - * Look for the '-refresh n' argument - */ - if (strcmp (argv[i], "-refresh") == 0) - { - DWORD dwRefreshRate = 0; - - /* Display the usage message if the argument is malformed */ - if (++i >= argc) - { - UseMsg (); - return 0; - } - - /* Grab the argument */ - dwRefreshRate = atoi (argv[i]); - - /* Is this parameter attached to a screen or global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].dwRefreshRate = dwRefreshRate; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].dwRefreshRate = dwRefreshRate; - } - - /* Indicate that we have processed the argument */ - return 2; - } - - /* - * Look for the '-clipupdates num_boxes' argument - */ - if (strcmp (argv[i], "-clipupdates") == 0) - { - DWORD dwNumBoxes = 0; - - /* Display the usage message if the argument is malformed */ - if (++i >= argc) - { - UseMsg (); - return 0; - } - - /* Grab the argument */ - dwNumBoxes = atoi (argv[i]); - - /* Is this parameter attached to a screen or global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].dwClipUpdatesNBoxes = dwNumBoxes; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].dwClipUpdatesNBoxes = dwNumBoxes; - } - - /* Indicate that we have processed the argument */ - return 2; - } - - /* - * Look for the '-emulatepseudo' argument - */ - if (strcmp (argv[i], "-emulatepseudo") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fEmulatePseudo = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fEmulatePseudo = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-nowinkill' argument - */ - if (strcmp (argv[i], "-nowinkill") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fUseWinKillKey = FALSE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fUseWinKillKey = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-winkill' argument - */ - if (strcmp (argv[i], "-winkill") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fUseWinKillKey = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fUseWinKillKey = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-nounixkill' argument - */ - if (strcmp (argv[i], "-nounixkill") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fUseUnixKillKey = FALSE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-unixkill' argument - */ - if (strcmp (argv[i], "-unixkill") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fUseUnixKillKey = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = TRUE; - } +#ifdef XKB + ErrorF ("-xkbrules XKBRules\n" + "\tEquivalent to XKBRules in XF86Config files.\n"); - /* Indicate that we have processed this argument */ - return 1; - } + ErrorF ("-xkbmodel XKBModel\n" + "\tEquivalent to XKBModel in XF86Config files.\n"); - /* - * Look for the '-notrayicon' argument - */ - if (strcmp (argv[i], "-notrayicon") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; + ErrorF ("-xkblayout XKBLayout\n" + "\tEquivalent to XKBLayout in XF86Config files.\n" + "\tFor example: -xkblayout de\n"); - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fNoTrayIcon = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fNoTrayIcon = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-trayicon' argument - */ - if (strcmp (argv[i], "-trayicon") == 0) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fNoTrayIcon = FALSE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fNoTrayIcon = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } + ErrorF ("-xkbvariant XKBVariant\n" + "\tEquivalent to XKBVariant in XF86Config files.\n" + "\tFor example: -xkbvariant nodeadkeys\n"); - /* - * Look for the '-fp' argument - */ - if (IS_OPTION ("-fp")) - { - CHECK_ARGS (1); - g_cmdline.fontPath = argv[++i]; - return 0; /* Let DIX parse this again */ - } - - /* - * Look for the '-co' argument - */ - if (IS_OPTION ("-co")) - { - CHECK_ARGS (1); - g_cmdline.rgbPath = argv[++i]; - return 0; /* Let DIX parse this again */ - } + ErrorF ("-xkboptions XKBOptions\n" + "\tEquivalent to XKBOptions in XF86Config files.\n"); +#endif - /* - * Look for the '-query' argument - */ - if (IS_OPTION ("-query")) - { - CHECK_ARGS (1); - g_pszQueryHost = argv[++i]; - return 0; /* Let DIX parse this again */ - } + ErrorF ("-logfile filename\n" + "\tWrite logmessages to <filename> instead of /tmp/Xwin.log.\n"); - /* - * Look for the '-config' argument. Accept -xf86config as an alias - */ - if (IS_OPTION ("-config") || IS_OPTION ("-xf86config")) - { - CHECK_ARGS (1); - g_cmdline.configFile = argv[++i]; - return 2; - } + ErrorF ("-logverbose verbosity\n" + "\tSet the verbosity of logmessages. [NOTE: Only a few messages\n" + "\trespect the settings yet]\n" + "\t\t0 - only print fatal error.\n" + "\t\t1 - print additional configuration information.\n" + "\t\t2 - print additional runtime information [default].\n" + "\t\t3 - print debugging and tracing information.\n"); - /* - * Look for the '-keyboard' argument - */ - if (IS_OPTION ("-keyboard")) - { - CHECK_ARGS (1); - g_cmdline.keyboard = argv[++i]; - return 2; - } + ErrorF ("-[no]keyhook\n" + "\tGrab special windows key combinations like Alt-Tab or the Menu " + "key.\n These keys are discarded by default.\n"); - /* - * Look for the '-logfile' argument - */ - if (IS_OPTION ("-logfile")) - { - CHECK_ARGS (1); - g_pszLogFile = argv[++i]; - return 2; - } + ErrorF ("-swcursor\n" + "\tDisable the usage of the windows cursor and use the X11 software " + "cursor instead\n"); +} - /* - * Look for the '-logverbose' argument - */ - if (IS_OPTION ("-logverbose")) - { - CHECK_ARGS (1); - g_iLogVerbose = atoi(argv[++i]); - return 2; - } +/* See Porting Layer Definition - p. 57 */ +void +ddxUseMsg(void) +{ + /* Set a flag so that FatalError won't give duplicate warning message */ + g_fUseMsg = TRUE; + + winUseMsg(); - return 0; + /* Log file will not be opened for UseMsg unless we open it now */ + if (!g_fLogInited) { + LogInit (g_pszLogFile, NULL); + g_fLogInited = TRUE; + } + LogClose (); + + /* Notify user where UseMsg text can be found.*/ + if (!g_fNoHelpMessageBox) + winMessageBoxF ("The Cygwin/X help text has been printed to " + "/tmp/XWin.log.\n" + "Please open /tmp/XWin.log to read the help text.\n", + MB_ICONINFORMATION); } +/* ddxInitGlobals - called by |InitGlobals| from os/util.c */ +void ddxInitGlobals(void) +{ +} #ifdef DDXTIME /* from ServerOSDefines */ CARD32 @@ -1269,15 +516,40 @@ void InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) { int i; - int iMaxConsecutiveScreen = 0; + + /* Log the command line */ + winLogCommandLine (argc, argv); #if CYGDEBUG - ErrorF ("InitOutput\n"); + winDebug ("InitOutput\n"); #endif + /* Validate command-line arguments */ + if (serverGeneration == 1 && !winValidateArgs ()) + { + FatalError ("InitOutput - Invalid command-line arguments found. " + "Exiting.\n"); + } + + /* Check for duplicate invocation on same display number.*/ + if (serverGeneration == 1 && !winCheckDisplayNumber ()) + { + FatalError ("InitOutput - Duplicate invocation on display " + "number: %s. Exiting.\n", display); + } + +#ifdef XWIN_XF86CONFIG /* Try to read the xorg.conf-style configuration file */ if (!winReadConfigfile ()) - ErrorF ("InitOutput - Error reading config file\n"); + winErrorFVerb (1, "InitOutput - Error reading config file\n"); +#else + winMsg(X_INFO, "XF86Config is not supported\n"); + winMsg(X_INFO, "See http://x.cygwin.com/docs/faq/cygwin-x-faq.html " + "for more information\n"); +#endif + + /* Load preferences from XWinrc file */ + LoadPreferences(); /* Setup global screen info parameters */ screenInfo->imageByteOrder = IMAGE_BYTE_ORDER; @@ -1306,7 +578,7 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) "_TrackMouseEvent"); if (g_fpTrackMouseEvent == NULL) { - ErrorF ("InitOutput - Could not get pointer to function\n" + winErrorFVerb (1, "InitOutput - Could not get pointer to function\n" "\t_TrackMouseEvent in comctl32.dll. Try installing\n" "\tInternet Explorer 3.0 or greater if you have not\n" "\talready.\n"); @@ -1316,37 +588,14 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) g_hmodCommonControls = NULL; /* Set function pointer to point to no operation function */ - g_fpTrackMouseEvent = (FARPROC) (void (*)())NoopDDA; + g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; } - /* - * Check for a malformed set of -screen parameters. - * Examples of malformed parameters: - * XWin -screen 1 - * XWin -screen 0 -screen 2 - * XWin -screen 1 -screen 2 - */ - for (i = 0; i < MAXSCREENS; i++) - { - if (g_ScreenInfo[i].fExplicitScreen) - iMaxConsecutiveScreen = i + 1; - } - ErrorF ("InitOutput - g_iNumScreens: %d iMaxConsecutiveScreen: %d\n", - g_iNumScreens, iMaxConsecutiveScreen); - if (g_iNumScreens < iMaxConsecutiveScreen) - FatalError ("InitOutput - Malformed set of screen parameter(s). " - "Screens must be specified consecutively starting with " - "screen 0. That is, you cannot have only a screen 1, nor " - "could you have screen 0 and screen 2. You instead must have " - "screen 0, or screen 0 and screen 1, respectively. Of " - "you can specify as many screens as you want from 0 up to " - "%d.\n", MAXSCREENS - 1); - /* Store the instance handle */ g_hInstance = GetModuleHandle (NULL); /* Initialize each screen */ - for (i = 0; i < g_iNumScreens; i++) + for (i = 0; i < g_iNumScreens; ++i) { /* Initialize the screen */ if (-1 == AddScreen (winScreenInit, argc, argv)) @@ -1355,9 +604,101 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) } } - LoadPreferences(); +#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) + +#if defined(XCSECURITY) + /* Generate a cookie used by internal clients for authorization */ + if (g_fXdmcpEnabled) + winGenerateAuthorization (); +#endif + + /* Perform some one time initialization */ + if (1 == serverGeneration) + { + /* + * setlocale applies to all threads in the current process. + * Apply locale specified in LANG environment variable. + */ + setlocale (LC_ALL, ""); + } +#endif #if CYGDEBUG || YES - ErrorF ("InitOutput - Returning.\n"); + winDebug ("InitOutput - Returning.\n"); #endif } + + +/* + * winCheckDisplayNumber - Check if another instance of Cygwin/X is + * already running on the same display number. If no one exists, + * make a mutex to prevent new instances from running on the same display. + * + * return FALSE if the display number is already used. + */ + +static Bool +winCheckDisplayNumber () +{ + int nDisp; + HANDLE mutex; + char name[MAX_PATH]; + char * pszPrefix = '\0'; + OSVERSIONINFO osvi = {0}; + + /* Check display range */ + nDisp = atoi (display); + if (nDisp < 0 || nDisp > 65535) + { + ErrorF ("winCheckDisplayNumber - Bad display number: %d\n", nDisp); + return FALSE; + } + + /* Set first character of mutex name to null */ + name[0] = '\0'; + + /* Get operating system version information */ + osvi.dwOSVersionInfoSize = sizeof (osvi); + GetVersionEx (&osvi); + + /* Want a mutex shared among all terminals on NT > 4.0 */ + if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT + && osvi.dwMajorVersion >= 5) + { + pszPrefix = "Global\\"; + } + + /* Setup Cygwin/X specific part of name */ + sprintf (name, "%sCYGWINX_DISPLAY:%d", pszPrefix, nDisp); + + /* Windows automatically releases the mutex when this process exits */ + mutex = CreateMutex (NULL, FALSE, name); + if (!mutex) + { + 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 ("winCheckDisplayNumber - CreateMutex failed: %s\n", + (LPSTR)lpMsgBuf); + LocalFree (lpMsgBuf); + + return FALSE; + } + if (GetLastError () == ERROR_ALREADY_EXISTS) + { + ErrorF ("winCheckDisplayNumber - " + "Cygwin/X is already running on display %d\n", + nDisp); + return FALSE; + } + + return TRUE; +} diff --git a/hw/xwin/X-boxed.ico b/hw/xwin/X-boxed.ico Binary files differnew file mode 100755 index 000000000..072704253 --- /dev/null +++ b/hw/xwin/X-boxed.ico diff --git a/hw/xwin/X.ico b/hw/xwin/X.ico Binary files differindex 26e2cf947..d47168fca 100644 --- a/hw/xwin/X.ico +++ b/hw/xwin/X.ico diff --git a/hw/xwin/XWin.man b/hw/xwin/XWin.man index 3fb3f2814..e758c98cb 100644 --- a/hw/xwin/XWin.man +++ b/hw/xwin/XWin.man @@ -1,129 +1,284 @@ -.\" $XFree86: xc/programs/Xserver/hw/xwin/XWin.man,v 1.5 2002/07/05 09:19:25 alanh Exp $ .TH XWIN 1 __vendorversion__ .SH NAME XWin \- X Server for the Cygwin environment on Microsoft Windows + + .SH SYNOPSIS .B XWin [ options ] ... + + .SH DESCRIPTION -.I XWin -is an X Server for the X Window System on the Cygwin environment +.I XWin is an X Server for the X Window System on the Cygwin environment running on Microsoft Windows. -.SH OPTIONS + + +.SH MODES +\fIXWin\fP can operate in five different and incompatible modes: +.br +* \fISingle Window\fP: This is the default option. The X server +appears as a single Windows window and all X windows are contained +within this window. This mode requires an external window manager. +.br +* \fINo Decoration\fP: This mode is like single window mode except +that the X server window does not have a title bar or border, thus +maximizing the amount of space available for X windows within the X +server window. This mode requires an external window manager. +.br +* \fIFull Screen\fP: This mode is like single window mode except that +the X server window takes the full screen, covering completely the +Windows desktop. This mode requires an external window manager. +.br +* \fIRootless\fP: The X server works on a window covering the whole +screen but the root window (traditionally covered with an X hatch +pattern) is hidden from view. This mode requires an external window +manager. +.br +* \fIMulti-Window\fP: In this mode \fIXWin\fP uses its own integrated +window manager in order to handle the top-level X windows, in such a +way that they appear as normal Windows windows. .PP +NOTE: \fIMulti-Window\fP mode will crash if an external window manager +such as \fItwm\fP or \fIfvwm\fP is launched since \fIMulti-Window\fP +uses its own internal window manager; all other modes require an +external window manager in order to move, resize, and perform other +operations on the individual X windows. + + +.SH LOG +As it runs \fIXWin\fP writes messages indicating the most relevant events +to the console +from which it was called and to a log file that by default is located at +\fI/tmp/XWin.log\fP. This file is mainly for debugging purposes. + + +.SH PREFERENCES FILE +On startup \fIXWin\fP looks for the file \fI$HOME/.XWinrc\fP or, if +the previous file does not exist, +\fI/usr/X11R6/lib/X11/system.XWinrc\fP. \fI.XWinrc\fP allows setting +preferences for the following: +.br +1- To include items into the menu associated with the \fIXWin\fP icon +which is in the \fIWindows\fP system tray. This functions in all +modes that have a tray icon. +.br +2- To include items in the menu which is associated with the Windows +window that \fIXWin -multiwindow\fP produces for each top-level X +window. That can be done both for the generic case and for particular +programs. +.br +3- To change the icon that is associated to the Windows window that +\fIXWin -multiwindow\fP produces for each top-level X-window. Again, +that can be done both for the generic case and for particular +programs. +.PP +The format of the \fI.XWinrc\fP file is given in the man page XWinrc(5). + + +.SH OPTIONS In addition to the normal server options described in the \fIXserver(1)\fP -manual page, \fIXWin\fP accepts the following command line switches: +manual page, \fIXWin\fP accepts the following command line switches, +\fIall\fP of which are optional: .TP 8 -.B "\-depth \fIdepth\fP" -Specify the color depth, in bits per pixel, to use when running in -fullscreen with a DirectDraw engine. This parameter is ignored if -\fB\-fullscreen\fP is not specified. +.B \-clipboard +Enables the integration +between the Cygwin/X clipboard and Windows clipboard. Do not use in +conjunction with the \fIxwinclip\fP program. +.TP 8 +.B "\-clipupdates \fInum_boxes\fP" +Specify an optional threshold, above which the boxes in a shadow +update operation will be collected into a GDI clipping region. The +clipping region is then used to do a single bit block transfer that is +constrained to the updated area by the clipping region. There is some +overhead involved in creating, installing, destroying, and removing +the clipping region, thus there may not be much benefit for a small +number of boxes (less than 10). It is even possible that this +functionality does not provide a benefit at any number of boxes; we +can only determine the usefulness of this feature through testing. +This parameter works in conjunction with engines 1, 2, and 4 (Shadow +GDI, Shadow DirectDraw, and Shadow DirectDraw Non-Locking, +respectively). .TP 8 .B "\-emulate3buttons \fItimeout\fP" Emulate a three button mouse; pressing both buttons within .I timeout milliseconds causes an emulated middle button press. The default .I timeout -is 50 milliseconds. +is 50 milliseconds. Note that most mice with scroll wheel have middle +button functionality, usually you will need this option only if you have +a two button mouse without scroll wheel. +.TP 8 +.B \-emulatepseudo +Create a depth 8 PseudoColor visual when running in depths 15, 16, 24, +or 32, collectively known as TrueColor depths. + At this date (April 2004) this option is not still operative. .TP 8 .B "\-engine \fIengine_type_id\fP" -Override the server's automatically supported engine type. This +This option, which is intended for Cygwin/X developers, +overrides the server's automatically supported engine type. This parameter will be ignored if the specified engine type is not supported on the current system. The supported engine type ids are 1 - Shadow GDI, 2 - Shadow DirectDraw, and 4 - Shadow DirectDraw4. Additionally, there is a barely functional experimental engine type id 16 - Native GDI. .TP 8 -.B \-fullscreen +.B "\-fullscreen [-depth \fIdepth\fP] [-refresh \fIrate_in_Hz\fP]" Run the server in fullscreen mode, as opposed to the default windowed mode. .TP 8 +.B "\-depth \fIdepth\fP" +Specify the color depth, in bits per pixel, to use when running in +fullscreen with a DirectDraw engine. This parameter is ignored if +\fB\-fullscreen\fP is not specified. +.TP 8 .B "\-refresh \fIrate_in_Hz\fP" Specify an optional refresh rate to use when running in fullscreen with a DirectDraw engine. This parameter is ignored if \fB\-fullscreen\fP is not specified. .TP 8 -.B "\-screen \fIscreen_number\fP \fIwidth\fP \fIheight\fP" -Sets the display resolution for the X server to use on screen -.I screen_number. +.B \-help +Write a help text to the console and to the log file. +.TP 8 +.B \-ignoreinput +Ignore keyboard and mouse input. This is usually only used for testing +and debugging purposes. +.TP 8 +.B \-[no]keyhook +Enable [disable] a low-level keyboard hook for catching +special key combinations like Alt+Tab and passing them to the X +Server instead of letting \fIWindows\fP handle them. +.TP 8 +.B \-lesspointer +Hide the Windows mouse cursor when the mouse is over any Cygwin/X +window (regardless of whether that window is active or inactive). This +prevents the Windows mouse cursor from being placed overtop of the X +cursor. +.TP 8 +.B "\-logfile \fIFile_Name\fP" +Change the log file from the default located at \fI/tmp/XWin.log\fP to +the one indicated by \fIFile_Name\fP. +.TP 8 +.B "\-logverbose \fIlevel\fP" +Control the degree of verbosity of the log messages with the integer +parameter \fIlevel\fP. For \fIlevel\fP=0 only fatal errors are +reported, for \fIlevel\fP=1 (default) simple information about +configuration is also given, for \fIlevel\fP=2 a detailed log +information (including trace and debug output) is produced. Bigger +values will yield a still more detailed debug output. At this date +(April 2004) the option is still not fully operative; the default +value is 2 and the output is insensitive to the level value. +.TP 8 +.B \-multimonitors +Create a root window that covers all monitors on a system with +multiple monitors. +.TP 8 +.B \-multiwindow +Start the integrated \fIWindowsi\fP-based window manager, which launches each +top-level X window in its own \fIWindows\fP window. Not to be used together +with \fB\-rootless\fP nor \fB\-fullscreen\fP. .TP 8 .B \-nodecoration -Draw the Cygwin/X window without a border or title bar. +Do not give the Cygwin/X window a Windows window border, title bar, +etc. This parameter only applies to windowed mode screens, i.e., this +parameter is ignored when the \fB\-fullscreen\fP parameter is specified. +.TP 8 +.B \-nounicodeclipboard +Do not use Unicode clipboard even if NT-based platform. .TP 8 .B \-rootless -EXPERIMENTAL: Run Cygwin/X in pseduo-rootless mode. +Run the server in rootless mode. Not to be used with \fB\-multiwindow\fP +nor with \fB\-fullscreen\fP. .TP 8 -.B \-lesspointer -Hide the Windows mouse pointer when over an inactive X window +.B "\-screen \fIscreen_number\fP \fIwidth\fP \fIheight\fP" +This parameter may be used to specify the +.I screen_number, +.I height, +and +.I width +of one or several Cygwin/X screens; each Cygwin/X screen will be +opened in its own window. When using multiple screens, be sure not to +duplicate any screen numbers. +.I XWin +default behavior is to create a single screen that is roughly +the size of the current Windows display area. +Screen specific parameters, such as \fB\-fullscreen\fP, can be applied as a +default to all screens by placing those screen specific parameters +before any \fB\-screen\fP parameter. Screen specific parameters placed after +the first \fB\-screen\fP parameter will apply only to the immediately +preceeding \fB\-screen\fP parameter. .TP 8 .B \-scrollbars In windowed mode, allow screens bigger than the Windows desktop. Moreover, if the window has decorations, one can now resize it. .TP 8 -.B "\-clipupdates \fInum_boxes\fP" -Specify an optional threshold, above which the boxes in a shadow -update operation will be collected into a GDI clipping region. The -clipping region is then used to do a single bit block transfer that is -constrained to the updated area by the clipping region. There is some -overhead involved in creating, installing, destroying, and removing -the clipping region, thus there may not be much benefit for a small -number of boxes (less than 10). It is even possible that this -functionality does not provide a benefit at any number of boxes; we -can only determine the usefullness of this feature through testing. -This parameter works in conjunction with engines 1, 2, and 4 (Shadow -GDI, Shadow DirectDraw, and Shadow DirectDraw Non-Locking, -respectively). -.TP 8 -.B \-emulatepseudo -Create a depth 8 PseudoColor visual when running in depths 15, 16, 24, -or 32, collectively known as TrueColor depths. The PseudoColor visual -does not have correct colors, and it may crash, but it at least allows -you to run your PseudoColor application in TrueColor modes. +.B \-[no]trayicon +Do not create a tray icon. Default is to create one +icon per screen. You can globally disable tray icons with +\fB\-notrayicon\fP, then enable it for specific screens with +\fB\-trayicon\fP for those screens. .TP 8 .B \-[no]unixkill -Ctrl+Alt+Backspace exits the X Server +Enable or disable the \fICtrl-Alt-Backspace\fP key combination as a +signal to exit the X Server. The \fICtrl-Alt-Backspace\fP key combination +is disabled by default. .TP 8 .B \-[no]winkill -Alt+F4 exits the X Server -.SH "SEE ALSO" +Enable or disable the \fIAlt-F4\fP key combination as a signal to exit the +X Server. +The \fIAlt-F4\fP key combination is enabled by default. +.TP 8 +.B \-swcursor +Disable the usage of the windows cursor and use the X11 software cursor instead. +.TP 8 +.B "\-xkblayout \fIlayout\fP" +.TP 8 +.B "\-xkbmodel \fImodel\fP" +.TP 8 +.B "\-xkboptions \fIoption\fP" +.TP 8 +.B "\-xkbrules \fIrule\fP" +.TP 8 +.B "\-xkbvariant \fIvariant\fp" +These options implement the xkeyboard extension for loading +a particular keyboard map as the X server starts. The behavior is similar +to the \fIsetxkbmap\fP program. The layout data is located at +\fI/usr/X11R6/lib/X11/xkb/\fP. Additional information is found in the +README files therein and in the man page of \fIsetxkbmap\fP. For example +in order to load a German layout for a pc105 keyboard one uses +the options: +.br +.I " \-xkblayout de \-xkbmodel pc105" .PP -X(__miscmansuffix__), Xserver(1), xdm(1), xinit(1), XWinrc(5) +Alternatively one may use the \fIsetxkbmap\fP program after XWin is +running or even the \fIxmodmap\fP program for loading the old-style +keyboard maps. + + +.SH "SEE ALSO" +X(__miscmansuffix__), Xserver(1), xdm(1), xinit(1), XWinrc(1), setxkbmap(1) + + .SH BUGS .I XWin -and this man page still have many limitations. Some of the more obvious +and this man page still have many limitations. Some of the more obvious ones are: .br - The display mode can not be changed once the X server has started. -.PP -.SH AUTHORS -X was originally ported to Cygwin by Dakshinamurthy Karra, -Dr. Peter Busch, John Fortin, and Suhaib Siddiqi. -.I XWin -is maintained by the Cygwin/X project, with hosting services -provided by freedesktop.org. -.PP -The following members, in alphabetical order by last name, of the -Cygwin/X Team contributed to the X.Org Foundation 6.7 release: -.PP -Robert Collins - Cygwin developer, miscellaneous -.br -Christopher Faylor - Management of hosting services, general -programming guru -.br -Alexander Gottwald - AltGr handling for non-U.S. keyboards -.br -Alan Hourihane - X developer, patch reviewer, general programming guru -.br -Pierre A Humblet - Debugging of socket-related crashes, developer -.br -Harold L Hunt II - Project leader, lead developer, documentation, -and website updates .br -Suhaib Siddiqi - Originator of the project - - - - - +- The XWin software is developing rapidly; it is therefore likely that +this man page is not up to date. It is always prudent to +look also at the output of \fIXWin -help\fP and to the Cygwin/X User Guide +at /usr/share/doc/cygwin-x-doc-x.x.x/ug/cygwin-x-ug.xxx in order to +check the options that are operative. +.SH AUTHORS +This list is by no means complete, but direct contributors to the +Cygwin/X project include (in alphabetical order by last name): Stuart +Adamson, Michael Bax, Jehan Bing, Lev Bishop, Dr. Peter Busch, Biju G +C, Robert Collins, Nick Crabtree, Early Ehlinger, Christopher Faylor, +John Fortin, Brian Genisio, Fabrizio Gennari, Alexander Gottwald, Ralf +Habacker, Colin Harrison, Matthieu Herrb, Alan Hourihane, Pierre A +Humblet, Harold L Hunt II, Dakshinamurthy Karra, Kensuke Matsuzaki, +Takuma Murakami, Earle F. Philhower III, Benjamin Riefenstahl, Suhaib +Siddiqi, Jack Tanner, and Nicholas Wourms. diff --git a/hw/xwin/XWin.rc b/hw/xwin/XWin.rc index 2e6cceb47..446174f64 100644 --- a/hw/xwin/XWin.rc +++ b/hw/xwin/XWin.rc @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2002-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,28 +15,48 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/XWin.rc,v 1.1 2002/10/17 08:18:21 alanh Exp $ */ -#include "resource.h" +#include "winresource.h" /* * Dialogs */ -/* Depth_Change */ +/* About */ +ABOUT_BOX DIALOG DISCARDABLE 32, 32, 240, 105 +STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_TABSTOP | DS_CENTER +CAPTION "About Cygwin/X" +FONT 8, "MS Sans Serif" +BEGIN + CONTROL "Cygwin/X Website", ID_ABOUT_WEBSITE, "Button", + BS_OWNERDRAW | WS_TABSTOP, 30, 45, 75, 15 + CONTROL "Change Log", ID_ABOUT_CHANGELOG, "Button", + BS_OWNERDRAW | WS_TABSTOP, 135, 45, 75, 15 + CONTROL "User's Guide", ID_ABOUT_UG, "Button", + BS_OWNERDRAW | WS_TABSTOP, 30, 65, 75, 15 + CONTROL "FAQ", ID_ABOUT_FAQ, "Button", + BS_OWNERDRAW | WS_TABSTOP, 135, 65, 75, 15 + + DEFPUSHBUTTON "Dismiss", IDOK, 95, 85, 50, 15 + + CTEXT "Welcome to the preliminary About box for the Cygwin/X X Server. This dialog was created on 2004/03/25 and will eventually be filled with more useful information. For now, use the links below to learn more about the Cygwin/X project.", IDC_STATIC, 5, 5, 230, 35 +END + + +/* Depth change */ DEPTH_CHANGE_BOX DIALOG DISCARDABLE 32, 32, 180, 100 STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | DS_CENTER @@ -52,15 +72,16 @@ END /* Exit */ -EXIT_DIALOG DIALOG DISCARDABLE 32, 32, 180, 70 +EXIT_DIALOG DIALOG DISCARDABLE 32, 32, 180, 78 STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_TABSTOP | DS_CENTER FONT 8, "MS Sans Serif" CAPTION "Cygwin/X - Exit?" BEGIN - PUSHBUTTON "E&xit", IDOK, 55, 48, 30, 14 - DEFPUSHBUTTON "&Cancel", IDCANCEL, 95, 48, 30, 14 + PUSHBUTTON "E&xit", IDOK, 55, 56, 30, 14 + DEFPUSHBUTTON "&Cancel", IDCANCEL, 95, 56, 30, 14 CTEXT "Exiting will close all screens running on this display.", IDC_STATIC, 7, 12, 166, 8 - CTEXT "Proceed with shutdown of this display/server?", IDC_STATIC, 7, 24, 166, 8 + CTEXT "No information about connected clients available.", IDC_CLIENTS_CONNECTED, 7, 24, 166, 8 + CTEXT "Proceed with shutdown of this display/server?", IDC_STATIC, 7, 36, 166, 8 END @@ -73,7 +94,7 @@ BEGIN POPUP "TRAYICON_MENU" BEGIN MENUITEM "&Hide Root Window", ID_APP_HIDE_ROOT - MENUITEM "&Show Root Window", ID_APP_SHOW_ROOT + MENUITEM "&About...", ID_APP_ABOUT MENUITEM SEPARATOR MENUITEM "E&xit", ID_APP_EXIT END @@ -85,3 +106,4 @@ END */ IDI_XWIN ICON DISCARDABLE "X.ico" +IDI_XWIN_BOXED ICON DISCARDABLE "X-boxed.ico" diff --git a/hw/xwin/XWinrc.man b/hw/xwin/XWinrc.man new file mode 100755 index 000000000..eba3fb603 --- /dev/null +++ b/hw/xwin/XWinrc.man @@ -0,0 +1,180 @@ +.TH XWIN 5 __vendorversion__ + + +.SH NAME +XWinrc\- XWin Server Resource Configuration File. + + +.SH DESCRIPTION +The X Server for the X Window System on the Cygwin/X environment +running on Microsoft Windows, \fIXWin\fP can be optionally configured +with the \fIXWinrc\fP file. A system-wide configuration file should +be placed in \fI/usr/X11R6/lib/X11/system.XWinrc\fP, a per-user file +should be put at \fI$HOME/.XWinrc\fP. The \fIsystem.XWinrc\fP file is +read only if no \fI$HOME/.XWinrc\fP exist. +.PP +With the \fI.XWinrc\fP configuration file it is possible to do the +following: +.PP +1- To include items into the menu associated with the \fIXWin\fP icon +which is in the \fIWindows\fP system tray. This feature functions in +all XWin modes that have such tray icon. +.PP +2- To include items into the menu which is associated with the +\fIWindows\fP window that \fIXWin -multiwindow\fP produces for each +top-level X-window. That can be done both for the generic case and +for particular programs. +.PP +3- To change the icon that is associated to the \fIWindows\fP window +that \fIXWin -multiwindow\fP produces for each top-level X-window. +Again, that can be done both for the generic case and for particular +programs. The new icons associated should be \fIWindows\fP format +icons \fI.ico\fP. + + +.SH FILE FORMAT +.B Keywords +are case insensitive, but in this document they will be written +completely capitalized. +.PP +.B Comments +are legal pretty much anywhere you can have an end-of-line; they +begin with "#" or "//" and go to the end-of-line. +.PP +Quote marks in strings are optional unless the string has included spaces. +.PP +There are three kinds of instructions: miscellaneous, menu, and icon. + + +.SH Miscellaneous instruction +.TP 8 +.B DEBUG \fIString\fP +The \fIString\fP is printed to the XWin.log file. + +.TP 8 +.B TRAYICON \fIicon-specifier\fB +The \fBTRAYICON\fP keyword changes the icon \fIXWin\fP displays in the +system tray area. + +.TP 8 +.B SILENTEXIT +The \fBSILENTEXIT\fP keyword, which takes no parameters, disables the +exit confirmation dialog. + + +.SH Menu instructions +.TP 8 +.B MENU \fIMenu_Name\fP { +.br +.B \fIMenu_Item_Line\fP +.br +.B \fIMenu_Item_Line\fP +.br +.B \fI...\fP +.br +.B } +.br +This instruction defines a menu and asigns a \fIMenu_Name\fP to it. +\fIMenu_Item_Line\fP are lines of any of the following types: +.TP 8 +.B \t SEPARATOR +.TP 8 +.B \t \fIItem_Label\fP EXEC \fICommand\fP +.TP 8 +.B \t \fIItem_Label\fP MENU \fIpreviously-defined-menu-name\fP +.TP 8 +.B \t \fIItem_Label\fP ALWAYSONTOP +.TP 8 +.B \t \fIItem_Label\fP RELOAD +.br +The \fIItem_Label\fP is the string that is written in the menu item. +.br +\fICommand\fP is a string with the command that will be executed by /bin/sh. +Here paths should be \fICYGWIN\fP style (e.g. /usr/local/bin/myprogram). +A string "%display%" appearing in the \fICommand\fP will be replaced +with the proper display variable (i.e. 127.0.0.1:<display>.0). +.br +\fBALWAYSONTOP\fP sets the window to which the menu is associated to +display above all others. +.br +\fBRELOAD\fP causes the XWinrc file to be reloaded and icons and menus +regenerated. +.TP 8 +.B ROOTMENU \fIpreviously-defined-menu-name\fP +Includes the items in the indicated menu into the menu associated with +\fIXWin\fP that appears in the system tray. +.TP 8 +.B DEFAULTSYSMENU \fIpreviously-defined-menu-name\fP ATSTART|ATEND +Includes the items in the indicated menu into the menu associated with +generic top-level X-Windows in the \fIXWin\fP \fImultiwindow\fP mode. The +keywords \fBATSTART\fP and \fBATEND\fP indicate if such items should be +included at the start or at the end of the menu. +.TP 8 +.B SYSMENU { + \fIclass-or-name-of-window\fP \fIdefined-menu-name\fP \fBATSTART|ATEND\fP +.br + \fI...\fP +.br + \fB}\fP +.br +Associates a specific menu to a specific WM_CLASS or WM_NAME. + + +.SH Icon Instructions +When specifying an \fIicon-file\fP in the following commands several different formats are allowed: +.br +\fB"NAME.ICO"\fP\fI of an .ico format file\fP +.br +\t \t ("cygwin.ico", "apple.ico") +.br +\fB"NAME.DLL,nn"\fP\fI of a .DLL and icon index\fP +.br +\t \t ("c:\\windows\\system32\\shell32.dll,4" is the default folder icon) +.br +\fB",nn"\fP\fI index into XWin.EXE internal ICON resources\fP +.br +\t \t (",101" is the 1st icon inside \fIXWin.EXE\fP) +.TP 8 +.B ICONDIRECTORY \fIWindows-path-to-icon-directory\fP +Defines the default directory to search for \ficon-file\fP files. +It should be a \fIWindows\fP style path (e.g. C:\\cygwin\\usr\\local\\icons). +.TP 8 +.B DEFAULTICON \fIicon-file\fP +Defines a replacement for the standard X icon for applications without +specified icons. +.TP 8 +.B ICONS { +.br + \fIclass-or-name-of-window\fP \fIicon-file\fP +.br + \fI...\fP +.br + \fB}\fP +.br +Defines icon replacements windows matching the specified window class or names. +If multiple name or class matches occur for a window, only the first one +will be used. + + +.SH EXAMPLE +.TP 8 +This example adds an Xterm menu item to the system tray icon +\fBMENU systray { +.br +\t xterm EXEC "xterm -display %display% -sb -sl 999" +.br +\t SEPARATOR +.br +} +.br +ROOTMENU systray +\fP + + +.SH "SEE ALSO" + XWin(1) + + +.SH AUTHOR +The XWinrc feature of XWin was written primarily by Earle F. Philhower +III. diff --git a/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc b/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc index dbd79f2bf..d9c2d4210 100644 --- a/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc +++ b/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc @@ -40,8 +40,24 @@ # ... # } +# When specifying an ICONFILE in the following commands several different +# formats are allowed: +# 1. Name of a regular Windows .ico format file +# (ex: "cygwin.ico", "apple.ico") +# 2. Name and index into a Windows .DLL +# (ex: "c:\windows\system32\shell32.dll,4" gives the default folder icon +# "c:\windows\system32\shell32.dll,5" gives the floppy drive icon) +# 3. Index into XWin.EXE internal ICON resource +# (ex: ",101" is the 1st icon inside XWin.exe) + # To define where ICO files live (** Windows path**) # ICONDIRECTORY <windows-path i.e. c:\cygwin\usr\icons> +# NOTE: If you specify a fully qualified path to an ICON below +# (i.e. "c:\xxx" or "d:\xxxx") +# this ICONDIRECTORY will not be prepended + +# To change the taskbar icon use... +# TRAYICON <name-of-windows-ico-file-in-icondirectory> # To define a replacement for the standard X icon for apps w/o specified icons # DEFAULTICON <name-of-windows-ico-file-in-icondirectory> @@ -54,6 +70,8 @@ # In the case where multiple matches occur, the first listed in the ICONS # section will be chosen. +# To disable exit confirmation dialog add the line containing SilentExit + # DEBUG <string> prints out the string to the XWin.log file // Below are just some silly menus to demonstrate writing your @@ -101,5 +119,7 @@ SysMenu { # "xterm" "uninstall.ico" # } +# SilentExit + DEBUG "Done parsing the configuration file..." diff --git a/hw/xwin/ddraw.h b/hw/xwin/ddraw.h index fbbf2b8eb..f72ce1f09 100644 --- a/hw/xwin/ddraw.h +++ b/hw/xwin/ddraw.h @@ -1,3 +1,4 @@ +/* $Id$ */ #ifndef __WINE_DDRAW_H #define __WINE_DDRAW_H diff --git a/hw/xwin/win.h b/hw/xwin/win.h index 53d0880ea..46ccb7884 100644 --- a/hw/xwin/win.h +++ b/hw/xwin/win.h @@ -36,7 +36,6 @@ #ifndef _WIN_H_ #define _WIN_H_ - #ifndef NO #define NO 0 #endif @@ -44,17 +43,10 @@ #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 */ +#ifndef CYGDEBUG #define CYGDEBUG NO +#endif #define NEED_EVENTS @@ -68,7 +60,9 @@ #define WIN_DEFAULT_WIN_KILL TRUE #define WIN_DEFAULT_UNIX_KILL FALSE #define WIN_DEFAULT_CLIP_UPDATES_NBOXES 0 +#ifdef XWIN_EMULATEPSEUDO #define WIN_DEFAULT_EMULATE_PSEUDO FALSE +#endif #define WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH FALSE #define WIN_DIB_MAXIMUM_SIZE 0x08000000 /* 16 MB on Windows 95, 98, Me */ @@ -107,8 +101,12 @@ #define WIN_SERVER_SHADOW_GDI 0x1L /* 1 */ #define WIN_SERVER_SHADOW_DD 0x2L /* 2 */ #define WIN_SERVER_SHADOW_DDNL 0x4L /* 4 */ +#ifdef XWIN_PRIMARYFB #define WIN_SERVER_PRIMARY_DD 0x8L /* 8 */ -#define WIN_SERVER_NATIVE_GDI 0x10L /* 16 */ +#endif +#ifdef XWIN_NATIVEGDI +# define WIN_SERVER_NATIVE_GDI 0x10L /* 16 */ +#endif #define AltMapIndex Mod1MapIndex #define NumLockMapIndex Mod2MapIndex @@ -133,8 +131,6 @@ #include <errno.h> #include <pthread.h> -#include <X11/XWDFile.h> - #ifdef HAS_MMAP #include <sys/mman.h> #ifndef MAP_FILE @@ -142,10 +138,10 @@ #endif /* MAP_FILE */ #endif /* HAS_MMAP */ -#include "X.h" -#include "Xproto.h" -#include "Xos.h" -#include "Xprotostr.h" +#include "X11/X.h" +#include "X11/Xproto.h" +#include "X11/Xos.h" +#include "X11/Xprotostr.h" #include "scrnintstr.h" #include "pixmapstr.h" #include "pixmap.h" @@ -158,20 +154,19 @@ #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 "X11/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" @@ -186,6 +181,7 @@ * Windows headers */ #include "winms.h" +#include "./winresource.h" /* @@ -197,18 +193,9 @@ #define WM_GIVEUP (WM_USER + 1002) -/* - * Multi-Window Window Manager header - */ - +/* Local includes */ #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 +#include "winmsg.h" /* @@ -254,9 +241,27 @@ if (fDebugProcMsg) \ #define DEBUGPROC_MSG #endif +#define PROFILEPOINT(point,thresh)\ +{\ +static unsigned int PROFPT##point = 0;\ +if (++PROFPT##point % thresh == 0)\ +ErrorF (#point ": PROFILEPOINT hit %u times\n", PROFPT##point);\ +} + + /* We use xor this macro for detecting toggle key state changes */ #define WIN_XOR(a,b) ((!(a) && (b)) || ((a) && !(b))) +#define DEFINE_ATOM_HELPER(func,atom_name) \ +static Atom func (void) { \ + static int generation; \ + static Atom atom; \ + if (generation != serverGeneration) { \ + generation = serverGeneration; \ + atom = MakeAtom (atom_name, strlen (atom_name), TRUE); \ + } \ + return atom; \ +} /* * Typedefs for engine dependent function pointers @@ -299,6 +304,12 @@ typedef Bool (*winCreatePrimarySurfaceProcPtr)(ScreenPtr); typedef Bool (*winReleasePrimarySurfaceProcPtr)(ScreenPtr); +typedef Bool (*winFinishCreateWindowsWindowProcPtr)(WindowPtr pWin); + + +/* Typedef for DIX wrapper functions */ +typedef int (*winDispatchProcPtr) (ClientPtr); + /* * GC (graphics context) privates @@ -337,19 +348,20 @@ typedef struct 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; + * Windows Cursor handling. + */ + +typedef struct { + /* from GetSystemMetrics */ + int sm_cx; + int sm_cy; -#endif /* WIN_NEW_KEYBOARD_SUPPORT */ + BOOL visible; + HCURSOR handle; + QueryBestSizeProcPtr QueryBestSize; + miPointerSpriteFuncPtr spriteFuncs; +} winCursorRec; /* * Screen information structure that we need before privates are available @@ -387,18 +399,22 @@ typedef struct DWORD dwDepth; DWORD dwRefreshRate; char *pfb; - XWDColor *pXWDCmap; - XWDFileHeader *pXWDHeader; DWORD dwEngine; DWORD dwEnginePreferred; DWORD dwClipUpdatesNBoxes; +#ifdef XWIN_EMULATEPSEUDO Bool fEmulatePseudo; +#endif Bool fFullScreen; Bool fDecoration; +#ifdef XWIN_MULTIWINDOWEXTWM + Bool fMWExtWM; +#endif Bool fRootless; +#ifdef XWIN_MULTIWINDOW Bool fMultiWindow; +#endif Bool fMultipleMonitors; - Bool fClipboard; Bool fLessPointer; Bool fScrollbars; Bool fNoTrayIcon; @@ -428,6 +444,8 @@ typedef struct _winPrivScreenRec int iDeltaZ; + int iConnectedClients; + CloseScreenProcPtr CloseScreen; DWORD dwRedMask; @@ -440,26 +458,11 @@ typedef struct _winPrivScreenRec /* 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; @@ -498,17 +501,29 @@ typedef struct _winPrivScreenRec /* Privates used by both shadow fb DirectDraw servers */ LPDIRECTDRAWCLIPPER pddcPrimary; - /* Privates used by multi-window server */ +#ifdef XWIN_MULTIWINDOWEXTWM + /* Privates used by multi-window external window manager */ + RootlessFrameID widTop; + Bool fRestacking; +#endif + +#ifdef XWIN_MULTIWINDOW + /* Privates used by multi-window */ pthread_t ptWMProc; pthread_t ptXMsgProc; void *pWMInfo; - Bool fWindowOrderChanged; - Bool fRestacking; +#endif + +#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) + /* Privates used by both multi-window and rootless */ Bool fRootWindowShown; +#endif +#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) /* Privates used for any module running in a seperate thread */ pthread_mutex_t pmServerStarted; Bool fServerStarted; +#endif /* Engine specific functions */ winAllocateFBProcPtr pwinAllocateFB; @@ -530,6 +545,11 @@ typedef struct _winPrivScreenRec winCreatePrimarySurfaceProcPtr pwinCreatePrimarySurface; winReleasePrimarySurfaceProcPtr pwinReleasePrimarySurface; +#ifdef XWIN_MULTIWINDOW + /* Window Procedures for MultiWindow mode */ + winFinishCreateWindowsWindowProcPtr pwinFinishCreateWindowsWindow; +#endif + /* Window Procedures for Rootless mode */ CreateWindowProcPtr CreateWindow; DestroyWindowProcPtr DestroyWindow; @@ -547,12 +567,35 @@ typedef struct _winPrivScreenRec ClipNotifyProcPtr ClipNotify; RestackWindowProcPtr RestackWindow; ReparentWindowProcPtr ReparentWindow; + ResizeWindowProcPtr ResizeWindow; + MoveWindowProcPtr MoveWindow; #ifdef SHAPE SetShapeProcPtr SetShape; #endif + + winCursorRec cursor; } winPrivScreenRec; +#ifdef XWIN_MULTIWINDOWEXTWM +typedef struct { + RootlessWindowPtr pFrame; + HWND hWnd; + int dwWidthBytes; + BITMAPINFOHEADER *pbmihShadow; + HBITMAP hbmpShadow; + HDC hdcShadow; + HDC hdcScreen; + BOOL fResized; + BOOL fRestackingNow; + BOOL fClose; + BOOL fMovingOrSizing; + BOOL fDestroyed;//for debug + char *pfb; +} win32RootlessWindowRec, *win32RootlessWindowPtr; +#endif + + typedef struct { pointer value; XID id; @@ -576,8 +619,6 @@ 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; @@ -666,29 +707,6 @@ extern FARPROC g_fpTrackMouseEvent; /* - * 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 */ @@ -708,6 +726,18 @@ winAllocateCmapPrivates (ColormapPtr pCmap); /* + * winauth.c + */ + +#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) +# if defined(XCSECURITY) +Bool +winGenerateAuthorization (void); +# endif +#endif + + +/* * winblock.c */ @@ -718,72 +748,39 @@ winBlockHandler (int nScreen, pointer pReadMask); +#ifdef XWIN_NATIVEGDI /* * winclip.c */ RegionPtr winPixmapToRegionNativeGDI (PixmapPtr pPix); +#endif +#ifdef XWIN_CLIPBOARD /* * winclipboardinit.c */ Bool -winInitClipboard (pthread_t *ptClipboardProc, - pthread_mutex_t *ppmServerStarted, - DWORD dwScreen); - -/* - * winclipboardthread.c - */ +winInitClipboard (void); void -winDeinitClipboard (); +winFixClipboardChain (void); +#endif /* * 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); +winSetColormapFunctions (ScreenPtr pScreen); Bool winCreateDefColormap (ScreenPtr pScreen); -Bool -winSetVisualTypesNativeGDI (int nDepth, int nVisuals, int nBitsPerRGB); - -void -winClearVisualTypes (void); - /* * wincreatewnd.c @@ -797,53 +794,47 @@ 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); +void +winDisplayAboutDialog (winPrivScreenPtr pScreenPriv); + /* * winengine.c */ void -winDetectSupportedEngines (); +winDetectSupportedEngines (void); Bool winSetEngine (ScreenPtr pScreen); Bool -winGetDDProcAddresses (); +winGetDDProcAddresses (void); /* * winerror.c */ +#ifdef DDXOSVERRORF void OSVenderVErrorF (const char *pszFormat, va_list va_args); +#endif + +void +winMessageBoxF (const char *pszError, UINT uType, ...); +#ifdef XWIN_NATIVEGDI /* * winfillsp.c */ @@ -855,8 +846,10 @@ winFillSpansNativeGDI (DrawablePtr pDrawable, DDXPointPtr pPoints, int *pWidths, int fSorted); +#endif +#ifdef XWIN_NATIVEGDI /* * winfont.c */ @@ -866,42 +859,20 @@ winRealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont); Bool winUnrealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont); +#endif +#ifdef XWIN_NATIVEGDI /* * 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); +#endif +#ifdef XWIN_NATIVEGDI /* * wingetsp.c */ @@ -913,29 +884,23 @@ winGetSpansNativeGDI (DrawablePtr pDrawable, int *pWidths, int nSpans, char *pDst); +#endif /* - * winkeybd.c + * winglobals.c */ -#if WIN_NEW_KEYBOARD_SUPPORT -winKeyEventsRec -winTranslateKey (DWORD dwVirtualKey, DWORD dwKeyData); -#else void -winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode); -#endif +winInitializeGlobals (void); -void -winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap); -void -winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt, - pointer pCtrl, int iClass); +/* + * winkeybd.c + */ void -winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl); +winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode); int winKeybdProc (DeviceIntPtr pDeviceInt, int iState); @@ -944,63 +909,38 @@ void winInitializeModeKeyStates (void); void -winStoreModeKeyStates (ScreenPtr pScreen); - -void -winRestoreModeKeyStates (ScreenPtr pScreen); +winRestoreModeKeyStates (void); Bool winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam); void -winKeybdReleaseKeys (); +winKeybdReleaseKeys (void); void winSendKeyEvent (DWORD dwKey, Bool fDown); -#if WIN_NEW_KEYBOARD_SUPPORT -void -winProcessKeyEvent (DWORD dwVirtKey, DWORD dwKeyData); -#endif - /* - * winlayer.c + * winkeyhook.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); +winInstallKeyboardHookLL (); -Bool -winRandRSetConfig (ScreenPtr pScreen, - Rotation rotateKind, - RRScreenSizePtr pSize); - -Bool -winRandRInit (ScreenPtr pScreen); -#endif /* RANDR */ -#endif /* WIN_LAYER_SUPPORT */ +void +winRemoveKeyboardHookLL (); /* * winmisc.c */ +#ifdef XWIN_NATIVEGDI void winQueryBestSizeNativeGDI (int class, unsigned short *pWidth, unsigned short *pHeight, ScreenPtr pScreen); +#endif CARD8 winCountBits (DWORD dw); @@ -1008,17 +948,16 @@ winCountBits (DWORD dw); Bool winUpdateFBPointer (ScreenPtr pScreen, void *pbits); +#ifdef XWIN_NATIVEGDI BOOL winPaintBackground (HWND hwnd, COLORREF colorref); +#endif /* * winmouse.c */ -void -winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl); - int winMouseProc (DeviceIntPtr pDeviceInt, int iState); @@ -1033,7 +972,7 @@ winMouseButtonsHandle (ScreenPtr pScreen, int iEventType, int iButton, WPARAM wParam); - +#ifdef XWIN_NATIVEGDI /* * winnativegdi.c */ @@ -1043,78 +982,21 @@ 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); - +#endif +#ifdef XWIN_PRIMARYFB /* * 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); +#endif +#ifdef XWIN_NATIVEGDI /* * winpixmap.c */ @@ -1125,16 +1007,6 @@ 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, @@ -1142,16 +1014,20 @@ winModifyPixmapHeaderNativeGDI (PixmapPtr pPixmap, int iBitsPerPixel, int devKind, pointer pPixData); +#endif +#ifdef XWIN_NATIVEGDI /* * winpntwin.c */ void winPaintWindowNativeGDI (WindowPtr pWin, RegionPtr pRegion, int what); +#endif +#ifdef XWIN_NATIVEGDI /* * winpolyline.c */ @@ -1162,6 +1038,18 @@ winPolyLineNativeGDI (DrawablePtr pDrawable, int mode, int npt, DDXPointPtr ppt); +#endif + + +#ifdef XWIN_NATIVEGDI +/* + * winpushpxl.c + */ + +void +winPushPixels (GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable, + int dx, int dy, int xOrg, int yOrg); +#endif /* @@ -1178,21 +1066,15 @@ winFinishScreenInitFB (int index, ScreenPtr pScreen, int argc, char **argv); +#if defined(XWIN_NATIVEGDI) 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); +#endif +#ifdef XWIN_NATIVEGDI /* * winsetsp.c */ @@ -1205,165 +1087,32 @@ winSetSpansNativeGDI (DrawablePtr pDrawable, int *pWidth, int nSpans, int fSorted); +#endif + /* * 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 @@ -1380,6 +1129,7 @@ winWakeupHandler (int nScreen, * winwindow.c */ +#ifdef XWIN_NATIVEGDI Bool winCreateWindowNativeGDI (WindowPtr pWin); @@ -1402,47 +1152,46 @@ winUnmapWindowNativeGDI (WindowPtr pWindow); Bool winMapWindowNativeGDI (WindowPtr pWindow); +#endif Bool -winCreateWindowPRootless (WindowPtr pWindow); +winCreateWindowRootless (WindowPtr pWindow); Bool -winDestroyWindowPRootless (WindowPtr pWindow); +winDestroyWindowRootless (WindowPtr pWindow); Bool -winPositionWindowPRootless (WindowPtr pWindow, int x, int y); +winPositionWindowRootless (WindowPtr pWindow, int x, int y); Bool -winChangeWindowAttributesPRootless (WindowPtr pWindow, unsigned long mask); +winChangeWindowAttributesRootless (WindowPtr pWindow, unsigned long mask); Bool -winUnmapWindowPRootless (WindowPtr pWindow); +winUnmapWindowRootless (WindowPtr pWindow); Bool -winMapWindowPRootless (WindowPtr pWindow); +winMapWindowRootless (WindowPtr pWindow); #ifdef SHAPE void -winSetShapePRootless (WindowPtr pWindow); +winSetShapeRootless (WindowPtr pWindow); #endif /* - * winmultiwindowicons.c + * winmultiwindowicons.c - Used by both multi-window and Win32Rootless */ HICON -winXIconToHICON (WindowPtr pWin); - -void -winUpdateIcon (Window id); +winXIconToHICON (WindowPtr pWin, int iconSize); +#ifdef XWIN_MULTIWINDOW /* * winmultiwindowshape.c */ -#ifdef SHAPE +# ifdef SHAPE void winReshapeMultiWindow (WindowPtr pWin); @@ -1451,9 +1200,11 @@ winSetShapeMultiWindow (WindowPtr pWindow); void winUpdateRgnMultiWindow (WindowPtr pWindow); +# endif #endif +#ifdef XWIN_MULTIWINDOW /* * winmultiwindowwindow.c */ @@ -1483,18 +1234,28 @@ void winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib); void -winReorderWindowsMultiWindow (ScreenPtr pScreen); +winReorderWindowsMultiWindow (void); void -winMoveXWindow (WindowPtr pWin, int x, int y); +winResizeWindowMultiWindow (WindowPtr pWin, int x, int y, unsigned int w, + unsigned int h, WindowPtr pSib); +void +winMoveWindowMultiWindow (WindowPtr pWin, int x, int y, + WindowPtr pSib, VTKind kind); void -winResizeXWindow (WindowPtr pWin, int w, int h); +winCopyWindowMultiWindow (WindowPtr pWin, DDXPointRec oldpt, + RegionPtr oldRegion); XID winGetWindowID (WindowPtr pWin); +int +winAdjustXWindow (WindowPtr pWin, HWND hwnd); +#endif + +#ifdef XWIN_MULTIWINDOW /* * winmultiwindowwndproc.c */ @@ -1502,6 +1263,7 @@ winGetWindowID (WindowPtr pWin); LRESULT CALLBACK winTopLevelWindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); +#endif /* @@ -1529,6 +1291,123 @@ winWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); +#ifdef XWIN_MULTIWINDOWEXTWM +/* + * winwin32rootless.c + */ + +Bool +winMWExtWMCreateFrame (RootlessWindowPtr pFrame, ScreenPtr pScreen, + int newX, int newY, RegionPtr pShape); + +void +winMWExtWMDestroyFrame (RootlessFrameID wid); + +void +winMWExtWMMoveFrame (RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY); + +void +winMWExtWMResizeFrame (RootlessFrameID wid, ScreenPtr pScreen, + int newX, int newY, unsigned int newW, unsigned int newH, + unsigned int gravity); + +void +winMWExtWMRestackFrame (RootlessFrameID wid, RootlessFrameID nextWid); + +void +winMWExtWMReshapeFrame (RootlessFrameID wid, RegionPtr pShape); + +void +winMWExtWMUnmapFrame (RootlessFrameID wid); + +void +winMWExtWMStartDrawing (RootlessFrameID wid, char **pixelData, int *bytesPerRow); + +void +winMWExtWMStopDrawing (RootlessFrameID wid, Bool flush); + +void +winMWExtWMUpdateRegion (RootlessFrameID wid, RegionPtr pDamage); + +void +winMWExtWMDamageRects (RootlessFrameID wid, int count, const BoxRec *rects, + int shift_x, int shift_y); + +void +winMWExtWMRootlessSwitchWindow (RootlessWindowPtr pFrame, WindowPtr oldWin); + +void +winMWExtWMCopyBytes (unsigned int width, unsigned int height, + const void *src, unsigned int srcRowBytes, + void *dst, unsigned int dstRowBytes); + +void +winMWExtWMFillBytes (unsigned int width, unsigned int height, unsigned int value, + void *dst, unsigned int dstRowBytes); + +int +winMWExtWMCompositePixels (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 +winMWExtWMCopyWindow (RootlessFrameID wid, int dstNrects, const BoxRec *dstRects, + int dx, int dy); +#endif + + +#ifdef XWIN_MULTIWINDOWEXTWM +/* + * winwin32rootlesswindow.c + */ + +void +winMWExtWMReorderWindows (ScreenPtr pScreen); + +void +winMWExtWMMoveXWindow (WindowPtr pWin, int x, int y); + +void +winMWExtWMResizeXWindow (WindowPtr pWin, int w, int h); + +void +winMWExtWMMoveResizeXWindow (WindowPtr pWin, int x, int y, int w, int h); + +void +winMWExtWMUpdateIcon (Window id); +#endif + + +#ifdef XWIN_MULTIWINDOWEXTWM +/* + * winwin32rootlesswndproc.c + */ + +LRESULT CALLBACK +winMWExtWMWindowProc (HWND hwnd, UINT message, + WPARAM wParam, LPARAM lParam); +#endif + + +/* + * winwindowswm.c + */ + +void +winWindowsWMSendEvent (int type, unsigned int mask, int which, int arg, + Window window, int x, int y, int w, int h); + +void +winWindowsWMExtensionInit (void); + +/* + * wincursor.c + */ + +Bool +winInitCursor (ScreenPtr pScreen); + /* * END DDX and DIX Function Prototypes */ diff --git a/hw/xwin/winallpriv.c b/hw/xwin/winallpriv.c index 0da136541..8fca13926 100644 --- a/hw/xwin/winallpriv.c +++ b/hw/xwin/winallpriv.c @@ -33,7 +33,6 @@ #include "win.h" - /* See Porting Layer Definition - p. 58 */ /* * Allocate indexes for the privates that we use. @@ -48,7 +47,7 @@ winAllocatePrivates (ScreenPtr pScreen) winPrivScreenPtr pScreenPriv; #if CYGDEBUG - ErrorF ("winAllocateScreenPrivates - g_ulServerGeneration: %d " + winDebug ("winAllocateScreenPrivates - g_ulServerGeneration: %d " "serverGeneration: %d\n", g_ulServerGeneration, serverGeneration); #endif @@ -120,7 +119,7 @@ Bool winInitCmapPrivates (ColormapPtr pcmap) { #if CYGDEBUG - ErrorF ("winInitCmapPrivates\n"); + winDebug ("winInitCmapPrivates\n"); #endif /* @@ -146,7 +145,7 @@ winAllocateCmapPrivates (ColormapPtr pCmap) static unsigned long s_ulPrivateGeneration = 0; #if CYGDEBUG - ErrorF ("winAllocateCmapPrivates\n"); + winDebug ("winAllocateCmapPrivates\n"); #endif /* Get a new privates index when the server generation changes */ @@ -174,7 +173,7 @@ winAllocateCmapPrivates (ColormapPtr pCmap) winSetCmapPriv (pCmap, pCmapPriv); #if CYGDEBUG - ErrorF ("winAllocateCmapPrivates - Returning\n"); + winDebug ("winAllocateCmapPrivates - Returning\n"); #endif return TRUE; diff --git a/hw/xwin/winauth.c b/hw/xwin/winauth.c new file mode 100644 index 000000000..155ed4add --- /dev/null +++ b/hw/xwin/winauth.c @@ -0,0 +1,129 @@ +#if defined(XCSECURITY) +/* + *Copyright (C) 2003-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "win.h" + +/* Includes for authorization */ +#include "X11/Xauth.h" +#define _SECURITY_SERVER +#include "X11/extensions/security.h" +#include "X11/extensions/securstr.h" + + +/* + * Constants + */ + +#define AUTH_NAME "MIT-MAGIC-COOKIE-1" + + +/* + * Globals + */ + +XID g_authId = 0; +unsigned int g_uiAuthDataLen = 0; +char *g_pAuthData = NULL; + + +/* + * Generate authorization cookie for internal server clients + */ + +Bool +winGenerateAuthorization () +{ + Bool fFreeAuth = FALSE; + SecurityAuthorizationPtr pAuth = NULL; + + /* Call OS layer to generate authorization key */ + g_authId = GenerateAuthorization (strlen (AUTH_NAME), + AUTH_NAME, + 0, + NULL, + &g_uiAuthDataLen, + &g_pAuthData); + if ((XID) ~0L == g_authId) + { + ErrorF ("winGenerateAuthorization - GenerateAuthorization failed\n"); + goto auth_bailout; + } +#if 0 + else + { + ErrorF ("winGenerateAuthorization - GenerateAuthorization success!\n" + "AuthDataLen: %d AuthData: %s\n", + g_uiAuthDataLen, g_pAuthData); + } +#endif + + /* Allocate structure for additional auth information */ + pAuth = (SecurityAuthorizationPtr) + xalloc (sizeof (SecurityAuthorizationRec)); + if (!(pAuth)) + { + ErrorF ("winGenerateAuthorization - Failed allocating " + "SecurityAuthorizationPtr.\n"); + goto auth_bailout; + } + + /* Fill in the auth fields */ + pAuth->id = g_authId; + pAuth->timeout = 0; /* live for x seconds after refcnt == 0 */ + pAuth->group = None; + pAuth->trustLevel = XSecurityClientTrusted; + pAuth->refcnt = 1; /* this auth must stick around */ + pAuth->secondsRemaining = 0; + pAuth->timer = NULL; + pAuth->eventClients = NULL; + + /* Add the authorization to the server's auth list */ + if (!AddResource (g_authId, + SecurityAuthorizationResType, + pAuth)) + { + ErrorF ("winGenerateAuthorization - AddResource failed for auth.\n"); + fFreeAuth = TRUE; + goto auth_bailout; + } + + /* Don't free the auth data, since it is still used internally */ + pAuth = NULL; + + return TRUE; + + auth_bailout: + if (fFreeAuth) + xfree (pAuth); + + return FALSE; +} +#endif diff --git a/hw/xwin/winblock.c b/hw/xwin/winblock.c index 35463493b..a7ca230c5 100644 --- a/hw/xwin/winblock.c +++ b/hw/xwin/winblock.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,21 +15,31 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winblock.c,v 1.5 2002/10/17 08:18:22 alanh Exp $ */ #include "win.h" +#include "winmsg.h" + + +/* + * References to external symbols + */ + +extern HWND g_hDlgDepthChange; +extern HWND g_hDlgExit; +extern HWND g_hDlgAbout; + /* See Porting Layer Definition - p. 6 */ void @@ -41,12 +51,13 @@ winBlockHandler (int nScreen, winScreenPriv((ScreenPtr)pBlockData); MSG msg; +#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) /* Signal threaded modules to begin */ if (pScreenPriv != NULL && !pScreenPriv->fServerStarted) { int iReturn; - ErrorF ("winBlockHandler - Releasing pmServerStarted\n"); + winDebug ("winBlockHandler - Releasing pmServerStarted\n"); /* Flag that modules are to be started */ pScreenPriv->fServerStarted = TRUE; @@ -60,10 +71,11 @@ winBlockHandler (int nScreen, goto winBlockHandler_ProcessMessages; } - ErrorF ("winBlockHandler - pthread_mutex_unlock () returned\n"); + winDebug ("winBlockHandler - pthread_mutex_unlock () returned\n"); } winBlockHandler_ProcessMessages: +#endif /* Process all messages on our queue */ while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) @@ -71,10 +83,11 @@ winBlockHandler_ProcessMessages: if ((g_hDlgDepthChange == 0 || !IsDialogMessage (g_hDlgDepthChange, &msg)) && (g_hDlgExit == 0 - || !IsDialogMessage (g_hDlgExit, &msg))) + || !IsDialogMessage (g_hDlgExit, &msg)) + && (g_hDlgAbout == 0 + || !IsDialogMessage (g_hDlgAbout, &msg))) { DispatchMessage (&msg); } } - winReorderWindowsMultiWindow ((ScreenPtr)pBlockData); } diff --git a/hw/xwin/winclip.c b/hw/xwin/winclip.c index b8d10365d..f7de6265f 100644 --- a/hw/xwin/winclip.c +++ b/hw/xwin/winclip.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,19 +15,18 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclip.c,v 1.1 2001/04/05 20:13:49 dawes Exp $ */ #include "win.h" diff --git a/hw/xwin/winclipboard.h b/hw/xwin/winclipboard.h index 3e7c22fa0..225f50418 100644 --- a/hw/xwin/winclipboard.h +++ b/hw/xwin/winclipboard.h @@ -1,5 +1,7 @@ +#ifndef _WINCLIPBOARD_H_ +#define _WINCLIPBOARD_H_ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,23 +17,18 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * - * Authors: Harold Hunt + * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winwindow.c,v 1.5 2002/11/07 10:31:32 alanh Exp $ */ - - -#ifndef _WINCLIPBOARD_H_ -#define _WINCLIPBOARD_H_ /* Standard library headers */ #include <assert.h> @@ -44,41 +41,42 @@ #include <pthread.h> /* X headers */ -#include "X.h" -#include "Xatom.h" +#include "X11/X.h" +#include "X11/Xatom.h" /* NOTE: For some unknown reason, including Xproto.h solves * tons of problems with including windows.h. Unknowns reasons * are usually bad, so someone should investigate this. */ -#include "Xproto.h" -#include "Xutil.h" -#include "Xlocale.h" +#include "X11/Xproto.h" +#include "X11/Xutil.h" +#include "X11/Xlocale.h" /* Fixups to prevent collisions between Windows and X headers */ #define ATOM DWORD /* Windows headers */ +#ifndef XFree86Server +#define XFree86Server +#endif #include <windows.h> +#undef XFree86Server /* Clipboard module constants */ #define WIN_CLIPBOARD_WINDOW_CLASS "xwinclip" #define WIN_CLIPBOARD_WINDOW_TITLE "xwinclip" #define WIN_MSG_QUEUE_FNAME "/dev/windows" -#define WIN_CONNECT_RETRIES 3 +#define WIN_CONNECT_RETRIES 40 #define WIN_CONNECT_DELAY 4 #define WIN_JMP_OKAY 0 #define WIN_JMP_ERROR_IO 2 +#define WIN_LOCAL_PROPERTY "CYGX_CUT_BUFFER" +#define WIN_XEVENTS_SUCCESS 0 +#define WIN_XEVENTS_SHUTDOWN 1 +#define WIN_XEVENTS_CONVERT 2 +#define WIN_XEVENTS_NOTIFY 3 -/* - * Argument structure for Clipboard module main thread - */ - -typedef struct _ClipboardProcArgRec { - DWORD dwScreen; - pthread_mutex_t *ppmServerStarted; -} ClipboardProcArgRec, *ClipboardProcArgPtr; - +#define WM_WM_REINIT (WM_USER + 1) /* * References to external symbols @@ -86,6 +84,8 @@ typedef struct _ClipboardProcArgRec { extern char *display; extern void ErrorF (const char* /*f*/, ...); +extern void winDebug (const char *format, ...); +extern void winErrorFVerb (int verb, const char *format, ...); /* @@ -93,12 +93,10 @@ extern void ErrorF (const char* /*f*/, ...); */ Bool -winInitClipboard (pthread_t *ptClipboardProc, - pthread_mutex_t *ppmServerStarted, - DWORD dwScreen); +winInitClipboard (void); HWND -winClipboardCreateMessagingWindow (); +winClipboardCreateMessagingWindow (void); /* @@ -117,17 +115,18 @@ winClipboardUNIXtoDOS (unsigned char **ppszData, int iLength); */ void * -winClipboardProc (void *pArg); +winClipboardProc (void *); void -winDeinitClipboard (); +winDeinitClipboard (void); + /* * winclipboardunicode.c */ Bool -winClipboardDetectUnicodeSupport (); +winClipboardDetectUnicodeSupport (void); /* @@ -146,14 +145,8 @@ winClipboardWindowProc (HWND hwnd, UINT message, * winclipboardxevents.c */ -Bool +int winClipboardFlushXEvents (HWND hwnd, - Atom atomClipboard, - Atom atomLocalProperty, - Atom atomUTF8String, - Atom atomCompoundText, - Atom atomTargets, - Atom atomDeleteWindow, int iWindow, Display *pDisplay, Bool fUnicodeSupport); diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c index 0a1977759..01a56cdf0 100644 --- a/hw/xwin/winclipboardinit.c +++ b/hw/xwin/winclipboardinit.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,50 +15,63 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclip.c,v 1.2 2001/06/04 13:04:41 alanh Exp $ */ +#include "dixstruct.h" #include "winclipboard.h" /* + * Local typedefs + */ + +typedef int (*winDispatchProcPtr) (ClientPtr); + +DISPATCH_PROC(winProcSetSelectionOwner); + + +/* + * References to external symbols + */ + +extern pthread_t g_ptClipboardProc; +extern winDispatchProcPtr winProcSetSelectionOwnerOrig; +extern Bool g_fClipboard; +extern HWND g_hwndClipboard; + + +/* * Intialize the Clipboard module */ Bool -winInitClipboard (pthread_t *ptClipboardProc, - pthread_mutex_t *ppmServerStarted, - DWORD dwScreen) +winInitClipboard () { - ClipboardProcArgPtr pArg; - ErrorF ("winInitClipboard ()\n"); - /* Allocate the parameter structure */ - pArg = (ClipboardProcArgPtr) malloc (sizeof (ClipboardProcArgRec)); - if (pArg == NULL) + /* Wrap some internal server functions */ + if (ProcVector[X_SetSelectionOwner] != winProcSetSelectionOwner) { - ErrorF ("winInitClipboard - malloc for ClipboardProcArgRec failed.\n"); - return FALSE; + winProcSetSelectionOwnerOrig = ProcVector[X_SetSelectionOwner]; + ProcVector[X_SetSelectionOwner] = winProcSetSelectionOwner; } - /* Setup the argument structure for the thread function */ - pArg->dwScreen = dwScreen; - pArg->ppmServerStarted = ppmServerStarted; - /* Spawn a thread for the Clipboard module */ - if (pthread_create (ptClipboardProc, NULL, winClipboardProc, pArg)) + if (pthread_create (&g_ptClipboardProc, + NULL, + winClipboardProc, + NULL)) { /* Bail if thread creation failed */ ErrorF ("winInitClipboard - pthread_create failed.\n"); @@ -76,8 +89,8 @@ winInitClipboard (pthread_t *ptClipboardProc, HWND winClipboardCreateMessagingWindow () { - WNDCLASS wc; - HWND hwnd; + WNDCLASS wc; + HWND hwnd; /* Setup our window class */ wc.style = CS_HREDRAW | CS_VREDRAW; @@ -104,7 +117,7 @@ winClipboardCreateMessagingWindow () (HWND) NULL, /* No parent or owner window */ (HMENU) NULL, /* No menu */ GetModuleHandle (NULL),/* Instance handle */ - NULL); /* ScreenPrivates */ + NULL); /* Creation data */ assert (hwnd != NULL); /* I'm not sure, but we may need to call this to start message processing */ @@ -115,3 +128,13 @@ winClipboardCreateMessagingWindow () return hwnd; } + +void +winFixClipboardChain (void) +{ + if (g_fClipboard + && g_hwndClipboard) + { + PostMessage (g_hwndClipboard, WM_WM_REINIT, 0, 0); + } +} diff --git a/hw/xwin/winclipboardtextconv.c b/hw/xwin/winclipboardtextconv.c index 2f11b9241..c657428f8 100644 --- a/hw/xwin/winclipboardtextconv.c +++ b/hw/xwin/winclipboardtextconv.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,30 +15,33 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclip.c,v 1.2 2001/06/04 13:04:41 alanh Exp $ */ #include "win.h" #include <stdio.h> #include <stdlib.h> +void +winClipboardDOStoUNIX (char *pszSrc, int iLength); +void +winClipboardUNIXtoDOS (unsigned char **ppszData, int iLength); /* * Convert \r\n to \n * - * NOTE: This was heavily inspired by, if not down right stolen from, - * Cygwin's winsup/cygwin/fhandler.cc/fhandler_base::read () + * NOTE: This was heavily inspired by, Cygwin's + * winsup/cygwin/fhandler.cc/fhandler_base::read () */ void diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c index 7a746a0b3..4987c99dd 100644 --- a/hw/xwin/winclipboardthread.c +++ b/hw/xwin/winclipboardthread.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,27 +15,44 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclip.c,v 1.2 2001/06/04 13:04:41 alanh Exp $ */ #include "winclipboard.h" +#include "X11/Xauth.h" + + +/* + * Constants + */ + +#define AUTH_NAME "MIT-MAGIC-COOKIE-1" + /* * References to external symbols */ -extern Bool g_fCalledSetLocale; +extern Bool g_fUnicodeClipboard; +extern unsigned long serverGeneration; +#if defined(XCSECURITY) +extern unsigned int g_uiAuthDataLen; +extern char *g_pAuthData; +#endif +extern Bool g_fClipboardStarted; +extern HWND g_hwndClipboard; +extern void *g_pClipboardDisplay; +extern Window g_iClipboardWindow; /* @@ -43,7 +60,7 @@ extern Bool g_fCalledSetLocale; */ static jmp_buf g_jmpEntry; -static Bool g_shutdown = FALSE; +Bool g_fUnicodeSupport = FALSE; /* @@ -62,72 +79,28 @@ winClipboardIOErrorHandler (Display *pDisplay); */ void * -winClipboardProc (void *pArg) +winClipboardProc (void *pvNotUsed) { Atom atomClipboard, atomClipboardManager; - Atom atomLocalProperty, atomCompoundText; - Atom atomUTF8String, atomTargets; int iReturn; HWND hwnd = NULL; - int iConnectionNumber; - int fdMessageQueue; + int iConnectionNumber = 0; + int fdMessageQueue = 0; fd_set fdsRead; int iMaxDescriptor; - Display *pDisplay; - Window iWindow; - Atom atomDeleteWindow; - Bool fReturn; + Display *pDisplay = NULL; + Window iWindow = None; int iRetries; Bool fUnicodeSupport; char szDisplay[512]; - ClipboardProcArgPtr pProcArg = (ClipboardProcArgPtr) pArg; ErrorF ("winClipboardProc - Hello\n"); - /* Check that argument pointer is not invalid */ - if (pArg == NULL) - { - ErrorF ("winClipboardProc - pArg is NULL, bailing.\n"); - pthread_exit (NULL); - } - - ErrorF ("winClipboardProc - Calling pthread_mutex_lock ()\n"); - - /* Grab the server started mutex - pause until we get it */ - iReturn = pthread_mutex_lock (pProcArg->ppmServerStarted); - if (iReturn != 0) - { - ErrorF ("winClipboardProc - pthread_mutex_lock () failed: %d\n", - iReturn); - pthread_exit (NULL); - } - - ErrorF ("winClipboardProc - pthread_mutex_lock () returned.\n"); - /* Do we have Unicode support? */ - fUnicodeSupport = winClipboardDetectUnicodeSupport (); + fUnicodeSupport = g_fUnicodeClipboard && winClipboardDetectUnicodeSupport (); - /* Set the current locale? What does this do? */ - if (fUnicodeSupport && !g_fCalledSetLocale) - { - ErrorF ("winClipboardProc - Calling setlocale ()\n"); - if (!setlocale (LC_ALL, "")) - { - ErrorF ("winClipboardProc - setlocale () error\n"); - pthread_exit (NULL); - } - ErrorF ("winClipboardProc - setlocale () returned\n"); - - /* See if X supports the current locale */ - if (XSupportsLocale () == False) - { - ErrorF ("winClipboardProc - Locale not supported by X\n"); - pthread_exit (NULL); - } - } - - /* Flag that we have called setlocale */ - g_fCalledSetLocale = TRUE; + /* Save the Unicode support flag in a global */ + g_fUnicodeSupport = fUnicodeSupport; /* Allow multiple threads to access Xlib */ if (XInitThreads () == 0) @@ -136,12 +109,12 @@ winClipboardProc (void *pArg) pthread_exit (NULL); } - ErrorF ("winClipboardProc - XInitThreads () returned.\n"); - - /* Release the server started mutex */ - pthread_mutex_unlock (pProcArg->ppmServerStarted); - - ErrorF ("winClipboardProc - pthread_mutex_unlock () returned.\n"); + /* See if X supports the current locale */ + if (XSupportsLocale () == False) + { + ErrorF ("winClipboardProc - Locale not supported by X. Exiting.\n"); + pthread_exit (NULL); + } /* Set jump point for Error exits */ iReturn = setjmp (g_jmpEntry); @@ -155,26 +128,40 @@ winClipboardProc (void *pArg) iReturn); pthread_exit (NULL); } - else if (g_shutdown) - { - /* Shutting down, the X server severed out connection! */ - ErrorF ("winClipboardProc - Detected shutdown in progress\n"); - pthread_exit (NULL); - } else if (iReturn == WIN_JMP_ERROR_IO) { - ErrorF ("winClipboardProc - setjmp returned and hwnd: %08x\n", hwnd); + /* TODO: Cleanup the Win32 window and free any allocated memory */ + ErrorF ("winClipboardProc - setjmp returned for IO Error Handler.\n"); + pthread_exit (NULL); } +#if defined(XCSECURITY) + /* Use our generated cookie for authentication */ + XSetAuthorization (AUTH_NAME, + strlen (AUTH_NAME), + g_pAuthData, + g_uiAuthDataLen); +#endif + + /* Set error handler */ + XSetErrorHandler (winClipboardErrorHandler); + XSetIOErrorHandler (winClipboardIOErrorHandler); + /* Initialize retry count */ iRetries = 0; /* Setup the display connection string x */ + /* + * NOTE: Always connect to screen 0 since we require that screen + * numbers start at 0 and increase without gaps. We only need + * to connect to one screen on the display to get events + * for all screens on the display. That is why there is only + * one clipboard client thread. + */ snprintf (szDisplay, 512, - "127.0.0.1:%s.%d", - display, - (int) pProcArg->dwScreen); + "127.0.0.1:%s.0", + display); /* Print the display connection string */ ErrorF ("winClipboardProc - DISPLAY=%s\n", szDisplay); @@ -204,12 +191,12 @@ winClipboardProc (void *pArg) pthread_exit (NULL); } + /* Save the display in the screen privates */ + g_pClipboardDisplay = pDisplay; + ErrorF ("winClipboardProc - XOpenDisplay () returned and " "successfully opened the display.\n"); - /* Create Windows messaging window */ - hwnd = winClipboardCreateMessagingWindow (); - /* Get our connection number */ iConnectionNumber = ConnectionNumber (pDisplay); @@ -233,6 +220,13 @@ winClipboardProc (void *pArg) ErrorF ("winClipboardProc - XSelectInput generated BadWindow " "on RootWindow\n\n"); + /* Create atoms */ + atomClipboard = XInternAtom (pDisplay, "CLIPBOARD", False); + atomClipboardManager = XInternAtom (pDisplay, "CLIPBOARD_MANAGER", False); + + /* FIXME: Save some values as globals for the window proc */ + g_fUnicodeSupport = fUnicodeSupport; + /* Create a messaging window */ iWindow = XCreateSimpleWindow (pDisplay, DefaultRootWindow (pDisplay), @@ -243,27 +237,24 @@ winClipboardProc (void *pArg) BlackPixel (pDisplay, 0)); if (iWindow == 0) { - ErrorF ("winClipboardProc - Could not create a window\n"); + ErrorF ("winClipboardProc - Could not create an X window.\n"); pthread_exit (NULL); } - /* This looks like our only hope for getting a message before shutdown */ - /* Register for WM_DELETE_WINDOW message from window manager */ - atomDeleteWindow = XInternAtom (pDisplay, "WM_DELETE_WINDOW", False); - XSetWMProtocols (pDisplay, iWindow, &atomDeleteWindow, 1); +#if 0 + ErrorF ("winClipboardProc - iWindow: %d\n", iWindow); +#endif - /* Set error handler */ - XSetErrorHandler (winClipboardErrorHandler); - XSetIOErrorHandler (winClipboardIOErrorHandler); + /* Save the window in the screen privates */ + g_iClipboardWindow = iWindow; - /* Create an atom for CLIPBOARD_MANAGER */ - atomClipboardManager = XInternAtom (pDisplay, "CLIPBOARD_MANAGER", False); - if (atomClipboardManager == None) - { - ErrorF ("winClipboardProc - Could not create CLIPBOARD_MANAGER atom\n"); - pthread_exit (NULL); - } + /* Create Windows messaging window */ + hwnd = winClipboardCreateMessagingWindow (); + + /* Save copy of HWND in screen privates */ + g_hwndClipboard = hwnd; +#if 0 /* Assert ownership of CLIPBOARD_MANAGER */ iReturn = XSetSelectionOwner (pDisplay, atomClipboardManager, iWindow, CurrentTime); @@ -272,63 +263,28 @@ winClipboardProc (void *pArg) ErrorF ("winClipboardProc - Could not set CLIPBOARD_MANAGER owner\n"); pthread_exit (NULL); } +#endif - /* Create an atom for CLIPBOARD */ - atomClipboard = XInternAtom (pDisplay, "CLIPBOARD", False); - if (atomClipboard == None) - { - ErrorF ("winClipboardProc - Could not create CLIPBOARD atom\n"); - pthread_exit (NULL); - } - - /* Assert ownership of CLIPBOARD */ - iReturn = XSetSelectionOwner (pDisplay, atomClipboard, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardProc - Could not set CLIPBOARD owner\n"); - pthread_exit (NULL); - } - - /* Assert ownership of PRIMARY */ - iReturn = XSetSelectionOwner (pDisplay, XA_PRIMARY, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardProc - Could not set PRIMARY owner\n"); - pthread_exit (NULL); - } - - /* Local property to hold pasted data */ - atomLocalProperty = XInternAtom (pDisplay, "CYGX_CUT_BUFFER", False); - if (atomLocalProperty == None) - { - ErrorF ("winClipboardProc - Could not create CYGX_CUT_BUFFER atom\n"); - pthread_exit (NULL); - } - - /* Create an atom for UTF8_STRING */ - atomUTF8String = XInternAtom (pDisplay, "UTF8_STRING", False); - if (atomUTF8String == None) - { - ErrorF ("winClipboardProc - Could not create UTF8_STRING atom\n"); - pthread_exit (NULL); - } - - /* Create an atom for COMPOUND_TEXT */ - atomCompoundText = XInternAtom (pDisplay, "COMPOUND_TEXT", False); - if (atomCompoundText == None) + /* Assert ownership of selections if Win32 clipboard is owned */ + if (NULL != GetClipboardOwner ()) { - ErrorF ("winClipboardProc - Could not create COMPOUND_TEXT atom\n"); - pthread_exit (NULL); - } + /* PRIMARY */ + iReturn = XSetSelectionOwner (pDisplay, XA_PRIMARY, + iWindow, CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + ErrorF ("winClipboardProc - Could not set PRIMARY owner\n"); + pthread_exit (NULL); + } - /* Create an atom for TARGETS */ - atomTargets = XInternAtom (pDisplay, "TARGETS", False); - if (atomTargets == None) - { - ErrorF ("winClipboardProc - Could not create TARGETS atom\n"); - pthread_exit (NULL); + /* CLIPBOARD */ + iReturn = XSetSelectionOwner (pDisplay, atomClipboard, + iWindow, CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + ErrorF ("winClipboardProc - Could not set CLIPBOARD owner\n"); + pthread_exit (NULL); + } } /* Pre-flush X events */ @@ -338,12 +294,6 @@ winClipboardProc (void *pArg) * already. */ winClipboardFlushXEvents (hwnd, - atomClipboard, - atomLocalProperty, - atomUTF8String, - atomCompoundText, - atomTargets, - atomDeleteWindow, iWindow, pDisplay, fUnicodeSupport); @@ -352,6 +302,9 @@ winClipboardProc (void *pArg) if (!winClipboardFlushWindowsMessageQueue (hwnd)) return 0; + /* Signal that the clipboard client has started */ + g_fClipboardStarted = TRUE; + /* Loop for X events */ while (1) { @@ -377,7 +330,7 @@ winClipboardProc (void *pArg) "Bailing.\n", iReturn); break; } - + /* Branch on which descriptor became active */ if (FD_ISSET (iConnectionNumber, &fdsRead)) { @@ -388,20 +341,14 @@ winClipboardProc (void *pArg) /* Process X events */ /* Exit when we see that server is shutting down */ - fReturn = winClipboardFlushXEvents (hwnd, - atomClipboard, - atomLocalProperty, - atomUTF8String, - atomCompoundText, - atomTargets, - atomDeleteWindow, + iReturn = winClipboardFlushXEvents (hwnd, iWindow, pDisplay, fUnicodeSupport); - if (!fReturn) + if (WIN_XEVENTS_SHUTDOWN == iReturn) { - ErrorF ("winClipboardProc - Caught WM_DELETE_WINDOW - " - "shutting down\n"); + ErrorF ("winClipboardProc - winClipboardFlushXEvents " + "trapped shutdown event, exiting main loop.\n"); break; } } @@ -413,14 +360,58 @@ winClipboardProc (void *pArg) #if 0 ErrorF ("winClipboardProc - Windows event ready\n"); #endif - + /* Process Windows messages */ if (!winClipboardFlushWindowsMessageQueue (hwnd)) - break; + { + ErrorF ("winClipboardProc - " + "winClipboardFlushWindowsMessageQueue trapped " + "WM_QUIT message, exiting main loop.\n"); + break; + } } } - return 0; + /* Close our X window */ + if (pDisplay && iWindow) + { + iReturn = XDestroyWindow (pDisplay, iWindow); + if (iReturn == BadWindow) + ErrorF ("winClipboardProc - XDestroyWindow returned BadWindow.\n"); + else + ErrorF ("winClipboardProc - XDestroyWindow succeeded.\n"); + } + + /* Close our Win32 message handle */ + if (fdMessageQueue) + close (fdMessageQueue); + +#if 0 + /* + * FIXME: XCloseDisplay hangs if we call it, as of 2004/03/26. The + * XSync and XSelectInput calls did not help. + */ + + /* Discard any remaining events */ + XSync (pDisplay, TRUE); + + /* Select event types to watch */ + XSelectInput (pDisplay, + DefaultRootWindow (pDisplay), + None); + + /* Close our X display */ + if (pDisplay) + { + XCloseDisplay (pDisplay); + } +#endif + + g_iClipboardWindow = None; + g_pClipboardDisplay = NULL; + g_hwndClipboard = NULL; + + return NULL; } @@ -439,19 +430,6 @@ winClipboardErrorHandler (Display *pDisplay, XErrorEvent *pErr) sizeof (pszErrorMsg)); ErrorF ("winClipboardErrorHandler - ERROR: \n\t%s\n", pszErrorMsg); - if (pErr->error_code == BadWindow - || pErr->error_code == BadMatch - || pErr->error_code == BadDrawable) - { -#if 0 - pthread_exit (NULL); -#endif - } - -#if 0 - pthread_exit (NULL); -#endif - return 0; } @@ -463,22 +441,10 @@ winClipboardErrorHandler (Display *pDisplay, XErrorEvent *pErr) static int winClipboardIOErrorHandler (Display *pDisplay) { - printf ("\nwinClipboardIOErrorHandler!\n\n"); + ErrorF ("\nwinClipboardIOErrorHandler!\n\n"); /* Restart at the main entry point */ longjmp (g_jmpEntry, WIN_JMP_ERROR_IO); return 0; } - - -/* - * Notify the clipboard thread we're exiting and not to reconnect - */ - -void -winDeinitClipboard () -{ - ErrorF ("winDeinitClipboard - Noting shutdown in progress\n"); - g_shutdown = TRUE; -} diff --git a/hw/xwin/winclipboardunicode.c b/hw/xwin/winclipboardunicode.c index bda09b79f..48a10fdba 100644 --- a/hw/xwin/winclipboardunicode.c +++ b/hw/xwin/winclipboardunicode.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,21 +15,20 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclip.c,v 1.2 2001/06/04 13:04:41 alanh Exp $ */ -#include "win.h" +#include "winclipboard.h" /* @@ -38,13 +37,12 @@ */ Bool -winClipboardDetectUnicodeSupport () +winClipboardDetectUnicodeSupport (void) { Bool fReturn = FALSE; - OSVERSIONINFO osvi; + OSVERSIONINFO osvi = {0}; /* Get operating system version information */ - ZeroMemory (&osvi, sizeof (osvi)); osvi.dwOSVersionInfoSize = sizeof (osvi); GetVersionEx (&osvi); @@ -52,13 +50,13 @@ winClipboardDetectUnicodeSupport () switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: - /* Engine 4 is supported on NT only */ + /* Unicode supported on NT only */ ErrorF ("DetectUnicodeSupport - Windows NT/2000/XP\n"); fReturn = TRUE; break; case VER_PLATFORM_WIN32_WINDOWS: - /* Engine 4 is supported on NT only */ + /* Unicode is not supported on non-NT */ ErrorF ("DetectUnicodeSupport - Windows 95/98/Me\n"); fReturn = FALSE; break; diff --git a/hw/xwin/winclipboardwndproc.c b/hw/xwin/winclipboardwndproc.c index f8e52a0ef..947db682c 100644 --- a/hw/xwin/winclipboardwndproc.c +++ b/hw/xwin/winclipboardwndproc.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,24 +15,121 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclip.c,v 1.2 2001/06/04 13:04:41 alanh Exp $ */ #include "winclipboard.h" /* + * Constants + */ + +#define WIN_CLIPBOARD_PROP "cyg_clipboard_prop" +#define WIN_POLL_TIMEOUT 1 + + +/* + * References to external symbols + */ + +extern Bool g_fUnicodeSupport; +extern void *g_pClipboardDisplay; +extern Window g_iClipboardWindow; +extern Atom g_atomLastOwnedSelection; + + +/* + * Local function prototypes + */ + +static Bool +winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay, + Bool fUnicodeSupport, int iTimeoutSec); + + +/* + * Process X events up to specified timeout + */ + +static int +winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay, + Bool fUnicodeSupport, int iTimeoutSec) +{ + int iConnNumber; + struct timeval tv; + int iReturn; + DWORD dwStopTime = (GetTickCount () / 1000) + iTimeoutSec; + + /* We need to ensure that all pending events are processed */ + XSync (pDisplay, FALSE); + + /* Get our connection number */ + iConnNumber = ConnectionNumber (pDisplay); + + /* Loop for X events */ + while (1) + { + fd_set fdsRead; + + /* Setup the file descriptor set */ + FD_ZERO (&fdsRead); + FD_SET (iConnNumber, &fdsRead); + + /* Adjust timeout */ + tv.tv_sec = dwStopTime - (GetTickCount () / 1000); + tv.tv_usec = 0; + + /* Break out if no time left */ + if (tv.tv_sec < 0) + return WIN_XEVENTS_SUCCESS; + + /* Wait for a Windows event or an X event */ + iReturn = select (iConnNumber + 1,/* Highest fds number */ + &fdsRead, /* Read mask */ + NULL, /* No write mask */ + NULL, /* No exception mask */ + &tv); /* No timeout */ + if (iReturn <= 0) + { + ErrorF ("winProcessXEventsTimeout - Call to select () failed: %d. " + "Bailing.\n", iReturn); + break; + } + + /* Branch on which descriptor became active */ + if (FD_ISSET (iConnNumber, &fdsRead)) + { + /* Process X events */ + /* Exit when we see that server is shutting down */ + iReturn = winClipboardFlushXEvents (hwnd, + iWindow, + pDisplay, + fUnicodeSupport); + if (WIN_XEVENTS_NOTIFY == iReturn + || WIN_XEVENTS_CONVERT == iReturn) + { + /* Bail out if convert or notify processed */ + return iReturn; + } + } + } + + return WIN_XEVENTS_SUCCESS; +} + + +/* * Process a given Windows message */ @@ -40,18 +137,413 @@ LRESULT CALLBACK winClipboardWindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { + static HWND s_hwndNextViewer; + static Bool s_fCBCInitialized; + /* Branch on message type */ switch (message) { case WM_DESTROY: - PostQuitMessage (0); + { + winDebug ("winClipboardWindowProc - WM_DESTROY\n"); + + /* Remove ourselves from the clipboard chain */ + ChangeClipboardChain (hwnd, s_hwndNextViewer); + + s_hwndNextViewer = NULL; + + PostQuitMessage (0); + } return 0; + case WM_CREATE: -#if 0 - ErrorF ("WindowProc - WM_CREATE\n"); -#endif + { + winDebug ("winClipboardWindowProc - WM_CREATE\n"); + + /* Add ourselves to the clipboard viewer chain */ + s_hwndNextViewer = SetClipboardViewer (hwnd); + if (s_hwndNextViewer == hwnd) + { + s_hwndNextViewer = NULL; + winErrorFVerb (1, "winClipboardWindowProc - WM_CREATE: " + "attempted to set next window to ourselves."); + } + } + return 0; + + + case WM_CHANGECBCHAIN: + { + static Bool s_fProcessingChangeCBChain = FALSE; + winDebug ("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%x) " + "lParam(%x) s_hwndNextViewer(%x)\n", + wParam, lParam, s_hwndNextViewer); + + + /* + * We've occasionally seen a loop in the clipboard chain. Break + * it on the first hint of recursion. + */ + if (! s_fProcessingChangeCBChain) + { + s_fProcessingChangeCBChain = TRUE; + } + else + { + winErrorFVerb (1, "winClipboardWindowProc - WM_CHANGECBCHAIN - " + "Nested calls detected. Bailing.\n"); + winDebug ("winClipboardWindowProc - WM_CHANGECBCHAIN: Exit\n"); + return 0; + } + + if ((HWND) wParam == s_hwndNextViewer) + { + s_hwndNextViewer = (HWND) lParam; + if (s_hwndNextViewer == hwnd) + { + s_hwndNextViewer = NULL; + winErrorFVerb (1, "winClipboardWindowProc - WM_CHANGECBCHAIN: " + "attempted to set next window to ourselves."); + } + } + else if (s_hwndNextViewer) + SendMessage (s_hwndNextViewer, message, + wParam, lParam); + + s_fProcessingChangeCBChain = FALSE; + } + winDebug ("winClipboardWindowProc - WM_CHANGECBCHAIN: Exit\n"); return 0; + + case WM_WM_REINIT: + { + /* Ensure that we're in the clipboard chain. Some apps, + * WinXP's remote desktop for one, don't play nice with the + * chain. This message is called whenever we receive a + * WM_ACTIVATEAPP message to ensure that we continue to + * receive clipboard messages. + * + * It might be possible to detect if we're still in the chain + * by calling SendMessage (GetClipboardViewer(), + * WM_DRAWCLIPBOARD, 0, 0); and then seeing if we get the + * WM_DRAWCLIPBOARD message. That, however, might be more + * expensive than just putting ourselves back into the chain. + */ + + winDebug ("winClipboardWindowProc - WM_WM_REINIT: Enter\n"); + if (hwnd != GetClipboardViewer ()) + { + winDebug (" WM_WM_REINIT: Replacing us(%x) with %x at head " + "of chain\n", hwnd, s_hwndNextViewer); + s_fCBCInitialized = FALSE; + ChangeClipboardChain (hwnd, s_hwndNextViewer); + s_hwndNextViewer = NULL; + s_fCBCInitialized = FALSE; + winDebug (" WM_WM_REINIT: Putting us back at head of chain.\n"); + s_hwndNextViewer = SetClipboardViewer (hwnd); + if (s_hwndNextViewer == hwnd) + { + s_hwndNextViewer = NULL; + winErrorFVerb (1, "winClipboardWindowProc - WM_WM_REINIT: " + "attempted to set next window to ourselves.\n"); + } + } + else + { + winDebug (" WM_WM_REINIT: already at head of viewer chain.\n"); + } + } + winDebug ("winClipboardWindowProc - WM_WM_REINIT: Exit\n"); + return 0; + + + case WM_DRAWCLIPBOARD: + { + static Bool s_fProcessingDrawClipboard = FALSE; + Display *pDisplay = g_pClipboardDisplay; + Window iWindow = g_iClipboardWindow; + int iReturn; + + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n"); + + /* + * We've occasionally seen a loop in the clipboard chain. Break + * it on the first hint of recursion. + */ + if (! s_fProcessingDrawClipboard) + { + s_fProcessingDrawClipboard = TRUE; + } + else + { + winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Nested calls detected. Bailing.\n"); + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); + return 0; + } + + /* Pass the message on the next window in the clipboard viewer chain */ + if (s_hwndNextViewer) + SendMessage (s_hwndNextViewer, message, 0, 0); + + /* Bail on first message */ + if (!s_fCBCInitialized) + { + s_fCBCInitialized = TRUE; + s_fProcessingDrawClipboard = FALSE; + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); + return 0; + } + + /* + * NOTE: We cannot bail out when NULL == GetClipboardOwner () + * because some applications deal with the clipboard in a manner + * that causes the clipboard owner to be NULL when they are in + * fact taking ownership. One example of this is the Win32 + * native compile of emacs. + */ + + /* Bail when we still own the clipboard */ + if (hwnd == GetClipboardOwner ()) + { + + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "We own the clipboard, returning.\n"); + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); + s_fProcessingDrawClipboard = FALSE; + return 0; + } + + /* + * Do not take ownership of the X11 selections when something + * other than CF_TEXT or CF_UNICODETEXT has been copied + * into the Win32 clipboard. + */ + if (!IsClipboardFormatAvailable (CF_TEXT) + && !IsClipboardFormatAvailable (CF_UNICODETEXT)) + { + + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Clipboard does not contain CF_TEXT nor " + "CF_UNICODETEXT.\n"); + + /* + * We need to make sure that the X Server has processed + * previous XSetSelectionOwner messages. + */ + XSync (pDisplay, FALSE); + + /* Release PRIMARY selection if owned */ + iReturn = XGetSelectionOwner (pDisplay, XA_PRIMARY); + if (iReturn == g_iClipboardWindow) + { + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "PRIMARY selection is owned by us.\n"); + XSetSelectionOwner (pDisplay, + XA_PRIMARY, + None, + CurrentTime); + } + else if (BadWindow == iReturn || BadAtom == iReturn) + winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "XGetSelection failed for PRIMARY: %d\n", iReturn); + + /* Release CLIPBOARD selection if owned */ + iReturn = XGetSelectionOwner (pDisplay, + XInternAtom (pDisplay, + "CLIPBOARD", + False)); + if (iReturn == g_iClipboardWindow) + { + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "CLIPBOARD selection is owned by us.\n"); + XSetSelectionOwner (pDisplay, + XInternAtom (pDisplay, + "CLIPBOARD", + False), + None, + CurrentTime); + } + else if (BadWindow == iReturn || BadAtom == iReturn) + winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "XGetSelection failed for CLIPBOARD: %d\n", iReturn); + + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); + s_fProcessingDrawClipboard = FALSE; + return 0; + } + + /* Reassert ownership of PRIMARY */ + iReturn = XSetSelectionOwner (pDisplay, + XA_PRIMARY, + iWindow, + CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Could not reassert ownership of PRIMARY\n"); + } + else + { + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Reasserted ownership of PRIMARY\n"); + } + + /* Reassert ownership of the CLIPBOARD */ + iReturn = XSetSelectionOwner (pDisplay, + XInternAtom (pDisplay, + "CLIPBOARD", + False), + iWindow, + CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Could not reassert ownership of CLIPBOARD\n"); + } + else + { + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Reasserted ownership of CLIPBOARD\n"); + } + + /* Flush the pending SetSelectionOwner event now */ + XFlush (pDisplay); + + s_fProcessingDrawClipboard = FALSE; + } + winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); + return 0; + + + case WM_DESTROYCLIPBOARD: + /* + * NOTE: Intentionally do nothing. + * Changes in the Win32 clipboard are handled by WM_DRAWCLIPBOARD + * above. We only process this message to conform to the specs + * for delayed clipboard rendering in Win32. You might think + * that we need to release ownership of the X11 selections, but + * we do not, because a WM_DRAWCLIPBOARD message will closely + * follow this message and reassert ownership of the X11 + * selections, handling the issue for us. + */ + return 0; + + + case WM_RENDERFORMAT: + case WM_RENDERALLFORMATS: + { + int iReturn; + Display *pDisplay = g_pClipboardDisplay; + Window iWindow = g_iClipboardWindow; + Bool fConvertToUnicode; + + winDebug ("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n"); + + /* Flag whether to convert to Unicode or not */ + if (message == WM_RENDERALLFORMATS) + fConvertToUnicode = FALSE; + else + fConvertToUnicode = g_fUnicodeSupport && (CF_UNICODETEXT == wParam); + + /* Request the selection contents */ + iReturn = XConvertSelection (pDisplay, + g_atomLastOwnedSelection, + XInternAtom (pDisplay, + "COMPOUND_TEXT", False), + XInternAtom (pDisplay, + "CYGX_CUT_BUFFER", False), + iWindow, + CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + winErrorFVerb (1, "winClipboardWindowProc - WM_RENDER*FORMAT - " + "XConvertSelection () failed\n"); + break; + } + + /* Special handling for WM_RENDERALLFORMATS */ + if (message == WM_RENDERALLFORMATS) + { + /* We must open and empty the clipboard */ + + /* Close clipboard if we have it open already */ + if (GetOpenClipboardWindow () == hwnd) + { + CloseClipboard (); + } + + if (!OpenClipboard (hwnd)) + { + winErrorFVerb (1, "winClipboardWindowProc - WM_RENDER*FORMATS - " + "OpenClipboard () failed: %08x\n", + GetLastError ()); + break; + } + + if (!EmptyClipboard ()) + { + winErrorFVerb (1, "winClipboardWindowProc - WM_RENDER*FORMATS - " + "EmptyClipboard () failed: %08x\n", + GetLastError ()); + break; + } + } + + /* Process the SelectionNotify event */ + iReturn = winProcessXEventsTimeout (hwnd, + iWindow, + pDisplay, + fConvertToUnicode, + WIN_POLL_TIMEOUT); + if (WIN_XEVENTS_CONVERT == iReturn) + { + /* + * The selection was offered for conversion first, so we have + * to process a second SelectionNotify event to get the actual + * data in the selection. + */ + iReturn = winProcessXEventsTimeout (hwnd, + iWindow, + pDisplay, + fConvertToUnicode, + WIN_POLL_TIMEOUT); + } + + /* + * The last of the up-to two calls to winProcessXEventsTimeout + * from above had better have seen a notify event, or else we + * are dealing with a buggy or old X11 app. In these cases we + * have to paste some fake data to the Win32 clipboard to + * satisfy the requirement that we write something to it. + */ + if (WIN_XEVENTS_NOTIFY != iReturn) + { + /* Paste no data, to satisfy required call to SetClipboardData */ + if (fConvertToUnicode) + SetClipboardData (CF_UNICODETEXT, NULL); + else + SetClipboardData (CF_TEXT, NULL); + } + + /* Special handling for WM_RENDERALLFORMATS */ + if (message == WM_RENDERALLFORMATS) + { + /* We must close the clipboard */ + + if (!CloseClipboard ()) + { + winErrorFVerb (1, "winClipboardWindowProc - WM_RENDERALLFORMATS - " + "CloseClipboard () failed: %08x\n", + GetLastError ()); + break; + } + } + + winDebug ("winClipboardWindowProc - WM_RENDER*FORMAT - Returning.\n"); + return 0; + } } /* Let Windows perform default processing for unhandled messages */ diff --git a/hw/xwin/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c new file mode 100755 index 000000000..910699dc3 --- /dev/null +++ b/hw/xwin/winclipboardwrappers.c @@ -0,0 +1,541 @@ +/* + *Copyright (C) 2003-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "win.h" +#include "dixstruct.h" +#include "X11/Xatom.h" + + +/* + * Constants + */ + +#define CLIP_NUM_SELECTIONS 2 +#define CLIP_OWN_PRIMARY 0 +#define CLIP_OWN_CLIPBOARD 1 + + +/* + * Local function prototypes + */ + +DISPATCH_PROC(winProcEstablishConnection); +DISPATCH_PROC(winProcQueryTree); +DISPATCH_PROC(winProcSetSelectionOwner); + + +/* + * References to external symbols + */ + +extern Bool g_fUnicodeSupport; +extern int g_iNumScreens; +extern unsigned int g_uiAuthDataLen; +extern char *g_pAuthData; +extern Bool g_fXdmcpEnabled; +extern Bool g_fClipboardLaunched; +extern Bool g_fClipboardStarted; +extern Bool g_fClipboard; +extern Window g_iClipboardWindow; +extern Atom g_atomLastOwnedSelection; +extern HWND g_hwndClipboard; + +extern winDispatchProcPtr winProcEstablishConnectionOrig; +extern winDispatchProcPtr winProcQueryTreeOrig; +extern winDispatchProcPtr winProcSetSelectionOwnerOrig; + + +/* + * Wrapper for internal QueryTree function. + * Hides the clipboard client when it is the only client remaining. + */ + +int +winProcQueryTree (ClientPtr client) +{ + int iReturn; + + /* + * This procedure is only used for initialization. + * We can unwrap the original procedure at this point + * so that this function is no longer called until the + * server resets and the function is wrapped again. + */ + ProcVector[X_QueryTree] = winProcQueryTreeOrig; + + /* + * Call original function and bail if it fails. + * NOTE: We must do this first, since we need XdmcpOpenDisplay + * to be called before we initialize our clipboard client. + */ + iReturn = (*winProcQueryTreeOrig) (client); + if (iReturn != 0) + { + ErrorF ("winProcQueryTree - ProcQueryTree failed, bailing.\n"); + return iReturn; + } + + /* Make errors more obvious */ + winProcQueryTreeOrig = NULL; + + /* Do nothing if clipboard is not enabled */ + if (!g_fClipboard) + { + ErrorF ("winProcQueryTree - Clipboard is not enabled, " + "returning.\n"); + return iReturn; + } + + /* If the clipboard client has already been started, abort */ + if (g_fClipboardLaunched) + { + ErrorF ("winProcQueryTree - Clipboard client already " + "launched, returning.\n"); + return iReturn; + } + + /* Startup the clipboard client if clipboard mode is being used */ + if (g_fXdmcpEnabled && g_fClipboard) + { + /* + * NOTE: The clipboard client is started here for a reason: + * 1) Assume you are using XDMCP (e.g. XWin -query %hostname%) + * 2) If the clipboard client attaches during X Server startup, + * then it becomes the "magic client" that causes the X Server + * to reset if it exits. + * 3) XDMCP calls KillAllClients when it starts up. + * 4) The clipboard client is a client, so it is killed. + * 5) The clipboard client is the "magic client", so the X Server + * resets itself. + * 6) This repeats ad infinitum. + * 7) We avoid this by waiting until at least one client (could + * be XDM, could be another client) connects, which makes it + * almost certain that the clipboard client will not connect + * until after XDM when using XDMCP. + * 8) Unfortunately, there is another problem. + * 9) XDM walks the list of windows with XQueryTree, + * killing any client it finds with a window. + * 10)Thus, when using XDMCP we wait until the first call + * to ProcQueryTree before we startup the clipboard client. + * This should prevent XDM from finding the clipboard client, + * since it has not yet created a window. + * 11)Startup when not using XDMCP is handled in + * winProcEstablishConnection. + */ + + /* Create the clipboard client thread */ + if (!winInitClipboard ()) + { + ErrorF ("winProcQueryTree - winClipboardInit " + "failed.\n"); + return iReturn; + } + + ErrorF ("winProcQueryTree - winInitClipboard returned.\n"); + } + + /* Flag that clipboard client has been launched */ + g_fClipboardLaunched = TRUE; + + return iReturn; +} + + +/* + * Wrapper for internal EstablishConnection function. + * Initializes internal clients that must not be started until + * an external client has connected. + */ + +int +winProcEstablishConnection (ClientPtr client) +{ + int iReturn; + static int s_iCallCount = 0; + static unsigned long s_ulServerGeneration = 0; + + ErrorF ("winProcEstablishConnection - Hello\n"); + + /* Do nothing if clipboard is not enabled */ + if (!g_fClipboard) + { + ErrorF ("winProcEstablishConnection - Clipboard is not enabled, " + "returning.\n"); + + /* Unwrap the original function, call it, and return */ + InitialVector[2] = winProcEstablishConnectionOrig; + iReturn = (*winProcEstablishConnectionOrig) (client); + winProcEstablishConnectionOrig = NULL; + return iReturn; + } + + /* Watch for server reset */ + if (s_ulServerGeneration != serverGeneration) + { + /* Save new generation number */ + s_ulServerGeneration = serverGeneration; + + /* Reset call count */ + s_iCallCount = 0; + } + + /* Increment call count */ + ++s_iCallCount; + + /* Wait for second call when Xdmcp is enabled */ + if (g_fXdmcpEnabled + && !g_fClipboardLaunched + && s_iCallCount < 4) + { + ErrorF ("winProcEstablishConnection - Xdmcp enabled, waiting to " + "start clipboard client until fourth call.\n"); + return (*winProcEstablishConnectionOrig) (client); + } + + /* + * This procedure is only used for initialization. + * We can unwrap the original procedure at this point + * so that this function is no longer called until the + * server resets and the function is wrapped again. + */ + InitialVector[2] = winProcEstablishConnectionOrig; + + /* + * Call original function and bail if it fails. + * NOTE: We must do this first, since we need XdmcpOpenDisplay + * to be called before we initialize our clipboard client. + */ + iReturn = (*winProcEstablishConnectionOrig) (client); + if (iReturn != 0) + { + ErrorF ("winProcEstablishConnection - ProcEstablishConnection " + "failed, bailing.\n"); + return iReturn; + } + + /* Clear original function pointer */ + winProcEstablishConnectionOrig = NULL; + + /* If the clipboard client has already been started, abort */ + if (g_fClipboardLaunched) + { + ErrorF ("winProcEstablishConnection - Clipboard client already " + "launched, returning.\n"); + return iReturn; + } + + /* Startup the clipboard client if clipboard mode is being used */ + if (g_fClipboard) + { + /* + * NOTE: The clipboard client is started here for a reason: + * 1) Assume you are using XDMCP (e.g. XWin -query %hostname%) + * 2) If the clipboard client attaches during X Server startup, + * then it becomes the "magic client" that causes the X Server + * to reset if it exits. + * 3) XDMCP calls KillAllClients when it starts up. + * 4) The clipboard client is a client, so it is killed. + * 5) The clipboard client is the "magic client", so the X Server + * resets itself. + * 6) This repeats ad infinitum. + * 7) We avoid this by waiting until at least one client (could + * be XDM, could be another client) connects, which makes it + * almost certain that the clipboard client will not connect + * until after XDM when using XDMCP. + * 8) Unfortunately, there is another problem. + * 9) XDM walks the list of windows with XQueryTree, + * killing any client it finds with a window. + * 10)Thus, when using XDMCP we wait until the second call + * to ProcEstablishCeonnection before we startup the clipboard + * client. This should prevent XDM from finding the clipboard + * client, since it has not yet created a window. + */ + + /* Create the clipboard client thread */ + if (!winInitClipboard ()) + { + ErrorF ("winProcEstablishConnection - winClipboardInit " + "failed.\n"); + return iReturn; + } + + ErrorF ("winProcEstablishConnection - winInitClipboard returned.\n"); + } + + /* Flag that clipboard client has been launched */ + g_fClipboardLaunched = TRUE; + + return iReturn; +} + + +/* + * Wrapper for internal SetSelectionOwner function. + * Grabs ownership of Windows clipboard when X11 clipboard owner changes. + */ + +int +winProcSetSelectionOwner (ClientPtr client) +{ + int i; + DrawablePtr pDrawable; + WindowPtr pWindow = None; + Bool fOwnedToNotOwned = FALSE; + static Window s_iOwners[CLIP_NUM_SELECTIONS] = {None}; + static unsigned long s_ulServerGeneration = 0; + REQUEST(xSetSelectionOwnerReq); + + REQUEST_SIZE_MATCH(xSetSelectionOwnerReq); + +#if 0 + ErrorF ("winProcSetSelectionOwner - Hello.\n"); +#endif + + /* Watch for server reset */ + if (s_ulServerGeneration != serverGeneration) + { + /* Save new generation number */ + s_ulServerGeneration = serverGeneration; + + /* Initialize static variables */ + for (i = 0; i < CLIP_NUM_SELECTIONS; ++i) + s_iOwners[i] = None; + } + + /* Abort if clipboard not completely initialized yet */ + if (!g_fClipboardStarted) + { + ErrorF ("winProcSetSelectionOwner - Clipboard not yet started, " + "aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Grab window if we have one */ + if (None != stuff->window) + { + /* Grab the Window from the request */ + pWindow = (WindowPtr) SecurityLookupWindow (stuff->window, client, + SecurityReadAccess); + if (!pWindow) + { + ErrorF ("winProcSetSelectionOwner - Found BadWindow, aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + } + + /* Now we either have a valid window or None */ + + /* Save selection owners for monitored selections, ignore other selections */ + if (XA_PRIMARY == stuff->selection) + { + /* Look for owned -> not owned transition */ + if (None == stuff->window + && None != s_iOwners[CLIP_OWN_PRIMARY]) + { + fOwnedToNotOwned = TRUE; + +#if 0 + ErrorF ("winProcSetSelectionOwner - PRIMARY - Going from " + "owned to not owned.\n"); +#endif + + /* Adjust last owned selection */ + if (None != s_iOwners[CLIP_OWN_CLIPBOARD]) + g_atomLastOwnedSelection = MakeAtom ("CLIPBOARD", 9, TRUE); + else + g_atomLastOwnedSelection = None; + } + + /* Save new selection owner or None */ + s_iOwners[CLIP_OWN_PRIMARY] = stuff->window; + +#if 0 + ErrorF ("winProcSetSelectionOwner - PRIMARY - Now owned by: %d\n", + stuff->window); +#endif + } + else if (MakeAtom ("CLIPBOARD", 9, TRUE) == stuff->selection) + { + /* Look for owned -> not owned transition */ + if (None == stuff->window + && None != s_iOwners[CLIP_OWN_CLIPBOARD]) + { + fOwnedToNotOwned = TRUE; + +#if 0 + ErrorF ("winProcSetSelectionOwner - CLIPBOARD - Going from " + "owned to not owned.\n"); +#endif + + /* Adjust last owned selection */ + if (None != s_iOwners[CLIP_OWN_PRIMARY]) + g_atomLastOwnedSelection = XA_PRIMARY; + else + g_atomLastOwnedSelection = None; + } + + /* Save new selection owner or None */ + s_iOwners[CLIP_OWN_CLIPBOARD] = stuff->window; + +#if 0 + ErrorF ("winProcSetSelectionOwner - CLIPBOARD - Now owned by: %d\n", + stuff->window); +#endif + } + else + goto winProcSetSelectionOwner_Done; + + /* + * At this point, if one of the selections is still owned by the + * clipboard manager then it should be marked as unowned since + * we will be taking ownership of the Win32 clipboard. + */ + if (g_iClipboardWindow == s_iOwners[CLIP_OWN_PRIMARY]) + s_iOwners[CLIP_OWN_PRIMARY] = None; + if (g_iClipboardWindow == s_iOwners[CLIP_OWN_CLIPBOARD]) + s_iOwners[CLIP_OWN_CLIPBOARD] = None; + + /* + * Handle case when selection is being disowned, + * WM_DRAWCLIPBOARD did not do the disowning, + * both monitored selections are no longer owned, + * an owned to not owned transition was detected, + * and we currently own the Win32 clipboard. + */ + if (None == stuff->window + && g_iClipboardWindow != client->lastDrawableID + && (None == s_iOwners[CLIP_OWN_PRIMARY] + || g_iClipboardWindow == s_iOwners[CLIP_OWN_PRIMARY]) + && (None == s_iOwners[CLIP_OWN_CLIPBOARD] + || g_iClipboardWindow == s_iOwners[CLIP_OWN_CLIPBOARD]) + && fOwnedToNotOwned + && g_hwndClipboard != NULL + && g_hwndClipboard == GetClipboardOwner ()) + { +#if 0 + ErrorF ("winProcSetSelectionOwner - We currently own the " + "clipboard and neither the PRIMARY nor the CLIPBOARD " + "selections are owned, releasing ownership of Win32 " + "clipboard.\n"); +#endif + + /* Release ownership of the Windows clipboard */ + OpenClipboard (NULL); + EmptyClipboard (); + CloseClipboard (); + + /* Clear X selection ownership (might still be marked as us owning) */ + s_iOwners[CLIP_OWN_PRIMARY] = None; + s_iOwners[CLIP_OWN_CLIPBOARD] = None; + + goto winProcSetSelectionOwner_Done; + } + + /* Abort if no window at this point */ + if (None == stuff->window) + { +#if 0 + ErrorF ("winProcSetSelectionOwner - No window, returning.\n"); +#endif + goto winProcSetSelectionOwner_Done; + } + + /* Abort if invalid selection */ + if (!ValidAtom (stuff->selection)) + { + ErrorF ("winProcSetSelectionOwner - Found BadAtom, aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Cast Window to Drawable */ + pDrawable = (DrawablePtr) pWindow; + + /* Abort if clipboard manager is owning the selection */ + if (pDrawable->id == g_iClipboardWindow) + { +#if 0 + ErrorF ("winProcSetSelectionOwner - We changed ownership, " + "aborting.\n"); +#endif + goto winProcSetSelectionOwner_Done; + } + + /* Abort if root window is taking ownership */ + if (pDrawable->id == 0) + { + ErrorF ("winProcSetSelectionOwner - Root window taking ownership, " + "aborting\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Close clipboard if we have it open already */ + if (GetOpenClipboardWindow () == g_hwndClipboard) + { + CloseClipboard (); + } + + /* Access the Windows clipboard */ + if (!OpenClipboard (g_hwndClipboard)) + { + ErrorF ("winProcSetSelectionOwner - OpenClipboard () failed: %08x\n", + (int) GetLastError ()); + goto winProcSetSelectionOwner_Done; + } + + /* Take ownership of the Windows clipboard */ + if (!EmptyClipboard ()) + { + ErrorF ("winProcSetSelectionOwner - EmptyClipboard () failed: %08x\n", + (int) GetLastError ()); + goto winProcSetSelectionOwner_Done; + } + + /* Advertise Unicode if we support it */ + if (g_fUnicodeSupport) + SetClipboardData (CF_UNICODETEXT, NULL); + + /* Always advertise regular text */ + SetClipboardData (CF_TEXT, NULL); + + /* Save handle to last owned selection */ + g_atomLastOwnedSelection = stuff->selection; + + /* Release the clipboard */ + if (!CloseClipboard ()) + { + ErrorF ("winProcSetSelectionOwner - CloseClipboard () failed: " + "%08x\n", + (int) GetLastError ()); + goto winProcSetSelectionOwner_Done; + } + + winProcSetSelectionOwner_Done: + return (*winProcSetSelectionOwnerOrig) (client); +} diff --git a/hw/xwin/winclipboardxevents.c b/hw/xwin/winclipboardxevents.c index d2cfb2e55..598620c4c 100644 --- a/hw/xwin/winclipboardxevents.c +++ b/hw/xwin/winclipboardxevents.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,19 +15,18 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclip.c,v 1.2 2001/06/04 13:04:41 alanh Exp $ */ #include "winclipboard.h" @@ -36,92 +35,74 @@ * Process any pending X events */ -Bool +int winClipboardFlushXEvents (HWND hwnd, - Atom atomClipboard, - Atom atomLocalProperty, - Atom atomUTF8String, - Atom atomCompoundText, - Atom atomTargets, - Atom atomDeleteWindow, int iWindow, Display *pDisplay, Bool fUnicodeSupport) { - Atom atomReturnType; - int iReturnFormat; - unsigned long ulReturnItems; - XTextProperty xtpText; - XEvent event; - XSelectionEvent eventSelection; - unsigned long ulReturnBytesLeft; - unsigned char *pszReturnData = NULL; - char *pszGlobalData = NULL; - int iReturn; - HGLOBAL hGlobal; - Bool fReturn = TRUE; - XICCEncodingStyle xiccesStyle; - int iUTF8; - char *pszUTF8 = NULL; - char *pszTextList[2]; - int iCount; - char **ppszTextList = NULL; - wchar_t *pwszUnicodeStr = NULL; - int iUnicodeLen = 0; + Atom atomLocalProperty = XInternAtom (pDisplay, + WIN_LOCAL_PROPERTY, + False); + Atom atomUTF8String = XInternAtom (pDisplay, + "UTF8_STRING", + False); + Atom atomCompoundText = XInternAtom (pDisplay, + "COMPOUND_TEXT", + False); + Atom atomTargets = XInternAtom (pDisplay, + "TARGETS", + False); /* Process all pending events */ while (XPending (pDisplay)) { + XTextProperty xtpText = {0}; + XEvent event; + XSelectionEvent eventSelection; + unsigned long ulReturnBytesLeft; + unsigned char *pszReturnData = NULL; + char *pszGlobalData = NULL; + int iReturn; + HGLOBAL hGlobal = NULL; + XICCEncodingStyle xiccesStyle; + int iConvertDataLen = 0; + char *pszConvertData = NULL; + char *pszTextList[2] = {NULL}; + int iCount; + char **ppszTextList = NULL; + wchar_t *pwszUnicodeStr = NULL; + int iUnicodeLen = 0; + int iReturnDataLen = 0; + int i; + Bool fAbort = FALSE; + Bool fCloseClipboard = FALSE; + Bool fSetClipboardData = TRUE; + /* Get the next event - will not block because one is ready */ XNextEvent (pDisplay, &event); /* Branch on the event type */ switch (event.type) { - case ClientMessage: - if (event.xclient.data.l[0] == atomDeleteWindow) - { - ErrorF ("\nwinClipboardFlushXEvents - Received " - "WM_DELETE_WINDOW\n\n"); - fReturn = FALSE; - } - else - ErrorF ("\nwinClipboardFlushXEvents - Unknown ClientMessage\n\n"); - break; - - case SelectionClear: - /* Request the lost selection contents */ - iReturn = XConvertSelection (pDisplay, - event.xselectionclear.selection, - atomCompoundText, - atomLocalProperty, - iWindow, - CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardFlushXEvents - SelectionClear - " - "XConvertSelection () failed\n"); - pthread_exit (NULL); - } - break; - - /* * SelectionRequest */ case SelectionRequest: #if 0 - char *pszAtomName = NULL - - ErrorF ("SelectionRequest - target %d\n", - event.xselectionrequest.target); - - pszAtomName = XGetAtomName (pDisplay, - event.xselectionrequest.target); - ErrorF ("SelectionRequest - Target atom name %s\n", pszAtomName); - XFree (pszAtomName); - pszAtomName = NULL; + { + char *pszAtomName = NULL; + + ErrorF ("SelectionRequest - target %d\n", + event.xselectionrequest.target); + + pszAtomName = XGetAtomName (pDisplay, + event.xselectionrequest.target); + ErrorF ("SelectionRequest - Target atom name %s\n", pszAtomName); + XFree (pszAtomName); + pszAtomName = NULL; + } #endif /* Abort if invalid target type */ @@ -130,49 +111,29 @@ winClipboardFlushXEvents (HWND hwnd, && event.xselectionrequest.target != atomCompoundText && event.xselectionrequest.target != atomTargets) { - /* Setup selection notify event */ - eventSelection.type = SelectionNotify; - eventSelection.send_event = True; - eventSelection.display = pDisplay; - eventSelection.requestor = event.xselectionrequest.requestor; - eventSelection.selection = event.xselectionrequest.selection; - eventSelection.target = event.xselectionrequest.target; - eventSelection.property = None; - eventSelection.time = event.xselectionrequest.time; - - /* Notify the requesting window that the operation is complete */ - iReturn = XSendEvent (pDisplay, - eventSelection.requestor, - False, - 0L, - (XEvent *) &eventSelection); - if (iReturn == BadValue || iReturn == BadWindow) - { - ErrorF ("winClipboardFlushXEvents - SelectionRequest - " - "XSendEvent () failed\n"); - pthread_exit (NULL); - } - - break; + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Handle targets type of request */ if (event.xselectionrequest.target == atomTargets) { - Atom atomTargetArr[4] = {atomTargets, - atomCompoundText, - atomUTF8String, - XA_STRING}; + Atom atomTargetArr[] = {atomTargets, + atomCompoundText, + atomUTF8String, + XA_STRING}; /* Try to change the property */ iReturn = XChangeProperty (pDisplay, event.xselectionrequest.requestor, event.xselectionrequest.property, event.xselectionrequest.target, - 8, + sizeof (atomTargetArr[0]), PropModeReplace, - (char *) atomTargetArr, - sizeof (atomTargetArr)); + (unsigned char *) atomTargetArr, + (sizeof (atomTargetArr) + / sizeof (atomTargetArr[0]))); if (iReturn == BadAlloc || iReturn == BadAtom || iReturn == BadMatch @@ -185,14 +146,14 @@ winClipboardFlushXEvents (HWND hwnd, } /* Setup selection notify xevent */ - eventSelection.type = SelectionNotify; - eventSelection.send_event = True; - eventSelection.display = pDisplay; - eventSelection.requestor = event.xselectionrequest.requestor; - eventSelection.selection = event.xselectionrequest.selection; - eventSelection.target = event.xselectionrequest.target; - eventSelection.property = event.xselectionrequest.property; - eventSelection.time = event.xselectionrequest.time; + eventSelection.type = SelectionNotify; + eventSelection.send_event = True; + eventSelection.display = pDisplay; + eventSelection.requestor = event.xselectionrequest.requestor; + eventSelection.selection = event.xselectionrequest.selection; + eventSelection.target = event.xselectionrequest.target; + eventSelection.property = event.xselectionrequest.property; + eventSelection.time = event.xselectionrequest.time; /* * Notify the requesting window that @@ -211,20 +172,56 @@ winClipboardFlushXEvents (HWND hwnd, break; } + /* Check that clipboard format is available */ + if (fUnicodeSupport + && !IsClipboardFormatAvailable (CF_UNICODETEXT)) + { + ErrorF ("winClipboardFlushXEvents - CF_UNICODETEXT is not " + "available from Win32 clipboard. Aborting.\n"); + + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionRequest_Done; + } + else if (!fUnicodeSupport + && !IsClipboardFormatAvailable (CF_TEXT)) + { + ErrorF ("winClipboardFlushXEvents - CF_TEXT is not " + "available from Win32 clipboard. Aborting.\n"); + + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionRequest_Done; + } + + /* Close clipboard if we have it open already */ + if (GetOpenClipboardWindow () == hwnd) + { + CloseClipboard (); + } + /* Access the clipboard */ if (!OpenClipboard (hwnd)) { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "OpenClipboard () failed: %08x\n", GetLastError ()); - pthread_exit (NULL); + + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionRequest_Done; } + + /* Indicate that clipboard was opened */ + fCloseClipboard = TRUE; /* Setup the string style */ if (event.xselectionrequest.target == XA_STRING) xiccesStyle = XStringStyle; +#ifdef X_HAVE_UTF8_STRING else if (event.xselectionrequest.target == atomUTF8String) xiccesStyle = XUTF8StringStyle; +#endif else if (event.xselectionrequest.target == atomCompoundText) xiccesStyle = XCompoundTextStyle; else @@ -234,99 +231,110 @@ winClipboardFlushXEvents (HWND hwnd, * FIXME: Can't pass CF_UNICODETEXT on Windows 95/98/Me */ - /* Get a pointer to the clipboard text */ + /* Get a pointer to the clipboard text, in desired format */ if (fUnicodeSupport) - hGlobal = GetClipboardData (CF_UNICODETEXT); + { + /* Retrieve clipboard data */ + hGlobal = GetClipboardData (CF_UNICODETEXT); + } else - hGlobal = GetClipboardData (CF_TEXT); + { + /* Retrieve clipboard data */ + hGlobal = GetClipboardData (CF_TEXT); + } if (!hGlobal) { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "GetClipboardData () failed: %08x\n", GetLastError ()); - pthread_exit (NULL); + + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionRequest_Done; } pszGlobalData = (char *) GlobalLock (hGlobal); /* Convert the Unicode string to UTF8 (MBCS) */ if (fUnicodeSupport) { - iUTF8 = WideCharToMultiByte (CP_UTF8, - 0, - (LPCWSTR)pszGlobalData, - -1, - NULL, - 0, - NULL, - NULL); - pszUTF8 = (char *) malloc (iUTF8); /* Don't need +1 */ + iConvertDataLen = WideCharToMultiByte (CP_UTF8, + 0, + (LPCWSTR)pszGlobalData, + -1, + NULL, + 0, + NULL, + NULL); + /* NOTE: iConvertDataLen includes space for null terminator */ + pszConvertData = (char *) malloc (iConvertDataLen); WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)pszGlobalData, -1, - pszUTF8, - iUTF8, + pszConvertData, + iConvertDataLen, NULL, NULL); } + else + { + pszConvertData = strdup (pszGlobalData); + iConvertDataLen = strlen (pszConvertData) + 1; + } /* Convert DOS string to UNIX string */ + winClipboardDOStoUNIX (pszConvertData, strlen (pszConvertData)); + + /* Setup our text list */ + pszTextList[0] = pszConvertData; + pszTextList[1] = NULL; + + /* Initialize the text property */ + xtpText.value = NULL; + + /* Create the text property from the text list */ if (fUnicodeSupport) { - winClipboardDOStoUNIX (pszUTF8, strlen (pszUTF8)); - - /* Setup our text list */ - pszTextList[0] = pszUTF8; - pszTextList[1] = NULL; - - /* Initialize the text property */ - xtpText.value = NULL; - - /* Create the text property from the text list */ +#ifdef X_HAVE_UTF8_STRING iReturn = Xutf8TextListToTextProperty (pDisplay, pszTextList, 1, xiccesStyle, &xtpText); - if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) - { - ErrorF ("winClipboardFlushXEvents - SelectionRequest - " - "Xutf8TextListToTextProperty failed: %d\n", - iReturn); - exit(1); - } - - /* Free the UTF8 string */ - free (pszUTF8); +#endif } else - winClipboardDOStoUNIX (pszGlobalData, strlen (pszGlobalData)); + { + iReturn = XmbTextListToTextProperty (pDisplay, + pszTextList, + 1, + xiccesStyle, + &xtpText); + } + if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) + { + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "X*TextListToTextProperty failed: %d\n", + iReturn); - /* - * FIXME: Pass pszGlobalData and strlen (pszGlobalData( - * on 1 byte, pass xtpText.value and xtpText.nitems - * on 2 byte. - */ + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionRequest_Done; + } + + /* Free the converted string */ + free (pszConvertData); + pszConvertData = NULL; /* Copy the clipboard text to the requesting window */ - if (fUnicodeSupport) - iReturn = XChangeProperty (pDisplay, - event.xselectionrequest.requestor, - event.xselectionrequest.property, - event.xselectionrequest.target, - 8, - PropModeReplace, - xtpText.value, - xtpText.nitems); - else - iReturn = XChangeProperty (pDisplay, - event.xselectionrequest.requestor, - event.xselectionrequest.property, - event.xselectionrequest.target, - 8, - PropModeReplace, - pszGlobalData, - strlen (pszGlobalData)); + iReturn = XChangeProperty (pDisplay, + event.xselectionrequest.requestor, + event.xselectionrequest.property, + event.xselectionrequest.target, + 8, + PropModeReplace, + xtpText.value, + xtpText.nitems); if (iReturn == BadAlloc || iReturn == BadAtom || iReturn == BadMatch || iReturn == BadValue || iReturn == BadWindow) @@ -334,20 +342,19 @@ winClipboardFlushXEvents (HWND hwnd, ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "XChangeProperty failed: %d\n", iReturn); - pthread_exit (NULL); + + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Release the clipboard data */ GlobalUnlock (hGlobal); pszGlobalData = NULL; - CloseClipboard (); - /* FIXME: Don't clean up on 1 byte. */ - if (fUnicodeSupport) - { - XFree (xtpText.value); - xtpText.value = NULL; - } + /* Clean up */ + XFree (xtpText.value); + xtpText.value = NULL; /* Setup selection notify event */ eventSelection.type = SelectionNotify; @@ -369,10 +376,59 @@ winClipboardFlushXEvents (HWND hwnd, { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "XSendEvent () failed\n"); - pthread_exit (NULL); + + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionRequest_Done; } - break; + + winClipboardFlushXEvents_SelectionRequest_Done: + /* Free allocated resources */ + if (xtpText.value) + XFree (xtpText.value); + if (pszConvertData) + free (pszConvertData); + if (hGlobal && pszGlobalData) + GlobalUnlock (hGlobal); + /* + * Send a SelectionNotify event to the requesting + * client when we abort. + */ + if (fAbort) + { + /* Setup selection notify event */ + eventSelection.type = SelectionNotify; + eventSelection.send_event = True; + eventSelection.display = pDisplay; + eventSelection.requestor = event.xselectionrequest.requestor; + eventSelection.selection = event.xselectionrequest.selection; + eventSelection.target = event.xselectionrequest.target; + eventSelection.property = None; + eventSelection.time = event.xselectionrequest.time; + + /* Notify the requesting window that the operation is complete */ + iReturn = XSendEvent (pDisplay, + eventSelection.requestor, + False, + 0L, + (XEvent *) &eventSelection); + if (iReturn == BadValue || iReturn == BadWindow) + { + /* + * Should not be a problem if XSendEvent fails because + * the client may simply have exited. + */ + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "XSendEvent () failed for abort event.\n"); + } + } + + /* Close clipboard if it was opened */ + if (fCloseClipboard) + CloseClipboard (); + break; + /* * SelectionNotify @@ -380,8 +436,7 @@ winClipboardFlushXEvents (HWND hwnd, case SelectionNotify: #if 0 - ErrorF ("SelectionNotify\n"); -#endif + ErrorF ("winClipboardFlushXEvents - SelectionNotify\n"); { char *pszAtomName; @@ -393,189 +448,212 @@ winClipboardFlushXEvents (HWND hwnd, XFree (pszAtomName); } - -#if 0 - /* - * TEMP: Bail if selection is anything other than CLIPBOARD - */ - - if (event.xselection.selection != atomClipboard) - break; #endif + /* - * - * What are we doing here? - * + * Request conversion of UTF8 and CompoundText targets. */ - if (fUnicodeSupport) + if (event.xselection.property == None) { - if (event.xselection.property == None) + if (event.xselection.target == XA_STRING) { - if(event.xselection.target == XA_STRING) - { #if 0 - ErrorF ("winClipboardFlushXEvents - SelectionNotify - " - "XA_STRING\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XA_STRING\n"); #endif - return fReturn; - } - else if (event.xselection.target == atomUTF8String) - { - ErrorF ("winClipboardFlushXEvents - SelectionNotify " - "UTF8\n"); - iReturn = XConvertSelection (pDisplay, - event.xselection.selection, - XA_STRING, - atomLocalProperty, - iWindow, - CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardFlushXEvents - SelectionNotify " - "- XConvertSelection () failed\n"); - pthread_exit (NULL); - } - return fReturn; - } - else if (event.xselection.target == atomCompoundText) + return WIN_XEVENTS_CONVERT; + } + else if (event.xselection.target == atomUTF8String) + { +#if 0 + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "Requesting conversion of UTF8 target.\n"); +#endif + iReturn = XConvertSelection (pDisplay, + event.xselection.selection, + XA_STRING, + atomLocalProperty, + iWindow, + CurrentTime); + if (iReturn != Success) { - ErrorF ("winClipboardFlushXEvents - SelectionNotify " - "CompoundText\n"); - iReturn = XConvertSelection (pDisplay, - event.xselection.selection, - atomUTF8String, - atomLocalProperty, - iWindow, - CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardFlushXEvents - SelectionNotify " - "- XConvertSelection () failed\n"); - pthread_exit (NULL); - } - return fReturn; + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XConvertSelection () failed for UTF8String, " + "aborting: %d\n", + iReturn); + break; } - else + + /* Process the ConvertSelection event */ + XFlush (pDisplay); + return WIN_XEVENTS_CONVERT; + } +#ifdef X_HAVE_UTF8_STRING + else if (event.xselection.target == atomCompoundText) + { +#if 0 + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "Requesting conversion of CompoundText target.\n"); +#endif + iReturn = XConvertSelection (pDisplay, + event.xselection.selection, + atomUTF8String, + atomLocalProperty, + iWindow, + CurrentTime); + if (iReturn != Success) { - ErrorF ("winClipboardFlushXEvents - Unknown format\n"); - return fReturn; + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XConvertSelection () failed for CompoundText, " + "aborting: %d\n", + iReturn); + break; } + + /* Process the ConvertSelection event */ + XFlush (pDisplay); + return WIN_XEVENTS_CONVERT; + } +#endif + else + { + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "Unknown format. Cannot request conversion, " + "aborting.\n"); + break; } } /* Retrieve the size of the stored data */ - if (fUnicodeSupport) - iReturn = XGetWindowProperty (pDisplay, - iWindow, - atomLocalProperty, - 0, - 0, /* Don't get data, just size */ - False, - AnyPropertyType, - &xtpText.encoding, - &xtpText.format, - &xtpText.nitems, - &ulReturnBytesLeft, - &xtpText.value); - else - iReturn = XGetWindowProperty (pDisplay, - iWindow, - atomLocalProperty, - 0, - 0, /* Don't get data, just size */ - False, - AnyPropertyType, - &atomReturnType, - &iReturnFormat, - &ulReturnItems, - &ulReturnBytesLeft, - &pszReturnData); + iReturn = XGetWindowProperty (pDisplay, + iWindow, + atomLocalProperty, + 0, + 0, /* Don't get data, just size */ + False, + AnyPropertyType, + &xtpText.encoding, + &xtpText.format, + &xtpText.nitems, + &ulReturnBytesLeft, + &xtpText.value); if (iReturn != Success) { ErrorF ("winClipboardFlushXEvents - SelectionNotify - " - "XGetWindowProperty () failed\n"); - pthread_exit (NULL); + "XGetWindowProperty () failed, aborting: %d\n", + iReturn); + break; } #if 0 - if (fUnicodeSupport) - ErrorF ("SelectionNotify - returned data %d left %d\n", - xtpText.nitems, ulReturnBytesLeft); - else - ErrorF ("SelectionNotify - returned data %d left %d\n", - ulReturnItems, ulReturnBytesLeft); + ErrorF ("SelectionNotify - returned data %d left %d\n", + xtpText.nitems, ulReturnBytesLeft); #endif /* Request the selection data */ - if (fUnicodeSupport) - iReturn = XGetWindowProperty (pDisplay, - iWindow, - atomLocalProperty, - 0, - ulReturnBytesLeft, - False, - AnyPropertyType, - &xtpText.encoding, - &xtpText.format, - &xtpText.nitems, - &ulReturnBytesLeft, - &xtpText.value); - else - iReturn = XGetWindowProperty (pDisplay, - iWindow, - atomLocalProperty, - 0, - ulReturnBytesLeft, - False, - AnyPropertyType, - &atomReturnType, - &iReturnFormat, - &ulReturnItems, - &ulReturnBytesLeft, - &pszReturnData); + iReturn = XGetWindowProperty (pDisplay, + iWindow, + atomLocalProperty, + 0, + ulReturnBytesLeft, + False, + AnyPropertyType, + &xtpText.encoding, + &xtpText.format, + &xtpText.nitems, + &ulReturnBytesLeft, + &xtpText.value); if (iReturn != Success) { ErrorF ("winClipboardFlushXEvents - SelectionNotify - " - "XGetWindowProperty () failed\n"); - pthread_exit (NULL); + "XGetWindowProperty () failed, aborting: %d\n", + iReturn); + break; } - if (fUnicodeSupport) - { #if 0 + { char *pszAtomName = NULL; ErrorF ("SelectionNotify - returned data %d left %d\n", - prop.nitems, ulReturnBytesLeft); + xtpText.nitems, ulReturnBytesLeft); - pszAtomName = XGetAtomName(pDisplay, prop.encoding); + pszAtomName = XGetAtomName(pDisplay, xtpText.encoding); ErrorF ("Notify atom name %s\n", pszAtomName); XFree (pszAtomName); pszAtomName = NULL; + } #endif - + + if (fUnicodeSupport) + { +#ifdef X_HAVE_UTF8_STRING /* Convert the text property to a text list */ - Xutf8TextPropertyToTextList (pDisplay, - &xtpText, - &ppszTextList, - &iCount); - if (iCount > 0) + iReturn = Xutf8TextPropertyToTextList (pDisplay, + &xtpText, + &ppszTextList, + &iCount); +#endif + } + else + { + iReturn = XmbTextPropertyToTextList (pDisplay, + &xtpText, + &ppszTextList, + &iCount); + } + if (iReturn == Success || iReturn > 0) + { + /* Conversion succeeded or some unconvertible characters */ + if (ppszTextList != NULL) { - pszReturnData = malloc (strlen (ppszTextList[0]) + 1); - strcpy (pszReturnData, ppszTextList[0]); + for (i = 0; i < iCount; i++) + { + iReturnDataLen += strlen(ppszTextList[i]); + } + pszReturnData = malloc (iReturnDataLen + 1); + pszReturnData[0] = '\0'; + for (i = 0; i < iCount; i++) + { + strcat (pszReturnData, ppszTextList[i]); + } } else { + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "X*TextPropertyToTextList list_return is NULL.\n"); pszReturnData = malloc (1); - pszReturnData[0] = 0; + pszReturnData[0] = '\0'; } - - /* Free the data returned from XGetWindowProperty */ - XFreeStringList (ppszTextList); - XFree (xtpText.value); } - + else + { + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "X*TextPropertyToTextList returned: "); + switch (iReturn) + { + case XNoMemory: + ErrorF ("XNoMemory\n"); + break; + case XConverterNotFound: + ErrorF ("XConverterNotFound\n"); + break; + default: + ErrorF ("%d", iReturn); + break; + } + pszReturnData = malloc (1); + pszReturnData[0] = '\0'; + } + + /* Free the data returned from XGetWindowProperty */ + if (ppszTextList) + XFreeStringList (ppszTextList); + ppszTextList = NULL; + XFree (xtpText.value); + xtpText.value = NULL; + /* Convert the X clipboard string to DOS format */ winClipboardUNIXtoDOS (&pszReturnData, strlen (pszReturnData)); @@ -588,11 +666,20 @@ winClipboardFlushXEvents (HWND hwnd, -1, NULL, 0); - + /* Allocate memory for the Unicode string */ pwszUnicodeStr = (wchar_t*) malloc (sizeof (wchar_t) * (iUnicodeLen + 1)); - + if (!pwszUnicodeStr) + { + ErrorF ("winClipboardFlushXEvents - SelectionNotify " + "malloc failed for pwszUnicodeStr, aborting.\n"); + + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionNotify_Done; + } + /* Do the actual conversion */ MultiByteToWideChar (CP_UTF8, 0, @@ -600,30 +687,31 @@ winClipboardFlushXEvents (HWND hwnd, -1, pwszUnicodeStr, iUnicodeLen); + + /* Allocate global memory for the X clipboard data */ + hGlobal = GlobalAlloc (GMEM_MOVEABLE, + sizeof (wchar_t) * (iUnicodeLen + 1)); } - - /* Access the Windows clipboard */ - if (!OpenClipboard (hwnd)) + else { - ErrorF ("winClipboardFlushXEvents - OpenClipboard () failed: " - "%08x\n", GetLastError ()); - pthread_exit (NULL); + pszConvertData = strdup (pszReturnData); + iConvertDataLen = strlen (pszConvertData) + 1; + + /* Allocate global memory for the X clipboard data */ + hGlobal = GlobalAlloc (GMEM_MOVEABLE, iConvertDataLen); } - /* Take ownership of the Window clipboard */ - if (!EmptyClipboard ()) + /* Check that global memory was allocated */ + if (!hGlobal) { - ErrorF ("winClipboardFlushXEvents - EmptyClipboard () failed: " - "%08x\n", GetLastError ()); - pthread_exit (NULL); - } + ErrorF ("winClipboardFlushXEvents - SelectionNotify " + "GlobalAlloc failed, aborting: %ld\n", + GetLastError ()); - /* Allocate global memory for the X clipboard data */ - if (fUnicodeSupport) - hGlobal = GlobalAlloc (GMEM_MOVEABLE, - sizeof (wchar_t) * (iUnicodeLen + 1)); - else - hGlobal = GlobalAlloc (GMEM_MOVEABLE, strlen (pszReturnData) + 1); + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionNotify_Done; + } /* Obtain a pointer to the global memory */ pszGlobalData = GlobalLock (hGlobal); @@ -631,27 +719,26 @@ winClipboardFlushXEvents (HWND hwnd, { ErrorF ("winClipboardFlushXEvents - Could not lock global " "memory for clipboard transfer\n"); - pthread_exit (NULL); + + /* Abort */ + fAbort = TRUE; + goto winClipboardFlushXEvents_SelectionNotify_Done; } /* Copy the returned string into the global memory */ if (fUnicodeSupport) - memcpy (pszGlobalData, - pwszUnicodeStr, - sizeof (wchar_t) * (iUnicodeLen + 1)); - else - strcpy (pszGlobalData, pszReturnData); - - /* Free the data returned from XGetWindowProperty */ - if (fUnicodeSupport) { + memcpy (pszGlobalData, + pwszUnicodeStr, + sizeof (wchar_t) * (iUnicodeLen + 1)); free (pwszUnicodeStr); pwszUnicodeStr = NULL; } else { - XFree (pszReturnData); - pszReturnData = NULL; + strcpy (pszGlobalData, pszConvertData); + free (pszConvertData); + pszConvertData = NULL; } /* Release the pointer to the global memory */ @@ -662,82 +749,38 @@ winClipboardFlushXEvents (HWND hwnd, if (fUnicodeSupport) SetClipboardData (CF_UNICODETEXT, hGlobal); else - SetClipboardData (CF_TEXT, hGlobal); + SetClipboardData (CF_TEXT, hGlobal); + + /* Flag that SetClipboardData has been called */ + fSetClipboardData = FALSE; /* * NOTE: Do not try to free pszGlobalData, it is owned by * Windows after the call to SetClipboardData (). */ - /* Release the clipboard */ - if (!CloseClipboard ()) - { - ErrorF ("winClipboardFlushXEvents - CloseClipboard () failed: " - "%08x\n", - GetLastError ()); - pthread_exit (NULL); - } - - /* Reassert ownership of the selection */ - iReturn = XSetSelectionOwner (pDisplay, - event.xselection.selection, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - char *pszAtomName = NULL; - - pszAtomName = XGetAtomName (pDisplay, - event.xselection.selection); - ErrorF ("winClipboardFlushXEvents - SelectionNotify - " - "Could not reassert ownership of selection ATOM: %s\n", - pszAtomName); - XFree (pszAtomName); - pszAtomName = NULL; - pthread_exit (NULL); - } - else - { -#if 0 - char *pszAtomName = NULL; - - pszAtomName = XGetAtomName (pDisplay, - event.xselection.selection); - ErrorF ("SelectionNotify - Reasserted ownership of ATOM: %s\n", - pszAtomName); - XFree (pszAtomName); - pszAtomName = NULL; -#endif - } -#if 0 - /* Reassert ownership of the CLIPBOARD */ - iReturn = XSetSelectionOwner (pDisplay, - atomClipboard, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardFlushXEvents - Could not reassert " - "ownership of selection\n"); - pthread_exit (NULL); - } -#endif - break; - -#if 0 - case CreateNotify: - ErrorF ("FlushXEvents - CreateNotify parent: %ld\twindow: %ld\n", - event.xcreatewindow.parent, event.xcreatewindow.window); - break; - - case DestroyNotify: - ErrorF ("FlushXEvents - DestroyNotify window: %ld\tevent: %ld\n", - event.xdestroywindow.window, event.xdestroywindow.event); - break; -#endif + winClipboardFlushXEvents_SelectionNotify_Done: + /* Free allocated resources */ + if (ppszTextList) + XFreeStringList (ppszTextList); + if (xtpText.value) + XFree (xtpText.value); + if (pszConvertData) + free (pszConvertData); + if (pwszUnicodeStr) + free (pwszUnicodeStr); + if (hGlobal && pszGlobalData) + GlobalUnlock (hGlobal); + if (fSetClipboardData && fUnicodeSupport) + SetClipboardData (CF_UNICODETEXT, NULL); + if (fSetClipboardData && !fUnicodeSupport) + SetClipboardData (CF_TEXT, NULL); + return WIN_XEVENTS_NOTIFY; default: break; } } - return fReturn; + return WIN_XEVENTS_SUCCESS; } diff --git a/hw/xwin/wincmap.c b/hw/xwin/wincmap.c index f89c26cf0..3dd5b9d3f 100644 --- a/hw/xwin/wincmap.c +++ b/hw/xwin/wincmap.c @@ -35,13 +35,65 @@ #include "win.h" +/* + * Local prototypes + */ + +static int +winListInstalledColormaps (ScreenPtr pScreen, Colormap *pmaps); + +static void +winStoreColors (ColormapPtr pmap, int ndef, xColorItem *pdefs); + +static void +winInstallColormap (ColormapPtr pmap); + +static void +winUninstallColormap (ColormapPtr pmap); + +static void +winResolveColor (unsigned short *pred, + unsigned short *pgreen, + unsigned short *pblue, + VisualPtr pVisual); + +static Bool +winCreateColormap (ColormapPtr pmap); + +static void +winDestroyColormap (ColormapPtr pmap); + +static Bool +winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap); + +static Bool +winGetPaletteDD (ScreenPtr pScreen, ColormapPtr pcmap); + + +/* + * Set screen functions for colormaps + */ + +void +winSetColormapFunctions (ScreenPtr pScreen) +{ + pScreen->CreateColormap = winCreateColormap; + pScreen->DestroyColormap = winDestroyColormap; + pScreen->InstallColormap = winInstallColormap; + pScreen->UninstallColormap = winUninstallColormap; + pScreen->ListInstalledColormaps = winListInstalledColormaps; + pScreen->StoreColors = winStoreColors; + pScreen->ResolveColor = winResolveColor; +} + + /* See Porting Layer Definition - p. 30 */ /* * Walk the list of installed colormaps, filling the pmaps list * with the resource ids of the installed maps, and return * a count of the total number of installed maps. */ -int +static int winListInstalledColormaps (ScreenPtr pScreen, Colormap *pmaps) { winScreenPriv(pScreen); @@ -58,7 +110,7 @@ winListInstalledColormaps (ScreenPtr pScreen, Colormap *pmaps) /* See Porting Layer Definition - p. 30 */ /* See Programming Windows - p. 663 */ -void +static void winInstallColormap (ColormapPtr pColormap) { ScreenPtr pScreen = pColormap->pScreen; @@ -66,14 +118,14 @@ winInstallColormap (ColormapPtr pColormap) ColormapPtr oldpmap = pScreenPriv->pcmapInstalled; #if CYGDEBUG - ErrorF ("winInstallColormap\n"); + winDebug ("winInstallColormap\n"); #endif /* Did the colormap actually change? */ if (pColormap != oldpmap) { #if CYGDEBUG - ErrorF ("winInstallColormap - Colormap has changed, attempt " + winDebug ("winInstallColormap - Colormap has changed, attempt " "to install.\n"); #endif @@ -91,7 +143,7 @@ winInstallColormap (ColormapPtr pColormap) /* Call the engine specific colormap install procedure */ if (!((*pScreenPriv->pwinInstallColormap) (pColormap))) { - ErrorF ("winInstallColormap - Screen specific colormap install " + winErrorFVerb (2, "winInstallColormap - Screen specific colormap install " "procedure failed. Continuing, but colors may be " "messed up from now on.\n"); } @@ -103,14 +155,14 @@ winInstallColormap (ColormapPtr pColormap) /* See Porting Layer Definition - p. 30 */ -void +static void winUninstallColormap (ColormapPtr pmap) { winScreenPriv(pmap->pScreen); ColormapPtr curpmap = pScreenPriv->pcmapInstalled; #if CYGDEBUG - ErrorF ("winUninstallColormap\n"); + winDebug ("winUninstallColormap\n"); #endif /* Is the colormap currently installed? */ @@ -139,7 +191,7 @@ winUninstallColormap (ColormapPtr pmap) /* See Porting Layer Definition - p. 30 */ -void +static void winStoreColors (ColormapPtr pmap, int ndef, xColorItem *pdefs) @@ -152,7 +204,7 @@ winStoreColors (ColormapPtr pmap, #if CYGDEBUG if (ndef != 1) - ErrorF ("winStoreColors - ndef: %d\n", + winDebug ("winStoreColors - ndef: %d\n", ndef); #endif @@ -175,7 +227,7 @@ winStoreColors (ColormapPtr pmap, pCmapPriv->rgbColors[pdefs[0].pixel + i].rgbBlue = nBlue; #if CYGDEBUG - ErrorF ("winStoreColors - nRed %d nGreen %d nBlue %d\n", + winDebug ("winStoreColors - nRed %d nGreen %d nBlue %d\n", nRed, nGreen, nBlue); #endif } @@ -183,7 +235,7 @@ winStoreColors (ColormapPtr pmap, /* Call the engine specific store colors procedure */ if (!((pScreenPriv->pwinStoreColors) (pmap, ndef, pdefs))) { - ErrorF ("winStoreColors - Engine cpecific color storage procedure " + winErrorFVerb (2, "winStoreColors - Engine cpecific color storage procedure " "failed. Continuing, but colors may be messed up from now " "on.\n"); } @@ -191,14 +243,14 @@ winStoreColors (ColormapPtr pmap, /* See Porting Layer Definition - p. 30 */ -void +static void winResolveColor (unsigned short *pred, unsigned short *pgreen, unsigned short *pblue, VisualPtr pVisual) { #if CYGDEBUG - ErrorF ("winResolveColor ()\n"); + winDebug ("winResolveColor ()\n"); #endif miResolveColor (pred, pgreen, pblue, pVisual); @@ -206,7 +258,7 @@ winResolveColor (unsigned short *pred, /* See Porting Layer Definition - p. 29 */ -Bool +static Bool winCreateColormap (ColormapPtr pmap) { winPrivCmapPtr pCmapPriv = NULL; @@ -214,7 +266,7 @@ winCreateColormap (ColormapPtr pmap) winScreenPriv(pScreen); #if CYGDEBUG - ErrorF ("winCreateColormap\n"); + winDebug ("winCreateColormap\n"); #endif /* Allocate colormap privates */ @@ -256,7 +308,7 @@ winCreateColormap (ColormapPtr pmap) /* See Porting Layer Definition - p. 29, 30 */ -void +static void winDestroyColormap (ColormapPtr pColormap) { winScreenPriv(pColormap->pScreen); @@ -265,7 +317,7 @@ winDestroyColormap (ColormapPtr pColormap) /* Call the engine specific colormap destruction procedure */ if (!((*pScreenPriv->pwinDestroyColormap) (pColormap))) { - ErrorF ("winDestroyColormap - Engine specific colormap destruction " + winErrorFVerb (2, "winDestroyColormap - Engine specific colormap destruction " "procedure failed. Continuing, but it is possible that memory " "was leaked, or that colors will be messed up from now on.\n"); } @@ -275,26 +327,16 @@ winDestroyColormap (ColormapPtr pColormap) winSetCmapPriv (pColormap, NULL); #if CYGDEBUG - ErrorF ("winDestroyColormap - Returning\n"); + winDebug ("winDestroyColormap - Returning\n"); #endif } -int -winExpandDirectColors (ColormapPtr pmap, int ndef, - xColorItem *indefs, xColorItem *outdefs) -{ - ErrorF ("\nwinExpandDirectColors\n"); - return miExpandDirectColors (pmap, ndef, indefs, outdefs); -} - - /* * Internal function to load the palette used by the Shadow DIB */ -static -Bool +static Bool winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap) { winScreenPriv(pScreen); @@ -316,7 +358,7 @@ winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap) } #if CYGDEBUG - ErrorF ("winGetPaletteDIB - Retrieved %d colors from DIB\n", + winDebug ("winGetPaletteDIB - Retrieved %d colors from DIB\n", uiColorsRetrieved); #endif @@ -341,7 +383,7 @@ winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap) nBlue = rgbColors[i].rgbBlue << 8; #if CYGDEBUG - ErrorF ("winGetPaletteDIB - Allocating a color: %d; " + winDebug ("winGetPaletteDIB - Allocating a color: %d; " "%d %d %d\n", pixel, nRed, nGreen, nBlue); #endif @@ -364,9 +406,9 @@ winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap) || nGreen != rgbColors[i].rgbGreen || nBlue != rgbColors[i].rgbBlue) { - ErrorF ("winGetPaletteDIB - Got: %d; " + winDebug ("winGetPaletteDIB - Got: %d; " "%d %d %d\n", - pixel, nRed, nGreen, nBlue); + (int) pixel, nRed, nGreen, nBlue); } /* FIXME: Not sure that this bit is needed at all */ @@ -385,11 +427,10 @@ winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap) /* - * Internal function to load the standard system palette being used by GDI + * Internal function to load the standard system palette being used by DD */ -static -Bool +static Bool winGetPaletteDD (ScreenPtr pScreen, ColormapPtr pcmap) { int i; @@ -418,7 +459,7 @@ winGetPaletteDD (ScreenPtr pScreen, ColormapPtr pcmap) } #if CYGDEBUG - ErrorF ("winGetPaletteDD - uiSystemPaletteEntries %d\n", + winDebug ("winGetPaletteDD - uiSystemPaletteEntries %d\n", uiSystemPaletteEntries); #endif @@ -444,7 +485,7 @@ winGetPaletteDD (ScreenPtr pScreen, ColormapPtr pcmap) nGreen = ppeColors[i].peGreen << 8; nBlue = ppeColors[i].peBlue << 8; #if CYGDEBUG - ErrorF ("winGetPaletteDD - Allocating a color: %d; " + winDebug ("winGetPaletteDD - Allocating a color: %d; " "%d %d %d\n", pixel, nRed, nGreen, nBlue); #endif @@ -506,13 +547,13 @@ winCreateDefColormap (ScreenPtr pScreen) Pixel wp, bp; #if CYGDEBUG - ErrorF ("winCreateDefColormap\n"); + winDebug ("winCreateDefColormap\n"); #endif /* Use standard fb colormaps for non palettized color modes */ if (pScreenInfo->dwBPP > 8) { - ErrorF ("winCreateDefColormap - Deferring to " \ + winDebug ("winCreateDefColormap - Deferring to " \ "fbCreateDefColormap ()\n"); return fbCreateDefColormap (pScreen); } @@ -528,7 +569,7 @@ winCreateDefColormap (ScreenPtr pScreen) */ #if CYGDEBUG - ErrorF ("winCreateDefColormap - defColormap: %d\n", + winDebug ("winCreateDefColormap - defColormap: %d\n", pScreen->defColormap); #endif @@ -550,7 +591,7 @@ winCreateDefColormap (ScreenPtr pScreen) } #if CYGDEBUG - ErrorF ("winCreateDefColormap - Created a colormap\n"); + winDebug ("winCreateDefColormap - Created a colormap\n"); #endif /* Branch on the visual class */ @@ -624,7 +665,7 @@ winCreateDefColormap (ScreenPtr pScreen) (*pScreen->InstallColormap)(pcmap); #if CYGDEBUG - ErrorF ("winCreateDefColormap - Returning\n"); + winDebug ("winCreateDefColormap - Returning\n"); #endif return TRUE; diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c index d62fb18d9..c6e8a7873 100644 --- a/hw/xwin/winconfig.c +++ b/hw/xwin/winconfig.c @@ -39,6 +39,7 @@ #include "XKBsrv.h" #endif +#ifdef XWIN_XF86CONFIG #ifndef CONFIGPATH #define CONFIGPATH "%A," "%R," \ "/etc/X11/%R," "%P/etc/X11/%R," \ @@ -53,14 +54,25 @@ #endif XF86ConfigPtr g_xf86configptr = NULL; +#endif + WinCmdlineRec g_cmdline = { +#ifdef XWIN_XF86CONFIG NULL, /* configFile */ +#endif NULL, /* fontPath */ NULL, /* rgbPath */ +#ifdef XWIN_XF86CONFIG NULL, /* keyboard */ +#endif #ifdef XKB FALSE, /* noXkbExtension */ NULL, /* xkbMap */ + NULL, /* xkbRules */ + NULL, /* xkbModel */ + NULL, /* xkbLayout */ + NULL, /* xkbVariant */ + NULL, /* xkbOptions */ #endif NULL, /* screenname */ NULL, /* mousename */ @@ -98,6 +110,9 @@ winInfoRec g_winInfo = { 50} }; +#define NULL_IF_EMPTY(x) (winNameCompare(x,"")?x:NULL) + +#ifdef XWIN_XF86CONFIG serverLayoutRec g_winConfigLayout; static Bool ParseOptionValue (int scrnIndex, pointer options, @@ -106,8 +121,6 @@ static Bool configLayout (serverLayoutPtr, XF86ConfLayoutPtr, char *); static Bool configImpliedLayout (serverLayoutPtr, XF86ConfScreenPtr); static Bool GetBoolValue (OptionInfoPtr p, const char *s); -#define NULL_IF_EMPTY(x) (winNameCompare(x,"")?x:NULL) - Bool winReadConfigfile () @@ -194,7 +207,7 @@ winReadConfigfile () g_xf86configptr->conf_layout_lst, NULL)) { - winMsg (X_ERROR, "Unable to determin the screen layout\n"); + winMsg (X_ERROR, "Unable to determine the screen layout\n"); return FALSE; } } @@ -204,6 +217,7 @@ winReadConfigfile () winConfigFiles (); return retval; } +#endif /* Set the keyboard configuration */ @@ -232,9 +246,10 @@ WinKBLayoutRec winKBLayouts[] = { { 0x40c, -1, "pc105", "fr", NULL, NULL, "French (Standard)"}, { 0x80c, -1, "pc105", "be", NULL, NULL, "French (Belgian)"}, { 0x410, -1, "pc105", "it", NULL, NULL, "Italian"}, - { 0x411, -1, "jp", "jp", NULL, NULL, "Japanese"}, + { 0x411, 7, "jp106", "jp", NULL, NULL, "Japanese"}, + { 0x813, -1, "pc105", "be", NULL, NULL, "Dutch (Belgian)"}, { 0x414, -1, "pc105", "no", NULL, NULL, "Norwegian"}, - { 0x416, -1, "pc105", "pt", NULL, NULL, "Portuguese (Brazil, ABNT)"}, + { 0x416, -1, "pc105", "br", NULL, NULL, "Portuguese (Brazil, ABNT)"}, {0x10416, -1, "abnt2", "br", NULL, NULL, "Portuguese (Brazil, ABNT2)"}, { 0x816, -1, "pc105", "pt", NULL, NULL, "Portuguese (Portugal)"}, { 0x41d, -1, "pc105", "se", NULL, NULL, "Swedish (Sweden)"}, @@ -245,13 +260,18 @@ WinKBLayoutRec winKBLayouts[] = { Bool winConfigKeyboard (DeviceIntPtr pDevice) { +#ifdef XKB char layoutName[KL_NAMELENGTH]; - unsigned int layoutNum; - int keyboardType; + static unsigned int layoutNum = 0; + int keyboardType; +#endif +#ifdef XWIN_XF86CONFIG XF86ConfInputPtr kbd = NULL; XF86ConfInputPtr input_list = NULL; - MessageType from = X_DEFAULT; MessageType kbdfrom = X_CONFIG; +#endif + MessageType from = X_DEFAULT; + char *s = NULL; /* Setup defaults */ #ifdef XKB @@ -270,22 +290,58 @@ winConfigKeyboard (DeviceIntPtr pDevice) g_winInfo.xkb.options = NULL; # endif /* PC98 */ + /* + * Query the windows autorepeat settings and change the xserver defaults. + * If XKB is disabled then windows handles the autorepeat and the special + * treatment is not needed + */ + { + int kbd_delay; + DWORD kbd_speed; + if (SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &kbd_delay, 0) && + SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &kbd_speed, 0)) + { + switch (kbd_delay) + { + case 0: g_winInfo.keyboard.delay = 250; break; + case 1: g_winInfo.keyboard.delay = 500; break; + case 2: g_winInfo.keyboard.delay = 750; break; + default: + case 3: g_winInfo.keyboard.delay = 1000; break; + } + g_winInfo.keyboard.rate = max(1,kbd_speed); + winMsgVerb(X_PROBED, 1, "Setting autorepeat to delay=%d, rate=%d\n", + g_winInfo.keyboard.delay, g_winInfo.keyboard.rate); + } + } keyboardType = GetKeyboardType (0); if (keyboardType > 0 && GetKeyboardLayoutName (layoutName)) { WinKBLayoutPtr pLayout; - - layoutNum = strtoul (layoutName, (char **)NULL, 16); + Bool bfound = FALSE; + + if (! layoutNum) + layoutNum = strtoul (layoutName, (char **)NULL, 16); if ((layoutNum & 0xffff) == 0x411) { /* The japanese layouts know a lot of different IMEs which all have - different layout numbers set. Map them to a single entry. - Same might apply for chinese, korean and other symbol languages - too */ + different layout numbers set. Map them to a single entry. + Same might apply for chinese, korean and other symbol languages + too */ layoutNum = (layoutNum & 0xffff); + if (keyboardType == 7) + { + /* Japanese layouts have problems with key event messages + such as the lack of WM_KEYUP for Caps Lock key. + Loading US layout fixes this problem. */ + if (LoadKeyboardLayout("00000409", KLF_ACTIVATE) != NULL) + winMsg (X_INFO, "Loading US keyboard layout.\n"); + else + winMsg (X_ERROR, "LoadKeyboardLaout failed.\n"); + } } - winMsg (X_DEFAULT, "winConfigKeyboard - Layout: \"%s\" (%08x) \n", + winMsg (X_PROBED, "winConfigKeyboard - Layout: \"%s\" (%08x) \n", layoutName, layoutNum); for (pLayout = winKBLayouts; pLayout->winlayout != -1; pLayout++) @@ -295,9 +351,10 @@ winConfigKeyboard (DeviceIntPtr pDevice) if (pLayout->winkbtype > 0 && pLayout->winkbtype != keyboardType) continue; - winMsg (X_DEFAULT, - "Using preset keyboard for \"%s\" (%s), type \"%d\"\n", - pLayout->layoutname, layoutName, keyboardType); + bfound = TRUE; + winMsg (X_PROBED, + "Using preset keyboard for \"%s\" (%x), type \"%d\"\n", + pLayout->layoutname, pLayout->winlayout, keyboardType); g_winInfo.xkb.model = pLayout->xkbmodel; g_winInfo.xkb.layout = pLayout->xkblayout; @@ -305,6 +362,31 @@ winConfigKeyboard (DeviceIntPtr pDevice) g_winInfo.xkb.options = pLayout->xkboptions; break; } + + if (!bfound) + { + HKEY regkey = NULL; + const char regtempl[] = + "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"; + char *regpath; + char lname[256]; + DWORD namesize = sizeof(lname); + + regpath = alloca(sizeof(regtempl) + KL_NAMELENGTH + 1); + strcpy(regpath, regtempl); + strcat(regpath, layoutName); + + if (!RegOpenKey(HKEY_LOCAL_MACHINE, regpath, ®key) && + !RegQueryValueEx(regkey, "Layout Text", 0, NULL, lname, &namesize)) + { + winMsg (X_ERROR, + "Keyboardlayout \"%s\" (%s) is unknown\n", lname, layoutName); + } + + /* Close registry key */ + if (regkey) + RegCloseKey (regkey); + } } g_winInfo.xkb.initialMap = NULL; @@ -317,7 +399,7 @@ winConfigKeyboard (DeviceIntPtr pDevice) #endif /* XKB */ /* parse the configuration */ - +#ifdef XWIN_XF86CONFIG if (g_cmdline.keyboard) kbdfrom = X_CMDLINE; @@ -344,10 +426,29 @@ winConfigKeyboard (DeviceIntPtr pDevice) if (kbd != NULL) { + if (kbd->inp_identifier) winMsg (kbdfrom, "Using keyboard \"%s\" as primary keyboard\n", kbd->inp_identifier); + if ((s = winSetStrOption(kbd->inp_option_lst, "AutoRepeat", NULL))) + { + if ((sscanf(s, "%ld %ld", &g_winInfo.keyboard.delay, + &g_winInfo.keyboard.rate) != 2) || + (g_winInfo.keyboard.delay < 1) || + (g_winInfo.keyboard.rate == 0) || + (1000 / g_winInfo.keyboard.rate) < 1) + { + winErrorFVerb (2, "\"%s\" is not a valid AutoRepeat value", s); + xfree(s); + return FALSE; + } + xfree(s); + winMsg (X_CONFIG, "AutoRepeat: %ld %ld\n", + g_winInfo.keyboard.delay, g_winInfo.keyboard.rate); + } +#endif + #ifdef XKB from = X_DEFAULT; if (g_cmdline.noXkbExtension) @@ -355,6 +456,7 @@ winConfigKeyboard (DeviceIntPtr pDevice) from = X_CMDLINE; g_winInfo.xkb.disable = TRUE; } +#ifdef XWIN_XF86CONFIG else if (kbd->inp_option_lst) { int b = winSetBoolOption (kbd->inp_option_lst, "XkbDisable", FALSE); @@ -364,44 +466,109 @@ winConfigKeyboard (DeviceIntPtr pDevice) g_winInfo.xkb.disable = TRUE; } } +#endif if (g_winInfo.xkb.disable) { winMsg (from, "XkbExtension disabled\n"); } else { - char *s; - - if ((s = winSetStrOption (kbd->inp_option_lst, "XkbRules", NULL))) + s = NULL; + if (g_cmdline.xkbRules) + { + s = g_cmdline.xkbRules; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbRules", NULL); + from = X_CONFIG; + } +#endif + if (s) { g_winInfo.xkb.rules = NULL_IF_EMPTY (s); - winMsg (X_CONFIG, "XKB: rules: \"%s\"\n", s); + winMsg (from, "XKB: rules: \"%s\"\n", s); } - - if ((s = winSetStrOption (kbd->inp_option_lst, "XkbModel", NULL))) + + s = NULL; + if (g_cmdline.xkbModel) + { + s = g_cmdline.xkbModel; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbModel", NULL); + from = X_CONFIG; + } +#endif + if (s) { g_winInfo.xkb.model = NULL_IF_EMPTY (s); - winMsg (X_CONFIG, "XKB: model: \"%s\"\n", s); + winMsg (from, "XKB: model: \"%s\"\n", s); } - if ((s = winSetStrOption (kbd->inp_option_lst, "XkbLayout", NULL))) + s = NULL; + if (g_cmdline.xkbLayout) + { + s = g_cmdline.xkbLayout; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbLayout", NULL); + from = X_CONFIG; + } +#endif + if (s) { g_winInfo.xkb.layout = NULL_IF_EMPTY (s); - winMsg (X_CONFIG, "XKB: layout: \"%s\"\n", s); + winMsg (from, "XKB: layout: \"%s\"\n", s); } - if ((s = winSetStrOption (kbd->inp_option_lst, "XkbVariant", NULL))) + s = NULL; + if (g_cmdline.xkbVariant) + { + s = g_cmdline.xkbVariant; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbVariant", NULL); + from = X_CONFIG; + } +#endif + if (s) { g_winInfo.xkb.variant = NULL_IF_EMPTY (s); - winMsg (X_CONFIG, "XKB: variant: \"%s\"\n", s); + winMsg (from, "XKB: variant: \"%s\"\n", s); } - if ((s = winSetStrOption (kbd->inp_option_lst, "XkbOptions", NULL))) + s = NULL; + if (g_cmdline.xkbOptions) + { + s = g_cmdline.xkbOptions; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbOptions", NULL); + from = X_CONFIG; + } +#endif + if (s) { g_winInfo.xkb.options = NULL_IF_EMPTY (s); - winMsg (X_CONFIG, "XKB: options: \"%s\"\n", s); + winMsg (from, "XKB: options: \"%s\"\n", s); } +#ifdef XWIN_XF86CONFIG from = X_CMDLINE; if (!XkbInitialMap) { @@ -433,16 +600,14 @@ winConfigKeyboard (DeviceIntPtr pDevice) winMsg (X_CONFIG, "XKB: types: \"%s\"\n", s); } - if ( - (s = + if ((s = winSetStrOption (kbd->inp_option_lst, "XkbKeycodes", NULL))) { g_winInfo.xkb.keycodes = NULL_IF_EMPTY (s); winMsg (X_CONFIG, "XKB: keycodes: \"%s\"\n", s); } - if ( - (s = + if ((s = winSetStrOption (kbd->inp_option_lst, "XkbGeometry", NULL))) { g_winInfo.xkb.geometry = NULL_IF_EMPTY (s); @@ -454,23 +619,23 @@ winConfigKeyboard (DeviceIntPtr pDevice) g_winInfo.xkb.symbols = NULL_IF_EMPTY (s); winMsg (X_CONFIG, "XKB: symbols: \"%s\"\n", s); } - } #endif +#endif + } +#ifdef XWIN_XF86CONFIG } - else - { - winMsg (X_ERROR, "No primary keyboard configured\n"); - winMsg (X_DEFAULT, "Using compiletime defaults for keyboard\n"); - } +#endif return TRUE; } +#ifdef XWIN_XF86CONFIG Bool winConfigMouse (DeviceIntPtr pDevice) { MessageType mousefrom = X_CONFIG; + XF86ConfInputPtr mouse = NULL; XF86ConfInputPtr input_list = NULL; @@ -563,6 +728,7 @@ winConfigFiles () return TRUE; } +#endif Bool @@ -579,6 +745,7 @@ winConfigScreens () } +#ifdef XWIN_XF86CONFIG char * winSetStrOption (pointer optlist, const char *name, char *deflt) { @@ -632,6 +799,7 @@ winSetRealOption (pointer optlist, const char *name, double deflt) deflt = o.value.realnum; return deflt; } +#endif /* @@ -680,6 +848,7 @@ winNameCompare (const char *s1, const char *s2) } +#ifdef XWIN_XF86CONFIG /* * Find the named option in the list. * @return the pointer to the option record, or NULL if not found. @@ -987,6 +1156,7 @@ GetBoolValue (OptionInfoPtr p, const char *s) } return TRUE; } +#endif char * @@ -1017,3 +1187,4 @@ winNormalizeName (const char *s) *q = '\0'; return ret; } + diff --git a/hw/xwin/winconfig.h b/hw/xwin/winconfig.h index 6f07ea9bc..8b7702501 100644 --- a/hw/xwin/winconfig.h +++ b/hw/xwin/winconfig.h @@ -1,3 +1,5 @@ +#ifndef __WIN_CONFIG_H__ +#define __WIN_CONFIG_H__ /* *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. * @@ -27,11 +29,12 @@ * * Authors: Alexander Gottwald */ -#ifndef __WIN_CONFIG_H__ -#define __WIN_CONFIG_H__ +/* $Id$ */ #include "win.h" +#ifdef XWIN_XF86CONFIG #include "../xfree86/parser/xf86Parser.h" +#endif /* These are taken from hw/xfree86/common/xf86str.h */ @@ -184,14 +187,23 @@ serverLayoutRec, *serverLayoutPtr; typedef struct { /* Files */ +#ifdef XWIN_XF86CONFIG char *configFile; +#endif char *fontPath; char *rgbPath; /* input devices - keyboard */ +#ifdef XWIN_XF86CONFIG char *keyboard; +#endif #ifdef XKB Bool noXkbExtension; char *xkbMap; + char *xkbRules; + char *xkbModel; + char *xkbLayout; + char *xkbVariant; + char *xkbOptions; #endif /* layout */ char *screenname; @@ -204,8 +216,9 @@ WinCmdlineRec, *WinCmdlinePtr; extern WinCmdlineRec g_cmdline; - +#ifdef XWIN_XF86CONFIG extern XF86ConfigPtr g_xf86configptr; +#endif extern serverLayoutRec g_winConfigLayout; @@ -281,9 +294,10 @@ char *winSetStrOption (pointer optlist, const char *name, char *deflt); int winSetBoolOption (pointer optlist, const char *name, int deflt); int winSetIntOption (pointer optlist, const char *name, int deflt); double winSetRealOption (pointer optlist, const char *name, double deflt); - +#ifdef XWIN_XF86CONFIG XF86OptionPtr winFindOption (XF86OptionPtr list, const char *name); char *winFindOptionValue (XF86OptionPtr list, const char *name); +#endif int winNameCompare (const char *s1, const char *s2); char *winNormalizeName (const char *s); diff --git a/hw/xwin/wincreatewnd.c b/hw/xwin/wincreatewnd.c index 10d2273cd..7a1c6f352 100644 --- a/hw/xwin/wincreatewnd.c +++ b/hw/xwin/wincreatewnd.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2001 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,23 +15,25 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/wincreatewnd.c,v 1.4 2002/10/17 08:18:22 alanh Exp $ */ #include "win.h" #include "shellapi.h" +#ifndef ABS_AUTOHIDE +#define ABS_AUTOHIDE 1 +#endif /* * Local function prototypes @@ -60,7 +62,7 @@ winCreateBoundingWindowFullScreen (ScreenPtr pScreen) char szTitle[256]; #if CYGDEBUG - ErrorF ("winCreateBoundingWindowFullScreen\n"); + winDebug ("winCreateBoundingWindowFullScreen\n"); #endif /* Setup our window class */ @@ -90,7 +92,7 @@ winCreateBoundingWindowFullScreen (ScreenPtr pScreen) (int) pScreenInfo->dwScreen); /* Create the window */ - *phwnd = CreateWindowExA (WS_EX_TOPMOST, /* Extended styles */ + *phwnd = CreateWindowExA (0, /* Extended styles */ WINDOW_CLASS, /* Class name */ szTitle, /* Window name */ WS_POPUP, @@ -106,10 +108,12 @@ winCreateBoundingWindowFullScreen (ScreenPtr pScreen) /* Branch on the server engine */ switch (pScreenInfo->dwEngine) { +#ifdef XWIN_NATIVEGDI case WIN_SERVER_SHADOW_GDI: /* Show the window */ ShowWindow (*phwnd, SW_SHOWMAXIMIZED); break; +#endif default: /* Hide the window */ @@ -144,18 +148,24 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) DWORD dwWindowStyle; char szTitle[256]; - ErrorF ("winCreateBoundingWindowWindowed - User w: %d h: %d\n", - pScreenInfo->dwUserWidth, pScreenInfo->dwUserHeight); - ErrorF ("winCreateBoundingWindowWindowed - Current w: %d h: %d\n", - pScreenInfo->dwWidth, pScreenInfo->dwHeight); - + winDebug ("winCreateBoundingWindowWindowed - User w: %d h: %d\n", + (int) pScreenInfo->dwUserWidth, (int) pScreenInfo->dwUserHeight); + winDebug ("winCreateBoundingWindowWindowed - Current w: %d h: %d\n", + (int) pScreenInfo->dwWidth, (int) pScreenInfo->dwHeight); + /* Set the common window style flags */ dwWindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX; /* Decorated or undecorated window */ if (pScreenInfo->fDecoration +#ifdef XWIN_MULTIWINDOWEXTWM + && !pScreenInfo->fMWExtWM +#endif && !pScreenInfo->fRootless - && !pScreenInfo->fMultiWindow) +#ifdef XWIN_MULTIWINDOW + && !pScreenInfo->fMultiWindow +#endif + ) { dwWindowStyle |= WS_CAPTION; if (pScreenInfo->fScrollbars) @@ -188,23 +198,29 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) { /* User gave a desired height and width, try to accomodate */ #if CYGDEBUG - ErrorF ("winCreateBoundingWindowWindowed - User gave height " + winDebug ("winCreateBoundingWindowWindowed - User gave height " "and width\n"); #endif /* Adjust the window width and height for borders and title bar */ if (pScreenInfo->fDecoration +#ifdef XWIN_MULTIWINDOWEXTWM + && !pScreenInfo->fMWExtWM +#endif && !pScreenInfo->fRootless - && !pScreenInfo->fMultiWindow) +#ifdef XWIN_MULTIWINDOW + && !pScreenInfo->fMultiWindow +#endif + ) { #if CYGDEBUG - ErrorF ("winCreateBoundingWindowWindowed - Window has decoration\n"); + winDebug ("winCreateBoundingWindowWindowed - Window has decoration\n"); #endif /* Are we using scrollbars? */ if (pScreenInfo->fScrollbars) { #if CYGDEBUG - ErrorF ("winCreateBoundingWindowWindowed - Window has " + winDebug ("winCreateBoundingWindowWindowed - Window has " "scrollbars\n"); #endif @@ -215,7 +231,7 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) else { #if CYGDEBUG - ErrorF ("winCreateBoundingWindowWindowed - Window does not have " + winDebug ("winCreateBoundingWindowWindowed - Window does not have " "scrollbars\n"); #endif @@ -247,7 +263,7 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) { /* By default, we are creating a window that is as large as possible */ #if CYGDEBUG - ErrorF ("winCreateBoundingWindowWindowed - User did not give " + winDebug ("winCreateBoundingWindowWindowed - User did not give " "height and width\n"); #endif /* Defaults are wrong if we have multiple monitors */ @@ -260,8 +276,14 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) /* Clean up the scrollbars flag, if necessary */ if ((!pScreenInfo->fDecoration +#ifdef XWIN_MULTIWINDOWEXTWM + || pScreenInfo->fMWExtWM +#endif || pScreenInfo->fRootless - || pScreenInfo->fMultiWindow) +#ifdef XWIN_MULTIWINDOW + || pScreenInfo->fMultiWindow +#endif + ) && pScreenInfo->fScrollbars) { /* We cannot have scrollbars if we do not have a window border */ @@ -277,7 +299,7 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) iHeight = rcWorkArea.bottom - rcWorkArea.top; #if CYGDEBUG - ErrorF ("winCreateBoundingWindowWindowed - Adjusted width: %d "\ + winDebug ("winCreateBoundingWindowWindowed - Adjusted width: %d "\ "height: %d\n", iWidth, iHeight); #endif @@ -315,7 +337,7 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) } #if CYGDEBUG - ErrorF ("winCreateBoundingWindowWindowed - CreateWindowEx () returned\n"); + winDebug ("winCreateBoundingWindowWindowed - CreateWindowEx () returned\n"); #endif /* Get the client area coordinates */ @@ -326,7 +348,7 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) return FALSE; } - ErrorF ("winCreateBoundingWindowWindowed - WindowClient " + winDebug ("winCreateBoundingWindowWindowed - WindowClient " "w %ld h %ld r %ld l %ld b %ld t %ld\n", rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, @@ -382,21 +404,28 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) /* Setup the width range and page size */ si.nMax = pScreenInfo->dwWidth - 1; si.nPage = rcClient.right - rcClient.left; - ErrorF ("winCreateBoundingWindowWindowed - HORZ nMax: %d nPage :%d\n", + winDebug ("winCreateBoundingWindowWindowed - HORZ nMax: %d nPage :%d\n", si.nMax, si.nPage); SetScrollInfo (*phwnd, SB_HORZ, &si, TRUE); /* Setup the height range and page size */ si.nMax = pScreenInfo->dwHeight - 1; si.nPage = rcClient.bottom - rcClient.top; - ErrorF ("winCreateBoundingWindowWindowed - VERT nMax: %d nPage :%d\n", + winDebug ("winCreateBoundingWindowWindowed - VERT nMax: %d nPage :%d\n", si.nMax, si.nPage); SetScrollInfo (*phwnd, SB_VERT, &si, TRUE); } #endif /* Show the window */ - if (pScreenInfo->fMultiWindow) + if (FALSE +#ifdef XWIN_MULTIWINDOWEXTWM + || pScreenInfo->fMWExtWM +#endif +#ifdef XWIN_MULTIWINDOW + || pScreenInfo->fMultiWindow +#endif + ) { pScreenPriv->fRootWindowShown = FALSE; ShowWindow (*phwnd, SW_HIDE); @@ -410,18 +439,31 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) } /* Attempt to bring our window to the top of the display */ - if (!BringWindowToTop (*phwnd)) + if (TRUE +#ifdef XWIN_MULTIWINDOWEXTWM + && !pScreenInfo->fMWExtWM +#endif + && !pScreenInfo->fRootless +#ifdef XWIN_MULTIWINDOW + && !pScreenInfo->fMultiWindow +#endif + ) { - ErrorF ("winCreateBoundingWindowWindowed - BringWindowToTop () " - "failed\n"); - return FALSE; + if (!BringWindowToTop (*phwnd)) + { + ErrorF ("winCreateBoundingWindowWindowed - BringWindowToTop () " + "failed\n"); + return FALSE; + } } +#ifdef XWIN_NATIVEGDI /* Paint window background blue */ if (pScreenInfo->dwEngine == WIN_SERVER_NATIVE_GDI) winPaintBackground (*phwnd, RGB (0x00, 0x00, 0xFF)); +#endif - ErrorF ("winCreateBoundingWindowWindowed - Returning\n"); + winDebug ("winCreateBoundingWindowWindowed - Returning\n"); return TRUE; } @@ -446,27 +488,27 @@ winGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo) if (!pScreenInfo->fMultipleMonitors) return TRUE; - ErrorF ("winGetWorkArea - Original WorkArea: %d %d %d %d\n", - prcWorkArea->top, prcWorkArea->left, - prcWorkArea->bottom, prcWorkArea->right); + winDebug ("winGetWorkArea - Original WorkArea: %d %d %d %d\n", + (int) prcWorkArea->top, (int) prcWorkArea->left, + (int) prcWorkArea->bottom, (int) prcWorkArea->right); /* Get size of full virtual screen */ iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); - ErrorF ("winGetWorkArea - Virtual screen is %d x %d\n", iWidth, iHeight); + winDebug ("winGetWorkArea - Virtual screen is %d x %d\n", iWidth, iHeight); /* Get origin of full virtual screen */ iLeft = GetSystemMetrics (SM_XVIRTUALSCREEN); iTop = GetSystemMetrics (SM_YVIRTUALSCREEN); - ErrorF ("winGetWorkArea - Virtual screen origin is %d, %d\n", iLeft, iTop); + winDebug ("winGetWorkArea - Virtual screen origin is %d, %d\n", iLeft, iTop); /* Get size of primary screen */ iPrimaryWidth = GetSystemMetrics (SM_CXSCREEN); iPrimaryHeight = GetSystemMetrics (SM_CYSCREEN); - ErrorF ("winGetWorkArea - Primary screen is %d x %d\n", + winDebug ("winGetWorkArea - Primary screen is %d x %d\n", iPrimaryWidth, iPrimaryHeight); /* Work out how much of the primary screen we aren't using */ @@ -489,10 +531,10 @@ winGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo) prcWorkArea->bottom = prcWorkArea->top + iHeight - iPrimaryNonWorkAreaHeight; - ErrorF ("winGetWorkArea - Adjusted WorkArea for multiple " + winDebug ("winGetWorkArea - Adjusted WorkArea for multiple " "monitors: %d %d %d %d\n", - prcWorkArea->top, prcWorkArea->left, - prcWorkArea->bottom, prcWorkArea->right); + (int) prcWorkArea->top, (int) prcWorkArea->left, + (int) prcWorkArea->bottom, (int) prcWorkArea->right); return TRUE; } @@ -509,22 +551,22 @@ winAdjustForAutoHide (RECT *prcWorkArea) APPBARDATA abd; HWND hwndAutoHide; - ErrorF ("winAdjustForAutoHide - Original WorkArea: %d %d %d %d\n", - prcWorkArea->top, prcWorkArea->left, - prcWorkArea->bottom, prcWorkArea->right); + winDebug ("winAdjustForAutoHide - Original WorkArea: %d %d %d %d\n", + (int) prcWorkArea->top, (int) prcWorkArea->left, + (int) prcWorkArea->bottom, (int) prcWorkArea->right); /* Find out if the Windows taskbar is set to auto-hide */ ZeroMemory (&abd, sizeof (abd)); abd.cbSize = sizeof (abd); if (SHAppBarMessage (ABM_GETSTATE, &abd) & ABS_AUTOHIDE) - ErrorF ("winAdjustForAutoHide - Taskbar is auto hide\n"); + winDebug ("winAdjustForAutoHide - Taskbar is auto hide\n"); /* Look for a TOP auto-hide taskbar */ abd.uEdge = ABE_TOP; hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd); if (hwndAutoHide != NULL) { - ErrorF ("winAdjustForAutoHide - Found TOP auto-hide taskbar\n"); + winDebug ("winAdjustForAutoHide - Found TOP auto-hide taskbar\n"); prcWorkArea->top += 1; } @@ -533,7 +575,7 @@ winAdjustForAutoHide (RECT *prcWorkArea) hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd); if (hwndAutoHide != NULL) { - ErrorF ("winAdjustForAutoHide - Found LEFT auto-hide taskbar\n"); + winDebug ("winAdjustForAutoHide - Found LEFT auto-hide taskbar\n"); prcWorkArea->left += 1; } @@ -542,7 +584,7 @@ winAdjustForAutoHide (RECT *prcWorkArea) hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd); if (hwndAutoHide != NULL) { - ErrorF ("winAdjustForAutoHide - Found BOTTOM auto-hide taskbar\n"); + winDebug ("winAdjustForAutoHide - Found BOTTOM auto-hide taskbar\n"); prcWorkArea->bottom -= 1; } @@ -551,19 +593,19 @@ winAdjustForAutoHide (RECT *prcWorkArea) hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd); if (hwndAutoHide != NULL) { - ErrorF ("winAdjustForAutoHide - Found RIGHT auto-hide taskbar\n"); + winDebug ("winAdjustForAutoHide - Found RIGHT auto-hide taskbar\n"); prcWorkArea->right -= 1; } - ErrorF ("winAdjustForAutoHide - Adjusted WorkArea: %d %d %d %d\n", - prcWorkArea->top, prcWorkArea->left, - prcWorkArea->bottom, prcWorkArea->right); + winDebug ("winAdjustForAutoHide - Adjusted WorkArea: %d %d %d %d\n", + (int) prcWorkArea->top, (int) prcWorkArea->left, + (int) prcWorkArea->bottom, (int) prcWorkArea->right); #if 0 /* Obtain the task bar window dimensions */ abd.hWnd = hwndAutoHide; hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETTASKBARPOS, &abd); - ErrorF ("hwndAutoHide %08x abd.hWnd %08x %d %d %d %d\n", + winDebug ("hwndAutoHide %08x abd.hWnd %08x %d %d %d %d\n", hwndAutoHide, abd.hWnd, abd.rc.top, abd.rc.left, abd.rc.bottom, abd.rc.right); #endif diff --git a/hw/xwin/wincursor.c b/hw/xwin/wincursor.c index 9e053a7d2..40ffe7364 100644 --- a/hw/xwin/wincursor.c +++ b/hw/xwin/wincursor.c @@ -33,6 +33,38 @@ /* $XFree86: xc/programs/Xserver/hw/xwin/wincursor.c,v 1.5 2002/07/05 09:19:26 alanh Exp $ */ #include "win.h" +#include "winmsg.h" +#include <cursorstr.h> +#include <mipointrst.h> +#include <servermd.h> + + +#ifndef MIN +#define MIN(x,y) ((x)<(y)?(x):(y)) +#endif + +#define BYTE_COUNT(x) (((x) + 7) / 8) + +#define BRIGHTNESS(x) (x##Red * 0.299 + x##Green * 0.587 + x##Blue * 0.114) + +#if 0 +# define WIN_DEBUG_MSG winDebug +#else +# define WIN_DEBUG_MSG(...) +#endif + +/* + * Local function prototypes + */ + +static void +winPointerWarpCursor (ScreenPtr pScreen, int x, int y); + +static Bool +winCursorOffScreen (ScreenPtr *ppScreen, int *x, int *y); + +static void +winCrossScreen (ScreenPtr pScreen, Bool fEntering); miPointerScreenFuncRec g_winPointerCursorFuncs = { @@ -42,7 +74,7 @@ miPointerScreenFuncRec g_winPointerCursorFuncs = }; -void +static void winPointerWarpCursor (ScreenPtr pScreen, int x, int y) { winScreenPriv(pScreen); @@ -57,7 +89,7 @@ winPointerWarpCursor (ScreenPtr pScreen, int x, int y) /* Don't ignore subsequent warps */ s_fInitialWarp = FALSE; - ErrorF ("winPointerWarpCursor - Discarding first warp: %d %d\n", + winErrorFVerb (2, "winPointerWarpCursor - Discarding first warp: %d %d\n", x, y); return; @@ -86,14 +118,495 @@ winPointerWarpCursor (ScreenPtr pScreen, int x, int y) miPointerWarpCursor (pScreen, x, y); } -Bool +static Bool winCursorOffScreen (ScreenPtr *ppScreen, int *x, int *y) { return FALSE; } -void +static void winCrossScreen (ScreenPtr pScreen, Bool fEntering) { } +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) +{ + winScreenPriv(pScreen); + HCURSOR hCursor = NULL; + unsigned char *pAnd; + unsigned char *pXor; + int nCX, nCY; + int nBytes; + double dForeY, dBackY; + BOOL fReverse; + HBITMAP hAnd, hXor; + ICONINFO ii; + unsigned char *pCur; + int x, y; + unsigned char bit; + HDC hDC; + BITMAPV4HEADER bi; + BITMAPINFO *pbmi; + unsigned long *lpBits; + + WIN_DEBUG_MSG("winLoadCursor: Win32: %dx%d X11: %dx%d hotspot: %d,%d\n", + pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy, + pCursor->bits->width, pCursor->bits->height, + pCursor->bits->xhot, pCursor->bits->yhot + ); + + /* We can use only White and Black, so calc brightness of color + * Also check if the cursor is inverted */ + dForeY = BRIGHTNESS(pCursor->fore); + dBackY = BRIGHTNESS(pCursor->back); + fReverse = dForeY < dBackY; + + /* Check wether the X11 cursor is bigger than the win32 cursor */ + if (pScreenPriv->cursor.sm_cx < pCursor->bits->width || + pScreenPriv->cursor.sm_cy < pCursor->bits->height) + { + winErrorFVerb (2, "winLoadCursor - Windows requires %dx%d cursor\n" + "\tbut X requires %dx%d\n", + pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy, + pCursor->bits->width, pCursor->bits->height); + } + + /* Get the number of bytes required to store the whole cursor image + * This is roughly (sm_cx * sm_cy) / 8 + * round up to 8 pixel boundary so we can convert whole bytes */ + nBytes = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * pScreenPriv->cursor.sm_cy; + + /* Get the effective width and height */ + nCX = MIN(pScreenPriv->cursor.sm_cx, pCursor->bits->width); + nCY = MIN(pScreenPriv->cursor.sm_cy, pCursor->bits->height); + + /* Allocate memory for the bitmaps */ + pAnd = malloc (nBytes); + memset (pAnd, 0xFF, nBytes); + pXor = malloc (nBytes); + memset (pXor, 0x00, nBytes); + + /* Convert the X11 bitmap to a win32 bitmap + * The first is for an empty mask */ + if (pCursor->bits->emptyMask) + { + int x, y, xmax = BYTE_COUNT(nCX); + for (y = 0; y < nCY; ++y) + for (x = 0; x < xmax; ++x) + { + int nWinPix = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * y + x; + int nXPix = BitmapBytePad(pCursor->bits->width) * y + x; + + pAnd[nWinPix] = 0; + if (fReverse) + pXor[nWinPix] = reverse (~pCursor->bits->source[nXPix]); + else + pXor[nWinPix] = reverse (pCursor->bits->source[nXPix]); + } + } + else + { + int x, y, xmax = BYTE_COUNT(nCX); + for (y = 0; y < nCY; ++y) + for (x = 0; x < xmax; ++x) + { + int nWinPix = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * y + x; + int nXPix = BitmapBytePad(pCursor->bits->width) * y + x; + + unsigned char mask = pCursor->bits->mask[nXPix]; + pAnd[nWinPix] = reverse (~mask); + if (fReverse) + pXor[nWinPix] = reverse (~pCursor->bits->source[nXPix] & mask); + else + pXor[nWinPix] = reverse (pCursor->bits->source[nXPix] & mask); + } + } + + /* prepare the pointers */ + hCursor = NULL; + lpBits = NULL; + + /* We have a truecolor alpha-blended cursor and can use it! */ + if (pCursor->bits->argb) + { + WIN_DEBUG_MSG("winLoadCursor: Trying truecolor alphablended cursor\n"); + memset (&bi, 0, sizeof (BITMAPV4HEADER)); + bi.bV4Size = sizeof(BITMAPV4HEADER); + bi.bV4Width = pScreenPriv->cursor.sm_cx; + bi.bV4Height = -(pScreenPriv->cursor.sm_cy); /* right-side up */ + bi.bV4Planes = 1; + bi.bV4BitCount = 32; + bi.bV4V4Compression = BI_BITFIELDS; + bi.bV4RedMask = 0x00FF0000; + bi.bV4GreenMask = 0x0000FF00; + bi.bV4BlueMask = 0x000000FF; + bi.bV4AlphaMask = 0xFF000000; + + lpBits = (unsigned long *) calloc (pScreenPriv->cursor.sm_cx*pScreenPriv->cursor.sm_cy, + sizeof (unsigned long)); + + if (lpBits) + { + for (y=0; y<nCY; y++) + { + unsigned long *src, *dst; + src = &(pCursor->bits->argb[y * pCursor->bits->width]); + dst = &(lpBits[y * pScreenPriv->cursor.sm_cx]); + memcpy (dst, src, 4*nCX); + } + } + } /* End if-truecolor-icon */ + + if (!lpBits) + { + /* Bicolor, use a palettized DIB */ + WIN_DEBUG_MSG("winLoadCursor: Trying two color cursor\n"); + pbmi = (BITMAPINFO*)&bi; + memset (pbmi, 0, sizeof (BITMAPINFOHEADER)); + pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + pbmi->bmiHeader.biWidth = pScreenPriv->cursor.sm_cx; + pbmi->bmiHeader.biHeight = -abs(pScreenPriv->cursor.sm_cy); /* right-side up */ + pbmi->bmiHeader.biPlanes = 1; + pbmi->bmiHeader.biBitCount = 8; + pbmi->bmiHeader.biCompression = BI_RGB; + pbmi->bmiHeader.biSizeImage = 0; + pbmi->bmiHeader.biClrUsed = 3; + pbmi->bmiHeader.biClrImportant = 3; + pbmi->bmiColors[0].rgbRed = 0; /* Empty */ + pbmi->bmiColors[0].rgbGreen = 0; + pbmi->bmiColors[0].rgbBlue = 0; + pbmi->bmiColors[0].rgbReserved = 0; + pbmi->bmiColors[1].rgbRed = pCursor->backRed>>8; /* Background */ + pbmi->bmiColors[1].rgbGreen = pCursor->backGreen>>8; + pbmi->bmiColors[1].rgbBlue = pCursor->backBlue>>8; + pbmi->bmiColors[1].rgbReserved = 0; + pbmi->bmiColors[2].rgbRed = pCursor->foreRed>>8; /* Foreground */ + pbmi->bmiColors[2].rgbGreen = pCursor->foreGreen>>8; + pbmi->bmiColors[2].rgbBlue = pCursor->foreBlue>>8; + pbmi->bmiColors[2].rgbReserved = 0; + + lpBits = (unsigned long *) calloc (pScreenPriv->cursor.sm_cx*pScreenPriv->cursor.sm_cy, + sizeof (char)); + + pCur = (unsigned char *)lpBits; + if (lpBits) + { + for (y=0; y<pScreenPriv->cursor.sm_cy; y++) + { + for (x=0; x<pScreenPriv->cursor.sm_cx; x++) + { + if (x>=nCX || y>=nCY) /* Outside of X11 icon bounds */ + (*pCur++) = 0; + else /* Within X11 icon bounds */ + { + int nWinPix = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * y + (x/8); + + bit = pAnd[nWinPix]; + bit = bit & (1<<(7-(x&7))); + if (!bit) /* Within the cursor mask? */ + { + int nXPix = BitmapBytePad(pCursor->bits->width) * y + (x/8); + bit = ~reverse(~pCursor->bits->source[nXPix] & pCursor->bits->mask[nXPix]); + bit = bit & (1<<(7-(x&7))); + if (bit) /* Draw foreground */ + (*pCur++) = 2; + else /* Draw background */ + (*pCur++) = 1; + } + else /* Outside the cursor mask */ + (*pCur++) = 0; + } + } /* end for (x) */ + } /* end for (y) */ + } /* end if (lpbits) */ + } + + /* If one of the previous two methods gave us the bitmap we need, make a cursor */ + if (lpBits) + { + WIN_DEBUG_MSG("winLoadCursor: Creating bitmap cursor: hotspot %d,%d\n", + pCursor->bits->xhot, pCursor->bits->yhot); + + hAnd = NULL; + hXor = NULL; + + hAnd = CreateBitmap (pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy, 1, 1, pAnd); + + hDC = GetDC (NULL); + if (hDC) + { + hXor = CreateCompatibleBitmap (hDC, pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy); + SetDIBits (hDC, hXor, 0, pScreenPriv->cursor.sm_cy, lpBits, (BITMAPINFO*)&bi, DIB_RGB_COLORS); + ReleaseDC (NULL, hDC); + } + free (lpBits); + + + if (hAnd && hXor) + { + ii.fIcon = FALSE; + ii.xHotspot = pCursor->bits->xhot; + ii.yHotspot = pCursor->bits->yhot; + ii.hbmMask = hAnd; + ii.hbmColor = hXor; + hCursor = (HCURSOR) CreateIconIndirect( &ii ); + + if (hCursor == NULL) + winW32Error(2, "winLoadCursor - CreateIconIndirect failed:"); + else + { + if (GetIconInfo(hCursor, &ii)) + { + if (ii.fIcon) + { + WIN_DEBUG_MSG("winLoadCursor: CreateIconIndirect returned no cursor. Trying again.\n"); + + DestroyCursor(hCursor); + + ii.fIcon = FALSE; + ii.xHotspot = pCursor->bits->xhot; + ii.yHotspot = pCursor->bits->yhot; + hCursor = (HCURSOR) CreateIconIndirect( &ii ); + + if (hCursor == NULL) + winW32Error(2, "winLoadCursor - CreateIconIndirect failed:"); + } + /* GetIconInfo creates new bitmaps. Destroy them again */ + if (ii.hbmMask) + DeleteObject(ii.hbmMask); + if (ii.hbmColor) + DeleteObject(ii.hbmColor); + } + } + } + + if (hAnd) + DeleteObject (hAnd); + if (hXor) + DeleteObject (hXor); + } + + if (!hCursor) + { + /* We couldn't make a color cursor for this screen, use + black and white instead */ + hCursor = CreateCursor (g_hInstance, + pCursor->bits->xhot, pCursor->bits->yhot, + pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy, + pAnd, pXor); + if (hCursor == NULL) + winW32Error(2, "winLoadCursor - CreateCursor failed:"); + } + free (pAnd); + free (pXor); + + return hCursor; +} + +/* +=========================================================================== + + Pointer sprite functions + +=========================================================================== +*/ + +/* + * winRealizeCursor + * Convert the X cursor representation to native format if possible. + */ +static Bool +winRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor) +{ + WIN_DEBUG_MSG("winRealizeCursor: cursor=%p\n", pCursor); + + if(pCursor == NULL || pCursor->bits == NULL) + return FALSE; + + /* FIXME: cache ARGB8888 representation? */ + + return TRUE; +} + + +/* + * winUnrealizeCursor + * Free the storage space associated with a realized cursor. + */ +static Bool +winUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) +{ + WIN_DEBUG_MSG("winUnrealizeCursor: cursor=%p\n", pCursor); + return TRUE; +} + + +/* + * winSetCursor + * Set the cursor sprite and position. + */ +static void +winSetCursor (ScreenPtr pScreen, CursorPtr pCursor, int x, int y) +{ + POINT ptCurPos, ptTemp; + HWND hwnd; + RECT rcClient; + BOOL bInhibit; + winScreenPriv(pScreen); + WIN_DEBUG_MSG("winSetCursor: cursor=%p\n", pCursor); + + /* Inhibit changing the cursor if the mouse is not in a client area */ + bInhibit = FALSE; + if (GetCursorPos (&ptCurPos)) + { + hwnd = WindowFromPoint (ptCurPos); + if (hwnd) + { + if (GetClientRect (hwnd, &rcClient)) + { + ptTemp.x = rcClient.left; + ptTemp.y = rcClient.top; + if (ClientToScreen (hwnd, &ptTemp)) + { + rcClient.left = ptTemp.x; + rcClient.top = ptTemp.y; + ptTemp.x = rcClient.right; + ptTemp.y = rcClient.bottom; + if (ClientToScreen (hwnd, &ptTemp)) + { + rcClient.right = ptTemp.x; + rcClient.bottom = ptTemp.y; + if (!PtInRect (&rcClient, ptCurPos)) + bInhibit = TRUE; + } + } + } + } + } + + if (pCursor == NULL) + { + if (pScreenPriv->cursor.visible) + { + if (!bInhibit) + ShowCursor (FALSE); + pScreenPriv->cursor.visible = FALSE; + } + } + else + { + if (pScreenPriv->cursor.handle) + { + if (!bInhibit) + SetCursor (NULL); + DestroyCursor (pScreenPriv->cursor.handle); + pScreenPriv->cursor.handle = NULL; + } + pScreenPriv->cursor.handle = + winLoadCursor (pScreen, pCursor, pScreen->myNum); + WIN_DEBUG_MSG("winSetCursor: handle=%p\n", pScreenPriv->cursor.handle); + + if (!bInhibit) + SetCursor (pScreenPriv->cursor.handle); + + if (!pScreenPriv->cursor.visible) + { + if (!bInhibit) + ShowCursor (TRUE); + pScreenPriv->cursor.visible = TRUE; + } + } +} + + +/* + * QuartzMoveCursor + * Move the cursor. This is a noop for us. + */ +static void +winMoveCursor (ScreenPtr pScreen, int x, int y) +{ +} + + +static miPointerSpriteFuncRec winSpriteFuncsRec = { + winRealizeCursor, + winUnrealizeCursor, + winSetCursor, + winMoveCursor +}; + + +/* +=========================================================================== + + Other screen functions + +=========================================================================== +*/ + +/* + * winCursorQueryBestSize + * Handle queries for best cursor size + */ +static void +winCursorQueryBestSize (int class, unsigned short *width, + unsigned short *height, ScreenPtr pScreen) +{ + winScreenPriv(pScreen); + + if (class == CursorShape) + { + *width = pScreenPriv->cursor.sm_cx; + *height = pScreenPriv->cursor.sm_cy; + } + else + { + if (pScreenPriv->cursor.QueryBestSize) + (*pScreenPriv->cursor.QueryBestSize)(class, width, height, pScreen); + } +} + +/* + * winInitCursor + * Initialize cursor support + */ +Bool +winInitCursor (ScreenPtr pScreen) +{ + winScreenPriv(pScreen); + miPointerScreenPtr pPointPriv; + /* override some screen procedures */ + pScreenPriv->cursor.QueryBestSize = pScreen->QueryBestSize; + pScreen->QueryBestSize = winCursorQueryBestSize; + + pPointPriv = (miPointerScreenPtr) pScreen->devPrivates[miPointerScreenIndex].ptr; + + pScreenPriv->cursor.spriteFuncs = pPointPriv->spriteFuncs; + pPointPriv->spriteFuncs = &winSpriteFuncsRec; + + pScreenPriv->cursor.handle = NULL; + pScreenPriv->cursor.visible = FALSE; + + pScreenPriv->cursor.sm_cx = GetSystemMetrics (SM_CXCURSOR); + pScreenPriv->cursor.sm_cy = GetSystemMetrics (SM_CYCURSOR); + + return TRUE; +} diff --git a/hw/xwin/windialogs.c b/hw/xwin/windialogs.c index 07db55075..af0e4d9b8 100755 --- a/hw/xwin/windialogs.c +++ b/hw/xwin/windialogs.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,32 +15,193 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II + * Earle F. Philhower III */ -/* $XFree86: $ */ #include "win.h" +#include <sys/cygwin.h> +#include <shellapi.h> +#include "winprefs.h" + + +/* + * References to external globals + */ extern Bool g_fCursor; +extern HWND g_hDlgDepthChange; +extern HWND g_hDlgExit; +extern HWND g_hDlgAbout; +extern WINPREFS pref; +extern Bool g_fClipboardStarted; +extern Bool g_fSoftwareCursor; + + +/* + * Local function prototypes + */ -BOOL CALLBACK +static BOOL CALLBACK winExitDlgProc (HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam); -BOOL CALLBACK +static BOOL CALLBACK winChangeDepthDlgProc (HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam); +static BOOL CALLBACK +winAboutDlgProc (HWND hDialog, UINT message, + WPARAM wParam, LPARAM lParam); + + +static void +winDrawURLWindow (LPARAM lParam); + +static LRESULT CALLBACK +winURLWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + +static void +winOverrideURLButton (HWND hdlg, int id); + +static void +winUnoverrideURLButton (HWND hdlg, int id); + + +/* + * Owner-draw a button as a URL + */ + +static void +winDrawURLWindow (LPARAM lParam) +{ + DRAWITEMSTRUCT *draw; + char str[256]; + RECT rect; + HFONT font; + COLORREF crText; + + draw = (DRAWITEMSTRUCT *) lParam; + GetWindowText (draw->hwndItem, str, sizeof(str)); + str[255] = 0; + GetClientRect (draw->hwndItem, &rect); + + /* Color the button depending upon its state */ + if (draw->itemState & ODS_SELECTED) + crText = RGB(128+64,0,0); + else if (draw->itemState & ODS_FOCUS) + crText = RGB(0,128+64,0); + else + crText = RGB(0,0,128+64); + SetTextColor (draw->hDC, crText); + + /* Create underlined font 14 high, standard dialog font */ + font = CreateFont (-14, 0, 0, 0, FW_NORMAL, FALSE, TRUE, FALSE, + 0, 0, 0, 0, 0, "MS Sans Serif"); + if (!font) + { + ErrorF ("winDrawURLWindow: Unable to create URL font, bailing.\n"); + return; + } + /* Draw it */ + SetBkMode (draw->hDC, OPAQUE); + SelectObject (draw->hDC, font); + DrawText (draw->hDC, str, strlen (str),&rect,DT_CENTER | DT_VCENTER); + /* Delete the created font, replace it with stock font */ + DeleteObject (SelectObject (draw->hDC, GetStockObject (ANSI_VAR_FONT))); +} + + +/* + * WndProc for overridden buttons + */ + +static LRESULT CALLBACK +winURLWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + WNDPROC origCB = NULL; + HCURSOR cursor; + + /* If it's a SetCursor message, tell it to the hand */ + if (msg==WM_SETCURSOR) { + cursor = LoadCursor (NULL, IDC_HAND); + if (cursor) + SetCursor (cursor); + return TRUE; + } + origCB = (WNDPROC)GetWindowLong (hwnd, GWL_USERDATA); + /* Otherwise fall through to original WndProc */ + if (origCB) + return CallWindowProc (origCB, hwnd, msg, wParam, lParam); + else + return FALSE; +} + + +/* + * Register and unregister the custom WndProc + */ + +static void +winOverrideURLButton (HWND hwnd, int id) +{ + WNDPROC origCB; + origCB = (WNDPROC)SetWindowLong (GetDlgItem (hwnd, id), + GWL_WNDPROC, (LONG)winURLWndProc); + SetWindowLong (GetDlgItem (hwnd, id), GWL_USERDATA, (LONG)origCB); +} + +static void +winUnoverrideURLButton (HWND hwnd, int id) +{ + WNDPROC origCB; + origCB = (WNDPROC)SetWindowLong (GetDlgItem (hwnd, id), + GWL_USERDATA, 0); + if (origCB) + SetWindowLong (GetDlgItem (hwnd, id), GWL_WNDPROC, (LONG)origCB); +} + + +/* + * Center a dialog window in the desktop window + */ + +static void +winCenterDialog (HWND hwndDlg) +{ + HWND hwndDesk; + RECT rc, rcDlg, rcDesk; + + hwndDesk = GetParent (hwndDlg); + if (!hwndDesk || IsIconic (hwndDesk)) + hwndDesk = GetDesktopWindow (); + + GetWindowRect (hwndDesk, &rcDesk); + GetWindowRect (hwndDlg, &rcDlg); + CopyRect (&rc, &rcDesk); + + OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top); + OffsetRect (&rc, -rc.left, -rc.top); + OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom); + + SetWindowPos (hwndDlg, + HWND_TOP, + rcDesk.left + (rc.right / 2), + rcDesk.top + (rc.bottom / 2), + 0, 0, + SWP_NOSIZE | SWP_NOZORDER); +} + /* * Display the Exit dialog box @@ -49,6 +210,37 @@ winChangeDepthDlgProc (HWND hDialog, UINT message, void winDisplayExitDialog (winPrivScreenPtr pScreenPriv) { + int i; + int liveClients = 0; + + /* Count up running clinets (clients[0] is serverClient) */ + for (i = 1; i < currentMaxClients; i++) + if (clients[i] != NullClient) + liveClients++; + /* Count down server internal clients */ + if (pScreenPriv->pScreenInfo->fMultiWindow) + liveClients -= 2; /* multiwindow window manager & XMsgProc */ + if (g_fClipboardStarted) + liveClients--; /* clipboard manager */ + + /* A user reported that this sometimes drops below zero. just eye-candy. */ + if (liveClients < 0) + liveClients = 0; + + /* Don't show the exit confirmation dialog if SilentExit is enabled */ + if (pref.fSilentExit && liveClients <= 0) + { + if (g_hDlgExit != NULL) + { + DestroyWindow (g_hDlgExit); + g_hDlgExit = NULL; + } + PostMessage (pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0); + return; + } + + pScreenPriv->iConnectedClients = liveClients; + /* Check if dialog already exists */ if (g_hDlgExit != NULL) { @@ -74,8 +266,8 @@ winDisplayExitDialog (winPrivScreenPtr pScreenPriv) & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX)); SetWindowLong (g_hDlgExit, GWL_EXSTYLE, GetWindowLong (g_hDlgExit, GWL_EXSTYLE) & ~WS_EX_APPWINDOW ); - SetWindowPos (g_hDlgExit, 0, 0, 0, 0, 0, - SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE); + SetWindowPos (g_hDlgExit, HWND_TOPMOST, 0, 0, 0, 0, + SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE); /* Show the dialog box */ ShowWindow (g_hDlgExit, SW_SHOW); @@ -83,38 +275,60 @@ winDisplayExitDialog (winPrivScreenPtr pScreenPriv) /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */ SetForegroundWindow (g_hDlgExit); - /* Set focus to the Cancel buton */ + /* Set focus to the Cancel button */ PostMessage (g_hDlgExit, WM_NEXTDLGCTL, (int) GetDlgItem (g_hDlgExit, IDCANCEL), TRUE); } +#define CONNECTED_CLIENTS_FORMAT "There are currently %d clients connected." + /* * Exit dialog window procedure */ -BOOL CALLBACK +static BOOL CALLBACK winExitDlgProc (HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) { static winPrivScreenPtr s_pScreenPriv = NULL; - static winScreenInfo *s_pScreenInfo = NULL; - static ScreenPtr s_pScreen = NULL; /* Branch on message type */ switch (message) { case WM_INITDIALOG: - /* Store pointers to private structures for future use */ - s_pScreenPriv = (winPrivScreenPtr) lParam; - s_pScreenInfo = s_pScreenPriv->pScreenInfo; - s_pScreen = s_pScreenInfo->pScreen; - - /* Set icon to standard app icon */ - PostMessage (hDialog, - WM_SETICON, - ICON_SMALL, - (LPARAM) LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN))); + { + char *pszConnectedClients; + int iReturn; + + /* Store pointers to private structures for future use */ + s_pScreenPriv = (winPrivScreenPtr) lParam; + + winCenterDialog (hDialog); + + /* Set icon to standard app icon */ + PostMessage (hDialog, + WM_SETICON, + ICON_SMALL, + (LPARAM) LoadIcon (g_hInstance, + MAKEINTRESOURCE(IDI_XWIN))); + + /* Format the connected clients string */ + iReturn = sprintf (NULL, CONNECTED_CLIENTS_FORMAT, + s_pScreenPriv->iConnectedClients); + if (iReturn <= 0) + return TRUE; + pszConnectedClients = malloc (iReturn + 1); + if (!pszConnectedClients) + return TRUE; + snprintf (pszConnectedClients, iReturn + 1, CONNECTED_CLIENTS_FORMAT, + s_pScreenPriv->iConnectedClients); + + /* Set the number of connected clients */ + SetWindowText (GetDlgItem (hDialog, IDC_CLIENTS_CONNECTED), + pszConnectedClients); + free (pszConnectedClients); + } return TRUE; case WM_COMMAND: @@ -143,7 +357,7 @@ winExitDlgProc (HWND hDialog, UINT message, case WM_MOUSEMOVE: case WM_NCMOUSEMOVE: /* Show the cursor if it is hidden */ - if (!g_fCursor) + if (g_fSoftwareCursor && !g_fCursor) { g_fCursor = TRUE; ShowCursor (TRUE); @@ -207,8 +421,9 @@ winDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv) ShowWindow (g_hDlgDepthChange, SW_SHOW); ErrorF ("winDisplayDepthChangeDialog - DialogBox returned: %d\n", - g_hDlgDepthChange); - ErrorF ("winDisplayDepthChangeDialog - GetLastError: %d\n", GetLastError ()); + (int) g_hDlgDepthChange); + ErrorF ("winDisplayDepthChangeDialog - GetLastError: %d\n", + (int) GetLastError ()); /* Minimize the display window */ ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE); @@ -220,7 +435,7 @@ winDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv) * disruptive screen depth changes. */ -BOOL CALLBACK +static BOOL CALLBACK winChangeDepthDlgProc (HWND hwndDialog, UINT message, WPARAM wParam, LPARAM lParam) { @@ -229,7 +444,7 @@ winChangeDepthDlgProc (HWND hwndDialog, UINT message, static ScreenPtr s_pScreen = NULL; #if CYGDEBUG - ErrorF ("winChangeDepthDlgProc\n"); + winDebug ("winChangeDepthDlgProc\n"); #endif /* Branch on message type */ @@ -237,7 +452,7 @@ winChangeDepthDlgProc (HWND hwndDialog, UINT message, { case WM_INITDIALOG: #if CYGDEBUG - ErrorF ("winChangeDepthDlgProc - WM_INITDIALOG\n"); + winDebug ("winChangeDepthDlgProc - WM_INITDIALOG\n"); #endif /* Store pointers to private structures for future use */ @@ -246,17 +461,19 @@ winChangeDepthDlgProc (HWND hwndDialog, UINT message, s_pScreen = s_pScreenInfo->pScreen; #if CYGDEBUG - ErrorF ("winChangeDepthDlgProc - WM_INITDIALG - s_pScreenPriv: %08x, " + winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - s_pScreenPriv: %08x, " "s_pScreenInfo: %08x, s_pScreen: %08x\n", s_pScreenPriv, s_pScreenInfo, s_pScreen); #endif #if CYGDEBUG - ErrorF ("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %d, " + winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %d, " "last bpp: %d\n", s_pScreenInfo->dwBPP, s_pScreenPriv->dwLastWindowsBitsPixel); #endif + + winCenterDialog( hwndDialog ); /* Set icon to standard app icon */ PostMessage (hwndDialog, @@ -268,7 +485,7 @@ winChangeDepthDlgProc (HWND hwndDialog, UINT message, case WM_DISPLAYCHANGE: #if CYGDEBUG - ErrorF ("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, " + winDebug ("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, " "last bpp: %d, new bpp: %d\n", s_pScreenInfo->dwBPP, s_pScreenPriv->dwLastWindowsBitsPixel, @@ -308,11 +525,250 @@ winChangeDepthDlgProc (HWND hwndDialog, UINT message, case WM_CLOSE: ErrorF ("winChangeDepthDlgProc - WM_CLOSE\n"); - /* - * User dismissed the dialog, hide it until the - * display mode is restored. - */ - ShowWindow (g_hDlgDepthChange, SW_HIDE); + DestroyWindow (g_hDlgAbout); + g_hDlgAbout = NULL; + + /* Fix to make sure keyboard focus isn't trapped */ + PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0); + return TRUE; + } + + return FALSE; +} + + +/* + * Display the About dialog box + */ + +void +winDisplayAboutDialog (winPrivScreenPtr pScreenPriv) +{ + /* Check if dialog already exists */ + if (g_hDlgAbout != NULL) + { + /* Dialog box already exists, display it */ + ShowWindow (g_hDlgAbout, SW_SHOWDEFAULT); + + /* User has lost the dialog. Show them where it is. */ + SetForegroundWindow (g_hDlgAbout); + + return; + } + + /* + * Display the about box + */ + g_hDlgAbout = CreateDialogParam (g_hInstance, + "ABOUT_BOX", + pScreenPriv->hwndScreen, + winAboutDlgProc, + (int) pScreenPriv); + + /* Drop minimize and maximize buttons */ + SetWindowLong (g_hDlgAbout, GWL_STYLE, + GetWindowLong (g_hDlgAbout, GWL_STYLE) + & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX)); + SetWindowLong (g_hDlgAbout, GWL_EXSTYLE, + GetWindowLong (g_hDlgAbout, GWL_EXSTYLE) & ~WS_EX_APPWINDOW); + SetWindowPos (g_hDlgAbout, 0, 0, 0, 0, 0, + SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE); + + /* Show the dialog box */ + ShowWindow (g_hDlgAbout, SW_SHOW); + + /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */ + SetForegroundWindow (g_hDlgAbout); + + /* Set focus to the OK button */ + PostMessage (g_hDlgAbout, WM_NEXTDLGCTL, + (int) GetDlgItem (g_hDlgAbout, IDOK), TRUE); +} + + +/* + * Process messages for the about dialog. + */ + +static BOOL CALLBACK +winAboutDlgProc (HWND hwndDialog, UINT message, + WPARAM wParam, LPARAM lParam) +{ + static winPrivScreenPtr s_pScreenPriv = NULL; + static winScreenInfo *s_pScreenInfo = NULL; + static ScreenPtr s_pScreen = NULL; + +#if CYGDEBUG + winDebug ("winAboutDlgProc\n"); +#endif + + /* Branch on message type */ + switch (message) + { + case WM_INITDIALOG: +#if CYGDEBUG + winDebug ("winAboutDlgProc - WM_INITDIALOG\n"); +#endif + + /* Store pointers to private structures for future use */ + s_pScreenPriv = (winPrivScreenPtr) lParam; + s_pScreenInfo = s_pScreenPriv->pScreenInfo; + s_pScreen = s_pScreenInfo->pScreen; + + winCenterDialog (hwndDialog); + + /* Set icon to standard app icon */ + PostMessage (hwndDialog, + WM_SETICON, + ICON_SMALL, + (LPARAM) LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN))); + + /* Override the URL buttons */ + winOverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG); + winOverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE); + winOverrideURLButton (hwndDialog, ID_ABOUT_UG); + winOverrideURLButton (hwndDialog, ID_ABOUT_FAQ); + + return TRUE; + + case WM_DRAWITEM: + /* Draw the URL buttons as needed */ + winDrawURLWindow (lParam); + return TRUE; + + case WM_MOUSEMOVE: + case WM_NCMOUSEMOVE: + /* Show the cursor if it is hidden */ + if (g_fSoftwareCursor && !g_fCursor) + { + g_fCursor = TRUE; + ShowCursor (TRUE); + } + return TRUE; + + case WM_COMMAND: + switch (LOWORD (wParam)) + { + case IDOK: + case IDCANCEL: + ErrorF ("winAboutDlgProc - WM_COMMAND - IDOK or IDCANCEL\n"); + + DestroyWindow (g_hDlgAbout); + g_hDlgAbout = NULL; + + /* Fix to make sure keyboard focus isn't trapped */ + PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0); + + /* Restore window procedures for URL buttons */ + winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG); + winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE); + winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG); + winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ); + + return TRUE; + + case ID_ABOUT_CHANGELOG: + { + const char * pszCygPath = "/usr/X11R6/share/doc/" + "xorg-x11-xwin/changelog.html"; + char pszWinPath[MAX_PATH + 1]; + int iReturn; + + /* Convert the POSIX path to a Win32 path */ + cygwin_conv_to_win32_path (pszCygPath, pszWinPath); + + iReturn = (int) ShellExecute (NULL, + "open", + pszWinPath, + NULL, + NULL, + SW_MAXIMIZE); + if (iReturn < 32) + { + ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_CHANGELOG - " + "ShellExecute failed: %d\n", + iReturn); + } + } + return TRUE; + + case ID_ABOUT_WEBSITE: + { + const char * pszPath = "http://x.cygwin.com/"; + int iReturn; + + iReturn = (int) ShellExecute (NULL, + "open", + pszPath, + NULL, + NULL, + SW_MAXIMIZE); + if (iReturn < 32) + { + ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_WEBSITE - " + "ShellExecute failed: %d\n", + iReturn); + } + } + return TRUE; + + case ID_ABOUT_UG: + { + const char * pszPath = "http://x.cygwin.com/docs/ug/"; + int iReturn; + + iReturn = (int) ShellExecute (NULL, + "open", + pszPath, + NULL, + NULL, + SW_MAXIMIZE); + if (iReturn < 32) + { + ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_UG - " + "ShellExecute failed: %d\n", + iReturn); + } + } + return TRUE; + + case ID_ABOUT_FAQ: + { + const char * pszPath = "http://x.cygwin.com/docs/faq/"; + int iReturn; + + iReturn = (int) ShellExecute (NULL, + "open", + pszPath, + NULL, + NULL, + SW_MAXIMIZE); + if (iReturn < 32) + { + ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_FAQ - " + "ShellExecute failed: %d\n", + iReturn); + } + } + return TRUE; + } + break; + + case WM_CLOSE: + ErrorF ("winAboutDlgProc - WM_CLOSE\n"); + + DestroyWindow (g_hDlgAbout); + g_hDlgAbout = NULL; + + /* Fix to make sure keyboard focus isn't trapped */ + PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0); + + /* Restore window procedures for URL buttons */ + winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG); + winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE); + winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG); + winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ); + return TRUE; } diff --git a/hw/xwin/winengine.c b/hw/xwin/winengine.c index c8c2ef40f..c7eb1285b 100644 --- a/hw/xwin/winengine.c +++ b/hw/xwin/winengine.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2001 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,21 +15,21 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winengine.c,v 1.3 2002/07/05 09:19:26 alanh Exp $ */ #include "win.h" +#include "winmsg.h" /* @@ -52,7 +52,7 @@ winDetectSupportedEngines () /* Initialize the engine support flags */ g_dwEnginesSupported = WIN_SERVER_SHADOW_GDI; -#if WIN_NATIVE_GDI_SUPPORT +#ifdef XWIN_NATIVEGDI g_dwEnginesSupported |= WIN_SERVER_NATIVE_GDI; #endif @@ -66,12 +66,12 @@ winDetectSupportedEngines () { case VER_PLATFORM_WIN32_NT: /* Engine 4 is supported on NT only */ - ErrorF ("winDetectSupportedEngines - Windows NT/2000/XP\n"); + winErrorFVerb (2, "winDetectSupportedEngines - Windows NT/2000/XP\n"); break; case VER_PLATFORM_WIN32_WINDOWS: /* Engine 4 is supported on NT only */ - ErrorF ("winDetectSupportedEngines - Windows 95/98/Me\n"); + winErrorFVerb (2, "winDetectSupportedEngines - Windows 95/98/Me\n"); break; } @@ -97,21 +97,23 @@ winDetectSupportedEngines () if (FAILED (ddrval)) { /* No DirectDraw support */ - ErrorF ("winDetectSupportedEngines - DirectDraw not installed\n"); + winErrorFVerb (2, "winDetectSupportedEngines - DirectDraw not installed\n"); return; } else { /* We have DirectDraw */ - ErrorF ("winDetectSupportedEngines - DirectDraw installed\n"); + winErrorFVerb (2, "winDetectSupportedEngines - DirectDraw installed\n"); g_dwEnginesSupported |= WIN_SERVER_SHADOW_DD; +#ifdef XWIN_PRIMARYFB /* Allow PrimaryDD engine if NT */ if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) { g_dwEnginesSupported |= WIN_SERVER_PRIMARY_DD; - ErrorF ("winDetectSupportedEngines - Allowing PrimaryDD\n"); + winErrorFVerb (2, "winDetectSupportedEngines - Allowing PrimaryDD\n"); } +#endif } /* Try to query for DirectDraw4 interface */ @@ -121,7 +123,7 @@ winDetectSupportedEngines () if (SUCCEEDED (ddrval)) { /* We have DirectDraw4 */ - ErrorF ("winDetectSupportedEngines - DirectDraw4 installed\n"); + winErrorFVerb (2, "winDetectSupportedEngines - DirectDraw4 installed\n"); g_dwEnginesSupported |= WIN_SERVER_SHADOW_DDNL; } @@ -132,8 +134,8 @@ winDetectSupportedEngines () IDirectDraw_Release (lpdd); } - ErrorF ("winDetectSupportedEngines - Returning, supported engines %08x\n", - g_dwEnginesSupported); + winErrorFVerb (2, "winDetectSupportedEngines - Returning, supported engines %08x\n", + (unsigned int) g_dwEnginesSupported); } @@ -173,7 +175,7 @@ winSetEngine (ScreenPtr pScreen) /* ShadowGDI is the only engine that supports windowed PseudoColor */ if (dwBPP == 8 && !pScreenInfo->fFullScreen) { - ErrorF ("winSetEngine - Windowed && PseudoColor => ShadowGDI\n"); + winErrorFVerb (2, "winSetEngine - Windowed && PseudoColor => ShadowGDI\n"); pScreenInfo->dwEngine = WIN_SERVER_SHADOW_GDI; /* Set engine function pointers */ @@ -182,9 +184,20 @@ winSetEngine (ScreenPtr pScreen) } /* ShadowGDI is the only engine that supports Multi Window Mode */ - if (pScreenInfo->fMultiWindow) + if ( +#ifdef XWIN_MULTIWINDOWEXTWM + pScreenInfo->fMWExtWM +#else + FALSE +#endif +#ifdef XWIN_MULTIWINDOW + || pScreenInfo->fMultiWindow +#else + || FALSE +#endif + ) { - ErrorF ("winSetEngine - Multi Window => ShadowGDI\n"); + winErrorFVerb (2, "winSetEngine - Multi Window or Rootless => ShadowGDI\n"); pScreenInfo->dwEngine = WIN_SERVER_SHADOW_GDI; /* Set engine function pointers */ @@ -195,8 +208,8 @@ winSetEngine (ScreenPtr pScreen) /* If the user's choice is supported, we'll use that */ if (g_dwEnginesSupported & pScreenInfo->dwEnginePreferred) { - ErrorF ("winSetEngine - Using user's preference: %d\n", - pScreenInfo->dwEnginePreferred); + winErrorFVerb (2, "winSetEngine - Using user's preference: %d\n", + (int) pScreenInfo->dwEnginePreferred); pScreenInfo->dwEngine = pScreenInfo->dwEnginePreferred; /* Setup engine function pointers */ @@ -211,12 +224,16 @@ winSetEngine (ScreenPtr pScreen) case WIN_SERVER_SHADOW_DDNL: winSetEngineFunctionsShadowDDNL (pScreen); break; +#ifdef XWIN_PRIMARYFB case WIN_SERVER_PRIMARY_DD: winSetEngineFunctionsPrimaryDD (pScreen); break; +#endif +#ifdef XWIN_NATIVEGDI case WIN_SERVER_NATIVE_GDI: winSetEngineFunctionsNativeGDI (pScreen); break; +#endif default: FatalError ("winSetEngine - Invalid engine type\n"); } @@ -226,7 +243,7 @@ winSetEngine (ScreenPtr pScreen) /* ShadowDDNL has good performance, so why not */ if (g_dwEnginesSupported & WIN_SERVER_SHADOW_DDNL) { - ErrorF ("winSetEngine - Using Shadow DirectDraw NonLocking\n"); + winErrorFVerb (2, "winSetEngine - Using Shadow DirectDraw NonLocking\n"); pScreenInfo->dwEngine = WIN_SERVER_SHADOW_DDNL; /* Set engine function pointers */ @@ -237,7 +254,7 @@ winSetEngine (ScreenPtr pScreen) /* ShadowDD is next in line */ if (g_dwEnginesSupported & WIN_SERVER_SHADOW_DD) { - ErrorF ("winSetEngine - Using Shadow DirectDraw\n"); + winErrorFVerb (2, "winSetEngine - Using Shadow DirectDraw\n"); pScreenInfo->dwEngine = WIN_SERVER_SHADOW_DD; /* Set engine function pointers */ @@ -248,7 +265,7 @@ winSetEngine (ScreenPtr pScreen) /* ShadowGDI is next in line */ if (g_dwEnginesSupported & WIN_SERVER_SHADOW_GDI) { - ErrorF ("winSetEngine - Using Shadow GDI DIB\n"); + winErrorFVerb (2, "winSetEngine - Using Shadow GDI DIB\n"); pScreenInfo->dwEngine = WIN_SERVER_SHADOW_GDI; /* Set engine function pointers */ diff --git a/hw/xwin/winerror.c b/hw/xwin/winerror.c index fa6687c1b..968467026 100644 --- a/hw/xwin/winerror.c +++ b/hw/xwin/winerror.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,23 +15,31 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winerror.c,v 1.3 2001/10/23 22:22:47 alanh Exp $ */ #include "win.h" +/* References to external symbols */ +extern char * g_pszCommandLine; +extern Bool g_fUseMsg; + + #ifdef DDXOSVERRORF +/* Prototype */ +void +OsVendorVErrorF (const char *pszFormat, va_list va_args); + void OsVendorVErrorF (const char *pszFormat, va_list va_args) { @@ -41,7 +49,7 @@ OsVendorVErrorF (const char *pszFormat, va_list va_args) pthread_mutex_lock (&s_pmPrinting); /* Print the error message to a log file, could be stderr */ - LogVWrite(0, pszFormat, va_args); + LogVWrite (0, pszFormat, va_args); /* Unlock the printing mutex */ pthread_mutex_unlock (&s_pmPrinting); @@ -60,6 +68,80 @@ OsVendorVErrorF (const char *pszFormat, va_list va_args) void OsVendorFatalError (void) { - + /* Don't give duplicate warning if UseMsg was called */ + if (g_fUseMsg) + return; + + winMessageBoxF ("A fatal error has occurred and Cygwin/X will now exit.\n" \ + "Please open /tmp/XWin.log for more information.\n", + MB_ICONERROR); } #endif + + +/* + * winMessageBoxF - Print a formatted error message in a useful + * message box. + */ + +void +winMessageBoxF (const char *pszError, UINT uType, ...) +{ + int i; + char * pszErrorF = NULL; + char * pszMsgBox = NULL; + va_list args; + + /* Get length of formatted error string */ + va_start (args, uType); + i = sprintf (NULL, pszError, args); + va_end (args); + + /* Allocate memory for formatted error string */ + pszErrorF = malloc (i); + if (!pszErrorF) + goto winMessageBoxF_Cleanup; + + /* Create the formatted error string */ + va_start (args, uType); + sprintf (pszErrorF, pszError, args); + va_end (args); + +#define MESSAGEBOXF \ + "%s\n" \ + "Vendor: %s\n" \ + "Release: %s\n" \ + "Contact: %s\n" \ + "XWin was started with the following command-line:\n\n" \ + "%s\n" + + /* Get length of message box string */ + i = sprintf (NULL, MESSAGEBOXF, + pszErrorF, + VENDOR_STRING, VERSION_STRING, VENDOR_CONTACT, + g_pszCommandLine); + + /* Allocate memory for message box string */ + pszMsgBox = malloc (i); + if (!pszMsgBox) + goto winMessageBoxF_Cleanup; + + /* Format the message box string */ + sprintf (pszMsgBox, MESSAGEBOXF, + pszErrorF, + VENDOR_STRING, VERSION_STRING, VENDOR_CONTACT, + g_pszCommandLine); + + /* Display the message box string */ + MessageBox (NULL, + pszMsgBox, + "Cygwin/X", + MB_OK | uType); + + winMessageBoxF_Cleanup: + if (pszErrorF) + free (pszErrorF); + if (pszMsgBox) + free (pszMsgBox); +#undef MESSAGEBOXF +} diff --git a/hw/xwin/winfillsp.c b/hw/xwin/winfillsp.c index 556fde718..b0633fa7a 100644 --- a/hw/xwin/winfillsp.c +++ b/hw/xwin/winfillsp.c @@ -32,6 +32,16 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iPixmapPrivateIndex; +extern int g_iGCPrivateIndex; +extern int g_copyROP[]; + + extern void ROP16(HDC hdc, int rop); #define TRANSLATE_COLOR(color) \ @@ -118,7 +128,7 @@ winFillSpansNativeGDI (DrawablePtr pDrawable, if (hbmpOrig == NULL) FatalError ("winFillSpans - DRAWABLE_PIXMAP - " "SelectObject () failed on\n\tpPixmapPriv->hBitmap: " - "%08x\n", pPixmapPriv->hBitmap); + "%08x\n", (unsigned int) pPixmapPriv->hBitmap); /* Branch on the fill type */ switch (pGC->fillStyle) diff --git a/hw/xwin/winfont.c b/hw/xwin/winfont.c index a6ff2f7da..4c633af80 100644 --- a/hw/xwin/winfont.c +++ b/hw/xwin/winfont.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,19 +15,18 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winfont.c,v 1.2 2001/06/04 13:04:41 alanh Exp $ */ #include "win.h" @@ -37,7 +36,7 @@ Bool winRealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont) { #if CYGDEBUG - ErrorF ("winRealizeFont()\n"); + winDebug ("winRealizeFont()\n"); #endif return TRUE; } @@ -48,7 +47,7 @@ Bool winUnrealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont) { #if CYGDEBUG - ErrorF ("winUnrealizeFont()\n"); + winDebug ("winUnrealizeFont()\n"); #endif return TRUE; } diff --git a/hw/xwin/wingc.c b/hw/xwin/wingc.c index ce0ef6584..e664da1bc 100644 --- a/hw/xwin/wingc.c +++ b/hw/xwin/wingc.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,23 +15,57 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/wingc.c,v 1.10 2001/10/30 15:39:09 alanh Exp $ */ #include "win.h" + void -winPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable, int dx, int dy, int xOrg, int yOrg); +winPushPixels (GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable, int dx, int dy, int xOrg, int yOrg); + + +/* + * Local prototypes + */ + +#if 0 +static void +winChangeGCNativeGDI (GCPtr pGC, unsigned long ulChanges); +#endif + +static void +winValidateGCNativeGDI (GCPtr pGC, + unsigned long changes, + DrawablePtr pDrawable); + +#if 0 +static void +winCopyGCNativeGDI (GCPtr pGCsrc, unsigned long ulMask, GCPtr pGCdst); +#endif + +static void +winDestroyGCNativeGDI (GCPtr pGC); + +#if 0 +static void +winChangeClipNativeGDI (GCPtr pGC, int nType, pointer pValue, int nRects); + +static void +winDestroyClipNativeGDI (GCPtr pGC); + +static void +winCopyClipNativeGDI (GCPtr pGCdst, GCPtr pGCsrc); +#endif #if 0 /* GC Handling Routines */ @@ -133,17 +167,19 @@ winCreateGCNativeGDI (GCPtr pGC) } +#if 0 /* See Porting Layer Definition - p. 45 */ -void +static void winChangeGCNativeGDI (GCPtr pGC, unsigned long ulChanges) { #if 0 ErrorF ("winChangeGCNativeGDI () - Doing nothing\n"); #endif } +#endif -void +static void winValidateGCNativeGDI (GCPtr pGC, unsigned long ulChanges, DrawablePtr pDrawable) @@ -156,16 +192,18 @@ winValidateGCNativeGDI (GCPtr pGC, } +#if 0 /* See Porting Layer Definition - p. 46 */ -void +static void winCopyGCNativeGDI (GCPtr pGCsrc, unsigned long ulMask, GCPtr pGCdst) { } +#endif /* See Porting Layer Definition - p. 46 */ -void +static void winDestroyGCNativeGDI (GCPtr pGC) { winGCPriv(pGC); @@ -193,8 +231,9 @@ winDestroyGCNativeGDI (GCPtr pGC) } +#if 0 /* See Porting Layer Definition - p. 46 */ -void +static void winChangeClipNativeGDI (GCPtr pGC, int nType, pointer pValue, int nRects) { @@ -202,7 +241,7 @@ winChangeClipNativeGDI (GCPtr pGC, int nType, pointer pValue, int nRects) /* See Porting Layer Definition - p. 47 */ -void +static void winDestroyClipNativeGDI (GCPtr pGC) { @@ -210,8 +249,9 @@ winDestroyClipNativeGDI (GCPtr pGC) /* See Porting Layer Definition - p. 47 */ -void +static void winCopyClipNativeGDI (GCPtr pGCdst, GCPtr pGCsrc) { } +#endif diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c new file mode 100644 index 000000000..da83b171a --- /dev/null +++ b/hw/xwin/winglobals.c @@ -0,0 +1,128 @@ +/* + *Copyright (C) 2003-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "win.h" + + +/* + * General global variables + */ + +int g_iNumScreens = 0; +winScreenInfo g_ScreenInfo[MAXSCREENS]; +int g_iLastScreen = -1; +int g_fdMessageQueue = WIN_FD_INVALID; +int g_iScreenPrivateIndex = -1; +int g_iCmapPrivateIndex = -1; +int g_iGCPrivateIndex = -1; +int g_iPixmapPrivateIndex = -1; +int g_iWindowPrivateIndex = -1; +unsigned long g_ulServerGeneration = 0; +Bool g_fInitializedDefaultScreens = FALSE; +DWORD g_dwEnginesSupported = 0; +HINSTANCE g_hInstance = 0; +HWND g_hDlgDepthChange = NULL; +HWND g_hDlgExit = NULL; +HWND g_hDlgAbout = NULL; +const char * g_pszQueryHost = NULL; +Bool g_fXdmcpEnabled = FALSE; +HICON g_hIconX = NULL; +HICON g_hSmallIconX = NULL; +char * g_pszLogFile = "/tmp/XWin.log"; +int g_iLogVerbose = 2; +Bool g_fLogInited = FALSE; +char * g_pszCommandLine = NULL; +Bool g_fUseMsg = FALSE; +DWORD g_dwCurrentThreadID = 0; +Bool g_fKeyboardHookLL = FALSE; +HHOOK g_hhookKeyboardLL = NULL; +HWND g_hwndKeyboardFocus = NULL; +Bool g_fNoHelpMessageBox = FALSE; +Bool g_fSoftwareCursor = FALSE; + + +/* + * Global variables for dynamically loaded libraries and + * their function pointers + */ + +HMODULE g_hmodDirectDraw = NULL; +FARPROC g_fpDirectDrawCreate = NULL; +FARPROC g_fpDirectDrawCreateClipper = NULL; + +HMODULE g_hmodCommonControls = NULL; +FARPROC g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; + + +#ifdef XWIN_CLIPBOARD +/* + * Wrapped DIX functions + */ +winDispatchProcPtr winProcEstablishConnectionOrig = NULL; +winDispatchProcPtr winProcQueryTreeOrig = NULL; +winDispatchProcPtr winProcSetSelectionOwnerOrig = NULL; + + +/* + * Clipboard variables + */ + +Bool g_fUnicodeClipboard = TRUE; +Bool g_fClipboard = FALSE; +Bool g_fClipboardLaunched = FALSE; +Bool g_fClipboardStarted = FALSE; +pthread_t g_ptClipboardProc = 0; +HWND g_hwndClipboard = NULL; +void *g_pClipboardDisplay = NULL; +Window g_iClipboardWindow = None; +Atom g_atomLastOwnedSelection = None; +#endif + + +/* + * Re-initialize global variables that are invalidated + * by a server reset. + */ + +void +winInitializeGlobals (void) +{ + g_dwCurrentThreadID = GetCurrentThreadId (); + g_hwndKeyboardFocus = NULL; +#ifdef XWIN_CLIPBOARD + g_fClipboardLaunched = FALSE; + g_fClipboardStarted = FALSE; + g_iClipboardWindow = None; + g_pClipboardDisplay = NULL; + g_atomLastOwnedSelection = None; + g_hwndClipboard = NULL; + g_ptClipboardProc = 0; +#endif +} diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c index 4228ad422..8fd9c49a6 100644 --- a/hw/xwin/winkeybd.c +++ b/hw/xwin/winkeybd.c @@ -36,7 +36,8 @@ #include "win.h" #include "winkeybd.h" #include "winconfig.h" - +#include "winmsg.h" + #ifdef XKB #define XKB_IN_SERVER #include "XKBsrv.h" @@ -44,172 +45,23 @@ static Bool g_winKeyState[NUM_KEYCODES]; +/* Stored to get internal mode key states. Must be read-only. */ +static unsigned short const *g_winInternalModeKeyStatesPtr = NULL; -#if WIN_NEW_KEYBOARD_SUPPORT - -const unsigned int MaxKeysPerKey = 4; - -void -winProcessKeyEvent (DWORD dwVirtualKey, DWORD dwKeyData) -{ - Bool fDown = ((dwKeyData & 0x80000000) == 0); - winKeyEventsRec kerEvent; - int i; - - /* Get the key events */ - kerEvent = winTranslateKey (dwVirtualKey, dwKeyData); - - if (kerEvent.dwReleaseModifiers & WIN_MOD_LCONTROL) - winSendKeyEvent (XK_Control_L, FALSE); - if (kerEvent.dwReleaseModifiers & WIN_MOD_RCONTROL) - winSendKeyEvent (XK_Control_R, FALSE); - if (kerEvent.dwReleaseModifiers & WIN_MOD_LALT) - winSendKeyEvent (XK_Alt_L, FALSE); - if (kerEvent.dwReleaseModifiers & WIN_MOD_RALT) - winSendKeyEvent (XK_Alt_R, FALSE); - - for (i = 0; kerEvent.dwXKeycodes[i] != XK_VoidSymbol; ++i) - winSendKeyEvent (kerEvent.dwXKeycodes[i], fDown); - - if (kerEvent.dwReleaseModifiers & WIN_MOD_LCONTROL) - winSendKeyEvent (XK_Control_L, FALSE); - if (kerEvent.dwReleaseModifiers & WIN_MOD_RCONTROL) - winSendKeyEvent (XK_Control_R, TRUE); - if (kerEvent.dwReleaseModifiers & WIN_MOD_LALT) - winSendKeyEvent (XK_Alt_L, FALSE); - if (kerEvent.dwReleaseModifiers & WIN_MOD_RALT) - winSendKeyEvent (XK_Alt_R, TRUE); - -} - - -winKeyEventsRec -winTranslateKey (DWORD dwVirtualKey, DWORD dwKeyData) -{ - winKeyEventsRec kerEvents; - Bool fExtended = ((HIWORD (dwKeyData) & KF_EXTENDED) != 0); - int i; - DWORD dwNumEvents = 0; - BYTE bKeyboardState[256]; - int iReturn; - unsigned char cAscii[4]; - - /* Remap extended modifiers to the right version of that key. */ - if (fExtended) - { - switch (dwVirtualKey) - { - case VK_MENU: - dwVirtualKey = VK_RMENU; - break; - - case VK_CONTROL: - dwVirtualKey = VK_RCONTROL; - break; - } - } - - /* Initialize the modifiers to release flag */ - kerEvents.dwReleaseModifiers = 0; - - /* Look up the current virtual key code in the translation table */ - for (i = 0; i < g_winKeymapEntries; ++i) - { - /* Did we find a mapping? */ - if (winKeymap[i].dwVirtualKey == dwVirtualKey) - { - /* Mapping found, we have at least one event now */ - kerEvents.dwXKeycodes[dwNumEvents] = winKeymap[i].dwXKey; - break; - } - } - - - /* Break out early, if we found the key in the translation table */ - if (dwNumEvents != 0) - { - /* Terminate the last of the key events with a void symbol */ - kerEvents.dwXKeycodes[dwNumEvents] = XK_VoidSymbol; - return kerEvents; - } - - /* Get the state of all keyboard keys */ - GetKeyboardState (bKeyboardState); - - /* Try to convert the key to ASCII */ - iReturn = ToAscii (dwVirtualKey, 0, bKeyboardState, (WORD *) cAscii, 0); - - /* - * Left Control and Alt pressed, combined with a valid result - * from ToAscii means that we have found the Windows version of AltGr. - */ - if ((bKeyboardState[VK_MENU] & 0x80) && (bKeyboardState[VK_CONTROL] & 0x80) - && (iReturn >= 1) - && (((cAscii[0] >= 32) && (cAscii[0] <= 126)) - || (cAscii[0] >= 160))) - { - /* These three calls will return 0 on Windows 95/98/Me */ - if ((GetKeyState (VK_LCONTROL) & KF_UP)) - kerEvents.dwReleaseModifiers |= WIN_MOD_LCONTROL; - if ((GetKeyState (VK_LMENU) & KF_UP)) - kerEvents.dwReleaseModifiers |= WIN_MOD_LALT; - if ((GetKeyState (VK_RMENU) & KF_UP)) - kerEvents.dwReleaseModifiers |= WIN_MOD_RALT; - - /* Windows 95/98/Me handling - pop all of them */ - if (kerEvents.dwReleaseModifiers == 0) - kerEvents.dwReleaseModifiers - = WIN_MOD_LCONTROL | WIN_MOD_LALT | WIN_MOD_RALT; - - /* Copy the string of character events */ - for (i = 0; i < iReturn; ++i) - kerEvents.dwXKeycodes[dwNumEvents++] = cAscii[i]; - } - /* Handle non Ctrl+Alt cases*/ - if (dwNumEvents == 0) - { - bKeyboardState[VK_CONTROL] = 0; - bKeyboardState[VK_LCONTROL] = 0; - bKeyboardState[VK_RCONTROL] = 0; - - iReturn = ToAscii (dwVirtualKey, 0, bKeyboardState, (WORD *)cAscii, 0); - if (iReturn < 0) - { - switch (cAscii[0]) - { - case '`': - kerEvents.dwXKeycodes[dwNumEvents++] = XK_dead_grave; - break; - - case '\'': - kerEvents.dwXKeycodes[dwNumEvents++] = XK_dead_acute; - break; - - case '~': - kerEvents.dwXKeycodes[dwNumEvents++] = XK_dead_tilde; - break; - - case '^': - kerEvents.dwXKeycodes[dwNumEvents++] = XK_dead_circumflex; - break; - } - } - - /* Send what we've got if its a printable character */ - if (iReturn >= 1) - for (i = 0; i < iReturn; ++i) - kerEvents.dwXKeycodes[dwNumEvents++] = cAscii[i]; - } +/* + * Local prototypes + */ - - /* Terminate the last of the key events with a void symbol */ - kerEvents.dwXKeycodes[dwNumEvents] = XK_VoidSymbol; - return kerEvents; -} +static void +winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap); +static void +winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt, + pointer pCtrl, int iClass); -#else /* WIN_NEW_KEYBOARD_SUPPORT */ +static void +winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl); /* @@ -236,15 +88,13 @@ winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode) *piScanCode = LOBYTE (HIWORD (lParam)); } -#endif /* WIN_NEW_KEYBOARD_SUPPORT */ - /* * We call this function from winKeybdProc when we are * initializing the keyboard. */ -void +static void winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap) { int i; @@ -287,7 +137,6 @@ winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap) pModMap[i] = AltMask; break; -#if !WIN_NEW_KEYBOARD_SUPPORT case XK_Num_Lock: pModMap[i] = NumLockMask; break; @@ -296,6 +145,12 @@ winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap) pModMap[i] = ScrollLockMask; break; +#if 0 + case XK_Super_L: + case XK_Super_R: + pModMap[i] = Mod4Mask; + break; +#else /* Hirigana/Katakana toggle */ case XK_Kana_Lock: case XK_Kana_Shift: @@ -318,7 +173,7 @@ winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap) /* Ring the keyboard bell (system speaker on PCs) */ -void +static void winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt, pointer pCtrl, int iClass) { @@ -333,10 +188,10 @@ winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt, /* Change some keyboard configuration parameters */ -void +static void winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl) { - + g_winInternalModeKeyStatesPtr = &(pDevice->key->state); } @@ -353,6 +208,8 @@ winKeybdProc (DeviceIntPtr pDeviceInt, int iState) DevicePtr pDevice = (DevicePtr) pDeviceInt; #ifdef XKB XkbComponentNamesRec names; + XkbSrvInfoPtr xkbi; + XkbControlsPtr ctrl; #endif switch (iState) @@ -402,7 +259,7 @@ winKeybdProc (DeviceIntPtr pDeviceInt, int iState) names.geometry = g_winInfo.xkb.geometry; } - ErrorF("Rules = \"%s\" Model = \"%s\" Layout = \"%s\"" + winErrorFVerb(2, "Rules = \"%s\" Model = \"%s\" Layout = \"%s\"" " Variant = \"%s\" Options = \"%s\"\n", g_winInfo.xkb.rules, g_winInfo.xkb.model, g_winInfo.xkb.layout, g_winInfo.xkb.variant, @@ -415,14 +272,36 @@ winKeybdProc (DeviceIntPtr pDeviceInt, int iState) modMap, winKeybdBell, winKeybdCtrl); } #endif + +#ifdef XKB + if (!g_winInfo.xkb.disable) + { + xkbi = pDeviceInt->key->xkbInfo; + if (xkbi != NULL) + { + ctrl = xkbi->desc->ctrls; + ctrl->repeat_delay = g_winInfo.keyboard.delay; + ctrl->repeat_interval = 1000/g_winInfo.keyboard.rate; + } + else + { + winErrorFVerb (1, "winKeybdProc - Error initializing keyboard AutoRepeat (No XKB)\n"); + } + } +#endif + + g_winInternalModeKeyStatesPtr = &(pDeviceInt->key->state); break; + case DEVICE_ON: pDevice->on = TRUE; + g_winInternalModeKeyStatesPtr = &(pDeviceInt->key->state); break; case DEVICE_CLOSE: case DEVICE_OFF: pDevice->on = FALSE; + g_winInternalModeKeyStatesPtr = NULL; break; } @@ -440,7 +319,6 @@ winKeybdProc (DeviceIntPtr pDeviceInt, int iState) void winInitializeModeKeyStates (void) { -#if !WIN_NEW_KEYBOARD_SUPPORT /* Restore NumLock */ if (GetKeyState (VK_NUMLOCK) & 0x0001) { @@ -468,36 +346,6 @@ winInitializeModeKeyStates (void) winSendKeyEvent (KEY_HKTG, TRUE); winSendKeyEvent (KEY_HKTG, FALSE); } -#endif -} - - -/* - * We have to store the last state of each mode - * key before we lose the keyboard focus. - */ - -void -winStoreModeKeyStates (ScreenPtr pScreen) -{ -#if !WIN_NEW_KEYBOARD_SUPPORT - winScreenPriv(pScreen); - - /* Initialize all mode key states to off */ - pScreenPriv->dwModeKeyStates = 0x0L; - - pScreenPriv->dwModeKeyStates |= - (GetKeyState (VK_NUMLOCK) & 0x0001) << NumLockMapIndex; - - pScreenPriv->dwModeKeyStates |= - (GetKeyState (VK_SCROLL) & 0x0001) << ScrollLockMapIndex; - - pScreenPriv->dwModeKeyStates |= - (GetKeyState (VK_CAPITAL) & 0x0001) << LockMapIndex; - - pScreenPriv->dwModeKeyStates |= - (GetKeyState (VK_KANA) & 0x0001) << KanaMapIndex; -#endif } @@ -508,11 +356,27 @@ winStoreModeKeyStates (ScreenPtr pScreen) */ void -winRestoreModeKeyStates (ScreenPtr pScreen) +winRestoreModeKeyStates () { -#if !WIN_NEW_KEYBOARD_SUPPORT - winScreenPriv(pScreen); DWORD dwKeyState; + BOOL processEvents = TRUE; + unsigned short internalKeyStates; + + /* X server is being initialized */ + if (!g_winInternalModeKeyStatesPtr) + return; + + /* Only process events if the rootwindow is mapped. The keyboard events + * will cause segfaults otherwise */ + if (WindowTable && WindowTable[0] && WindowTable[0]->mapped == FALSE) + processEvents = FALSE; + + /* Force to process all pending events in the mi event queue */ + if (processEvents) + mieqProcessInputEvents (); + + /* Read the mode key states of our X server */ + internalKeyStates = *g_winInternalModeKeyStatesPtr; /* * NOTE: The C XOR operator, ^, will not work here because it is @@ -522,7 +386,7 @@ winRestoreModeKeyStates (ScreenPtr pScreen) /* Has the key state changed? */ dwKeyState = GetKeyState (VK_NUMLOCK) & 0x0001; - if (WIN_XOR (pScreenPriv->dwModeKeyStates & NumLockMask, dwKeyState)) + if (WIN_XOR (internalKeyStates & NumLockMask, dwKeyState)) { winSendKeyEvent (KEY_NumLock, TRUE); winSendKeyEvent (KEY_NumLock, FALSE); @@ -530,7 +394,7 @@ winRestoreModeKeyStates (ScreenPtr pScreen) /* Has the key state changed? */ dwKeyState = GetKeyState (VK_CAPITAL) & 0x0001; - if (WIN_XOR (pScreenPriv->dwModeKeyStates & LockMask, dwKeyState)) + if (WIN_XOR (internalKeyStates & LockMask, dwKeyState)) { winSendKeyEvent (KEY_CapsLock, TRUE); winSendKeyEvent (KEY_CapsLock, FALSE); @@ -538,7 +402,7 @@ winRestoreModeKeyStates (ScreenPtr pScreen) /* Has the key state changed? */ dwKeyState = GetKeyState (VK_SCROLL) & 0x0001; - if (WIN_XOR (pScreenPriv->dwModeKeyStates & ScrollLockMask, dwKeyState)) + if (WIN_XOR (internalKeyStates & ScrollLockMask, dwKeyState)) { winSendKeyEvent (KEY_ScrollLock, TRUE); winSendKeyEvent (KEY_ScrollLock, FALSE); @@ -546,16 +410,14 @@ winRestoreModeKeyStates (ScreenPtr pScreen) /* Has the key state changed? */ dwKeyState = GetKeyState (VK_KANA) & 0x0001; - if (WIN_XOR (pScreenPriv->dwModeKeyStates & KanaMask, dwKeyState)) + if (WIN_XOR (internalKeyStates & KanaMask, dwKeyState)) { winSendKeyEvent (KEY_HKTG, TRUE); winSendKeyEvent (KEY_HKTG, FALSE); } -#endif } -#if !WIN_NEW_KEYBOARD_SUPPORT /* * Look for the lovely fake Control_L press/release generated by Windows * when AltGr is pressed/released on a non-U.S. keyboard. @@ -580,12 +442,27 @@ winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam) /* Get time of current message */ lTime = GetMessageTime (); - + /* Look for fake Ctrl_L preceeding an Alt_R press. */ fReturn = PeekMessage (&msgNext, NULL, WM_KEYDOWN, WM_KEYDOWN, PM_NOREMOVE); + /* + * Try again if the first call fails. + * NOTE: This usually happens when TweakUI is enabled. + */ + if (!fReturn) + { + /* Voodoo to make sure that the Alt_R message has posted */ + Sleep (0); + + /* Look for fake Ctrl_L preceeding an Alt_R press. */ + fReturn = PeekMessage (&msgNext, NULL, + WM_KEYDOWN, WM_KEYDOWN, + PM_NOREMOVE); + } + /* Is next press an Alt_R with the same timestamp? */ if (fReturn && msgNext.wParam == VK_MENU && msgNext.time == lTime @@ -618,6 +495,21 @@ winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam) WM_KEYUP, WM_SYSKEYUP, PM_NOREMOVE); + /* + * Try again if the first call fails. + * NOTE: This usually happens when TweakUI is enabled. + */ + if (!fReturn) + { + /* Voodoo to make sure that the Alt_R message has posted */ + Sleep (0); + + /* Look for fake Ctrl_L release preceeding an Alt_R release. */ + fReturn = PeekMessage (&msgNext, NULL, + WM_KEYUP, WM_SYSKEYUP, + PM_NOREMOVE); + } + /* Is next press an Alt_R with the same timestamp? */ if (fReturn && (msgNext.message == WM_KEYUP @@ -638,7 +530,6 @@ winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam) /* Not a fake control left press/release */ return FALSE; } -#endif /* WIN_NEW_KEYBOARD_SUPPORT */ /* @@ -648,7 +539,6 @@ winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam) void winKeybdReleaseKeys () { -#if !WIN_NEW_KEYBOARD_SUPPORT int i; /* Verify that the mi input system has been initialized */ @@ -665,7 +555,6 @@ winKeybdReleaseKeys () /* Reset pressed flag for keys */ g_winKeyState[i] = FALSE; } -#endif } diff --git a/hw/xwin/winkeybd.h b/hw/xwin/winkeybd.h index 375245f80..f320c98e7 100644 --- a/hw/xwin/winkeybd.h +++ b/hw/xwin/winkeybd.h @@ -1,3 +1,5 @@ +#if !defined(WINKEYBD_H) +#define WINKEYBD_H /* *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. * @@ -32,7 +34,7 @@ /* * We need symbols for the scan codes of keys. */ -#include "../xfree86/common/atKeynames.h" +#include "winkeynames.h" /* @@ -40,98 +42,7 @@ * * This header declares a static KeySym array called 'map'. */ -#include "../xfree86/common/xf86Keymap.h" - - -#if WIN_NEW_KEYBOARD_SUPPORT - -/* Define the keymap structure */ -typedef struct -{ - DWORD dwVirtualKey; - DWORD dwXKey; -} winKeymappingRec, *winKeymappingPtr; - -static const winKeymappingRec -winKeymap[] = { - {VK_BACK, XK_BackSpace}, - {VK_TAB, XK_Tab}, - {VK_CLEAR, XK_Clear}, - {VK_RETURN, XK_Return}, - {VK_LSHIFT, XK_Shift_L}, - {VK_RSHIFT, XK_Shift_R}, - {VK_SHIFT, XK_Shift_L}, - {VK_LCONTROL, XK_Control_L}, - {VK_RCONTROL, XK_Control_R}, - {VK_CONTROL, XK_Control_L}, - {VK_LMENU, XK_Alt_L}, - {VK_RMENU, XK_Alt_R}, - {VK_MENU, XK_Alt_L}, - {VK_PAUSE, XK_Pause}, - {VK_CAPITAL, XK_Caps_Lock}, - {VK_ESCAPE, XK_Escape}, - {VK_SPACE, XK_space}, - {VK_PRIOR, XK_Page_Up}, - {VK_NEXT, XK_Page_Down}, - {VK_END, XK_End}, - {VK_HOME, XK_Home}, - {VK_LEFT, XK_Left}, - {VK_UP, XK_Up}, - {VK_RIGHT, XK_Right}, - {VK_DOWN, XK_Down}, - {VK_SELECT, XK_Select}, - {VK_EXECUTE, XK_Execute}, - {VK_SNAPSHOT, XK_Print}, - {VK_INSERT, XK_Insert}, - {VK_DELETE, XK_Delete}, - {VK_HELP, XK_Help}, - {VK_NUMPAD0, XK_KP_0}, - {VK_NUMPAD1, XK_KP_1}, - {VK_NUMPAD2, XK_KP_2}, - {VK_NUMPAD3, XK_KP_3}, - {VK_NUMPAD4, XK_KP_4}, - {VK_NUMPAD5, XK_KP_5}, - {VK_NUMPAD6, XK_KP_6}, - {VK_NUMPAD7, XK_KP_7}, - {VK_NUMPAD8, XK_KP_8}, - {VK_NUMPAD9, XK_KP_9}, - {VK_MULTIPLY, XK_KP_Multiply}, - {VK_ADD, XK_KP_Add}, - {VK_SEPARATOR, XK_KP_Separator}, // often comma - {VK_SUBTRACT, XK_KP_Subtract}, - {VK_DECIMAL, XK_KP_Decimal}, - {VK_DIVIDE, XK_KP_Divide}, - {VK_F1, XK_F1}, - {VK_F2, XK_F2}, - {VK_F3, XK_F3}, - {VK_F4, XK_F4}, - {VK_F5, XK_F5}, - {VK_F6, XK_F6}, - {VK_F7, XK_F7}, - {VK_F8, XK_F8}, - {VK_F9, XK_F9}, - {VK_F10, XK_F10}, - {VK_F11, XK_F11}, - {VK_F12, XK_F12}, - {VK_F13, XK_F13}, - {VK_F14, XK_F14}, - {VK_F15, XK_F15}, - {VK_F16, XK_F16}, - {VK_F17, XK_F17}, - {VK_F18, XK_F18}, - {VK_F19, XK_F19}, - {VK_F20, XK_F20}, - {VK_F21, XK_F21}, - {VK_F22, XK_F22}, - {VK_F23, XK_F23}, - {VK_F24, XK_F24}, - {VK_NUMLOCK, XK_Num_Lock}, - {VK_SCROLL, XK_Scroll_Lock} -}; - -static int g_winKeymapEntries = sizeof (winKeymap) / sizeof (winKeymappingRec); - -#else /* WIN_NEW_KEYBOARD_SUPPORT */ +#include "winkeymap.h" #define WIN_KEYMAP_COLS 3 @@ -395,4 +306,5 @@ g_iKeyMap [] = { /* 254 */ 0, 0, 0, /* 255 */ 0, 0, 0 }; -#endif /* WIN_NEW_KEYBOARD_SUPPORT */ + +#endif /* WINKEYBD_H */ diff --git a/hw/xwin/winkeyhook.c b/hw/xwin/winkeyhook.c new file mode 100755 index 000000000..60176d9ad --- /dev/null +++ b/hw/xwin/winkeyhook.c @@ -0,0 +1,170 @@ +/* + *Copyright (C) 2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "win.h" + + +/* + * References to external symbols + */ + +extern HHOOK g_hhookKeyboardLL; +extern DWORD g_dwCurrentThreadID; +extern HWND g_hwndKeyboardFocus; + + +/* + * Function prototypes + */ + +static LRESULT CALLBACK +winKeyboardMessageHookLL (int iCode, WPARAM wParam, LPARAM lParam); + + +#ifndef LLKHF_EXTENDED +# define LLKHF_EXTENDED 0x00000001 +#endif +#ifndef LLKHF_UP +# define LLKHF_UP 0x00000080 +#endif + + +/* + * KeyboardMessageHook + */ + +static LRESULT CALLBACK +winKeyboardMessageHookLL (int iCode, WPARAM wParam, LPARAM lParam) +{ + BOOL fPassKeystroke = FALSE; + PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam; + + /* Pass keystrokes on to our main message loop */ + if (iCode == HC_ACTION) + { +#if 0 + ErrorF ("vkCode: %08x\tscanCode: %08x\n", p->vkCode, p->scanCode); +#endif + + switch (wParam) + { + case WM_KEYDOWN: case WM_SYSKEYDOWN: + case WM_KEYUP: case WM_SYSKEYUP: + fPassKeystroke = + ((p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0)) +#if 0 + || (p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN) +#endif + ; + break; + } + } + + /* + * Pass message on to our main message loop. + * We process this immediately with SendMessage so that the keystroke + * appears in, hopefully, the correct order. + */ + if (fPassKeystroke) + { + LPARAM lParamKey = 0x0; + + /* Construct the lParam from KBDLLHOOKSTRUCT */ + lParamKey = lParamKey | (0x0000FFFF & 0x00000001); /* Repeat count */ + lParamKey = lParamKey | (0x00FF0000 & (p->scanCode << 16)); + lParamKey = lParamKey + | (0x01000000 & ((p->flags & LLKHF_EXTENDED) << 23)); + lParamKey = lParamKey + | (0x20000000 + & ((p->flags & LLKHF_ALTDOWN) << 24)); + lParamKey = lParamKey | (0x80000000 & ((p->flags & LLKHF_UP) << 24)); + + /* Send message to our main window that has the keyboard focus */ + PostMessage (g_hwndKeyboardFocus, + (UINT) wParam, + (WPARAM) p->vkCode, + lParamKey); + + return 1; + } + + /* Call next hook */ + return CallNextHookEx (NULL, iCode, wParam, lParam); +} + + +/* + * Attempt to install the keyboard hook, return FALSE if it was not installed + */ + +Bool +winInstallKeyboardHookLL () +{ + OSVERSIONINFO osvi = {0}; + + /* Get operating system version information */ + osvi.dwOSVersionInfoSize = sizeof (osvi); + GetVersionEx (&osvi); + + /* Branch on platform ID */ + switch (osvi.dwPlatformId) + { + case VER_PLATFORM_WIN32_NT: + /* Low-level is supported on NT 4.0 SP3+ only */ + /* TODO: Return FALSE on NT 4.0 with no SP, SP1, or SP2 */ + break; + + case VER_PLATFORM_WIN32_WINDOWS: + /* Low-level hook is not supported on non-NT */ + return FALSE; + } + + /* Install the hook only once */ + if (!g_hhookKeyboardLL) + g_hhookKeyboardLL = SetWindowsHookEx (WH_KEYBOARD_LL, + winKeyboardMessageHookLL, + g_hInstance, + 0); + + return TRUE; +} + + +/* + * Remove the keyboard hook if it is installed + */ + +void +winRemoveKeyboardHookLL () +{ + if (g_hhookKeyboardLL) + UnhookWindowsHookEx (g_hhookKeyboardLL); + g_hhookKeyboardLL = NULL; +} diff --git a/hw/xwin/winkeymap.h b/hw/xwin/winkeymap.h new file mode 100755 index 000000000..31e6cf21b --- /dev/null +++ b/hw/xwin/winkeymap.h @@ -0,0 +1,138 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Keymap.h,v 3.19 2002/05/31 18:45:58 dawes Exp $ */ +/* + * + * For Scancodes see notes in winkeynames.h !!!! + * + */ +/* $XConsortium: xf86Keymap.h /main/14 1996/02/21 17:38:47 kaleb $ */ + +static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = { + /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x01 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol, + /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol, + /* 0x03 */ XK_2, XK_at, NoSymbol, NoSymbol, + /* 0x04 */ XK_3, XK_numbersign, NoSymbol, NoSymbol, + /* 0x05 */ XK_4, XK_dollar, NoSymbol, NoSymbol, + /* 0x06 */ XK_5, XK_percent, NoSymbol, NoSymbol, + /* 0x07 */ XK_6, XK_asciicircum, NoSymbol, NoSymbol, + /* 0x08 */ XK_7, XK_ampersand, NoSymbol, NoSymbol, + /* 0x09 */ XK_8, XK_asterisk, NoSymbol, NoSymbol, + /* 0x0a */ XK_9, XK_parenleft, NoSymbol, NoSymbol, + /* 0x0b */ XK_0, XK_parenright, NoSymbol, NoSymbol, + /* 0x0c */ XK_minus, XK_underscore, NoSymbol, NoSymbol, + /* 0x0d */ XK_equal, XK_plus, NoSymbol, NoSymbol, + /* 0x0e */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol, + /* 0x0f */ XK_Tab, XK_ISO_Left_Tab,NoSymbol, NoSymbol, + /* 0x10 */ XK_Q, NoSymbol, NoSymbol, NoSymbol, + /* 0x11 */ XK_W, NoSymbol, NoSymbol, NoSymbol, + /* 0x12 */ XK_E, NoSymbol, NoSymbol, NoSymbol, + /* 0x13 */ XK_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x14 */ XK_T, NoSymbol, NoSymbol, NoSymbol, + /* 0x15 */ XK_Y, NoSymbol, NoSymbol, NoSymbol, + /* 0x16 */ XK_U, NoSymbol, NoSymbol, NoSymbol, + /* 0x17 */ XK_I, NoSymbol, NoSymbol, NoSymbol, + /* 0x18 */ XK_O, NoSymbol, NoSymbol, NoSymbol, + /* 0x19 */ XK_P, NoSymbol, NoSymbol, NoSymbol, + /* 0x1a */ XK_bracketleft, XK_braceleft, NoSymbol, NoSymbol, + /* 0x1b */ XK_bracketright,XK_braceright, NoSymbol, NoSymbol, + /* 0x1c */ XK_Return, NoSymbol, NoSymbol, NoSymbol, + /* 0x1d */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x1e */ XK_A, NoSymbol, NoSymbol, NoSymbol, + /* 0x1f */ XK_S, NoSymbol, NoSymbol, NoSymbol, + /* 0x20 */ XK_D, NoSymbol, NoSymbol, NoSymbol, + /* 0x21 */ XK_F, NoSymbol, NoSymbol, NoSymbol, + /* 0x22 */ XK_G, NoSymbol, NoSymbol, NoSymbol, + /* 0x23 */ XK_H, NoSymbol, NoSymbol, NoSymbol, + /* 0x24 */ XK_J, NoSymbol, NoSymbol, NoSymbol, + /* 0x25 */ XK_K, NoSymbol, NoSymbol, NoSymbol, + /* 0x26 */ XK_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x27 */ XK_semicolon, XK_colon, NoSymbol, NoSymbol, + /* 0x28 */ XK_quoteright, XK_quotedbl, NoSymbol, NoSymbol, + /* 0x29 */ XK_quoteleft, XK_asciitilde, NoSymbol, NoSymbol, + /* 0x2a */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x2b */ XK_backslash, XK_bar, NoSymbol, NoSymbol, + /* 0x2c */ XK_Z, NoSymbol, NoSymbol, NoSymbol, + /* 0x2d */ XK_X, NoSymbol, NoSymbol, NoSymbol, + /* 0x2e */ XK_C, NoSymbol, NoSymbol, NoSymbol, + /* 0x2f */ XK_V, NoSymbol, NoSymbol, NoSymbol, + /* 0x30 */ XK_B, NoSymbol, NoSymbol, NoSymbol, + /* 0x31 */ XK_N, NoSymbol, NoSymbol, NoSymbol, + /* 0x32 */ XK_M, NoSymbol, NoSymbol, NoSymbol, + /* 0x33 */ XK_comma, XK_less, NoSymbol, NoSymbol, + /* 0x34 */ XK_period, XK_greater, NoSymbol, NoSymbol, + /* 0x35 */ XK_slash, XK_question, NoSymbol, NoSymbol, + /* 0x36 */ XK_Shift_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x37 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol, + /* 0x38 */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol, + /* 0x39 */ XK_space, NoSymbol, NoSymbol, NoSymbol, + /* 0x3a */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol, + /* 0x3b */ XK_F1, NoSymbol, NoSymbol, NoSymbol, + /* 0x3c */ XK_F2, NoSymbol, NoSymbol, NoSymbol, + /* 0x3d */ XK_F3, NoSymbol, NoSymbol, NoSymbol, + /* 0x3e */ XK_F4, NoSymbol, NoSymbol, NoSymbol, + /* 0x3f */ XK_F5, NoSymbol, NoSymbol, NoSymbol, + /* 0x40 */ XK_F6, NoSymbol, NoSymbol, NoSymbol, + /* 0x41 */ XK_F7, NoSymbol, NoSymbol, NoSymbol, + /* 0x42 */ XK_F8, NoSymbol, NoSymbol, NoSymbol, + /* 0x43 */ XK_F9, NoSymbol, NoSymbol, NoSymbol, + /* 0x44 */ XK_F10, NoSymbol, NoSymbol, NoSymbol, + /* 0x45 */ XK_Num_Lock, NoSymbol, NoSymbol, NoSymbol, + /* 0x46 */ XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol, + /* 0x47 */ XK_KP_Home, XK_KP_7, NoSymbol, NoSymbol, + /* 0x48 */ XK_KP_Up, XK_KP_8, NoSymbol, NoSymbol, + /* 0x49 */ XK_KP_Prior, XK_KP_9, NoSymbol, NoSymbol, + /* 0x4a */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol, + /* 0x4b */ XK_KP_Left, XK_KP_4, NoSymbol, NoSymbol, + /* 0x4c */ XK_KP_Begin, XK_KP_5, NoSymbol, NoSymbol, + /* 0x4d */ XK_KP_Right, XK_KP_6, NoSymbol, NoSymbol, + /* 0x4e */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol, + /* 0x4f */ XK_KP_End, XK_KP_1, NoSymbol, NoSymbol, + /* 0x50 */ XK_KP_Down, XK_KP_2, NoSymbol, NoSymbol, + /* 0x51 */ XK_KP_Next, XK_KP_3, NoSymbol, NoSymbol, + /* 0x52 */ XK_KP_Insert, XK_KP_0, NoSymbol, NoSymbol, + /* 0x53 */ XK_KP_Delete, XK_KP_Decimal, NoSymbol, NoSymbol, + /* 0x54 */ XK_Sys_Req, NoSymbol, NoSymbol, NoSymbol, + /* 0x55 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x56 */ XK_less, XK_greater, NoSymbol, NoSymbol, + /* 0x57 */ XK_F11, NoSymbol, NoSymbol, NoSymbol, + /* 0x58 */ XK_F12, NoSymbol, NoSymbol, NoSymbol, + /* 0x59 */ XK_Home, NoSymbol, NoSymbol, NoSymbol, + /* 0x5a */ XK_Up, NoSymbol, NoSymbol, NoSymbol, + /* 0x5b */ XK_Prior, NoSymbol, NoSymbol, NoSymbol, + /* 0x5c */ XK_Left, NoSymbol, NoSymbol, NoSymbol, + /* 0x5d */ XK_Begin, NoSymbol, NoSymbol, NoSymbol, + /* 0x5e */ XK_Right, NoSymbol, NoSymbol, NoSymbol, + /* 0x5f */ XK_End, NoSymbol, NoSymbol, NoSymbol, + /* 0x60 */ XK_Down, NoSymbol, NoSymbol, NoSymbol, + /* 0x61 */ XK_Next, NoSymbol, NoSymbol, NoSymbol, + /* 0x62 */ XK_Insert, NoSymbol, NoSymbol, NoSymbol, + /* 0x63 */ XK_Delete, NoSymbol, NoSymbol, NoSymbol, + /* 0x64 */ XK_KP_Enter, NoSymbol, NoSymbol, NoSymbol, + /* 0x65 */ XK_Control_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x66 */ XK_Pause, NoSymbol, NoSymbol, NoSymbol, + /* 0x67 */ XK_Print, NoSymbol, NoSymbol, NoSymbol, + /* 0x68 */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol, + /* 0x69 */ XK_Alt_R, XK_Meta_R, NoSymbol, NoSymbol, + /* 0x6a */ XK_Break, NoSymbol, NoSymbol, NoSymbol, + /* 0x6b */ XK_Meta_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x6c */ XK_Meta_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x6d */ XK_Menu, NoSymbol, NoSymbol, NoSymbol, + /* 0x6e */ XK_F13, NoSymbol, NoSymbol, NoSymbol, + /* 0x6f */ XK_F14, NoSymbol, NoSymbol, NoSymbol, + /* 0x70 */ XK_F15, NoSymbol, NoSymbol, NoSymbol, + /* 0x71 */ XK_F16, NoSymbol, NoSymbol, NoSymbol, + /* 0x72 */ XK_F17, NoSymbol, NoSymbol, NoSymbol, + /* 0x73 */ XK_backslash, XK_underscore, NoSymbol, NoSymbol, + /* 0x74 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x75 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x76 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x77 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x78 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x79 */ XK_Henkan, XK_Mode_switch, NoSymbol, NoSymbol, + /* 0x7a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7b */ XK_Muhenkan, NoSymbol, NoSymbol, NoSymbol, + /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7d */ XK_backslash, XK_bar, NoSymbol, NoSymbol, + /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, +}; diff --git a/hw/xwin/winkeynames.h b/hw/xwin/winkeynames.h new file mode 100755 index 000000000..661a8b15f --- /dev/null +++ b/hw/xwin/winkeynames.h @@ -0,0 +1,204 @@ +#ifndef _WINKEYNAMES_H +#define _WINKEYNAMES_H +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/atKeynames.h,v 3.18 2001/09/29 20:40:30 herrb Exp $ */ +/* + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Thomas Roell not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Thomas Roell makes no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + */ +/* $XConsortium: atKeynames.h /main/11 1996/03/09 11:17:41 kaleb $ */ + +#define XK_TECHNICAL +#define XK_KATAKANA +#include "keysym.h" + +#define GLYPHS_PER_KEY 4 +#define NUM_KEYCODES 248 +#define MIN_KEYCODE 8 +#define MAX_KEYCODE (NUM_KEYCODES + MIN_KEYCODE - 1) + +#define AltMask Mod1Mask +#define NumLockMask Mod2Mask +#define AltLangMask Mod3Mask +#define KanaMask Mod4Mask +#define ScrollLockMask Mod5Mask + +#define KeyPressed(k) (keyc->down[k >> 3] & (1 << (k & 7))) +#define ModifierDown(k) ((keyc->state & (k)) == (k)) + +/* + * NOTE: The AT/MF keyboards can generate (via the 8042) two (MF: three) + * sets of scancodes. Set3 can only be generated by a MF keyboard. + * Set2 sends a makecode for keypress, and the same code prefixed by a + * F0 for keyrelease. This is a little bit ugly to handle. Thus we use + * here for X386 the PC/XT compatible Set1. This set uses 8bit scancodes. + * Bit 7 ist set if the key is released. The code E0 switches to a + * different meaning to add the new MF cursorkeys, while not breaking old + * applications. E1 is another special prefix. Since I assume that there + * will be further versions of PC/XT scancode compatible keyboards, we + * may be in trouble one day. + * + * IDEA: 1) Use Set2 on AT84 keyboards and translate it to MF Set3. + * 2) Use the keyboards native set and translate it to common keysyms. + */ + +/* + * definition of the AT84/MF101/MF102 Keyboard: + * ============================================================ + * Defined Key Cap Glyphs Pressed value + * Key Name Main Also (hex) (dec) + * ---------------- ---------- ------- ------ ------ + */ + +#define KEY_Escape /* Escape 0x01 */ 1 +#define KEY_1 /* 1 ! 0x02 */ 2 +#define KEY_2 /* 2 @ 0x03 */ 3 +#define KEY_3 /* 3 # 0x04 */ 4 +#define KEY_4 /* 4 $ 0x05 */ 5 +#define KEY_5 /* 5 % 0x06 */ 6 +#define KEY_6 /* 6 ^ 0x07 */ 7 +#define KEY_7 /* 7 & 0x08 */ 8 +#define KEY_8 /* 8 * 0x09 */ 9 +#define KEY_9 /* 9 ( 0x0a */ 10 +#define KEY_0 /* 0 ) 0x0b */ 11 +#define KEY_Minus /* - (Minus) _ (Under) 0x0c */ 12 +#define KEY_Equal /* = (Equal) + 0x0d */ 13 +#define KEY_BackSpace /* Back Space 0x0e */ 14 +#define KEY_Tab /* Tab 0x0f */ 15 +#define KEY_Q /* Q 0x10 */ 16 +#define KEY_W /* W 0x11 */ 17 +#define KEY_E /* E 0x12 */ 18 +#define KEY_R /* R 0x13 */ 19 +#define KEY_T /* T 0x14 */ 20 +#define KEY_Y /* Y 0x15 */ 21 +#define KEY_U /* U 0x16 */ 22 +#define KEY_I /* I 0x17 */ 23 +#define KEY_O /* O 0x18 */ 24 +#define KEY_P /* P 0x19 */ 25 +#define KEY_LBrace /* [ { 0x1a */ 26 +#define KEY_RBrace /* ] } 0x1b */ 27 +#define KEY_Enter /* Enter 0x1c */ 28 +#define KEY_LCtrl /* Ctrl(left) 0x1d */ 29 +#define KEY_A /* A 0x1e */ 30 +#define KEY_S /* S 0x1f */ 31 +#define KEY_D /* D 0x20 */ 32 +#define KEY_F /* F 0x21 */ 33 +#define KEY_G /* G 0x22 */ 34 +#define KEY_H /* H 0x23 */ 35 +#define KEY_J /* J 0x24 */ 36 +#define KEY_K /* K 0x25 */ 37 +#define KEY_L /* L 0x26 */ 38 +#define KEY_SemiColon /* ;(SemiColon) :(Colon) 0x27 */ 39 +#define KEY_Quote /* ' (Apostr) " (Quote) 0x28 */ 40 +#define KEY_Tilde /* ` (Accent) ~ (Tilde) 0x29 */ 41 +#define KEY_ShiftL /* Shift(left) 0x2a */ 42 +#define KEY_BSlash /* \(BckSlash) |(VertBar)0x2b */ 43 +#define KEY_Z /* Z 0x2c */ 44 +#define KEY_X /* X 0x2d */ 45 +#define KEY_C /* C 0x2e */ 46 +#define KEY_V /* V 0x2f */ 47 +#define KEY_B /* B 0x30 */ 48 +#define KEY_N /* N 0x31 */ 49 +#define KEY_M /* M 0x32 */ 50 +#define KEY_Comma /* , (Comma) < (Less) 0x33 */ 51 +#define KEY_Period /* . (Period) >(Greater)0x34 */ 52 +#define KEY_Slash /* / (Slash) ? 0x35 */ 53 +#define KEY_ShiftR /* Shift(right) 0x36 */ 54 +#define KEY_KP_Multiply /* * 0x37 */ 55 +#define KEY_Alt /* Alt(left) 0x38 */ 56 +#define KEY_Space /* (SpaceBar) 0x39 */ 57 +#define KEY_CapsLock /* CapsLock 0x3a */ 58 +#define KEY_F1 /* F1 0x3b */ 59 +#define KEY_F2 /* F2 0x3c */ 60 +#define KEY_F3 /* F3 0x3d */ 61 +#define KEY_F4 /* F4 0x3e */ 62 +#define KEY_F5 /* F5 0x3f */ 63 +#define KEY_F6 /* F6 0x40 */ 64 +#define KEY_F7 /* F7 0x41 */ 65 +#define KEY_F8 /* F8 0x42 */ 66 +#define KEY_F9 /* F9 0x43 */ 67 +#define KEY_F10 /* F10 0x44 */ 68 +#define KEY_NumLock /* NumLock 0x45 */ 69 +#define KEY_ScrollLock /* ScrollLock 0x46 */ 70 +#define KEY_KP_7 /* 7 Home 0x47 */ 71 +#define KEY_KP_8 /* 8 Up 0x48 */ 72 +#define KEY_KP_9 /* 9 PgUp 0x49 */ 73 +#define KEY_KP_Minus /* - (Minus) 0x4a */ 74 +#define KEY_KP_4 /* 4 Left 0x4b */ 75 +#define KEY_KP_5 /* 5 0x4c */ 76 +#define KEY_KP_6 /* 6 Right 0x4d */ 77 +#define KEY_KP_Plus /* + (Plus) 0x4e */ 78 +#define KEY_KP_1 /* 1 End 0x4f */ 79 +#define KEY_KP_2 /* 2 Down 0x50 */ 80 +#define KEY_KP_3 /* 3 PgDown 0x51 */ 81 +#define KEY_KP_0 /* 0 Insert 0x52 */ 82 +#define KEY_KP_Decimal /* . (Decimal) Delete 0x53 */ 83 +#define KEY_SysReqest /* SysReqest 0x54 */ 84 + /* NOTUSED 0x55 */ +#define KEY_Less /* < (Less) >(Greater) 0x56 */ 86 +#define KEY_F11 /* F11 0x57 */ 87 +#define KEY_F12 /* F12 0x58 */ 88 + +#define KEY_Prefix0 /* special 0x60 */ 96 +#define KEY_Prefix1 /* specail 0x61 */ 97 + +/* + * The 'scancodes' below are generated by the server, because the MF101/102 + * keyboard sends them as sequence of other scancodes + */ +#define KEY_Home /* Home 0x59 */ 89 +#define KEY_Up /* Up 0x5a */ 90 +#define KEY_PgUp /* PgUp 0x5b */ 91 +#define KEY_Left /* Left 0x5c */ 92 +#define KEY_Begin /* Begin 0x5d */ 93 +#define KEY_Right /* Right 0x5e */ 94 +#define KEY_End /* End 0x5f */ 95 +#define KEY_Down /* Down 0x60 */ 96 +#define KEY_PgDown /* PgDown 0x61 */ 97 +#define KEY_Insert /* Insert 0x62 */ 98 +#define KEY_Delete /* Delete 0x63 */ 99 +#define KEY_KP_Enter /* Enter 0x64 */ 100 +#define KEY_RCtrl /* Ctrl(right) 0x65 */ 101 +#define KEY_Pause /* Pause 0x66 */ 102 +#define KEY_Print /* Print 0x67 */ 103 +#define KEY_KP_Divide /* Divide 0x68 */ 104 +#define KEY_AltLang /* AtlLang(right) 0x69 */ 105 +#define KEY_Break /* Break 0x6a */ 106 +#define KEY_LMeta /* Left Meta 0x6b */ 107 +#define KEY_RMeta /* Right Meta 0x6c */ 108 +#define KEY_Menu /* Menu 0x6d */ 109 +#define KEY_F13 /* F13 0x6e */ 110 +#define KEY_F14 /* F14 0x6f */ 111 +#define KEY_F15 /* F15 0x70 */ 112 +#define KEY_HKTG /* Hirugana/Katakana tog 0x70 */ 112 +#define KEY_F16 /* F16 0x71 */ 113 +#define KEY_F17 /* F17 0x72 */ 114 +#define KEY_KP_DEC /* KP_DEC 0x73 */ 115 +#define KEY_BSlash2 /* \ _ 0x73 */ 115 +#define KEY_KP_Equal /* Equal (Keypad) 0x76 */ 118 +#define KEY_XFER /* Kanji Transfer 0x79 */ 121 +#define KEY_NFER /* No Kanji Transfer 0x7b */ 123 +#define KEY_Yen /* Yen 0x7d */ 125 + +/* These are for "notused" and "unknown" entries in translation maps. */ +#define KEY_NOTUSED 0 +#define KEY_UNKNOWN 255 + +#endif /* _WINKEYNAMES_H */ diff --git a/hw/xwin/winmessages.h b/hw/xwin/winmessages.h new file mode 100755 index 000000000..8fb8fe4cd --- /dev/null +++ b/hw/xwin/winmessages.h @@ -0,0 +1,1027 @@ +static const unsigned MESSAGE_NAMES_LEN =1024; +static const char *MESSAGE_NAMES[1024] = { + "WM_NULL", + "WM_CREATE", + "WM_DESTROY", + "WM_MOVE", + "4", + "WM_SIZE", + "WM_ACTIVATE", + "WM_SETFOCUS", + "WM_KILLFOCUS", + "9", + "WM_ENABLE", + "WM_SETREDRAW", + "WM_SETTEXT", + "WM_GETTEXT", + "WM_GETTEXTLENGTH", + "WM_PAINT", + "WM_CLOSE", + "WM_QUERYENDSESSION", + "WM_QUIT", + "WM_QUERYOPEN", + "WM_ERASEBKGND", + "WM_SYSCOLORCHANGE", + "WM_ENDSESSION", + "23", + "WM_SHOWWINDOW", + "25", + "WM_WININICHANGE", + "WM_DEVMODECHANGE", + "WM_ACTIVATEAPP", + "WM_FONTCHANGE", + "WM_TIMECHANGE", + "WM_CANCELMODE", + NULL /* WM_SETCURSOR */, + "WM_MOUSEACTIVATE", + "WM_CHILDACTIVATE", + "WM_QUEUESYNC", + "WM_GETMINMAXINFO", + "37", + "WM_PAINTICON", + "WM_ICONERASEBKGND", + "WM_NEXTDLGCTL", + "41", + "WM_SPOOLERSTATUS", + "WM_DRAWITEM", + "WM_MEASUREITEM", + "WM_DELETEITEM", + "WM_VKEYTOITEM", + "WM_CHARTOITEM", + "WM_SETFONT", + "WM_GETFONT", + "WM_SETHOTKEY", + "WM_GETHOTKEY", + "52", + "53", + "54", + "WM_QUERYDRAGICON", + "56", + "WM_COMPAREITEM", + "58", + "59", + "60", + "61", + "62", + "63", + "64", + "WM_COMPACTING", + "66", + "67", + "WM_COMMNOTIFY", + "69", + "WM_WINDOWPOSCHANGING", + "WM_WINDOWPOSCHANGED", + "WM_POWER", + "73", + "WM_COPYDATA", + "WM_CANCELJOURNAL", + "76", + "77", + "WM_NOTIFY", + "79", + "WM_INPUTLANGCHANGEREQUEST", + "WM_INPUTLANGCHANGE", + "WM_TCARD", + "WM_HELP", + "WM_USERCHANGED", + "WM_NOTIFYFORMAT", + "86", + "87", + "88", + "89", + "90", + "91", + "92", + "93", + "94", + "95", + "96", + "97", + "98", + "99", + "100", + "101", + "102", + "103", + "104", + "105", + "106", + "107", + "108", + "109", + "110", + "111", + "112", + "113", + "114", + "115", + "116", + "117", + "118", + "119", + "120", + "121", + "122", + "WM_CONTEXTMENU", + "WM_STYLECHANGING", + "WM_STYLECHANGED", + "WM_DISPLAYCHANGE", + "WM_GETICON", + "WM_SETICON", + "WM_NCCREATE", + "WM_NCDESTROY", + "WM_NCCALCSIZE", + NULL /* WM_NCHITTEST */, + "WM_NCPAINT", + "WM_NCACTIVATE", + "WM_GETDLGCODE", + "WM_SYNCPAINT", + "137", + "138", + "139", + "140", + "141", + "142", + "143", + "144", + "145", + "146", + "147", + "148", + "149", + "150", + "151", + "152", + "153", + "154", + "155", + "156", + "157", + "158", + "159", + NULL /* WM_NCMOUSEMOVE */, + "WM_NCLBUTTONDOWN", + "WM_NCLBUTTONUP", + "WM_NCLBUTTONDBLCLK", + "WM_NCRBUTTONDOWN", + "WM_NCRBUTTONUP", + "WM_NCRBUTTONDBLCLK", + "WM_NCMBUTTONDOWN", + "WM_NCMBUTTONUP", + "WM_NCMBUTTONDBLCLK", + "170", + "171", + "172", + "173", + "174", + "175", + "176", + "177", + "178", + "179", + "180", + "181", + "182", + "183", + "184", + "185", + "186", + "187", + "188", + "189", + "190", + "191", + "192", + "193", + "194", + "195", + "196", + "197", + "198", + "199", + "200", + "201", + "202", + "203", + "204", + "205", + "206", + "207", + "208", + "209", + "210", + "211", + "212", + "213", + "214", + "215", + "216", + "217", + "218", + "219", + "220", + "221", + "222", + "223", + "224", + "225", + "226", + "227", + "228", + "229", + "230", + "231", + "232", + "233", + "234", + "235", + "236", + "237", + "238", + "239", + "240", + "241", + "242", + "243", + "244", + "245", + "246", + "247", + "248", + "249", + "250", + "251", + "252", + "253", + "254", + "255", + "WM_KEYDOWN", + "WM_KEYUP", + "WM_CHAR", + "WM_DEADCHAR", + "WM_SYSKEYDOWN", + "WM_SYSKEYUP", + "WM_SYSCHAR", + "WM_SYSDEADCHAR", + "WM_CONVERTREQUESTEX", + "265", + "266", + "267", + "268", + "WM_IME_STARTCOMPOSITION", + "WM_IME_ENDCOMPOSITION", + "WM_IME_KEYLAST", + "WM_INITDIALOG", + "WM_COMMAND", + "WM_SYSCOMMAND", + NULL /* WM_TIMER */, + "WM_HSCROLL", + "WM_VSCROLL", + "WM_INITMENU", + "WM_INITMENUPOPUP", + "280", + "281", + "282", + "283", + "284", + "285", + "286", + "WM_MENUSELECT", + "WM_MENUCHAR", + "WM_ENTERIDLE", + "290", + "291", + "292", + "293", + "294", + "295", + "296", + "297", + "298", + "299", + "300", + "301", + "302", + "303", + "304", + "305", + "WM_CTLCOLORMSGBOX", + "WM_CTLCOLOREDIT", + "WM_CTLCOLORLISTBOX", + "WM_CTLCOLORBTN", + "WM_CTLCOLORDLG", + "WM_CTLCOLORSCROLLBAR", + "WM_CTLCOLORSTATIC", + "313", + "314", + "315", + "316", + "317", + "318", + "319", + "320", + "321", + "322", + "323", + "324", + "325", + "326", + "327", + "328", + "329", + "330", + "331", + "332", + "333", + "334", + "335", + "336", + "337", + "338", + "339", + "340", + "341", + "342", + "343", + "344", + "345", + "346", + "347", + "348", + "349", + "350", + "351", + "352", + "353", + "354", + "355", + "356", + "357", + "358", + "359", + "360", + "361", + "362", + "363", + "364", + "365", + "366", + "367", + "368", + "369", + "370", + "371", + "372", + "373", + "374", + "375", + "376", + "377", + "378", + "379", + "380", + "381", + "382", + "383", + "384", + "385", + "386", + "387", + "388", + "389", + "390", + "391", + "392", + "393", + "394", + "395", + "396", + "397", + "398", + "399", + "400", + "401", + "402", + "403", + "404", + "405", + "406", + "407", + "408", + "409", + "410", + "411", + "412", + "413", + "414", + "415", + "416", + "417", + "418", + "419", + "420", + "421", + "422", + "423", + "424", + "425", + "426", + "427", + "428", + "429", + "430", + "431", + "432", + "433", + "434", + "435", + "436", + "437", + "438", + "439", + "440", + "441", + "442", + "443", + "444", + "445", + "446", + "447", + "448", + "449", + "450", + "451", + "452", + "453", + "454", + "455", + "456", + "457", + "458", + "459", + "460", + "461", + "462", + "463", + "464", + "465", + "466", + "467", + "468", + "469", + "470", + "471", + "472", + "473", + "474", + "475", + "476", + "477", + "478", + "479", + "480", + "481", + "482", + "483", + "484", + "485", + "486", + "487", + "488", + "489", + "490", + "491", + "492", + "493", + "494", + "495", + "496", + "497", + "498", + "499", + "500", + "501", + "502", + "503", + "504", + "505", + "506", + "507", + "508", + "509", + "510", + "511", + NULL /* WM_MOUSEMOVE */, + "WM_LBUTTONDOWN", + "WM_LBUTTONUP", + "WM_LBUTTONDBLCLK", + "WM_RBUTTONDOWN", + "WM_RBUTTONUP", + "WM_RBUTTONDBLCLK", + "WM_MBUTTONDOWN", + "WM_MBUTTONUP", + "WM_MBUTTONDBLCLK", + "WM_MOUSEWHEEL", + "523", + "524", + "525", + "526", + "527", + "WM_PARENTNOTIFY", + "WM_ENTERMENULOOP", + "WM_EXITMENULOOP", + "WM_NEXTMENU", + "WM_SIZING", + "WM_CAPTURECHANGED", + "WM_MOVING", + "535", + "WM_POWERBROADCAST", + "WM_DEVICECHANGE", + "538", + "539", + "540", + "541", + "542", + "543", + "WM_MDICREATE", + "WM_MDIDESTROY", + "WM_MDIACTIVATE", + "WM_MDIRESTORE", + "WM_MDINEXT", + "WM_MDIMAXIMIZE", + "WM_MDITILE", + "WM_MDICASCADE", + "WM_MDIICONARRANGE", + "WM_MDIGETACTIVE", + "554", + "555", + "556", + "557", + "558", + "559", + "WM_MDISETMENU", + "WM_ENTERSIZEMOVE", + "WM_EXITSIZEMOVE", + "WM_DROPFILES", + "WM_MDIREFRESHMENU", + "565", + "566", + "567", + "568", + "569", + "570", + "571", + "572", + "573", + "574", + "575", + "576", + "577", + "578", + "579", + "580", + "581", + "582", + "583", + "584", + "585", + "586", + "587", + "588", + "589", + "590", + "591", + "592", + "593", + "594", + "595", + "596", + "597", + "598", + "599", + "600", + "601", + "602", + "603", + "604", + "605", + "606", + "607", + "608", + "609", + "610", + "611", + "612", + "613", + "614", + "615", + "616", + "617", + "618", + "619", + "620", + "621", + "622", + "623", + "624", + "625", + "626", + "627", + "628", + "629", + "630", + "631", + "632", + "633", + "634", + "635", + "636", + "637", + "638", + "639", + "640", + "WM_IME_SETCONTEXT", + "WM_IME_NOTIFY", + "WM_IME_CONTROL", + "WM_IME_COMPOSITIONFULL", + "WM_IME_SELECT", + "WM_IME_CHAR", + "647", + "648", + "649", + "650", + "651", + "652", + "653", + "654", + "655", + "WM_IME_KEYDOWN", + "WM_IME_KEYUP", + "658", + "659", + "660", + "661", + "662", + "663", + "664", + "665", + "666", + "667", + "668", + "669", + "670", + "671", + "672", + "WM_MOUSEHOVER", + "674", + "WM_MOUSELEAVE", + "676", + "677", + "678", + "679", + "680", + "681", + "682", + "683", + "684", + "685", + "686", + "687", + "688", + "689", + "690", + "691", + "692", + "693", + "694", + "695", + "696", + "697", + "698", + "699", + "700", + "701", + "702", + "703", + "704", + "705", + "706", + "707", + "708", + "709", + "710", + "711", + "712", + "713", + "714", + "715", + "716", + "717", + "718", + "719", + "720", + "721", + "722", + "723", + "724", + "725", + "726", + "727", + "728", + "729", + "730", + "731", + "732", + "733", + "734", + "735", + "736", + "737", + "738", + "739", + "740", + "741", + "742", + "743", + "744", + "745", + "746", + "747", + "748", + "749", + "750", + "751", + "752", + "753", + "754", + "755", + "756", + "757", + "758", + "759", + "760", + "761", + "762", + "763", + "764", + "765", + "766", + "767", + "WM_CUT", + "WM_COPY", + "WM_PASTE", + "WM_CLEAR", + "WM_UNDO", + "WM_RENDERFORMAT", + "WM_RENDERALLFORMATS", + "WM_DESTROYCLIPBOARD", + "WM_DRAWCLIPBOARD", + "WM_PAINTCLIPBOARD", + "WM_VSCROLLCLIPBOARD", + "WM_SIZECLIPBOARD", + "WM_ASKCBFORMATNAME", + "WM_CHANGECBCHAIN", + "WM_HSCROLLCLIPBOARD", + "WM_QUERYNEWPALETTE", + "WM_PALETTEISCHANGING", + "WM_PALETTECHANGED", + "WM_HOTKEY", + "787", + "788", + "789", + "790", + "WM_PRINT", + "WM_PRINTCLIENT", + "793", + "794", + "795", + "796", + "797", + "798", + "799", + "800", + "801", + "802", + "803", + "804", + "805", + "806", + "807", + "808", + "809", + "810", + "811", + "812", + "813", + "814", + "815", + "816", + "817", + "818", + "819", + "820", + "821", + "822", + "823", + "824", + "825", + "826", + "827", + "828", + "829", + "830", + "831", + "832", + "833", + "834", + "835", + "836", + "837", + "838", + "839", + "840", + "841", + "842", + "843", + "844", + "845", + "846", + "847", + "848", + "849", + "850", + "851", + "852", + "853", + "854", + "855", + "856", + "857", + "858", + "859", + "860", + "861", + "862", + "863", + "864", + "865", + "866", + "867", + "868", + "869", + "870", + "871", + "872", + "873", + "874", + "875", + "876", + "877", + "878", + "879", + "880", + "881", + "882", + "883", + "884", + "885", + "886", + "887", + "888", + "889", + "890", + "891", + "892", + "893", + "894", + "895", + "896", + "897", + "898", + "899", + "900", + "901", + "902", + "903", + "904", + "905", + "906", + "907", + "908", + "909", + "910", + "911", + "912", + "913", + "914", + "915", + "916", + "917", + "918", + "919", + "920", + "921", + "922", + "923", + "924", + "925", + "926", + "927", + "928", + "929", + "930", + "931", + "932", + "933", + "934", + "935", + "936", + "937", + "938", + "939", + "940", + "941", + "942", + "943", + "944", + "945", + "946", + "947", + "948", + "949", + "950", + "951", + "952", + "953", + "954", + "955", + "956", + "957", + "958", + "959", + "960", + "961", + "962", + "963", + "964", + "965", + "966", + "967", + "968", + "969", + "970", + "971", + "972", + "973", + "974", + "975", + "976", + "977", + "978", + "979", + "980", + "981", + "982", + "983", + "984", + "985", + "986", + "987", + "988", + "989", + "990", + "991", + "992", + "993", + "994", + "995", + "996", + "997", + "998", + "999", + "1000", + "1001", + "1002", + "1003", + "1004", + "1005", + "1006", + "1007", + "1008", + "1009", + "1010", + "1011", + "1012", + "1013", + "1014", + "1015", + "1016", + "1017", + "1018", + "1019", + "1020", + "1021", + "1022", + "1023" +}; diff --git a/hw/xwin/winmisc.c b/hw/xwin/winmisc.c index e93d1fd93..a116043a8 100644 --- a/hw/xwin/winmisc.c +++ b/hw/xwin/winmisc.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,23 +15,22 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winmisc.c,v 1.5 2001/11/11 22:45:57 alanh Exp $ */ #include "win.h" - +#ifdef XWIN_NATIVEGDI /* See Porting Layer Definition - p. 33 */ /* * Called by clients, returns the best size for a cursor, tile, or @@ -44,6 +43,7 @@ winQueryBestSizeNativeGDI (int class, unsigned short *pWidth, { ErrorF ("winQueryBestSizeNativeGDI\n"); } +#endif /* @@ -96,6 +96,7 @@ winUpdateFBPointer (ScreenPtr pScreen, void *pbits) } +#ifdef XWIN_NATIVEGDI /* * Paint the window background with the specified color */ @@ -145,3 +146,4 @@ winPaintBackground (HWND hwnd, COLORREF colorref) return TRUE; } +#endif diff --git a/hw/xwin/winmouse.c b/hw/xwin/winmouse.c index ef3a2eb92..46850652b 100644 --- a/hw/xwin/winmouse.c +++ b/hw/xwin/winmouse.c @@ -34,7 +34,23 @@ #include "win.h" -void +#if defined(XFree86Server) && defined(XINPUT) +#include "inputstr.h" + +/* Peek the internal button mapping */ +static CARD8 const *g_winMouseButtonMap = NULL; +#endif + + +/* + * Local prototypes + */ + +static void +winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl); + + +static void winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl) { } @@ -65,6 +81,10 @@ winMouseProc (DeviceIntPtr pDeviceInt, int iState) miPointerGetMotionEvents, winMouseCtrl, miPointerGetMotionBufferSize ()); + +#if defined(XFree86Server) && defined(XINPUT) + g_winMouseButtonMap = pDeviceInt->button->map; +#endif break; case DEVICE_ON: @@ -72,6 +92,9 @@ winMouseProc (DeviceIntPtr pDeviceInt, int iState) break; case DEVICE_CLOSE: +#if defined(XFree86Server) && defined(XINPUT) + g_winMouseButtonMap = NULL; +#endif case DEVICE_OFF: pDevice->on = FALSE; break; @@ -85,7 +108,7 @@ int winMouseWheel (ScreenPtr pScreen, int iDeltaZ) { winScreenPriv(pScreen); - xEvent xCurrentEvent; + int button; /* Button4 or Button5 */ /* Button4 = WheelUp */ /* Button5 = WheelDown */ @@ -136,11 +159,11 @@ winMouseWheel (ScreenPtr pScreen, int iDeltaZ) /* Set the button to indicate up or down wheel delta */ if (iDeltaZ > 0) { - xCurrentEvent.u.u.detail = Button4; + button = Button4; } else { - xCurrentEvent.u.u.detail = Button5; + button = Button5; } /* @@ -157,16 +180,10 @@ winMouseWheel (ScreenPtr pScreen, int iDeltaZ) while (iDeltaZ--) { /* Push the wheel button */ - xCurrentEvent.u.u.type = ButtonPress; - xCurrentEvent.u.keyButtonPointer.time - = g_c32LastInputEventTime = GetTickCount (); - mieqEnqueue (&xCurrentEvent); + winMouseButtonsSendEvent (ButtonPress, button); /* Release the wheel button */ - xCurrentEvent.u.u.type = ButtonRelease; - xCurrentEvent.u.keyButtonPointer.time - = g_c32LastInputEventTime = GetTickCount (); - mieqEnqueue (&xCurrentEvent); + winMouseButtonsSendEvent (ButtonRelease, button); } return 0; @@ -184,6 +201,11 @@ winMouseButtonsSendEvent (int iEventType, int iButton) /* Load an xEvent and enqueue the event */ xCurrentEvent.u.u.type = iEventType; +#if defined(XFree86Server) && defined(XINPUT) + if (g_winMouseButtonMap) + xCurrentEvent.u.u.detail = g_winMouseButtonMap[iButton]; + else +#endif xCurrentEvent.u.u.detail = iButton; xCurrentEvent.u.keyButtonPointer.time = g_c32LastInputEventTime = GetTickCount (); diff --git a/hw/xwin/winms.h b/hw/xwin/winms.h index ad20348b6..cbd3dfbea 100644 --- a/hw/xwin/winms.h +++ b/hw/xwin/winms.h @@ -1,5 +1,7 @@ +#ifndef _WINMS_H_ +#define _WINMS_H_ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,22 +17,18 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winms.h,v 1.1 2001/04/05 20:13:50 dawes Exp $ */ - -#ifndef _WINMS_H_ -#define _WINMS_H_ #undef MINSHORT #undef MAXSHORT @@ -44,6 +42,9 @@ #define WIN32_LEAN_AND_MEAN #endif +#ifndef XFree86Server +#define XFree86Server +#endif #include <windows.h> #include <windowsx.h> diff --git a/hw/xwin/winmsg.c b/hw/xwin/winmsg.c index 8d42d95a0..49ecd09f9 100644 --- a/hw/xwin/winmsg.c +++ b/hw/xwin/winmsg.c @@ -33,14 +33,8 @@ #include "winmsg.h" #include <stdarg.h> -#ifndef VERBOSE_LEVEL -#define VERBOSE_LEVEL 4 -#endif - - void winVMsg (int, MessageType, int verb, const char *, va_list); - void winVMsg (int scrnIndex, MessageType type, int verb, const char *format, va_list ap) @@ -64,7 +58,7 @@ winMsg (MessageType type, const char *format, ...) { va_list ap; va_start (ap, format); - LogVMessageVerb(type, 0, format, ap); + LogVMessageVerb(type, 1, format, ap); va_end (ap); } @@ -98,3 +92,42 @@ winErrorFVerb (int verb, const char *format, ...) LogVMessageVerb(X_NONE, verb, format, ap); va_end (ap); } + +void +winDebug (const char *format, ...) +{ + va_list ap; + va_start (ap, format); + LogVMessageVerb(X_NONE, 3, format, ap); + va_end (ap); +} + +void +winW32Error(int verb, const char *msg) +{ + winW32ErrorEx(verb, msg, GetLastError()); +} + +void +winW32ErrorEx(int verb, const char *msg, DWORD errorcode) +{ + LPVOID buffer; + if (!FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + errorcode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &buffer, + 0, + NULL )) + { + winErrorFVerb(verb, "Unknown error in FormatMessage!\n"); + } + else + { + winErrorFVerb(verb, "%s %s", msg, (char *)buffer); + LocalFree(buffer); + } +} diff --git a/hw/xwin/winmsg.h b/hw/xwin/winmsg.h index 136cdc3a8..f29972004 100644 --- a/hw/xwin/winmsg.h +++ b/hw/xwin/winmsg.h @@ -1,3 +1,5 @@ +#ifndef __WIN_MSG_H__ +#define __WIN_MSG_H__ /* *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. * @@ -29,8 +31,6 @@ */ /* $XFree86$ */ -#ifndef __WIN_MSG_H__ -#define __WIN_MSG_H__ /* * Function prototypes @@ -41,7 +41,10 @@ void winDrvMsgVerb (int scrnIndex, void winDrvMsg (int scrnIndex, MessageType type, const char *format, ...); void winMsgVerb (MessageType type, int verb, const char *format, ...); void winMsg (MessageType type, const char *format, ...); +void winDebug (const char *format, ...); void winErrorFVerb (int verb, const char *format, ...); +void winW32Error(int verb, const char *message); +void winW32ErrorEx(int verb, const char *message, DWORD errorcode); #endif diff --git a/hw/xwin/winmultiwindowclass.c b/hw/xwin/winmultiwindowclass.c index be65bd153..d369db70e 100755 --- a/hw/xwin/winmultiwindowclass.c +++ b/hw/xwin/winmultiwindowclass.c @@ -29,10 +29,18 @@ */ /* $XFree86$ */ -#include <Xatom.h> +#include "X11/Xatom.h" #include "propertyst.h" #include "windowstr.h" #include "winmultiwindowclass.h" +#include "win.h" + +/* + * Local function + */ + +DEFINE_ATOM_HELPER(AtmWmWindowRole, "WM_WINDOW_ROLE") + int winMultiWindowGetClassHint (WindowPtr pWin, char **res_name, char **res_class) @@ -148,15 +156,10 @@ winMultiWindowGetWindowRole (WindowPtr pWin, char **res_role) struct _Window *pwin; struct _Property *prop; int len_role; - static Atom atmWmWindowRole = 0; if (!pWin || !res_role) return 0; - /* Initialize the window role atom, not in XAtom.h */ - if (!atmWmWindowRole) - atmWmWindowRole = MakeAtom ("WM_WINDOW_ROLE", 14, 1); - pwin = (struct _Window*) pWin; if (pwin->optional) @@ -167,7 +170,7 @@ winMultiWindowGetWindowRole (WindowPtr pWin, char **res_role) *res_role = NULL; while (prop) { - if (prop->propertyName == atmWmWindowRole + if (prop->propertyName == AtmWmWindowRole () && prop->type == XA_STRING && prop->format == 8 && prop->data) @@ -226,10 +229,46 @@ winMultiWindowGetWMNormalHints (WindowPtr pWin, WinXSizeHints *hints) else prop = prop->next; } - + return 0; } +int +winMultiWindowGetTransientFor (WindowPtr pWin, WindowPtr *ppDaddy) +{ + struct _Window *pwin; + struct _Property *prop; + + if (!pWin) + { + ErrorF ("winMultiWindowGetTransientFor - pWin was NULL\n"); + return 0; + } + + pwin = (struct _Window*) pWin; + + if (pwin->optional) + prop = (struct _Property *) pwin->optional->userProps; + else + prop = NULL; + + if (ppDaddy) + *ppDaddy = NULL; + + while (prop) + { + if (prop->propertyName == XA_WM_TRANSIENT_FOR) + { + if (ppDaddy) + memcpy (*ppDaddy, prop->data, sizeof (WindowPtr *)); + return 1; + } + else + prop = prop->next; + } + + return 0; +} int winMultiWindowGetWMName (WindowPtr pWin, char **wmName) @@ -281,4 +320,3 @@ winMultiWindowGetWMName (WindowPtr pWin, char **wmName) return 0; } - diff --git a/hw/xwin/winmultiwindowclass.h b/hw/xwin/winmultiwindowclass.h index f9cfee30f..0b430f2f8 100755 --- a/hw/xwin/winmultiwindowclass.h +++ b/hw/xwin/winmultiwindowclass.h @@ -1,3 +1,5 @@ +#if !defined(WINMULTIWINDOWCLASS_H) +#define WINMULTIWINDOWCLASS_H /* *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. * @@ -108,3 +110,7 @@ winMultiWindowGetWMNormalHints (WindowPtr pWin, WinXSizeHints *hints); int winMultiWindowGetWMName (WindowPtr pWin, char **wmName); +int +winMultiWindowGetTransientFor (WindowPtr pWin, WindowPtr *ppDaddy); + +#endif diff --git a/hw/xwin/winmultiwindowicons.c b/hw/xwin/winmultiwindowicons.c index 33b9391a8..34151a46c 100755 --- a/hw/xwin/winmultiwindowicons.c +++ b/hw/xwin/winmultiwindowicons.c @@ -39,7 +39,8 @@ * External global variables */ -extern HICON g_hiconX; +extern HICON g_hIconX; +extern HICON g_hSmallIconX; /* @@ -71,26 +72,39 @@ winScaleXBitmapToWindows (int iconSize, unsigned int zero; unsigned int color; + effXBPP = BitsPerPixel(pixmap->drawable.depth); + effXDepth = pixmap->drawable.depth; if (pixmap->drawable.bitsPerPixel == 15) effXBPP = 16; - else - effXBPP = pixmap->drawable.bitsPerPixel; if (pixmap->drawable.depth == 15) effXDepth = 16; - else - effXDepth = pixmap->drawable.depth; /* Need 32-bit aligned rows */ stride = ((iconSize * effBPP + 31) & (~31)) / 8; - xStride = ((pixmap->drawable.width * effXBPP + 31) & (~31)) / 8; - + xStride = PixmapBytePad (pixmap->drawable.width, pixmap->drawable.depth); + if (stride == 0 || xStride == 0) + { + ErrorF ("winScaleXBitmapToWindows - stride or xStride is zero. " + "Bailing.\n"); + return; + } + + /* Allocate memory for icon data */ iconData = malloc (xStride * pixmap->drawable.height); + if (!iconData) + { + ErrorF ("winScaleXBitmapToWindows - malloc failed for iconData. " + "Bailing.\n"); + return; + } + + /* Get icon data */ miGetImage ((DrawablePtr) &(pixmap->drawable), 0, 0, pixmap->drawable.width, pixmap->drawable.height, ZPixmap, 0xffffffff, iconData); - + /* Keep aspect ratio */ factX = ((float)pixmap->drawable.width) / ((float)iconSize); factY = ((float)pixmap->drawable.height) / ((float)iconSize); @@ -250,13 +264,13 @@ winScaleXBitmapToWindows (int iconSize, */ HICON -winXIconToHICON (WindowPtr pWin) +winXIconToHICON (WindowPtr pWin, int iconSize) { unsigned char *mask, *image, *imageMask; unsigned char *dst, *src; PixmapPtr iconPtr; PixmapPtr maskPtr; - int iconSize, planes, bpp, effBPP, stride, maskStride, i; + int planes, bpp, effBPP, stride, maskStride, i; HDC hDC; ICONINFO ii; WinXWMHints hints; @@ -269,8 +283,6 @@ winXIconToHICON (WindowPtr pWin) if (!iconPtr) return NULL; - iconSize = 32; - hDC = GetDC (GetDesktopWindow ()); planes = GetDeviceCaps (hDC, PLANES); bpp = GetDeviceCaps (hDC, BITSPIXEL); @@ -357,7 +369,7 @@ winUpdateIcon (Window id) hIcon = (HICON)winOverrideIcon ((unsigned long)pWin); if (!hIcon) - hIcon = winXIconToHICON (pWin); + hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON)); if (hIcon) { @@ -370,9 +382,92 @@ winUpdateIcon (Window id) (int) hIcon); /* Delete the icon if its not the default */ - if (hiconOld != g_hiconX && - !winIconIsOverride((unsigned long)hiconOld)) - DeleteObject (hiconOld); + winDestroyIcon(hiconOld); + } + } + + hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON)); + if (hIcon) + { + winWindowPriv(pWin); + + if (pWinPriv->hWnd) + { + hiconOld = (HICON) SetClassLong (pWinPriv->hWnd, + GCL_HICONSM, + (int) hIcon); + winDestroyIcon (hiconOld); } } } + +void winInitGlobalIcons (void) +{ + int sm_cx = GetSystemMetrics(SM_CXICON); + int sm_cxsm = GetSystemMetrics(SM_CXSMICON); + /* Load default X icon in case it's not ready yet */ + if (!g_hIconX) + { + g_hIconX = (HICON)winOverrideDefaultIcon(sm_cx); + g_hSmallIconX = (HICON)winOverrideDefaultIcon(sm_cxsm); + } + + if (!g_hIconX) + { + g_hIconX = (HICON)LoadImage (g_hInstance, + MAKEINTRESOURCE(IDI_XWIN), + IMAGE_ICON, + GetSystemMetrics(SM_CXICON), + GetSystemMetrics(SM_CYICON), + 0); + g_hSmallIconX = (HICON)LoadImage (g_hInstance, + MAKEINTRESOURCE(IDI_XWIN), + IMAGE_ICON, + GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), + LR_DEFAULTSIZE); + } +} + +void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon) +{ + HICON hIcon, hSmallIcon; + + winInitGlobalIcons(); + + /* Try and get the icon from WM_HINTS */ + hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON)); + hSmallIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON)); + + /* If we got the small, but not the large one swap them */ + if (!hIcon && hSmallIcon) + { + hIcon = hSmallIcon; + hSmallIcon = NULL; + } + + /* Use default X icon if no icon loaded from WM_HINTS */ + if (!hIcon) { + hIcon = g_hIconX; + hSmallIcon = g_hSmallIconX; + } + + if (pIcon) + *pIcon = hIcon; + else + winDestroyIcon(hIcon); + if (pSmallIcon) + *pSmallIcon = hSmallIcon; + else + winDestroyIcon(hSmallIcon); +} + +void winDestroyIcon(HICON hIcon) +{ + /* Delete the icon if its not the default */ + if (hIcon && + hIcon != g_hIconX && + hIcon != g_hSmallIconX && + !winIconIsOverride((unsigned long)hIcon)) + DestroyIcon (hIcon); +} diff --git a/hw/xwin/winmultiwindowshape.c b/hw/xwin/winmultiwindowshape.c index a21bbe9f3..bfec1a1ea 100755 --- a/hw/xwin/winmultiwindowshape.c +++ b/hw/xwin/winmultiwindowshape.c @@ -36,13 +36,6 @@ /* - * External global variables - */ - -extern HICON g_hiconX; - - -/* * winSetShapeMultiWindow - See Porting Layer Definition - p. 42 */ @@ -91,7 +84,7 @@ winReshapeMultiWindow (WindowPtr pWin) winWindowPriv(pWin); #if CYGDEBUG - ErrorF ("winReshape ()\n"); + winDebug ("winReshape ()\n"); #endif /* Bail if the window is the root window */ diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c index 1430b7d88..1c5e2fbbf 100644 --- a/hw/xwin/winmultiwindowwindow.c +++ b/hw/xwin/winmultiwindowwindow.c @@ -36,19 +36,19 @@ #include "winmultiwindowclass.h" #include "winprefs.h" - /* * External global variables */ -extern HICON g_hiconX; +extern HWND g_hDlgDepthChange; +extern void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon); /* * Prototypes for local functions */ -static void +void winCreateWindowsWindow (WindowPtr pWin); static void @@ -60,12 +60,6 @@ winUpdateWindowsWindow (WindowPtr pWin); static void winFindWindow (pointer value, XID id, pointer cdata); -#if 0 -static void -winRestackXWindow (WindowPtr pWin, int smode); -#endif - - /* * Constant defines */ @@ -109,8 +103,7 @@ winCreateWindowMultiWindow (WindowPtr pWin) pWinPriv->hWnd = NULL; pWinPriv->pScreenPriv = winGetScreenPriv(pWin->drawable.pScreen); pWinPriv->fXKilled = FALSE; - pWinPriv->fNeedRestore = FALSE; - + return fResult; } @@ -145,13 +138,17 @@ winDestroyWindowMultiWindow (WindowPtr pWin) /* * PositionWindow - See Porting Layer Definition - p. 37 + * + * This function adjusts the position and size of Windows window + * with respect to the underlying X window. This is the inverse + * of winAdjustXWindow, which adjusts X window to Windows window. */ Bool winPositionWindowMultiWindow (WindowPtr pWin, int x, int y) { Bool fResult = TRUE; - int iX, iY, iWidth, iHeight, iBorder; + int iX, iY, iWidth, iHeight; winWindowPriv(pWin); HWND hWnd = pWinPriv->hWnd; RECT rcNew; @@ -171,17 +168,24 @@ winPositionWindowMultiWindow (WindowPtr pWin, int x, int y) if (winGetScreenPriv(pWin->drawable.pScreen)->PositionWindow) fResult = winGetScreenPriv(pWin->drawable.pScreen)->PositionWindow (pWin, x, y); +#if CYGWINDOWING_DEBUG + ErrorF ("winPositionWindowMultiWindow: (x, y) = (%d, %d)\n", + x, y); +#endif + /* Bail out if the Windows window handle is bad */ if (!hWnd) - return fResult; + { +#if CYGWINDOWING_DEBUG + ErrorF ("\timmediately return since hWnd is NULL\n"); +#endif + return fResult; + } /* Get the Windows window style and extended style */ dwExStyle = GetWindowLongPtr (hWnd, GWL_EXSTYLE); dwStyle = GetWindowLongPtr (hWnd, GWL_STYLE); - /* Get the width of the X window border */ - iBorder = wBorderWidth (pWin); - /* Get the X and Y location of the X window */ iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN); iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN); @@ -232,6 +236,10 @@ winPositionWindowMultiWindow (WindowPtr pWin, int x, int y) ErrorF ("winPositionWindowMultiWindow - Need to move\n"); #endif +#if CYGWINDOWING_DEBUG + ErrorF ("\tMoveWindow to (%ld, %ld) - %ldx%ld\n", rcNew.left, rcNew.top, + rcNew.right - rcNew.left, rcNew.bottom - rcNew.top); +#endif /* Change the position and dimensions of the Windows window */ MoveWindow (hWnd, rcNew.left, rcNew.top, @@ -372,7 +380,7 @@ winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib) HWND hWnd = NULL; winWindowPriv(pWin); -#if CYGMULTIWINDOW_DEBUG +#if CYGMULTIWINDOW_DEBUG || CYGWINDOWING_DEBUG ErrorF ("winRestackMultiWindow - %08x\n", pWin); #endif @@ -381,9 +389,13 @@ winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib) winGetScreenPriv(pWin->drawable.pScreen)->RestackWindow (pWin, pOldNextSib); - if (winGetScreenPriv(pWin->drawable.pScreen)->fRestacking) - return; - +#if 1 + /* + * Calling winReorderWindowsMultiWindow here means our window manager + * (i.e. Windows Explorer) has initiative to determine Z order. + */ + winReorderWindowsMultiWindow (); +#else /* Bail out if no window privates or window handle is invalid */ if (!pWinPriv || !pWinPriv->hWnd) return; @@ -436,6 +448,7 @@ winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib) 0, 0, 0, 0, uFlags); +#endif } @@ -443,50 +456,49 @@ winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib) * winCreateWindowsWindow - Create a Windows window associated with an X window */ -static void +void winCreateWindowsWindow (WindowPtr pWin) { int iX, iY; int iWidth; int iHeight; - int iBorder; HWND hWnd; - WNDCLASS wc; + WNDCLASSEX wc; winWindowPriv(pWin); - HICON hIcon; + HICON hIcon; + HICON hIconSmall; #define CLASS_NAME_LENGTH 512 char pszClass[CLASS_NAME_LENGTH], pszWindowID[12]; char *res_name, *res_class, *res_role; static int s_iWindowID = 0; + winPrivScreenPtr pScreenPriv = pWinPriv->pScreenPriv; + WinXSizeHints hints; #if CYGMULTIWINDOW_DEBUG ErrorF ("winCreateWindowsWindow - pWin: %08x\n", pWin); #endif - iBorder = wBorderWidth (pWin); - iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN); iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN); - + + /* Default positions if none specified */ + if (!winMultiWindowGetWMNormalHints(pWin, &hints)) + hints.flags = 0; + if ( !(hints.flags & (USPosition|PPosition)) && + !winMultiWindowGetTransientFor (pWin, NULL) && + !pWin->overrideRedirect ) + { + iX = CW_USEDEFAULT; + iY = CW_USEDEFAULT; + } + iWidth = pWin->drawable.width; iHeight = pWin->drawable.height; - /* Load default X icon in case it's not ready yet */ - if (!g_hiconX) - g_hiconX = (HICON)winOverrideDefaultIcon(); - - if (!g_hiconX) - g_hiconX = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN)); - - /* Try and get the icon from WM_HINTS */ - hIcon = winXIconToHICON (pWin); - - /* Use default X icon if no icon loaded from WM_HINTS */ - if (!hIcon) - hIcon = g_hiconX; + winSelectIcons(pWin, &hIcon, &hIconSmall); /* Set standard class name prefix so we can identify window easily */ - strncpy (pszClass, WINDOW_CLASS_X, strlen (WINDOW_CLASS_X)); + strncpy (pszClass, WINDOW_CLASS_X, sizeof(pszClass)); if (winMultiWindowGetClassHint (pWin, &res_name, &res_class)) { @@ -520,23 +532,27 @@ winCreateWindowsWindow (WindowPtr pWin) #endif /* Setup our window class */ + wc.cbSize = sizeof(wc); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = winTopLevelWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = g_hInstance; wc.hIcon = hIcon; + wc.hIconSm = hIconSmall; wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = pszClass; - RegisterClass (&wc); + RegisterClassEx (&wc); /* Create the window */ + /* Make it OVERLAPPED in create call since WS_POPUP doesn't support */ + /* CW_USEDEFAULT, change back to popup after creation */ hWnd = CreateWindowExA (WS_EX_TOOLWINDOW, /* Extended styles */ pszClass, /* Class name */ WINDOW_TITLE_X, /* Window name */ - WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, + WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, iX, /* Horizontal position */ iY, /* Vertical position */ iWidth, /* Right edge */ @@ -548,18 +564,28 @@ winCreateWindowsWindow (WindowPtr pWin) if (hWnd == NULL) { ErrorF ("winCreateWindowsWindow - CreateWindowExA () failed: %d\n", - GetLastError ()); + (int) GetLastError ()); } - + + /* Change style back to popup, already placed... */ + SetWindowLong (hWnd, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); + SetWindowPos (hWnd, 0, 0, 0, 0, 0, + SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE); + /* Make sure it gets the proper system menu for a WS_POPUP, too */ + GetSystemMenu (hWnd, TRUE); + pWinPriv->hWnd = hWnd; - /* Cause the "Always On Top" to be added in main WNDPROC */ + /* Cause any .XWinrc menus to be added in main WNDPROC */ PostMessage (hWnd, WM_INIT_SYS_MENU, 0, 0); SetProp (pWinPriv->hWnd, WIN_WID_PROP, (HANDLE) winGetWindowID(pWin)); /* Flag that this Windows window handles its own activation */ SetProp (pWinPriv->hWnd, WIN_NEEDMANAGE_PROP, (HANDLE) 0); + + /* Call engine-specific create window procedure */ + (*pScreenPriv->pwinFinishCreateWindowsWindow) (pWin); } @@ -567,13 +593,13 @@ winCreateWindowsWindow (WindowPtr pWin) * winDestroyWindowsWindow - Destroy a Windows window associated * with an X window */ - static void winDestroyWindowsWindow (WindowPtr pWin) { MSG msg; winWindowPriv(pWin); HICON hiconClass; + HICON hiconSmClass; HMODULE hInstance; int iReturn; char pszClass[512]; @@ -586,11 +612,10 @@ winDestroyWindowsWindow (WindowPtr pWin) if (pWinPriv->hWnd == NULL) return; - SetProp (pWinPriv->hWnd, WIN_WINDOW_PROP, 0); - /* Store the info we need to destroy after this window is gone */ hInstance = (HINSTANCE) GetClassLong (pWinPriv->hWnd, GCL_HMODULE); hiconClass = (HICON) GetClassLong (pWinPriv->hWnd, GCL_HICON); + hiconSmClass = (HICON) GetClassLong (pWinPriv->hWnd, GCL_HICONSM); iReturn = GetClassName (pWinPriv->hWnd, pszClass, 512); /* Destroy the Windows window */ @@ -620,15 +645,8 @@ winDestroyWindowsWindow (WindowPtr pWin) ErrorF ("winDestroyWindowsWindow - %d Deleting Icon: ", iReturn); #endif - /* Only delete if it's not the default */ - if (hiconClass != g_hiconX && - !winIconIsOverride((unsigned long)hiconClass)) - { - iReturn = DestroyIcon (hiconClass); -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winDestroyWindowsWindow - %d\n", iReturn); -#endif - } + winDestroyIcon(hiconClass); + winDestroyIcon(hiconSmClass); } #if CYGMULTIWINDOW_DEBUG @@ -705,38 +723,6 @@ winGetWindowID (WindowPtr pWin) /* - * winMoveXWindow - - */ - -void -winMoveXWindow (WindowPtr pWin, int x, int y) -{ - XID *vlist = malloc(sizeof(long)*2); - - (CARD32*)vlist[0] = x; - (CARD32*)vlist[1] = y; - ConfigureWindow (pWin, CWX | CWY, vlist, wClient(pWin)); - free(vlist); -} - - -/* - * winResizeXWindow - - */ - -void -winResizeXWindow (WindowPtr pWin, int w, int h) -{ - XID *vlist = malloc(sizeof(long)*2); - - (CARD32*)vlist[0] = w; - (CARD32*)vlist[1] = h; - ConfigureWindow (pWin, CWWidth | CWHeight, vlist, wClient(pWin)); - free(vlist); -} - - -/* * winFindWindow - */ @@ -752,95 +738,69 @@ winFindWindow (pointer value, XID id, pointer cdata) } -#if 0 -/* - * winRestackXWindow - - */ - -static void -winRestackXWindow (WindowPtr pWin, int smode) -{ - XID *vlist = malloc(sizeof(unsigned long)); - - if (vlist == NULL) - { - ErrorF ("winRestackXWindow - malloc () failed\n"); - return; - } - - if (pWin == NULL) - { - ErrorF ("winRestackXWindow - NULL window\n"); - free(vlist); - return; - } - - *((unsigned long*)vlist) = smode; - ConfigureWindow (pWin, CWStackMode, vlist, wClient(pWin)); - - free(vlist); -} -#endif - - /* * winReorderWindowsMultiWindow - */ void -winReorderWindowsMultiWindow (ScreenPtr pScreen) +winReorderWindowsMultiWindow (void) { - winScreenPriv(pScreen); HWND hwnd = NULL; WindowPtr pWin = NULL; WindowPtr pWinSib = NULL; + XID vlist[2]; + static Bool fRestacking = FALSE; /* Avoid recusive calls to this function */ + DWORD dwCurrentProcessID = GetCurrentProcessId (); + DWORD dwWindowProcessID = 0; -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winOrderWindowsMultiWindow\n"); +#if CYGMULTIWINDOW_DEBUG || CYGWINDOWING_DEBUG + ErrorF ("winReorderWindowsMultiWindow\n"); #endif - pScreenPriv->fRestacking = TRUE; - - if (pScreenPriv->fWindowOrderChanged) + if (fRestacking) { -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winOrderWindowsMultiWindow - Need to restack\n"); + /* It is a recusive call so immediately exit */ +#if CYGWINDOWING_DEBUG + ErrorF ("winReorderWindowsMultiWindow - " + "exit because fRestacking == TRUE\n"); #endif - hwnd = GetTopWindow (NULL); + return; + } + fRestacking = TRUE; - while (hwnd) + /* Loop through top level Window windows, descending in Z order */ + for ( hwnd = GetTopWindow (NULL); + hwnd; + hwnd = GetNextWindow (hwnd, GW_HWNDNEXT) ) + { + /* Don't take care of other Cygwin/X process's windows */ + GetWindowThreadProcessId (hwnd, &dwWindowProcessID); + + if ( GetProp (hwnd, WIN_WINDOW_PROP) + && (dwWindowProcessID == dwCurrentProcessID) + && !IsIconic (hwnd) ) /* ignore minimized windows */ { - if (GetProp (hwnd, WIN_WINDOW_PROP)) - { - pWinSib = pWin; - pWin = GetProp (hwnd, WIN_WINDOW_PROP); + pWinSib = pWin; + pWin = GetProp (hwnd, WIN_WINDOW_PROP); - if (pWinSib) - { - XID *vlist = malloc (sizeof(long) * 2); - - if (vlist == NULL) - { - ErrorF ("winOrderWindowsMultiWindow - malloc () " - "failed\n"); - return; - } + if (!pWinSib) + { /* 1st window - raise to the top */ + vlist[0] = Above; - ((long*)vlist)[0] = winGetWindowID (pWinSib); - ((long*)vlist)[1] = Below; + ConfigureWindow (pWin, CWStackMode, vlist, wClient(pWin)); + } + else + { /* 2nd or deeper windows - just below the previous one */ + vlist[0] = winGetWindowID (pWinSib); + vlist[1] = Below; - ConfigureWindow (pWin, CWSibling | CWStackMode, - vlist, wClient(pWin)); - - free (vlist); - } + ConfigureWindow (pWin, CWSibling | CWStackMode, + vlist, wClient(pWin)); } - hwnd = GetNextWindow (hwnd, GW_HWNDNEXT); } } - pScreenPriv->fRestacking = FALSE; - pScreenPriv->fWindowOrderChanged = FALSE; + fRestacking = FALSE; } @@ -853,6 +813,10 @@ winMinimizeWindow (Window id) { WindowPtr pWin; winPrivWinPtr pWinPriv; + +#if CYGWINDOWING_DEBUG + ErrorF ("winMinimizeWindow\n"); +#endif pWin = LookupIDByType (id, RT_WINDOW); @@ -860,3 +824,147 @@ winMinimizeWindow (Window id) ShowWindow (pWinPriv->hWnd, SW_MINIMIZE); } + + +/* + * CopyWindow - See Porting Layer Definition - p. 39 + */ +void +winCopyWindowMultiWindow (WindowPtr pWin, DDXPointRec oldpt, + RegionPtr oldRegion) +{ +#if CYGWINDOWING_DEBUG + ErrorF ("CopyWindowMultiWindow\n"); +#endif + /* Call any wrapped CopyWindow function */ + if (winGetScreenPriv(pWin->drawable.pScreen)->CopyWindow) + winGetScreenPriv(pWin->drawable.pScreen)->CopyWindow (pWin, + oldpt, + oldRegion); +} + + +/* + * MoveWindow - See Porting Layer Definition - p. 42 + */ +void +winMoveWindowMultiWindow (WindowPtr pWin, int x, int y, + WindowPtr pSib, VTKind kind) +{ +#if CYGWINDOWING_DEBUG + ErrorF ("MoveWindowMultiWindow to (%d, %d)\n", x, y); +#endif + /* Call any wrapped MoveWindow function */ + if (winGetScreenPriv(pWin->drawable.pScreen)->MoveWindow) + winGetScreenPriv(pWin->drawable.pScreen)->MoveWindow (pWin, x, y, + pSib, kind); +} + + +/* + * ResizeWindow - See Porting Layer Definition - p. 42 + */ +void +winResizeWindowMultiWindow (WindowPtr pWin, int x, int y, unsigned int w, + unsigned int h, WindowPtr pSib) +{ +#if CYGWINDOWING_DEBUG + ErrorF ("ResizeWindowMultiWindow to (%d, %d) - %dx%d\n", x, y, w, h); +#endif + /* Call any wrapped MoveWindow function */ + if (winGetScreenPriv(pWin->drawable.pScreen)->ResizeWindow) + winGetScreenPriv(pWin->drawable.pScreen)->ResizeWindow (pWin, x, y, + w, h, pSib); +} + + +/* + * winAdjustXWindow + * + * Move and resize X window with respect to corresponding Windows window. + * This is called from WM_MOVE/WM_SIZE handlers when the user performs + * any windowing operation (move, resize, minimize, maximize, restore). + * + * The functionality is the inverse of winPositionWindowMultiWindow, which + * adjusts Windows window with respect to X window. + */ +int +winAdjustXWindow (WindowPtr pWin, HWND hwnd) +{ + RECT rcDraw; /* Rect made from pWin->drawable to be adjusted */ + RECT rcWin; /* The source: WindowRect from hwnd */ + DrawablePtr pDraw; + XID vlist[4]; + LONG dX, dY, dW, dH, x, y; + DWORD dwStyle, dwExStyle; + +#define WIDTH(rc) (rc.right - rc.left) +#define HEIGHT(rc) (rc.bottom - rc.top) + +#if CYGWINDOWING_DEBUG + ErrorF ("winAdjustXWindow\n"); +#endif + + if (IsIconic (hwnd)) + { +#if CYGWINDOWING_DEBUG + ErrorF ("\timmediately return because the window is iconized\n"); +#endif + /* + * If the Windows window is minimized, its WindowRect has + * meaningless values so we don't adjust X window to it. + * Instead we put the X window to the bottom in Z order to + * be obscured by other windows. + */ + vlist[0] = Below; + return ConfigureWindow (pWin, CWStackMode, vlist, wClient(pWin)); + } + + pDraw = &pWin->drawable; + + /* Calculate the window rect from the drawable */ + x = pDraw->x + GetSystemMetrics (SM_XVIRTUALSCREEN); + y = pDraw->y + GetSystemMetrics (SM_YVIRTUALSCREEN); + SetRect (&rcDraw, x, y, x + pDraw->width, y + pDraw->height); + dwExStyle = GetWindowLongPtr (hwnd, GWL_EXSTYLE); + dwStyle = GetWindowLongPtr (hwnd, GWL_STYLE); + AdjustWindowRectEx (&rcDraw, dwStyle, FALSE, dwExStyle); + + /* The source of adjust */ + GetWindowRect (hwnd, &rcWin); + + if (EqualRect (&rcDraw, &rcWin)) { + /* Bail if no adjust is needed */ +#if CYGWINDOWING_DEBUG + ErrorF ("\treturn because already adjusted\n"); +#endif + return 0; + } + + /* Calculate delta values */ + dX = rcWin.left - rcDraw.left; + dY = rcWin.top - rcDraw.top; + dW = WIDTH(rcWin) - WIDTH(rcDraw); + dH = HEIGHT(rcWin) - HEIGHT(rcDraw); + + /* + * Adjust. + * We may only need to move (vlist[0] and [1]), or only resize + * ([2] and [3]) but currently we set all the parameters and leave + * the decision to ConfigureWindow. The reason is code simplicity. + */ + vlist[0] = pDraw->x + dX - wBorderWidth(pWin); + vlist[1] = pDraw->y + dY - wBorderWidth(pWin); + vlist[2] = pDraw->width + dW; + vlist[3] = pDraw->height + dH; +#if CYGWINDOWING_DEBUG + ErrorF ("\tConfigureWindow to (%ld, %ld) - %ldx%ld\n", vlist[0], vlist[1], + vlist[2], vlist[3]); +#endif + return ConfigureWindow (pWin, CWX | CWY | CWWidth | CWHeight, + vlist, wClient(pWin)); + +#undef WIDTH +#undef HEIGHT +} + diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index f77a40476..786b4e001 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -51,8 +51,15 @@ #include <windows.h> /* Local headers */ +#include "obj_base.h" +#include "ddraw.h" #include "winwindow.h" +extern void winDebug(const char *format, ...); + +#ifndef CYGDEBUG +#define CYGDEBUG NO +#endif /* * Constant defines @@ -79,6 +86,7 @@ typedef struct _WMMsgQueueRec { struct _WMMsgNodeRec *pTail; pthread_mutex_t pmMutex; pthread_cond_t pcNotEmpty; + int nQueueSize; } WMMsgQueueRec, *WMMsgQueuePtr; typedef struct _WMInfo { @@ -96,9 +104,9 @@ typedef struct _WMProcArgRec { } WMProcArgRec, *WMProcArgPtr; typedef struct _XMsgProcArgRec { - Display *pDisplay; - DWORD dwScreen; - WMInfoPtr pWMInfo; + Display *pDisplay; + DWORD dwScreen; + WMInfoPtr pWMInfo; pthread_mutex_t *ppmServerStarted; } XMsgProcArgRec, *XMsgProcArgPtr; @@ -109,8 +117,6 @@ typedef struct _XMsgProcArgRec { extern char *display; extern void ErrorF (const char* /*f*/, ...); -extern Bool g_fCalledSetLocale; -extern Bool g_fCalledXInitThreads; /* @@ -139,26 +145,40 @@ static void* winMultiWindowWMProc (void* pArg); static int -winMultiWindowWMErrorHandler (Display *pDisp, XErrorEvent *e); +winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr); + +static int +winMultiWindowWMIOErrorHandler (Display *pDisplay); static void * winMultiWindowXMsgProc (void *pArg); +static int +winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr); + +static int +winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay); + +static int +winRedirectErrorHandler (Display *pDisplay, XErrorEvent *pErr); + static void winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg); -static int -winMutliWindowWMIOErrorHandler (Display *pDisplay); +#if 0 +static void +PreserveWin32Stack(WMInfoPtr pWMInfo, Window iWindow, UINT direction); +#endif /* * Local globals */ -static int g_nQueueSize; -static jmp_buf g_jmpEntry; +static jmp_buf g_jmpWMEntry; +static jmp_buf g_jmpXMsgProcEntry; static Bool g_shutdown = FALSE; - +static Bool redirectError = FALSE; /* @@ -214,7 +234,7 @@ PushMessage (WMMsgQueuePtr pQueue, WMMsgNodePtr pNode) #endif /* Increase the count of elements in the queue by one */ - ++g_nQueueSize; + ++(pQueue->nQueueSize); /* Release the queue mutex */ pthread_mutex_unlock (&pQueue->pmMutex); @@ -274,10 +294,10 @@ PopMessage (WMMsgQueuePtr pQueue, WMInfoPtr pWMInfo) } /* Drop the number of elements in the queue by one */ - --g_nQueueSize; + --(pQueue->nQueueSize); #if CYGMULTIWINDOW_DEBUG - ErrorF ("Queue Size %d %d\n", g_nQueueSize, QueueSize(pQueue)); + ErrorF ("Queue Size %d %d\n", pQueue->nQueueSize, QueueSize(pQueue)); #endif /* Release the queue mutex */ @@ -328,10 +348,11 @@ InitQueue (WMMsgQueuePtr pQueue) pQueue->pTail = NULL; /* There are no elements initially */ - g_nQueueSize = 0; + pQueue->nQueueSize = 0; #if CYGMULTIWINDOW_DEBUG - ErrorF ("InitQueue - Queue Size %d %d\n", g_nQueueSize, QueueSize(pQueue)); + ErrorF ("InitQueue - Queue Size %d %d\n", pQueue->nQueueSize, + QueueSize(pQueue)); #endif ErrorF ("InitQueue - Calling pthread_mutex_init\n"); @@ -399,10 +420,10 @@ GetWindowName (Display *pDisplay, Window iWin, char **ppName) /* */ if (nNum && ppList && *ppList) { - XFree (xtpName.value); *ppName = strdup (*ppList); XFreeStringList (ppList); } + XFree (xtpName.value); #if CYGMULTIWINDOW_DEBUG ErrorF ("GetWindowName - %s %s\n", @@ -410,7 +431,6 @@ GetWindowName (Display *pDisplay, Window iWin, char **ppName) #endif } - #if CYGMULTIWINDOW_DEBUG ErrorF ("GetWindowName - Returning\n"); #endif @@ -499,6 +519,74 @@ UpdateName (WMInfoPtr pWMInfo, Window iWindow) } +#if 0 +/* + * Fix up any differences between the X11 and Win32 window stacks + * starting at the window passed in + */ +static void +PreserveWin32Stack(WMInfoPtr pWMInfo, Window iWindow, UINT direction) +{ + Atom atmType; + int fmtRet; + unsigned long items, remain; + HWND hWnd, *retHwnd; + DWORD myWinProcID, winProcID; + Window xWindow; + WINDOWPLACEMENT wndPlace; + + hWnd = NULL; + /* See if we can get the cached HWND for this window... */ + if (XGetWindowProperty (pWMInfo->pDisplay, + iWindow, + pWMInfo->atmPrivMap, + 0, + 1, + False, + pWMInfo->atmPrivMap, + &atmType, + &fmtRet, + &items, + &remain, + (unsigned char **) &retHwnd) == Success) + { + if (retHwnd) + { + hWnd = *retHwnd; + XFree (retHwnd); + } + } + + if (!hWnd) return; + + GetWindowThreadProcessId (hWnd, &myWinProcID); + hWnd = GetNextWindow (hWnd, direction); + + while (hWnd) { + GetWindowThreadProcessId (hWnd, &winProcID); + if (winProcID == myWinProcID) + { + wndPlace.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement (hWnd, &wndPlace); + if ( !(wndPlace.showCmd==SW_HIDE || + wndPlace.showCmd==SW_MINIMIZE) ) + { + xWindow = (Window)GetProp (hWnd, WIN_WID_PROP); + if (xWindow) + { + if (direction==GW_HWNDPREV) + XRaiseWindow (pWMInfo->pDisplay, xWindow); + else + XLowerWindow (pWMInfo->pDisplay, xWindow); + } + } + } + hWnd = GetNextWindow(hWnd, direction); + } +} +#endif /* PreserveWin32Stack */ + + /* * winMultiWindowWMProc */ @@ -527,7 +615,7 @@ winMultiWindowWMProc (void *pArg) { /* Bail if PopMessage returns without a message */ /* NOTE: Remember that PopMessage is a blocking function. */ - ErrorF ("winMultiWindowWMProc - Queue is Empty?\n"); + ErrorF ("winMultiWindowWMProc - Queue is Empty? Exiting.\n"); pthread_exit (NULL); } @@ -553,9 +641,11 @@ winMultiWindowWMProc (void *pArg) #if CYGMULTIWINDOW_DEBUG ErrorF ("\tWM_WM_RAISE\n"); #endif - /* Raise the window */ XRaiseWindow (pWMInfo->pDisplay, pNode->msg.iWindow); +#if 0 + PreserveWin32Stack (pWMInfo, pNode->msg.iWindow, GW_HWNDPREV); +#endif break; case WM_WM_LOWER: @@ -582,6 +672,10 @@ winMultiWindowWMProc (void *pArg) 1); UpdateName (pWMInfo, pNode->msg.iWindow); winUpdateIcon (pNode->msg.iWindow); +#if 0 + /* Handles the case where there are AOT windows above it in W32 */ + PreserveWin32Stack (pWMInfo, pNode->msg.iWindow, GW_HWNDPREV); +#endif break; case WM_WM_UNMAP: @@ -652,7 +746,7 @@ winMultiWindowWMProc (void *pArg) break; default: - ErrorF ("winMultiWindowWMProc - Unknown Message.\n"); + ErrorF ("winMultiWindowWMProc - Unknown Message. Exiting.\n"); pthread_exit (NULL); break; } @@ -680,48 +774,7 @@ winMultiWindowWMProc (void *pArg) /* - * winMultiWindowWMErrorHandler - Our application specific error handler - */ - -static int -winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr) -{ - char pszErrorMsg[100]; - - if (pErr->request_code == X_ChangeWindowAttributes - && pErr->error_code == BadAccess) - { - ErrorF ("winMultiWindowWMErrorHandler - ChangeWindowAttributes " - "BadAccess.\n"); -#if 0 - pthread_exit (NULL); -#endif - return 0; - } - - XGetErrorText (pDisplay, - pErr->error_code, - pszErrorMsg, - sizeof (pszErrorMsg)); - ErrorF ("winMultiWindowWMErrorHandler - ERROR: %s\n", pszErrorMsg); - - if (pErr->error_code == BadWindow - || pErr->error_code == BadMatch - || pErr->error_code == BadDrawable) - { -#if 0 - pthread_exit (NULL); -#endif - return 0; - } - - pthread_exit (NULL); - return 0; -} - - -/* - * + * X message procedure */ static void * @@ -743,7 +796,7 @@ winMultiWindowXMsgProc (void *pArg) /* Check that argument pointer is not invalid */ if (pProcArg == NULL) { - ErrorF ("winMultiWindowXMsgProc - pProcArg is NULL, bailing.\n"); + ErrorF ("winMultiWindowXMsgProc - pProcArg is NULL. Exiting.\n"); pthread_exit (NULL); } @@ -753,27 +806,27 @@ winMultiWindowXMsgProc (void *pArg) iReturn = pthread_mutex_lock (pProcArg->ppmServerStarted); if (iReturn != 0) { - ErrorF ("winMultiWindowXMsgProc - pthread_mutex_lock () failed: %d\n", + ErrorF ("winMultiWindowXMsgProc - pthread_mutex_lock () failed: %d. " + "Exiting.\n", iReturn); pthread_exit (NULL); } ErrorF ("winMultiWindowXMsgProc - pthread_mutex_lock () returned.\n"); - /* Only call XInitThreads once for the whole process */ - if (!g_fCalledXInitThreads) + /* Allow multiple threads to access Xlib */ + if (XInitThreads () == 0) { - /* Allow multiple threads to access Xlib */ - if (XInitThreads () == 0) - { - ErrorF ("winMultiWindowXMsgProc - XInitThreads () failed.\n"); - pthread_exit (NULL); - } - - /* Flag that XInitThreads has been called */ - g_fCalledXInitThreads = TRUE; + ErrorF ("winMultiWindowXMsgProc - XInitThreads () failed. Exiting.\n"); + pthread_exit (NULL); + } - ErrorF ("winMultiWindowXMsgProc - XInitThreads () returned.\n"); + /* See if X supports the current locale */ + if (XSupportsLocale () == False) + { + ErrorF ("winMultiWindowXMsgProc - Locale not supported by X. " + "Exiting.\n"); + pthread_exit (NULL); } /* Release the server started mutex */ @@ -781,6 +834,28 @@ winMultiWindowXMsgProc (void *pArg) ErrorF ("winMultiWindowXMsgProc - pthread_mutex_unlock () returned.\n"); + /* Set jump point for IO Error exits */ + iReturn = setjmp (g_jmpXMsgProcEntry); + + /* Check if we should continue operations */ + if (iReturn != WIN_JMP_ERROR_IO + && iReturn != WIN_JMP_OKAY) + { + /* setjmp returned an unknown value, exit */ + ErrorF ("winInitMultiWindowXMsgProc - setjmp returned: %d. Exiting.\n", + iReturn); + pthread_exit (NULL); + } + else if (iReturn == WIN_JMP_ERROR_IO) + { + ErrorF ("winInitMultiWindowXMsgProc - Caught IO Error. Exiting.\n"); + pthread_exit (NULL); + } + + /* Install our error handler */ + XSetErrorHandler (winMultiWindowXMsgProcErrorHandler); + XSetIOErrorHandler (winMultiWindowXMsgProcIOErrorHandler); + /* Setup the display connection string x */ snprintf (pszDisplay, 512, "127.0.0.1:%s.%d", display, (int)pProcArg->dwScreen); @@ -788,6 +863,7 @@ winMultiWindowXMsgProc (void *pArg) /* Print the display connection string */ ErrorF ("winMultiWindowXMsgProc - DISPLAY=%s\n", pszDisplay); + /* Initialize retry count */ iRetries = 0; /* Open the X display */ @@ -812,21 +888,28 @@ winMultiWindowXMsgProc (void *pArg) /* Make sure that the display opened */ if (pProcArg->pDisplay == NULL) { - ErrorF ("winMultiWindowXMsgProcwinInitMultiWindowWM - " - "Failed opening the display, giving up.\n\f"); + ErrorF ("winMultiWindowXMsgProc - Failed opening the display. " + "Exiting.\n"); pthread_exit (NULL); } ErrorF ("winMultiWindowXMsgProc - XOpenDisplay () returned and " "successfully opened the display.\n"); - - /* Install our error handler */ - XSetErrorHandler (winMultiWindowWMErrorHandler); - XSetIOErrorHandler (winMutliWindowWMIOErrorHandler); - XSelectInput (pProcArg->pDisplay, - RootWindow(pProcArg->pDisplay, pProcArg->dwScreen), - SubstructureNotifyMask); + /* Check if another window manager is already running */ + redirectError = FALSE; + XSetErrorHandler (winRedirectErrorHandler); + XSelectInput(pProcArg->pDisplay, + RootWindow (pProcArg->pDisplay, pProcArg->dwScreen), + SubstructureNotifyMask | ButtonPressMask); + XSync (pProcArg->pDisplay, 0); + XSetErrorHandler (winMultiWindowXMsgProcErrorHandler); + if (redirectError) + { + ErrorF ("winMultiWindowXMsgProc - " + "another window manager is running. Exiting.\n"); + pthread_exit (NULL); + } /* Set up the supported icon sizes */ xis = XAllocIconSize (); @@ -924,10 +1007,15 @@ winInitWM (void **ppWMInfo, /* Bail if the input parameters are bad */ if (pArg == NULL || pWMInfo == NULL) { - ErrorF ("winInitWM - malloc fail.\n"); + ErrorF ("winInitWM - malloc failed.\n"); return FALSE; } + /* Zero the allocated memory */ + ZeroMemory (pArg, sizeof (WMProcArgRec)); + ZeroMemory (pWMInfo, sizeof (WMInfoRec)); + ZeroMemory (pXMsgArg, sizeof (XMsgProcArgRec)); + /* Set a return pointer to the Window Manager info structure */ *ppWMInfo = pWMInfo; @@ -963,7 +1051,7 @@ winInitWM (void **ppWMInfo, } #if CYGDEBUG || YES - ErrorF ("winInitWM - Returning.\n"); + winDebug ("winInitWM - Returning.\n"); #endif return TRUE; @@ -971,26 +1059,22 @@ winInitWM (void **ppWMInfo, /* - * winInitMultiWindowWM - + * Window manager thread - setup */ -Bool -winClipboardDetectUnicodeSupport (); - static void winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) { int iRetries = 0; char pszDisplay[512]; int iReturn; - Bool fUnicodeSupport; ErrorF ("winInitMultiWindowWM - Hello\n"); /* Check that argument pointer is not invalid */ if (pProcArg == NULL) { - ErrorF ("winInitMultiWindowWM - pProcArg is NULL, bailing.\n"); + ErrorF ("winInitMultiWindowWM - pProcArg is NULL. Exiting.\n"); pthread_exit (NULL); } @@ -1000,52 +1084,26 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) iReturn = pthread_mutex_lock (pProcArg->ppmServerStarted); if (iReturn != 0) { - ErrorF ("winInitMultiWindowWM - pthread_mutex_lock () failed: %d\n", + ErrorF ("winInitMultiWindowWM - pthread_mutex_lock () failed: %d. " + "Exiting.\n", iReturn); pthread_exit (NULL); } ErrorF ("winInitMultiWindowWM - pthread_mutex_lock () returned.\n"); - /* Do we have Unicode support? */ - fUnicodeSupport = winClipboardDetectUnicodeSupport (); - - /* Set the current locale? What does this do? */ - if (fUnicodeSupport && !g_fCalledSetLocale) + /* Allow multiple threads to access Xlib */ + if (XInitThreads () == 0) { - ErrorF ("winInitMultiWindowWM - Calling setlocale ()\n"); - if (!setlocale (LC_ALL, "")) - { - ErrorF ("winInitMultiWindowWM - setlocale () error\n"); - pthread_exit (NULL); - } - ErrorF ("winInitMultiWindowWM - setlocale () returned\n"); - - /* See if X supports the current locale */ - if (XSupportsLocale () == False) - { - ErrorF ("winInitMultiWindowWM - Locale not supported by X\n"); - pthread_exit (NULL); - } + ErrorF ("winInitMultiWindowWM - XInitThreads () failed. Exiting.\n"); + pthread_exit (NULL); } - /* Flag that we have called setlocale */ - g_fCalledSetLocale = TRUE; - - /* Only call XInitThreads once for the whole process */ - if (!g_fCalledXInitThreads) + /* See if X supports the current locale */ + if (XSupportsLocale () == False) { - /* Allow multiple threads to access Xlib */ - if (XInitThreads () == 0) - { - ErrorF ("winInitMultiWindowWM - XInitThreads () failed.\n"); - pthread_exit (NULL); - } - - /* Flag that XInitThreads has been called */ - g_fCalledXInitThreads = TRUE; - - ErrorF ("winInitMultiWindowWM - XInitThreads () returned.\n"); + ErrorF ("winInitMultiWindowWM - Locale not supported by X. Exiting.\n"); + pthread_exit (NULL); } /* Release the server started mutex */ @@ -1054,28 +1112,27 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) ErrorF ("winInitMultiWindowWM - pthread_mutex_unlock () returned.\n"); /* Set jump point for IO Error exits */ - iReturn = setjmp (g_jmpEntry); + iReturn = setjmp (g_jmpWMEntry); /* Check if we should continue operations */ if (iReturn != WIN_JMP_ERROR_IO && iReturn != WIN_JMP_OKAY) { /* setjmp returned an unknown value, exit */ - ErrorF ("winInitMultiWindowWM - setjmp returned: %d exiting\n", + ErrorF ("winInitMultiWindowWM - setjmp returned: %d. Exiting.\n", iReturn); pthread_exit (NULL); } - else if (g_shutdown) - { - /* Shutting down, the X server severed out connection! */ - ErrorF ("winInitMultiWindowWM - Detected shutdown in progress\n"); - pthread_exit (NULL); - } else if (iReturn == WIN_JMP_ERROR_IO) { - ErrorF ("winInitMultiWindowWM - setjmp returned WIN_JMP_ERROR_IO\n"); + ErrorF ("winInitMultiWindowWM - Caught IO Error. Exiting.\n"); + pthread_exit (NULL); } + /* Install our error handler */ + XSetErrorHandler (winMultiWindowWMErrorHandler); + XSetIOErrorHandler (winMultiWindowWMIOErrorHandler); + /* Setup the display connection string x */ snprintf (pszDisplay, 512, @@ -1108,17 +1165,14 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) /* Make sure that the display opened */ if (pWMInfo->pDisplay == NULL) { - ErrorF ("winInitMultiWindowWM - Failed opening the display, " - "giving up.\n\f"); + ErrorF ("winInitMultiWindowWM - Failed opening the display. " + "Exiting.\n"); pthread_exit (NULL); } ErrorF ("winInitMultiWindowWM - XOpenDisplay () returned and " "successfully opened the display.\n"); - /* Install our error handler */ - XSetErrorHandler (winMultiWindowWMErrorHandler); - XSetIOErrorHandler (winMutliWindowWMIOErrorHandler); /* Create some atoms */ pWMInfo->atmWmProtos = XInternAtom (pWMInfo->pDisplay, @@ -1156,22 +1210,96 @@ winSendMessageToWM (void *pWMInfo, winWMMessagePtr pMsg) /* - * winMutliWindowWMIOErrorHandler - Our application specific IO error handler + * Window manager error handler + */ + +static int +winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr) +{ + char pszErrorMsg[100]; + + if (pErr->request_code == X_ChangeWindowAttributes + && pErr->error_code == BadAccess) + { + ErrorF ("winMultiWindowWMErrorHandler - ChangeWindowAttributes " + "BadAccess.\n"); + return 0; + } + + XGetErrorText (pDisplay, + pErr->error_code, + pszErrorMsg, + sizeof (pszErrorMsg)); + ErrorF ("winMultiWindowWMErrorHandler - ERROR: %s\n", pszErrorMsg); + + return 0; +} + + +/* + * Window manager IO error handler */ static int -winMutliWindowWMIOErrorHandler (Display *pDisplay) +winMultiWindowWMIOErrorHandler (Display *pDisplay) { - printf ("\nwinMutliWindowWMIOErrorHandler!\n\n"); + ErrorF ("\nwinMultiWindowWMIOErrorHandler!\n\n"); /* Restart at the main entry point */ - longjmp (g_jmpEntry, WIN_JMP_ERROR_IO); + longjmp (g_jmpWMEntry, WIN_JMP_ERROR_IO); return 0; } /* + * X message procedure error handler + */ + +static int +winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr) +{ + char pszErrorMsg[100]; + + XGetErrorText (pDisplay, + pErr->error_code, + pszErrorMsg, + sizeof (pszErrorMsg)); + ErrorF ("winMultiWindowXMsgProcErrorHandler - ERROR: %s\n", pszErrorMsg); + + return 0; +} + + +/* + * X message procedure IO error handler + */ + +static int +winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay) +{ + ErrorF ("\nwinMultiWindowXMsgProcIOErrorHandler!\n\n"); + + /* Restart at the main entry point */ + longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO); + + return 0; +} + + +/* + * Catch RedirectError to detect other window manager running + */ + +static int +winRedirectErrorHandler (Display *pDisplay, XErrorEvent *pErr) +{ + redirectError = TRUE; + return 0; +} + + +/* * Notify the MWM thread we're exiting and not to reconnect */ diff --git a/hw/xwin/winmultiwindowwndproc.c b/hw/xwin/winmultiwindowwndproc.c index 83f3b02f6..ff18f2e42 100755 --- a/hw/xwin/winmultiwindowwndproc.c +++ b/hw/xwin/winmultiwindowwndproc.c @@ -35,19 +35,17 @@ #include "dixevents.h" #include "winmultiwindowclass.h" #include "winprefs.h" +#if CYGDEBUG +#include "winmessages.h" +#endif /* * External global variables */ -extern Bool g_fCursor; - - -/* - * Global variables - */ - -HICON g_hiconX = NULL; +extern Bool g_fCursor; +extern Bool g_fKeyboardHookLL; +extern Bool g_fSoftwareCursor; /* @@ -65,7 +63,6 @@ static UINT_PTR g_uipMousePollingTimerID = 0; #define WIN_MULTIWINDOW_SHAPE YES - /* * ConstrainSize - Taken from TWM sources - Respects hints for sizing */ @@ -206,8 +203,7 @@ ValidateSizing (HWND hwnd, WindowPtr pWin, { WinXSizeHints sizeHints; RECT *rect; - int iWidth, iHeight, iTopBorder; - POINT pt; + int iWidth, iHeight; /* Invalid input checking */ if (pWin==NULL || lParam==0) @@ -229,21 +225,19 @@ ValidateSizing (HWND hwnd, WindowPtr pWin, iWidth = rect->right - rect->left; iHeight = rect->bottom - rect->top; - /* Get title bar height, there must be an easier way?! */ - pt.x = pt.y = 0; - ClientToScreen(hwnd, &pt); - iTopBorder = pt.y - rect->top; - /* Now remove size of any borders */ iWidth -= 2 * GetSystemMetrics(SM_CXSIZEFRAME); - iHeight -= GetSystemMetrics(SM_CYSIZEFRAME) + iTopBorder; + iHeight -= (GetSystemMetrics(SM_CYCAPTION) + + 2 * GetSystemMetrics(SM_CYSIZEFRAME)); + /* Constrain the size to legal values */ ConstrainSize (sizeHints, &iWidth, &iHeight); /* Add back the borders */ iWidth += 2 * GetSystemMetrics(SM_CXSIZEFRAME); - iHeight += GetSystemMetrics(SM_CYSIZEFRAME) + iTopBorder; + iHeight += (GetSystemMetrics(SM_CYCAPTION) + + 2 * GetSystemMetrics(SM_CYSIZEFRAME)); /* Adjust size according to where we're dragging from */ switch(wParam) { @@ -296,6 +290,19 @@ winTopLevelWindowProc (HWND hwnd, UINT message, winWMMessageRec wmMsg; Bool fWMMsgInitialized = FALSE; static Bool s_fTracking = FALSE; + +#if CYGDEBUG + if (message >= WM_USER) + { + winDebug("winTopLevelWindowProc - Message WM_USER + %d", message - WM_USER); + winDebug(" wParam 0x%x lParam 0x%x\n", wParam, lParam); + } + else if (message < MESSAGE_NAMES_LEN && MESSAGE_NAMES[message]) + { + winDebug("winTopLevelWindowProc - Message %s", MESSAGE_NAMES[message]); + winDebug(" wParam 0x%x lParam 0x%x\n", wParam, lParam); + } +#endif /* Check if the Windows window property for our X window pointer is valid */ if ((pWin = GetProp (hwnd, WIN_WINDOW_PROP)) != NULL) @@ -321,10 +328,10 @@ winTopLevelWindowProc (HWND hwnd, UINT message, wmMsg.hwndWindow = hwnd; wmMsg.iWindow = (Window)GetProp (hwnd, WIN_WID_PROP); - wmMsg.iX = pWinPriv->iX; - wmMsg.iY = pWinPriv->iY; - wmMsg.iWidth = pWinPriv->iWidth; - wmMsg.iHeight = pWinPriv->iHeight; + wmMsg.iX = pDraw->x; + wmMsg.iY = pDraw->y; + wmMsg.iWidth = pDraw->width; + wmMsg.iHeight = pDraw->height; fWMMsgInitialized = TRUE; @@ -373,9 +380,14 @@ winTopLevelWindowProc (HWND hwnd, UINT message, WIN_WID_PROP, (HANDLE)winGetWindowID (((LPCREATESTRUCT) lParam)->lpCreateParams)); + /* + * Make X windows' Z orders sync with Windows windows because + * there can be AlwaysOnTop windows overlapped on the window + * currently being created. + */ + winReorderWindowsMultiWindow (); return 0; - case WM_INIT_SYS_MENU: /* * Add whatever the setup file wants to for this window @@ -387,7 +399,33 @@ winTopLevelWindowProc (HWND hwnd, UINT message, /* * Any window menu items go through here */ - HandleCustomWM_COMMAND ((unsigned long)hwnd, LOWORD(wParam)); +#if CYGMULTIWINDOW_DEBUG + switch (wParam & 0xFFF0) /* See MSDN for the magic number 0xFFF0 */ + { + case SC_MINIMIZE: + ErrorF ("winTopLevelWindowProc - WM_SYSCOMMAND (SC_MINIMIZE)\n"); + break; + + case SC_RESTORE: + ErrorF ("winTopLevelWindowProc - WM_SYSCOMMAND (SC_RESTORE)\n"); + break; + + case SC_MAXIMIZE: + ErrorF ("winTopLevelWindowProc - WM_SYSCOMMAND (SC_MAXIMIZE)\n"); + break; + + default: + ErrorF ("winTopLevelWindowProc - WM_SYSCOMMAND (UNKNOWN)\n"); +#endif + if (HandleCustomWM_COMMAND ((unsigned long)hwnd, LOWORD(wParam))) + { + /* Don't pass customized menus to DefWindowProc */ + return 0; + } +#if CYGMULTIWINDOW_DEBUG + break; + } +#endif break; case WM_INITMENU: @@ -481,7 +519,7 @@ winTopLevelWindowProc (HWND hwnd, UINT message, } /* Hide or show the Windows mouse cursor */ - if (g_fCursor) + if (g_fSoftwareCursor && g_fCursor) { /* Hide Windows cursor */ g_fCursor = FALSE; @@ -516,7 +554,7 @@ winTopLevelWindowProc (HWND hwnd, UINT message, break; /* Non-client mouse movement, show Windows cursor */ - if (!g_fCursor) + if (g_fSoftwareCursor && !g_fCursor) { g_fCursor = TRUE; ShowCursor (TRUE); @@ -540,7 +578,7 @@ winTopLevelWindowProc (HWND hwnd, UINT message, s_fTracking = FALSE; /* Show the mouse cursor, if necessary */ - if (!g_fCursor) + if (g_fSoftwareCursor && !g_fCursor) { g_fCursor = TRUE; ShowCursor (TRUE); @@ -599,9 +637,23 @@ winTopLevelWindowProc (HWND hwnd, UINT message, SendMessage (hwndScreen, message, wParam, lParam); return 0; + case WM_SETFOCUS: + if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) + break; + + winRestoreModeKeyStates (); + + /* Add the keyboard hook if possible */ + if (g_fKeyboardHookLL) + g_fKeyboardHookLL = winInstallKeyboardHookLL (); + return 0; + case WM_KILLFOCUS: /* Pop any pressed keys since we are losing keyboard focus */ winKeybdReleaseKeys (); + + /* Remove our keyboard hook if it is installed */ + winRemoveKeyboardHookLL (); return 0; case WM_SYSDEADCHAR: @@ -635,6 +687,42 @@ winTopLevelWindowProc (HWND hwnd, UINT message, if (wParam == VK_F4 && (GetKeyState (VK_MENU) & 0x8000)) break; +#if CYGWINDOWING_DEBUG + if (wParam == VK_ESCAPE) + { + /* Place for debug: put any tests and dumps here */ + WINDOWPLACEMENT windPlace; + RECT rc; + LPRECT pRect; + + windPlace.length = sizeof (WINDOWPLACEMENT); + GetWindowPlacement (hwnd, &windPlace); + pRect = &windPlace.rcNormalPosition; + ErrorF ("\nCYGWINDOWING Dump:\n" + "\tdrawable: (%hd, %hd) - %hdx%hd\n", pDraw->x, + pDraw->y, pDraw->width, pDraw->height); + ErrorF ("\twindPlace: (%ld, %ld) - %ldx%ld\n", pRect->left, + pRect->top, pRect->right - pRect->left, + pRect->bottom - pRect->top); + if (GetClientRect (hwnd, &rc)) + { + pRect = &rc; + ErrorF ("\tClientRect: (%ld, %ld) - %ldx%ld\n", pRect->left, + pRect->top, pRect->right - pRect->left, + pRect->bottom - pRect->top); + } + if (GetWindowRect (hwnd, &rc)) + { + pRect = &rc; + ErrorF ("\tWindowRect: (%ld, %ld) - %ldx%ld\n", pRect->left, + pRect->top, pRect->right - pRect->left, + pRect->bottom - pRect->top); + } + ErrorF ("\n"); + return 0; + } +#endif + /* Pass the message to the root window */ SendMessage (hwndScreen, message, wParam, lParam); return 0; @@ -667,15 +755,18 @@ winTopLevelWindowProc (HWND hwnd, UINT message, /* Pass the message to the root window */ SendMessage (hwndScreen, message, wParam, lParam); - if (s_pScreenPriv != NULL) - s_pScreenPriv->fWindowOrderChanged = TRUE; - if (LOWORD(wParam) != WA_INACTIVE) { + /* Raise the window to the top in Z order */ + wmMsg.msg = WM_WM_RAISE; + if (fWMMsgInitialized) + winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); + /* Tell our Window Manager thread to activate the window */ wmMsg.msg = WM_WM_ACTIVATE; if (fWMMsgInitialized) - winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); + if (!pWin || !pWin->overrideRedirect) /* for OOo menus */ + winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); } return 0; @@ -683,10 +774,11 @@ winTopLevelWindowProc (HWND hwnd, UINT message, #if CYGMULTIWINDOW_DEBUG ErrorF ("winTopLevelWindowProc - WM_ACTIVATEAPP\n"); #endif - - /* Pass the message to the root window */ - SendMessage (hwndScreen, message, wParam, lParam); - return 0; + /* + * This message is also sent to the root window + * so we do nothing for individual multiwindow windows + */ + break; case WM_CLOSE: #if CYGMULTIWINDOW_DEBUG @@ -723,48 +815,23 @@ winTopLevelWindowProc (HWND hwnd, UINT message, winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); } + RemoveProp (hwnd, WIN_WINDOW_PROP); + RemoveProp (hwnd, WIN_WID_PROP); + RemoveProp (hwnd, WIN_NEEDMANAGE_PROP); + #if CYGMULTIWINDOW_DEBUG ErrorF ("winTopLevelWindowProc - WM_DESTROY\n"); #endif break; case WM_MOVE: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_MOVE - %d ms\n", GetTickCount ()); -#endif - - /* Bail if Windows window is not actually moving */ - if (pWinPriv->iX == (short) LOWORD(lParam) - && pWinPriv->iY == (short) HIWORD(lParam)) - break; - - /* Also bail if we're maximizing, we'll do the whole thing in WM_SIZE */ - { - WINDOWPLACEMENT windPlace; - windPlace.length = sizeof (WINDOWPLACEMENT); - - /* Get current window placement */ - GetWindowPlacement (hwnd, &windPlace); - - /* Bail if maximizing */ - if (windPlace.showCmd == SW_MAXIMIZE - || windPlace.showCmd == SW_SHOWMAXIMIZED) - break; - } - - /* Get new position */ - pWinPriv->iX = (short) LOWORD(lParam); - pWinPriv->iY = (short) HIWORD(lParam); - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\t(%d, %d)\n", pWinPriv->iX, pWinPriv->iY); +#if CYGWINDOWING_DEBUG + ErrorF ("winTopLevelWindowProc - WM_MOVE to (%d, %d) - %d ms\n", + (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), + (int)(GetTickCount ())); #endif - - winMoveXWindow (pWin, - (LOWORD(lParam) - wBorderWidth (pWin) - - GetSystemMetrics (SM_XVIRTUALSCREEN)), - (HIWORD(lParam) - wBorderWidth (pWin) - - GetSystemMetrics (SM_YVIRTUALSCREEN))); + /* Adjust the X Window to the moved Windows window */ + winAdjustXWindow (pWin, hwnd); return 0; case WM_SHOWWINDOW: @@ -772,6 +839,10 @@ winTopLevelWindowProc (HWND hwnd, UINT message, if (!wParam) return 0; +#if CYGWINDOWING_DEBUG + ErrorF ("winTopLevelWindowProc - WM_SHOWWINDOW\n"); +#endif + /* Tell X to map the window */ MapWindow (pWin, wClient(pWin)); @@ -795,10 +866,10 @@ winTopLevelWindowProc (HWND hwnd, UINT message, { /* Setup a rectangle with the X window position and size */ SetRect (&rcNew, - pWinPriv->iX, - pWinPriv->iY, - pWinPriv->iX + pWinPriv->iWidth, - pWinPriv->iY + pWinPriv->iHeight); + pDraw->x, + pDraw->y, + pDraw->x + pDraw->width, + pDraw->y + pDraw->height); #if 0 ErrorF ("winTopLevelWindowProc - (%d, %d)-(%d, %d)\n", @@ -813,8 +884,8 @@ winTopLevelWindowProc (HWND hwnd, UINT message, WS_EX_APPWINDOW); /* Calculate position deltas */ - iDx = pWinPriv->iX - rcNew.left; - iDy = pWinPriv->iY - rcNew.top; + iDx = pDraw->x - rcNew.left; + iDy = pDraw->y - rcNew.top; /* Calculate new rectangle */ rcNew.left += iDx; @@ -846,18 +917,24 @@ winTopLevelWindowProc (HWND hwnd, UINT message, SetForegroundWindow (hwnd); } } + else /* It is an overridden window so make it top of Z stack */ + { +#if CYGWINDOWING_DEBUG + ErrorF ("overridden window is shown\n"); +#endif + SetWindowPos (hwnd, HWND_TOPMOST, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE); + } /* Setup the Window Manager message */ wmMsg.msg = WM_WM_MAP; - wmMsg.iWidth = pWinPriv->iWidth; - wmMsg.iHeight = pWinPriv->iHeight; + wmMsg.iWidth = pDraw->width; + wmMsg.iHeight = pDraw->height; /* Tell our Window Manager thread to map the window */ if (fWMMsgInitialized) winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); - if (s_pScreenPriv != NULL) - s_pScreenPriv->fWindowOrderChanged = TRUE; return 0; case WM_SIZING: @@ -865,119 +942,78 @@ winTopLevelWindowProc (HWND hwnd, UINT message, /* for applications like xterm */ return ValidateSizing (hwnd, pWin, wParam, lParam); - case WM_WINDOWPOSCHANGED: - { - LPWINDOWPOS pwindPos = (LPWINDOWPOS) lParam; - - /* Bail if window z order was not changed */ - if (pwindPos->flags & SWP_NOZORDER) - break; - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - hwndInsertAfter: %p\n", - pwindPos->hwndInsertAfter); + case WM_WINDOWPOSCHANGING: + if (lParam != 0) + { + WINDOWPOS *windowpos = (WINDOWPOS *)lParam; + HWND hwndprev = GetNextWindow(hwnd, GW_HWNDPREV); + HWND hwndafter = windowpos->hwndInsertAfter; +#if CYGDEBUG + char buffer[1024]; + char buffer2[1024]; + GetWindowText(hwndafter, buffer, sizeof(buffer)); + GetWindowText(hwndprev, buffer2, sizeof(buffer2)); + winDebug("%s - hwndInsertAfter = %x (%s), hwndPrev = %x (%s)\n", + __FUNCTION__, hwndafter, + (hwndafter==HWND_TOP?"HWND_TOP": + (hwndafter==HWND_BOTTOM?"HWND_BOTTOM": + (hwndafter==HWND_NOTOPMOST?"HWND_NOTOPMOST": + (hwndafter==HWND_TOPMOST?"HWND_TOPMOST": + buffer)))), + hwndprev, + (hwndprev==HWND_TOP?"HWND_TOP": + (hwndprev==HWND_BOTTOM?"HWND_BOTTOM": + (hwndprev==HWND_NOTOPMOST?"HWND_NOTOPMOST": + (hwndprev==HWND_TOPMOST?"HWND_TOPMOST": + buffer2))))); + winDebug("%s - flags: %s\n", __FUNCTION__, + (windowpos->flags & SWP_NOZORDER?"NOZORDER":"")); + #endif - - /* Pass the message to the root window */ - SendMessage (hwndScreen, message, wParam, lParam); - - if (s_pScreenPriv != NULL) - s_pScreenPriv->fWindowOrderChanged = TRUE; - } - return 0; + if (windowpos->flags & SWP_NOZORDER) + break; + if (TRUE || hwndafter == HWND_TOP || hwndafter != hwndprev) + { + wmMsg.msg = WM_WM_RAISE; + //if (fWMMsgInitialized) + winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); + } + } + break; + case WM_WINDOWPOSCHANGED: + /* + * Pass the message to DefWindowProc to let the function + * break down WM_WINDOWPOSCHANGED to WM_MOVE and WM_SIZE. + */ + break; case WM_SIZE: /* see dix/window.c */ - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_SIZE - %d ms\n", GetTickCount ()); -#endif - - /* Branch on type of resizing occurring */ - switch (wParam) - { - case SIZE_MINIMIZED: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\tSIZE_MINIMIZED\n"); -#endif - if (s_pScreenPriv != NULL) - s_pScreenPriv->fWindowOrderChanged = TRUE; - break; - - case SIZE_RESTORED: - case SIZE_MAXIMIZED: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("SIZE_RESTORED || SIZE_MAXIMIZED\n"); -#endif - /* Break out if nothing to do */ - if (pWinPriv->iWidth == (short) LOWORD(lParam) - && pWinPriv->iHeight == (short) HIWORD(lParam)) +#if CYGWINDOWING_DEBUG + { + char buf[64]; + switch (wParam) + { + case SIZE_MINIMIZED: + strcpy(buf, "SIZE_MINIMIZED"); break; - - /* Get the dimensions of the resized Windows window */ - pWinPriv->iWidth = (short) LOWORD(lParam); - pWinPriv->iHeight = (short) HIWORD(lParam); - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\t(%d, %d)\n", pWinPriv->iWidth, pWinPriv->iHeight); + case SIZE_MAXIMIZED: + strcpy(buf, "SIZE_MAXIMIZED"); + break; + case SIZE_RESTORED: + strcpy(buf, "SIZE_RESTORED"); + break; + default: + strcpy(buf, "UNKNOWN_FLAG"); + } + ErrorF ("winTopLevelWindowProc - WM_SIZE to %dx%d (%s) - %d ms\n", + (int)LOWORD(lParam), (int)HIWORD(lParam), buf, + (int)(GetTickCount ())); + } #endif - - /* - * If we're maximizing the window has been moved to upper left - * of current screen. Now it is safe for X to know about this. - */ - if (wParam == SIZE_MAXIMIZED) - { - POINT ptHome; - - /* Flag that we are being maximized and store info for restore */ - pWinPriv->fNeedRestore = TRUE; - pWinPriv->ptRestore.x = pWinPriv->iX; - pWinPriv->ptRestore.y = pWinPriv->iY; - - /* Get screen location of window root */ - ptHome.x = 0; - ptHome.y = 0; - ClientToScreen (hwnd, &ptHome); - - /* Map from screen (-X,-Y) to (0,0) root coords */ - winMoveXWindow (pWin, - ptHome.x - wBorderWidth (pWin) - - GetSystemMetrics (SM_XVIRTUALSCREEN), - ptHome.y - wBorderWidth (pWin) - - GetSystemMetrics (SM_YVIRTUALSCREEN)); - } - else if (wParam == SIZE_RESTORED && pWinPriv->fNeedRestore) - { - /* If need restore and !maximized then move to cached position */ - WINDOWPLACEMENT windPlace; - - windPlace.length = sizeof (WINDOWPLACEMENT); - - GetWindowPlacement (hwnd, &windPlace); - - if (windPlace.showCmd != SW_MAXIMIZE - && windPlace.showCmd != SW_SHOWMAXIMIZED) - { - pWinPriv->fNeedRestore = FALSE; - winMoveXWindow (pWin, - pWinPriv->ptRestore.x - wBorderWidth (pWin) - - GetSystemMetrics (SM_XVIRTUALSCREEN), - pWinPriv->ptRestore.y - wBorderWidth (pWin) - - GetSystemMetrics (SM_YVIRTUALSCREEN)); - } - } - - /* Perform the resize and notify the X client */ - winResizeXWindow (pWin, - (short) LOWORD(lParam), - (short) HIWORD(lParam)); - break; - - default: - break; - } - return 0; + /* Adjust the X Window to the moved Windows window */ + winAdjustXWindow (pWin, hwnd); + return 0; /* end of WM_SIZE handler */ case WM_MOUSEACTIVATE: #if CYGMULTIWINDOW_DEBUG @@ -997,6 +1033,14 @@ winTopLevelWindowProc (HWND hwnd, UINT message, } break; + case WM_SETCURSOR: + if (LOWORD(lParam) == HTCLIENT) + { + if (!g_fSoftwareCursor) SetCursor (s_pScreenPriv->cursor.handle); + return TRUE; + } + break; + default: break; } diff --git a/hw/xwin/winnativegdi.c b/hw/xwin/winnativegdi.c index b2ac9f14e..dbee9d285 100644 --- a/hw/xwin/winnativegdi.c +++ b/hw/xwin/winnativegdi.c @@ -31,7 +31,65 @@ #include "win.h" -Bool + +/* + * External symbols + */ + +extern HWND g_hDlgExit; + + +/* + * Local function prototypes + */ + +static Bool +winAllocateFBNativeGDI (ScreenPtr pScreen); + +static void +winShadowUpdateNativeGDI (ScreenPtr pScreen, + shadowBufPtr pBuf); + +static Bool +winCloseScreenNativeGDI (int nIndex, ScreenPtr pScreen); + +static Bool +winInitVisualsNativeGDI (ScreenPtr pScreen); + +static Bool +winAdjustVideoModeNativeGDI (ScreenPtr pScreen); + +#if 0 +static Bool +winBltExposedRegionsNativeGDI (ScreenPtr pScreen); +#endif + +static Bool +winActivateAppNativeGDI (ScreenPtr pScreen); + +static Bool +winRedrawScreenNativeGDI (ScreenPtr pScreen); + +static Bool +winRealizeInstalledPaletteNativeGDI (ScreenPtr pScreen); + +static Bool +winInstallColormapNativeGDI (ColormapPtr pColormap); + +static Bool +winStoreColorsNativeGDI (ColormapPtr pmap, + int ndef, + xColorItem *pdefs); + +static Bool +winCreateColormapNativeGDI (ColormapPtr pColormap); + +static Bool +winDestroyColormapNativeGDI (ColormapPtr pColormap); + + + +static Bool winAllocateFBNativeGDI (ScreenPtr pScreen) { FatalError ("winAllocateFBNativeGDI\n"); @@ -39,11 +97,13 @@ winAllocateFBNativeGDI (ScreenPtr pScreen) return TRUE; } + /* * We wrap whatever CloseScreen procedure was specified by fb; * a pointer to said procedure is stored in our privates. */ -Bool + +static Bool winCloseScreenNativeGDI (int nIndex, ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -95,7 +155,7 @@ winCloseScreenNativeGDI (int nIndex, ScreenPtr pScreen) } -void +static void winShadowUpdateNativeGDI (ScreenPtr pScreen, shadowBufPtr pBuf) { @@ -104,7 +164,7 @@ winShadowUpdateNativeGDI (ScreenPtr pScreen, } -Bool +static Bool winInitVisualsNativeGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -149,7 +209,7 @@ winInitVisualsNativeGDI (ScreenPtr pScreen) /* Tell the user how many bits per RGB we are using */ ErrorF ("winInitVisualsNativeGDI - Using dwBitsPerRGB: %d\n", - pScreenPriv->dwBitsPerRGB); + (int) pScreenPriv->dwBitsPerRGB); /* Create a single visual according to the Windows screen depth */ switch (pScreenInfo->dwDepth) @@ -199,7 +259,7 @@ winInitVisualsNativeGDI (ScreenPtr pScreen) /* Adjust the video mode */ -Bool +static Bool winAdjustVideoModeNativeGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -239,7 +299,8 @@ winAdjustVideoModeNativeGDI (ScreenPtr pScreen) { /* No -depth parameter passed, let the user know the depth being used */ ErrorF ("winAdjustVideoModeNativeGDI - Using Windows display " - "depth of %d bits per pixel, %d depth\n", dwBPP, pScreenInfo->dwDepth); + "depth of %d bits per pixel, %d depth\n", + (int) dwBPP, (int) pScreenInfo->dwDepth); /* Use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -248,7 +309,8 @@ winAdjustVideoModeNativeGDI (ScreenPtr pScreen) { /* Warn user if GDI depth is different than -depth parameter */ ErrorF ("winAdjustVideoModeNativeGDI - Command line bpp: %d, "\ - "using bpp: %d\n", pScreenInfo->dwBPP, dwBPP); + "using bpp: %d\n", + (int) pScreenInfo->dwBPP, (int) dwBPP); /* We'll use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -261,7 +323,7 @@ winAdjustVideoModeNativeGDI (ScreenPtr pScreen) } -Bool +static Bool winActivateAppNativeGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -380,15 +442,17 @@ winCreateDIBNativeGDI (int iWidth, int iHeight, int iDepth, } -Bool +#if 0 +static Bool winBltExposedRegionsNativeGDI (ScreenPtr pScreen) { return TRUE; } +#endif -Bool +static Bool winRedrawScreenNativeGDI (ScreenPtr pScreen) { FatalError ("winRedrawScreenNativeGDI\n"); @@ -396,7 +460,7 @@ winRedrawScreenNativeGDI (ScreenPtr pScreen) } -Bool +static Bool winRealizeInstalledPaletteNativeGDI (ScreenPtr pScreen) { FatalError ("winRealizeInstalledPaletteNativeGDI\n"); @@ -404,7 +468,7 @@ winRealizeInstalledPaletteNativeGDI (ScreenPtr pScreen) } -Bool +static Bool winInstallColormapNativeGDI (ColormapPtr pColormap) { FatalError ("winInstallColormapNativeGDI\n"); @@ -412,7 +476,7 @@ winInstallColormapNativeGDI (ColormapPtr pColormap) } -Bool +static Bool winStoreColorsNativeGDI (ColormapPtr pmap, int ndef, xColorItem *pdefs) @@ -422,7 +486,7 @@ winStoreColorsNativeGDI (ColormapPtr pmap, } -Bool +static Bool winCreateColormapNativeGDI (ColormapPtr pColormap) { FatalError ("winCreateColormapNativeGDI\n"); @@ -430,7 +494,7 @@ winCreateColormapNativeGDI (ColormapPtr pColormap) } -Bool +static Bool winDestroyColormapNativeGDI (ColormapPtr pColormap) { FatalError ("winDestroyColormapNativeGDI\n"); @@ -474,7 +538,7 @@ winSetEngineFunctionsNativeGDI (ScreenPtr pScreen) pScreenPriv->pwinStoreColors = winStoreColorsNativeGDI; pScreenPriv->pwinCreateColormap = winCreateColormapNativeGDI; pScreenPriv->pwinDestroyColormap = winDestroyColormapNativeGDI; - pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)())NoopDDA; + pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA; return TRUE; } diff --git a/hw/xwin/winpfbdd.c b/hw/xwin/winpfbdd.c index 33cb42eb1..959fef991 100644 --- a/hw/xwin/winpfbdd.c +++ b/hw/xwin/winpfbdd.c @@ -36,17 +36,41 @@ /* - * External global variables + * External symbols */ -extern const GUID _IID_IDirectDraw2; +extern const GUID _IID_IDirectDraw2; +extern HWND g_hDlgExit; + + +/* + * Local function prototypes + */ + +static Bool +winAllocateFBPrimaryDD (ScreenPtr pScreen); + +static Bool +winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen); + +static Bool +winInitVisualsPrimaryDD (ScreenPtr pScreen); + +static Bool +winAdjustVideoModePrimaryDD (ScreenPtr pScreen); + +static Bool +winActivateAppPrimaryDD (ScreenPtr pScreen); + +static Bool +winHotKeyAltTabPrimaryDD (ScreenPtr pScreen); /* * Create a DirectDraw primary surface */ -Bool +static Bool winAllocateFBPrimaryDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -77,7 +101,7 @@ winAllocateFBPrimaryDD (ScreenPtr pScreen) if (FAILED (ddrval)) { ErrorF ("winAllocateFBShadowDD - Failed DD2 query: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } @@ -131,7 +155,7 @@ winAllocateFBPrimaryDD (ScreenPtr pScreen) NULL); if (FAILED (ddrval)) FatalError ("winAllocateFBPrimaryDD - Could not create primary " - "surface %08x\n", ddrval); + "surface %08x\n", (unsigned int) ddrval); ErrorF ("winAllocateFBPrimaryDD - Created primary\n"); @@ -222,7 +246,7 @@ winAllocateFBPrimaryDD (ScreenPtr pScreen) * Free our resources and private structures. */ -Bool +static Bool winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -305,7 +329,7 @@ winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen) * to verify that last sentence. */ -Bool +static Bool winInitVisualsPrimaryDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -326,10 +350,10 @@ winInitVisualsPrimaryDD (ScreenPtr pScreen) pScreenPriv->dwBitsPerRGB = dwBlueBits; ErrorF ("winInitVisualsPrimaryDD - Masks: %08x %08x %08x bpRGB: %d\n", - pScreenPriv->dwRedMask, - pScreenPriv->dwGreenMask, - pScreenPriv->dwBlueMask, - pScreenPriv->dwBitsPerRGB); + (unsigned int) pScreenPriv->dwRedMask, + (unsigned int) pScreenPriv->dwGreenMask, + (unsigned int) pScreenPriv->dwBlueMask, + (int) pScreenPriv->dwBitsPerRGB); /* Create a single visual according to the Windows screen depth */ switch (pScreenInfo->dwDepth) @@ -353,7 +377,7 @@ winInitVisualsPrimaryDD (ScreenPtr pScreen) case 8: #if CYGDEBUG - ErrorF ("winInitVisuals - Calling miSetVisualTypesAndMasks\n"); + winDebug ("winInitVisuals - Calling miSetVisualTypesAndMasks\n"); #endif /* CYGDEBUG */ if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth, PseudoColorMask, @@ -368,7 +392,7 @@ winInitVisualsPrimaryDD (ScreenPtr pScreen) return FALSE; } #if CYGDEBUG - ErrorF ("winInitVisualsPrimaryDD - Returned from " + winDebug ("winInitVisualsPrimaryDD - Returned from " "miSetVisualTypesAndMasks\n"); #endif /* CYGDEBUG */ break; @@ -384,7 +408,7 @@ winInitVisualsPrimaryDD (ScreenPtr pScreen) } -Bool +static Bool winAdjustVideoModePrimaryDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -408,7 +432,7 @@ winAdjustVideoModePrimaryDD (ScreenPtr pScreen) { /* No -depth parameter passed, let the user know the depth being used */ ErrorF ("winAdjustVideoModePrimaryDD - Using Windows display " - "depth of %d bits per pixel\n", dwBPP); + "depth of %d bits per pixel\n", (int) dwBPP); /* Use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -418,14 +442,14 @@ winAdjustVideoModePrimaryDD (ScreenPtr pScreen) { /* FullScreen, and GDI depth differs from -depth parameter */ ErrorF ("winAdjustVideoModePrimaryDD - FullScreen, using command " - "line depth: %d\n", pScreenInfo->dwBPP); + "line depth: %d\n", (int) pScreenInfo->dwBPP); } else if (dwBPP != pScreenInfo->dwBPP) { /* Windowed, and GDI depth differs from -depth parameter */ ErrorF ("winAdjustVideoModePrimaryDD - Windowed, command line " "depth: %d, using depth: %d\n", - pScreenInfo->dwBPP, dwBPP); + (int) pScreenInfo->dwBPP, (int) dwBPP); /* We'll use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -444,7 +468,7 @@ winAdjustVideoModePrimaryDD (ScreenPtr pScreen) * the fb code back to the primary surface memory. */ -Bool +static Bool winActivateAppPrimaryDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -498,7 +522,7 @@ winActivateAppPrimaryDD (ScreenPtr pScreen) NULL); if (ddrval != DD_OK) FatalError ("winActivateAppPrimaryDD () - Failed blitting offscreen " - "surface to primary surface %08x\n", ddrval); + "surface to primary surface %08x\n", (unsigned int) ddrval); /* Lock the primary surface */ ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsPrimary, @@ -533,7 +557,7 @@ winActivateAppPrimaryDD (ScreenPtr pScreen) * fb for the duration of the deactivation. */ -Bool +static Bool winHotKeyAltTabPrimaryDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -596,12 +620,12 @@ winHotKeyAltTabPrimaryDD (ScreenPtr pScreen) if (FAILED (ddrval)) FatalError ("winHotKeyAltTabPrimaryDD - Failed blitting primary " "surface to offscreen surface: %08x\n", - ddrval); + (unsigned int) ddrval); } else { FatalError ("winHotKeyAltTabPrimaryDD - Unknown error from " - "Blt: %08dx\n", ddrval); + "Blt: %08dx\n", (unsigned int) ddrval); } /* Lock the offscreen surface */ @@ -636,7 +660,7 @@ winSetEngineFunctionsPrimaryDD (ScreenPtr pScreen) /* Set our pointers */ pScreenPriv->pwinAllocateFB = winAllocateFBPrimaryDD; pScreenPriv->pwinShadowUpdate - = (winShadowUpdateProcPtr) (void (*)())NoopDDA; + = (winShadowUpdateProcPtr) (void (*)(void))NoopDDA; pScreenPriv->pwinCloseScreen = winCloseScreenPrimaryDD; pScreenPriv->pwinInitVisuals = winInitVisualsPrimaryDD; pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModePrimaryDD; @@ -646,9 +670,13 @@ winSetEngineFunctionsPrimaryDD (ScreenPtr pScreen) pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed; pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB; pScreenPriv->pwinBltExposedRegions - = (winBltExposedRegionsProcPtr) (void (*)())NoopDDA; + = (winBltExposedRegionsProcPtr) (void (*)(void))NoopDDA; pScreenPriv->pwinActivateApp = winActivateAppPrimaryDD; pScreenPriv->pwinHotKeyAltTab = winHotKeyAltTabPrimaryDD; +#ifdef XWIN_MULTIWINDOW + pScreenPriv->pwinFinishCreateWindowsWindow = + (winFinishCreateWindowsWindowProcPtr) (void (*)(void))NoopDDA; +#endif return TRUE; } diff --git a/hw/xwin/winpixmap.c b/hw/xwin/winpixmap.c index 24e49719a..e1fa34f0c 100644 --- a/hw/xwin/winpixmap.c +++ b/hw/xwin/winpixmap.c @@ -32,6 +32,31 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iPixmapPrivateIndex; + + +/* + * Local prototypes + */ + +#if 0 +static void +winXRotatePixmapNativeGDI (PixmapPtr pPix, int rw); + +static void +winYRotatePixmapNativeGDI (PixmapPtr pPix, int rh); + +static void +winCopyRotatePixmapNativeGDI (PixmapPtr psrcPix, PixmapPtr *ppdstPix, + int xrot, int yrot); +#endif + + /* See Porting Layer Definition - p. 34 */ /* See mfb/mfbpixmap.c - mfbCreatePixmap() */ PixmapPtr @@ -51,7 +76,7 @@ winCreatePixmapNativeGDI (ScreenPtr pScreen, } #if CYGDEBUG - ErrorF ("winCreatePixmap () - w %d h %d d %d bw %d\n", + winDebug ("winCreatePixmap () - w %d h %d d %d bw %d\n", iWidth, iHeight, iDepth, PixmapBytePad (iWidth, iDepth)); #endif @@ -94,7 +119,7 @@ winCreatePixmapNativeGDI (ScreenPtr pScreen, (BITMAPINFO **) &pPixmapPriv->pbmih); #if CYGDEBUG - ErrorF ("winCreatePixmap () - Created a pixmap %08x, %dx%dx%d, for " \ + winDebug ("winCreatePixmap () - Created a pixmap %08x, %dx%dx%d, for " \ "screen: %08x\n", pPixmapPriv->hBitmap, iWidth, iHeight, iDepth, pScreen); #endif @@ -115,7 +140,7 @@ winDestroyPixmapNativeGDI (PixmapPtr pPixmap) winPrivPixmapPtr pPixmapPriv = NULL; #if CYGDEBUG - ErrorF ("winDestroyPixmapNativeGDI ()\n"); + winDebug ("winDestroyPixmapNativeGDI ()\n"); #endif /* Bail early if there is not a pixmap to destroy */ @@ -129,7 +154,7 @@ winDestroyPixmapNativeGDI (PixmapPtr pPixmap) pPixmapPriv = winGetPixmapPriv (pPixmap); #if CYGDEBUG - ErrorF ("winDestroyPixmapNativeGDI - pPixmapPriv->hBitmap: %08x\n", + winDebug ("winDestroyPixmapNativeGDI - pPixmapPriv->hBitmap: %08x\n", pPixmapPriv->hBitmap); #endif @@ -173,12 +198,13 @@ winModifyPixmapHeaderNativeGDI (PixmapPtr pPixmap, } +#if 0 /* * Not used yet. * See cfb/cfbpixmap.c */ -void +static void winXRotatePixmapNativeGDI (PixmapPtr pPix, int rw) { ErrorF ("winXRotatePixmap()\n"); @@ -190,7 +216,7 @@ winXRotatePixmapNativeGDI (PixmapPtr pPix, int rw) * Not used yet. * See cfb/cfbpixmap.c */ -void +static void winYRotatePixmapNativeGDI (PixmapPtr pPix, int rh) { ErrorF ("winYRotatePixmap()\n"); @@ -203,10 +229,11 @@ winYRotatePixmapNativeGDI (PixmapPtr pPix, int rh) * See cfb/cfbpixmap.c */ -void +static void winCopyRotatePixmapNativeGDI (PixmapPtr psrcPix, PixmapPtr *ppdstPix, int xrot, int yrot) { ErrorF ("winCopyRotatePixmap()\n"); /* fill in this function, look at CFB */ } +#endif diff --git a/hw/xwin/winpntwin.c b/hw/xwin/winpntwin.c index 46d738209..034ac9362 100644 --- a/hw/xwin/winpntwin.c +++ b/hw/xwin/winpntwin.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,19 +15,18 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winpntwin.c,v 1.1 2001/04/05 20:13:50 dawes Exp $ */ #include "win.h" diff --git a/hw/xwin/winpolyline.c b/hw/xwin/winpolyline.c index baafd8c39..c94ba06c5 100644 --- a/hw/xwin/winpolyline.c +++ b/hw/xwin/winpolyline.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,19 +15,18 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winpolyline.c,v 1.3 2001/09/13 08:25:45 alanh Exp $ */ #include "win.h" diff --git a/hw/xwin/winprefs.c b/hw/xwin/winprefs.c index b0a5d49ee..ea36dd9b8 100644 --- a/hw/xwin/winprefs.c +++ b/hw/xwin/winprefs.c @@ -37,6 +37,7 @@ /* Fixups to prevent collisions between Windows and X headers */ #define ATOM DWORD #include <windows.h> +#include <shellapi.h> #include "winprefs.h" #include "winmultiwindowclass.h" @@ -44,14 +45,20 @@ /* Where will the custom menu commands start counting from? */ #define STARTMENUID WM_USER +/* External global variables */ +#ifdef XWIN_MULTIWINDOW +extern DWORD g_dwCurrentThreadID; +#endif + /* From winmultiwindowflex.l, the real parser */ extern void parse_file (FILE *fp); -/* From winmultiwindowyacc.y, the pref structure loaded by the parser */ -extern WINMULTIWINDOWPREFS pref; +/* From winprefyacc.y, the pref structure loaded by the parser */ +extern WINPREFS pref; /* The global X default icon */ -extern HICON g_hiconX; +extern HICON g_hIconX; +extern HICON g_hSmallIconX; /* Currently in use command ID, incremented each new menu item created */ static int g_cmdid = STARTMENUID; @@ -60,6 +67,11 @@ static int g_cmdid = STARTMENUID; /* Defined in DIX */ extern char *display; +/* Local function to handle comma-ified icon names */ +static HICON +LoadImageComma (char *fname, int sx, int sy, int flags); + + /* * Creates or appends a menu from a MENUPARSED structure */ @@ -71,7 +83,7 @@ MakeMenu (char *name, int i; int item; MENUPARSED *m; - HMENU hmenu; + HMENU hmenu, hsub; for (i=0; i<pref.menuItems; i++) { @@ -96,6 +108,11 @@ MakeMenu (char *name, else { hmenu = CreatePopupMenu(); + if (!hmenu) + { + ErrorF("MakeMenu: Unable to CreatePopupMenu() %s\n", name); + return NULL; + } item = 0; } @@ -128,11 +145,13 @@ MakeMenu (char *name, case CMD_MENU: /* Recursive! */ - InsertMenu (hmenu, - item, - MF_BYPOSITION|MF_POPUP|MF_ENABLED|MF_STRING, - (UINT_PTR)MakeMenu (m->menuItem[i].param, 0, 0), - m->menuItem[i].text); + hsub = MakeMenu (m->menuItem[i].param, 0, 0); + if (hsub) + InsertMenu (hmenu, + item, + MF_BYPOSITION|MF_POPUP|MF_ENABLED|MF_STRING, + (UINT_PTR)hsub, + m->menuItem[i].text); break; } @@ -145,6 +164,7 @@ MakeMenu (char *name, } +#ifdef XWIN_MULTIWINDOW /* * Callback routine that is executed once per window class. * Removes or creates custom window settings depending on LPARAM @@ -152,16 +172,14 @@ MakeMenu (char *name, static BOOL CALLBACK ReloadEnumWindowsProc (HWND hwnd, LPARAM lParam) { - char szClassName[1024]; HICON hicon; + Window wid; - if (!GetClassName (hwnd, szClassName, 1024)) - return TRUE; + if (!hwnd) { + ErrorF("ReloadEnumWindowsProc: hwnd==NULL!\n"); + return FALSE; + } - if (strncmp (szClassName, WINDOW_CLASS_X, strlen (WINDOW_CLASS_X))) - /* Not one of our windows... */ - return TRUE; - /* It's our baby, either clean or dirty it */ if (lParam==FALSE) { @@ -171,8 +189,15 @@ ReloadEnumWindowsProc (HWND hwnd, LPARAM lParam) SetClassLong (hwnd, GCL_HICON, (LONG)LoadIcon (NULL, IDI_APPLICATION)); /* If it's generated on-the-fly, get rid of it, will regen */ - if (!winIconIsOverride((unsigned long)hicon) && hicon!=g_hiconX) - DestroyIcon (hicon); + winDestroyIcon (hicon); + + hicon = (HICON)GetClassLong(hwnd, GCL_HICONSM); + + /* Unselect any icon in the class structure */ + SetClassLong (hwnd, GCL_HICONSM, 0); + + /* If it's generated on-the-fly, get rid of it, will regen */ + winDestroyIcon (hicon); /* Remove any menu additions, use bRevert flag */ GetSystemMenu (hwnd, TRUE); @@ -181,9 +206,12 @@ ReloadEnumWindowsProc (HWND hwnd, LPARAM lParam) } else { - /* Make the icon default, dynamic, of from xwinrc */ - SetClassLong (hwnd, GCL_HICON, (LONG)g_hiconX); - winUpdateIcon ((Window)GetProp (hwnd, WIN_WID_PROP)); + /* Make the icon default, dynamic, or from xwinrc */ + SetClassLong (hwnd, GCL_HICON, (LONG)g_hIconX); + SetClassLong (hwnd, GCL_HICONSM, (LONG)g_hSmallIconX); + wid = (Window)GetProp (hwnd, WIN_WID_PROP); + if (wid) + winUpdateIcon (wid); /* Update the system menu for this window */ SetupSysMenu ((unsigned long)hwnd); @@ -192,6 +220,7 @@ ReloadEnumWindowsProc (HWND hwnd, LPARAM lParam) return TRUE; } +#endif /* @@ -201,13 +230,15 @@ ReloadEnumWindowsProc (HWND hwnd, LPARAM lParam) * Set custom icons and menus again. */ static void -ReloadPrefs () +ReloadPrefs (void) { int i; +#ifdef XWIN_MULTIWINDOW /* First, iterate over all windows replacing their icon with system */ /* default one and deleting any custom system menus */ - EnumWindows (ReloadEnumWindowsProc, FALSE); + EnumThreadWindows (g_dwCurrentThreadID, ReloadEnumWindowsProc, FALSE); +#endif /* Now, free/clear all info from our prefs structure */ for (i=0; i<pref.menuItems; i++) @@ -226,6 +257,7 @@ ReloadPrefs () pref.iconDirectory[0] = 0; pref.defaultIconName[0] = 0; + pref.trayIconName[0] = 0; for (i=0; i<pref.iconItems; i++) if (pref.icon[i].hicon) @@ -235,7 +267,10 @@ ReloadPrefs () pref.iconItems = 0; /* Free global default X icon */ - DestroyIcon (g_hiconX); + if (g_hIconX) + DestroyIcon (g_hIconX); + if (g_hSmallIconX) + DestroyIcon (g_hSmallIconX); /* Reset the custom command IDs */ g_cmdid = STARTMENUID; @@ -243,13 +278,15 @@ ReloadPrefs () /* Load the updated resource file */ LoadPreferences(); - /* Define global icon, load it */ - g_hiconX = (HICON)winOverrideDefaultIcon(); - if (!g_hiconX) - g_hiconX = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN)); + g_hIconX = NULL; + g_hSmallIconX = NULL; + + winInitGlobalIcons(); +#ifdef XWIN_MULTIWINDOW /* Rebuild the icons and menus */ - EnumWindows (ReloadEnumWindowsProc, TRUE); + EnumThreadWindows (g_dwCurrentThreadID, ReloadEnumWindowsProc, TRUE); +#endif /* Whew, done */ } @@ -284,9 +321,10 @@ HandleCustomWM_INITMENU(unsigned long hwndIn, } /* - * Searches for the custom WM_COMMAND command ID and performs action + * Searches for the custom WM_COMMAND command ID and performs action. + * Return TRUE if command is proccessed, FALSE otherwise. */ -int +Bool HandleCustomWM_COMMAND (unsigned long hwndIn, int command) { @@ -298,7 +336,7 @@ HandleCustomWM_COMMAND (unsigned long hwndIn, hwnd = (HWND)hwndIn; if (!command) - return 0; + return FALSE; for (i=0; i<pref.menuItems; i++) { @@ -332,12 +370,12 @@ HandleCustomWM_COMMAND (unsigned long hwndIn, exit (0); } else - return 0; + return TRUE; break; case CMD_ALWAYSONTOP: if (!hwnd) - return 0; + return FALSE; /* Get extended window style */ dwExStyle = GetWindowLong (hwnd, GWL_EXSTYLE); @@ -355,23 +393,28 @@ HandleCustomWM_COMMAND (unsigned long hwndIn, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); - return 0; +#if XWIN_MULTIWINDOW + /* Reflect the changed Z order */ + winReorderWindowsMultiWindow (); +#endif + return TRUE; case CMD_RELOAD: ReloadPrefs(); - return 0; + return TRUE; default: - return 0; + return FALSE; } } /* match */ } /* for j */ } /* for i */ - return 0; + return FALSE; } +#ifdef XWIN_MULTIWINDOW /* * Add the default or a custom menu depending on the class match */ @@ -428,6 +471,7 @@ SetupSysMenu (unsigned long hwndIn) MakeMenu (pref.defaultSysMenuName, sys, -1); } } +#endif /* @@ -453,28 +497,16 @@ SetupRootMenu (unsigned long hmenuRoot) * Check for and return an overridden default ICON specified in the prefs */ unsigned long -winOverrideDefaultIcon() +winOverrideDefaultIcon(int size) { HICON hicon; - char fname[PATH_MAX+NAME_MAX+2]; if (pref.defaultIconName[0]) { - /* Make sure we have a dir with trailing backslash */ - /* Note we are using _Windows_ paths here, not cygwin */ - strcpy (fname, pref.iconDirectory); - if (pref.iconDirectory[0]) - if (fname[strlen(fname)-1]!='\\') - strcat (fname, "\\"); - strcat (fname, pref.defaultIconName); - - hicon = (HICON)LoadImage(NULL, - fname, - IMAGE_ICON, - 0, 0, - LR_DEFAULTSIZE|LR_LOADFROMFILE); + hicon = LoadImageComma (pref.defaultIconName, size, size, 0); if (hicon==NULL) - ErrorF ("winOverrideDefaultIcon: LoadIcon(%s) failed\n", fname); + ErrorF ("winOverrideDefaultIcon: LoadImageComma(%s) failed\n", + pref.defaultIconName); return (unsigned long)hicon; } @@ -484,6 +516,104 @@ winOverrideDefaultIcon() /* + * Return the HICON to use in the taskbar notification area + */ +unsigned long +winTaskbarIcon(void) +{ + HICON hicon; + + hicon = 0; + /* First try and load an overridden, if success then return it */ + if (pref.trayIconName[0]) + { + hicon = LoadImageComma (pref.trayIconName, + GetSystemMetrics (SM_CXSMICON), + GetSystemMetrics (SM_CYSMICON), + 0 ); + } + + /* Otherwise return the default */ + if (!hicon) + hicon = (HICON) LoadImage (g_hInstance, + MAKEINTRESOURCE(IDI_XWIN), + IMAGE_ICON, + GetSystemMetrics (SM_CXSMICON), + GetSystemMetrics (SM_CYSMICON), + 0); + + return (unsigned long)hicon; +} + + +/* + * Parse a filename to extract an icon: + * If fname is exactly ",nnn" then extract icon from our resource + * else if it is "file,nnn" then extract icon nnn from that file + * else try to load it as an .ico file and if that fails return NULL + */ +static HICON +LoadImageComma (char *fname, int sx, int sy, int flags) +{ + HICON hicon; + int index; + char file[PATH_MAX+NAME_MAX+2]; + + /* Some input error checking */ + if (!fname || !fname[0]) + return NULL; + + index = 0; + hicon = NULL; + + if (fname[0]==',') + { + /* It's the XWIN.EXE resource they want */ + index = atoi (fname+1); + hicon = LoadImage (g_hInstance, + MAKEINTRESOURCE(index), + IMAGE_ICON, + sx, + sy, + flags); + } + else + { + file[0] = 0; + /* Prepend path if not given a "X:\" filename */ + if ( !(fname[0] && fname[1]==':' && fname[2]=='\\') ) + { + strcpy (file, pref.iconDirectory); + if (pref.iconDirectory[0]) + if (fname[strlen(fname)-1]!='\\') + strcat (file, "\\"); + } + strcat (file, fname); + + if (strrchr (file, ',')) + { + /* Specified as <fname>,<index> */ + + *(strrchr (file, ',')) = 0; /* End string at comma */ + index = atoi (strrchr (fname, ',') + 1); + hicon = ExtractIcon (g_hInstance, file, index); + } + else + { + /* Just an .ico file... */ + + hicon = (HICON)LoadImage (NULL, + file, + IMAGE_ICON, + sx, + sy, + LR_LOADFROMFILE|flags); + } + } + return hicon; +} + +/* * Check for a match of the window class to one specified in the * ICONS{} section in the prefs file, and load the icon from a file */ @@ -494,7 +624,6 @@ winOverrideIcon (unsigned long longWin) char *res_name, *res_class; int i; HICON hicon; - char fname[PATH_MAX+NAME_MAX+2]; char *wmName; if (pWin==NULL) @@ -519,21 +648,10 @@ winOverrideIcon (unsigned long longWin) if (pref.icon[i].hicon) return pref.icon[i].hicon; - /* Make sure we have a dir with trailing backslash */ - /* Note we are using _Windows_ paths here, not cygwin */ - strcpy (fname, pref.iconDirectory); - if (pref.iconDirectory[0]) - if (fname[strlen(fname)-1]!='\\') - strcat (fname, "\\"); - strcat (fname, pref.icon[i].iconFile); - - hicon = (HICON)LoadImage(NULL, - fname, - IMAGE_ICON, - 0, 0, - LR_DEFAULTSIZE|LR_LOADFROMFILE); - if (hicon==NULL) - ErrorF ("winOverrideIcon: LoadIcon(%s) failed\n", fname); + hicon = LoadImageComma (pref.icon[i].iconFile, 0, 0, LR_DEFAULTSIZE); + if (hicon==NULL) + ErrorF ("winOverrideIcon: LoadImageComma(%s) failed\n", + pref.icon[i].iconFile); pref.icon[i].hicon = (unsigned long)hicon; return (unsigned long)hicon; @@ -604,11 +722,18 @@ LoadPreferences () strcat (fname, ".XWinrc"); prefFile = fopen (fname, "r"); + if (prefFile) + ErrorF ("winPrefsLoadPreferences: %s\n", fname); } /* No home file found, check system default */ if (!prefFile) - prefFile = fopen (PROJECTROOT"/lib/X11/system.XWinrc", "r"); + { + prefFile = fopen (PROJECTROOT"/lib/X11/system.XWinrc", "r"); + if (prefFile) + ErrorF ("winPrefsLoadPreferences: %s\n", + PROJECTROOT"/lib/X11/system.XWinrc"); + } /* If we could open it, then read the settings and close it */ if (prefFile) @@ -658,4 +783,3 @@ LoadPreferences () } /* for all menus */ } - diff --git a/hw/xwin/winprefs.h b/hw/xwin/winprefs.h index 4ae01c081..eb8867907 100644 --- a/hw/xwin/winprefs.h +++ b/hw/xwin/winprefs.h @@ -1,3 +1,5 @@ +#if !defined(WINPREFS_H) +#define WINPREFS_H /* * Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. * @@ -29,6 +31,11 @@ */ /* $XFree86: $ */ +/* Need Bool */ +#include "Xdefs.h" +/* Need TURE */ +#include "misc.h" + /* Need to know how long paths can be... */ #include <limits.h> @@ -36,7 +43,7 @@ #define NAME_MAX PATH_MAX #endif #define MENU_MAX 128 /* Maximum string length of a menu name or item */ -#define PARAM_MAX (4*PATH_MAX) /* Maximim length of a parameter to a MENU */ +#define PARAM_MAX (4*PATH_MAX) /* Maximum length of a parameter to a MENU */ /* Supported commands in a MENU {} statement */ @@ -89,7 +96,7 @@ typedef struct ICONITEM unsigned long hicon; /* LoadImage() result */ } ICONITEM; -typedef struct WINMULTIWINDOWPREFS +typedef struct WINPREFS { /* Menu information */ MENUPARSED *menu; /* Array of created menus */ @@ -109,18 +116,22 @@ typedef struct WINMULTIWINDOWPREFS /* Icon information */ char iconDirectory[PATH_MAX+1]; /* Where do the .icos lie? (Win32 path) */ char defaultIconName[NAME_MAX+1]; /* Replacement for x.ico */ + char trayIconName[NAME_MAX+1]; /* Replacement for tray icon */ ICONITEM *icon; int iconItems; -} WINMULTIWINDOWPREFS; + /* Silent exit flag */ + Bool fSilentExit; + +} WINPREFS; /* Functions */ void -LoadPreferences(); +LoadPreferences(void); void SetupRootMenu (unsigned long hmenuRoot); @@ -132,7 +143,7 @@ void HandleCustomWM_INITMENU(unsigned long hwndIn, unsigned long hmenuIn); -int +Bool HandleCustomWM_COMMAND (unsigned long hwndIn, int command); @@ -143,5 +154,8 @@ unsigned long winOverrideIcon (unsigned long longpWin); unsigned long -winOverrideDefaultIcon(); +winTaskbarIcon(void); +unsigned long +winOverrideDefaultIcon(int size); +#endif diff --git a/hw/xwin/winprefslex.l b/hw/xwin/winprefslex.l index 960183498..a4c1abc3d 100644 --- a/hw/xwin/winprefslex.l +++ b/hw/xwin/winprefslex.l @@ -37,7 +37,7 @@ extern YYSTYPE yylval; extern char *yytext; -extern int yyparse(); +extern int yyparse(void); extern void ErrorF (const char* /*f*/, ...); @@ -62,31 +62,33 @@ static char *makestr(char *str) %option yylineno %% -\#.*[\r\n] { /* comment */ return NEWLINE; } -\/\/.*[\r\n] { /* comment */ return NEWLINE; } -[\r\n] { return NEWLINE; } -[ \t]+ { /* ignore whitespace */ } -[mM][eE][nN][uU] { return MENU; } -[iI][cC][oO][nN][dD][iI][rR][eE][cC][tT][oO][rR][yY] { return ICONDIRECTORY; } -[dD][eE][fF][aA][uU][lL][tT][iI][cC][oO][nN] { return DEFAULTICON; } -[iI][cC][oO][nN][sS] { return ICONS; } -[rR][oO][oO][tT][mM][eE][nN][uU] { return ROOTMENU; } -[dD][eE][fF][aA][uU][lL][tT][sS][yY][sS][mM][eE][nN][uU] { return DEFAULTSYSMENU; } -[sS][yY][sS][mM][eE][nN][uU] { return SYSMENU; } -[sS][eE][pP][aA][rR][aA][tT][oO][rR] { return SEPARATOR; } -[aA][tT][sS][tT][aA][rR][tT] { return ATSTART; } -[aA][tT][eE][nN][dD] { return ATEND; } -[eE][xX][eE][cC] { return EXEC; } -[aA][lL][wW][aA][yY][sS][oO][nN][tT][oO][pP] { return ALWAYSONTOP; } -[dD][eE][bB][uU][gG] { return DEBUG; } -[rR][eE][lL][oO][aA][dD] { return RELOAD; } -"{" { return LB; } -"}" { return RB; } -"\""[^\"\r\n]+"\"" { yylval.sVal = makestr(yytext+1); \ - yylval.sVal[strlen(yylval.sVal)-1] = 0; \ - return STRING; } -[^ \t\r\n]+ { yylval.sVal = makestr(yytext); \ - return STRING; } +\#.*[\r\n] { /* comment */ return NEWLINE; } +\/\/.*[\r\n] { /* comment */ return NEWLINE; } +[\r\n] { return NEWLINE; } +[ \t]+ { /* ignore whitespace */ } +MENU { return MENU; } +ICONDIRECTORY { return ICONDIRECTORY; } +DEFAULTICON { return DEFAULTICON; } +ICONS { return ICONS; } +ROOTMENU { return ROOTMENU; } +DEFAULTSYSMENU { return DEFAULTSYSMENU; } +SYSMENU { return SYSMENU; } +SEPARATOR { return SEPARATOR; } +ATSTART { return ATSTART; } +ATEND { return ATEND; } +EXEC { return EXEC; } +ALWAYSONTOP { return ALWAYSONTOP; } +DEBUG { return DEBUG; } +RELOAD { return RELOAD; } +TRAYICON { return TRAYICON; } +SILENTEXIT { return SILENTEXIT; } +"{" { return LB; } +"}" { return RB; } +"\""[^\"\r\n]+"\"" { yylval.sVal = makestr(yytext+1); \ + yylval.sVal[strlen(yylval.sVal)-1] = 0; \ + return STRING; } +[^ \t\r\n]+ { yylval.sVal = makestr(yytext); \ + return STRING; } %% /* @@ -111,3 +113,4 @@ parse_file (FILE *file) yyin = file; yyparse (); } + diff --git a/hw/xwin/winprefsyacc.y b/hw/xwin/winprefsyacc.y index 5ae33b67e..debfe0c01 100644 --- a/hw/xwin/winprefsyacc.y +++ b/hw/xwin/winprefsyacc.y @@ -39,7 +39,7 @@ #define YYERROR_VERBOSE 1 /* The global pref settings */ -WINMULTIWINDOWPREFS pref; +WINPREFS pref; /* The working menu */ static MENUPARSED menu; @@ -51,24 +51,25 @@ static void SetIconDirectory (char *path); static void SetDefaultIcon (char *fname); static void SetRootMenu (char *menu); static void SetDefaultSysMenu (char *menu, int pos); +static void SetTrayIcon (char *fname); static void OpenMenu(char *menuname); static void AddMenuLine(char *name, MENUCOMMANDTYPE cmd, char *param); -static void CloseMenu(); +static void CloseMenu(void); -static void OpenIcons(); +static void OpenIcons(void); static void AddIconLine(char *matchstr, char *iconfile); -static void CloseIcons(); +static void CloseIcons(void); -static void OpenSysMenu(); +static void OpenSysMenu(void); static void AddSysMenuLine(char *matchstr, char *menuname, int pos); -static void CloseSysMenu(); +static void CloseSysMenu(void); static int yyerror (char *s); extern void ErrorF (const char* /*f*/, ...); extern char *yytext; -extern int yylex(); +extern int yylex(void); %} @@ -79,7 +80,7 @@ extern int yylex(); %token NEWLINE MENU LB RB ICONDIRECTORY DEFAULTICON ICONS DEFAULTSYSMENU %token SYSMENU ROOTMENU SEPARATOR ATSTART ATEND EXEC ALWAYSONTOP DEBUG -%token RELOAD +%token RELOAD TRAYICON SILENTEXIT %token <sVal> STRING %type <iVal> atspot @@ -107,6 +108,11 @@ command: defaulticon | rootmenu | defaultsysmenu | debug + | trayicon + | silentexit + ; + +trayicon: TRAYICON STRING NEWLINE { SetTrayIcon($2); free($2); } ; rootmenu: ROOTMENU STRING NEWLINE { SetRootMenu($2); free($2); } @@ -160,6 +166,9 @@ sysmenulist: sysmenuline sysmenu: SYSMENU LB NEWLINE {OpenSysMenu();} newline_or_nada sysmenulist RB {CloseSysMenu();} ; +silentexit: SILENTEXIT NEWLINE { pref.fSilentExit = TRUE; } + ; + debug: DEBUG STRING NEWLINE { ErrorF("LoadPreferences: %s\n", $2); free($2); } ; @@ -193,6 +202,13 @@ SetDefaultIcon (char *fname) } static void +SetTrayIcon (char *fname) +{ + strncpy (pref.trayIconName, fname, NAME_MAX); + pref.trayIconName[NAME_MAX] = 0; +} + +static void SetRootMenu (char *menu) { strncpy (pref.rootMenuName, menu, MENU_MAX); @@ -240,7 +256,7 @@ AddMenuLine (char *text, MENUCOMMANDTYPE cmd, char *param) } static void -CloseMenu () +CloseMenu (void) { if (menu.menuItem==NULL || menu.menuItems==0) { @@ -261,7 +277,7 @@ CloseMenu () } static void -OpenIcons () +OpenIcons (void) { if (pref.icon != NULL) { ErrorF("LoadPreferences: Redefining icon mappings\n"); @@ -292,12 +308,12 @@ AddIconLine (char *matchstr, char *iconfile) } static void -CloseIcons () +CloseIcons (void) { } static void -OpenSysMenu () +OpenSysMenu (void) { if (pref.sysMenu != NULL) { ErrorF("LoadPreferences: Redefining system menu\n"); @@ -328,7 +344,7 @@ AddSysMenuLine (char *matchstr, char *menuname, int pos) } static void -CloseSysMenu () +CloseSysMenu (void) { } diff --git a/hw/xwin/winpriv.c b/hw/xwin/winpriv.c new file mode 100644 index 000000000..20b0840f8 --- /dev/null +++ b/hw/xwin/winpriv.c @@ -0,0 +1,131 @@ +/* + * Export window information for the Windows-OpenGL GLX implementation. + * + * Authors: Alexander Gottwald + */ + +#include "win.h" +#include "winpriv.h" +#include "winwindow.h" + +void +winCreateWindowsWindow (WindowPtr pWin); +/** + * Return size and handles of a window. + * If pWin is NULL, then the information for the root window is requested. + */ +extern void winGetWindowInfo(WindowPtr pWin, winWindowInfoPtr pWinInfo) +{ + /* Sanity check */ + if (pWinInfo == NULL) + return; + + winDebug("%s:%d pWin=%p\n", __FUNCTION__, __LINE__, pWin); + + /* a real window was requested */ + if (pWin != NULL) + { + /* Initialize the size information */ + RECT rect = { + pWin->drawable.x, + pWin->drawable.y, + pWin->drawable.x + pWin->drawable.width, + pWin->drawable.y + pWin->drawable.height + }, rect_extends; + /* Get the window and screen privates */ + ScreenPtr pScreen = pWin->drawable.pScreen; + winPrivScreenPtr pWinScreen = winGetScreenPriv(pScreen); + winScreenInfoPtr pScreenInfo = NULL; + + rect_extends = rect; + OffsetRect(&rect_extends, -pWin->drawable.x, -pWin->drawable.y); + + if (pWinScreen == NULL) + { + ErrorF("winGetWindowInfo: screen has no privates\n"); + return; + } + + pWinInfo->hwnd = pWinScreen->hwndScreen; + pWinInfo->hrgn = NULL; + pWinInfo->rect = rect; + + + pScreenInfo = pWinScreen->pScreenInfo; +#ifdef XWIN_MULTIWINDOW + /* check for multiwindow mode */ + if (pScreenInfo->fMultiWindow) + { + winWindowPriv(pWin); + + if (pWinPriv == NULL) + { + ErrorF("winGetWindowInfo: window has no privates\n"); + return; + } + + if (pWinPriv->hWnd == NULL) + { + winCreateWindowsWindow(pWin); + } + if (pWinPriv->hWnd != NULL) { + + /* copy size and window handle */ + pWinInfo->rect = rect_extends; + pWinInfo->hwnd = pWinPriv->hWnd; + + /* Copy window region */ + if (pWinInfo->hrgn) + DeleteObject(pWinInfo->hrgn); + pWinInfo->hrgn = CreateRectRgn(0,0,0,0); + CombineRgn(pWinInfo->hrgn, pWinPriv->hRgn, pWinPriv->hRgn, + RGN_COPY); + } + + return; + } +#endif +#ifdef XWIN_MULTIWINDOWEXTWM + /* check for multiwindow external wm mode */ + if (pScreenInfo->fMWExtWM) + { + win32RootlessWindowPtr pRLWinPriv + = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE); + + if (pRLWinPriv == NULL) { + ErrorF("winGetWindowInfo: window has no privates\n"); + return; + } + + if (pRLWinPriv->hWnd != NULL) + { + /* copy size and window handle */ + pWinInfo->rect = rect_extends; + pWinInfo->hwnd = pRLWinPriv->hWnd; + } + return; + } +#endif + } + else + { + RECT rect = {0, 0, 0, 0}; + ScreenPtr pScreen = g_ScreenInfo[0].pScreen; + winPrivScreenPtr pWinScreen = winGetScreenPriv(pScreen); + + pWinInfo->hwnd = NULL; + pWinInfo->hrgn = NULL; + pWinInfo->rect = rect; + + if (pWinScreen == NULL) + { + ErrorF("winGetWindowInfo: screen has no privates\n"); + return; + } + + ErrorF("winGetWindowInfo: returning root window\n"); + + pWinInfo->hwnd = pWinScreen->hwndScreen; + } + return; +} diff --git a/hw/xwin/winpriv.h b/hw/xwin/winpriv.h new file mode 100644 index 000000000..d4505c83e --- /dev/null +++ b/hw/xwin/winpriv.h @@ -0,0 +1,15 @@ +/* + * Export window information for the Windows-OpenGL GLX implementation. + * + * Authors: Alexander Gottwald + */ +#include <windows.h> + +typedef struct +{ + HWND hwnd; + HRGN hrgn; + RECT rect; +} winWindowInfoRec, *winWindowInfoPtr; + +extern void winGetWindowInfo(WindowPtr pWin, winWindowInfoPtr pWinInfo); diff --git a/hw/xwin/winprocarg.c b/hw/xwin/winprocarg.c new file mode 100755 index 000000000..a7302fe82 --- /dev/null +++ b/hw/xwin/winprocarg.c @@ -0,0 +1,1250 @@ +/* + +Copyright 1993, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +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 OPEN GROUP 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 Open Group 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 Open Group. + +*/ + +#include "win.h" +#include "winconfig.h" +#include "winprefs.h" +#include "winmsg.h" + +/* + * References to external symbols + */ + +extern int g_iNumScreens; +extern winScreenInfo g_ScreenInfo[]; +extern int g_iLastScreen; +extern Bool g_fInitializedDefaultScreens; +#ifdef XWIN_CLIPBOARD +extern Bool g_fUnicodeClipboard; +extern Bool g_fClipboard; +#endif +extern int g_iLogVerbose; +extern char * g_pszLogFile; +extern Bool g_fXdmcpEnabled; +extern char * g_pszCommandLine; +extern Bool g_fKeyboardHookLL; +extern Bool g_fNoHelpMessageBox; +extern Bool g_fSoftwareCursor; + + +/* + * Function prototypes + */ + +void +winLogCommandLine (int argc, char *argv[]); + +void +winLogVersionInfo (void); + +#ifdef DDXOSVERRORF +void OsVendorVErrorF (const char *pszFormat, va_list va_args); +#endif + +void +winInitializeDefaultScreens (void); + + +/* + * Process arguments on the command line + */ + +void +winInitializeDefaultScreens (void) +{ + int i; + DWORD dwWidth, dwHeight; + + /* Bail out early if default screens have already been initialized */ + if (g_fInitializedDefaultScreens) + return; + + /* Zero the memory used for storing the screen info */ + ZeroMemory (g_ScreenInfo, MAXSCREENS * sizeof (winScreenInfo)); + + /* Get default width and height */ + /* + * NOTE: These defaults will cause the window to cover only + * the primary monitor in the case that we have multiple monitors. + */ + dwWidth = GetSystemMetrics (SM_CXSCREEN); + dwHeight = GetSystemMetrics (SM_CYSCREEN); + + winErrorFVerb (2, "winInitializeDefaultScreens - w %d h %d\n", + (int) dwWidth, (int) dwHeight); + + /* Set a default DPI, if no parameter was passed */ + if (monitorResolution == 0) + monitorResolution = WIN_DEFAULT_DPI; + + for (i = 0; i < MAXSCREENS; ++i) + { + g_ScreenInfo[i].dwScreen = i; + g_ScreenInfo[i].dwWidth = dwWidth; + g_ScreenInfo[i].dwHeight = dwHeight; + g_ScreenInfo[i].dwUserWidth = dwWidth; + g_ScreenInfo[i].dwUserHeight = dwHeight; + g_ScreenInfo[i].fUserGaveHeightAndWidth + = WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH; + g_ScreenInfo[i].dwBPP = WIN_DEFAULT_BPP; + g_ScreenInfo[i].dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES; +#ifdef XWIN_EMULATEPSEUDO + g_ScreenInfo[i].fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO; +#endif + g_ScreenInfo[i].dwRefreshRate = WIN_DEFAULT_REFRESH; + g_ScreenInfo[i].pfb = NULL; + g_ScreenInfo[i].fFullScreen = FALSE; + g_ScreenInfo[i].fDecoration = TRUE; +#ifdef XWIN_MULTIWINDOWEXTWM + g_ScreenInfo[i].fMWExtWM = FALSE; +#endif + g_ScreenInfo[i].fRootless = FALSE; +#ifdef XWIN_MULTIWINDOW + g_ScreenInfo[i].fMultiWindow = FALSE; +#endif + g_ScreenInfo[i].fMultipleMonitors = FALSE; + g_ScreenInfo[i].fLessPointer = FALSE; + g_ScreenInfo[i].fScrollbars = FALSE; + g_ScreenInfo[i].fNoTrayIcon = FALSE; + g_ScreenInfo[i].iE3BTimeout = WIN_E3B_OFF; + g_ScreenInfo[i].dwWidth_mm = (dwWidth / WIN_DEFAULT_DPI) + * 25.4; + g_ScreenInfo[i].dwHeight_mm = (dwHeight / WIN_DEFAULT_DPI) + * 25.4; + g_ScreenInfo[i].fUseWinKillKey = WIN_DEFAULT_WIN_KILL; + g_ScreenInfo[i].fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL; + g_ScreenInfo[i].fIgnoreInput = FALSE; + g_ScreenInfo[i].fExplicitScreen = FALSE; + } + + /* Signal that the default screens have been initialized */ + g_fInitializedDefaultScreens = TRUE; + + winErrorFVerb (2, "winInitializeDefaultScreens - Returning\n"); +} + +/* See Porting Layer Definition - p. 57 */ +/* + * INPUT + * argv: pointer to an array of null-terminated strings, one for + * each token in the X Server command line; the first token + * is 'XWin.exe', or similar. + * argc: a count of the number of tokens stored in argv. + * i: a zero-based index into argv indicating the current token being + * processed. + * + * OUTPUT + * return: return the number of tokens processed correctly. + * + * NOTE + * When looking for n tokens, check that i + n is less than argc. Or, + * you may check if i is greater than or equal to argc, in which case + * you should display the UseMsg () and return 0. + */ + +/* Check if enough arguments are given for the option */ +#define CHECK_ARGS(count) if (i + count >= argc) { UseMsg (); return 0; } + +/* Compare the current option with the string. */ +#define IS_OPTION(name) (strcmp (argv[i], name) == 0) + +int +ddxProcessArgument (int argc, char *argv[], int i) +{ + static Bool s_fBeenHere = FALSE; + + /* Initialize once */ + if (!s_fBeenHere) + { +#ifdef DDXOSVERRORF + /* + * This initialises our hook into VErrorF () for catching log messages + * that are generated before OsInit () is called. + */ + OsVendorVErrorFProc = OsVendorVErrorF; +#endif + + s_fBeenHere = TRUE; + + /* Initialize only if option is not -help */ + if (!IS_OPTION("-help") && !IS_OPTION("-h") && !IS_OPTION("--help") && + !IS_OPTION("-version") && !IS_OPTION("--version")) + { + + /* Log the version information */ + winLogVersionInfo (); + + /* Log the command line */ + winLogCommandLine (argc, argv); + + /* + * Initialize default screen settings. We have to do this before + * OsVendorInit () gets called, otherwise we will overwrite + * settings changed by parameters such as -fullscreen, etc. + */ + winErrorFVerb (2, "ddxProcessArgument - Initializing default " + "screens\n"); + winInitializeDefaultScreens (); + } + } + +#if CYGDEBUG + winDebug ("ddxProcessArgument - arg: %s\n", argv[i]); +#endif + + /* + * Look for the '-help' and similar options + */ + if (IS_OPTION ("-help") || IS_OPTION("-h") || IS_OPTION("--help")) + { + /* Reset logfile. We don't need that helpmessage in the logfile */ + g_pszLogFile = NULL; + g_fNoHelpMessageBox = TRUE; + UseMsg(); + exit (0); + return 1; + } + + if (IS_OPTION ("-version") || IS_OPTION("--version")) + { + /* Reset logfile. We don't need that versioninfo in the logfile */ + g_pszLogFile = NULL; + winLogVersionInfo (); + exit (0); + return 1; + } + + /* + * Look for the '-screen scr_num [width height]' argument + */ + if (IS_OPTION ("-screen")) + { + int iArgsProcessed = 1; + int nScreenNum; + int iWidth, iHeight; + +#if CYGDEBUG + winDebug ("ddxProcessArgument - screen - argc: %d i: %d\n", + argc, i); +#endif + + /* Display the usage message if the argument is malformed */ + if (i + 1 >= argc) + { + return 0; + } + + /* Grab screen number */ + nScreenNum = atoi (argv[i + 1]); + + /* Validate the specified screen number */ + if (nScreenNum < 0 || nScreenNum >= MAXSCREENS) + { + ErrorF ("ddxProcessArgument - screen - Invalid screen number %d\n", + nScreenNum); + UseMsg (); + return 0; + } + + /* Look for 'WxD' or 'W D' */ + if (i + 2 < argc + && 2 == sscanf (argv[i + 2], "%dx%d", + (int *) &iWidth, + (int *) &iHeight)) + { + winErrorFVerb (2, "ddxProcessArgument - screen - Found ``WxD'' arg\n"); + iArgsProcessed = 3; + g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE; + g_ScreenInfo[nScreenNum].dwWidth = iWidth; + g_ScreenInfo[nScreenNum].dwHeight = iHeight; + g_ScreenInfo[nScreenNum].dwUserWidth = iWidth; + g_ScreenInfo[nScreenNum].dwUserHeight = iHeight; + } + else if (i + 3 < argc + && 1 == sscanf (argv[i + 2], "%d", + (int *) &iWidth) + && 1 == sscanf (argv[i + 3], "%d", + (int *) &iHeight)) + { + winErrorFVerb (2, "ddxProcessArgument - screen - Found ``W D'' arg\n"); + iArgsProcessed = 4; + g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE; + g_ScreenInfo[nScreenNum].dwWidth = iWidth; + g_ScreenInfo[nScreenNum].dwHeight = iHeight; + g_ScreenInfo[nScreenNum].dwUserWidth = iWidth; + g_ScreenInfo[nScreenNum].dwUserHeight = iHeight; + } + else + { + winErrorFVerb (2, "ddxProcessArgument - screen - Did not find size arg. " + "dwWidth: %d dwHeight: %d\n", + (int) g_ScreenInfo[nScreenNum].dwWidth, + (int) g_ScreenInfo[nScreenNum].dwHeight); + iArgsProcessed = 2; + g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE; + } + + /* Calculate the screen width and height in millimeters */ + if (g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth) + { + g_ScreenInfo[nScreenNum].dwWidth_mm + = (g_ScreenInfo[nScreenNum].dwWidth + / monitorResolution) * 25.4; + g_ScreenInfo[nScreenNum].dwHeight_mm + = (g_ScreenInfo[nScreenNum].dwHeight + / monitorResolution) * 25.4; + } + + /* Flag that this screen was explicity specified by the user */ + g_ScreenInfo[nScreenNum].fExplicitScreen = TRUE; + + /* + * Keep track of the last screen number seen, as parameters seen + * before a screen number apply to all screens, whereas parameters + * seen after a screen number apply to that screen number only. + */ + g_iLastScreen = nScreenNum; + + /* Keep a count of the number of screens */ + ++g_iNumScreens; + + return iArgsProcessed; + } + + /* + * Look for the '-engine n' argument + */ + if (IS_OPTION ("-engine")) + { + DWORD dwEngine = 0; + CARD8 c8OnBits = 0; + + /* Display the usage message if the argument is malformed */ + if (++i >= argc) + { + UseMsg (); + return 0; + } + + /* Grab the argument */ + dwEngine = atoi (argv[i]); + + /* Count the one bits in the engine argument */ + c8OnBits = winCountBits (dwEngine); + + /* Argument should only have a single bit on */ + if (c8OnBits != 1) + { + UseMsg (); + return 0; + } + + /* Is this parameter attached to a screen or global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].dwEnginePreferred = dwEngine; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].dwEnginePreferred = dwEngine; + } + + /* Indicate that we have processed the argument */ + return 2; + } + + /* + * Look for the '-fullscreen' argument + */ + if (IS_OPTION ("-fullscreen")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fFullScreen = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fFullScreen = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-lesspointer' argument + */ + if (IS_OPTION ("-lesspointer")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fLessPointer = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fLessPointer = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-nodecoration' argument + */ + if (IS_OPTION ("-nodecoration")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fDecoration = FALSE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fDecoration = FALSE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + +#ifdef XWIN_MULTIWINDOWEXTWM + /* + * Look for the '-mwextwm' argument + */ + if (IS_OPTION ("-mwextwm")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fMWExtWM = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fMWExtWM = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } +#endif + + /* + * Look for the '-rootless' argument + */ + if (IS_OPTION ("-rootless")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fRootless = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fRootless = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + +#ifdef XWIN_MULTIWINDOW + /* + * Look for the '-multiwindow' argument + */ + if (IS_OPTION ("-multiwindow")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fMultiWindow = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fMultiWindow = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } +#endif + + /* + * Look for the '-multiplemonitors' argument + */ + if (IS_OPTION ("-multiplemonitors") + || IS_OPTION ("-multimonitors")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fMultipleMonitors = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-scrollbars' argument + */ + if (IS_OPTION ("-scrollbars")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fScrollbars = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fScrollbars = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + +#ifdef XWIN_CLIPBOARD + /* + * Look for the '-clipboard' argument + */ + if (IS_OPTION ("-clipboard")) + { + g_fClipboard = TRUE; + + /* Indicate that we have processed this argument */ + return 1; + } +#endif + + + /* + * Look for the '-ignoreinput' argument + */ + if (IS_OPTION ("-ignoreinput")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fIgnoreInput = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fIgnoreInput = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-emulate3buttons' argument + */ + if (IS_OPTION ("-emulate3buttons")) + { + int iArgsProcessed = 1; + int iE3BTimeout = WIN_DEFAULT_E3B_TIME; + + /* Grab the optional timeout value */ + if (i + 1 < argc + && 1 == sscanf (argv[i + 1], "%d", + &iE3BTimeout)) + { + /* Indicate that we have processed the next argument */ + iArgsProcessed++; + } + else + { + /* + * sscanf () won't modify iE3BTimeout if it doesn't find + * the specified format; however, I want to be explicit + * about setting the default timeout in such cases to + * prevent some programs (me) from getting confused. + */ + iE3BTimeout = WIN_DEFAULT_E3B_TIME; + } + + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].iE3BTimeout = iE3BTimeout; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].iE3BTimeout = iE3BTimeout; + } + + /* Indicate that we have processed this argument */ + return iArgsProcessed; + } + + /* + * Look for the '-depth n' argument + */ + if (IS_OPTION ("-depth")) + { + DWORD dwBPP = 0; + + /* Display the usage message if the argument is malformed */ + if (++i >= argc) + { + UseMsg (); + return 0; + } + + /* Grab the argument */ + dwBPP = atoi (argv[i]); + + /* Is this parameter attached to a screen or global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].dwBPP = dwBPP; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].dwBPP = dwBPP; + } + + /* Indicate that we have processed the argument */ + return 2; + } + + /* + * Look for the '-refresh n' argument + */ + if (IS_OPTION ("-refresh")) + { + DWORD dwRefreshRate = 0; + + /* Display the usage message if the argument is malformed */ + if (++i >= argc) + { + UseMsg (); + return 0; + } + + /* Grab the argument */ + dwRefreshRate = atoi (argv[i]); + + /* Is this parameter attached to a screen or global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].dwRefreshRate = dwRefreshRate; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].dwRefreshRate = dwRefreshRate; + } + + /* Indicate that we have processed the argument */ + return 2; + } + + /* + * Look for the '-clipupdates num_boxes' argument + */ + if (IS_OPTION ("-clipupdates")) + { + DWORD dwNumBoxes = 0; + + /* Display the usage message if the argument is malformed */ + if (++i >= argc) + { + UseMsg (); + return 0; + } + + /* Grab the argument */ + dwNumBoxes = atoi (argv[i]); + + /* Is this parameter attached to a screen or global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].dwClipUpdatesNBoxes = dwNumBoxes; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].dwClipUpdatesNBoxes = dwNumBoxes; + } + + /* Indicate that we have processed the argument */ + return 2; + } + +#ifdef XWIN_EMULATEPSEUDO + /* + * Look for the '-emulatepseudo' argument + */ + if (IS_OPTION ("-emulatepseudo")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fEmulatePseudo = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fEmulatePseudo = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } +#endif + + /* + * Look for the '-nowinkill' argument + */ + if (IS_OPTION ("-nowinkill")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fUseWinKillKey = FALSE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fUseWinKillKey = FALSE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-winkill' argument + */ + if (IS_OPTION ("-winkill")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fUseWinKillKey = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fUseWinKillKey = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-nounixkill' argument + */ + if (IS_OPTION ("-nounixkill")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fUseUnixKillKey = FALSE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = FALSE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-unixkill' argument + */ + if (IS_OPTION ("-unixkill")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fUseUnixKillKey = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-notrayicon' argument + */ + if (IS_OPTION ("-notrayicon")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fNoTrayIcon = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fNoTrayIcon = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-trayicon' argument + */ + if (IS_OPTION ("-trayicon")) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fNoTrayIcon = FALSE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fNoTrayIcon = FALSE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-fp' argument + */ + if (IS_OPTION ("-fp")) + { + CHECK_ARGS (1); + g_cmdline.fontPath = argv[++i]; + return 0; /* Let DIX parse this again */ + } + + /* + * Look for the '-co' argument + */ + if (IS_OPTION ("-co")) + { + CHECK_ARGS (1); + g_cmdline.rgbPath = argv[++i]; + return 0; /* Let DIX parse this again */ + } + + /* + * Look for the '-query' argument + */ + if (IS_OPTION ("-query")) + { + CHECK_ARGS (1); + g_fXdmcpEnabled = TRUE; + g_pszQueryHost = argv[++i]; + return 0; /* Let DIX parse this again */ + } + + /* + * Look for the '-indirect' or '-broadcast' arguments + */ + if (IS_OPTION ("-indirect") + || IS_OPTION ("-broadcast")) + { + g_fXdmcpEnabled = TRUE; + return 0; /* Let DIX parse this again */ + } + + /* + * Look for the '-config' argument + */ + if (IS_OPTION ("-config") + || IS_OPTION ("-xf86config")) + { + CHECK_ARGS (1); +#ifdef XWIN_XF86CONFIG + g_cmdline.configFile = argv[++i]; +#else + winMessageBoxF ("The %s option is not supported in this " + "release.\n" + "Ignoring this option and continuing.\n", + MB_ICONINFORMATION, + argv[i]); +#endif + return 2; + } + + /* + * Look for the '-keyboard' argument + */ + if (IS_OPTION ("-keyboard")) + { +#ifdef XWIN_XF86CONFIG + CHECK_ARGS (1); + g_cmdline.keyboard = argv[++i]; +#else + winMessageBoxF ("The -keyboard option is not supported in this " + "release.\n" + "Ignoring this option and continuing.\n", + MB_ICONINFORMATION); +#endif + return 2; + } + + /* + * Look for the '-logfile' argument + */ + if (IS_OPTION ("-logfile")) + { + CHECK_ARGS (1); + g_pszLogFile = argv[++i]; + return 2; + } + + /* + * Look for the '-logverbose' argument + */ + if (IS_OPTION ("-logverbose")) + { + CHECK_ARGS (1); + g_iLogVerbose = atoi(argv[++i]); + return 2; + } + +#ifdef XWIN_CLIPBOARD + /* + * Look for the '-nounicodeclipboard' argument + */ + if (IS_OPTION ("-nounicodeclipboard")) + { + g_fUnicodeClipboard = FALSE; + /* Indicate that we have processed the argument */ + return 1; + } +#endif + +#ifdef XKB + /* + * Look for the '-kb' argument + */ + if (IS_OPTION ("-kb")) + { + g_cmdline.noXkbExtension = TRUE; + return 0; /* Let DIX parse this again */ + } + + if (IS_OPTION ("-xkbrules")) + { + CHECK_ARGS (1); + g_cmdline.xkbRules = argv[++i]; + return 2; + } + if (IS_OPTION ("-xkbmodel")) + { + CHECK_ARGS (1); + g_cmdline.xkbModel = argv[++i]; + return 2; + } + if (IS_OPTION ("-xkblayout")) + { + CHECK_ARGS (1); + g_cmdline.xkbLayout = argv[++i]; + return 2; + } + if (IS_OPTION ("-xkbvariant")) + { + CHECK_ARGS (1); + g_cmdline.xkbVariant = argv[++i]; + return 2; + } + if (IS_OPTION ("-xkboptions")) + { + CHECK_ARGS (1); + g_cmdline.xkbOptions = argv[++i]; + return 2; + } +#endif + + if (IS_OPTION ("-keyhook")) + { + g_fKeyboardHookLL = TRUE; + return 1; + } + + if (IS_OPTION ("-nokeyhook")) + { + g_fKeyboardHookLL = FALSE; + return 1; + } + + if (IS_OPTION ("-swcursor")) + { + g_fSoftwareCursor = TRUE; + return 1; + } + + return 0; +} + + +/* + * winLogCommandLine - Write entire command line to the log file + */ + +void +winLogCommandLine (int argc, char *argv[]) +{ + int i; + int iSize = 0; + int iCurrLen = 0; + +#define CHARS_PER_LINE 60 + + /* Bail if command line has already been logged */ + if (g_pszCommandLine) + return; + + /* Count how much memory is needed for concatenated command line */ + for (i = 0, iCurrLen = 0; i < argc; ++i) + if (argv[i]) + { + /* Add a character for lines that overflow */ + if ((strlen (argv[i]) < CHARS_PER_LINE + && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE) + || strlen (argv[i]) > CHARS_PER_LINE) + { + iCurrLen = 0; + ++iSize; + } + + /* Add space for item and trailing space */ + iSize += strlen (argv[i]) + 1; + + /* Update current line length */ + iCurrLen += strlen (argv[i]); + } + + /* Allocate memory for concatenated command line */ + g_pszCommandLine = malloc (iSize + 1); + if (!g_pszCommandLine) + FatalError ("winLogCommandLine - Could not allocate memory for " + "command line string. Exiting.\n"); + + /* Set first character to concatenated command line to null */ + g_pszCommandLine[0] = '\0'; + + /* Loop through all args */ + for (i = 0, iCurrLen = 0; i < argc; ++i) + { + /* Add a character for lines that overflow */ + if ((strlen (argv[i]) < CHARS_PER_LINE + && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE) + || strlen (argv[i]) > CHARS_PER_LINE) + { + iCurrLen = 0; + + /* Add line break if it fits */ + strncat (g_pszCommandLine, "\n", iSize - strlen (g_pszCommandLine)); + } + + strncat (g_pszCommandLine, argv[i], iSize - strlen (g_pszCommandLine)); + strncat (g_pszCommandLine, " ", iSize - strlen (g_pszCommandLine)); + + /* Save new line length */ + iCurrLen += strlen (argv[i]); + } + + ErrorF ("XWin was started with the following command line:\n\n" + "%s\n\n", g_pszCommandLine); +} + + +/* + * winLogVersionInfo - Log Cygwin/X version information + */ + +void +winLogVersionInfo (void) +{ + static Bool s_fBeenHere = FALSE; + + if (s_fBeenHere) + return; + s_fBeenHere = TRUE; + + ErrorF ("Welcome to the XWin X Server\n"); + ErrorF ("Vendor: %s\n", VENDOR_STRING); + ErrorF ("Release: %s\n\n", VERSION_STRING); + ErrorF ("Contact: %s\n\n", VENDOR_CONTACT); +} diff --git a/hw/xwin/winpushpxl.c b/hw/xwin/winpushpxl.c index 2ae0e6557..9d7072e83 100644 --- a/hw/xwin/winpushpxl.c +++ b/hw/xwin/winpushpxl.c @@ -75,11 +75,8 @@ bitsizeof(int) padding and sacnline unit == bitsizeof(int).) * in the server, we need to rename one of them */ void -winPushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg) - GCPtr pGC; - PixmapPtr pBitMap; - DrawablePtr pDrawable; - int dx, dy, xOrg, yOrg; +winPushPixels (GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable, + int dx, int dy, int xOrg, int yOrg) { int h, dxDivPPW, ibEnd; MiBits *pwLineStart; diff --git a/hw/xwin/winrandr.c b/hw/xwin/winrandr.c new file mode 100755 index 000000000..590b3f40c --- /dev/null +++ b/hw/xwin/winrandr.c @@ -0,0 +1,138 @@ +/* + *Copyright (C) 2001-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "win.h" + + +/* + * Local prototypes + */ + +static Bool +winRandRGetInfo (ScreenPtr pScreen, Rotation *pRotations); + +static Bool +winRandRSetConfig (ScreenPtr pScreen, + Rotation rotateKind, + int rate, + RRScreenSizePtr pSize); + +Bool +winRandRInit (ScreenPtr pScreen); + + +/* + * Answer queries about the RandR features supported. + */ + +static Bool +winRandRGetInfo (ScreenPtr pScreen, Rotation *pRotations) +{ + winScreenPriv(pScreen); + winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; + int n; + Rotation rotateKind; + RRScreenSizePtr pSize; + + winDebug ("winRandRGetInfo ()\n"); + + /* Don't support rotations, yet */ + *pRotations = RR_Rotate_0; + + /* Bail if no depth has a visual associated with it */ + for (n = 0; n < pScreen->numDepths; n++) + if (pScreen->allowedDepths[n].numVids) + break; + if (n == pScreen->numDepths) + return FALSE; + + /* Only one allowed rotation for now */ + rotateKind = RR_Rotate_0; + + /* + * Register supported sizes. This can be called many times, but + * we only support one size for now. + */ + pSize = RRRegisterSize (pScreen, + pScreenInfo->dwWidth, + pScreenInfo->dwHeight, + pScreenInfo->dwWidth_mm, + pScreenInfo->dwHeight_mm); + + /* Tell RandR what the current config is */ + RRSetCurrentConfig (pScreen, + rotateKind, + 0, /* refresh rate, not needed */ + pSize); + + return TRUE; +} + + +/* + * Respond to resize/rotate request from either X Server or X client app + */ + +static Bool +winRandRSetConfig (ScreenPtr pScreen, + Rotation rotateKind, + int rate, + RRScreenSizePtr pSize) +{ + winDebug ("winRandRSetConfig ()\n"); + + return TRUE; +} + + +/* + * Initialize the RandR layer. + */ + +Bool +winRandRInit (ScreenPtr pScreen) +{ + rrScrPrivPtr pRRScrPriv; + + winDebug ("winRandRInit ()\n"); + + if (!RRScreenInit (pScreen)) + { + ErrorF ("winRandRInit () - RRScreenInit () failed\n"); + return FALSE; + } + + /* Set some RandR function pointers */ + pRRScrPriv = rrGetScrPriv (pScreen); + pRRScrPriv->rrGetInfo = winRandRGetInfo; + pRRScrPriv->rrSetConfig = winRandRSetConfig; + + return TRUE; +} diff --git a/hw/xwin/winregistry.c b/hw/xwin/winregistry.c index 7d4a473ab..a39428d3e 100644 --- a/hw/xwin/winregistry.c +++ b/hw/xwin/winregistry.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2002-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,22 +15,24 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winmisc.c,v 1.5 2001/11/11 22:45:57 alanh Exp $ */ #include "win.h" +/* Prototypes */ +DWORD +winGetRegistryDWORD (HKEY hkey, char *pszRegistryKey); DWORD winGetRegistryDWORD (HKEY hkey, char *pszRegistryKey) diff --git a/hw/xwin/winresource.h b/hw/xwin/winresource.h new file mode 100644 index 000000000..300fcd198 --- /dev/null +++ b/hw/xwin/winresource.h @@ -0,0 +1,57 @@ +#if !defined(WINRESOURCE_H) +#define WINRESOURCE_H +/* + *Copyright (C) 2002-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "winms.h" + + +/* + * Local defines + */ + +#define IDC_STATIC -1 +#define IDI_XWIN 101 +#define IDI_XWIN_BOXED 102 +#define IDM_TRAYICON_MENU 103 +#define IDC_CLIENTS_CONNECTED 104 + + +#define ID_APP_EXIT 200 +#define ID_APP_HIDE_ROOT 201 +#define ID_APP_ALWAYS_ON_TOP 202 +#define ID_APP_ABOUT 203 + +#define ID_ABOUT_UG 300 +#define ID_ABOUT_FAQ 301 +#define ID_ABOUT_CHANGELOG 302 +#define ID_ABOUT_WEBSITE 303 + +#endif diff --git a/hw/xwin/winrop.c b/hw/xwin/winrop.c index 76a997aaa..ca78ee72e 100644 --- a/hw/xwin/winrop.c +++ b/hw/xwin/winrop.c @@ -34,6 +34,9 @@ */ #include "win.h" +void +ROP16 (HDC hdc, int rop); + int g_copyROP[16] = { 0xFF0062, /* GXclear - 0 */ 0x8800C6, /* GXand - S & D */ 0x440328, /* GXandReverse - S & !D */ diff --git a/hw/xwin/winscrinit.c b/hw/xwin/winscrinit.c index 595f3da7e..6dd37cf04 100644 --- a/hw/xwin/winscrinit.c +++ b/hw/xwin/winscrinit.c @@ -34,6 +34,62 @@ /* $XFree86: xc/programs/Xserver/hw/xwin/winscrinit.c,v 1.27 2003/07/29 21:25:18 dawes Exp $ */ #include "win.h" +#include "winmsg.h" +#include "safeAlpha.h" + + +#ifdef XWIN_MULTIWINDOWEXTWM +static RootlessFrameProcsRec +winMWExtWMProcs = { + winMWExtWMCreateFrame, + winMWExtWMDestroyFrame, + + winMWExtWMMoveFrame, + winMWExtWMResizeFrame, + winMWExtWMRestackFrame, + winMWExtWMReshapeFrame, + winMWExtWMUnmapFrame, + + winMWExtWMStartDrawing, + winMWExtWMStopDrawing, + winMWExtWMUpdateRegion, +#ifndef ROOTLESS_TRACK_DAMAGE + winMWExtWMDamageRects, +#endif + winMWExtWMRootlessSwitchWindow, + + NULL,//winMWExtWMCopyBytes, + NULL,//winMWExtWMFillBytes, + NULL,//winMWExtWMCompositePixels, + winMWExtWMCopyWindow +}; +#endif + + +/* + * References to external symbols + */ + +extern winScreenInfo g_ScreenInfo[]; +extern miPointerScreenFuncRec g_winPointerCursorFuncs; +extern int g_iScreenPrivateIndex; +extern Bool g_fSoftwareCursor; + + +/* + * Prototypes + */ + +Bool +winRandRInit (ScreenPtr pScreen); + + +/* + * Local functions + */ + +static Bool +winSaveScreen (ScreenPtr pScreen, int on); /* @@ -51,8 +107,8 @@ winScreenInit (int index, winPrivScreenPtr pScreenPriv; HDC hdc; -#if CYGDEBUG - ErrorF ("winScreenInit - dwWidth: %d dwHeight: %d\n", +#if CYGDEBUG || YES + winDebug ("winScreenInit - dwWidth: %ld dwHeight: %ld\n", pScreenInfo->dwWidth, pScreenInfo->dwHeight); #endif @@ -98,7 +154,7 @@ winScreenInit (int index, ErrorF ("winScreenInit - Unsupported display depth: %d\n" \ "Change your Windows display depth to 15, 16, 24, or 32 bits " "per pixel.\n", - pScreenInfo->dwBPP); + (int) pScreenInfo->dwBPP); ErrorF ("winScreenInit - Supported depths: %08x\n", WIN_SUPPORTED_BPPS); #if WIN_CHECK_DEPTH @@ -177,8 +233,13 @@ winScreenInit (int index, return FALSE; } + if (!g_fSoftwareCursor) + winInitCursor(pScreen); + else + winErrorFVerb(2, "winScreenInit - Using software cursor\n"); + #if CYGDEBUG || YES - ErrorF ("winScreenInit - returning\n"); + winDebug ("winScreenInit - returning\n"); #endif return TRUE; @@ -197,10 +258,6 @@ winFinishScreenInitFB (int index, char *pbits = NULL; int iReturn; -#if WIN_LAYER_SUPPORT - pScreenPriv->dwLayerKind = LAYER_SHADOW; -#endif - /* Create framebuffer */ if (!(*pScreenPriv->pwinAllocateFB) (pScreen)) { @@ -218,9 +275,10 @@ winFinishScreenInitFB (int index, + winCountBits (pScreenPriv->dwGreenMask) + winCountBits (pScreenPriv->dwBlueMask); - ErrorF ("winFinishScreenInitFB - Masks: %08x %08x %08x\n", - pScreenPriv->dwRedMask, pScreenPriv->dwGreenMask, - pScreenPriv->dwBlueMask); + winErrorFVerb (2, "winFinishScreenInitFB - Masks: %08x %08x %08x\n", + (unsigned int) pScreenPriv->dwRedMask, + (unsigned int) pScreenPriv->dwGreenMask, + (unsigned int) pScreenPriv->dwBlueMask); /* Init visuals */ if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) @@ -255,13 +313,7 @@ winFinishScreenInitFB (int index, || (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; + winSetColormapFunctions (pScreen); /* * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its @@ -322,45 +374,14 @@ winFinishScreenInitFB (int index, } #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)) + /* Initialize resize and rotate support */ + if (!winRandRInit (pScreen)) { ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n"); return FALSE; } #endif -#endif /* * Backing store support should reduce network traffic and increase @@ -371,14 +392,14 @@ winFinishScreenInitFB (int index, /* KDrive does miDCInitialize right after miInitializeBackingStore */ /* Setup the cursor routines */ #if CYGDEBUG - ErrorF ("winFinishScreenInitFB - Calling miDCInitialize ()\n"); + winDebug ("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"); + winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n"); #endif if (!winCreateDefColormap (pScreen)) { @@ -386,14 +407,17 @@ winFinishScreenInitFB (int index, 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->dwEngine == WIN_SERVER_SHADOW_GDI + || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD + || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL) +#ifdef XWIN_MULTIWINDOWEXTWM + && !pScreenInfo->fMWExtWM +#endif + ) { #if CYGDEBUG - ErrorF ("winFinishScreenInitFB - Calling shadowInit ()\n"); + winDebug ("winFinishScreenInitFB - Calling shadowInit ()\n"); #endif if (!shadowInit (pScreen, pScreenPriv->pwinShadowUpdate, @@ -403,10 +427,28 @@ winFinishScreenInitFB (int index, return FALSE; } } -#endif +#ifdef XWIN_MULTIWINDOWEXTWM + /* Handle multi-window external window manager mode */ + if (pScreenInfo->fMWExtWM) + { + winDebug ("winScreenInit - MultiWindowExtWM - Calling RootlessInit\n"); + + RootlessInit(pScreen, &winMWExtWMProcs); + + winDebug ("winScreenInit - MultiWindowExtWM - RootlessInit returned\n"); + + rootless_CopyBytes_threshold = 0; + rootless_FillBytes_threshold = 0; + rootless_CompositePixels_threshold = 0; + /* FIXME: How many? Profiling needed? */ + rootless_CopyWindow_threshold = 1; - /* Handle pseudo-rootless mode */ + winWindowsWMExtensionInit (); + } +#endif + + /* Handle rootless mode */ if (pScreenInfo->fRootless) { /* Define the WRAP macro temporarily for local use */ @@ -429,20 +471,23 @@ winFinishScreenInitFB (int index, 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; + /* Assign rootless window procedures to be top level procedures */ + pScreen->CreateWindow = winCreateWindowRootless; + pScreen->DestroyWindow = winDestroyWindowRootless; + pScreen->PositionWindow = winPositionWindowRootless; + pScreen->ChangeWindowAttributes = winChangeWindowAttributesRootless; + pScreen->RealizeWindow = winMapWindowRootless; + pScreen->UnrealizeWindow = winUnmapWindowRootless; #ifdef SHAPE - pScreen->SetShape = winSetShapePRootless; + pScreen->SetShape = winSetShapeRootless; #endif /* Undefine the WRAP macro, as it is not needed elsewhere */ #undef WRAP } + + +#ifdef XWIN_MULTIWINDOW /* Handle multi window mode */ else if (pScreenInfo->fMultiWindow) { @@ -464,6 +509,9 @@ winFinishScreenInitFB (int index, WRAP(ChangeWindowAttributes); WRAP(ReparentWindow); WRAP(RestackWindow); + WRAP(ResizeWindow); + WRAP(MoveWindow); + WRAP(CopyWindow); #ifdef SHAPE WRAP(SetShape); #endif @@ -477,6 +525,9 @@ winFinishScreenInitFB (int index, pScreen->UnrealizeWindow = winUnmapWindowMultiWindow; pScreen->ReparentWindow = winReparentWindowMultiWindow; pScreen->RestackWindow = winRestackWindowMultiWindow; + pScreen->ResizeWindow = winResizeWindowMultiWindow; + pScreen->MoveWindow = winMoveWindowMultiWindow; + pScreen->CopyWindow = winCopyWindowMultiWindow; #ifdef SHAPE pScreen->SetShape = winSetShapeMultiWindow; #endif @@ -484,12 +535,14 @@ winFinishScreenInitFB (int index, /* Undefine the WRAP macro, as it is not needed elsewhere */ #undef WRAP } +#endif /* 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 */ +#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) + /* Create a mutex for modules in separate threads to wait for */ iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL); if (iReturn != 0) { @@ -498,7 +551,7 @@ winFinishScreenInitFB (int index, return FALSE; } - /* Own the mutex for modules in seperate threads */ + /* Own the mutex for modules in separate threads */ iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted); if (iReturn != 0) { @@ -509,15 +562,16 @@ winFinishScreenInitFB (int index, /* Set the ServerStarted flag to false */ pScreenPriv->fServerStarted = FALSE; +#endif - /* Set the WindowOrderChanged flag to false */ - pScreenPriv->fWindowOrderChanged = FALSE; - +#ifdef XWIN_MULTIWINDOWEXTWM pScreenPriv->fRestacking = FALSE; +#endif +#ifdef XWIN_MULTIWINDOW #if CYGDEBUG || YES if (pScreenInfo->fMultiWindow) - ErrorF ("winFinishScreenInitFB - Calling winInitWM.\n"); + winDebug ("winFinishScreenInitFB - Calling winInitWM.\n"); #endif /* Initialize multi window mode */ @@ -531,22 +585,8 @@ winFinishScreenInitFB (int index, 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; @@ -554,27 +594,13 @@ winFinishScreenInitFB (int index, pScreenPriv->fBadDepth = FALSE; #if CYGDEBUG || YES - ErrorF ("winFinishScreenInitFB - returning\n"); + winDebug ("winFinishScreenInitFB - returning\n"); #endif return TRUE; } - -/* - * - * - * - * - * TEST CODE BELOW - NOT USED IN NORMAL COMPILATION - * - * - * - * - * - */ - - +#ifdef XWIN_NATIVEGDI /* See Porting Layer Definition - p. 20 */ Bool @@ -677,11 +703,11 @@ winFinishScreenInitNativeGDI (int index, /* Colormap Routines */ pScreen->CreateColormap = miInitializeColormap; - pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)()) NoopDDA; + pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)(void)) NoopDDA; pScreen->InstallColormap = miInstallColormap; pScreen->UninstallColormap = miUninstallColormap; pScreen->ListInstalledColormaps = miListInstalledColormaps; - pScreen->StoreColors = (StoreColorsProcPtr) (void (*)()) NoopDDA; + pScreen->StoreColors = (StoreColorsProcPtr) (void (*)(void)) NoopDDA; pScreen->ResolveColor = miResolveColor; /* Bitmap */ @@ -718,30 +744,16 @@ winFinishScreenInitNativeGDI (int index, ErrorF ("winFinishScreenInitNativeGDI - Successful addition of " "screen %08x\n", - pScreen); + (unsigned int) pScreen); return TRUE; } +#endif /* See Porting Layer Definition - p. 33 */ -Bool +static 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 --git a/hw/xwin/winsetsp.c b/hw/xwin/winsetsp.c index 87a16fc31..e41d794c5 100644 --- a/hw/xwin/winsetsp.c +++ b/hw/xwin/winsetsp.c @@ -32,6 +32,16 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iPixmapPrivateIndex; +extern int g_iGCPrivateIndex; +extern int g_copyROP[]; + + /* See Porting Layer Definition - p. 55 */ void winSetSpansNativeGDI (DrawablePtr pDrawable, diff --git a/hw/xwin/winshaddd.c b/hw/xwin/winshaddd.c index 239c0f5ab..7aa553560 100644 --- a/hw/xwin/winshaddd.c +++ b/hw/xwin/winshaddd.c @@ -34,6 +34,14 @@ #include "win.h" + +/* + * External symbols + */ + +extern HWND g_hDlgExit; + + /* * FIXME: Headers are broken, DEFINE_GUID doesn't work correctly, * so we have to redefine it here. @@ -54,12 +62,65 @@ DEFINE_GUID( IID_IDirectDraw2,0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00, /* + * Local prototypes + */ + +static Bool +winAllocateFBShadowDD (ScreenPtr pScreen); + +static void +winShadowUpdateDD (ScreenPtr pScreen, + shadowBufPtr pBuf); + +static Bool +winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen); + +static Bool +winInitVisualsShadowDD (ScreenPtr pScreen); + +static Bool +winAdjustVideoModeShadowDD (ScreenPtr pScreen); + +static Bool +winBltExposedRegionsShadowDD (ScreenPtr pScreen); + +static Bool +winActivateAppShadowDD (ScreenPtr pScreen); + +static Bool +winRedrawScreenShadowDD (ScreenPtr pScreen); + +static Bool +winRealizeInstalledPaletteShadowDD (ScreenPtr pScreen); + +static Bool +winInstallColormapShadowDD (ColormapPtr pColormap); + +static Bool +winStoreColorsShadowDD (ColormapPtr pmap, + int ndef, + xColorItem *pdefs); + +static Bool +winCreateColormapShadowDD (ColormapPtr pColormap); + +static Bool +winDestroyColormapShadowDD (ColormapPtr pColormap); + +static Bool +winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen); + +static Bool +winReleasePrimarySurfaceShadowDD (ScreenPtr pScreen); + + +/* * Create the primary surface and attach the clipper. * Used for both the initial surface creation and during * WM_DISPLAYCHANGE messages. */ -Bool +static Bool winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -80,12 +141,12 @@ winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen) if (FAILED (ddrval)) { ErrorF ("winCreatePrimarySurfaceShadowDD - Could not create primary " - "surface: %08x\n", ddrval); + "surface: %08x\n", (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winCreatePrimarySurfaceShadowDD - Created primary surface\n"); + winDebug ("winCreatePrimarySurfaceShadowDD - Created primary surface\n"); #endif /* @@ -98,12 +159,12 @@ winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen) { ErrorF ("winCreatePrimarySurfaceShadowDD - Primary attach clipper " "failed: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winCreatePrimarySurfaceShadowDD - Attached clipper to " + winDebug ("winCreatePrimarySurfaceShadowDD - Attached clipper to " "primary surface\n"); #endif @@ -117,7 +178,7 @@ winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen) * Called from WM_DISPLAYCHANGE. */ -Bool +static Bool winReleasePrimarySurfaceShadowDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -155,7 +216,7 @@ winReleasePrimarySurfaceShadowDD (ScreenPtr pScreen) * that clips our blits to the unobscured client area of our display window. */ -Bool +static Bool winAllocateFBShadowDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -165,7 +226,7 @@ winAllocateFBShadowDD (ScreenPtr pScreen) DDSURFACEDESC *pddsdShadow = NULL; #if CYGDEBUG - ErrorF ("winAllocateFBShadowDD\n"); + winDebug ("winAllocateFBShadowDD\n"); #endif /* Create a clipper */ @@ -175,12 +236,12 @@ winAllocateFBShadowDD (ScreenPtr pScreen) if (FAILED (ddrval)) { ErrorF ("winAllocateFBShadowDD - Could not create clipper: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winAllocateFBShadowDD - Created a clipper\n"); + winDebug ("winAllocateFBShadowDD - Created a clipper\n"); #endif /* Get a device context for the screen */ @@ -194,12 +255,12 @@ winAllocateFBShadowDD (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDD - Clipper not attached to " "window: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winAllocateFBShadowDD - Attached clipper to window\n"); + winDebug ("winAllocateFBShadowDD - Attached clipper to window\n"); #endif /* Create a DirectDraw object, store the address at lpdd */ @@ -207,12 +268,12 @@ winAllocateFBShadowDD (ScreenPtr pScreen) if (FAILED (ddrval)) { ErrorF ("winAllocateFBShadowDD - Could not start DirectDraw: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winAllocateFBShadowDD () - Created and initialized DD\n"); + winDebug ("winAllocateFBShadowDD () - Created and initialized DD\n"); #endif /* Get a DirectDraw2 interface pointer */ @@ -222,7 +283,7 @@ winAllocateFBShadowDD (ScreenPtr pScreen) if (FAILED (ddrval)) { ErrorF ("winAllocateFBShadowDD - Failed DD2 query: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } @@ -242,7 +303,7 @@ winAllocateFBShadowDD (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDD - Could not set " "cooperative level: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } @@ -262,7 +323,7 @@ winAllocateFBShadowDD (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDD - Could not get current " "refresh rate: %08x. Continuing.\n", - ddrval); + (unsigned int) ddrval); dwRefreshRateCurrent = 0; } else @@ -309,7 +370,7 @@ winAllocateFBShadowDD (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDD - Could not set "\ "full screen display mode: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } } @@ -332,7 +393,7 @@ winAllocateFBShadowDD (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDD - Could not set "\ "cooperative level: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } } @@ -368,12 +429,12 @@ winAllocateFBShadowDD (ScreenPtr pScreen) if (FAILED (ddrval)) { ErrorF ("winAllocateFBShadowDD - Could not create shadow "\ - "surface: %08x\n", ddrval); + "surface: %08x\n", (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winAllocateFBShadowDD - Created shadow\n"); + winDebug ("winAllocateFBShadowDD - Created shadow\n"); #endif /* Allocate a DD surface description for our screen privates */ @@ -388,7 +449,7 @@ winAllocateFBShadowDD (ScreenPtr pScreen) pddsdShadow->dwSize = sizeof (*pddsdShadow); #if CYGDEBUG - ErrorF ("winAllocateFBShadowDD - Locking shadow\n"); + winDebug ("winAllocateFBShadowDD - Locking shadow\n"); #endif /* Lock the shadow surface */ @@ -400,12 +461,12 @@ winAllocateFBShadowDD (ScreenPtr pScreen) if (FAILED (ddrval) || pddsdShadow->lpSurface == NULL) { ErrorF ("winAllocateFBShadowDD - Could not lock shadow "\ - "surface: %08x\n", ddrval); + "surface: %08x\n", (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winAllocateFBShadowDD - Locked shadow\n"); + winDebug ("winAllocateFBShadowDD - Locked shadow\n"); #endif /* We don't know how to deal with anything other than RGB */ @@ -428,7 +489,7 @@ winAllocateFBShadowDD (ScreenPtr pScreen) pScreenPriv->dwBlueMask = pddsdShadow->ddpfPixelFormat.u4.dwBBitMask; #if CYGDEBUG - ErrorF ("winAllocateFBShadowDD - Returning\n"); + winDebug ("winAllocateFBShadowDD - Returning\n"); #endif return TRUE; @@ -439,7 +500,7 @@ winAllocateFBShadowDD (ScreenPtr pScreen) * Transfer the damaged regions of the shadow framebuffer to the display. */ -void +static void winShadowUpdateDD (ScreenPtr pScreen, shadowBufPtr pBuf) { @@ -604,7 +665,7 @@ winShadowUpdateDD (ScreenPtr pScreen, * Free our resources and private structures. */ -Bool +static Bool winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -612,7 +673,7 @@ winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen) Bool fReturn; #if CYGDEBUG - ErrorF ("winCloseScreenShadowDD - Freeing screen resources\n"); + winDebug ("winCloseScreenShadowDD - Freeing screen resources\n"); #endif /* Flag that the screen is closed */ @@ -689,8 +750,10 @@ winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen) pScreenPriv->hwndScreen = NULL; } +#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) /* Destroy the thread startup mutex */ pthread_mutex_destroy (&pScreenPriv->pmServerStarted); +#endif /* Kill our screeninfo's pointer to the screen */ pScreenInfo->pScreen = NULL; @@ -713,7 +776,7 @@ winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen) * to verify that last sentence. */ -Bool +static Bool winInitVisualsShadowDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -737,12 +800,12 @@ winInitVisualsShadowDD (ScreenPtr pScreen) ErrorF ("winInitVisualsShadowDD - Masks %08x %08x %08x BPRGB %d d %d " "bpp %d\n", - pScreenPriv->dwRedMask, - pScreenPriv->dwGreenMask, - pScreenPriv->dwBlueMask, - pScreenPriv->dwBitsPerRGB, - pScreenInfo->dwDepth, - pScreenInfo->dwBPP); + (unsigned int) pScreenPriv->dwRedMask, + (unsigned int) pScreenPriv->dwGreenMask, + (unsigned int) pScreenPriv->dwBlueMask, + (int) pScreenPriv->dwBitsPerRGB, + (int) pScreenInfo->dwDepth, + (int) pScreenInfo->dwBPP); /* Create a single visual according to the Windows screen depth */ switch (pScreenInfo->dwDepth) @@ -765,7 +828,7 @@ winInitVisualsShadowDD (ScreenPtr pScreen) return FALSE; } -#if WIN_EMULATE_PSEUDO_SUPPORT +#ifdef XWIN_EMULATEPSEUDO if (!pScreenInfo->fEmulatePseudo) break; @@ -797,7 +860,7 @@ winInitVisualsShadowDD (ScreenPtr pScreen) return FALSE; } -#if WIN_EMULATE_PSEUDO_SUPPORT +#ifdef XWIN_EMULATEPSEUDO if (!pScreenInfo->fEmulatePseudo) break; @@ -855,7 +918,7 @@ winInitVisualsShadowDD (ScreenPtr pScreen) } #if CYGDEBUG - ErrorF ("winInitVisualsShadowDD - Returning\n"); + winDebug ("winInitVisualsShadowDD - Returning\n"); #endif return TRUE; @@ -866,7 +929,7 @@ winInitVisualsShadowDD (ScreenPtr pScreen) * Adjust the user proposed video mode */ -Bool +static Bool winAdjustVideoModeShadowDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -890,7 +953,7 @@ winAdjustVideoModeShadowDD (ScreenPtr pScreen) { /* No -depth parameter passed, let the user know the depth being used */ ErrorF ("winAdjustVideoModeShadowDD - Using Windows display " - "depth of %d bits per pixel\n", dwBPP); + "depth of %d bits per pixel\n", (int) dwBPP); /* Use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -900,13 +963,13 @@ winAdjustVideoModeShadowDD (ScreenPtr pScreen) { /* FullScreen, and GDI depth differs from -depth parameter */ ErrorF ("winAdjustVideoModeShadowDD - FullScreen, using command line " - "bpp: %d\n", pScreenInfo->dwBPP); + "bpp: %d\n", (int) pScreenInfo->dwBPP); } else if (dwBPP != pScreenInfo->dwBPP) { /* Windowed, and GDI depth differs from -depth parameter */ ErrorF ("winAdjustVideoModeShadowDD - Windowed, command line bpp: " - "%d, using bpp: %d\n", pScreenInfo->dwBPP, dwBPP); + "%d, using bpp: %d\n", (int) pScreenInfo->dwBPP, (int) dwBPP); /* We'll use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -934,7 +997,7 @@ winAdjustVideoModeShadowDD (ScreenPtr pScreen) * Blt exposed regions to the screen */ -Bool +static Bool winBltExposedRegionsShadowDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -1007,10 +1070,10 @@ winBltExposedRegionsShadowDD (ScreenPtr pScreen) /* Try to restore the surface, once */ ddrval = IDirectDrawSurface2_Restore (pScreenPriv->pddsPrimary); - ErrorF ("winBltExposedRegionsShadowDDNL - " + ErrorF ("winBltExposedRegionsShadowDD - " "IDirectDrawSurface2_Restore returned: "); if (ddrval == DD_OK) - continue; + ErrorF ("DD_OK\n"); else if (ddrval == DDERR_WRONGMODE) ErrorF ("DDERR_WRONGMODE\n"); else if (ddrval == DDERR_INCOMPATIBLEPRIMARY) @@ -1022,7 +1085,7 @@ winBltExposedRegionsShadowDD (ScreenPtr pScreen) else if (ddrval == DDERR_INVALIDOBJECT) ErrorF ("DDERR_INVALIDOBJECT\n"); else - ErrorF ("unknown error: %08x\n", ddrval); + ErrorF ("unknown error: %08x\n", (unsigned int) ddrval); /* Loop around to try the blit one more time */ continue; @@ -1031,7 +1094,8 @@ winBltExposedRegionsShadowDD (ScreenPtr pScreen) { fReturn = FALSE; ErrorF ("winBltExposedRegionsShadowDD - IDirectDrawSurface2_Blt " - "failed, but surface not lost: %08x %d\n", ddrval, ddrval); + "failed, but surface not lost: %08x %d\n", + (unsigned int) ddrval, (int) ddrval); goto winBltExposedRegionsShadowDD_Exit; } else @@ -1097,7 +1161,7 @@ winBltExposedRegionsShadowDD (ScreenPtr pScreen) * Do any engine-specific appliation-activation processing */ -Bool +static Bool winActivateAppShadowDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -1123,7 +1187,7 @@ winActivateAppShadowDD (ScreenPtr pScreen) * Reblit the shadow framebuffer to the screen. */ -Bool +static Bool winRedrawScreenShadowDD (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -1160,7 +1224,7 @@ winRedrawScreenShadowDD (ScreenPtr pScreen) { ErrorF ("winRedrawScreenShadowDD - IDirectDrawSurface_Blt () " "failed: %08x\n", - ddrval); + (unsigned int) ddrval); } return TRUE; @@ -1171,7 +1235,7 @@ winRedrawScreenShadowDD (ScreenPtr pScreen) * Realize the currently installed colormap */ -Bool +static Bool winRealizeInstalledPaletteShadowDD (ScreenPtr pScreen) { return TRUE; @@ -1182,7 +1246,7 @@ winRealizeInstalledPaletteShadowDD (ScreenPtr pScreen) * Install the specified colormap */ -Bool +static Bool winInstallColormapShadowDD (ColormapPtr pColormap) { ScreenPtr pScreen = pColormap->pScreen; @@ -1211,7 +1275,7 @@ winInstallColormapShadowDD (ColormapPtr pColormap) * Store the specified colors in the specified colormap */ -Bool +static Bool winStoreColorsShadowDD (ColormapPtr pColormap, int ndef, xColorItem *pdefs) @@ -1231,7 +1295,7 @@ winStoreColorsShadowDD (ColormapPtr pColormap, + pdefs[0].pixel); if (FAILED (ddrval)) { - ErrorF ("winStoreColorsShadowDDNL - SetEntries () failed\n"); + ErrorF ("winStoreColorsShadowDD - SetEntries () failed\n"); return FALSE; } @@ -1243,7 +1307,7 @@ winStoreColorsShadowDD (ColormapPtr pColormap, if (!winInstallColormapShadowDD (pColormap)) { - ErrorF ("winStoreColorsShadowDDNL - Failed installing colormap\n"); + ErrorF ("winStoreColorsShadowDD - Failed installing colormap\n"); return FALSE; } @@ -1255,7 +1319,7 @@ winStoreColorsShadowDD (ColormapPtr pColormap, * Colormap initialization procedure */ -Bool +static Bool winCreateColormapShadowDD (ColormapPtr pColormap) { HRESULT ddrval = DD_OK; @@ -1271,7 +1335,7 @@ winCreateColormapShadowDD (ColormapPtr pColormap) NULL); if (FAILED (ddrval)) { - ErrorF ("winCreateColormapShadowDDNL - CreatePalette failed\n"); + ErrorF ("winCreateColormapShadowDD - CreatePalette failed\n"); return FALSE; } @@ -1283,7 +1347,7 @@ winCreateColormapShadowDD (ColormapPtr pColormap) * Colormap destruction procedure */ -Bool +static Bool winDestroyColormapShadowDD (ColormapPtr pColormap) { winScreenPriv(pColormap->pScreen); @@ -1301,7 +1365,7 @@ winDestroyColormapShadowDD (ColormapPtr pColormap) if (pColormap->flags & IsDefault) { #if CYGDEBUG - ErrorF ("winDestroyColormapShadowDDNL - Destroying default " + winDebug ("winDestroyColormapShadowDD - Destroying default " "colormap\n"); #endif @@ -1315,7 +1379,7 @@ winDestroyColormapShadowDD (ColormapPtr pColormap) NULL); if (FAILED (ddrval)) { - ErrorF ("winDestroyColormapShadowDDNL - Failed freeing the " + ErrorF ("winDestroyColormapShadowDD - Failed freeing the " "default colormap DirectDraw palette.\n"); return FALSE; } @@ -1364,10 +1428,13 @@ winSetEngineFunctionsShadowDD (ScreenPtr pScreen) pScreenPriv->pwinStoreColors = winStoreColorsShadowDD; pScreenPriv->pwinCreateColormap = winCreateColormapShadowDD; pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowDD; - pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)())NoopDDA; + pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA; pScreenPriv->pwinCreatePrimarySurface = winCreatePrimarySurfaceShadowDD; pScreenPriv->pwinReleasePrimarySurface = winReleasePrimarySurfaceShadowDD; +#ifdef XWIN_MULTIWINDOW + pScreenPriv->pwinFinishCreateWindowsWindow = + (winFinishCreateWindowsWindowProcPtr) (void (*)(void))NoopDDA; +#endif return TRUE; } - diff --git a/hw/xwin/winshadddnl.c b/hw/xwin/winshadddnl.c index a5e09421e..c9e629298 100644 --- a/hw/xwin/winshadddnl.c +++ b/hw/xwin/winshadddnl.c @@ -34,6 +34,14 @@ #include "win.h" + +/* + * External symbols + */ + +extern HWND g_hDlgExit; + + /* * FIXME: Headers are broken, DEFINE_GUID doesn't work correctly, * so we have to redefine it here. @@ -55,19 +63,72 @@ DEFINE_GUID( IID_IDirectDraw4, 0x9c59509a,0x39bd,0x11d1,0x8c,0x4a,0x00,0xc0,0x4f /* + * Local prototypes + */ + +static Bool +winAllocateFBShadowDDNL (ScreenPtr pScreen); + +static void +winShadowUpdateDDNL (ScreenPtr pScreen, + shadowBufPtr pBuf); + +static Bool +winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen); + +static Bool +winInitVisualsShadowDDNL (ScreenPtr pScreen); + +static Bool +winAdjustVideoModeShadowDDNL (ScreenPtr pScreen); + +static Bool +winBltExposedRegionsShadowDDNL (ScreenPtr pScreen); + +static Bool +winActivateAppShadowDDNL (ScreenPtr pScreen); + +static Bool +winRedrawScreenShadowDDNL (ScreenPtr pScreen); + +static Bool +winRealizeInstalledPaletteShadowDDNL (ScreenPtr pScreen); + +static Bool +winInstallColormapShadowDDNL (ColormapPtr pColormap); + +static Bool +winStoreColorsShadowDDNL (ColormapPtr pmap, + int ndef, + xColorItem *pdefs); + +static Bool +winCreateColormapShadowDDNL (ColormapPtr pColormap); + +static Bool +winDestroyColormapShadowDDNL (ColormapPtr pColormap); + +static Bool +winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen); + +static Bool +winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen); + + +/* * Create the primary surface and attach the clipper. * Used for both the initial surface creation and during * WM_DISPLAYCHANGE messages. */ -Bool +static Bool winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen) { winScreenPriv(pScreen); HRESULT ddrval = DD_OK; DDSURFACEDESC2 ddsd; - ErrorF ("winCreatePrimarySurfaceShadowDDNL - Creating primary surface\n"); + winDebug ("winCreatePrimarySurfaceShadowDDNL - Creating primary surface\n"); /* Describe the primary surface */ ZeroMemory (&ddsd, sizeof (ddsd)); @@ -84,12 +145,12 @@ winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen) { ErrorF ("winCreatePrimarySurfaceShadowDDNL - Could not create primary " "surface: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if 1 - ErrorF ("winCreatePrimarySurfaceShadowDDNL - Created primary surface\n"); + winDebug ("winCreatePrimarySurfaceShadowDDNL - Created primary surface\n"); #endif /* Attach our clipper to our primary surface handle */ @@ -99,12 +160,12 @@ winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen) { ErrorF ("winCreatePrimarySurfaceShadowDDNL - Primary attach clipper " "failed: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if 1 - ErrorF ("winCreatePrimarySurfaceShadowDDNL - Attached clipper to primary " + winDebug ("winCreatePrimarySurfaceShadowDDNL - Attached clipper to primary " "surface\n"); #endif @@ -118,12 +179,12 @@ winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen) * Called from WM_DISPLAYCHANGE. */ -Bool +static Bool winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen) { winScreenPriv(pScreen); - ErrorF ("winReleasePrimarySurfaceShadowDDNL - Hello\n"); + winDebug ("winReleasePrimarySurfaceShadowDDNL - Hello\n"); /* Release the primary surface and clipper, if they exist */ if (pScreenPriv->pddsPrimary4) @@ -135,14 +196,14 @@ winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen) IDirectDrawSurface4_SetClipper (pScreenPriv->pddsPrimary4, NULL); - ErrorF ("winReleasePrimarySurfaceShadowDDNL - Detached clipper\n"); + winDebug ("winReleasePrimarySurfaceShadowDDNL - Detached clipper\n"); /* Release the primary surface */ IDirectDrawSurface4_Release (pScreenPriv->pddsPrimary4); pScreenPriv->pddsPrimary4 = NULL; } - ErrorF ("winReleasePrimarySurfaceShadowDDNL - Released primary surface\n"); + winDebug ("winReleasePrimarySurfaceShadowDDNL - Released primary surface\n"); return TRUE; } @@ -167,7 +228,7 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) DDPIXELFORMAT ddpfPrimary; #if CYGDEBUG - ErrorF ("winAllocateFBShadowDDNL - w %d h %d d %d\n", + winDebug ("winAllocateFBShadowDDNL - w %d h %d d %d\n", pScreenInfo->dwWidth, pScreenInfo->dwHeight, pScreenInfo->dwDepth); #endif @@ -192,12 +253,12 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) if (FAILED (ddrval)) { ErrorF ("winAllocateFBShadowDDNL - Could not attach clipper: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winAllocateFBShadowDDNL - Created a clipper\n"); + winDebug ("winAllocateFBShadowDDNL - Created a clipper\n"); #endif /* Get a device context for the screen */ @@ -211,12 +272,12 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDDNL - Clipper not attached " "to window: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winAllocateFBShadowDDNL - Attached clipper to window\n"); + winDebug ("winAllocateFBShadowDDNL - Attached clipper to window\n"); #endif /* Create a DirectDraw object, store the address at lpdd */ @@ -227,12 +288,12 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDDNL - Could not start " "DirectDraw: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winAllocateFBShadowDDNL - Created and initialized DD\n"); + winDebug ("winAllocateFBShadowDDNL - Created and initialized DD\n"); #endif /* Get a DirectDraw4 interface pointer */ @@ -242,7 +303,7 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) if (FAILED (ddrval)) { ErrorF ("winAllocateFBShadowDDNL - Failed DD4 query: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } @@ -262,7 +323,7 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDDNL - Could not set " "cooperative level: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } @@ -282,7 +343,7 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDDNL - Could not get current " "refresh rate: %08x. Continuing.\n", - ddrval); + (unsigned int) ddrval); dwRefreshRateCurrent = 0; } else @@ -316,7 +377,7 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) || pScreenInfo->dwBPP != GetDeviceCaps (hdc, BITSPIXEL) || pScreenInfo->dwRefreshRate != 0)) { - ErrorF ("winAllocateFBShadowDDNL - Changing video mode\n"); + winDebug ("winAllocateFBShadowDDNL - Changing video mode\n"); /* Change the video mode to the mode requested */ ddrval = IDirectDraw4_SetDisplayMode (pScreenPriv->pdd4, @@ -329,13 +390,13 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDDNL - Could not set " "full screen display mode: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } } else { - ErrorF ("winAllocateFBShadowDDNL - Not changing video mode\n"); + winDebug ("winAllocateFBShadowDDNL - Not changing video mode\n"); } /* Release our DC */ @@ -352,7 +413,7 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDDNL - Could not set " "cooperative level: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } } @@ -374,12 +435,12 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) { ErrorF ("winAllocateFBShadowDDNL - Could not get primary " "pixformat: %08x\n", - ddrval); + (unsigned int) ddrval); return FALSE; } #if CYGDEBUG - ErrorF ("winAllocateFBShadowDDNL - Primary masks: %08x %08x %08x " + winDebug ("winAllocateFBShadowDDNL - Primary masks: %08x %08x %08x " "dwRGBBitCount: %d\n", ddpfPrimary.u2.dwRBitMask, ddpfPrimary.u3.dwGBitMask, @@ -407,8 +468,8 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) ddsdShadow.lpSurface = lpSurface; ddsdShadow.u4.ddpfPixelFormat = ddpfPrimary; - ErrorF ("winAllocateFBShadowDDNL - lPitch: %d\n", - pScreenInfo->dwPaddedWidth); + winDebug ("winAllocateFBShadowDDNL - lPitch: %d\n", + (int) pScreenInfo->dwPaddedWidth); /* Create the shadow surface */ ddrval = IDirectDraw4_CreateSurface (pScreenPriv->pdd4, @@ -418,13 +479,13 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) if (FAILED (ddrval)) { ErrorF ("winAllocateFBShadowDDNL - Could not create shadow " - "surface: %08x\n", ddrval); + "surface: %08x\n", (unsigned int) ddrval); return FALSE; } #if CYGDEBUG || YES - ErrorF ("winAllocateFBShadowDDNL - Created shadow pitch: %d\n", - ddsdShadow.u1.lPitch); + winDebug ("winAllocateFBShadowDDNL - Created shadow pitch: %d\n", + (int) ddsdShadow.u1.lPitch); #endif /* Grab the pitch from the surface desc */ @@ -432,8 +493,8 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) / pScreenInfo->dwBPP; #if CYGDEBUG || YES - ErrorF ("winAllocateFBShadowDDNL - Created shadow stride: %d\n", - pScreenInfo->dwStride); + winDebug ("winAllocateFBShadowDDNL - Created shadow stride: %d\n", + (int) pScreenInfo->dwStride); #endif /* Save the pointer to our surface memory */ @@ -445,7 +506,7 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) pScreenPriv->dwBlueMask = ddsdShadow.u4.ddpfPixelFormat.u4.dwBBitMask; #if CYGDEBUG - ErrorF ("winAllocateFBShadowDDNL - Returning\n"); + winDebug ("winAllocateFBShadowDDNL - Returning\n"); #endif return TRUE; @@ -453,10 +514,57 @@ winAllocateFBShadowDDNL (ScreenPtr pScreen) /* + * Create a DirectDraw surface for the new multi-window window + */ + +static +Bool +winFinishCreateWindowsWindowDDNL (WindowPtr pWin) +{ + winWindowPriv(pWin); + winPrivScreenPtr pScreenPriv = pWinPriv->pScreenPriv; + HRESULT ddrval = DD_OK; + DDSURFACEDESC2 ddsd; + int iWidth, iHeight; + int iX, iY; + + winDebug ("\nwinFinishCreateWindowsWindowDDNL!\n\n"); + + iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN); + iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN); + + iWidth = pWin->drawable.width; + iHeight = pWin->drawable.height; + + /* Describe the primary surface */ + ZeroMemory (&ddsd, sizeof (ddsd)); + ddsd.dwSize = sizeof (ddsd); + ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + ddsd.dwHeight = iHeight; + ddsd.dwWidth = iWidth; + + /* Create the primary surface */ + ddrval = IDirectDraw4_CreateSurface (pScreenPriv->pdd4, + &ddsd, + &pWinPriv->pddsPrimary4, + NULL); + if (FAILED (ddrval)) + { + ErrorF ("winFinishCreateWindowsWindowDDNL - Could not create primary " + "surface: %08x\n", + (unsigned int)ddrval); + return FALSE; + } + return TRUE; +} + + +/* * Transfer the damaged regions of the shadow framebuffer to the display. */ -void +static void winShadowUpdateDDNL (ScreenPtr pScreen, shadowBufPtr pBuf) { @@ -522,7 +630,7 @@ winShadowUpdateDDNL (ScreenPtr pScreen, { ErrorF ("winShadowUpdateDDNL - IDirectDrawSurface4_Blt () " "failed: %08x\n", - ddrval); + (unsigned int) ddrval); ++s_iFailCount; @@ -530,7 +638,7 @@ winShadowUpdateDDNL (ScreenPtr pScreen, { ErrorF ("winShadowUpdateDDNL - IDirectDrawSurface4_Blt " "failure message maximum (%d) reached. No " - "more failure messages will be printed.", + "more failure messages will be printed.\n", FAIL_MSG_MAX_BLT); } } @@ -562,7 +670,7 @@ winShadowUpdateDDNL (ScreenPtr pScreen, hrgnCombined = NULL; #if CYGDEBUG - ErrorF ("winShadowUpdateDDNL - be x1 %d y1 %d x2 %d y2 %d\n", + winDebug ("winShadowUpdateDDNL - be x1 %d y1 %d x2 %d y2 %d\n", pBoxExtents->x1, pBoxExtents->y1, pBoxExtents->x2, pBoxExtents->y2); #endif @@ -599,7 +707,7 @@ winShadowUpdateDDNL (ScreenPtr pScreen, * Free our resources and private structures. */ -Bool +static Bool winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -607,7 +715,7 @@ winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen) Bool fReturn; #if CYGDEBUG - ErrorF ("winCloseScreenShadowDDNL - Freeing screen resources\n"); + winDebug ("winCloseScreenShadowDDNL - Freeing screen resources\n"); #endif /* Flag that the screen is closed */ @@ -685,8 +793,10 @@ winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen) pScreenPriv->hwndScreen = NULL; } +#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) /* Destroy the thread startup mutex */ pthread_mutex_destroy (&pScreenPriv->pmServerStarted); +#endif /* Kill our screeninfo's pointer to the screen */ pScreenInfo->pScreen = NULL; @@ -709,7 +819,7 @@ winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen) * to verify that last sentence. */ -Bool +static Bool winInitVisualsShadowDDNL (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -731,14 +841,14 @@ winInitVisualsShadowDDNL (ScreenPtr pScreen) else pScreenPriv->dwBitsPerRGB = dwBlueBits; - ErrorF ("winInitVisualsShadowDDNL - Masks %08x %08x %08x BPRGB %d d %d " + winDebug ("winInitVisualsShadowDDNL - Masks %08x %08x %08x BPRGB %d d %d " "bpp %d\n", - pScreenPriv->dwRedMask, - pScreenPriv->dwGreenMask, - pScreenPriv->dwBlueMask, - pScreenPriv->dwBitsPerRGB, - pScreenInfo->dwDepth, - pScreenInfo->dwBPP); + (unsigned int) pScreenPriv->dwRedMask, + (unsigned int) pScreenPriv->dwGreenMask, + (unsigned int) pScreenPriv->dwBlueMask, + (int) pScreenPriv->dwBitsPerRGB, + (int) pScreenInfo->dwDepth, + (int) pScreenInfo->dwBPP); /* Create a single visual according to the Windows screen depth */ switch (pScreenInfo->dwDepth) @@ -761,7 +871,7 @@ winInitVisualsShadowDDNL (ScreenPtr pScreen) return FALSE; } -#if WIN_EMULATE_PSEUDO_SUPPORT +#ifdef XWIN_EMULATEPSEUDO if (!pScreenInfo->fEmulatePseudo) break; @@ -793,7 +903,7 @@ winInitVisualsShadowDDNL (ScreenPtr pScreen) return FALSE; } -#if WIN_EMULATE_PSEUDO_SUPPORT +#ifdef XWIN_EMULATEPSEUDO if (!pScreenInfo->fEmulatePseudo) break; @@ -851,7 +961,7 @@ winInitVisualsShadowDDNL (ScreenPtr pScreen) } #if CYGDEBUG - ErrorF ("winInitVisualsShadowDDNL - Returning\n"); + winDebug ("winInitVisualsShadowDDNL - Returning\n"); #endif return TRUE; @@ -862,7 +972,7 @@ winInitVisualsShadowDDNL (ScreenPtr pScreen) * Adjust the user proposed video mode */ -Bool +static Bool winAdjustVideoModeShadowDDNL (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -885,8 +995,8 @@ winAdjustVideoModeShadowDDNL (ScreenPtr pScreen) if (pScreenInfo->dwBPP == WIN_DEFAULT_BPP) { /* No -depth parameter passed, let the user know the depth being used */ - ErrorF ("winAdjustVideoModeShadowDDNL - Using Windows display " - "depth of %d bits per pixel\n", dwBPP); + winErrorFVerb (2, "winAdjustVideoModeShadowDDNL - Using Windows display " + "depth of %d bits per pixel\n", (int) dwBPP); /* Use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -895,15 +1005,15 @@ winAdjustVideoModeShadowDDNL (ScreenPtr pScreen) && pScreenInfo->dwBPP != dwBPP) { /* FullScreen, and GDI depth differs from -depth parameter */ - ErrorF ("winAdjustVideoModeShadowDDNL - FullScreen, using command " - "line bpp: %d\n", pScreenInfo->dwBPP); + winErrorFVerb (2, "winAdjustVideoModeShadowDDNL - FullScreen, using command " + "line bpp: %d\n", (int) pScreenInfo->dwBPP); } else if (dwBPP != pScreenInfo->dwBPP) { /* Windowed, and GDI depth differs from -depth parameter */ - ErrorF ("winAdjustVideoModeShadowDDNL - Windowed, command line " + winErrorFVerb (2, "winAdjustVideoModeShadowDDNL - Windowed, command line " "bpp: %d, using bpp: %d\n", - pScreenInfo->dwBPP, dwBPP); + (int) pScreenInfo->dwBPP, (int) dwBPP); /* We'll use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -913,7 +1023,7 @@ winAdjustVideoModeShadowDDNL (ScreenPtr pScreen) if (pScreenInfo->dwWidth * pScreenInfo->dwHeight * pScreenInfo->dwBPP >= WIN_DIB_MAXIMUM_SIZE) { - ErrorF ("winAdjustVideoModeShadowDDNL - Requested DirectDraw surface " + winErrorFVerb (1, "winAdjustVideoModeShadowDDNL - Requested DirectDraw surface " "will be larger than %d MB. The surface may fail to be " "allocated on Windows 95, 98, or Me, due to a %d MB limit in " "DIB size. This limit does not apply to Windows NT/2000, and " @@ -932,7 +1042,7 @@ winAdjustVideoModeShadowDDNL (ScreenPtr pScreen) * Blt exposed regions to the screen */ -Bool +static Bool winBltExposedRegionsShadowDDNL (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -986,29 +1096,29 @@ winBltExposedRegionsShadowDDNL (ScreenPtr pScreen) if (ddrval == DDERR_SURFACELOST) { /* Surface was lost */ - ErrorF ("winBltExposedRegionsShadowDDNL - IDirectDrawSurface4_Blt " - "reported that the primary surface was lost, " - "trying to restore, retry: %d\n", i + 1); + winErrorFVerb (1, "winBltExposedRegionsShadowDDNL - " + "IDirectDrawSurface4_Blt reported that the primary " + "surface was lost, trying to restore, retry: %d\n", i + 1); /* Try to restore the surface, once */ ddrval = IDirectDrawSurface4_Restore (pScreenPriv->pddsPrimary4); - ErrorF ("winBltExposedRegionsShadowDDNL - " + winDebug ("winBltExposedRegionsShadowDDNL - " "IDirectDrawSurface4_Restore returned: "); if (ddrval == DD_OK) - continue; + winDebug ("DD_OK\n"); else if (ddrval == DDERR_WRONGMODE) - ErrorF ("DDERR_WRONGMODE\n"); + winDebug ("DDERR_WRONGMODE\n"); else if (ddrval == DDERR_INCOMPATIBLEPRIMARY) - ErrorF ("DDERR_INCOMPATIBLEPRIMARY\n"); + winDebug ("DDERR_INCOMPATIBLEPRIMARY\n"); else if (ddrval == DDERR_UNSUPPORTED) - ErrorF ("DDERR_UNSUPPORTED\n"); + winDebug ("DDERR_UNSUPPORTED\n"); else if (ddrval == DDERR_INVALIDPARAMS) - ErrorF ("DDERR_INVALIDPARAMS\n"); + winDebug ("DDERR_INVALIDPARAMS\n"); else if (ddrval == DDERR_INVALIDOBJECT) - ErrorF ("DDERR_INVALIDOBJECT\n"); + winDebug ("DDERR_INVALIDOBJECT\n"); else - ErrorF ("unknown error: %08x\n", ddrval); + winDebug ("unknown error: %08x\n", (unsigned int) ddrval); /* Loop around to try the blit one more time */ continue; @@ -1016,8 +1126,10 @@ winBltExposedRegionsShadowDDNL (ScreenPtr pScreen) else if (FAILED (ddrval)) { fReturn = FALSE; - ErrorF ("winBltExposedRegionsShadowDDNL - IDirectDrawSurface4_Blt " - "failed, but surface not lost: %08x %d\n", ddrval, ddrval); + winErrorFVerb (1, "winBltExposedRegionsShadowDDNL - " + "IDirectDrawSurface4_Blt failed, but surface not " + "lost: %08x %d\n", + (unsigned int) ddrval, (int) ddrval); goto winBltExposedRegionsShadowDDNL_Exit; } else @@ -1036,10 +1148,10 @@ winBltExposedRegionsShadowDDNL (ScreenPtr pScreen) /* - * Do any engine-specific appliation-activation processing + * Do any engine-specific application-activation processing */ -Bool +static Bool winActivateAppShadowDDNL (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -1065,7 +1177,7 @@ winActivateAppShadowDDNL (ScreenPtr pScreen) * Reblit the shadow framebuffer to the screen. */ -Bool +static Bool winRedrawScreenShadowDDNL (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -1102,7 +1214,7 @@ winRedrawScreenShadowDDNL (ScreenPtr pScreen) { ErrorF ("winRedrawScreenShadowDDNL - IDirectDrawSurface4_Blt () " "failed: %08x\n", - ddrval); + (unsigned int) ddrval); } return TRUE; @@ -1113,7 +1225,7 @@ winRedrawScreenShadowDDNL (ScreenPtr pScreen) * Realize the currently installed colormap */ -Bool +static Bool winRealizeInstalledPaletteShadowDDNL (ScreenPtr pScreen) { return TRUE; @@ -1124,7 +1236,7 @@ winRealizeInstalledPaletteShadowDDNL (ScreenPtr pScreen) * Install the specified colormap */ -Bool +static Bool winInstallColormapShadowDDNL (ColormapPtr pColormap) { ScreenPtr pScreen = pColormap->pScreen; @@ -1153,7 +1265,7 @@ winInstallColormapShadowDDNL (ColormapPtr pColormap) * Store the specified colors in the specified colormap */ -Bool +static Bool winStoreColorsShadowDDNL (ColormapPtr pColormap, int ndef, xColorItem *pdefs) @@ -1197,7 +1309,7 @@ winStoreColorsShadowDDNL (ColormapPtr pColormap, * Colormap initialization procedure */ -Bool +static Bool winCreateColormapShadowDDNL (ColormapPtr pColormap) { HRESULT ddrval = DD_OK; @@ -1225,7 +1337,7 @@ winCreateColormapShadowDDNL (ColormapPtr pColormap) * Colormap destruction procedure */ -Bool +static Bool winDestroyColormapShadowDDNL (ColormapPtr pColormap) { winScreenPriv(pColormap->pScreen); @@ -1243,8 +1355,7 @@ winDestroyColormapShadowDDNL (ColormapPtr pColormap) if (pColormap->flags & IsDefault) { #if CYGDEBUG - ErrorF ("winDestroyColormapShadowDDNL - Destroying default " - "colormap\n"); + winDebug ("winDestroyColormapShadowDDNL - Destroying default colormap\n"); #endif /* @@ -1306,11 +1417,13 @@ winSetEngineFunctionsShadowDDNL (ScreenPtr pScreen) pScreenPriv->pwinStoreColors = winStoreColorsShadowDDNL; pScreenPriv->pwinCreateColormap = winCreateColormapShadowDDNL; pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowDDNL; - pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)())NoopDDA; + pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA; pScreenPriv->pwinCreatePrimarySurface = winCreatePrimarySurfaceShadowDDNL; pScreenPriv->pwinReleasePrimarySurface = winReleasePrimarySurfaceShadowDDNL; +#ifdef XWIN_MULTIWINDOW + pScreenPriv->pwinFinishCreateWindowsWindow + = winFinishCreateWindowsWindowDDNL; +#endif return TRUE; } - - diff --git a/hw/xwin/winshadgdi.c b/hw/xwin/winshadgdi.c index 29ce6761b..71a993acf 100644 --- a/hw/xwin/winshadgdi.c +++ b/hw/xwin/winshadgdi.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,29 +15,86 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winshadgdi.c,v 1.21 2002/10/17 08:18:25 alanh Exp $ */ #include "win.h" + +/* + * External symbols + */ + +#ifdef XWIN_MULTIWINDOW +extern DWORD g_dwCurrentThreadID; +#endif +extern HWND g_hDlgExit; + + /* * Local function prototypes */ -BOOL CALLBACK +#ifdef XWIN_MULTIWINDOW +static BOOL CALLBACK winRedrawAllProcShadowGDI (HWND hwnd, LPARAM lParam); +static BOOL CALLBACK +winRedrawDamagedWindowShadowGDI (HWND hwnd, LPARAM lParam); +#endif + +static Bool +winAllocateFBShadowGDI (ScreenPtr pScreen); + +static void +winShadowUpdateGDI (ScreenPtr pScreen, + shadowBufPtr pBuf); + +static Bool +winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen); + +static Bool +winInitVisualsShadowGDI (ScreenPtr pScreen); + +static Bool +winAdjustVideoModeShadowGDI (ScreenPtr pScreen); + +static Bool +winBltExposedRegionsShadowGDI (ScreenPtr pScreen); + +static Bool +winActivateAppShadowGDI (ScreenPtr pScreen); + +static Bool +winRedrawScreenShadowGDI (ScreenPtr pScreen); + +static Bool +winRealizeInstalledPaletteShadowGDI (ScreenPtr pScreen); + +static Bool +winInstallColormapShadowGDI (ColormapPtr pColormap); + +static Bool +winStoreColorsShadowGDI (ColormapPtr pmap, + int ndef, + xColorItem *pdefs); + +static Bool +winCreateColormapShadowGDI (ColormapPtr pColormap); + +static Bool +winDestroyColormapShadowGDI (ColormapPtr pColormap); + /* * Internal function to get the DIB format that is compatible with the screen @@ -82,7 +139,7 @@ winQueryScreenDIBFormat (ScreenPtr pScreen, BITMAPINFOHEADER *pbmih) /* Get a pointer to bitfields */ pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER)); - ErrorF ("winQueryScreenDIBFormat - First call masks: %08x %08x %08x\n", + winDebug ("winQueryScreenDIBFormat - First call masks: %08x %08x %08x\n", pdw[0], pdw[1], pdw[2]); #endif @@ -169,27 +226,53 @@ winQueryRGBBitsAndMasks (ScreenPtr pScreen) pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER)); #if CYGDEBUG - ErrorF ("winQueryRGBBitsAndMasks - Masks: %08x %08x %08x\n", + winDebug ("%s - Masks: %08x %08x %08x\n", __FUNCTION__, pdw[0], pdw[1], pdw[2]); + winDebug ("%s - Bitmap: %dx%d %d bpp %d planes\n", __FUNCTION__, + pbmih->biWidth, pbmih->biHeight, pbmih->biBitCount, pbmih->biPlanes); + winDebug ("%s - Compression: %d %s\n", __FUNCTION__, + pbmih->biCompression, + (pbmih->biCompression == BI_RGB?"(BI_RGB)": + (pbmih->biCompression == BI_RLE8?"(BI_RLE8)": + (pbmih->biCompression == BI_RLE4?"(BI_RLE4)": + (pbmih->biCompression == BI_BITFIELDS?"(BI_BITFIELDS)":"" + ))))); #endif - /* Count the number of bits in each mask */ - dwRedBits = winCountBits (pdw[0]); - dwGreenBits = winCountBits (pdw[1]); - dwBlueBits = winCountBits (pdw[2]); - - /* Find maximum bits per red, green, blue */ - if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits) - pScreenPriv->dwBitsPerRGB = dwRedBits; - else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits) - pScreenPriv->dwBitsPerRGB = dwGreenBits; - else - pScreenPriv->dwBitsPerRGB = dwBlueBits; - - /* Set screen privates masks */ - pScreenPriv->dwRedMask = pdw[0]; - pScreenPriv->dwGreenMask = pdw[1]; - pScreenPriv->dwBlueMask = pdw[2]; + /* Handle BI_RGB case, which is returned by Wine */ + if (pbmih->biCompression == BI_RGB) + { + dwRedBits = 5; + dwGreenBits = 5; + dwBlueBits = 5; + + pScreenPriv->dwBitsPerRGB = 5; + + /* Set screen privates masks */ + pScreenPriv->dwRedMask = 0x7c00; + pScreenPriv->dwGreenMask = 0x03e0; + pScreenPriv->dwBlueMask = 0x001f; + } + else + { + /* Count the number of bits in each mask */ + dwRedBits = winCountBits (pdw[0]); + dwGreenBits = winCountBits (pdw[1]); + dwBlueBits = winCountBits (pdw[2]); + + /* Find maximum bits per red, green, blue */ + if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits) + pScreenPriv->dwBitsPerRGB = dwRedBits; + else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits) + pScreenPriv->dwBitsPerRGB = dwGreenBits; + else + pScreenPriv->dwBitsPerRGB = dwBlueBits; + + /* Set screen privates masks */ + pScreenPriv->dwRedMask = pdw[0]; + pScreenPriv->dwGreenMask = pdw[1]; + pScreenPriv->dwBlueMask = pdw[2]; + } } else { @@ -205,32 +288,59 @@ winQueryRGBBitsAndMasks (ScreenPtr pScreen) } +#ifdef XWIN_MULTIWINDOW /* * Redraw all ---? */ -BOOL CALLBACK +static BOOL CALLBACK winRedrawAllProcShadowGDI (HWND hwnd, LPARAM lParam) { - char strClassName[100]; + if (hwnd == (HWND)lParam) + return TRUE; + InvalidateRect (hwnd, NULL, FALSE); + UpdateWindow (hwnd); + return TRUE; +} - if (GetClassName (hwnd, strClassName, 100)) +static BOOL CALLBACK +winRedrawDamagedWindowShadowGDI (HWND hwnd, LPARAM lParam) +{ + BoxPtr pDamage = (BoxPtr)lParam; + RECT rcClient, rcDamage, rcRedraw; + POINT topLeft, bottomRight; + + if (IsIconic (hwnd)) + return TRUE; /* Don't care minimized windows */ + + /* Convert the damaged area from Screen coords to Client coords */ + topLeft.x = pDamage->x1; topLeft.y = pDamage->y1; + bottomRight.x = pDamage->x2; bottomRight.y = pDamage->y2; + topLeft.x += GetSystemMetrics (SM_XVIRTUALSCREEN); + bottomRight.x += GetSystemMetrics (SM_XVIRTUALSCREEN); + topLeft.y += GetSystemMetrics (SM_YVIRTUALSCREEN); + bottomRight.y += GetSystemMetrics (SM_YVIRTUALSCREEN); + ScreenToClient (hwnd, &topLeft); + ScreenToClient (hwnd, &bottomRight); + SetRect (&rcDamage, topLeft.x, topLeft.y, bottomRight.x, bottomRight.y); + + GetClientRect (hwnd, &rcClient); + + if (IntersectRect (&rcRedraw, &rcClient, &rcDamage)) { - if (strncmp (WINDOW_CLASS_X, strClassName, strlen (WINDOW_CLASS_X)) == 0) - { - InvalidateRect (hwnd, NULL, FALSE); - UpdateWindow (hwnd); - } + InvalidateRect (hwnd, &rcRedraw, FALSE); + UpdateWindow (hwnd); } return TRUE; } +#endif /* * Allocate a DIB for the shadow framebuffer GDI server */ -Bool +static Bool winAllocateFBShadowGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -261,7 +371,7 @@ winAllocateFBShadowGDI (ScreenPtr pScreen) ErrorF ("winAllocateFBShadowGDI - Creating DIB with width: %d height: %d " "depth: %d\n", - pbmih->biWidth, -pbmih->biHeight, pbmih->biBitCount); + (int) pbmih->biWidth, (int) -pbmih->biHeight, pbmih->biBitCount); /* Create a DI shadow bitmap with a bit pointer */ pScreenPriv->hbmpShadow = CreateDIBSection (pScreenPriv->hdcScreen, @@ -272,13 +382,13 @@ winAllocateFBShadowGDI (ScreenPtr pScreen) 0); if (pScreenPriv->hbmpShadow == NULL || pScreenInfo->pfb == NULL) { - ErrorF ("winAllocateFBShadowGDI - CreateDIBSection failed\n"); + winW32Error (2, "winAllocateFBShadowGDI - CreateDIBSection failed:"); return FALSE; } else { #if CYGDEBUG - ErrorF ("winAllocateFBShadowGDI - Shadow buffer allocated\n"); + winDebug ("winAllocateFBShadowGDI - Shadow buffer allocated\n"); #endif } @@ -289,11 +399,11 @@ winAllocateFBShadowGDI (ScreenPtr pScreen) #if CYGDEBUG || YES /* Print information about bitmap allocated */ - ErrorF ("winAllocateFBShadowGDI - Dibsection width: %d height: %d " + winDebug ("winAllocateFBShadowGDI - Dibsection width: %d height: %d " "depth: %d size image: %d\n", - dibsection.dsBmih.biWidth, dibsection.dsBmih.biHeight, + (int) dibsection.dsBmih.biWidth, (int) dibsection.dsBmih.biHeight, dibsection.dsBmih.biBitCount, - dibsection.dsBmih.biSizeImage); + (int) dibsection.dsBmih.biSizeImage); #endif /* Select the shadow bitmap into the shadow DC */ @@ -301,7 +411,7 @@ winAllocateFBShadowGDI (ScreenPtr pScreen) pScreenPriv->hbmpShadow); #if CYGDEBUG - ErrorF ("winAllocateFBShadowGDI - Attempting a shadow blit\n"); + winDebug ("winAllocateFBShadowGDI - Attempting a shadow blit\n"); #endif /* Do a test blit from the shadow to the screen, I think */ @@ -314,23 +424,25 @@ winAllocateFBShadowGDI (ScreenPtr pScreen) if (fReturn) { #if CYGDEBUG - ErrorF ("winAllocateFBShadowGDI - Shadow blit success\n"); + winDebug ("winAllocateFBShadowGDI - Shadow blit success\n"); #endif } else { - ErrorF ("winAllocateFBShadowGDI - Shadow blit failure\n"); + winW32Error (2, "winAllocateFBShadowGDI - Shadow blit failure\n"); +#if 0 return FALSE; +#else + /* ago: ignore this error. The blit fails with wine, but does not + * cause any problems later. */ + + fReturn = TRUE; +#endif } /* Look for height weirdness */ if (dibsection.dsBmih.biHeight < 0) { - /* FIXME: Figure out why biHeight is sometimes negative */ - ErrorF ("winAllocateFBShadowGDI - WEIRDNESS - biHeight " - "still negative: %d\n" - "winAllocateFBShadowGDI - WEIRDNESS - Flipping biHeight sign\n", - dibsection.dsBmih.biHeight); dibsection.dsBmih.biHeight = -dibsection.dsBmih.biHeight; } @@ -340,8 +452,8 @@ winAllocateFBShadowGDI (ScreenPtr pScreen) * 8) / pScreenInfo->dwBPP; #if CYGDEBUG || YES - ErrorF ("winAllocateFBShadowGDI - Created shadow stride: %d\n", - pScreenInfo->dwStride); + winDebug ("winAllocateFBShadowGDI - Created shadow stride: %d\n", + (int) pScreenInfo->dwStride); #endif /* See if the shadow bitmap will be larger than the DIB size limit */ @@ -363,8 +475,11 @@ winAllocateFBShadowGDI (ScreenPtr pScreen) return FALSE; } +#ifdef XWIN_MULTIWINDOW /* Redraw all windows */ - if (pScreenInfo->fMultiWindow) EnumWindows(winRedrawAllProcShadowGDI, 0); + if (pScreenInfo->fMultiWindow) + EnumThreadWindows (g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0); +#endif return fReturn; } @@ -374,7 +489,7 @@ winAllocateFBShadowGDI (ScreenPtr pScreen) * Blit the damaged regions of the shadow fb to the screen */ -void +static void winShadowUpdateGDI (ScreenPtr pScreen, shadowBufPtr pBuf) { @@ -385,11 +500,12 @@ winShadowUpdateGDI (ScreenPtr pScreen, BoxPtr pBox = REGION_RECTS (damage); int x, y, w, h; HRGN hrgnTemp = NULL, hrgnCombined = NULL; -#if WIN_UPDATE_STATS +#ifdef XWIN_UPDATESTATS static DWORD s_dwNonUnitRegions = 0; static DWORD s_dwTotalUpdates = 0; static DWORD s_dwTotalBoxes = 0; #endif + BoxPtr pBoxExtents = REGION_EXTENTS (pScreen, damage); /* * Return immediately if the app is not active @@ -398,7 +514,7 @@ winShadowUpdateGDI (ScreenPtr pScreen, if ((!pScreenPriv->fActive && pScreenInfo->fFullScreen) || pScreenPriv->fBadDepth) return; -#if WIN_UPDATE_STATS +#ifdef XWIN_UPDATESTATS ++s_dwTotalUpdates; s_dwTotalBoxes += dwBox; @@ -414,7 +530,7 @@ winShadowUpdateGDI (ScreenPtr pScreen, (s_dwNonUnitRegions * 100) / s_dwTotalUpdates, s_dwTotalBoxes / s_dwTotalUpdates, s_dwNonUnitRegions, s_dwTotalUpdates); -#endif /* WIN_UPDATE_STATS */ +#endif /* XWIN_UPDATESTATS */ /* * Handle small regions with multiple blits, @@ -449,8 +565,6 @@ winShadowUpdateGDI (ScreenPtr pScreen, } else { - BoxPtr pBoxExtents = REGION_EXTENTS (pScreen, damage); - /* Compute a GDI region from the damaged region */ hrgnCombined = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2); dwBox--; @@ -484,8 +598,13 @@ winShadowUpdateGDI (ScreenPtr pScreen, SelectClipRgn (pScreenPriv->hdcScreen, NULL); } - /* Redraw all windows */ - if (pScreenInfo->fMultiWindow) EnumWindows(winRedrawAllProcShadowGDI, 0); +#ifdef XWIN_MULTIWINDOW + /* Redraw all multiwindow windows */ + if (pScreenInfo->fMultiWindow) + EnumThreadWindows (g_dwCurrentThreadID, + winRedrawDamagedWindowShadowGDI, + (LPARAM)pBoxExtents); +#endif } @@ -495,7 +614,7 @@ winShadowUpdateGDI (ScreenPtr pScreen, * a pointer to said procedure is stored in our privates. */ -Bool +static Bool winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -503,7 +622,7 @@ winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen) Bool fReturn; #if CYGDEBUG - ErrorF ("winCloseScreenShadowGDI - Freeing screen resources\n"); + winDebug ("winCloseScreenShadowGDI - Freeing screen resources\n"); #endif /* Flag that the screen is closed */ @@ -544,8 +663,10 @@ winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen) pScreenPriv->hwndScreen = NULL; } +#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) /* Destroy the thread startup mutex */ pthread_mutex_destroy (&pScreenPriv->pmServerStarted); +#endif /* Invalidate our screeninfo's pointer to the screen */ pScreenInfo->pScreen = NULL; @@ -568,7 +689,7 @@ winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen) * to verify that last sentence. */ -Bool +static Bool winInitVisualsShadowGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -577,12 +698,12 @@ winInitVisualsShadowGDI (ScreenPtr pScreen) /* Display debugging information */ ErrorF ("winInitVisualsShadowGDI - Masks %08x %08x %08x BPRGB %d d %d " "bpp %d\n", - pScreenPriv->dwRedMask, - pScreenPriv->dwGreenMask, - pScreenPriv->dwBlueMask, - pScreenPriv->dwBitsPerRGB, - pScreenInfo->dwDepth, - pScreenInfo->dwBPP); + (unsigned int) pScreenPriv->dwRedMask, + (unsigned int) pScreenPriv->dwGreenMask, + (unsigned int) pScreenPriv->dwBlueMask, + (int) pScreenPriv->dwBitsPerRGB, + (int) pScreenInfo->dwDepth, + (int) pScreenInfo->dwBPP); /* Create a single visual according to the Windows screen depth */ switch (pScreenInfo->dwDepth) @@ -605,7 +726,7 @@ winInitVisualsShadowGDI (ScreenPtr pScreen) return FALSE; } -#if WIN_EMULATE_PSEUDO_SUPPORT +#ifdef XWIN_EMULATEPSEUDO if (!pScreenInfo->fEmulatePseudo) break; @@ -637,7 +758,7 @@ winInitVisualsShadowGDI (ScreenPtr pScreen) return FALSE; } -#if WIN_EMULATE_PSEUDO_SUPPORT +#ifdef XWIN_EMULATEPSEUDO if (!pScreenInfo->fEmulatePseudo) break; @@ -692,7 +813,7 @@ winInitVisualsShadowGDI (ScreenPtr pScreen) } #if CYGDEBUG - ErrorF ("winInitVisualsShadowGDI - Returning\n"); + winDebug ("winInitVisualsShadowGDI - Returning\n"); #endif return TRUE; @@ -703,7 +824,7 @@ winInitVisualsShadowGDI (ScreenPtr pScreen) * Adjust the proposed video mode */ -Bool +static Bool winAdjustVideoModeShadowGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -728,7 +849,7 @@ winAdjustVideoModeShadowGDI (ScreenPtr pScreen) { /* No -depth parameter passed, let the user know the depth being used */ ErrorF ("winAdjustVideoModeShadowGDI - Using Windows display " - "depth of %d bits per pixel\n", dwBPP); + "depth of %d bits per pixel\n", (int) dwBPP); /* Use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -737,7 +858,7 @@ winAdjustVideoModeShadowGDI (ScreenPtr pScreen) { /* Warn user if GDI depth is different than -depth parameter */ ErrorF ("winAdjustVideoModeShadowGDI - Command line bpp: %d, "\ - "using bpp: %d\n", pScreenInfo->dwBPP, dwBPP); + "using bpp: %d\n", (int) pScreenInfo->dwBPP, (int) dwBPP); /* We'll use GDI's depth */ pScreenInfo->dwBPP = dwBPP; @@ -755,7 +876,7 @@ winAdjustVideoModeShadowGDI (ScreenPtr pScreen) * Blt exposed regions to the screen */ -Bool +static Bool winBltExposedRegionsShadowGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -787,8 +908,12 @@ winBltExposedRegionsShadowGDI (ScreenPtr pScreen) /* EndPaint frees the DC */ EndPaint (pScreenPriv->hwndScreen, &ps); +#ifdef XWIN_MULTIWINDOW /* Redraw all windows */ - if (pScreenInfo->fMultiWindow) EnumWindows(winRedrawAllProcShadowGDI, 0); + if (pScreenInfo->fMultiWindow) + EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI, + (LPARAM)pScreenPriv->hwndScreen); +#endif return TRUE; } @@ -798,15 +923,22 @@ winBltExposedRegionsShadowGDI (ScreenPtr pScreen) * Do any engine-specific appliation-activation processing */ -Bool +static Bool winActivateAppShadowGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; -#if CYGDEBUG - ErrorF ("winActivateAppShadowGDI\n"); -#endif + /* + * 2004/04/12 - Harold - We perform the restoring or minimizing + * manually for ShadowGDI in fullscreen modes so that this engine + * will perform just like ShadowDD and ShadowDDNL in fullscreen mode; + * if we do not do this then our fullscreen window will appear in the + * z-order when it is deactivated and it can be uncovered by resizing + * or minimizing another window that is on top of it, which is not how + * the DirectDraw engines work. Therefore we keep this code here to + * make sure that all engines work the same in fullscreen mode. + */ /* * Are we active? @@ -831,10 +963,6 @@ winActivateAppShadowGDI (ScreenPtr pScreen) ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE); } -#if CYGDEBUG - ErrorF ("winActivateAppShadowGDI - Returning\n"); -#endif - return TRUE; } @@ -843,7 +971,7 @@ winActivateAppShadowGDI (ScreenPtr pScreen) * Reblit the shadow framebuffer to the screen. */ -Bool +static Bool winRedrawScreenShadowGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); @@ -857,31 +985,36 @@ winRedrawScreenShadowGDI (ScreenPtr pScreen) 0, 0, SRCCOPY); +#ifdef XWIN_MULTIWINDOW /* Redraw all windows */ - if (pScreenInfo->fMultiWindow) EnumWindows(winRedrawAllProcShadowGDI, 0); + if (pScreenInfo->fMultiWindow) + EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0); +#endif + return TRUE; } + /* * Realize the currently installed colormap */ -Bool +static Bool winRealizeInstalledPaletteShadowGDI (ScreenPtr pScreen) { winScreenPriv(pScreen); winPrivCmapPtr pCmapPriv = NULL; #if CYGDEBUG - ErrorF ("winRealizeInstalledPaletteShadowGDI\n"); + winDebug ("winRealizeInstalledPaletteShadowGDI\n"); #endif /* Don't do anything if there is not a colormap */ if (pScreenPriv->pcmapInstalled == NULL) { #if CYGDEBUG - ErrorF ("winRealizeInstalledPaletteShadowGDI - No colormap " + winDebug ("winRealizeInstalledPaletteShadowGDI - No colormap " "installed\n"); #endif return TRUE; @@ -916,7 +1049,7 @@ winRealizeInstalledPaletteShadowGDI (ScreenPtr pScreen) * Install the specified colormap */ -Bool +static Bool winInstallColormapShadowGDI (ColormapPtr pColormap) { ScreenPtr pScreen = pColormap->pScreen; @@ -963,8 +1096,11 @@ winInstallColormapShadowGDI (ColormapPtr pColormap) /* Save a pointer to the newly installed colormap */ pScreenPriv->pcmapInstalled = pColormap; +#ifdef XWIN_MULTIWINDOW /* Redraw all windows */ - if (pScreenInfo->fMultiWindow) EnumWindows(winRedrawAllProcShadowGDI, 0); + if (pScreenInfo->fMultiWindow) + EnumThreadWindows (g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0); +#endif return TRUE; } @@ -974,7 +1110,7 @@ winInstallColormapShadowGDI (ColormapPtr pColormap) * Store the specified colors in the specified colormap */ -Bool +static Bool winStoreColorsShadowGDI (ColormapPtr pColormap, int ndef, xColorItem *pdefs) @@ -1034,7 +1170,7 @@ winStoreColorsShadowGDI (ColormapPtr pColormap, * Colormap initialization procedure */ -Bool +static Bool winCreateColormapShadowGDI (ColormapPtr pColormap) { LPLOGPALETTE lpPaletteNew = NULL; @@ -1056,7 +1192,7 @@ winCreateColormapShadowGDI (ColormapPtr pColormap) { ErrorF ("winCreateColormapShadowGDI - Couldn't allocate palette " "with %d entries\n", - dwEntriesMax); + (int) dwEntriesMax); return FALSE; } @@ -1091,7 +1227,7 @@ winCreateColormapShadowGDI (ColormapPtr pColormap) * Colormap destruction procedure */ -Bool +static Bool winDestroyColormapShadowGDI (ColormapPtr pColormap) { winScreenPriv(pColormap->pScreen); @@ -1108,7 +1244,7 @@ winDestroyColormapShadowGDI (ColormapPtr pColormap) if (pColormap->flags & IsDefault) { #if CYGDEBUG - ErrorF ("winDestroyColormapShadowGDI - Destroying default " + winDebug ("winDestroyColormapShadowGDI - Destroying default " "colormap\n"); #endif @@ -1170,11 +1306,15 @@ winSetEngineFunctionsShadowGDI (ScreenPtr pScreen) pScreenPriv->pwinStoreColors = winStoreColorsShadowGDI; pScreenPriv->pwinCreateColormap = winCreateColormapShadowGDI; pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowGDI; - pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)())NoopDDA; + pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA; pScreenPriv->pwinCreatePrimarySurface - = (winCreatePrimarySurfaceProcPtr) (void (*)())NoopDDA; + = (winCreatePrimarySurfaceProcPtr) (void (*)(void))NoopDDA; pScreenPriv->pwinReleasePrimarySurface - = (winReleasePrimarySurfaceProcPtr) (void (*)())NoopDDA; + = (winReleasePrimarySurfaceProcPtr) (void (*)(void))NoopDDA; +#ifdef XWIN_MULTIWINDOW + pScreenPriv->pwinFinishCreateWindowsWindow = + (winFinishCreateWindowsWindowProcPtr) (void (*)(void))NoopDDA; +#endif return TRUE; } diff --git a/hw/xwin/wintrayicon.c b/hw/xwin/wintrayicon.c index 9ba507ad2..6a4c90f1a 100755 --- a/hw/xwin/wintrayicon.c +++ b/hw/xwin/wintrayicon.c @@ -49,12 +49,7 @@ winInitNotifyIcon (winPrivScreenPtr pScreenPriv) nid.uID = pScreenInfo->dwScreen; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; nid.uCallbackMessage = WM_TRAYICON; - nid.hIcon = LoadImage (g_hInstance, - MAKEINTRESOURCE(IDI_XWIN), - IMAGE_ICON, - GetSystemMetrics (SM_CXSMICON), - GetSystemMetrics (SM_CYSMICON), - 0); + nid.hIcon = (HICON)winTaskbarIcon (); /* Save handle to the icon so it can be freed later */ pScreenPriv->hiconNotifyIcon = nid.hIcon; @@ -143,41 +138,33 @@ winHandleIconMessage (HWND hwnd, UINT message, /* Get actual tray icon menu */ hmenuTray = GetSubMenu (hmenuPopup, 0); +#ifdef XWIN_MULTIWINDOW /* Check for MultiWindow mode */ if (pScreenInfo->fMultiWindow) { - /* Check if root window is shown or hidden */ + MENUITEMINFO mii = {0}; + + /* Root is shown, remove the check box */ + + /* Setup menu item info structure */ + mii.cbSize = sizeof (MENUITEMINFO); + mii.fMask = MIIM_STATE; + mii.fState = MFS_CHECKED; + + /* Unheck box if root is shown */ if (pScreenPriv->fRootWindowShown) - { - /* Remove Show Root Window button */ - RemoveMenu (hmenuTray, - ID_APP_SHOW_ROOT, - MF_BYCOMMAND); - } - else - { - /* Remove Hide Root Window button */ - RemoveMenu (hmenuTray, - ID_APP_HIDE_ROOT, - MF_BYCOMMAND); - } + mii.fState = MFS_UNCHECKED; + + /* Set menu state */ + SetMenuItemInfo (hmenuTray, ID_APP_HIDE_ROOT, FALSE, &mii); } else +#endif { - /* Remove Show Root Window button */ - RemoveMenu (hmenuTray, - ID_APP_SHOW_ROOT, - MF_BYCOMMAND); - /* Remove Hide Root Window button */ RemoveMenu (hmenuTray, ID_APP_HIDE_ROOT, MF_BYCOMMAND); - - /* Remove separator */ - RemoveMenu (hmenuTray, - 0, - MF_BYPOSITION); } SetupRootMenu ((unsigned long)hmenuTray); diff --git a/hw/xwin/winvalargs.c b/hw/xwin/winvalargs.c new file mode 100755 index 000000000..0932644bb --- /dev/null +++ b/hw/xwin/winvalargs.c @@ -0,0 +1,185 @@ +/* + *Copyright (C) 2003-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "win.h" +#include "winmsg.h" + + +/* + * References to external symbols + */ + +extern int g_iNumScreens; +extern winScreenInfo g_ScreenInfo[]; +extern Bool g_fXdmcpEnabled; + + +/* + * Prototypes + */ + +Bool +winValidateArgs (void); + + +/* + * winValidateArgs - Look for invalid argument combinations + */ + +Bool +winValidateArgs (void) +{ + int i; + int iMaxConsecutiveScreen = 0; + BOOL fHasNormalScreen0 = FALSE; + + /* + * Check for a malformed set of -screen parameters. + * Examples of malformed parameters: + * XWin -screen 1 + * XWin -screen 0 -screen 2 + * XWin -screen 1 -screen 2 + */ + for (i = 0; i < MAXSCREENS; i++) + { + if (g_ScreenInfo[i].fExplicitScreen) + iMaxConsecutiveScreen = i + 1; + } + winErrorFVerb (2, "winValidateArgs - g_iNumScreens: %d " + "iMaxConsecutiveScreen: %d\n", + g_iNumScreens, iMaxConsecutiveScreen); + if (g_iNumScreens < iMaxConsecutiveScreen) + { + ErrorF ("winValidateArgs - Malformed set of screen parameter(s). " + "Screens must be specified consecutively starting with " + "screen 0. That is, you cannot have only a screen 1, nor " + "could you have screen 0 and screen 2. You instead must " + "have screen 0, or screen 0 and screen 1, respectively. Of " + "you can specify as many screens as you want from 0 up to " + "%d.\n", MAXSCREENS - 1); + return FALSE; + } + + /* Loop through all screens */ + for (i = 0; i < g_iNumScreens; ++i) + { + /* + * Check for any combination of + * -multiwindow, -mwextwm, and -rootless. + */ + { + int iCount = 0; + + /* Count conflicting options */ +#ifdef XWIN_MULTIWINDOW + if (g_ScreenInfo[i].fMultiWindow) + ++iCount; +#endif +#ifdef XWIN_MULTIWINDOWEXTWM + if (g_ScreenInfo[i].fMWExtWM) + ++iCount; +#endif + if (g_ScreenInfo[i].fRootless) + ++iCount; + + /* Check if the first screen is without rootless and multiwindow */ + if (iCount == 0 && i == 0) + fHasNormalScreen0 = TRUE; + + /* Fail if two or more conflicting options */ + if (iCount > 1) + { + ErrorF ("winValidateArgs - Only one of -multiwindow, -mwextwm, " + "and -rootless can be specific at a time.\n"); + return FALSE; + } + } + + /* Check for -multiwindow or -mwextwm and Xdmcp */ + /* allow xdmcp if screen 0 is normal. */ + if (g_fXdmcpEnabled && !fHasNormalScreen0 + && (FALSE +#ifdef XWIN_MULTIWINDOW + || g_ScreenInfo[i].fMultiWindow +#endif +#ifdef XWIN_MULTIWINDOWEXTWM + || g_ScreenInfo[i].fMWExtWM +#endif + ) + ) + { + ErrorF ("winValidateArgs - Xdmcp (-query, -broadcast, or -indirect) " + "is invalid with -multiwindow or -mwextwm.\n"); + return FALSE; + } + + /* Check for -multiwindow, -mwextwm, or -rootless and fullscreen */ + if (g_ScreenInfo[i].fFullScreen + && (FALSE +#ifdef XWIN_MULTIWINDOW + || g_ScreenInfo[i].fMultiWindow +#endif +#ifdef XWIN_MULTIWINDOWEXTWM + || g_ScreenInfo[i].fMWExtWM +#endif + || g_ScreenInfo[i].fRootless) + ) + { + ErrorF ("winValidateArgs - -fullscreen is invalid with " + "-multiwindow, -mwextwm, or -rootless.\n"); + return FALSE; + } + + /* Check for !fullscreen and any fullscreen-only parameters */ + if (!g_ScreenInfo[i].fFullScreen + && (g_ScreenInfo[i].dwRefreshRate != WIN_DEFAULT_BPP + || g_ScreenInfo[i].dwBPP != WIN_DEFAULT_REFRESH)) + { + ErrorF ("winValidateArgs - -refresh and -depth are only valid " + "with -fullscreen.\n"); + return FALSE; + } + + /* Check for fullscreen and any non-fullscreen parameters */ + if (g_ScreenInfo[i].fFullScreen + && (g_ScreenInfo[i].fScrollbars + || !g_ScreenInfo[i].fDecoration + || g_ScreenInfo[i].fLessPointer)) + { + ErrorF ("winValidateArgs - -fullscreen is invalid with " + "-scrollbars, -nodecoration, or -lesspointer.\n"); + return FALSE; + } + } + + winDebug ("winValidateArgs - Returning.\n"); + + return TRUE; +} diff --git a/hw/xwin/winvideo.c b/hw/xwin/winvideo.c index d4a856fcf..5a86513d5 100755 --- a/hw/xwin/winvideo.c +++ b/hw/xwin/winvideo.c @@ -1,5 +1,5 @@ /* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -15,24 +15,25 @@ *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 + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 + *Except as contained in this notice, the name of Harold L Hunt II *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. + *from Harold L Hunt II. * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winvideo.c,v 1.1tsi Exp $ */ #include "win.h" #include "Xv.h" #include "Xvproto.h" +void +winInitVideo (ScreenPtr pScreen); /* * winInitVideo - Initialize support for the X Video (Xv) Extension. diff --git a/hw/xwin/winwakeup.c b/hw/xwin/winwakeup.c index 55658ecac..4553a4636 100644 --- a/hw/xwin/winwakeup.c +++ b/hw/xwin/winwakeup.c @@ -34,6 +34,16 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern HWND g_hDlgDepthChange; +extern HWND g_hDlgExit; +extern HWND g_hDlgAbout; + + /* See Porting Layer Definition - p. 7 */ void winWakeupHandler (int nScreen, @@ -41,9 +51,7 @@ winWakeupHandler (int nScreen, unsigned long ulResult, pointer pReadmask) { -#if 0 winScreenPriv((ScreenPtr)pWakeupData); -#endif MSG msg; /* Process all messages on our queue */ @@ -52,12 +60,11 @@ winWakeupHandler (int nScreen, if ((g_hDlgDepthChange == 0 || !IsDialogMessage (g_hDlgDepthChange, &msg)) && (g_hDlgExit == 0 - || !IsDialogMessage (g_hDlgExit, &msg))) + || !IsDialogMessage (g_hDlgExit, &msg)) + && (g_hDlgAbout == 0 + || !IsDialogMessage (g_hDlgAbout, &msg))) { DispatchMessage (&msg); } } - winReorderWindowsMultiWindow ((ScreenPtr)pWakeupData); } - - diff --git a/hw/xwin/winwin32rootless.c b/hw/xwin/winwin32rootless.c new file mode 100755 index 000000000..308411c3e --- /dev/null +++ b/hw/xwin/winwin32rootless.c @@ -0,0 +1,1035 @@ +/* + *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + * + *Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + *"Software"), to deal in the Software without restriction, including + *without limitation the rights to use, copy, modify, merge, publish, + *distribute, sublicense, and/or sell copies of the Software, and to + *permit persons to whom the Software is furnished to do so, subject to + *the following conditions: + * + *The above copyright notice and this permission notice shall be + *included in all copies or substantial portions of the Software. + * + *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR + *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *Except as contained in this notice, the name of the XFree86 Project + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from the XFree86 Project. + * + * Authors: Kensuke Matsuzaki + * Earle F. Philhower, III + * Harold L Hunt II + */ +/* + * Look at hw/darwin/quartz/xpr/xprFrame.c and hw/darwin/quartz/cr/crFrame.c + */ +#include "win.h" +#include <winuser.h> +#define _WINDOWSWM_SERVER_ +#include "windowswmstr.h" +#include "dixevents.h" +#include "winmultiwindowclass.h" +#include "winprefs.h" +#include "Xatom.h" + + +/* + * Constant defines + */ + +#define MOUSE_POLLING_INTERVAL 500 + +#define ULW_COLORKEY 0x00000001 +#define ULW_ALPHA 0x00000002 +#define ULW_OPAQUE 0x00000004 +#define AC_SRC_ALPHA 0x01 + + +/* + * Local function + */ + +DEFINE_ATOM_HELPER(AtmWindowsWmNativeHwnd, WINDOWSWM_NATIVE_HWND) +static void +winMWExtWMSetNativeProperty (RootlessWindowPtr pFrame); + +/* + * Global variables + */ + +Bool g_fNoConfigureWindow = FALSE; + + +extern void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon); + +/* + * Internal function to get the DIB format that is compatible with the screen + * Fixme: Share code with winshadgdi.c + */ + +static +Bool +winMWExtWMQueryDIBFormat (win32RootlessWindowPtr pRLWinPriv, BITMAPINFOHEADER *pbmih) +{ + HBITMAP hbmp; +#if CYGMULTIWINDOW_DEBUG + LPDWORD pdw = NULL; +#endif + + /* Create a memory bitmap compatible with the screen */ + hbmp = CreateCompatibleBitmap (pRLWinPriv->hdcScreen, 1, 1); + if (hbmp == NULL) + { + ErrorF ("winMWExtWMQueryDIBFormat - 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 ("winMWExtWMQueryDIBFormat - First call to GetDIBits failed\n"); + DeleteObject (hbmp); + return FALSE; + } + +#if CYGMULTIWINDOW_DEBUG + /* Get a pointer to bitfields */ + pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER)); + + winDebug ("winMWExtWMQueryDIBFormat - First call masks: %08x %08x %08x\n", + (unsigned int)pdw[0], (unsigned int)pdw[1], (unsigned int)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 ("winMWExtWMQueryDIBFormat - Second call to GetDIBits " + "failed\n"); + DeleteObject (hbmp); + return FALSE; + } + + /* Free memory */ + DeleteObject (hbmp); + + return TRUE; +} + +static HRGN +winMWExtWMCreateRgnFromRegion (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, (int) 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, + (int) GetLastError ()); + } + + /* Merge the Windows region with the accumulated region */ + if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR) + { + ErrorF ("winReshape - CombineRgn () failed: %d\n", + (int) GetLastError ()); + } + + /* Delete the temporary Windows region */ + DeleteObject (hRgnRect); + } + + return hRgn; +} + +static void +InitWin32RootlessEngine (win32RootlessWindowPtr 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 ("winMWExtWMCreateFrame - malloc () failed\n"); + return; + } + + /* Query the screen format */ + winMWExtWMQueryDIBFormat (pRLWinPriv, + pRLWinPriv->pbmihShadow); +} + +Bool +winMWExtWMCreateFrame (RootlessWindowPtr pFrame, ScreenPtr pScreen, + int newX, int newY, RegionPtr pShape) +{ +#define CLASS_NAME_LENGTH 512 + Bool fResult = TRUE; + win32RootlessWindowPtr pRLWinPriv; + WNDCLASSEX wc; + char pszClass[CLASS_NAME_LENGTH], pszWindowID[12]; + HICON hIcon; + HICON hIconSmall; + char *res_name, *res_class, *res_role; + static int s_iWindowID = 0; + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMCreateFrame %d %d - %d %d\n", + newX, newY, pFrame->width, pFrame->height); +#endif + + pRLWinPriv = (win32RootlessWindowPtr) malloc (sizeof (win32RootlessWindowRec)); + pRLWinPriv->pFrame = pFrame; + pRLWinPriv->pfb = NULL; + pRLWinPriv->hbmpShadow = NULL; + pRLWinPriv->hdcShadow = NULL; + pRLWinPriv->hdcScreen = NULL; + pRLWinPriv->pbmihShadow = NULL; + pRLWinPriv->fResized = TRUE; + pRLWinPriv->fClose = FALSE; + pRLWinPriv->fRestackingNow = FALSE; + pRLWinPriv->fDestroyed = FALSE; + pRLWinPriv->fMovingOrSizing = FALSE; + + // Store the implementation private frame ID + pFrame->wid = (RootlessFrameID) pRLWinPriv; + + winSelectIcons(pFrame->win, &hIcon, &hIconSmall); + + /* Set standard class name prefix so we can identify window easily */ + strncpy (pszClass, WINDOW_CLASS_X, sizeof(pszClass)); + + if (winMultiWindowGetClassHint (pFrame->win, &res_name, &res_class)) + { + strncat (pszClass, "-", 1); + strncat (pszClass, res_name, CLASS_NAME_LENGTH - strlen (pszClass)); + strncat (pszClass, "-", 1); + strncat (pszClass, res_class, CLASS_NAME_LENGTH - strlen (pszClass)); + + /* Check if a window class is provided by the WM_WINDOW_ROLE property, + * if not use the WM_CLASS information. + * For further information see: + * http://tronche.com/gui/x/icccm/sec-5.html + */ + if (winMultiWindowGetWindowRole (pFrame->win, &res_role) ) + { + strcat (pszClass, "-"); + strcat (pszClass, res_role); + free (res_role); + } + + free (res_name); + free (res_class); + } + + /* Add incrementing window ID to make unique class name */ + sprintf (pszWindowID, "-%x", s_iWindowID++); + strcat (pszClass, pszWindowID); + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winCreateWindowsWindow - Creating class: %s\n", pszClass); +#endif + + /* Setup our window class */ + wc.cbSize = sizeof(wc); + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = winMWExtWMWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = g_hInstance; + wc.hIcon = hIcon; + wc.hIconSm = hIconSmall; + wc.hCursor = 0; + wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); + wc.lpszMenuName = NULL; + wc.lpszClassName = pszClass; + RegisterClassEx (&wc); + + /* Create the window */ + g_fNoConfigureWindow = TRUE; + pRLWinPriv->hWnd = CreateWindowExA (WS_EX_TOOLWINDOW, /* Extended styles */ + pszClass, /* Class name */ + WINDOW_TITLE_X, /* Window name */ + WS_POPUP | WS_CLIPCHILDREN, + newX, /* Horizontal position */ + newY, /* Vertical position */ + pFrame->width, /* Right edge */ + pFrame->height, /* Bottom edge */ + (HWND) NULL, /* No parent or owner window */ + (HMENU) NULL, /* No menu */ + GetModuleHandle (NULL), /* Instance handle */ + pRLWinPriv); /* ScreenPrivates */ + if (pRLWinPriv->hWnd == NULL) + { + ErrorF ("winMWExtWMCreateFrame - CreateWindowExA () failed: %d\n", + (int) GetLastError ()); + fResult = FALSE; + } + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMCreateFrame - ShowWindow\n"); +#endif + + //ShowWindow (pRLWinPriv->hWnd, SW_SHOWNOACTIVATE); + g_fNoConfigureWindow = FALSE; + + if (pShape != NULL) + { + winMWExtWMReshapeFrame (pFrame->wid, pShape); + } + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMCreateFrame - (%08x) %08x\n", + (int) pFrame->wid, (int) pRLWinPriv->hWnd); +#if 0 + { + WindowPtr pWin2 = NULL; + win32RootlessWindowPtr pRLWinPriv2 = NULL; + + /* Check if the Windows window property for our X window pointer is valid */ + if ((pWin2 = (WindowPtr)GetProp (pRLWinPriv->hWnd, WIN_WINDOW_PROP)) != NULL) + { + pRLWinPriv2 = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin2, FALSE); + } + winDebug ("winMWExtWMCreateFrame2 (%08x) %08x\n", + pRLWinPriv2, pRLWinPriv2->hWnd); + if (pRLWinPriv != pRLWinPriv2 || pRLWinPriv->hWnd != pRLWinPriv2->hWnd) + { + winDebug ("Error param missmatch\n"); + } + } +#endif +#endif + + winMWExtWMSetNativeProperty (pFrame); + + return fResult; +} + +void +winMWExtWMDestroyFrame (RootlessFrameID wid) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; + HICON hiconClass; + HICON hiconSmClass; + HMODULE hInstance; + int iReturn; + char pszClass[CLASS_NAME_LENGTH]; + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMDestroyFrame (%08x) %08x\n", + (int) pRLWinPriv, (int) pRLWinPriv->hWnd); +#if 0 + { + WindowPtr pWin2 = NULL; + win32RootlessWindowPtr pRLWinPriv2 = NULL; + + /* Check if the Windows window property for our X window pointer is valid */ + if ((pWin2 = (WindowPtr)GetProp (pRLWinPriv->hWnd, WIN_WINDOW_PROP)) != NULL) + { + pRLWinPriv2 = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin2, FALSE); + } + winDebug ("winMWExtWMDestroyFrame2 (%08x) %08x\n", + pRLWinPriv2, pRLWinPriv2->hWnd); + if (pRLWinPriv != pRLWinPriv2 || pRLWinPriv->hWnd != pRLWinPriv2->hWnd) + { + winDebug ("Error param missmatch\n"); + *(int*)0 = 1;//raise exseption + } + } +#endif +#endif + + /* Store the info we need to destroy after this window is gone */ + hInstance = (HINSTANCE) GetClassLong (pRLWinPriv->hWnd, GCL_HMODULE); + hiconClass = (HICON) GetClassLong (pRLWinPriv->hWnd, GCL_HICON); + hiconSmClass = (HICON) GetClassLong (pRLWinPriv->hWnd, GCL_HICONSM); + iReturn = GetClassName (pRLWinPriv->hWnd, pszClass, CLASS_NAME_LENGTH); + + pRLWinPriv->fClose = TRUE; + pRLWinPriv->fDestroyed = TRUE; + + /* Destroy the Windows window */ + DestroyWindow (pRLWinPriv->hWnd); + + /* Only if we were able to get the name */ + if (iReturn) + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMDestroyFrame - Unregistering %s: ", pszClass); +#endif + iReturn = UnregisterClass (pszClass, hInstance); + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMDestroyFramew - %d Deleting Icon: ", iReturn); +#endif + + winDestroyIcon(hiconClass); + winDestroyIcon(hiconSmClass); + } + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMDestroyFrame - done\n"); +#endif +} + +void +winMWExtWMMoveFrame (RootlessFrameID wid, ScreenPtr pScreen, int iNewX, int iNewY) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; + RECT rcNew; + DWORD dwExStyle; + DWORD dwStyle; + int iX, iY, iWidth, iHeight; + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMMoveFrame (%08x) (%d %d)\n", (int) pRLWinPriv, iNewX, iNewY); +#endif + + /* Get the Windows window style and extended style */ + dwExStyle = GetWindowLongPtr (pRLWinPriv->hWnd, GWL_EXSTYLE); + dwStyle = GetWindowLongPtr (pRLWinPriv->hWnd, GWL_STYLE); + + /* Get the X and Y location of the X window */ + iX = iNewX + GetSystemMetrics (SM_XVIRTUALSCREEN); + iY = iNewY + GetSystemMetrics (SM_YVIRTUALSCREEN); + + /* Get the height and width of the X window */ + iWidth = pRLWinPriv->pFrame->width; + iHeight = pRLWinPriv->pFrame->height; + + /* Store the origin, height, and width in a rectangle structure */ + SetRect (&rcNew, iX, iY, iX + iWidth, iY + iHeight); + + /* + * Calculate the required size of the Windows window rectangle, + * given the size of the Windows window client area. + */ + AdjustWindowRectEx (&rcNew, dwStyle, FALSE, dwExStyle); + + g_fNoConfigureWindow = TRUE; + SetWindowPos (pRLWinPriv->hWnd, NULL, rcNew.left, rcNew.top, 0, 0, + SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); + g_fNoConfigureWindow = FALSE; +} + +void +winMWExtWMResizeFrame (RootlessFrameID wid, ScreenPtr pScreen, + int iNewX, int iNewY, + unsigned int uiNewWidth, unsigned int uiNewHeight, + unsigned int uiGravity) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; + RECT rcNew; + RECT rcOld; + DWORD dwExStyle; + DWORD dwStyle; + int iX, iY; + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMResizeFrame (%08x) (%d %d)-(%d %d)\n", + (int) pRLWinPriv, iNewX, iNewY, uiNewWidth, uiNewHeight); +#endif + + pRLWinPriv->fResized = TRUE; + + /* Get the Windows window style and extended style */ + dwExStyle = GetWindowLongPtr (pRLWinPriv->hWnd, GWL_EXSTYLE); + dwStyle = GetWindowLongPtr (pRLWinPriv->hWnd, GWL_STYLE); + + /* Get the X and Y location of the X window */ + iX = iNewX + GetSystemMetrics (SM_XVIRTUALSCREEN); + iY = iNewY + GetSystemMetrics (SM_YVIRTUALSCREEN); + + /* Store the origin, height, and width in a rectangle structure */ + SetRect (&rcNew, iX, iY, iX + uiNewWidth, iY + uiNewHeight); + + /* + * Calculate the required size of the Windows window rectangle, + * given the size of the Windows window client area. + */ + AdjustWindowRectEx (&rcNew, dwStyle, FALSE, dwExStyle); + + /* Get a rectangle describing the old Windows window */ + GetWindowRect (pRLWinPriv->hWnd, &rcOld); + + /* Check if the old rectangle and new rectangle are the same */ + if (!EqualRect (&rcNew, &rcOld)) + { + + g_fNoConfigureWindow = TRUE; + MoveWindow (pRLWinPriv->hWnd, + rcNew.left, rcNew.top, + rcNew.right - rcNew.left, rcNew.bottom - rcNew.top, + TRUE); + g_fNoConfigureWindow = FALSE; + } +} + +void +winMWExtWMRestackFrame (RootlessFrameID wid, RootlessFrameID nextWid) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; + win32RootlessWindowPtr pRLNextWinPriv = (win32RootlessWindowPtr) nextWid; + winScreenPriv(pRLWinPriv->pFrame->win->drawable.pScreen); + DWORD dwCurrentProcessID = GetCurrentProcessId (); + DWORD dwWindowProcessID = 0; + HWND hWnd; + Bool fFirst = TRUE; + Bool fNeedRestack = TRUE; +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMRestackFrame (%08x)\n", (int) pRLWinPriv); +#endif + + if (pScreenPriv->fRestacking) return; + + pRLWinPriv->fRestackingNow = TRUE; + + /* Show window */ + if(!IsWindowVisible (pRLWinPriv->hWnd)) + ShowWindow (pRLWinPriv->hWnd, SW_SHOWNOACTIVATE); + + if (pRLNextWinPriv == NULL) + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("Win %08x is top\n", pRLWinPriv); +#endif + pScreenPriv->widTop = wid; + SetWindowPos (pRLWinPriv->hWnd, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + } + else + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("Win %08x is not top\n", pRLWinPriv); +#endif + for (hWnd = GetNextWindow (pRLWinPriv->hWnd, GW_HWNDPREV); + fNeedRestack && hWnd != NULL; + hWnd = GetNextWindow (hWnd, GW_HWNDPREV)) + { + GetWindowThreadProcessId (hWnd, &dwWindowProcessID); + + if ((dwWindowProcessID == dwCurrentProcessID) + && GetProp (hWnd, WIN_WINDOW_PROP)) + { + if (hWnd == pRLNextWinPriv->hWnd) + { + /* Enable interleave X window and Windows window */ + if (!fFirst) + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("raise: Insert after Win %08x\n", pRLNextWinPriv); +#endif + SetWindowPos (pRLWinPriv->hWnd, pRLNextWinPriv->hWnd, + 0, 0, 0, 0, + SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + } + else + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("No change\n"); +#endif + } + fNeedRestack = FALSE; + break; + } + if (fFirst) fFirst = FALSE; + } + } + + for (hWnd = GetNextWindow (pRLWinPriv->hWnd, GW_HWNDNEXT); + fNeedRestack && hWnd != NULL; + hWnd = GetNextWindow (hWnd, GW_HWNDNEXT)) + { + GetWindowThreadProcessId (hWnd, &dwWindowProcessID); + + if ((dwWindowProcessID == dwCurrentProcessID) + && GetProp (hWnd, WIN_WINDOW_PROP)) + { + if (hWnd == pRLNextWinPriv->hWnd) + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("lower: Insert after Win %08x\n", pRLNextWinPriv); +#endif + SetWindowPos (pRLWinPriv->hWnd, pRLNextWinPriv->hWnd, + 0, 0, 0, 0, + SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + fNeedRestack = FALSE; + break; + } + } + } + } + + pRLWinPriv->fRestackingNow = FALSE; +} + +void +winMWExtWMReshapeFrame (RootlessFrameID wid, RegionPtr pShape) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; + HRGN hRgn, hRgnWindow, hRgnClient; + RECT rcWindow, rcClient; +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMReshapeFrame (%08x)\n", (int) pRLWinPriv); +#endif + + hRgn = winMWExtWMCreateRgnFromRegion (pShape); + + /* Create region for non-client area */ + GetWindowRect (pRLWinPriv->hWnd, &rcWindow); + GetClientRect (pRLWinPriv->hWnd, &rcClient); + MapWindowPoints (pRLWinPriv->hWnd, HWND_DESKTOP, (LPPOINT)&rcClient, 2); + OffsetRgn (hRgn, rcClient.left - rcWindow.left, rcClient.top - rcWindow.top); + OffsetRect (&rcClient, -rcWindow.left, -rcWindow.top); + OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top); + hRgnWindow = CreateRectRgnIndirect (&rcWindow); + hRgnClient = CreateRectRgnIndirect (&rcClient); + CombineRgn (hRgnWindow, hRgnWindow, hRgnClient, RGN_DIFF); + CombineRgn (hRgn, hRgnWindow, hRgn, RGN_OR); + + + SetWindowRgn (pRLWinPriv->hWnd, hRgn, TRUE); + + DeleteObject (hRgnWindow); + DeleteObject (hRgnClient); +} + +void +winMWExtWMUnmapFrame (RootlessFrameID wid) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMUnmapFrame (%08x)\n", (int) pRLWinPriv); +#endif + + g_fNoConfigureWindow = TRUE; + //ShowWindow (pRLWinPriv->hWnd, SW_MINIMIZE); + ShowWindow (pRLWinPriv->hWnd, SW_HIDE); + g_fNoConfigureWindow = FALSE; +} + +/* + * Fixme: Code sharing with winshadgdi.c and other engine support + */ +void +winMWExtWMStartDrawing (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 + winDebug ("winMWExtWMStartDrawing (%08x) %08x\n", (int) pRLWinPriv, pRLWinPriv->fDestroyed); +#endif + + if (!pRLWinPriv->fDestroyed) + { + pScreen = pRLWinPriv->pFrame->win->drawable.pScreen; + if (pScreen) pScreenPriv = winGetScreenPriv(pScreen); + if (pScreenPriv) pScreenInfo = pScreenPriv->pScreenInfo; + +#if CYGMULTIWINDOW_DEBUG + winDebug ("pScreenPriv %08X\n", (int) pScreenPriv); + winDebug ("pScreenInfo %08X\n", (int) pScreenInfo); +#endif + if (pRLWinPriv->hdcScreen == NULL) + { + InitWin32RootlessEngine (pRLWinPriv); + } + + if (pRLWinPriv->fResized) + { + hdcNew = CreateCompatibleDC (pRLWinPriv->hdcScreen); + /* Describe shadow bitmap to be created */ + pRLWinPriv->pbmihShadow->biWidth = pRLWinPriv->pFrame->width;//pRLWinPriv->dwWidth; + pRLWinPriv->pbmihShadow->biHeight = -pRLWinPriv->pFrame->height;//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 ("winMWExtWMStartDrawing - CreateDIBSection failed\n"); + //return FALSE; + } + else + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMStartDrawing - Shadow buffer allocated\n"); +#endif + } + + /* Get information about the bitmap that was allocated */ + GetObject (hbmpNew, sizeof (dibsection), &dibsection); + +#if CYGMULTIWINDOW_DEBUG + /* Print information about bitmap allocated */ + winDebug ("winMWExtWMStartDrawing - Dibsection width: %d height: %d " + "depth: %d size image: %d\n", + (unsigned int)dibsection.dsBmih.biWidth, + (unsigned int)dibsection.dsBmih.biHeight, + (unsigned int)dibsection.dsBmih.biBitCount, + (unsigned int)dibsection.dsBmih.biSizeImage); +#endif + + /* Select the shadow bitmap into the shadow DC */ + SelectObject (hdcNew, hbmpNew); + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMStartDrawing - Attempting a shadow blit\n"); +#endif + + /* Blit from the old shadow to the new shadow */ + fReturn = BitBlt (hdcNew, + 0, 0, + pRLWinPriv->pFrame->width, pRLWinPriv->pFrame->height, + pRLWinPriv->hdcShadow, + 0, 0, + SRCCOPY); + if (fReturn) + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMStartDrawing - Shadow blit success\n"); +#endif + } + else + { + ErrorF ("winMWExtWMStartDrawing - Shadow blit failure\n"); + } + + /* Look for height weirdness */ + if (dibsection.dsBmih.biHeight < 0) + { + /* FIXME: Figure out why biHeight is sometimes negative */ + ErrorF ("winMWExtWMStartDrawing - WEIRDNESS - biHeight " + "still negative: %d\n" + "winAllocateFBShadowGDI - WEIRDNESS - Flipping biHeight sign\n", + (int) dibsection.dsBmih.biHeight); + dibsection.dsBmih.biHeight = -dibsection.dsBmih.biHeight; + } + + pRLWinPriv->dwWidthBytes = dibsection.dsBm.bmWidthBytes; + +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMStartDrawing - bytesPerRow: %d\n", + (unsigned int)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 CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMStartDrawing - 0x%08x %d\n", + (unsigned int)pRLWinPriv->pfb, (unsigned int)dibsection.dsBm.bmWidthBytes); +#endif + } + else + { + ErrorF ("winMWExtWMStartDrawing - Already window was destroyed \n"); + } +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMStartDrawing - done (0x08x) 0x%08x %d\n", + (int) pRLWinPriv, + (unsigned int)pRLWinPriv->pfb, (unsigned int)pRLWinPriv->dwWidthBytes); +#endif + *pixelData = pRLWinPriv->pfb; + *bytesPerRow = pRLWinPriv->dwWidthBytes; +} + +void +winMWExtWMStopDrawing (RootlessFrameID wid, Bool fFlush) +{ +#if 0 + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; + BLENDFUNCTION bfBlend; + SIZE szWin; + POINT ptSrc; +#if CYGMULTIWINDOW_DEBUG || TRUE + winDebug ("winMWExtWMStopDrawing (%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 ("winMWExtWMStopDrawing - UpdateLayeredWindow failed\n"); + } +#endif +} + +void +winMWExtWMUpdateRegion (RootlessFrameID wid, RegionPtr pDamage) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; +#if 0 + BLENDFUNCTION bfBlend; + SIZE szWin; + POINT ptSrc; +#endif +#if CYGMULTIWINDOW_DEBUG && 0 + winDebug ("winMWExtWMUpdateRegion (%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 ("winMWExtWMUpdateRegion - UpdateLayeredWindow failed: %s\n", + (LPSTR)lpMsgBuf); + LocalFree (lpMsgBuf); + } +#endif + if (!g_fNoConfigureWindow) UpdateWindow (pRLWinPriv->hWnd); +} + +void +winMWExtWMDamageRects (RootlessFrameID wid, int nCount, const BoxRec *pRects, + int shift_x, int shift_y) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; + const BoxRec *pEnd; +#if CYGMULTIWINDOW_DEBUG && 0 + winDebug ("winMWExtWMDamageRects (%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 +winMWExtWMRootlessSwitchWindow (RootlessWindowPtr pFrame, WindowPtr oldWin) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) pFrame->wid; +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMRootlessSwitchWindow (%08x) %08x\n", + (int) pRLWinPriv, (int) pRLWinPriv->hWnd); +#endif + pRLWinPriv->pFrame = pFrame; + pRLWinPriv->fResized = TRUE; + + DeleteProperty (oldWin, AtmWindowsWmNativeHwnd ()); + winMWExtWMSetNativeProperty (pFrame); +#if CYGMULTIWINDOW_DEBUG +#if 0 + { + WindowPtr pWin2 = NULL; + win32RootlessWindowPtr pRLWinPriv2 = NULL; + + /* Check if the Windows window property for our X window pointer is valid */ + if ((pWin2 = (WindowPtr)GetProp (pRLWinPriv->hWnd, WIN_WINDOW_PROP)) != NULL) + { + pRLWinPriv2 = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin2, FALSE); + } + winDebug ("winMWExtWMSwitchFrame2 (%08x) %08x\n", + pRLWinPriv2, pRLWinPriv2->hWnd); + if (pRLWinPriv != pRLWinPriv2 || pRLWinPriv->hWnd != pRLWinPriv2->hWnd) + { + winDebug ("Error param missmatch\n"); + } + } +#endif +#endif +} + +void +winMWExtWMCopyBytes (unsigned int width, unsigned int height, + const void *src, unsigned int srcRowBytes, + void *dst, unsigned int dstRowBytes) +{ +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMCopyBytes - Not implemented\n"); +#endif +} + +void +winMWExtWMFillBytes (unsigned int width, unsigned int height, unsigned int value, + void *dst, unsigned int dstRowBytes) +{ +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMFillBytes - Not implemented\n"); +#endif +} + +int +winMWExtWMCompositePixels (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 + winDebug ("winMWExtWMCompositePixels - Not implemented\n"); +#endif + return 0; +} + + +void +winMWExtWMCopyWindow (RootlessFrameID wid, int nDstRects, const BoxRec *pDstRects, + int nDx, int nDy) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid; + const BoxRec *pEnd; + RECT rcDmg; +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMCopyWindow (%08x, %d, %08x, %d, %d)\n", + (int) pRLWinPriv, nDstRects, (int) pDstRects, nDx, nDy); +#endif + + for (pEnd = pDstRects + nDstRects; pDstRects < pEnd; pDstRects++) + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("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); +#endif + + 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 ("winMWExtWMCopyWindow - 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 + winDebug ("winMWExtWMCopyWindow - done\n"); +#endif +} + + +/* + * winMWExtWMSetNativeProperty + */ + +static void +winMWExtWMSetNativeProperty (RootlessWindowPtr pFrame) +{ + win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) pFrame->wid; + long lData; + + /* FIXME: move this to WindowsWM extension */ + + lData = pRLWinPriv->hWnd; + ChangeWindowProperty (pFrame->win, AtmWindowsWmNativeHwnd (), + XA_INTEGER, 32, PropModeReplace, 1, &lData, TRUE); +} diff --git a/hw/xwin/winwin32rootlesswindow.c b/hw/xwin/winwin32rootlesswindow.c new file mode 100755 index 000000000..eedfe2f0c --- /dev/null +++ b/hw/xwin/winwin32rootlesswindow.c @@ -0,0 +1,184 @@ +/* + *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + * + *Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + *"Software"), to deal in the Software without restriction, including + *without limitation the rights to use, copy, modify, merge, publish, + *distribute, sublicense, and/or sell copies of the Software, and to + *permit persons to whom the Software is furnished to do so, subject to + *the following conditions: + * + *The above copyright notice and this permission notice shall be + *included in all copies or substantial portions of the Software. + * + *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR + *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *Except as contained in this notice, the name of the XFree86 Project + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from the XFree86 Project. + * + * Authors: Kensuke Matsuzaki + * Earle F. Philhower, III + * Harold L Hunt II + */ + +#include "win.h" +#include "winprefs.h" + +#if 0 +/* + * winMWExtWMReorderWindows + */ + +void +winMWExtWMReorderWindows (ScreenPtr pScreen) +{ + winScreenPriv(pScreen); + HWND hwnd = NULL; + win32RootlessWindowPtr pRLWin = NULL; + win32RootlessWindowPtr pRLWinSib = NULL; + DWORD dwCurrentProcessID = GetCurrentProcessId (); + DWORD dwWindowProcessID = 0; + XID vlist[2]; + +#if CYGMULTIWINDOW_DEBUG && FALSE + ErrorF ("winMWExtWMReorderWindows\n"); +#endif + + pScreenPriv->fRestacking = TRUE; + + if (pScreenPriv->fWindowOrderChanged) + { +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winMWExtWMReorderWindows - Need to restack\n"); +#endif + hwnd = GetTopWindow (NULL); + + while (hwnd) + { + GetWindowThreadProcessId (hwnd, &dwWindowProcessID); + + if ((dwWindowProcessID == dwCurrentProcessID) + && GetProp (hwnd, WIN_WINDOW_PROP)) + { + pRLWinSib = pRLWin; + pRLWin = (win32RootlessWindowPtr)GetProp (hwnd, WIN_WINDOW_PROP); + + if (pRLWinSib) + { + vlist[0] = pRLWinSib->pFrame->win->drawable.id; + vlist[1] = Below; + + ConfigureWindow (pRLWin->pFrame->win, CWSibling | CWStackMode, + vlist, wClient(pRLWin->pFrame->win)); + } + else + { + /* 1st window - raise to the top */ + vlist[0] = Above; + + ConfigureWindow (pRLWin->pFrame->win, CWStackMode, + vlist, wClient(pRLWin->pFrame->win)); + } + } + hwnd = GetNextWindow (hwnd, GW_HWNDNEXT); + } + } + + pScreenPriv->fRestacking = FALSE; + pScreenPriv->fWindowOrderChanged = FALSE; +} +#endif + + +/* + * winMWExtWMMoveXWindow + */ + +void +winMWExtWMMoveXWindow (WindowPtr pWin, int x, int y) +{ + XID *vlist = malloc(sizeof(long)*2); + + (CARD32*)vlist[0] = x; + (CARD32*)vlist[1] = y; + ConfigureWindow (pWin, CWX | CWY, vlist, wClient(pWin)); + free(vlist); +} + + +/* + * winMWExtWMResizeXWindow + */ + +void +winMWExtWMResizeXWindow (WindowPtr pWin, int w, int h) +{ + XID *vlist = malloc(sizeof(long)*2); + + (CARD32*)vlist[0] = w; + (CARD32*)vlist[1] = h; + ConfigureWindow (pWin, CWWidth | CWHeight, vlist, wClient(pWin)); + free(vlist); +} + + +/* + * winMWExtWMMoveResizeXWindow + */ + +void +winMWExtWMMoveResizeXWindow (WindowPtr pWin, int x, int y, int w, int h) +{ + XID *vlist = malloc(sizeof(long)*4); + + (CARD32*)vlist[0] = x; + (CARD32*)vlist[1] = y; + (CARD32*)vlist[2] = w; + (CARD32*)vlist[3] = h; + + ConfigureWindow (pWin, CWX | CWY | CWWidth | CWHeight, vlist, wClient(pWin)); + free(vlist); +} + + +/* + * winMWExtWMUpdateIcon + * Change the Windows window icon + */ + +void +winMWExtWMUpdateIcon (Window id) +{ + WindowPtr pWin; + HICON hIcon, hiconOld; + + pWin = LookupIDByType (id, RT_WINDOW); + hIcon = (HICON)winOverrideIcon ((unsigned long)pWin); + + if (!hIcon) + hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON)); + + if (hIcon) + { + win32RootlessWindowPtr pRLWinPriv + = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE); + + if (pRLWinPriv->hWnd) + { + hiconOld = (HICON) SetClassLong (pRLWinPriv->hWnd, + GCL_HICON, + (int) hIcon); + + winDestroyIcon(hiconOld); + } + } +} diff --git a/hw/xwin/winwin32rootlesswndproc.c b/hw/xwin/winwin32rootlesswndproc.c new file mode 100755 index 000000000..d7fb85075 --- /dev/null +++ b/hw/xwin/winwin32rootlesswndproc.c @@ -0,0 +1,1162 @@ +/* + *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + * + *Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + *"Software"), to deal in the Software without restriction, including + *without limitation the rights to use, copy, modify, merge, publish, + *distribute, sublicense, and/or sell copies of the Software, and to + *permit persons to whom the Software is furnished to do so, subject to + *the following conditions: + * + *The above copyright notice and this permission notice shall be + *included in all copies or substantial portions of the Software. + * + *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR + *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *Except as contained in this notice, the name of the XFree86 Project + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from the XFree86 Project. + * + * Authors: Kensuke Matsuzaki + * Earle F. Philhower, III + * Harold L Hunt II + */ +#include "win.h" +#include <winuser.h> +#define _WINDOWSWM_SERVER_ +#include "windowswmstr.h" +#include "dixevents.h" +#include "propertyst.h" +#include "Xatom.h" +#include "winmultiwindowclass.h" + + +/* + * Constant defines + */ + +#define MOUSE_POLLING_INTERVAL 500 +#define MOUSE_ACTIVATE_DEFAULT TRUE +#define RAISE_ON_CLICK_DEFAULT FALSE + + + +/* + * Global variables + */ + +extern Bool g_fNoConfigureWindow; +extern Bool g_fSoftwareCursor; + + +/* + * Local globals + */ + +static UINT_PTR g_uipMousePollingTimerID = 0; + + +/* + * Local function + */ + +DEFINE_ATOM_HELPER(AtmWindowsWmRaiseOnClick, WINDOWSWM_RAISE_ON_CLICK) +DEFINE_ATOM_HELPER(AtmWindowsWMMouseActivate, WINDOWSWM_MOUSE_ACTIVATE) +DEFINE_ATOM_HELPER(AtmWindowsWMClientWindow, WINDOWSWM_CLIENT_WINDOW) + +/* + * ConstrainSize - Taken from TWM sources - Respects hints for sizing + */ +#define makemult(a,b) ((b==1) ? (a) : (((int)((a)/(b))) * (b)) ) +static void +ConstrainSize (WinXSizeHints hints, int *widthp, int *heightp) +{ + int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta; + int baseWidth, baseHeight; + int dwidth = *widthp, dheight = *heightp; + + if (hints.flags & PMinSize) + { + minWidth = hints.min_width; + minHeight = hints.min_height; + } + else if (hints.flags & PBaseSize) + { + minWidth = hints.base_width; + minHeight = hints.base_height; + } + else + minWidth = minHeight = 1; + + if (hints.flags & PBaseSize) + { + baseWidth = hints.base_width; + baseHeight = hints.base_height; + } + else if (hints.flags & PMinSize) + { + baseWidth = hints.min_width; + baseHeight = hints.min_height; + } + else + baseWidth = baseHeight = 0; + + if (hints.flags & PMaxSize) + { + maxWidth = hints.max_width; + maxHeight = hints.max_height; + } + else + { + maxWidth = MAXINT; + maxHeight = MAXINT; + } + + if (hints.flags & PResizeInc) + { + xinc = hints.width_inc; + yinc = hints.height_inc; + } + else + xinc = yinc = 1; + + /* + * First, clamp to min and max values + */ + if (dwidth < minWidth) + dwidth = minWidth; + if (dheight < minHeight) + dheight = minHeight; + + if (dwidth > maxWidth) + dwidth = maxWidth; + if (dheight > maxHeight) + dheight = maxHeight; + + /* + * Second, fit to base + N * inc + */ + dwidth = ((dwidth - baseWidth) / xinc * xinc) + baseWidth; + dheight = ((dheight - baseHeight) / yinc * yinc) + baseHeight; + + /* + * Third, adjust for aspect ratio + */ + + /* + * The math looks like this: + * + * minAspectX dwidth maxAspectX + * ---------- <= ------- <= ---------- + * minAspectY dheight maxAspectY + * + * If that is multiplied out, then the width and height are + * invalid in the following situations: + * + * minAspectX * dheight > minAspectY * dwidth + * maxAspectX * dheight < maxAspectY * dwidth + * + */ + + if (hints.flags & PAspect) + { + if (hints.min_aspect.x * dheight > hints.min_aspect.y * dwidth) + { + delta = makemult(hints.min_aspect.x * dheight / hints.min_aspect.y - dwidth, xinc); + if (dwidth + delta <= maxWidth) + dwidth += delta; + else + { + delta = makemult(dheight - dwidth*hints.min_aspect.y/hints.min_aspect.x, yinc); + if (dheight - delta >= minHeight) + dheight -= delta; + } + } + + if (hints.max_aspect.x * dheight < hints.max_aspect.y * dwidth) + { + delta = makemult(dwidth * hints.max_aspect.y / hints.max_aspect.x - dheight, yinc); + if (dheight + delta <= maxHeight) + dheight += delta; + else + { + delta = makemult(dwidth - hints.max_aspect.x*dheight/hints.max_aspect.y, xinc); + if (dwidth - delta >= minWidth) + dwidth -= delta; + } + } + } + + /* Return computed values */ + *widthp = dwidth; + *heightp = dheight; +} +#undef makemult + + + +/* + * ValidateSizing - Ensures size request respects hints + */ +static int +ValidateSizing (HWND hwnd, WindowPtr pWin, + WPARAM wParam, LPARAM lParam) +{ + WinXSizeHints sizeHints; + RECT *rect; + int iWidth, iHeight, iTopBorder; + POINT pt; + + /* Invalid input checking */ + if (pWin==NULL || lParam==0) + { + ErrorF ("Invalid input checking\n"); + return FALSE; + } + + /* No size hints, no checking */ + if (!winMultiWindowGetWMNormalHints (pWin, &sizeHints)) + { + ErrorF ("No size hints, no checking\n"); + return FALSE; + } + + /* Avoid divide-by-zero */ + if (sizeHints.flags & PResizeInc) + { + if (sizeHints.width_inc == 0) sizeHints.width_inc = 1; + if (sizeHints.height_inc == 0) sizeHints.height_inc = 1; + } + + rect = (RECT*)lParam; + + iWidth = rect->right - rect->left; + iHeight = rect->bottom - rect->top; + + /* Get title bar height, there must be an easier way?! */ + pt.x = pt.y = 0; + ClientToScreen(hwnd, &pt); + iTopBorder = pt.y - rect->top; + + /* Now remove size of any borders */ + iWidth -= 2 * GetSystemMetrics(SM_CXSIZEFRAME); + iHeight -= GetSystemMetrics(SM_CYSIZEFRAME) + iTopBorder; + + /* Constrain the size to legal values */ + ConstrainSize (sizeHints, &iWidth, &iHeight); + + /* Add back the borders */ + iWidth += 2 * GetSystemMetrics(SM_CXSIZEFRAME); + iHeight += GetSystemMetrics(SM_CYSIZEFRAME) + iTopBorder; + + /* Adjust size according to where we're dragging from */ + switch(wParam) { + case WMSZ_TOP: + case WMSZ_TOPRIGHT: + case WMSZ_BOTTOM: + case WMSZ_BOTTOMRIGHT: + case WMSZ_RIGHT: + rect->right = rect->left + iWidth; + break; + default: + rect->left = rect->right - iWidth; + break; + } + switch(wParam) { + case WMSZ_BOTTOM: + case WMSZ_BOTTOMRIGHT: + case WMSZ_BOTTOMLEFT: + case WMSZ_RIGHT: + case WMSZ_LEFT: + rect->bottom = rect->top + iHeight; + break; + default: + rect->top = rect->bottom - iHeight; + break; + } + return TRUE; +} + + +/* + * IsRaiseOnClick + */ + +static Bool +IsRaiseOnClick (WindowPtr pWin) +{ + + struct _Window *pwin; + struct _Property *prop; + WindowPtr pRoot = GetCurrentRootWindow (); + + if (!pWin) + { + ErrorF ("IsRaiseOnClick - no prop use default value:%d\n", + RAISE_ON_CLICK_DEFAULT); + return RAISE_ON_CLICK_DEFAULT; + } + + pwin = (struct _Window*) pWin; + + if (pwin->optional) + prop = (struct _Property *) pwin->optional->userProps; + else + prop = NULL; + + while (prop) + { + if (prop->propertyName == AtmWindowsWmRaiseOnClick () + && prop->type == XA_INTEGER + && prop->format == 32) + { + return *(int*)prop->data; + } + else + prop = prop->next; + } + + if (pWin != pRoot) + { + return IsRaiseOnClick (pRoot); + } + else + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("IsRaiseOnClick - no prop use default value:%d\n", + RAISE_ON_CLICK_DEFAULT); +#endif + return RAISE_ON_CLICK_DEFAULT; + } +} + + +/* + * IsMouseActive + */ + +static Bool +IsMouseActive (WindowPtr pWin) +{ + + struct _Window *pwin; + struct _Property *prop; + WindowPtr pRoot = GetCurrentRootWindow (); + + if (!pWin) + { + ErrorF ("IsMouseActive - pWin was NULL use default value:%d\n", + MOUSE_ACTIVATE_DEFAULT); + return MOUSE_ACTIVATE_DEFAULT; + } + + pwin = (struct _Window*) pWin; + + if (pwin->optional) + prop = (struct _Property *) pwin->optional->userProps; + else + prop = NULL; + + while (prop) + { + if (prop->propertyName == AtmWindowsWMMouseActivate () + && prop->type == XA_INTEGER + && prop->format == 32) + { + return *(int*)prop->data; + } + else + prop = prop->next; + } + + if (pWin != pRoot) + { + return IsMouseActive (pRoot); + } + else + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("IsMouseActive - no prop use default value:%d\n", + MOUSE_ACTIVATE_DEFAULT); +#endif + return MOUSE_ACTIVATE_DEFAULT; + } +} + + +/* + * winMWExtWMWindowProc - Window procedure + */ + +LRESULT CALLBACK +winMWExtWMWindowProc (HWND hwnd, UINT message, + WPARAM wParam, LPARAM lParam) +{ + WindowPtr pWin = NULL; + 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; + LPWINDOWPOS pWinPos = NULL; + RECT rcClient; + XID vlist[2]; + + /* Check if the Windows window property for our X window pointer is valid */ + if ((pRLWinPriv = (win32RootlessWindowPtr)GetProp (hwnd, WIN_WINDOW_PROP)) != NULL) + { + pWin = pRLWinPriv->pFrame->win; + pScreen = pWin->drawable.pScreen; + if (pScreen) pScreenPriv = winGetScreenPriv(pScreen); + if (pScreenPriv) pScreenInfo = pScreenPriv->pScreenInfo; + if (pScreenPriv) hwndScreen = pScreenPriv->hwndScreen; +#if 0 + winDebug ("hWnd %08X\n", hwnd); + winDebug ("pScreenPriv %08X\n", pScreenPriv); + winDebug ("pScreenInfo %08X\n", pScreenInfo); + winDebug ("hwndScreen %08X\n", hwndScreen); + winDebug ("winMWExtWMWindowProc (%08x) %08x %08x %08x\n", + pRLWinPriv, message, wParam, lParam); +#endif + } + /* Branch on message type */ + switch (message) + { + case WM_CREATE: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_CREATE\n"); +#endif + /* */ + SetProp (hwnd, + WIN_WINDOW_PROP, + (HANDLE)((LPCREATESTRUCT) lParam)->lpCreateParams); + return 0; + + case WM_CLOSE: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_CLOSE %d\n", pRLWinPriv->fClose); +#endif + /* Tell window-manager to close window */ + if (pRLWinPriv->fClose) + { + DestroyWindow (hwnd); + } + else + { + winWindowsWMSendEvent(WindowsWMControllerNotify, + WindowsWMControllerNotifyMask, + 1, + WindowsWMCloseWindow, + pWin->drawable.id, + 0, 0, 0, 0); + } + return 0; + + case WM_DESTROY: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_DESTROY\n"); +#endif + /* Free the shaodw 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; + + /* Free shadow buffer info header */ + free (pRLWinPriv->pbmihShadow); + pRLWinPriv->pbmihShadow = NULL; + + pRLWinPriv->fResized = FALSE; + pRLWinPriv->pfb = NULL; + free (pRLWinPriv); + RemoveProp (hwnd, WIN_WINDOW_PROP); + break; + + case WM_MOUSEMOVE: +#if CYGMULTIWINDOW_DEBUG && 0 + winDebug ("winMWExtWMWindowProc - 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 ("winMWExtWMWindowProc - _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 && 0 + winDebug ("winMWExtWMWindowProc - 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 + winDebug ("winMWExtWMWindowProc - 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 + winDebug ("winMWExtWMWindowProc - WM_LBUTTONDBLCLK\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + SetCapture (hwnd); + return winMouseButtonsHandle (pScreen, ButtonPress, Button1, wParam); + + case WM_LBUTTONUP: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - 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 + winDebug ("winMWExtWMWindowProc - WM_MBUTTONDBLCLK\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + SetCapture (hwnd); + return winMouseButtonsHandle (pScreen, ButtonPress, Button2, wParam); + + case WM_MBUTTONUP: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - 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 + winDebug ("winMWExtWMWindowProc - WM_RBUTTONDBLCLK\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + SetCapture (hwnd); + return winMouseButtonsHandle (pScreen, ButtonPress, Button3, wParam); + + case WM_RBUTTONUP: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_RBUTTONUP\n"); +#endif + if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput) + break; + ReleaseCapture (); + return winMouseButtonsHandle (pScreen, ButtonRelease, Button3, wParam); + + case WM_MOUSEWHEEL: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_MOUSEWHEEL\n"); +#endif + + /* Pass the message to the root window */ + SendMessage (hwndScreen, message, wParam, lParam); + return 0; + + case WM_MOUSEACTIVATE: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_MOUSEACTIVATE\n"); +#endif +#if 0 + /* Check if this window needs to be made active when clicked */ + if (pWin->overrideRedirect) + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_MOUSEACTIVATE - " + "MA_NOACTIVATE\n"); +#endif + + /* */ + return MA_NOACTIVATE; + } +#endif + if (!IsMouseActive (pWin)) return MA_NOACTIVATE; + + break; + + 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 + winDebug ("winMWExtWMWindowProc - 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 + winDebug ("winMWExtWMWindowProc - WM_*KEYUP\n"); +#endif + + /* Pass the message to the root window */ + SendMessage (hwndScreen, message, wParam, lParam); + return 0; + + case WM_HOTKEY: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - 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 ("winMWExtWMWindowProc - BitBlt failed: %s\n", + (LPSTR)lpMsgBuf); + LocalFree (lpMsgBuf); + } + + /* EndPaint frees the DC */ + EndPaint (hwnd, &ps); + break; + + case WM_ACTIVATE: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_ACTIVATE\n"); +#endif + if (LOWORD(wParam) != WA_INACTIVE) + { + winWindowsWMSendEvent(WindowsWMControllerNotify, + WindowsWMControllerNotifyMask, + 1, + WindowsWMActivateWindow, + pWin->drawable.id, + 0, 0, + 0, 0); + } + return 0; + +#if 1 + case WM_WINDOWPOSCHANGING: + pWinPos = (LPWINDOWPOS)lParam; + if (!(pWinPos->flags & SWP_NOZORDER)) + { + if (pRLWinPriv->fRestackingNow) + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("Win %08x is now restacking.\n", (unsigned int)pRLWinPriv); +#endif + break; + } + + if (IsRaiseOnClick (pWin)) + { +#if CYGMULTIWINDOW_DEBUG + winDebug ("Win %08x has WINDOWSWM_RAISE_ON_CLICK.\n", (unsigned int)pRLWinPriv); +#endif + break; + } + +#if CYGMULTIWINDOW_DEBUG + winDebug ("Win %08x forbid to change z order (%08x).\n", + (unsigned int)pRLWinPriv, (unsigned int)pWinPos->hwndInsertAfter); +#endif + pWinPos->flags |= SWP_NOZORDER; + } + break; +#endif + + case WM_MOVE: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_MOVE - %d ms\n", + (unsigned int)GetTickCount ()); +#endif + if (g_fNoConfigureWindow) break; +#if 0 + /* Bail if Windows window is not actually moving */ + if (pRLWinPriv->dwX == (short) LOWORD(lParam) + && pRLWinPriv->dwY == (short) HIWORD(lParam)) + break; + + /* Also bail if we're maximizing, we'll do the whole thing in WM_SIZE */ + { + WINDOWPLACEMENT windPlace; + windPlace.length = sizeof (WINDOWPLACEMENT); + + /* Get current window placement */ + GetWindowPlacement (hwnd, &windPlace); + + /* Bail if maximizing */ + if (windPlace.showCmd == SW_MAXIMIZE + || windPlace.showCmd == SW_SHOWMAXIMIZED) + break; + } +#endif + +#if CYGMULTIWINDOW_DEBUG + winDebug ("\t(%d, %d)\n", (short) LOWORD(lParam), (short) HIWORD(lParam)); +#endif + if (!pRLWinPriv->fMovingOrSizing) + { + winMWExtWMMoveXWindow (pWin, + (LOWORD(lParam) - wBorderWidth (pWin) + - GetSystemMetrics (SM_XVIRTUALSCREEN)), + (HIWORD(lParam) - wBorderWidth (pWin) + - GetSystemMetrics (SM_YVIRTUALSCREEN))); + } + return 0; + + case WM_SHOWWINDOW: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_SHOWWINDOW - %d ms\n", + (unsigned int)GetTickCount ()); +#endif + break; + + case WM_SIZING: + /* Need to legalize the size according to WM_NORMAL_HINTS */ + /* for applications like xterm */ + return ValidateSizing (hwnd, pWin, wParam, lParam); + + case WM_WINDOWPOSCHANGED: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_WINDOWPOSCHANGED\n"); +#endif + { + pWinPos = (LPWINDOWPOS) lParam; +#if CYGMULTIWINDOW_DEBUG + winDebug("flags: "); + if (pWinPos->flags & SWP_DRAWFRAME) winDebug("SWP_DRAWFRAME "); + if (pWinPos->flags & SWP_FRAMECHANGED) winDebug("SWP_FRAMECHANGED "); + if (pWinPos->flags & SWP_HIDEWINDOW) winDebug("SWP_HIDEWINDOW "); + if (pWinPos->flags & SWP_NOACTIVATE) winDebug("SWP_NOACTIVATE "); + if (pWinPos->flags & SWP_NOCOPYBITS) winDebug("SWP_NOCOPYBITS "); + if (pWinPos->flags & SWP_NOMOVE) winDebug("SWP_NOMOVE "); + if (pWinPos->flags & SWP_NOOWNERZORDER) winDebug("SWP_NOOWNERZORDER "); + if (pWinPos->flags & SWP_NOSIZE) winDebug("SWP_NOSIZE "); + if (pWinPos->flags & SWP_NOREDRAW) winDebug("SWP_NOREDRAW "); + if (pWinPos->flags & SWP_NOSENDCHANGING) winDebug("SWP_NOSENDCHANGING "); + if (pWinPos->flags & SWP_NOZORDER) winDebug("SWP_NOZORDER "); + if (pWinPos->flags & SWP_SHOWWINDOW) winDebug("SWP_SHOWWINDOW "); + winDebug("\n"); +#endif + if (pWinPos->flags & SWP_HIDEWINDOW) break; + + /* Reorder if window z order was changed */ + if ((pScreenPriv != NULL) + && !(pWinPos->flags & SWP_NOZORDER) + && !(pWinPos->flags & SWP_SHOWWINDOW)) + { + if (pWinPos->hwndInsertAfter == HWND_TOP + ||pWinPos->hwndInsertAfter == HWND_TOPMOST + ||pWinPos->hwndInsertAfter == HWND_NOTOPMOST) + { + vlist[0] = Above; + ConfigureWindow (pWin, CWStackMode, + vlist, wClient(pWin)); + } +#if 1 + else if (pWinPos->hwndInsertAfter == HWND_BOTTOM) + { + } + else + { + /* Check if this window is top of X windows. */ + HWND hWndAbove = NULL; + DWORD dwCurrentProcessID = GetCurrentProcessId (); + DWORD dwWindowProcessID = 0; + + for (hWndAbove = pWinPos->hwndInsertAfter; + hWndAbove != NULL; + hWndAbove = GetNextWindow (hWndAbove, GW_HWNDPREV)) + { + /* Ignore other XWin process's window */ + GetWindowThreadProcessId (hWndAbove, &dwWindowProcessID); + + if ((dwWindowProcessID == dwCurrentProcessID) + && GetProp (Above, WIN_WINDOW_PROP) + && !IsIconic (hwnd) ) /* ignore minimized windows */ + break; + } + /* If this is top of X windows in Windows stack, + raise it in X stack. */ + if (hWndAbove == NULL) + { + vlist[0] = Above; + ConfigureWindow (pWin, CWStackMode, + vlist, wClient(pWin)); + } + } +#endif + } + + if (!(pWinPos->flags & SWP_NOSIZE)) { + if (IsIconic(hwnd)){ +#if CYGMULTIWINDOW_DEBUG + winDebug ("\tIconic -> MINIMIZED\n"); +#endif + winWindowsWMSendEvent(WindowsWMControllerNotify, + WindowsWMControllerNotifyMask, + 1, + WindowsWMMinimizeWindow, + pWin->drawable.id, + 0, 0, 0, 0); + } else if (IsZoomed(hwnd)){ +#if CYGMULTIWINDOW_DEBUG + winDebug ("\tZoomed -> MAXIMIZED\n"); +#endif + winWindowsWMSendEvent(WindowsWMControllerNotify, + WindowsWMControllerNotifyMask, + 1, + WindowsWMMaximizeWindow, + pWin->drawable.id, + 0, 0, 0, 0); + } else { +#if CYGMULTIWINDOW_DEBUG + winDebug ("\tnone -> RESTORED\n"); +#endif + winWindowsWMSendEvent(WindowsWMControllerNotify, + WindowsWMControllerNotifyMask, + 1, + WindowsWMRestoreWindow, + pWin->drawable.id, + 0, 0, 0, 0); + } + } + if (!g_fNoConfigureWindow ) { + + if (!pRLWinPriv->fMovingOrSizing + /*&& (pWinPos->flags & SWP_SHOWWINDOW)*/) { + GetClientRect (hwnd, &rcClient); + MapWindowPoints (hwnd, HWND_DESKTOP, (LPPOINT)&rcClient, 2); + + if (!(pWinPos->flags & SWP_NOMOVE) + &&!(pWinPos->flags & SWP_NOSIZE)) { +#if CYGMULTIWINDOW_DEBUG + winDebug ("\tmove & resize\n"); +#endif + winMWExtWMMoveResizeXWindow (pWin, + rcClient.left - wBorderWidth (pWin) + - GetSystemMetrics (SM_XVIRTUALSCREEN), + rcClient.top - wBorderWidth (pWin) + - GetSystemMetrics (SM_YVIRTUALSCREEN), + rcClient.right - rcClient.left + - wBorderWidth (pWin)*2, + rcClient.bottom - rcClient.top + - wBorderWidth (pWin)*2); + } else if (!(pWinPos->flags & SWP_NOMOVE)) { +#if CYGMULTIWINDOW_DEBUG + winDebug ("\tmove\n"); +#endif + winMWExtWMMoveXWindow (pWin, + rcClient.left - wBorderWidth (pWin) + - GetSystemMetrics (SM_XVIRTUALSCREEN), + rcClient.top - wBorderWidth (pWin) + - GetSystemMetrics (SM_YVIRTUALSCREEN)); + } else if (!(pWinPos->flags & SWP_NOSIZE)) { +#if CYGMULTIWINDOW_DEBUG + winDebug ("\tresize\n"); +#endif + winMWExtWMResizeXWindow (pWin, + rcClient.right - rcClient.left + - wBorderWidth (pWin)*2, + rcClient.bottom - rcClient.top + - wBorderWidth (pWin)*2); + } + } + } + } +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_WINDOWPOSCHANGED - done.\n"); +#endif + return 0; + + case WM_SIZE: + /* see dix/window.c */ + /* FIXME: Maximize/Restore? */ +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_SIZE - %d ms\n", + (unsigned int)GetTickCount ()); +#endif +#if CYGMULTIWINDOW_DEBUG + winDebug ("\t(%d, %d) %d\n", (short) LOWORD(lParam), (short) HIWORD(lParam), g_fNoConfigureWindow); +#endif + if (g_fNoConfigureWindow) break; + + /* Branch on type of resizing occurring */ + switch (wParam) + { + case SIZE_MINIMIZED: +#if CYGMULTIWINDOW_DEBUG + winDebug ("\tSIZE_MINIMIZED\n"); +#endif + winWindowsWMSendEvent(WindowsWMControllerNotify, + WindowsWMControllerNotifyMask, + 1, + WindowsWMMinimizeWindow, + pWin->drawable.id, + 0, 0, + LOWORD(lParam), HIWORD(lParam)); + break; + + case SIZE_RESTORED: +#if CYGMULTIWINDOW_DEBUG + winDebug ("\tSIZE_RESTORED\n"); +#endif + winWindowsWMSendEvent(WindowsWMControllerNotify, + WindowsWMControllerNotifyMask, + 1, + WindowsWMRestoreWindow, + pWin->drawable.id, + 0, 0, + LOWORD(lParam), HIWORD(lParam)); + break; + + case SIZE_MAXIMIZED: +#if CYGMULTIWINDOW_DEBUG + winDebug ("\tSIZE_MAXIMIZED\n"); +#endif + winWindowsWMSendEvent(WindowsWMControllerNotify, + WindowsWMControllerNotifyMask, + 1, + WindowsWMMaximizeWindow, + pWin->drawable.id, + 0, 0, + LOWORD(lParam), HIWORD(lParam)); + break; + } + + /* Perform the resize and notify the X client */ + if (!pRLWinPriv->fMovingOrSizing) + { + winMWExtWMResizeXWindow (pWin, + (short) LOWORD(lParam) + - wBorderWidth (pWin)*2, + (short) HIWORD(lParam) + - wBorderWidth (pWin)*2); + } + break; + + case WM_ACTIVATEAPP: + if (wParam) + { + winWindowsWMSendEvent(WindowsWMActivationNotify, + WindowsWMActivationNotifyMask, + 1, + WindowsWMIsActive, + pWin->drawable.id, + 0, 0, + 0, 0); + } + else + { + winWindowsWMSendEvent(WindowsWMActivationNotify, + WindowsWMActivationNotifyMask, + 1, + WindowsWMIsInactive, + pWin->drawable.id, + 0, 0, + 0, 0); + } + break; + + case WM_SETCURSOR: + if (LOWORD(lParam) == HTCLIENT) + { + if (!g_fSoftwareCursor) SetCursor (pScreenPriv->cursor.handle); + return TRUE; + } + break; + + case WM_ENTERSIZEMOVE: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_ENTERSIZEMOVE - %d ms\n", + (unsigned int)GetTickCount ()); +#endif + pRLWinPriv->fMovingOrSizing = TRUE; + break; + + case WM_EXITSIZEMOVE: +#if CYGMULTIWINDOW_DEBUG + winDebug ("winMWExtWMWindowProc - WM_EXITSIZEMOVE - %d ms\n", + (unsigned int)GetTickCount ()); +#endif + pRLWinPriv->fMovingOrSizing = FALSE; + + GetClientRect (hwnd, &rcClient); + + MapWindowPoints (hwnd, HWND_DESKTOP, (LPPOINT)&rcClient, 2); + winMWExtWMMoveResizeXWindow (pWin, + rcClient.left - wBorderWidth (pWin) + - GetSystemMetrics (SM_XVIRTUALSCREEN), + rcClient.top - wBorderWidth (pWin) + - GetSystemMetrics (SM_YVIRTUALSCREEN), + rcClient.right - rcClient.left + - wBorderWidth (pWin)*2, + rcClient.bottom - rcClient.top + - wBorderWidth (pWin)*2); + break; + + default: + break; + } + + return DefWindowProc (hwnd, message, wParam, lParam); +} diff --git a/hw/xwin/winwindow.c b/hw/xwin/winwindow.c index 378465bc4..86dd71178 100644 --- a/hw/xwin/winwindow.c +++ b/hw/xwin/winwindow.c @@ -32,6 +32,7 @@ #include "win.h" + /* * Prototypes for local functions */ @@ -41,15 +42,16 @@ winAddRgn (WindowPtr pWindow, pointer data); static void -winUpdateRgnPRootless (WindowPtr pWindow); +winUpdateRgnRootless (WindowPtr pWindow); #ifdef SHAPE static void -winReshapePRootless (WindowPtr pWin); +winReshapeRootless (WindowPtr pWin); #endif +#ifdef XWIN_NATIVEGDI /* See Porting Layer Definition - p. 37 */ /* See mfb/mfbwindow.c - mfbCreateWindow() */ @@ -212,19 +214,20 @@ winMapWindowNativeGDI (WindowPtr pWindow) return TRUE; } +#endif /* See Porting Layer Definition - p. 37 */ /* See mfb/mfbwindow.c - mfbCreateWindow() */ Bool -winCreateWindowPRootless (WindowPtr pWin) +winCreateWindowRootless (WindowPtr pWin) { Bool fResult = FALSE; winWindowPriv(pWin); #if CYGDEBUG - ErrorF ("winCreateWindowPRootless ()\n"); + winDebug ("winCreateWindowRootless ()\n"); #endif fResult = winGetScreenPriv(pWin->drawable.pScreen)->CreateWindow(pWin); @@ -239,13 +242,13 @@ winCreateWindowPRootless (WindowPtr pWin) /* See mfb/mfbwindow.c - mfbDestroyWindow() */ Bool -winDestroyWindowPRootless (WindowPtr pWin) +winDestroyWindowRootless (WindowPtr pWin) { Bool fResult = FALSE; winWindowPriv(pWin); #if CYGDEBUG - ErrorF ("winDestroyWindowPRootless ()\n"); + winDebug ("winDestroyWindowRootless ()\n"); #endif fResult = winGetScreenPriv(pWin->drawable.pScreen)->DestroyWindow(pWin); @@ -256,7 +259,7 @@ winDestroyWindowPRootless (WindowPtr pWin) pWinPriv->hRgn = NULL; } - winUpdateRgnPRootless (pWin); + winUpdateRgnRootless (pWin); return fResult; } @@ -266,17 +269,17 @@ winDestroyWindowPRootless (WindowPtr pWin) /* See mfb/mfbwindow.c - mfbPositionWindow() */ Bool -winPositionWindowPRootless (WindowPtr pWin, int x, int y) +winPositionWindowRootless (WindowPtr pWin, int x, int y) { Bool fResult = FALSE; #if CYGDEBUG - ErrorF ("winPositionWindowPRootless ()\n"); + winDebug ("winPositionWindowRootless ()\n"); #endif fResult = winGetScreenPriv(pWin->drawable.pScreen)->PositionWindow(pWin, x, y); - winUpdateRgnPRootless (pWin); + winUpdateRgnRootless (pWin); return fResult; } @@ -286,17 +289,17 @@ winPositionWindowPRootless (WindowPtr pWin, int x, int y) /* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */ Bool -winChangeWindowAttributesPRootless (WindowPtr pWin, unsigned long mask) +winChangeWindowAttributesRootless (WindowPtr pWin, unsigned long mask) { Bool fResult = FALSE; #if CYGDEBUG - ErrorF ("winChangeWindowAttributesPRootless ()\n"); + winDebug ("winChangeWindowAttributesRootless ()\n"); #endif fResult = winGetScreenPriv(pWin->drawable.pScreen)->ChangeWindowAttributes(pWin, mask); - winUpdateRgnPRootless (pWin); + winUpdateRgnRootless (pWin); return fResult; } @@ -307,13 +310,13 @@ winChangeWindowAttributesPRootless (WindowPtr pWin, unsigned long mask) */ Bool -winUnmapWindowPRootless (WindowPtr pWin) +winUnmapWindowRootless (WindowPtr pWin) { Bool fResult = FALSE; winWindowPriv(pWin); #if CYGDEBUG - ErrorF ("winUnmapWindowPRootless ()\n"); + winDebug ("winUnmapWindowRootless ()\n"); #endif fResult = winGetScreenPriv(pWin->drawable.pScreen)->UnrealizeWindow(pWin); @@ -324,7 +327,7 @@ winUnmapWindowPRootless (WindowPtr pWin) pWinPriv->hRgn = NULL; } - winUpdateRgnPRootless (pWin); + winUpdateRgnRootless (pWin); return fResult; } @@ -335,19 +338,21 @@ winUnmapWindowPRootless (WindowPtr pWin) */ Bool -winMapWindowPRootless (WindowPtr pWin) +winMapWindowRootless (WindowPtr pWin) { Bool fResult = FALSE; #if CYGDEBUG - ErrorF ("winMapWindowPRootless ()\n"); + winDebug ("winMapWindowRootless ()\n"); #endif fResult = winGetScreenPriv(pWin->drawable.pScreen)->RealizeWindow(pWin); + +#ifdef SHAPE + winReshapeRootless (pWin); +#endif - winReshapePRootless (pWin); - - winUpdateRgnPRootless (pWin); + winUpdateRgnRootless (pWin); return fResult; } @@ -355,16 +360,16 @@ winMapWindowPRootless (WindowPtr pWin) #ifdef SHAPE void -winSetShapePRootless (WindowPtr pWin) +winSetShapeRootless (WindowPtr pWin) { #if CYGDEBUG - ErrorF ("winSetShapePRootless ()\n"); + winDebug ("winSetShapeRootless ()\n"); #endif winGetScreenPriv(pWin->drawable.pScreen)->SetShape(pWin); - winReshapePRootless (pWin); - winUpdateRgnPRootless (pWin); + winReshapeRootless (pWin); + winUpdateRgnRootless (pWin); return; } @@ -388,7 +393,7 @@ winAddRgn (WindowPtr pWin, pointer data) if (pWin->parent != NULL) { #if CYGDEBUG - ErrorF ("winAddRgn ()\n"); + winDebug ("winAddRgn ()\n"); #endif if (pWin->mapped) { @@ -442,7 +447,7 @@ winAddRgn (WindowPtr pWin, pointer data) static void -winUpdateRgnPRootless (WindowPtr pWin) +winUpdateRgnRootless (WindowPtr pWin) { HRGN hRgn = CreateRectRgn (0, 0, 0, 0); @@ -454,7 +459,7 @@ winUpdateRgnPRootless (WindowPtr pWin) } else { - ErrorF ("winUpdateRgnPRootless - CreateRectRgn failed.\n"); + ErrorF ("winUpdateRgnRootless - CreateRectRgn failed.\n"); } } @@ -462,7 +467,7 @@ winUpdateRgnPRootless (WindowPtr pWin) #ifdef SHAPE static void -winReshapePRootless (WindowPtr pWin) +winReshapeRootless (WindowPtr pWin) { int nRects; ScreenPtr pScreen = pWin->drawable.pScreen; @@ -472,7 +477,7 @@ winReshapePRootless (WindowPtr pWin) winWindowPriv(pWin); #if CYGDEBUG - ErrorF ("winReshapePRootless ()\n"); + winDebug ("winReshapeRootless ()\n"); #endif /* Bail if the window is the root window */ @@ -515,13 +520,13 @@ winReshapePRootless (WindowPtr pWin) pRects->x2, pRects->y2); if (hRgnRect == NULL) { - ErrorF("winReshapePRootless - CreateRectRgn() failed\n"); + ErrorF("winReshapeRootless - CreateRectRgn() failed\n"); } /* Merge the Windows region with the accumulated region */ if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR) { - ErrorF("winReshapePRootless - CombineRgn() failed\n"); + ErrorF("winReshapeRootless - CombineRgn() failed\n"); } /* Delete the temporary Windows region */ diff --git a/hw/xwin/winwindow.h b/hw/xwin/winwindow.h index b8e164c2b..b4a92187a 100644 --- a/hw/xwin/winwindow.h +++ b/hw/xwin/winwindow.h @@ -1,3 +1,5 @@ +#if !defined(_WINWINDOW_H_) +#define _WINWINDOW_H_ /* *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. * @@ -29,10 +31,6 @@ */ /* $XFree86: xc/programs/Xserver/hw/xwin/winwindow.h,v 1.3 2003/10/02 13:30:11 eich Exp $ */ - -#ifndef _WINWINDOW_H_ -#define _WINWINDOW_H_ - #ifndef NO #define NO 0 #endif @@ -49,11 +47,15 @@ #define WINDOW_TITLE_X "Cygwin/X X" #define WIN_WINDOW_PROP "cyg_window_prop_rl" #define WIN_MSG_QUEUE_FNAME "/dev/windows" -#define WIN_LOG_FNAME "/tmp/XWin.log" #define WIN_WID_PROP "cyg_wid_prop_rl" #define WIN_NEEDMANAGE_PROP "cyg_override_redirect_prop_rl" -#define WIN_HWND_CACHE "cyg_privmap_rl" +#define WIN_HWND_CACHE "cyg_privmap_rl" +#ifndef CYGMULTIWINDOW_DEBUG #define CYGMULTIWINDOW_DEBUG NO +#endif +#ifndef CYGWINDOWING_DEBUG +#define CYGWINDOWING_DEBUG NO +#endif typedef struct _winPrivScreenRec *winPrivScreenPtr; @@ -68,15 +70,19 @@ typedef struct HRGN hRgn; HWND hWnd; winPrivScreenPtr pScreenPriv; - int iX; - int iY; - int iWidth; - int iHeight; Bool fXKilled; - Bool fNeedRestore; - POINT ptRestore; + + /* Privates used by primary fb DirectDraw server */ + LPDDSURFACEDESC pddsdPrimary; + + /* Privates used by shadow fb DirectDraw Nonlocking server */ + LPDIRECTDRAWSURFACE4 pddsPrimary4; + + /* Privates used by both shadow fb DirectDraw servers */ + LPDIRECTDRAWCLIPPER pddcPrimary; } winPrivWinRec, *winPrivWinPtr; +#ifdef XWIN_MULTIWINDOW typedef struct _winWMMessageRec{ DWORD dwID; DWORD msg; @@ -88,7 +94,7 @@ typedef struct _winWMMessageRec{ /* - * winrootlesswm.c + * winmultiwindowwm.c */ #define WM_WM_MOVE (WM_USER + 1) @@ -103,11 +109,6 @@ typedef struct _winWMMessageRec{ #define WM_WM_HINTS_EVENT (WM_USER + 10) #define WM_WM_CHANGE_STATE (WM_USER + 11) - -/* - * winmultiwindowwm.c - */ - void winSendMessageToWM (void *pWMInfo, winWMMessagePtr msg); @@ -119,7 +120,7 @@ winInitWM (void **ppWMInfo, int dwScreen); void -winDeinitMultiWindowWM (); +winDeinitMultiWindowWM (void); void winMinimizeWindow (Window id); @@ -132,4 +133,11 @@ winMinimizeWindow (Window id); void winUpdateIcon (Window id); +void +winInitGlobalIcons (void); + +void +winDestroyIcon(HICON hIcon); + +#endif /* XWIN_MULTIWINDOW */ #endif diff --git a/hw/xwin/winwindowswm.c b/hw/xwin/winwindowswm.c new file mode 100755 index 000000000..a63c09210 --- /dev/null +++ b/hw/xwin/winwindowswm.c @@ -0,0 +1,663 @@ +/* WindowsWM extension is based on AppleWM extension */ +/************************************************************************** + +Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved. +Copyright (c) 2003 Torrey T. Lyons. 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, sub license, 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 (including the +next paragraph) 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 NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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. + +**************************************************************************/ + +#include "win.h" + +#define NEED_REPLIES +#define NEED_EVENTS +#include "misc.h" +#include "dixstruct.h" +#include "extnsionst.h" +#include "colormapst.h" +#include "cursorstr.h" +#include "scrnintstr.h" +#include "servermd.h" +#include "swaprep.h" +#define _WINDOWSWM_SERVER_ +#include "windowswmstr.h" + +static int WMErrorBase; + +static DISPATCH_PROC(ProcWindowsWMDispatch); +static DISPATCH_PROC(SProcWindowsWMDispatch); + +static void WindowsWMResetProc(ExtensionEntry* extEntry); + +static unsigned char WMReqCode = 0; +static int WMEventBase = 0; + +static RESTYPE ClientType, EventType; /* resource types for event masks */ +static XID eventResource; + +/* Currently selected events */ +static unsigned int eventMask = 0; + +static int WMFreeClient (pointer data, XID id); +static int WMFreeEvents (pointer data, XID id); +static void SNotifyEvent(xWindowsWMNotifyEvent *from, xWindowsWMNotifyEvent *to); + +typedef struct _WMEvent *WMEventPtr; +typedef struct _WMEvent { + WMEventPtr next; + ClientPtr client; + XID clientResource; + unsigned int mask; +} WMEventRec; + +static inline BoxRec +make_box (int x, int y, int w, int h) +{ + BoxRec r; + r.x1 = x; + r.y1 = y; + r.x2 = x + w; + r.y2 = y + h; + return r; +} + +void +winWindowsWMExtensionInit () +{ + ExtensionEntry* extEntry; + + ClientType = CreateNewResourceType(WMFreeClient); + EventType = CreateNewResourceType(WMFreeEvents); + eventResource = FakeClientID(0); + + if (ClientType && EventType && + (extEntry = AddExtension(WINDOWSWMNAME, + WindowsWMNumberEvents, + WindowsWMNumberErrors, + ProcWindowsWMDispatch, + SProcWindowsWMDispatch, + WindowsWMResetProc, + StandardMinorOpcode))) + { + WMReqCode = (unsigned char)extEntry->base; + WMErrorBase = extEntry->errorBase; + WMEventBase = extEntry->eventBase; + EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent; + } +} + +/*ARGSUSED*/ +static void +WindowsWMResetProc (ExtensionEntry* extEntry) +{ +} + +static int +ProcWindowsWMQueryVersion(register ClientPtr client) +{ + xWindowsWMQueryVersionReply rep; + register int n; + + REQUEST_SIZE_MATCH(xWindowsWMQueryVersionReq); + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.majorVersion = WINDOWS_WM_MAJOR_VERSION; + rep.minorVersion = WINDOWS_WM_MINOR_VERSION; + rep.patchVersion = WINDOWS_WM_PATCH_VERSION; + if (client->swapped) + { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + } + WriteToClient(client, sizeof(xWindowsWMQueryVersionReply), (char *)&rep); + return (client->noClientException); +} + + +/* events */ + +static inline void +updateEventMask (WMEventPtr *pHead) +{ + WMEventPtr pCur; + + eventMask = 0; + for (pCur = *pHead; pCur != NULL; pCur = pCur->next) + eventMask |= pCur->mask; +} + +/*ARGSUSED*/ +static int +WMFreeClient (pointer data, XID id) +{ + WMEventPtr pEvent; + WMEventPtr *pHead, pCur, pPrev; + + pEvent = (WMEventPtr) data; + pHead = (WMEventPtr *) LookupIDByType(eventResource, EventType); + if (pHead) + { + pPrev = 0; + for (pCur = *pHead; pCur && pCur != pEvent; pCur=pCur->next) + pPrev = pCur; + if (pCur) + { + if (pPrev) + pPrev->next = pEvent->next; + else + *pHead = pEvent->next; + } + updateEventMask (pHead); + } + xfree ((pointer) pEvent); + return 1; +} + +/*ARGSUSED*/ +static int +WMFreeEvents (pointer data, XID id) +{ + WMEventPtr *pHead, pCur, pNext; + + pHead = (WMEventPtr *) data; + for (pCur = *pHead; pCur; pCur = pNext) + { + pNext = pCur->next; + FreeResource (pCur->clientResource, ClientType); + xfree ((pointer) pCur); + } + xfree ((pointer) pHead); + eventMask = 0; + return 1; +} + +static int +ProcWindowsWMSelectInput (register ClientPtr client) +{ + REQUEST(xWindowsWMSelectInputReq); + WMEventPtr pEvent, pNewEvent, *pHead; + XID clientResource; + + REQUEST_SIZE_MATCH (xWindowsWMSelectInputReq); + pHead = (WMEventPtr *)SecurityLookupIDByType(client, eventResource, + EventType, SecurityWriteAccess); + if (stuff->mask != 0) + { + if (pHead) + { + /* check for existing entry. */ + for (pEvent = *pHead; pEvent; pEvent = pEvent->next) + { + if (pEvent->client == client) + { + pEvent->mask = stuff->mask; + updateEventMask (pHead); + return Success; + } + } + } + + /* build the entry */ + pNewEvent = (WMEventPtr) xalloc (sizeof (WMEventRec)); + if (!pNewEvent) + return BadAlloc; + pNewEvent->next = 0; + pNewEvent->client = client; + pNewEvent->mask = stuff->mask; + /* + * add a resource that will be deleted when + * the client goes away + */ + clientResource = FakeClientID (client->index); + pNewEvent->clientResource = clientResource; + if (!AddResource (clientResource, ClientType, (pointer)pNewEvent)) + return BadAlloc; + /* + * create a resource to contain a pointer to the list + * of clients selecting input. This must be indirect as + * the list may be arbitrarily rearranged which cannot be + * done through the resource database. + */ + if (!pHead) + { + pHead = (WMEventPtr *) xalloc (sizeof (WMEventPtr)); + if (!pHead || + !AddResource (eventResource, EventType, (pointer)pHead)) + { + FreeResource (clientResource, RT_NONE); + return BadAlloc; + } + *pHead = 0; + } + pNewEvent->next = *pHead; + *pHead = pNewEvent; + updateEventMask (pHead); + } + else if (stuff->mask == 0) + { + /* delete the interest */ + if (pHead) + { + pNewEvent = 0; + for (pEvent = *pHead; pEvent; pEvent = pEvent->next) + { + if (pEvent->client == client) + break; + pNewEvent = pEvent; + } + if (pEvent) + { + FreeResource (pEvent->clientResource, ClientType); + if (pNewEvent) + pNewEvent->next = pEvent->next; + else + *pHead = pEvent->next; + xfree (pEvent); + updateEventMask (pHead); + } + } + } + else + { + client->errorValue = stuff->mask; + return BadValue; + } + return Success; +} + +/* + * deliver the event + */ + +void +winWindowsWMSendEvent (int type, unsigned int mask, int which, int arg, + Window window, int x, int y, int w, int h) +{ + WMEventPtr *pHead, pEvent; + ClientPtr client; + xWindowsWMNotifyEvent se; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWindowsWMSendEvent %d %d %d %d, %d %d - %d %d\n", + type, mask, which, arg, x, y, w, h); +#endif + pHead = (WMEventPtr *) LookupIDByType(eventResource, EventType); + if (!pHead) + return; + for (pEvent = *pHead; pEvent; pEvent = pEvent->next) + { + client = pEvent->client; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWindowsWMSendEvent - x%08x\n", (int) client); +#endif + if ((pEvent->mask & mask) == 0 + || client == serverClient || client->clientGone) + { + continue; + } +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winWindowsWMSendEvent - send\n"); +#endif + se.type = type + WMEventBase; + se.kind = which; + se.window = window; + se.arg = arg; + se.x = x; + se.y = y; + se.w = w; + se.h = h; + se.sequenceNumber = client->sequence; + se.time = currentTime.milliseconds; + WriteEventsToClient (client, 1, (xEvent *) &se); + } +} + +/* Safe to call from any thread. */ +unsigned int +WindowsWMSelectedEvents (void) +{ + return eventMask; +} + + +/* general utility functions */ + +static int +ProcWindowsWMDisableUpdate (register ClientPtr client) +{ + REQUEST_SIZE_MATCH(xWindowsWMDisableUpdateReq); + + //winDisableUpdate(); + + return (client->noClientException); +} + +static int +ProcWindowsWMReenableUpdate (register ClientPtr client) +{ + REQUEST_SIZE_MATCH(xWindowsWMReenableUpdateReq); + + //winEnableUpdate(); + + return (client->noClientException); +} + + +/* window functions */ + +static int +ProcWindowsWMSetFrontProcess (register ClientPtr client) +{ + REQUEST_SIZE_MATCH(xWindowsWMSetFrontProcessReq); + + //QuartzMessageMainThread(kWindowsSetFrontProcess, NULL, 0); + + return (client->noClientException); +} + + +/* frame functions */ + +static int +ProcWindowsWMFrameGetRect (register ClientPtr client) +{ + xWindowsWMFrameGetRectReply rep; + BoxRec ir; + RECT rcNew; + REQUEST(xWindowsWMFrameGetRectReq); + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameGetRect %d %d\n", + (sizeof(xWindowsWMFrameGetRectReq) >> 2), (int) client->req_len); +#endif + + REQUEST_SIZE_MATCH(xWindowsWMFrameGetRectReq); + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + + ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih); + + if (stuff->frame_rect != 0) + { + ErrorF ("ProcWindowsWMFrameGetRect - stuff->frame_rect != 0\n"); + return BadValue; + } + + /* Store the origin, height, and width in a rectangle structure */ + SetRect (&rcNew, stuff->ix, stuff->iy, + stuff->ix + stuff->iw, stuff->iy + stuff->ih); + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameGetRect - %d %d %d %d\n", + stuff->ix, stuff->iy, stuff->ix + stuff->iw, stuff->iy + stuff->ih); +#endif + + /* + * Calculate the required size of the Windows window rectangle, + * given the size of the Windows window client area. + */ + AdjustWindowRectEx (&rcNew, stuff->frame_style, FALSE, stuff->frame_style_ex); + rep.x = rcNew.left; + rep.y = rcNew.top; + rep.w = rcNew.right - rcNew.left; + rep.h = rcNew.bottom - rcNew.top; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameGetRect - %d %d %d %d\n", + rep.x, rep.y, rep.w, rep.h); +#endif + + WriteToClient(client, sizeof(xWindowsWMFrameGetRectReply), (char *)&rep); + return (client->noClientException); +} + + +static int +ProcWindowsWMFrameDraw (register ClientPtr client) +{ + REQUEST(xWindowsWMFrameDrawReq); + WindowPtr pWin; + win32RootlessWindowPtr pRLWinPriv; + RECT rcNew; + int nCmdShow; + RegionRec newShape; + ScreenPtr pScreen; + + REQUEST_SIZE_MATCH (xWindowsWMFrameDrawReq); + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameDraw\n"); +#endif + if (!(pWin = SecurityLookupWindow((Drawable)stuff->window, + client, SecurityReadAccess))) + { + return BadValue; + } +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameDraw - Window found\n"); +#endif + + pRLWinPriv = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, TRUE); + if (pRLWinPriv == 0) return BadWindow; + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameDraw - HWND 0x%08x 0x%08x 0x%08x\n", + (int) pRLWinPriv->hWnd, (int) stuff->frame_style, + (int) stuff->frame_style_ex); + ErrorF ("ProcWindowsWMFrameDraw - %d %d %d %d\n", + stuff->ix, stuff->iy, stuff->iw, stuff->ih); +#endif + + /* Store the origin, height, and width in a rectangle structure */ + SetRect (&rcNew, stuff->ix, stuff->iy, + stuff->ix + stuff->iw, stuff->iy + stuff->ih); + + /* + * Calculate the required size of the Windows window rectangle, + * given the size of the Windows window client area. + */ + AdjustWindowRectEx (&rcNew, stuff->frame_style, FALSE, stuff->frame_style_ex); + + /* Set the window extended style flags */ + if (!SetWindowLongPtr (pRLWinPriv->hWnd, GWL_EXSTYLE, stuff->frame_style_ex)) + { + return BadValue; + } + + /* Set the window standard style flags */ + if (!SetWindowLongPtr (pRLWinPriv->hWnd, GWL_STYLE, stuff->frame_style)) + { + return BadValue; + } + + /* Flush the window style */ + if (!SetWindowPos (pRLWinPriv->hWnd, NULL, + rcNew.left, rcNew.top, + rcNew.right - rcNew.left, rcNew.bottom - rcNew.top, + SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE)) + { + return BadValue; + } + if (!IsWindowVisible(pRLWinPriv->hWnd)) + nCmdShow = SW_HIDE; + else + nCmdShow = SW_SHOWNA; + + ShowWindow (pRLWinPriv->hWnd, nCmdShow); + + winMWExtWMUpdateIcon (pWin->drawable.id); + + if (wBoundingShape(pWin) != NULL) + { + pScreen = pWin->drawable.pScreen; + /* wBoundingShape is relative to *inner* origin of window. + Translate by borderWidth to get the outside-relative position. */ + + REGION_NULL(pScreen, &newShape); + REGION_COPY(pScreen, &newShape, wBoundingShape(pWin)); + REGION_TRANSLATE(pScreen, &newShape, pWin->borderWidth, pWin->borderWidth); + winMWExtWMReshapeFrame (pRLWinPriv, &newShape); + REGION_UNINIT(pScreen, &newShape); + } +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameDraw - done\n"); +#endif + + return (client->noClientException); +} + +static int +ProcWindowsWMFrameSetTitle( + register ClientPtr client + ) +{ + unsigned int title_length, title_max; + unsigned char *title_bytes; + REQUEST(xWindowsWMFrameSetTitleReq); + WindowPtr pWin; + win32RootlessWindowPtr pRLWinPriv; + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameSetTitle\n"); +#endif + + REQUEST_AT_LEAST_SIZE(xWindowsWMFrameSetTitleReq); + + if (!(pWin = SecurityLookupWindow((Drawable)stuff->window, + client, SecurityReadAccess))) + { + return BadValue; + } +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameSetTitle - Window found\n"); +#endif + + title_length = stuff->title_length; + title_max = (stuff->length << 2) - sizeof(xWindowsWMFrameSetTitleReq); + + if (title_max < title_length) + return BadValue; + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameSetTitle - length is valid\n"); +#endif + + title_bytes = malloc (title_length+1); + strncpy (title_bytes, (unsigned char *) &stuff[1], title_length); + title_bytes[title_length] = '\0'; + + pRLWinPriv = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE); + + if (pRLWinPriv == 0) + { + free (title_bytes); + return BadWindow; + } + + /* Flush the window style */ + SetWindowText (pRLWinPriv->hWnd, title_bytes); + + free (title_bytes); + +#if CYGMULTIWINDOW_DEBUG + ErrorF ("ProcWindowsWMFrameSetTitle - done\n"); +#endif + + return (client->noClientException); +} + + +/* dispatch */ + +static int +ProcWindowsWMDispatch (register ClientPtr client) +{ + REQUEST(xReq); + + switch (stuff->data) + { + case X_WindowsWMQueryVersion: + return ProcWindowsWMQueryVersion(client); + } + + if (!LocalClient(client)) + return WMErrorBase + WindowsWMClientNotLocal; + + switch (stuff->data) + { + case X_WindowsWMSelectInput: + return ProcWindowsWMSelectInput(client); + case X_WindowsWMDisableUpdate: + return ProcWindowsWMDisableUpdate(client); + case X_WindowsWMReenableUpdate: + return ProcWindowsWMReenableUpdate(client); + case X_WindowsWMSetFrontProcess: + return ProcWindowsWMSetFrontProcess(client); + case X_WindowsWMFrameGetRect: + return ProcWindowsWMFrameGetRect(client); + case X_WindowsWMFrameDraw: + return ProcWindowsWMFrameDraw(client); + case X_WindowsWMFrameSetTitle: + return ProcWindowsWMFrameSetTitle(client); + default: + return BadRequest; + } +} + +static void +SNotifyEvent (xWindowsWMNotifyEvent *from, xWindowsWMNotifyEvent *to) +{ + to->type = from->type; + to->kind = from->kind; + cpswaps (from->sequenceNumber, to->sequenceNumber); + cpswapl (from->window, to->window); + cpswapl (from->time, to->time); + cpswapl (from->arg, to->arg); +} + +static int +SProcWindowsWMQueryVersion (register ClientPtr client) +{ + register int n; + REQUEST(xWindowsWMQueryVersionReq); + swaps(&stuff->length, n); + return ProcWindowsWMQueryVersion(client); +} + +static int +SProcWindowsWMDispatch (register ClientPtr client) +{ + REQUEST(xReq); + + /* It is bound to be non-local when there is byte swapping */ + if (!LocalClient(client)) + return WMErrorBase + WindowsWMClientNotLocal; + + /* only local clients are allowed WM access */ + switch (stuff->data) + { + case X_WindowsWMQueryVersion: + return SProcWindowsWMQueryVersion(client); + default: + return BadRequest; + } +} diff --git a/hw/xwin/winwndproc.c b/hw/xwin/winwndproc.c index 535882753..e9a644e40 100644 --- a/hw/xwin/winwndproc.c +++ b/hw/xwin/winwndproc.c @@ -36,14 +36,27 @@ #include "win.h" #include <commctrl.h> #include "winprefs.h" +#include "winconfig.h" +#if CYGDEBUG +#include "winmessages.h" +#endif /* * Global variables */ -Bool g_fCursor = TRUE; +Bool g_fCursor = TRUE; + +/* + * References to external symbols + */ +extern Bool g_fClipboard; +extern HWND g_hDlgDepthChange; +extern Bool g_fKeyboardHookLL; +extern HWND g_hwndKeyboardFocus; +extern Bool g_fSoftwareCursor; /* * Called by winWakeupHandler @@ -61,9 +74,23 @@ winWindowProc (HWND hwnd, UINT message, static HINSTANCE s_hInstance; static Bool s_fTracking = FALSE; static unsigned long s_ulServerGeneration = 0; + static UINT s_uTaskbarRestart = 0; int iScanCode; int i; +#if CYGDEBUG + if (message >= WM_USER) + { + winDebug("winWindowProc - Message WM_USER + %d", message - WM_USER); + winDebug(" wParam 0x%x lParam 0x%x\n", wParam, lParam); + } + else if (message < MESSAGE_NAMES_LEN && MESSAGE_NAMES[message]) + { + winDebug("winWindowProc - Message %s", MESSAGE_NAMES[message]); + winDebug(" wParam 0x%x lParam 0x%x\n", wParam, lParam); + } +#endif + /* Watch for server regeneration */ if (g_ulServerGeneration != s_ulServerGeneration) { @@ -76,7 +103,7 @@ winWindowProc (HWND hwnd, UINT message, && (s_pScreenPriv = GetProp (hwnd, WIN_SCR_PROP)) != NULL) { #if CYGDEBUG - ErrorF ("winWindowProc - Setting privates handle\n"); + winDebug ("winWindowProc - Setting privates handle\n"); #endif s_pScreenInfo = s_pScreenPriv->pScreenInfo; s_pScreen = s_pScreenInfo->pScreen; @@ -99,7 +126,7 @@ winWindowProc (HWND hwnd, UINT message, case WM_CREATE: #if CYGDEBUG - ErrorF ("winWindowProc - WM_CREATE\n"); + winDebug ("winWindowProc - WM_CREATE\n"); #endif /* @@ -116,11 +143,9 @@ winWindowProc (HWND hwnd, UINT message, s_pScreenInfo = s_pScreenPriv->pScreenInfo; s_pScreen = s_pScreenInfo->pScreen; s_hwndLastPrivates = hwnd; + s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated")); SetProp (hwnd, WIN_SCR_PROP, s_pScreenPriv); - /* Store the mode key states so restore doesn't try to restore them */ - winStoreModeKeyStates (s_pScreen); - /* Setup tray icon */ if (!s_pScreenInfo->fNoTrayIcon) { @@ -154,7 +179,10 @@ winWindowProc (HWND hwnd, UINT message, if (s_pScreenInfo->fFullScreen && (s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD || s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL - || s_pScreenInfo->dwEngine == WIN_SERVER_PRIMARY_DD)) +#ifdef XWIN_PRIMARYFB + || s_pScreenInfo->dwEngine == WIN_SERVER_PRIMARY_DD +#endif + )) { /* * Store the new display dimensions and depth. @@ -170,8 +198,8 @@ winWindowProc (HWND hwnd, UINT message, ErrorF ("winWindowProc - WM_DISPLAYCHANGE - orig bpp: %d, last bpp: %d, " "new bpp: %d\n", - s_pScreenInfo->dwBPP, - s_pScreenPriv->dwLastWindowsBitsPixel, + (int) s_pScreenInfo->dwBPP, + (int) s_pScreenPriv->dwLastWindowsBitsPixel, wParam); ErrorF ("winWindowProc - WM_DISPLAYCHANGE - new width: %d " @@ -208,7 +236,10 @@ winWindowProc (HWND hwnd, UINT message, if ((s_pScreenInfo->dwBPP != wParam) && (s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD || s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL - || s_pScreenInfo->dwEngine == WIN_SERVER_PRIMARY_DD)) +#ifdef XWIN_PRIMARYFB + || s_pScreenInfo->dwEngine == WIN_SERVER_PRIMARY_DD +#endif + )) { /* Cannot display the visual until the depth is restored */ ErrorF ("winWindowProc - Disruptive change in depth\n"); @@ -245,14 +276,14 @@ winWindowProc (HWND hwnd, UINT message, */ #if CYGDEBUG - ErrorF ("winWindowProc - WM_DISPLAYCHANGE - Dimensions changed\n"); + winDebug ("winWindowProc - WM_DISPLAYCHANGE - Dimensions changed\n"); #endif /* Release the old primary surface */ (*s_pScreenPriv->pwinReleasePrimarySurface) (s_pScreen); #if CYGDEBUG - ErrorF ("winWindowProc - WM_DISPLAYCHANGE - Released " + winDebug ("winWindowProc - WM_DISPLAYCHANGE - Released " "primary surface\n"); #endif @@ -260,21 +291,41 @@ winWindowProc (HWND hwnd, UINT message, (*s_pScreenPriv->pwinCreatePrimarySurface) (s_pScreen); #if CYGDEBUG - ErrorF ("winWindowProc - WM_DISPLAYCHANGE - Recreated " + winDebug ("winWindowProc - WM_DISPLAYCHANGE - Recreated " "primary surface\n"); #endif + +#if 0 + /* Multi-Window mode uses RandR for resizes */ + if (s_pScreenInfo->fMultiWindow) + { + RRSetScreenConfig (); + } +#endif } else { #if CYGDEBUG - ErrorF ("winWindowProc - WM_DISPLAYCHANGE - Dimensions did not " + winDebug ("winWindowProc - WM_DISPLAYCHANGE - Dimensions did not " "change\n"); #endif } /* Store the new display dimensions and depth */ - s_pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXSCREEN); - s_pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYSCREEN); + if (s_pScreenInfo->fMultipleMonitors) + { + s_pScreenPriv->dwLastWindowsWidth + = GetSystemMetrics (SM_CXVIRTUALSCREEN); + s_pScreenPriv->dwLastWindowsHeight + = GetSystemMetrics (SM_CYVIRTUALSCREEN); + } + else + { + s_pScreenPriv->dwLastWindowsWidth + = GetSystemMetrics (SM_CXSCREEN); + s_pScreenPriv->dwLastWindowsHeight + = GetSystemMetrics (SM_CYSCREEN); + } s_pScreenPriv->dwLastWindowsBitsPixel = GetDeviceCaps (s_pScreenPriv->hdcScreen, BITSPIXEL); break; @@ -286,14 +337,19 @@ winWindowProc (HWND hwnd, UINT message, int iWidth, iHeight; #if CYGDEBUG - ErrorF ("winWindowProc - WM_SIZE\n"); + winDebug ("winWindowProc - WM_SIZE\n"); #endif /* Break if we do not use scrollbars */ if (!s_pScreenInfo->fScrollbars || !s_pScreenInfo->fDecoration +#ifdef XWIN_MULTIWINDOWEXTWM + || s_pScreenInfo->fMWExtWM +#endif || s_pScreenInfo->fRootless +#ifdef XWIN_MULTIWINDOW || s_pScreenInfo->fMultiWindow +#endif || s_pScreenInfo->fFullScreen) break; @@ -383,7 +439,7 @@ winWindowProc (HWND hwnd, UINT message, int iVertPos; #if CYGDEBUG - ErrorF ("winWindowProc - WM_VSCROLL\n"); + winDebug ("winWindowProc - WM_VSCROLL\n"); #endif /* Get vertical scroll bar info */ @@ -468,7 +524,7 @@ winWindowProc (HWND hwnd, UINT message, int iHorzPos; #if CYGDEBUG - ErrorF ("winWindowProc - WM_HSCROLL\n"); + winDebug ("winWindowProc - WM_HSCROLL\n"); #endif /* Get horizontal scroll bar info */ @@ -554,7 +610,7 @@ winWindowProc (HWND hwnd, UINT message, int iBorderHeight, iBorderWidth; #if CYGDEBUG - ErrorF ("winWindowProc - WM_GETMINMAXINFO - pScreenInfo: %08x\n", + winDebug ("winWindowProc - WM_GETMINMAXINFO - pScreenInfo: %08x\n", s_pScreenInfo); #endif @@ -563,8 +619,14 @@ winWindowProc (HWND hwnd, UINT message, || !s_pScreenInfo->fScrollbars || s_pScreenInfo->fFullScreen || !s_pScreenInfo->fDecoration +#ifdef XWIN_MULTIWINDOWEXTWM + || s_pScreenInfo->fMWExtWM +#endif || s_pScreenInfo->fRootless - || s_pScreenInfo->fMultiWindow) +#ifdef XWIN_MULTIWINDOW + || s_pScreenInfo->fMultiWindow +#endif + ) break; /* @@ -594,7 +656,7 @@ winWindowProc (HWND hwnd, UINT message, case WM_ERASEBKGND: #if CYGDEBUG - ErrorF ("winWindowProc - WM_ERASEBKGND\n"); + winDebug ("winWindowProc - WM_ERASEBKGND\n"); #endif /* * Pretend that we did erase the background but we don't care, @@ -605,7 +667,7 @@ winWindowProc (HWND hwnd, UINT message, case WM_PAINT: #if CYGDEBUG - ErrorF ("winWindowProc - WM_PAINT\n"); + winDebug ("winWindowProc - WM_PAINT\n"); #endif /* Only paint if we have privates and the server is enabled */ if (s_pScreenPriv == NULL @@ -628,7 +690,7 @@ winWindowProc (HWND hwnd, UINT message, case WM_PALETTECHANGED: { #if CYGDEBUG - ErrorF ("winWindowProc - WM_PALETTECHANGED\n"); + winDebug ("winWindowProc - WM_PALETTECHANGED\n"); #endif /* * Don't process if we don't have privates or a colormap, @@ -686,13 +748,13 @@ winWindowProc (HWND hwnd, UINT message, } /* Hide or show the Windows mouse cursor */ - if (g_fCursor && (s_pScreenPriv->fActive || s_pScreenInfo->fLessPointer)) + if (g_fSoftwareCursor && g_fCursor && (s_pScreenPriv->fActive || s_pScreenInfo->fLessPointer)) { /* Hide Windows cursor */ g_fCursor = FALSE; ShowCursor (FALSE); } - else if (!g_fCursor && !s_pScreenPriv->fActive + else if (g_fSoftwareCursor && !g_fCursor && !s_pScreenPriv->fActive && !s_pScreenInfo->fLessPointer) { /* Show Windows cursor */ @@ -721,7 +783,7 @@ winWindowProc (HWND hwnd, UINT message, break; /* Non-client mouse movement, show Windows cursor */ - if (!g_fCursor) + if (g_fSoftwareCursor && !g_fCursor) { g_fCursor = TRUE; ShowCursor (TRUE); @@ -735,7 +797,7 @@ winWindowProc (HWND hwnd, UINT message, s_fTracking = FALSE; /* Show the mouse cursor, if necessary */ - if (!g_fCursor) + if (g_fSoftwareCursor && !g_fCursor) { g_fCursor = TRUE; ShowCursor (TRUE); @@ -746,39 +808,69 @@ winWindowProc (HWND hwnd, UINT message, case WM_LBUTTONDOWN: if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) break; - if (s_pScreenInfo->fRootless) SetCapture (hwnd); + if (s_pScreenInfo->fRootless +#ifdef XWIN_MULTIWINDOWEXTWM + || s_pScreenInfo->fMWExtWM +#endif + ) + SetCapture (hwnd); return winMouseButtonsHandle (s_pScreen, ButtonPress, Button1, wParam); case WM_LBUTTONUP: if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) break; - if (s_pScreenInfo->fRootless) ReleaseCapture (); + if (s_pScreenInfo->fRootless +#ifdef XWIN_MULTIWINDOWEXTWM + || s_pScreenInfo->fMWExtWM +#endif + ) + ReleaseCapture (); return winMouseButtonsHandle (s_pScreen, ButtonRelease, Button1, wParam); case WM_MBUTTONDBLCLK: case WM_MBUTTONDOWN: if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) break; - if (s_pScreenInfo->fRootless) SetCapture (hwnd); + if (s_pScreenInfo->fRootless +#ifdef XWIN_MULTIWINDOWEXTWM + || s_pScreenInfo->fMWExtWM +#endif + ) + SetCapture (hwnd); return winMouseButtonsHandle (s_pScreen, ButtonPress, Button2, wParam); case WM_MBUTTONUP: if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) break; - if (s_pScreenInfo->fRootless) ReleaseCapture (); + if (s_pScreenInfo->fRootless +#ifdef XWIN_MULTIWINDOWEXTWM + || s_pScreenInfo->fMWExtWM +#endif + ) + ReleaseCapture (); return winMouseButtonsHandle (s_pScreen, ButtonRelease, Button2, wParam); case WM_RBUTTONDBLCLK: case WM_RBUTTONDOWN: if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) break; - if (s_pScreenInfo->fRootless) SetCapture (hwnd); + if (s_pScreenInfo->fRootless +#ifdef XWIN_MULTIWINDOWEXTWM + || s_pScreenInfo->fMWExtWM +#endif + ) + SetCapture (hwnd); return winMouseButtonsHandle (s_pScreen, ButtonPress, Button3, wParam); case WM_RBUTTONUP: if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) break; - if (s_pScreenInfo->fRootless) ReleaseCapture (); + if (s_pScreenInfo->fRootless +#ifdef XWIN_MULTIWINDOWEXTWM + || s_pScreenInfo->fMWExtWM +#endif + ) + ReleaseCapture (); return winMouseButtonsHandle (s_pScreen, ButtonRelease, Button3, wParam); case WM_TIMER: @@ -827,7 +919,7 @@ winWindowProc (HWND hwnd, UINT message, if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) break; #if CYGDEBUG - ErrorF ("winWindowProc - WM_MOUSEWHEEL\n"); + winDebug ("winWindowProc - WM_MOUSEWHEEL\n"); #endif winMouseWheel (s_pScreen, GET_WHEEL_DELTA_WPARAM(wParam)); break; @@ -836,41 +928,31 @@ winWindowProc (HWND hwnd, UINT message, if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) break; + /* Save handle of our main window that last received focus */ + g_hwndKeyboardFocus = hwnd; + /* Restore the state of all mode keys */ - winRestoreModeKeyStates (s_pScreen); + winRestoreModeKeyStates (); + + /* Add the keyboard hook if possible */ + if (g_fKeyboardHookLL) + g_fKeyboardHookLL = winInstallKeyboardHookLL (); return 0; case WM_KILLFOCUS: if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) break; - /* Store the state of all mode keys */ - winStoreModeKeyStates (s_pScreen); + /* Clear handle of our main window that last received focus */ + g_hwndKeyboardFocus = NULL; /* Release any pressed keys */ winKeybdReleaseKeys (); - return 0; -#if WIN_NEW_KEYBOARD_SUPPORT - case WM_SYSKEYDOWN: - case WM_KEYDOWN: - case WM_SYSKEYUP: - case WM_KEYUP: - if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) - break; - - /* Don't process keys if we are not active */ - if (!s_pScreenPriv->fActive) - return 0; - - winProcessKeyEvent ((DWORD)wParam, (DWORD) lParam); - return 0; - - case WM_DEADCHAR: - case WM_SYSDEADCHAR: + /* Remove our keyboard hook if it is installed */ + winRemoveKeyboardHookLL (); return 0; -#else /* WIN_NEW_KEYBOARD_SUPPORT */ case WM_SYSKEYDOWN: case WM_KEYDOWN: if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) @@ -911,12 +993,30 @@ winWindowProc (HWND hwnd, UINT message, if (wParam == VK_LWIN || wParam == VK_RWIN) break; +#ifdef XKB + /* + * Discard presses generated from Windows auto-repeat + * ago: Only discard them if XKB is not disabled + */ + if (!g_winInfo.xkb.disable) + { + if (lParam & (1<<30)) + return 0; + } +#endif + /* Discard fake Ctrl_L presses that precede AltGR on non-US keyboards */ if (winIsFakeCtrl_L (message, wParam, lParam)) return 0; - /* Send the key event(s) */ + /* Translate Windows key code to X scan code */ winTranslateKey (wParam, lParam, &iScanCode); + + /* Ignore repeats for CapsLock */ + if (wParam == VK_CAPITAL) + lParam = 1; + + /* Send the key event(s) */ for (i = 0; i < LOWORD(lParam); ++i) winSendKeyEvent (iScanCode, TRUE); return 0; @@ -942,7 +1042,6 @@ winWindowProc (HWND hwnd, UINT message, winTranslateKey (wParam, lParam, &iScanCode); winSendKeyEvent (iScanCode, FALSE); return 0; -#endif /* WIN_NEW_KEYBOARD_SUPPORT */ case WM_HOTKEY: if (s_pScreenPriv == NULL) @@ -983,7 +1082,7 @@ winWindowProc (HWND hwnd, UINT message, } #if CYGDEBUG - ErrorF ("winWindowProc - WM_ACTIVATE\n"); + winDebug ("winWindowProc - WM_ACTIVATE\n"); #endif /* @@ -996,7 +1095,7 @@ winWindowProc (HWND hwnd, UINT message, s_pScreenPriv->iDeltaZ = 0; /* Reshow the Windows mouse cursor if we are being deactivated */ - if (LOWORD(wParam) == WA_INACTIVE + if (g_fSoftwareCursor && LOWORD(wParam) == WA_INACTIVE && !g_fCursor) { /* Show Windows cursor */ @@ -1011,14 +1110,14 @@ winWindowProc (HWND hwnd, UINT message, break; #if CYGDEBUG - ErrorF ("winWindowProc - WM_ACTIVATEAPP\n"); + winDebug ("winWindowProc - WM_ACTIVATEAPP\n"); #endif /* Activate or deactivate */ s_pScreenPriv->fActive = wParam; /* Reshow the Windows mouse cursor if we are being deactivated */ - if (!s_pScreenPriv->fActive + if (g_fSoftwareCursor && !s_pScreenPriv->fActive && !g_fCursor) { /* Show Windows cursor */ @@ -1026,6 +1125,9 @@ winWindowProc (HWND hwnd, UINT message, ShowCursor (TRUE); } + /* Make sure the clipboard chain is ok. */ + winFixClipboardChain (); + /* Call engine specific screen activation/deactivation function */ (*s_pScreenPriv->pwinActivateApp) (s_pScreen); return 0; @@ -1038,27 +1140,35 @@ winWindowProc (HWND hwnd, UINT message, winDisplayExitDialog (s_pScreenPriv); return 0; +#ifdef XWIN_MULTIWINDOW case ID_APP_HIDE_ROOT: - ShowWindow (s_pScreenPriv->hwndScreen, SW_HIDE); - s_pScreenPriv->fRootWindowShown = FALSE; + if (s_pScreenPriv->fRootWindowShown) + ShowWindow (s_pScreenPriv->hwndScreen, SW_HIDE); + else + ShowWindow (s_pScreenPriv->hwndScreen, SW_SHOW); + s_pScreenPriv->fRootWindowShown = !s_pScreenPriv->fRootWindowShown; return 0; +#endif - case ID_APP_SHOW_ROOT: - ShowWindow (s_pScreenPriv->hwndScreen, SW_SHOW); - s_pScreenPriv->fRootWindowShown = TRUE; + case ID_APP_ABOUT: + /* Display the About box */ + winDisplayAboutDialog (s_pScreenPriv); return 0; default: /* It's probably one of the custom menus... */ - return HandleCustomWM_COMMAND (0, LOWORD (wParam)); - + if (HandleCustomWM_COMMAND (0, LOWORD (wParam))) + return 0; } break; + case WM_ENDSESSION: case WM_GIVEUP: - /* Tell X that we are giving up */ - winDeinitClipboard (); - winDeinitMultiWindowWM (); + /* Tell X that we are giving up */ +#ifdef XWIN_MULTIWINDOW + if (s_pScreenInfo->fMultiWindow) + winDeinitMultiWindowWM (); +#endif GiveUp (0); return 0; @@ -1066,6 +1176,21 @@ winWindowProc (HWND hwnd, UINT message, /* Display Exit dialog */ winDisplayExitDialog (s_pScreenPriv); return 0; + + case WM_SETCURSOR: + if (LOWORD(lParam) == HTCLIENT) + { + if (!g_fSoftwareCursor) SetCursor (s_pScreenPriv->cursor.handle); + return TRUE; + } + break; + + default: + if(message == s_uTaskbarRestart) + { + winInitNotifyIcon (s_pScreenPriv); + } + break; } return DefWindowProc (hwnd, message, wParam, lParam); |